diff --git a/setup.py b/setup.py index bda3d8e0..2d305690 100644 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ "web3==5.2.2", "asyncio==3.4.3", "pyyaml==5.1.2", - "sgx.py>=0.2.dev1", + "sgx.py>=0.2.dev3", ], python_requires='>=3.6,<4', diff --git a/skale/wallets/sgx_wallet.py b/skale/wallets/sgx_wallet.py index 69191abe..f2b134fa 100644 --- a/skale/wallets/sgx_wallet.py +++ b/skale/wallets/sgx_wallet.py @@ -26,9 +26,9 @@ def __init__(self, sgx_endpoint, web3, key_name=None): self.sgx_client = SgxClient(sgx_endpoint) self._web3 = web3 if key_name is None: - self.key_name, self._address, self._public_key = self._generate() + self._key_name, self._address, self._public_key = self._generate() else: - self.key_name = key_name + self._key_name = key_name self._address, self._public_key = self._get_account(key_name) def sign(self, tx): @@ -46,14 +46,14 @@ def address(self): def public_key(self): return self._public_key - def rename_key(self, new_key): - self.sgx_client.rename_key(self.key_name, new_key) - self.key_name = new_key + @property + def key_name(self): + return self._key_name def _generate(self): account = self.sgx_client.generate_key() - return account.keyName, account.address, account.publicKey + return account.key_name, account.address, account.public_key def _get_account(self, key_name): account = self.sgx_client.get_account(key_name) - return account.address, account.publicKey + return account.address, account.public_key diff --git a/tests/wallets/sgx_test.py b/tests/wallets/sgx_test.py index bcfa9aff..a6f318dd 100644 --- a/tests/wallets/sgx_test.py +++ b/tests/wallets/sgx_test.py @@ -14,15 +14,15 @@ def __init__(self, endpoint): def generate_key(self): return AttributeDict({ - 'keyName': 'tmp_NEK:aaabbb', + 'key_name': 'NEK:aaabbb', 'address': '0xAB00000000000000000000000000000000000000', - 'publicKey': 'ab00000000000000000000000000000000000000', + 'public_key': 'ab00000000000000000000000000000000000000', }) def get_account(self, key_name): return AttributeDict({ 'address': '0xAB00000000000000000000000000000000000000', - 'publicKey': 'ab00000000000000000000000000000000000000', + 'public_key': 'ab00000000000000000000000000000000000000', }) def sign(self, transaction_dict, key_name): @@ -72,19 +72,11 @@ def test_sgx_sign_with_key(): wallet.sign(tx_dict) -def test_sgx_sign_with_rename(): +def test_sgx_key_init(): with mock.patch('skale.wallets.sgx_wallet.SgxClient', new=SgxClient): web3 = init_web3(ENDPOINT) - wallet = SgxWallet('TEST_ENDPOINT', web3) - wallet.rename_key('NEW_KEY') - tx_dict = { - 'to': '0x1057dc7277a319927D3eB43e05680B75a00eb5f4', - 'value': 9, - 'gas': 200000, - 'gasPrice': 1, - 'nonce': 7, - 'chainId': None, - 'data': b'\x9b\xd9\xbb\xc6\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x95qY\xc4i\xfc;\xba\xa8\xe3\x9e\xe0\xa3$\xc28\x8a\xd6Q\xe5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\r\xe0\xb6\xb3\xa7d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00`\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x006\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa8\xc0\x04/Rglamorous-kitalpha\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' # noqa - } - wallet.sign(tx_dict) + wallet = SgxWallet('TEST_ENDPOINT', web3, 'TEST_KEY') + assert wallet.key_name == 'TEST_KEY' + assert wallet.address == '0xAB00000000000000000000000000000000000000' + assert wallet.public_key == 'ab00000000000000000000000000000000000000'