def test_dexrpc_get(self, test_params): # check get id schema_broadcast = { 'type': 'object', 'properties': { 'timestamp': { 'type': 'integer' }, 'recvtime': { 'type': 'integer' }, 'id': { 'type': 'integer' }, 'tagA': { 'type': 'string' }, 'tagB': { 'type': 'string' }, 'senderpub': { 'type': 'string' }, 'destpub': { 'type': 'string' }, 'payload': { 'type': 'string' }, 'hex': { 'type': 'integer' }, 'amountA': { 'type': ['string'] }, 'amountB': { 'type': ['string'] }, 'priority': { 'type': 'integer' }, 'error': { 'type': 'string' }, 'cancelled': { 'type': 'integer' } }, 'required': ['timestamp', 'id', 'tagA', 'tagB', 'payload'] } rpc1 = test_params.get('node1').get('rpc') pubkey = rpc1.DEX_stats().get('publishable_pubkey') message = randomhex() res = rpc1.DEX_broadcast(message, '4', 'BASE', 'REL', pubkey, '10', '1') order_id = str(res.get('id')) res = rpc1.DEX_get(order_id) validate_template(res, schema_broadcast) # same response to broadcast
def bad_calls(proxy, fundtxid): name = proxy.rewardsinfo(fundtxid).get('name') invalidfunding = randomhex() # looking up non-existent reward should return error res = proxy.rewardsinfo(invalidfunding) assert res.get('result') == 'error' # creating rewards plan with name > 8 chars, should return error res = proxy.rewardscreatefunding("STUFFSTUFF", "7777", "25", "0", "10", "10") assert res.get('result') == 'error' # creating rewards plan with 0 funding res = proxy.rewardscreatefunding("STUFF", "0", "25", "0", "10", "10") assert res.get('result') == 'error' # creating rewards plan with 0 maxdays res = proxy.rewardscreatefunding("STUFF", "7777", "25", "0", "10", "0") assert res.get('result') == 'error' # creating rewards plan with > 25% APR res = proxy.rewardscreatefunding("STUFF", "7777", "30", "0", "10", "10") assert res.get('result') == 'error' # creating reward plan with already existing name, should return error res = proxy.rewardscreatefunding(name, "777", "25", "0", "10", "10") assert res.get('result') == 'error' # add funding amount must be positive res = proxy.rewardsaddfunding(name, fundtxid, "-1") assert res.get('result') == 'error' # add funding amount must be positive res = proxy.rewardsaddfunding(name, fundtxid, "0") assert res.get('result') == 'error' # trying to lock funds, locking funds amount must be positive res = proxy.rewardslock(name, fundtxid, "-5") assert res.get('result') == 'error' # trying to lock funds, locking funds amount must be positive res = proxy.rewardslock(name, fundtxid, "0") assert res.get('result') == 'error' # trying to lock less than the min amount is an error res = proxy.rewardslock(name, fundtxid, "7") assert res.get('result') == 'error'
def badbets_check(proxy, fundtxid): casino = proxy.diceinfo(fundtxid) dname = str(casino.get('name')) minbet = str(casino.get('minbet')) maxbet = str(casino.get('maxbet')) maxodds = str(casino.get('maxodds')) funding = str(casino.get('funding')) res = proxy.dicebet(dname, fundtxid, '0', maxodds) # 0 bet assert res.get('result') == 'error' res = proxy.dicebet(dname, fundtxid, minbet, '0') # 0 odds assert res.get('result') == 'error' res = proxy.dicebet(dname, fundtxid, '-1', maxodds) # negative bet assert res.get('result') == 'error' res = proxy.dicebet(dname, fundtxid, minbet, '-1') # negative odds assert res.get('result') == 'error' # placing bet more than maxbet dmb = Decimal(maxbet) dmb += 1 res = proxy.dicebet(dname, fundtxid, "{0:.8f}".format(dmb), maxodds) assert res.get('result') == 'error' # placing bet with odds more than allowed dmo = Decimal(maxodds) dmo += 1 res = proxy.dicebet(dname, fundtxid, minbet, "{0:.8f}".format(dmo)) assert res.get('result') == 'error' # placing bet with amount more than funding betamount = funding res = proxy.dicebet(dname, fundtxid, str(betamount), maxodds) assert res.get('result') == 'error' # placing bet with not correct dice name name = randomstring(5) res = proxy.dicebet(name, fundtxid, minbet, maxodds) assert res.get('result') == 'error' # placing bet with not correct dice id badtxid = randomhex() res = proxy.dicebet(dname, badtxid, minbet, maxodds) assert res.get('result') == 'error'
def test_dexrpc_setpubkey(self, test_params): # check setpubkey with random pubkey-like string schema_setpub = { 'type': 'object', 'properties': { 'publishable_pubkey': { 'type': 'string' }, 'perfstats': { 'type': 'string' }, 'result': { 'type': 'string' }, 'secpkey': { 'type': 'string' }, 'recvaddr': { 'type': 'string' }, 'recvZaddr': { 'type': 'string' }, 'handle': { 'type': 'string' }, 'txpowbits': { 'type': 'integer' }, 'vip': { 'type': 'integer' }, 'cmdpriority': { 'type': 'integer' } } } rpc1 = test_params.get('node1').get('rpc') res = rpc1.DEX_setpubkey('01' + randomhex()) validate_template(res, schema_setpub) assert res.get('result') == 'success'
def test_dexrpc_orderbook(self, test_params): # check orderbook schema_orderbook = { 'type': 'object', 'properties': { 'asks': { 'type': 'array', 'items': { 'type': 'object', 'properties': { 'price': { 'type': 'string' }, 'price15': { 'type': 'string' }, 'baseamount': { 'type': 'string' }, 'basesatoshis': { 'type': 'integer' }, 'relamount': { 'type': 'string' }, 'relsatoshis': { 'type': 'integer' }, 'priority': { 'type': 'integer' }, 'timestamp': { 'type': 'integer' }, 'id': { 'type': 'integer' }, 'pubkey': { 'type': 'string' }, 'hash': { 'type': 'string' } } } }, 'bids': { 'type': 'array', 'items': { 'type': 'object', 'properties': { 'price': { 'type': 'string' }, 'price15': { 'type': 'string' }, 'baseamount': { 'type': 'integer' }, 'basesatoshis': { 'type': 'integer' }, 'relamount': { 'type': 'integer' }, 'relsatoshis': { 'type': 'integer' }, 'priority': { 'type': 'integer' }, 'timestamp': { 'type': 'integer' }, 'id': { 'type': 'integer' }, 'pubkey': { 'type': 'string' }, 'hash': { 'type': 'string' } } } } }, 'required': ['asks', 'bids'] } rpc1 = test_params.get('node1').get('rpc') pubkey = rpc1.DEX_stats().get('publishable_pubkey') message = randomhex() rpc1.DEX_broadcast(message, '4', 'BASE', 'REL', pubkey, '10', '1') res = rpc1.DEX_orderbook('', '0', 'BASE', 'REL') validate_template(res, schema_orderbook)
def test_dexrpc_list(self, test_params): # check dexlist schema_list = { 'type': 'object', 'properties': { 'tagA': { 'type': 'string' }, 'tagB': { 'type': 'string' }, 'destpub': { 'type': 'string' }, 'n': { 'type': 'integer' }, 'matches': { 'type': 'array', 'items': { 'type': 'object', 'properties': { 'timestamp': { 'type': 'integer' }, 'id': { 'type': 'integer' }, 'hex': { 'type': 'integer' }, 'priority': { 'type': 'integer' }, 'amountA': { 'type': ['string'] }, 'amountB': { 'type': ['string'] }, 'tagA': { 'type': 'string' }, 'tagB': { 'type': 'string' }, 'destpub': { 'type': 'string' }, 'payload': { 'type': 'string' }, 'decrypted': { 'type': 'string' }, 'decryptedhex': { 'type': 'integer' }, 'senderpub': { 'type': 'string' }, 'recvtime': { 'type': 'integer' }, 'error': { 'type': 'string' }, 'cancelled': { 'type': 'integer' } } } } }, 'required': ['tagA', 'tagB', 'n'] } rpc1 = test_params.get('node1').get('rpc') pubkey = rpc1.DEX_stats().get('publishable_pubkey') message = randomhex() rpc1.DEX_broadcast(message, '4', 'inbox', '', pubkey, '', '') res = rpc1.DEX_list('', '4', '', '', pubkey) validate_template(res, schema_list)