From 3085e0b17cd3c14bda8d97d98030feca921b26c3 Mon Sep 17 00:00:00 2001 From: Vasiliy Zaznobin Date: Fri, 11 Feb 2022 15:29:09 +0300 Subject: [PATCH 1/2] Check that the user's account balance is less than required and raise an RuntimeError --- proxy/docker-compose-test.yml | 1 + proxy/plugin/gas_price_calculator.py | 10 +++- proxy/plugin/solana_rest_api.py | 12 +++- proxy/run-set-env.sh | 6 +- proxy/testing/test_airdropper_integration.py | 2 + proxy/testing/test_create_account_block.py | 4 +- proxy/testing/test_erc20_wrapper_contract.py | 4 ++ proxy/testing/test_eth_estimateGas.py | 5 +- proxy/testing/test_eth_getLogs.py | 5 +- proxy/testing/test_eth_sendRawTransaction.py | 56 +++++++++++++++---- proxy/testing/test_gas_price_calculator.py | 13 +++-- proxy/testing/test_indexer_work.py | 2 +- proxy/testing/test_neon_faucet.py | 3 + proxy/testing/test_operator_spending.py | 5 +- proxy/testing/test_permission_token.py | 4 ++ proxy/testing/test_query_account_contract.py | 3 + proxy/testing/test_read_only_accounts.py | 9 ++- proxy/testing/test_resize_storage_account.py | 4 +- .../testing/test_retry_on_blocked_accounts.py | 7 ++- proxy/testing/testing_helpers.py | 2 +- 20 files changed, 121 insertions(+), 36 deletions(-) diff --git a/proxy/docker-compose-test.yml b/proxy/docker-compose-test.yml index d0b104088..9b4f3c1cc 100644 --- a/proxy/docker-compose-test.yml +++ b/proxy/docker-compose-test.yml @@ -73,6 +73,7 @@ services: PYTH_MAPPING_ACCOUNT: BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2 MIN_OPERATOR_BALANCE_TO_WARN: 4565760000 # = 913152000 * 5 (5 storage accounts) = 4.56576 SOL MIN_OPERATOR_BALANCE_TO_ERR: 913152000 # = solana rent 131072 (= Rent-exempt minimum: 0.913152 SOL) SOLs to create a storage + MINIMAL_GAS_PRICE: 1 hostname: proxy depends_on: postgres: diff --git a/proxy/plugin/gas_price_calculator.py b/proxy/plugin/gas_price_calculator.py index 05bd0e106..ce7ac2915 100644 --- a/proxy/plugin/gas_price_calculator.py +++ b/proxy/plugin/gas_price_calculator.py @@ -16,13 +16,17 @@ def __init__(self, solana_client, pyth_mapping_acc) -> None: self.recent_sol_price_update_time = None self.min_gas_price = None + def env_min_gas_price(self): + if MINIMAL_GAS_PRICE is not None: + return MINIMAL_GAS_PRICE + def update_mapping(self): if self.mapping_account is not None: self.pyth_network_client.update_mapping(self.mapping_account) def get_min_gas_price(self): - if MINIMAL_GAS_PRICE is not None: - return MINIMAL_GAS_PRICE + if self.env_min_gas_price() is not None: + return self.env_min_gas_price() self.try_update_gas_price() return self.min_gas_price @@ -60,4 +64,4 @@ def start_update_gas_price(self, cur_time): raise Exception('Failed to estimate gas price. Try again later') self.info(f'Will retry getting price after {GET_SOL_PRICE_RETRY_INTERVAL} seconds') - time.sleep(GET_SOL_PRICE_RETRY_INTERVAL) \ No newline at end of file + time.sleep(GET_SOL_PRICE_RETRY_INTERVAL) diff --git a/proxy/plugin/solana_rest_api.py b/proxy/plugin/solana_rest_api.py index 216836271..c670a0a12 100644 --- a/proxy/plugin/solana_rest_api.py +++ b/proxy/plugin/solana_rest_api.py @@ -361,9 +361,19 @@ def eth_sendRawTransaction(self, rawTrx): min_gas_price = self.gas_price_calculator.get_min_gas_price() if trx.gasPrice < min_gas_price: - raise RuntimeError("The transaction gasPrice is less then the minimum allowable value" + + raise RuntimeError("The transaction gasPrice is less than the minimum allowable value" + f"({trx.gasPrice}<{min_gas_price})") + user_balance = int(self.eth_getBalance('0x' + trx.sender(), 'latest'), 16) + fee = trx.gasPrice * trx.gasLimit + required_balance = fee + trx.value + if user_balance < required_balance: + raise RuntimeError("The account balance is less than required: " + + f"Account {trx.sender()}; balance = {user_balance}; " + + f"gasPrice = {trx.gasPrice}; gasLimit = {trx.gasLimit}; " + + f"fee = {fee}; value = {trx.value}; " + + f"required_balance = {required_balance}; ") + eth_signature = '0x' + trx.hash_signed().hex() try: diff --git a/proxy/run-set-env.sh b/proxy/run-set-env.sh index 936888706..7025d5b48 100755 --- a/proxy/run-set-env.sh +++ b/proxy/run-set-env.sh @@ -9,7 +9,7 @@ if [ "$CONFIG" == "ci" ]; then [[ -z "$EXTRA_GAS" ]] && export EXTRA_GAS=100000 [[ -z "$NEON_CLI_TIMEOUT" ]] && export NEON_CLI_TIMEOUT="0.5" [[ -z "$CONTINUE_COUNT_FACTOR" ]] && export CONTINUE_COUNT_FACTOR="3" - [[ -z "$MINIMAL_GAS_PRICE" ]] && export MINIMAL_GAS_PRICE=0 + [[ -z "$MINIMAL_GAS_PRICE" ]] && export MINIMAL_GAS_PRICE=1 [[ -z "$POSTGRES_HOST" ]] && export POSTGRES_HOST="postgres" [[ -z "$CANCEL_TIMEOUT" ]] && export CANCEL_TIMEOUT=10 [[ -z "$RETRY_ON_FAIL" ]] && export RETRY_ON_FAIL=10 @@ -21,7 +21,7 @@ elif [ "$CONFIG" == "local" ]; then [[ -z "$SOLANA_URL" ]] && export SOLANA_URL="http://localhost:8899" [[ -z "$EXTRA_GAS" ]] && export EXTRA_GAS=0 [[ -z "$NEON_CLI_TIMEOUT" ]] && export NEON_CLI_TIMEOUT="0.9" - [[ -z "$MINIMAL_GAS_PRICE" ]] && export MINIMAL_GAS_PRICE=0 + [[ -z "$MINIMAL_GAS_PRICE" ]] && export MINIMAL_GAS_PRICE=1 [[ -z "$POSTGRES_HOST" ]] && export POSTGRES_HOST="localhost" [[ -z "$CANCEL_TIMEOUT" ]] && export CANCEL_TIMEOUT=10 [[ -z "$RETRY_ON_FAIL" ]] && export RETRY_ON_FAIL=10 @@ -47,7 +47,7 @@ elif [ "$CONFIG" == "testnet" ]; then [[ -z "$EVM_LOADER" ]] && export EVM_LOADER=eeLSJgWzzxrqKv1UxtRVVH8FX3qCQWUs9QuAjJpETGU [[ -z "$EXTRA_GAS" ]] && export EXTRA_GAS=90000 [[ -z "$NEON_CLI_TIMEOUT" ]] && export NEON_CLI_TIMEOUT="15" - [[ -z "$MINIMAL_GAS_PRICE" ]] && export MINIMAL_GAS_PRICE="1" + [[ -z "$MINIMAL_GAS_PRICE" ]] && export MINIMAL_GAS_PRICE=1 [[ -z "$POSTGRES_HOST" ]] && export POSTGRES_HOST="localhost" [[ -z "$CANCEL_TIMEOUT" ]] && export CANCEL_TIMEOUT=60 [[ -z "$RETRY_ON_FAIL" ]] && export RETRY_ON_FAIL=10 diff --git a/proxy/testing/test_airdropper_integration.py b/proxy/testing/test_airdropper_integration.py index 75be3338a..a358b0617 100644 --- a/proxy/testing/test_airdropper_integration.py +++ b/proxy/testing/test_airdropper_integration.py @@ -18,6 +18,7 @@ import os import json +from proxy.testing.testing_helpers import request_airdrop MAX_AIRDROP_WAIT_TIME = 45 EVM_LOADER_ID = PublicKey(EVM_LOADER_ID) @@ -28,6 +29,7 @@ proxy = Web3(Web3.HTTPProvider(PROXY_URL)) admin = proxy.eth.account.create('neonlabsorg/proxy-model.py/issues/344/admin20') proxy.eth.default_account = admin.address +request_airdrop(admin.address) # Helper function calculating solana address and nonce from given NEON(Ethereum) address diff --git a/proxy/testing/test_create_account_block.py b/proxy/testing/test_create_account_block.py index ae9a9bff2..be7d345aa 100644 --- a/proxy/testing/test_create_account_block.py +++ b/proxy/testing/test_create_account_block.py @@ -57,7 +57,7 @@ def deploy_contract(self): nonce=proxy.eth.get_transaction_count(eth_account.address), chainId=proxy.eth.chain_id, gas=987654321, - gasPrice=0, + gasPrice=1000000000, to='', value=0, data=storage.bytecode), @@ -72,7 +72,7 @@ def transfer(self, target_account, value): nonce=proxy.eth.get_transaction_count(eth_account.address), chainId=proxy.eth.chain_id, gas=987654321, - gasPrice=0, + gasPrice=1000000000, to=bytes(target_account), value=value), eth_account.key diff --git a/proxy/testing/test_erc20_wrapper_contract.py b/proxy/testing/test_erc20_wrapper_contract.py index c08a94b34..629912111 100644 --- a/proxy/testing/test_erc20_wrapper_contract.py +++ b/proxy/testing/test_erc20_wrapper_contract.py @@ -18,12 +18,16 @@ from proxy.common_neon.neon_instruction import NeonInstruction from solana.rpc.types import TokenAccountOpts +from proxy.testing.testing_helpers import request_airdrop + proxy_url = os.environ.get('PROXY_URL', 'http://127.0.0.1:9090/solana') solana_url = os.environ.get("SOLANA_URL", "http://127.0.0.1:8899") proxy = Web3(Web3.HTTPProvider(proxy_url)) 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 +request_airdrop(admin.address) +request_airdrop(user.address) NAME = 'NEON' SYMBOL = 'NEO' diff --git a/proxy/testing/test_eth_estimateGas.py b/proxy/testing/test_eth_estimateGas.py index 715b0f0a4..f6627dad4 100644 --- a/proxy/testing/test_eth_estimateGas.py +++ b/proxy/testing/test_eth_estimateGas.py @@ -5,6 +5,8 @@ from web3 import Web3 from solcx import compile_source +from proxy.testing.testing_helpers import request_airdrop + 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)) @@ -32,6 +34,7 @@ def setUpClass(cls): print("\n\nhttps://github.com/neonlabsorg/proxy-model.py/issues/487") print('eth_account.address:', eth_account.address) print('eth_account.key:', eth_account.key.hex()) + request_airdrop(eth_account.address) cls.deploy_counter_487_solidity_contract(cls) def deploy_counter_487_solidity_contract(self): @@ -42,7 +45,7 @@ def deploy_counter_487_solidity_contract(self): nonce=proxy.eth.get_transaction_count(proxy.eth.default_account), chainId=proxy.eth.chain_id, gas=987654321, - gasPrice=0, + gasPrice=1000000000, to='', value=0, data=counter.bytecode), diff --git a/proxy/testing/test_eth_getLogs.py b/proxy/testing/test_eth_getLogs.py index 1ffef3634..12795d8d2 100644 --- a/proxy/testing/test_eth_getLogs.py +++ b/proxy/testing/test_eth_getLogs.py @@ -3,6 +3,8 @@ from web3 import Web3 from solcx import compile_source +from proxy.testing.testing_helpers import request_airdrop + SEED = 'https://github.com/neonlabsorg/proxy-model.py/issues/210' EXTRA_GAS = int(os.environ.get("EXTRA_GAS", "0")) proxy_url = os.environ.get('PROXY_URL', 'http://localhost:9090/solana') @@ -50,6 +52,7 @@ def setUpClass(cls): print(SEED) print('eth_account.address:', eth_account.address) print('eth_account.key:', eth_account.key.hex()) + request_airdrop(eth_account.address) cls.block_hashes = [] cls.topics = [] @@ -75,7 +78,7 @@ def deploy_contract(self): nonce=proxy.eth.get_transaction_count(proxy.eth.default_account), chainId=proxy.eth.chain_id, gas=987654321, - gasPrice=0, + gasPrice=1000000000, to='', value=0, data=storage.bytecode), diff --git a/proxy/testing/test_eth_sendRawTransaction.py b/proxy/testing/test_eth_sendRawTransaction.py index d06e51be6..1ddb8aa92 100644 --- a/proxy/testing/test_eth_sendRawTransaction.py +++ b/proxy/testing/test_eth_sendRawTransaction.py @@ -14,6 +14,8 @@ SUBSTRING_LOG_ERR_147 = 'Invalid Ethereum transaction nonce:' +SUBSTRING_ERR_484 = 'The account balance is less than required:' + STORAGE_SOLIDITY_SOURCE_147 = ''' pragma solidity >=0.7.0 <0.9.0; /** @@ -97,7 +99,7 @@ def deploy_storage_147_solidity_contract(self): nonce=proxy.eth.get_transaction_count(proxy.eth.default_account), chainId=proxy.eth.chain_id, gas=987654321, - gasPrice=0, + gasPrice=2000000000, to='', value=0, data=storage.bytecode), @@ -127,7 +129,7 @@ def deploy_test_185_solidity_contract(self): nonce=proxy.eth.get_transaction_count(proxy.eth.default_account), chainId=proxy.eth.chain_id, gas=987654321, - gasPrice=0, + gasPrice=1000000000, to='', value=0, data=test_185_solidity_contract.bytecode), @@ -186,7 +188,7 @@ def test_02_execute_with_right_nonce(self): 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}) + trx_store = self.storage_contract.functions.store(148).buildTransaction({'nonce': right_nonce, 'gasPrice': 1000000000}) print('trx_store:', trx_store) trx_store['gas'] = trx_store['gas'] - 2 - EXTRA_GAS # less than estimated print('trx_store:', trx_store) @@ -241,6 +243,8 @@ def test_05_transfer_one_gwei(self): 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) + request_airdrop(eth_account_alice.address) + request_airdrop(eth_account_bob.address) if True: print("add funds to alice and bob") @@ -250,7 +254,7 @@ def test_05_transfer_one_gwei(self): nonce=proxy.eth.get_transaction_count(proxy.eth.default_account), chainId=proxy.eth.chain_id, gas=987654321, - gasPrice=0, + gasPrice=1000000000, to=eth_account_alice.address, value=eth_utils.denoms.gwei), eth_account.key @@ -267,7 +271,7 @@ def test_05_transfer_one_gwei(self): nonce=proxy.eth.get_transaction_count(proxy.eth.default_account), chainId=proxy.eth.chain_id, gas=987654321, - gasPrice=0, + gasPrice=1000000000, to=eth_account_bob.address, value=eth_utils.denoms.gwei), eth_account.key @@ -289,7 +293,7 @@ def test_05_transfer_one_gwei(self): nonce=proxy.eth.get_transaction_count(eth_account_alice.address), chainId=proxy.eth.chain_id, gas=987654321, - gasPrice=0, + gasPrice=1000000000, to=eth_account_bob.address, value=eth_utils.denoms.gwei), eth_account_alice.key @@ -305,7 +309,7 @@ def test_05_transfer_one_gwei(self): 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 - eth_utils.denoms.gwei) + self.assertLessEqual(alice_balance_after_transfer, alice_balance_before_transfer - eth_utils.denoms.gwei) self.assertEqual(bob_balance_after_transfer, bob_balance_before_transfer + eth_utils.denoms.gwei) # @unittest.skip("a.i.") @@ -316,6 +320,8 @@ def test_06_transfer_one_and_a_half_gweis(self): 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) + request_airdrop(eth_account_alice.address) + request_airdrop(eth_account_bob.address) if True: print("add funds to alice and bob") @@ -325,7 +331,7 @@ def test_06_transfer_one_and_a_half_gweis(self): nonce=proxy.eth.get_transaction_count(proxy.eth.default_account), chainId=proxy.eth.chain_id, gas=987654321, - gasPrice=0, + gasPrice=1000000000, to=eth_account_alice.address, value=eth_utils.denoms.gwei), eth_account.key @@ -342,7 +348,7 @@ def test_06_transfer_one_and_a_half_gweis(self): nonce=proxy.eth.get_transaction_count(proxy.eth.default_account), chainId=proxy.eth.chain_id, gas=987654321, - gasPrice=0, + gasPrice=1000000000, to=eth_account_bob.address, value=eth_utils.denoms.gwei), eth_account.key @@ -365,7 +371,7 @@ def test_06_transfer_one_and_a_half_gweis(self): nonce=proxy.eth.get_transaction_count(eth_account_alice.address), chainId=proxy.eth.chain_id, gas=987654321, - gasPrice=0, + gasPrice=1000000000, to=eth_account_bob.address, value=one_and_a_half_gweis), eth_account_alice.key @@ -383,7 +389,7 @@ def test_06_transfer_one_and_a_half_gweis(self): print('bob_balance_after_transfer:', bob_balance_after_transfer) print('check https://github.com/neonlabsorg/neon-evm/issues/210') print('one_gwei:', eth_utils.denoms.gwei) - self.assertEqual(alice_balance_after_transfer, alice_balance_before_transfer - eth_utils.denoms.gwei) + self.assertLessEqual(alice_balance_after_transfer, alice_balance_before_transfer - eth_utils.denoms.gwei) self.assertEqual(bob_balance_after_transfer, bob_balance_before_transfer + eth_utils.denoms.gwei) @unittest.skip("a.i.") @@ -456,5 +462,33 @@ def test_get_storage_at(self): print('eth_getStorageAt not_a_contract_address address => ', value_received.hex()) self.assertEqual(int.from_bytes(value_received, byteorder='big'), 0) + # @unittest.skip("a.i.") + def test_08_execute_with_huge_gas(self): + print("\ntest_08_execute_with_huge_gas_limit") + nonce = proxy.eth.get_transaction_count(proxy.eth.default_account) + trx_store = self.storage_contract.functions.store(147).buildTransaction({'gas': 987654321987654321, 'nonce': nonce, 'gasPrice': 1000000000}) + 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'], -32000) + substring_err_484 = SUBSTRING_ERR_484 + print('substring_err_484:', substring_err_484) + print('message:', response['message']) + message = response['message'] + self.assertTrue(substring_err_484 in message) + self.assertGreater(len(message), len(substring_err_484)) + + if __name__ == '__main__': unittest.main() diff --git a/proxy/testing/test_gas_price_calculator.py b/proxy/testing/test_gas_price_calculator.py index 868216d4a..6734625f6 100644 --- a/proxy/testing/test_gas_price_calculator.py +++ b/proxy/testing/test_gas_price_calculator.py @@ -4,17 +4,22 @@ from proxy.indexer.pythnetwork import PythNetworkClient from proxy.plugin.gas_price_calculator import GasPriceCalculator from solana.rpc.api import Client as SolanaClient -from unittest.mock import patch, call +from unittest.mock import patch, call, Mock from decimal import Decimal -from ..environment import NEON_PRICE_USD, OPERATOR_FEE, GET_SOL_PRICE_MAX_RETRIES, SOL_PRICE_UPDATE_INTERVAL +from ..environment import NEON_PRICE_USD, OPERATOR_FEE, GET_SOL_PRICE_MAX_RETRIES, SOL_PRICE_UPDATE_INTERVAL, \ + MINIMAL_GAS_PRICE + +MINIMAL_GAS_PRICE = None class TestGasPriceCalculator(unittest.TestCase): @classmethod def setUpClass(cls) -> None: - cls.mapping_account = PublicKey('BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2') # only for devnet + cls.mapping_account = PublicKey('BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2') # only for devnet cls.solana_url = "https://api.devnet.solana.com" # devnet cls.solana_client = SolanaClient(cls.solana_url) cls.testee = GasPriceCalculator(cls.solana_client, cls.mapping_account) + cls.testee.env_min_gas_price = Mock() + cls.testee.env_min_gas_price.return_value = None def setUp(self) -> None: @@ -137,4 +142,4 @@ def test_success_get_price_time_intervals(self, mock_get_price, mock_get_current self.assertEqual(gas_price3, expected_price2) mock_get_current_time.assert_has_calls([call()] * 3) - mock_get_price.assert_has_calls([call('Crypto.SOL/USD')] * 2) \ No newline at end of file + mock_get_price.assert_has_calls([call('Crypto.SOL/USD')] * 2) diff --git a/proxy/testing/test_indexer_work.py b/proxy/testing/test_indexer_work.py index 85b2ff7f6..bcbdee5d1 100644 --- a/proxy/testing/test_indexer_work.py +++ b/proxy/testing/test_indexer_work.py @@ -130,7 +130,7 @@ def deploy_contract(self): nonce=proxy.eth.get_transaction_count(proxy.eth.default_account), chainId=proxy.eth.chain_id, gas=987654321, - gasPrice=0, + gasPrice=1000000000, to='', value=0, data=storage.bytecode), diff --git a/proxy/testing/test_neon_faucet.py b/proxy/testing/test_neon_faucet.py index 5462c47ca..6e78d0489 100644 --- a/proxy/testing/test_neon_faucet.py +++ b/proxy/testing/test_neon_faucet.py @@ -10,12 +10,15 @@ from web3 import Web3 from solcx import compile_source +from proxy.testing.testing_helpers import request_airdrop + issue = 'https://github.com/neonlabsorg/neon-evm/issues/166' proxy_url = os.environ.get('PROXY_URL', 'http://localhost:9090/solana') proxy = Web3(Web3.HTTPProvider(proxy_url)) admin = proxy.eth.account.create(issue + '/admin') user = proxy.eth.account.create(issue + '/user') proxy.eth.default_account = admin.address +request_airdrop(admin.address) ERC20_CONTRACT_SOURCE = ''' // SPDX-License-Identifier: MIT diff --git a/proxy/testing/test_operator_spending.py b/proxy/testing/test_operator_spending.py index bcde1e431..360bc92df 100644 --- a/proxy/testing/test_operator_spending.py +++ b/proxy/testing/test_operator_spending.py @@ -6,6 +6,8 @@ from solana.rpc.commitment import Confirmed from solana_utils import * +from proxy.testing.testing_helpers import request_airdrop + proxy_url = os.environ.get('PROXY_URL', 'http://127.0.0.1:9090/solana') solana_url = os.environ.get("SOLANA_URL", "http://127.0.0.1:8899") evm_loader_id = PublicKey(os.environ.get("EVM_LOADER")) @@ -53,6 +55,7 @@ def setUpClass(self): print("\n\nhttps://app.zenhub.com/workspaces/solana-evm-6007c75a9dc141001100ccb8/issues/neonlabsorg/proxy-model.py/245") self.account = proxy.eth.account.create() print('account.address:', self.account.address) + request_airdrop(self.account.address) self.client = Client(solana_url) wallet = WalletAccount(wallet_path()) @@ -69,7 +72,7 @@ def test_deploy_cost(self): nonce=proxy.eth.get_transaction_count(self.account.address), chainId=proxy.eth.chain_id, gas=987654321, - gasPrice=0, + gasPrice=1000000000, to='', value=0, data=contract.bytecode), diff --git a/proxy/testing/test_permission_token.py b/proxy/testing/test_permission_token.py index 14868efc5..1259ed18f 100644 --- a/proxy/testing/test_permission_token.py +++ b/proxy/testing/test_permission_token.py @@ -8,6 +8,9 @@ from web3 import Web3 from solana.rpc.commitment import Confirmed +from proxy.testing.testing_helpers import request_airdrop + + class TestPermissionToken(unittest.TestCase): @classmethod def setUpClass(cls) -> None: @@ -16,6 +19,7 @@ def setUpClass(cls) -> None: proxy_url = os.environ['PROXY_URL'] cls.proxy = Web3(Web3.HTTPProvider(proxy_url)) cls.eth_account = cls.proxy.eth.account.create('https://github.com/neonlabsorg/proxy-model.py/issues/468') + request_airdrop(cls.eth_account.address) cls.payer = SolanaAccount() cls.solana.request_airdrop(cls.payer.public_key(), 1000_000_000_000, Confirmed) diff --git a/proxy/testing/test_query_account_contract.py b/proxy/testing/test_query_account_contract.py index d26c68812..ab6ca90ca 100644 --- a/proxy/testing/test_query_account_contract.py +++ b/proxy/testing/test_query_account_contract.py @@ -17,11 +17,14 @@ from web3 import Web3 from solcx import compile_source +from proxy.testing.testing_helpers import request_airdrop + issue = 'https://github.com/neonlabsorg/neon-evm/issues/360' proxy_url = os.environ.get('PROXY_URL', 'http://localhost:9090/solana') proxy = Web3(Web3.HTTPProvider(proxy_url)) admin = proxy.eth.account.create(issue + '/admin') proxy.eth.default_account = admin.address +request_airdrop(admin.address) # Address: HPsV9Deocecw3GeZv1FkAPNCBRfuVyfw9MMwjwRe1xaU (a token mint account) # uint256: 110178555362476360822489549210862241441608066866019832842197691544474470948129 diff --git a/proxy/testing/test_read_only_accounts.py b/proxy/testing/test_read_only_accounts.py index b36b69990..cea02ff2b 100644 --- a/proxy/testing/test_read_only_accounts.py +++ b/proxy/testing/test_read_only_accounts.py @@ -19,11 +19,14 @@ from proxy.common_neon.neon_instruction import NeonInstruction from solcx import compile_source +from proxy.testing.testing_helpers import request_airdrop + proxy_url = os.environ.get('PROXY_URL', 'http://127.0.0.1:9090/solana') solana_url = os.environ.get("SOLANA_URL", "http://127.0.0.1:8899") proxy = Web3(Web3.HTTPProvider(proxy_url)) admin = proxy.eth.account.create('issues/neonlabsorg/proxy-model.py/197/admin') proxy.eth.default_account = admin.address +request_airdrop(proxy.eth.default_account) CONTRACT = ''' pragma solidity >= 0.7.0; @@ -86,7 +89,7 @@ def deploy_test_contract(self): nonce=proxy.eth.get_transaction_count(admin.address), chainId=proxy.eth.chain_id, gas=987654321, - gasPrice=0, + gasPrice=1000000000, to='', value=0, data=contract.bytecode), @@ -100,7 +103,7 @@ def deploy_test_contract(self): abi=contract.abi ) - + def test_balanceOf(self): account = proxy.eth.account.create() @@ -144,7 +147,7 @@ def test_erc20_balanceOf(self): self.assertFalse(self.account_exists(solana_account)) self.assertFalse(self.account_exists(token_account)) - + if __name__ == '__main__': unittest.main() diff --git a/proxy/testing/test_resize_storage_account.py b/proxy/testing/test_resize_storage_account.py index 23341e559..0f7cfc83b 100644 --- a/proxy/testing/test_resize_storage_account.py +++ b/proxy/testing/test_resize_storage_account.py @@ -4,6 +4,7 @@ from solana.publickey import PublicKey from solcx import compile_source, install_solc +from proxy.testing.testing_helpers import request_airdrop proxy_url = os.environ.get('PROXY_URL', 'http://127.0.0.1:9090/solana') solana_url = os.environ.get("SOLANA_URL", "http://127.0.0.1:8899") @@ -41,6 +42,7 @@ def setUpClass(self): print("\n\nhttps://app.zenhub.com/workspaces/solana-evm-6007c75a9dc141001100ccb8/issues/neonlabsorg/proxy-model.py/233") self.account = proxy.eth.account.create() print('account.address:', self.account.address) + request_airdrop(self.account.address) compiled = compile_source(INCREAZE_STORAGE_CONTRACT) id, interface = compiled.popitem() @@ -49,7 +51,7 @@ def setUpClass(self): nonce=proxy.eth.get_transaction_count(self.account.address), chainId=proxy.eth.chain_id, gas=987654321, - gasPrice=0, + gasPrice=1000000000, to='', value=0, data=contract.bytecode), diff --git a/proxy/testing/test_retry_on_blocked_accounts.py b/proxy/testing/test_retry_on_blocked_accounts.py index ac0d4601a..85e673d33 100644 --- a/proxy/testing/test_retry_on_blocked_accounts.py +++ b/proxy/testing/test_retry_on_blocked_accounts.py @@ -29,7 +29,7 @@ from .testing_helpers import request_airdrop from solcx import compile_source -MINIMAL_GAS_PRICE = 1 +MINIMAL_GAS_PRICE = 1000000003 SEED = 'https://github.com/neonlabsorg/proxy-model.py/issues/365' proxy_url = os.environ.get('PROXY_URL', 'http://localhost:9090/solana') proxy = Web3(Web3.HTTPProvider(proxy_url)) @@ -63,12 +63,13 @@ def send_routine(acc_seed, contractAddress, abi, loop, return_dict, padding_stri abi=abi ) new_eth_account = proxy.eth.account.create(acc_seed) + request_airdrop(new_eth_account.address) right_nonce = proxy.eth.get_transaction_count(new_eth_account.address) trx_store = storage_contract.functions.add_some(2, loop, padding_string).buildTransaction( { "chainId": proxy.eth.chain_id, "gas": 987654321, - "gasPrice": 0, + "gasPrice": 1000000001, "nonce": right_nonce, } ) @@ -135,7 +136,7 @@ def deploy_contract(self): nonce=proxy.eth.get_transaction_count(proxy.eth.default_account), chainId=proxy.eth.chain_id, gas=987654321, - gasPrice=0, + gasPrice=1000000002, to='', value=0, data=storage.bytecode), diff --git a/proxy/testing/testing_helpers.py b/proxy/testing/testing_helpers.py index f7411876c..1c1841e03 100644 --- a/proxy/testing/testing_helpers.py +++ b/proxy/testing/testing_helpers.py @@ -49,7 +49,7 @@ def web3(self) -> Web3: def request_airdrop(address): - FAUCET_URL = os.environ.get('FAUCET_URL', 'http://faucet:3333') + FAUCET_URL = os.environ.get('FAUCET_URL', 'http://localhost:3333') url = FAUCET_URL + '/request_neon' data = '{"wallet": "' + address + '", "amount": 10}' r = requests.post(url, data=data) From 227bce31c956c2d2e84b4447b246db2429bdb494 Mon Sep 17 00:00:00 2001 From: Vasiliy Zaznobin Date: Mon, 14 Feb 2022 16:59:34 +0300 Subject: [PATCH 2/2] Set back to FAUCET_URL=http://faucet:3333 --- proxy/testing/testing_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/testing/testing_helpers.py b/proxy/testing/testing_helpers.py index 1c1841e03..f7411876c 100644 --- a/proxy/testing/testing_helpers.py +++ b/proxy/testing/testing_helpers.py @@ -49,7 +49,7 @@ def web3(self) -> Web3: def request_airdrop(address): - FAUCET_URL = os.environ.get('FAUCET_URL', 'http://localhost:3333') + FAUCET_URL = os.environ.get('FAUCET_URL', 'http://faucet:3333') url = FAUCET_URL + '/request_neon' data = '{"wallet": "' + address + '", "amount": 10}' r = requests.post(url, data=data)