Skip to content

Commit

Permalink
Merge pull request #8 from allbridge-io/eof/tests
Browse files Browse the repository at this point in the history
Added EOF tests
  • Loading branch information
YaroslavNekryach authored Sep 4, 2023
2 parents b4668c2 + 355aee3 commit e134af6
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 23 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions evm_loader/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Binary file added evm_loader/tests/eof-contracts/BigContract.binary
Binary file not shown.
Binary file added evm_loader/tests/eof-contracts/ERC20ForSpl.binary
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added evm_loader/tests/eof-contracts/NeonToken.binary
Binary file not shown.
Binary file added evm_loader/tests/eof-contracts/hello_world.binary
Binary file not shown.
Binary file added evm_loader/tests/eof-contracts/rw_lock.binary
Binary file not shown.
Binary file not shown.
Binary file added evm_loader/tests/eof-contracts/small.binary
Binary file not shown.
Binary file not shown.
21 changes: 20 additions & 1 deletion evm_loader/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()')
Expand Down Expand Up @@ -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))

Expand Down
30 changes: 26 additions & 4 deletions evm_loader/tests/test_execute_trx_from_instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand All @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions evm_loader/tests/test_step_instructions_work_the_same.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
56 changes: 51 additions & 5 deletions evm_loader/tests/test_transaction_step_from_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Loading

0 comments on commit e134af6

Please sign in to comment.