Skip to content

Commit

Permalink
Fix old ptr writes test
Browse files Browse the repository at this point in the history
  • Loading branch information
techraed committed Dec 20, 2023
1 parent ffef3f2 commit 18834ca
Showing 1 changed file with 40 additions and 44 deletions.
84 changes: 40 additions & 44 deletions utils/wasm-gen/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,50 +209,46 @@ fn injecting_addresses_works() {
assert_eq!(*ptr, size + (stack_end_page * WASM_PAGE_SIZE as u32) as i32);
}

// #[test]
// fn ptr_setters_work() {
// const INITIAL_VALUE: u128 = 10_000;
// const REPLY_VALUE: u128 = 1_000;

// let buf = vec![0; UNSTRUCTURED_SIZE];
// let mut unstructured = Unstructured::new(&buf);

// let params_config = SysCallsParamsConfig::default();
// let mut pointer_writes_config = PtrParamFillersConfig::empty();
// pointer_writes_config.set_rule(
// PtrType::Value,
// vec![PtrParamAllowedValuesExt {
// value_offset: 0,
// allowed_values: FillingPtrParamData::U128(REPLY_VALUE..=REPLY_VALUE),
// }],
// );

// let mut injection_types = SysCallsInjectionTypes::all_never();
// injection_types.set(InvocableSysCall::Loose(SysCallName::Reply), 1, 1);
// let sys_calls_config = SysCallsConfigBuilder::new(injection_types)
// .with_params_config(params_config)
// .with_pointer_writes_config(pointer_writes_config)
// .with_error_processing_config(ErrorProcessingConfig::All)
// .build();

// let backend_report = execute_wasm_with_custom_configs(
// &mut unstructured,
// sys_calls_config,
// None,
// 1,
// false,
// INITIAL_VALUE,
// );

// assert_eq!(
// backend_report.ext.context.value_counter.left(),
// INITIAL_VALUE - REPLY_VALUE
// );
// assert_eq!(
// backend_report.termination_reason,
// TerminationReason::Actor(ActorTerminationReason::Success)
// );
// }
// test for syscalls with destination
// test for syscalls with destination and existing addresses

// Syscalls of a `gr_*reply*` kind are the only of those, which has `Value` input param.
#[test]
fn test_msg_value_ptr() {
const INITIAL_BALANCE: u128 = 10_000;
const REPLY_VALUE: u128 = 1_000;

let buf = vec![0; UNSTRUCTURED_SIZE];
let mut unstructured = Unstructured::new(&buf);

let mut params_config = SyscallsParamsConfig::default_regular();
params_config.set_ptr_rule(PtrParamAllowedValues::Value(REPLY_VALUE..=REPLY_VALUE));

let mut injection_types = SyscallsInjectionTypes::all_never();
injection_types.set(InvocableSyscall::Loose(SyscallName::Reply), 1, 1);
let syscalls_config = SyscallsConfigBuilder::new(injection_types)
.with_params_config(params_config)
.with_error_processing_config(ErrorProcessingConfig::All)
.build();

let backend_report = execute_wasm_with_custom_configs(
&mut unstructured,
syscalls_config,
None,
1,
false,
INITIAL_BALANCE,
);

assert_eq!(
backend_report.ext.context.value_counter.left(),
INITIAL_BALANCE - REPLY_VALUE
);
assert_eq!(
backend_report.termination_reason,
TerminationReason::Actor(ActorTerminationReason::Success)
);
}

#[test]
fn error_processing_works_for_fallible_syscalls() {
Expand Down

0 comments on commit 18834ca

Please sign in to comment.