From 2c4fdb90aab74445fb7751e682d227aabbcdb671 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 22 Dec 2023 09:33:48 +0800 Subject: [PATCH 01/11] Problem: push0 opcode is not tested - shanghai hardfork introduces push0 opcode, can be enabled in solc --- CHANGELOG.md | 1 + integration_tests/contracts/contracts/CosmosToken.sol | 2 +- integration_tests/contracts/contracts/Gravity.sol | 2 +- integration_tests/contracts/contracts/ICosmosToken.sol | 2 +- integration_tests/contracts/contracts/TestBlackListERC20.sol | 2 +- integration_tests/contracts/contracts/TestCRC20.sol | 2 +- integration_tests/contracts/contracts/TestERC20A.sol | 2 +- integration_tests/contracts/contracts/TestERC20Utility.sol | 2 +- integration_tests/contracts/contracts/TestERC21Source.sol | 2 +- .../contracts/contracts/TestMaliciousSupply.sol | 2 +- integration_tests/contracts/hardhat.config.ts | 5 +++-- 11 files changed, 13 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f6e30d6ef..41f5011a02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## UNRELEASED - [#1258](https://github.com/crypto-org-chain/cronos/pull/1258) Support hard-fork style upgrades. +- [#]() Enable push0 opcode in integration test *December 11, 2023* diff --git a/integration_tests/contracts/contracts/CosmosToken.sol b/integration_tests/contracts/contracts/CosmosToken.sol index 6a9e66695f..c948d5f7ce 100644 --- a/integration_tests/contracts/contracts/CosmosToken.sol +++ b/integration_tests/contracts/contracts/CosmosToken.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.8.10; +pragma solidity ^0.8.21; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "./ICosmosToken.sol"; diff --git a/integration_tests/contracts/contracts/Gravity.sol b/integration_tests/contracts/contracts/Gravity.sol index a55f28e1f8..943b55976f 100644 --- a/integration_tests/contracts/contracts/Gravity.sol +++ b/integration_tests/contracts/contracts/Gravity.sol @@ -1,4 +1,4 @@ -pragma solidity 0.8.10; +pragma solidity 0.8.21; import "@openzeppelin/contracts/access/AccessControl.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; diff --git a/integration_tests/contracts/contracts/ICosmosToken.sol b/integration_tests/contracts/contracts/ICosmosToken.sol index 8dc9251881..1e7eacb314 100644 --- a/integration_tests/contracts/contracts/ICosmosToken.sol +++ b/integration_tests/contracts/contracts/ICosmosToken.sol @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.10; +pragma solidity 0.8.21; /** * @dev Interface of the CosmosToken deployed by the gravity contract diff --git a/integration_tests/contracts/contracts/TestBlackListERC20.sol b/integration_tests/contracts/contracts/TestBlackListERC20.sol index 407596418a..51f11b8490 100644 --- a/integration_tests/contracts/contracts/TestBlackListERC20.sol +++ b/integration_tests/contracts/contracts/TestBlackListERC20.sol @@ -1,4 +1,4 @@ -pragma solidity 0.8.10; +pragma solidity 0.8.21; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; contract TestBlackListERC20 is ERC20 { diff --git a/integration_tests/contracts/contracts/TestCRC20.sol b/integration_tests/contracts/contracts/TestCRC20.sol index 5b8be5b755..5edc07c8eb 100644 --- a/integration_tests/contracts/contracts/TestCRC20.sol +++ b/integration_tests/contracts/contracts/TestCRC20.sol @@ -1,4 +1,4 @@ -pragma solidity 0.8.10; +pragma solidity 0.8.21; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; // An utility erc20 contract that has a fancy method diff --git a/integration_tests/contracts/contracts/TestERC20A.sol b/integration_tests/contracts/contracts/TestERC20A.sol index 545443c7aa..9aafb3b8ea 100644 --- a/integration_tests/contracts/contracts/TestERC20A.sol +++ b/integration_tests/contracts/contracts/TestERC20A.sol @@ -1,4 +1,4 @@ -pragma solidity 0.8.10; +pragma solidity 0.8.21; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; contract TestERC20A is ERC20 { diff --git a/integration_tests/contracts/contracts/TestERC20Utility.sol b/integration_tests/contracts/contracts/TestERC20Utility.sol index 6658478538..0707943f7f 100644 --- a/integration_tests/contracts/contracts/TestERC20Utility.sol +++ b/integration_tests/contracts/contracts/TestERC20Utility.sol @@ -1,4 +1,4 @@ -pragma solidity 0.8.10; +pragma solidity 0.8.21; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; // An utility erc20 contract that has a fancy method diff --git a/integration_tests/contracts/contracts/TestERC21Source.sol b/integration_tests/contracts/contracts/TestERC21Source.sol index 1e09f8d004..6164473bae 100644 --- a/integration_tests/contracts/contracts/TestERC21Source.sol +++ b/integration_tests/contracts/contracts/TestERC21Source.sol @@ -1,4 +1,4 @@ -pragma solidity 0.8.10; +pragma solidity 0.8.21; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; contract TestERC21Source is ERC20 { diff --git a/integration_tests/contracts/contracts/TestMaliciousSupply.sol b/integration_tests/contracts/contracts/TestMaliciousSupply.sol index 19eda558b4..f97c5b3ecd 100644 --- a/integration_tests/contracts/contracts/TestMaliciousSupply.sol +++ b/integration_tests/contracts/contracts/TestMaliciousSupply.sol @@ -1,4 +1,4 @@ -pragma solidity 0.8.10; +pragma solidity 0.8.21; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; // This contract is for testing a case on the gravity bridge when attacker try to send an amount diff --git a/integration_tests/contracts/hardhat.config.ts b/integration_tests/contracts/hardhat.config.ts index cac109b93b..3292349ae6 100644 --- a/integration_tests/contracts/hardhat.config.ts +++ b/integration_tests/contracts/hardhat.config.ts @@ -4,11 +4,12 @@ module.exports = { solidity: { compilers: [ { - version: "0.8.10", + version: "0.8.21", settings: { optimizer: { enabled: true - } + }, + evmVersion: "shanghai" } }, { From 5df17e3ddac7283106e420035988ea84354aa11f Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 22 Dec 2023 09:35:53 +0800 Subject: [PATCH 02/11] Update CHANGELOG.md Signed-off-by: yihuang --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41f5011a02..fa38004f14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## UNRELEASED - [#1258](https://github.com/crypto-org-chain/cronos/pull/1258) Support hard-fork style upgrades. -- [#]() Enable push0 opcode in integration test +- [#1273](https://github.com/crypto-org-chain/cronos/pull/1273) Enable push0 opcode in integration test *December 11, 2023* From f63b2bb94fa1648d3a3baedad0c6db3db876051a Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 22 Dec 2023 09:45:36 +0800 Subject: [PATCH 03/11] enlarge gas gap --- integration_tests/test_ibc_rly_gas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/test_ibc_rly_gas.py b/integration_tests/test_ibc_rly_gas.py index 4300adc817..fcad133e54 100644 --- a/integration_tests/test_ibc_rly_gas.py +++ b/integration_tests/test_ibc_rly_gas.py @@ -23,7 +23,7 @@ def test_ibc(ibc): cli = ibc.cronos.cosmos_cli() wait_for_new_blocks(cli, 1) rly_transfer(ibc) - diff = 0.005 + diff = 0.01 record = log_gas_records(cli) if record: records.append(record) From a183cce8d19317af9fc3fe063f0a0757f72ca094 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 22 Dec 2023 10:17:17 +0800 Subject: [PATCH 04/11] assert some exact gas number --- integration_tests/conftest.py | 1 + integration_tests/test_basic.py | 2 ++ integration_tests/test_pruned_node.py | 2 +- integration_tests/utils.py | 5 ++++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/integration_tests/conftest.py b/integration_tests/conftest.py index 6a0b68caf7..0510c2cb49 100644 --- a/integration_tests/conftest.py +++ b/integration_tests/conftest.py @@ -11,6 +11,7 @@ def pytest_configure(config): + config.addinivalue_line("markers", "unmarked: fallback mark for unmarked tests") config.addinivalue_line("markers", "slow: marks tests as slow") config.addinivalue_line("markers", "gravity: gravity bridge test cases") config.addinivalue_line("markers", "ica: marks ica tests") diff --git a/integration_tests/test_basic.py b/integration_tests/test_basic.py index cd18aad705..3cd843895b 100644 --- a/integration_tests/test_basic.py +++ b/integration_tests/test_basic.py @@ -51,6 +51,7 @@ def test_send_transaction(cluster): ) receipt = w3.eth.wait_for_transaction_receipt(txhash) assert receipt.status == 1 + assert receipt.gasUsed == 21000 def test_events(cluster, suspend_capture): @@ -59,6 +60,7 @@ def test_events(cluster, suspend_capture): w3, CONTRACTS["TestERC20A"], key=KEYS["validator"], + exp_gas_used=633810, ) tx = erc20.functions.transfer(ADDRS["community"], 10).build_transaction( {"from": ADDRS["validator"]} diff --git a/integration_tests/test_pruned_node.py b/integration_tests/test_pruned_node.py index 83e3288685..aee213fa40 100644 --- a/integration_tests/test_pruned_node.py +++ b/integration_tests/test_pruned_node.py @@ -46,7 +46,7 @@ def test_pruned_node(cronos): ) signed = sign_transaction(w3, tx, KEYS["validator"]) txhash = w3.eth.send_raw_transaction(signed.rawTransaction) - exp_gas_used = 51384 + exp_gas_used = 51383 print("wait for prunning happens") wait_for_new_blocks(cronos.cosmos_cli(0), 10) diff --git a/integration_tests/utils.py b/integration_tests/utils.py index a51bb26a32..8d51a688b8 100644 --- a/integration_tests/utils.py +++ b/integration_tests/utils.py @@ -345,7 +345,7 @@ def supervisorctl(inipath, *args): ).decode() -def deploy_contract(w3, jsonfile, args=(), key=KEYS["validator"]): +def deploy_contract(w3, jsonfile, args=(), key=KEYS["validator"], exp_gas_used=None): """ deploy contract and return the deployed contract instance """ @@ -360,6 +360,9 @@ def deploy_contract(w3, jsonfile, args=(), key=KEYS["validator"]): tx = contract.constructor(*args).build_transaction({"from": acct.address}) txreceipt = send_transaction(w3, tx, key) assert txreceipt.status == 1 + if exp_gas_used is not None: + assert exp_gas_used == txreceipt.gasUsed, \ + f'exp {exp_gas_used}, got {txreceipt.gasUsed}' address = txreceipt.contractAddress return w3.eth.contract(address=address, abi=info["abi"]) From ea4a2923e9b245ab44b4b20889087da997b00e67 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 22 Dec 2023 10:20:29 +0800 Subject: [PATCH 05/11] fix python lint --- integration_tests/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/integration_tests/utils.py b/integration_tests/utils.py index 8d51a688b8..7259928238 100644 --- a/integration_tests/utils.py +++ b/integration_tests/utils.py @@ -361,8 +361,9 @@ def deploy_contract(w3, jsonfile, args=(), key=KEYS["validator"], exp_gas_used=N txreceipt = send_transaction(w3, tx, key) assert txreceipt.status == 1 if exp_gas_used is not None: - assert exp_gas_used == txreceipt.gasUsed, \ - f'exp {exp_gas_used}, got {txreceipt.gasUsed}' + assert ( + exp_gas_used == txreceipt.gasUsed + ), f"exp {exp_gas_used}, got {txreceipt.gasUsed}" address = txreceipt.contractAddress return w3.eth.contract(address=address, abi=info["abi"]) From 7b0ce3bbc1353a54762fcc223695d29e1987416c Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 22 Dec 2023 14:10:09 +0800 Subject: [PATCH 06/11] Problem: there are flaky integration tests (#1276) * Problem: there are flaky integration tests wait for first block * add missing markers --- integration_tests/conftest.py | 1 + integration_tests/test_min_gas_price.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/integration_tests/conftest.py b/integration_tests/conftest.py index 0510c2cb49..e867573f78 100644 --- a/integration_tests/conftest.py +++ b/integration_tests/conftest.py @@ -22,6 +22,7 @@ def pytest_configure(config): config.addinivalue_line("markers", "ibc_timeout: marks ibc timeout tests") config.addinivalue_line("markers", "ibc_update_client: marks ibc updateclient test") config.addinivalue_line("markers", "gov: marks gov related tests") + config.addinivalue_line("markers", "gas: marks gas related tests") def pytest_collection_modifyitems(items, config): diff --git a/integration_tests/test_min_gas_price.py b/integration_tests/test_min_gas_price.py index 272a64780a..5a9a7bd53f 100644 --- a/integration_tests/test_min_gas_price.py +++ b/integration_tests/test_min_gas_price.py @@ -3,7 +3,7 @@ import pytest from .network import setup_custom_cronos -from .utils import ADDRS, KEYS, send_transaction, w3_wait_for_block +from .utils import ADDRS, KEYS, send_transaction, w3_wait_for_block, wait_for_new_blocks pytestmark = pytest.mark.gas @@ -26,7 +26,7 @@ def custom_cronos(tmp_path_factory): @pytest.fixture(scope="module") def custom_cronos_lte(tmp_path_factory): - path = tmp_path_factory.mktemp("min-gas-price-gt") + path = tmp_path_factory.mktemp("min-gas-price-lte") yield from setup_custom_cronos( path, 26560, Path(__file__).parent / "configs/min_gas_price_lte.jsonnet" ) @@ -65,6 +65,7 @@ def get_params(cli): def test_dynamic_fee_tx(custom_cluster): + wait_for_new_blocks(custom_cluster.cosmos_cli(), 1) w3 = custom_cluster.w3 amount = 10000 before = w3.eth.get_balance(ADDRS["community"]) @@ -102,6 +103,7 @@ def test_base_fee_adjustment(custom_cluster): """ verify base fee adjustment of three continuous empty blocks """ + wait_for_new_blocks(custom_cluster.cosmos_cli(), 1) w3 = custom_cluster.w3 begin = w3.eth.block_number w3_wait_for_block(w3, begin + 3) From 6a475183ef8b50d95d9d3fb28a26a06bd9e63fb7 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 22 Dec 2023 09:33:48 +0800 Subject: [PATCH 07/11] Problem: push0 opcode is not tested - shanghai hardfork introduces push0 opcode, can be enabled in solc Update CHANGELOG.md Signed-off-by: yihuang enlarge gas gap assert some exact gas number fix python lint test upgrade test push0 opcode in upgrade --- .../contracts/contracts/Greeter.sol | 2 +- integration_tests/contracts/hardhat.config.ts | 8 ++++++++ integration_tests/test_upgrade.py | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/integration_tests/contracts/contracts/Greeter.sol b/integration_tests/contracts/contracts/Greeter.sol index 2f5dbda54f..0bd0d5330e 100644 --- a/integration_tests/contracts/contracts/Greeter.sol +++ b/integration_tests/contracts/contracts/Greeter.sol @@ -1,4 +1,4 @@ -pragma solidity >0.5.0; +pragma solidity 0.8.21; contract Greeter { string public greeting; diff --git a/integration_tests/contracts/hardhat.config.ts b/integration_tests/contracts/hardhat.config.ts index 3292349ae6..80e05f7eed 100644 --- a/integration_tests/contracts/hardhat.config.ts +++ b/integration_tests/contracts/hardhat.config.ts @@ -12,6 +12,14 @@ module.exports = { evmVersion: "shanghai" } }, + { + version: "0.8.10", + settings: { + optimizer: { + enabled: true + } + } + }, { version: "0.6.6", settings: { diff --git a/integration_tests/test_upgrade.py b/integration_tests/test_upgrade.py index 214109e8f5..52e9260ffe 100644 --- a/integration_tests/test_upgrade.py +++ b/integration_tests/test_upgrade.py @@ -123,7 +123,21 @@ def exec(c, tmp_path_factory, testnet=True): print("upgrade height", target_height) w3 = c.w3 + + if not testnet: + # before upgrade, PUSH0 opcode is not supported + with pytest.raises(ValueError) as e_info: + deploy_contract(w3, CONTRACTS["Greeter"]) + assert 'invalid opcode: PUSH0' in str(e_info.value) + contract = deploy_contract(w3, CONTRACTS["TestERC20A"]) + + tx = contract.functions.transfer(ADDRS["community"], 10).transact( + {"from": ADDRS["validator"]} + ) + tx_receipt = w3.eth.wait_for_transaction_receipt(tx) + print(tx_receipt) + old_height = w3.eth.block_number old_balance = w3.eth.get_balance(ADDRS["validator"], block_identifier=old_height) old_base_fee = w3.eth.get_block(old_height).baseFeePerGas @@ -174,6 +188,10 @@ def exec(c, tmp_path_factory, testnet=True): ) assert receipt.status == 1 + if not testnet: + # after upgrade, PUSH0 opcode is supported + deploy_contract(w3, CONTRACTS["Greeter"]) + # query json-rpc on older blocks should success assert old_balance == w3.eth.get_balance( ADDRS["validator"], block_identifier=old_height From 02ee4da8bda6e0bfc7e6015053654eaca138c166 Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 22 Dec 2023 14:38:35 +0800 Subject: [PATCH 08/11] Update integration_tests/test_upgrade.py Signed-off-by: yihuang --- integration_tests/test_upgrade.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/integration_tests/test_upgrade.py b/integration_tests/test_upgrade.py index 52e9260ffe..5a9087f1ec 100644 --- a/integration_tests/test_upgrade.py +++ b/integration_tests/test_upgrade.py @@ -131,13 +131,6 @@ def exec(c, tmp_path_factory, testnet=True): assert 'invalid opcode: PUSH0' in str(e_info.value) contract = deploy_contract(w3, CONTRACTS["TestERC20A"]) - - tx = contract.functions.transfer(ADDRS["community"], 10).transact( - {"from": ADDRS["validator"]} - ) - tx_receipt = w3.eth.wait_for_transaction_receipt(tx) - print(tx_receipt) - old_height = w3.eth.block_number old_balance = w3.eth.get_balance(ADDRS["validator"], block_identifier=old_height) old_base_fee = w3.eth.get_block(old_height).baseFeePerGas From 53cf858a3f65e3b91baad4153ddc83e1af5e4bdb Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 22 Dec 2023 14:39:13 +0800 Subject: [PATCH 09/11] py lint --- integration_tests/test_upgrade.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/test_upgrade.py b/integration_tests/test_upgrade.py index 5a9087f1ec..9ed2c0da19 100644 --- a/integration_tests/test_upgrade.py +++ b/integration_tests/test_upgrade.py @@ -128,7 +128,7 @@ def exec(c, tmp_path_factory, testnet=True): # before upgrade, PUSH0 opcode is not supported with pytest.raises(ValueError) as e_info: deploy_contract(w3, CONTRACTS["Greeter"]) - assert 'invalid opcode: PUSH0' in str(e_info.value) + assert "invalid opcode: PUSH0" in str(e_info.value) contract = deploy_contract(w3, CONTRACTS["TestERC20A"]) old_height = w3.eth.block_number From 18462e2960ad649e766a018b361cd2e63f4b7045 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 22 Dec 2023 14:46:40 +0800 Subject: [PATCH 10/11] fix test --- integration_tests/contracts/contracts/TestERC20A.sol | 2 +- integration_tests/test_pruned_node.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/integration_tests/contracts/contracts/TestERC20A.sol b/integration_tests/contracts/contracts/TestERC20A.sol index 9aafb3b8ea..545443c7aa 100644 --- a/integration_tests/contracts/contracts/TestERC20A.sol +++ b/integration_tests/contracts/contracts/TestERC20A.sol @@ -1,4 +1,4 @@ -pragma solidity 0.8.21; +pragma solidity 0.8.10; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; contract TestERC20A is ERC20 { diff --git a/integration_tests/test_pruned_node.py b/integration_tests/test_pruned_node.py index aee213fa40..83e3288685 100644 --- a/integration_tests/test_pruned_node.py +++ b/integration_tests/test_pruned_node.py @@ -46,7 +46,7 @@ def test_pruned_node(cronos): ) signed = sign_transaction(w3, tx, KEYS["validator"]) txhash = w3.eth.send_raw_transaction(signed.rawTransaction) - exp_gas_used = 51383 + exp_gas_used = 51384 print("wait for prunning happens") wait_for_new_blocks(cronos.cosmos_cli(0), 10) From cf651a8b09a44ff183a3e3c28a9885c797cde5fe Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 22 Dec 2023 15:24:08 +0800 Subject: [PATCH 11/11] Update integration_tests/test_basic.py Signed-off-by: yihuang --- integration_tests/test_basic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/test_basic.py b/integration_tests/test_basic.py index f33f6bdbc5..7d0445b355 100644 --- a/integration_tests/test_basic.py +++ b/integration_tests/test_basic.py @@ -64,7 +64,7 @@ def test_events(cluster, suspend_capture): w3, CONTRACTS["TestERC20A"], key=KEYS["validator"], - exp_gas_used=633810, + exp_gas_used=641641, ) tx = erc20.functions.transfer(ADDRS["community"], 10).build_transaction( {"from": ADDRS["validator"]}