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

test: refactor predicate feature tests #1079

Merged
merged 36 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
04cf5a6
chore: fix spellings in typegen
May 30, 2023
100b1f7
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts
May 31, 2023
0bbdbb1
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts
May 31, 2023
90b5d3c
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts
Jun 1, 2023
047ef9b
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts
Jun 1, 2023
fe875a2
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts
Jun 6, 2023
b14ad1d
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts
Jun 7, 2023
9a7cf0e
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts
Jun 19, 2023
dc8461f
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts
Jun 20, 2023
d822b51
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts
Jun 28, 2023
55cc6c3
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts
Jun 28, 2023
919f390
test: remove predicate tests from fuel gauge
Jun 29, 2023
62f9508
test: move predicate feature tests to predicate package
Jun 30, 2023
09433b7
chore: linting
Jun 30, 2023
afbb594
test: fix file path in predicate contract test
Jul 3, 2023
67f6b92
chore: linting
Jul 3, 2023
9f87874
test: add more set data test cases
Jul 3, 2023
9bc7255
test: add test case for simulating a transaction
Jul 3, 2023
e387483
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
Jul 3, 2023
80c0f2d
chore: changeset
Jul 3, 2023
d07c311
test: remove redundant fixture
Jul 3, 2023
fdeb888
test: add script to build predicates
Jul 3, 2023
f810884
test: add missing forc projects to predicate worksapce
Jul 3, 2023
1bc6965
chore: linting
Jul 3, 2023
94524f9
fix: fix incorrect method name in predicagte test
Jul 3, 2023
c0a86d6
Merge branch 'master' into db/test/refactor-predicate-tests
arboleya Jul 5, 2023
2c2b83b
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
Jul 18, 2023
4b240c9
test: move predicate integration tests to fuel gauge
Jul 19, 2023
e99ff79
core: regen lock file
Jul 19, 2023
6827de9
docs: update doc paths
Jul 19, 2023
737daf3
Merge branch 'db/test/refactor-predicate-tests' of https://github.com…
Jul 19, 2023
527434a
chore: delete redundant test file
Jul 19, 2023
73d2316
chore: regen lock file
Jul 19, 2023
15e01fe
test: remove redundant predicate test
Jul 19, 2023
ca66013
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
Jul 19, 2023
45aea73
Merge branch 'master' into db/test/refactor-predicate-tests
danielbate Jul 24, 2023
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
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';
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 <contact@fuel.sh> (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
Loading