-
Notifications
You must be signed in to change notification settings - Fork 298
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
refactor: remove redundant e2e tests and organize #8561
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod main; | ||
mod utils; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
use crate::test::utils; | ||
use crate::Auth; | ||
|
||
use dep::aztec::prelude::AztecAddress; | ||
|
||
global CHANGE_AUTHORIZED_DELAY_BLOCKS = 5; | ||
|
||
// TODO (#8588): These were ported over directly from e2e tests. Refactor these in the correct TXe style. | ||
#[test] | ||
unconstrained fn main() { | ||
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough | ||
let (env, auth_contract_address, admin, to_authorize, other) = utils::setup(); | ||
|
||
let authorized_is_unset_initially = || { | ||
env.impersonate(admin); | ||
let authorized = env.call_public(Auth::at(auth_contract_address).get_authorized()); | ||
assert_eq(authorized, AztecAddress::from_field(0)); | ||
}; | ||
authorized_is_unset_initially(); | ||
|
||
let non_admin_cannot_set_unauthorized = || { | ||
env.impersonate(other); | ||
env.assert_public_call_fails(Auth::at(auth_contract_address).set_authorized(to_authorize)); | ||
}; | ||
non_admin_cannot_set_unauthorized(); | ||
|
||
let admin_sets_authorized = || { | ||
env.impersonate(admin); | ||
env.call_public(Auth::at(auth_contract_address).set_authorized(to_authorize)); | ||
env.advance_block_by(1); | ||
|
||
let scheduled_authorized = env.call_public(Auth::at(auth_contract_address).get_scheduled_authorized()); | ||
assert_eq(scheduled_authorized, to_authorize); | ||
}; | ||
admin_sets_authorized(); | ||
|
||
let authorized_is_not_yet_effective = || { | ||
env.impersonate(to_authorize); | ||
let authorized: AztecAddress = env.call_public(Auth::at(auth_contract_address).get_authorized()); | ||
assert_eq(authorized, AztecAddress::zero()); | ||
|
||
env.assert_private_call_fails(Auth::at(auth_contract_address).do_private_authorized_thing()); | ||
}; | ||
authorized_is_not_yet_effective(); | ||
|
||
let authorized_becomes_effective_after_delay = || { | ||
env.impersonate(to_authorize); | ||
|
||
// We advance block by 4, because the delay is 5, and we initially advanced block by one after setting the value. See below comment for explanation. | ||
env.advance_block_by(CHANGE_AUTHORIZED_DELAY_BLOCKS - 1); | ||
let authorized: AztecAddress = env.call_public(Auth::at(auth_contract_address).get_authorized()); | ||
assert_eq(authorized, to_authorize); | ||
|
||
let authorized_in_private: AztecAddress = env.call_private(Auth::at(auth_contract_address).get_authorized_in_private()); | ||
assert_eq(authorized_in_private, AztecAddress::zero()); | ||
|
||
// We need to always advance the block one more time to get the current value in private, compared to the value in public. | ||
// To see why let's see this diagram. | ||
// When we schedule a change in public, lets say we are at block 2 (building a tx to be included in block 2), which means the latest committed block is block 1. | ||
// Thus, the value change will be set to block 7 (2 + 5). | ||
// If we now advance our env by 5 blocks, we will be at block 7 (building a tx to be included in block 7), which means the latest committed block is block 6. | ||
// Reading the value in public will work, because it will use the current block (7), and the current block is the block of change; but | ||
// if we try to create a historical proof, we do not have access to block 7 yet, and have to build the proof off of block 6, but at this time, the value change will not have | ||
// taken place yet, therefore we need to be at block 8 (building a tx to be included in block 8), for the historical proof to work, as it will have access to the full block 7 | ||
// where the value change takes effect. | ||
// Note: We do not see this behavior in the e2e tests because setting the value inplicitly advances the block number by 1. | ||
// 1 2 3 4 5 6 7 8 9 | ||
// | | | | | | | | | | ||
// ^ | ||
// value change scheduled here | ||
// ^ | ||
// get_authorized() (public) called here with block_number = 7 | ||
// ^ | ||
// get_authorized() (private) called here with block_number = 8 | ||
Comment on lines
+62
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a very good explanation, but it ultimately shows that the current API is flawed. Users should not have to be exposed to this level of detail for something as simple as this. We should at least have |
||
env.advance_block_by(1); | ||
let authorized_in_private_again: AztecAddress = env.call_private(Auth::at(auth_contract_address).get_authorized_in_private()); | ||
assert_eq(authorized_in_private_again, to_authorize); | ||
|
||
env.call_private_void(Auth::at(auth_contract_address).do_private_authorized_thing()); | ||
}; | ||
authorized_becomes_effective_after_delay(); | ||
|
||
let authorize_other = || { | ||
env.impersonate(admin); | ||
env.call_public(Auth::at(auth_contract_address).set_authorized(other)); | ||
env.advance_block_by(1); | ||
|
||
let scheduled_authorized = env.call_public(Auth::at(auth_contract_address).get_scheduled_authorized()); | ||
assert_eq(scheduled_authorized, other); | ||
|
||
let authorized: AztecAddress = env.call_public(Auth::at(auth_contract_address).get_authorized()); | ||
assert_eq(authorized, to_authorize); | ||
|
||
env.impersonate(to_authorize); | ||
env.call_private_void(Auth::at(auth_contract_address).do_private_authorized_thing()); | ||
|
||
env.impersonate(other); | ||
env.assert_private_call_fails(Auth::at(auth_contract_address).do_private_authorized_thing()); | ||
}; | ||
authorize_other(); | ||
|
||
let authorized_becomes_effective_after_delay_again = || { | ||
env.impersonate(to_authorize); | ||
|
||
// We advance the block by 4 again like above | ||
env.advance_block_by(CHANGE_AUTHORIZED_DELAY_BLOCKS - 1); | ||
let authorized: AztecAddress = env.call_public(Auth::at(auth_contract_address).get_authorized()); | ||
assert_eq(authorized, other); | ||
|
||
let authorized_in_private: AztecAddress = env.call_private(Auth::at(auth_contract_address).get_authorized_in_private()); | ||
assert_eq(authorized_in_private, to_authorize); | ||
|
||
env.advance_block_by(1); | ||
let authorized_in_private_again: AztecAddress = env.call_private(Auth::at(auth_contract_address).get_authorized_in_private()); | ||
assert_eq(authorized_in_private_again, other); | ||
|
||
env.assert_private_call_fails(Auth::at(auth_contract_address).do_private_authorized_thing()); | ||
|
||
env.impersonate(other); | ||
env.call_private_void(Auth::at(auth_contract_address).do_private_authorized_thing()); | ||
}; | ||
authorized_becomes_effective_after_delay_again(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use dep::aztec::{prelude::AztecAddress, test::helpers::test_environment::TestEnvironment}; | ||
|
||
use crate::Auth; | ||
|
||
pub fn setup() -> (&mut TestEnvironment, AztecAddress, AztecAddress, AztecAddress, AztecAddress) { | ||
let mut env = TestEnvironment::new(); | ||
|
||
let admin = env.create_account(); | ||
let to_authorize = env.create_account(); | ||
let other = env.create_account(); | ||
|
||
let initializer_call_interface = Auth::interface().constructor(admin); | ||
|
||
let auth_contract = env.deploy_self("Auth").with_public_initializer(initializer_call_interface); | ||
let auth_contract_address = auth_contract.to_address(); | ||
env.advance_block_by(1); | ||
(&mut env, auth_contract_address, admin, to_authorize, other) | ||
} |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a todo mentioning this was simply ported from the e2e flow - at some point we'd want to rewrite this in TXE-style and e.g. check the error strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah fair, added ! And I did it like this to avoid setup each time. It would be nice to also have
assert_fails_with_x
, I will look into improving this pattern in the next tests I port.