@@ -9,8 +9,8 @@ import { InputType, OutputType, ReceiptType } from '@fuel-ts/transactions';
9
9
import { DateTime , arrayify , sleep } from '@fuel-ts/utils' ;
10
10
import { ASSET_A , ASSET_B } from '@fuel-ts/utils/test-utils' ;
11
11
import { versions } from '@fuel-ts/versions' ;
12
- import * as fuelTsVersionsMod from '@fuel-ts/versions' ;
13
12
13
+ import { Wallet } from '..' ;
14
14
import {
15
15
messageStatusResponse ,
16
16
MESSAGE_PROOF_RAW_RESPONSE ,
@@ -20,6 +20,7 @@ import {
20
20
MOCK_TX_UNKNOWN_RAW_PAYLOAD ,
21
21
MOCK_TX_SCRIPT_RAW_PAYLOAD ,
22
22
} from '../../test/fixtures/transaction-summary' ;
23
+ import { mockIncompatibleVersions } from '../../test/utils/mockIncompabileVersions' ;
23
24
import { setupTestProviderAndWallets , launchNode , TestMessage } from '../test-utils' ;
24
25
25
26
import type { Coin } from './coin' ;
@@ -1148,74 +1149,132 @@ describe('Provider', () => {
1148
1149
expect ( gasConfig . maxGasPerTx ) . toBeDefined ( ) ;
1149
1150
} ) ;
1150
1151
1151
- it ( 'warns on difference between major client version and supported major version' , async ( ) => {
1152
- const { FUEL_CORE } = versions ;
1153
- const [ major , minor , patch ] = FUEL_CORE . split ( '.' ) ;
1154
- const majorMismatch = major === '0' ? 1 : parseInt ( patch , 10 ) - 1 ;
1152
+ it ( 'Prepend a warning to an error with version mismatch [major]' , async ( ) => {
1153
+ const { current, supported } = mockIncompatibleVersions ( {
1154
+ isMajorMismatch : true ,
1155
+ isMinorMismatch : false ,
1156
+ } ) ;
1155
1157
1156
- const mock = {
1157
- isMajorSupported : false ,
1158
- isMinorSupported : true ,
1159
- isPatchSupported : true ,
1160
- supportedVersion : `${ majorMismatch } .${ minor } .${ patch } ` ,
1161
- } ;
1158
+ using launched = await setupTestProviderAndWallets ( ) ;
1159
+ const {
1160
+ provider : { url } ,
1161
+ } = launched ;
1162
1162
1163
- if ( mock . supportedVersion === FUEL_CORE ) {
1164
- throw new Error ( ) ;
1165
- }
1163
+ const provider = await new Provider ( url ) . init ( ) ;
1164
+ const sender = Wallet . generate ( { provider } ) ;
1165
+ const receiver = Wallet . generate ( { provider } ) ;
1166
1166
1167
- const spy = vi . spyOn ( fuelTsVersionsMod , 'checkFuelCoreVersionCompatibility' ) ;
1168
- spy . mockImplementationOnce ( ( ) => mock ) ;
1167
+ await expectToThrowFuelError ( ( ) => sender . transfer ( receiver . address , 1 ) , {
1168
+ code : ErrorCode . NOT_ENOUGH_FUNDS ,
1169
+ message : [
1170
+ `The account(s) sending the transaction don't have enough funds to cover the transaction.` ,
1171
+ `` ,
1172
+ `The Fuel Node that you are trying to connect to is using fuel-core version ${ current . FUEL_CORE } .` ,
1173
+ `The TS SDK currently supports fuel-core version ${ supported . FUEL_CORE } .` ,
1174
+ `Things may not work as expected.` ,
1175
+ ] . join ( '\n' ) ,
1176
+ } ) ;
1177
+ } ) ;
1169
1178
1170
- const consoleWarnSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
1179
+ it ( 'Prepend a warning to an error with version mismatch [minor]' , async ( ) => {
1180
+ const { current, supported } = mockIncompatibleVersions ( {
1181
+ isMajorMismatch : false ,
1182
+ isMinorMismatch : true ,
1183
+ } ) ;
1171
1184
1172
1185
using launched = await setupTestProviderAndWallets ( ) ;
1173
- const { provider } = launched ;
1186
+ const {
1187
+ provider : { url } ,
1188
+ } = launched ;
1174
1189
1175
- await new Provider ( provider . url ) . init ( ) ;
1190
+ const provider = await new Provider ( url ) . init ( ) ;
1191
+ const sender = Wallet . generate ( { provider } ) ;
1192
+ const receiver = Wallet . generate ( { provider } ) ;
1176
1193
1177
- expect ( consoleWarnSpy ) . toHaveBeenCalledOnce ( ) ;
1178
- expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
1179
- `The Fuel Node that you are trying to connect to is using fuel-core version ${ FUEL_CORE } ,
1180
- which is not supported by the version of the TS SDK that you are using.
1181
- Things may not work as expected.
1182
- Supported fuel-core version: ${ mock . supportedVersion } .`
1183
- ) ;
1194
+ await expectToThrowFuelError ( ( ) => sender . transfer ( receiver . address , 1 ) , {
1195
+ code : ErrorCode . NOT_ENOUGH_FUNDS ,
1196
+ message : [
1197
+ `The account(s) sending the transaction don't have enough funds to cover the transaction.` ,
1198
+ `` ,
1199
+ `The Fuel Node that you are trying to connect to is using fuel-core version ${ current . FUEL_CORE } .` ,
1200
+ `The TS SDK currently supports fuel-core version ${ supported . FUEL_CORE } .` ,
1201
+ `Things may not work as expected.` ,
1202
+ ] . join ( '\n' ) ,
1203
+ } ) ;
1184
1204
} ) ;
1185
1205
1186
- it ( 'warns on difference between minor client version and supported minor version' , async ( ) => {
1187
- const { FUEL_CORE } = versions ;
1188
- const [ major , minor , patch ] = FUEL_CORE . split ( '.' ) ;
1189
- const minorMismatch = minor === '0' ? 1 : parseInt ( patch , 10 ) - 1 ;
1206
+ it ( 'Prepend a warning to a subscription error with version mismatch [major]' , async ( ) => {
1207
+ const { current, supported } = mockIncompatibleVersions ( {
1208
+ isMajorMismatch : true ,
1209
+ isMinorMismatch : false ,
1210
+ } ) ;
1190
1211
1191
- const mock = {
1192
- isMajorSupported : true ,
1193
- isMinorSupported : false ,
1194
- isPatchSupported : true ,
1195
- supportedVersion : `${ major } .${ minorMismatch } .${ patch } ` ,
1196
- } ;
1212
+ using launched = await setupTestProviderAndWallets ( ) ;
1213
+ const { provider } = launched ;
1197
1214
1198
- if ( mock . supportedVersion === FUEL_CORE ) {
1199
- throw new Error ( ) ;
1200
- }
1215
+ await expectToThrowFuelError (
1216
+ async ( ) => {
1217
+ for await ( const value of await provider . operations . statusChange ( {
1218
+ transactionId : 'invalid transaction id' ,
1219
+ } ) ) {
1220
+ // shouldn't be reached and should fail if reached
1221
+ expect ( value ) . toBeFalsy ( ) ;
1222
+ }
1223
+ } ,
1201
1224
1202
- const spy = vi . spyOn ( fuelTsVersionsMod , 'checkFuelCoreVersionCompatibility' ) ;
1203
- spy . mockImplementationOnce ( ( ) => mock ) ;
1225
+ { code : FuelError . CODES . INVALID_REQUEST }
1226
+ ) ;
1204
1227
1205
- const consoleWarnSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
1228
+ const chainId = await provider . getChainId ( ) ;
1229
+ const response = new TransactionResponse ( 'invalid transaction id' , provider , chainId ) ;
1230
+
1231
+ await expectToThrowFuelError ( ( ) => response . waitForResult ( ) , {
1232
+ code : FuelError . CODES . INVALID_REQUEST ,
1233
+ message : [
1234
+ `Failed to parse "TransactionId": Invalid character 'i' at position 0` ,
1235
+ `` ,
1236
+ `The Fuel Node that you are trying to connect to is using fuel-core version ${ current . FUEL_CORE } .` ,
1237
+ `The TS SDK currently supports fuel-core version ${ supported . FUEL_CORE } .` ,
1238
+ `Things may not work as expected.` ,
1239
+ ] . join ( '\n' ) ,
1240
+ } ) ;
1241
+ } ) ;
1242
+
1243
+ it ( 'Prepend a warning to a subscription error with version mismatch [minor]' , async ( ) => {
1244
+ const { current, supported } = mockIncompatibleVersions ( {
1245
+ isMajorMismatch : false ,
1246
+ isMinorMismatch : true ,
1247
+ } ) ;
1206
1248
1207
1249
using launched = await setupTestProviderAndWallets ( ) ;
1208
1250
const { provider } = launched ;
1209
1251
1210
- await new Provider ( provider . url ) . init ( ) ;
1252
+ await expectToThrowFuelError (
1253
+ async ( ) => {
1254
+ for await ( const value of await provider . operations . statusChange ( {
1255
+ transactionId : 'invalid transaction id' ,
1256
+ } ) ) {
1257
+ // shouldn't be reached and should fail if reached
1258
+ expect ( value ) . toBeFalsy ( ) ;
1259
+ }
1260
+ } ,
1211
1261
1212
- expect ( consoleWarnSpy ) . toHaveBeenCalledOnce ( ) ;
1213
- expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
1214
- `The Fuel Node that you are trying to connect to is using fuel-core version ${ FUEL_CORE } ,
1215
- which is not supported by the version of the TS SDK that you are using.
1216
- Things may not work as expected.
1217
- Supported fuel-core version: ${ mock . supportedVersion } .`
1262
+ { code : FuelError . CODES . INVALID_REQUEST }
1218
1263
) ;
1264
+
1265
+ const chainId = await provider . getChainId ( ) ;
1266
+ const response = new TransactionResponse ( 'invalid transaction id' , provider , chainId ) ;
1267
+
1268
+ await expectToThrowFuelError ( ( ) => response . waitForResult ( ) , {
1269
+ code : FuelError . CODES . INVALID_REQUEST ,
1270
+ message : [
1271
+ `Failed to parse "TransactionId": Invalid character 'i' at position 0` ,
1272
+ `` ,
1273
+ `The Fuel Node that you are trying to connect to is using fuel-core version ${ current . FUEL_CORE } .` ,
1274
+ `The TS SDK currently supports fuel-core version ${ supported . FUEL_CORE } .` ,
1275
+ `Things may not work as expected.` ,
1276
+ ] . join ( '\n' ) ,
1277
+ } ) ;
1219
1278
} ) ;
1220
1279
1221
1280
it ( 'An invalid subscription request throws a FuelError and does not hold the test runner (closes all handles)' , async ( ) => {
0 commit comments