def test_signature_verification(message_encodings):
    account = Account.create()
    structured_msg = encode_structured_data(**message_encodings)
    signed = Account.sign_message(structured_msg, account.key)
    new_addr = Account.recover_message(structured_msg,
                                       signature=signed.signature)
    assert new_addr == account.address
def test_signature_variables(message_encodings):
    # Check that the signature of typed message is the same as that
    # mentioned in the EIP. The link is as follows
    # https://github.com/ethereum/EIPs/blob/master/assets/eip-712/Example.js
    structured_msg = encode_structured_data(**message_encodings)
    privateKey = keccak(text="cow")
    acc = Account.from_key(privateKey)
    assert HexBytes(
        acc.address) == HexBytes("0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826")
    sig = Account.sign_message(structured_msg, privateKey)
    assert sig.v == 27
    assert hex(
        sig.r
    ) == "0x58635e9afd7a2a5338cf2af3d711b50235a1955c43f8bca1657c9d0834fcdb5a"
    assert hex(
        sig.s
    ) == "0x44a7c0169616cfdfc16815714c9bc1c94139e17a0761a17530cf3dd1746bc10b"