示例#1
0
def test_registry():
    library_path = get_contract_path('IterableMappingCMC.sol')
    ncc_path = get_contract_path('IterableMappingNCC.sol')
    decoder_path = get_contract_path('Decoder.sol')
    registry_path = get_contract_path('Registry.sol')

    s = tester.state()
    assert s.block.number < 1150000
    s.block.number = 1158001
    assert s.block.number > 1150000
    lib_c = s.abi_contract(None, path=library_path, language="solidity")
    s.mine()
    lib_ncc = s.abi_contract(None, path=ncc_path, language="solidity")
    s.mine()
    lib_dec = s.abi_contract(None, path=decoder_path, language="solidity")
    s.mine()
    c = s.abi_contract(None, path=registry_path, language="solidity", libraries={'IterableMappingCMC': lib_c.address.encode('hex'), 'IterableMappingNCC': lib_ncc.address.encode('hex'), 'Decoder': lib_dec.address.encode('hex')})

    contract_address = c.addAsset(sha3('asset')[:20])
    c.addAsset(sha3('address')[:20])
    # if address already exists, throw
    with pytest.raises(TransactionFailed):
        c.addAsset(sha3('asset')[:20])

    cmc = c.channelManagerByAsset(sha3('asset')[:20])
    assert cmc == contract_address
    # if address does not exist, throw
    with pytest.raises(TransactionFailed):
        c.channelManagerByAsset(sha3('mainz')[:20])

    adrs = c.assetAddresses()
    assert len(adrs) == 2
    assert adrs[0] == sha3('asset')[:20].encode('hex')
    assert adrs[1] == sha3('address')[:20].encode('hex')
示例#2
0
def test_cmc():
    library_path = get_contract_path('IterableMappingNCC.sol')
    cmc_path = get_contract_path('ChannelManagerContract.sol')

    s = tester.state()
    assert s.block.number < 1150000
    s.block.number = 1158001
    assert s.block.number > 1150000
    lib_c = s.abi_contract(None, path=library_path, language="solidity")
    c = s.abi_contract(None, path=cmc_path, language="solidity", libraries={'IterableMappingNCC': lib_c.address.encode('hex')}, constructor_parameters=['0x0bd4060688a1800ae986e4840aebc924bb40b5bf'])

    # test key()
    # uncomment private in function to run test
    # vs = sorted((sha3('address1')[:20], sha3('address2')[:20]))
    # k0 = c.key(sha3('address1')[:20], sha3('address2')[:20])
    # assert k0 == sha3(vs[0] + vs[1])
    # k1 = c.key(sha3('address2')[:20], sha3('address1')[:20])
    # assert k1 == sha3(vs[0] + vs[1])
    # with pytest.raises(TransactionFailed):
        # c.key(sha3('address1')[:20], sha3('address1')[:20])

    # test newChannel()
    assert c.assetAddress() == sha3('asset')[:20].encode('hex')
    nc1 = c.newChannel(sha3('address1')[:20], 30)
    nc2 = c.newChannel(sha3('address3')[:20], 30)
    with pytest.raises(TransactionFailed):
        c.newChannel(sha3('address1')[:20], 30)
    with pytest.raises(TransactionFailed):
        c.newChannel(sha3('address3')[:20], 30)

    # TODO test event

    # test get()
    print nc1[0]
    chn1 = c.get(nc1[1], sha3('address1')[:20]) # nc1[1] is msg.sender of newChannel
    assert chn1 == nc1[0] # nc1[0] is address of new NettingChannelContract
    chn2 = c.get(nc2[1], sha3('address3')[:20]) # nc2[1] is msg.sender of newChannel
    assert chn2 == nc2[0] # nc2[0] is msg.sender of newChannel
    with pytest.raises(TransactionFailed):  # should throw if key doesn't exist
        c.get(nc1[1], sha3('iDontExist')[:20])

    # test nettingContractsByAddress()
    msg_sender_channels = c.nettingContractsByAddress(nc1[1])
    assert len(msg_sender_channels) == 2
    # assert c.numberOfItems(nc1[1]) == 2  # uncomment private in function to run test
    address1_channels = c.nettingContractsByAddress(sha3('address1')[:20])
    assert len(address1_channels) == 1
    # assert c.numberOfItems(sha3('address1')[:20]) == 1 # uncomment private in function to run test
    address1_channels = c.nettingContractsByAddress(sha3('iDontExist')[:20])
    assert len(address1_channels) == 0
    # assert c.numberOfItems(sha3('iDontExist')[:20]) == 0  # uncomment private in function to run test

    # test getAllChannels()
    arr_of_items = c.getAllChannels()
    assert len(arr_of_items) == 4
    c.newChannel(sha3('address4')[:20])
    assert len(c.getAllChannels()) == 6
示例#3
0
def test_registry():
    library_path = get_contract_path('IterableMappingCMC.sol')
    ncc_path = get_contract_path('IterableMappingNCC.sol')
    decoder_path = get_contract_path('Decoder.sol')
    registry_path = get_contract_path('Registry.sol')

    s = tester.state()
    assert s.block.number < 1150000
    s.block.number = 1158001
    assert s.block.number > 1150000
    lib_c = s.abi_contract(None, path=library_path, language="solidity")
    s.mine()
    lib_ncc = s.abi_contract(None, path=ncc_path, language="solidity")
    s.mine()
    lib_dec = s.abi_contract(None, path=decoder_path, language="solidity")
    s.mine()
    c = s.abi_contract(None,
                       path=registry_path,
                       language="solidity",
                       libraries={
                           'IterableMappingCMC': lib_c.address.encode('hex'),
                           'IterableMappingNCC': lib_ncc.address.encode('hex'),
                           'Decoder': lib_dec.address.encode('hex')
                       })

    contract_address = c.addAsset(sha3('asset')[:20])
    c.addAsset(sha3('address')[:20])
    # if address already exists, throw
    with pytest.raises(TransactionFailed):
        c.addAsset(sha3('asset')[:20])

    cmc = c.channelManagerByAsset(sha3('asset')[:20])
    assert cmc == contract_address
    # if address does not exist, throw
    with pytest.raises(TransactionFailed):
        c.channelManagerByAsset(sha3('mainz')[:20])

    adrs = c.assetAddresses()
    assert len(adrs) == 2
    assert adrs[0] == sha3('asset')[:20].encode('hex')
    assert adrs[1] == sha3('address')[:20].encode('hex')
示例#4
0
def test_slice():
    slicer_path = get_contract_path('Slicer.sol')

    state = tester.state()
    slicer = state.abi_contract(None, path=slicer_path, language='solidity')

    # pylint: disable=no-member
    assert slicer.slice('hello', 0, 2).decode('utf-8') == 'he'
    assert slicer.slice('hello', 0, 5).decode('utf-8') == 'hello'

    # should throw on invalid input
    with pytest.raises(TransactionFailed):
        slicer.slice('hello', 5, 8)
示例#5
0
def test_slice():
    slicer_path = get_contract_path('Slicer.sol')

    with open(slicer_path) as slicer_file:
        slicer_code = slicer_file.read()

    state = tester.state()
    slicer = state.abi_contract(slicer_code, language='solidity')

    # pylint: disable=no-member
    assert slicer.slice('hello', 0, 2).decode('utf-8') == 'he'
    assert slicer.slice('hello', 0, 5).decode('utf-8') == 'hello'

    # should throw on invalid input
    with pytest.raises(TransactionFailed):
        slicer.slice('hello', 5, 8)
示例#6
0
def test_ncc():
    token_library_path = get_contract_path('StandardToken.sol')
    token_path = get_contract_path('HumanStandardToken.sol')

    library_path = get_contract_path('Decoder.sol')
    ncc_path = get_contract_path('NettingChannelContract.sol.old')

    s = tester.state()
    assert s.block.number < 1150000
    s.block.number = 1158001
    assert s.block.number > 1150000
    # Token creation
    lib_token = s.abi_contract(None,
                               path=token_library_path,
                               language="solidity")
    token = s.abi_contract(
        None,
        path=token_path,
        language="solidity",
        libraries={'StandardToken': lib_token.address.encode('hex')},
        constructor_parameters=[10000, "raiden", 0, "rd"])

    s.mine()

    lib_c = s.abi_contract(None, path=library_path, language="solidity")
    s.mine()
    c = s.abi_contract(
        None,
        path=ncc_path,
        language="solidity",
        libraries={'Decoder': lib_c.address.encode('hex')},
        constructor_parameters=[token.address, tester.a0, tester.a1, 30])

    # test tokens and distribute tokens
    assert token.balanceOf(tester.a0) == 10000
    assert token.balanceOf(tester.a1) == 0
    assert token.transfer(tester.a1, 5000) == True
    assert token.balanceOf(tester.a0) == 5000
    assert token.balanceOf(tester.a1) == 5000

    # test global variables
    assert c.lockedTime() == 30
    assert c.assetAddress() == token.address.encode('hex')
    assert c.opened() == 0
    assert c.closed() == 0
    assert c.settled() == 0

    # test participants variables changed when constructing
    assert c.participants(0)[0] == tester.a0.encode('hex')
    assert c.participants(1)[0] == tester.a1.encode('hex')

    # test atIndex()
    # private must be removed from the function in order to work
    # assert c.atIndex(sha3('address1')[:20]) == 0
    # assert c.atIndex(sha3('address2')[:20]) == 1

    # test deposit(uint)
    assert token.balanceOf(c.address) == 0
    assert token.approve(c.address,
                         30) == True  # allow the contract do deposit
    assert c.participants(0)[1] == 0
    with pytest.raises(TransactionFailed):
        c.deposit(5001)
    c.deposit(30)
    assert c.participants(0)[1] == 30
    assert token.balanceOf(c.address) == 30
    assert token.balanceOf(tester.a0) == 4970
    assert c.opened() == s.block.number

    # test open()
    # private must be removed from the function in order to work
    # assert c.opened() == 0  # channel is not yet opened
    # c.open()
    # assert c.opened() > 0
    # assert c.opened() <= s.block.number

    # test partner(address)
    # private must be removed from the function in order to work
    # assert c.partner(sha3('address1')[:20]) == sha3('address2')[:20].encode('hex')
    # assert c.partner(sha3('address2')[:20]) == sha3('address1')[:20].encode('hex')

    # test addrAndDep()
    a1, d1, a2, d2 = c.addrAndDep()
    assert a1 == tester.a0.encode('hex')
    assert a2 == tester.a1.encode('hex')
    assert d1 == 30
    assert d2 == 0
示例#7
0
# -*- coding: utf8 -*-
import pytest

from ethereum import tester
from ethereum.utils import sha3, privtoaddr
from ethereum.tester import TransactionFailed

from raiden.network.rpc.client import get_contract_path

decoder_path = get_contract_path('Decoder.sol')

with open(decoder_path) as decoder_file:
    decode_code = decoder_file.read()


def test_decode_secret():
    encoded_data = "040000000000000000000000000000000000000000000000000000000000736563726574d37b47b46bea9027a92a6e1c374450092016b9935c0f1e738a9516693f708f5b35937bb4e0a7de93be31585e6aa04984869477ce5283415d4e736e537e59d43501"
    # longer than expected input
    bad_encoded_data = "040000000000000000000000000000000000000000000000000000000000736563726574d37b47b46bea9027a92a6e1c374450092016b9935c0f1e738a9516693f708f5b35937bb4e0a7de93be31585e6aa04984869477ce5283415d4e736e537e59d4350101"

    data = encoded_data.decode('hex')
    bad_data = bad_encoded_data.decode('hex')

    s = tester.state()
    c = s.abi_contract(decode_code, language="solidity")
    assert data[0] == '\x04'  # make sure data has right cmdid
    o1 = c.decodeSecret(data)
    assert o1[0][26:32] == 'secret'
    assert o1[0].encode('hex') == '0000000000000000000000000000000000000000000000000000736563726574'
    signature = 'd37b47b46bea9027a92a6e1c374450092016b9935c0f1e738a9516693f708f5b35937bb4e0a7de93be31585e6aa04984869477ce5283415d4e736e537e59d43501'
    assert o1[1].encode('hex') == signature[:64]
示例#8
0
# -*- coding: utf8 -*-
import pytest

from ethereum import tester
from ethereum.utils import sha3, privtoaddr
from ethereum.tester import TransactionFailed

from raiden.network.rpc.client import get_contract_path

decoder_path = get_contract_path("Decoder.sol")

with open(decoder_path) as decoder_file:
    decode_code = decoder_file.read()


def test_decode_secret():
    encoded_data = "040000000000000000000000000000000000000000000000000000000000736563726574d37b47b46bea9027a92a6e1c374450092016b9935c0f1e738a9516693f708f5b35937bb4e0a7de93be31585e6aa04984869477ce5283415d4e736e537e59d43501"
    # longer than expected input
    bad_encoded_data = "040000000000000000000000000000000000000000000000000000000000736563726574d37b47b46bea9027a92a6e1c374450092016b9935c0f1e738a9516693f708f5b35937bb4e0a7de93be31585e6aa04984869477ce5283415d4e736e537e59d4350101"

    data = encoded_data.decode("hex")
    bad_data = bad_encoded_data.decode("hex")

    s = tester.state()
    c = s.abi_contract(decode_code, language="solidity")
    assert data[0] == "\x04"  # make sure data has right cmdid
    o1 = c.decodeSecret(data)
    assert o1[0][26:32] == "secret"
    assert o1[0].encode("hex") == "0000000000000000000000000000000000000000000000000000736563726574"
    signature = "d37b47b46bea9027a92a6e1c374450092016b9935c0f1e738a9516693f708f5b35937bb4e0a7de93be31585e6aa04984869477ce5283415d4e736e537e59d43501"
    assert o1[1].encode("hex") == signature[:64]
示例#9
0
def test_ncc():
    token_library_path = get_contract_path('StandardToken.sol')
    token_path = get_contract_path('HumanStandardToken.sol')

    library_path = get_contract_path('Decoder.sol')
    ncc_path = get_contract_path('NettingChannelContract.sol.old')

    s = tester.state()
    assert s.block.number < 1150000
    s.block.number = 1158001
    assert s.block.number > 1150000
    # Token creation
    lib_token = s.abi_contract(None, path=token_library_path, language="solidity")
    token = s.abi_contract(None, path=token_path, language="solidity", libraries={'StandardToken': lib_token.address.encode('hex')}, constructor_parameters=[10000, "raiden", 0, "rd"])

    s.mine()

    lib_c = s.abi_contract(None, path=library_path, language="solidity")
    s.mine()
    c = s.abi_contract(None, path=ncc_path, language="solidity", libraries={'Decoder': lib_c.address.encode('hex')}, constructor_parameters=[token.address, tester.a0, tester.a1, 30])

    # test tokens and distribute tokens
    assert token.balanceOf(tester.a0) == 10000
    assert token.balanceOf(tester.a1) == 0
    assert token.transfer(tester.a1, 5000) == True
    assert token.balanceOf(tester.a0) == 5000
    assert token.balanceOf(tester.a1) == 5000

    # test global variables
    assert c.lockedTime() == 30
    assert c.assetAddress() == token.address.encode('hex')
    assert c.opened() == 0
    assert c.closed() == 0
    assert c.settled() == 0

    # test participants variables changed when constructing
    assert c.participants(0)[0] == tester.a0.encode('hex')
    assert c.participants(1)[0] == tester.a1.encode('hex')

    # test atIndex()
    # private must be removed from the function in order to work
    # assert c.atIndex(sha3('address1')[:20]) == 0
    # assert c.atIndex(sha3('address2')[:20]) == 1

    # test deposit(uint)
    assert token.balanceOf(c.address) == 0
    assert token.approve(c.address, 30) == True # allow the contract do deposit
    assert c.participants(0)[1] == 0
    with pytest.raises(TransactionFailed):
        c.deposit(5001)
    c.deposit(30)
    assert c.participants(0)[1] == 30
    assert token.balanceOf(c.address) == 30
    assert token.balanceOf(tester.a0) == 4970
    assert c.opened() == s.block.number

    # test open()
    # private must be removed from the function in order to work
    # assert c.opened() == 0  # channel is not yet opened
    # c.open()
    # assert c.opened() > 0
    # assert c.opened() <= s.block.number

    # test partner(address)
    # private must be removed from the function in order to work
    # assert c.partner(sha3('address1')[:20]) == sha3('address2')[:20].encode('hex')
    # assert c.partner(sha3('address2')[:20]) == sha3('address1')[:20].encode('hex')

    # test addrAndDep()
    a1, d1, a2, d2 = c.addrAndDep()
    assert a1 == tester.a0.encode('hex')
    assert a2 == tester.a1.encode('hex')
    assert d1 == 30
    assert d2 == 0
示例#10
0
# -*- coding: utf8 -*-
import pytest

from ethereum import tester
from ethereum.utils import sha3, privtoaddr
from ethereum.tester import TransactionFailed
from raiden.mtree import merkleroot
from raiden.messages import Lock, CancelTransfer, DirectTransfer, MediatedTransfer, Secret

from raiden.network.rpc.client import get_contract_path

decoder_path = get_contract_path('Decoder.sol')

# with open(decoder_path) as decoder_file:
    # decode_code = decoder_file.read()

INITIATOR_PRIVKEY = 'x' * 32
INITIATOR_ADDRESS = privtoaddr(INITIATOR_PRIVKEY)
SECRET = 'secret'

RECIPIENT_PRIVKEY = 'y' * 32
RECIPIENT_ADDRESS = privtoaddr(RECIPIENT_PRIVKEY)

TARGET_PRIVKEY = 'z' * 32
TARGET_ADDRESS = privtoaddr(TARGET_PRIVKEY)

ASSET_ADDRESS = sha3('asset')[:20]

HASHLOCK = sha3(INITIATOR_PRIVKEY)
LOCK_AMOUNT = 29
LOCK_EXPIRATION = 31
示例#11
0
def test_blockchain(request):
    # pylint: disable=too-many-locals
    from hydrachain import app
    app.slogging.configure(':ERROR')

    quantity = 3
    base_port = 29870
    timeout = 3  # seconds
    tmp_datadir = tempfile.mktemp()

    private_keys = [
        mk_privkey('raidentest:{}'.format(position))
        for position in range(quantity)
    ]

    addresses = [
        privtoaddr(priv)
        for priv in private_keys
    ]

    hydrachain_apps = hydrachain_network(private_keys, base_port, tmp_datadir)

    privatekey = private_keys[0]
    address = privtoaddr(privatekey)

    jsonrpc_client = JSONRPCClient(privkey=private_keys[0], print_communication=False)

    humantoken_path = get_contract_path('HumanStandardToken.sol')
    humantoken_contracts = compile_file(humantoken_path, libraries=dict())
    token_abi = jsonrpc_client.deploy_solidity_contract(
        address,
        'HumanStandardToken',
        humantoken_contracts,
        dict(),
        (9999, 'raiden', 2, 'Rd'),
        timeout=timeout,
    )

    registry_path = get_contract_path('Registry.sol')
    registry_contracts = compile_file(registry_path, libraries=dict())
    registry_abi = jsonrpc_client.deploy_solidity_contract(
        address,
        'Registry',
        registry_contracts,
        dict(),
        tuple(),
        timeout=timeout,
    )

    log_list = jsonrpc_client.call(
        'eth_getLogs',
        {
            'fromBlock': '0x0',
            'toBlock': 'latest',
            'topics': [],
        },
    )
    assert len(log_list) == 0

    # pylint: disable=no-member

    assert token_abi.balanceOf(address) == 9999
    transaction_hash = registry_abi.addAsset(token_abi.address)
    jsonrpc_client.poll(transaction_hash.decode('hex'), timeout=timeout)

    log_list = jsonrpc_client.call(
        'eth_getLogs',
        {
            'fromBlock': '0x0',
            'toBlock': 'latest',
            'topics': [],
        },
    )
    assert len(log_list) == 1

    channel_manager_address_encoded = registry_abi.channelManagerByAsset.call(token_abi.address)
    channel_manager_address = channel_manager_address_encoded.decode('hex')

    log_channel_manager_address_encoded = log_list[0]['data']
    log_channel_manager_address = log_channel_manager_address_encoded[2:].lstrip('0').rjust(40, '0').decode('hex')

    assert channel_manager_address == log_channel_manager_address

    channel_manager_abi = jsonrpc_client.new_contract_proxy(
        registry_contracts['ChannelManagerContract']['abi'],
        channel_manager_address,
    )

    transaction_hash = channel_manager_abi.newChannel(addresses[1], 10)
    jsonrpc_client.poll(transaction_hash.decode('hex'), timeout=timeout)

    log_list = jsonrpc_client.call(
        'eth_getLogs',
        {
            'fromBlock': '0x0',
            'toBlock': 'latest',
            'topics': [],
        },
    )
    assert len(log_list) == 2

    channel_manager_abi.get.call(
        address.encode('hex'),
        addresses[1].encode('hex'),
    )
示例#12
0
def test_blockchain(request):
    # pylint: disable=too-many-locals
    from hydrachain import app
    app.slogging.configure(':ERROR')

    quantity = 3
    base_port = 29870
    timeout = 3  # seconds
    tmp_datadir = tempfile.mktemp()

    private_keys = [
        mk_privkey('raidentest:{}'.format(position))
        for position in range(quantity)
    ]

    addresses = [privtoaddr(priv) for priv in private_keys]

    hydrachain_apps = hydrachain_network(private_keys, base_port, tmp_datadir)

    privatekey = private_keys[0]
    address = privtoaddr(privatekey)

    jsonrpc_client = JSONRPCClient(privkey=private_keys[0],
                                   print_communication=False)

    humantoken_path = get_contract_path('HumanStandardToken.sol')
    humantoken_contracts = compile_file(humantoken_path, libraries=dict())
    token_abi = jsonrpc_client.deploy_solidity_contract(
        address,
        'HumanStandardToken',
        humantoken_contracts,
        dict(),
        (9999, 'raiden', 2, 'Rd'),
        timeout=timeout,
    )

    registry_path = get_contract_path('Registry.sol')
    registry_contracts = compile_file(registry_path, libraries=dict())
    registry_abi = jsonrpc_client.deploy_solidity_contract(
        address,
        'Registry',
        registry_contracts,
        dict(),
        tuple(),
        timeout=timeout,
    )

    log_list = jsonrpc_client.call(
        'eth_getLogs',
        {
            'fromBlock': '0x0',
            'toBlock': 'latest',
            'topics': [],
        },
    )
    assert len(log_list) == 0

    # pylint: disable=no-member

    assert token_abi.balanceOf(address) == 9999
    transaction_hash = registry_abi.addAsset(token_abi.address)
    jsonrpc_client.poll(transaction_hash.decode('hex'), timeout=timeout)

    log_list = jsonrpc_client.call(
        'eth_getLogs',
        {
            'fromBlock': '0x0',
            'toBlock': 'latest',
            'topics': [],
        },
    )
    assert len(log_list) == 1

    channel_manager_address_encoded = registry_abi.channelManagerByAsset.call(
        token_abi.address)
    channel_manager_address = channel_manager_address_encoded.decode('hex')

    log_channel_manager_address_encoded = log_list[0]['data']
    log_channel_manager_address = log_channel_manager_address_encoded[
        2:].lstrip('0').rjust(40, '0').decode('hex')

    assert channel_manager_address == log_channel_manager_address

    channel_manager_abi = jsonrpc_client.new_contract_proxy(
        registry_contracts['ChannelManagerContract']['abi'],
        channel_manager_address,
    )

    transaction_hash = channel_manager_abi.newChannel(addresses[1], 10)
    jsonrpc_client.poll(transaction_hash.decode('hex'), timeout=timeout)

    log_list = jsonrpc_client.call(
        'eth_getLogs',
        {
            'fromBlock': '0x0',
            'toBlock': 'latest',
            'topics': [],
        },
    )
    assert len(log_list) == 2

    channel_manager_abi.get.call(
        address.encode('hex'),
        addresses[1].encode('hex'),
    )
示例#13
0
def test_ncc():

    token_library_path = get_contract_path('StandardToken.sol')
    token_path = get_contract_path('HumanStandardToken.sol')

    s = tester.state()
    assert s.block.number < 1150000
    s.block.number = 1158001
    assert s.block.number > 1150000
    # Token creation
    lib_token = s.abi_contract(None, path=token_library_path, language="solidity")
    token = s.abi_contract(None, path=token_path, language="solidity", libraries={'StandardToken': lib_token.address.encode('hex')}, constructor_parameters=[10000, "raiden", 0, "rd"])
    # Getter creation
    lib_getter = s.abi_contract(None, path=decode_lib, language="solidity")
    getter = s.abi_contract(None, path=getter_path, language="solidity", libraries={'Decoder': lib_getter.address.encode('hex')})

    INITIATOR_PRIVKEY = tester.k0
    INITIATOR_ADDRESS = privtoaddr(INITIATOR_PRIVKEY)

    RECIPIENT_PRIVKEY = tester.k1
    RECIPIENT_ADDRESS = privtoaddr(RECIPIENT_PRIVKEY)

    ASSET_ADDRESS = token.address

    HASHLOCK = sha3(INITIATOR_PRIVKEY)
    LOCK_AMOUNT = 29
    LOCK_EXPIRATION = 31
    LOCK = Lock(LOCK_AMOUNT, LOCK_EXPIRATION, HASHLOCK)
    LOCKSROOT = merkleroot([
        sha3(LOCK.as_bytes), ])   # print direct_transfer.encode('hex')

    nonce = 1
    asset = ASSET_ADDRESS
    balance = 1
    recipient = RECIPIENT_ADDRESS
    locksroot = LOCKSROOT

    msg = DirectTransfer(
        nonce,
        asset,
        balance,
        recipient,
        locksroot,
    ).sign(INITIATOR_PRIVKEY)
    packed = msg.packed()
    direct_transfer = str(packed.data)

    # pure python recover
    sen = recover_publickey(direct_transfer[:148], str(packed.signature))
    assert address_from_key(sen) == tester.a0

    # addr = getter.ecTest(direct_transfer[:148], sig)
    # assert addr == INITIATOR_ADDRESS.encode('hex')
    sender = getter.getSender(direct_transfer)
    assert sender == tester.a0.encode('hex')

    # with sigSplit directly in Getters.sol
    r, s, v = getter.sigSplit(str(packed.signature))
    assert r == str(packed.signature[:32])
    assert s == str(packed.signature[32:64])
    assert v == packed.signature[64] + 27

    sender = getter.getSender(direct_transfer)
    assert sender == tester.a0.encode('hex')
示例#14
0
import pytest

from ethereum import tester
from ethereum import slogging
from ethereum.tester import TransactionFailed

from raiden.mtree import merkleroot
from raiden.utils import privtoaddr, sha3
from raiden.messages import Lock, DirectTransfer
from raiden.encoding.signing import recover_publickey, address_from_key, sign
from raiden.network.rpc.client import get_contract_path

log = slogging.getLogger(__name__)  # pylint: disable=invalid-name

decode_lib = get_contract_path('Decoder.sol')
getter_path = get_contract_path('Getters.sol')


# @pytest.mark.xfail
def test_ncc():

    token_library_path = get_contract_path('StandardToken.sol')
    token_path = get_contract_path('HumanStandardToken.sol')

    s = tester.state()
    assert s.block.number < 1150000
    s.block.number = 1158001
    assert s.block.number > 1150000
    # Token creation
    lib_token = s.abi_contract(None, path=token_library_path, language="solidity")
    token = s.abi_contract(None, path=token_path, language="solidity", libraries={'StandardToken': lib_token.address.encode('hex')}, constructor_parameters=[10000, "raiden", 0, "rd"])