def run_faucet_tests(self):
        rpc = self.rpc
        rpc1 = self.rpc1

        # basic sanity tests
        result = rpc.getwalletinfo()
        assert_greater_than(result['txcount'], 100)
        assert_greater_than(result['balance'], 0.0)
        balance = result['balance']

        result = rpc.faucetaddress()
        assert_equal(result['result'], 'success')

        # verify all keys look like valid AC addrs, could be better
        for x in result.keys():
            if x.find('ddress') > 0:
                assert_equal(result[x][0], 'R')

        result = rpc.faucetaddress(self.pubkey)
        assert_success(result)
        for x in result.keys():
            print(x + ": " + str(result[x]))
        # test that additional CCaddress key is returned

        for x in result.keys():
            if x.find('ddress') > 0:
                assert_equal(result[x][0], 'R')

        # no funds in the faucet yet
        result = rpc.faucetget()
        assert_error(result)

        result = rpc.faucetinfo()
        assert_success(result)

        result = rpc.faucetfund("0")
        assert_error(result)

        result = rpc.faucetfund("-1")
        assert_error(result)

        # we need at least 1 + txfee to get
        result = rpc.faucetfund("2")
        assert_success(result)
        assert result['hex'], "hex key found"

        # broadcast the xtn
        result = rpc.sendrawtransaction(result['hex'])
        txid = result[0]
        assert txid, "found txid"

        # we need the tx above to be confirmed in the next block
        rpc.generate(1)
        self.sync_all()

        result = rpc.getwalletinfo()
        # minus one block reward
        balance2 = result['balance'] - 100000
        # make sure our balance is less now
        assert_greater_than(balance, balance2)

        result = rpc.faucetinfo()
        assert_success(result)
        assert_greater_than(result['funding'], 0)

        # claiming faucet on second node
        faucetgethex = rpc1.faucetget()
        assert_success(faucetgethex)
        assert faucetgethex['hex'], "hex key found"

        balance1 = rpc1.getwalletinfo()['balance']

        # try to broadcast the faucetget transaction
        result = self.send_and_mine(faucetgethex['hex'], rpc1)
        assert txid, "transaction broadcasted"

        balance2 = rpc1.getwalletinfo()['balance']
        assert_greater_than(balance2, balance1)

        self.sync_all()
    def run_oracles_tests(self):
        rpc = self.nodes[0]
        rpc1 = self.nodes[1]

        result = rpc1.oraclesaddress()

        result = rpc.oraclesaddress()
        assert_success(result)
        for x in ['OraclesCCaddress', 'Oraclesmarker', 'myCCaddress', 'myaddress']:
            assert_equal(result[x][0], 'R')

        result = rpc.oraclesaddress(self.pubkey)
        assert_success(result)
        for x in ['OraclesCCaddress', 'Oraclesmarker', 'myCCaddress', 'myaddress']:
            assert_equal(result[x][0], 'R')

        # there are no oracles created yet
        result = rpc.oracleslist()
        assert_equal(result, [])

        # looking up non-existent oracle should return error.
        result = rpc.oraclesinfo("none")
        assert_error(result)

        # attempt to create oracle with not valid data type should return error
        result = rpc.oraclescreate("Test", "Test", "Test")
        assert_error(result)

        # attempt to create oracle with description > 32 symbols should return error
        too_long_name = generate_random_string(33)
        result = rpc.oraclescreate(too_long_name, "Test", "s")

        # attempt to create oracle with description > 4096 symbols should return error
        too_long_description = generate_random_string(4100)
        result = rpc.oraclescreate("Test", too_long_description, "s")
        assert_error(result)
        # valid creating oracles of different types
        # using such naming to re-use it for data publishing / reading (e.g. oracle_s for s type)
        valid_formats = ["s", "S", "d", "D", "c", "C", "t", "T", "i", "I", "l", "L", "h", "Ihh"]
        for f in valid_formats:
            result = rpc.oraclescreate("Test", "Test", f)
            assert_success(result)
            globals()["oracle_{}".format(f)] = self.send_and_mine(result['hex'], rpc)

        # trying to register with negative datafee
        for f in valid_formats:
            result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "-100")
            assert_error(result)

        # trying to register with zero datafee
        for f in valid_formats:
            result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "0")
            assert_error(result)

        # trying to register with datafee less than txfee
        for f in valid_formats:
            result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "500")
            assert_error(result)

        # trying to register valid
        for f in valid_formats:
            result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "10000")
            assert_success(result)
            register_txid = self.send_and_mine(result["hex"], rpc)
            assert register_txid, "got txid"

        # TODO: for most of the non valid oraclesregister and oraclessubscribe transactions generating and broadcasting now
        # so trying only valid oraclessubscribe atm
        for f in valid_formats:
            result = rpc.oraclessubscribe(globals()["oracle_{}".format(f)], self.pubkey, "1")
            assert_success(result)
            subscribe_txid = self.send_and_mine(result["hex"], rpc)
            assert register_txid, "got txid"

        # now lets publish and read valid data for each oracle type

        # s type
        result = rpc.oraclesdata(globals()["oracle_{}".format("s")], "05416e746f6e")
        assert_success(result)
        # baton
        oraclesdata_s = self.send_and_mine(result["hex"], rpc)
        result = rpc.oraclessamples(globals()["oracle_{}".format("s")], oraclesdata_s, "1")
        assert_equal("[u'Anton']", str(result["samples"][0]), "Data match")

        # S type
        result = rpc.oraclesdata(globals()["oracle_{}".format("S")], "000161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161")
        assert_success(result)
        # baton
        oraclesdata_S = self.send_and_mine(result["hex"], rpc)
        result = rpc.oraclessamples(globals()["oracle_{}".format("S")], oraclesdata_S, "1")
        assert_equal("[u'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa']", str(result["samples"][0]), "Data match")

        # d type
        result = rpc.oraclesdata(globals()["oracle_{}".format("d")], "0101")
        assert_success(result)
        # baton
        oraclesdata_d = self.send_and_mine(result["hex"], rpc)
        result = rpc.oraclessamples(globals()["oracle_{}".format("d")], oraclesdata_d, "1")
        # TODO: working not correct now!
        #assert_equal("[u'01']", str(result["samples"][0]), "Data match")

        # D type
        result = rpc.oraclesdata(globals()["oracle_{}".format("D")], "0101")
        assert_success(result)
        # baton
        oraclesdata_D = self.send_and_mine(result["hex"], rpc)
        result = rpc.oraclessamples(globals()["oracle_{}".format("D")], oraclesdata_D, "1")
        # TODO: working not correct now!
        #assert_equal("[u'01']", str(result["samples"][0]), "Data match")

        # c type
        result = rpc.oraclesdata(globals()["oracle_{}".format("c")], "ff")
        assert_success(result)
        # baton
        oraclesdata_c = self.send_and_mine(result["hex"], rpc)
        result = rpc.oraclessamples(globals()["oracle_{}".format("c")], oraclesdata_c, "1")
        assert_equal("[u'-1']", str(result["samples"][0]), "Data match")

        # C type
        result = rpc.oraclesdata(globals()["oracle_{}".format("C")], "ff")
        assert_success(result)
        # baton
        oraclesdata_C = self.send_and_mine(result["hex"], rpc)
        result = rpc.oraclessamples(globals()["oracle_{}".format("C")], oraclesdata_C, "1")
        assert_equal("[u'255']", str(result["samples"][0]), "Data match")

        # t type
        result = rpc.oraclesdata(globals()["oracle_{}".format("t")], "ffff")
        assert_success(result)
        # baton
        oraclesdata_t = self.send_and_mine(result["hex"], rpc)
        result = rpc.oraclessamples(globals()["oracle_{}".format("t")], oraclesdata_t, "1")
        assert_equal("[u'-1']", str(result["samples"][0]), "Data match")

        # T type
        result = rpc.oraclesdata(globals()["oracle_{}".format("T")], "ffff")
        assert_success(result)
        # baton
        oraclesdata_T = self.send_and_mine(result["hex"], rpc)
        result = rpc.oraclessamples(globals()["oracle_{}".format("T")], oraclesdata_T, "1")
        assert_equal("[u'65535']", str(result["samples"][0]), "Data match")

        # i type
        result = rpc.oraclesdata(globals()["oracle_{}".format("i")], "ffffffff")
        assert_success(result)
        # baton
        oraclesdata_i = self.send_and_mine(result["hex"], rpc)
        result = rpc.oraclessamples(globals()["oracle_{}".format("i")], oraclesdata_i, "1")
        assert_equal("[u'-1']", str(result["samples"][0]), "Data match")

        # I type
        result = rpc.oraclesdata(globals()["oracle_{}".format("I")], "ffffffff")
        assert_success(result)
        # baton
        oraclesdata_I = self.send_and_mine(result["hex"], rpc)
        result = rpc.oraclessamples(globals()["oracle_{}".format("I")], oraclesdata_I, "1")
        assert_equal("[u'4294967295']", str(result["samples"][0]), "Data match")

        # l type
        result = rpc.oraclesdata(globals()["oracle_{}".format("l")], "00000000ffffffff")
        assert_success(result)
        # baton
        oraclesdata_l = self.send_and_mine(result["hex"], rpc)
        result = rpc.oraclessamples(globals()["oracle_{}".format("l")], oraclesdata_l, "1")
        # TODO: working not correct now!
        #assert_equal("[u'-4294967296']", str(result["samples"][0]), "Data match")

        # L type
        result = rpc.oraclesdata(globals()["oracle_{}".format("L")], "00000000ffffffff")
        assert_success(result)
        # baton
        oraclesdata_L = self.send_and_mine(result["hex"], rpc)
        result = rpc.oraclessamples(globals()["oracle_{}".format("L")], oraclesdata_L, "1")
        assert_equal("[u'18446744069414584320']", str(result["samples"][0]), "Data match")

        # h type
        result = rpc.oraclesdata(globals()["oracle_{}".format("h")], "00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff")
        assert_success(result)
        # baton
        oraclesdata_h = self.send_and_mine(result["hex"], rpc)
        result = rpc.oraclessamples(globals()["oracle_{}".format("h")], oraclesdata_h, "1")
        assert_equal("[u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000']", str(result["samples"][0]), "Data match")

        # Ihh type
        result = rpc.oraclesdata(globals()["oracle_{}".format("Ihh")], "00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff")
        assert_success(result)
        # baton
        oraclesdata_Ihh = self.send_and_mine(result["hex"], rpc)
        result = rpc.oraclessamples(globals()["oracle_{}".format("Ihh")], oraclesdata_Ihh, "1")
        assert_equal("[u'0']", str(result["samples"][0]), "Data match")
    def run_channels_tests(self):


        """!!! for testing needed test daemon which built with custom flag
        export CONFIGURE_FLAGS='CPPFLAGS=-DTESTMODE'
        since in usual mode 101 confirmations are needed for payment/refund
        """

        rpc = self.nodes[0]
        rpc1 = self.nodes[1]

        # getting empty channels list
        result = rpc.channelsinfo()
        assert_equal(len(result), 2)
        assert_equal(result["result"], "success")
        assert_equal(result["name"], "Channels Info")

        # 10 payments, 100000 sat denomination channel opening with second node pubkey
        new_channel_hex = rpc.channelsopen(self.pubkey1, "10", "100000")
        assert_success(new_channel_hex)
        channel_txid = self.send_and_mine(new_channel_hex["hex"], rpc)
        assert channel_txid, "got channel txid"

        # checking if our new channel in common channels list
        result = rpc.channelsinfo()
        assert_equal(len(result), 3)

        # checking info about channel directly
        result = rpc.channelsinfo(channel_txid)
        assert_success(result)
        assert_equal(result["Open"], "10 payments of 100000 satoshi")

        # open transaction should be confirmed
        rpc.generate(1)

        # trying to make wrong denomination channel payment
        result = rpc.channelspayment(channel_txid, "199000")
        assert_error(result)

        # trying to make 0 channel payment
        result = rpc.channelspayment(channel_txid, "0")
        assert_error(result)

        # trying to make negative channel payment
        result = rpc.channelspayment(channel_txid, "-1")
        assert_error(result)

        # valid channel payment
        result = rpc.channelspayment(channel_txid, "100000")
        assert_success(result)
        payment_tx_id = self.send_and_mine(result["hex"], rpc)
        assert payment_tx_id, "got txid"

        # now in channelinfo payment information should appear
        result = rpc.channelsinfo(channel_txid)
        assert_equal(result["Payment"], "100000 satoshi to {}, 9 payments left".format(self.addr1))

        # executing channel close
        result = rpc.channelsclose(channel_txid)
        assert_success(result)
        channel_close_txid = self.send_and_mine(result["hex"], rpc)
        assert channel_close_txid, "got txid"

        rpc.generate(2)
        self.sync_all()

        # now in channelinfo closed flag should appear
        result = rpc.channelsinfo(channel_txid)
        assert_equal(result["Close"], "channel")

        # executing channel refund
        result = rpc.channelsrefund(channel_txid, channel_close_txid)
        assert_success(result)
        refund_txid = self.send_and_mine(result["hex"], rpc)
        assert refund_txid, "got txid"
Exemple #4
0
    def run_channels_tests(self):
        """!!! for testing needed test daemon which built with custom flag
        export CONFIGURE_FLAGS='CPPFLAGS=-DTESTMODE'
        since in usual mode 101 confirmations are needed for payment/refund
        """

        rpc = self.nodes[0]
        rpc1 = self.nodes[1]

        # checking channelsaddress call

        result = rpc.channelsaddress(self.pubkey)
        assert_success(result)
        # test that additional CCaddress key is returned

        for x in result.keys():
            if x.find('ddress') > 0:
                assert_equal(result[x][0], 'R')

        # getting empty channels list
        result = rpc.channelslist()
        assert_equal(len(result), 2)
        assert_equal(result["result"], "success")
        assert_equal(result["name"], "Channels List")

        # 10 payments, 100000 sat denomination channel opening with second node pubkey
        new_channel_hex = rpc.channelsopen(self.pubkey1, "10", "100000")
        assert_success(new_channel_hex)
        channel_txid = self.send_and_mine(new_channel_hex["hex"], rpc)
        assert channel_txid, "got channel txid"

        # checking if our new channel in common channels list
        result = rpc.channelslist()
        assert_equal(len(result), 3)

        # checking info about channel directly
        result = rpc.channelsinfo(channel_txid)
        assert_success(result)
        assert_equal(result["Transactions"][0]["Open"], channel_txid)

        # open transaction should be confirmed
        rpc.generate(1)

        # trying to make wrong denomination channel payment
        result = rpc.channelspayment(channel_txid, "199000")
        assert_error(result)

        # trying to make 0 channel payment
        result = rpc.channelspayment(channel_txid, "0")
        assert_error(result)

        # trying to make negative channel payment
        result = rpc.channelspayment(channel_txid, "-1")
        assert_error(result)

        # valid channel payment
        result = rpc.channelspayment(channel_txid, "100000")
        assert_success(result)
        payment_tx_id = self.send_and_mine(result["hex"], rpc)
        assert payment_tx_id, "got txid"

        # now in channelinfo payment information should appear
        result = rpc.channelsinfo(channel_txid)
        assert_equal(result["Transactions"][1]["Payment"], payment_tx_id)

        # number of payments should be equal 1 (one denomination used)
        result = rpc.channelsinfo(
            channel_txid)["Transactions"][1]["Number of payments"]
        assert_equal(result, 1)
        # payments left param should reduce 1 and be equal 9 now ( 10 - 1 = 9 )
        result = rpc.channelsinfo(
            channel_txid)["Transactions"][1]["Payments left"]
        assert_equal(result, 9)

        # lets try payment with x2 amount to ensure that counters works correct
        result = rpc.channelspayment(channel_txid, "200000")
        assert_success(result)
        payment_tx_id = self.send_and_mine(result["hex"], rpc)
        assert payment_tx_id, "got txid"

        result = rpc.channelsinfo(channel_txid)
        assert_equal(result["Transactions"][2]["Payment"], payment_tx_id)

        result = rpc.channelsinfo(
            channel_txid)["Transactions"][2]["Number of payments"]
        assert_equal(result, 2)

        result = rpc.channelsinfo(
            channel_txid)["Transactions"][2]["Payments left"]
        assert_equal(result, 7)

        # check if payment value really transferred
        raw_transaction = rpc.getrawtransaction(payment_tx_id, 1)

        result = raw_transaction["vout"][3]["valueSat"]
        assert_equal(result, 200000)

        result = rpc1.validateaddress(
            raw_transaction["vout"][3]["scriptPubKey"]["addresses"]
            [0])["ismine"]
        assert_equal(result, True)

        # have to check that second node have coins to cover txfee at least
        rpc.sendtoaddress(rpc1.getnewaddress(), 1)
        rpc.sendtoaddress(rpc1.getnewaddress(), 1)
        rpc.generate(2)
        self.sync_all()
        result = rpc1.getbalance()
        assert_greater_than(result, 0.1)

        # trying to initiate channels payment from node B without any secret
        # TODO: have to add RPC validation
        payment_hex = rpc1.channelspayment(channel_txid, "100000")
        try:
            result = rpc1.sendrawtransaction(payment_hex["hex"])
        except Exception as e:
            pass

        # trying to initiate channels payment from node B with secret from previous payment
        result = rpc1.channelspayment(
            channel_txid, "100000",
            rpc1.channelsinfo(channel_txid)["Transactions"][1]["Secret"])
        #result = rpc1.sendrawtransaction(payment_hex["hex"])
        assert_error(result)

        # executing channel close
        result = rpc.channelsclose(channel_txid)
        assert_success(result)
        channel_close_txid = self.send_and_mine(result["hex"], rpc)
        assert channel_close_txid, "got txid"

        rpc.generate(2)
        self.sync_all()

        # now in channelinfo closed flag should appear
        result = rpc.channelsinfo(channel_txid)
        assert_equal(result["Transactions"][3]["Close"], channel_close_txid)

        # executing channel refund
        result = rpc.channelsrefund(channel_txid, channel_close_txid)
        assert_success(result)
        refund_txid = self.send_and_mine(result["hex"], rpc)
        assert refund_txid, "got txid"

        # checking if it refunded to opener address
        raw_transaction = rpc.getrawtransaction(refund_txid, 1)

        result = raw_transaction["vout"][2]["valueSat"]
        assert_equal(result, 700000)

        result = rpc.validateaddress(raw_transaction["vout"][2]["scriptPubKey"]
                                     ["addresses"][0])["ismine"]
        assert_equal(result, True)

        # creating and draining channel (10 payment by 100000 satoshies in total to fit full capacity)
        new_channel_hex1 = rpc.channelsopen(self.pubkey1, "10", "100000")
        assert_success(new_channel_hex1)
        channel1_txid = self.send_and_mine(new_channel_hex1["hex"], rpc)
        assert channel1_txid, "got channel txid"

        # need to have 2+ confirmations in the test mode
        rpc.generate(2)
        self.sync_all()

        for i in range(10):
            result = rpc.channelspayment(channel1_txid, "100000")
            assert_success(result)
            payment_tx_id = self.send_and_mine(result["hex"], rpc)
            assert payment_tx_id, "got txid"

        # last payment should indicate that 0 payments left
        result = rpc.channelsinfo(
            channel1_txid)["Transactions"][10]["Payments left"]
        assert_equal(result, 0)

        # no more payments possible
        result = rpc.channelspayment(channel1_txid, "100000")
        assert_error(result)

        # creating new channel to test the case when node B initiate payment when node A revealed secret in offline
        # 10 payments, 100000 sat denomination channel opening with second node pubkey
        new_channel_hex2 = rpc.channelsopen(self.pubkey1, "10", "100000")
        assert_success(new_channel_hex)
        channel2_txid = self.send_and_mine(new_channel_hex2["hex"], rpc)
        assert channel2_txid, "got channel txid"

        rpc.generate(2)
        self.sync_all()

        # disconnecting first node from network
        rpc.setban("127.0.0.0/24", "add")
        assert_equal(rpc.getinfo()["connections"], 0)
        assert_equal(rpc1.getinfo()["connections"], 0)

        rpc1.generate(1)

        # sending one payment to mempool to reveal the secret but not mine it
        payment_hex = rpc.channelspayment(channel2_txid, "100000")
        result = rpc.sendrawtransaction(payment_hex["hex"])
        assert result, "got payment txid"

        secret = rpc.channelsinfo(channel2_txid)["Transactions"][1]["Secret"]
        assert secret, "Secret revealed"

        # secret shouldn't be available for node B
        secret_not_revealed = None
        try:
            rpc1.channelsinfo(channel2_txid)["Transactions"][1]["Secret"]
        except Exception:
            secret_not_revealed = True
        assert_equal(secret_not_revealed, True)

        # trying to initiate payment from second node with revealed secret
        assert_equal(rpc1.getinfo()["connections"], 0)
        dc_payment_hex = rpc1.channelspayment(channel2_txid, "100000", secret)
        assert_success(dc_payment_hex)
        result = rpc1.sendrawtransaction(dc_payment_hex["hex"])
        assert result, "got channelspayment transaction id"
Exemple #5
0
    def run_rewards_tests(self):
        rpc = self.nodes[0]
        result = rpc.rewardsaddress()
        for x in [
                'RewardsCCaddress', 'myCCaddress', 'Rewardsmarker', 'myaddress'
        ]:
            assert_equal(result[x][0], 'R')

        result = rpc.rewardsaddress(self.pubkey)
        for x in [
                'RewardsCCaddress', 'myCCaddress', 'Rewardsmarker',
                'myaddress', 'CCaddress'
        ]:
            assert_equal(result[x][0], 'R')

        # no rewards yet
        result = rpc.rewardslist()
        assert_equal(result, [])

        # looking up non-existent reward should return error
        result = rpc.rewardsinfo("none")
        assert_error(result)

        # creating rewards plan with name > 8 chars, should return error
        result = rpc.rewardscreatefunding("STUFFSTUFF", "7777", "25", "0",
                                          "10", "10")
        assert_error(result)

        # creating rewards plan with 0 funding
        result = rpc.rewardscreatefunding("STUFF", "0", "25", "0", "10", "10")
        assert_error(result)

        # creating rewards plan with 0 maxdays
        result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10",
                                          "0")
        assert_error(result)

        # creating rewards plan with > 25% APR
        result = rpc.rewardscreatefunding("STUFF", "7777", "30", "0", "10",
                                          "10")
        assert_error(result)

        # creating valid rewards plan
        result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10",
                                          "10")
        assert result['hex'], 'got raw xtn'
        fundingtxid = rpc.sendrawtransaction(result['hex'])
        assert fundingtxid, 'got txid'

        # confirm the above xtn
        rpc.generate(1)
        result = rpc.rewardsinfo(fundingtxid)
        assert_success(result)
        assert_equal(result['name'], 'STUFF')
        assert_equal(result['APR'], "25.00000000")
        assert_equal(result['minseconds'], 0)
        assert_equal(result['maxseconds'], 864000)
        assert_equal(result['funding'], "7777.00000000")
        assert_equal(result['mindeposit'], "10.00000000")
        assert_equal(result['fundingtxid'], fundingtxid)

        # checking if new plan in rewardslist
        result = rpc.rewardslist()
        assert_equal(result[0], fundingtxid)

        # creating reward plan with already existing name, should return error
        result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10",
                                          "10")
        assert_error(result)

        # add funding amount must be positive
        result = rpc.rewardsaddfunding("STUFF", fundingtxid, "-1")
        assert_error(result)

        # add funding amount must be positive
        result = rpc.rewardsaddfunding("STUFF", fundingtxid, "0")
        assert_error(result)

        # adding valid funding
        result = rpc.rewardsaddfunding("STUFF", fundingtxid, "555")
        addfundingtxid = self.send_and_mine(result['hex'], rpc)
        assert addfundingtxid, 'got funding txid'

        # checking if funding added to rewardsplan
        result = rpc.rewardsinfo(fundingtxid)
        assert_equal(result['funding'], "8332.00000000")

        # trying to lock funds, locking funds amount must be positive
        result = rpc.rewardslock("STUFF", fundingtxid, "-5")
        assert_error(result)

        # trying to lock funds, locking funds amount must be positive
        result = rpc.rewardslock("STUFF", fundingtxid, "0")
        assert_error(result)

        # trying to lock less than the min amount is an error
        result = rpc.rewardslock("STUFF", fundingtxid, "7")
        assert_error(result)

        # locking funds in rewards plan
        result = rpc.rewardslock("STUFF", fundingtxid, "10")
        assert_success(result)
        locktxid = result['hex']
        assert locktxid, "got lock txid"

        # locktxid has not been broadcast yet
        result = rpc.rewardsunlock("STUFF", fundingtxid, locktxid)
        assert_error(result)

        # broadcast xtn
        txid = rpc.sendrawtransaction(locktxid)
        assert txid, 'got txid from sendrawtransaction'

        # confirm the xtn above
        rpc.generate(1)

        # will not unlock since reward amount is less than tx fee
        result = rpc.rewardsunlock("STUFF", fundingtxid, locktxid)
        assert_error(result)
    def run_heir_tests(self):

        rpc = self.nodes[0]
        rpc1 = self.nodes[1]

        result = rpc.heiraddress('')
        assert_success(result)

        # verify all keys look like valid AC addrs, could be better
        for x in result.keys():
            if x.find('ddress') > 0:
                assert_equal(result[x][0], 'R')

        result = rpc.heiraddress(self.pubkey)
        assert_success(result)

        # test that additional CCaddress key is returned
        for x in result.keys():
            if x.find('ddress') > 0:
                assert_equal(result[x][0], 'R')

        # getting empty heir list
        result = rpc.heirlist()
        assert_equal(result, [])

        # valid heirfund case with coins
        result = rpc.heirfund("0", "1000", "UNITHEIR", self.pubkey1, "10", "TESTMEMO")
        assert_success(result)

        heir_fund_txid = self.send_and_mine(result["hex"], rpc)
        assert heir_fund_txid, "got heir funding txid"

        # heir fund txid should be in heirlist now
        result = rpc.heirlist()
        assert_equal(result, [heir_fund_txid])

        # checking heirinfo
        result = rpc.heirinfo(heir_fund_txid)
        assert_success(result)
        assert_equal(result["fundingtxid"], heir_fund_txid)
        assert_equal(result["name"], "UNITHEIR")
        assert_equal(result["owner"], self.pubkey)
        assert_equal(result["heir"], self.pubkey1)
        assert_equal(result["memo"], "TESTMEMO")
        assert_equal(result["lifetime"], "1000.00000000")
        assert_equal(result["type"], "coins")
        assert_equal(result["InactivityTimeSetting"], "10")
        assert_equal(result["InactivityTime"], "0")
        assert_equal(result["IsHeirSpendingAllowed"], "false")

        # waiting for 11 seconds to be sure that needed time passed for heir claiming
        time.sleep(11)
        rpc.generate(1)
        self.sync_all()
        result = rpc.heirinfo(heir_fund_txid)
        assert_equal(result["lifetime"], "1000.00000000")
        assert_equal(result["IsHeirSpendingAllowed"], "true")

        # have to check that second node have coins to cover txfee at least
        rpc.sendtoaddress(rpc1.getnewaddress(), 1)
        rpc.sendtoaddress(rpc1.getnewaddress(), 1)
        rpc.generate(2)
        self.sync_all()
        second_node_balance = rpc1.getbalance()
        assert_greater_than(second_node_balance, 0.1)

        # let's claim whole heir sum from second node
        result = rpc1.heirclaim("0", "1000", heir_fund_txid)
        assert_success(result)

        heir_claim_txid = self.send_and_mine(result["hex"], rpc1)
        assert heir_claim_txid, "got claim txid"

        # balance of second node after heirclaim should increase for 1000 coins - txfees
        # + get one block reward when broadcasted heir_claim_txid
        result = round(rpc1.getbalance()) - round(second_node_balance)
        assert_greater_than(result, 100999)

        self.sync_all()

        # no more funds should be available for claiming
        result = rpc.heirinfo(heir_fund_txid)
        assert_equal(result["lifetime"], "1000.00000000")
        assert_equal(result["available"], "0.00000000")

        # creating tokens which we put to heir contract
        token_hex = rpc.tokencreate("TEST", "1", "TESTING")
        token_txid = self.send_and_mine(token_hex["hex"], rpc)
        assert token_txid, "got token txid"

        # checking possesion over the tokens and balance
        result = rpc.tokenbalance(token_txid, self.pubkey)["balance"]
        assert_equal(result, 100000000)

        # valid heir case with tokens
        token_heir_hex = rpc.heirfund("0", "100000000", "UNITHEIR", self.pubkey1, "10", "TESTMEMO", token_txid)
        token_heir_txid = self.send_and_mine(token_heir_hex["hex"], rpc)
        assert token_heir_txid, "got txid of heirfund with tokens"

        self.sync_all()

        # checking heirinfo
        result = rpc.heirinfo(token_heir_txid)
        assert_success(result)
        assert_equal(result["fundingtxid"], token_heir_txid)
        assert_equal(result["name"], "UNITHEIR")
        assert_equal(result["owner"], self.pubkey)
        assert_equal(result["heir"], self.pubkey1)
        assert_equal(result["lifetime"], "100000000")
        assert_equal(result["type"], "tokens")
        assert_equal(result["InactivityTimeSetting"], "10")
        assert_equal(result["InactivityTime"], "0")
        assert_equal(result["IsHeirSpendingAllowed"], "false")

        # waiting for 11 seconds to be sure that needed time passed for heir claiming
        time.sleep(11)
        rpc.generate(1)
        self.sync_all()
        result = rpc.heirinfo(token_heir_txid)
        assert_equal(result["lifetime"], "100000000")
        assert_equal(result["IsHeirSpendingAllowed"], "true")

        # let's claim whole heir sum from second node
        result = rpc1.heirclaim("0", "100000000", token_heir_txid)
        assert_success(result)

        heir_tokens_claim_txid = self.send_and_mine(result["hex"], rpc1)
        assert heir_tokens_claim_txid, "got claim txid"

        # claiming node should have correct token balance now
        result = rpc1.tokenbalance(token_txid, self.pubkey1)["balance"]
        assert_equal(result, 100000000)

        self.sync_all()

        # no more funds should be available for claiming
        result = rpc.heirinfo(token_heir_txid)
        assert_equal(result["lifetime"], "100000000")
        assert_equal(result["available"], "0")
Exemple #7
0
    def run_gateways_tests(self):
        rpc = self.nodes[0]
        rpc1 = self.nodes[1]

        result = rpc.gatewaysaddress()
        assert_success(result)

        for x in result.keys():
            if x.find('ddress') > 0:
                assert_equal(result[x][0], 'R')

        assert_equal("03ea9c062b9652d8eff34879b504eda0717895d27597aaeb60347d65eed96ccb40", result["GatewaysPubkey"])

        # getting an empty gateways list

        result = rpc.gatewayslist()
        assert_equal(result, [])

        # Gateways binding preparation

        # creating oracle
        oracle_hex = rpc.oraclescreate("Test", "Testing", "Ihh")
        assert_success(oracle_hex)
        oracle_txid = self.send_and_mine(oracle_hex["hex"], rpc)
        assert oracle_txid, "got txid"

        # registering as an oracle publisher
        reg_hex = rpc.oraclesregister(oracle_txid, "10000")
        assert_success(reg_hex)
        reg_txid = self.send_and_mine(reg_hex["hex"], rpc)
        assert reg_txid, "got txid"

        # subscribing on oracle
        sub_hex = rpc.oraclessubscribe(oracle_txid, self.pubkey, "1")
        assert_success(sub_hex)
        sub_txid = self.send_and_mine(sub_hex["hex"], rpc)
        assert sub_txid, "got txid"

        # creating token
        token_hex = rpc.tokencreate("Test", "1", "Testing")
        assert_success(token_hex)
        token_txid = self.send_and_mine(token_hex["hex"], rpc)
        assert token_txid, "got txid"

        # converting tokens
        convertion_hex = rpc.tokenconvert("241",token_txid,"03ea9c062b9652d8eff34879b504eda0717895d27597aaeb60347d65eed96ccb40","100000000")
        assert_success(convertion_hex)
        convertion_txid = self.send_and_mine(convertion_hex["hex"], rpc)
        assert convertion_txid, "got txid"

        # binding gateway
        bind_hex = rpc.gatewaysbind(token_txid, oracle_txid, "KMD", "100000000", "1", "1", self.pubkey)
        assert_success(bind_hex)
        bind_txid = self.send_and_mine(bind_hex["hex"], rpc)
        assert bind_txid, "got txid"

        # checking if created gateway in list
        result = rpc.gatewayslist()
        assert_equal(result[0], bind_txid)
    def run_token_tests(self):

        rpc = self.nodes[0]
        rpc1 = self.nodes[1]

        result = rpc.tokenaddress()
        assert_success(result)
        for x in result.keys():
            if x.find('ddress') > 0:
                assert_equal(result[x][0], 'R')

        result = rpc.tokenaddress(self.pubkey)
        assert_success(result)
        for x in result.keys():
            if x.find('ddress') > 0:
                assert_equal(result[x][0], 'R')

        result = rpc.assetsaddress()
        assert_success(result)
        for x in result.keys():
            if x.find('ddress') > 0:
                assert_equal(result[x][0], 'R')

        result = rpc.assetsaddress(self.pubkey)
        assert_success(result)
        for x in result.keys():
            if x.find('ddress') > 0:
                assert_equal(result[x][0], 'R')

        # there are no tokens created yet
        result = rpc.tokenlist()
        assert_equal(result, [])

        # trying to create token with negative supply
        result = rpc.tokencreate("NUKE", "-1987420", "no bueno supply")
        assert_error(result)

        # creating token with name more than 32 chars
        result = rpc.tokencreate("NUKE123456789012345678901234567890",
                                 "1987420", "name too long")
        assert_error(result)

        # creating valid token
        result = rpc.tokencreate("DUKE", "1987.420", "Duke's custom token")
        assert_success(result)

        tokenid = self.send_and_mine(result['hex'], rpc)

        result = rpc.tokenlist()
        assert_equal(result[0], tokenid)

        # there are no token orders yet
        result = rpc.tokenorders(tokenid)
        assert_equal(result, [])

        # getting token balance for non existing tokenid
        result = rpc.tokenbalance(self.pubkey)
        assert_error(result)

        # get token balance for token with pubkey
        result = rpc.tokenbalance(tokenid, self.pubkey)
        assert_success(result)
        assert_equal(result['balance'], 198742000000)
        assert_equal(result['tokenid'], tokenid)

        # get token balance for token without pubkey
        result = rpc.tokenbalance(tokenid)
        assert_success(result)
        assert_equal(result['balance'], 198742000000)
        assert_equal(result['tokenid'], tokenid)

        # this is not a valid assetid
        result = rpc.tokeninfo(self.pubkey)
        assert_error(result)

        # check tokeninfo for valid token
        result = rpc.tokeninfo(tokenid)
        assert_success(result)
        assert_equal(result['tokenid'], tokenid)
        assert_equal(result['owner'], self.pubkey)
        assert_equal(result['name'], "DUKE")
        assert_equal(result['supply'], 198742000000)
        assert_equal(result['description'], "Duke's custom token")

        # invalid numtokens ask
        result = rpc.tokenask("-1", tokenid, "1")
        assert_error(result)

        # invalid numtokens ask
        result = rpc.tokenask("0", tokenid, "1")
        assert_error(result)

        # invalid price ask
        result = rpc.tokenask("1", tokenid, "-1")
        assert_error(result)

        # invalid price ask
        result = rpc.tokenask("1", tokenid, "0")
        assert_error(result)

        # invalid tokenid ask
        result = rpc.tokenask("100", "deadbeef", "1")
        assert_error(result)

        # valid ask
        tokenask = rpc.tokenask("100", tokenid, "7.77")
        tokenaskhex = tokenask['hex']
        tokenaskid = self.send_and_mine(tokenask['hex'], rpc)
        result = rpc.tokenorders(tokenid)
        order = result[0]
        assert order, "found order"

        # invalid ask fillunits
        result = rpc.tokenfillask(tokenid, tokenaskid, "0")
        assert_error(result)

        # invalid ask fillunits
        result = rpc.tokenfillask(tokenid, tokenaskid, "-777")
        assert_error(result)

        # valid ask fillunits
        fillask = rpc.tokenfillask(tokenid, tokenaskid, "777")
        result = self.send_and_mine(fillask['hex'], rpc)
        txid = result[0]
        assert txid, "found txid"

        # should be no token orders
        result = rpc.tokenorders(tokenid)
        assert_equal(result, [])

        # checking ask cancellation
        testorder = rpc.tokenask("100", tokenid, "7.77")
        testorderid = self.send_and_mine(testorder['hex'], rpc)
        # from other node (ensuring that second node have enough balance to cover txfee
        # to get the actual error - not "not enough balance" one
        rpc.sendtoaddress(rpc1.getnewaddress(), 1)
        rpc.sendtoaddress(rpc1.getnewaddress(), 1)
        rpc.generate(2)
        self.sync_all()
        result = rpc1.getbalance()
        assert_greater_than(result, 0.1)

        result = rpc1.tokencancelask(tokenid, testorderid)
        assert_error(result)

        # from valid node
        cancel = rpc.tokencancelask(tokenid, testorderid)
        self.send_and_mine(cancel["hex"], rpc)
        result = rpc.tokenorders(tokenid)
        assert_equal(result, [])

        # invalid numtokens bid
        result = rpc.tokenbid("-1", tokenid, "1")
        assert_error(result)

        # invalid numtokens bid
        result = rpc.tokenbid("0", tokenid, "1")
        assert_error(result)

        # invalid price bid
        result = rpc.tokenbid("1", tokenid, "-1")
        assert_error(result)

        # invalid price bid
        result = rpc.tokenbid("1", tokenid, "0")
        assert_error(result)

        # invalid tokenid bid
        result = rpc.tokenbid("100", "deadbeef", "1")
        assert_error(result)

        tokenbid = rpc.tokenbid("100", tokenid, "10")
        tokenbidhex = tokenbid['hex']
        tokenbidid = self.send_and_mine(tokenbid['hex'], rpc)
        result = rpc.tokenorders(tokenid)
        order = result[0]
        assert order, "found order"

        # invalid bid fillunits
        result = rpc.tokenfillbid(tokenid, tokenbidid, "0")
        assert_error(result)

        # invalid bid fillunits
        result = rpc.tokenfillbid(tokenid, tokenbidid, "-777")
        assert_error(result)

        # valid bid fillunits
        fillbid = rpc.tokenfillbid(tokenid, tokenbidid, "1000")
        result = self.send_and_mine(fillbid['hex'], rpc)
        txid = result[0]
        assert txid, "found txid"

        # should be no token orders
        result = rpc.tokenorders(tokenid)
        assert_equal(result, [])

        # checking bid cancellation
        testorder = rpc.tokenbid("100", tokenid, "7.77")
        testorderid = self.send_and_mine(testorder['hex'], rpc)

        # from other node
        result = rpc1.getbalance()
        assert_greater_than(result, 0.1)

        result = rpc1.tokencancelbid(tokenid, testorderid)
        assert_error(result)

        # from valid node
        cancel = rpc.tokencancelbid(tokenid, testorderid)
        self.send_and_mine(cancel["hex"], rpc)
        result = rpc.tokenorders(tokenid)
        assert_equal(result, [])

        # invalid token transfer amount (have to add status to CC code!)
        randompubkey = "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96"
        result = rpc.tokentransfer(tokenid, randompubkey, "0")
        assert_error(result)

        # invalid token transfer amount (have to add status to CC code!)
        result = rpc.tokentransfer(tokenid, randompubkey, "-1")
        assert_error(result)

        # valid token transfer
        sendtokens = rpc.tokentransfer(tokenid, randompubkey, "1")
        self.send_and_mine(sendtokens["hex"], rpc)
        result = rpc.tokenbalance(tokenid, randompubkey)
        assert_equal(result["balance"], 1)
    def run_token_tests(self):
        rpc = self.nodes[0]
        result = rpc.tokenaddress()
        assert_success(result)
        for x in [
                'AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress'
        ]:
            assert_equal(result[x][0], 'R')

        result = rpc.tokenaddress(self.pubkey)
        assert_success(result)
        for x in [
                'AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress',
                'CCaddress'
        ]:
            assert_equal(result[x][0], 'R')
        # there are no tokens created yet
        result = rpc.tokenlist()
        assert_equal(result, [])

        # trying to create token with negaive supply
        result = rpc.tokencreate("NUKE", "-1987420", "no bueno supply")
        assert_error(result)

        # creating token with name more than 32 chars
        result = rpc.tokencreate("NUKE123456789012345678901234567890",
                                 "1987420", "name too long")
        assert_error(result)

        # creating valid token
        result = rpc.tokencreate("DUKE", "1987.420", "Duke's custom token")
        assert_success(result)

        tokenid = self.send_and_mine(result['hex'], rpc)

        result = rpc.tokenlist()
        assert_equal(result[0], tokenid)

        # there are no token orders yet
        result = rpc.tokenorders()
        assert_equal(result, [])

        # getting token balance for pubkey
        result = rpc.tokenbalance(self.pubkey)
        assert_success(result)
        assert_equal(result['balance'], 0)
        assert_equal(result['CCaddress'], 'RCRsm3VBXz8kKTsYaXKpy7pSEzrtNNQGJC')
        assert_equal(result['tokenid'], self.pubkey)

        # get token balance for token with pubkey
        result = rpc.tokenbalance(tokenid, self.pubkey)
        assert_success(result)
        assert_equal(result['balance'], 198742000000)
        assert_equal(result['tokenid'], tokenid)

        # get token balance for token without pubkey
        result = rpc.tokenbalance(tokenid)
        assert_success(result)
        assert_equal(result['balance'], 198742000000)
        assert_equal(result['tokenid'], tokenid)

        # this is not a valid assetid
        result = rpc.tokeninfo(self.pubkey)
        assert_error(result)

        # check tokeninfo for valid token
        result = rpc.tokeninfo(tokenid)
        assert_success(result)
        assert_equal(result['tokenid'], tokenid)
        assert_equal(result['owner'], self.pubkey)
        assert_equal(result['name'], "DUKE")
        assert_equal(result['supply'], 198742000000)
        assert_equal(result['description'], "Duke's custom token")

        # invalid numtokens ask
        result = rpc.tokenask("-1", tokenid, "1")
        assert_error(result)

        # invalid numtokens ask
        result = rpc.tokenask("0", tokenid, "1")
        assert_error(result)

        # invalid price ask
        result = rpc.tokenask("1", tokenid, "-1")
        assert_error(result)

        # invalid price ask
        result = rpc.tokenask("1", tokenid, "0")
        assert_error(result)

        # invalid tokenid ask
        result = rpc.tokenask("100", "deadbeef", "1")
        assert_error(result)

        # valid ask
        tokenask = rpc.tokenask("100", tokenid, "7.77")
        tokenaskhex = tokenask['hex']
        tokenaskid = self.send_and_mine(tokenask['hex'], rpc)
        result = rpc.tokenorders()
        order = result[0]
        assert order, "found order"

        # invalid ask fillunits
        result = rpc.tokenfillask(tokenid, tokenaskid, "0")
        assert_error(result)

        # invalid ask fillunits
        result = rpc.tokenfillask(tokenid, tokenaskid, "-777")
        assert_error(result)

        # valid ask fillunits
        fillask = rpc.tokenfillask(tokenid, tokenaskid, "777")
        result = self.send_and_mine(fillask['hex'], rpc)
        txid = result[0]
        assert txid, "found txid"

        # should be no token orders
        result = rpc.tokenorders()
        assert_equal(result, [])

        # checking ask cancellation
        testorder = rpc.tokenask("100", tokenid, "7.77")
        testorderid = self.send_and_mine(testorder['hex'], rpc)
        cancel = rpc.tokencancelask(tokenid, testorderid)
        self.send_and_mine(cancel["hex"], rpc)
        result = rpc.tokenorders()
        assert_equal(result, [])

        # invalid numtokens bid
        result = rpc.tokenbid("-1", tokenid, "1")
        assert_error(result)

        # invalid numtokens bid
        result = rpc.tokenbid("0", tokenid, "1")
        assert_error(result)

        # invalid price bid
        result = rpc.tokenbid("1", tokenid, "-1")
        assert_error(result)

        # invalid price bid
        result = rpc.tokenbid("1", tokenid, "0")
        assert_error(result)

        # invalid tokenid bid
        result = rpc.tokenbid("100", "deadbeef", "1")
        assert_error(result)

        tokenbid = rpc.tokenbid("100", tokenid, "10")
        tokenbidhex = tokenbid['hex']
        tokenbidid = self.send_and_mine(tokenbid['hex'], rpc)
        result = rpc.tokenorders()
        order = result[0]
        assert order, "found order"

        # invalid bid fillunits
        result = rpc.tokenfillbid(tokenid, tokenbidid, "0")
        assert_error(result)

        # invalid bid fillunits
        result = rpc.tokenfillbid(tokenid, tokenbidid, "-777")
        assert_error(result)

        # valid bid fillunits
        fillbid = rpc.tokenfillbid(tokenid, tokenbidid, "1000")
        result = self.send_and_mine(fillbid['hex'], rpc)
        txid = result[0]
        assert txid, "found txid"

        # should be no token orders
        result = rpc.tokenorders()
        assert_equal(result, [])

        # checking bid cancellation
        testorder = rpc.tokenbid("100", tokenid, "7.77")
        testorderid = self.send_and_mine(testorder['hex'], rpc)
        cancel = rpc.tokencancelbid(tokenid, testorderid)
        self.send_and_mine(cancel["hex"], rpc)
        result = rpc.tokenorders()
        assert_equal(result, [])

        # invalid token transfer amount (have to add status to CC code!)
        randompubkey = "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96"
        result = rpc.tokentransfer(tokenid, randompubkey, "0")
        assert_error(result)

        # invalid token transfer amount (have to add status to CC code!)
        result = rpc.tokentransfer(tokenid, randompubkey, "-1")
        assert_error(result)

        # valid token transfer
        sendtokens = rpc.tokentransfer(tokenid, randompubkey, "1")
        self.send_and_mine(sendtokens["hex"], rpc)
        result = rpc.tokenbalance(tokenid, randompubkey)
        assert_equal(result["balance"], 1)
    def run_gateways_tests(self):
        rpc = self.nodes[0]
        rpc1 = self.nodes[1]

        result = rpc.gatewaysaddress()
        assert_success(result)
        for x in ['GatewaysCCaddress', 'myCCaddress', 'Gatewaysmarker', 'myaddress']:
            assert_equal(result[x][0], 'R')

        assert_equal("03ea9c062b9652d8eff34879b504eda0717895d27597aaeb60347d65eed96ccb40", result["GatewaysPubkey"])

        # getting an empty gateways list

        result = rpc.gatewayslist()
        assert_equal(result, [])

        # Gateways binding preparation

        # creating oracle
        oracle_hex = rpc.oraclescreate("Test", "Testing", "Ihh")
        assert_success(oracle_hex)
        oracle_txid = self.send_and_mine(oracle_hex["hex"], rpc)
        assert oracle_txid, "got txid"

        # registering as an oracle publisher
        reg_hex = rpc.oraclesregister(oracle_txid, "10000")
        assert_success(reg_hex)
        reg_txid = self.send_and_mine(reg_hex["hex"], rpc)
        assert reg_txid, "got txid"

        # subscribing on oracle
        sub_hex = rpc.oraclessubscribe(oracle_txid, self.pubkey, "1")
        assert_success(sub_hex)
        sub_txid = self.send_and_mine(sub_hex["hex"], rpc)
        assert sub_txid, "got txid"

        # creating token
        token_hex = rpc.tokencreate("Test", "1", "Testing")
        assert_success(token_hex)
        token_txid = self.send_and_mine(token_hex["hex"], rpc)
        assert token_txid, "got txid"

        # converting tokens
        convertion_hex = rpc.tokenconvert("241",token_txid,"03ea9c062b9652d8eff34879b504eda0717895d27597aaeb60347d65eed96ccb40","100000000")
        assert_success(convertion_hex)
        convertion_txid = self.send_and_mine(convertion_hex["hex"], rpc)
        assert convertion_txid, "got txid"

        # binding gateway
        bind_hex = rpc.gatewaysbind(token_txid, oracle_txid, "KMD", "100000000", "1", "1", self.pubkey)
        assert_success(bind_hex)
        bind_txid = self.send_and_mine(bind_hex["hex"], rpc)
        assert bind_txid, "got txid"

        # checking if created gateway in list
        result = rpc.gatewayslist()
        assert_equal(result[0], bind_txid)
    def run_oracles_tests(self):
        rpc = self.nodes[0]
        rpc1 = self.nodes[1]
        result = rpc1.oraclesaddress()

        result = rpc.oraclesaddress()
        assert_success(result)

        for x in result.keys():
            if x.find('ddress') > 0:
                assert_equal(result[x][0], 'R')

        result = rpc.oraclesaddress(self.pubkey)
        assert_success(result)

        for x in result.keys():
            if x.find('ddress') > 0:
                assert_equal(result[x][0], 'R')

        # there are no oracles created yet
        result = rpc.oracleslist()
        assert_equal(result, [])

        # looking up non-existent oracle should return error.
        result = rpc.oraclesinfo("none")
        assert_error(result)

        # attempt to create oracle with not valid data type should return error
        result = rpc.oraclescreate("Test", "Test", "Test")
        assert_error(result)

        # attempt to create oracle with description > 32 symbols should return error
        too_long_name = generate_random_string(33)
        result = rpc.oraclescreate(too_long_name, "Test", "s")

        # attempt to create oracle with description > 4096 symbols should return error
        too_long_description = generate_random_string(4100)
        result = rpc.oraclescreate("Test", too_long_description, "s")
        assert_error(result)

        # need uxtos to create oracle? Crashes if without generate
        rpc.generate(2)

        # valid creating oracles of different types
        # using such naming to re-use it for data publishing / reading (e.g. oracle_s for s type)

        valid_formats = ["s", "S", "d", "D", "c", "C", "t", "T", "i", "I", "l", "L", "h", "Ihh"]
        for f in valid_formats:
            result = rpc.oraclescreate("Test_"+f, "Test_"+f, f)
            assert_success(result)
            globals()["oracle_{}".format(f)] = self.send_and_mine(result['hex'], rpc)

        # trying to register with negative datafee
            result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "-100")
            assert_error(result)

        # trying to register with zero datafee
            result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "0")
            assert_error(result)

        # trying to register with datafee less than txfee
            result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "500")
            assert_error(result)

        # trying to register valid (unfunded)
            result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "10000")
            assert_error(result)

        # Fund the oracles
            result = rpc.oraclesfund(globals()["oracle_{}".format(f)])
            assert_success(result)
            fund_txid = self.send_and_mine(result["hex"], rpc)
            assert fund_txid, "got txid"

        # trying to register valid (funded)
            result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "10000")
            print(f)
            assert_success(result)
            register_txid = self.send_and_mine(result["hex"], rpc)
            assert register_txid, "got txid"

        # TODO: for most of the non valid oraclesregister and oraclessubscribe transactions generating and broadcasting now
        # so trying only valid oraclessubscribe atm
            result = rpc.oraclessubscribe(globals()["oracle_{}".format(f)], self.pubkey, "1")
            assert_success(result)
            subscribe_txid = self.send_and_mine(result["hex"], rpc)
            assert register_txid, "got txid"

            rpc.generate(1)

        # now lets publish and read valid data for each oracle type

        # s type
        result = rpc.oraclesdata(globals()["oracle_{}".format("s")], "05416e746f6e")
        assert_success(result)
        oraclesdata_s = self.send_and_mine(result["hex"], rpc)        
        info = rpc.oraclesinfo(globals()["oracle_{}".format("s")])
        batonaddr = info['registered'][0]['baton']
        result = rpc.oraclessamples(globals()["oracle_{}".format("s")], batonaddr, "1")
        assert_equal("[u'Anton']", str(result["samples"][0]['data']), "Data match")

        # S type
        result = rpc.oraclesdata(globals()["oracle_{}".format("S")], "000161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161")
        assert_success(result)
        oraclesdata_S = self.send_and_mine(result["hex"], rpc)
        info = rpc.oraclesinfo(globals()["oracle_{}".format("S")])
        batonaddr = info['registered'][0]['baton']
        result = rpc.oraclessamples(globals()["oracle_{}".format("S")], batonaddr, "1")
        assert_equal("[u'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa']", str(result["samples"][0]['data']), "Data match")

        # d type
        result = rpc.oraclesdata(globals()["oracle_{}".format("d")], "0101")
        assert_success(result)
        # baton
        oraclesdata_d = self.send_and_mine(result["hex"], rpc)
        info = rpc.oraclesinfo(globals()["oracle_{}".format("d")])
        batonaddr = info['registered'][0]['baton']
        result = rpc.oraclessamples(globals()["oracle_{}".format("d")], batonaddr, "1")
        assert_equal("[u'01']", str(result["samples"][0]['data']), "Data match")

        # D type
        result = rpc.oraclesdata(globals()["oracle_{}".format("D")], "010001")
        assert_success(result)
        # baton
        oraclesdata_D = self.send_and_mine(result["hex"], rpc)
        info = rpc.oraclesinfo(globals()["oracle_{}".format("D")])
        batonaddr = info['registered'][0]['baton']
        result = rpc.oraclessamples(globals()["oracle_{}".format("D")], batonaddr, "1")
        assert_equal("[u'01']", str(result["samples"][0]['data']), "Data match")

        # c type
        result = rpc.oraclesdata(globals()["oracle_{}".format("c")], "ff")
        assert_success(result)
        # baton
        oraclesdata_c = self.send_and_mine(result["hex"], rpc)
        info = rpc.oraclesinfo(globals()["oracle_{}".format("c")])
        batonaddr = info['registered'][0]['baton']
        result = rpc.oraclessamples(globals()["oracle_{}".format("c")], batonaddr, "1")
        assert_equal("[u'-1']", str(result["samples"][0]['data']), "Data match")

        # C type
        result = rpc.oraclesdata(globals()["oracle_{}".format("C")], "ff")
        assert_success(result)
        # baton
        oraclesdata_C = self.send_and_mine(result["hex"], rpc)
        info = rpc.oraclesinfo(globals()["oracle_{}".format("C")])
        batonaddr = info['registered'][0]['baton']
        result = rpc.oraclessamples(globals()["oracle_{}".format("C")], batonaddr, "1")
        assert_equal("[u'255']", str(result["samples"][0]['data']), "Data match")

        # t type
        result = rpc.oraclesdata(globals()["oracle_{}".format("t")], "ffff")
        assert_success(result)
        # baton
        oraclesdata_t = self.send_and_mine(result["hex"], rpc)
        info = rpc.oraclesinfo(globals()["oracle_{}".format("t")])
        batonaddr = info['registered'][0]['baton']
        result = rpc.oraclessamples(globals()["oracle_{}".format("t")], batonaddr, "1")
        assert_equal("[u'-1']", str(result["samples"][0]['data']), "Data match")

        # T type
        result = rpc.oraclesdata(globals()["oracle_{}".format("T")], "ffff")
        assert_success(result)
        # baton
        oraclesdata_T = self.send_and_mine(result["hex"], rpc)
        info = rpc.oraclesinfo(globals()["oracle_{}".format("T")])
        batonaddr = info['registered'][0]['baton']
        result = rpc.oraclessamples(globals()["oracle_{}".format("T")], batonaddr, "1")
        assert_equal("[u'65535']", str(result["samples"][0]['data']), "Data match")

        # i type
        result = rpc.oraclesdata(globals()["oracle_{}".format("i")], "ffffffff")
        assert_success(result)
        # baton
        oraclesdata_i = self.send_and_mine(result["hex"], rpc)
        info = rpc.oraclesinfo(globals()["oracle_{}".format("i")])
        batonaddr = info['registered'][0]['baton']
        result = rpc.oraclessamples(globals()["oracle_{}".format("i")], batonaddr, "1")
        assert_equal("[u'-1']", str(result["samples"][0]['data']), "Data match")

        # I type
        result = rpc.oraclesdata(globals()["oracle_{}".format("I")], "ffffffff")
        assert_success(result)
        # baton
        oraclesdata_I = self.send_and_mine(result["hex"], rpc)
        info = rpc.oraclesinfo(globals()["oracle_{}".format("I")])
        batonaddr = info['registered'][0]['baton']
        result = rpc.oraclessamples(globals()["oracle_{}".format("I")], batonaddr, "1")
        assert_equal("[u'4294967295']", str(result["samples"][0]['data']), "Data match")

        # l type
        result = rpc.oraclesdata(globals()["oracle_{}".format("l")], "00000000ffffffff")
        assert_success(result)
        # baton
        oraclesdata_l = self.send_and_mine(result["hex"], rpc)
        info = rpc.oraclesinfo(globals()["oracle_{}".format("l")])
        batonaddr = info['registered'][0]['baton']
        result = rpc.oraclessamples(globals()["oracle_{}".format("l")], batonaddr, "1")
        assert_equal("[u'-4294967296']", str(result["samples"][0]['data']), "Data match")

        # L type
        result = rpc.oraclesdata(globals()["oracle_{}".format("L")], "00000000ffffffff")
        assert_success(result)
        # baton
        oraclesdata_L = self.send_and_mine(result["hex"], rpc)
        info = rpc.oraclesinfo(globals()["oracle_{}".format("L")])
        batonaddr = info['registered'][0]['baton']
        result = rpc.oraclessamples(globals()["oracle_{}".format("L")], batonaddr, "1")
        assert_equal("[u'18446744069414584320']", str(result["samples"][0]['data']), "Data match")

        # h type
        result = rpc.oraclesdata(globals()["oracle_{}".format("h")], "00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff")
        assert_success(result)
        # baton
        oraclesdata_h = self.send_and_mine(result["hex"], rpc)
        info = rpc.oraclesinfo(globals()["oracle_{}".format("h")])
        batonaddr = info['registered'][0]['baton']
        result = rpc.oraclessamples(globals()["oracle_{}".format("h")], batonaddr, "1")
        assert_equal("[u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000']", str(result["samples"][0]['data']), "Data match")

        # Ihh type
        result = rpc.oraclesdata(globals()["oracle_{}".format("Ihh")], "ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff")
        assert_success(result)
        # baton
        oraclesdata_Ihh = self.send_and_mine(result["hex"], rpc)
        info = rpc.oraclesinfo(globals()["oracle_{}".format("Ihh")])
        batonaddr = info['registered'][0]['baton']
        result = rpc.oraclessamples(globals()["oracle_{}".format("Ihh")], batonaddr, "1")
        print(result)
        assert_equal("[u'4294967295', u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000', u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000']", str(result["samples"][0]['data']), "Data match")
    def run_token_tests(self):
        rpc    = self.nodes[0]
        result = rpc.tokenaddress()
        assert_success(result)
        for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress']:
            assert_equal(result[x][0], 'R')

        result = rpc.tokenaddress(self.pubkey)
        assert_success(result)
        for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress', 'CCaddress']:
            assert_equal(result[x][0], 'R')
        # there are no tokens created yet
        result = rpc.tokenlist()
        assert_equal(result, [])

        # trying to create token with negaive supply
        result = rpc.tokencreate("NUKE", "-1987420", "no bueno supply")
        assert_error(result)

        # creating token with name more than 32 chars
        result = rpc.tokencreate("NUKE123456789012345678901234567890", "1987420", "name too long")
        assert_error(result)

        # creating valid token
        result = rpc.tokencreate("DUKE", "1987.420", "Duke's custom token")
        assert_success(result)

        tokenid = self.send_and_mine(result['hex'], rpc)

        result = rpc.tokenlist()
        assert_equal(result[0], tokenid)

        # there are no token orders yet
        result = rpc.tokenorders()
        assert_equal(result, [])

        # getting token balance for pubkey
        result = rpc.tokenbalance(self.pubkey)
        assert_success(result)
        assert_equal(result['balance'], 0)
        assert_equal(result['CCaddress'], 'RCRsm3VBXz8kKTsYaXKpy7pSEzrtNNQGJC')
        assert_equal(result['tokenid'], self.pubkey)

        # get token balance for token with pubkey
        result = rpc.tokenbalance(tokenid, self.pubkey)
        assert_success(result)
        assert_equal(result['balance'], 198742000000)
        assert_equal(result['tokenid'], tokenid)

        # get token balance for token without pubkey
        result = rpc.tokenbalance(tokenid)
        assert_success(result)
        assert_equal(result['balance'], 198742000000)
        assert_equal(result['tokenid'], tokenid)

        # this is not a valid assetid
        result = rpc.tokeninfo(self.pubkey)
        assert_error(result)

        # check tokeninfo for valid token
        result = rpc.tokeninfo(tokenid)
        assert_success(result)
        assert_equal(result['tokenid'], tokenid)
        assert_equal(result['owner'], self.pubkey)
        assert_equal(result['name'], "DUKE")
        assert_equal(result['supply'], 198742000000)
        assert_equal(result['description'], "Duke's custom token")

        # invalid numtokens ask
        result = rpc.tokenask("-1", tokenid, "1")
        assert_error(result)

        # invalid numtokens ask
        result = rpc.tokenask("0", tokenid, "1")
        assert_error(result)

        # invalid price ask
        result = rpc.tokenask("1", tokenid, "-1")
        assert_error(result)

        # invalid price ask
        result = rpc.tokenask("1", tokenid, "0")
        assert_error(result)

        # invalid tokenid ask
        result = rpc.tokenask("100", "deadbeef", "1")
        assert_error(result)

        # valid ask
        tokenask = rpc.tokenask("100", tokenid, "7.77")
        tokenaskhex = tokenask['hex']
        tokenaskid = self.send_and_mine(tokenask['hex'], rpc)
        result = rpc.tokenorders()
        order = result[0]
        assert order, "found order"

        # invalid ask fillunits
        result = rpc.tokenfillask(tokenid, tokenaskid, "0")
        assert_error(result)

        # invalid ask fillunits
        result = rpc.tokenfillask(tokenid, tokenaskid, "-777")
        assert_error(result)

        # valid ask fillunits
        fillask = rpc.tokenfillask(tokenid, tokenaskid, "777")
        result = self.send_and_mine(fillask['hex'], rpc)
        txid   = result[0]
        assert txid, "found txid"

        # should be no token orders
        result = rpc.tokenorders()
        assert_equal(result, [])

        # checking ask cancellation
        testorder = rpc.tokenask("100", tokenid, "7.77")
        testorderid = self.send_and_mine(testorder['hex'], rpc)
        cancel = rpc.tokencancelask(tokenid, testorderid)
        self.send_and_mine(cancel["hex"], rpc)
        result = rpc.tokenorders()
        assert_equal(result, [])

        # invalid numtokens bid
        result = rpc.tokenbid("-1", tokenid, "1")
        assert_error(result)

        # invalid numtokens bid
        result = rpc.tokenbid("0", tokenid, "1")
        assert_error(result)

        # invalid price bid
        result = rpc.tokenbid("1", tokenid, "-1")
        assert_error(result)

        # invalid price bid
        result = rpc.tokenbid("1", tokenid, "0")
        assert_error(result)

        # invalid tokenid bid
        result = rpc.tokenbid("100", "deadbeef", "1")
        assert_error(result)

        tokenbid = rpc.tokenbid("100", tokenid, "10")
        tokenbidhex = tokenbid['hex']
        tokenbidid = self.send_and_mine(tokenbid['hex'], rpc)
        result = rpc.tokenorders()
        order = result[0]
        assert order, "found order"

        # invalid bid fillunits
        result = rpc.tokenfillbid(tokenid, tokenbidid, "0")
        assert_error(result)

        # invalid bid fillunits
        result = rpc.tokenfillbid(tokenid, tokenbidid, "-777")
        assert_error(result)

        # valid bid fillunits
        fillbid = rpc.tokenfillbid(tokenid, tokenbidid, "1000")
        result = self.send_and_mine(fillbid['hex'], rpc)
        txid   = result[0]
        assert txid, "found txid"

        # should be no token orders
        result = rpc.tokenorders()
        assert_equal(result, [])

        # checking bid cancellation
        testorder = rpc.tokenbid("100", tokenid, "7.77")
        testorderid = self.send_and_mine(testorder['hex'], rpc)
        cancel = rpc.tokencancelbid(tokenid, testorderid)
        self.send_and_mine(cancel["hex"], rpc)
        result = rpc.tokenorders()
        assert_equal(result, [])

        # invalid token transfer amount (have to add status to CC code!)
        randompubkey = "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96"
        result = rpc.tokentransfer(tokenid,randompubkey,"0")
        assert_error(result)

        # invalid token transfer amount (have to add status to CC code!)
        result = rpc.tokentransfer(tokenid,randompubkey,"-1")
        assert_error(result)

        # valid token transfer
        sendtokens = rpc.tokentransfer(tokenid,randompubkey,"1")
        self.send_and_mine(sendtokens["hex"], rpc)
        result = rpc.tokenbalance(tokenid,randompubkey)
        assert_equal(result["balance"], 1)
    def run_dice_tests(self):
        rpc     = self.nodes[0]
        rpc1    = self.nodes[1]
        self.sync_all()

        # have to generate few blocks on second node to be able to place bets
        rpc1.generate(10)
        result = rpc1.getbalance()
        assert_greater_than(result, 100000)

        dice  = rpc.diceaddress()
        assert_equal(dice['result'], 'success')
        for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress']:
            assert_equal(dice[x][0], 'R')

        dice  = rpc.diceaddress(self.pubkey)
        assert_equal(dice['result'], 'success')
        for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress', 'CCaddress']:
            assert_equal(dice[x][0], 'R')

        # no dice created yet
        result  = rpc.dicelist()
        assert_equal(result, [])

        # creating dice plan with too long name (>8 chars)
        result = rpc.dicefund("THISISTOOLONG", "10000", "10", "10000", "10", "5")
        assert_error(result)

        # creating dice plan with < 100 funding
        result = rpc.dicefund("LUCKY","10","1","10000","10","5")
        assert_error(result)

        # creating dice plan with 0 blocks timeout
        result = rpc.dicefund("LUCKY","10","1","10000","10","0")
        assert_error(result)

        # creating dice plan
        dicefundtx  = rpc.dicefund("LUCKY","1000","1","800","10","5")
        diceid = self.send_and_mine(dicefundtx['hex'], rpc)

        # checking if it in plans list now
        result = rpc.dicelist()
        assert_equal(result[0], diceid)

        # set dice name for futher usage
        dicename = "LUCKY"

        # adding zero funds to plan
        result = rpc.diceaddfunds(dicename,diceid,"0")
        assert_error(result)

        # adding negative funds to plan
        result = rpc.diceaddfunds(dicename,diceid,"-1")
        assert_error(result)

        # adding funds to plan
        addfundstx = rpc.diceaddfunds(dicename,diceid,"1100")
        result = self.send_and_mine(addfundstx['hex'], rpc)

        # checking if funds added to plan
        result = rpc.diceinfo(diceid)
        assert_equal(result["funding"], "2100.00000000")

        # not valid dice info checking
        result = rpc.diceinfo("invalid")
        assert_error(result)

        # placing 0 amount bet
        result = rpc1.dicebet(dicename,diceid,"0","2")
        assert_error(result)

        # placing negative amount bet
        result = rpc1.dicebet(dicename,diceid,"-1","2")
        assert_error(result)

        # placing bet more than maxbet
        result = rpc1.dicebet(dicename,diceid,"900","2")
        assert_error(result)

        # placing bet with amount more than funding
        result = rpc1.dicebet(dicename,diceid,"3000","2")
        assert_error(result)

        # placing bet with potential won more than funding
        result = rpc1.dicebet(dicename,diceid,"750","9")
        assert_error(result)

        # placing 0 odds bet
        result = rpc1.dicebet(dicename,diceid,"1","0")
        assert_error(result)

        # placing negative odds bet
        result = rpc1.dicebet(dicename,diceid,"1","-1")
        assert_error(result)

        # placing bet with odds more than allowed
        result = rpc1.dicebet(dicename,diceid,"1","11")
        assert_error(result)

        # placing bet with not correct dice name
        result = rpc1.dicebet("nope",diceid,"100","2")
        assert_error(result)

        # placing bet with not correct dice id
        result = rpc1.dicebet(dicename,self.pubkey,"100","2")
        assert_error(result)

        # have to make some entropy for the next test
        entropytx = 0
        fundingsum = 1
        while entropytx < 110:
             fundingsuminput = str(fundingsum)
             fundinghex = rpc.diceaddfunds(dicename,diceid,fundingsuminput)
             result = self.send_and_mine(fundinghex['hex'], rpc)
             entropytx = entropytx + 1
             fundingsum = fundingsum + 1

        rpc.generate(2)
        self.sync_all()

        # valid bet placing
        placebet = rpc1.dicebet(dicename,diceid,"100","2")
        betid = self.send_and_mine(placebet["hex"], rpc1)
        assert result, "bet placed"

        # check bet status
        result = rpc1.dicestatus(dicename,diceid,betid)
        assert_success(result)

        # note initial dice funding state at this point.
        # TODO: track player balance somehow (hard to do because of mining and fees)
        diceinfo = rpc.diceinfo(diceid)
        funding = float(diceinfo['funding'])
    def run_rewards_tests(self):
        rpc = self.nodes[0]
        result = rpc.rewardsaddress()
        for x in ['RewardsCCaddress', 'myCCaddress', 'Rewardsmarker', 'myaddress']:
            assert_equal(result[x][0], 'R')

        result = rpc.rewardsaddress(self.pubkey)
        for x in ['RewardsCCaddress', 'myCCaddress', 'Rewardsmarker', 'myaddress', 'CCaddress']:
            assert_equal(result[x][0], 'R')

        # no rewards yet
        result = rpc.rewardslist()
        assert_equal(result, [])

        # looking up non-existent reward should return error
        result = rpc.rewardsinfo("none")
        assert_error(result)

        # creating rewards plan with name > 8 chars, should return error
        result = rpc.rewardscreatefunding("STUFFSTUFF", "7777", "25", "0", "10", "10")
        assert_error(result)

        # creating rewards plan with 0 funding
        result = rpc.rewardscreatefunding("STUFF", "0", "25", "0", "10", "10")
        assert_error(result)

        # creating rewards plan with 0 maxdays
        result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10", "0")
        assert_error(result)

        # creating rewards plan with > 25% APR
        result = rpc.rewardscreatefunding("STUFF", "7777", "30", "0", "10", "10")
        assert_error(result)

        # creating valid rewards plan
        result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10", "10")
        assert result['hex'], 'got raw xtn'
        fundingtxid = rpc.sendrawtransaction(result['hex'])
        assert fundingtxid, 'got txid'

        # confirm the above xtn
        rpc.generate(1)
        result = rpc.rewardsinfo(fundingtxid)
        assert_success(result)
        assert_equal(result['name'], 'STUFF')
        assert_equal(result['APR'], "25.00000000")
        assert_equal(result['minseconds'], 0)
        assert_equal(result['maxseconds'], 864000)
        assert_equal(result['funding'], "7777.00000000")
        assert_equal(result['mindeposit'], "10.00000000")
        assert_equal(result['fundingtxid'], fundingtxid)

        # checking if new plan in rewardslist
        result = rpc.rewardslist()
        assert_equal(result[0], fundingtxid)

        # creating reward plan with already existing name, should return error
        result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10", "10")
        assert_error(result)

        # add funding amount must be positive
        result = rpc.rewardsaddfunding("STUFF", fundingtxid, "-1")
        assert_error(result)

        # add funding amount must be positive
        result = rpc.rewardsaddfunding("STUFF", fundingtxid, "0")
        assert_error(result)

        # adding valid funding
        result = rpc.rewardsaddfunding("STUFF", fundingtxid, "555")
        addfundingtxid = self.send_and_mine(result['hex'], rpc)
        assert addfundingtxid, 'got funding txid'

        # checking if funding added to rewardsplan
        result = rpc.rewardsinfo(fundingtxid)
        assert_equal(result['funding'], "8332.00000000")

        # trying to lock funds, locking funds amount must be positive
        result = rpc.rewardslock("STUFF", fundingtxid, "-5")
        assert_error(result)

        # trying to lock funds, locking funds amount must be positive
        result = rpc.rewardslock("STUFF", fundingtxid, "0")
        assert_error(result)

        # trying to lock less than the min amount is an error
        result = rpc.rewardslock("STUFF", fundingtxid, "7")
        assert_error(result)

        # locking funds in rewards plan
        result = rpc.rewardslock("STUFF", fundingtxid, "10")
        assert_success(result)
        locktxid = result['hex']
        assert locktxid, "got lock txid"

        # locktxid has not been broadcast yet
        result = rpc.rewardsunlock("STUFF", fundingtxid, locktxid)
        assert_error(result)

        # broadcast xtn
        txid = rpc.sendrawtransaction(locktxid)
        assert txid, 'got txid from sendrawtransaction'

        # confirm the xtn above
        rpc.generate(1)

        # will not unlock since reward amount is less than tx fee
        result = rpc.rewardsunlock("STUFF", fundingtxid, locktxid)
        assert_error(result)