Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: cleanup feature handling in test contract #6620

Merged
merged 1 commit into from
Apr 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions integration-tests/src/tests/client/process_blocks.rs
Original file line number Diff line number Diff line change
@@ -182,7 +182,7 @@ fn prepare_env_with_congestion(
"test0".parse().unwrap(),
&signer,
vec![Action::DeployContract(DeployContractAction {
code: near_test_contracts::rs_contract_base_protocol().to_vec(),
code: near_test_contracts::base_rs_contract().to_vec(),
})],
*genesis_block.hash(),
);
@@ -4730,7 +4730,7 @@ mod chunk_nodes_cache_test {
deploy_test_contract(
&mut env,
"test0".parse().unwrap(),
near_test_contracts::rs_contract(),
near_test_contracts::base_rs_contract(),
num_blocks,
1,
);
2 changes: 1 addition & 1 deletion integration-tests/src/tests/client/sharding_upgrade.rs
Original file line number Diff line number Diff line change
@@ -551,7 +551,7 @@ fn setup_test_env_with_cross_contract_txs(
account_id.clone(),
&signer,
vec![Action::DeployContract(DeployContractAction {
code: near_test_contracts::rs_contract().to_vec(),
code: near_test_contracts::base_rs_contract().to_vec(),
})],
genesis_hash,
)
3 changes: 2 additions & 1 deletion pytest/lib/utils.py
Original file line number Diff line number Diff line change
@@ -171,7 +171,8 @@ def load_binary_file(filepath):
return bytearray(binaryfile.read())


def load_test_contract(filename: str = 'test_contract_rs.wasm') -> bytearray:
def load_test_contract(
filename: str = 'base_test_contract_rs.wasm') -> bytearray:
"""Loads a WASM file from near-test-contracts package.

This is just a convenience function around load_binary_file which loads
15 changes: 3 additions & 12 deletions runtime/near-test-contracts/build.rs
Original file line number Diff line number Diff line change
@@ -13,23 +13,14 @@ fn main() {
}

fn try_main() -> Result<(), Error> {
build_contract("./test-contract-rs", &[], "test_contract_rs")?;
build_contract("./test-contract-rs", &["--features", "latest_protocol"], "test_contract_rs")?;
build_contract("./test-contract-rs", &[], "base_test_contract_rs")?;
build_contract(
"./test-contract-rs",
&["--features", "nightly_protocol_features"],
&["--features", "latest_protocol,nightly_protocol_features"],
"nightly_test_contract_rs",
)?;
build_contract("./contract-for-fuzzing-rs", &[], "contract_for_fuzzing_rs")?;
build_contract(
"./test-contract-rs",
&["--features", "base_protocol"],
"test_contract_rs_base_protocol",
)?;
build_contract(
"./test-contract-rs",
&["--features", "protocol_feature_function_call_weight"],
"test_contract_rs_function_call_weight",
)?;
Ok(())
}

13 changes: 5 additions & 8 deletions runtime/near-test-contracts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -36,16 +36,13 @@ pub fn rs_contract() -> &'static [u8] {
CONTRACT.get_or_init(|| read_contract("test_contract_rs.wasm")).as_slice()
}

pub fn rs_contract_base_protocol() -> &'static [u8] {
/// Standard test contract which is compatible with the oldest protocol version.
pub fn base_rs_contract() -> &'static [u8] {
static CONTRACT: OnceCell<Vec<u8>> = OnceCell::new();
CONTRACT.get_or_init(|| read_contract("test_contract_rs_base_protocol.wasm")).as_slice()
}

pub fn function_call_weight_rs_contract() -> &'static [u8] {
static CONTRACT: OnceCell<Vec<u8>> = OnceCell::new();
CONTRACT.get_or_init(|| read_contract("test_contract_rs_function_call_weight.wasm")).as_slice()
CONTRACT.get_or_init(|| read_contract("base_test_contract_rs.wasm")).as_slice()
}

/// Standard test contract with all latest and nightly protocol features.
pub fn nightly_rs_contract() -> &'static [u8] {
static CONTRACT: OnceCell<Vec<u8>> = OnceCell::new();
CONTRACT.get_or_init(|| read_contract("nightly_test_contract_rs.wasm")).as_slice()
@@ -78,7 +75,7 @@ fn smoke_test() {
assert!(!ts_contract().is_empty());
assert!(!trivial_contract().is_empty());
assert!(!fuzzing_contract().is_empty());
assert!(!rs_contract_base_protocol().is_empty());
assert!(!base_rs_contract().is_empty());
}

pub fn many_functions_contract(function_count: u32) -> Vec<u8> {
2 changes: 1 addition & 1 deletion runtime/near-test-contracts/test-contract-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -33,4 +33,4 @@ members = []
nightly_protocol_features = ["protocol_feature_alt_bn128"]
protocol_feature_alt_bn128 = []
protocol_feature_function_call_weight = []
base_protocol = []
latest_protocol = []
10 changes: 5 additions & 5 deletions runtime/near-test-contracts/test-contract-rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@ extern "C" {
amount_ptr: u64,
gas: u64,
);
#[cfg(feature = "protocol_feature_function_call_weight")]
#[cfg(feature = "latest_protocol")]
fn promise_batch_action_function_call_weight(
promise_index: u64,
method_name_len: u64,
@@ -161,7 +161,7 @@ extern "C" {
// ###################
// # Math Extensions #
// ###################
#[cfg(not(feature = "base_protocol"))]
#[cfg(feature = "latest_protocol")]
fn ripemd160(value_len: u64, value_ptr: u64, register_id: u64);
// #################
// # alt_bn128 API #
@@ -783,7 +783,7 @@ fn call_promise() {
}
}

#[cfg(feature = "protocol_feature_function_call_weight")]
#[cfg(feature = "latest_protocol")]
#[no_mangle]
fn attach_unspent_gas_but_burn_all_gas() {
unsafe {
@@ -812,7 +812,7 @@ fn attach_unspent_gas_but_burn_all_gas() {
}
}

#[cfg(feature = "protocol_feature_function_call_weight")]
#[cfg(feature = "latest_protocol")]
#[no_mangle]
fn attach_unspent_gas_but_use_all_gas() {
unsafe {
@@ -853,7 +853,7 @@ fn attach_unspent_gas_but_use_all_gas() {
}
}

#[cfg(not(feature = "base_protocol"))]
#[cfg(feature = "latest_protocol")]
#[no_mangle]
fn do_ripemd() {
let data = b"tesdsst";
2 changes: 1 addition & 1 deletion runtime/near-vm-runner/src/tests/rs_contract.rs
Original file line number Diff line number Diff line change
@@ -294,7 +294,7 @@ pub fn test_out_of_memory() {
}

fn function_call_weight_contract() -> ContractCode {
ContractCode::new(near_test_contracts::function_call_weight_rs_contract().to_vec(), None)
ContractCode::new(near_test_contracts::rs_contract().to_vec(), None)
}

#[test]