Skip to content

Commit

Permalink
improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Feb 5, 2025
1 parent 08ac0b3 commit 6f11f09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::{
context::{PrivateContext, PublicContext, UnconstrainedContext},
state_vars::shared_mutable::SharedMutable,
test::helpers::test_environment::TestEnvironment,
test::{helpers::test_environment::TestEnvironment, mocks::mock_struct::MockStruct},
};

use dep::std::mem::zeroed;

global new_value: Field = 17;
global new_value: MockStruct = MockStruct { a: 17, b: 42 };

global new_delay: u32 = 20;

Expand All @@ -20,20 +20,20 @@ unconstrained fn setup() -> TestEnvironment {

unconstrained fn in_public(
env: TestEnvironment,
) -> SharedMutable<Field, TEST_INITIAL_DELAY, &mut PublicContext> {
) -> SharedMutable<MockStruct, TEST_INITIAL_DELAY, &mut PublicContext> {
SharedMutable::new(&mut env.public(), storage_slot)
}

unconstrained fn in_private(
env: &mut TestEnvironment,
historical_block_number: u32,
) -> SharedMutable<Field, TEST_INITIAL_DELAY, &mut PrivateContext> {
) -> SharedMutable<MockStruct, TEST_INITIAL_DELAY, &mut PrivateContext> {
SharedMutable::new(&mut env.private_at(historical_block_number), storage_slot)
}

unconstrained fn in_unconstrained(
env: TestEnvironment,
) -> SharedMutable<Field, TEST_INITIAL_DELAY, UnconstrainedContext> {
) -> SharedMutable<MockStruct, TEST_INITIAL_DELAY, UnconstrainedContext> {
SharedMutable::new(env.unkonstrained(), storage_slot)
}

Expand Down Expand Up @@ -194,7 +194,7 @@ unconstrained fn test_get_current_value_in_private_before_change() {
let schedule_block_number = env.block_number();

let private_state_var = in_private(&mut env, schedule_block_number);
assert_eq(private_state_var.get_current_value(), 0);
assert_eq(private_state_var.get_current_value(), MockStruct::empty());
assert_eq(private_state_var.context.max_block_number.unwrap(), block_of_change - 1);
}

Expand All @@ -211,7 +211,7 @@ unconstrained fn test_get_current_value_in_private_immediately_before_change() {

// Note that this transaction would never be valid since the max block number is the same as the historical block
// used to built the proof, i.e. in the past.
assert_eq(private_state_var.get_current_value(), 0);
assert_eq(private_state_var.get_current_value(), MockStruct::empty());
assert_eq(private_state_var.context.max_block_number.unwrap(), block_of_change - 1);
}

Expand Down
8 changes: 7 additions & 1 deletion noir-projects/aztec-nr/aztec/src/test/mocks/mock_struct.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dep::protocol_types::traits::{Deserialize, Packable, Serialize};
use dep::protocol_types::traits::{Deserialize, Empty, Packable, Serialize};

pub struct MockStruct {
pub a: Field,
Expand All @@ -17,6 +17,12 @@ impl Eq for MockStruct {
}
}

impl Empty for MockStruct {
fn empty() -> Self {
Self { a: 0, b: 0 }
}
}

impl Serialize<2> for MockStruct {
fn serialize(self) -> [Field; 2] {
[self.a, self.b]
Expand Down

0 comments on commit 6f11f09

Please sign in to comment.