From ca196f2fea8414046ad34c411c8a2e0ac768dc6f Mon Sep 17 00:00:00 2001 From: Vasily Kondratyev Date: Wed, 15 Sep 2021 12:49:16 +0300 Subject: [PATCH 1/8] Add test_erc20_wrapper_contract.py (197-integration-test-for-erc20-wrapper-contract) --- proxy/test_erc20_wrapper_contract.py | 293 +++++++++++++++++++++++++++ 1 file changed, 293 insertions(+) create mode 100644 proxy/test_erc20_wrapper_contract.py diff --git a/proxy/test_erc20_wrapper_contract.py b/proxy/test_erc20_wrapper_contract.py new file mode 100644 index 000000000..62754f595 --- /dev/null +++ b/proxy/test_erc20_wrapper_contract.py @@ -0,0 +1,293 @@ +import unittest +import os +import pprint +from web3 import Web3 +from solcx import install_solc + +# install_solc(version='latest') +install_solc(version='0.7.0') +from solcx import compile_source + +EXTRA_GAS = int(os.environ.get("EXTRA_GAS", "0")) +proxy_url = os.environ.get('PROXY_URL', 'http://localhost:9090/solana') +proxy = Web3(Web3.HTTPProvider(proxy_url)) +eth_account = proxy.eth.account.create('issues/neonlabsorg/proxy-model.py/197') +proxy.eth.default_account = eth_account.address + +NAME = 'NEON' +SYMBOL = 'NEO' + +# token_mint::id = "HPsV9Deocecw3GeZv1FkAPNCBRfuVyfw9MMwjwRe1xaU" in Base58 +# Convert Base58 to hex number: +TOKEN_MINT = bytes.fromhex('f396da383e57418540f8caa598584f49a3b50d256f75cb6d94d101681d6d9d21') + +# Copy of contract: https://github.com/neonlabsorg/neon-evm/blob/develop/evm_loader/SPL_ERC20_Wrapper.sol +ERC20_WRAPPER_SOURCE = ''' +pragma solidity >=0.5.12; + + +interface IERC20 { + function decimals() external view returns (uint8); + function totalSupply() external view returns (uint256); + function balanceOf(address who) external view returns (uint256); + function allowance(address owner, address spender) external view returns (uint256); + function transfer(address to, uint256 value) external returns (bool); + function approve(address spender, uint256 value) external returns (bool); + function transferFrom(address from, address to, uint256 value) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval(address indexed owner, address indexed spender, uint256 value); + + + function approveSolana(bytes32 spender, uint64 value) external returns (bool); + event ApprovalSolana(address indexed owner, bytes32 indexed spender, uint64 value); +} + + + +/*abstract*/ contract NeonERC20Wrapper /*is IERC20*/ { + address constant NeonERC20 = 0xff00000000000000000000000000000000000001; + + string public name; + string public symbol; + bytes32 public tokenMint; + + constructor( + string memory _name, + string memory _symbol, + bytes32 _tokenMint + ) { + name = _name; + symbol = _symbol; + tokenMint = _tokenMint; + } + + fallback() external { + bytes memory call_data = abi.encodePacked(tokenMint, msg.data); + (bool success, bytes memory result) = NeonERC20.delegatecall(call_data); + + require(success, string(result)); + + assembly { + return(add(result, 0x20), mload(result)) + } + } +} +''' + + +class Test_erc20_wrapper_contract(unittest.TestCase): + @classmethod + def setUpClass(cls): + print("\n\nhttps://github.com/neonlabsorg/proxy-model.py/issues/197") + print('eth_account.address:', eth_account.address) + print('eth_account.key:', eth_account.key.hex()) + cls.deploy_erc20_wrapper_contract(cls) + + def deploy_erc20_wrapper_contract(self): + compiled_sol = compile_source(ERC20_WRAPPER_SOURCE) + contract_id, contract_interface = compiled_sol.popitem() + + erc20 = proxy.eth.contract(abi=contract_interface['abi'], bytecode=contract_interface['bin']) + trx_constructor = erc20.constructor(NAME, SYMBOL, TOKEN_MINT).buildTransaction( + {'nonce': proxy.eth.get_transaction_count(proxy.eth.default_account)} + ) + trx_deploy = proxy.eth.account.sign_transaction(trx_constructor, eth_account.key) + print('trx_deploy:', trx_deploy) + trx_deploy_hash = proxy.eth.send_raw_transaction(trx_deploy.rawTransaction) + print('trx_deploy_hash:', trx_deploy_hash.hex()) + trx_deploy_receipt = proxy.eth.wait_for_transaction_receipt(trx_deploy_hash) + print('trx_deploy_receipt:', trx_deploy_receipt) + + self.erc20_contract = proxy.eth.contract( + address=trx_deploy_receipt.contractAddress, + abi=erc20.abi + ) + + # @unittest.skip("a.i.") + def test_erc20_name(self): + print("\ntest_erc20_name") + name = self.erc20_contract.functions.name().call() + print('name:', name) + self.assertEqual(name, NAME) + + @unittest.skip("a.i.") + def test_02_execute_with_right_nonce(self): + print("\ntest_02_execute_with_right_nonce") + right_nonce = proxy.eth.get_transaction_count(proxy.eth.default_account) + trx_store = self.storage_contract.functions.store(147).buildTransaction({'nonce': right_nonce}) + print('trx_store:', trx_store) + trx_store_signed = proxy.eth.account.sign_transaction(trx_store, eth_account.key) + print('trx_store_signed:', trx_store_signed) + trx_store_hash = proxy.eth.send_raw_transaction(trx_store_signed.rawTransaction) + print('trx_store_hash:', trx_store_hash.hex()) + trx_store_receipt = proxy.eth.wait_for_transaction_receipt(trx_store_hash) + print('trx_store_receipt:', trx_store_receipt) + number = self.storage_contract.functions.retrieve().call() + print('number:', number) + self.assertEqual(number, 147) + + @unittest.skip("a.i.") + def test_03_execute_with_low_gas(self): + print("\ntest_03_execute_with_low_gas") + right_nonce = proxy.eth.get_transaction_count(proxy.eth.default_account) + trx_store = self.storage_contract.functions.store(148).buildTransaction({'nonce': right_nonce, 'gasPrice': 1}) + print('trx_store:', trx_store) + trx_store['gas'] = trx_store['gas'] - 2 - EXTRA_GAS # less than estimated + print('trx_store:', trx_store) + trx_store_signed = proxy.eth.account.sign_transaction(trx_store, eth_account.key) + print('trx_store_signed:', trx_store_signed) + trx_store_hash = proxy.eth.send_raw_transaction(trx_store_signed.rawTransaction) + print('trx_store_hash:', trx_store_hash.hex()) + trx_store_receipt = proxy.eth.wait_for_transaction_receipt(trx_store_hash) + print('trx_store_receipt:', trx_store_receipt) + self.assertEqual(trx_store_receipt['status'], 0) # false Transaction mined but execution failed + + @unittest.skip("a.i.") + def test_04_execute_with_bad_nonce(self): + print("\ntest_04_execute_with_bad_nonce") + bad_nonce = 1 + proxy.eth.get_transaction_count(proxy.eth.default_account) + trx_store = self.storage_contract.functions.store(147).buildTransaction({'nonce': bad_nonce}) + print('trx_store:', trx_store) + trx_store_signed = proxy.eth.account.sign_transaction(trx_store, eth_account.key) + print('trx_store_signed:', trx_store_signed) + try: + trx_store_hash = proxy.eth.send_raw_transaction(trx_store_signed.rawTransaction) + print('trx_store_hash:', trx_store_hash) + self.assertTrue(False) + except Exception as e: + print('type(e):', type(e)) + print('e:', e) + import json + response = json.loads(str(e).replace('\'', '\"').replace('None', 'null')) + print('response:', response) + print('code:', response['code']) + self.assertEqual(response['code'], -32002) + print('substring_err_147:', SUBSTRING_LOG_ERR_147) + logs = response['data']['logs'] + print('logs:', logs) + log = [s for s in logs if SUBSTRING_LOG_ERR_147 in s][0] + print(log) + self.assertGreater(len(log), len(SUBSTRING_LOG_ERR_147)) + file_name = 'src/entrypoint.rs' + self.assertTrue(file_name in log) + + @unittest.skip("a.i.") + def test_05_transfer_one_gwei(self): + print("\ntest_05_transfer_one_gwei") + eth_account_alice = proxy.eth.account.create('alice') + eth_account_bob = proxy.eth.account.create('bob') + print('eth_account_alice.address:', eth_account_alice.address) + print('eth_account_bob.address:', eth_account_bob.address) + + alice_balance_before_transfer = proxy.eth.get_balance(eth_account_alice.address) + bob_balance_before_transfer = proxy.eth.get_balance(eth_account_bob.address) + print('alice_balance_before_transfer:', alice_balance_before_transfer) + print('bob_balance_before_transfer:', bob_balance_before_transfer) + one_gwei = 1_000_000_000 + print('one_gwei:', one_gwei) + + trx_transfer = proxy.eth.account.sign_transaction(dict( + nonce=proxy.eth.get_transaction_count(eth_account_alice.address), + chainId=proxy.eth.chain_id, + gas=987654321, + gasPrice=0, + to=eth_account_bob.address, + value=one_gwei), + eth_account_alice.key + ) + + print('trx_transfer:', trx_transfer) + trx_transfer_hash = proxy.eth.send_raw_transaction(trx_transfer.rawTransaction) + print('trx_transfer_hash:', trx_transfer_hash.hex()) + trx_transfer_receipt = proxy.eth.wait_for_transaction_receipt(trx_transfer_hash) + print('trx_transfer_receipt:', trx_transfer_receipt) + + alice_balance_after_transfer = proxy.eth.get_balance(eth_account_alice.address) + bob_balance_after_transfer = proxy.eth.get_balance(eth_account_bob.address) + print('alice_balance_after_transfer:', alice_balance_after_transfer) + print('bob_balance_after_transfer:', bob_balance_after_transfer) + self.assertEqual(alice_balance_after_transfer, alice_balance_before_transfer - one_gwei) + self.assertEqual(bob_balance_after_transfer, bob_balance_before_transfer + one_gwei) + + @unittest.skip("a.i.") + def test_06_transfer_one_and_a_half_gweis(self): + print("\ntest_06_transfer_one_and_a_half_gweis") + eth_account_alice = proxy.eth.account.create('alice') + eth_account_bob = proxy.eth.account.create('bob') + print('eth_account_alice.address:', eth_account_alice.address) + print('eth_account_bob.address:', eth_account_bob.address) + + alice_balance_before_transfer = proxy.eth.get_balance(eth_account_alice.address) + bob_balance_before_transfer = proxy.eth.get_balance(eth_account_bob.address) + print('alice_balance_before_transfer:', alice_balance_before_transfer) + print('bob_balance_before_transfer:', bob_balance_before_transfer) + one_and_a_half_gweis = 1_500_000_000 + print('one_and_a_half_gweis:', one_and_a_half_gweis) + + trx_transfer = proxy.eth.account.sign_transaction(dict( + nonce=proxy.eth.get_transaction_count(eth_account_alice.address), + chainId=proxy.eth.chain_id, + gas=987654321, + gasPrice=0, + to=eth_account_bob.address, + value=one_and_a_half_gweis), + eth_account_alice.key + ) + + print('trx_transfer:', trx_transfer) + trx_transfer_hash = proxy.eth.send_raw_transaction(trx_transfer.rawTransaction) + print('trx_transfer_hash:', trx_transfer_hash.hex()) + trx_transfer_receipt = proxy.eth.wait_for_transaction_receipt(trx_transfer_hash) + print('trx_transfer_receipt:', trx_transfer_receipt) + + alice_balance_after_transfer = proxy.eth.get_balance(eth_account_alice.address) + bob_balance_after_transfer = proxy.eth.get_balance(eth_account_bob.address) + print('alice_balance_after_transfer:', alice_balance_after_transfer) + print('bob_balance_after_transfer:', bob_balance_after_transfer) + print('check https://github.com/neonlabsorg/neon-evm/issues/210') + one_gwei = 1_000_000_000 + print('one_gwei:', one_gwei) + self.assertEqual(alice_balance_after_transfer, alice_balance_before_transfer - one_gwei) + self.assertEqual(bob_balance_after_transfer, bob_balance_before_transfer + one_gwei) + + @unittest.skip("a.i.") + def test_07_execute_long_transaction(self): + print("\ntest_07_execute_long_transaction") + trx_initValue = self.test_185_solidity_contract.functions.initValue('185 init value').buildTransaction({'nonce': proxy.eth.get_transaction_count(proxy.eth.default_account)}) + print('trx_initValue:', trx_initValue) + trx_initValue_signed = proxy.eth.account.sign_transaction(trx_initValue, eth_account.key) + print('trx_initValue_signed:', trx_initValue_signed) + trx_initValue_hash = proxy.eth.send_raw_transaction(trx_initValue_signed.rawTransaction) + print('trx_initValue_hash:', trx_initValue_hash.hex()) + trx_initValue_receipt = proxy.eth.wait_for_transaction_receipt(trx_initValue_hash) + print('trx_initValue_hash_receipt:', trx_initValue_receipt) + + value = self.test_185_solidity_contract.functions.getValue().call() + print('value:', value.hex()) + self.assertEqual(value.hex(), '36fb9ea61aba18555110881836366c8d7701685174abe4926673754580ee26c5') + + from datetime import datetime + start = datetime.now() + + times_to_calculate = 10 + trx_calculate = self.test_185_solidity_contract.functions.calculateKeccakAndStore(times_to_calculate).buildTransaction({'nonce': proxy.eth.get_transaction_count(proxy.eth.default_account)}) + print('trx_calculate:', trx_calculate) + trx_calculate_signed = proxy.eth.account.sign_transaction(trx_calculate, eth_account.key) + print('trx_calculate_signed:', trx_calculate_signed) + trx_calculate_hash = proxy.eth.send_raw_transaction(trx_calculate_signed.rawTransaction) + print('trx_calculate_hash:', trx_calculate_hash.hex()) + trx_calculate_receipt = proxy.eth.wait_for_transaction_receipt(trx_calculate_hash) + print('trx_calculate_hash_receipt:', trx_calculate_receipt) + + time_duration = datetime.now() - start + + value = self.test_185_solidity_contract.functions.getValue().call() + print('value:', value.hex()) + self.assertEqual(value.hex(), 'e6d201b1e3aab3b3cc100ea7a0b76fcbb3c2fef88fc4e540f9866d8d2e6e2131') + print('times_to_calculate:', times_to_calculate) + print('time_duration:', time_duration) + + +if __name__ == '__main__': + unittest.main() From 4796c3a714e3b8156cfb8651fc99a39e07577619 Mon Sep 17 00:00:00 2001 From: Vasily Kondratyev Date: Thu, 16 Sep 2021 12:12:06 +0300 Subject: [PATCH 2/8] Introduce ERC20 Interface (197-integration-test-for-erc20-wrapper-contract) --- proxy/test_erc20_wrapper_contract.py | 49 +++++++++++++++++++--------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/proxy/test_erc20_wrapper_contract.py b/proxy/test_erc20_wrapper_contract.py index 62754f595..6bcb1576f 100644 --- a/proxy/test_erc20_wrapper_contract.py +++ b/proxy/test_erc20_wrapper_contract.py @@ -1,11 +1,13 @@ +## File: test_erc20_wrapper_contract.py +## Integration test for the Neon ERC20 Wrapper contract. + import unittest import os -import pprint from web3 import Web3 from solcx import install_solc # install_solc(version='latest') -install_solc(version='0.7.0') +install_solc(version='0.7.6') from solcx import compile_source EXTRA_GAS = int(os.environ.get("EXTRA_GAS", "0")) @@ -21,10 +23,27 @@ # Convert Base58 to hex number: TOKEN_MINT = bytes.fromhex('f396da383e57418540f8caa598584f49a3b50d256f75cb6d94d101681d6d9d21') +# Standard interface of ERC20 contract to generate ABI for wrapper +ERC20_INTERFACE_SOURCE = ''' +pragma solidity >=0.7.0; + +interface IERC20 { + function decimals() external view returns (uint8); + function totalSupply() external view returns (uint256); + function balanceOf(address who) external view returns (uint256); + function allowance(address owner, address spender) external view returns (uint256); + function transfer(address to, uint256 value) external returns (bool); + function approve(address spender, uint256 value) external returns (bool); + function transferFrom(address from, address to, uint256 value) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval(address indexed owner, address indexed spender, uint256 value); +} +''' + # Copy of contract: https://github.com/neonlabsorg/neon-evm/blob/develop/evm_loader/SPL_ERC20_Wrapper.sol ERC20_WRAPPER_SOURCE = ''' -pragma solidity >=0.5.12; - +pragma solidity >=0.7.0; interface IERC20 { function decimals() external view returns (uint8); @@ -38,13 +57,10 @@ event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); - function approveSolana(bytes32 spender, uint64 value) external returns (bool); event ApprovalSolana(address indexed owner, bytes32 indexed spender, uint64 value); } - - /*abstract*/ contract NeonERC20Wrapper /*is IERC20*/ { address constant NeonERC20 = 0xff00000000000000000000000000000000000001; @@ -75,7 +91,6 @@ } ''' - class Test_erc20_wrapper_contract(unittest.TestCase): @classmethod def setUpClass(cls): @@ -85,19 +100,23 @@ def setUpClass(cls): cls.deploy_erc20_wrapper_contract(cls) def deploy_erc20_wrapper_contract(self): - compiled_sol = compile_source(ERC20_WRAPPER_SOURCE) - contract_id, contract_interface = compiled_sol.popitem() + compiled_interface = compile_source(ERC20_INTERFACE_SOURCE) + interface_id, interface = compiled_interface.popitem() + + compiled_wrapper = compile_source(ERC20_WRAPPER_SOURCE) + wrapper_id, wrapper_interface = compiled_wrapper.popitem() - erc20 = proxy.eth.contract(abi=contract_interface['abi'], bytecode=contract_interface['bin']) + erc20 = proxy.eth.contract(abi=wrapper_interface['abi'], bytecode=wrapper_interface['bin']) trx_constructor = erc20.constructor(NAME, SYMBOL, TOKEN_MINT).buildTransaction( {'nonce': proxy.eth.get_transaction_count(proxy.eth.default_account)} ) trx_deploy = proxy.eth.account.sign_transaction(trx_constructor, eth_account.key) - print('trx_deploy:', trx_deploy) + #print('trx_deploy:', trx_deploy) trx_deploy_hash = proxy.eth.send_raw_transaction(trx_deploy.rawTransaction) - print('trx_deploy_hash:', trx_deploy_hash.hex()) + #print('trx_deploy_hash:', trx_deploy_hash.hex()) trx_deploy_receipt = proxy.eth.wait_for_transaction_receipt(trx_deploy_hash) - print('trx_deploy_receipt:', trx_deploy_receipt) + #print('trx_deploy_receipt:', trx_deploy_receipt) + print('deploy status:', trx_deploy_receipt.status) self.erc20_contract = proxy.eth.contract( address=trx_deploy_receipt.contractAddress, @@ -106,9 +125,7 @@ def deploy_erc20_wrapper_contract(self): # @unittest.skip("a.i.") def test_erc20_name(self): - print("\ntest_erc20_name") name = self.erc20_contract.functions.name().call() - print('name:', name) self.assertEqual(name, NAME) @unittest.skip("a.i.") From 5f4b5ee276658542e1338895b486635220d18929 Mon Sep 17 00:00:00 2001 From: Vasily Kondratyev Date: Thu, 16 Sep 2021 15:09:47 +0300 Subject: [PATCH 3/8] Add test decimals (197-integration-test-for-erc20-wrapper-contract) --- proxy/test_erc20_wrapper_contract.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/proxy/test_erc20_wrapper_contract.py b/proxy/test_erc20_wrapper_contract.py index 6bcb1576f..bb3457d8f 100644 --- a/proxy/test_erc20_wrapper_contract.py +++ b/proxy/test_erc20_wrapper_contract.py @@ -95,18 +95,20 @@ class Test_erc20_wrapper_contract(unittest.TestCase): @classmethod def setUpClass(cls): print("\n\nhttps://github.com/neonlabsorg/proxy-model.py/issues/197") - print('eth_account.address:', eth_account.address) print('eth_account.key:', eth_account.key.hex()) + print('eth_account.address:', eth_account.address) cls.deploy_erc20_wrapper_contract(cls) def deploy_erc20_wrapper_contract(self): compiled_interface = compile_source(ERC20_INTERFACE_SOURCE) interface_id, interface = compiled_interface.popitem() + self.interface = interface compiled_wrapper = compile_source(ERC20_WRAPPER_SOURCE) wrapper_id, wrapper_interface = compiled_wrapper.popitem() + self.wrapper = wrapper_interface - erc20 = proxy.eth.contract(abi=wrapper_interface['abi'], bytecode=wrapper_interface['bin']) + erc20 = proxy.eth.contract(abi=self.wrapper['abi'], bytecode=wrapper_interface['bin']) trx_constructor = erc20.constructor(NAME, SYMBOL, TOKEN_MINT).buildTransaction( {'nonce': proxy.eth.get_transaction_count(proxy.eth.default_account)} ) @@ -117,17 +119,23 @@ def deploy_erc20_wrapper_contract(self): trx_deploy_receipt = proxy.eth.wait_for_transaction_receipt(trx_deploy_hash) #print('trx_deploy_receipt:', trx_deploy_receipt) print('deploy status:', trx_deploy_receipt.status) + self.contract_address= trx_deploy_receipt.contractAddress - self.erc20_contract = proxy.eth.contract( - address=trx_deploy_receipt.contractAddress, - abi=erc20.abi - ) - - # @unittest.skip("a.i.") def test_erc20_name(self): - name = self.erc20_contract.functions.name().call() + erc20 = proxy.eth.contract(address=self.contract_address, abi=self.wrapper['abi']) + name = erc20.functions.name().call() self.assertEqual(name, NAME) + def test_erc20_symbol(self): + erc20 = proxy.eth.contract(address=self.contract_address, abi=self.wrapper['abi']) + sym = erc20.functions.symbol().call() + self.assertEqual(sym, SYMBOL) + + def test_erc20_decimals(self): + erc20 = proxy.eth.contract(address=self.contract_address, abi=self.interface['abi']) + decs = erc20.functions.decimals().call() + self.assertEqual(decs, 9) + @unittest.skip("a.i.") def test_02_execute_with_right_nonce(self): print("\ntest_02_execute_with_right_nonce") From 036a7728b2d85bf12db83ba5ebb8ac48d91c6761 Mon Sep 17 00:00:00 2001 From: Vasily Kondratyev Date: Thu, 16 Sep 2021 15:13:50 +0300 Subject: [PATCH 4/8] Add test totalSupply (197-integration-test-for-erc20-wrapper-contract) --- proxy/test_erc20_wrapper_contract.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/proxy/test_erc20_wrapper_contract.py b/proxy/test_erc20_wrapper_contract.py index bb3457d8f..4ea5bf531 100644 --- a/proxy/test_erc20_wrapper_contract.py +++ b/proxy/test_erc20_wrapper_contract.py @@ -13,7 +13,7 @@ EXTRA_GAS = int(os.environ.get("EXTRA_GAS", "0")) proxy_url = os.environ.get('PROXY_URL', 'http://localhost:9090/solana') proxy = Web3(Web3.HTTPProvider(proxy_url)) -eth_account = proxy.eth.account.create('issues/neonlabsorg/proxy-model.py/197') +eth_account = proxy.eth.account.create('issues/neonlabsorg/proxy-model.py/197/admin') proxy.eth.default_account = eth_account.address NAME = 'NEON' @@ -136,6 +136,11 @@ def test_erc20_decimals(self): decs = erc20.functions.decimals().call() self.assertEqual(decs, 9) + def test_erc20_totalSupply(self): + erc20 = proxy.eth.contract(address=self.contract_address, abi=self.interface['abi']) + ts = erc20.functions.totalSupply().call() + self.assertEqual(ts, 100000000000000) + @unittest.skip("a.i.") def test_02_execute_with_right_nonce(self): print("\ntest_02_execute_with_right_nonce") From 8c3f32ad5f86207bd768cbae85b22dd7ce0275cb Mon Sep 17 00:00:00 2001 From: Vasily Kondratyev Date: Thu, 16 Sep 2021 19:38:07 +0300 Subject: [PATCH 5/8] Add test_erc20_balanceOf (197-integration-test-for-erc20-wrapper-contract) --- proxy/test_erc20_wrapper_contract.py | 57 ++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/proxy/test_erc20_wrapper_contract.py b/proxy/test_erc20_wrapper_contract.py index 4ea5bf531..25fee0c41 100644 --- a/proxy/test_erc20_wrapper_contract.py +++ b/proxy/test_erc20_wrapper_contract.py @@ -13,8 +13,9 @@ EXTRA_GAS = int(os.environ.get("EXTRA_GAS", "0")) proxy_url = os.environ.get('PROXY_URL', 'http://localhost:9090/solana') proxy = Web3(Web3.HTTPProvider(proxy_url)) -eth_account = proxy.eth.account.create('issues/neonlabsorg/proxy-model.py/197/admin') -proxy.eth.default_account = eth_account.address +admin = proxy.eth.account.create('issues/neonlabsorg/proxy-model.py/197/admin') +user = proxy.eth.account.create('issues/neonlabsorg/proxy-model.py/197/user') +proxy.eth.default_account = admin.address NAME = 'NEON' SYMBOL = 'NEO' @@ -95,8 +96,10 @@ class Test_erc20_wrapper_contract(unittest.TestCase): @classmethod def setUpClass(cls): print("\n\nhttps://github.com/neonlabsorg/proxy-model.py/issues/197") - print('eth_account.key:', eth_account.key.hex()) - print('eth_account.address:', eth_account.address) + print('admin.key:', admin.key.hex()) + print('admin.address:', admin.address) + print('user.key:', user.key.hex()) + print('user.address:', user.address) cls.deploy_erc20_wrapper_contract(cls) def deploy_erc20_wrapper_contract(self): @@ -109,38 +112,62 @@ def deploy_erc20_wrapper_contract(self): self.wrapper = wrapper_interface erc20 = proxy.eth.contract(abi=self.wrapper['abi'], bytecode=wrapper_interface['bin']) - trx_constructor = erc20.constructor(NAME, SYMBOL, TOKEN_MINT).buildTransaction( - {'nonce': proxy.eth.get_transaction_count(proxy.eth.default_account)} - ) - trx_deploy = proxy.eth.account.sign_transaction(trx_constructor, eth_account.key) - #print('trx_deploy:', trx_deploy) - trx_deploy_hash = proxy.eth.send_raw_transaction(trx_deploy.rawTransaction) - #print('trx_deploy_hash:', trx_deploy_hash.hex()) - trx_deploy_receipt = proxy.eth.wait_for_transaction_receipt(trx_deploy_hash) - #print('trx_deploy_receipt:', trx_deploy_receipt) - print('deploy status:', trx_deploy_receipt.status) - self.contract_address= trx_deploy_receipt.contractAddress + nonce = proxy.eth.get_transaction_count(proxy.eth.default_account) + tx = {'nonce': nonce} + tx_constructor = erc20.constructor(NAME, SYMBOL, TOKEN_MINT).buildTransaction(tx) + tx_deploy = proxy.eth.account.sign_transaction(tx_constructor, admin.key) + #print('tx_deploy:', tx_deploy) + tx_deploy_hash = proxy.eth.send_raw_transaction(tx_deploy.rawTransaction) + #print('tx_deploy_hash:', tx_deploy_hash.hex()) + tx_deploy_receipt = proxy.eth.wait_for_transaction_receipt(tx_deploy_hash) + #print('tx_deploy_receipt:', tx_deploy_receipt) + print('deploy status:', tx_deploy_receipt.status) + self.contract_address= tx_deploy_receipt.contractAddress + @unittest.skip("a.i.") def test_erc20_name(self): erc20 = proxy.eth.contract(address=self.contract_address, abi=self.wrapper['abi']) name = erc20.functions.name().call() self.assertEqual(name, NAME) + @unittest.skip("a.i.") def test_erc20_symbol(self): erc20 = proxy.eth.contract(address=self.contract_address, abi=self.wrapper['abi']) sym = erc20.functions.symbol().call() self.assertEqual(sym, SYMBOL) + @unittest.skip("a.i.") def test_erc20_decimals(self): erc20 = proxy.eth.contract(address=self.contract_address, abi=self.interface['abi']) decs = erc20.functions.decimals().call() self.assertEqual(decs, 9) + @unittest.skip("a.i.") def test_erc20_totalSupply(self): erc20 = proxy.eth.contract(address=self.contract_address, abi=self.interface['abi']) ts = erc20.functions.totalSupply().call() self.assertEqual(ts, 100000000000000) + #@unittest.skip("a.i.") + def test_erc20_balanceOf(self): + erc20 = proxy.eth.contract(address=self.contract_address, abi=self.interface['abi']) + b = erc20.functions.balanceOf(admin.address).call() + self.assertGreater(b, 0) + b = erc20.functions.balanceOf(user.address).call() + self.assertEqual(b, 0) + + @unittest.skip("a.i.") + def test_erc20_transfer(self): + erc20 = proxy.eth.contract(address=self.contract_address, abi=self.interface['abi']) + nonce = proxy.eth.get_transaction_count(proxy.eth.default_account) + tx = {'nonce': nonce} + #tx = erc20.functions.transfer(user.address, 1000).buildTransaction(tx) + #print('tx:',tx) + #tx = proxy.eth.account.sign_transaction(tx, admin.key) + #tx_hash = proxy.eth.send_raw_transaction(tx.rawTransaction) + #tx_receipt = proxy.eth.wait_for_transaction_receipt(tx_hash) + #self.assertIsNotNone(tx_receipt) + @unittest.skip("a.i.") def test_02_execute_with_right_nonce(self): print("\ntest_02_execute_with_right_nonce") From e48e7f200159f618ec48444c58547e730872c109 Mon Sep 17 00:00:00 2001 From: Vasily Kondratyev Date: Mon, 20 Sep 2021 16:23:36 +0300 Subject: [PATCH 6/8] Developing (197-integration-test-for-erc20-wrapper-contract) --- proxy/test_erc20_wrapper_contract.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/proxy/test_erc20_wrapper_contract.py b/proxy/test_erc20_wrapper_contract.py index 25fee0c41..4bbf656f1 100644 --- a/proxy/test_erc20_wrapper_contract.py +++ b/proxy/test_erc20_wrapper_contract.py @@ -118,9 +118,9 @@ def deploy_erc20_wrapper_contract(self): tx_deploy = proxy.eth.account.sign_transaction(tx_constructor, admin.key) #print('tx_deploy:', tx_deploy) tx_deploy_hash = proxy.eth.send_raw_transaction(tx_deploy.rawTransaction) - #print('tx_deploy_hash:', tx_deploy_hash.hex()) + print('tx_deploy_hash:', tx_deploy_hash.hex()) tx_deploy_receipt = proxy.eth.wait_for_transaction_receipt(tx_deploy_hash) - #print('tx_deploy_receipt:', tx_deploy_receipt) + print('tx_deploy_receipt:', tx_deploy_receipt) print('deploy status:', tx_deploy_receipt.status) self.contract_address= tx_deploy_receipt.contractAddress @@ -148,7 +148,7 @@ def test_erc20_totalSupply(self): ts = erc20.functions.totalSupply().call() self.assertEqual(ts, 100000000000000) - #@unittest.skip("a.i.") + @unittest.skip("a.i.") def test_erc20_balanceOf(self): erc20 = proxy.eth.contract(address=self.contract_address, abi=self.interface['abi']) b = erc20.functions.balanceOf(admin.address).call() @@ -156,17 +156,17 @@ def test_erc20_balanceOf(self): b = erc20.functions.balanceOf(user.address).call() self.assertEqual(b, 0) - @unittest.skip("a.i.") + #@unittest.skip("a.i.") def test_erc20_transfer(self): erc20 = proxy.eth.contract(address=self.contract_address, abi=self.interface['abi']) nonce = proxy.eth.get_transaction_count(proxy.eth.default_account) tx = {'nonce': nonce} - #tx = erc20.functions.transfer(user.address, 1000).buildTransaction(tx) - #print('tx:',tx) - #tx = proxy.eth.account.sign_transaction(tx, admin.key) - #tx_hash = proxy.eth.send_raw_transaction(tx.rawTransaction) - #tx_receipt = proxy.eth.wait_for_transaction_receipt(tx_hash) - #self.assertIsNotNone(tx_receipt) + tx = erc20.functions.transfer(user.address, 1000).buildTransaction(tx) + tx = proxy.eth.account.sign_transaction(tx, admin.key) + tx_hash = proxy.eth.send_raw_transaction(tx.rawTransaction) + print('tx_hash:',tx_hash) + tx_receipt = proxy.eth.wait_for_transaction_receipt(tx_hash) + self.assertIsNotNone(tx_receipt) @unittest.skip("a.i.") def test_02_execute_with_right_nonce(self): From f0b9b7c21ed5bc080812fa27b4d3df03f3d986ed Mon Sep 17 00:00:00 2001 From: Anton Lisanin Date: Wed, 22 Sep 2021 09:21:13 +0300 Subject: [PATCH 7/8] Fix token accounts creation --- proxy/plugin/solana_rest_api_tools.py | 17 +++++++++++------ proxy/test_erc20_wrapper_contract.py | 2 +- requirements.txt | 3 ++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/proxy/plugin/solana_rest_api_tools.py b/proxy/plugin/solana_rest_api_tools.py index cca640fa4..abd894222 100644 --- a/proxy/plugin/solana_rest_api_tools.py +++ b/proxy/plugin/solana_rest_api_tools.py @@ -760,6 +760,7 @@ def create_account_list_by_emulate(signer, client, ethTrx): sender_ether = bytes.fromhex(ethTrx.sender()) add_keys_05 = [] trx = Transaction() + new_neon_token_acccounts = [] output_json = call_emulated(ethTrx.toAddress.hex(), sender_ether.hex(), ethTrx.callData.hex(), hex(ethTrx.value)) logger.debug("emulator returns: %s", json.dumps(output_json, indent=3)) @@ -789,7 +790,11 @@ def create_account_list_by_emulate(signer, client, ethTrx): code_account_balance = client.get_minimum_balance_for_rent_exemption(code_account_size)["result"] trx.add(createAccountWithSeedTrx(signer.public_key(), signer.public_key(), seed, code_account_balance, code_account_size, PublicKey(evm_loader_id))) add_keys_05.append(AccountMeta(pubkey=code_account, is_signer=False, is_writable=acc_desc["writable"])) - trx.add(createEtherAccountTrx(client, address, evm_loader_id, signer, code_account)[0]) + + (create_trx, solana_address, token_address) = createEtherAccountTrx(client, address, evm_loader_id, signer, code_account) + trx.add(create_trx) + new_neon_token_acccounts.append(token_address) + if address == sender_ether and NEW_USER_AIRDROP_AMOUNT > 0: trx.add(transfer2(Transfer2Params( amount=NEW_USER_AIRDROP_AMOUNT*1_000_000_000, @@ -806,13 +811,13 @@ def create_account_list_by_emulate(signer, client, ethTrx): str(NEW_USER_AIRDROP_AMOUNT)) for token_account in output_json["token_accounts"]: - add_keys_05.append(AccountMeta(pubkey=token_account["key"], is_signer=False, is_writable=True)) + add_keys_05.append(AccountMeta(pubkey=PublicKey(token_account["key"]), is_signer=False, is_writable=True)) - if token_account["new"]: - trx.add(create_associated_token_account(signer.public_key(), token_account["owner"], token_account["mint"])) + if token_account["new"] and (PublicKey(token_account["key"]) not in new_neon_token_acccounts): + trx.add(create_associated_token_account(signer.public_key(), PublicKey(token_account["owner"]), PublicKey(token_account["mint"]))) for account_meta in output_json["solana_accounts"]: - add_keys_05.append(AccountMeta(pubkey=account_meta["pubkey"], is_signer=account_meta["is_signer"], is_writable=account_meta["is_writable"])) + add_keys_05.append(AccountMeta(pubkey=PublicKey(account_meta["pubkey"]), is_signer=account_meta["is_signer"], is_writable=account_meta["is_writable"])) caller_token = get_associated_token_address(PublicKey(sender_sol), ETH_TOKEN_MINT_ID) @@ -969,7 +974,7 @@ def createEtherAccountTrx(client, ether, evm_loader_id, signer, code_acc=None): AccountMeta(pubkey=ASSOCIATED_TOKEN_PROGRAM_ID, is_signer=False, is_writable=False), AccountMeta(pubkey=rentid, is_signer=False, is_writable=False), ])) - return (trx, sol) + return (trx, sol, associated_token) def write_trx_to_holder_account(signer, client, holder, ethTrx): diff --git a/proxy/test_erc20_wrapper_contract.py b/proxy/test_erc20_wrapper_contract.py index 4bbf656f1..0fd1f287c 100644 --- a/proxy/test_erc20_wrapper_contract.py +++ b/proxy/test_erc20_wrapper_contract.py @@ -10,7 +10,7 @@ install_solc(version='0.7.6') from solcx import compile_source -EXTRA_GAS = int(os.environ.get("EXTRA_GAS", "0")) +EXTRA_GAS = int(os.environ.get("EXTRA_GAS", "100000")) proxy_url = os.environ.get('PROXY_URL', 'http://localhost:9090/solana') proxy = Web3(Web3.HTTPProvider(proxy_url)) admin = proxy.eth.account.create('issues/neonlabsorg/proxy-model.py/197/admin') diff --git a/requirements.txt b/requirements.txt index 34f20ed7e..c3c2110a7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,5 +3,6 @@ ecdsa==0.16.0 pysha3==1.0.2 eth-keys==0.3.3 rlp==2.0.1 -web3 +web3==5.22.0 solana==0.10.0 +py-solc-x==1.1.0 \ No newline at end of file From acd3486d33e14338ed5da34a68a6c052a24b2154 Mon Sep 17 00:00:00 2001 From: Anton Lisanin Date: Wed, 22 Sep 2021 10:15:35 +0300 Subject: [PATCH 8/8] Remove unused tests --- proxy/test_erc20_wrapper_contract.py | 186 +-------------------------- 1 file changed, 1 insertion(+), 185 deletions(-) diff --git a/proxy/test_erc20_wrapper_contract.py b/proxy/test_erc20_wrapper_contract.py index 0fd1f287c..90d9c36a8 100644 --- a/proxy/test_erc20_wrapper_contract.py +++ b/proxy/test_erc20_wrapper_contract.py @@ -124,31 +124,26 @@ def deploy_erc20_wrapper_contract(self): print('deploy status:', tx_deploy_receipt.status) self.contract_address= tx_deploy_receipt.contractAddress - @unittest.skip("a.i.") def test_erc20_name(self): erc20 = proxy.eth.contract(address=self.contract_address, abi=self.wrapper['abi']) name = erc20.functions.name().call() self.assertEqual(name, NAME) - @unittest.skip("a.i.") def test_erc20_symbol(self): erc20 = proxy.eth.contract(address=self.contract_address, abi=self.wrapper['abi']) sym = erc20.functions.symbol().call() self.assertEqual(sym, SYMBOL) - @unittest.skip("a.i.") def test_erc20_decimals(self): erc20 = proxy.eth.contract(address=self.contract_address, abi=self.interface['abi']) decs = erc20.functions.decimals().call() self.assertEqual(decs, 9) - @unittest.skip("a.i.") def test_erc20_totalSupply(self): erc20 = proxy.eth.contract(address=self.contract_address, abi=self.interface['abi']) ts = erc20.functions.totalSupply().call() - self.assertEqual(ts, 100000000000000) + self.assertGreater(ts, 0) - @unittest.skip("a.i.") def test_erc20_balanceOf(self): erc20 = proxy.eth.contract(address=self.contract_address, abi=self.interface['abi']) b = erc20.functions.balanceOf(admin.address).call() @@ -156,7 +151,6 @@ def test_erc20_balanceOf(self): b = erc20.functions.balanceOf(user.address).call() self.assertEqual(b, 0) - #@unittest.skip("a.i.") def test_erc20_transfer(self): erc20 = proxy.eth.contract(address=self.contract_address, abi=self.interface['abi']) nonce = proxy.eth.get_transaction_count(proxy.eth.default_account) @@ -168,183 +162,5 @@ def test_erc20_transfer(self): tx_receipt = proxy.eth.wait_for_transaction_receipt(tx_hash) self.assertIsNotNone(tx_receipt) - @unittest.skip("a.i.") - def test_02_execute_with_right_nonce(self): - print("\ntest_02_execute_with_right_nonce") - right_nonce = proxy.eth.get_transaction_count(proxy.eth.default_account) - trx_store = self.storage_contract.functions.store(147).buildTransaction({'nonce': right_nonce}) - print('trx_store:', trx_store) - trx_store_signed = proxy.eth.account.sign_transaction(trx_store, eth_account.key) - print('trx_store_signed:', trx_store_signed) - trx_store_hash = proxy.eth.send_raw_transaction(trx_store_signed.rawTransaction) - print('trx_store_hash:', trx_store_hash.hex()) - trx_store_receipt = proxy.eth.wait_for_transaction_receipt(trx_store_hash) - print('trx_store_receipt:', trx_store_receipt) - number = self.storage_contract.functions.retrieve().call() - print('number:', number) - self.assertEqual(number, 147) - - @unittest.skip("a.i.") - def test_03_execute_with_low_gas(self): - print("\ntest_03_execute_with_low_gas") - right_nonce = proxy.eth.get_transaction_count(proxy.eth.default_account) - trx_store = self.storage_contract.functions.store(148).buildTransaction({'nonce': right_nonce, 'gasPrice': 1}) - print('trx_store:', trx_store) - trx_store['gas'] = trx_store['gas'] - 2 - EXTRA_GAS # less than estimated - print('trx_store:', trx_store) - trx_store_signed = proxy.eth.account.sign_transaction(trx_store, eth_account.key) - print('trx_store_signed:', trx_store_signed) - trx_store_hash = proxy.eth.send_raw_transaction(trx_store_signed.rawTransaction) - print('trx_store_hash:', trx_store_hash.hex()) - trx_store_receipt = proxy.eth.wait_for_transaction_receipt(trx_store_hash) - print('trx_store_receipt:', trx_store_receipt) - self.assertEqual(trx_store_receipt['status'], 0) # false Transaction mined but execution failed - - @unittest.skip("a.i.") - def test_04_execute_with_bad_nonce(self): - print("\ntest_04_execute_with_bad_nonce") - bad_nonce = 1 + proxy.eth.get_transaction_count(proxy.eth.default_account) - trx_store = self.storage_contract.functions.store(147).buildTransaction({'nonce': bad_nonce}) - print('trx_store:', trx_store) - trx_store_signed = proxy.eth.account.sign_transaction(trx_store, eth_account.key) - print('trx_store_signed:', trx_store_signed) - try: - trx_store_hash = proxy.eth.send_raw_transaction(trx_store_signed.rawTransaction) - print('trx_store_hash:', trx_store_hash) - self.assertTrue(False) - except Exception as e: - print('type(e):', type(e)) - print('e:', e) - import json - response = json.loads(str(e).replace('\'', '\"').replace('None', 'null')) - print('response:', response) - print('code:', response['code']) - self.assertEqual(response['code'], -32002) - print('substring_err_147:', SUBSTRING_LOG_ERR_147) - logs = response['data']['logs'] - print('logs:', logs) - log = [s for s in logs if SUBSTRING_LOG_ERR_147 in s][0] - print(log) - self.assertGreater(len(log), len(SUBSTRING_LOG_ERR_147)) - file_name = 'src/entrypoint.rs' - self.assertTrue(file_name in log) - - @unittest.skip("a.i.") - def test_05_transfer_one_gwei(self): - print("\ntest_05_transfer_one_gwei") - eth_account_alice = proxy.eth.account.create('alice') - eth_account_bob = proxy.eth.account.create('bob') - print('eth_account_alice.address:', eth_account_alice.address) - print('eth_account_bob.address:', eth_account_bob.address) - - alice_balance_before_transfer = proxy.eth.get_balance(eth_account_alice.address) - bob_balance_before_transfer = proxy.eth.get_balance(eth_account_bob.address) - print('alice_balance_before_transfer:', alice_balance_before_transfer) - print('bob_balance_before_transfer:', bob_balance_before_transfer) - one_gwei = 1_000_000_000 - print('one_gwei:', one_gwei) - - trx_transfer = proxy.eth.account.sign_transaction(dict( - nonce=proxy.eth.get_transaction_count(eth_account_alice.address), - chainId=proxy.eth.chain_id, - gas=987654321, - gasPrice=0, - to=eth_account_bob.address, - value=one_gwei), - eth_account_alice.key - ) - - print('trx_transfer:', trx_transfer) - trx_transfer_hash = proxy.eth.send_raw_transaction(trx_transfer.rawTransaction) - print('trx_transfer_hash:', trx_transfer_hash.hex()) - trx_transfer_receipt = proxy.eth.wait_for_transaction_receipt(trx_transfer_hash) - print('trx_transfer_receipt:', trx_transfer_receipt) - - alice_balance_after_transfer = proxy.eth.get_balance(eth_account_alice.address) - bob_balance_after_transfer = proxy.eth.get_balance(eth_account_bob.address) - print('alice_balance_after_transfer:', alice_balance_after_transfer) - print('bob_balance_after_transfer:', bob_balance_after_transfer) - self.assertEqual(alice_balance_after_transfer, alice_balance_before_transfer - one_gwei) - self.assertEqual(bob_balance_after_transfer, bob_balance_before_transfer + one_gwei) - - @unittest.skip("a.i.") - def test_06_transfer_one_and_a_half_gweis(self): - print("\ntest_06_transfer_one_and_a_half_gweis") - eth_account_alice = proxy.eth.account.create('alice') - eth_account_bob = proxy.eth.account.create('bob') - print('eth_account_alice.address:', eth_account_alice.address) - print('eth_account_bob.address:', eth_account_bob.address) - - alice_balance_before_transfer = proxy.eth.get_balance(eth_account_alice.address) - bob_balance_before_transfer = proxy.eth.get_balance(eth_account_bob.address) - print('alice_balance_before_transfer:', alice_balance_before_transfer) - print('bob_balance_before_transfer:', bob_balance_before_transfer) - one_and_a_half_gweis = 1_500_000_000 - print('one_and_a_half_gweis:', one_and_a_half_gweis) - - trx_transfer = proxy.eth.account.sign_transaction(dict( - nonce=proxy.eth.get_transaction_count(eth_account_alice.address), - chainId=proxy.eth.chain_id, - gas=987654321, - gasPrice=0, - to=eth_account_bob.address, - value=one_and_a_half_gweis), - eth_account_alice.key - ) - - print('trx_transfer:', trx_transfer) - trx_transfer_hash = proxy.eth.send_raw_transaction(trx_transfer.rawTransaction) - print('trx_transfer_hash:', trx_transfer_hash.hex()) - trx_transfer_receipt = proxy.eth.wait_for_transaction_receipt(trx_transfer_hash) - print('trx_transfer_receipt:', trx_transfer_receipt) - - alice_balance_after_transfer = proxy.eth.get_balance(eth_account_alice.address) - bob_balance_after_transfer = proxy.eth.get_balance(eth_account_bob.address) - print('alice_balance_after_transfer:', alice_balance_after_transfer) - print('bob_balance_after_transfer:', bob_balance_after_transfer) - print('check https://github.com/neonlabsorg/neon-evm/issues/210') - one_gwei = 1_000_000_000 - print('one_gwei:', one_gwei) - self.assertEqual(alice_balance_after_transfer, alice_balance_before_transfer - one_gwei) - self.assertEqual(bob_balance_after_transfer, bob_balance_before_transfer + one_gwei) - - @unittest.skip("a.i.") - def test_07_execute_long_transaction(self): - print("\ntest_07_execute_long_transaction") - trx_initValue = self.test_185_solidity_contract.functions.initValue('185 init value').buildTransaction({'nonce': proxy.eth.get_transaction_count(proxy.eth.default_account)}) - print('trx_initValue:', trx_initValue) - trx_initValue_signed = proxy.eth.account.sign_transaction(trx_initValue, eth_account.key) - print('trx_initValue_signed:', trx_initValue_signed) - trx_initValue_hash = proxy.eth.send_raw_transaction(trx_initValue_signed.rawTransaction) - print('trx_initValue_hash:', trx_initValue_hash.hex()) - trx_initValue_receipt = proxy.eth.wait_for_transaction_receipt(trx_initValue_hash) - print('trx_initValue_hash_receipt:', trx_initValue_receipt) - - value = self.test_185_solidity_contract.functions.getValue().call() - print('value:', value.hex()) - self.assertEqual(value.hex(), '36fb9ea61aba18555110881836366c8d7701685174abe4926673754580ee26c5') - - from datetime import datetime - start = datetime.now() - - times_to_calculate = 10 - trx_calculate = self.test_185_solidity_contract.functions.calculateKeccakAndStore(times_to_calculate).buildTransaction({'nonce': proxy.eth.get_transaction_count(proxy.eth.default_account)}) - print('trx_calculate:', trx_calculate) - trx_calculate_signed = proxy.eth.account.sign_transaction(trx_calculate, eth_account.key) - print('trx_calculate_signed:', trx_calculate_signed) - trx_calculate_hash = proxy.eth.send_raw_transaction(trx_calculate_signed.rawTransaction) - print('trx_calculate_hash:', trx_calculate_hash.hex()) - trx_calculate_receipt = proxy.eth.wait_for_transaction_receipt(trx_calculate_hash) - print('trx_calculate_hash_receipt:', trx_calculate_receipt) - - time_duration = datetime.now() - start - - value = self.test_185_solidity_contract.functions.getValue().call() - print('value:', value.hex()) - self.assertEqual(value.hex(), 'e6d201b1e3aab3b3cc100ea7a0b76fcbb3c2fef88fc4e540f9866d8d2e6e2131') - print('times_to_calculate:', times_to_calculate) - print('time_duration:', time_duration) - - if __name__ == '__main__': unittest.main()