def test_registry(tester_registry, tester_events, private_keys, tester_chain): privatekey0 = tester.k0 token_address1 = tester_token_address(private_keys, 100, tester_chain, 0) token_address2 = tester_token_address(private_keys, 100, tester_chain, 1) unregistered_address = tester_token_address(private_keys, 100, tester_chain, 2) tester_chain.head_state.log_listeners.append(tester_events.append) contract_address1 = tester_registry.addToken(token_address1, sender=privatekey0) channel_manager_address1 = tester_registry.channelManagerByToken( token_address1, sender=privatekey0, ) assert channel_manager_address1 == contract_address1 with pytest.raises(tester.TransactionFailed): tester_registry.addToken(token_address1, sender=privatekey0) contract_address2 = tester_registry.addToken(token_address2, sender=privatekey0) channel_manager_address2 = tester_registry.channelManagerByToken( token_address2, sender=privatekey0, ) assert channel_manager_address2 == contract_address2 with pytest.raises(tester.TransactionFailed): tester_registry.channelManagerByToken( unregistered_address, sender=privatekey0, ) addresses = tester_registry.tokenAddresses(sender=privatekey0) assert len(addresses) == 2 assert addresses[0] == address_encoder(token_address1) assert addresses[1] == address_encoder(token_address2) assert len(tester_events) == 2 event0 = event_decoder(tester_events[0], tester_registry.translator) event1 = event_decoder(tester_events[1], tester_registry.translator) assert event0['_event_type'] == b'TokenAdded' assert event0['token_address'] == address_encoder(token_address1) assert event0['channel_manager_address'] == contract_address1 assert event1['_event_type'] == b'TokenAdded' assert event1['token_address'] == address_encoder(token_address2) assert event1['channel_manager_address'] == contract_address2
def test_registry(tester_registry, tester_events, private_keys, tester_chain): privatekey0 = tester.k0 token_address1 = tester_token_address(private_keys, 100, tester_chain, 0) token_address2 = tester_token_address(private_keys, 100, tester_chain, 1) unregistered_address = tester_token_address(private_keys, 100, tester_chain, 2) tester_chain.head_state.log_listeners.append(tester_events.append) contract_address1 = tester_registry.addToken(token_address1, sender=privatekey0) channel_manager_address1 = tester_registry.channelManagerByToken( token_address1, sender=privatekey0, ) assert channel_manager_address1 == contract_address1 with pytest.raises(tester.TransactionFailed): tester_registry.addToken(token_address1, sender=privatekey0) contract_address2 = tester_registry.addToken(token_address2, sender=privatekey0) channel_manager_address2 = tester_registry.channelManagerByToken( token_address2, sender=privatekey0, ) assert channel_manager_address2 == contract_address2 with pytest.raises(tester.TransactionFailed): tester_registry.channelManagerByToken( unregistered_address, sender=privatekey0, ) addresses = tester_registry.tokenAddresses(sender=privatekey0) assert len(addresses) == 2 assert addresses[0] == address_encoder(token_address1) assert addresses[1] == address_encoder(token_address2) assert len(tester_events) == 2 event0 = event_decoder(tester_events[0], tester_registry.translator) event1 = event_decoder(tester_events[1], tester_registry.translator) assert event0['_event_type'] == b'TokenAdded' assert event0['token_address'] == address_encoder(token_address1) assert event0['channel_manager_address'] == contract_address1 assert event1['_event_type'] == b'TokenAdded' assert event1['token_address'] == address_encoder(token_address2) assert event1['channel_manager_address'] == contract_address2
def test_registry(tester_registry, tester_events, private_keys, tester_state): privatekey0 = tester.DEFAULT_KEY token_address1 = tester_token_address(private_keys, 100, tester_state, 0) token_address2 = tester_token_address(private_keys, 100, tester_state, 1) unregistered_address = tester_token_address(private_keys, 100, tester_state, 2) contract_address1 = tester_registry.addToken(token_address1, sender=privatekey0) channel_manager_address1 = tester_registry.channelManagerByToken( token_address1, sender=privatekey0, ) assert channel_manager_address1 == contract_address1 with pytest.raises(tester.TransactionFailed): tester_registry.addToken(token_address1, sender=privatekey0) contract_address2 = tester_registry.addToken(token_address2, sender=privatekey0) channel_manager_address2 = tester_registry.channelManagerByToken( token_address2, sender=privatekey0, ) assert channel_manager_address2 == contract_address2 with pytest.raises(tester.TransactionFailed): tester_registry.channelManagerByToken( unregistered_address, sender=privatekey0, ) addresses = tester_registry.tokenAddresses(sender=privatekey0) assert len(addresses) == 2 assert addresses[0] == token_address1.encode('hex') assert addresses[1] == token_address2.encode('hex') assert len(tester_events) == 2 assert tester_events[0]['_event_type'] == 'TokenAdded' assert tester_events[0]['token_address'] == token_address1.encode('hex') assert tester_events[0]['channel_manager_address'] == contract_address1 assert tester_events[1]['_event_type'] == 'TokenAdded' assert tester_events[1]['token_address'] == token_address2.encode('hex') assert tester_events[1]['channel_manager_address'] == contract_address2
def test_close_valid_tranfer_different_token(tester_state, tester_nettingcontracts, token_amount, tester_events): """ Valid messages from a different channel must be rejected. """ pkey0, pkey1, nettingchannel = tester_nettingcontracts[0] from raiden.tests.fixtures.tester import ( tester_token, tester_token_address, ) private_keys = [pkey0, pkey1] other_token = tester_token( token_amount, private_keys, tester_state, tester_token_address(private_keys, token_amount, tester_state), tester_events, ) opened_block = nettingchannel.opened(sender=pkey0) nonce = 1 + (opened_block * (2**32)) direct_transfer_other_token = make_direct_transfer( nonce=nonce, token=other_token.address, ) address = privatekey_to_address(pkey0) sign_key = PrivateKey(pkey0) direct_transfer_other_token.sign(sign_key, address) direct_transfer_data = direct_transfer_other_token.encode() with pytest.raises(TransactionFailed): nettingchannel.close(direct_transfer_data, sender=pkey1)
def test_close_valid_tranfer_different_token( tester_chain, tester_nettingcontracts, token_amount, tester_events): """ Valid messages from a different channel must be rejected. """ pkey0, pkey1, nettingchannel = tester_nettingcontracts[0] from raiden.tests.fixtures.tester import ( tester_token, tester_token_address, ) private_keys = [pkey0, pkey1] other_token = tester_token( token_amount, private_keys, tester_chain, tester_token_address(private_keys, token_amount, tester_chain), tester_events, ) opened_block = nettingchannel.opened(sender=pkey0) nonce = 1 + (opened_block * (2 ** 32)) direct_transfer_other_token = make_direct_transfer( nonce=nonce, token=other_token.address, ) address = privatekey_to_address(pkey0) sign_key = PrivateKey(pkey0) direct_transfer_other_token.sign(sign_key, address) direct_transfer_other_token_hash = sha3(direct_transfer_other_token.encode()[:-65]) with pytest.raises(TransactionFailed): nettingchannel.close( direct_transfer_other_token.nonce, direct_transfer_other_token.transferred_amount, direct_transfer_other_token.locksroot, direct_transfer_other_token_hash, direct_transfer_other_token.signature, sender=pkey1, )