Skip to content

Commit

Permalink
test: refactor predicate feature tests (#1079)
Browse files Browse the repository at this point in the history
* chore: fix spellings in typegen

* test: remove predicate tests from fuel gauge

* test: move predicate feature tests to predicate package

* chore: linting

* test: fix file path in predicate contract test

* chore: linting

* test: add more set data test cases

* test: add test case for simulating a transaction

* chore: changeset

* test: remove redundant fixture

* test: add script to build predicates

* test: add missing forc projects to predicate worksapce

* chore: linting

* fix: fix incorrect method name in predicagte test
'
'

* test: move predicate integration tests to fuel gauge

* core: regen lock file

* docs: update doc paths

* chore: delete redundant test file

* chore: regen lock file

* test: remove redundant predicate test

---------

Co-authored-by: danielbate <--global>
Co-authored-by: Anderson Arboleya <[email protected]>
  • Loading branch information
danielbate and arboleya committed Jul 24, 2023
1 parent 39479c2 commit 9da0e6a
Show file tree
Hide file tree
Showing 124 changed files with 1,284 additions and 1,149 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-spiders-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/predicate": patch
---

Refactor structure of tests in the predicate package
2 changes: 1 addition & 1 deletion apps/docs/src/guide/abi-typegen/using-generated-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ console.log({ value, logs });

Consider the following predicate:

<<< @/../../../packages/fuel-gauge/test-projects/predicate-main-args-struct/src/main.sw#Predicate-main-args{ts:line-numbers}
<<< @/../../../packages/fuel-gauge/fixtures/forc-projects/predicate-main-args-struct/src/main.sw#Predicate-main-args{ts:line-numbers}

Now, after generating types via:

Expand Down
4 changes: 2 additions & 2 deletions apps/docs/src/guide/cookbook/deposit-and-withdraw.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

Consider the following contracts:

<<< @/../../../packages/fuel-gauge/test-projects/token_contract/src/main.sw#token-contract{rust:line-numbers}
<<< @/../../../packages/fuel-gauge/fixtures/forc-projects/token_contract/src/main.sw#token-contract{rust:line-numbers}

<<< @/../../../packages/fuel-gauge/test-projects/liquidity-pool/src/main.sw#liquidity-pool-contract{rust:line-numbers}
<<< @/../../../packages/fuel-gauge/fixtures/forc-projects/liquidity-pool/src/main.sw#liquidity-pool-contract{rust:line-numbers}

The first contract is a contract that represents a simple token.

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/guide/scripts/calling-a-script.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Suppose your Sway script `main` function is written using the arguments passed to the `main` function like so:

<<< @/../../../packages/fuel-gauge/test-projects/script-main-args/src/main.sw#script-with-main-args{rust:line-numbers}
<<< @/../../../packages/fuel-gauge/fixtures/forc-projects/script-main-args/src/main.sw#script-with-main-args{rust:line-numbers}

You can still hand code out a solution wrapper using `callScript` utility to call your script with data. However, if you prefer to use the ABI generated from your script, you can use the `ScriptFactory` helper:

Expand Down
2 changes: 1 addition & 1 deletion packages/fuel-gauge/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test-projects/**/index.ts
fixtures/forc-projects/**/index.ts
38 changes: 38 additions & 0 deletions packages/fuel-gauge/fixtures/abi/predicate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { JsonAbi } from 'fuels';

export const defaultPredicateAbi: JsonAbi = {
types: [
{
typeId: 0,
type: 'bool',
components: null,
typeParameters: null,
},
{
typeId: 1,
type: 'b256',
components: null,
typeParameters: null,
},
],
functions: [
{
inputs: [
{
name: 'data',
type: 1,
typeArguments: null,
},
],
name: 'main',
output: {
name: '',
type: 0,
typeArguments: null,
},
attributes: null,
},
],
loggedTypes: [],
configurables: [],
};
2 changes: 2 additions & 0 deletions packages/fuel-gauge/fixtures/bytecode/predicate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const defaultPredicateBytecode =
'0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8';
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/fuel-gauge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Fuel Labs <[email protected]> (https://fuel.network/)",
"scripts": {
"build": "run-s build:forc-projects build:process-predicates",
"build:forc-projects": "pnpm fuels-forc build -p test-projects",
"build:forc-projects": "pnpm fuels-forc build -p fixtures/forc-projects",
"build:process-predicates": "tsx ./scripts/process-predicates.ts"
},
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/fuel-gauge/scripts/process-predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFileSync, readdirSync, writeFileSync } from 'fs';
import { hexlify } from 'fuels';
import { join } from 'path';

const projectsDir = join(__dirname, '../test-projects');
const projectsDir = join(__dirname, '../fixtures/forc-projects');

const files = readdirSync(projectsDir).filter((file) => file.includes('predicate-'));

Expand Down
4 changes: 2 additions & 2 deletions packages/fuel-gauge/src/auth-testing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Contract, WalletUnlocked } from 'fuels';
import { AssertFailedRevertError, ContractFactory, NativeAssetId, Provider } from 'fuels';
import path from 'path';

import FactoryAbi from '../test-projects/auth_testing_contract/out/debug/auth_testing_contract-abi.json';
import FactoryAbi from '../fixtures/forc-projects/auth_testing_contract/out/debug/auth_testing_contract-abi.json';

let contractInstance: Contract;
let wallet: WalletUnlocked;
Expand All @@ -17,7 +17,7 @@ describe('Auth Testing', () => {
const bytecode = fs.readFileSync(
path.join(
__dirname,
'../test-projects/auth_testing_contract/out/debug/auth_testing_contract.bin'
'../fixtures/forc-projects/auth_testing_contract/out/debug/auth_testing_contract.bin'
)
);
const factory = new ContractFactory(bytecode, FactoryAbi, wallet);
Expand Down
4 changes: 2 additions & 2 deletions packages/fuel-gauge/src/call-test-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { readFileSync } from 'fs';
import { BN, bn, toHex, NativeAssetId } from 'fuels';
import { join } from 'path';

import abiJSON from '../test-projects/call-test-contract/out/debug/call-test-abi.json';
import abiJSON from '../fixtures/forc-projects/call-test-contract/out/debug/call-test-abi.json';

import { createSetupConfig } from './utils';

const contractBytecode = readFileSync(
join(__dirname, '../test-projects/call-test-contract/out/debug/call-test.bin')
join(__dirname, '../fixtures/forc-projects/call-test-contract/out/debug/call-test.bin')
);

const setupContract = createSetupConfig({
Expand Down
7 changes: 5 additions & 2 deletions packages/fuel-gauge/src/configurable-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import type { CoinQuantityLike, WalletUnlocked } from 'fuels';
import { getRandomB256, BN, ContractFactory, NativeAssetId, Provider } from 'fuels';
import { join } from 'path';

import contractAbi from '../test-projects/configurable-contract/out/debug/configurable-contract-abi.json';
import contractAbi from '../fixtures/forc-projects/configurable-contract/out/debug/configurable-contract-abi.json';

const contractBytecode = readFileSync(
join(__dirname, '../test-projects/configurable-contract/out/debug/configurable-contract.bin')
join(
__dirname,
'../fixtures/forc-projects/configurable-contract/out/debug/configurable-contract.bin'
)
);

const defaultValues = {
Expand Down
9 changes: 6 additions & 3 deletions packages/fuel-gauge/src/contract-factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { readFileSync } from 'fs';
import { bn, toHex, Interface, Provider, ContractFactory, NativeAssetId } from 'fuels';
import { join } from 'path';

import storageSlots from '../test-projects/storage-test-contract/out/debug/storage-test-storage_slots.json';
import storageSlots from '../fixtures/forc-projects/storage-test-contract/out/debug/storage-test-storage_slots.json';

describe('Contract Factory', () => {
const createContractFactory = async () => {
Expand All @@ -12,13 +12,16 @@ describe('Contract Factory', () => {

// load the byteCode of the contract, generated from Sway source
const byteCode = readFileSync(
join(__dirname, '../test-projects/storage-test-contract/out/debug/storage-test.bin')
join(__dirname, '../fixtures/forc-projects/storage-test-contract/out/debug/storage-test.bin')
);

// load the JSON abi of the contract, generated from Sway source
const abi = JSON.parse(
readFileSync(
join(__dirname, '../test-projects/storage-test-contract/out/debug/storage-test-abi.json')
join(
__dirname,
'../fixtures/forc-projects/storage-test-contract/out/debug/storage-test-abi.json'
)
).toString()
);

Expand Down
6 changes: 3 additions & 3 deletions packages/fuel-gauge/src/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ import {
} from 'fuels';
import { join } from 'path';

import abiJSON from '../test-projects/call-test-contract/out/debug/call-test-abi.json';
import abiJSON from '../fixtures/forc-projects/call-test-contract/out/debug/call-test-abi.json';

import { createSetupConfig } from './utils';

const contractBytecode = readFileSync(
join(__dirname, '../test-projects/call-test-contract/out/debug/call-test.bin')
join(__dirname, '../fixtures/forc-projects/call-test-contract/out/debug/call-test.bin')
);

const predicateBytecode = readFileSync(
join(__dirname, '../test-projects/predicate-true/out/debug/predicate-true.bin')
join(__dirname, '../fixtures/forc-projects/predicate-true/out/debug/predicate-true.bin')
);

const setupContract = createSetupConfig({
Expand Down
14 changes: 7 additions & 7 deletions packages/fuel-gauge/src/doc-examples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import {
} from 'fuels';
import { join } from 'path';

import abiJSON from '../test-projects/call-test-contract/out/debug/call-test-abi.json';
import liquidityPoolABI from '../test-projects/liquidity-pool/out/debug/liquidity-pool-abi.json';
import predicateTriple from '../test-projects/predicate-triple-sig';
import testPredicateTrue from '../test-projects/predicate-true';
import tokenContractABI from '../test-projects/token_contract/out/debug/token_contract-abi.json';
import abiJSON from '../fixtures/forc-projects/call-test-contract/out/debug/call-test-abi.json';
import liquidityPoolABI from '../fixtures/forc-projects/liquidity-pool/out/debug/liquidity-pool-abi.json';
import predicateTriple from '../fixtures/forc-projects/predicate-triple-sig';
import testPredicateTrue from '../fixtures/forc-projects/predicate-true';
import tokenContractABI from '../fixtures/forc-projects/token_contract/out/debug/token_contract-abi.json';

const PUBLIC_KEY =
'0x2f34bc0df4db0ec391792cedb05768832b49b1aa3a2dd8c30054d1af00f67d00b74b7acbbf3087c8e0b1a4c343db50aa471d21f278ff5ce09f07795d541fb47e';
Expand Down Expand Up @@ -442,14 +442,14 @@ test('deposit and withdraw cookbook guide', async () => {

// #region deposit-and-withdraw-cookbook-contract-deployments
const tokenContractBytecode = readFileSync(
join(__dirname, '../test-projects/token_contract/out/debug/token_contract.bin')
join(__dirname, '../fixtures/forc-projects/token_contract/out/debug/token_contract.bin')
);
const tokenContractFactory = new ContractFactory(tokenContractBytecode, tokenContractABI, wallet);
const tokenContract = await tokenContractFactory.deployContract();
const tokenContractID = tokenContract.id;

const liquidityPoolContractBytecode = readFileSync(
join(__dirname, '../test-projects/liquidity-pool/out/debug/liquidity-pool.bin')
join(__dirname, '../fixtures/forc-projects/liquidity-pool/out/debug/liquidity-pool.bin')
);
const liquidityPoolContractFactory = new ContractFactory(
liquidityPoolContractBytecode,
Expand Down
7 changes: 5 additions & 2 deletions packages/fuel-gauge/src/generic-types-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { readFileSync } from 'fs';
import { toHex } from 'fuels';
import { join } from 'path';

import abiJSON from '../test-projects/generic-types-contract/out/debug/generic-types-contract-abi.json';
import abiJSON from '../fixtures/forc-projects/generic-types-contract/out/debug/generic-types-contract-abi.json';

import { setup } from './utils';

const contractBytecode = readFileSync(
join(__dirname, '../test-projects/generic-types-contract/out/debug/generic-types-contract.bin')
join(
__dirname,
'../fixtures/forc-projects/generic-types-contract/out/debug/generic-types-contract.bin'
)
);

describe('GenericTypesContract', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/fuel-gauge/src/payable-annotation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { readFileSync } from 'fs';
import { bn, NativeAssetId } from 'fuels';
import { join } from 'path';

import abiJSON from '../test-projects/payable-annotation/out/debug/payable-annotation-abi.json';
import abiJSON from '../fixtures/forc-projects/payable-annotation/out/debug/payable-annotation-abi.json';

import { createSetupConfig } from './utils';

const contractBytecode = readFileSync(
join(__dirname, '../test-projects/payable-annotation/out/debug/payable-annotation.bin')
join(__dirname, '../fixtures/forc-projects/payable-annotation/out/debug/payable-annotation.bin')
);

const setupContract = createSetupConfig({
Expand Down
Loading

0 comments on commit 9da0e6a

Please sign in to comment.