From 6024521c304f3f60e60da44d57402740f9bb25cf Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 29 May 2025 09:28:29 +0000 Subject: [PATCH] fix: correctly decoding string return value --- yarn-project/stdlib/src/abi/decoder.test.ts | 4 +--- yarn-project/stdlib/src/abi/decoder.ts | 9 +++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/yarn-project/stdlib/src/abi/decoder.test.ts b/yarn-project/stdlib/src/abi/decoder.test.ts index d5ccbb7cf341..7e048e0fb84e 100644 --- a/yarn-project/stdlib/src/abi/decoder.test.ts +++ b/yarn-project/stdlib/src/abi/decoder.test.ts @@ -263,9 +263,7 @@ describe('decoder', () => { 1n, 2n, false, - // TODO(#14600): correctly decode the string as string instead of 3 bigints - // 'xyz', - [120n, 121n, 122n], + 'xyz', AztecAddress.fromBigInt(1n), // eslint-disable-next-line camelcase { x: 1n, y: 2n, is_infinite: false }, diff --git a/yarn-project/stdlib/src/abi/decoder.ts b/yarn-project/stdlib/src/abi/decoder.ts index da5c39023a51..ff858cf287a7 100644 --- a/yarn-project/stdlib/src/abi/decoder.ts +++ b/yarn-project/stdlib/src/abi/decoder.ts @@ -7,7 +7,7 @@ import { isAztecAddressStruct, parseSignedInt } from './utils.js'; /** * The type of our decoded ABI. */ -export type AbiDecoded = bigint | boolean | AztecAddress | AbiDecoded[] | { [key: string]: AbiDecoded }; +export type AbiDecoded = bigint | boolean | string | AztecAddress | AbiDecoded[] | { [key: string]: AbiDecoded }; /** * Decodes values using a provided ABI. @@ -58,11 +58,12 @@ class AbiDecoder { return struct; } case 'string': { - const array = []; + let str = ''; for (let i = 0; i < abiType.length; i += 1) { - array.push(this.getNextField().toBigInt()); + const charCode = Number(this.getNextField().toBigInt()); + str += String.fromCharCode(charCode); } - return array; + return str; } case 'tuple': { const array = [];