contracts: Remove wat support from test fixtures (#3588)

In order to prepare for PolkaVM support I removed the wat support from
our test fixture crate.

- Removed redundant tests (invalid module checks are already inside the
prepare module where they belong
- Converted the gas_sync tests to Rust
- Moved the start function test to the `wasm` module
This commit is contained in:
Alexander Theißen
2024-03-07 09:05:04 +08:00
committed by GitHub
parent 117a9433da
commit 4ae7398818
12 changed files with 49 additions and 283 deletions
+11 -156
View File
@@ -852,27 +852,6 @@ fn deposit_event_max_value_limit() {
});
}
// Fail out of fuel (ref_time weight) inside the start function.
#[test]
fn run_out_of_fuel_start_fun() {
let (wasm, _code_hash) = compile_module::<Test>("run_out_of_gas_start_fn").unwrap();
ExtBuilder::default().existential_deposit(50).build().execute_with(|| {
let _ = <Test as Config>::Currency::set_balance(&ALICE, 1_000_000);
assert_err_ignore_postinfo!(
Contracts::instantiate_with_code(
RuntimeOrigin::signed(ALICE),
0,
Weight::from_parts(1_000_000_000_000, u64::MAX),
None,
wasm,
vec![],
vec![],
),
Error::<Test>::OutOfGas,
);
});
}
// Fail out of fuel (ref_time weight) in the engine.
#[test]
fn run_out_of_fuel_engine() {
@@ -956,50 +935,15 @@ fn run_out_of_fuel_host() {
#[test]
fn gas_syncs_work() {
let (wasm0, _code_hash) = compile_module::<Test>("seal_input_noop").unwrap();
let (wasm1, _code_hash) = compile_module::<Test>("seal_input_once").unwrap();
let (wasm2, _code_hash) = compile_module::<Test>("seal_input_twice").unwrap();
let (code, _code_hash) = compile_module::<Test>("caller_is_origin_n").unwrap();
ExtBuilder::default().existential_deposit(200).build().execute_with(|| {
let _ = <Test as Config>::Currency::set_balance(&ALICE, 1_000_000);
// Instantiate noop contract.
let addr0 = Contracts::bare_instantiate(
let addr = Contracts::bare_instantiate(
ALICE,
0,
GAS_LIMIT,
None,
Code::Upload(wasm0),
vec![],
vec![],
DebugInfo::Skip,
CollectEvents::Skip,
)
.result
.unwrap()
.account_id;
// Instantiate 1st contract.
let addr1 = Contracts::bare_instantiate(
ALICE,
0,
GAS_LIMIT,
None,
Code::Upload(wasm1),
vec![],
vec![],
DebugInfo::Skip,
CollectEvents::Skip,
)
.result
.unwrap()
.account_id;
// Instantiate 2nd contract.
let addr2 = Contracts::bare_instantiate(
ALICE,
0,
GAS_LIMIT,
None,
Code::Upload(wasm2),
Code::Upload(code),
vec![],
vec![],
DebugInfo::Skip,
@@ -1011,11 +955,11 @@ fn gas_syncs_work() {
let result = Contracts::bare_call(
ALICE,
addr0,
addr.clone(),
0,
GAS_LIMIT,
None,
1u8.to_le_bytes().to_vec(),
0u32.encode(),
DebugInfo::Skip,
CollectEvents::Skip,
Determinism::Enforced,
@@ -1025,27 +969,28 @@ fn gas_syncs_work() {
let result = Contracts::bare_call(
ALICE,
addr1,
addr.clone(),
0,
GAS_LIMIT,
None,
1u8.to_le_bytes().to_vec(),
1u32.encode(),
DebugInfo::Skip,
CollectEvents::Skip,
Determinism::Enforced,
);
assert_ok!(result.result);
let gas_consumed_once = result.gas_consumed.ref_time();
let host_consumed_once = <Test as Config>::Schedule::get().host_fn_weights.input.ref_time();
let host_consumed_once =
<Test as Config>::Schedule::get().host_fn_weights.caller_is_origin.ref_time();
let engine_consumed_once = gas_consumed_once - host_consumed_once - engine_consumed_noop;
let result = Contracts::bare_call(
ALICE,
addr2,
addr,
0,
GAS_LIMIT,
None,
1u8.to_le_bytes().to_vec(),
2u32.encode(),
DebugInfo::Skip,
CollectEvents::Skip,
Determinism::Enforced,
@@ -4453,96 +4398,6 @@ fn contract_reverted() {
});
}
#[test]
fn code_rejected_error_works() {
ExtBuilder::default().existential_deposit(200).build().execute_with(|| {
let _ = <Test as Config>::Currency::set_balance(&ALICE, 1_000_000);
let (wasm, _) = compile_module::<Test>("invalid_module").unwrap();
assert_noop!(
Contracts::upload_code(
RuntimeOrigin::signed(ALICE),
wasm.clone(),
None,
Determinism::Enforced
),
<Error<Test>>::CodeRejected,
);
let result = Contracts::bare_instantiate(
ALICE,
0,
GAS_LIMIT,
None,
Code::Upload(wasm),
vec![],
vec![],
DebugInfo::UnsafeDebug,
CollectEvents::Skip,
);
assert_err!(result.result, <Error<Test>>::CodeRejected);
assert_eq!(
std::str::from_utf8(&result.debug_message).unwrap(),
"Can't load the module into wasmi!"
);
let (wasm, _) = compile_module::<Test>("invalid_contract_no_call").unwrap();
assert_noop!(
Contracts::upload_code(
RuntimeOrigin::signed(ALICE),
wasm.clone(),
None,
Determinism::Enforced
),
<Error<Test>>::CodeRejected,
);
let result = Contracts::bare_instantiate(
ALICE,
0,
GAS_LIMIT,
None,
Code::Upload(wasm),
vec![],
vec![],
DebugInfo::UnsafeDebug,
CollectEvents::Skip,
);
assert_err!(result.result, <Error<Test>>::CodeRejected);
assert_eq!(
std::str::from_utf8(&result.debug_message).unwrap(),
"call function isn't exported"
);
let (wasm, _) = compile_module::<Test>("invalid_contract_no_memory").unwrap();
assert_noop!(
Contracts::upload_code(
RuntimeOrigin::signed(ALICE),
wasm.clone(),
None,
Determinism::Enforced
),
<Error<Test>>::CodeRejected,
);
let result = Contracts::bare_instantiate(
ALICE,
0,
GAS_LIMIT,
None,
Code::Upload(wasm),
vec![],
vec![],
DebugInfo::UnsafeDebug,
CollectEvents::Skip,
);
assert_err!(result.result, <Error<Test>>::CodeRejected);
assert_eq!(
std::str::from_utf8(&result.debug_message).unwrap(),
"No memory import found in the module"
);
});
}
#[test]
fn set_code_hash() {
let (wasm, code_hash) = compile_module::<Test>("set_code_hash").unwrap();