def test_verify( web3, token_network, signature_test_contract, get_accounts, create_channel: Callable, create_balance_proof, ): """ ECVerify.ecverify returns the correct address This test checks if the signature test contract returns the correct addresses on the balance hash signed by both ends of a channel """ (A, B) = get_accounts(2) channel_identifier = create_channel(A, B)[0] balance_proof_A = create_balance_proof(channel_identifier, A, 2, 0, 3) signature = balance_proof_A[3] balance_proof_hash = hash_balance_proof(token_network.address, int(web3.version.network), channel_identifier, *balance_proof_A[:3]) address = signature_test_contract.functions.verify(balance_proof_hash, signature).call() assert address == A balance_proof_B = create_balance_proof(channel_identifier, B, 0, 0, 0) signature = balance_proof_B[3] balance_proof_hash = hash_balance_proof(token_network.address, int(web3.version.network), channel_identifier, *balance_proof_B[:3]) address = signature_test_contract.functions.verify(balance_proof_hash, signature).call() assert address == B
def test_ecrecover_output( web3, token_network, signature_test_contract, get_accounts, create_channel, create_balance_proof, ): """ ecrecover returns the address that was used to sign a balance proof """ (A, B) = get_accounts(2) channel_identifier = create_channel(A, B)[0] balance_proof_A = create_balance_proof(channel_identifier, A, 2, 0, 3) signature = balance_proof_A[3] r = signature[:32] s = signature[32:64] v = signature[64:] balance_proof_hash = hash_balance_proof( token_network.address, int(web3.version.network), channel_identifier, *balance_proof_A[:3], ) address = signature_test_contract.functions.verifyEcrecoverOutput( balance_proof_hash, r, s, int.from_bytes(v, byteorder='big'), ).call() assert address == A