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

chore: integrate launchTestNode into current test suites #2579

Open
wants to merge 64 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
a6c5d8d
feat: add browser testing support in `launchTestNode` utility
nedsalk Jun 18, 2024
f3724b6
chore: changeset update
nedsalk Jun 18, 2024
f642a31
add missing group to test
nedsalk Jun 18, 2024
99a8aed
remove unnecessary addition
nedsalk Jun 18, 2024
0abbed7
test: add test for specific port
nedsalk Jun 18, 2024
562cbf5
fix: linting
nedsalk Jun 18, 2024
fd4a5f2
Merge branch 'master' into ns/feat/launch-test-node-in-browser-tests
nedsalk Jun 18, 2024
7045dcf
Add longer timeouts
nedsalk Jun 18, 2024
49b7360
Merge branch 'master' into ns/feat/launch-test-node-in-browser-tests
maschad Jun 20, 2024
7a1ebbf
apply change requests
nedsalk Jun 20, 2024
cdd971e
Merge remote-tracking branch 'origin/master' into ns/feat/launch-test…
nedsalk Jun 20, 2024
475e65e
Merge branch 'master' into ns/feat/launch-test-node-in-browser-tests
maschad Jun 20, 2024
ead34f5
wip
maschad Jun 21, 2024
10af335
Merge branch 'master' into mc/chore/integrate-launch-test-node
maschad Jun 21, 2024
61b28bf
removed unnecessary methods
maschad Jun 21, 2024
9036e45
Merge branch 'master' into ns/feat/launch-test-node-in-browser-tests
danielbate Jun 21, 2024
549b1fa
Merge branch 'master' into ns/feat/launch-test-node-in-browser-tests
petertonysmith94 Jun 21, 2024
624f24b
add /close-server endpoint
nedsalk Jun 21, 2024
b5132b4
fix: linting
nedsalk Jun 21, 2024
eb8eff8
increase timeout
nedsalk Jun 21, 2024
127ad84
Merge branch 'master' into mc/chore/integrate-launch-test-node
maschad Jun 21, 2024
69a9353
Merge branch 'ns/feat/launch-test-node-in-browser-tests' into mc/chor…
maschad Jun 21, 2024
aa44421
test: remove getSetupContract completely
maschad Jun 21, 2024
a5ac3fe
test: refactor launchTestNode use cases to use utility
maschad Jun 23, 2024
e07b86d
refactor: add type inference to setupContract
maschad Jun 24, 2024
908d187
Merge branch 'master' into mc/chore/integrate-launch-test-node
maschad Jun 24, 2024
7da953c
fix: adjust advanced logging to use new pattern
maschad Jun 25, 2024
2a28b9b
Merge branch 'master' into mc/chore/integrate-launch-test-node
maschad Jun 25, 2024
7b783e3
test: integrate launchTestNode with other tests
maschad Jun 26, 2024
7d9b650
refactor: refactor more tests to use launchTestNode
maschad Jun 29, 2024
616e455
Merge branch 'master' into mc/chore/integrate-launch-test-node
maschad Jun 29, 2024
56febeb
Merge branch 'master' into mc/chore/integrate-launch-test-node
maschad Jul 2, 2024
89d356a
refactor: refactored more tests to use launchTestNode
maschad Jul 2, 2024
bb47402
Merge branch 'master' into mc/chore/integrate-launch-test-node
maschad Jul 6, 2024
de20c8c
fix: add typegen for token contract abi + more tests
maschad Jul 6, 2024
f9c5fbf
fix: update script configurable tests
maschad Jul 7, 2024
96a0595
test: fixed more tests, only policy and predicates remaining
maschad Jul 9, 2024
0efd7c4
Merge branch 'master' into mc/chore/integrate-launch-test-node
maschad Jul 9, 2024
9dd6d1b
test: predicate tests now passing
maschad Jul 9, 2024
067a392
test: all tests passing
maschad Jul 10, 2024
7d57766
lint: fixing linting issues
maschad Jul 10, 2024
36c744b
Merge branch 'master' into mc/chore/integrate-launch-test-node
maschad Jul 10, 2024
32a7595
Merge branch 'master' into mc/chore/integrate-launch-test-node
maschad Jul 10, 2024
0ba79bf
test: updated configurable-contract tests
maschad Jul 10, 2024
2abdad8
docs: update changeset typo
maschad Jul 10, 2024
1a281d4
test: remove only on policies test
maschad Jul 10, 2024
08cf2b0
refactor: clean up type inferences
maschad Jul 10, 2024
d7b84ba
test: refactor type inferencing
maschad Jul 11, 2024
fb48b41
Merge branch 'master' into mc/chore/integrate-launch-test-node
maschad Jul 11, 2024
b1c0dba
test: fix issue with hanging tests due to variables not dropping reso…
maschad Jul 11, 2024
ba33790
Merge branch 'master' into mc/chore/integrate-launch-test-node
maschad Jul 11, 2024
e952b48
fix: increase block production times on policy tests
maschad Jul 11, 2024
a18c37b
Merge branch 'master' into mc/chore/integrate-launch-test-node
maschad Jul 12, 2024
8bc6b61
fix: undo call parameters test change
maschad Jul 12, 2024
7c8a51e
fix: resotre create-fuels.js
maschad Jul 12, 2024
f401c95
test: update typegen demo-test
maschad Jul 12, 2024
d998db8
lint: linting fixes
maschad Jul 12, 2024
453e71a
test: skipping policy tests temporarily
maschad Jul 12, 2024
5cb3ce1
fix: import wallet in tests
maschad Jul 12, 2024
9d306ed
fix: remove node specific testing utilities
maschad Jul 12, 2024
e7b0287
test: removed maturity from policy tests due to inconsistency
maschad Jul 12, 2024
74a8847
lint: linting fixes
maschad Jul 12, 2024
5e925dd
test: update configs for await-execution test
maschad Jul 12, 2024
1f1b7ff
docs: update changeset
maschad Jul 12, 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
5 changes: 5 additions & 0 deletions .changeset/pretty-hornets-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/contract": patch
---

chore: integrate `launchTestNode` into current test suites
97 changes: 73 additions & 24 deletions apps/demo-typegen/src/demo.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// #region Testing-in-ts-ts
import { ContractFactory, Provider, toHex, Wallet, FUEL_NETWORK_URL, Address } from 'fuels';
import { generateTestWallet, safeExec } from 'fuels/test-utils';
import { ContractFactory, toHex, Address, Wallet } from 'fuels';
import { launchTestNode, safeExec } from 'fuels/test-utils';

import storageSlots from '../contract/out/release/demo-contract-storage_slots.json';

Expand All @@ -10,19 +10,21 @@ import type { PredicateAbiInputs } from './predicate-types';
import { PredicateAbi__factory } from './predicate-types';
import { ScriptAbi__factory } from './script-types';

let baseAssetId: string;

/**
* @group node
* @group browser
*/
describe('ExampleContract', () => {
beforeAll(async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
baseAssetId = provider.getBaseAssetId();
});
it('with imported storage slots', async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);
using launched = await launchTestNode({
walletsConfig: {
amountPerCoin: 500_000,
},
});

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

// #region typegen-demo-contract-storage-slots
// #context import storageSlots from './contract/out/debug/demo-contract-storage_slots.json';
Expand All @@ -36,8 +38,15 @@ describe('ExampleContract', () => {
expect(contract.id).toBeTruthy();
});
it('should return the input', async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);
using launched = await launchTestNode({
walletsConfig: {
amountPerCoin: 500_000,
},
});

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

// Deploy
const factory = new ContractFactory(bytecode, DemoContractAbi__factory.abi, wallet);
Expand All @@ -64,8 +73,15 @@ describe('ExampleContract', () => {
});

it('deployContract method', async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);
using launched = await launchTestNode({
walletsConfig: {
amountPerCoin: 500_000,
},
});

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

// #region typegen-demo-contract-factory-deploy
// #context import { DemoContractAbi__factory } from './types';
Expand All @@ -88,8 +104,17 @@ describe('ExampleContract', () => {
// #endregion Testing-in-ts-ts

it('should throw when simulating via contract factory with wallet with no resources', async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
const fundedWallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);
using launched = await launchTestNode({
walletsConfig: {
amountPerCoin: 500_000,
},
});

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

const unfundedWallet = Wallet.generate({ provider });

const factory = new ContractFactory(bytecode, DemoContractAbi__factory.abi, fundedWallet);
Expand All @@ -103,8 +128,16 @@ it('should throw when simulating via contract factory with wallet with no resour
});

it('should not throw when dry running via contract factory with wallet with no resources', async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
const fundedWallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);
using launched = await launchTestNode({
walletsConfig: {
amountPerCoin: 500_000,
},
});

const {
provider,
wallets: [fundedWallet],
} = launched;
const unfundedWallet = Wallet.generate({ provider });

const factory = new ContractFactory(bytecode, DemoContractAbi__factory.abi, fundedWallet);
Expand All @@ -116,8 +149,15 @@ it('should not throw when dry running via contract factory with wallet with no r
});

test('Example script', async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);
using launched = await launchTestNode({
walletsConfig: {
amountPerCoin: 500_000,
},
});

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

// #region typegen-demo-script
// #context import { ScriptAbi__factory } from './types';
Expand All @@ -135,18 +175,27 @@ test('Example predicate', async () => {
// #context import { PredicateAbi__factory } from './types';

// In this exchange, we are first transferring some coins to the predicate
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);
using launched = await launchTestNode({
walletsConfig: {
amountPerCoin: 10_000_000_000,
},
});

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

const receiver = Wallet.fromAddress(Address.fromRandom(), provider);

const predicateData: PredicateAbiInputs = [];
const predicate = PredicateAbi__factory.createInstance(provider, predicateData);

const tx = await wallet.transfer(predicate.address, 150_000, baseAssetId);
const tx = await wallet.transfer(predicate.address, 1_000_000, provider.getBaseAssetId());
const { isStatusSuccess } = await tx.wait();

// Then we are transferring some coins from the predicate to a random address (receiver)
const tx2 = await predicate.transfer(receiver.address, 50_000, baseAssetId);
const tx2 = await predicate.transfer(receiver.address, 50_000, provider.getBaseAssetId());
await tx2.wait();

expect((await receiver.getBalance()).toNumber()).toEqual(50_000);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "return-script"
Expand Down
3 changes: 3 additions & 0 deletions packages/contract/src/test-utils/launch-test-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import type {
import { FuelError } from '@fuel-ts/errors';
import type { BytesLike } from '@fuel-ts/interfaces';
import type { SnapshotConfigs } from '@fuel-ts/utils';
import { EventEmitter } from 'events';
import { readFileSync } from 'fs';
import * as path from 'path';
import { mergeDeepRight } from 'ramda';

import type { DeployContractOptions, DeployContractResult } from '../contract-factory';

EventEmitter.defaultMaxListeners = 20;

export interface ContractDeployer {
deployContract(
bytecode: BytesLike,
Expand Down
Loading
Loading