Skip to content

Commit 7c5b74d

Browse files
jakmeierNikolay Kurtov
authored andcommitted
test: use backwards_compatible_rs_contract where appropriate (#9175)
`rs_contract` can be used by tests that run only on the latest protocol version, as defined by the const PROTOCOL_VERSION. `backwards_compatible_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)
1 parent 4b95f2c commit 7c5b74d

File tree

12 files changed

+26
-19
lines changed

12 files changed

+26
-19
lines changed

integration-tests/src/tests/client/features/chunk_nodes_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn compare_node_counts() {
101101
deploy_test_contract(
102102
&mut env,
103103
"test0".parse().unwrap(),
104-
near_test_contracts::base_rs_contract(),
104+
near_test_contracts::backwards_compatible_rs_contract(),
105105
num_blocks,
106106
1,
107107
);

integration-tests/src/tests/client/features/flat_storage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn test_flat_storage_upgrade() {
4646
deploy_test_contract_with_protocol_version(
4747
&mut env,
4848
"test0".parse().unwrap(),
49-
near_test_contracts::base_rs_contract(),
49+
near_test_contracts::backwards_compatible_rs_contract(),
5050
blocks_to_process_txn,
5151
1,
5252
old_protocol_version,

integration-tests/src/tests/client/features/increase_storage_compute_cost.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ fn assert_compute_limit_reached(
207207
// setup: deploy the contract
208208
{
209209
// This contract has a bunch of methods to invoke storage operations.
210-
let code = near_test_contracts::rs_contract().to_vec();
210+
let code = near_test_contracts::backwards_compatible_rs_contract().to_vec();
211211
let actions = vec![Action::DeployContract(DeployContractAction { code })];
212212

213213
let signer = InMemorySigner::from_seed(

integration-tests/src/tests/client/features/lower_storage_key_limit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn protocol_upgrade() {
5656
deploy_test_contract_with_protocol_version(
5757
&mut env,
5858
"test0".parse().unwrap(),
59-
near_test_contracts::base_rs_contract(),
59+
near_test_contracts::backwards_compatible_rs_contract(),
6060
epoch_length,
6161
1,
6262
old_protocol_version,

integration-tests/src/tests/client/features/nearvm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn test_nearvm_upgrade() {
3737
deploy_test_contract(
3838
&mut env,
3939
"test0".parse().unwrap(),
40-
near_test_contracts::rs_contract(),
40+
near_test_contracts::backwards_compatible_rs_contract(),
4141
epoch_length,
4242
1,
4343
);

integration-tests/src/tests/client/process_blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ pub(crate) fn prepare_env_with_congestion(
199199
"test0".parse().unwrap(),
200200
&signer,
201201
vec![Action::DeployContract(DeployContractAction {
202-
code: near_test_contracts::base_rs_contract().to_vec(),
202+
code: near_test_contracts::backwards_compatible_rs_contract().to_vec(),
203203
})],
204204
*genesis_block.hash(),
205205
);

integration-tests/src/tests/client/sharding_upgrade.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ fn setup_test_env_with_cross_contract_txs(
639639
account_id.clone(),
640640
&signer,
641641
vec![Action::DeployContract(DeployContractAction {
642-
code: near_test_contracts::base_rs_contract().to_vec(),
642+
code: near_test_contracts::backwards_compatible_rs_contract().to_vec(),
643643
})],
644644
genesis_hash,
645645
)

pytest/lib/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def load_binary_file(filepath):
232232

233233

234234
def load_test_contract(
235-
filename: str = 'base_test_contract_rs.wasm') -> bytearray:
235+
filename: str = 'backwards_compatible_rs_contract.wasm') -> bytearray:
236236
"""Loads a WASM file from near-test-contracts package.
237237
238238
This is just a convenience function around load_binary_file which loads

runtime/near-test-contracts/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn sized_contract(size: usize) -> Vec<u8> {
4545
///
4646
/// Note: the contract relies on the latest stable protocol version, and might
4747
/// not work for tests using an older version. In particular, if a test depends
48-
/// on a specific protocol version, it should use [`base_rs_contract`].
48+
/// on a specific protocol version, it should use [`backwards_compatible_rs_contract`].
4949
pub fn rs_contract() -> &'static [u8] {
5050
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/res/", "test_contract_rs.wasm"))
5151
}
@@ -65,9 +65,9 @@ pub fn rs_contract() -> &'static [u8] {
6565
/// enabled. So we have to build it with Rustc <= 1.69. If we need to update the
6666
/// contracts content, we can build it manually with an older compiler and check
6767
/// in the new WASM.
68-
pub fn base_rs_contract() -> &'static [u8] {
68+
pub fn backwards_compatible_rs_contract() -> &'static [u8] {
6969
static CONTRACT: OnceCell<Vec<u8>> = OnceCell::new();
70-
CONTRACT.get_or_init(|| read_contract("base_test_contract_rs.wasm")).as_slice()
70+
CONTRACT.get_or_init(|| read_contract("backwards_compatible_rs_contract.wasm")).as_slice()
7171
}
7272

7373
/// Standard test contract which additionally includes all host functions from
@@ -154,7 +154,7 @@ fn smoke_test() {
154154
assert!(!ts_contract().is_empty());
155155
assert!(!trivial_contract().is_empty());
156156
assert!(!fuzzing_contract().is_empty());
157-
assert!(!base_rs_contract().is_empty());
157+
assert!(!backwards_compatible_rs_contract().is_empty());
158158
assert!(!ft_contract().is_empty());
159159
}
160160

@@ -238,7 +238,7 @@ pub fn arbitrary_contract(seed: u64) -> Vec<u8> {
238238
config.exceptions_enabled = false;
239239
config.saturating_float_to_int_enabled = false;
240240
config.sign_extension_enabled = false;
241-
config.available_imports = Some(base_rs_contract().to_vec());
241+
config.available_imports = Some(backwards_compatible_rs_contract().to_vec());
242242
let module = wasm_smith::Module::new(config, &mut arbitrary).expect("generate module");
243243
module.to_bytes()
244244
}

runtime/near-vm-runner/src/tests/rs_contract.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@ use crate::tests::{
1616
};
1717
use crate::vm_kind::VMKind;
1818

19-
fn test_contract() -> ContractCode {
20-
let code = near_test_contracts::rs_contract();
19+
fn test_contract(vm_kind: VMKind) -> ContractCode {
20+
let code = match vm_kind {
21+
// testing backwards-compatibility, use an old WASM
22+
VMKind::Wasmer0 | VMKind::Wasmer2 => {
23+
near_test_contracts::backwards_compatible_rs_contract()
24+
}
25+
// production and developer environment, use a cutting-edge WASM
26+
VMKind::Wasmtime | VMKind::NearVm => near_test_contracts::rs_contract(),
27+
};
2128
ContractCode::new(code.to_vec(), None)
2229
}
2330

@@ -39,7 +46,7 @@ fn assert_run_result(result: VMResult, expected_value: u64) {
3946
pub fn test_read_write() {
4047
let config = VMConfig::test();
4148
with_vm_variants(&config, |vm_kind: VMKind| {
42-
let code = test_contract();
49+
let code = test_contract(vm_kind);
4350
let mut fake_external = MockedExternal::new();
4451

4552
let context = create_context(encode(&[10u64, 20u64]));
@@ -112,7 +119,7 @@ fn run_test_ext(
112119
validators: Vec<(&str, Balance)>,
113120
vm_kind: VMKind,
114121
) {
115-
let code = test_contract();
122+
let code = test_contract(vm_kind);
116123
let mut fake_external = MockedExternal::new();
117124
fake_external.validators =
118125
validators.into_iter().map(|(s, b)| (s.parse().unwrap(), b)).collect();
@@ -218,7 +225,7 @@ pub fn test_out_of_memory() {
218225
_ => {}
219226
}
220227

221-
let code = test_contract();
228+
let code = test_contract(vm_kind);
222229
let mut fake_external = MockedExternal::new();
223230

224231
let context = create_context(Vec::new());

tools/state-viewer/src/state_dump.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ mod test {
449449
"test0".parse().unwrap(),
450450
&signer0,
451451
vec![Action::DeployContract(DeployContractAction {
452-
code: near_test_contracts::base_rs_contract().to_vec(),
452+
code: near_test_contracts::backwards_compatible_rs_contract().to_vec(),
453453
})],
454454
genesis_hash,
455455
);

0 commit comments

Comments
 (0)