Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added tests to check account list #509

Merged
merged 13 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/tests/audit/erc/test_ERC20SPL.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ tokens
| TestERC20wrapperContract::test_allowance_incorrect_address | Check allowance method with incorrect address | |
| TestERC20wrapperContract::test_allowance_for_new_account | Check allowance method for new account | |
| TestERC20wrapperContract::test_transfer | Verify transfer | |
| TestERC20wrapperContract::test_transfer_and_check_sol_account_list_is_correct | Check account list doesn't contain program address of precompiled contract | |
| TestERC20wrapperContract::test_transfer_incorrect_address | Verify transfer for incorrect address | |
| TestERC20wrapperContract::test_transfer_more_than_balance | Expect error on transfer more than balance | |
| TestERC20wrapperContract::test_transfer_no_enough_gas | Expect error with not enough gas | |
Expand All @@ -61,4 +62,3 @@ tokens
| TestMultipleActionsForERC20::test_burn_transfer_burn_transfer | Verify burn -> transfer -> burn in one transaction | |
| TestMultipleActionsForERC20::test_burn_mint_transfer | Verify burn -> mint -> transfer in one transaction | |
| TestMultipleActionsForERC20::test_parallel_trxs_transfer_read_balance_transfer | Verify spl balance isn't cashed | |

19 changes: 9 additions & 10 deletions docs/tests/audit/indexer/test_instruction_parsing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

Tests for instructions

| Test case | Description | XFailed |
|---------------------------------------------------------|-------------------------------------------------|---------|
| TestInstruction::test_tx_exec_from_data | Check TxExecFromData | |
| TestInstruction::test_tx_step_from_data | Check TxStepFromData | |
| TestInstruction::test_cancel_with_hash | Check CancelWithHash | |
| TestInstruction::test_tx_exec_from_data_solana_call | Check TxExecFromDataSolanaCall | |
| TestInstruction::test_tx_step_from_account_no_chain_id | Check TxStepFromAccountNoChainId | |
| TestInstruction::test_holder_write_tx_exec_from_account | Check HolderWrite & TxExecFromAccount | |
| TestInstruction::test_step_from_account | Check TxStepFromAccount & HolderWrite | |
| TestInstruction::test_tx_exec_from_account_solana_call | Check HolderWrite & TxExecFromAccountSolanaCall | |
| Test case | Description | XFailed |
|---------------------------------------------------------------|----------------------------------------------------|---------|
| TestInstruction::test_tx_exec_from_data | Check TxExecFromData | |
| TestInstruction::test_cancel_with_hash | Check CancelWithHash | |
| TestInstruction::test_tx_exec_from_data_solana_call | Check TxExecFromDataSolanaCall | |
| TestInstruction::test_tx_iterative_with_and_without_chain_id | Check TxStepFromAccountNoChainId & TxStepFromData |
| TestInstruction::test_holder_write_tx_exec_from_account | Check HolderWrite & TxExecFromAccount | |
| TestInstruction::test_step_from_account | Check TxStepFromAccount & HolderWrite | |
| TestInstruction::test_tx_exec_from_account_solana_call | Check HolderWrite & TxExecFromAccountSolanaCall | |
63 changes: 2 additions & 61 deletions integration/tests/basic/erc/test_EIP2535.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from web3.exceptions import ContractLogicError

from utils.consts import ZERO_ADDRESS
from utils.helpers import get_selectors, decode_function_signature
from utils.helpers import get_selectors

from utils.web3client import NeonChainWeb3Client
from utils.accounts import EthAccounts
Expand All @@ -20,66 +20,6 @@ class TestDiamond:
web3_client: NeonChainWeb3Client
accounts: EthAccounts

@pytest.fixture(scope="class")
def diamond_init(self, web3_client_session, accounts):
contract, _ = web3_client_session.deploy_and_get_contract(
"EIPs/EIP2535/upgradeInitializers/DiamondInit.sol",
"0.8.10",
accounts[0],
contract_name="DiamondInit",
)
return contract

@pytest.fixture(scope="class")
def facet_cuts(self, diamond_cut_facet, diamond_loupe_facet, ownership_facet):
facet_cuts = []
for facet in [diamond_cut_facet, diamond_loupe_facet, ownership_facet]:
facet_cuts.append((facet.address, facet_cut_action["Add"], get_selectors(facet.abi)))
return facet_cuts

@pytest.fixture(scope="class")
def diamond_cut_facet(self, web3_client_session, accounts):
contract, _ = web3_client_session.deploy_and_get_contract(
"EIPs/EIP2535/facets/DiamondCutFacet",
"0.8.10",
accounts[0],
contract_name="DiamondCutFacet",
)
return contract

@pytest.fixture(scope="class")
def diamond_loupe_facet(self, web3_client_session, accounts):
contract, _ = web3_client_session.deploy_and_get_contract(
"EIPs/EIP2535/facets/DiamondLoupeFacet.sol",
"0.8.10",
accounts[0],
contract_name="DiamondLoupeFacet",
)
return contract

@pytest.fixture(scope="class")
def ownership_facet(self, web3_client_session, accounts):
contract, _ = web3_client_session.deploy_and_get_contract(
"EIPs/EIP2535/facets/OwnershipFacet",
"0.8.10",
accounts[0],
contract_name="OwnershipFacet",
)
return contract

@pytest.fixture(scope="class")
def diamond(self, web3_client_session, diamond_init, facet_cuts, accounts):
calldata = decode_function_signature("init()")
diamond_args = [accounts[0].address, diamond_init.address, calldata]
contract, tx = web3_client_session.deploy_and_get_contract(
"EIPs/EIP2535/Diamond",
"0.8.10",
accounts[0],
contract_name="Diamond",
constructor_args=[facet_cuts, diamond_args],
)
return contract

def test_facet_addresses(self, diamond, facet_cuts):
addresses = self.web3_client.call_function_at_address(diamond.address, "facetAddresses()", None, ["address[]"])
assert len(addresses) == 3
Expand Down Expand Up @@ -114,6 +54,7 @@ def test_add_and_remove_function(self, diamond, diamond_cut_facet):

tx = self.web3_client.make_raw_tx(account, diamond.address, 0, data=calldata, estimate_gas=True)
self.web3_client.send_transaction(account, tx)

result = self.web3_client.call_function_at_address(
diamond.address,
"facetFunctionSelectors(address)",
Expand Down
14 changes: 13 additions & 1 deletion integration/tests/basic/erc/test_ERC20SPL.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
from spl.token import instructions
from spl.token.constants import TOKEN_PROGRAM_ID

from integration.tests.basic.helpers.rpc_checks import assert_solana_address_was_not_used_in_trx
from utils import metaplex
from utils.consts import ZERO_ADDRESS
from utils.consts import ZERO_ADDRESS, METAPLEX_ADDRESS, SPL_TOKEN_ADDRESS, CALL_SOLANA_ADDRESS, SOLANA_NATIVE_ADDRESS
from utils.erc20wrapper import ERC20Wrapper
from utils.helpers import gen_hash_of_block, wait_condition, create_invalid_address
from utils.web3client import NeonChainWeb3Client
Expand Down Expand Up @@ -213,6 +214,17 @@ def test_transfer(self, erc20_contract, restore_balance):
assert balance_acc2_after == balance_acc2_before + amount
assert total_before == total_after

def test_transfer_and_check_sol_account_list_is_correct(self, erc20_contract, restore_balance, evm_loader):
new_account = self.accounts.create_account()

receipt = erc20_contract.transfer(erc20_contract.account, new_account.address, 100)
precompiled_addresses = [METAPLEX_ADDRESS, SPL_TOKEN_ADDRESS, CALL_SOLANA_ADDRESS, SOLANA_NATIVE_ADDRESS]
for precompiled_address in precompiled_addresses:
program_address = evm_loader.ether2program(precompiled_address[2:])[0]
assert_solana_address_was_not_used_in_trx(
receipt["transactionHash"].hex(), program_address, self.web3_client, evm_loader
)

@pytest.mark.parametrize(
"block_len, expected_exception, msg",
[
Expand Down
4 changes: 1 addition & 3 deletions integration/tests/basic/evm/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
from web3.contract import Contract
from utils import helpers
from utils.accounts import EthAccounts
from utils.consts import SPL_TOKEN_ADDRESS, METAPLEX_ADDRESS
from utils.solana_client import SolanaClient
from utils.web3client import Web3Client

SPL_TOKEN_ADDRESS = "0xFf00000000000000000000000000000000000004"
METAPLEX_ADDRESS = "0xff00000000000000000000000000000000000005"


@pytest.fixture(scope="class")
def precompiled_contract(web3_client, faucet, accounts):
Expand Down
32 changes: 23 additions & 9 deletions integration/tests/basic/evm/opcodes/test_extcodehash.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_extcodehash_with_send_tx_for_destroyed_contract(self, eip1052_checker):
def test_extcodehash_for_reverted_destroyed_contract(self, eip1052_checker, json_rpc_client, destroyable_contract):
# Check the EXTCODEHASH of an account that selfdestructed and later the selfdestruct has been reverted.
sender_account = self.accounts[0]
destroyCaller, _ = self.web3_client.deploy_and_get_contract(
destroy_caller, _ = self.web3_client.deploy_and_get_contract(
"EIPs/EIP1052Extcodehash",
"0.8.10",
sender_account,
Expand All @@ -112,7 +112,7 @@ def test_extcodehash_for_reverted_destroyed_contract(self, eip1052_checker, json

tx = self.web3_client.make_raw_tx(sender_account)
instruction_tx = eip1052_checker.functions.getHashForDestroyedContractAfterRevert(
destroyable_contract.address, destroyCaller.address
destroyable_contract.address, destroy_caller.address
).build_transaction(tx)
receipt = self.web3_client.send_transaction(sender_account, instruction_tx)
neon_logs = json_rpc_client.send_rpc(
Expand All @@ -125,23 +125,37 @@ def test_extcodehash_for_reverted_destroyed_contract(self, eip1052_checker, json
assert all(x == data[0] for x in data)

@pytest.mark.only_stands
def test_extcodehash_for_precompiled_contract(self, eip1052_checker):
# Check the EXTCODEHASH of a precompiled contract.
precompiled_acc = AccountData(address="0xFf00000000000000000000000000000000000004")
@pytest.mark.parametrize(
"address,expected_hash",
[
("0x0000000000000000000000000000000000000004", ZERO_HASH),
("0xFf00000000000000000000000000000000000004", keccak(hexstr="0xFE").hex()),
],
)
def test_extcodehash_for_precompiled_contract(self, eip1052_checker, address, expected_hash):
# Check the EXTCODEHASH of a ethereum precompiled contract.
precompiled_acc = AccountData(address=address)
contract_hash = eip1052_checker.functions.getContractHash(precompiled_acc.address).call()
assert contract_hash.hex() == ZERO_HASH
assert contract_hash.hex() == expected_hash

@pytest.mark.only_stands
def test_extcodehash_with_send_tx_for_precompiled_contract(self, eip1052_checker):
@pytest.mark.parametrize(
"address,expected_hash",
[
("0x0000000000000000000000000000000000000004", ZERO_HASH),
("0xFf00000000000000000000000000000000000004", keccak(hexstr="0xFE").hex()),
],
)
def test_extcodehash_with_send_tx_for_precompiled_contract(self, eip1052_checker, address, expected_hash):
# Check the EXTCODEHASH of a precompiled contract with send_tx.
sender_account = self.accounts[0]
tx = self.web3_client.make_raw_tx(sender_account)
precompiled_acc = AccountData(address="0xFf00000000000000000000000000000000000004")
precompiled_acc = AccountData(address=address)
instruction_tx = eip1052_checker.functions.getContractHashWithLog(precompiled_acc.address).build_transaction(tx)
receipt = self.web3_client.send_transaction(sender_account, instruction_tx)
event_logs = eip1052_checker.events.ReceivedHash().process_receipt(receipt)
contract_hash = event_logs[0]["args"]["hash"]
assert contract_hash.hex() == ZERO_HASH
assert contract_hash.hex() == expected_hash

@pytest.mark.only_stands
def test_extcodehash_for_new_account_with_changed_balance(self, eip1052_checker, common_contract):
Expand Down
9 changes: 2 additions & 7 deletions integration/tests/basic/evm/test_precompiled_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,7 @@ def test_delegatecall_via_contract(self, precompiled_contract, address, input_da
@pytest.mark.xdist_group("precompiled_contract_balance")
@pytest.mark.parametrize(**parametrized_data)
def test_call_via_send_trx(
self,
web3_client: NeonChainWeb3Client,
address,
input_data,
expected,
request,
pytestconfig,
self, web3_client: NeonChainWeb3Client, address, input_data, request, pytestconfig, expected, evm_loader
):
if request.node.callspec.id == "blake2f-vector 8":
pytest.skip("NDEV-1961")
Expand All @@ -155,6 +149,7 @@ def test_call_via_send_trx(
]:
receipt = self.web3_client.send_transaction(sender_account, instruction_tx)
assert receipt["status"] == 1

if pytestconfig.getoption("--network") not in ["devnet", "night-stand"]:
assert self.web3_client.get_balance(address) - balance_before == amount
else:
Expand Down
17 changes: 12 additions & 5 deletions integration/tests/basic/evm/test_solana_interoperability.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from utils.web3client import NeonChainWeb3Client


@pytest.fixture(scope="function")
@pytest.fixture(scope="class")
def get_counter_value() -> tp.Iterator[int]:
def gen_increment_counter():
count = 0
Expand Down Expand Up @@ -371,7 +371,7 @@ def test_limit_of_simple_instr_in_one_trx(self, call_solana_caller, counter_reso
sender = self.accounts[0]
call_params = []

for _ in range(24):
for _ in range(26):
instruction = Instruction(
program_id=COUNTER_ID,
accounts=[
Expand Down Expand Up @@ -505,7 +505,7 @@ def test_failed_solana_call_after_iterative_actions(self, call_solana_caller, so
def test_solana_call_after_iterative_actions_exceed_accounts_limit(
self, counter_resource_address: bytes, call_solana_caller
):
iterations = 53
loop_count = 54
sender = self.accounts[0]
lamports = 0

Expand All @@ -524,7 +524,7 @@ def test_solana_call_after_iterative_actions_exceed_accounts_limit(
web3.exceptions.ContractLogicError,
match="too many accounts: 65 > 64",
):
call_solana_caller.functions.executeInIterativeMode(iterations, lamports, serialized).build_transaction(tx)
call_solana_caller.functions.executeInIterativeMode(loop_count, lamports, serialized).build_transaction(tx)

def test_solana_call_inside_iterative_actions(
self, counter_resource_address: bytes, call_solana_caller, get_counter_value
Expand All @@ -551,7 +551,14 @@ def test_solana_call_inside_iterative_actions(
assert resp["status"] == 1

event_logs_bytes = call_solana_caller.events.LogBytes().process_receipt(resp)
assert int.from_bytes(event_logs_bytes[0].args.value, byteorder="little") == next(get_counter_value)
for i in range(matrix_lenght - 1):
next(get_counter_value)

all_logs_value = [
int.from_bytes(event_logs_byte.args.value, byteorder="little") for event_logs_byte in event_logs_bytes
]

assert max(all_logs_value) == next(get_counter_value)

event_logs_int = call_solana_caller.events.LogInt().process_receipt(resp)
assert event_logs_int[0].args.value == sum(sum(row) for row in matrix)
Expand Down
13 changes: 13 additions & 0 deletions integration/tests/basic/helpers/rpc_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
from collections import Counter
from types import SimpleNamespace

import allure
from hexbytes import HexBytes
from solders.pubkey import Pubkey
from web3 import types

from clickfile import EnvName
from integration.tests.basic.helpers.assert_message import AssertMessage
from integration.tests.basic.helpers.basic import NeonEventType, SolanaInstruction
from utils.models.result import NeonGetTransactionResult, SolanaByNeonTransaction
from utils.solana_client import SolanaClient
from utils.web3client import Web3Client

NoneType = type(None)

Expand Down Expand Up @@ -420,3 +424,12 @@ def assert_solana_trxs_in_neon_receipt(rpc_client, trx_hash, neon_receipt: NeonG

solana_trxs_by_neon = [trx.solanaTransactionSignature for trx in neon_receipt.result.solanaTransactions]
assert set(solana_transactions.result) == set(solana_trxs_by_neon)


@allure.step("Assert that {solana_address} was not used in the transaction")
def assert_solana_address_was_not_used_in_trx(
neon_trx: str, solana_address: str, web3_client: Web3Client, sol_client: SolanaClient
):
sol_trx = web3_client.get_solana_trx_by_neon(neon_trx)["result"][0]
sol_accounts = sol_client.get_account_keys_for_transaction(sol_trx)
assert Pubkey.from_string(solana_address) not in sol_accounts, f"Address {solana_address} is in the account list"
Loading
Loading