Skip to content

Commit

Permalink
feat: add test against live Node (#1324)
Browse files Browse the repository at this point in the history
* add basics

* cs

* update

* add script test

* adjust script

* adjust ref check for proof

* eq eq

* ref

* force

* adjust

* rename

* relocate helper text

* rename to e2e

* use other wallet

* pret

* remove commetn

---------

Co-authored-by: Daniel Bate <[email protected]>
Co-authored-by: Anderson Arboleya <[email protected]>
  • Loading branch information
3 people authored Oct 18, 2023
1 parent 047520d commit af2500b
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/old-drinks-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/wallet": minor
---

Added support for integration testing on live node
24 changes: 24 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,27 @@ jobs:
test-script: pnpm ci:test
prnumber: ${{ steps.findPr.outputs.number }}
base-coverage-file: coverage-reports/report.master.json
live-tests:
name: Run Live Tests
if: github.head_ref == 'changeset-release/master'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: CI Setup
uses: ./.github/actions/ci-setup

- name: Build
run: pnpm build

- name: Pretest
run: pnpm pretest

- name: Run Isolated Tests
run: pnpm test:e2e
env:
FUEL_NETWORK_URL: https://beta-4.fuel.network/graphql
FUEL_NETWORK_GENESIS_KEY: ${{ secrets.FUEL_NETWORK_GENESIS_KEY }}
3 changes: 2 additions & 1 deletion jest.env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ const getPrivateKeyForCurrentWorker = () => {
return privateKey;
};

process.env.GENESIS_SECRET = getPrivateKeyForCurrentWorker();
process.env.GENESIS_SECRET =
process.env.FUEL_NETWORK_GENESIS_KEY || getPrivateKeyForCurrentWorker();
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"ci:test": "./scripts/ci-test.sh",
"pretest": "turbo run pretest",
"test": "jest --no-cache --runInBand --coverage",
"test:e2e": "jest --no-cache --runInBand packages/fuel-gauge/src/e2e-script.test.ts",
"test:watch": "jest --no-cache --watchAll",
"lint": "run-s lint:check prettier:check",
"lint:check": "eslint . --ext .ts",
Expand Down
122 changes: 122 additions & 0 deletions packages/fuel-gauge/src/e2e-script.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/* eslint-disable no-console */
import type { BN } from 'fuels';
import { Provider, FUEL_NETWORK_URL, WalletUnlocked, bn } from 'fuels';

import { getScript } from './utils';

const U32_VEC = [0, 1, 2];
const VEC_IN_VEC = [
[0, 1, 2],
[0, 1, 2],
];
const STRUCT_IN_VEC = [{ a: 0 }, { a: 1 }];
const VEC_IN_STRUCT = { a: [0, 1, 2] };
const ARRAY_IN_VEC = [
[0, 1],
[0, 1],
];
const VEC_IN_ARRAY = [
[0, 1, 2],
[0, 1, 2],
];
const VEC_IN_ENUM = { a: [0, 1, 2] };
const ENUM_IN_VEC = [{ a: 0 }, { a: 1 }];
const TUPLE_IN_VEC = [
[0, 0],
[1, 1],
];
const VEC_IN_TUPLE = [
[0, 1, 2],
[0, 1, 2],
];
const VEC_IN_A_VEC_IN_A_STRUCT_IN_A_VEC = [
{
a: [
[0, 1, 2],
[3, 4, 5],
],
},
{
a: [
[6, 7, 8],
[9, 10, 11],
],
},
];

type SomeStruct = {
a: number;
};

type SomeStructWithVec = {
a: number[];
};

type VecInAStructInAVec = {
a: number[][];
}[];

type TwoDimensionArray = number[][];

// these Type shapes are here to get the TypeScript inference, they aren't 100% accurate
type MainArgs = [
number[], // U32_VEC
TwoDimensionArray, // VEC_IN_VEC
SomeStruct[], // STRUCT_IN_VEC
SomeStructWithVec, // VEC_IN_STRUCT
TwoDimensionArray, // ARRAY_IN_VEC
TwoDimensionArray, // VEC_IN_ARRAY
SomeStructWithVec, // VEC_IN_ENUM
SomeStruct[], // ENUM_IN_VEC
TwoDimensionArray, // TUPLE_IN_VEC
TwoDimensionArray, // VEC_IN_TUPLE
VecInAStructInAVec // VEC_IN_A_VEC_IN_A_STRUCT_IN_A_VEC
];

describe('Live Script Test', () => {
it('can use script against live Fuel Node', async () => {
if (!process.env.FUEL_NETWORK_GENESIS_KEY) {
console.log('Skipping live Fuel Node test');
return;
}

const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = new WalletUnlocked(process.env.FUEL_NETWORK_GENESIS_KEY, provider);
const scriptInstance = getScript<MainArgs, BN>('vector-types-script', wallet);

let output: BN = bn(0);
try {
const { value } = await scriptInstance.functions
.main(
U32_VEC,
VEC_IN_VEC,
STRUCT_IN_VEC,
VEC_IN_STRUCT,
ARRAY_IN_VEC,
VEC_IN_ARRAY,
VEC_IN_ENUM,
ENUM_IN_VEC,
TUPLE_IN_VEC,
VEC_IN_TUPLE,
VEC_IN_A_VEC_IN_A_STRUCT_IN_A_VEC
)
.txParams({
gasPrice: 1,
})
.call();

output = value;
} catch (e) {
console.error((e as Error).message);
console.warn(`
not enough coins to fit the target?
- add assets: https://faucet-beta-4.fuel.network/
- check balance: https://fuellabs.github.io/block-explorer-v2/beta-4/#/address/fuel1nknjglsav0fs6603xmc0se2waq6qxck8sk6s7znq2y78akl4hd7qpwlm8m
- bech32 address: fuel1nknjglsav0fs6603xmc0se2waq6qxck8sk6s7znq2y78akl4hd7qpwlm8m
`);
}

expect(output.toString()).toBe('1');
});
});
2 changes: 1 addition & 1 deletion packages/wallet/src/configs.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const FUEL_NETWORK_URL = 'http://127.0.0.1:4000/graphql';
export const FUEL_NETWORK_URL = process.env.FUEL_NETWORK_URL || 'http://127.0.0.1:4000/graphql';

0 comments on commit af2500b

Please sign in to comment.