Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: adding abi transpiler #2856

Merged
merged 80 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
7585782
Upgrading forc to temp branch
arboleya Jul 29, 2024
bb3a168
Adding ABI transpiler and integrating it with related areas
arboleya Jul 29, 2024
d08b334
Updating typegen fixtures
arboleya Jul 29, 2024
81ec4cc
Fixing broken typegen tests; updating outdated IDs
arboleya Jul 29, 2024
3caff6d
Re-instating the order
arboleya Jul 29, 2024
5816eaf
Loading forc projects the standard and proper way
arboleya Jul 29, 2024
f04bc3f
Updating coder’s types, regexes, and fixing type matching everywhere
arboleya Jul 29, 2024
a34f676
Updating test using callpath-based naming for Option
arboleya Jul 29, 2024
bf760a2
Fixing test, intercepting ABI loading so it can be transpiled
arboleya Jul 29, 2024
27a1e61
Adding changeset
arboleya Jul 29, 2024
05c45be
Adjusting changeset
arboleya Jul 29, 2024
2a00ce3
Excluding sway-repo source files in `forc:check` script
arboleya Jul 29, 2024
ddb3cfe
Ensuring branches are up to date before building
arboleya Jul 29, 2024
bdcf220
Building internal packages in `--release` mode
arboleya Jul 29, 2024
045adc8
Fixing directory path for new build target
arboleya Jul 29, 2024
7de6c06
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Jul 30, 2024
3b62ef4
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Jul 30, 2024
0b7d477
Merge branch 'master' into aa/feat/adding-abi-transpiler
petertonysmith94 Jul 30, 2024
45929ee
Merge branch 'master' into aa/feat/adding-abi-transpiler
petertonysmith94 Jul 30, 2024
188a5e2
Merge branch 'master' into aa/feat/adding-abi-transpiler
nedsalk Jul 30, 2024
fcfe0df
Merge branch 'master' into aa/feat/adding-abi-transpiler
nedsalk Jul 30, 2024
38973b1
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Jul 31, 2024
8198c53
Merging duplicated variables, standardizing terminologies
arboleya Jul 31, 2024
45f3ef2
Improving validation to handle strings / non-objects as well
arboleya Jul 31, 2024
fed8d3a
fix: option coder decoding incorrect value (#2870)
petertonysmith94 Jul 31, 2024
a42e859
Standardizing timeout limits across workflows
arboleya Jul 31, 2024
bc70ce0
Ignoring `sway-repo`in links check when building things from source
arboleya Jul 31, 2024
b4ee165
Fixing ignore path
arboleya Jul 31, 2024
7b4ce7b
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Jul 31, 2024
e0417bf
Stop deleting `concreteTypeId`, used in public API
arboleya Jul 31, 2024
d5ae163
Merge branch 'aa/feat/adding-abi-transpiler' of github.com:FuelLabs/f…
arboleya Jul 31, 2024
8d1795c
Update .changeset/odd-horses-cheer.md
arboleya Jul 31, 2024
a175a6f
Ignoring also `fuel-core-repo` for the same reasons as `sway-repo`
arboleya Jul 31, 2024
5626954
Update .changeset/odd-horses-cheer.md
arboleya Jul 31, 2024
67013cb
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Aug 1, 2024
306738f
Updating more fixtures
arboleya Aug 1, 2024
d9f9d30
Updating snippet
arboleya Aug 1, 2024
00e2b8e
Fixing random lint warning
arboleya Aug 1, 2024
a203ff6
Incrasing test timeout limit
arboleya Aug 1, 2024
e725b1d
Fixing ignored paths
arboleya Aug 1, 2024
942e5cc
chore!: internalize old `JsonAbi` format (#2862)
nedsalk Aug 5, 2024
5621ccf
Getting around non-null assertions
arboleya Aug 5, 2024
98a0c1a
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Aug 5, 2024
1e4996f
Adjusting changeset
arboleya Aug 5, 2024
265ee88
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Aug 6, 2024
4241143
Adjusting scripts
arboleya Aug 6, 2024
47f54f2
Updating template fixtures/snapshots
arboleya Aug 6, 2024
84d50b3
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Aug 6, 2024
e81dfde
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Aug 11, 2024
d2bb381
Triggering CI
arboleya Aug 11, 2024
0877d5e
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Aug 13, 2024
2c9d14f
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Aug 13, 2024
d4962de
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Aug 13, 2024
a1efe88
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Aug 13, 2024
d8f7d5c
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Aug 14, 2024
ac8f02d
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Aug 14, 2024
14c8505
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Aug 15, 2024
85b20ad
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Aug 15, 2024
6b75b30
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Aug 15, 2024
29d6ba3
The branch is gone - temporarily switching to `master`
arboleya Aug 16, 2024
48b0ab3
Temporarily patching sway std lib
arboleya Aug 16, 2024
dc054ff
Temporarily skipping problematic sway projects and related tests
arboleya Aug 16, 2024
76b9a9c
Lintfix - deprecations, types mismatch, and broken imports
arboleya Aug 16, 2024
d7a5100
DRYing test setup/teardown
arboleya Aug 16, 2024
e239137
Fixing broken tests
arboleya Aug 16, 2024
23e3e7e
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Aug 16, 2024
b97c944
Patching base library individually
arboleya Aug 17, 2024
b741c93
Unskipping problematic workspace members
arboleya Aug 17, 2024
f035e4c
Adjusting predicate data handling
arboleya Aug 17, 2024
b8451a3
Undoing undesired changed
arboleya Aug 17, 2024
b36d444
Adjuting more projects
arboleya Aug 17, 2024
d233464
Revert "Temporarily skipping problematic sway projects and related te…
arboleya Aug 17, 2024
5ae0e32
Formatting
arboleya Aug 17, 2024
edc3f34
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Aug 19, 2024
84954af
Revert "Temporarily patching sway std lib"
arboleya Aug 19, 2024
2d88c07
Revert "Patching base library individually"
arboleya Aug 19, 2024
bd174ca
Replacing sway `branch` by `0.63.0` version
arboleya Aug 19, 2024
28734a9
Update .changeset/odd-horses-cheer.md
arboleya Aug 19, 2024
7ef4e88
Merge branch 'master' into aa/feat/adding-abi-transpiler
arboleya Aug 19, 2024
f019cba
Updating forc version
arboleya Aug 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/odd-horses-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@fuel-ts/abi-typegen": patch
"@fuel-ts/abi-coder": patch
"@fuel-ts/versions": patch
"@fuel-ts/utils": patch
"@internal/forc": patch
arboleya marked this conversation as resolved.
Show resolved Hide resolved
---
arboleya marked this conversation as resolved.
Show resolved Hide resolved

feat: adding `abi` transpiler
arboleya marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 14 additions & 2 deletions apps/docs-snippets/src/guide/contracts/deploying-contracts.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { readFileSync } from 'fs';
import { readFileSync as originalReadFileSync } from 'fs';
import { Provider, FUEL_NETWORK_URL, Wallet, ContractFactory } from 'fuels';
import { join } from 'path';

import { DocSnippetProjectsEnum } from '../../../test/fixtures/forc-projects';
import {
DocSnippetProjectsEnum,
getDocsSnippetsForcProject,
} from '../../../test/fixtures/forc-projects';
import { getTestWallet } from '../../utils';

/**
Expand All @@ -13,6 +16,15 @@ describe(__filename, () => {
let projectsPath: string;
let contractName: string;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function readFileSync(path: string | Buffer, encoding?: BufferEncoding): any {
if (/-abi\.json/.test(path.toString())) {
const abi = getDocsSnippetsForcProject(DocSnippetProjectsEnum.ECHO_VALUES);
return JSON.stringify(abi.abiContents, null, 2).toString();
}
return originalReadFileSync(path, encoding);
}

beforeAll(async () => {
const wallet = await getTestWallet();
PRIVATE_KEY = wallet.privateKey;
Expand Down
2 changes: 1 addition & 1 deletion internal/forc/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.62.0
git:esdrubal/abi_changes
15 changes: 12 additions & 3 deletions internal/forc/lib/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,20 @@
const stdioOpts = { stdio: 'inherit' };

if (existsSync(swayRepoDir)) {
execSync(`cd ${swayRepoDir} && git fetch origin && git checkout ${branchName}`, stdioOpts);
execSync(`cd ${swayRepoDir} && cargo build`, stdioOpts);
execSync(
[
`cd ${swayRepoDir}`,
`git fetch origin`,
`git checkout ${branchName}`,
`git pull origin ${branchName}`,
].join('&&'),
Dismissed Show dismissed Hide dismissed
stdioOpts
);

execSync(`cd ${swayRepoDir} && cargo build --release`, stdioOpts);
Dismissed Show dismissed Hide dismissed
} else {
execSync(`git clone --branch ${branchName} ${swayRepoUrl} ${swayRepoDir}`, stdioOpts);
execSync(`cd ${swayRepoDir} && cargo build`, stdioOpts);
execSync(`cd ${swayRepoDir} && cargo build --release`, stdioOpts);
Fixed Show fixed Hide fixed
Dismissed Show dismissed Hide dismissed
}

const [from, to] = [swayRepoDebugDir, forcBinDirPath];
Expand Down
6 changes: 3 additions & 3 deletions internal/fuel-core/lib/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ export const buildFromGitBranch = (branchName) => {
const stdioOpts = { stdio: 'inherit' };

if (existsSync(fuelCoreRepoDir)) {
spawnSync('git', ['pull'], { cwd: fuelCoreRepoDir, ...stdioOpts });
spawnSync('git', ['checkout', branchName], { cwd: fuelCoreRepoDir, ...stdioOpts });
spawnSync('cargo', ['build'], { cwd: fuelCoreRepoDir, ...stdioOpts });
spawnSync('git', ['pull'], { cwd: fuelCoreRepoDir, ...stdioOpts });
spawnSync('cargo', ['build', '--release'], { cwd: fuelCoreRepoDir, ...stdioOpts });
} else {
spawnSync(
'git',
['clone', '--branch', branchName, fuelCoreRepoUrl, fuelCoreRepoDir],
stdioOpts
);
spawnSync('cargo', ['build'], { cwd: fuelCoreRepoDir, ...stdioOpts });
spawnSync('cargo', ['build', '--release'], { cwd: fuelCoreRepoDir, ...stdioOpts });
}

const [from, to] = [fuelCoreRepoDebugDir, fuelCoreBinDirPath];
Expand Down
4 changes: 2 additions & 2 deletions packages/abi-coder/src/FunctionFragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
JsonAbiFunctionAttribute,
} from './types/JsonAbi';
import type { EncodingVersion } from './utils/constants';
import { OPTION_CODER_TYPE } from './utils/constants';
import { optionCoderRegex } from './utils/constants';
import {
findFunctionByName,
findNonEmptyInputs,
Expand Down Expand Up @@ -96,7 +96,7 @@ export class FunctionFragment<

const inputTypes = inputs.map((input) => findTypeById(abi, input.type));
const optionalInputs = inputTypes.filter(
(x) => x.type === OPTION_CODER_TYPE || x.type === '()'
(x) => optionCoderRegex.test(x.type) || x.type === '()'
);
if (optionalInputs.length === inputTypes.length) {
return;
Expand Down
6 changes: 3 additions & 3 deletions packages/abi-coder/src/encoding/coders/EnumCoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { toNumber } from '@fuel-ts/math';
import { concat } from '@fuel-ts/utils';
import type { RequireExactlyOne } from 'type-fest';

import { OPTION_CODER_TYPE } from '../../utils/constants';
import { optionCoderRegex } from '../../utils/constants';
import { hasNestedOption } from '../../utils/utilities';

import type { TypesOfCoder } from './AbstractCoder';
Expand Down Expand Up @@ -39,13 +39,13 @@ export class EnumCoder<TCoders extends Record<string, Coder>> extends Coder<
this.coders = coders;
this.#caseIndexCoder = caseIndexCoder;
this.#encodedValueSize = encodedValueSize;
this.#shouldValidateLength = !(this.type === OPTION_CODER_TYPE || hasNestedOption(coders));
this.#shouldValidateLength = !(optionCoderRegex.test(this.type) || hasNestedOption(coders));
}

// We parse a native enum as an empty tuple, so we are looking for a tuple with no child coders.
// The '()' is enough but the child coders is a stricter check.
#isNativeEnum(coder: Coder): boolean {
if (this.type !== OPTION_CODER_TYPE && coder.type === '()') {
if (!optionCoderRegex.test(this.type) && coder.type === '()') {
const tupleCoder = coder as TupleCoder<[]>;
return tupleCoder.coders.length === 0;
}
Expand Down
16 changes: 11 additions & 5 deletions packages/abi-coder/src/encoding/strategies/getCoderV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
VEC_CODER_TYPE,
arrayRegEx,
enumRegEx,
lastNameRegExMatch,
stringRegEx,
structRegEx,
tupleRegEx,
Expand Down Expand Up @@ -122,21 +123,26 @@ export const getCoder: GetCoderFn = (
return new VecCoder(itemCoder as Coder);
}

const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
const structMatch = structRegEx.test(resolvedAbiType.type);
if (structMatch) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
arboleya marked this conversation as resolved.
Show resolved Hide resolved
const [name] = resolvedAbiType.type.match(lastNameRegExMatch)!;
const coders = getCoders(components, { getCoder });
return new StructCoder(structMatch.name, coders);
return new StructCoder(name, coders);
}

const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
const enumMatch = enumRegEx.test(resolvedAbiType.type);
if (enumMatch) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const [name] = resolvedAbiType.type.match(lastNameRegExMatch)!;

const coders = getCoders(components, { getCoder });

const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
petertonysmith94 marked this conversation as resolved.
Show resolved Hide resolved
if (isOptionEnum) {
return new OptionCoder(enumMatch.name, coders);
return new OptionCoder(name, coders);
}
return new EnumCoder(enumMatch.name, coders);
return new EnumCoder(name, coders);
}

const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
Expand Down
22 changes: 14 additions & 8 deletions packages/abi-coder/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ export const RAW_PTR_CODER_TYPE = 'raw untyped ptr';
export const RAW_SLICE_CODER_TYPE = 'raw untyped slice';
export const BOOL_CODER_TYPE = 'bool';
export const B256_CODER_TYPE = 'b256';
export const B512_CODER_TYPE = 'struct B512';
export const OPTION_CODER_TYPE = 'enum Option';
export const VEC_CODER_TYPE = 'struct Vec';
export const BYTES_CODER_TYPE = 'struct Bytes';
export const STD_STRING_CODER_TYPE = 'struct String';
export const B512_CODER_TYPE = 'struct std::b512::B512';
export const OPTION_CODER_TYPE = 'enum std::option::Option';
export const VEC_CODER_TYPE = 'struct std::vec::Vec';
export const BYTES_CODER_TYPE = 'struct std::bytes::Bytes';
export const STD_STRING_CODER_TYPE = 'struct std::string::String';
petertonysmith94 marked this conversation as resolved.
Show resolved Hide resolved
export const STR_SLICE_CODER_TYPE = 'str';

export const optionCoderRegex = /^enum.+Option$/m;

export const stringRegEx = /str\[(?<length>[0-9]+)\]/;
export const arrayRegEx = /\[(?<item>[\w\s\\[\]]+);\s*(?<length>[0-9]+)\]/;
export const structRegEx = /^struct (?<name>\w+)$/;
export const enumRegEx = /^enum (?<name>\w+)$/;
export const structRegEx = /struct.+/;
export const enumRegEx = /^enum.+$/;
export const tupleRegEx = /^\((?<items>.*)\)$/;
export const genericRegEx = /^generic (?<name>\w+)$/;
export const genericRegEx = /^generic.+$/;

export const lastNameRegExMatch = /([^:\s]+)$/m;

/**
* Encoding versions
*/
Expand Down
11 changes: 6 additions & 5 deletions packages/abi-coder/src/utils/utilities.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { OPTION_CODER_TYPE } from './constants';
import { hasNestedOption, type TCoders } from './utilities';

/**
Expand All @@ -15,7 +16,7 @@ describe('findNestedOption', () => {
coders: {
a: {
name: 'tuple',
type: '(boolean, [enum Option; 3])',
type: `(boolean, [${OPTION_CODER_TYPE}; 3])`,
encodedLength: 28,
coders: [
{
Expand All @@ -26,12 +27,12 @@ describe('findNestedOption', () => {
},
{
name: 'array',
type: '[enum Option; 3]',
type: `[${OPTION_CODER_TYPE}; 3]`,
encodedLength: 27,
// Deeply nested option
coder: {
name: 'Option',
type: 'enum Option',
type: `${OPTION_CODER_TYPE}`,
encodedLength: 9,
coders: {
None: { name: 'tuple', type: '()', encodedLength: 0, coders: [] },
Expand Down Expand Up @@ -65,7 +66,7 @@ describe('findNestedOption', () => {
coders: {
a: {
name: 'tuple',
type: '(boolean, [enum Option; 3])',
type: `(boolean, [${OPTION_CODER_TYPE}; 3])`,
encodedLength: 28,
coders: [
{
Expand All @@ -76,7 +77,7 @@ describe('findNestedOption', () => {
},
{
name: 'array',
type: '[enum Option; 3]',
type: `[${OPTION_CODER_TYPE}; 3]`,
encodedLength: 27,
coder: {
name: 'AnotherEnum',
Expand Down
13 changes: 8 additions & 5 deletions packages/abi-coder/test/Interface.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
import type { BN } from '@fuel-ts/math';
import { concat } from '@fuel-ts/utils';

import { Interface } from '../src';
/** @knipignore */
import type { JsonAbiConfigurable } from '../src/json-abi';
import { Interface } from '../src/Interface';
import type { JsonAbiConfigurable } from '../src/types/JsonAbi';

import exhaustiveExamplesAbi from './fixtures/forc-projects/exhaustive-examples/out/release/exhaustive-examples-abi.json';
import { AbiCoderProjectsEnum, getCoderForcProject } from './fixtures/forc-projects';
import {
B256_DECODED,
B256_ENCODED,
Expand Down Expand Up @@ -35,6 +34,10 @@ import {
U8_MIN_ENCODED,
} from './utils/constants';

const exhaustiveExamplesAbi = getCoderForcProject(
AbiCoderProjectsEnum.EXHAUSTIVE_EXAMPLES
).abiContents;

const exhaustiveExamplesInterface = new Interface(exhaustiveExamplesAbi);

/**
Expand Down Expand Up @@ -735,7 +738,7 @@ describe('Abi interface', () => {

describe('abi types', () => {
it('should return the correct type when it exists', () => {
const abiType = exhaustiveExamplesInterface.getTypeById(0);
const abiType = exhaustiveExamplesInterface.getTypeById(72);
expect(abiType.type).toEqual('()');
expect(abiType.components).toBeDefined();
expect(abiType.typeParameters).toBeNull();
Expand Down
18 changes: 18 additions & 0 deletions packages/abi-coder/test/fixtures/forc-projects/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { getForcProject } from '@fuel-ts/utils/test-utils';
import { join } from 'path';

import type { JsonAbi } from '../../../src';

export enum AbiCoderProjectsEnum {
EXHAUSTIVE_EXAMPLES = 'exhaustive-examples',
}

export const getCoderForcProject = (
project: AbiCoderProjectsEnum,
build: 'release' | 'debug' = 'release'
) =>
getForcProject<JsonAbi>({
projectDir: join(__dirname, project),
projectName: project,
build,
});
2 changes: 1 addition & 1 deletion packages/abi-coder/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"compilerOptions": {
"outDir": "./dist"
},
"include": ["src"]
"include": ["src", "test"]
}
6 changes: 3 additions & 3 deletions packages/abi-typegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
"dist"
],
"scripts": {
"pretest": "run-s build:forc-callpaths build:forc",
"pretest": "run-s build:forc:debug build:forc:release",
"build": "tsup",
"build:forc": "pnpm fuels-forc build -p test/fixtures/forc-projects --release",
"build:forc-callpaths": "pnpm fuels-forc build -p test/fixtures/forc-projects --json-abi-with-callpaths",
"build:forc:debug": "pnpm fuels-forc build -p test/fixtures/forc-projects",
"build:forc:release": "pnpm fuels-forc build -p test/fixtures/forc-projects --release",
"postbuild": "tsx ../../scripts/postbuild.ts"
},
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/abi-typegen/src/abi/types/ArrayType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('ArrayType.ts', () => {
const rawTypes = project.abiContents.types;
const types = rawTypes.map((rawAbiType: JsonAbiType) => makeType({ rawAbiType }));

const a = findType({ types, typeId: 1 }) as ArrayType;
const a = findType({ types, typeId: 0 }) as ArrayType;

expect(a.attributes.inputLabel).toEqual(
'[Generic1Input<Generic2Input<BigNumberish>, string>, Generic1Input<Generic2Input<BigNumberish>, string>]'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('EvmAddressType.ts', () => {

parseTypeArguments.mockClear();

const evmAddress = findType({ types, typeId: 1 }) as EvmAddressType;
const evmAddress = findType({ types, typeId: 0 }) as EvmAddressType;

expect(evmAddress.attributes.inputLabel).toEqual('EvmAddress');
expect(evmAddress.attributes.outputLabel).toEqual('EvmAddress');
Expand Down
3 changes: 2 additions & 1 deletion packages/abi-typegen/src/abi/types/ResultType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ describe('ResultType.ts', () => {
const project = getTypegenForcProject(AbiTypegenProjectsEnum.FULL);
const rawTypes = project.abiContents.types as JsonAbiType[];
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return parseTypes({ rawAbiTypes: [rawTypes.find((t) => t.type === 'enum Result')!] })[0];
const rawAbiTypes = [rawTypes.find((t) => t.type === 'enum std::result::Result')!];
return parseTypes({ rawAbiTypes })[0];
}

test('should properly evaluate type suitability', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/abi-typegen/src/abi/types/TupleType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('TupleType.ts', () => {

// validating `struct B`, with simple tuples on property `x`
parseTypeArguments.mockClear();
const b = findType({ types, typeId: 0 }) as TupleType;
const b = findType({ types, typeId: 1 }) as TupleType;

expect(b.attributes.inputLabel).toEqual('[boolean, BigNumberish]');
expect(b.attributes.outputLabel).toEqual('[boolean, BN]');
Expand All @@ -40,7 +40,7 @@ describe('TupleType.ts', () => {

// validating `struct C`, with nested (tuple) `typeArguments` on `b` property
parseTypeArguments.mockClear();
const c = findType({ types, typeId: 1 }) as TupleType;
const c = findType({ types, typeId: 0 }) as TupleType;

expect(c.attributes.inputLabel).toEqual(
'[BigNumberish, StructAInput<StructBInput<BigNumberish>, string>]'
Expand Down
6 changes: 5 additions & 1 deletion packages/abi-typegen/src/runTypegen.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ErrorCode, FuelError } from '@fuel-ts/errors';
import { transpileAbi } from '@fuel-ts/utils';
import { readFileSync, writeFileSync } from 'fs';
import { globSync } from 'glob';
import mkdirp from 'mkdirp';
Expand Down Expand Up @@ -52,10 +53,13 @@ export function runTypegen(params: IGenerateFilesParams) {
Assembling file paths x contents
*/
const abiFiles = filepaths.map((filepath) => {
const raw = readFileSync(filepath, 'utf-8');
const transpiled = JSON.stringify(transpileAbi(JSON.parse(raw)), null, 2);
const abi: IFile = {
path: filepath,
contents: readFileSync(filepath, 'utf-8'),
contents: transpiled,
};

return abi;
});
petertonysmith94 marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
Loading
Loading