Skip to content

Commit

Permalink
fix erc20ForSpl tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kristinaNikolaevaa committed Oct 21, 2024
1 parent 297fd18 commit bc4c1ec
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 181 deletions.
12 changes: 5 additions & 7 deletions clickfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,11 @@ def update_contracts(branch):
download_evm_contracts(branch)
update_contracts_from_git(HOODIES_CHAINLINK_GITHUB_URL, "hoodies_chainlink", "main")

contracts_branch = "main"
if is_branch_exist(NEON_CONTRACTS_GITHUB_URL, branch) and branch != "develop":
contracts_branch = branch
update_contracts_from_git(
NEON_CONTRACTS_REPO_URL, "neon-contracts", contracts_branch, update_npm=False
)
subprocess.check_call(f'npm ci --prefix {EXTERNAL_CONTRACT_PATH / "neon-contracts" / "ERC20ForSPL"}', shell=True)
# uncomment for new version of erc20ForSpl
# update_contracts_from_git(
# f"https://github.com/{DOCKER_HUB_ORG_NAME}/neon-contracts.git", "neon-contracts", "main", update_npm=False
# )
# subprocess.check_call(f'npm ci --prefix {EXTERNAL_CONTRACT_PATH / "neon-contracts" / "ERC20ForSPL"}', shell=True)


@cli.command(help="Run any type of tests")
Expand Down
18 changes: 12 additions & 6 deletions contracts/EIPs/ERC20/MultipleActions.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
pragma solidity >=0.7.0;
pragma abicoder v2;

import "../../external/neon-contracts/ERC20ForSPL/contracts/ERC20ForSPLMintable.sol";
import "../../external/neon-contracts/ERC20ForSPL/contracts/ERC20ForSPLMintableFactory.sol";
import "../../external/neon-evm/erc20_for_spl.sol";

contract MultipleActionsERC20 {
uint256 data;
ERC20ForSPLMintable erc20;
ERC20ForSplMintable erc20;

constructor(
address _token
string memory _name,
string memory _symbol,
uint8 _decimals
) {
erc20 = ERC20ForSPLMintable(_token);
erc20 = new ERC20ForSplMintable(
_name,
_symbol,
_decimals,
address(this)
);
}

function balance(address who) public view returns (uint256) {
Expand Down Expand Up @@ -127,4 +133,4 @@ contract MultipleActionsERC20 {
erc20.transfer(transfer_to, mint_amount1);
erc20.transfer(transfer_to, mint_amount2);
}
}
}
4 changes: 2 additions & 2 deletions integration/tests/basic/erc/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def multiple_actions_erc20(web3_client_session, accounts, erc20_spl_mintable):
"0.8.24",
accounts[0],
contract_name="MultipleActionsERC20",
constructor_args=[erc20_spl_mintable.address],
constructor_args=[f"Test TTT", "TTT", 18],
)
erc20_spl_mintable.transfer_ownership(erc20_spl_mintable.account, contract.address)
return accounts[0], contract

34 changes: 16 additions & 18 deletions integration/tests/basic/erc/test_ERC20SPL.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ def test_burn_more_than_exist(
):
with pytest.raises(
web3.exceptions.ContractLogicError,
match="0x96ab19c8", # AmountExceedsBalance error
match="burn amount exceeds balance",
):
erc20_contract.burn(self.accounts[2], 1000)

def test_burn_more_than_total_supply(self, erc20_contract):
total = erc20_contract.contract.functions.totalSupply().call()
with pytest.raises(
web3.exceptions.ContractLogicError,
match="0x96ab19c8", # AmountExceedsBalance error
match="burn amount exceeds balance",
):
erc20_contract.burn(erc20_contract.account, total + 1)

Expand All @@ -136,7 +136,7 @@ def test_burnFrom_without_allowance(self, erc20_contract):
new_account = self.accounts.create_account()
with pytest.raises(
web3.exceptions.ContractLogicError,
match="0x65ba6fc3", # InvalidAllowance error
match="insufficient allowance",
):
erc20_contract.burn_from(new_account, erc20_contract.account.address, 10)

Expand All @@ -146,7 +146,7 @@ def test_burnFrom_more_than_allowanced(self, erc20_contract):
erc20_contract.approve(erc20_contract.account, new_account.address, amount)
with pytest.raises(
web3.exceptions.ContractLogicError,
match="0x65ba6fc3", # InvalidAllowance error
match="insufficient allowance",
):
erc20_contract.burn_from(new_account, erc20_contract.account.address, amount + 1)

Expand All @@ -173,7 +173,7 @@ def test_approve_more_than_total_supply(self, erc20_contract):
(
ZERO_ADDRESS,
web3.exceptions.ContractLogicError,
"0x7138356f", # EmptyAddress error
"approve to the zero address",
),
],
)
Expand Down Expand Up @@ -219,7 +219,7 @@ def test_transfer(self, erc20_contract, restore_balance):
(
ZERO_ADDRESS,
web3.exceptions.ContractLogicError,
"0x7138356f", # EmptyAddress error
"transfer to the zero address",
),
],
)
Expand All @@ -232,7 +232,7 @@ def test_transfer_more_than_balance(self, erc20_contract):
balance = erc20_contract.contract.functions.balanceOf(erc20_contract.account.address).call()
with pytest.raises(
web3.exceptions.ContractLogicError,
match="0x96ab19c8", # AmountExceedsBalance error
match="transfer amount exceeds balance",
):
erc20_contract.transfer(erc20_contract.account, erc20_contract.account.address, balance + 1)

Expand Down Expand Up @@ -260,7 +260,7 @@ def test_transferFrom_without_allowance(self, erc20_contract):
new_account = self.accounts.create_account()
with pytest.raises(
web3.exceptions.ContractLogicError,
match="0x65ba6fc3", # InvalidAllowance error
match="insufficient allowance", # InvalidAllowance error insufficient allowance
):
erc20_contract.transfer_from(
signer=new_account,
Expand All @@ -275,7 +275,7 @@ def test_transferFrom_more_than_allowanced(self, erc20_contract):
erc20_contract.approve(erc20_contract.account, new_account.address, amount)
with pytest.raises(
web3.exceptions.ContractLogicError,
match="0x65ba6fc3", # InvalidAllowance error
match="insufficient allowance",
):
erc20_contract.transfer_from(
signer=new_account,
Expand All @@ -299,7 +299,7 @@ def test_transferFrom_more_than_balance(self, erc20_contract):
erc20_contract.approve(erc20_contract.account, new_account.address, amount)
with pytest.raises(
web3.exceptions.ContractLogicError,
match="0x96ab19c8", # AmountExceedsBalance error
match="transfer amount exceeds balance",
):
erc20_contract.transfer_from(
signer=new_account,
Expand Down Expand Up @@ -473,6 +473,7 @@ def restore_balance(self, erc20_spl_mintable):
default_value - current_balance,
)

@pytest.mark.skip(reason="This test is not actual for erc20ForSpl 1.0.0")
def test_owner(self, erc20_contract):
owner = erc20_contract.contract.functions.owner().call()
assert owner == erc20_contract.account.address
Expand All @@ -482,6 +483,7 @@ def return_ownership(self, erc20_contract, accounts):
yield
erc20_contract.transfer_ownership(accounts[2], erc20_contract.account.address)

@pytest.mark.skip(reason="This test is not actual for erc20ForSpl 1.0.0")
def test_transferOwnership(self, erc20_contract, accounts, return_ownership):
erc20_contract.transfer_ownership(erc20_contract.account, accounts[2].address)
owner = erc20_contract.contract.functions.owner().call()
Expand All @@ -493,7 +495,6 @@ def test_metaplex_data(self, erc20_contract):
metadata = metaplex.get_metadata(self.sol_client, mint_key)
assert metadata["data"]["name"] == erc20_contract.name
assert metadata["data"]["symbol"] == erc20_contract.symbol
assert metadata["data"]["uri"] == "http://uri.com"
assert metadata["is_mutable"] is True

def test_mint_to_self(self, erc20_contract, restore_balance):
Expand All @@ -513,20 +514,16 @@ def test_mint_to_another_account(self, erc20_contract):

def test_mint_by_no_minter_role(self, erc20_contract):
recipient_account = self.accounts[1]
try:
with pytest.raises(web3.exceptions.ContractLogicError, match="must have minter role to mint"):
erc20_contract.mint_tokens(recipient_account, recipient_account.address, 0)
except web3.exceptions.ContractLogicError as e:
assert "0x118cdaa7" in str(e)
else:
assert False, "No exception raised"

@pytest.mark.parametrize(
"address_to, expected_exception, msg",
[
(
ZERO_ADDRESS,
web3.exceptions.ContractLogicError,
"0x7138356f", # EmptyAddress error
"mint to the zero address",
),
],
)
Expand All @@ -538,7 +535,7 @@ def test_mint_with_incorrect_address(self, erc20_contract, address_to, expected_
def test_mint_with_too_big_amount(self, erc20_contract):
with pytest.raises(
web3.exceptions.ContractLogicError,
match="0x679346bc", # AmountExceedsUint64 error
match="total mint amount exceeds uint64 max",
):
erc20_contract.mint_tokens(
erc20_contract.account,
Expand Down Expand Up @@ -1008,6 +1005,7 @@ def new_token_contract(web3_client, erc20_spl_mintable):
@allure.story("ERC20SPL: Tests for factory update")
@pytest.mark.usefixtures("accounts", "web3_client", "sol_client")
@pytest.mark.neon_only
@pytest.mark.skip(reason="This test is not actual for erc20ForSpl 1.0.0")
class TestERC20FactoryUpdate:
web3_client: NeonChainWeb3Client
accounts: EthAccounts
Expand Down
2 changes: 1 addition & 1 deletion integration/tests/basic/rpc/test_rpc_estimate_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_rpc_estimate_gas_spl(self, erc20_spl):

assert "gas" in transaction
estimated_gas = transaction["gas"]
assert estimated_gas == 2_089_280
assert estimated_gas == 2_079_280

@pytest.mark.neon_only # Geth returns a different estimate
def test_rpc_estimate_gas_contract_get_value(self, common_contract):
Expand Down
34 changes: 4 additions & 30 deletions integration/tests/neon_evm/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import eth_abi
import pytest
from eth_utils import abi
from solders.keypair import Keypair
from eth_keys import keys as eth_keys
from solders.pubkey import Pubkey
Expand Down Expand Up @@ -176,43 +175,18 @@ def calculator_caller_contract(


@pytest.fixture(scope="session")
def erc20_for_spl_proxy_contract(
def erc20_for_spl_factory_contract(
operator_keypair, evm_loader, sender_with_tokens, treasury_pool, neon_api_client, holder_acc
):
contracts_path = "external/neon-contracts/ERC20ForSPL/contracts/"
beacon_erc20 = deploy_contract(
operator_keypair,
sender_with_tokens,
f"{contracts_path}ERC20ForSPLMintable",
evm_loader,
treasury_pool,
contract_name="ERC20ForSPLMintable",
version="0.8.24",
)

erc20_factory = deploy_contract(
operator_keypair,
sender_with_tokens,
f"{contracts_path}ERC20ForSPLMintableFactory",
evm_loader,
treasury_pool,
contract_name="ERC20ForSPLMintableFactory",
version="0.8.24",
)
data = abi.function_signature_to_4byte_selector("initialize(address)") + eth_abi.encode(
["address"], [f"0x{beacon_erc20.eth_address.hex()}"]
)
proxy_contract = deploy_contract(
return deploy_contract(
operator_keypair,
sender_with_tokens,
f"{contracts_path}openzeppelin-fork/contracts/proxy/ERC1967/ERC1967Proxy",
"external/neon-evm/erc20_for_spl_factory",
evm_loader,
treasury_pool,
contract_name="ERC1967Proxy",
contract_name="ERC20ForSplFactory",
version="0.8.24",
encoded_args=eth_abi.encode(["address", "bytes"], [f"0x{erc20_factory.eth_address.hex()}", data]),
)
return proxy_contract


@pytest.fixture(scope="session")
Expand Down
13 changes: 6 additions & 7 deletions integration/tests/neon_evm/test_transaction_step_from_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,27 +905,26 @@ def test_next_operator_can_continue_trx_with_created_spl(
treasury_pool,
holder_acc,
neon_api_client,
erc20_for_spl_proxy_contract,
erc20_for_spl_factory_contract,
):
func_signature = "deploy(string,string,string,uint8)"
func_args = ["Test", "TTT", "http://uri.com", 9]
func_signature = "createErc20ForSplMintable(string,string,uint8,address)"
func_args = ["Test", "TTT", 9, sender_with_tokens.eth_address.hex()]
emulate_result = neon_api_client.emulate_contract_call(
sender_with_tokens.eth_address.hex(),
erc20_for_spl_proxy_contract.eth_address.hex(),
erc20_for_spl_factory_contract.eth_address.hex(),
func_signature,
func_args,
)
additional_accounts = [Pubkey.from_string(item["pubkey"]) for item in emulate_result["solana_accounts"]]
signed_tx = make_contract_call_trx(
evm_loader, sender_with_tokens, erc20_for_spl_proxy_contract, func_signature, func_args
evm_loader, sender_with_tokens, erc20_for_spl_factory_contract, func_signature, func_args
)

evm_loader.write_transaction_to_holder_account(signed_tx, holder_acc, operator_keypair)

operator_balance_pubkey = evm_loader.get_operator_balance_pubkey(operator_keypair)
second_operator_balance = evm_loader.get_operator_balance_pubkey(second_operator_keypair)

# 1
evm_loader.send_transaction_step_from_account(
operator_keypair,
operator_balance_pubkey,
Expand All @@ -942,7 +941,7 @@ def test_next_operator_can_continue_trx_with_created_spl(
treasury_pool,
holder_acc,
additional_accounts,
5000,
emulate_result["steps_executed"],
operator_keypair,
)

Expand Down
Loading

0 comments on commit bc4c1ec

Please sign in to comment.