-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove redundant e2e tests and organize (#8561)
This is phase 1 of dealing with the e2e tests, where I am handling first the redundant tests. The next phase will start to port over non-redundant tests. For reference, the doc regarding the state of e2e tests are here: https://hackmd.io/QiOaGHBlS9W_A-ZCU6tpag?view A quick summary of changes: - Consolidate, organize, and remove redundant `cross_chain` tests into the multi-stage test - Remove `counter` e2e test - Port and remove `auth` e2e test --------- Co-authored-by: Nicolás Venturo <[email protected]>
- Loading branch information
Showing
19 changed files
with
268 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
noir-projects/noir-contracts/contracts/auth_contract/src/test.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod main; | ||
mod utils; |
123 changes: 123 additions & 0 deletions
123
noir-projects/noir-contracts/contracts/auth_contract/src/test/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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(); | ||
} |
18 changes: 18 additions & 0 deletions
18
noir-projects/noir-contracts/contracts/auth_contract/src/test/utils.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.