Example #1
0
def test_hash():
    ping = Ping(nonce=0)
    ping.sign(PRIVKEY)
    data = ping.encode()
    msghash = sha3(data)
    decoded_ping = decode(data)
    assert sha3(decoded_ping.encode()) == msghash
Example #2
0
def test_hash():
    ping = Ping(nonce=0, current_protocol_version=constants.PROTOCOL_VERSION)
    ping.sign(signer)
    data = ping.encode()
    msghash = sha3(data)
    decoded_ping = decode(data)
    assert sha3(decoded_ping.encode()) == msghash
def test_hash():
    ping = Ping(nonce=0, current_protocol_version=constants.PROTOCOL_VERSION)
    ping.sign(PRIVKEY)
    data = ping.encode()
    msghash = sha3(data)
    decoded_ping = decode(data)
    assert sha3(decoded_ping.encode()) == msghash
Example #4
0
def test_encoding():
    ping = Ping(nonce=0)
    ping.sign(PRIVKEY)
    decoded_ping = decode(ping.encode())
    assert isinstance(decoded_ping, Ping)
    assert decoded_ping.sender == ADDRESS == ping.sender
    assert ping.nonce == decoded_ping.nonce
    assert ping.signature == decoded_ping.signature
    assert ping.cmdid == decoded_ping.cmdid
    assert ping.hash == decoded_ping.hash
def test_encoding():
    ping = Ping(nonce=0, current_protocol_version=constants.PROTOCOL_VERSION)
    ping.sign(PRIVKEY)
    decoded_ping = decode(ping.encode())
    assert isinstance(decoded_ping, Ping)
    assert decoded_ping.sender == ADDRESS == ping.sender
    assert ping.nonce == decoded_ping.nonce
    assert ping.signature == decoded_ping.signature
    assert ping.cmdid == decoded_ping.cmdid
    assert ping.hash == decoded_ping.hash
Example #6
0
def test_encoding():
    ping = Ping(nonce=0, current_protocol_version=constants.PROTOCOL_VERSION)
    ping.sign(signer)
    decoded_ping = decode(ping.encode())
    assert isinstance(decoded_ping, Ping)
    assert decoded_ping.sender == ADDRESS == ping.sender
    assert ping.nonce == decoded_ping.nonce
    assert ping.signature == decoded_ping.signature
    assert ping.cmdid == decoded_ping.cmdid
    assert ping.hash == decoded_ping.hash
Example #7
0
def test_encoding():
    p = Ping(nonce=0)
    with pytest.raises(SignatureMissingError):
        p.encode()
    p.sign(privkey)
    d = p.encode()
    p2 = decode(d)
    assert isinstance(p2, Ping)
    assert p2.sender == address == p.sender
    assert p.nonce == p2.nonce
    assert p.signature == p2.signature
    assert p.cmdid == p.cmdid
    assert p.hash == p2.hash
Example #8
0
def test_encoding():
    p = Ping(nonce=0)
    with pytest.raises(SignatureMissingError):
        p.encode()
    p.sign(privkey)
    d = p.encode()
    p2 = decode(d)
    assert isinstance(p2, Ping)
    assert p2.sender == address == p.sender
    assert p.nonce == p2.nonce
    assert p.signature == p2.signature
    assert p.cmdid == p.cmdid
    assert p.hash == p2.hash
def test_signature():
    ping = Ping(nonce=0, current_protocol_version=constants.PROTOCOL_VERSION)
    ping.sign(PRIVKEY)
    assert ping.sender == ADDRESS

    # test that the valid v values are accepted
    message_data = ping._data_to_sign()
    # This signature will sometimes end up with v being 0, sometimes 1
    signature = eth_sign(privkey=PRIVKEY, data=message_data, v=0)
    assert ADDRESS == eth_recover(message_data, signature)
    # This signature will sometimes end up with v being 27, sometimes 28
    signature = eth_sign(privkey=PRIVKEY, data=message_data, v=27)
    assert ADDRESS == eth_recover(message_data, signature)

    # test that other v values are rejected
    signature = signature[:-1] + bytes([29])
    with pytest.raises(InvalidSignature):
        eth_recover(message_data, signature)
    signature = signature[:-1] + bytes([37])
    with pytest.raises(InvalidSignature):
        eth_recover(message_data, signature)
    signature = signature[:-1] + bytes([38])
    with pytest.raises(InvalidSignature):
        eth_recover(message_data, signature)
Example #10
0
def test_signature():
    ping = Ping(nonce=0, current_protocol_version=constants.PROTOCOL_VERSION)
    ping.sign(signer)
    assert ping.sender == ADDRESS

    # test that the valid v values are accepted
    message_data = ping._data_to_sign()
    # This signature will sometimes end up with v being 0, sometimes 1
    signature = signer.sign(data=message_data, v=0)
    assert ADDRESS == recover(message_data, signature)
    # This signature will sometimes end up with v being 27, sometimes 28
    signature = signer.sign(data=message_data, v=27)
    assert ADDRESS == recover(message_data, signature)

    # test that other v values are rejected
    signature = signature[:-1] + bytes([29])
    with pytest.raises(InvalidSignature):
        recover(message_data, signature)
    signature = signature[:-1] + bytes([37])
    with pytest.raises(InvalidSignature):
        recover(message_data, signature)
    signature = signature[:-1] + bytes([38])
    with pytest.raises(InvalidSignature):
        recover(message_data, signature)
Example #11
0
def test_ping(iterations=ITERATIONS):
    msg = Ping(nonce=0)
    msg.sign(PRIVKEY, ADDRESS)
    run_timeit('Ping', msg, iterations=iterations)
Example #12
0
def test_signature():
    ping = Ping(nonce=0)
    ping.sign(PRIVKEY)
    assert ping.sender == ADDRESS
Example #13
0
def test_signature():
    ping = Ping(nonce=0)
    ping.sign(PRIVKEY, UNIT_CHAIN_ID)
    assert ping.sender == ADDRESS
Example #14
0
def test_signature():
    p = Ping(nonce=0)
    with pytest.raises(SignatureMissingError):
        p.sender
    p.sign(privkey)
    assert p.sender == address
Example #15
0
def test_signature():
    p = Ping(nonce=0)
    with pytest.raises(SignatureMissingError):
        p.sender
    p.sign(privkey)
    assert p.sender == address
Example #16
0
def test_signature():
    ping = Ping(nonce=0, current_protocol_version=0)
    ping.sign(PRIVKEY)
    assert ping.sender == ADDRESS
Example #17
0
def test_signature():
    ping = Ping(nonce=0, current_protocol_version=0)
    ping.sign(PRIVKEY)
    assert ping.sender == ADDRESS
Example #18
0
def test_ping(iterations=ITERATIONS):
    msg = Ping(nonce=0)
    msg.sign(PRIVKEY, ADDRESS)
    run_timeit('Ping', msg, iterations=iterations)
def test_signature():
    ping = Ping(nonce=0, current_protocol_version=constants.PROTOCOL_VERSION)
    ping.sign(PRIVKEY)
    assert ping.sender == ADDRESS