From ce8416174f360a4a00cc70c20c8f2d99354aec2e Mon Sep 17 00:00:00 2001 From: Lasse Herskind <16536249+LHerskind@users.noreply.github.com> Date: Mon, 22 Apr 2024 11:47:10 +0100 Subject: [PATCH] refactor: purge unconstrained functions where possible (#5819) Fixes #5451 --- noir-projects/noir-contracts/Nargo.toml | 1 - .../contracts/avm_test_contract/src/main.nr | 12 --- .../contracts/gas_token_contract/src/main.nr | 4 +- .../contracts/lending_contract/src/asset.nr | 16 ++-- .../contracts/lending_contract/src/main.nr | 17 ++--- .../lending_contract/src/position.nr | 30 ++++++++ .../price_feed_contract/src/asset.nr | 2 +- .../contracts/price_feed_contract/src/main.nr | 4 - .../contracts/reader_contract/Nargo.toml | 9 --- .../contracts/reader_contract/src/main.nr | 69 ----------------- .../stateful_test_contract/src/main.nr | 3 +- .../token_blacklist_contract/src/main.nr | 24 +++--- .../token_bridge_contract/src/main.nr | 25 +------ .../contracts/token_contract/src/main.nr | 64 +++++++--------- .../end-to-end/src/e2e_avm_simulator.test.ts | 4 +- .../src/e2e_blacklist_token_contract.test.ts | 1 - .../reading_constants.test.ts | 75 ++++--------------- .../src/shared/cross_chain_test_harness.ts | 2 +- 18 files changed, 112 insertions(+), 250 deletions(-) create mode 100644 noir-projects/noir-contracts/contracts/lending_contract/src/position.nr delete mode 100644 noir-projects/noir-contracts/contracts/reader_contract/Nargo.toml delete mode 100644 noir-projects/noir-contracts/contracts/reader_contract/src/main.nr diff --git a/noir-projects/noir-contracts/Nargo.toml b/noir-projects/noir-contracts/Nargo.toml index b3d1c57c752..e27753c3f88 100644 --- a/noir-projects/noir-contracts/Nargo.toml +++ b/noir-projects/noir-contracts/Nargo.toml @@ -40,6 +40,5 @@ members = [ "contracts/token_blacklist_contract", "contracts/token_bridge_contract", "contracts/uniswap_contract", - "contracts/reader_contract", "contracts/multi_call_entrypoint_contract", ] diff --git a/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr index 7eb12dd0e7c..98b92a0065e 100644 --- a/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr @@ -41,18 +41,6 @@ contract AvmTest { /************************************************************************ * Storage ************************************************************************/ - unconstrained fn view_storage_single() -> pub Field { - storage.single.read() - } - - unconstrained fn view_storage_list() -> pub [Field; 2] { - storage.list.read().serialize() - } - - unconstrained fn view_storage_map(address: AztecAddress) -> pub u32 { - storage.map.at(address).read() - } - #[aztec(public-vm)] fn set_storage_single(a: Field) { storage.single.write(a); diff --git a/noir-projects/noir-contracts/contracts/gas_token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/gas_token_contract/src/main.nr index ec1adf32116..e1b8c0fd39d 100644 --- a/noir-projects/noir-contracts/contracts/gas_token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/gas_token_contract/src/main.nr @@ -55,8 +55,8 @@ contract GasToken { rebate.to_field() } - // utility function for testing - unconstrained fn balance_of_public(owner: AztecAddress) -> pub Field { + #[aztec(public)] + fn balance_of_public(owner: AztecAddress) -> pub Field { storage.balances.at(owner).read().to_field() } } diff --git a/noir-projects/noir-contracts/contracts/lending_contract/src/asset.nr b/noir-projects/noir-contracts/contracts/lending_contract/src/asset.nr index 7415ec54d92..3e53fbb28e1 100644 --- a/noir-projects/noir-contracts/contracts/lending_contract/src/asset.nr +++ b/noir-projects/noir-contracts/contracts/lending_contract/src/asset.nr @@ -13,14 +13,16 @@ struct Asset { oracle: AztecAddress, } -global SERIALIZED_LEN: Field = 4; +global SERIALIZED_LEN: Field = 6; impl Serialize for Asset { fn serialize(Asset: Asset) -> [Field; SERIALIZED_LEN] { [ - Asset.interest_accumulator.to_integer(), + Asset.interest_accumulator.lo as Field, + Asset.interest_accumulator.hi as Field, Asset.last_updated_ts as Field, - Asset.loan_to_value.to_integer(), + Asset.loan_to_value.lo as Field, + Asset.loan_to_value.hi as Field, Asset.oracle.to_field() ] } @@ -30,10 +32,10 @@ impl Deserialize for Asset { // Right now we are wasting so many writes. If changing last_updated_ts // we will end up rewriting all of them, wasting writes. fn deserialize(fields: [Field; SERIALIZED_LEN]) -> Asset { - let interest_accumulator = U128::from_integer(fields[0]); - let last_updated_ts = fields[1] as u64; - let loan_to_value = U128::from_integer(fields[2]); - let oracle = AztecAddress::from_field(fields[3]); + let interest_accumulator = U128 {lo: fields[0], hi: fields[1]}; + let last_updated_ts = fields[2] as u64; + let loan_to_value = U128 {lo: fields[3], hi: fields[4]}; + let oracle = AztecAddress::from_field(fields[5]); Asset { interest_accumulator, 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..328ec71ce97 100644 --- a/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr @@ -1,4 +1,5 @@ mod asset; +mod position; mod interest_math; mod helpers; @@ -14,6 +15,7 @@ contract Lending { use dep::aztec::context::{PublicContext, Context, gas::GasOpts}; use crate::asset::Asset; + use crate::position::Position; use crate::interest_math::compute_multiplier; use crate::helpers::{covered_by_collateral, DebtReturn, debt_updates, debt_value, compute_identifier}; use dep::token::Token; @@ -29,12 +31,6 @@ contract Lending { static_debt: Map>, // abusing keys very heavily } - struct Position { - collateral: Field, - static_debt: Field, - debt: Field, - } - // Constructs the contract. #[aztec(private)] #[aztec(initializer)] @@ -265,11 +261,13 @@ contract Lending { storage.static_debt.at(owner).write(debt_returns.static_debt.to_integer()); } - unconstrained fn get_asset(asset_id: Field) -> pub Asset { + #[aztec(public)] + fn get_asset(asset_id: Field) -> pub Asset { storage.assets.at(asset_id).read() } - unconstrained fn get_position(owner: AztecAddress) -> pub Position { + #[aztec(public)] + fn get_position(owner: AztecAddress) -> pub Position { let collateral = storage.collateral.at(owner).read(); let static_debt = storage.static_debt.at(owner).read(); let asset: Asset = storage.assets.at(0).read(); @@ -280,7 +278,8 @@ contract Lending { Position { collateral, static_debt, debt } } - unconstrained fn get_assets() -> pub [AztecAddress; 2] { + #[aztec(public)] + fn get_assets() -> pub [AztecAddress; 2] { [storage.collateral_asset.read(), storage.stable_coin.read()] } } diff --git a/noir-projects/noir-contracts/contracts/lending_contract/src/position.nr b/noir-projects/noir-contracts/contracts/lending_contract/src/position.nr new file mode 100644 index 00000000000..080f977e9c0 --- /dev/null +++ b/noir-projects/noir-contracts/contracts/lending_contract/src/position.nr @@ -0,0 +1,30 @@ +use dep::aztec::prelude::AztecAddress; +use dep::aztec::protocol_types::traits::{Deserialize, Serialize}; + +struct Position { + collateral: Field, + static_debt: Field, + debt: Field, +} + +global POSITION_SERIALIZED_LEN: Field = 3; + +impl Serialize for Position { + fn serialize(position: Position) -> [Field; POSITION_SERIALIZED_LEN] { + [ + position.collateral.to_field(), + position.static_debt.to_field(), + position.debt.to_field(), + ] + } +} + +impl Deserialize for Position { + fn deserialize(fields: [Field; POSITION_SERIALIZED_LEN]) -> Position { + Position { + collateral: fields[0], + static_debt: fields[1], + debt: fields[2], + } + } +} diff --git a/noir-projects/noir-contracts/contracts/price_feed_contract/src/asset.nr b/noir-projects/noir-contracts/contracts/price_feed_contract/src/asset.nr index 0f34a0429b1..3e148e12aa3 100644 --- a/noir-projects/noir-contracts/contracts/price_feed_contract/src/asset.nr +++ b/noir-projects/noir-contracts/contracts/price_feed_contract/src/asset.nr @@ -8,7 +8,7 @@ global ASSET_SERIALIZED_LEN: Field = 1; impl Serialize for Asset { fn serialize(asset: Asset) -> [Field; ASSET_SERIALIZED_LEN] { - [asset.price.to_integer()] + [asset.price.to_field()] } } diff --git a/noir-projects/noir-contracts/contracts/price_feed_contract/src/main.nr b/noir-projects/noir-contracts/contracts/price_feed_contract/src/main.nr index c4afaacf753..c563792bf0c 100644 --- a/noir-projects/noir-contracts/contracts/price_feed_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/price_feed_contract/src/main.nr @@ -21,8 +21,4 @@ contract PriceFeed { fn get_price(asset_id: Field) -> Asset { storage.assets.at(asset_id).read() } - - unconstrained fn fetch_price(asset_id: Field) -> pub Asset { - storage.assets.at(asset_id).read() - } } diff --git a/noir-projects/noir-contracts/contracts/reader_contract/Nargo.toml b/noir-projects/noir-contracts/contracts/reader_contract/Nargo.toml deleted file mode 100644 index 8ae3ed01400..00000000000 --- a/noir-projects/noir-contracts/contracts/reader_contract/Nargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "reader_contract" -authors = [""] -compiler_version = ">=0.25.0" -type = "contract" - -[dependencies] -aztec = { path = "../../../aztec-nr/aztec" } -compressed_string = { path = "../../../aztec-nr/compressed-string" } diff --git a/noir-projects/noir-contracts/contracts/reader_contract/src/main.nr b/noir-projects/noir-contracts/contracts/reader_contract/src/main.nr deleted file mode 100644 index 0cfbb45b596..00000000000 --- a/noir-projects/noir-contracts/contracts/reader_contract/src/main.nr +++ /dev/null @@ -1,69 +0,0 @@ -contract Reader { - use dep::aztec::prelude::{AztecAddress, FunctionSelector, Deserialize}; - - use dep::compressed_string::FieldCompressedString; - - #[aztec(private)] - fn constructor() {} - - #[aztec(public)] - fn check_name_public(who: AztecAddress, what: str<31>) { - let selector = FunctionSelector::from_signature("public_get_name()"); - let name: FieldCompressedString = context.call_public_function_no_args(who, selector).deserialize_into(); - let _what = FieldCompressedString::from_string(what); - assert(name.is_eq(_what)); - } - - #[aztec(private)] - fn check_name_private(who: AztecAddress, what: str<31>) { - let selector = FunctionSelector::from_signature("private_get_name()"); - let name: FieldCompressedString = context.call_private_function_no_args(who, selector).unpack_into(); - let _what = FieldCompressedString::from_string(what); - assert(name.is_eq(_what)); - } - - unconstrained fn get_name(who: AztecAddress) -> pub str<6> { - // We cannot yet call an unconstrained function from another - "Reader" - } - - #[aztec(public)] - fn check_symbol_public(who: AztecAddress, what: str<31>) { - let selector = FunctionSelector::from_signature("public_get_symbol()"); - let symbol: FieldCompressedString = context.call_public_function_no_args(who, selector).deserialize_into(); - let _what = FieldCompressedString::from_string(what); - assert(symbol.is_eq(_what)); - } - - #[aztec(private)] - fn check_symbol_private(who: AztecAddress, what: str<31>) { - let selector = FunctionSelector::from_signature("private_get_symbol()"); - let symbol: FieldCompressedString = context.call_private_function_no_args(who, selector).unpack_into(); - let _what = FieldCompressedString::from_string(what); - assert(symbol.is_eq(_what)); - } - - unconstrained fn get_symbol(who: AztecAddress) -> pub str<3> { - // We cannot yet call an unconstrained function from another - "RDR" - } - - #[aztec(public)] - fn check_decimals_public(who: AztecAddress, what: u8) { - let selector = FunctionSelector::from_signature("public_get_decimals()"); - let ret: u8 = context.call_public_function_no_args(who, selector).deserialize_into(); - assert(ret == what); - } - - #[aztec(private)] - fn check_decimals_private(who: AztecAddress, what: u8) { - let selector = FunctionSelector::from_signature("private_get_decimals()"); - let result: u8 = context.call_private_function_no_args(who, selector).unpack_into(); - assert(result == what); - } - - unconstrained fn get_decimals(who: AztecAddress) -> pub u8 { - // We cannot yet call an unconstrained function from another - 18 - } -} diff --git a/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr index db8efde4a25..a96fbfca3a1 100644 --- a/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr @@ -94,7 +94,8 @@ contract StatefulTest { balance_utils::get_balance(owner_balance) } - unconstrained fn get_public_value(owner: AztecAddress) -> pub Field { + #[aztec(public)] + fn get_public_value(owner: AztecAddress) -> pub Field { storage.public_values.at(owner).read() } } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr index ddb115c721e..21f62b8853f 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr @@ -38,6 +38,16 @@ contract TokenBlacklist { slow_update: SharedImmutable, } + #[aztec(public)] + fn total_supply() -> pub Field { + storage.total_supply.read().to_field() + } + + #[aztec(public)] + fn balance_of_public(owner: AztecAddress) -> pub Field { + storage.public_balances.at(owner).read().to_field() + } + // docs:start:constructor #[aztec(public)] #[aztec(initializer)] @@ -227,8 +237,7 @@ contract TokenBlacklist { storage.balances.sub(from, U128::from_integer(amount)); - let selector = FunctionSelector::from_signature("_increase_public_balance((Field),Field)"); - context.call_public_function(context.this_address(), selector, [to.to_field(), amount]); + TokenBlacklist::at(context.this_address())._increase_public_balance(to, amount).enqueue(&mut context); } // docs:start:transfer_private @@ -266,8 +275,7 @@ contract TokenBlacklist { storage.balances.sub(from, U128::from_integer(amount)); - let selector = FunctionSelector::from_signature("_reduce_total_supply(Field)"); - context.call_public_function(context.this_address(), selector, [amount]); + TokenBlacklist::at(context.this_address())._reduce_total_supply(amount).enqueue(&mut context); } /// Internal /// @@ -289,15 +297,7 @@ contract TokenBlacklist { /// Unconstrained /// - unconstrained fn total_supply() -> pub Field { - storage.total_supply.read().to_field() - } - unconstrained fn balance_of_private(owner: AztecAddress) -> pub Field { storage.balances.balance_of(owner).to_field() } - - unconstrained fn balance_of_public(owner: AztecAddress) -> pub Field { - storage.public_balances.at(owner).read().to_field() - } } diff --git a/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr index 28226b5b10b..b32d8c41d78 100644 --- a/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr @@ -26,8 +26,7 @@ contract TokenBridge { #[aztec(private)] #[aztec(initializer)] fn constructor(token: AztecAddress) { - let selector = FunctionSelector::from_signature("_initialize((Field))"); - context.call_public_function(context.this_address(), selector, [token.to_field()]); + TokenBridge::at(context.this_address())._initialize(token).enqueue(&mut context); } // docs:end:token_bridge_storage_and_constructor @@ -99,11 +98,7 @@ contract TokenBridge { // `mint_private` on token is public. So we call an internal public function // which then calls the public method on the token contract. // Since the secret_hash is passed, no secret is leaked. - context.call_public_function( - context.this_address(), - FunctionSelector::from_signature("_call_mint_on_token(Field,Field)"), - [amount, secret_hash_for_redeeming_minted_notes] - ); + TokenBridge::at(context.this_address())._call_mint_on_token(amount, secret_hash_for_redeeming_minted_notes).enqueue(&mut context); } // docs:end:claim_private @@ -124,11 +119,7 @@ contract TokenBridge { // docs:start:call_assert_token_is_same // Assert that user provided token address is same as seen in storage. - context.call_public_function( - context.this_address(), - FunctionSelector::from_signature("_assert_token_is_same((Field))"), - [token.to_field()] - ); + TokenBridge::at(context.this_address())._assert_token_is_same(token).enqueue(&mut context); // docs:end:call_assert_token_is_same // Burn tokens @@ -136,19 +127,11 @@ contract TokenBridge { } /// docs:end:exit_to_l1_private - // View function that is callable by other contracts. - // Unconstrained can't be called by others since it isn't safe. + // docs:start:read_token #[aztec(public)] fn get_token() -> AztecAddress { storage.token.read() } - - // /// Unconstrained /// - - // docs:start:read_token - unconstrained fn token() -> pub AztecAddress { - storage.token.read() - } // docs:end:read_token #[aztec(public)] diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr index cc892421ece..a8a5cb8edbd 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr @@ -84,10 +84,6 @@ contract Token { storage.name.read_private() } - unconstrained fn un_get_name() -> pub [u8; 31] { - storage.name.read_public().to_bytes() - } - #[aztec(public)] fn public_get_symbol() -> pub FieldCompressedString { storage.symbol.read_public() @@ -98,10 +94,6 @@ contract Token { storage.symbol.read_private() } - unconstrained fn un_get_symbol() -> pub [u8; 31] { - storage.symbol.read_public().to_bytes() - } - #[aztec(public)] fn public_get_decimals() -> pub u8 { // docs:start:read_decimals_public @@ -116,9 +108,33 @@ contract Token { // docs:end:read_decimals_private } - unconstrained fn un_get_decimals() -> pub u8 { - storage.decimals.read_public() + // docs:start:admin + #[aztec(public)] + fn admin() -> pub Field { + storage.admin.read().to_field() + } + // docs:end:admin + + // docs:start:is_minter + #[aztec(public)] + fn is_minter(minter: AztecAddress) -> pub bool { + storage.minters.at(minter).read() } + // docs:end:is_minter + + // docs:start:total_supply + #[aztec(public)] + fn total_supply() -> pub Field { + storage.total_supply.read().to_field() + } + // docs:end:total_supply + + // docs:start:balance_of_public + #[aztec(public)] + fn balance_of_public(owner: AztecAddress) -> pub Field { + storage.public_balances.at(owner).read().to_field() + } + // docs:end:balance_of_public // docs:start:set_minter #[aztec(public)] @@ -190,7 +206,7 @@ contract Token { let from_balance = storage.public_balances.at(from).read().sub(amount); let pending_shields = storage.pending_shields; - let mut note = TransparentNote::new(amount.to_integer(), secret_hash); + let mut note = TransparentNote::new(amount.to_field(), secret_hash); storage.public_balances.at(from).write(from_balance); pending_shields.insert_from_public(&mut note); @@ -330,34 +346,10 @@ contract Token { /// Unconstrained /// - // docs:start:admin - unconstrained fn admin() -> pub Field { - storage.admin.read().to_field() - } - // docs:end:admin - - // docs:start:is_minter - unconstrained fn is_minter(minter: AztecAddress) -> pub bool { - storage.minters.at(minter).read() - } - // docs:end:is_minter - - // docs:start:total_supply - unconstrained fn total_supply() -> pub Field { - storage.total_supply.read().to_integer() - } - // docs:end:total_supply - // docs:start:balance_of_private unconstrained fn balance_of_private(owner: AztecAddress) -> pub Field { - storage.balances.balance_of(owner).to_integer() + storage.balances.balance_of(owner).to_field() } // docs:end:balance_of_private - - // docs:start:balance_of_public - unconstrained fn balance_of_public(owner: AztecAddress) -> pub Field { - storage.public_balances.at(owner).read().to_integer() - } - // docs:end:balance_of_public } // docs:end:token_all diff --git a/yarn-project/end-to-end/src/e2e_avm_simulator.test.ts b/yarn-project/end-to-end/src/e2e_avm_simulator.test.ts index ac36f13ceaf..c94e1ca00ff 100644 --- a/yarn-project/end-to-end/src/e2e_avm_simulator.test.ts +++ b/yarn-project/end-to-end/src/e2e_avm_simulator.test.ts @@ -35,14 +35,14 @@ describe('e2e_avm_simulator', () => { describe('Storage', () => { it('Modifies storage (Field)', async () => { await avmContract.methods.set_storage_single(20n).send().wait(); - expect(await avmContract.methods.view_storage_single().simulate()).toEqual(20n); + expect(await avmContract.methods.read_storage_single().simulate()).toEqual(20n); }); it('Modifies storage (Map)', async () => { const address = AztecAddress.fromBigInt(9090n); await avmContract.methods.set_storage_map(address, 100).send().wait(); await avmContract.methods.add_storage_map(address, 100).send().wait(); - expect(await avmContract.methods.view_storage_map(address).simulate()).toEqual(200n); + expect(await avmContract.methods.read_storage_map(address).simulate()).toEqual(200n); }); }); diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract.test.ts index 59224084453..1500098a5bc 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract.test.ts @@ -994,7 +994,6 @@ describe('e2e_blacklist_token_contract', () => { .methods.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) .send(); await expect(txReplay.wait()).rejects.toThrow('Transaction '); - // @todo @LHerskind This error is weird? }); describe('failure cases', () => { diff --git a/yarn-project/end-to-end/src/e2e_token_contract/reading_constants.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/reading_constants.test.ts index b7a5089217f..af856853415 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/reading_constants.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/reading_constants.test.ts @@ -1,12 +1,14 @@ -import { ReaderContract } from '@aztec/noir-contracts.js'; +import { Fr } from '@aztec/circuits.js'; import { TokenContractTest } from './token_contract_test.js'; -const toString = (val: bigint[]) => { +const toString = ({ value }: { value: bigint }) => { + const vals: number[] = Array.from(new Fr(value).toBuffer()); + let str = ''; - for (let i = 0; i < val.length; i++) { - if (val[i] != 0n) { - str += String.fromCharCode(Number(val[i])); + for (let i = 0; i < vals.length; i++) { + if (vals[i] != 0) { + str += String.fromCharCode(Number(vals[i])); } } return str; @@ -16,26 +18,9 @@ describe('e2e_token_contract reading constants', () => { const t = new TokenContractTest('reading_constants'); const { TOKEN_DECIMALS, TOKEN_NAME, TOKEN_SYMBOL } = TokenContractTest; // Do not destructure anything mutable. - const { logger } = t; - let reader: ReaderContract; beforeAll(async () => { await t.applyBaseSnapshots(); - - await t.snapshot( - 'reading_constants', - async () => { - logger.verbose('Deploying ReaderContract...'); - const reader = await ReaderContract.deploy(t.wallets[0]).send().deployed(); - logger.verbose(`Deployed ReaderContract to ${reader.address}.`); - return { readerAddress: reader.address }; - }, - async ({ readerAddress }) => { - reader = await ReaderContract.at(readerAddress, t.wallets[0]); - logger.verbose(`Reader contract restored to ${readerAddress}.`); - }, - ); - await t.setup(); }); @@ -50,66 +35,32 @@ describe('e2e_token_contract reading constants', () => { }); it('check name private', async () => { - const name = toString(await t.asset.methods.un_get_name().simulate()); + const name = toString(await t.asset.methods.private_get_name().simulate()); expect(name).toBe(TOKEN_NAME); - - await reader.methods.check_name_private(t.asset.address, TOKEN_NAME).send().wait(); - await expect(reader.methods.check_name_private(t.asset.address, 'WRONG_NAME').simulate()).rejects.toThrow( - 'name.is_eq(_what)', - ); }); it('check name public', async () => { - const name = toString(await t.asset.methods.un_get_name().simulate()); + const name = toString(await t.asset.methods.public_get_name().simulate()); expect(name).toBe(TOKEN_NAME); - - await reader.methods.check_name_public(t.asset.address, TOKEN_NAME).send().wait(); - await expect(reader.methods.check_name_public(t.asset.address, 'WRONG_NAME').simulate()).rejects.toThrow( - 'name.is_eq(_what)', - ); }); it('check symbol private', async () => { - const sym = toString(await t.asset.methods.un_get_symbol().simulate()); + const sym = toString(await t.asset.methods.private_get_symbol().simulate()); expect(sym).toBe(TOKEN_SYMBOL); - - await reader.methods.check_symbol_private(t.asset.address, TOKEN_SYMBOL).send().wait(); - - await expect(reader.methods.check_symbol_private(t.asset.address, 'WRONG_SYMBOL').simulate()).rejects.toThrow( - "Cannot satisfy constraint 'symbol.is_eq(_what)'", - ); }); it('check symbol public', async () => { - const sym = toString(await t.asset.methods.un_get_symbol().simulate()); + const sym = toString(await t.asset.methods.public_get_symbol().simulate()); expect(sym).toBe(TOKEN_SYMBOL); - - await reader.methods.check_symbol_public(t.asset.address, TOKEN_SYMBOL).send().wait(); - - await expect(reader.methods.check_symbol_public(t.asset.address, 'WRONG_SYMBOL').simulate()).rejects.toThrow( - "Failed to solve brillig function 'symbol.is_eq(_what)'", - ); }); it('check decimals private', async () => { - const dec = await t.asset.methods.un_get_decimals().simulate(); + const dec = await t.asset.methods.private_get_decimals().simulate(); expect(dec).toBe(TOKEN_DECIMALS); - - await reader.methods.check_decimals_private(t.asset.address, TOKEN_DECIMALS).send().wait(); - - await expect(reader.methods.check_decimals_private(t.asset.address, 99).simulate()).rejects.toThrow( - "Cannot satisfy constraint 'result == what'", - ); }); it('check decimals public', async () => { - const dec = await t.asset.methods.un_get_decimals().simulate(); + const dec = await t.asset.methods.public_get_decimals().simulate(); expect(dec).toBe(TOKEN_DECIMALS); - - await reader.methods.check_decimals_public(t.asset.address, TOKEN_DECIMALS).send().wait(); - - await expect(reader.methods.check_decimals_public(t.asset.address, 99).simulate()).rejects.toThrow( - "Failed to solve brillig function 'ret == what'", - ); }); }); diff --git a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts index 63975935c91..ef1d31bd8d3 100644 --- a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts +++ b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts @@ -109,7 +109,7 @@ export async function deployAndInitializeTokenAndBridgeContracts( throw new Error(`Token admin is not ${owner}`); } - if (!(await bridge.methods.token().simulate()).equals(token.address)) { + if (!(await bridge.methods.get_token().simulate()).equals(token.address)) { throw new Error(`Bridge token is not ${token.address}`); }