From cbd1472de04fc54abd59c0068f79020efe3d7d09 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 20 Dec 2023 09:33:45 +0800 Subject: [PATCH] test providers --- integration_tests/conftest.py | 5 +++++ integration_tests/test_basic.py | 28 ++++++++++++++-------------- scripts/run-integration-tests | 2 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/integration_tests/conftest.py b/integration_tests/conftest.py index 980d4a9627..7c48da5858 100644 --- a/integration_tests/conftest.py +++ b/integration_tests/conftest.py @@ -77,3 +77,8 @@ def cluster(request, cronos, geth): yield cronos_ws else: raise NotImplementedError + + +def pytest_generate_tests(metafunc): + if "provider" in metafunc.fixturenames: + metafunc.parametrize("provider", ["cronos", "geth"]) diff --git a/integration_tests/test_basic.py b/integration_tests/test_basic.py index 7057644e67..caf1bfbb2c 100644 --- a/integration_tests/test_basic.py +++ b/integration_tests/test_basic.py @@ -34,14 +34,14 @@ ) -def test_basic(cluster): - w3 = cluster.w3 +def test_basic(provider, cronos, geth): + w3 = geth.w3 if provider == "geth" else cronos.w3 assert w3.eth.chain_id == 777 -def test_send_transaction(cluster): +def test_send_transaction(provider, cronos, geth): "test eth_sendTransaction api" - w3 = cluster.w3 + w3 = geth.w3 if provider == "geth" else cronos.w3 txhash = w3.eth.send_transaction( { "from": ADDRS["validator"], @@ -53,8 +53,8 @@ def test_send_transaction(cluster): assert receipt.status == 1 -def test_events(cluster, suspend_capture): - w3 = cluster.w3 +def test_events(provider, cronos, geth): + w3 = geth.w3 if provider == "geth" else cronos.w3 erc20 = deploy_contract( w3, CONTRACTS["TestERC20A"], @@ -524,8 +524,8 @@ def assert_receipt_transaction_and_block(w3, futures): assert transaction["blockNumber"] == block["number"] -def test_exception(cluster): - w3 = cluster.w3 +def test_exception(provider, cronos, geth): + w3 = geth.w3 if provider == "geth" else cronos.w3 contract = deploy_contract( w3, CONTRACTS["TestRevert"], @@ -543,14 +543,14 @@ def test_exception(cluster): assert 5 * (10**18) == contract.caller.query() -def test_refund_unused_gas_when_contract_tx_reverted(cluster): +def test_refund_unused_gas_when_contract_tx_reverted(provider, cronos, geth): """ Call a smart contract method that reverts with very high gas limit Call tx receipt should be status 0 (fail) Fee is gasUsed * effectiveGasPrice """ - w3 = cluster.w3 + w3 = geth.w3 if provider == "geth" else cronos.w3 contract = deploy_contract(w3, CONTRACTS["TestRevert"]) more_than_enough_gas = 1000000 @@ -594,13 +594,13 @@ def test_message_call(cronos): assert len(receipt.logs) == iterations -def test_suicide(cluster): +def test_suicide(provider, cronos, geth): """ test compliance of contract suicide - within the tx, after contract suicide, the code is still available. - after the tx, the code is not available. """ - w3 = cluster.w3 + w3 = geth.w3 if provider == "geth" else cronos.w3 destroyee = deploy_contract( w3, contract_path("Destroyee", "TestSuicide.sol"), @@ -747,11 +747,11 @@ def test_failed_transfer_tx(cronos): assert receipt.gasUsed == rsp["gas"] -def test_log0(cluster): +def test_log0(provider, cronos, geth): """ test compliance of empty topics behavior """ - w3 = cluster.w3 + w3 = geth.w3 if provider == "geth" else cronos.w3 contract = deploy_contract( w3, Path(__file__).parent diff --git a/scripts/run-integration-tests b/scripts/run-integration-tests index 258efd4d72..cfd5dffc8c 100755 --- a/scripts/run-integration-tests +++ b/scripts/run-integration-tests @@ -10,4 +10,4 @@ cd ../integration_tests/contracts HUSKY_SKIP_INSTALL=1 npm install npm run typechain cd .. -nix-shell --run "pytest -n auto -v -s test_basic.py::test_basic" \ No newline at end of file +nix-shell --run "pytest -v -s test_basic.py" \ No newline at end of file