From b3ae289748954229aac7ae2e1fe72483ede79a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Fri, 3 May 2024 11:47:47 -0300 Subject: [PATCH] chore: use correct call type (#6064) 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. --- .../app_subscription_contract/src/main.nr | 4 ++-- .../contracts/crowdfunding_contract/src/main.nr | 2 +- .../contracts/docs_example_contract/src/main.nr | 4 ++-- .../contracts/lending_contract/src/main.nr | 4 ++-- .../contracts/uniswap_contract/src/main.nr | 14 +++++++------- .../end-to-end/src/e2e_auth_contract.test.ts | 6 +++--- .../end-to-end/src/e2e_note_getter.test.ts | 2 +- .../src/e2e_pending_note_hashes_contract.test.ts | 4 ++-- yarn-project/end-to-end/src/e2e_state_vars.test.ts | 4 ++-- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr index bab4f24cb51..c3233b2d55d 100644 --- a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr @@ -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()); } @@ -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)) { diff --git a/noir-projects/noir-contracts/contracts/crowdfunding_contract/src/main.nr b/noir-projects/noir-contracts/contracts/crowdfunding_contract/src/main.nr index 3b1f7114772..38fb7984a38 100644 --- a/noir-projects/noir-contracts/contracts/crowdfunding_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/crowdfunding_contract/src/main.nr @@ -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 diff --git a/noir-projects/noir-contracts/contracts/docs_example_contract/src/main.nr b/noir-projects/noir-contracts/contracts/docs_example_contract/src/main.nr index ec83e8cc964..e36efb875bc 100644 --- a/noir-projects/noir-contracts/contracts/docs_example_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/docs_example_contract/src/main.nr @@ -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 } @@ -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 } diff --git a/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr b/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr index c2c05f58a09..80d693340c6 100644 --- a/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr @@ -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(); @@ -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()); diff --git a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr index 7fe8812d566..9ab011d9e0e 100644 --- a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr @@ -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( @@ -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" @@ -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( @@ -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" @@ -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" ); } diff --git a/yarn-project/end-to-end/src/e2e_auth_contract.test.ts b/yarn-project/end-to-end/src/e2e_auth_contract.test.ts index 099885c1c9a..2ccf9ff3493 100644 --- a/yarn-project/end-to-end/src/e2e_auth_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_auth_contract.test.ts @@ -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', ); }); @@ -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', ); @@ -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', ); diff --git a/yarn-project/end-to-end/src/e2e_note_getter.test.ts b/yarn-project/end-to-end/src/e2e_note_getter.test.ts index b17cb3ed286..1feac9426fd 100644 --- a/yarn-project/end-to-end/src/e2e_note_getter.test.ts +++ b/yarn-project/end-to-end/src/e2e_note_getter.test.ts @@ -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`, ); } diff --git a/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts b/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts index 405fab1fab7..4b49fa43f6b 100644 --- a/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts @@ -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`, ); @@ -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`, ); diff --git a/yarn-project/end-to-end/src/e2e_state_vars.test.ts b/yarn-project/end-to-end/src/e2e_state_vars.test.ts index dcdbdfd9454..2eebaec5d99 100644 --- a/yarn-project/end-to-end/src/e2e_state_vars.test.ts +++ b/yarn-project/end-to-end/src/e2e_state_vars.test.ts @@ -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'", ); }); @@ -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'", ); });