-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: map 'not enough coins' error (#2902)
* feat: map 'not enough coins' error * add testing group * handle multiple errors properly * update tests * update test * add `rawError` metadata * add docs * Update handle-gql-error-message.ts * update test * add description to docs for the error Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk> * remove 'unknown error' prefix * update error msg * remove from gql subscriber * assert `FuelError`s instead of plain errors * missing imports * set rawError to null * missing { * update error msg * fix tests * fix test Co-authored-by: Sérgio Torres <30977845+Torres-ssf@users.noreply.github.com> * reword docs Co-authored-by: Anderson Arboleya <anderson@arboleya.me> * reword docs Co-authored-by: Anderson Arboleya <anderson@arboleya.me> --------- Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk> Co-authored-by: Daniel Bate <djbate23@gmail.com> Co-authored-by: Sérgio Torres <30977845+Torres-ssf@users.noreply.github.com> Co-authored-by: Chad Nehemiah <chad.nehemiah94@gmail.com> Co-authored-by: Anderson Arboleya <anderson@arboleya.me>
- Loading branch information
1 parent
be1c43f
commit a059ea1
Showing
18 changed files
with
157 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@fuel-ts/account": patch | ||
"@fuel-ts/errors": patch | ||
--- | ||
|
||
feat: map 'not enough coins' error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/account/src/providers/utils/handle-gql-error-message.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ErrorCode, FuelError } from '@fuel-ts/errors'; | ||
import type { GraphQLError } from 'graphql'; | ||
|
||
export enum GqlErrorMessage { | ||
NOT_ENOUGH_COINS = 'not enough coins to fit the target', | ||
} | ||
|
||
export const handleGqlErrorMessage = (errorMessage: string, rawError: GraphQLError) => { | ||
switch (errorMessage) { | ||
case GqlErrorMessage.NOT_ENOUGH_COINS: | ||
throw new FuelError( | ||
ErrorCode.NOT_ENOUGH_FUNDS, | ||
`The account(s) sending the transaction don't have enough funds to cover the transaction.`, | ||
{}, | ||
rawError | ||
); | ||
default: | ||
throw new FuelError(ErrorCode.INVALID_REQUEST, errorMessage); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Contract, ErrorCode, Wallet } from 'fuels'; | ||
import { expectToThrowFuelError } from 'fuels/test-utils'; | ||
|
||
import { CallTestContractFactory } from '../test/typegen/contracts'; | ||
|
||
import { launchTestContract } from './utils'; | ||
|
||
/** | ||
* @group node | ||
*/ | ||
test('not enough coins error', async () => { | ||
using contract = await launchTestContract({ factory: CallTestContractFactory }); | ||
|
||
const emptyWallet = Wallet.generate({ provider: contract.provider }); | ||
|
||
const emptyWalletContract = new Contract(contract.id, contract.interface.jsonAbi, emptyWallet); | ||
|
||
await expectToThrowFuelError(() => emptyWalletContract.functions.return_void().call(), { | ||
code: ErrorCode.NOT_ENOUGH_FUNDS, | ||
message: `The account(s) sending the transaction don't have enough funds to cover the transaction.`, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters