From 4a646343d57bb27c840f9fbd8cf24fd5f2e1ae4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nedim=20Salki=C4=87?= Date: Tue, 8 Aug 2023 18:08:03 +0200 Subject: [PATCH] fix: nested implicit generics get encoded properly (#1107) * fix: nested implicit generics get encoded properly *refactor: move to ResolvedAbiType handling generic type resolution and getting of signature --- .changeset/tasty-taxis-sneeze.md | 5 + packages/abi-coder/src/abi-coder.ts | 161 ++--- packages/abi-coder/src/function-fragment.ts | 88 +-- packages/abi-coder/src/interface.ts | 6 +- packages/abi-coder/src/resolved-abi-type.ts | 179 ++++++ .../test/fixtures/exhaustive-examples-abi.ts | 558 ++++++++++-------- packages/abi-coder/test/interface.test.ts | 43 +- .../exhaustive-examples/src/main.sw | 17 +- 8 files changed, 627 insertions(+), 430 deletions(-) create mode 100644 .changeset/tasty-taxis-sneeze.md create mode 100644 packages/abi-coder/src/resolved-abi-type.ts diff --git a/.changeset/tasty-taxis-sneeze.md b/.changeset/tasty-taxis-sneeze.md new file mode 100644 index 00000000000..f5ce9d21c86 --- /dev/null +++ b/.changeset/tasty-taxis-sneeze.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/abi-coder": patch +--- + +encoding bugfix diff --git a/packages/abi-coder/src/abi-coder.ts b/packages/abi-coder/src/abi-coder.ts index a20c111d89e..bc173446188 100644 --- a/packages/abi-coder/src/abi-coder.ts +++ b/packages/abi-coder/src/abi-coder.ts @@ -24,111 +24,38 @@ import { tupleRegEx, OPTION_CODER_TYPE, VEC_CODER_TYPE, - genericRegEx, } from './constants'; -import type { JsonAbi, JsonAbiArgument, JsonAbiType } from './json-abi'; +import type { JsonAbi, JsonAbiArgument } from './json-abi'; +import { ResolvedAbiType } from './resolved-abi-type'; import { findOrThrow } from './utilities'; const logger = new Logger(versions.FUELS); - export abstract class AbiCoder { - private static getImplicitGenericTypeParameters( - abi: JsonAbi, - abiType: JsonAbiType, - implicitGenericParametersParam: number[] | undefined = undefined - ): number[] { - const isExplicitGeneric = abiType.typeParameters !== null; - if (isExplicitGeneric || abiType.components === null) return []; - - const implicitGenericParameters: number[] = implicitGenericParametersParam ?? []; - - abiType.components.forEach((component) => { - const componentType = findOrThrow(abi.types, (t) => t.typeId === component.type); - - const isGeneric = genericRegEx.test(componentType.type); - - if (isGeneric) { - implicitGenericParameters.push(componentType.typeId); - return; - } - - this.getImplicitGenericTypeParameters(abi, componentType, implicitGenericParameters); - }); + static getCoder(abi: JsonAbi, argument: JsonAbiArgument): Coder { + const resolvedAbiType = new ResolvedAbiType(abi, argument); - return implicitGenericParameters; + return AbiCoder.getCoderImpl(resolvedAbiType); } - private static resolveGenericArgs( - abi: JsonAbi, - args: readonly JsonAbiArgument[], - typeParametersAndArgsMap: Record | undefined - ): readonly JsonAbiArgument[] { - if (typeParametersAndArgsMap === undefined) return args; - - return args.map((arg) => { - if (typeParametersAndArgsMap[arg.type] !== undefined) { - return { - ...typeParametersAndArgsMap[arg.type], - name: arg.name, - }; - } - - if (arg.typeArguments !== null) { - return { - ...structuredClone(arg), - typeArguments: this.resolveGenericArgs(abi, arg.typeArguments, typeParametersAndArgsMap), - }; - } - - const abiType = findOrThrow(abi.types, (x) => x.typeId === arg.type); - if (abiType.components === null) return arg; - const implicitGenericTypeParameters = this.getImplicitGenericTypeParameters(abi, abiType); - if (implicitGenericTypeParameters.length === 0) return arg; - - return { - ...structuredClone(arg), - typeArguments: implicitGenericTypeParameters.map((tp) => typeParametersAndArgsMap[tp]), - }; - }); + static encode(abi: JsonAbi, argument: JsonAbiArgument, value: InputValue) { + return this.getCoder(abi, argument).encode(value); } - static resolveGenericComponents(abi: JsonAbi, arg: JsonAbiArgument): readonly JsonAbiArgument[] { - let abiType = findOrThrow(abi.types, (t) => t.typeId === arg.type); - - const implicitGenericTypeParameters = this.getImplicitGenericTypeParameters(abi, abiType); - if (implicitGenericTypeParameters.length > 0) { - abiType = { ...structuredClone(abiType), typeParameters: implicitGenericTypeParameters }; - } - - const typeParametersAndArgsMap = abiType.typeParameters?.reduce( - (obj, typeParameter, typeParameterIndex) => { - const o: Record = { ...obj }; - o[typeParameter] = structuredClone(arg.typeArguments?.[typeParameterIndex]); - return o; - }, - {} as Record - ); - - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - return this.resolveGenericArgs(abi, abiType.components!, typeParametersAndArgsMap); + static decode( + abi: JsonAbi, + argument: JsonAbiArgument, + data: Uint8Array, + offset: number + ): [DecodedValue | undefined, number] { + return this.getCoder(abi, argument).decode(data, offset) as [DecodedValue | undefined, number]; } - static getCoder(abi: JsonAbi, argument: JsonAbiArgument): Coder { - const abiType = findOrThrow( - abi.types, - (t) => t.typeId === argument.type, - () => - logger.throwArgumentError('Type does not exist in the provided abi', 'type', { - argument, - abi, - }) - ); - - switch (abiType.type) { + private static getCoderImpl(resolvedAbiType: ResolvedAbiType): Coder { + switch (resolvedAbiType.type) { case 'u8': case 'u16': case 'u32': - return new NumberCoder(abiType.type); + return new NumberCoder(resolvedAbiType.type); case 'u64': case 'raw untyped ptr': return new U64Coder(); @@ -144,23 +71,24 @@ export abstract class AbiCoder { break; } - const stringMatch = stringRegEx.exec(abiType.type)?.groups; + const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups; if (stringMatch) { const length = parseInt(stringMatch.length, 10); return new StringCoder(length); } - if (['raw untyped slice'].includes(abiType.type)) { + if (['raw untyped slice'].includes(resolvedAbiType.type)) { const length = 0; const itemCoder = new U64Coder(); return new ArrayCoder(itemCoder, length); } // ABI types underneath MUST have components by definition - const components = this.resolveGenericComponents(abi, argument); + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const components = resolvedAbiType.components!; - const arrayMatch = arrayRegEx.exec(abiType.type)?.groups; + const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups; if (arrayMatch) { const length = parseInt(arrayMatch.length, 10); const arg = components[0]; @@ -168,64 +96,53 @@ export abstract class AbiCoder { throw new Error('Expected array type to have an item component'); } - const arrayElementCoder = this.getCoder(abi, arg); + const arrayElementCoder = AbiCoder.getCoderImpl(arg); return new ArrayCoder(arrayElementCoder, length); } - if (abiType.type === VEC_CODER_TYPE) { - const typeArgument = components.find((x) => x.name === 'buf')?.typeArguments?.[0]; - if (!typeArgument) { + if (resolvedAbiType.type === VEC_CODER_TYPE) { + const arg = findOrThrow(components, (c) => c.name === 'buf').originalTypeArguments?.[0]; + if (!arg) { throw new Error('Expected Vec type to have a type argument'); } - const itemCoder = this.getCoder(abi, typeArgument); + const argType = new ResolvedAbiType(resolvedAbiType.abi, arg); + + const itemCoder = AbiCoder.getCoderImpl(argType); return new VecCoder(itemCoder); } - const structMatch = structRegEx.exec(abiType.type)?.groups; + const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups; if (structMatch) { - const coders = this.getCoders(components, abi); + const coders = AbiCoder.getCoders(components); return new StructCoder(structMatch.name, coders); } - const enumMatch = enumRegEx.exec(abiType.type)?.groups; + const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups; if (enumMatch) { - const coders = this.getCoders(components, abi); + const coders = AbiCoder.getCoders(components); - const isOptionEnum = abiType.type === OPTION_CODER_TYPE; + const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE; if (isOptionEnum) { return new OptionCoder(enumMatch.name, coders); } return new EnumCoder(enumMatch.name, coders); } - const tupleMatch = tupleRegEx.exec(abiType.type)?.groups; + const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups; if (tupleMatch) { - const coders = components.map((component) => this.getCoder(abi, component)); + const coders = components.map((component) => AbiCoder.getCoderImpl(component)); return new TupleCoder(coders); } - return logger.throwArgumentError('Coder not found', 'type', { abiType, abi }); + return logger.throwArgumentError('Coder not found', 'abiType', { abiType: resolvedAbiType }); } - private static getCoders(components: readonly JsonAbiArgument[], abi: JsonAbi) { + private static getCoders(components: readonly ResolvedAbiType[]) { return components.reduce((obj, component) => { const o: Record = obj; - o[component.name] = this.getCoder(abi, component); + o[component.name] = AbiCoder.getCoderImpl(component); return o; }, {}); } - - static encode(abi: JsonAbi, argument: JsonAbiArgument, value: InputValue) { - return this.getCoder(abi, argument).encode(value); - } - - static decode( - abi: JsonAbi, - arg: JsonAbiArgument, - data: Uint8Array, - offset: number - ): [DecodedValue | undefined, number] { - return this.getCoder(abi, arg).decode(data, offset) as [DecodedValue | undefined, number]; - } } diff --git a/packages/abi-coder/src/function-fragment.ts b/packages/abi-coder/src/function-fragment.ts index 25fc863e0e1..f87b8a9d1ae 100644 --- a/packages/abi-coder/src/function-fragment.ts +++ b/packages/abi-coder/src/function-fragment.ts @@ -11,13 +11,14 @@ import type { DecodedValue, InputValue } from './coders/abstract-coder'; import type { ArrayCoder } from './coders/array'; import { TupleCoder } from './coders/tuple'; import type { U64Coder } from './coders/u64'; -import { arrayRegEx, enumRegEx, OPTION_CODER_TYPE, stringRegEx, structRegEx } from './constants'; +import { OPTION_CODER_TYPE } from './constants'; import type { JsonAbi, JsonAbiArgument, JsonAbiFunction, JsonAbiFunctionAttribute, } from './json-abi'; +import { ResolvedAbiType } from './resolved-abi-type'; import type { Uint8ArrayWithDynamicData } from './utilities'; import { isPointerType, unpackDynamicData, findOrThrow } from './utilities'; @@ -32,78 +33,25 @@ export class FunctionFragment< readonly name: string; readonly jsonFn: JsonAbiFunction; readonly attributes: readonly JsonAbiFunctionAttribute[]; - private readonly jsonAbi: JsonAbi; - constructor(abi: JsonAbi, name: FnName) { - this.jsonAbi = abi; - this.jsonFn = findOrThrow(abi.functions, (f) => f.name === name); + + constructor(jsonAbi: JsonAbi, name: FnName) { + this.jsonAbi = jsonAbi; + this.jsonFn = findOrThrow(this.jsonAbi.functions, (f) => f.name === name); this.name = name; - this.signature = FunctionFragment.getSignature(abi, this.jsonFn); + this.signature = FunctionFragment.getSignature(this.jsonAbi, this.jsonFn); this.selector = FunctionFragment.getFunctionSelector(this.signature); this.attributes = this.jsonFn.attributes ?? []; } private static getSignature(abi: JsonAbi, fn: JsonAbiFunction): string { - const inputsSignatures = fn.inputs.map((input) => this.getArgSignature(abi, input)); + const inputsSignatures = fn.inputs.map((input) => + new ResolvedAbiType(abi, input).getSignature() + ); return `${fn.name}(${inputsSignatures.join(',')})`; } - private static getArgSignature(abi: JsonAbi, arg: JsonAbiArgument): string { - const prefix = this.getArgSignaturePrefix(abi, arg); - const content = this.getArgSignatureContent(abi, arg); - - return `${prefix}${content}`; - } - - private static getArgSignaturePrefix(abi: JsonAbi, input: JsonAbiArgument): string { - const abiType = findOrThrow(abi.types, (x) => x.typeId === input.type); - const structMatch = structRegEx.test(abiType.type); - if (structMatch) return 's'; - - const arrayMatch = arrayRegEx.test(abiType.type); - if (arrayMatch) return 'a'; - - const enumMatch = enumRegEx.test(abiType.type); - if (enumMatch) return 'e'; - - return ''; - } - - private static getArgSignatureContent(abi: JsonAbi, input: JsonAbiArgument): string { - const abiType = findOrThrow(abi.types, (x) => x.typeId === input.type); - - if (abiType.type === 'raw untyped ptr') { - return 'rawptr'; - } - - const strMatch = stringRegEx.exec(abiType.type)?.groups; - if (strMatch) { - return `str[${strMatch.length}]`; - } - - let components = abiType.components; - - if (components === null) return abiType.type; - - components = AbiCoder.resolveGenericComponents(abi, input); - - const arrayMatch = arrayRegEx.exec(abiType.type)?.groups; - - if (arrayMatch) { - return `[${this.getArgSignature(abi, components[0])};${arrayMatch.length}]`; - } - - const typeArgumentsSignature = Array.isArray(input.typeArguments) - ? `<${input.typeArguments.map((arg) => this.getArgSignature(abi, arg)).join(',')}>` - : ''; - const componentsSignature = `(${components - .map((arg) => this.getArgSignature(abi, arg)) - .join(',')})`; - - return `${typeArgumentsSignature}${componentsSignature}`; - } - private static getFunctionSelector(functionSignature: string) { const hashedFunctionSignature = sha256(bufferFromString(functionSignature, 'utf-8')); // get first 4 bytes of signature + 0x prefix. then left-pad it to 8 bytes using toHex(8) @@ -123,16 +71,16 @@ export class FunctionFragment< const shallowCopyValues = values.slice(); - const nonEmptyTypes = this.jsonFn.inputs.filter( + const nonEmptyInputs = this.jsonFn.inputs.filter( (x) => findOrThrow(this.jsonAbi.types, (t) => t.typeId === x.type).type !== '()' ); - if (Array.isArray(values) && nonEmptyTypes.length !== values.length) { + if (Array.isArray(values) && nonEmptyInputs.length !== values.length) { shallowCopyValues.length = this.jsonFn.inputs.length; shallowCopyValues.fill(undefined as unknown as InputValue, values.length); } - const coders = nonEmptyTypes.map((type) => AbiCoder.getCoder(this.jsonAbi, type)); + const coders = nonEmptyInputs.map((t) => AbiCoder.getCoder(this.jsonAbi, t)); const coder = new TupleCoder(coders); const results: Uint8ArrayWithDynamicData = coder.encode(shallowCopyValues); @@ -159,11 +107,11 @@ export class FunctionFragment< decodeArguments(data: BytesLike) { const bytes = arrayify(data); - const nonEmptyTypes = this.jsonFn.inputs.filter( + const nonEmptyInputs = this.jsonFn.inputs.filter( (x) => findOrThrow(this.jsonAbi.types, (t) => t.typeId === x.type).type !== '()' ); - if (nonEmptyTypes.length === 0) { + if (nonEmptyInputs.length === 0) { // The VM is current return 0x0000000000000000, but we should treat it as undefined / void if (bytes.length === 0) return undefined; @@ -173,19 +121,19 @@ export class FunctionFragment< { count: { types: this.jsonFn.inputs.length, - nonEmptyTypes: nonEmptyTypes.length, + nonEmptyInputs: nonEmptyInputs.length, values: bytes.length, }, value: { args: this.jsonFn.inputs, - nonEmptyTypes, + nonEmptyInputs, values: bytes, }, } ); } - const result = nonEmptyTypes.reduce( + const result = nonEmptyInputs.reduce( (obj: { decoded: unknown[]; offset: number }, input, currentIndex) => { const coder = AbiCoder.getCoder(this.jsonAbi, input); if (currentIndex === 0) { diff --git a/packages/abi-coder/src/interface.ts b/packages/abi-coder/src/interface.ts index 67c7cf92d9a..5f9ede3fb03 100644 --- a/packages/abi-coder/src/interface.ts +++ b/packages/abi-coder/src/interface.ts @@ -24,7 +24,7 @@ export class Interface { we're interacting with. */ private externalLoggedTypes: Record; - jsonAbi: TAbi; + readonly jsonAbi: TAbi; constructor(jsonAbi: TAbi) { this.jsonAbi = jsonAbi; @@ -32,10 +32,10 @@ export class Interface { this.externalLoggedTypes = {}; this.functions = Object.fromEntries( - jsonAbi.functions.map((x) => [x.name, new FunctionFragment(jsonAbi, x.name)]) + this.jsonAbi.functions.map((x) => [x.name, new FunctionFragment(this.jsonAbi, x.name)]) ); - this.configurables = Object.fromEntries(jsonAbi.configurables.map((x) => [x.name, x])); + this.configurables = Object.fromEntries(this.jsonAbi.configurables.map((x) => [x.name, x])); } /** diff --git a/packages/abi-coder/src/resolved-abi-type.ts b/packages/abi-coder/src/resolved-abi-type.ts new file mode 100644 index 00000000000..c0de96901b4 --- /dev/null +++ b/packages/abi-coder/src/resolved-abi-type.ts @@ -0,0 +1,179 @@ +import { Logger } from '@ethersproject/logger'; +import { versions } from '@fuel-ts/versions'; + +import { arrayRegEx, enumRegEx, genericRegEx, stringRegEx, structRegEx } from './constants'; +import type { JsonAbi, JsonAbiArgument } from './json-abi'; +import { findOrThrow } from './utilities'; + +const logger = new Logger(versions.FUELS); + +export class ResolvedAbiType { + readonly abi: JsonAbi; + name: string; + readonly type: string; + readonly originalTypeArguments: readonly JsonAbiArgument[] | null; + readonly components: readonly ResolvedAbiType[] | null; + + constructor(abi: JsonAbi, argument: JsonAbiArgument) { + this.abi = abi; + const type = findOrThrow( + abi.types, + (t) => t.typeId === argument.type, + () => + logger.throwArgumentError('Type does not exist in the provided abi', 'type', { + argument, + abi: this.abi, + }) + ); + this.name = argument.name; + + this.type = type.type; + this.originalTypeArguments = argument.typeArguments; + this.components = ResolvedAbiType.getResolvedGenericComponents( + abi, + argument, + type.components, + type.typeParameters ?? ResolvedAbiType.getImplicitGenericTypeParameters(abi, type.components) + ); + } + + private static getResolvedGenericComponents( + abi: JsonAbi, + arg: JsonAbiArgument, + components: readonly JsonAbiArgument[] | null, + typeParameters: readonly number[] | null + ) { + if (components === null) return null; + if (typeParameters === null || typeParameters.length === 0) + return components.map((c) => new ResolvedAbiType(abi, c)); + + const typeParametersAndArgsMap = typeParameters.reduce( + (obj, typeParameter, typeParameterIndex) => { + const o: Record = { ...obj }; + o[typeParameter] = structuredClone(arg.typeArguments?.[typeParameterIndex]); + return o; + }, + {} as Record + ); + + const resolvedComponents = this.resolveGenericArgTypes( + abi, + components, + typeParametersAndArgsMap + ); + + return resolvedComponents.map((c) => new ResolvedAbiType(abi, c)); + } + + private static resolveGenericArgTypes( + abi: JsonAbi, + args: readonly JsonAbiArgument[], + typeParametersAndArgsMap: Record + ): readonly JsonAbiArgument[] { + return args.map((arg) => { + if (typeParametersAndArgsMap[arg.type] !== undefined) { + return { + ...typeParametersAndArgsMap[arg.type], + name: arg.name, + }; + } + + if (arg.typeArguments) { + return { + ...structuredClone(arg), + typeArguments: this.resolveGenericArgTypes( + abi, + arg.typeArguments, + typeParametersAndArgsMap + ), + }; + } + + const argType = findOrThrow(abi.types, (t) => t.typeId === arg.type); + const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components); + + if (implicitTypeParameters && implicitTypeParameters.length > 0) { + return { + ...structuredClone(arg), + typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp]), + }; + } + + return arg; + }); + } + + private static getImplicitGenericTypeParameters( + abi: JsonAbi, + args: readonly JsonAbiArgument[] | null, + implicitGenericParametersParam?: number[] + ) { + if (!Array.isArray(args)) return null; + + const implicitGenericParameters: number[] = implicitGenericParametersParam ?? []; + + args.forEach((a) => { + const argType = findOrThrow(abi.types, (t) => t.typeId === a.type); + + if (genericRegEx.test(argType.type)) { + implicitGenericParameters.push(argType.typeId); + return; + } + + if (!Array.isArray(a.typeArguments)) return; + this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters); + }); + + return implicitGenericParameters.length > 0 ? implicitGenericParameters : null; + } + + getSignature(): string { + const prefix = this.getArgSignaturePrefix(); + const content = this.getArgSignatureContent(); + + return `${prefix}${content}`; + } + + private getArgSignaturePrefix(): string { + const structMatch = structRegEx.test(this.type); + if (structMatch) return 's'; + + const arrayMatch = arrayRegEx.test(this.type); + if (arrayMatch) return 'a'; + + const enumMatch = enumRegEx.test(this.type); + if (enumMatch) return 'e'; + + return ''; + } + + private getArgSignatureContent(): string { + if (this.type === 'raw untyped ptr') { + return 'rawptr'; + } + + const strMatch = stringRegEx.exec(this.type)?.groups; + if (strMatch) { + return `str[${strMatch.length}]`; + } + + if (this.components === null) return this.type; + + const arrayMatch = arrayRegEx.exec(this.type)?.groups; + + if (arrayMatch) { + return `[${this.components[0].getSignature()};${arrayMatch.length}]`; + } + + const typeArgumentsSignature = + this.originalTypeArguments !== null + ? `<${this.originalTypeArguments + .map((a) => new ResolvedAbiType(this.abi, a).getSignature()) + .join(',')}>` + : ''; + + const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(',')})`; + + return `${typeArgumentsSignature}${componentsSignature}`; + } +} diff --git a/packages/abi-coder/test/fixtures/exhaustive-examples-abi.ts b/packages/abi-coder/test/fixtures/exhaustive-examples-abi.ts index 79accdee452..59c3ce9bf06 100644 --- a/packages/abi-coder/test/fixtures/exhaustive-examples-abi.ts +++ b/packages/abi-coder/test/fixtures/exhaustive-examples-abi.ts @@ -12,12 +12,12 @@ export const exhaustiveExamplesAbi = { components: [ { name: '__tuple_element', - type: 34, + type: 35, typeArguments: null, }, { name: '__tuple_element', - type: 18, + type: 19, typeArguments: null, }, ], @@ -29,12 +29,12 @@ export const exhaustiveExamplesAbi = { components: [ { name: '__tuple_element', - type: 28, + type: 29, typeArguments: null, }, { name: '__tuple_element', - type: 29, + type: 30, typeArguments: null, }, ], @@ -46,12 +46,12 @@ export const exhaustiveExamplesAbi = { components: [ { name: '__tuple_element', - type: 18, + type: 19, typeArguments: null, }, { name: '__tuple_element', - type: 50, + type: 53, typeArguments: null, }, ], @@ -63,27 +63,27 @@ export const exhaustiveExamplesAbi = { components: [ { name: '__tuple_element', - type: 51, + type: 54, typeArguments: null, }, { name: '__tuple_element', - type: 42, + type: 45, typeArguments: [ { name: '', - type: 43, + type: 46, typeArguments: [ { name: '', - type: 50, + type: 53, typeArguments: null, }, ], }, { name: '', - type: 32, + type: 33, typeArguments: null, }, ], @@ -97,36 +97,36 @@ export const exhaustiveExamplesAbi = { components: [ { name: '__tuple_element', - type: 51, + type: 54, typeArguments: null, }, { name: '__tuple_element', - type: 18, + type: 19, typeArguments: null, }, { name: '__tuple_element', - type: 12, + type: 13, typeArguments: null, }, { name: '__tuple_element', - type: 33, + type: 34, typeArguments: null, }, { name: '__tuple_element', - type: 42, + type: 45, typeArguments: [ { name: '', - type: 51, + type: 54, typeArguments: null, }, { name: '', - type: 18, + type: 19, typeArguments: null, }, ], @@ -140,11 +140,11 @@ export const exhaustiveExamplesAbi = { components: [ { name: '__array_element', - type: 47, + type: 50, typeArguments: [ { name: '', - type: 49, + type: 52, typeArguments: null, }, ], @@ -158,7 +158,7 @@ export const exhaustiveExamplesAbi = { components: [ { name: '__array_element', - type: 17, + type: 18, typeArguments: null, }, ], @@ -170,7 +170,7 @@ export const exhaustiveExamplesAbi = { components: [ { name: '__array_element', - type: 32, + type: 33, typeArguments: null, }, ], @@ -182,7 +182,7 @@ export const exhaustiveExamplesAbi = { components: [ { name: '__array_element', - type: 39, + type: 41, typeArguments: null, }, ], @@ -194,7 +194,7 @@ export const exhaustiveExamplesAbi = { components: [ { name: '__array_element', - type: 41, + type: 44, typeArguments: null, }, ], @@ -206,8 +206,19 @@ export const exhaustiveExamplesAbi = { components: [ { name: '__array_element', - type: 17, - typeArguments: null, + type: 42, + typeArguments: [ + { + name: '', + type: 30, + typeArguments: null, + }, + { + name: '', + type: 54, + typeArguments: null, + }, + ], }, ], typeParameters: null, @@ -218,7 +229,7 @@ export const exhaustiveExamplesAbi = { components: [ { name: '__array_element', - type: 49, + type: 18, typeArguments: null, }, ], @@ -230,7 +241,7 @@ export const exhaustiveExamplesAbi = { components: [ { name: '__array_element', - type: 28, + type: 52, typeArguments: null, }, ], @@ -242,7 +253,7 @@ export const exhaustiveExamplesAbi = { components: [ { name: '__array_element', - type: 32, + type: 29, typeArguments: null, }, ], @@ -250,11 +261,11 @@ export const exhaustiveExamplesAbi = { }, { typeId: 15, - type: '[_; 4]', + type: '[_; 3]', components: [ { name: '__array_element', - type: 51, + type: 33, typeArguments: null, }, ], @@ -266,16 +277,28 @@ export const exhaustiveExamplesAbi = { components: [ { name: '__array_element', - type: 36, + type: 54, + typeArguments: null, + }, + ], + typeParameters: null, + }, + { + typeId: 17, + type: '[_; 4]', + components: [ + { + name: '__array_element', + type: 38, typeArguments: [ { name: '', - type: 50, + type: 53, typeArguments: null, }, { name: '', - type: 18, + type: 19, typeArguments: null, }, ], @@ -284,19 +307,19 @@ export const exhaustiveExamplesAbi = { typeParameters: null, }, { - typeId: 17, + typeId: 18, type: 'b256', components: null, typeParameters: null, }, { - typeId: 18, + typeId: 19, type: 'bool', components: null, typeParameters: null, }, { - typeId: 19, + typeId: 20, type: 'enum Color', components: [ { @@ -328,65 +351,65 @@ export const exhaustiveExamplesAbi = { typeParameters: null, }, { - typeId: 20, + typeId: 21, type: 'enum EnumWithBuiltinType', components: [ { name: 'a', - type: 18, + type: 19, typeArguments: null, }, { name: 'b', - type: 50, + type: 53, typeArguments: null, }, ], typeParameters: null, }, { - typeId: 21, + typeId: 22, type: 'enum EnumWithGeneric', components: [ { name: 'VariantOne', - type: 28, + type: 29, typeArguments: null, }, { name: 'VariantTwo', - type: 50, + type: 53, typeArguments: null, }, ], - typeParameters: [28], + typeParameters: [29], }, { - typeId: 22, + typeId: 23, type: 'enum EnumWithStructs', components: [ { name: 'a', - type: 19, + type: 20, typeArguments: null, }, { name: 'b', - type: 41, + type: 44, typeArguments: null, }, { name: 'c', - type: 42, + type: 45, typeArguments: [ { name: '', - type: 50, + type: 53, typeArguments: null, }, { name: '', - type: 41, + type: 44, typeArguments: null, }, ], @@ -395,21 +418,21 @@ export const exhaustiveExamplesAbi = { typeParameters: null, }, { - typeId: 23, + typeId: 24, type: 'enum EnumWithVector', components: [ { name: 'num', - type: 51, + type: 54, typeArguments: null, }, { name: 'vec', - type: 47, + type: 50, typeArguments: [ { name: '', - type: 51, + type: 54, typeArguments: null, }, ], @@ -418,46 +441,46 @@ export const exhaustiveExamplesAbi = { typeParameters: null, }, { - typeId: 24, + typeId: 25, type: 'enum MyEnum', components: [ { name: 'Foo', - type: 50, + type: 53, typeArguments: null, }, { name: 'Bar', - type: 18, + type: 19, typeArguments: null, }, { name: 'Din', - type: 18, + type: 19, typeArguments: null, }, ], typeParameters: null, }, { - typeId: 25, + typeId: 26, type: 'enum MyGenericEnum', components: [ { name: 'Foo', - type: 50, + type: 53, typeArguments: null, }, { name: 'Bar', - type: 18, + type: 19, typeArguments: null, }, ], - typeParameters: [30], + typeParameters: [31], }, { - typeId: 26, + typeId: 27, type: 'enum Option', components: [ { @@ -467,73 +490,85 @@ export const exhaustiveExamplesAbi = { }, { name: 'Some', - type: 28, + type: 29, typeArguments: null, }, ], - typeParameters: [28], + typeParameters: [29], }, { - typeId: 27, + typeId: 28, type: 'enum TestEnum', components: [ { name: 'Value', - type: 18, + type: 19, typeArguments: null, }, { name: 'Data', - type: 18, + type: 19, typeArguments: null, }, ], typeParameters: null, }, { - typeId: 28, + typeId: 29, type: 'generic T', components: null, typeParameters: null, }, { - typeId: 29, + typeId: 30, type: 'generic U', components: null, typeParameters: null, }, { - typeId: 30, + typeId: 31, type: 'generic V', components: null, typeParameters: null, }, { - typeId: 31, + typeId: 32, type: 'raw untyped ptr', components: null, typeParameters: null, }, { - typeId: 32, + typeId: 33, type: 'str[3]', components: null, typeParameters: null, }, { - typeId: 33, + typeId: 34, type: 'str[4]', components: null, typeParameters: null, }, { - typeId: 34, + typeId: 35, type: 'str[5]', components: null, typeParameters: null, }, { - typeId: 35, + typeId: 36, + type: 'struct ArrWithGenericStruct', + components: [ + { + name: 'a', + type: 11, + typeArguments: null, + }, + ], + typeParameters: [30], + }, + { + typeId: 37, type: 'struct B512', components: [ { @@ -545,144 +580,183 @@ export const exhaustiveExamplesAbi = { typeParameters: null, }, { - typeId: 36, + typeId: 38, type: 'struct MyGenericStruct', components: [ { name: 'bim', - type: 28, + type: 29, typeArguments: null, }, { name: 'bam', - type: 25, + type: 26, typeArguments: [ { name: '', - type: 50, + type: 53, typeArguments: null, }, ], }, ], - typeParameters: [28, 29], + typeParameters: [29, 30], }, { - typeId: 37, + typeId: 39, type: 'struct MyOtherStruct', components: [ { name: 'bom', - type: 50, + type: 53, typeArguments: null, }, ], typeParameters: null, }, { - typeId: 38, + typeId: 40, type: 'struct MyStruct', components: [ { name: 'dummy_a', - type: 18, + type: 19, typeArguments: null, }, { name: 'dummy_b', - type: 50, + type: 53, typeArguments: null, }, ], typeParameters: null, }, { - typeId: 39, + typeId: 41, type: 'struct MyStructWithEnum', components: [ { name: 'bim', - type: 32, + type: 33, typeArguments: null, }, { name: 'bam', - type: 24, + type: 25, typeArguments: null, }, ], typeParameters: null, }, { - typeId: 40, + typeId: 42, + type: 'struct MyStructWithGeneric', + components: [ + { + name: 'bim', + type: 29, + typeArguments: null, + }, + { + name: 'bam', + type: 46, + typeArguments: [ + { + name: '', + type: 30, + typeArguments: null, + }, + ], + }, + { + name: 'bom', + type: 45, + typeArguments: [ + { + name: '', + type: 30, + typeArguments: null, + }, + { + name: '', + type: 29, + typeArguments: null, + }, + ], + }, + ], + typeParameters: [29, 30], + }, + { + typeId: 43, type: 'struct RawVec', components: [ { name: 'ptr', - type: 31, + type: 32, typeArguments: null, }, { name: 'cap', - type: 50, + type: 53, typeArguments: null, }, ], - typeParameters: [28], + typeParameters: [29], }, { - typeId: 41, + typeId: 44, type: 'struct SimpleStruct', components: [ { name: 'a', - type: 18, + type: 19, typeArguments: null, }, { name: 'b', - type: 49, + type: 52, typeArguments: null, }, ], typeParameters: null, }, { - typeId: 42, + typeId: 45, type: 'struct StructA', components: [ { name: 'propA1', - type: 28, + type: 29, typeArguments: null, }, { name: 'propA2', - type: 29, + type: 30, typeArguments: null, }, ], - typeParameters: [28, 29], + typeParameters: [29, 30], }, { - typeId: 43, + typeId: 46, type: 'struct StructB', components: [ { name: 'propB1', - type: 28, + type: 29, typeArguments: null, }, ], - typeParameters: [28], + typeParameters: [29], }, { - typeId: 44, + typeId: 47, type: 'struct StructWithImplicitGenerics', components: [ { name: 'arr', - type: 13, + type: 14, typeArguments: null, }, { @@ -691,24 +765,24 @@ export const exhaustiveExamplesAbi = { typeArguments: null, }, ], - typeParameters: [28, 29], + typeParameters: [29, 30], }, { - typeId: 45, + typeId: 48, type: 'struct StructWithVector', components: [ { name: 'num', - type: 51, + type: 54, typeArguments: null, }, { name: 'vec', - type: 47, + type: 50, typeArguments: [ { name: '', - type: 51, + type: 54, typeArguments: null, }, ], @@ -717,65 +791,65 @@ export const exhaustiveExamplesAbi = { typeParameters: null, }, { - typeId: 46, + typeId: 49, type: 'struct Test', components: [ { name: 'foo', - type: 50, + type: 53, typeArguments: null, }, { name: 'bar', - type: 50, + type: 53, typeArguments: null, }, ], typeParameters: null, }, { - typeId: 47, + typeId: 50, type: 'struct Vec', components: [ { name: 'buf', - type: 40, + type: 43, typeArguments: [ { name: '', - type: 28, + type: 29, typeArguments: null, }, ], }, { name: 'len', - type: 50, + type: 53, typeArguments: null, }, ], - typeParameters: [28], + typeParameters: [29], }, { - typeId: 48, + typeId: 51, type: 'u16', components: null, typeParameters: null, }, { - typeId: 49, + typeId: 52, type: 'u32', components: null, typeParameters: null, }, { - typeId: 50, + typeId: 53, type: 'u64', components: null, typeParameters: null, }, { - typeId: 51, + typeId: 54, type: 'u8', components: null, typeParameters: null, @@ -786,16 +860,16 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'a', - type: 41, + type: 44, typeArguments: null, }, { name: 'x', - type: 47, + type: 50, typeArguments: [ { name: '', - type: 51, + type: 54, typeArguments: null, }, ], @@ -804,7 +878,7 @@ export const exhaustiveExamplesAbi = { name: 'arg_then_vector_u8', output: { name: '', - type: 51, + type: 54, typeArguments: null, }, attributes: null, @@ -820,7 +894,7 @@ export const exhaustiveExamplesAbi = { name: 'array_of_structs', output: { name: '', - type: 32, + type: 33, typeArguments: null, }, attributes: null, @@ -829,14 +903,14 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'x', - type: 15, + type: 16, typeArguments: null, }, ], name: 'array_simple', output: { name: '', - type: 51, + type: 54, typeArguments: null, }, attributes: null, @@ -852,7 +926,7 @@ export const exhaustiveExamplesAbi = { name: 'array_struct', output: { name: '', - type: 51, + type: 54, typeArguments: null, }, attributes: null, @@ -861,14 +935,36 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'arg', - type: 17, + type: 36, + typeArguments: [ + { + name: '', + type: 18, + typeArguments: null, + }, + ], + }, + ], + name: 'array_with_generic_struct', + output: { + name: '', + type: 0, + typeArguments: null, + }, + attributes: null, + }, + { + inputs: [ + { + name: 'arg', + type: 18, typeArguments: null, }, ], name: 'b_256', output: { name: '', - type: 17, + type: 18, typeArguments: null, }, attributes: null, @@ -877,14 +973,14 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'arg', - type: 35, + type: 37, typeArguments: null, }, ], name: 'b_512', output: { name: '', - type: 35, + type: 37, typeArguments: null, }, attributes: null, @@ -893,14 +989,14 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'arg', - type: 18, + type: 19, typeArguments: null, }, ], name: 'boolean', output: { name: '', - type: 18, + type: 19, typeArguments: null, }, attributes: null, @@ -909,23 +1005,23 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'arg1', - type: 36, + type: 38, typeArguments: [ { name: '', - type: 11, + type: 12, typeArguments: null, }, { name: '', - type: 51, + type: 54, typeArguments: null, }, ], }, { name: 'arg2', - type: 16, + type: 17, typeArguments: null, }, { @@ -935,7 +1031,7 @@ export const exhaustiveExamplesAbi = { }, { name: 'arg4', - type: 37, + type: 39, typeArguments: null, }, ], @@ -951,14 +1047,14 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'arg', - type: 50, + type: 53, typeArguments: null, }, ], name: 'entry_one', output: { name: '', - type: 50, + type: 53, typeArguments: null, }, attributes: null, @@ -967,14 +1063,14 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'x', - type: 19, + type: 20, typeArguments: null, }, ], name: 'enum_simple', output: { name: '', - type: 51, + type: 54, typeArguments: null, }, attributes: null, @@ -983,14 +1079,14 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'x', - type: 20, + type: 21, typeArguments: null, }, ], name: 'enum_with_builtin_type', output: { name: '', - type: 51, + type: 54, typeArguments: null, }, attributes: null, @@ -999,14 +1095,14 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'x', - type: 22, + type: 23, typeArguments: null, }, ], name: 'enum_with_structs', output: { name: '', - type: 51, + type: 54, typeArguments: null, }, attributes: null, @@ -1015,19 +1111,19 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'my_u64', - type: 50, + type: 53, typeArguments: null, }, { name: 'my_struct', - type: 38, + type: 40, typeArguments: null, }, ], name: 'my_struct', output: { name: '', - type: 50, + type: 53, typeArguments: null, }, attributes: null, @@ -1036,11 +1132,11 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'x', - type: 26, + type: 27, typeArguments: [ { name: '', - type: 51, + type: 54, typeArguments: null, }, ], @@ -1049,7 +1145,7 @@ export const exhaustiveExamplesAbi = { name: 'option_u8', output: { name: '', - type: 51, + type: 54, typeArguments: null, }, attributes: null, @@ -1068,11 +1164,11 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'arg', - type: 47, + type: 50, typeArguments: [ { name: '', - type: 51, + type: 54, typeArguments: null, }, ], @@ -1090,14 +1186,14 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'arg', - type: 34, + type: 35, typeArguments: null, }, ], name: 'string', output: { name: '', - type: 34, + type: 35, typeArguments: null, }, attributes: null, @@ -1106,11 +1202,11 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'x', - type: 43, + type: 46, typeArguments: [ { name: '', - type: 51, + type: 54, typeArguments: null, }, ], @@ -1119,7 +1215,7 @@ export const exhaustiveExamplesAbi = { name: 'struct_generic_simple', output: { name: '', - type: 51, + type: 54, typeArguments: null, }, attributes: null, @@ -1128,14 +1224,14 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'x', - type: 41, + type: 44, typeArguments: null, }, ], name: 'struct_simple', output: { name: '', - type: 51, + type: 54, typeArguments: null, }, attributes: null, @@ -1144,16 +1240,16 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'arg', - type: 44, + type: 47, typeArguments: [ { name: '', - type: 17, + type: 18, typeArguments: null, }, { name: '', - type: 51, + type: 54, typeArguments: null, }, ], @@ -1162,7 +1258,7 @@ export const exhaustiveExamplesAbi = { name: 'struct_with_implicitGenerics', output: { name: '', - type: 51, + type: 54, typeArguments: null, }, attributes: null, @@ -1171,7 +1267,7 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'x', - type: 43, + type: 46, typeArguments: [ { name: '', @@ -1184,7 +1280,7 @@ export const exhaustiveExamplesAbi = { name: 'struct_with_tuple', output: { name: '', - type: 51, + type: 54, typeArguments: null, }, attributes: null, @@ -1193,19 +1289,19 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'a', - type: 50, + type: 53, typeArguments: null, }, { name: 'b', - type: 50, + type: 53, typeArguments: null, }, ], name: 'sum', output: { name: '', - type: 50, + type: 53, typeArguments: null, }, attributes: null, @@ -1214,14 +1310,14 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'test', - type: 46, + type: 49, typeArguments: null, }, ], name: 'sum_test', output: { name: '', - type: 50, + type: 53, typeArguments: null, }, attributes: null, @@ -1230,14 +1326,14 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'enum_arg', - type: 27, + type: 28, typeArguments: null, }, ], name: 'take_enum', output: { name: '', - type: 18, + type: 19, typeArguments: null, }, attributes: null, @@ -1246,7 +1342,7 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'arg', - type: 14, + type: 15, typeArguments: null, }, ], @@ -1263,7 +1359,7 @@ export const exhaustiveExamplesAbi = { name: 'test_function', output: { name: '', - type: 18, + type: 19, typeArguments: null, }, attributes: null, @@ -1279,7 +1375,7 @@ export const exhaustiveExamplesAbi = { name: 'tuple_as_param', output: { name: '', - type: 51, + type: 54, typeArguments: null, }, attributes: null, @@ -1288,19 +1384,19 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'arg1', - type: 17, + type: 18, typeArguments: null, }, { name: 'arg2', - type: 18, + type: 19, typeArguments: null, }, ], name: 'two_args', output: { name: '', - type: 18, + type: 19, typeArguments: null, }, attributes: null, @@ -1309,22 +1405,22 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'x', - type: 47, + type: 50, typeArguments: [ { name: '', - type: 51, + type: 54, typeArguments: null, }, ], }, { name: 'y', - type: 47, + type: 50, typeArguments: [ { name: '', - type: 51, + type: 54, typeArguments: null, }, ], @@ -1333,7 +1429,7 @@ export const exhaustiveExamplesAbi = { name: 'two_u8_vectors', output: { name: '', - type: 51, + type: 54, typeArguments: null, }, attributes: null, @@ -1342,38 +1438,38 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'x', - type: 49, + type: 52, typeArguments: null, }, { name: 'y', - type: 47, + type: 50, typeArguments: [ { name: '', - type: 50, + type: 53, typeArguments: null, }, ], }, { name: 'z', - type: 47, + type: 50, typeArguments: [ { name: '', - type: 50, + type: 53, typeArguments: null, }, ], }, { name: 'q', - type: 47, + type: 50, typeArguments: [ { name: '', - type: 50, + type: 53, typeArguments: null, }, ], @@ -1382,7 +1478,7 @@ export const exhaustiveExamplesAbi = { name: 'u32_then_three_vectors_u64', output: { name: '', - type: 51, + type: 54, typeArguments: null, }, attributes: null, @@ -1391,14 +1487,14 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'arg', - type: 48, + type: 51, typeArguments: null, }, ], name: 'u_16', output: { name: '', - type: 48, + type: 51, typeArguments: null, }, attributes: null, @@ -1407,14 +1503,14 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'arg', - type: 49, + type: 52, typeArguments: null, }, ], name: 'u_32', output: { name: '', - type: 49, + type: 52, typeArguments: null, }, attributes: null, @@ -1423,14 +1519,14 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'arg', - type: 50, + type: 53, typeArguments: null, }, ], name: 'u_64', output: { name: '', - type: 50, + type: 53, typeArguments: null, }, attributes: null, @@ -1439,14 +1535,14 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'arg', - type: 51, + type: 54, typeArguments: null, }, ], name: 'u_8', output: { name: '', - type: 51, + type: 54, typeArguments: null, }, attributes: null, @@ -1455,11 +1551,11 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'x', - type: 47, + type: 50, typeArguments: [ { name: '', - type: 18, + type: 19, typeArguments: null, }, ], @@ -1468,7 +1564,7 @@ export const exhaustiveExamplesAbi = { name: 'vector_boolean', output: { name: '', - type: 51, + type: 54, typeArguments: null, }, attributes: null, @@ -1493,7 +1589,7 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'arg', - type: 23, + type: 24, typeArguments: null, }, ], @@ -1509,7 +1605,7 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'arg', - type: 45, + type: 48, typeArguments: null, }, ], @@ -1525,15 +1621,15 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'arg', - type: 47, + type: 50, typeArguments: [ { name: '', - type: 47, + type: 50, typeArguments: [ { name: '', - type: 49, + type: 52, typeArguments: null, }, ], @@ -1553,11 +1649,11 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'x', - type: 47, + type: 50, typeArguments: [ { name: '', - type: 51, + type: 54, typeArguments: null, }, ], @@ -1566,7 +1662,7 @@ export const exhaustiveExamplesAbi = { name: 'vector_u8', output: { name: '', - type: 51, + type: 54, typeArguments: null, }, attributes: null, @@ -1575,25 +1671,25 @@ export const exhaustiveExamplesAbi = { inputs: [ { name: 'x', - type: 47, + type: 50, typeArguments: [ { name: '', - type: 51, + type: 54, typeArguments: null, }, ], }, { name: 'y', - type: 17, + type: 18, typeArguments: null, }, ], name: 'vector_u8_then_arg', output: { name: '', - type: 51, + type: 54, typeArguments: null, }, attributes: null, @@ -1606,57 +1702,57 @@ export const exhaustiveExamplesAbi = { name: 'U8', configurableType: { name: '', - type: 51, + type: 54, typeArguments: null, }, - offset: 1272, + offset: 1296, }, { name: 'BOOL', configurableType: { name: '', - type: 18, + type: 19, typeArguments: null, }, - offset: 1280, + offset: 1304, }, { name: 'ARRAY', configurableType: { name: '', - type: 12, + type: 13, typeArguments: null, }, - offset: 1288, + offset: 1312, }, { name: 'STR_4', configurableType: { name: '', - type: 33, + type: 34, typeArguments: null, }, - offset: 1312, + offset: 1336, }, { name: 'STRUCT', configurableType: { name: '', - type: 42, + type: 45, typeArguments: [ { name: '', - type: 51, + type: 54, typeArguments: null, }, { name: '', - type: 18, + type: 19, typeArguments: null, }, ], }, - offset: 1320, + offset: 1344, }, ], } as const; diff --git a/packages/abi-coder/test/interface.test.ts b/packages/abi-coder/test/interface.test.ts index 5904ead1b28..c034faa29dd 100644 --- a/packages/abi-coder/test/interface.test.ts +++ b/packages/abi-coder/test/interface.test.ts @@ -375,6 +375,45 @@ describe('Abi interface', () => { EMPTY_U8_ARRAY.slice().fill(2, 7), ], }, + { + fn: exhaustiveExamplesInterface.functions.array_with_generic_struct, + title: '[array] with generic struct', + value: [ + { + a: [ + { + bim: B256_DECODED, + bam: { propB1: U8_MAX }, + bom: { propA1: U8_MAX, propA2: B256_DECODED }, + }, + { + bim: B256_DECODED, + bam: { propB1: 0 }, + bom: { propA1: U8_MAX, propA2: B256_DECODED }, + }, + { + bim: B256_DECODED, + bam: { propB1: U8_MAX }, + bom: { propA1: U8_MAX, propA2: B256_DECODED }, + }, + ], + }, + ], + encodedValue: [ + B256_ENCODED, + U8_MAX_ENCODED, + U8_MAX_ENCODED, + B256_ENCODED, + B256_ENCODED, + EMPTY_U8_ARRAY, + U8_MAX_ENCODED, + B256_ENCODED, + B256_ENCODED, + U8_MAX_ENCODED, + U8_MAX_ENCODED, + B256_ENCODED, + ], + }, { fn: exhaustiveExamplesInterface.functions.vector_boolean, title: '[vector] boolean', @@ -777,8 +816,8 @@ describe('Abi interface', () => { describe('abi types', () => { it('should return the correct type when it exists', () => { - const abiType = exhaustiveExamplesInterface.getTypeById(22); - expect(abiType.type).toEqual('enum EnumWithStructs'); + const abiType = exhaustiveExamplesInterface.getTypeById(0); + expect(abiType.type).toEqual('()'); expect(abiType.components).toBeDefined(); expect(abiType.typeParameters).toBeNull(); }); diff --git a/packages/abi-coder/test/sway-projects/exhaustive-examples/src/main.sw b/packages/abi-coder/test/sway-projects/exhaustive-examples/src/main.sw index 4120ec5963a..52411058874 100644 --- a/packages/abi-coder/test/sway-projects/exhaustive-examples/src/main.sw +++ b/packages/abi-coder/test/sway-projects/exhaustive-examples/src/main.sw @@ -23,7 +23,7 @@ struct StructA { propA2: U, } -struct StructB { +struct StructB{ propB1: T, } @@ -108,6 +108,17 @@ struct StructWithVector { vec: Vec } +struct MyStructWithGeneric { + bim: T, + bam: StructB, + bom: StructA +} + + +struct ArrWithGenericStruct { + a: [MyStructWithGeneric; 3] +} + abi MyContract { fn test_function() -> bool; fn u_8(arg: u8) -> u8; @@ -158,6 +169,8 @@ abi MyContract { fn vector_inside_array(arg: [Vec; 1]); fn vector_inside_enum(arg: EnumWithVector); fn vector_inside_struct(arg: StructWithVector); + + fn array_with_generic_struct(arg: ArrWithGenericStruct); } impl MyContract for Contract { @@ -214,5 +227,5 @@ impl MyContract for Contract { fn vector_inside_array(arg: [Vec; 1]) {} fn vector_inside_enum(arg: EnumWithVector) {} fn vector_inside_struct(arg: StructWithVector) {} - + fn array_with_generic_struct(arg: ArrWithGenericStruct) {} }