diff --git a/scripts/build.sh b/scripts/build.sh index b54514cf..e3ffaa22 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -3,7 +3,7 @@ set -e CURRENT_VERSION="$(python setup.py --version)" -sed -i "s/${CURRENT_VERSION}/${VERSION}/g" setup.py +sed -i "s/version='${CURRENT_VERSION}/version='${VERSION}/g" setup.py rm -rf ./dist/* diff --git a/scripts/deploy_manager.sh b/scripts/deploy_manager.sh index b634c1d4..22e462f4 100644 --- a/scripts/deploy_manager.sh +++ b/scripts/deploy_manager.sh @@ -7,7 +7,7 @@ set -e : "${DOCKER_PASSWORD?Need to set DOCKER_PASSWORD}" : "${MANAGER_BRANCH?Need to set MANAGER_BRANCH}" -docker run -d --network host --name ganache trufflesuite/ganache-cli:latest \ +docker run -d --network host --name ganache trufflesuite/ganache-cli:v6.8.1-beta.0 \ --account="${ETH_PRIVATE_KEY},100000000000000000000000000" -l 80000000 echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin diff --git a/setup.py b/setup.py index 277f1b41..ae9cc5a6 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.dev5", + "sgx.py==0.2.1dev2", ], python_requires='>=3.6,<4', diff --git a/skale/wallets/sgx_wallet.py b/skale/wallets/sgx_wallet.py index c4b1699b..b8aeac34 100644 --- a/skale/wallets/sgx_wallet.py +++ b/skale/wallets/sgx_wallet.py @@ -23,8 +23,8 @@ class SgxWallet(BaseWallet): - def __init__(self, sgx_endpoint, web3, key_name=None): - self.sgx_client = SgxClient(sgx_endpoint) + def __init__(self, sgx_endpoint, web3, key_name=None, path_to_cert=None): + self.sgx_client = SgxClient(sgx_endpoint, path_to_cert=path_to_cert) self._web3 = web3 if key_name is None: self._key_name, self._address, self._public_key = self._generate() @@ -33,12 +33,12 @@ def __init__(self, sgx_endpoint, web3, key_name=None): self._address, self._public_key = self._get_account(key_name) def sign(self, tx_dict): - if not tx_dict.get('nonce'): + if tx_dict.get('nonce') is None: tx_dict['nonce'] = get_eth_nonce(self._web3, self._address) return self.sgx_client.sign(tx_dict, self.key_name) - def sign_and_send(self, tx) -> str: - signed_tx = self.sgx_client.sign(tx, self.key_name) + def sign_and_send(self, tx_dict) -> str: + signed_tx = self.sign(tx_dict) return self._web3.eth.sendRawTransaction(signed_tx.rawTransaction).hex() @property diff --git a/tests/wallets/sgx_test.py b/tests/wallets/sgx_test.py index c824a93f..96b5d7ab 100644 --- a/tests/wallets/sgx_test.py +++ b/tests/wallets/sgx_test.py @@ -1,4 +1,5 @@ import mock +import web3 from hexbytes import HexBytes from eth_account.datastructures import AttributeDict @@ -17,7 +18,7 @@ class SgxClient: - def __init__(self, endpoint): + def __init__(self, endpoint, path_to_cert=None): pass def generate_key(self): @@ -76,6 +77,25 @@ def test_sgx_sign_without_nonce(): wallet.sign(tx_dict) +def test_sgx_sign_and_send_without_nonce(): + with mock.patch.object(web3.eth.Eth, 'sendRawTransaction') as send_tx_mock: + with mock.patch('skale.wallets.sgx_wallet.SgxClient', + new=SgxClient): + web3_inst = init_web3(ENDPOINT) + wallet = SgxWallet('TEST_ENDPOINT', web3_inst) + tx_dict = { + 'to': '0x1057dc7277a319927D3eB43e05680B75a00eb5f4', + 'value': 9, + 'gas': 200000, + 'gasPrice': 1, + '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 + } + signed = wallet.sign(tx_dict) + wallet.sign_and_send(tx_dict) + send_tx_mock.assert_called_with(signed.rawTransaction) + + def test_sgx_sign_with_key(): with mock.patch('skale.wallets.sgx_wallet.SgxClient', new=SgxClient):