-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathtest_wallet.py
More file actions
46 lines (32 loc) · 1.75 KB
/
test_wallet.py
File metadata and controls
46 lines (32 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from eth_hash.auto import keccak
from pyinjective import Address, PrivateKey
class TestPrivateKey:
def test_private_key_signature_generation(self):
private_key = PrivateKey.from_mnemonic("test mnemonic never use other places")
signature = private_key.sign(msg="test message".encode())
expected_signature = (
b'\x8f\xae\xcb#z\x9a+\x12\x88\xea\xb5xZ"\x8f\x98y\xb8\x97\xa7F\xd5\xdd\x15s\x05;'
b"\x04\x1d\xbaY|rw\x8b\xbb\x19\xfc\x8e\x15\x8b\xf1\x18\x08\xba\xc7\x15\xed\xb0\xee\x95"
b"\x0e|Ch\x7f\xaf\x9cH\xc6\x9f\xbf\x14\xa5"
)
assert expected_signature == signature
class TestPublicKey:
def test_convert_public_key_to_address(self):
private_key = PrivateKey.from_mnemonic("test mnemonic never use other places")
public_key = private_key.to_public_key()
address = public_key.to_address()
key = public_key.verify_key.to_string("uncompressed")
hashed_value = keccak(key[1:])
expected_address = Address(hashed_value[12:])
assert expected_address == address
class TestAddress:
def test_from_acc_bech32(self):
address = Address.from_acc_bech32("inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r")
assert address.to_acc_bech32() == "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
eth_address = address.get_ethereum_address()
assert eth_address == "0xbdaedec95d563fb05240d6e01821008454c24c36"
def test_from_eth(self):
address = Address.from_eth_address("0xbdaedec95d563fb05240d6e01821008454c24c36")
assert address.to_acc_bech32() == "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
eth_address = address.get_ethereum_address()
assert eth_address == "0xbdaedec95d563fb05240d6e01821008454c24c36"