Skip to content

Commit

Permalink
Merge pull request #78 from skalenetwork/develop
Browse files Browse the repository at this point in the history
New beta release
  • Loading branch information
dmytrotkk authored Jan 10, 2020
2 parents bed3f10 + 068129c commit 0976c1c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/*

Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy_manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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.dev5",
"sgx.py==0.2.1dev2",
],

python_requires='>=3.6,<4',
Expand Down
10 changes: 5 additions & 5 deletions skale/wallets/sgx_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
22 changes: 21 additions & 1 deletion tests/wallets/sgx_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import mock
import web3

from hexbytes import HexBytes
from eth_account.datastructures import AttributeDict
Expand All @@ -17,7 +18,7 @@


class SgxClient:
def __init__(self, endpoint):
def __init__(self, endpoint, path_to_cert=None):
pass

def generate_key(self):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 0976c1c

Please sign in to comment.