Skip to content

Commit 03b151b

Browse files
authored
fix: provider auto-refetch (#3869)
* Removing duplicated operation * Fixing `dryRun` type (it's not a mutation anymore) * Adding `latestBlock` props to `chainInfo` fragment * Considering `latestBlock` info when serializing/deserializing `chainInfo` * Using correct `consensusParametersVersion` * Fixing (false positive) test * Adding changeset * Lintfix (updating fixture) * Trigger CI
1 parent 444b80e commit 03b151b

File tree

6 files changed

+42
-11
lines changed

6 files changed

+42
-11
lines changed

.changeset/khaki-zoos-cough.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@fuel-ts/account": patch
3+
---
4+
5+
fix: provider auto-refetch

packages/account/src/providers/operations.graphql

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,11 @@ fragment chainInfoFragment on ChainInfo {
591591
consensusParameters {
592592
...consensusParametersFragment
593593
}
594+
latestBlock {
595+
header {
596+
consensusParametersVersion
597+
}
598+
}
594599
}
595600

596601
fragment contractBalanceFragment on ContractBalance {
@@ -995,12 +1000,6 @@ query getAssetDetails($assetId: AssetId!) {
9951000
}
9961001
}
9971002

998-
query daCompressedBlock($height: U32!) {
999-
daCompressedBlock(height: $height) {
1000-
bytes
1001-
}
1002-
}
1003-
10041003
query assembleTx(
10051004
$tx: HexString!
10061005
$blockHorizon: U32!
@@ -1071,7 +1070,7 @@ query assembleTx(
10711070
}
10721071
}
10731072

1074-
mutation dryRun(
1073+
query dryRun(
10751074
$encodedTransactions: [HexString!]!
10761075
$utxoValidation: Boolean
10771076
$gasPrice: U64

packages/account/src/providers/provider.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2312,10 +2312,23 @@ describe('Provider', () => {
23122312
const provider = new Provider(launched.provider.url);
23132313
const fetchChainAndNodeInfo = vi.spyOn(provider, 'fetchChainAndNodeInfo');
23142314

2315-
// calling twice
2315+
// calling once to perform the first fetch
23162316
await provider.autoRefetchConfigs();
2317+
2318+
// reset timestamp to force a refetch
23172319
provider.consensusParametersTimestamp = 0;
23182320

2321+
// mock the `getConsensusParametersVersion` to return a different value,
2322+
// thus forcing a refetch (the first value will be zero)
2323+
vi.spyOn(provider.operations, 'getConsensusParametersVersion').mockResolvedValue({
2324+
chain: {
2325+
latestBlock: {
2326+
header: { consensusParametersVersion: '1' },
2327+
},
2328+
},
2329+
});
2330+
2331+
// calling again to perform the second fetch
23192332
await provider.autoRefetchConfigs();
23202333

23212334
expect(fetchChainAndNodeInfo).toHaveBeenCalledTimes(2);

packages/account/src/providers/provider.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ export type ChainInfo = {
249249
name: string;
250250
baseChainHeight: BN;
251251
consensusParameters: ConsensusParameters;
252+
latestBlock: {
253+
header: {
254+
consensusParametersVersion: string;
255+
};
256+
};
252257
};
253258

254259
/**
@@ -1465,7 +1470,9 @@ export default class Provider {
14651470
const chainInfo = Provider.chainInfoCache[this.urlWithoutAuth];
14661471

14671472
const {
1468-
consensusParameters: { version: previous },
1473+
latestBlock: {
1474+
header: { consensusParametersVersion: previous },
1475+
},
14691476
} = chainInfo;
14701477

14711478
const {

packages/account/src/providers/utils/serialization.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export type TransactionSummaryJsonPartial = Omit<TransactionSummaryJson, 'id' |
8080

8181
/** @hidden */
8282
export const deserializeChain = (chain: ChainInfoJson): ChainInfo => {
83-
const { name, daHeight, consensusParameters } = chain;
83+
const { name, daHeight, consensusParameters, latestBlock } = chain;
8484

8585
const {
8686
contractParams,
@@ -134,12 +134,13 @@ export const deserializeChain = (chain: ChainInfoJson): ChainInfo => {
134134
},
135135
gasCosts,
136136
},
137+
latestBlock,
137138
};
138139
};
139140

140141
/** @hidden */
141142
export const serializeChain = (chain: ChainInfo): ChainInfoJson => {
142-
const { name, baseChainHeight, consensusParameters } = chain;
143+
const { name, baseChainHeight, consensusParameters, latestBlock } = chain;
143144

144145
const {
145146
contractParameters,
@@ -193,6 +194,7 @@ export const serializeChain = (chain: ChainInfo): ChainInfoJson => {
193194
},
194195
gasCosts,
195196
},
197+
latestBlock,
196198
};
197199
};
198200

packages/account/test/fixtures/chain.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,9 @@ export const MOCK_CHAIN: GqlChainInfoFragment = {
7272
newStoragePerByte: '1',
7373
},
7474
},
75+
latestBlock: {
76+
header: {
77+
consensusParametersVersion: '0',
78+
},
79+
},
7580
};

0 commit comments

Comments
 (0)