예제 #1
0
def test_token(test_params):

    # test params inits
    rpc = test_params.get('node1').get('rpc')
    rpc1 = test_params.get('node2').get('rpc')

    pubkey = test_params.get('node1').get('pubkey')
    pubkey1 = test_params.get('node2').get('pubkey')

    is_fresh_chain = test_params.get("is_fresh_chain")

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

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

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

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

    # there are no tokens created yet
    # TODO: this test conflicts with heir test because token creating for heir
#    if is_fresh_chain:
#        result = rpc.tokenlist()
#        assert result == []

# trying to create token with negative supply
    with pytest.raises(RPCError):
        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 = send_and_mine(result['hex'], rpc)

    result = rpc.tokenlist()
    assert tokenid in result

    # there are no token orders yet
    if is_fresh_chain:
        result = rpc.tokenorders(tokenid)
        assert result == []

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

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

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

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

    # check tokeninfo for valid token
    result = rpc.tokeninfo(tokenid)
    assert_success(result)
    assert result['tokenid'] == tokenid
    assert result['owner'] == pubkey
    assert result['name'] == "DUKE"
    assert result['supply'] == 198742000000
    assert 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
    with pytest.raises(RPCError):
        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 = 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 = send_and_mine(fillask['hex'], rpc)
    txid = result[0]
    assert txid, "found txid"

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

    # checking ask cancellation
    testorder = rpc.tokenask("100", tokenid, "7.77")
    testorderid = 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)
    time.sleep(10)  # to ensure transactions are in different blocks
    rpc.sendtoaddress(rpc1.getnewaddress(), 1)
    wait_some_blocks(rpc, 2)
    result = rpc1.getbalance()
    assert result > 0.1

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

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

    # TODO: should be no ask in orders - bad test
    if is_fresh_chain:
        result = rpc.tokenorders(tokenid)
        assert 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
    with pytest.raises(RPCError):
        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 = 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 = send_and_mine(fillbid['hex'], rpc)
    txid = result[0]
    assert txid, "found txid"

    # should be no token orders
    # TODO: should be no bid in orders - bad test
    if is_fresh_chain:
        result = rpc.tokenorders(tokenid)
        assert result == []

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

    # from other node
    result = rpc1.getbalance()
    assert result > 0.1

    result = rpc1.tokencancelbid(tokenid, testorderid)
    #TODO: not throwing error now on tx generation
    #assert_error(result)

    # from valid node
    cancel = rpc.tokencancelbid(tokenid, testorderid)
    send_and_mine(cancel["hex"], rpc)
    result = rpc.tokenorders(tokenid)
    assert 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")
    send_and_mine(sendtokens["hex"], rpc)
    result = rpc.tokenbalance(tokenid, randompubkey)
    assert result["balance"] == 1
예제 #2
0
def test_rewards(test_params):

    # test params inits
    rpc = test_params.get('node1').get('rpc')
    rpc1 = test_params.get('node2').get('rpc')

    pubkey = test_params.get('node1').get('pubkey')
    pubkey1 = test_params.get('node2').get('pubkey')

    is_fresh_chain = test_params.get("is_fresh_chain")

    global proxy
    proxy = [rpc, rpc1]

    result = rpc.rewardsaddress()
    for x in result.keys():
        if x.find('ddress') > 0:
            assert result[x][0] == 'R'

    result = rpc.rewardsaddress(pubkey)
    for x in result.keys():
        if x.find('ddress') > 0:
            assert result[x][0] == 'R'

    # no rewards yet
    if is_fresh_chain:
        result = rpc.rewardslist()
        assert 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
    plan_name = generate_random_string(6)
    result = rpc.rewardscreatefunding(plan_name, "7777", "25", "0", "10", "10")
    assert result['hex'], 'got raw xtn'
    fundingtxid = send_and_mine(result['hex'], rpc)
    assert fundingtxid, 'got txid'
    result = rpc.rewardsinfo(fundingtxid)
    assert_success(result)
    assert result['name'] == plan_name
    assert result['APR'] == "25.00000000"
    assert result['minseconds'] == 0
    assert result['maxseconds'] == 864000
    assert result['funding'] == "7777.00000000"
    assert result['mindeposit'] == "10.00000000"
    assert result['fundingtxid'] == fundingtxid

    # checking if new plan in rewardslist
    result = rpc.rewardslist()
    assert fundingtxid in result

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

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

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

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

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

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

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

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

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

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

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

    # confirm the xtn above
    wait_some_blocks(rpc, 1)

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

    # test params inits
    with open('test_config.json', 'r') as f:
        params_dict = json.load(f)

    node1_params = params_dict["node1"]
    node2_params = params_dict["node2"]

    rpc = rpc_connect(node1_params["rpc_user"], node1_params["rpc_password"],
                      node1_params["rpc_ip"], node1_params["rpc_port"])
    rpc1 = rpc_connect(node2_params["rpc_user"], node2_params["rpc_password"],
                       node2_params["rpc_ip"], node2_params["rpc_port"])
    pubkey = node1_params["pubkey"]
    pubkey1 = node2_params["pubkey"]

    is_fresh_chain = params_dict["is_fresh_chain"]

    result = rpc.rewardsaddress()
    for x in result.keys():
        if x.find('ddress') > 0:
            assert result[x][0] == 'R'

    result = rpc.rewardsaddress(pubkey)
    for x in result.keys():
        if x.find('ddress') > 0:
            assert result[x][0] == 'R'

    # no rewards yet
    if is_fresh_chain:
        result = rpc.rewardslist()
        assert 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
    plan_name = generate_random_string(6)
    result = rpc.rewardscreatefunding(plan_name, "7777", "25", "0", "10", "10")
    assert result['hex'], 'got raw xtn'
    fundingtxid = send_and_mine(result['hex'], rpc)
    assert fundingtxid, 'got txid'
    result = rpc.rewardsinfo(fundingtxid)
    assert_success(result)
    assert result['name'] == plan_name
    assert result['APR'] == "25.00000000"
    assert result['minseconds'] == 0
    assert result['maxseconds'] == 864000
    assert result['funding'] == "7777.00000000"
    assert result['mindeposit'] == "10.00000000"
    assert result['fundingtxid'] == fundingtxid

    # checking if new plan in rewardslist
    result = rpc.rewardslist()
    assert fundingtxid in result

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

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

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

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

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

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

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

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

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

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

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

    # confirm the xtn above
    wait_some_blocks(rpc, 1)

    # will not unlock since reward amount is less than tx fee
    result = rpc.rewardsunlock(plan_name, fundingtxid, locktxid)
    assert_error(result)
예제 #4
0
def test_faucet():

    # test params inits
    with open('test_config.json', 'r') as f:
        params_dict = json.load(f)

    node1_params = params_dict["node1"]
    node2_params = params_dict["node2"]

    rpc = rpc_connect(node1_params["rpc_user"], node1_params["rpc_password"],
                      node1_params["rpc_ip"], node1_params["rpc_port"])
    rpc1 = rpc_connect(node2_params["rpc_user"], node2_params["rpc_password"],
                       node2_params["rpc_ip"], node2_params["rpc_port"])
    pubkey = node1_params["pubkey"]
    pubkey1 = node2_params["pubkey"]

    is_fresh_chain = params_dict["is_fresh_chain"]

    # faucet got only one entity per chain

    if is_fresh_chain:
        # basic sanity tests
        result = rpc.getinfo()
        assert result, "got response"

        result = rpc1.getinfo()
        assert result, "got response"

        result = rpc.getwalletinfo()
        assert result['balance'] > 0.0
        balance = result['balance']

        result = rpc.faucetaddress()
        assert 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 result[x][0] == 'R'

        result = rpc.faucetaddress(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 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
        assert txid, "found txid"
        # we need the tx above to be confirmed in the next block
        check_if_mined(rpc, txid)

        result = rpc.getwalletinfo()
        balance2 = result['balance']
        # make sure our balance is less now
        # TODO: this check not working at the moment because of the mining rewards
        # assert balance > balance2

        result = rpc.faucetinfo()
        assert_success(result)
        assert float(result['funding']) > 0

        # claiming faucet on second node
        # TODO: to pass it we should increase default timeout in rpclib
        # or sometimes we'll get such pycurl.error: (28, 'Operation timed out after 30000 milliseconds with 0 bytes received')
        #faucetgethex = rpc1.faucetget()
        #assert_success(faucetgethex)
        #assert faucetgethex['hex'], "hex key found"

        balance1 = rpc1.getwalletinfo()['balance']
예제 #5
0
def test_channels(test_params):

    # test params inits
    rpc = test_params.get('node1').get('rpc')
    rpc1 = test_params.get('node2').get('rpc')

    pubkey = test_params.get('node1').get('pubkey')
    pubkey1 = test_params.get('node2').get('pubkey')

    is_fresh_chain = test_params.get("is_fresh_chain")
    """!!! 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
    """

    # checking channelsaddress call

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

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

    # getting empty channels list

    result = rpc.channelslist()
    assert result["result"] == "success"
    assert result["name"] == "Channels List"
    if is_fresh_chain:
        assert len(result) == 2

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

    # checking if our new channel in common channels list
    if is_fresh_chain:
        result = rpc.channelslist()
        assert len(result) == 3

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

    # open transaction should be confirmed at least twice
    wait_some_blocks(rpc, 3)

    # 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 = 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 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 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 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 = send_and_mine(result["hex"], rpc)
    assert payment_tx_id, "got txid"

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

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

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

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

    result = raw_transaction["vout"][3]["valueSat"]
    assert result == 200000

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

    # have to check that second node have coins to cover txfee at least
    rpc.sendtoaddress(rpc1.getnewaddress(), 1)
    time.sleep(10)  # to ensure transactions are in different blocks
    rpc.sendtoaddress(rpc1.getnewaddress(), 1)
    wait_some_blocks(rpc, 2)
    result = rpc1.getbalance()
    assert 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)
    # TODO: by some reason channels close just returning hex instead of result and hex json
    channel_close_txid = send_and_mine(result, rpc)
    assert channel_close_txid, "got txid"

    wait_some_blocks(rpc, 2)

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

    # executing channel refund
    result = rpc.channelsrefund(channel_txid, channel_close_txid)
    # TODO: by some reason channels refund just returning hex instead of result and hex json
    refund_txid = send_and_mine(result, 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 result == 700000

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

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

    # need to have 2+ confirmations in the test mode
    wait_some_blocks(rpc, 2)

    # TODO: maybe it's possible to send in single block to not wait 10 blocks?
    for i in range(10):
        result = rpc.channelspayment(channel1_txid, "100000")
        assert_success(result)
        payment_tx_id = 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 result == 0

    # no more payments possible
    result = rpc.channelspayment(channel1_txid, "100000")
    assert_error(result)
예제 #6
0
def test_heir():

    # test params inits
    with open('test_config.json', 'r') as f:
        params_dict = json.load(f)

    node1_params = params_dict["node1"]
    node2_params = params_dict["node2"]

    rpc = rpc_connect(node1_params["rpc_user"], node1_params["rpc_password"], node1_params["rpc_ip"], node1_params["rpc_port"])
    rpc1 = rpc_connect(node2_params["rpc_user"], node2_params["rpc_password"], node2_params["rpc_ip"], node2_params["rpc_port"])
    pubkey = node1_params["pubkey"]
    pubkey1 = node2_params["pubkey"]
    is_fresh_chain = params_dict["is_fresh_chain"]

    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 result[x][0] == 'R'

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

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

    # getting empty heir list
    if is_fresh_chain:
        result = rpc.heirlist()
        assert result == []

    # valid heirfund case with coins
    result = rpc.heirfund("1000", "UNITHEIR", pubkey1, "10", "TESTMEMO")
    assert_success(result)
    heir_fund_txid = 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 heir_fund_txid in result

    # checking heirinfo
    result = rpc.heirinfo(heir_fund_txid)
    assert_success(result)
    assert result["fundingtxid"] == heir_fund_txid
    assert result["name"] == "UNITHEIR"
    assert result["owner"] == pubkey
    assert result["heir"] == pubkey1
    assert result["memo"] == "TESTMEMO"
    assert result["lifetime"] == "1000.00000000"
    assert result["type"] == "coins"
    assert result["InactivityTimeSetting"] == "10"
    # TODO: we have non insta blocks now so should set inactivity time more than blocktime to proper test it
    #assert result["IsHeirSpendingAllowed"] == "false"

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

    # have to check that second node have coins to cover txfee at least
    second_node_balance = rpc1.getbalance()
    if second_node_balance < 0.1:
        rpc.sendtoaddress(rpc1.getnewaddress(), 1)
        rpc.sendtoaddress(rpc1.getnewaddress(), 1)
        wait_some_blocks(rpc, 2)
    assert second_node_balance > 0.1

    # let's claim whole heir sum from second node
    result = rpc1.heirclaim("1000", heir_fund_txid)
    assert_success(result)
    heir_claim_txid = 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
    # TODO: very bad test with non-clearly hardcoded blockreward - needs to be changed
    #result = round(rpc1.getbalance()) - round(second_node_balance)
    #assert result > 100999

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

    # creating tokens which we put to heir contract
    token_hex = rpc.tokencreate("TEST", "1", "TESTING")
    token_txid = 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, pubkey)["balance"]
    assert result == 100000000

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

    # checking heirinfo
    result = rpc.heirinfo(token_heir_txid)
    assert_success(result)
    assert result["fundingtxid"] == token_heir_txid
    assert result["name"] == "UNITHEIR"
    assert result["owner"] == pubkey
    assert result["heir"] == pubkey1
    assert result["lifetime"] == "100000000"
    assert result["type"] == "tokens"
    assert result["InactivityTimeSetting"] == "10"
    # TODO: we have non insta blocks now so should set inactivity time more than blocktime to proper test it
    #assert result["IsHeirSpendingAllowed"] == "false"

    # waiting for 11 seconds to be sure that needed time passed for heir claiming
    time.sleep(11)
    wait_some_blocks(rpc, 2)
    result = rpc.heirinfo(token_heir_txid)
    assert result["lifetime"] == "100000000"
    assert result["IsHeirSpendingAllowed"] == "true"

    # let's claim whole heir sum from second node
    result = rpc1.heirclaim("100000000", token_heir_txid)
    assert_success(result)
    
    heir_tokens_claim_txid = 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, pubkey1)["balance"]
    assert result == 100000000

    # no more funds should be available for claiming
    result = rpc.heirinfo(token_heir_txid)
    assert result["lifetime"] == "100000000"
    assert result["available"] == "0"
예제 #7
0
def test_ccindex(test_params):

    # test params inits
    rpc = test_params.get('node1').get('rpc')
    rpc1 = test_params.get('node2').get('rpc')

    pubkey = test_params.get('node1').get('pubkey')
    pubkey1 = test_params.get('node2').get('pubkey')

    is_fresh_chain = test_params.get("is_fresh_chain")

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

    # get token cc address for pubkey:
    result = rpc.tokenaddress(pubkey)
    assert_success(result)
    pubkeyTokenCCAddress = ""
    for x in result.keys():
        if x.find('ddress') > 0:
            assert result[x][0] == 'R'
            if x == 'pubkey Tokens CC Address':
                pubkeyTokenCCAddress = result[x]

    # get token cc address for pubkey1:
    result = rpc.tokenaddress(pubkey1)
    assert_success(result)
    pubkey1TokenCCAddress = ""
    for x in result.keys():
        if x.find('ddress') > 0:
            assert result[x][0] == 'R'
            if x == 'pubkey Tokens CC Address':
                pubkey1TokenCCAddress = result[x]

    # there are no tokens created yet
    # TODO: this test conflicts with heir test because token creating for heir
#    if is_fresh_chain:
#        result = rpc.tokenlist()
#        assert result == []

    print("stop mining to test txns in mempool")
    rpc.setgenerate(False)
    rpc1.setgenerate(False)

    print("creating test token...")
    result = rpc.tokencreate("T1", "20", "token for testing cc index")
    assert_success(result)

    tokenid = rpc.sendrawtransaction(result['hex'])

    # check mempool index:
    print("check cc index for tokencreate in mempool...")

    # check one utxo in the index
    result = rpc.listccunspents(pubkeyTokenCCAddress, tokenid)
    # print('type(result)=' + str(type(result)))
    assert(str(type(result)) == "<class 'list'>")
    assert(len(result) == 1)
    assert(result[0]['creationId'] == tokenid)
    assert(result[0]['txhash'] == tokenid)
    assert(result[0]['satoshis'] == 20*100000000)
    assert(result[0]['funcid'].upper() == "C")
    assert(result[0]['blockHeight'] == 0)   # in mempool

    print("check cc index for tokentransfer in mempool...")

    result = rpc.tokentransfer(tokenid, pubkey1, "1")
    assert_success(result)
    txid = rpc.sendrawtransaction(result['hex'])

    # check two utxos in the mempool index

    result = rpc.listccunspents(pubkeyTokenCCAddress, tokenid)
    assert(str(type(result)) == "<class 'list'>")

    # note: once I got assert failed here: 
    # 'E       assert 0 == 1'
    # probably it happened because setgenerate(False) had not finished atm
    assert(len(result) == 1)
    assert(result[0]['creationId'] == tokenid)
    assert(result[0]['txhash'] == txid)
    assert(result[0]['satoshis'] == 20*100000000-1)
    assert(result[0]['funcid'].upper() == "T")
    assert(result[0]['blockHeight'] == 0)   # in mempool

    result = rpc.listccunspents(pubkey1TokenCCAddress, tokenid)
    assert(str(type(result)) == "<class 'list'>")
    assert(len(result) == 1)
    assert(result[0]['creationId'] == tokenid)
    assert(result[0]['txhash'] == txid)
    assert(result[0]['satoshis'] == 1)
    assert(result[0]['funcid'].upper() == "T")
    assert(result[0]['blockHeight'] == 0)   # in mempool

    print("mine txns and check cc index in db...")

    rpc.setgenerate(True, 1)
    while True:
        print("waiting until mempool empty...")
        time.sleep(10)
        mempool = rpc.getrawmempool()
        if len(mempool) == 0:
            break    

    result = rpc.listccunspents(pubkeyTokenCCAddress, tokenid)
    assert(str(type(result)) == "<class 'list'>")
    assert(len(result) == 1)
    assert(result[0]['creationId'] == tokenid)
    assert(result[0]['txhash'] == txid)
    assert(result[0]['satoshis'] == 20*100000000-1)
    assert(result[0]['funcid'].upper() == "T")
    assert(result[0]['blockHeight'] != 0)   # not in mempool

    result = rpc.listccunspents(pubkey1TokenCCAddress, tokenid)
    assert(str(type(result)) == "<class 'list'>")
    assert(len(result) == 1)
    assert(result[0]['creationId'] == tokenid)
    assert(result[0]['txhash'] == txid)
    assert(result[0]['satoshis'] == 1)
    assert(result[0]['funcid'].upper() == "T")
    assert(result[0]['blockHeight'] != 0)   # not in mempool

    print("test cc index okay")
예제 #8
0
def test_oracles(test_params):

    # test params inits
    rpc = test_params.get('node1').get('rpc')
    rpc1 = test_params.get('node2').get('rpc')

    pubkey = test_params.get('node1').get('pubkey')
    pubkey1 = test_params.get('node2').get('pubkey')

    is_fresh_chain = test_params.get("is_fresh_chain")

    result = rpc.oraclesaddress()
    assert_success(result)

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

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

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

    # there are no oracles created yet
    if is_fresh_chain:
        result = rpc.oracleslist()
        assert 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")
    assert_error(result)

    # 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)
    print(len(rpc.listunspent()))
    # enable mining
    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)] = rpc.sendrawtransaction(result['hex'])
        globals()["oracle_{}".format(f)] = send_and_mine(result['hex'], rpc)

    list_fund_txid = []
    for f in valid_formats:
        # 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 = rpc.sendrawtransaction(result["hex"])
        list_fund_txid.append(fund_txid)
        assert fund_txid, "got txid"

    wait_some_blocks(rpc, 2)

    for t in list_fund_txid:
        c = 0
        print("Waiting confiramtions for oraclesfund")
        while c < 2:
            try:
                c = rpc.getrawtransaction(t, 1)['confirmations']
            except KeyError:
                time.sleep(29)
        print("Oracles fund confirmed \n", t)

    for f in valid_formats:
        # trying to register valid (funded)
        result = rpc.oraclesregister(globals()["oracle_{}".format(f)],
                                     "100000")
        assert_success(result)
        print("Registering ", f)
        register_txid = rpc.sendrawtransaction(result["hex"])
        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)], pubkey,
                                      "1")
        assert_success(result)
        subscribe_txid = rpc.sendrawtransaction(result["hex"])
        assert register_txid, "got txid"

    wait_some_blocks(rpc, 2)

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

    # recording data for s type
    result = rpc.oraclesdata(globals()["oracle_{}".format("s")],
                             "05416e746f6e")
    assert_success(result)
    oraclesdata_s = rpc.sendrawtransaction(result["hex"])
    info_s = rpc.oraclesinfo(globals()["oracle_{}".format("s")])
    batonaddr_s = info_s['registered'][0]['baton']

    # recording data for S type
    result = rpc.oraclesdata(
        globals()["oracle_{}".format("S")],
        "000161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161"
    )
    assert_success(result)
    oraclesdata_S = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("S")])
    batonaddr_S = info['registered'][0]['baton']

    # recording data for d type
    result = rpc.oraclesdata(globals()["oracle_{}".format("d")], "0101")
    assert_success(result)
    # baton
    oraclesdata_d = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("d")])
    batonaddr_d = info['registered'][0]['baton']

    # recording data for D type
    result = rpc.oraclesdata(globals()["oracle_{}".format("D")], "010001")
    assert_success(result)
    # baton
    oraclesdata_D = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("D")])
    batonaddr_D = info['registered'][0]['baton']

    # recording data for c type
    result = rpc.oraclesdata(globals()["oracle_{}".format("c")], "ff")
    assert_success(result)
    # baton
    oraclesdata_c = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("c")])
    batonaddr_c = info['registered'][0]['baton']

    # recording data for C type
    result = rpc.oraclesdata(globals()["oracle_{}".format("C")], "ff")
    assert_success(result)
    # baton
    oraclesdata_C = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("C")])
    batonaddr_C = info['registered'][0]['baton']

    # recording data for t type
    result = rpc.oraclesdata(globals()["oracle_{}".format("t")], "ffff")
    assert_success(result)
    # baton
    oraclesdata_t = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("t")])
    batonaddr_t = info['registered'][0]['baton']

    # recording data for T type
    result = rpc.oraclesdata(globals()["oracle_{}".format("T")], "ffff")
    assert_success(result)
    # baton
    oraclesdata_T = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("T")])
    batonaddr_T = info['registered'][0]['baton']

    # recording data for i type
    result = rpc.oraclesdata(globals()["oracle_{}".format("i")], "ffffffff")
    assert_success(result)
    # baton
    oraclesdata_i = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("i")])
    batonaddr_i = info['registered'][0]['baton']

    # recording data for I type
    result = rpc.oraclesdata(globals()["oracle_{}".format("I")], "ffffffff")
    assert_success(result)
    # baton
    oraclesdata_I = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("I")])
    batonaddr_I = info['registered'][0]['baton']

    # recording data for l type
    result = rpc.oraclesdata(globals()["oracle_{}".format("l")],
                             "00000000ffffffff")
    assert_success(result)
    # baton
    oraclesdata_l = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("l")])
    batonaddr_l = info['registered'][0]['baton']

    # recording data for L type
    result = rpc.oraclesdata(globals()["oracle_{}".format("L")],
                             "00000000ffffffff")
    assert_success(result)
    # baton
    oraclesdata_L = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("L")])
    batonaddr_L = info['registered'][0]['baton']

    # recording data for h type
    result = rpc.oraclesdata(
        globals()["oracle_{}".format("h")],
        "00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff")
    assert_success(result)
    # baton
    oraclesdata_h = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("h")])
    batonaddr_h = info['registered'][0]['baton']

    # recording data for Ihh type
    result = rpc.oraclesdata(
        globals()["oracle_{}".format("Ihh")],
        "ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff"
    )
    assert_success(result)
    # baton
    oraclesdata_Ihh = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("Ihh")])
    batonaddr_Ihh = info['registered'][0]['baton']

    wait_some_blocks(rpc, 1)

    # checking data for s type
    result = rpc.oraclessamples(globals()["oracle_{}".format("s")],
                                batonaddr_s, "1")
    assert "['Anton']" == str(result["samples"][0]['data'])

    # checking data for S type
    result = rpc.oraclessamples(globals()["oracle_{}".format("S")],
                                batonaddr_S, "1")
    assert "['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa']" == str(
        result["samples"][0]['data'])

    # checking data for d type
    result = rpc.oraclessamples(globals()["oracle_{}".format("d")],
                                batonaddr_d, "1")
    assert "['01']" == str(result["samples"][0]['data'])

    # checking data for D type
    result = rpc.oraclessamples(globals()["oracle_{}".format("D")],
                                batonaddr_D, "1")
    assert "['01']" == str(result["samples"][0]['data'])

    # checking data for c type
    result = rpc.oraclessamples(globals()["oracle_{}".format("c")],
                                batonaddr_c, "1")
    assert "['-1']" == str(result["samples"][0]['data'])

    # checking data for C type
    result = rpc.oraclessamples(globals()["oracle_{}".format("C")],
                                batonaddr_C, "1")
    assert "['255']" == str(result["samples"][0]['data'])

    # checking data for t type
    result = rpc.oraclessamples(globals()["oracle_{}".format("t")],
                                batonaddr_t, "1")
    assert "['-1']" == str(result["samples"][0]['data'])

    # checking data for T type
    result = rpc.oraclessamples(globals()["oracle_{}".format("T")],
                                batonaddr_T, "1")
    assert "['65535']" == str(result["samples"][0]['data'])

    # checking data for i type
    result = rpc.oraclessamples(globals()["oracle_{}".format("i")],
                                batonaddr_i, "1")
    assert "['-1']" == str(result["samples"][0]['data'])

    # checking data for I type
    result = rpc.oraclessamples(globals()["oracle_{}".format("I")],
                                batonaddr_I, "1")
    assert "['4294967295']" == str(result["samples"][0]['data'])

    # checking data for l type
    result = rpc.oraclessamples(globals()["oracle_{}".format("l")],
                                batonaddr_l, "1")
    assert "['-4294967296']" == str(result["samples"][0]['data'])

    # checking data for L type
    result = rpc.oraclessamples(globals()["oracle_{}".format("L")],
                                batonaddr_L, "1")
    assert "['18446744069414584320']" == str(result["samples"][0]['data'])

    # checking data for h type
    result = rpc.oraclessamples(globals()["oracle_{}".format("h")],
                                batonaddr_h, "1")
    assert "['ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000']" == str(
        result["samples"][0]['data'])

    # checking data for Ihh type
    result = rpc.oraclessamples(globals()["oracle_{}".format("Ihh")],
                                batonaddr_Ihh, "1")
    assert "['4294967295', 'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000', 'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000']" == str(
        result["samples"][0]['data'])
예제 #9
0
def test_oracles():

    # test params inits
    with open('test_config.json', 'r') as f:
        params_dict = json.load(f)

    node1_params = params_dict["node1"]
    node2_params = params_dict["node2"]

    rpc = rpc_connect(node1_params["rpc_user"], node1_params["rpc_password"],
                      node1_params["rpc_ip"], node1_params["rpc_port"])
    rpc1 = rpc_connect(node2_params["rpc_user"], node2_params["rpc_password"],
                       node2_params["rpc_ip"], node2_params["rpc_port"])
    pubkey = node1_params["pubkey"]
    pubkey1 = node2_params["pubkey"]

    is_fresh_chain = params_dict["is_fresh_chain"]

    result = rpc.oraclesaddress()
    assert_success(result)

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

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

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

    # there are no oracles created yet
    if is_fresh_chain:
        result = rpc.oracleslist()
        assert 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")
    assert_error(result)

    # 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)
    print(len(rpc.listunspent()))
    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)] = rpc.sendrawtransaction(
            result['hex'])

    wait_some_blocks(rpc, 1)

    for f in valid_formats:
        # 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 = rpc.sendrawtransaction(result["hex"])
        assert fund_txid, "got txid"

    wait_some_blocks(rpc, 1)

    for f in valid_formats:
        # trying to register valid (funded)
        result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "10000")
        print(f)
        assert_success(result)
        register_txid = rpc.sendrawtransaction(result["hex"])
        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)], pubkey,
                                      "1")
        assert_success(result)
        subscribe_txid = rpc.sendrawtransaction(result["hex"])
        assert register_txid, "got txid"

    wait_some_blocks(rpc, 2)

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

    # recording data for s type
    result = rpc.oraclesdata(globals()["oracle_{}".format("s")],
                             "05416e746f6e")
    assert_success(result)
    oraclesdata_s = rpc.sendrawtransaction(result["hex"])
    info_s = rpc.oraclesinfo(globals()["oracle_{}".format("s")])
    batonaddr_s = info_s['registered'][0]['baton']

    # recording data for S type
    result = rpc.oraclesdata(
        globals()["oracle_{}".format("S")],
        "000161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161"
    )
    assert_success(result)
    oraclesdata_S = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("S")])
    batonaddr_S = info['registered'][0]['baton']

    # recording data for d type
    result = rpc.oraclesdata(globals()["oracle_{}".format("d")], "0101")
    assert_success(result)
    # baton
    oraclesdata_d = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("d")])
    batonaddr_d = info['registered'][0]['baton']

    # recording data for D type
    result = rpc.oraclesdata(globals()["oracle_{}".format("D")], "010001")
    assert_success(result)
    # baton
    oraclesdata_D = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("D")])
    batonaddr_D = info['registered'][0]['baton']

    # recording data for c type
    result = rpc.oraclesdata(globals()["oracle_{}".format("c")], "ff")
    assert_success(result)
    # baton
    oraclesdata_c = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("c")])
    batonaddr_c = info['registered'][0]['baton']

    # recording data for C type
    result = rpc.oraclesdata(globals()["oracle_{}".format("C")], "ff")
    assert_success(result)
    # baton
    oraclesdata_C = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("C")])
    batonaddr_C = info['registered'][0]['baton']

    # recording data for t type
    result = rpc.oraclesdata(globals()["oracle_{}".format("t")], "ffff")
    assert_success(result)
    # baton
    oraclesdata_t = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("t")])
    batonaddr_t = info['registered'][0]['baton']

    # recording data for T type
    result = rpc.oraclesdata(globals()["oracle_{}".format("T")], "ffff")
    assert_success(result)
    # baton
    oraclesdata_T = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("T")])
    batonaddr_T = info['registered'][0]['baton']

    # recording data for i type
    result = rpc.oraclesdata(globals()["oracle_{}".format("i")], "ffffffff")
    assert_success(result)
    # baton
    oraclesdata_i = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("i")])
    batonaddr_i = info['registered'][0]['baton']

    # recording data for I type
    result = rpc.oraclesdata(globals()["oracle_{}".format("I")], "ffffffff")
    assert_success(result)
    # baton
    oraclesdata_I = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("I")])
    batonaddr_I = info['registered'][0]['baton']

    # recording data for l type
    result = rpc.oraclesdata(globals()["oracle_{}".format("l")],
                             "00000000ffffffff")
    assert_success(result)
    # baton
    oraclesdata_l = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("l")])
    batonaddr_l = info['registered'][0]['baton']

    # recording data for L type
    result = rpc.oraclesdata(globals()["oracle_{}".format("L")],
                             "00000000ffffffff")
    assert_success(result)
    # baton
    oraclesdata_L = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("L")])
    batonaddr_L = info['registered'][0]['baton']

    # recording data for h type
    result = rpc.oraclesdata(
        globals()["oracle_{}".format("h")],
        "00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff")
    assert_success(result)
    # baton
    oraclesdata_h = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("h")])
    batonaddr_h = info['registered'][0]['baton']

    # recording data for Ihh type
    result = rpc.oraclesdata(
        globals()["oracle_{}".format("Ihh")],
        "ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff"
    )
    assert_success(result)
    # baton
    oraclesdata_Ihh = rpc.sendrawtransaction(result["hex"])
    info = rpc.oraclesinfo(globals()["oracle_{}".format("Ihh")])
    batonaddr_Ihh = info['registered'][0]['baton']

    wait_some_blocks(rpc, 1)

    # checking data for s type
    result = rpc.oraclessamples(globals()["oracle_{}".format("s")],
                                batonaddr_s, "1")
    assert "['Anton']" == str(result["samples"][0]['data'])

    # checking data for S type
    result = rpc.oraclessamples(globals()["oracle_{}".format("S")],
                                batonaddr_S, "1")
    assert "['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa']" == str(
        result["samples"][0]['data'])

    # checking data for d type
    result = rpc.oraclessamples(globals()["oracle_{}".format("d")],
                                batonaddr_d, "1")
    assert "['01']" == str(result["samples"][0]['data'])

    # checking data for D type
    result = rpc.oraclessamples(globals()["oracle_{}".format("D")],
                                batonaddr_D, "1")
    assert "['01']" == str(result["samples"][0]['data'])

    # checking data for c type
    result = rpc.oraclessamples(globals()["oracle_{}".format("c")],
                                batonaddr_c, "1")
    assert "['-1']" == str(result["samples"][0]['data'])

    # checking data for C type
    result = rpc.oraclessamples(globals()["oracle_{}".format("C")],
                                batonaddr_C, "1")
    assert "['255']" == str(result["samples"][0]['data'])

    # checking data for t type
    result = rpc.oraclessamples(globals()["oracle_{}".format("t")],
                                batonaddr_t, "1")
    assert "['-1']" == str(result["samples"][0]['data'])

    # checking data for T type
    result = rpc.oraclessamples(globals()["oracle_{}".format("T")],
                                batonaddr_T, "1")
    assert "['65535']" == str(result["samples"][0]['data'])

    # checking data for i type
    result = rpc.oraclessamples(globals()["oracle_{}".format("i")],
                                batonaddr_i, "1")
    assert "['-1']" == str(result["samples"][0]['data'])

    # checking data for I type
    result = rpc.oraclessamples(globals()["oracle_{}".format("I")],
                                batonaddr_I, "1")
    assert "['4294967295']" == str(result["samples"][0]['data'])

    # checking data for l type
    result = rpc.oraclessamples(globals()["oracle_{}".format("l")],
                                batonaddr_l, "1")
    assert "['-4294967296']" == str(result["samples"][0]['data'])

    # checking data for L type
    result = rpc.oraclessamples(globals()["oracle_{}".format("L")],
                                batonaddr_L, "1")
    assert "['18446744069414584320']" == str(result["samples"][0]['data'])

    # checking data for h type
    result = rpc.oraclessamples(globals()["oracle_{}".format("h")],
                                batonaddr_h, "1")
    assert "['ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000']" == str(
        result["samples"][0]['data'])

    # checking data for Ihh type
    result = rpc.oraclessamples(globals()["oracle_{}".format("Ihh")],
                                batonaddr_Ihh, "1")
    assert "['4294967295', 'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000', 'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000']" == str(
        result["samples"][0]['data'])