Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into NDEV-2981-traceCal…
Browse files Browse the repository at this point in the history
…l-overrides-param

# Conflicts:
#	integration/tests/tracer/test_tracer_debug_methods.py
  • Loading branch information
romanova-natasha committed May 23, 2024
2 parents bcd368c + 7e61655 commit 3380e11
Show file tree
Hide file tree
Showing 5 changed files with 497 additions and 6 deletions.
43 changes: 43 additions & 0 deletions contracts/precompiled/QueryAccountCaller.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0;

import "../libraries/external/QueryAccount.sol";

contract QueryAccountCaller {

event QueryResultUint256(bool success, uint256 result);
event QueryResultBytes(bool success, bytes result);

function queryOwner(uint256 solana_address) external returns (bool, uint256) {
(bool success, uint256 result) = QueryAccount.owner(solana_address);
emit QueryResultUint256(success, result);
return (success, result);
}

function queryLength(uint256 solana_address) external view returns (bool, uint256) {
(bool success, uint256 result) = QueryAccount.length(solana_address);
return (success, result);
}

function queryLamports(uint256 solana_address) external view returns (bool, uint256) {
(bool success, uint256 result) = QueryAccount.lamports(solana_address);
return (success, result);
}

function queryExecutable(uint256 solana_address) external view returns (bool, bool) {
(bool success, bool result) = QueryAccount.executable(solana_address);
return (success, result);
}

function queryRentEpoch(uint256 solana_address) external view returns (bool, uint256) {
(bool success, uint256 result) = QueryAccount.rent_epoch(solana_address);
return (success, result);
}

function queryData(uint256 solana_address, uint64 offset, uint64 len) external returns (bool, bytes memory) {
(bool success, bytes memory result) = QueryAccount.data(solana_address, offset, len);
emit QueryResultBytes(success, result);
return (success, result);
}
}
26 changes: 26 additions & 0 deletions docs/tests/audit/evm/test_query_account.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Overview

Validate QueryAccount library

# Tests list

| Test case | Description | XFailed |
|------------------------------------------|-----------------------------------------------------------------------------------------------------|---------|
| test_owner_positive | Verifies correct owner address retrieval for a Solana account | |
| test_owner_through_transaction_positive | Verifies correct Solana address owner retrieval through a transaction (not function call) | |
| test_owner_negative_address_max_int | Tests behavior of queryOwner function with maximum possible integer as Solana address | |
| test_length_positive | Checks if queryLength function returns correct data length for a Solana account | |
| test_length_negative_address_max_int | Tests behavior of queryLength function with maximum possible integer as Solana address | |
| test_lamports_positive | Ensures correct retrieval of lamports for a Solana account | |
| test_lamports_negative_address_max_int | Tests behavior of queryLamports function with maximum possible integer as Solana address | |
| test_executable_true | Checks if queryExecutable function correctly identifies EVM loader-associated account as executable | |
| test_executable_false | Verifies queryExecutable function correctly identifies regular Solana account as non-executable | |
| test_executable_negative_address_max_int | Tests behavior of queryExecutable function with maximum possible integer as Solana address | |
| test_rent_epoch_positive | Ensures correct retrieval of rent epoch for a Solana account | |
| test_rent_epoch_negative_address_max_int | Tests behavior of queryRentEpoch function with maximum possible integer as Solana address | |
| test_data_positive | Checks if queryData function returns correct data for an EVM loader-associated Solana account | |
| test_data_through_transaction_positive | Checks if queryData function returns correct data through a transaction (not function call) | |
| test_data_negative_address_max_int | Tests behavior of queryData function with maximum possible integer as Solana address | |
| test_data_negative_invalid_offset | Verifies error handling of queryData function when providing an invalid offset | |
| test_data_negative_length_zero | Ensures queryData function returns an error when the provided length is zero | |
| test_data_negative_invalid_length | Tests error handling of queryData function when providing an invalid length | |
35 changes: 35 additions & 0 deletions integration/tests/basic/evm/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import pytest
from solana.publickey import PublicKey
from web3.contract import Contract

from utils import helpers
from utils.accounts import EthAccounts
from utils.solana_client import SolanaClient
from utils.web3client import Web3Client

SPL_TOKEN_ADDRESS = "0xFf00000000000000000000000000000000000004"
METAPLEX_ADDRESS = "0xff00000000000000000000000000000000000005"
Expand Down Expand Up @@ -52,3 +58,32 @@ def blockhash_contract(web3_client, accounts):
account=accounts[0],
)
return contract


@pytest.fixture(scope="class")
def query_account_caller_contract(
web3_client: Web3Client,
accounts: EthAccounts,
) -> Contract:
contract, _ = web3_client.deploy_and_get_contract(
"precompiled/QueryAccountCaller.sol",
"0.8.10",
contract_name="QueryAccountCaller",
account=accounts[0],
)
return contract


@pytest.fixture(scope="session")
def max_non_existent_solana_address(
sol_client_session: SolanaClient,
) -> int:
address_uint_256 = 2 ** 256
address_exists = True

while address_exists:
address_uint_256 -= 1
pubkey = PublicKey(address_uint_256.to_bytes(32, byteorder='big'))
address_exists = sol_client_session.get_account_info(pubkey=pubkey).value is not None

return address_uint_256
Loading

0 comments on commit 3380e11

Please sign in to comment.