2024-01-26 11:16:55 +00:00
|
|
|
from common import * # isort:skip
|
2023-06-28 10:58:54 +00:00
|
|
|
|
2019-08-26 16:47:49 +00:00
|
|
|
if not utils.BITCOIN_ONLY:
|
2023-02-03 13:39:31 +00:00
|
|
|
from ethereum_common import make_network
|
2018-06-12 15:45:40 +00:00
|
|
|
|
2024-01-26 11:16:55 +00:00
|
|
|
from apps.ethereum.helpers import address_from_bytes
|
|
|
|
|
2019-08-26 16:47:49 +00:00
|
|
|
|
|
|
|
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
|
2018-06-12 15:45:40 +00:00
|
|
|
class TestEthereumGetAddress(unittest.TestCase):
|
2019-01-28 14:44:18 +00:00
|
|
|
def test_address_from_bytes_eip55(self):
|
2018-06-12 15:45:40 +00:00
|
|
|
# https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md
|
|
|
|
eip55 = [
|
2023-02-03 13:39:31 +00:00
|
|
|
"0x52908400098527886E0F7030069857D2E4169EE7",
|
|
|
|
"0x8617E340B3D01FA5F11F306F4090FD50E238070D",
|
|
|
|
"0xde709f2102306220921060314715629080e2fb77",
|
|
|
|
"0x27b1fdb04752bbc536007a920d24acb045561c26",
|
|
|
|
"0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed",
|
|
|
|
"0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359",
|
|
|
|
"0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB",
|
|
|
|
"0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb",
|
2018-06-12 15:45:40 +00:00
|
|
|
]
|
|
|
|
for s in eip55:
|
2021-08-31 09:47:56 +00:00
|
|
|
b = unhexlify(s[2:])
|
2019-01-28 14:44:18 +00:00
|
|
|
h = address_from_bytes(b)
|
2021-08-31 09:47:56 +00:00
|
|
|
self.assertEqual(h, s)
|
2018-06-12 15:45:40 +00:00
|
|
|
|
2019-01-28 14:44:18 +00:00
|
|
|
def test_address_from_bytes_rskip60(self):
|
2018-06-13 16:37:51 +00:00
|
|
|
# https://github.com/rsksmart/RSKIPs/blob/master/IPs/RSKIP60.md
|
|
|
|
rskip60_chain_30 = [
|
2023-02-03 13:39:31 +00:00
|
|
|
"0x5aaEB6053f3e94c9b9a09f33669435E7ef1bEAeD",
|
|
|
|
"0xFb6916095cA1Df60bb79ce92cE3EA74c37c5d359",
|
|
|
|
"0xDBF03B407c01E7CD3cBea99509D93F8Dddc8C6FB",
|
|
|
|
"0xD1220A0Cf47c7B9BE7a2e6ba89F429762E7B9adB",
|
2018-06-13 16:37:51 +00:00
|
|
|
]
|
|
|
|
rskip60_chain_31 = [
|
2023-02-03 13:39:31 +00:00
|
|
|
"0x5aAeb6053F3e94c9b9A09F33669435E7EF1BEaEd",
|
|
|
|
"0xFb6916095CA1dF60bb79CE92ce3Ea74C37c5D359",
|
|
|
|
"0xdbF03B407C01E7cd3cbEa99509D93f8dDDc8C6fB",
|
|
|
|
"0xd1220a0CF47c7B9Be7A2E6Ba89f429762E7b9adB",
|
2018-06-13 16:37:51 +00:00
|
|
|
]
|
2023-02-03 13:39:31 +00:00
|
|
|
|
|
|
|
n = make_network(chain_id=30)
|
2018-06-13 16:37:51 +00:00
|
|
|
for s in rskip60_chain_30:
|
2021-08-31 09:47:56 +00:00
|
|
|
b = unhexlify(s[2:])
|
2019-01-28 14:44:18 +00:00
|
|
|
h = address_from_bytes(b, n)
|
2021-08-31 09:47:56 +00:00
|
|
|
self.assertEqual(h, s)
|
2023-02-03 13:39:31 +00:00
|
|
|
|
|
|
|
n = make_network(chain_id=31)
|
2018-06-13 16:37:51 +00:00
|
|
|
for s in rskip60_chain_31:
|
2021-08-31 09:47:56 +00:00
|
|
|
b = unhexlify(s[2:])
|
2019-01-28 14:44:18 +00:00
|
|
|
h = address_from_bytes(b, n)
|
2021-08-31 09:47:56 +00:00
|
|
|
self.assertEqual(h, s)
|
2018-06-13 16:37:51 +00:00
|
|
|
|
|
|
|
|
2023-02-03 13:39:31 +00:00
|
|
|
if __name__ == "__main__":
|
2018-06-12 15:45:40 +00:00
|
|
|
unittest.main()
|