Skip to content

Commit 8966263

Browse files
author
sklppy88
committed
adding comments requested
1 parent 1b65c4a commit 8966263

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr

+21-3
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,43 @@ impl TestEnvironment {
2828
get_block_number()
2929
}
3030

31-
// Returns the block number of the last committed block - this is the block number that gets used in production
32-
// to execute the private part of transactions when your PXE managed to successfully sync to the tip of the chain.
31+
/// Returns the block number of the last committed block - this is the block number that gets used in production
32+
/// to execute the private part of transactions when your PXE managed to successfully sync to the tip of the chain.
3333
pub unconstrained fn committed_block_number(self: Self) -> u32 {
3434
self.pending_block_number() - 1
3535
}
3636

37+
/// With TXe tests, every test is run in a mock "contract". This facilitates the ability to write to and read from storage,
38+
/// emit and retrieve nullifiers (because they are hashed with a contract address), and formulate notes in a canonical way.
39+
/// The contract_address also represents the "msg_sender" when we call a contract with a private or public context; and when
40+
/// we call top-level unconstrained functions, we must set this contract address to the contract being called.
41+
/// The contract address can be manipulated to do the above at any particular address, and not simply the one provided at
42+
/// the instantiation of the test.
43+
/// Returns the currently set contract address.
3744
pub unconstrained fn contract_address(_self: Self) -> AztecAddress {
3845
get_contract_address()
3946
}
4047

48+
/// Modifies the currently set contract address. As per above, it sets the "msg_sender" address on our subsequent calls.
49+
/// This is useful when we have multiple "accounts" that need to interact with an arbitrary contract. This also allows
50+
/// us to change the "contract" we emit side effects from, and is required when we want to run a top-level unconstrained function on another contract.
4151
pub unconstrained fn impersonate(_self: Self, address: AztecAddress) {
4252
cheatcodes::set_contract_address(address)
4353
}
4454

55+
/// Advances the internal TXe state to specified block number.
56+
/// Note that this block number describes the block being built. i.e. If you advance the block to 5 from 1,
57+
/// the pending block number will be 5, and your last committed block number will be 4.
4558
pub unconstrained fn advance_block_to(&mut self, block_number: u32) {
46-
let difference = block_number - get_block_number();
59+
let pending_block_number = self.pending_block_number();
60+
assert(pending_block_number <= block_number, "Cannot advance block to a previous block.");
61+
62+
let difference = block_number - pending_block_number;
4763
self.advance_block_by(difference);
4864
}
4965

66+
/// Advances the internal TXe state by the amount of blocks specified. The TXe produces a valid block for every
67+
/// block advanced, and we are able to fetch historical data from warped over blocks.
5068
pub unconstrained fn advance_block_by(_self: &mut Self, blocks: u32) {
5169
cheatcodes::advance_blocks_by(blocks);
5270
}

0 commit comments

Comments
 (0)