|
| 1 | +import time |
| 2 | +import unittest |
| 3 | +import random |
| 4 | + |
| 5 | +from web3 import Web3 |
| 6 | +from eth_keys import keys |
| 7 | + |
| 8 | +from sdk.kit import Kit |
| 9 | +from sdk.tests import test_data |
| 10 | + |
| 11 | + |
| 12 | +class TestAccountsWrapper(unittest.TestCase): |
| 13 | + |
| 14 | + @classmethod |
| 15 | + def setUpClass(self): |
| 16 | + # https://alfajores-forno.celo-testnet.org |
| 17 | + # http://localhost:8545 |
| 18 | + self.kit = Kit('https://alfajores-forno.celo-testnet.org') |
| 19 | + self.accounts_wrapper = self.kit.base_wrapper.create_and_get_contract_by_name( |
| 20 | + 'Accounts') |
| 21 | + self.kit.wallet_add_new_key = test_data.pk1 |
| 22 | + self.kit.wallet_add_new_key = test_data.pk2 |
| 23 | + |
| 24 | + self.validators_contract = self.kit.base_wrapper.create_and_get_contract_by_name( |
| 25 | + 'Validators') |
| 26 | + self.locked_gold_contract = self.kit.base_wrapper.create_and_get_contract_by_name( |
| 27 | + 'LockedGold') |
| 28 | + |
| 29 | + self.min_locked_gold_value = self.kit.w3.toWei(10000, 'ether') |
| 30 | + |
| 31 | + self.bls_public_key = '0x4fa3f67fc913878b068d1fa1cdddc54913d3bf988dbe5a36a20fa888f20d4894c408a6773f3d7bde11154f2a3076b700d345a42fd25a0e5e83f4db5586ac7979ac2053cd95d8f2efd3e959571ceccaa743e02cf4be3f5d7aaddb0b06fc9aff00' |
| 32 | + self.bls_pop = '0xcdb77255037eb68897cd487fdd85388cbda448f617f874449d4b11588b0b7ad8ddc20d9bb450b513bb35664ea3923900' |
| 33 | + |
| 34 | + def test_authorize_validator_key_not_validator(self): |
| 35 | + accounts = list(self.kit.wallet.accounts.values())[1:] |
| 36 | + |
| 37 | + account = accounts[0] |
| 38 | + signer = accounts[1] |
| 39 | + |
| 40 | + self.kit.wallet_change_account = account.address |
| 41 | + |
| 42 | + self.accounts_wrapper.create_account() |
| 43 | + |
| 44 | + sig = self.get_parsed_signature_of_address(account.address, signer.address) |
| 45 | + |
| 46 | + print(self.accounts_wrapper.authorize_validator_signer(signer.address, sig)) |
| 47 | + |
| 48 | + # def test_authorize_validator_key_validator(self): |
| 49 | + # accounts = list(self.kit.wallet.accounts.values())[1:] |
| 50 | + |
| 51 | + # account = accounts[0] |
| 52 | + # signer = accounts[1] |
| 53 | + |
| 54 | + # self.kit.wallet_change_account = account.address |
| 55 | + |
| 56 | + # self.accounts_wrapper.create_account() |
| 57 | + |
| 58 | + # self.setup_validator(account.address) |
| 59 | + |
| 60 | + # sig = self.get_parsed_signature_of_address(account.address, signer.address) |
| 61 | + |
| 62 | + # print(self.accounts_wrapper.authorize_validator_signer(signer.address, sig)) |
| 63 | + |
| 64 | + # def test_authorize_validator_key_change_bls_key(self): |
| 65 | + # hex_characters = '0123456789abcdef' |
| 66 | + # hex_sample = [random.choice(hex_characters) for _ in range(96)] |
| 67 | + # new_bls_public_key = '0x'+''.join(hex_sample) |
| 68 | + |
| 69 | + # hex_sample = [random.choice(hex_characters) for _ in range(48)] |
| 70 | + # new_bls_pop = '0x'+''.join(hex_sample) |
| 71 | + |
| 72 | + # accounts = list(self.kit.wallet.accounts.values())[1:] |
| 73 | + |
| 74 | + # account = accounts[0] |
| 75 | + # signer = accounts[1] |
| 76 | + |
| 77 | + # self.accounts_wrapper.create_account() |
| 78 | + |
| 79 | + # self.setup_validator(account.address) |
| 80 | + |
| 81 | + # sig = self.get_parsed_signature_of_address(account.address, signer.address) |
| 82 | + |
| 83 | + # print(self.accounts_wrapper.authorize_validator_signer_and_bls(signer.address, sig, new_bls_public_key, new_bls_pop)) |
| 84 | + |
| 85 | + # def test_set_wallet_address_to_caller(self): |
| 86 | + # accounts = list(self.kit.wallet.accounts.values())[1:] |
| 87 | + |
| 88 | + # self.accounts_wrapper.create_account() |
| 89 | + # print(self.accounts_wrapper.set_wallet_address(accounts[0].address)) |
| 90 | + |
| 91 | + # def test_set_wallet_address_to_different_address(self): |
| 92 | + # accounts = list(self.kit.wallet.accounts.values())[1:] |
| 93 | + |
| 94 | + # account = accounts[0] |
| 95 | + # signer = accounts[1] |
| 96 | + |
| 97 | + # self.accounts_wrapper.create_account() |
| 98 | + |
| 99 | + # signature = self.accounts_wrapper.generate_proof_of_key_possession(account.address, signer.address) |
| 100 | + |
| 101 | + # print(self.accounts_wrapper.set_wallet_address(signer.address, signature)) |
| 102 | + |
| 103 | + # def test_set_wallet_address_without_signature(self): |
| 104 | + # """ |
| 105 | + # Should fail |
| 106 | + # """ |
| 107 | + # accounts = list(self.kit.wallet.accounts.values())[1:] |
| 108 | + # print(self.accounts_wrapper.set_wallet_address(accounts[1].address)) |
| 109 | + |
| 110 | + # def register_account_with_locked_gold(self, account: str): |
| 111 | + # if not self.accounts_wrapper.is_account(account): |
| 112 | + # _ = self.accounts_wrapper.create_account({'from': account}) |
| 113 | + # _ = self.locked_gold_contract.lock( |
| 114 | + # {'from': account, 'value': self.min_locked_gold_value}) |
| 115 | + |
| 116 | + def get_parsed_signature_of_address(self, address: str, signer: 'Account object') -> 'Signature object': |
| 117 | + message = self.kit.w3.soliditySha3(['address'], [address]).hex() |
| 118 | + signature = self.kit.wallet.active_account.signHash(message) |
| 119 | + return signature |
| 120 | + |
| 121 | + # def setup_validator(self, validator_account: str): |
| 122 | + # """ |
| 123 | + # validator_account should be an address of active account in wallet now |
| 124 | + # """ |
| 125 | + # self.register_account_with_locked_gold(validator_account) |
| 126 | + # priv_key = keys.PrivateKey(self.kit.wallet.active_account.privateKey) |
| 127 | + # pub_key = priv_key.public_key |
| 128 | + # _ = self.validators_contract.register_validator(pub_key, self.bls_public_key, self.bls_pop) |
0 commit comments