-
Notifications
You must be signed in to change notification settings - Fork 296
/
execute_subnet_message_update_settings.rs
64 lines (58 loc) · 2.25 KB
/
execute_subnet_message_update_settings.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#![no_main]
use ic_ic00_types::{Method, Payload, UpdateSettingsArgs};
use ic_test_utilities_execution_environment::ExecutionTestBuilder;
use libfuzzer_sys::{fuzz_target, Corpus};
// This fuzz tries to execute the UpdateSettings management canister method
//
// The fuzz test is only compiled but not executed by CI.
//
// To execute the fuzzer run
// bazel run --config=fuzzing //rs/execution_environment/fuzz:execute_subnet_message_update_settings
fuzz_target!(|args: UpdateSettingsArgs| -> Corpus {
let mut test = ExecutionTestBuilder::new()
.with_deterministic_time_slicing_disabled()
.with_canister_sandboxing_disabled()
.build();
let wat = r#"(module)"#;
let canister_id = test.canister_from_wat(wat).unwrap();
let mut update_settings_args = args;
update_settings_args.canister_id = canister_id.into();
match test.subnet_message(Method::UpdateSettings, update_settings_args.encode()) {
Ok(_) => {
let controllers = &test.canister_state(canister_id).system_state.controllers;
let compute_allocation = test
.canister_state(canister_id)
.scheduler_state
.compute_allocation
.as_percent();
let memory_allocation = test
.canister_state(canister_id)
.system_state
.memory_allocation
.bytes()
.get();
let freezing_threshold = test
.canister_state(canister_id)
.system_state
.freeze_threshold
.get();
for principal in update_settings_args.settings.controllers.unwrap().get() {
assert!(controllers.contains(principal));
}
assert_eq!(
compute_allocation,
update_settings_args.settings.compute_allocation.unwrap()
);
assert_eq!(
memory_allocation,
update_settings_args.settings.memory_allocation.unwrap()
);
assert_eq!(
freezing_threshold,
update_settings_args.settings.freezing_threshold.unwrap()
);
Corpus::Keep
}
Err(_err) => Corpus::Reject,
}
});