def test_cooperative_settle_channel_event( get_accounts: Callable, token_network: Contract, create_channel: Callable, channel_deposit: Callable, create_cooperative_settle_signatures: Callable, event_handler: Callable, ) -> None: ev_handler = event_handler(token_network) (A, B) = get_accounts(2) deposit_A = 10 balance_A = 2 balance_B = 8 channel_identifier = create_channel(A, B)[0] channel_deposit(channel_identifier, A, deposit_A, B) (signature_A, signature_B) = create_cooperative_settle_signatures( [A, B], channel_identifier, B, balance_B, A, balance_A) txn_hash = token_network.functions.cooperativeSettle( channel_identifier, B, balance_B, A, balance_A, signature_B, signature_A).call_and_transact({"from": B}) ev_handler.add( txn_hash, ChannelEvent.SETTLED, check_channel_settled(channel_identifier, balance_B, balance_A), ) ev_handler.check()
def test_update_channel_event( web3, get_accounts, token_network, create_channel, channel_deposit, create_cooperative_settle_signatures, event_handler ): ev_handler = event_handler(token_network) (A, B) = get_accounts(2) deposit_A = 10 balance_A = 2 balance_B = 8 channel_identifier = create_channel(A, B) channel_deposit(channel_identifier, A, deposit_A) (signature_A, signature_B) = create_cooperative_settle_signatures( [A, B], channel_identifier, B, balance_B, A, balance_A ) txn_hash = token_network.transact({'from': B}).cooperativeSettle( channel_identifier, B, balance_B, A, balance_A, signature_B, signature_A ) ev_handler.add(txn_hash, E_CHANNEL_SETTLED, check_channel_settled(channel_identifier)) ev_handler.check()
def test_settle_channel_event(web3, get_accounts, token_network, create_channel, channel_deposit, create_balance_proof, create_balance_proof_update_signature, event_handler): ev_handler = event_handler(token_network) (A, B) = get_accounts(2) deposit_A = 10 settle_timeout = SETTLE_TIMEOUT_MIN locksroot = fake_hex(32, '00') channel_identifier = create_channel(A, B)[0] channel_deposit(A, deposit_A, B) balance_proof_A = create_balance_proof(channel_identifier, A, 10, 0, 1, locksroot) balance_proof_B = create_balance_proof(channel_identifier, B, 5, 0, 3, locksroot) balance_proof_update_signature_B = create_balance_proof_update_signature( B, channel_identifier, *balance_proof_A) token_network.functions.closeChannel(B, *balance_proof_B).transact( {'from': A}) token_network.functions.updateNonClosingBalanceProof( A, B, *balance_proof_A, balance_proof_update_signature_B).transact({'from': B}) web3.testing.mine(settle_timeout) txn_hash = token_network.functions.settleChannel( A, 10, 0, locksroot, B, 5, 0, locksroot).transact({'from': A}) ev_handler.add(txn_hash, EVENT_CHANNEL_SETTLED, check_channel_settled(channel_identifier, 5, 5)) ev_handler.check()
def test_settle_channel_event( web3, get_accounts, token_network, create_channel, channel_deposit, create_balance_proof, create_balance_proof_update_signature, event_handler, ): ev_handler = event_handler(token_network) (A, B) = get_accounts(2) deposit_A = 10 settle_timeout = TEST_SETTLE_TIMEOUT_MIN channel_identifier = create_channel(A, B)[0] channel_deposit(channel_identifier, A, deposit_A, B) balance_proof_A = create_balance_proof(channel_identifier, A, 10, 0, 1, EMPTY_LOCKSROOT) balance_proof_B = create_balance_proof(channel_identifier, B, 5, 0, 3, EMPTY_LOCKSROOT) balance_proof_update_signature_B = create_balance_proof_update_signature( B, channel_identifier, *balance_proof_A, ) token_network.functions.closeChannel( channel_identifier, B, *balance_proof_B, ).transact({'from': A}) token_network.functions.updateNonClosingBalanceProof( channel_identifier, A, B, *balance_proof_A, balance_proof_update_signature_B, ).transact({'from': B}) web3.testing.mine(settle_timeout) txn_hash = token_network.functions.settleChannel( channel_identifier, B, 5, 0, EMPTY_LOCKSROOT, A, 10, 0, EMPTY_LOCKSROOT, ).transact({'from': A}) ev_handler.add(txn_hash, ChannelEvent.SETTLED, check_channel_settled( channel_identifier, 5, 5, )) ev_handler.check()
def test_cooperative_settle_channel_event( get_accounts: Callable, token_network: Contract, create_channel: Callable, channel_deposit: Callable, create_withdraw_signatures: Callable, event_handler: Callable, ) -> None: ev_handler = event_handler(token_network) (A, B) = get_accounts(2) deposit_A = 10 balance_A = 2 balance_B = 8 channel_identifier = create_channel(A, B)[0] channel_deposit(channel_identifier, A, deposit_A, B) (signature_A1, signature_B1) = create_withdraw_signatures([A, B], channel_identifier, A, balance_A, EXPIRATION) (signature_A2, signature_B2) = create_withdraw_signatures([A, B], channel_identifier, B, balance_B, EXPIRATION) txn_hash = call_and_transact( token_network.functions.cooperativeSettle( channel_identifier, (B, balance_B, EXPIRATION, signature_B2, signature_A2), (A, balance_A, EXPIRATION, signature_A1, signature_B1), ), {"from": B}, ) withdraw_events = token_network.events.ChannelWithdraw.getLogs() assert any( map(check_withdraw_2(channel_identifier, A, balance_A), withdraw_events)) assert any( map(check_withdraw_2(channel_identifier, B, balance_B), withdraw_events)) ev_handler.add( txn_hash, ChannelEvent.SETTLED, check_channel_settled( channel_identifier, B, balance_B, EMPTY_LOCKSROOT, A, balance_A, EMPTY_LOCKSROOT, ), ) ev_handler.check()
def test_settle_channel_event( web3: Web3, get_accounts: Callable, token_network: Contract, create_channel: Callable, channel_deposit: Callable, create_balance_proof: Callable, create_balance_proof_countersignature: Callable, event_handler: Callable, ) -> None: """ A successful settleChannel() call causes a SETTLED event """ ev_handler = event_handler(token_network) (A, B) = get_accounts(2) deposit_A = 10 settle_timeout = TEST_SETTLE_TIMEOUT_MIN channel_identifier = create_channel(A, B)[0] channel_deposit(channel_identifier, A, deposit_A, B) 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_countersignature( B, channel_identifier, MessageTypeId.BALANCE_PROOF_UPDATE, *balance_proof_A) close_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, close_sig_A).call_and_transact({"from": A}) token_network.functions.updateNonClosingBalanceProof( channel_identifier, A, B, *balance_proof_A, balance_proof_update_signature_B).call_and_transact({"from": B}) web3.testing.mine(settle_timeout + 1) txn_hash = token_network.functions.settleChannel( channel_identifier=channel_identifier, participant1=B, participant1_transferred_amount=5, participant1_locked_amount=0, participant1_locksroot=LOCKSROOT_OF_NO_LOCKS, participant2=A, participant2_transferred_amount=10, participant2_locked_amount=0, participant2_locksroot=LOCKSROOT_OF_NO_LOCKS, ).call_and_transact({"from": A}) ev_handler.add(txn_hash, ChannelEvent.SETTLED, check_channel_settled(channel_identifier, 5, 5)) ev_handler.check()
def test_settle_channel_event( web3, get_accounts, token_network, create_channel, channel_deposit, create_balance_proof, create_balance_proof_update_signature, event_handler, ): """ A successful settleChannel() call causes a SETTLED event """ ev_handler = event_handler(token_network) (A, B) = get_accounts(2) deposit_A = 10 settle_timeout = TEST_SETTLE_TIMEOUT_MIN channel_identifier = create_channel(A, B)[0] channel_deposit(channel_identifier, A, deposit_A, B) balance_proof_A = create_balance_proof(channel_identifier, A, 10, 0, 1, EMPTY_LOCKSROOT) balance_proof_B = create_balance_proof(channel_identifier, B, 5, 0, 3, EMPTY_LOCKSROOT) balance_proof_update_signature_B = create_balance_proof_update_signature( B, channel_identifier, *balance_proof_A) token_network.functions.closeChannel( channel_identifier, B, *balance_proof_B).call_and_transact({"from": A}) token_network.functions.updateNonClosingBalanceProof( channel_identifier, A, B, *balance_proof_A, balance_proof_update_signature_B).call_and_transact({"from": B}) web3.testing.mine(settle_timeout + 1) txn_hash = token_network.functions.settleChannel( channel_identifier=channel_identifier, participant1=B, participant1_transferred_amount=5, participant1_locked_amount=0, participant1_locksroot=EMPTY_LOCKSROOT, participant2=A, participant2_transferred_amount=10, participant2_locked_amount=0, participant2_locksroot=EMPTY_LOCKSROOT, ).call_and_transact({"from": A}) ev_handler.add(txn_hash, ChannelEvent.SETTLED, check_channel_settled(channel_identifier, 5, 5)) ev_handler.check()
def test_cooperative_settle_channel_event( get_accounts, token_network, create_channel, channel_deposit, create_cooperative_settle_signatures, event_handler, ): ev_handler = event_handler(token_network) (A, B) = get_accounts(2) deposit_A = 10 balance_A = 2 balance_B = 8 channel_identifier = create_channel(A, B)[0] channel_deposit(channel_identifier, A, deposit_A, B) (signature_A, signature_B) = create_cooperative_settle_signatures( [A, B], channel_identifier, B, balance_B, A, balance_A, ) txn_hash = token_network.functions.cooperativeSettle( channel_identifier, B, balance_B, A, balance_A, signature_B, signature_A, ).transact({'from': B}) ev_handler.add( txn_hash, ChannelEvent.SETTLED, check_channel_settled( channel_identifier, balance_B, balance_A, )) ev_handler.check()