From 6f78d7257b8bec6f7f5fde7c77e411611a9c3cff Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Mon, 12 Jun 2023 14:28:06 +0200 Subject: [PATCH] test: use `base_rs_contract` where appropriate `rs_contract` can be used by tests that run only on the latest protocol version, as defined by the const PROTOCOL_VERSION. `base_rs_contract` must be used in backwards compatibility tests that rely on specific protocol versions. This is a pre-requisite to land the rustc 1.70 toolchain upgrade. (See also #9140) --- .../features/increase_storage_compute_cost.rs | 2 +- .../src/tests/client/features/nearvm.rs | 2 +- runtime/near-vm-runner/src/tests/rs_contract.rs | 15 ++++++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/integration-tests/src/tests/client/features/increase_storage_compute_cost.rs b/integration-tests/src/tests/client/features/increase_storage_compute_cost.rs index 2164466f3a5..9af2a406af7 100644 --- a/integration-tests/src/tests/client/features/increase_storage_compute_cost.rs +++ b/integration-tests/src/tests/client/features/increase_storage_compute_cost.rs @@ -207,7 +207,7 @@ fn assert_compute_limit_reached( // setup: deploy the contract { // This contract has a bunch of methods to invoke storage operations. - let code = near_test_contracts::rs_contract().to_vec(); + let code = near_test_contracts::base_rs_contract().to_vec(); let actions = vec![Action::DeployContract(DeployContractAction { code })]; let signer = InMemorySigner::from_seed( diff --git a/integration-tests/src/tests/client/features/nearvm.rs b/integration-tests/src/tests/client/features/nearvm.rs index 8d2e2c53386..be747cca1a1 100644 --- a/integration-tests/src/tests/client/features/nearvm.rs +++ b/integration-tests/src/tests/client/features/nearvm.rs @@ -36,7 +36,7 @@ fn test_nearvm_upgrade() { deploy_test_contract( &mut env, "test0".parse().unwrap(), - near_test_contracts::rs_contract(), + near_test_contracts::base_rs_contract(), epoch_length, 1, ); diff --git a/runtime/near-vm-runner/src/tests/rs_contract.rs b/runtime/near-vm-runner/src/tests/rs_contract.rs index cdcca8ac1e5..3bd337c190f 100644 --- a/runtime/near-vm-runner/src/tests/rs_contract.rs +++ b/runtime/near-vm-runner/src/tests/rs_contract.rs @@ -16,8 +16,13 @@ use crate::tests::{ }; use crate::vm_kind::VMKind; -fn test_contract() -> ContractCode { - let code = near_test_contracts::rs_contract(); +fn test_contract(vm_kind: VMKind) -> ContractCode { + let code = match vm_kind { + // testing backwards-compatibility, use an old WASM + VMKind::Wasmer0 | VMKind::Wasmer2 => near_test_contracts::base_rs_contract(), + // production and developer environment, use a cutting-edge WASM + VMKind::Wasmtime | VMKind::NearVm => near_test_contracts::rs_contract(), + }; ContractCode::new(code.to_vec(), None) } @@ -39,7 +44,7 @@ fn assert_run_result(result: VMResult, expected_value: u64) { pub fn test_read_write() { let config = VMConfig::test(); with_vm_variants(&config, |vm_kind: VMKind| { - let code = test_contract(); + let code = test_contract(vm_kind); let mut fake_external = MockedExternal::new(); let context = create_context(encode(&[10u64, 20u64])); @@ -112,7 +117,7 @@ fn run_test_ext( validators: Vec<(&str, Balance)>, vm_kind: VMKind, ) { - let code = test_contract(); + let code = test_contract(vm_kind); let mut fake_external = MockedExternal::new(); fake_external.validators = validators.into_iter().map(|(s, b)| (s.parse().unwrap(), b)).collect(); @@ -218,7 +223,7 @@ pub fn test_out_of_memory() { _ => {} } - let code = test_contract(); + let code = test_contract(vm_kind); let mut fake_external = MockedExternal::new(); let context = create_context(Vec::new());