Skip to content

Commit

Permalink
chore: use correct call type (#6064)
Browse files Browse the repository at this point in the history
This came up with working on #5472, I realized we were using broader
call types than needed in many cases so I changed them to be more
restrictive.
  • Loading branch information
nventuro authored May 3, 2024
1 parent acc8641 commit b3ae289
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract AppSubscription {

context.end_setup();

AppSubscription::at(context.this_address()).assert_not_expired(note.expiry_block_number).enqueue(&mut context);
AppSubscription::at(context.this_address()).assert_not_expired(note.expiry_block_number).static_enqueue(&mut context);

payload.execute_calls(&mut context, storage.target_address.read_private());
}
Expand Down Expand Up @@ -105,7 +105,7 @@ contract AppSubscription {
).call(&mut context);

// Assert that the given expiry_block_number < current_block_number + SUBSCRIPTION_DURATION_IN_BLOCKS.
AppSubscription::at(context.this_address()).assert_block_number(expiry_block_number).enqueue(&mut context);
AppSubscription::at(context.this_address()).assert_block_number(expiry_block_number).static_enqueue(&mut context);

let mut subscription_note = SubscriptionNote::new(subscriber_address, expiry_block_number, tx_count);
if (!is_initialized(subscriber_address)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ contract Crowdfunding {
#[aztec(private)]
fn donate(amount: u64) {
// 1) Check that the deadline has not passed
Crowdfunding::at(context.this_address())._check_deadline().enqueue(&mut context);
Crowdfunding::at(context.this_address())._check_deadline().static_enqueue(&mut context);
// docs:end:call-check-deadline

// docs:start:do-transfer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ contract DocsExample {
// and returns the response.
// Used to test that we can retrieve values through calls and
// correctly return them in the simulation
let mut leader = DocsExample::at(context.this_address()).get_shared_immutable_constrained_private().call(&mut context);
let mut leader = DocsExample::at(context.this_address()).get_shared_immutable_constrained_private().static_call(&mut context);
leader.points += 1;
leader
}
Expand All @@ -124,7 +124,7 @@ contract DocsExample {
// and returns the response.
// Used to test that we can retrieve values through calls and
// correctly return them in the simulation
let mut leader = DocsExample::at(context.this_address()).get_shared_immutable_constrained_public().call(&mut context);
let mut leader = DocsExample::at(context.this_address()).get_shared_immutable_constrained_public().static_call(&mut context);
leader.points += 1;
leader
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ contract Lending {
#[aztec(internal)]
fn _withdraw(owner: AztecAddress, recipient: AztecAddress, amount: Field) {
let asset = Lending::at(context.this_address()).update_accumulator().call(&mut context);
let price = PriceFeed::at(asset.oracle).get_price(0).call(&mut context).price;
let price = PriceFeed::at(asset.oracle).get_price(0).static_call(&mut context).price;

let coll_loc = storage.collateral.at(owner);
let collateral: Field = coll_loc.read();
Expand Down Expand Up @@ -197,7 +197,7 @@ contract Lending {
#[aztec(internal)]
fn _borrow(owner: AztecAddress, to: AztecAddress, amount: Field) {
let asset = Lending::at(context.this_address()).update_accumulator().call(&mut context);
let price = PriceFeed::at(asset.oracle).get_price(0).call(&mut context).price;
let price = PriceFeed::at(asset.oracle).get_price(0).static_call(&mut context).price;

// Fetch collateral and static_debt, compute health of current position
let collateral = U128::from_integer(storage.collateral.at(owner).read());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ contract Uniswap {
assert_current_call_valid_authwit_public(&mut context, sender);
}

let input_asset = TokenBridge::at(input_asset_bridge).get_token().call(&mut context);
let input_asset = TokenBridge::at(input_asset_bridge).get_token().static_call(&mut context);

// Transfer funds to this contract
Token::at(input_asset).transfer_public(
Expand All @@ -71,8 +71,8 @@ contract Uniswap {
Uniswap::at(context.this_address())._approve_bridge_and_exit_input_asset_to_L1(input_asset, input_asset_bridge, input_amount).call(&mut context);
// Create swap message and send to Outbox for Uniswap Portal
// this ensures the integrity of what the user originally intends to do on L1.
let input_asset_bridge_portal_address = TokenBridge::at(input_asset_bridge).get_portal_address_public().call(&mut context);
let output_asset_bridge_portal_address = TokenBridge::at(output_asset_bridge).get_portal_address_public().call(&mut context);
let input_asset_bridge_portal_address = TokenBridge::at(input_asset_bridge).get_portal_address_public().static_call(&mut context);
let output_asset_bridge_portal_address = TokenBridge::at(output_asset_bridge).get_portal_address_public().static_call(&mut context);
// ensure portal exists - else funds might be lost
assert(
!input_asset_bridge_portal_address.is_zero(), "L1 portal address of input_asset's bridge is 0"
Expand Down Expand Up @@ -114,7 +114,7 @@ contract Uniswap {
) {
// Assert that user provided token address is same as expected by token bridge.
// we can't directly use `input_asset_bridge.token` because that is a public method and public can't return data to private
Uniswap::at(context.this_address())._assert_token_is_same(input_asset, input_asset_bridge).enqueue(&mut context);
Uniswap::at(context.this_address())._assert_token_is_same(input_asset, input_asset_bridge).static_enqueue(&mut context);

// Transfer funds to this contract
Token::at(input_asset).unshield(
Expand All @@ -129,8 +129,8 @@ contract Uniswap {

// Create swap message and send to Outbox for Uniswap Portal
// this ensures the integrity of what the user originally intends to do on L1.
let input_asset_bridge_portal_address = TokenBridge::at(input_asset_bridge).get_portal_address().call(&mut context);
let output_asset_bridge_portal_address = TokenBridge::at(output_asset_bridge).get_portal_address().call(&mut context);
let input_asset_bridge_portal_address = TokenBridge::at(input_asset_bridge).get_portal_address().static_call(&mut context);
let output_asset_bridge_portal_address = TokenBridge::at(output_asset_bridge).get_portal_address().static_call(&mut context);
// ensure portal exists - else funds might be lost
assert(
!input_asset_bridge_portal_address.is_zero(), "L1 portal address of input_asset's bridge is 0"
Expand Down Expand Up @@ -220,7 +220,7 @@ contract Uniswap {
#[aztec(internal)]
fn _assert_token_is_same(token: AztecAddress, token_bridge: AztecAddress) {
assert(
token.eq(TokenBridge::at(token_bridge).get_token().call(&mut context)), "input_asset address is not the same as seen in the bridge contract"
token.eq(TokenBridge::at(token_bridge).get_token().static_call(&mut context)), "input_asset address is not the same as seen in the bridge contract"
);
}

Expand Down
6 changes: 3 additions & 3 deletions yarn-project/end-to-end/src/e2e_auth_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('e2e_auth_contract', () => {
it('authorized is not yet set, cannot use permission', async () => {
expect(await contract.methods.get_authorized().simulate()).toEqual(AztecAddress.ZERO);

await expect(contract.withWallet(authorized).methods.do_private_authorized_thing().send().wait()).rejects.toThrow(
await expect(contract.withWallet(authorized).methods.do_private_authorized_thing().prove()).rejects.toThrow(
'caller is not authorized',
);
});
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('e2e_auth_contract', () => {

expect(await contract.methods.get_scheduled_authorized().simulate()).toEqual(other.getAddress());

await expect(contract.withWallet(other).methods.do_private_authorized_thing().send().wait()).rejects.toThrow(
await expect(contract.withWallet(other).methods.do_private_authorized_thing().prove()).rejects.toThrow(
'caller is not authorized',
);

Expand All @@ -107,7 +107,7 @@ describe('e2e_auth_contract', () => {

expect(await contract.methods.get_authorized().simulate()).toEqual(other.getAddress());

await expect(contract.withWallet(authorized).methods.do_private_authorized_thing().send().wait()).rejects.toThrow(
await expect(contract.withWallet(authorized).methods.do_private_authorized_thing().prove()).rejects.toThrow(
'caller is not authorized',
);

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_note_getter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe('e2e_note_getter', () => {
await expect(contract.methods.call_view_notes(storageSlot, activeOrNullified).simulate()).rejects.toThrow(
'is_some',
);
await expect(contract.methods.call_get_notes(storageSlot, activeOrNullified).send().wait()).rejects.toThrow(
await expect(contract.methods.call_get_notes(storageSlot, activeOrNullified).prove()).rejects.toThrow(
`Assertion failed: Cannot return zero notes`,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('e2e_pending_note_hashes_contract', () => {
)
.send()
.wait();
await expect(deployedContract.methods.get_note_zero_balance(owner).send().wait()).rejects.toThrow(
await expect(deployedContract.methods.get_note_zero_balance(owner).prove()).rejects.toThrow(
`Assertion failed: Cannot return zero notes`,
);

Expand Down Expand Up @@ -158,7 +158,7 @@ describe('e2e_pending_note_hashes_contract', () => {
)
.send()
.wait();
await expect(deployedContract.methods.get_note_zero_balance(owner).send().wait()).rejects.toThrow(
await expect(deployedContract.methods.get_note_zero_balance(owner).prove()).rejects.toThrow(
`Assertion failed: Cannot return zero notes`,
);

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/e2e_state_vars.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('e2e_state_vars', () => {
it('initializing SharedImmutable the second time should fail', async () => {
// Jest executes the tests sequentially and the first call to initialize_shared_immutable was executed
// in the previous test, so the call bellow should fail.
await expect(contract.methods.initialize_shared_immutable(1).send().wait()).rejects.toThrow(
await expect(contract.methods.initialize_shared_immutable(1).prove()).rejects.toThrow(
"Assertion failed: SharedImmutable already initialized 'fields_read[0] == 0'",
);
});
Expand All @@ -100,7 +100,7 @@ describe('e2e_state_vars', () => {
it('initializing PublicImmutable the second time should fail', async () => {
// Jest executes the tests sequentially and the first call to initialize_public_immutable was executed
// in the previous test, so the call bellow should fail.
await expect(contract.methods.initialize_public_immutable(1).send().wait()).rejects.toThrow(
await expect(contract.methods.initialize_public_immutable(1).prove()).rejects.toThrow(
"Assertion failed: PublicImmutable already initialized 'fields_read[0] == 0'",
);
});
Expand Down

0 comments on commit b3ae289

Please sign in to comment.