diff --git a/integration-tests/src/tests/client/features/chunk_nodes_cache.rs b/integration-tests/src/tests/client/features/chunk_nodes_cache.rs index 6b664914c59..7e32e167a98 100644 --- a/integration-tests/src/tests/client/features/chunk_nodes_cache.rs +++ b/integration-tests/src/tests/client/features/chunk_nodes_cache.rs @@ -101,7 +101,7 @@ fn compare_node_counts() { deploy_test_contract( &mut env, "test0".parse().unwrap(), - near_test_contracts::base_rs_contract(), + near_test_contracts::backwards_compatible_rs_contract(), num_blocks, 1, ); diff --git a/integration-tests/src/tests/client/features/flat_storage.rs b/integration-tests/src/tests/client/features/flat_storage.rs index 3bd74d5f9e4..8739218c393 100644 --- a/integration-tests/src/tests/client/features/flat_storage.rs +++ b/integration-tests/src/tests/client/features/flat_storage.rs @@ -46,7 +46,7 @@ fn test_flat_storage_upgrade() { deploy_test_contract_with_protocol_version( &mut env, "test0".parse().unwrap(), - near_test_contracts::base_rs_contract(), + near_test_contracts::backwards_compatible_rs_contract(), blocks_to_process_txn, 1, old_protocol_version, 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..4cf6fbb4d89 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::backwards_compatible_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/lower_storage_key_limit.rs b/integration-tests/src/tests/client/features/lower_storage_key_limit.rs index 2c817b4edea..c69507d6301 100644 --- a/integration-tests/src/tests/client/features/lower_storage_key_limit.rs +++ b/integration-tests/src/tests/client/features/lower_storage_key_limit.rs @@ -56,7 +56,7 @@ fn protocol_upgrade() { deploy_test_contract_with_protocol_version( &mut env, "test0".parse().unwrap(), - near_test_contracts::base_rs_contract(), + near_test_contracts::backwards_compatible_rs_contract(), epoch_length, 1, old_protocol_version, diff --git a/integration-tests/src/tests/client/features/nearvm.rs b/integration-tests/src/tests/client/features/nearvm.rs index 8d2e2c53386..ab9fd3d7d89 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::backwards_compatible_rs_contract(), epoch_length, 1, ); diff --git a/integration-tests/src/tests/client/process_blocks.rs b/integration-tests/src/tests/client/process_blocks.rs index 504ad7f55cf..103fb8eb0ff 100644 --- a/integration-tests/src/tests/client/process_blocks.rs +++ b/integration-tests/src/tests/client/process_blocks.rs @@ -199,7 +199,7 @@ pub(crate) fn prepare_env_with_congestion( "test0".parse().unwrap(), &signer, vec![Action::DeployContract(DeployContractAction { - code: near_test_contracts::base_rs_contract().to_vec(), + code: near_test_contracts::backwards_compatible_rs_contract().to_vec(), })], *genesis_block.hash(), ); diff --git a/integration-tests/src/tests/client/sharding_upgrade.rs b/integration-tests/src/tests/client/sharding_upgrade.rs index 339d233ba58..7e9ba79ce7d 100644 --- a/integration-tests/src/tests/client/sharding_upgrade.rs +++ b/integration-tests/src/tests/client/sharding_upgrade.rs @@ -639,7 +639,7 @@ fn setup_test_env_with_cross_contract_txs( account_id.clone(), &signer, vec![Action::DeployContract(DeployContractAction { - code: near_test_contracts::base_rs_contract().to_vec(), + code: near_test_contracts::backwards_compatible_rs_contract().to_vec(), })], genesis_hash, ) diff --git a/pytest/lib/utils.py b/pytest/lib/utils.py index 8e6e1fcff70..3c087a2791c 100644 --- a/pytest/lib/utils.py +++ b/pytest/lib/utils.py @@ -232,7 +232,7 @@ def load_binary_file(filepath): def load_test_contract( - filename: str = 'base_test_contract_rs.wasm') -> bytearray: + filename: str = 'backwards_compatible_rs_contract.wasm') -> bytearray: """Loads a WASM file from near-test-contracts package. This is just a convenience function around load_binary_file which loads diff --git a/runtime/near-test-contracts/res/base_test_contract_rs.wasm b/runtime/near-test-contracts/res/backwards_compatible_rs_contract.wasm similarity index 100% rename from runtime/near-test-contracts/res/base_test_contract_rs.wasm rename to runtime/near-test-contracts/res/backwards_compatible_rs_contract.wasm diff --git a/runtime/near-test-contracts/src/lib.rs b/runtime/near-test-contracts/src/lib.rs index 668ccf64ec7..1d975e24787 100644 --- a/runtime/near-test-contracts/src/lib.rs +++ b/runtime/near-test-contracts/src/lib.rs @@ -45,7 +45,7 @@ pub fn sized_contract(size: usize) -> Vec { /// /// Note: the contract relies on the latest stable protocol version, and might /// not work for tests using an older version. In particular, if a test depends -/// on a specific protocol version, it should use [`base_rs_contract`]. +/// on a specific protocol version, it should use [`backwards_compatible_rs_contract`]. pub fn rs_contract() -> &'static [u8] { include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/res/", "test_contract_rs.wasm")) } @@ -65,9 +65,9 @@ pub fn rs_contract() -> &'static [u8] { /// enabled. So we have to build it with Rustc <= 1.69. If we need to update the /// contracts content, we can build it manually with an older compiler and check /// in the new WASM. -pub fn base_rs_contract() -> &'static [u8] { +pub fn backwards_compatible_rs_contract() -> &'static [u8] { static CONTRACT: OnceCell> = OnceCell::new(); - CONTRACT.get_or_init(|| read_contract("base_test_contract_rs.wasm")).as_slice() + CONTRACT.get_or_init(|| read_contract("backwards_compatible_rs_contract.wasm")).as_slice() } /// Standard test contract which additionally includes all host functions from @@ -154,7 +154,7 @@ fn smoke_test() { assert!(!ts_contract().is_empty()); assert!(!trivial_contract().is_empty()); assert!(!fuzzing_contract().is_empty()); - assert!(!base_rs_contract().is_empty()); + assert!(!backwards_compatible_rs_contract().is_empty()); assert!(!ft_contract().is_empty()); } @@ -238,7 +238,7 @@ pub fn arbitrary_contract(seed: u64) -> Vec { config.exceptions_enabled = false; config.saturating_float_to_int_enabled = false; config.sign_extension_enabled = false; - config.available_imports = Some(base_rs_contract().to_vec()); + config.available_imports = Some(backwards_compatible_rs_contract().to_vec()); let module = wasm_smith::Module::new(config, &mut arbitrary).expect("generate module"); module.to_bytes() } diff --git a/runtime/near-vm-runner/src/tests/rs_contract.rs b/runtime/near-vm-runner/src/tests/rs_contract.rs index cdcca8ac1e5..5eb03dc0e27 100644 --- a/runtime/near-vm-runner/src/tests/rs_contract.rs +++ b/runtime/near-vm-runner/src/tests/rs_contract.rs @@ -16,8 +16,15 @@ 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::backwards_compatible_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 +46,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 +119,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 +225,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()); diff --git a/tools/state-viewer/src/state_dump.rs b/tools/state-viewer/src/state_dump.rs index 9e216c770d4..de5c1fe3ac3 100644 --- a/tools/state-viewer/src/state_dump.rs +++ b/tools/state-viewer/src/state_dump.rs @@ -449,7 +449,7 @@ mod test { "test0".parse().unwrap(), &signer0, vec![Action::DeployContract(DeployContractAction { - code: near_test_contracts::base_rs_contract().to_vec(), + code: near_test_contracts::backwards_compatible_rs_contract().to_vec(), })], genesis_hash, );