Skip to content

Commit

Permalink
Fixed test and updated changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmus-kirk committed Oct 16, 2024
1 parent 83aea04 commit b4d6213
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
9 changes: 9 additions & 0 deletions concordium-std/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
- `set_slot_time`
- `set_receive_self_address`
- `set_receive_self_balance`
- `set_parameter`

- Added a more user-friendly interface `TestEnv` that allows users to build
a test host environment using method chaining and proper types. It supports
the following operations:
- `set_slot_time`
- `set_receive_balance`
- `set_receive_self_address`
- `set_parameter`

## concordium-std 10.1.0 (2024-04-04)

Expand Down
21 changes: 15 additions & 6 deletions concordium-std/src/test_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,29 @@ mod wasm_test {

#[concordium_test]
fn set_get_parameter() {
let i = 1;
let param = vec![3u8; 7];

TestEnv.set_parameter(0, &param);

let mut buf = vec![0u8; 10];
let bytes_read = external_call_response().read(&mut stored).unwrap();

let param_size = unsafe { prims::get_parameter_size(0) };
let bytes_written = unsafe { prims::get_parameter_section(0, buf.as_mut_ptr(), 5, 2) };
TestEnv.set_parameter(i, &param);

// Use the prims call to test length and offset
let param_size = unsafe { prims::get_parameter_size(i) };
let bytes_written = unsafe { prims::get_parameter_section(i, buf.as_mut_ptr(), 5, 2) };
let expected = vec![0, 0, 3, 3, 3, 3, 3, 0, 0, 0];

claim_eq!(param_size, 7);
claim_eq!(bytes_written, 5);
claim_eq!(buf, expected);

// Use the external call to test the actual function that would be called in
// most real scenarios
buf = vec![0u8; 7];
let bytes_written =
external_call_response().read(&mut buf).expect("Unable to read bytes to buffer");
let expected = param;

claim_eq!(buf, expected);
claim_eq!(bytes_written, 7);
}
}

0 comments on commit b4d6213

Please sign in to comment.