diff --git a/Dockerfile b/Dockerfile index 27d90adfe..d941e8417 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,6 +33,7 @@ RUN apt-get update && \ DEBIAN_FRONTEND=nontineractive apt-get -y install xxd && \ rm -rf /var/lib/apt/lists/* /var/lib/apt/cache/* COPY evm_loader/tests/contracts/*.sol /opt/ +COPY evm_loader/tests/eof-contracts/*.binary /opt/eof-contracts/ COPY evm_loader/solidity/*.sol /opt/ #COPY evm_loader/tests/test_solidity_precompiles.json /opt/ COPY --from=solc /usr/bin/solc /usr/bin/solc diff --git a/evm_loader/tests/conftest.py b/evm_loader/tests/conftest.py index 1fcab2bd7..e334cc80d 100644 --- a/evm_loader/tests/conftest.py +++ b/evm_loader/tests/conftest.py @@ -27,8 +27,10 @@ def pytest_addoption(parser): def pytest_configure(config): if "RUST_LOG" in os.environ: pytest.CONTRACTS_PATH = pathlib.Path("/opt/solidity") + pytest.EOF_CONTRACTS_PATH = pathlib.Path("/opt/solidity/eof-contracts") else: pytest.CONTRACTS_PATH = pathlib.Path(__file__).parent / "contracts" + pytest.EOF_CONTRACTS_PATH = pathlib.Path(__file__).parent / "eof-contracts" @pytest.fixture(scope="session") @@ -118,6 +120,11 @@ def rw_lock_contract(evm_loader: EvmLoader, operator_keypair: Keypair, session_u treasury_pool) -> Contract: return deploy_contract(operator_keypair, session_user, "rw_lock.binary", evm_loader, treasury_pool) +@pytest.fixture(scope="function") +def rw_lock_eof_contract(evm_loader: EvmLoader, operator_keypair: Keypair, session_user: Caller, + treasury_pool) -> Contract: + return deploy_contract(operator_keypair, session_user, "rw_lock.binary", evm_loader, treasury_pool, eof=True) + @pytest.fixture(scope="function") def rw_lock_caller(evm_loader: EvmLoader, operator_keypair: Keypair, @@ -131,3 +138,8 @@ def rw_lock_caller(evm_loader: EvmLoader, operator_keypair: Keypair, def string_setter_contract(evm_loader: EvmLoader, operator_keypair: Keypair, session_user: Caller, treasury_pool) -> Contract: return deploy_contract(operator_keypair, session_user, "string_setter.binary", evm_loader, treasury_pool) +@pytest.fixture(scope="function") + +def string_setter_eof_contract(evm_loader: EvmLoader, operator_keypair: Keypair, session_user: Caller, + treasury_pool) -> Contract: + return deploy_contract(operator_keypair, session_user, "string_setter.binary", evm_loader, treasury_pool, eof=True) diff --git a/evm_loader/tests/eof-contracts/BigContract.binary b/evm_loader/tests/eof-contracts/BigContract.binary new file mode 100644 index 000000000..b254fdc0b Binary files /dev/null and b/evm_loader/tests/eof-contracts/BigContract.binary differ diff --git a/evm_loader/tests/eof-contracts/ERC20ForSpl.binary b/evm_loader/tests/eof-contracts/ERC20ForSpl.binary new file mode 100644 index 000000000..c9fa8b6f9 Binary files /dev/null and b/evm_loader/tests/eof-contracts/ERC20ForSpl.binary differ diff --git a/evm_loader/tests/eof-contracts/ERC20ForSplFactory.binary b/evm_loader/tests/eof-contracts/ERC20ForSplFactory.binary new file mode 100644 index 000000000..1d2c1537b Binary files /dev/null and b/evm_loader/tests/eof-contracts/ERC20ForSplFactory.binary differ diff --git a/evm_loader/tests/eof-contracts/ERC20ForSplMintable.binary b/evm_loader/tests/eof-contracts/ERC20ForSplMintable.binary new file mode 100644 index 000000000..581f45f92 Binary files /dev/null and b/evm_loader/tests/eof-contracts/ERC20ForSplMintable.binary differ diff --git a/evm_loader/tests/eof-contracts/NeonToken.binary b/evm_loader/tests/eof-contracts/NeonToken.binary new file mode 100644 index 000000000..71370ba30 Binary files /dev/null and b/evm_loader/tests/eof-contracts/NeonToken.binary differ diff --git a/evm_loader/tests/eof-contracts/hello_world.binary b/evm_loader/tests/eof-contracts/hello_world.binary new file mode 100644 index 000000000..09273b63d Binary files /dev/null and b/evm_loader/tests/eof-contracts/hello_world.binary differ diff --git a/evm_loader/tests/eof-contracts/rw_lock.binary b/evm_loader/tests/eof-contracts/rw_lock.binary new file mode 100644 index 000000000..7580c7318 Binary files /dev/null and b/evm_loader/tests/eof-contracts/rw_lock.binary differ diff --git a/evm_loader/tests/eof-contracts/rw_lock_caller.binary b/evm_loader/tests/eof-contracts/rw_lock_caller.binary new file mode 100644 index 000000000..94f510a8f Binary files /dev/null and b/evm_loader/tests/eof-contracts/rw_lock_caller.binary differ diff --git a/evm_loader/tests/eof-contracts/small.binary b/evm_loader/tests/eof-contracts/small.binary new file mode 100644 index 000000000..d1c089181 Binary files /dev/null and b/evm_loader/tests/eof-contracts/small.binary differ diff --git a/evm_loader/tests/eof-contracts/string_setter.binary b/evm_loader/tests/eof-contracts/string_setter.binary new file mode 100644 index 000000000..ce179bd3e Binary files /dev/null and b/evm_loader/tests/eof-contracts/string_setter.binary differ diff --git a/evm_loader/tests/test_cli.py b/evm_loader/tests/test_cli.py index a5887bf76..39279b97c 100644 --- a/evm_loader/tests/test_cli.py +++ b/evm_loader/tests/test_cli.py @@ -41,7 +41,13 @@ def test_emulate_transfer(user_account, evm_loader, session_user): def test_emulate_contract_deploy(user_account, evm_loader): contract_path = pytest.CONTRACTS_PATH / "hello_world.binary" + emulate_contract_deploy(user_account, evm_loader, contract_path) +def test_emulate_eof_contract_deploy(user_account, evm_loader): + contract_path = pytest.EOF_CONTRACTS_PATH / "hello_world.binary" + emulate_contract_deploy(user_account, evm_loader, contract_path) + +def emulate_contract_deploy(user_account, evm_loader, contract_path): with open(contract_path, 'rb') as f: contract_code = f.read() @@ -57,7 +63,14 @@ def test_emulate_contract_deploy(user_account, evm_loader): def test_emulate_call_contract_function(user_account, evm_loader, operator_keypair, treasury_pool): - contract = deploy_contract(operator_keypair, user_account, "hello_world.binary", evm_loader, treasury_pool) + contract = deploy_contract(operator_keypair, user_account, "hello_world.binary", evm_loader, treasury_pool, eof=False) + emulate_call_contract_function(user_account, evm_loader, operator_keypair, treasury_pool, contract) + +def test_emulate_call_eof_contract_function(user_account, evm_loader, operator_keypair, treasury_pool): + contract = deploy_contract(operator_keypair, user_account, "hello_world.binary", evm_loader, treasury_pool, eof=True) + emulate_call_contract_function(user_account, evm_loader, operator_keypair, treasury_pool, contract) + +def emulate_call_contract_function(user_account, evm_loader, operator_keypair, treasury_pool, contract): assert contract.eth_address assert get_solana_balance(contract.solana_address) > 0 data = abi.function_signature_to_4byte_selector('call_hello_world()') @@ -141,6 +154,12 @@ def test_get_storage_at(evm_loader, operator_keypair, user_account, treasury_poo def test_cancel_trx(evm_loader, user_account, rw_lock_contract, operator_keypair, treasury_pool): + cancel_trx_eof(evm_loader, user_account, rw_lock_contract, operator_keypair, treasury_pool) + +def test_cancel_trx_eof(evm_loader, user_account, rw_lock_eof_contract, operator_keypair, treasury_pool): + cancel_trx_eof(evm_loader, user_account, rw_lock_eof_contract, operator_keypair, treasury_pool) + +def cancel_trx_eof(evm_loader, user_account, rw_lock_contract, operator_keypair, treasury_pool): func_name = abi.function_signature_to_4byte_selector('unchange_storage(uint8,uint8)') data = (func_name + bytes.fromhex("%064x" % 0x01) + bytes.fromhex("%064x" % 0x01)) diff --git a/evm_loader/tests/test_execute_trx_from_instruction.py b/evm_loader/tests/test_execute_trx_from_instruction.py index 534b3348d..010849b35 100644 --- a/evm_loader/tests/test_execute_trx_from_instruction.py +++ b/evm_loader/tests/test_execute_trx_from_instruction.py @@ -63,6 +63,17 @@ def test_transfer_transaction_with_non_existing_recipient(self, operator_keypair def test_call_contract_function_without_neon_transfer(self, operator_keypair, treasury_pool, sender_with_tokens, evm_loader, string_setter_contract): + self.call_contract_function_without_neon_transfer(operator_keypair, treasury_pool, sender_with_tokens, + evm_loader, string_setter_contract, "exit_status=0x11") + + def test_call_eof_contract_function_without_neon_transfer(self, operator_keypair, treasury_pool, sender_with_tokens, + evm_loader, string_setter_eof_contract): + self.call_contract_function_without_neon_transfer(operator_keypair, treasury_pool, sender_with_tokens, + evm_loader, string_setter_eof_contract, "exit_status=0x12") + + + def call_contract_function_without_neon_transfer(self, operator_keypair, treasury_pool, sender_with_tokens, + evm_loader, string_setter_contract, exit_status): text = ''.join(random.choice(string.ascii_letters) for _ in range(10)) signed_tx = make_contract_call_trx(sender_with_tokens, string_setter_contract, "set(string)", [text]) @@ -72,17 +83,28 @@ def test_call_contract_function_without_neon_transfer(self, operator_keypair, tr string_setter_contract.solana_address], operator_keypair) - check_transaction_logs_have_text(resp.value, "exit_status=0x11") + check_transaction_logs_have_text(resp.value, exit_status) assert text in to_text( neon_cli().call_contract_get_function(evm_loader, sender_with_tokens, string_setter_contract, "get()")) def test_call_contract_function_with_neon_transfer(self, operator_keypair, treasury_pool, sender_with_tokens, - evm_loader): - transfer_amount = random.randint(1, 1000) + evm_loader): + contract = deploy_contract(operator_keypair, sender_with_tokens, "string_setter.binary", evm_loader, + treasury_pool) + self.call_contract_function_with_neon_transfer(operator_keypair, treasury_pool, sender_with_tokens, + evm_loader, contract, "exit_status=0x11") + def test_call_contract_function_with_neon_transfer(self, operator_keypair, treasury_pool, sender_with_tokens, + evm_loader): contract = deploy_contract(operator_keypair, sender_with_tokens, "string_setter.binary", evm_loader, - treasury_pool) + treasury_pool) + self.call_contract_function_with_neon_transfer(operator_keypair, treasury_pool, sender_with_tokens, + evm_loader, contract, "exit_status=0x12") + + def call_contract_function_with_neon_transfer(self, operator_keypair, treasury_pool, sender_with_tokens, + evm_loader, contract, exit_status): + transfer_amount = random.randint(1, 1000) sender_balance_before = get_neon_balance(solana_client, sender_with_tokens.solana_account_address) contract_balance_before = get_neon_balance(solana_client, contract.solana_address) diff --git a/evm_loader/tests/test_step_instructions_work_the_same.py b/evm_loader/tests/test_step_instructions_work_the_same.py index d9ed80e23..5eaf19bd9 100644 --- a/evm_loader/tests/test_step_instructions_work_the_same.py +++ b/evm_loader/tests/test_step_instructions_work_the_same.py @@ -32,16 +32,22 @@ def test_simple_transfer_transaction(self, operator_keypair, treasury_pool, evm_ resp_from_inst.transaction.meta.post_balances[i] - resp_from_inst.transaction.meta.pre_balances[i] def test_deploy_contract(self, operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens): + self.deploy_contract(operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens, False) + + def test_deploy_eof_contract(self, operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens): + self.deploy_contract(operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens, True) + + def deploy_contract(self, operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens, eof): contract_filename = "small.binary" contract = create_contract_address(sender_with_tokens, evm_loader) - signed_tx = make_deployment_transaction(sender_with_tokens, contract_filename) + signed_tx = make_deployment_transaction(sender_with_tokens, contract_filename, eof=eof) write_transaction_to_holder_account(signed_tx, holder_acc, operator_keypair) resp_from_acc = execute_transaction_steps_from_account(operator_keypair, evm_loader, treasury_pool, holder_acc, [contract.solana_address, sender_with_tokens.solana_account_address]).value - signed_tx = make_deployment_transaction(sender_with_tokens, contract_filename) + signed_tx = make_deployment_transaction(sender_with_tokens, contract_filename, eof=eof) holder_acc = create_holder(operator_keypair) contract = create_contract_address(sender_with_tokens, evm_loader) diff --git a/evm_loader/tests/test_transaction_step_from_account.py b/evm_loader/tests/test_transaction_step_from_account.py index 4141e60ab..754528bcb 100644 --- a/evm_loader/tests/test_transaction_step_from_account.py +++ b/evm_loader/tests/test_transaction_step_from_account.py @@ -50,13 +50,19 @@ def test_simple_transfer_transaction(self, operator_keypair, treasury_pool, evm_ assert recipient_balance_before + amount == recipient_balance_after def test_deploy_contract(self, operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens): + self.deploy_contract(operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens, False) + + def test_deploy_eof_contract(self, operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens): + self.deploy_contract(operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens, True) + + def deploy_contract(self, operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens, eof): contract_filename = "hello_world.binary" contract = create_contract_address(sender_with_tokens, evm_loader) - signed_tx = make_deployment_transaction(sender_with_tokens, contract_filename) + signed_tx = make_deployment_transaction(sender_with_tokens, contract_filename, eof=eof) write_transaction_to_holder_account(signed_tx, holder_acc, operator_keypair) - contract_path = pytest.CONTRACTS_PATH / contract_filename + contract_path = (pytest.EOF_CONTRACTS_PATH if eof else pytest.CONTRACTS_PATH) / contract_filename with open(contract_path, 'rb') as f: contract_code = f.read() @@ -68,8 +74,19 @@ def test_deploy_contract(self, operator_keypair, holder_acc, treasury_pool, evm_ check_holder_account_tag(holder_acc, FINALIZED_STORAGE_ACCOUNT_INFO_LAYOUT, TAG_FINALIZED_STATE) check_transaction_logs_have_text(resp.value.transaction.transaction.signatures[0], "exit_status=0x12") + def test_call_contract_function_without_neon_transfer(self, operator_keypair, holder_acc, treasury_pool, sender_with_tokens, evm_loader, string_setter_contract): + self.call_contract_function_without_neon_transfer(operator_keypair, holder_acc, treasury_pool, sender_with_tokens, + evm_loader, string_setter_contract, "exit_status=0x11") + + def test_call_eof_contract_function_without_neon_transfer(self, operator_keypair, holder_acc, treasury_pool, + sender_with_tokens, evm_loader, string_setter_eof_contract): + self.call_contract_function_without_neon_transfer(operator_keypair, holder_acc, treasury_pool, sender_with_tokens, + evm_loader, string_setter_eof_contract, "exit_status=0x12") + + def call_contract_function_without_neon_transfer(self, operator_keypair, holder_acc, treasury_pool, + sender_with_tokens, evm_loader, string_setter_contract, exit_status): text = ''.join(random.choice(string.ascii_letters) for _ in range(10)) signed_tx = make_contract_call_trx(sender_with_tokens, string_setter_contract, "set(string)", [text]) write_transaction_to_holder_account(signed_tx, holder_acc, operator_keypair) @@ -79,7 +96,7 @@ def test_call_contract_function_without_neon_transfer(self, operator_keypair, ho sender_with_tokens.solana_account_address]) check_holder_account_tag(holder_acc, FINALIZED_STORAGE_ACCOUNT_INFO_LAYOUT, TAG_FINALIZED_STATE) - check_transaction_logs_have_text(resp.value.transaction.transaction.signatures[0], "exit_status=0x11") + check_transaction_logs_have_text(resp.value.transaction.transaction.signatures[0], exit_status) assert text in to_text( neon_cli().call_contract_get_function(evm_loader, sender_with_tokens, string_setter_contract, @@ -88,6 +105,21 @@ def test_call_contract_function_without_neon_transfer(self, operator_keypair, ho def test_call_contract_function_with_neon_transfer(self, operator_keypair, treasury_pool, sender_with_tokens, string_setter_contract, holder_acc, evm_loader): + self.call_contract_function_with_neon_transfer(operator_keypair, treasury_pool, + sender_with_tokens, string_setter_contract, holder_acc, + evm_loader, "exit_status=0x11") + + def test_call_eof_contract_function_with_neon_transfer(self, operator_keypair, treasury_pool, + sender_with_tokens, string_setter_eof_contract, holder_acc, + evm_loader): + self.call_contract_function_with_neon_transfer(operator_keypair, treasury_pool, + sender_with_tokens, string_setter_eof_contract, holder_acc, + evm_loader, "exit_status=0x12") + + + def call_contract_function_with_neon_transfer(self, operator_keypair, treasury_pool, + sender_with_tokens, string_setter_contract, holder_acc, + evm_loader, exit_status): transfer_amount = random.randint(1, 1000) sender_balance_before = get_neon_balance(solana_client, sender_with_tokens.solana_account_address) @@ -105,7 +137,7 @@ def test_call_contract_function_with_neon_transfer(self, operator_keypair, treas ) check_holder_account_tag(holder_acc, FINALIZED_STORAGE_ACCOUNT_INFO_LAYOUT, TAG_FINALIZED_STATE) - check_transaction_logs_have_text(resp.value.transaction.transaction.signatures[0], "exit_status=0x11") + check_transaction_logs_have_text(resp.value.transaction.transaction.signatures[0], exit_status) sender_balance_after = get_neon_balance(solana_client, sender_with_tokens.solana_account_address) contract_balance_after = get_neon_balance(solana_client, string_setter_contract.solana_address) @@ -453,6 +485,20 @@ class TestStepFromAccountChangingOperatorsDuringTrxRun: def test_next_operator_can_continue_trx_after_some_time(self, rw_lock_contract, user_account, evm_loader, operator_keypair, second_operator_keypair, treasury_pool, new_holder_acc): + self.next_operator_can_continue_trx_after_some_time(rw_lock_contract, user_account, evm_loader, + operator_keypair, second_operator_keypair, treasury_pool, + new_holder_acc, "exit_status=0x11") + + def test_next_operator_can_continue_trx_after_some_time(self, rw_lock_eof_contract, user_account, evm_loader, + operator_keypair, second_operator_keypair, treasury_pool, + new_holder_acc): + self.next_operator_can_continue_trx_after_some_time(rw_lock_eof_contract, user_account, evm_loader, + operator_keypair, second_operator_keypair, treasury_pool, + new_holder_acc, "exit_status=0x12") + + def next_operator_can_continue_trx_after_some_time(self, rw_lock_contract, user_account, evm_loader, + operator_keypair, second_operator_keypair, treasury_pool, + new_holder_acc, exit_status): signed_tx = make_contract_call_trx(user_account, rw_lock_contract, 'update_storage_str(string)', ['text']) write_transaction_to_holder_account(signed_tx, new_holder_acc, operator_keypair) @@ -480,4 +526,4 @@ def test_next_operator_can_continue_trx_after_some_time(self, rw_lock_contract, resp = send_transaction_step_from_account(second_operator_keypair, evm_loader, treasury_pool, new_holder_acc, [user_account.solana_account_address, rw_lock_contract.solana_address], 1, second_operator_keypair) - check_transaction_logs_have_text(resp.value.transaction.transaction.signatures[0], "exit_status=0x11") + check_transaction_logs_have_text(resp.value.transaction.transaction.signatures[0], exit_status) diff --git a/evm_loader/tests/test_transaction_step_from_account_no_chainid.py b/evm_loader/tests/test_transaction_step_from_account_no_chainid.py index c53ab0528..b9af14ebd 100644 --- a/evm_loader/tests/test_transaction_step_from_account_no_chainid.py +++ b/evm_loader/tests/test_transaction_step_from_account_no_chainid.py @@ -38,13 +38,19 @@ def test_simple_transfer_transaction(self, operator_keypair, treasury_pool, evm_ assert recipient_balance_before + amount == recipient_balance_after def test_deploy_contract(self, operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens): + self.deploy_contract(operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens, False) + + def test_deploy_eof_contract(self, operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens): + self.deploy_contract(operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens, True) + + def deploy_contract(self, operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens, eof): contract_filename = "hello_world.binary" contract = create_contract_address(sender_with_tokens, evm_loader) signed_tx = make_deployment_transaction(sender_with_tokens, contract_filename, chain_id=None) write_transaction_to_holder_account(signed_tx, holder_acc, operator_keypair) - contract_path = pytest.CONTRACTS_PATH / contract_filename + contract_path = (pytest.EOF_CONTRACTS_PATH if eof else pytest.EOF_CONTRACTS_PATH) / contract_filename with open(contract_path, 'rb') as f: contract_code = f.read() @@ -60,6 +66,20 @@ def test_deploy_contract(self, operator_keypair, holder_acc, treasury_pool, evm_ def test_call_contract_function_with_neon_transfer(self, operator_keypair, treasury_pool, sender_with_tokens, string_setter_contract, holder_acc, evm_loader): + self.call_contract_function_with_neon_transfer(operator_keypair, treasury_pool, + sender_with_tokens, string_setter_contract, holder_acc, + evm_loader, "exit_status=0x11") + + def test_call_eof_contract_function_with_neon_transfer(self, operator_keypair, treasury_pool, + sender_with_tokens, string_setter_eof_contract, holder_acc, + evm_loader): + self.call_contract_function_with_neon_transfer(operator_keypair, treasury_pool, + sender_with_tokens, string_setter_eof_contract, holder_acc, + evm_loader, "exit_status=0x12") + + def call_contract_function_with_neon_transfer(self, operator_keypair, treasury_pool, + sender_with_tokens, string_setter_contract, holder_acc, + evm_loader, exit_status): transfer_amount = random.randint(1, 1000) sender_balance_before = get_neon_balance(solana_client, sender_with_tokens.solana_account_address) @@ -78,7 +98,7 @@ def test_call_contract_function_with_neon_transfer(self, operator_keypair, treas ) check_holder_account_tag(holder_acc, FINALIZED_STORAGE_ACCOUNT_INFO_LAYOUT, TAG_FINALIZED_STATE) - check_transaction_logs_have_text(resp.value.transaction.transaction.signatures[0], "exit_status=0x11") + check_transaction_logs_have_text(resp.value.transaction.transaction.signatures[0], exit_status) sender_balance_after = get_neon_balance(solana_client, sender_with_tokens.solana_account_address) contract_balance_after = get_neon_balance(solana_client, string_setter_contract.solana_address) diff --git a/evm_loader/tests/test_transaction_step_from_instruction.py b/evm_loader/tests/test_transaction_step_from_instruction.py index f3564bd68..e4875379f 100644 --- a/evm_loader/tests/test_transaction_step_from_instruction.py +++ b/evm_loader/tests/test_transaction_step_from_instruction.py @@ -54,12 +54,22 @@ def test_simple_transfer_transaction(self, operator_keypair, treasury_pool, evm_ @pytest.mark.parametrize("chain_id", [None, 111]) def test_deploy_contract(self, operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens, chain_id): + self.deploy_contract(operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens, + chain_id, False) + + @pytest.mark.parametrize("chain_id", [None, 111]) + def test_deploy_eof_contract(self, operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens, + chain_id): + self.deploy_contract(operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens, + chain_id, True) + def deploy_contract(self, operator_keypair, holder_acc, treasury_pool, evm_loader, sender_with_tokens, + chain_id, eof): contract_filename = "small.binary" - signed_tx = make_deployment_transaction(sender_with_tokens, contract_filename, chain_id=chain_id) + signed_tx = make_deployment_transaction(sender_with_tokens, contract_filename, chain_id=chain_id, eof=eof) contract = create_contract_address(sender_with_tokens, evm_loader) - contract_path = pytest.CONTRACTS_PATH / contract_filename + contract_path = (pytest.EOF_CONTRACTS_PATH if eof else pytest.CONTRACTS_PATH) / contract_filename with open(contract_path, 'rb') as f: contract_code = f.read() @@ -74,6 +84,16 @@ def test_deploy_contract(self, operator_keypair, holder_acc, treasury_pool, evm_ def test_call_contract_function_without_neon_transfer(self, operator_keypair, treasury_pool, sender_with_tokens, evm_loader, holder_acc, string_setter_contract): + self.call_contract_function_without_neon_transfer(operator_keypair, treasury_pool, sender_with_tokens, + evm_loader, holder_acc, string_setter_contract, "exit_status=0x11") + + def test_call_eof_contract_function_without_neon_transfer(self, operator_keypair, treasury_pool, sender_with_tokens, + evm_loader, holder_acc, string_setter_eof_contract): + self.call_contract_function_without_neon_transfer(operator_keypair, treasury_pool, sender_with_tokens, + evm_loader, holder_acc, string_setter_eof_contract, "exit_status=0x12") + + def call_contract_function_without_neon_transfer(self, operator_keypair, treasury_pool, sender_with_tokens, + evm_loader, holder_acc, string_setter_contract, exit_status): text = ''.join(random.choice(string.ascii_letters) for _ in range(10)) signed_tx = make_contract_call_trx(sender_with_tokens, string_setter_contract, "set(string)", [text]) @@ -83,7 +103,7 @@ def test_call_contract_function_without_neon_transfer(self, operator_keypair, tr ) check_holder_account_tag(holder_acc, FINALIZED_STORAGE_ACCOUNT_INFO_LAYOUT, TAG_FINALIZED_STATE) - check_transaction_logs_have_text(resp.value, "exit_status=0x11") + check_transaction_logs_have_text(resp.value, exit_status) assert text in to_text( neon_cli().call_contract_get_function(evm_loader, sender_with_tokens, string_setter_contract, @@ -91,6 +111,16 @@ def test_call_contract_function_without_neon_transfer(self, operator_keypair, tr def test_call_contract_function_with_neon_transfer(self, operator_keypair, treasury_pool, sender_with_tokens, evm_loader, holder_acc, string_setter_contract): + self.call_contract_function_with_neon_transfer(operator_keypair, treasury_pool, sender_with_tokens, + evm_loader, holder_acc, string_setter_contract, "exit_status=0x11") + + def test_call_eof_contract_function_with_neon_transfer(self, operator_keypair, treasury_pool, sender_with_tokens, + evm_loader, holder_acc, string_setter_eof_contract): + self.call_contract_function_with_neon_transfer(operator_keypair, treasury_pool, sender_with_tokens, + evm_loader, holder_acc, string_setter_eof_contract, "exit_status=0x12") + + def call_contract_function_with_neon_transfer(self, operator_keypair, treasury_pool, sender_with_tokens, + evm_loader, holder_acc, string_setter_contract, exit_status): transfer_amount = random.randint(1, 1000) sender_balance_before = get_neon_balance(solana_client, sender_with_tokens.solana_account_address) @@ -106,7 +136,7 @@ def test_call_contract_function_with_neon_transfer(self, operator_keypair, treas ) check_holder_account_tag(holder_acc, FINALIZED_STORAGE_ACCOUNT_INFO_LAYOUT, TAG_FINALIZED_STATE) - check_transaction_logs_have_text(resp.value, "exit_status=0x11") + check_transaction_logs_have_text(resp.value, exit_status) sender_balance_after = get_neon_balance(solana_client, sender_with_tokens.solana_account_address) contract_balance_after = get_neon_balance(solana_client, string_setter_contract.solana_address) @@ -441,6 +471,20 @@ class TestStepFromInstructionChangingOperatorsDuringTrxRun: def test_next_operator_can_continue_trx_after_some_time(self, rw_lock_contract, user_account, evm_loader, operator_keypair, second_operator_keypair, treasury_pool, new_holder_acc): + self.next_operator_can_continue_trx_after_some_time(rw_lock_contract, user_account, evm_loader, + operator_keypair, second_operator_keypair, treasury_pool, + new_holder_acc, "exit_status=0x11") + + def test_eof_next_operator_can_continue_trx_after_some_time(self, rw_lock_eof_contract, user_account, evm_loader, + operator_keypair, second_operator_keypair, treasury_pool, + new_holder_acc): + self.next_operator_can_continue_trx_after_some_time(rw_lock_eof_contract, user_account, evm_loader, + operator_keypair, second_operator_keypair, treasury_pool, + new_holder_acc, "exit_status=0x12") + + def next_operator_can_continue_trx_after_some_time(self, rw_lock_contract, user_account, evm_loader, + operator_keypair, second_operator_keypair, treasury_pool, + new_holder_acc, exit_status): signed_tx = make_contract_call_trx(user_account, rw_lock_contract, 'update_storage_str(string)', ['text']) send_transaction_step_from_instruction(operator_keypair, evm_loader, treasury_pool, new_holder_acc, @@ -464,7 +508,7 @@ def test_next_operator_can_continue_trx_after_some_time(self, rw_lock_contract, new_holder_acc, signed_tx, [user_account.solana_account_address, rw_lock_contract.solana_address], 1, second_operator_keypair) - check_transaction_logs_have_text(resp.value, "exit_status=0x11") + check_transaction_logs_have_text(resp.value, exit_status) class TestStepFromInstructionWithChangedRLPTrx: diff --git a/evm_loader/tests/utils/contract.py b/evm_loader/tests/utils/contract.py index d01d0bbcf..47226107e 100644 --- a/evm_loader/tests/utils/contract.py +++ b/evm_loader/tests/utils/contract.py @@ -21,12 +21,12 @@ def make_deployment_transaction( user: Caller, contract_path: tp.Union[pathlib.Path, str], encoded_args=None, - gas: int = 999999999, chain_id=111 + gas: int = 999999999, chain_id=111, eof=False ) -> SignedTransaction: if isinstance(contract_path, str): contract_path = pathlib.Path(contract_path) if not contract_path.name.startswith("/") or not contract_path.name.startswith("."): - contract_path = pytest.CONTRACTS_PATH / contract_path + contract_path = (pytest.EOF_CONTRACTS_PATH if eof else pytest.CONTRACTS_PATH ) / contract_path with open(contract_path, 'rb') as f: data = f.read() @@ -69,14 +69,15 @@ def deploy_contract( evm_loader: EvmLoader, treasury_pool: TreasuryPool, step_count: int = 1000, - encoded_args=None + encoded_args=None, + eof=False ): print("Deploying contract") if isinstance(contract_path, str): contract_path = pathlib.Path(contract_path) contract = create_contract_address(user, evm_loader) holder_acc = create_holder(operator) - signed_tx = make_deployment_transaction(user, contract_path, encoded_args=encoded_args) + signed_tx = make_deployment_transaction(user, contract_path, encoded_args=encoded_args, eof=eof) write_transaction_to_holder_account(signed_tx, holder_acc, operator) contract_deployed = False