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

fix: make properties of configurables optional in typegen #2815

Merged
merged 10 commits into from
Jul 23, 2024
5 changes: 5 additions & 0 deletions .changeset/tasty-fireants-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/abi-typegen": patch
---

fix: make Predicate configurables option in typegen
Torres-ssf marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions packages/abi-typegen/src/templates/predicate/factory.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ export type {{structName}}Output{{typeAnnotations}} = { {{outputValues}} };
{{/if}}
{{/each}}

export type {{capitalizedName}}Configurables = {
export type {{capitalizedName}}Configurables = Partial<{
{{#each formattedConfigurables}}
{{configurableName}}: {{configurableType}};
{{/each}}
};
}>;

export type {{capitalizedName}}Inputs = [{{inputs}}];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import {
Provider,
} from 'fuels';

export type MyPredicateAbiConfigurables = {
export type MyPredicateAbiConfigurables = Partial<{
FEE: BigNumberish;
ADDRESS: string;
};
}>;

export type MyPredicateAbiInputs = [fee: BigNumberish, address: string];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export type MyGenericStructOutput<T> = MyGenericStructInput<T>;
export type ValidationInput = { has_account: boolean, total_complete: BigNumberish };
export type ValidationOutput = { has_account: boolean, total_complete: BN };

export type MyPredicateAbiConfigurables = {
};
export type MyPredicateAbiConfigurables = Partial<{
}>;

export type MyPredicateAbiInputs = [vec: Vec<ValidationInput>, enm: MyGenericEnumInput<BigNumberish>, opt: Option<BigNumberish>, res: Result<MyGenericStructInput<string>, BigNumberish>];

Expand Down
8 changes: 4 additions & 4 deletions packages/fuel-gauge/src/policies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ describe('Policies', () => {
} = launched;

const factory = new ContractFactory(
ScriptMainArgsAbi__factory.bin,
ScriptMainArgsAbi__factory.abi,
PayableAnnotationAbiHex,
maschad marked this conversation as resolved.
Show resolved Hide resolved
PayableAnnotationAbi__factory.abi,
wallet
);

Expand Down Expand Up @@ -446,8 +446,8 @@ describe('Policies', () => {
const maxFee = 1;

const factory = new ContractFactory(
ScriptMainArgsAbi__factory.bin,
ScriptMainArgsAbi__factory.abi,
PayableAnnotationAbiHex,
PayableAnnotationAbi__factory.abi,
wallet
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,50 @@ describe('Predicate', () => {
await assertBalance(destination, amountToTransfer, provider.getBaseAssetId());
});

it('calls a predicate with partial configurables being set', async () => {
using launched = await launchTestNode();

const {
provider,
wallets: [wallet],
} = launched;

const configurableConstants = {
ADDRESS: getRandomB256(),
};

const amountToTransfer = 300;

const predicate = new Predicate({
maschad marked this conversation as resolved.
Show resolved Hide resolved
bytecode: PredicateWithConfigurableAbi__factory.bin,
abi: PredicateWithConfigurableAbi__factory.abi,
provider,
inputData: [defaultValues.FEE, configurableConstants.ADDRESS],
configurableConstants,
});

const destination = WalletUnlocked.generate({
provider: wallet.provider,
});

await assertBalance(destination, 0, provider.getBaseAssetId());

await fundPredicate(wallet, predicate, amountToPredicate);

const tx = await predicate.transfer(
destination.address,
amountToTransfer,
provider.getBaseAssetId(),
{
gasLimit: 1000,
}
);

await tx.waitForResult();

await assertBalance(destination, amountToTransfer, provider.getBaseAssetId());
});

it('throws when configurable data is not set', async () => {
using launched = await launchTestNode();

Expand Down
Loading