def test_channel_223_create_bounty_limit(get_block, owner, get_accounts, uraiden_instance, token_instance): token = token_instance (sender, receiver, C, D) = get_accounts(4) txdata = bytes.fromhex(receiver[2:].zfill(40)) # Fund accounts with tokens token.transact({"from": owner}).transfer(sender, channel_deposit_bugbounty_limit + 1) pre_balance = token_instance.call().balanceOf(uraiden_instance.address) with pytest.raises(tester.TransactionFailed): token_instance.transact({"from": sender}).transfer( uraiden_instance.address, channel_deposit_bugbounty_limit + 1, txdata ) with pytest.raises(tester.TransactionFailed): token_instance.transact({"from": sender}).transfer( uraiden_instance.address, channel_deposit_bugbounty_limit + 10, txdata ) txn_hash = token_instance.transact({"from": sender}).transfer( uraiden_instance.address, channel_deposit_bugbounty_limit, txdata ) post_balance = pre_balance + channel_deposit_bugbounty_limit assert token_instance.call().balanceOf(uraiden_instance.address) == post_balance open_block_number = get_block(txn_hash) channel_data = uraiden_instance.call().getChannelInfo(sender, receiver, open_block_number) assert channel_data[1] == channel_deposit_bugbounty_limit
def test_channel_erc20_create(owner, get_accounts, uraiden_instance, token_instance): token = token_instance (sender, receiver) = get_accounts(2) deposit = 1000 # Fund accounts with tokens token.transact({"from": owner}).transfer(sender, deposit + 100) token.transact({"from": owner}).transfer(receiver, 20) # Cannot create a channel if tokens were not approved with pytest.raises(tester.TransactionFailed): uraiden_instance.transact({"from": sender}).createChannel(receiver, deposit) assert token_instance.call().balanceOf(uraiden_instance.address) == 0 # Can create a channel with deposit 0 uraiden_instance.transact({"from": sender}).createChannel(receiver, 0) # Approve token allowance token_instance.transact({"from": sender}).approve(uraiden_instance.address, deposit) with pytest.raises(TypeError): uraiden_instance.transact({"from": sender}).createChannel(0x0, deposit) with pytest.raises(TypeError): uraiden_instance.transact({"from": sender}).createChannel('0x0', deposit) with pytest.raises(TypeError): uraiden_instance.transact({"from": sender}).createChannel(fake_address, deposit) with pytest.raises(TypeError): uraiden_instance.transact({"from": sender}).createChannel(receiver, -3) with pytest.raises(TypeError): uraiden_instance.transact({"from": sender}).createChannel(receiver, MAX_UINT192 + 1) # Create channel uraiden_instance.transact({"from": sender}).createChannel(receiver, deposit)
def test_channel_20_create(owner, get_accounts, uraiden_instance, token_instance): token = token_instance (sender, receiver) = get_accounts(2) deposit = 1000 # Fund accounts with tokens token.transact({"from": owner}).transfer(sender, deposit + 100) token.transact({"from": owner}).transfer(receiver, 20) # Cannot create a channel if tokens were not approved with pytest.raises(tester.TransactionFailed): uraiden_instance.transact({"from": sender}).createChannelERC20(receiver, deposit) assert token_instance.call().balanceOf(uraiden_instance.address) == 0 # Can create a channel with deposit 0 uraiden_instance.transact({"from": sender}).createChannelERC20(receiver, 0) # Approve token allowance token_instance.transact({"from": sender}).approve(uraiden_instance.address, deposit) with pytest.raises(TypeError): uraiden_instance.transact({"from": sender}).createChannelERC20(0x0, deposit) with pytest.raises(TypeError): uraiden_instance.transact({"from": sender}).createChannelERC20('0x0', deposit) with pytest.raises(TypeError): uraiden_instance.transact({"from": sender}).createChannelERC20(fake_address, deposit) with pytest.raises(TypeError): uraiden_instance.transact({"from": sender}).createChannelERC20(receiver, -3) with pytest.raises(TypeError): uraiden_instance.transact({"from": sender}).createChannelERC20(receiver, MAX_UINT192 + 1) # Create channel uraiden_instance.transact({"from": sender}).createChannelERC20(receiver, deposit)
def test_channel_erc223_create(owner, get_accounts, uraiden_instance, token_instance): token = token_instance (sender, receiver, C, D) = get_accounts(4) deposit = 1000 txdata = bytes.fromhex(receiver[2:].zfill(40)) txdata_fake = txdata[1:] # Fund accounts with tokens token.transact({"from": owner}).transfer(sender, deposit + 100) token.transact({"from": owner}).transfer(receiver, 20) with pytest.raises(TypeError): token_instance.transact({ "from": sender }).transfer(0x0, deposit, txdata) with pytest.raises(TypeError): token_instance.transact({ "from": sender }).transfer(fake_address, deposit, txdata) with pytest.raises(TypeError): token_instance.transact({ "from": sender }).transfer(uraiden_instance.address, -2, txdata) with pytest.raises(TypeError): token_instance.transact({ "from": sender }).transfer(uraiden_instance.address, MAX_UINT256 + 1, txdata) with pytest.raises(tester.TransactionFailed): token_instance.transact({ "from": sender }).transfer(empty_address, deposit, txdata) with pytest.raises(tester.TransactionFailed): token_instance.transact({ "from": sender }).transfer(uraiden_instance.address, deposit, bytearray(10)) with pytest.raises(tester.TransactionFailed): token_instance.transact({ "from": sender }).transfer(uraiden_instance.address, deposit, txdata_fake) # tokenFallback only callable by token with pytest.raises(tester.TransactionFailed): uraiden_instance.transact({ 'from': C }).tokenFallback(sender, 10, txdata) assert token_instance.call().balanceOf(uraiden_instance.address) == 0 # Deposit 0 is possible now token_instance.transact({ "from": sender }).transfer(uraiden_instance.address, 0, txdata) token_instance.transact({ "from": sender }).transfer(uraiden_instance.address, deposit, txdata)
def test_channel_erc20_create_bounty_limit( owner, get_accounts, uraiden_instance, token_instance, get_block): token = token_instance (sender, receiver) = get_accounts(2) # Fund accounts with tokens token.transact({"from": owner}).transfer(sender, channel_deposit_bugbounty_limit + 1) # Approve token allowance token_instance.transact({"from": sender}).approve( uraiden_instance.address, channel_deposit_bugbounty_limit + 1 ) pre_balance = token_instance.call().balanceOf(uraiden_instance.address) with pytest.raises(tester.TransactionFailed): uraiden_instance.transact({"from": sender}).createChannel( receiver, channel_deposit_bugbounty_limit + 1 ) with pytest.raises(tester.TransactionFailed): uraiden_instance.transact({"from": sender}).createChannel( receiver, channel_deposit_bugbounty_limit + 100 ) txn_hash = uraiden_instance.transact({"from": sender}).createChannel( receiver, channel_deposit_bugbounty_limit ) post_balance = pre_balance + channel_deposit_bugbounty_limit assert token_instance.call().balanceOf(uraiden_instance.address) == post_balance open_block_number = get_block(txn_hash) channel_data = uraiden_instance.call().getChannelInfo(sender, receiver, open_block_number) assert channel_data[1] == channel_deposit_bugbounty_limit
def test_channel_erc223_create_bounty_limit( get_block, owner, get_accounts, uraiden_instance, token_instance): token = token_instance (sender, receiver, C, D) = get_accounts(4) txdata = bytes.fromhex(sender[2:] + receiver[2:]) # Fund accounts with tokens token.transact({"from": owner}).transfer(sender, channel_deposit_bugbounty_limit + 1) pre_balance = token_instance.call().balanceOf(uraiden_instance.address) with pytest.raises(tester.TransactionFailed): token_instance.transact({"from": sender}).transfer( uraiden_instance.address, channel_deposit_bugbounty_limit + 1, txdata ) with pytest.raises(tester.TransactionFailed): token_instance.transact({"from": sender}).transfer( uraiden_instance.address, channel_deposit_bugbounty_limit + 10, txdata ) txn_hash = token_instance.transact({"from": sender}).transfer( uraiden_instance.address, channel_deposit_bugbounty_limit, txdata ) post_balance = pre_balance + channel_deposit_bugbounty_limit assert token_instance.call().balanceOf(uraiden_instance.address) == post_balance open_block_number = get_block(txn_hash) channel_data = uraiden_instance.call().getChannelInfo(sender, receiver, open_block_number) assert channel_data[1] == channel_deposit_bugbounty_limit
def test_channel_erc223_create(owner, get_accounts, uraiden_instance, token_instance): token = token_instance (sender, receiver, C, D) = get_accounts(4) deposit = 1000 txdata = bytes.fromhex(sender[2:] + receiver[2:]) txdata_fake = txdata[1:] # Fund accounts with tokens token.transact({"from": owner}).transfer(sender, deposit + 100) token.transact({"from": owner}).transfer(receiver, 20) with pytest.raises(TypeError): token_instance.transact({"from": sender}).transfer(0x0, deposit, txdata) with pytest.raises(TypeError): token_instance.transact({"from": sender}).transfer(fake_address, deposit, txdata) with pytest.raises(TypeError): token_instance.transact({"from": sender}).transfer(uraiden_instance.address, -2, txdata) with pytest.raises(TypeError): token_instance.transact({"from": sender}).transfer( uraiden_instance.address, MAX_UINT256 + 1, txdata ) with pytest.raises(tester.TransactionFailed): token_instance.transact({"from": sender}).transfer(empty_address, deposit, txdata) with pytest.raises(tester.TransactionFailed): token_instance.transact({"from": sender}).transfer( uraiden_instance.address, deposit, encode_hex(bytearray(10)) ) with pytest.raises(tester.TransactionFailed): token_instance.transact({"from": sender}).transfer( uraiden_instance.address, deposit, txdata_fake ) # tokenFallback only callable by token with pytest.raises(tester.TransactionFailed): uraiden_instance.transact({'from': C}).tokenFallback(sender, 10, txdata) assert token_instance.call().balanceOf(uraiden_instance.address) == 0 # Deposit 0 is possible now token_instance.transact({"from": sender}).transfer(uraiden_instance.address, 0, txdata) token_instance.transact({"from": sender}).transfer(uraiden_instance.address, deposit, txdata)
def test_channel_topup_223_bounty_limit( get_accounts, owner, uraiden_instance, token_instance, get_channel): token = token_instance (sender, receiver, A) = get_accounts(3) channel_deposit = 1 channel = get_channel(uraiden_instance, token_instance, channel_deposit, sender, receiver)[:3] (sender, receiver, open_block_number) = channel top_up_data = sender[2:] + receiver[2:] + hex(open_block_number)[2:].zfill(8) top_up_data = bytes.fromhex(top_up_data) # See how many tokens we need to reach channel_deposit_bugbounty_limit added_deposit = channel_deposit_bugbounty_limit - channel_deposit # Fund accounts with tokens token.transact({"from": owner}).transfer(sender, added_deposit + 1) pre_balance = token.call().balanceOf(uraiden_instance.address) with pytest.raises(tester.TransactionFailed): token_instance.transact({"from": sender}).transfer( uraiden_instance.address, added_deposit + 1, top_up_data ) with pytest.raises(tester.TransactionFailed): token_instance.transact({"from": sender}).transfer( uraiden_instance.address, added_deposit + 20, top_up_data ) token_instance.transact({"from": sender}).transfer( uraiden_instance.address, added_deposit, top_up_data ) post_balance = pre_balance + added_deposit assert token_instance.call().balanceOf(uraiden_instance.address) == post_balance channel_data = uraiden_instance.call().getChannelInfo(sender, receiver, open_block_number) assert channel_data[1] == channel_deposit_bugbounty_limit
def test_channel_topup_20_bounty_limit( get_accounts, owner, uraiden_instance, token_instance, get_channel): token = token_instance (sender, receiver, A) = get_accounts(3) channel_deposit = 1 channel = get_channel(uraiden_instance, token_instance, channel_deposit, sender, receiver)[:3] (sender, receiver, open_block_number) = channel # See how many tokens we need to reach channel_deposit_bugbounty_limit added_deposit = channel_deposit_bugbounty_limit - channel_deposit # Fund accounts with tokens token.transact({"from": owner}).transfer(sender, added_deposit + 1) # Approve token allowance txn_hash = token.transact({"from": sender}).approve(uraiden_instance.address, added_deposit + 1) pre_balance = token.call().balanceOf(uraiden_instance.address) with pytest.raises(tester.TransactionFailed): uraiden_instance.transact({'from': sender}).topUp( receiver, open_block_number, added_deposit + 1 ) with pytest.raises(tester.TransactionFailed): uraiden_instance.transact({'from': sender}).topUp( receiver, open_block_number, added_deposit + 50 ) uraiden_instance.transact({'from': sender}).topUp( receiver, open_block_number, added_deposit ) post_balance = pre_balance + added_deposit assert token_instance.call().balanceOf(uraiden_instance.address) == post_balance channel_data = uraiden_instance.call().getChannelInfo(sender, receiver, open_block_number) assert channel_data[1] == channel_deposit_bugbounty_limit
def test_cooperative_close_state( web3, contract_params, channel_params, uraiden_instance, token_instance, get_channel, get_block): (sender, receiver, open_block_number, balance_msg_sig, closing_sig) = get_channel() balance = channel_params['balance'] deposit = channel_params['deposit'] # Keep track of pre closing balances receiver_pre_balance = token_instance.call().balanceOf(receiver) sender_pre_balance = token_instance.call().balanceOf(sender) contract_pre_balance = token_instance.call().balanceOf(uraiden_instance.address) # Cooperative close can be called by anyone uraiden_instance.transact({"from": receiver}).cooperativeClose( receiver, open_block_number, balance, balance_msg_sig, closing_sig ) # Check post closing balances receiver_post_balance = receiver_pre_balance + balance sender_post_balance = sender_pre_balance + (deposit - balance) contract_post_balance = contract_pre_balance - deposit assert token_instance.call().balanceOf(receiver) == receiver_post_balance assert token_instance.call().balanceOf(sender) == sender_post_balance assert token_instance.call().balanceOf(uraiden_instance.address) == contract_post_balance channel_settle_tests(uraiden_instance, token_instance, (sender, receiver, open_block_number) ) # Channel does not exist anymore, so this will fail with pytest.raises(tester.TransactionFailed): uraiden_instance.call().getChannelInfo(sender, receiver, open_block_number) web3.testing.mine(30) # Cannot be called another time with pytest.raises(tester.TransactionFailed): uraiden_instance.transact({"from": receiver}).cooperativeClose( receiver, open_block_number, balance, balance_msg_sig, closing_sig )
def test_settle_state( web3, channel_params, contract_params, uraiden_instance, token_instance, get_channel, print_gas): (sender, receiver, open_block_number) = get_channel()[:3] balance = channel_params['balance'] deposit = channel_params['deposit'] # Trigger a challenge period uraiden_instance.transact({"from": sender}).uncooperativeClose( receiver, open_block_number, balance ) web3.testing.mine(contract_params['challenge_period'] + 1) # Keep track of pre closing balances receiver_pre_balance = token_instance.call().balanceOf(receiver) sender_pre_balance = token_instance.call().balanceOf(sender) contract_pre_balance = token_instance.call().balanceOf(uraiden_instance.address) txn_hash = uraiden_instance.transact({"from": sender}).settle(receiver, open_block_number) # Check post closing balances receiver_post_balance = receiver_pre_balance + balance sender_post_balance = sender_pre_balance + (deposit - balance) contract_post_balance = contract_pre_balance - deposit assert token_instance.call().balanceOf(receiver) == receiver_post_balance assert token_instance.call().balanceOf(sender) == sender_post_balance assert token_instance.call().balanceOf(uraiden_instance.address) == contract_post_balance channel_settle_tests(uraiden_instance, token_instance, (sender, receiver, open_block_number) ) # Channel does not exist anymore, so this will fail with pytest.raises(tester.TransactionFailed): uraiden_instance.call().getChannelInfo(sender, receiver, open_block_number) web3.testing.mine(30) # Cannot be called another time with pytest.raises(tester.TransactionFailed): uraiden_instance.transact({"from": sender}).settle(receiver, open_block_number) print_gas(txn_hash, 'settle')
def test_close_after_withdraw(contract_params, channel_params, uraiden_instance, token_instance, get_channel, get_block, print_gas): (sender, receiver, open_block_number) = get_channel()[:3] deposit = channel_params['deposit'] balance1 = 20 balance2 = deposit balance_message_hash1 = balance_proof_hash(receiver, open_block_number, balance1, uraiden_instance.address) balance_msg_sig1, addr = sign.check(balance_message_hash1, tester.k2) assert is_same_address(addr, sender) # Withdraw some tokens txn_hash = uraiden_instance.transact({ "from": receiver }).withdraw(open_block_number, balance1, balance_msg_sig1) # Cooperatively close the channel balance_message_hash = balance_proof_hash(receiver, open_block_number, balance2, uraiden_instance.address) balance_msg_sig, addr = sign.check(balance_message_hash, tester.k2) assert is_same_address(addr, sender) closing_msg_hash = closing_message_hash(sender, open_block_number, balance2, uraiden_instance.address) closing_sig, addr = sign.check(closing_msg_hash, tester.k3) # Memorize balances for tests uraiden_pre_balance = token_instance.call().balanceOf( uraiden_instance.address) sender_pre_balance = token_instance.call().balanceOf(sender) receiver_pre_balance = token_instance.call().balanceOf(receiver) uraiden_instance.transact({ "from": receiver }).cooperativeClose(receiver, open_block_number, balance2, balance_msg_sig, closing_sig) # Check post closing balances receiver_post_balance = receiver_pre_balance + (balance2 - balance1) sender_post_balance = sender_pre_balance + (deposit - balance2) uraiden_post_balance = uraiden_pre_balance - (balance2 - balance1) assert token_instance.call().balanceOf(receiver) == receiver_post_balance assert token_instance.call().balanceOf(sender) == sender_post_balance assert token_instance.call().balanceOf( uraiden_instance.address) == uraiden_post_balance
def test_channel_topup_20_bounty_limit(get_accounts, owner, uraiden_instance, token_instance, get_channel): token = token_instance (sender, receiver, A) = get_accounts(3) channel_deposit = 1 channel = get_channel(uraiden_instance, token_instance, channel_deposit, sender, receiver)[:3] (sender, receiver, open_block_number) = channel # See how many tokens we need to reach channel_deposit_bugbounty_limit added_deposit = channel_deposit_bugbounty_limit - channel_deposit # Fund accounts with tokens token.transact({"from": owner}).transfer(sender, added_deposit + 1) # Approve token allowance txn_hash = token.transact({ "from": sender }).approve(uraiden_instance.address, added_deposit + 1) pre_balance = token.call().balanceOf(uraiden_instance.address) with pytest.raises(tester.TransactionFailed): uraiden_instance.transact({ 'from': sender }).topUp(receiver, open_block_number, added_deposit + 1) with pytest.raises(tester.TransactionFailed): uraiden_instance.transact({ 'from': sender }).topUp(receiver, open_block_number, added_deposit + 50) uraiden_instance.transact({ 'from': sender }).topUp(receiver, open_block_number, added_deposit) post_balance = pre_balance + added_deposit assert token_instance.call().balanceOf( uraiden_instance.address) == post_balance channel_data = uraiden_instance.call().getChannelInfo( sender, receiver, open_block_number) assert channel_data[1] == channel_deposit_bugbounty_limit
def test_channel_topup_223_bounty_limit(get_accounts, owner, uraiden_instance, token_instance, get_channel): token = token_instance (sender, receiver, A) = get_accounts(3) channel_deposit = 1 channel = get_channel(uraiden_instance, token_instance, channel_deposit, sender, receiver)[:3] (sender, receiver, open_block_number) = channel top_up_data = sender[2:] + receiver[2:] + hex(open_block_number)[2:].zfill( 8) top_up_data = bytes.fromhex(top_up_data) # See how many tokens we need to reach channel_deposit_bugbounty_limit added_deposit = channel_deposit_bugbounty_limit - channel_deposit # Fund accounts with tokens token.transact({"from": owner}).transfer(sender, added_deposit + 1) pre_balance = token.call().balanceOf(uraiden_instance.address) with pytest.raises(tester.TransactionFailed): token_instance.transact({ "from": sender }).transfer(uraiden_instance.address, added_deposit + 1, top_up_data) with pytest.raises(tester.TransactionFailed): token_instance.transact({ "from": sender }).transfer(uraiden_instance.address, added_deposit + 20, top_up_data) token_instance.transact({ "from": sender }).transfer(uraiden_instance.address, added_deposit, top_up_data) post_balance = pre_balance + added_deposit assert token_instance.call().balanceOf( uraiden_instance.address) == post_balance channel_data = uraiden_instance.call().getChannelInfo( sender, receiver, open_block_number) assert channel_data[1] == channel_deposit_bugbounty_limit
def test_withdraw_state( contract_params, channel_params, uraiden_instance, token_instance, get_channel, get_block, print_gas): (sender, receiver, open_block_number) = get_channel()[:3] deposit = channel_params['deposit'] balance1 = 20 balance2 = deposit balance_message_hash = balance_proof_hash( receiver, open_block_number, balance1, uraiden_instance.address ) balance_msg_sig, addr = sign.check(balance_message_hash, tester.k2) assert is_same_address(addr, sender) # Memorize balances for tests uraiden_pre_balance = token_instance.call().balanceOf(uraiden_instance.address) sender_pre_balance = token_instance.call().balanceOf(sender) receiver_pre_balance = token_instance.call().balanceOf(receiver) txn_hash = uraiden_instance.transact({"from": receiver}).withdraw( open_block_number, balance1, balance_msg_sig ) # Check channel info channel_info = uraiden_instance.call().getChannelInfo(sender, receiver, open_block_number) # deposit assert channel_info[1] == deposit assert channel_info[2] == 0 assert channel_info[3] == 0 assert channel_info[4] == balance1 # Check token balances post withrawal uraiden_balance = uraiden_pre_balance - balance1 assert token_instance.call().balanceOf(uraiden_instance.address) == uraiden_balance assert token_instance.call().balanceOf(sender) == sender_pre_balance assert token_instance.call().balanceOf(receiver) == receiver_pre_balance + balance1 print_gas(txn_hash, 'withdraw') balance_message_hash = balance_proof_hash( receiver, open_block_number, balance2, uraiden_instance.address ) balance_msg_sig, addr = sign.check(balance_message_hash, tester.k2) assert is_same_address(addr, sender) txn_hash = uraiden_instance.transact({"from": receiver}).withdraw( open_block_number, balance2, balance_msg_sig ) channel_info = uraiden_instance.call().getChannelInfo(sender, receiver, open_block_number) # deposit assert channel_info[1] == deposit assert channel_info[2] == 0 assert channel_info[3] == 0 assert channel_info[4] == balance2 # Check token balances post withrawal uraiden_balance = uraiden_pre_balance - deposit assert token_instance.call().balanceOf(uraiden_instance.address) == uraiden_balance assert token_instance.call().balanceOf(sender) == sender_pre_balance assert token_instance.call().balanceOf(receiver) == receiver_pre_balance + deposit print_gas(txn_hash, 'withdraw')
def test_close_after_withdraw( contract_params, channel_params, uraiden_instance, token_instance, get_channel, get_block, print_gas): (sender, receiver, open_block_number) = get_channel()[:3] deposit = channel_params['deposit'] balance1 = 20 balance2 = deposit balance_message_hash1 = balance_proof_hash( receiver, open_block_number, balance1, uraiden_instance.address ) balance_msg_sig1, addr = sign.check(balance_message_hash1, tester.k2) assert is_same_address(addr, sender) # Withdraw some tokens txn_hash = uraiden_instance.transact({"from": receiver}).withdraw( open_block_number, balance1, balance_msg_sig1 ) # Cooperatively close the channel balance_message_hash = balance_proof_hash( receiver, open_block_number, balance2, uraiden_instance.address ) balance_msg_sig, addr = sign.check(balance_message_hash, tester.k2) assert is_same_address(addr, sender) closing_msg_hash = closing_message_hash( sender, open_block_number, balance2, uraiden_instance.address ) closing_sig, addr = sign.check(closing_msg_hash, tester.k3) # Memorize balances for tests uraiden_pre_balance = token_instance.call().balanceOf(uraiden_instance.address) sender_pre_balance = token_instance.call().balanceOf(sender) receiver_pre_balance = token_instance.call().balanceOf(receiver) uraiden_instance.transact({"from": receiver}).cooperativeClose( receiver, open_block_number, balance2, balance_msg_sig, closing_sig ) # Check post closing balances receiver_post_balance = receiver_pre_balance + (balance2 - balance1) sender_post_balance = sender_pre_balance + (deposit - balance2) uraiden_post_balance = uraiden_pre_balance - (balance2 - balance1) assert token_instance.call().balanceOf(receiver) == receiver_post_balance assert token_instance.call().balanceOf(sender) == sender_post_balance assert token_instance.call().balanceOf(uraiden_instance.address) == uraiden_post_balance
def test_withdraw_state(contract_params, channel_params, uraiden_instance, token_instance, get_channel, get_block, print_gas): (sender, receiver, open_block_number) = get_channel()[:3] deposit = channel_params['deposit'] balance1 = 20 balance2 = deposit balance_message_hash = balance_proof_hash(receiver, open_block_number, balance1, uraiden_instance.address) balance_msg_sig, addr = sign.check(balance_message_hash, tester.k2) assert is_same_address(addr, sender) # Memorize balances for tests uraiden_pre_balance = token_instance.call().balanceOf( uraiden_instance.address) sender_pre_balance = token_instance.call().balanceOf(sender) receiver_pre_balance = token_instance.call().balanceOf(receiver) txn_hash = uraiden_instance.transact({ "from": receiver }).withdraw(open_block_number, balance1, balance_msg_sig) # Check channel info channel_info = uraiden_instance.call().getChannelInfo( sender, receiver, open_block_number) # deposit assert channel_info[1] == deposit assert channel_info[2] == 0 assert channel_info[3] == 0 assert channel_info[4] == balance1 # Check token balances post withrawal uraiden_balance = uraiden_pre_balance - balance1 assert token_instance.call().balanceOf( uraiden_instance.address) == uraiden_balance assert token_instance.call().balanceOf(sender) == sender_pre_balance assert token_instance.call().balanceOf( receiver) == receiver_pre_balance + balance1 print_gas(txn_hash, 'withdraw') balance_message_hash = balance_proof_hash(receiver, open_block_number, balance2, uraiden_instance.address) balance_msg_sig, addr = sign.check(balance_message_hash, tester.k2) assert is_same_address(addr, sender) txn_hash = uraiden_instance.transact({ "from": receiver }).withdraw(open_block_number, balance2, balance_msg_sig) channel_info = uraiden_instance.call().getChannelInfo( sender, receiver, open_block_number) # deposit assert channel_info[1] == deposit assert channel_info[2] == 0 assert channel_info[3] == 0 assert channel_info[4] == balance2 # Check token balances post withrawal uraiden_balance = uraiden_pre_balance - deposit assert token_instance.call().balanceOf( uraiden_instance.address) == uraiden_balance assert token_instance.call().balanceOf(sender) == sender_pre_balance assert token_instance.call().balanceOf( receiver) == receiver_pre_balance + deposit print_gas(txn_hash, 'withdraw')