Skip to content

Commit

Permalink
Merge pull request #52 from skalenetwork/enhancement/SKALE-1787-updat…
Browse files Browse the repository at this point in the history
…e-sgxwallet

Enhancement/skale 1787 update sgxwallet
  • Loading branch information
DmytroNazarenko authored Nov 20, 2019
2 parents 23de1bf + f8aa7a3 commit 4518036
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 7 additions & 7 deletions skale/wallets/sgx_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
24 changes: 8 additions & 16 deletions tests/wallets/sgx_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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'

0 comments on commit 4518036

Please sign in to comment.