Skip to content

Commit d74c4a6

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

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

docs/docs/migration_notes.md

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ Aztec is in full-speed development. Literally every version breaks compatibility
88

99
## TBD
1010

11+
### [aztec-nr] `TestEnvironment::block_number()` removed and refactored
12+
13+
The `block_number` function from `TestEnvironment` is now two functions, the first being `pending_block_number`, and the second being `committed_block_number`. `pending_block_number` now returns what previously `block_number` did. In other words, it returns the block number of the block we are currently building. `committed_block_number` returns the block number of the last committed block, i.e. the block number that gets used to execute the private part of transactions when your PXE is successfully synced to the tip of the chain.
14+
15+
```diff
16+
- `TestEnvironment::block_number()`
17+
+ `TestEnvironment::pending_block_number()`
18+
+ `TestEnvironment::committed_block_number()`
19+
```
20+
1121
### [aztec-nr] `compute_nullifier_without_context` renamed
1222

1323
The `compute_nullifier_without_context` function from `NoteHash` (ex `NoteInterface`) is now called `compute_nullifier_unconstrained`, and instead of taking storage slot, contract address and nonce it takes a note hash for nullification (same as `compute_note_hash`). This makes writing this

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)