1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00

ethereum: update tests to new message format (addresses are strings)

This commit is contained in:
Tomas Susanka 2019-01-25 16:07:15 +01:00
parent a19f35747d
commit f81bc61316
7 changed files with 23 additions and 24 deletions

View File

@ -1073,8 +1073,7 @@ def decrypt_keyvalue(connect, address, key, value):
def ethereum_get_address(connect, address, show_display): def ethereum_get_address(connect, address, show_display):
client = connect() client = connect()
address_n = tools.parse_path(address) address_n = tools.parse_path(address)
address = ethereum.get_address(client, address_n, show_display) return ethereum.get_address(client, address_n, show_display)
return "0x%s" % address.hex()
@cli.command(help="Get Ethereum public node of given path.") @cli.command(help="Get Ethereum public node of given path.")

View File

@ -27,26 +27,26 @@ class TestMsgEthereumGetaddress(TrezorTest):
def test_ethereum_getaddress(self): def test_ethereum_getaddress(self):
self.setup_mnemonic_nopin_nopassphrase() self.setup_mnemonic_nopin_nopassphrase()
assert ( assert (
ethereum.get_address(self.client, [H_(44), H_(60)]).hex() ethereum.get_address(self.client, [H_(44), H_(60)])
== "e025dfbe2c53638e547c6487ded34add7b8aafc1" == "0xE025dfbE2C53638E547C6487DED34Add7b8Aafc1"
) )
assert ( assert (
ethereum.get_address(self.client, [H_(44), H_(60), 1]).hex() ethereum.get_address(self.client, [H_(44), H_(60), 1])
== "ed46c856d0c79661cf7d40ffe0c0c5077c00e898" == "0xeD46C856D0c79661cF7d40FFE0C0C5077c00E898"
) )
assert ( assert (
ethereum.get_address(self.client, [H_(44), H_(60), 0, H_(1)]).hex() ethereum.get_address(self.client, [H_(44), H_(60), 0, H_(1)])
== "6682fa7f3ec58581b1e576268b5463b4b5c93839" == "0x6682Fa7F3eC58581b1e576268b5463B4b5c93839"
) )
assert ( assert (
ethereum.get_address(self.client, [H_(44), H_(60), H_(9), 0]).hex() ethereum.get_address(self.client, [H_(44), H_(60), H_(9), 0])
== "fb3be0f9717ff5fcf3c58eb49a9ed67f1bd89d4e" == "0xFb3BE0F9717fF5fCF3C58EB49a9Ed67F1BD89D4E"
) )
assert ( assert (
ethereum.get_address(self.client, [H_(44), H_(60), 0, 9999999]).hex() ethereum.get_address(self.client, [H_(44), H_(60), 0, 9999999])
== "6b909b50d88c9a8e02453a87b3662e3e7a5e0cf1" == "0x6b909b50d88c9A8E02453A87b3662E3e7a5E0CF1"
) )
assert ( assert (
ethereum.get_address(self.client, [H_(44), H_(6060), 0, 9999999]).hex() ethereum.get_address(self.client, [H_(44), H_(6060), 0, 9999999])
== "98b8e926bd224764de2a0e4f4cbe1521474050af" == "0x98b8e926bd224764De2A0E4f4CBe1521474050AF"
) )

View File

@ -26,7 +26,7 @@ from .common import TrezorTest
class TestMsgEthereumSignmessage(TrezorTest): class TestMsgEthereumSignmessage(TrezorTest):
PATH = [H_(44), H_(60), H_(0), 0] PATH = [H_(44), H_(60), H_(0), 0]
ADDRESS = "ea53af85525b1779ee99ece1a5560c0b78537c3b" ADDRESS = "0xEa53AF85525B1779eE99ece1a5560C0b78537C3b"
VECTORS = [ VECTORS = [
( (
"This is an example of a signed message.", "This is an example of a signed message.",
@ -42,5 +42,5 @@ class TestMsgEthereumSignmessage(TrezorTest):
self.setup_mnemonic_nopin_nopassphrase() self.setup_mnemonic_nopin_nopassphrase()
for msg, sig in self.VECTORS: for msg, sig in self.VECTORS:
res = ethereum.sign_message(self.client, self.PATH, msg) res = ethereum.sign_message(self.client, self.PATH, msg)
assert res.address.hex() == self.ADDRESS assert res.address == self.ADDRESS
assert res.signature.hex() == sig assert res.signature.hex() == sig

View File

@ -21,7 +21,7 @@ from trezorlib.tools import parse_path
from .common import TrezorTest from .common import TrezorTest
TO_ADDR = bytes.fromhex("1d1c328764a41bda0492b66baa30c4a339ff85ef") TO_ADDR = "0x1d1c328764a41bda0492b66baa30c4a339ff85ef"
@pytest.mark.ethereum @pytest.mark.ethereum
@ -62,7 +62,7 @@ class TestMsgEthereumSigntx(TrezorTest):
gas_price=20, gas_price=20,
gas_limit=20, gas_limit=20,
# ADT token address # ADT token address
to=b"\xd0\xd6\xd6\xc5\xfe\x4a\x67\x7d\x34\x3c\xc4\x33\x53\x6b\xb7\x17\xba\xe1\x67\xdd", to="0xd0d6d6c5fe4a677d343cc433536bb717bae167dd",
chain_id=1, chain_id=1,
# value needs to be 0, token value is set in the contract (data) # value needs to be 0, token value is set in the contract (data)
value=0, value=0,
@ -115,7 +115,7 @@ class TestMsgEthereumSigntx(TrezorTest):
gas_price=20, gas_price=20,
gas_limit=20, gas_limit=20,
# unknown token address (Grzegorz Brzęczyszczykiewicz Token) # unknown token address (Grzegorz Brzęczyszczykiewicz Token)
to=b"\xfc\x6b\x5d\x6a\xf8\xa1\x32\x58\xf7\xcb\xd0\xd3\x9e\x11\xb3\x5e\x01\xa3\x2f\x93", to="0xfc6b5d6af8a13258f7cbd0d39e11b35e01a32f93",
chain_id=1, chain_id=1,
# value needs to be 0, token value is set in the contract (data) # value needs to be 0, token value is set in the contract (data)
value=0, value=0,

View File

@ -209,7 +209,7 @@ class TestMsgEthereumSigntxChainId(TrezorTest):
nonce=n, nonce=n,
gas_price=20000000000, gas_price=20000000000,
gas_limit=gl, gas_limit=gl,
to=bytes.fromhex("8ea7a3fccc211ed48b763b4164884ddbcf3b0a98"), to="0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
value=v, value=v,
chain_id=ci, chain_id=ci,
data=d, data=d,

View File

@ -24,7 +24,7 @@ from .common import TrezorTest
@pytest.mark.ethereum @pytest.mark.ethereum
class TestMsgEthereumVerifymessage(TrezorTest): class TestMsgEthereumVerifymessage(TrezorTest):
ADDRESS = "cb3864960e8db1a751212c580af27ee8867d688f" ADDRESS = "0xCb3864960e8DB1A751212c580AF27Ee8867d688F"
VECTORS = [ VECTORS = [
( (
"This is an example of a signed message.", "This is an example of a signed message.",
@ -40,7 +40,7 @@ class TestMsgEthereumVerifymessage(TrezorTest):
self.setup_mnemonic_nopin_nopassphrase() self.setup_mnemonic_nopin_nopassphrase()
for msg, sig in self.VECTORS: for msg, sig in self.VECTORS:
res = ethereum.verify_message( res = ethereum.verify_message(
self.client, bytes.fromhex(self.ADDRESS), bytes.fromhex(sig), msg self.client, self.ADDRESS, bytes.fromhex(sig), msg
) )
assert res is True assert res is True
@ -48,6 +48,6 @@ class TestMsgEthereumVerifymessage(TrezorTest):
self.setup_mnemonic_nopin_nopassphrase() self.setup_mnemonic_nopin_nopassphrase()
signature = bytes.fromhex(self.VECTORS[0][1]) signature = bytes.fromhex(self.VECTORS[0][1])
res = ethereum.verify_message( res = ethereum.verify_message(
self.client, bytes.fromhex(self.ADDRESS), signature, "another message" self.client, self.ADDRESS, signature, "another message"
) )
assert res is False assert res is False

@ -1 +1 @@
Subproject commit b947aa3d45af58605f8f090078a2de3d5878571d Subproject commit 495b35e212f48ea2ac9e356febd5a49c3ee5254b