Skip to content

Commit addb0dd

Browse files
author
rozhkovdmitrii
committed
Merge branch 'develop' into 299-emulate-solidity-raise-an-exception
# Conflicts: # proxy/plugin/solana_rest_api_tools.py # proxy/testing/test_airdropping_eth_accounts.py
2 parents 72ef3d0 + 6f3cf9a commit addb0dd

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

proxy/plugin/solana_rest_api_tools.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,16 +1258,21 @@ def make_instruction_data_from_tx(instruction, private_key=None):
12581258
raise Exception("function gets ")
12591259

12601260

1261-
def is_account_exists(client: SolanaClient, pda_account: str) -> bool:
1261+
def is_account_exists(client: SolanaClient, eth_account: EthereumAddress) -> bool:
1262+
pda_account, nonce = ether2program(eth_account)
12621263
info = client.get_account_info(pda_account, commitment=Confirmed)
12631264
value = get_from_dict(info, "result", "value")
12641265
return value is not None
12651266

12661267

1267-
def estimate_gas(client: SolanaClient, signer: SolanaAccount, contract_id: str, eth_caller_address: EthereumAddress,
1268+
def estimate_gas(client: SolanaClient, signer: SolanaAccount, contract_id: str, caller_eth_account: EthereumAddress,
12681269
data: str = None, value: str = None):
1269-
pda_account, nonce = ether2program(eth_caller_address)
1270-
if not is_account_exists(client, pda_account):
1271-
create_eth_account_and_airdrop(client, signer, eth_caller_address)
1272-
result = call_emulated(contract_id, str(eth_caller_address), data, value)
1273-
return result['used_gas'] + EXTRA_GAS
1270+
if not is_account_exists(client, caller_eth_account):
1271+
create_eth_account_and_airdrop(client, signer, caller_eth_account)
1272+
result = call_emulated(contract_id, str(caller_eth_account), data, value)
1273+
used_gas = result.get("used_gas")
1274+
if used_gas is None:
1275+
logger.error(f"Failed estimate_gas, unexpected result, by contract_id: {contract_id}, caller_eth_account: "
1276+
f"{caller_eth_account}, data: {data}, value: {value}, emulation result: {result}")
1277+
raise Exception("Bad estimate_gas result")
1278+
return used_gas + EXTRA_GAS

proxy/testing/test_airdropping_eth_accounts.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from solana.rpc.api import Client as SolanaClient
1212

1313
from ..plugin.solana_rest_api import EthereumModel
14-
from ..plugin.solana_rest_api_tools import get_token_balance_gwei, EthereumAddress, ether2program
14+
from ..plugin.solana_rest_api_tools import get_token_balance_gwei, ether2program
1515

1616

1717
class TestAirdroppingEthAccounts(unittest.TestCase):
@@ -50,9 +50,15 @@ def test_airdrop_onto_wrapped_new_address(self):
5050
self.assertEqual(self._EXPECTED_BALANCE_WEI, wrapper_actual_balance)
5151
self.assertEqual(self._EXPECTED_BALANCE_WEI, nested_actual_balance)
5252

53-
def test_raise_on_constructing(self):
54-
contract_owner: LocalAccount = self._web3.eth.account.create()
55-
contract = self._compile_and_deploy_contract(contract_owner, self._WRAPPER_CONTRACT_STORAGE_SOURCE)
53+
def test_airdrop_on_deploy_estimation(self):
54+
owner_eth_account: LocalAccount = self._web3.eth.account.create()
55+
compile_result = solcx.compile_source(self._CONTRACT_STORAGE_SOURCE)
56+
_, contract_interface = compile_result.popitem()
57+
contract_data = contract_interface.get("bin")
58+
self.assertIsNotNone(contract_data)
59+
self._web3.eth.estimate_gas({"from": owner_eth_account.address, "data": contract_data})
60+
owner_balance = self._get_balance_wei(owner_eth_account.address)
61+
self.assertEqual(self._EXPECTED_BALANCE_WEI, owner_balance)
5662

5763
def test_eth_call_array_constructable_contract(self):
5864
compile_result = solcx.compile_source(self._CONTRACT_LIST_CONSTRUCTABLE)
@@ -65,8 +71,8 @@ def test_eth_call_array_constructable_contract(self):
6571
self.assertEqual("ListConstructable: empty list", str(cm.exception))
6672

6773
def _compile_and_deploy_contract(self, contract_owner: LocalAccount, source: str) -> web3_eth.Contract:
68-
compiled_sol = solcx.compile_source(source)
69-
contract_id, contract_interface = compiled_sol.popitem()
74+
compile_result = solcx.compile_source(source)
75+
contract_id, contract_interface = compile_result.popitem()
7076
contract = self._web3.eth.contract(abi=contract_interface['abi'], bytecode=contract_interface['bin'])
7177
nonce = self._web3.eth.get_transaction_count(contract_owner.address)
7278
chain_id = self._web3.eth.chain_id
@@ -78,8 +84,8 @@ def _compile_and_deploy_contract(self, contract_owner: LocalAccount, source: str
7884
contract = self._web3.eth.contract(address=trx_receipt.contractAddress, abi=contract.abi)
7985
return contract
8086

81-
def _get_balance_wei(self, eth_acc: str) -> int:
82-
token_owner_account, nonce = ether2program(eth_acc)
87+
def _get_balance_wei(self, eth_account: str) -> int:
88+
token_owner_account, nonce = ether2program(eth_account)
8389
balance = get_token_balance_gwei(self._solana_client, token_owner_account)
8490
self.assertIsNotNone(balance)
8591
self.assertIsInstance(balance, int)

0 commit comments

Comments
 (0)