88from hexbytes import HexBytes
99import eth_keys
1010from celo_sdk .celo_account .messages import encode_defunct
11+ from celo_sdk .celo_account .account import Account
1112
1213from celo_sdk .kit import Kit
1314from celo_sdk .tests import test_data
@@ -44,46 +45,6 @@ def test_create_acc(self):
4445 self .kit .wallet .sign_with_provider = True
4546 print (self .accounts_wrapper .create_account ())
4647
47- def test_eth_sign (self ):
48- accounts = self .kit .w3 .eth .accounts
49-
50- account = accounts [0 ]
51- signer = accounts [1 ]
52-
53- self .kit .w3 .eth .defaultAccount = signer
54- self .kit .wallet_change_account = signer
55-
56- signature = self .kit .w3 .eth .sign (account = signer , text = '0x8857ae6cb26d382cac66a53711ede22129df1628ab102efa2e4707c9a92cf123' )
57- print (f"Signature:\n { signature .hex ()} " )
58-
59- def test_contract_verify_signature (self ):
60- accounts = self .kit .w3 .eth .accounts
61-
62- account = accounts [0 ]
63- signer = accounts [1 ]
64-
65- self .kit .w3 .eth .defaultAccount = signer
66- self .kit .wallet_change_account = signer
67- print (f"Signer: { signer } " )
68-
69- message = self .kit .w3 .soliditySha3 (['address' ], [signer ]).hex ()
70- message = encode_defunct (text = message )
71- print (f"Message { message .body } " )
72- signature = self .kit .wallet .sign_message (message .body )
73- print (f"signatures of message: { signature } " )
74- print (f"Result: { self .accounts_wrapper ._contract .functions .getSigner (signer , 27 , HexBytes (signature .r ), HexBytes (signature .s )).call ()} " )
75-
76- def test_hash_address_with_contract (self ):
77- accounts = self .kit .w3 .eth .accounts
78-
79- account = accounts [0 ]
80- signer = accounts [1 ]
81-
82- self .kit .w3 .eth .defaultAccount = signer
83- self .kit .wallet_change_account = signer
84-
85- print (f"Hash: { HexBytes (self .accounts_wrapper ._contract .functions .getHashAddress (signer ).call ()).hex ()} " )
86-
8748 def test_pub_key_recovering (self ):
8849 accounts = self .kit .w3 .eth .accounts
8950
@@ -94,34 +55,11 @@ def test_pub_key_recovering(self):
9455 self .kit .wallet_change_account = signer
9556
9657 message = self .kit .w3 .soliditySha3 (['address' ], [signer ]).hex ()
97- message = encode_defunct (text = message )
58+ message = encode_defunct (hexstr = message )
9859 signature = self .kit .wallet .active_account .sign_message (message )
99- print (f"Signature: { signature } " )
100-
101- pub_key = PublicKey .recover_from_msg_hash (message .body , signature ).to_hex ()
102- print (f"Signer pub key: { pub_key } " )
103-
104- def test_recover_with_eth_keys (self ):
105- accounts = self .kit .w3 .eth .accounts
106-
107- account = accounts [0 ]
108- signer = accounts [1 ]
109-
110- self .kit .w3 .eth .defaultAccount = signer
111- self .kit .wallet_change_account = signer
11260
113- signerPrivKey = eth_keys .keys .PrivateKey (HexBytes ('0x5d862464fe9303452126c8bc94274b8c5f9874cbd219789b3eb2128075a76f72' ))
114- print (f"address: { signerPrivKey .public_key .to_checksum_address ()} " )
115- message = self .kit .w3 .soliditySha3 (['address' ], [signer ]).hex ()
116- message = encode_defunct (text = message )
117- signature = signerPrivKey .sign_msg (message .body )
118-
119- recoveredPubKey = signature .recover_public_key_from_msg (message .body )
120- print (f"Recovered pub key: { recoveredPubKey } " )
61+ self .assertEqual (Account .recover_hash_to_pub (message , vrs = signature .vrs ).to_hex (), test_data .recovered_pub_key )
12162
122- signerPubKey = signerPrivKey .public_key
123- print (f"Signare actual pub key: { signerPubKey } " )
124-
12563 def test_authorize_validator_key_not_validator (self ):
12664 accounts = self .kit .w3 .eth .accounts
12765
@@ -135,7 +73,7 @@ def test_authorize_validator_key_not_validator(self):
13573
13674 sig = self .get_parsed_signature_of_address (account , signer )
13775
138- print (self .accounts_wrapper .authorize_validator_signer (signer , sig ))
76+ self . assertTrue (self .accounts_wrapper .authorize_validator_signer (signer , sig ))
13977
14078 def test_authorize_validator_key_validator (self ):
14179 accounts = self .kit .w3 .eth .accounts
@@ -158,7 +96,7 @@ def test_authorize_validator_key_validator(self):
15896 self .kit .wallet_change_account = account
15997 self .kit .w3 .eth .defaultAccount = account
16098
161- print (self .accounts_wrapper .authorize_validator_signer (signer .address , sig ))
99+ self . assertTrue (self .accounts_wrapper .authorize_validator_signer (signer .address , sig ))
162100
163101 def test_authorize_validator_key_change_bls_key (self ):
164102 hex_characters = '0123456789abcdef'
@@ -179,13 +117,13 @@ def test_authorize_validator_key_change_bls_key(self):
179117
180118 sig = self .get_parsed_signature_of_address (account , signer )
181119
182- print (self .accounts_wrapper .authorize_validator_signer_and_bls (signer .address , sig , new_bls_public_key , new_bls_pop ))
120+ self . assertTrue (self .accounts_wrapper .authorize_validator_signer_and_bls (signer .address , sig , new_bls_public_key , new_bls_pop ))
183121
184122 def test_set_wallet_address_to_caller (self ):
185123 accounts = list (self .kit .wallet .accounts .values ())[1 :]
186124
187125 self .accounts_wrapper .create_account ()
188- print (self .accounts_wrapper .set_wallet_address (accounts [0 ]))
126+ self . assertTrue (self .accounts_wrapper .set_wallet_address (accounts [0 ]))
189127
190128 def test_set_wallet_address_to_different_address (self ):
191129 accounts = list (self .kit .wallet .accounts .values ())[1 :]
@@ -197,14 +135,14 @@ def test_set_wallet_address_to_different_address(self):
197135
198136 signature = self .accounts_wrapper .generate_proof_of_key_possession (account , signer )
199137
200- print (self .accounts_wrapper .set_wallet_address (signer , signature ))
138+ self . assertTrue (self .accounts_wrapper .set_wallet_address (signer , signature ))
201139
202140 def test_set_wallet_address_without_signature (self ):
203141 """
204142 Should fail
205143 """
206144 accounts = list (self .kit .wallet .accounts .values ())[1 :]
207- print (self .accounts_wrapper .set_wallet_address (accounts [1 ]))
145+ self . assertTrue (self .accounts_wrapper .set_wallet_address (accounts [1 ]))
208146
209147 def register_account_with_locked_gold (self , account : str ):
210148 if not self .accounts_wrapper .is_account (account ):
@@ -217,7 +155,7 @@ def get_parsed_signature_of_address(self, address: str, signer: 'Account object'
217155 self .kit .wallet_change_account = signer
218156
219157 message = self .kit .w3 .soliditySha3 (['address' ], [address ]).hex ()
220- message = encode_defunct (text = message )
158+ message = encode_defunct (hexstr = message )
221159 signature = self .kit .wallet .active_account .sign_message (message )
222160
223161 self .kit .w3 .eth .defaultAccount = address
0 commit comments