From 70d0d51bfae0b203dd65cff60d642a619b4e50f3 Mon Sep 17 00:00:00 2001 From: Esau Date: Thu, 25 Jan 2024 23:26:27 +0100 Subject: [PATCH 1/2] fix --- .../end-to-end/src/shared/cross_chain_test_harness.ts | 3 +-- yarn-project/foundation/src/abi/decoder.ts | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) 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 db556b0ffe2..d72c2f1e8f2 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 @@ -104,8 +104,7 @@ export async function deployAndInitializeTokenAndBridgeContracts( throw new Error(`Token admin is not ${owner}`); } - // TODO(#3641) - Fix deserialization and compare AztecAddress directly - if ((await bridge.methods.token().view()).inner !== token.address.toBigInt()) { + if (!(await bridge.methods.token().view()).equals(token.address)) { throw new Error(`Bridge token is not ${token.address}`); } diff --git a/yarn-project/foundation/src/abi/decoder.ts b/yarn-project/foundation/src/abi/decoder.ts index ac509d59ba1..e1f4558afa2 100644 --- a/yarn-project/foundation/src/abi/decoder.ts +++ b/yarn-project/foundation/src/abi/decoder.ts @@ -1,10 +1,12 @@ +import { AztecAddress } from '../aztec-address/index.js'; import { Fr } from '../fields/index.js'; import { ABIParameter, type ABIType, ABIVariable, FunctionArtifact } from './abi.js'; +import { isAztecAddressStruct } from './utils.js'; /** * The type of our decoded ABI. */ -export type DecodedReturn = bigint | boolean | DecodedReturn[] | { [key: string]: DecodedReturn }; +export type DecodedReturn = bigint | boolean | AztecAddress | DecodedReturn[] | { [key: string]: DecodedReturn }; /** * Decodes return values from a function call. @@ -38,6 +40,10 @@ class ReturnValuesDecoder { } case 'struct': { const struct: { [key: string]: DecodedReturn } = {}; + if (isAztecAddressStruct(abiType)) { + return new AztecAddress(this.getNextField().toBuffer()); + } + for (const field of abiType.fields) { struct[field.name] = this.decodeReturn(field.type); } From e1ca6572f9a1faa89fd0d97ade8afb1adec947f7 Mon Sep 17 00:00:00 2001 From: Esau Date: Fri, 26 Jan 2024 20:54:01 +0100 Subject: [PATCH 2/2] Fixes tests broken by fixing aztec address deserialization --- .../end-to-end/src/e2e_card_game.test.ts | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_card_game.test.ts b/yarn-project/end-to-end/src/e2e_card_game.test.ts index b4b881cd08e..69d7bbae065 100644 --- a/yarn-project/end-to-end/src/e2e_card_game.test.ts +++ b/yarn-project/end-to-end/src/e2e_card_game.test.ts @@ -28,9 +28,7 @@ const cardToField = (card: Card): bigint => { }; interface PlayerGameEntry { - address: { - inner: bigint; - }; + address: AztecAddress; deck_strength: bigint; points: bigint; } @@ -183,16 +181,12 @@ describe('e2e_card_game', () => { expect((await contract.methods.view_game(GAME_ID).view({ from: firstPlayer })) as Game).toMatchObject({ players: [ { - address: { - inner: firstPlayer.toBigInt(), - }, + address: firstPlayer, deck_strength: expect.anything(), points: 0n, }, { - address: { - inner: 0n, - }, + address: AztecAddress.ZERO, deck_strength: 0n, points: 0n, }, @@ -227,16 +221,12 @@ describe('e2e_card_game', () => { expect((await contract.methods.view_game(GAME_ID).view({ from: firstPlayer })) as Game).toMatchObject({ players: expect.arrayContaining([ { - address: { - inner: firstPlayer.toBigInt(), - }, + address: firstPlayer, deck_strength: expect.anything(), points: 0n, }, { - address: { - inner: secondPlayer.toBigInt(), - }, + address: secondPlayer, deck_strength: expect.anything(), points: 0n, }, @@ -281,16 +271,16 @@ describe('e2e_card_game', () => { async function playGame(playerDecks: { address: AztecAddress; deck: Card[] }[], id = GAME_ID) { const initialGameState = (await contract.methods.view_game(id).view({ from: firstPlayer })) as Game; - const players = initialGameState.players.map(player => player.address.inner); + const players = initialGameState.players.map(player => player.address); const cards = players.map( - player => playerDecks.find(playerDeckEntry => playerDeckEntry.address.toBigInt() === player)!.deck, + player => playerDecks.find(playerDeckEntry => playerDeckEntry.address.equals(player))!.deck, ); for (let roundIndex = 0; roundIndex < cards.length; roundIndex++) { for (let playerIndex = 0; playerIndex < players.length; playerIndex++) { const player = players[playerIndex]; const card = cards[playerIndex][roundIndex]; - await contractFor(AztecAddress.fromBigInt(player)).methods.play_card(id, card).send().wait(); + await contractFor(player).methods.play_card(id, card).send().wait(); } } @@ -315,8 +305,8 @@ describe('e2e_card_game', () => { ]); const sortedByPoints = game.players.sort((a, b) => Number(b.points - a.points)); - const winner = AztecAddress.fromBigInt(sortedByPoints[0].address.inner); - const loser = AztecAddress.fromBigInt(sortedByPoints[1].address.inner); + const winner = sortedByPoints[0].address; + const loser = sortedByPoints[1].address; await expect( contractFor(loser).methods.claim_cards(GAME_ID, game.rounds_cards.map(cardToField)).send().wait(),