Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: extend SharedMutable tests #6005

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,16 @@ mod test {

global TEST_DELAY = 20;

global pre = 13;
global post = 42;

#[test]
fn test_get_current_value_in_public_before_change() {
let (state_var, block_number) = setup(false);

let slot = state_var.get_derived_storage_slot();
let (pre, post) = (13, 17);

// Change in the future
// Change in the future, current value is pre
OracleMock::mock("storageRead").with_params((slot, 3)).returns([pre, post, block_number + 1]);
assert_eq(state_var.get_current_value_in_public(), pre);
}
Expand All @@ -146,9 +148,8 @@ mod test {
let (state_var, block_number) = setup(false);

let slot = state_var.get_derived_storage_slot();
let (pre, post) = (13, 17);

// Change in the current block
// Change in the current block, current value is post
OracleMock::mock("storageRead").with_params((slot, 3)).returns([pre, post, block_number]);
assert_eq(state_var.get_current_value_in_public(), post);
}
Expand All @@ -158,19 +159,50 @@ mod test {
let (state_var, block_number) = setup(false);

let slot = state_var.get_derived_storage_slot();
let (pre, post) = (13, 17);

// Change in the past
// Change in the past, current value is post
OracleMock::mock("storageRead").with_params((slot, 3)).returns([pre, post, block_number - 1]);
assert_eq(state_var.get_current_value_in_public(), post);
}

#[test]
fn test_get_scheduled_value_in_public_before_change() {
let (state_var, block_number) = setup(false);

let slot = state_var.get_derived_storage_slot();

// Change in the future, scheduled is post (always is)
OracleMock::mock("storageRead").with_params((slot, 3)).returns([pre, post, block_number + 1]);
assert_eq(state_var.get_scheduled_value_in_public(), (post, (block_number + 1) as u32));
}

#[test]
fn test_get_scheduled_value_in_public_at_change() {
let (state_var, block_number) = setup(false);

let slot = state_var.get_derived_storage_slot();

// Change in the current block, scheduled is post (always is)
OracleMock::mock("storageRead").with_params((slot, 3)).returns([pre, post, block_number]);
assert_eq(state_var.get_scheduled_value_in_public(), (post, block_number as u32));
}

#[test]
fn test_get_scheduled_value_in_public_after_change() {
let (state_var, block_number) = setup(false);

let slot = state_var.get_derived_storage_slot();

// Change in the past, scheduled is post (always is)
OracleMock::mock("storageRead").with_params((slot, 3)).returns([pre, post, block_number - 1]);
assert_eq(state_var.get_scheduled_value_in_public(), (post, (block_number - 1) as u32));
}

#[test]
fn test_schedule_value_change_before_change() {
let (state_var, block_number) = setup(false);

let slot = state_var.get_derived_storage_slot();
let (pre, post) = (13, 17);

// Change in the future
OracleMock::mock("storageRead").with_params((slot, 3)).returns([pre, post, block_number + 1]);
Expand All @@ -189,7 +221,6 @@ mod test {
let (state_var, block_number) = setup(false);

let slot = state_var.get_derived_storage_slot();
let (pre, post) = (13, 17);

// Change in the current block
OracleMock::mock("storageRead").with_params((slot, 3)).returns([pre, post, block_number]);
Expand All @@ -208,7 +239,6 @@ mod test {
let (state_var, block_number) = setup(false);

let slot = state_var.get_derived_storage_slot();
let (pre, post) = (13, 17);

// Change in the past
OracleMock::mock("storageRead").with_params((slot, 3)).returns([pre, post, block_number - 1]);
Expand Down
Loading