forked from neonevm/neon-tests
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa8787d
commit 24993ff
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
pragma solidity 0.8.12; | ||
|
||
contract saveZeros { | ||
|
||
bytes32[64] public b; // prefills the contract storage | ||
bytes32 public number; | ||
mapping(uint256 => uint256) public intMapping; | ||
|
||
function saveZeroToVar() public returns (bytes32) { // should not create a new account | ||
number = bytes32(0); | ||
return number; | ||
} | ||
|
||
function saveZeroToMapping() public { // should not create a new account | ||
intMapping[0] = 0; | ||
} | ||
|
||
function saveZeroToMappingCycle() public { // should not create a new account | ||
for (uint i = 0; i < 10; i++) { | ||
intMapping[i] = 0; | ||
} | ||
} | ||
|
||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import pytest | ||
from solana.keypair import Keypair | ||
from solana.transaction import Signature | ||
|
||
from integration.tests.neon_evm.utils.contract import deploy_contract | ||
from integration.tests.neon_evm.utils.neon_api_client import NeonApiClient | ||
from utils.accounts import EthAccounts | ||
from utils.evm_loader import EvmLoader | ||
from utils.helpers import wait_condition | ||
from utils.solana_client import SolanaClient | ||
from utils.types import Contract, Caller, TreasuryPool | ||
from utils.web3client import NeonChainWeb3Client | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"function_signature", | ||
[ | ||
"saveZeroToVar", | ||
"saveZeroToMapping", | ||
"saveZeroToMappingCycle", | ||
], | ||
) | ||
class TestStorageCells: | ||
|
||
def test_emulate_save_zero( | ||
self, | ||
operator_keypair: Keypair, | ||
user_account: Caller, | ||
evm_loader: EvmLoader, | ||
treasury_pool: TreasuryPool, | ||
neon_api_client: NeonApiClient, | ||
sol_client: SolanaClient, | ||
function_signature: str, | ||
): | ||
contract: Contract = deploy_contract( | ||
operator=operator_keypair, | ||
user=user_account, | ||
contract_file_name="issues/Ndev3234.sol", | ||
evm_loader=evm_loader, | ||
treasury_pool=treasury_pool, | ||
contract_name="saveZeros", | ||
version="0.8.12", | ||
) | ||
|
||
emulate_result = neon_api_client.emulate_contract_call( | ||
sender=user_account.eth_address.hex(), | ||
contract=contract.eth_address.hex(), | ||
function_signature=function_signature + "()", | ||
) | ||
|
||
accounts_count = len(emulate_result["solana_accounts"]) | ||
assert accounts_count == 2, f"{accounts_count - 2} new account(s) created" | ||
|
||
def test_save_zero( | ||
self, | ||
web3_client: NeonChainWeb3Client, | ||
function_signature: str, | ||
accounts: EthAccounts, | ||
sol_client: SolanaClient, | ||
): | ||
account = accounts[0] | ||
contract, _ = web3_client.deploy_and_get_contract( | ||
contract="issues/Ndev3234.sol", | ||
version="0.8.12", | ||
account=account, | ||
contract_name="saveZeros", | ||
) | ||
|
||
raw_eth_tx = self.web3_client.make_raw_tx(from_=account) | ||
instruction_tx = getattr(contract.functions, function_signature)().build_transaction(raw_eth_tx) | ||
receipt = self.web3_client.send_transaction(account, instruction_tx) | ||
assert receipt.status == 1 | ||
solana_tx_hash = web3_client.get_solana_trx_by_neon(receipt.transactionHash.hex())["result"][0] | ||
solana_tx = wait_condition( | ||
func_cond=lambda: sol_client.get_transaction( | ||
tx_sig=Signature.from_string(solana_tx_hash), | ||
max_supported_transaction_version=0, | ||
), | ||
check_success=lambda tx: tx.value is not None, | ||
) | ||
if solana_tx.value.transaction.transaction.message.address_table_lookups: | ||
alt = solana_tx.value.transaction.transaction.message.address_table_lookups | ||
accounts_count = len(alt[0].writable_indexes) + len(alt[0].readonly_indexes) | ||
else: | ||
accounts_count = len(solana_tx.value.transaction.transaction.message.account_keys) | ||
assert accounts_count == 9, f"{accounts_count - 9} new account(s) created" |