Skip to content

Commit

Permalink
Merge branch 'cm/issue-1276' of github.com:FuelLabs/fuels-ts into cm/…
Browse files Browse the repository at this point in the history
…issue-1276
  • Loading branch information
Cameron Manavian committed Oct 3, 2023
2 parents c6df9c8 + b1e50d2 commit dc106ae
Show file tree
Hide file tree
Showing 25 changed files with 223 additions and 129 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-cars-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/providers": minor
---

rename Provider switchUrl to connect
2 changes: 2 additions & 0 deletions .changeset/perfect-apes-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
5 changes: 5 additions & 0 deletions .changeset/three-dolls-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/program": minor
---

made prop transactionRequest protected on BaseInvocationScope in favor of getTransactionRequest
4 changes: 4 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ jobs:
- name: Build
run: pnpm build

# linting of some tests depends on pretest being run so that it generates the necessary files
- name: Pretest
run: pnpm pretest

- name: Lint
run: pnpm lint

Expand Down
1 change: 0 additions & 1 deletion apps/demo-nodejs-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"type": "module",
"license": "Apache-2.0",
"scripts": {
"build": "pnpm test",
"test": "node ./index.mjs"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion apps/demo-typegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Simple demo using Typegen generated types",
"author": "Fuel Labs <contact@fuel.sh> (https://fuel.network/)",
"scripts": {
"build": "run-s build:forc build:types",
"pretest": "run-s build:forc build:types",
"build:forc": "pnpm fuels-forc build -p contract",
"build:types": "pnpm fuels typegen -i contract/out/debug/demo-contract-abi.json -o src/generated-types"
},
Expand Down
3 changes: 2 additions & 1 deletion apps/docs-snippets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "",
"private": true,
"scripts": {
"build": "pnpm fuels-forc build -p projects"
"pretest": "pnpm build:forc",
"build:forc": "pnpm fuels-forc build -p projects"
},
"devDependencies": {
"fuels": "workspace:*",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
},
"packageManager": "pnpm@8.6.1",
"scripts": {
"dev": "nodemon --config nodemon.config.json -x 'turbo run build --filter=!fuel-gauge'",
"dev": "nodemon --config nodemon.config.json -x 'pnpm build:packages'",
"build": "turbo run build",
"build:packages": "turbo run build --filter=!docs",
"ci:test": "./scripts/ci-test.sh",
"pretest": "turbo run pretest",
"test": "jest --no-cache --runInBand --coverage",
Expand Down
3 changes: 2 additions & 1 deletion packages/abi-typegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
"dist"
],
"scripts": {
"pretest": "pnpm fuels-forc build -p test/fixtures/forc-projects",
"pretest": "pnpm build:forc",
"build": "tsup",
"build:forc": "pnpm fuels-forc build -p test/fixtures/forc-projects",
"postbuild": "tsx ../../scripts/postbuild.ts"
},
"license": "Apache-2.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/fuel-gauge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"description": "",
"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 fixtures/forc-projects",
"pretest": "run-s build:forc build:process-predicates",
"build:forc": "pnpm fuels-forc build -p fixtures/forc-projects",
"build:process-predicates": "tsx ./scripts/process-predicates.ts"
},
"license": "Apache-2.0",
Expand Down
12 changes: 8 additions & 4 deletions packages/fuel-gauge/src/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,14 @@ describe('Contract', () => {

const scope = contract.multiCall(calls).addContracts([otherContract]);

expect(scope.transactionRequest.getContractInputs()).toEqual([
const transactionRequest = await scope.getTransactionRequest();

expect(transactionRequest.getContractInputs()).toEqual([
{ contractId: contract.id.toB256(), type: 1, txPointer },
{ contractId: otherContract.id.toB256(), type: 1, txPointer },
]);

expect(scope.transactionRequest.getContractOutputs()).toEqual([
expect(transactionRequest.getContractOutputs()).toEqual([
{ type: 1, inputIndex: 0 },
{ type: 1, inputIndex: 1 },
]);
Expand Down Expand Up @@ -343,12 +345,14 @@ describe('Contract', () => {

const scope = contract.multiCall([contract.functions.foo(1336)]).addContracts([otherContract]);

expect(scope.transactionRequest.getContractInputs()).toEqual([
const transactionRequest = await scope.getTransactionRequest();

expect(transactionRequest.getContractInputs()).toEqual([
{ contractId: contract.id.toB256(), type: 1, txPointer },
{ contractId: otherContract.id.toB256(), type: 1, txPointer },
]);

expect(scope.transactionRequest.getContractOutputs()).toEqual([
expect(transactionRequest.getContractOutputs()).toEqual([
{ type: 1, inputIndex: 0 },
{ type: 1, inputIndex: 1 },
]);
Expand Down
4 changes: 2 additions & 2 deletions packages/fuel-gauge/src/std-lib-string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('std-lib-string Tests', () => {
expect(true).toBe(true);
});

it('should test bytes input [predicate-std-lib-string]', async () => {
it('should test String input [predicate-std-lib-string]', async () => {
const wallet = await setup();
const receiver = Wallet.fromAddress(Address.fromRandom(), wallet.provider);
const amountToPredicate = 100;
Expand Down Expand Up @@ -78,7 +78,7 @@ describe('std-lib-string Tests', () => {
expect(finalPredicateBalance.lte(initialPredicateBalance)).toBeTruthy();
});

it('should test bytes input [script-std-lib-string]', async () => {
it('should test String input [script-std-lib-string]', async () => {
const wallet = await setup();
type MainArgs = [string];
const scriptInstance = getScript<MainArgs, void>('script-std-lib-string', wallet);
Expand Down
6 changes: 3 additions & 3 deletions packages/program/src/functions/base-invocation-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { InputValue } from '@fuel-ts/abi-coder';
import { ErrorCode, FuelError } from '@fuel-ts/errors';
import type { AbstractContract, AbstractProgram } from '@fuel-ts/interfaces';
import { bn, toNumber } from '@fuel-ts/math';
import type { Provider, CoinQuantity, TransactionRequest } from '@fuel-ts/providers';
import type { Provider, CoinQuantity } from '@fuel-ts/providers';
import { transactionRequestify, ScriptTransactionRequest } from '@fuel-ts/providers';
import { InputType } from '@fuel-ts/transactions';
import type { BaseWalletUnlocked } from '@fuel-ts/wallet';
Expand Down Expand Up @@ -46,7 +46,7 @@ function createContractCall(funcScope: InvocationScopeLike, offset: number): Con
* Base class for managing invocation scopes and preparing transactions.
*/
export class BaseInvocationScope<TReturn = any> {
transactionRequest: ScriptTransactionRequest;
protected transactionRequest: ScriptTransactionRequest;
protected program: AbstractProgram;
protected functionInvocationScopes: Array<InvocationScopeLike> = [];
protected txParameters?: TxParams;
Expand Down Expand Up @@ -277,7 +277,7 @@ export class BaseInvocationScope<TReturn = any> {
*
* @returns The prepared transaction request.
*/
async getTransactionRequest(): Promise<TransactionRequest> {
async getTransactionRequest(): Promise<ScriptTransactionRequest> {
await this.prepareTransaction();
return this.transactionRequest;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
"dist"
],
"scripts": {
"update-schema": "get-graphql-schema http://localhost:4000/graphql > fuel-core-schema.graphql && prettier --write fuel-core-schema.graphql",
"build-operations": "pnpm graphql-codegen",
"prebuild": "pnpm build-operations",
"prebuild": "pnpm build:operations",
"build": "tsup",
"build:schema": "get-graphql-schema http://localhost:4000/graphql > fuel-core-schema.graphql && prettier --write fuel-core-schema.graphql",
"build:operations": "pnpm graphql-codegen",
"postbuild": "tsx ../../scripts/postbuild.ts"
},
"license": "Apache-2.0",
Expand Down
35 changes: 16 additions & 19 deletions packages/providers/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,33 +326,20 @@ export default class Provider {
/**
* Updates the URL for the provider and fetches the consensus parameters for the new URL, if needed.
*/
async switchUrl(url: string) {
async connect(url: string) {
this.url = url;
this.createOperations();
await this.fetchChainAndNodeInfo();
}

/**
* Retrieves and caches chain and node information if not already cached.
*
* - Checks the cache for existing chain and node information based on the current URL.
* - If not found in cache, fetches the information, caches it, and then returns the data.
* Fetches both the chain and node information, saves it to the cache, and return it.
*
* @returns NodeInfo and Chain
*/
async fetchChainAndNodeInfo() {
let nodeInfo = Provider.nodeInfoCache[this.url];
let chain = Provider.chainInfoCache[this.url];

if (!nodeInfo) {
nodeInfo = await this.fetchNode();
Provider.nodeInfoCache[this.url] = nodeInfo;
}

if (!chain) {
chain = await this.fetchChain();
Provider.chainInfoCache[this.url] = chain;
}
const chain = await this.fetchChain();
const nodeInfo = await this.fetchNode();

return {
chain,
Expand Down Expand Up @@ -483,14 +470,19 @@ export default class Provider {
*/
async fetchNode(): Promise<NodeInfo> {
const { nodeInfo } = await this.operations.getNodeInfo();
return {

const processedNodeInfo: NodeInfo = {
maxDepth: bn(nodeInfo.maxDepth),
maxTx: bn(nodeInfo.maxTx),
minGasPrice: bn(nodeInfo.minGasPrice),
nodeVersion: nodeInfo.nodeVersion,
utxoValidation: nodeInfo.utxoValidation,
vmBacktrace: nodeInfo.vmBacktrace,
};

Provider.nodeInfoCache[this.url] = processedNodeInfo;

return processedNodeInfo;
}

/**
Expand All @@ -500,7 +492,12 @@ export default class Provider {
*/
async fetchChain(): Promise<ChainInfo> {
const { chain } = await this.operations.getChain();
return processGqlChain(chain);

const processedChain = processGqlChain(chain);

Provider.chainInfoCache[this.url] = processedChain;

return processedChain;
}

/**
Expand Down
97 changes: 50 additions & 47 deletions packages/providers/test/fixtures/messageProof.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
export const messageProofResponse = {
data: {
messageProof: {
messageProof: {
proofSet: ['0x34fdfbc73458998a106b02f13bba51bc0fd36513602e312ca1d1893f2075eca5'],
proofIndex: '0',
},
blockProof: {
proofSet: [
'0x3480098c927d3a8a86745ba6c91419f04901baf5d25bbd0e6ba56fcb3b3e35bd',
'0xa8795e5d15b88c2383f5673a4658edae93dcdb7986ccfacbe916e656ec11ce70',
'0x97ea3aee8cb9ccc6593c21879979eeab0f748066b9e22e2294cb973ee5d95e3c',
'0x50a33f4fe58e35955df499092515fe2f77d7bfaed35f80194b338d7091c363ab',
'0xa07fc684d351ab1970efe9ffd04eb67b6544dd4443169ecf6dd0bfc546216211',
],
proofIndex: '432',
},
messageBlockHeader: {
id: '0x864b55089878bf7009d2ff64cbeeeeb75fcd73768785dcb75d54180e7fbaab7b',
daHeight: '0',
transactionsCount: '2',
transactionsRoot: '0xbf760e126159b72f59bde2d59a972620f826e5a5134deb2a775a21c37644e1a1',
messageReceiptCount: '1',
messageReceiptRoot: '0x34fdfbc73458998a106b02f13bba51bc0fd36513602e312ca1d1893f2075eca5',
height: '432',
prevRoot: '0x26e49e4af2253e0bca68d2a8b38fa7406a546ebc476b6ca51569cb325ad55ea6',
time: '4611686020115956241',
applicationHash: '0x76b6838a38a3049fa1dd42f923a0f287594a390493003af0f1c3da94f3d2b8c7',
},
commitBlockHeader: {
id: '0xe4dfe8fc1b5de2c669efbcc5e4c0a61db175d1b2f03e3cd46ed4396e76695c5b',
daHeight: '0',
transactionsCount: '2',
transactionsRoot: '0x471d68713ae2fef6bb3eede37a976b38390f2ab8916e463b22942e7130456a8a',
messageReceiptRoot: '0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
messageReceiptCount: '0',
height: '433',
prevRoot: '0xcc024475c2ccd175082bc233f5ebb3736e47a648a666d82567b001ab46cf0a83',
time: '4611686020115956241',
applicationHash: '0x441dece8e41d111f3a875ed89d716e48abf450ad385b111cf7c55e06e0b57d6b',
},
sender: '0x79c54219a5c910979e5e4c2728df163fa654a1fe03843e6af59daa2c3fcd42ea',
recipient: '0x00000000000000000000000047ba61eec8e5e65247d717ff236f504cf3b0a263',
nonce: '0x3e87e0f44613cabecd1aad381ad41a433afb12ec5c54c172de3db25b1b4d1b53',
amount: '10',
data: '0x',
},
import type { GqlGetMessageProofQuery } from '../../src/__generated__/operations';

export const messageProofResponse: GqlGetMessageProofQuery['messageProof'] = {
__typename: 'MessageProof',
messageProof: {
__typename: 'MerkleProof',
proofSet: ['0x34fdfbc73458998a106b02f13bba51bc0fd36513602e312ca1d1893f2075eca5'],
proofIndex: '0',
},
blockProof: {
__typename: 'MerkleProof',
proofSet: [
'0x3480098c927d3a8a86745ba6c91419f04901baf5d25bbd0e6ba56fcb3b3e35bd',
'0xa8795e5d15b88c2383f5673a4658edae93dcdb7986ccfacbe916e656ec11ce70',
'0x97ea3aee8cb9ccc6593c21879979eeab0f748066b9e22e2294cb973ee5d95e3c',
'0x50a33f4fe58e35955df499092515fe2f77d7bfaed35f80194b338d7091c363ab',
'0xa07fc684d351ab1970efe9ffd04eb67b6544dd4443169ecf6dd0bfc546216211',
],
proofIndex: '432',
},
messageBlockHeader: {
__typename: 'Header',
id: '0x864b55089878bf7009d2ff64cbeeeeb75fcd73768785dcb75d54180e7fbaab7b',
daHeight: '0',
transactionsCount: '2',
transactionsRoot: '0xbf760e126159b72f59bde2d59a972620f826e5a5134deb2a775a21c37644e1a1',
messageReceiptCount: '1',
messageReceiptRoot: '0x34fdfbc73458998a106b02f13bba51bc0fd36513602e312ca1d1893f2075eca5',
height: '432',
prevRoot: '0x26e49e4af2253e0bca68d2a8b38fa7406a546ebc476b6ca51569cb325ad55ea6',
time: '4611686020115956241',
applicationHash: '0x76b6838a38a3049fa1dd42f923a0f287594a390493003af0f1c3da94f3d2b8c7',
},
commitBlockHeader: {
__typename: 'Header',
id: '0xe4dfe8fc1b5de2c669efbcc5e4c0a61db175d1b2f03e3cd46ed4396e76695c5b',
daHeight: '0',
transactionsCount: '2',
transactionsRoot: '0x471d68713ae2fef6bb3eede37a976b38390f2ab8916e463b22942e7130456a8a',
messageReceiptRoot: '0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
messageReceiptCount: '0',
height: '433',
prevRoot: '0xcc024475c2ccd175082bc233f5ebb3736e47a648a666d82567b001ab46cf0a83',
time: '4611686020115956241',
applicationHash: '0x441dece8e41d111f3a875ed89d716e48abf450ad385b111cf7c55e06e0b57d6b',
},
sender: '0x79c54219a5c910979e5e4c2728df163fa654a1fe03843e6af59daa2c3fcd42ea',
recipient: '0x00000000000000000000000047ba61eec8e5e65247d717ff236f504cf3b0a263',
nonce: '0x3e87e0f44613cabecd1aad381ad41a433afb12ec5c54c172de3db25b1b4d1b53',
amount: '10',
data: '0x',
};
7 changes: 6 additions & 1 deletion packages/providers/test/fixtures/messageStatus.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export const messageStatusResponse = { data: { messageStatus: { state: 'SPENT' } } };
import { GqlMessageState, type GqlGetMessageStatusQuery } from '../../src/__generated__/operations';

export const messageStatusResponse: Omit<GqlGetMessageStatusQuery['messageStatus'], '__typename'> =
{
state: GqlMessageState.Spent,
};
Loading

0 comments on commit dc106ae

Please sign in to comment.