|
1 | 1 | import { ErrorCode, FuelError } from '@fuel-ts/errors'; |
2 | 2 | import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils'; |
3 | 3 | import type { TransactionResultReceipt } from 'fuels'; |
4 | | -import { bn, getRandomB256, ContractFactory } from 'fuels'; |
5 | | -import { launchTestNode } from 'fuels/test-utils'; |
| 4 | +import { bn, getRandomB256, ContractFactory, Wallet } from 'fuels'; |
| 5 | +import { launchTestNode, TestAssetId } from 'fuels/test-utils'; |
6 | 6 |
|
7 | | -import { RevertErrorFactory, TokenContract, TokenContractFactory } from '../test/typegen'; |
| 7 | +import { |
| 8 | + CallTestContractFactory, |
| 9 | + RevertErrorFactory, |
| 10 | + TokenContract, |
| 11 | + TokenContractFactory, |
| 12 | +} from '../test/typegen'; |
8 | 13 |
|
| 14 | +import { fundAccount } from './predicate/utils/predicate'; |
9 | 15 | import { launchTestContract } from './utils'; |
10 | 16 |
|
11 | 17 | function launchContract() { |
@@ -299,4 +305,48 @@ describe('Revert Error Testing', () => { |
299 | 305 | ) |
300 | 306 | ); |
301 | 307 | }); |
| 308 | + |
| 309 | + it('should properly decode error when contract CALL receipt is not available', async () => { |
| 310 | + using launched = await launchTestNode({ |
| 311 | + contractsConfigs: [{ factory: CallTestContractFactory }], |
| 312 | + }); |
| 313 | + const { |
| 314 | + provider, |
| 315 | + wallets: [adminWallet], |
| 316 | + contracts: [contract], |
| 317 | + } = launched; |
| 318 | + |
| 319 | + const transferAmount = 100; |
| 320 | + const baseAssetId = await provider.getBaseAssetId(); |
| 321 | + |
| 322 | + const wallet = Wallet.generate({ provider }); |
| 323 | + |
| 324 | + await fundAccount(adminWallet, wallet, 500_000); |
| 325 | + |
| 326 | + contract.account = wallet; |
| 327 | + |
| 328 | + // Contract call requires an amount of asset A |
| 329 | + const scope = contract.functions.return_context_amount().callParams({ |
| 330 | + forward: [transferAmount, TestAssetId.A.value], |
| 331 | + }); |
| 332 | + |
| 333 | + const request = await scope.getTransactionRequest(); |
| 334 | + |
| 335 | + request.gasLimit = bn(100_000); |
| 336 | + request.maxFee = bn(100_000); |
| 337 | + |
| 338 | + const baseAssetResources = await wallet.getResourcesToSpend([ |
| 339 | + { amount: transferAmount, assetId: baseAssetId }, |
| 340 | + ]); |
| 341 | + |
| 342 | + // Funding the transaction only with the base asset |
| 343 | + request.addResources(baseAssetResources); |
| 344 | + |
| 345 | + const res = await wallet.sendTransaction(request); |
| 346 | + |
| 347 | + await expectToThrowFuelError(() => res.waitForResult(), { |
| 348 | + code: ErrorCode.SCRIPT_REVERTED, |
| 349 | + message: expect.stringMatching(`The transaction reverted with reason: "NotEnoughBalance".`), |
| 350 | + }); |
| 351 | + }); |
302 | 352 | }); |
0 commit comments