1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-23 07:58:09 +00:00
trezor-firmware/core/tests/test_apps.bitcoin.address_grs.py

106 lines
3.9 KiB
Python
Raw Normal View History

from common import * # isort:skip
2018-07-07 16:36:16 +00:00
from trezor.crypto import bip32, bip39
from apps.bitcoin.addresses import *
from apps.bitcoin.common import *
2018-07-07 16:36:16 +00:00
from apps.common import coins
def node_derive(root, path):
node = root.clone()
node.derive_path(path)
return node
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
2018-07-07 16:36:16 +00:00
class TestAddressGRS(unittest.TestCase):
# pylint: disable=C0301
def test_p2pkh_node_derive_address(self):
2023-06-28 10:46:29 +00:00
coin = coins.by_name("Groestlcoin")
seed = bip39.seed(" ".join(["all"] * 12), "")
2018-07-07 16:36:16 +00:00
root = bip32.from_seed(seed, coin.curve_name)
2023-06-28 10:46:29 +00:00
node = node_derive(
root, [44 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 1, 0]
)
address = node.address(coin.address_type) # generate in trezor-crypto
self.assertEqual(address, "FmRaqvVBRrAp2Umfqx9V1ectZy8gw54QDN")
address = address_pkh(node.public_key(), coin) # generate in trezor-core
self.assertEqual(address, "FmRaqvVBRrAp2Umfqx9V1ectZy8gw54QDN")
node = node_derive(
root, [44 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 1, 1]
)
2018-07-07 16:36:16 +00:00
address = node.address(coin.address_type)
2023-06-28 10:46:29 +00:00
self.assertEqual(address, "Fmhtxeh7YdCBkyQF7AQG4QnY8y3rJg89di")
2018-07-07 16:36:16 +00:00
address = address_pkh(node.public_key(), coin)
2023-06-28 10:46:29 +00:00
self.assertEqual(address, "Fmhtxeh7YdCBkyQF7AQG4QnY8y3rJg89di")
2018-07-07 16:36:16 +00:00
2023-06-28 10:46:29 +00:00
node = node_derive(
root, [44 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 0, 0]
)
2018-07-07 16:36:16 +00:00
address = node.address(coin.address_type)
2023-06-28 10:46:29 +00:00
self.assertEqual(address, "Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM")
2018-07-07 16:36:16 +00:00
address = address_pkh(node.public_key(), coin)
2023-06-28 10:46:29 +00:00
self.assertEqual(address, "Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM")
2018-07-07 16:36:16 +00:00
def test_p2wpkh_in_p2sh_node_derive_address(self):
2023-06-28 10:46:29 +00:00
coin = coins.by_name("Groestlcoin Testnet")
seed = bip39.seed(" ".join(["all"] * 12), "")
2018-07-07 16:36:16 +00:00
root = bip32.from_seed(seed, coin.curve_name)
2023-06-28 10:46:29 +00:00
node = node_derive(
root, [49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0]
)
2018-07-07 16:36:16 +00:00
address = address_p2wpkh_in_p2sh(node.public_key(), coin)
2023-06-28 10:46:29 +00:00
self.assertEqual(address, "2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7")
2018-07-07 16:36:16 +00:00
2023-06-28 10:46:29 +00:00
node = node_derive(
root, [49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 1]
)
2018-07-07 16:36:16 +00:00
address = address_p2wpkh_in_p2sh(node.public_key(), coin)
2023-06-28 10:46:29 +00:00
self.assertEqual(address, "2NFWLCJQBSpz1oUJwwLpX8ECifFWGxQyzGu")
2018-07-07 16:36:16 +00:00
2023-06-28 10:46:29 +00:00
node = node_derive(
root, [49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0]
)
2018-07-07 16:36:16 +00:00
address = address_p2wpkh_in_p2sh(node.public_key(), coin)
2023-06-28 10:46:29 +00:00
self.assertEqual(address, "2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e")
2018-07-07 16:36:16 +00:00
def test_p2sh_address(self):
2023-06-28 10:46:29 +00:00
coin = coins.by_name("Groestlcoin Testnet")
2018-07-07 16:36:16 +00:00
2023-06-28 10:46:29 +00:00
address = address_p2sh(
unhexlify("7a55d61848e77ca266e79a39bfc85c580a6426c9"), coin
)
self.assertEqual(address, "2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e")
2018-07-07 16:36:16 +00:00
def test_p2wpkh_node_derive_address(self):
2023-06-28 10:46:29 +00:00
coin = coins.by_name("Groestlcoin")
seed = bip39.seed(" ".join(["all"] * 12), "")
2018-07-07 16:36:16 +00:00
root = bip32.from_seed(seed, coin.curve_name)
2023-06-28 10:46:29 +00:00
node = node_derive(
root, [84 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 1, 0]
)
address = address_p2wpkh(node.public_key(), coin)
2023-06-28 10:46:29 +00:00
self.assertEqual(address, "grs1qzfpwn55tvkxcw0xwfa0g8k2gtlzlgkcq3z000e")
2018-07-07 16:36:16 +00:00
2023-06-28 10:46:29 +00:00
node = node_derive(
root, [84 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 1, 1]
)
address = address_p2wpkh(node.public_key(), coin)
2023-06-28 10:46:29 +00:00
self.assertEqual(address, "grs1qxsgwl66tx7tsuwfm4kk5c5dh6tlfpr4qjqg6gg")
2018-07-07 16:36:16 +00:00
2023-06-28 10:46:29 +00:00
node = node_derive(
root, [84 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 0, 0]
)
address = address_p2wpkh(node.public_key(), coin)
2023-06-28 10:46:29 +00:00
self.assertEqual(address, "grs1qw4teyraux2s77nhjdwh9ar8rl9dt7zww8r6lne")
2018-07-07 16:36:16 +00:00
2023-06-28 10:46:29 +00:00
if __name__ == "__main__":
2018-07-07 16:36:16 +00:00
unittest.main()