Skip to content

Commit

Permalink
chore: integrate launchTestNode into current test suites (#2579)
Browse files Browse the repository at this point in the history
* feat: add browser testing support in `launchTestNode` utility

* chore: changeset update

* add missing group to test

* remove unnecessary addition

* test: add test for specific port

* fix: linting

* Add longer timeouts

* apply change requests

* wip

* removed unnecessary methods

* add /close-server endpoint

* fix: linting

* increase timeout

* test: remove getSetupContract completely

* test: refactor launchTestNode use cases to use utility

* refactor: add type inference to setupContract

* fix: adjust advanced logging to use new pattern

* test: integrate launchTestNode with other tests

* refactor: refactor more tests to use launchTestNode

* refactor: refactored more tests to use launchTestNode

* fix: add typegen for token contract abi + more tests

* fix: update script configurable tests

* test: fixed more tests, only policy and predicates remaining

* test: predicate tests now passing

* test: all tests passing

* lint: fixing linting issues

* test: updated configurable-contract tests

* docs: update changeset typo

* test: remove only on policies test

* refactor: clean up type inferences

* test: refactor type inferencing

* test: fix issue with hanging tests due to variables not dropping resources

* fix: increase block production times on policy tests

* fix: undo call parameters test change

* fix: resotre create-fuels.js

* test: update typegen demo-test

* lint: linting fixes

* test: skipping policy tests temporarily

* fix: import wallet in tests

* fix: remove node specific testing utilities

* test: removed maturity from policy tests due to inconsistency

* lint: linting fixes

* test: update configs for await-execution test

* docs: update changeset

* refactor: optimizations based on PR feedback

* fix: remove max event emitters patch for warning

* refactor: PR feedback

* refactor: further PR feedback

* refactor: set lower amount on transaction-response test

* Replace `launchtestNode({})` with `launchTestNode()` globally

* `bytes.test.ts` to use typegen outputs

* chore: improve `fuel-gauge` tests (#2789)

Co-authored-by: Chad Nehemiah <chad.nehemiah94@gmail.com>

* test: update payabale-annotation test

Co-authored-by: Anderson Arboleya <anderson@arboleya.me>

---------

Co-authored-by: nedsalk <nedim.salkic@fuel.sh>
Co-authored-by: Daniel Bate <djbate23@gmail.com>
Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>
Co-authored-by: Anderson Arboleya <anderson@arboleya.me>
  • Loading branch information
5 people committed Jul 19, 2024
1 parent f3e89d2 commit 538d8b6
Show file tree
Hide file tree
Showing 66 changed files with 3,394 additions and 2,873 deletions.
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
69 changes: 45 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,17 @@ 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();

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 +34,11 @@ 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();

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

// Deploy
const factory = new ContractFactory(bytecode, DemoContractAbi__factory.abi, wallet);
Expand All @@ -64,8 +65,11 @@ 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();

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

// #region typegen-demo-contract-factory-deploy
// #context import { DemoContractAbi__factory } from './types';
Expand All @@ -88,8 +92,13 @@ 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();

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

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

const factory = new ContractFactory(bytecode, DemoContractAbi__factory.abi, fundedWallet);
Expand All @@ -103,8 +112,12 @@ 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();

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

const factory = new ContractFactory(bytecode, DemoContractAbi__factory.abi, fundedWallet);
Expand All @@ -116,8 +129,11 @@ 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();

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

// #region typegen-demo-script
// #context import { ScriptAbi__factory } from './types';
Expand All @@ -135,18 +151,23 @@ 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();

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, 200_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
Loading

0 comments on commit 538d8b6

Please sign in to comment.