diff --git a/raiden_contracts/tests/fixtures/channel.py b/raiden_contracts/tests/fixtures/channel.py index c8cc64876..c984edfb3 100644 --- a/raiden_contracts/tests/fixtures/channel.py +++ b/raiden_contracts/tests/fixtures/channel.py @@ -170,8 +170,7 @@ def get( def close_and_update_channel( token_network: Contract, create_balance_proof: Callable, - create_balance_proof_closing_countersignature: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, ) -> Callable: def get( channel_identifier: int, @@ -203,11 +202,11 @@ def get( participant2_values.locksroot, additional_hash2, ) - balance_proof_close_signature_1 = create_balance_proof_closing_countersignature( - participant1, channel_identifier, *balance_proof_2 + balance_proof_close_signature_1 = create_balance_proof_countersignature( + participant1, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof_2 ) - balance_proof_update_signature_2 = create_balance_proof_updating_countersignature( - participant2, channel_identifier, *balance_proof_1 + balance_proof_update_signature_2 = create_balance_proof_countersignature( + participant2, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_1 ) token_network.functions.closeChannel( @@ -660,12 +659,13 @@ def get( @pytest.fixture(scope="session") -def create_balance_proof_closing_countersignature( +def create_balance_proof_countersignature( token_network: Contract, get_private_key: Callable ) -> Callable: def get( participant: HexAddress, channel_identifier: int, + msg_type: MessageTypeId, balance_hash: bytes, nonce: int, additional_hash: bytes, @@ -681,41 +681,7 @@ def get( _token_network.address, int(_token_network.functions.chain_id().call()), channel_identifier, - MessageTypeId.BALANCE_PROOF, - balance_hash, - nonce, - additional_hash, - original_signature, - v, - ) - return non_closing_signature - - return get - - -@pytest.fixture(scope="session") -def create_balance_proof_updating_countersignature( - token_network: Contract, get_private_key: Callable -) -> Callable: - def get( - participant: HexAddress, - channel_identifier: int, - balance_hash: bytes, - nonce: int, - additional_hash: bytes, - original_signature: bytes, - v: int = 27, - other_token_network: Optional[Contract] = None, - ) -> bytes: - _token_network = other_token_network or token_network - private_key = get_private_key(participant) - - non_closing_signature = sign_balance_proof_message( - private_key, - _token_network.address, - int(_token_network.functions.chain_id().call()), - channel_identifier, - MessageTypeId.BALANCE_PROOF_UPDATE, + msg_type, balance_hash, nonce, additional_hash, diff --git a/raiden_contracts/tests/test_channel_close.py b/raiden_contracts/tests/test_channel_close.py index 0de029fe2..932f13af9 100644 --- a/raiden_contracts/tests/test_channel_close.py +++ b/raiden_contracts/tests/test_channel_close.py @@ -5,7 +5,12 @@ from web3 import Web3 from web3.contract import Contract -from raiden_contracts.constants import TEST_SETTLE_TIMEOUT_MIN, ChannelEvent, ChannelState +from raiden_contracts.constants import ( + TEST_SETTLE_TIMEOUT_MIN, + ChannelEvent, + ChannelState, + MessageTypeId, +) from raiden_contracts.tests.utils import ( EMPTY_ADDITIONAL_HASH, EMPTY_BALANCE_HASH, @@ -107,7 +112,7 @@ def test_close_wrong_signature( channel_deposit: Callable, get_accounts: Callable, create_balance_proof: Callable, - create_balance_proof_closing_countersignature: Callable, + create_balance_proof_countersignature: Callable, ) -> None: """ Closing a channel with a balance proof of the third party should fail """ (A, B, C) = get_accounts(3) @@ -123,8 +128,8 @@ def test_close_wrong_signature( balance_proof = create_balance_proof( channel_identifier, C, transferred_amount, 0, nonce, locksroot ) - closing_signature_A = create_balance_proof_closing_countersignature( - A, channel_identifier, *balance_proof + closing_signature_A = create_balance_proof_countersignature( + A, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof ) with pytest.raises(TransactionFailed): @@ -201,7 +206,7 @@ def test_close_nonce_zero( token_network: Contract, create_channel: Callable, create_balance_proof: Callable, - create_balance_proof_closing_countersignature: Callable, + create_balance_proof_countersignature: Callable, event_handler: Callable, ) -> None: """ closeChannel with a balance proof with nonce zero should not change the channel state """ @@ -225,8 +230,8 @@ def test_close_nonce_zero( vals_B.nonce, vals_B.locksroot, ) - close_sig_A = create_balance_proof_closing_countersignature( - A, channel_identifier, *balance_proof_B + close_sig_A = create_balance_proof_countersignature( + A, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof_B ) ( @@ -277,7 +282,7 @@ def test_close_first_argument_is_for_partner_transfer( create_channel: Callable, get_accounts: Callable, create_balance_proof: Callable, - create_balance_proof_closing_countersignature: Callable, + create_balance_proof_countersignature: Callable, ) -> None: """ closeChannel fails on a self-submitted balance proof """ (A, B) = get_accounts(2) @@ -287,11 +292,11 @@ def test_close_first_argument_is_for_partner_transfer( # Create balance proofs balance_proof = create_balance_proof(channel_identifier, B) - closing_sig_A = create_balance_proof_closing_countersignature( - A, channel_identifier, *balance_proof + closing_sig_A = create_balance_proof_countersignature( + A, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof ) - closing_sig_B = create_balance_proof_closing_countersignature( - B, channel_identifier, *balance_proof + closing_sig_B = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof ) # closeChannel fails, if the provided balance proof is from the same participant who closes @@ -397,7 +402,7 @@ def test_close_channel_state( get_block: Callable, create_balance_proof: Callable, txn_cost: Callable, - create_balance_proof_closing_countersignature: Callable, + create_balance_proof_countersignature: Callable, ) -> None: """ Observe the effect of a successful closeChannel @@ -466,8 +471,8 @@ def test_close_channel_state( vals_B.nonce, vals_B.locksroot, ) - closing_sig_A = create_balance_proof_closing_countersignature( - A, channel_identifier, *balance_proof_B + closing_sig_A = create_balance_proof_countersignature( + A, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof_B ) txn_hash = token_network.functions.closeChannel( @@ -558,7 +563,7 @@ def test_close_replay_reopened_channel( create_channel: Callable, channel_deposit: Callable, create_balance_proof: Callable, - create_balance_proof_closing_countersignature: Callable, + create_balance_proof_countersignature: Callable, ) -> None: """ The same balance proof cannot close another channel between the same participants """ (A, B) = get_accounts(2) @@ -576,8 +581,8 @@ def test_close_replay_reopened_channel( nonce, values_B.locksroot, ) - closing_sig_A = create_balance_proof_closing_countersignature( - A, channel_identifier1, *balance_proof_B + closing_sig_A = create_balance_proof_countersignature( + A, channel_identifier1, MessageTypeId.BALANCE_PROOF, *balance_proof_B ) token_network.functions.closeChannel( channel_identifier1, B, A, *balance_proof_B, closing_sig_A @@ -614,8 +619,8 @@ def test_close_replay_reopened_channel( nonce, values_B.locksroot, ) - closing_sig_A2 = create_balance_proof_closing_countersignature( - A, channel_identifier2, *balance_proof_B2 + closing_sig_A2 = create_balance_proof_countersignature( + A, channel_identifier2, MessageTypeId.BALANCE_PROOF, *balance_proof_B2 ) token_network.functions.closeChannel( channel_identifier2, B, A, *balance_proof_B2, closing_sig_A2 @@ -629,7 +634,7 @@ def test_close_channel_event( channel_deposit: Callable, create_balance_proof: Callable, event_handler: Callable, - create_balance_proof_closing_countersignature: Callable, + create_balance_proof_countersignature: Callable, ) -> None: """ A successful closeChannel call produces a CLOSED event """ ev_handler = event_handler(token_network) @@ -641,8 +646,8 @@ def test_close_channel_event( balance_proof = create_balance_proof( channel_identifier, B, transferred_amount=5, locked_amount=0, nonce=3 ) - close_sig = create_balance_proof_closing_countersignature( - A, channel_identifier, *balance_proof + close_sig = create_balance_proof_countersignature( + A, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof ) txn_hash = token_network.functions.closeChannel( diff --git a/raiden_contracts/tests/test_channel_settle.py b/raiden_contracts/tests/test_channel_settle.py index c2dc0a9bc..30f01e518 100644 --- a/raiden_contracts/tests/test_channel_settle.py +++ b/raiden_contracts/tests/test_channel_settle.py @@ -6,7 +6,12 @@ from web3 import Web3 from web3.contract import Contract -from raiden_contracts.constants import TEST_SETTLE_TIMEOUT_MIN, ChannelEvent, ChannelState +from raiden_contracts.constants import ( + TEST_SETTLE_TIMEOUT_MIN, + ChannelEvent, + ChannelState, + MessageTypeId, +) from raiden_contracts.tests.fixtures.channel import call_settle from raiden_contracts.tests.utils import ( EMPTY_ADDITIONAL_HASH, @@ -160,7 +165,7 @@ def test_settle_single_direct_transfer_for_closing_party( create_channel: Callable, channel_deposit: Callable, create_balance_proof: Callable, - create_balance_proof_closing_countersignature: Callable, + create_balance_proof_countersignature: Callable, ) -> None: """ Test settle of a channel with one direct transfer to the participant that called close. @@ -184,8 +189,8 @@ def test_settle_single_direct_transfer_for_closing_party( 1, LOCKSROOT_OF_NO_LOCKS, ) - closing_sig_A = create_balance_proof_closing_countersignature( - A, channel_identifier, *balance_proof_B + closing_sig_A = create_balance_proof_countersignature( + A, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof_B ) token_network.functions.closeChannel( channel_identifier, B, A, *balance_proof_B, closing_sig_A @@ -230,7 +235,7 @@ def test_settle_single_direct_transfer_for_counterparty( create_channel: Callable, channel_deposit: Callable, create_balance_proof: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, create_close_signature_for_no_balance_proof: Callable, ) -> None: """ Test settle of a channel with one direct transfer to the participant @@ -267,8 +272,8 @@ def test_settle_single_direct_transfer_for_counterparty( LOCKSROOT_OF_NO_LOCKS, ) - balance_proof_update_signature_B = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_A + balance_proof_update_signature_B = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_A ) token_network.functions.updateNonClosingBalanceProof( channel_identifier, A, B, *balance_proof_A, balance_proof_update_signature_B @@ -571,8 +576,7 @@ def test_settle_channel_event( create_channel: Callable, channel_deposit: Callable, create_balance_proof: Callable, - create_balance_proof_closing_countersignature: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, event_handler: Callable, ) -> None: """ A successful settleChannel() call causes a SETTLED event """ @@ -586,11 +590,11 @@ def test_settle_channel_event( balance_proof_A = create_balance_proof(channel_identifier, A, 10, 0, 1, LOCKSROOT_OF_NO_LOCKS) balance_proof_B = create_balance_proof(channel_identifier, B, 5, 0, 3, LOCKSROOT_OF_NO_LOCKS) - balance_proof_update_signature_B = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_A + balance_proof_update_signature_B = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_A ) - close_sig_A = create_balance_proof_closing_countersignature( - A, channel_identifier, *balance_proof_B + close_sig_A = create_balance_proof_countersignature( + A, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof_B ) token_network.functions.closeChannel( diff --git a/raiden_contracts/tests/test_channel_update_transfer.py b/raiden_contracts/tests/test_channel_update_transfer.py index 9b66e5c25..c06d8b2fa 100644 --- a/raiden_contracts/tests/test_channel_update_transfer.py +++ b/raiden_contracts/tests/test_channel_update_transfer.py @@ -11,6 +11,7 @@ TEST_SETTLE_TIMEOUT_MIN, ChannelEvent, ChannelState, + MessageTypeId, ) from raiden_contracts.tests.utils import ( EMPTY_ADDITIONAL_HASH, @@ -28,7 +29,7 @@ def test_update_call( create_channel: Callable, channel_deposit: Callable, create_balance_proof: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, create_close_signature_for_no_balance_proof: Callable, ) -> None: """ Call updateNonClosingBalanceProof() with various wrong arguments """ @@ -48,8 +49,8 @@ def test_update_call( ).call_and_transact({"from": A}) balance_proof_A = create_balance_proof(channel_identifier, A, 10, 0, 5, fake_bytes(32, "02")) - balance_proof_update_signature_B = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_A + balance_proof_update_signature_B = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_A ) (balance_hash, nonce, additional_hash, closing_signature) = balance_proof_A @@ -135,7 +136,7 @@ def test_update_nonexistent_fail( get_accounts: Callable, token_network: Contract, create_balance_proof: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, ) -> None: """ updateNonClosingBalanceProof() on a not-yet openned channel should fail """ (A, B, C) = get_accounts(3) @@ -148,8 +149,8 @@ def test_update_nonexistent_fail( assert state == ChannelState.NONEXISTENT balance_proof_A = create_balance_proof(channel_identifier, A, 10, 0, 5, fake_bytes(32, "02")) - balance_proof_update_signature_B = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_A + balance_proof_update_signature_B = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_A ) with pytest.raises(TransactionFailed): @@ -164,7 +165,7 @@ def test_update_notclosed_fail( create_channel: Callable, channel_deposit: Callable, create_balance_proof: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, ) -> None: """ updateNonClosingBalanceProof() on an Opened channel should fail """ (A, B, C) = get_accounts(3) @@ -172,8 +173,8 @@ def test_update_notclosed_fail( channel_deposit(channel_identifier, A, 25, B) balance_proof_A = create_balance_proof(channel_identifier, A, 10, 0, 5, fake_bytes(32, "02")) - balance_proof_update_signature_B = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_A + balance_proof_update_signature_B = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_A ) (settle_block_number, state) = token_network.functions.getChannelInfo( @@ -194,8 +195,7 @@ def test_update_wrong_nonce_fail( channel_deposit: Callable, get_accounts: Callable, create_balance_proof: Callable, - create_balance_proof_closing_countersignature: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, update_state_tests: Callable, ) -> None: (A, B, Delegate) = get_accounts(3) @@ -205,11 +205,11 @@ def test_update_wrong_nonce_fail( channel_deposit(channel_identifier, A, deposit_A, B) balance_proof_A = create_balance_proof(channel_identifier, A, 10, 0, 5, fake_bytes(32, "02")) balance_proof_B = create_balance_proof(channel_identifier, B, 5, 0, 3, fake_bytes(32, "02")) - closing_sig_A = create_balance_proof_closing_countersignature( - A, channel_identifier, *balance_proof_B + closing_sig_A = create_balance_proof_countersignature( + A, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof_B ) - balance_proof_update_signature_B = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_A + balance_proof_update_signature_B = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_A ) txn_hash1 = token_network.functions.closeChannel( channel_identifier, B, A, *balance_proof_B, closing_sig_A @@ -236,8 +236,8 @@ def test_update_wrong_nonce_fail( channel_identifier, A, 10, 0, 4, fake_bytes(32, "02") ) - balance_proof_update_signature_B = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_A_lower_nonce + balance_proof_update_signature_B = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_A_lower_nonce ) with pytest.raises(TransactionFailed): token_network.functions.updateNonClosingBalanceProof( @@ -259,7 +259,7 @@ def test_update_wrong_signatures( channel_deposit: Callable, get_accounts: Callable, create_balance_proof: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, create_close_signature_for_no_balance_proof: Callable, ) -> None: """ updateNonClosingBalanceProof() should fail with wrong signatures """ @@ -272,11 +272,11 @@ def test_update_wrong_signatures( channel_identifier, A, 10, 0, 5, fake_bytes(32, "02"), signer=C ) - balance_proof_update_signature_B = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_A + balance_proof_update_signature_B = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_A ) - balance_proof_update_signature_B_fake = create_balance_proof_updating_countersignature( - C, channel_identifier, *balance_proof_A + balance_proof_update_signature_B_fake = create_balance_proof_countersignature( + C, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_A ) # Close the channel so updateNonClosingBalanceProof() is possible @@ -315,8 +315,7 @@ def test_update_channel_state( channel_deposit: Callable, get_accounts: Callable, create_balance_proof: Callable, - create_balance_proof_closing_countersignature: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, update_state_tests: Callable, txn_cost: Callable, ) -> None: @@ -328,11 +327,11 @@ def test_update_channel_state( channel_deposit(channel_identifier, A, deposit_A, B) balance_proof_A = create_balance_proof(channel_identifier, A, 10, 0, 5, fake_bytes(32, "02")) balance_proof_B = create_balance_proof(channel_identifier, B, 5, 0, 3, fake_bytes(32, "02")) - closing_sig_A = create_balance_proof_closing_countersignature( - A, channel_identifier, *balance_proof_B + closing_sig_A = create_balance_proof_countersignature( + A, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof_B ) - balance_proof_update_signature_B = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_A + balance_proof_update_signature_B = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_A ) txn_hash1 = token_network.functions.closeChannel( @@ -373,7 +372,7 @@ def test_update_channel_fail_no_offchain_transfers( token_network: Contract, create_channel: Callable, create_balance_proof: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, create_close_signature_for_no_balance_proof: Callable, ) -> None: """ Calls to updateNonClosingBalanceProof() fail with the zero nonce """ @@ -381,8 +380,8 @@ def test_update_channel_fail_no_offchain_transfers( channel_identifier = create_channel(A, B)[0] balance_proof_A = create_balance_proof(channel_identifier, A, 0, 0, 0) - balance_proof_update_signature_B = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_A + balance_proof_update_signature_B = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_A ) closing_sig = create_close_signature_for_no_balance_proof(A, channel_identifier) @@ -421,8 +420,7 @@ def test_update_not_allowed_after_settlement_period( channel_deposit: Callable, get_accounts: Callable, create_balance_proof: Callable, - create_balance_proof_closing_countersignature: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, web3: Web3, ) -> None: """ updateNonClosingBalanceProof cannot be called after the settlement period. """ @@ -433,11 +431,11 @@ def test_update_not_allowed_after_settlement_period( channel_deposit(channel_identifier, A, deposit_A, B) balance_proof_A = create_balance_proof(channel_identifier, A, 10, 0, 5, fake_bytes(32, "02")) balance_proof_B = create_balance_proof(channel_identifier, B, 5, 0, 3, fake_bytes(32, "02")) - closing_sig_A = create_balance_proof_closing_countersignature( - A, channel_identifier, *balance_proof_B + closing_sig_A = create_balance_proof_countersignature( + A, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof_B ) - balance_proof_update_signature_B = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_A + balance_proof_update_signature_B = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_A ) token_network.functions.closeChannel( channel_identifier, B, A, *balance_proof_B, closing_sig_A @@ -455,8 +453,7 @@ def test_update_not_allowed_for_the_closing_address( channel_deposit: Callable, get_accounts: Callable, create_balance_proof: Callable, - create_balance_proof_closing_countersignature: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, ) -> None: """ Closing address cannot call updateNonClosingBalanceProof. """ (A, B, M) = get_accounts(3) @@ -467,16 +464,16 @@ def test_update_not_allowed_for_the_closing_address( # Some balance proof from B balance_proof_B_0 = create_balance_proof(channel_identifier, B, 5, 0, 3, fake_bytes(32, "02")) - closing_sig_A_0 = create_balance_proof_closing_countersignature( - A, channel_identifier, *balance_proof_B_0 + closing_sig_A_0 = create_balance_proof_countersignature( + A, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof_B_0 ) # Later balance proof, higher transferred amount, higher nonce balance_proof_B_1 = create_balance_proof(channel_identifier, B, 10, 0, 4, fake_bytes(32, "02")) # B's signature on the update message is valid - balance_proof_update_signature_B = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_B_1 + balance_proof_update_signature_B = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_B_1 ) # A closes with the first balance proof @@ -506,7 +503,7 @@ def test_update_invalid_balance_proof_arguments( channel_deposit: Callable, get_accounts: Callable, create_balance_proof: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, create_close_signature_for_no_balance_proof: Callable, ) -> None: """ updateNonClosingBalanceProof() should fail on balance proofs with various wrong params """ @@ -538,8 +535,8 @@ def test_update_invalid_balance_proof_arguments( ) # And a valid nonclosing_signature - valid_balance_proof_update_signature = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_valid + valid_balance_proof_update_signature = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_valid ) # We test invalid balance proof arguments with valid signatures @@ -557,9 +554,10 @@ def test_update_invalid_balance_proof_arguments( ) ) - signature_invalid_token_network = create_balance_proof_updating_countersignature( + signature_invalid_token_network = create_balance_proof_countersignature( B, channel_identifier, + MessageTypeId.BALANCE_PROOF_UPDATE, balance_proof_valid.balance_hash, balance_proof_valid.nonce, balance_proof_valid.additional_hash, @@ -580,9 +578,10 @@ def test_update_invalid_balance_proof_arguments( *create_balance_proof(channel_identifier, C, 10, 0, 2, fake_bytes(32, "02")) ) - signature_invalid_channel_participant = create_balance_proof_updating_countersignature( + signature_invalid_channel_participant = create_balance_proof_countersignature( B, channel_identifier, + MessageTypeId.BALANCE_PROOF_UPDATE, balance_proof_valid.balance_hash, balance_proof_valid.nonce, balance_proof_valid.additional_hash, @@ -602,9 +601,10 @@ def test_update_invalid_balance_proof_arguments( *create_balance_proof(channel_identifier + 1, A, 10, 0, 2, fake_bytes(32, "02")) ) - signature_invalid_channel_identifier = create_balance_proof_updating_countersignature( + signature_invalid_channel_identifier = create_balance_proof_countersignature( B, channel_identifier + 1, + MessageTypeId.BALANCE_PROOF_UPDATE, balance_proof_valid.balance_hash, balance_proof_valid.nonce, balance_proof_valid.additional_hash, @@ -619,9 +619,10 @@ def test_update_invalid_balance_proof_arguments( signature_invalid_channel_identifier, ).call({"from": B}) - signature_invalid_balance_hash = create_balance_proof_updating_countersignature( + signature_invalid_balance_hash = create_balance_proof_countersignature( B, channel_identifier, + MessageTypeId.BALANCE_PROOF_UPDATE, balance_proof_valid.balance_hash[::-1], balance_proof_valid.nonce, balance_proof_valid.additional_hash, @@ -639,9 +640,10 @@ def test_update_invalid_balance_proof_arguments( signature_invalid_balance_hash, ).call({"from": B}) - signature_invalid_nonce = create_balance_proof_updating_countersignature( + signature_invalid_nonce = create_balance_proof_countersignature( B, channel_identifier, + MessageTypeId.BALANCE_PROOF_UPDATE, balance_proof_valid.balance_hash, 1, balance_proof_valid.additional_hash, @@ -660,9 +662,10 @@ def test_update_invalid_balance_proof_arguments( signature_invalid_nonce, ).call({"from": B}) - signature_invalid_additional_hash = create_balance_proof_updating_countersignature( + signature_invalid_additional_hash = create_balance_proof_countersignature( B, channel_identifier, + MessageTypeId.BALANCE_PROOF_UPDATE, balance_proof_valid.balance_hash, balance_proof_valid.nonce, balance_proof_valid.additional_hash[::-1], @@ -681,9 +684,10 @@ def test_update_invalid_balance_proof_arguments( signature_invalid_additional_hash, ).call({"from": B}) - signature_invalid_closing_signature = create_balance_proof_updating_countersignature( + signature_invalid_closing_signature = create_balance_proof_countersignature( B, channel_identifier, + MessageTypeId.BALANCE_PROOF_UPDATE, balance_proof_valid.balance_hash, balance_proof_valid.nonce, balance_proof_valid.additional_hash, @@ -716,7 +720,7 @@ def test_update_signature_on_invalid_arguments( channel_deposit: Callable, get_accounts: Callable, create_balance_proof: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, create_close_signature_for_no_balance_proof: Callable, ) -> None: @@ -750,9 +754,10 @@ def test_update_signature_on_invalid_arguments( ) ) - signature_invalid_token_network_address = create_balance_proof_updating_countersignature( + signature_invalid_token_network_address = create_balance_proof_countersignature( B, channel_identifier, + MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_valid, other_token_network=token_network_test_utils, # invalid token_network_address ) @@ -761,9 +766,10 @@ def test_update_signature_on_invalid_arguments( channel_identifier, A, B, *balance_proof_valid, signature_invalid_token_network_address ).call({"from": B}) - signature_invalid_participant = create_balance_proof_updating_countersignature( + signature_invalid_participant = create_balance_proof_countersignature( C, # invalid signer channel_identifier, + MessageTypeId.BALANCE_PROOF_UPDATE, balance_proof_valid.balance_hash, balance_proof_valid.nonce, balance_proof_valid.additional_hash, @@ -774,9 +780,10 @@ def test_update_signature_on_invalid_arguments( channel_identifier, A, B, *balance_proof_valid, signature_invalid_participant ).call({"from": B}) - signature_invalid_channel_identifier = create_balance_proof_updating_countersignature( + signature_invalid_channel_identifier = create_balance_proof_countersignature( B, channel_identifier + 1, # invalid channel_identifier + MessageTypeId.BALANCE_PROOF_UPDATE, balance_proof_valid.balance_hash, balance_proof_valid.nonce, balance_proof_valid.additional_hash, @@ -787,9 +794,10 @@ def test_update_signature_on_invalid_arguments( channel_identifier, A, B, *balance_proof_valid, signature_invalid_channel_identifier ).call({"from": B}) - signature_invalid_balance_hash = create_balance_proof_updating_countersignature( + signature_invalid_balance_hash = create_balance_proof_countersignature( B, channel_identifier, + MessageTypeId.BALANCE_PROOF_UPDATE, balance_proof_valid.balance_hash[::-1], # invalid balance_hash balance_proof_valid.nonce, balance_proof_valid.additional_hash, @@ -800,9 +808,10 @@ def test_update_signature_on_invalid_arguments( channel_identifier, A, B, *balance_proof_valid, signature_invalid_balance_hash ).call({"from": B}) - signature_invalid_nonce = create_balance_proof_updating_countersignature( + signature_invalid_nonce = create_balance_proof_countersignature( B, channel_identifier, + MessageTypeId.BALANCE_PROOF_UPDATE, balance_proof_valid.balance_hash, 1, # invalid nonce balance_proof_valid.additional_hash, @@ -813,9 +822,10 @@ def test_update_signature_on_invalid_arguments( channel_identifier, A, B, *balance_proof_valid, signature_invalid_nonce ).call({"from": B}) - signature_invalid_additional_hash = create_balance_proof_updating_countersignature( + signature_invalid_additional_hash = create_balance_proof_countersignature( B, channel_identifier, + MessageTypeId.BALANCE_PROOF_UPDATE, balance_proof_valid.balance_hash, balance_proof_valid.nonce, b"\x00" * 32, # invalid additional_hash @@ -826,9 +836,10 @@ def test_update_signature_on_invalid_arguments( channel_identifier, A, B, *balance_proof_valid, signature_invalid_additional_hash ).call({"from": B}) - signature_invalid_closing_signature = create_balance_proof_updating_countersignature( + signature_invalid_closing_signature = create_balance_proof_countersignature( B, channel_identifier, + MessageTypeId.BALANCE_PROOF_UPDATE, balance_proof_valid.balance_hash, balance_proof_valid.nonce, balance_proof_valid.additional_hash, @@ -840,8 +851,8 @@ def test_update_signature_on_invalid_arguments( ).call({"from": B}) # Call with same balance_proof and signature on valid arguments works - balance_proof_update_signature = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_valid + balance_proof_update_signature = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_valid ) token_network.functions.updateNonClosingBalanceProof( channel_identifier, A, B, *balance_proof_valid, balance_proof_update_signature @@ -855,7 +866,7 @@ def test_update_replay_reopened_channel( create_channel: Callable, channel_deposit: Callable, create_balance_proof: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, create_close_signature_for_no_balance_proof: Callable, ) -> None: """ updateNonClosingBalanceProof() should refuse a balance proof with a stale channel id """ @@ -874,8 +885,8 @@ def test_update_replay_reopened_channel( nonce_B, values_B.locksroot, ) - balance_proof_update_signature_A = create_balance_proof_updating_countersignature( - A, channel_identifier1, *balance_proof_B + balance_proof_update_signature_A = create_balance_proof_countersignature( + A, channel_identifier1, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_B ) closing_sig = create_close_signature_for_no_balance_proof(B, channel_identifier1) @@ -943,8 +954,8 @@ def test_update_replay_reopened_channel( nonce_B, values_B.locksroot, ) - balance_proof_update_signature_A2 = create_balance_proof_updating_countersignature( - A, channel_identifier2, *balance_proof_B2 + balance_proof_update_signature_A2 = create_balance_proof_countersignature( + A, channel_identifier2, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_B2 ) token_network.functions.updateNonClosingBalanceProof( @@ -958,8 +969,7 @@ def test_update_channel_event( create_channel: Callable, channel_deposit: Callable, create_balance_proof: Callable, - create_balance_proof_closing_countersignature: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, event_handler: Callable, ) -> None: """ Successful updateNonClosingBalanceProof() emit BALANCE_PROOF_UPDATED events """ @@ -972,12 +982,12 @@ def test_update_channel_event( channel_deposit(channel_identifier, A, deposit_A, B) channel_deposit(channel_identifier, B, deposit_B, A) balance_proof_B = create_balance_proof(channel_identifier, B, 5, 0, 3) - closing_sig_A = create_balance_proof_closing_countersignature( - A, channel_identifier, *balance_proof_B + closing_sig_A = create_balance_proof_countersignature( + A, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof_B ) balance_proof_A = create_balance_proof(channel_identifier, A, 2, 0, 1) - balance_proof_update_signature_B = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_A + balance_proof_update_signature_B = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_A ) token_network.functions.closeChannel( @@ -996,8 +1006,8 @@ def test_update_channel_event( # Test event for second balance proof update balance_proof_A2 = create_balance_proof(channel_identifier, A, 4, 0, 2) - balance_proof_update_signature_B2 = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_A2 + balance_proof_update_signature_B2 = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_A2 ) txn_hash = token_network.functions.updateNonClosingBalanceProof( channel_identifier, A, B, *balance_proof_A2, balance_proof_update_signature_B2 diff --git a/raiden_contracts/tests/test_monitoring_service.py b/raiden_contracts/tests/test_monitoring_service.py index d7b30ac97..ebedb1f87 100644 --- a/raiden_contracts/tests/test_monitoring_service.py +++ b/raiden_contracts/tests/test_monitoring_service.py @@ -11,6 +11,7 @@ from raiden_contracts.constants import ( LOCKSROOT_OF_NO_LOCKS, TEST_SETTLE_TIMEOUT_MIN, + MessageTypeId, MonitoringServiceEvent, ) from raiden_contracts.tests.utils import SERVICE_DEPOSIT @@ -41,8 +42,7 @@ def setup_monitor_data( deposit_to_udc: Callable, create_channel: Callable, create_balance_proof: Callable, - create_balance_proof_closing_countersignature: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, token_network: Contract, ms_address: HexAddress, get_private_key: Callable, @@ -62,11 +62,11 @@ def f(monitoring_service_contract: Contract) -> Dict: ) # Add signatures by non_closing_participant - closing_signature_A = create_balance_proof_closing_countersignature( - A, channel_identifier, *balance_proof_A + closing_signature_A = create_balance_proof_countersignature( + A, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof_A ) - non_closing_signature_B = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_B + non_closing_signature_B = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_B ) reward_proof_signature = sign_reward_proof( privatekey=get_private_key(B), diff --git a/raiden_contracts/tests/test_print_gas.py b/raiden_contracts/tests/test_print_gas.py index 3d14ec9a2..e048f069c 100644 --- a/raiden_contracts/tests/test_print_gas.py +++ b/raiden_contracts/tests/test_print_gas.py @@ -14,6 +14,7 @@ CONTRACT_USER_DEPOSIT, TEST_SETTLE_TIMEOUT_MAX, TEST_SETTLE_TIMEOUT_MIN, + MessageTypeId, ) from raiden_contracts.contract_manager import gas_measurements from raiden_contracts.tests.utils.constants import ( @@ -146,8 +147,7 @@ def print_gas_channel_cycle( get_accounts: Callable, print_gas: Callable, create_balance_proof: Callable, - create_balance_proof_closing_countersignature: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, ) -> None: """ Abusing pytest to print gas costs of TokenNetwork's operations """ (A, B, C, D) = get_accounts(4) @@ -179,12 +179,12 @@ def print_gas_channel_cycle( balance_proof_A = create_balance_proof( channel_identifier, A, 10, locked_amount1, 5, locksroot1 ) - balance_proof_update_signature_B = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_A + balance_proof_update_signature_B = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_A ) balance_proof_B = create_balance_proof(channel_identifier, B, 5, locked_amount2, 3, locksroot2) - closing_sig_A = create_balance_proof_closing_countersignature( - A, channel_identifier, *balance_proof_B + closing_sig_A = create_balance_proof_countersignature( + A, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof_B ) for lock in pending_transfers_tree1.unlockable: @@ -243,8 +243,7 @@ def print_gas_monitoring_service( get_accounts: Callable, create_channel: Callable, create_balance_proof: Callable, - create_balance_proof_closing_countersignature: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, service_registry: Contract, custom_token: Contract, deposit_to_udc: Callable, @@ -269,12 +268,12 @@ def print_gas_monitoring_service( # create balance and reward proofs balance_proof_A = create_balance_proof(channel_identifier, B, transferred_amount=10, nonce=1) - closing_sig_A = create_balance_proof_closing_countersignature( - A, channel_identifier, *balance_proof_A + closing_sig_A = create_balance_proof_countersignature( + A, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof_A ) balance_proof_B = create_balance_proof(channel_identifier, A, transferred_amount=20, nonce=2) - non_closing_signature_B = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_B + non_closing_signature_B = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_B ) reward_proof_signature = sign_reward_proof( privatekey=get_private_key(B), diff --git a/raiden_contracts/tests/unit/test_unit_signatures.py b/raiden_contracts/tests/unit/test_unit_signatures.py index 3aababacd..285d2f3a6 100644 --- a/raiden_contracts/tests/unit/test_unit_signatures.py +++ b/raiden_contracts/tests/unit/test_unit_signatures.py @@ -113,7 +113,7 @@ def test_recover_address_from_balance_proof( def test_recover_address_from_balance_proof_update( token_network_test_signatures: Contract, create_balance_proof: Callable, - create_balance_proof_updating_countersignature: Callable, + create_balance_proof_countersignature: Callable, get_accounts: Callable, ) -> None: """ TokenNetwork can recover the signer's address from a balance proof update @@ -130,19 +130,23 @@ def test_recover_address_from_balance_proof_update( balance_proof = create_balance_proof( channel_identifier, A, other_token_network=other_token_network ) - balance_proof_update_signature = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof, other_token_network=other_token_network + balance_proof_update_signature = create_balance_proof_countersignature( + B, + channel_identifier, + MessageTypeId.BALANCE_PROOF_UPDATE, + *balance_proof, + other_token_network=other_token_network, ) - sig_wrong_token_network = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof + sig_wrong_token_network = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof ) balance_proof_signed_B = create_balance_proof( channel_identifier, B, other_token_network=other_token_network ) - balance_proof_update_signature_wrong_signer = create_balance_proof_updating_countersignature( - B, channel_identifier, *balance_proof_signed_B + balance_proof_update_signature_wrong_signer = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_signed_B ) assert ( @@ -179,7 +183,7 @@ def test_recover_address_from_balance_proof_update( def test_recover_address_from_balance_proof_close( token_network_test_signatures: Contract, create_balance_proof: Callable, - create_balance_proof_closing_countersignature: Callable, + create_balance_proof_countersignature: Callable, get_accounts: Callable, ) -> None: """ TokenNetwork can recover the signer's address from a closing proof @@ -196,19 +200,23 @@ def test_recover_address_from_balance_proof_close( balance_proof = create_balance_proof( channel_identifier, A, other_token_network=other_token_network ) - balance_proof_update_signature = create_balance_proof_closing_countersignature( - B, channel_identifier, *balance_proof, other_token_network=other_token_network + balance_proof_update_signature = create_balance_proof_countersignature( + B, + channel_identifier, + MessageTypeId.BALANCE_PROOF, + *balance_proof, + other_token_network=other_token_network, ) - sig_wrong_token_network = create_balance_proof_closing_countersignature( - B, channel_identifier, *balance_proof + sig_wrong_token_network = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof ) balance_proof_signed_B = create_balance_proof( channel_identifier, B, other_token_network=other_token_network ) - balance_proof_update_signature_wrong_signer = create_balance_proof_closing_countersignature( - B, channel_identifier, *balance_proof_signed_B + balance_proof_update_signature_wrong_signer = create_balance_proof_countersignature( + B, channel_identifier, MessageTypeId.BALANCE_PROOF, *balance_proof_signed_B ) assert (