Skip to content

Commit

Permalink
test: use base_rs_contract where appropriate
Browse files Browse the repository at this point in the history
`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 near#9140)
  • Loading branch information
jakmeier committed Jun 12, 2023
1 parent 863f712 commit 6f78d72
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/tests/client/features/nearvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
15 changes: 10 additions & 5 deletions runtime/near-vm-runner/src/tests/rs_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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]));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 6f78d72

Please sign in to comment.