Skip to content

Commit

Permalink
test: fix non-determinisit tests (#6847)
Browse files Browse the repository at this point in the history
The test might pass or fail depending on whether you `cargo t` or `cargo
t -p integration-tests`.

The reason for that is that `preserve_order` feature of serde_json
differs depending on which cargo command you invoke. That in turn leads
to different input to the contract.

There's two ways we can fix this:

* enableing preserve_order feature for integration tests crate
* formatting the JSON manually

I went with the second option as it seems simpler and more robust.
  • Loading branch information
matklad authored May 20, 2022
1 parent c84daa1 commit 010b32f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
21 changes: 14 additions & 7 deletions integration-tests/src/tests/runtime/sanity_checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,26 @@ fn test_cost_sanity() {
near_test_contracts::rs_contract()
};
let node = setup_runtime_node_with_contract(test_contract);
let data = serde_json::json!({
"contract_code": to_base64(near_test_contracts::trivial_contract()),
"method_name": "main",
"method_args": to_base64(&[]),
"validator_id": bob_account().as_str(),
});

let args = format!(
r#"{{
"contract_code": {:?},
"method_name": "main",
"method_args": "",
"validator_id": {:?}
}}"#,
to_base64(near_test_contracts::trivial_contract()),
bob_account().as_str()
);
eprintln!("{args}");

let res = node
.user()
.function_call(
alice_account(),
test_contract_account(),
"sanity_check",
serde_json::to_vec(&data).unwrap(),
args.into_bytes(),
MAX_GAS,
0,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: integration-tests/src/tests/runtime/sanity_checks.rs
expression: receipts_gas_profile

---
[
[
Expand Down Expand Up @@ -113,7 +112,7 @@ expression: receipts_gas_profile
CostGasUsed {
cost_category: "WASM_HOST_COST",
cost: "READ_REGISTER_BYTE",
gas_used: 18628218,
gas_used: 25034748,
},
CostGasUsed {
cost_category: "WASM_HOST_COST",
Expand Down Expand Up @@ -233,7 +232,7 @@ expression: receipts_gas_profile
CostGasUsed {
cost_category: "WASM_HOST_COST",
cost: "WASM_INSTRUCTION",
gas_used: 24159407184,
gas_used: 27893896668,
},
CostGasUsed {
cost_category: "WASM_HOST_COST",
Expand All @@ -243,7 +242,7 @@ expression: receipts_gas_profile
CostGasUsed {
cost_category: "WASM_HOST_COST",
cost: "WRITE_MEMORY_BYTE",
gas_used: 689114316,
gas_used: 866159496,
},
CostGasUsed {
cost_category: "WASM_HOST_COST",
Expand All @@ -253,7 +252,7 @@ expression: receipts_gas_profile
CostGasUsed {
cost_category: "WASM_HOST_COST",
cost: "WRITE_REGISTER_BYTE",
gas_used: 1170881712,
gas_used: 1417983372,
},
],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ expression: receipts_gas_profile
CostGasUsed {
cost_category: "WASM_HOST_COST",
cost: "READ_REGISTER_BYTE",
gas_used: 18628218,
gas_used: 25034748,
},
CostGasUsed {
cost_category: "WASM_HOST_COST",
Expand Down Expand Up @@ -262,7 +262,7 @@ expression: receipts_gas_profile
CostGasUsed {
cost_category: "WASM_HOST_COST",
cost: "WASM_INSTRUCTION",
gas_used: 24286111608,
gas_used: 28020601092,
},
CostGasUsed {
cost_category: "WASM_HOST_COST",
Expand All @@ -272,7 +272,7 @@ expression: receipts_gas_profile
CostGasUsed {
cost_category: "WASM_HOST_COST",
cost: "WRITE_MEMORY_BYTE",
gas_used: 689114316,
gas_used: 866159496,
},
CostGasUsed {
cost_category: "WASM_HOST_COST",
Expand All @@ -282,7 +282,7 @@ expression: receipts_gas_profile
CostGasUsed {
cost_category: "WASM_HOST_COST",
cost: "WRITE_REGISTER_BYTE",
gas_used: 1657481904,
gas_used: 1904583564,
},
],
[
Expand Down

0 comments on commit 010b32f

Please sign in to comment.