def test_signature_contract_verify_v_r_s(web3: Web3, signature_contract: Contract):
    """Test that our signature verification works in Solidity contract.

    """

    # Use random Ethereum address as payload for signing
    data = "0xda39147df55f6c51ad539a5e108adc5d7284b309"

    # Convert address to raw bytes
    data_bin = binascii.unhexlify(data[2:])
    assert type(data_bin) == bytes

    private_key_seed = "foobar"
    # Address is 0x58708390680239282143999941903085911172379991841

    signature_data = sign(data_bin, private_key_seed)

    # hash = big_endian_to_int(signature_data["hash"])
    hash = signature_data["hash"]
    v = signature_data["v"]
    r = signature_data["r_bytes"]
    s = signature_data["s_bytes"]

    # 0x0a489345f9e9bc5254e18dd14fa7ecfdb2ce5f21
    result = signature_contract.call().verify(hash, v, r, s)
    assert result == signature_data["address_ethereum"]
def test_signature_internal():
    """Test that our signature verification works in pure Python.

    Note that this uses bitcoin.ecdsa_raw_verify() which takes public key as public key format, not address.
    """

    # Use random Ethereum address as payload for signing
    data = "0xda39147df55f6c51ad539a5e108adc5d7284b309"

    # Convert address to raw bytes
    data_bin = binascii.unhexlify(data[2:])
    assert type(data_bin) == bytes

    private_key_seed = "foobar"

    signature_data = sign(data_bin, private_key_seed)
    print(signature_data)

    assert verify(signature_data["hash"], signature_data["signature"], signature_data["public_key"])