From e13b12ad992fc01ee3abb050ebf483493b329146 Mon Sep 17 00:00:00 2001 From: Krupananda Reddy Date: Tue, 3 Dec 2024 16:31:28 +0530 Subject: [PATCH] refactor(sdk-api): send many uniform error messages fix Ticket: WIN-3945 --- CODEOWNERS | 1 + modules/abstract-eth/src/abstractEthLikeNewCoins.ts | 6 ++++-- modules/abstract-eth/test/unit/coin.ts | 4 +++- modules/sdk-coin-arbeth/test/unit/arbeth.ts | 4 +++- modules/sdk-coin-avaxc/src/avaxc.ts | 6 ++++-- modules/sdk-coin-avaxc/test/unit/avaxc.ts | 4 +++- modules/sdk-coin-bera/test/unit/bera.ts | 4 +++- modules/sdk-coin-celo/src/celo.ts | 4 +++- modules/sdk-coin-celo/test/unit/celo.ts | 4 +++- modules/sdk-coin-dot/src/dot.ts | 4 +++- modules/sdk-coin-dot/test/unit/dot.ts | 4 +++- modules/sdk-coin-eth/test/unit/eth.ts | 4 +++- modules/sdk-coin-opeth/test/unit/opeth.ts | 4 +++- modules/sdk-coin-polygon/test/unit/polygon.ts | 5 +++-- modules/sdk-coin-stx/src/stx.ts | 4 +++- modules/sdk-coin-stx/test/unit/stx.ts | 4 +++- modules/sdk-coin-xrp/src/xrp.ts | 4 +++- modules/sdk-coin-xtz/src/xtz.ts | 4 +++- modules/sdk-coin-xtz/test/unit/xtz.ts | 4 +++- modules/sdk-coin-zketh/test/unit/zketh.ts | 4 +++- 20 files changed, 60 insertions(+), 22 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index abc965ec34..61c0edb3d2 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -52,6 +52,7 @@ /modules/sdk-coin-atom/ @BitGo/ethalt-team /modules/sdk-coin-avaxc/ @BitGo/ethalt-team /modules/sdk-coin-avaxp/ @BitGo/ethalt-team +/modules/sdk-coin-bera/ @BitGo/ethalt-team /modules/sdk-coin-bsc/ @BitGo/ethalt-team /modules/sdk-coin-coredao/ @BitGo/ethalt-team /modules/sdk-coin-cspr/ @BitGo/ethalt-team diff --git a/modules/abstract-eth/src/abstractEthLikeNewCoins.ts b/modules/abstract-eth/src/abstractEthLikeNewCoins.ts index 3e2d3ba3f7..7cbb321d0c 100644 --- a/modules/abstract-eth/src/abstractEthLikeNewCoins.ts +++ b/modules/abstract-eth/src/abstractEthLikeNewCoins.ts @@ -2280,8 +2280,10 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { if (txParams.hop && txParams.recipients.length > 1) { throw new Error(`tx cannot be both a batch and hop transaction`); } - if (txPrebuild.recipients.length !== 1) { - throw new Error(`txPrebuild should only have 1 recipient but ${txPrebuild.recipients.length} found`); + if (txPrebuild.recipients.length > 1) { + throw new Error( + `${this.getChain()} doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); } if (txParams.hop && txPrebuild.hopTransaction) { // Check recipient amount for hop transaction diff --git a/modules/abstract-eth/test/unit/coin.ts b/modules/abstract-eth/test/unit/coin.ts index 48cc29e8a0..9e2ba56c66 100644 --- a/modules/abstract-eth/test/unit/coin.ts +++ b/modules/abstract-eth/test/unit/coin.ts @@ -348,7 +348,9 @@ export function runTransactionVerificationTests(coinName: string, bitgo: TestBit await basecoin .verifyTransaction({ txParams, txPrebuild, wallet, verification }) - .should.be.rejectedWith('txPrebuild should only have 1 recipient but 2 found'); + .should.be.rejectedWith( + `${coinTest} doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); }); it('should reject a hop txPrebuild that does not send to its hop address', async () => { diff --git a/modules/sdk-coin-arbeth/test/unit/arbeth.ts b/modules/sdk-coin-arbeth/test/unit/arbeth.ts index 4336f8b7ea..d32da12957 100644 --- a/modules/sdk-coin-arbeth/test/unit/arbeth.ts +++ b/modules/sdk-coin-arbeth/test/unit/arbeth.ts @@ -402,7 +402,9 @@ describe('Arbitrum', function () { await basecoin .verifyTransaction({ txParams, txPrebuild, wallet, verification }) - .should.be.rejectedWith('txPrebuild should only have 1 recipient but 2 found'); + .should.be.rejectedWith( + `tarbeth doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); }); it('should reject a hop txPrebuild that does not send to its hop address', async function () { diff --git a/modules/sdk-coin-avaxc/src/avaxc.ts b/modules/sdk-coin-avaxc/src/avaxc.ts index 77ebe26837..2b644b01f5 100644 --- a/modules/sdk-coin-avaxc/src/avaxc.ts +++ b/modules/sdk-coin-avaxc/src/avaxc.ts @@ -170,8 +170,10 @@ export class AvaxC extends AbstractEthLikeNewCoins { if (txParams.hop && txParams.recipients.length > 1) { throw new Error(`tx cannot be both a batch and hop transaction`); } - if (txPrebuild.recipients.length !== 1) { - throw new Error(`txPrebuild should only have 1 recipient but ${txPrebuild.recipients.length} found`); + if (txPrebuild.recipients.length > 1) { + throw new Error( + `${this.getChain()} doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); } if (txParams.hop && txPrebuild.hopTransaction) { // Check recipient amount for hop transaction diff --git a/modules/sdk-coin-avaxc/test/unit/avaxc.ts b/modules/sdk-coin-avaxc/test/unit/avaxc.ts index 6a06801e73..309d9220e4 100644 --- a/modules/sdk-coin-avaxc/test/unit/avaxc.ts +++ b/modules/sdk-coin-avaxc/test/unit/avaxc.ts @@ -610,7 +610,9 @@ describe('Avalanche C-Chain', function () { await tavaxCoin .verifyTransaction({ txParams, txPrebuild, wallet, verification }) - .should.be.rejectedWith('txPrebuild should only have 1 recipient but 2 found'); + .should.be.rejectedWith( + `tavaxc doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); }); it('should reject a hop txPrebuild that does not send to its hop address', async function () { diff --git a/modules/sdk-coin-bera/test/unit/bera.ts b/modules/sdk-coin-bera/test/unit/bera.ts index cf6499d80f..a562ce3632 100644 --- a/modules/sdk-coin-bera/test/unit/bera.ts +++ b/modules/sdk-coin-bera/test/unit/bera.ts @@ -302,7 +302,9 @@ describe('Bera', function () { await basecoin .verifyTransaction({ txParams, txPrebuild, wallet, verification }) - .should.be.rejectedWith('txPrebuild should only have 1 recipient but 2 found'); + .should.be.rejectedWith( + `tbera doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); }); it('should reject a normal txPrebuild from the bitgo server with the wrong amount', async function () { diff --git a/modules/sdk-coin-celo/src/celo.ts b/modules/sdk-coin-celo/src/celo.ts index 9d097f382b..d021d8e86e 100644 --- a/modules/sdk-coin-celo/src/celo.ts +++ b/modules/sdk-coin-celo/src/celo.ts @@ -32,7 +32,9 @@ export class Celo extends AbstractEthLikeCoin { async verifyTransaction(params: VerifyTransactionOptions): Promise { const { txParams } = params; if (Array.isArray(txParams.recipients) && txParams.recipients.length > 1) { - throw new Error(`txParams should only have 1 recipient but ${txParams?.recipients?.length} found`); + throw new Error( + `${this.getChain()} doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); } return true; } diff --git a/modules/sdk-coin-celo/test/unit/celo.ts b/modules/sdk-coin-celo/test/unit/celo.ts index cd8ce46a7a..78fd1ce78d 100644 --- a/modules/sdk-coin-celo/test/unit/celo.ts +++ b/modules/sdk-coin-celo/test/unit/celo.ts @@ -40,7 +40,9 @@ describe('Celo Gold', function () { await basecoin .verifyTransaction({ txParams }) - .should.be.rejectedWith('txParams should only have 1 recipient but 2 found'); + .should.be.rejectedWith( + `tcelo doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); }); }); }); diff --git a/modules/sdk-coin-dot/src/dot.ts b/modules/sdk-coin-dot/src/dot.ts index 49d033b4c7..318d8863c8 100644 --- a/modules/sdk-coin-dot/src/dot.ts +++ b/modules/sdk-coin-dot/src/dot.ts @@ -641,7 +641,9 @@ export class Dot extends BaseCoin { async verifyTransaction(params: VerifyTransactionOptions): Promise { const { txParams } = params; if (Array.isArray(txParams.recipients) && txParams.recipients.length > 1) { - throw new Error(`txParams should only have 1 recipient but ${txParams?.recipients?.length} found`); + throw new Error( + `${this.getChain()} doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); } return true; } diff --git a/modules/sdk-coin-dot/test/unit/dot.ts b/modules/sdk-coin-dot/test/unit/dot.ts index 7fa5c9979e..ebd694dac0 100644 --- a/modules/sdk-coin-dot/test/unit/dot.ts +++ b/modules/sdk-coin-dot/test/unit/dot.ts @@ -665,7 +665,9 @@ describe('DOT:', function () { await basecoin .verifyTransaction({ txParams }) - .should.be.rejectedWith('txParams should only have 1 recipient but 2 found'); + .should.be.rejectedWith( + `tdot doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); }); }); }); diff --git a/modules/sdk-coin-eth/test/unit/eth.ts b/modules/sdk-coin-eth/test/unit/eth.ts index bc02e8e67d..6475b08acd 100644 --- a/modules/sdk-coin-eth/test/unit/eth.ts +++ b/modules/sdk-coin-eth/test/unit/eth.ts @@ -411,7 +411,9 @@ describe('ETH:', function () { await coin .verifyTransaction({ txParams, txPrebuild: txPrebuild as any, wallet, verification }) - .should.be.rejectedWith('txPrebuild should only have 1 recipient but 2 found'); + .should.be.rejectedWith( + `teth doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); }); it('should reject a hop txPrebuild that does not send to its hop address', async function () { diff --git a/modules/sdk-coin-opeth/test/unit/opeth.ts b/modules/sdk-coin-opeth/test/unit/opeth.ts index c5e43a887d..41319e4c34 100644 --- a/modules/sdk-coin-opeth/test/unit/opeth.ts +++ b/modules/sdk-coin-opeth/test/unit/opeth.ts @@ -398,7 +398,9 @@ describe('Optimism', function () { await basecoin .verifyTransaction({ txParams, txPrebuild, wallet, verification }) - .should.be.rejectedWith('txPrebuild should only have 1 recipient but 2 found'); + .should.be.rejectedWith( + `topeth doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); }); it('should reject a hop txPrebuild that does not send to its hop address', async function () { diff --git a/modules/sdk-coin-polygon/test/unit/polygon.ts b/modules/sdk-coin-polygon/test/unit/polygon.ts index 1cf0e5b2ac..a00ee76fac 100644 --- a/modules/sdk-coin-polygon/test/unit/polygon.ts +++ b/modules/sdk-coin-polygon/test/unit/polygon.ts @@ -387,9 +387,10 @@ describe('Polygon', function () { await basecoin .verifyTransaction({ txParams, txPrebuild, wallet, verification }) - .should.be.rejectedWith('txPrebuild should only have 1 recipient but 2 found'); + .should.be.rejectedWith( + `tpolygon doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); }); - it('should reject a hop txPrebuild that does not send to its hop address', async function () { const wallet = new Wallet(bitgo, basecoin, {}); diff --git a/modules/sdk-coin-stx/src/stx.ts b/modules/sdk-coin-stx/src/stx.ts index cf97f41bc8..943b63a57d 100644 --- a/modules/sdk-coin-stx/src/stx.ts +++ b/modules/sdk-coin-stx/src/stx.ts @@ -48,7 +48,9 @@ export class Stx extends BaseCoin { async verifyTransaction(params: VerifyTransactionOptions): Promise { const { txParams } = params; if (Array.isArray(txParams.recipients) && txParams.recipients.length > 1) { - throw new Error(`txParams should only have 1 recipient but ${txParams?.recipients?.length} found`); + throw new Error( + `${this.getChain()} doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); } return true; } diff --git a/modules/sdk-coin-stx/test/unit/stx.ts b/modules/sdk-coin-stx/test/unit/stx.ts index 3206d8ed6b..15d6d8610c 100644 --- a/modules/sdk-coin-stx/test/unit/stx.ts +++ b/modules/sdk-coin-stx/test/unit/stx.ts @@ -303,7 +303,9 @@ describe('STX:', function () { await basecoin .verifyTransaction({ txParams }) - .should.be.rejectedWith('txParams should only have 1 recipient but 2 found'); + .should.be.rejectedWith( + `tstx doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); }); }); }); diff --git a/modules/sdk-coin-xrp/src/xrp.ts b/modules/sdk-coin-xrp/src/xrp.ts index 93d9799086..57298502f2 100644 --- a/modules/sdk-coin-xrp/src/xrp.ts +++ b/modules/sdk-coin-xrp/src/xrp.ts @@ -319,7 +319,9 @@ export class Xrp extends BaseCoin { if (txParams.type === 'enabletoken') { if (txParams.recipients?.length !== 1) { - throw new Error('Only one recipient is allowed.'); + throw new Error( + `${this.getChain()} doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); } const recipient = txParams.recipients[0]; if (!recipient.tokenName) { diff --git a/modules/sdk-coin-xtz/src/xtz.ts b/modules/sdk-coin-xtz/src/xtz.ts index af8f6e5513..1581854d3e 100644 --- a/modules/sdk-coin-xtz/src/xtz.ts +++ b/modules/sdk-coin-xtz/src/xtz.ts @@ -106,7 +106,9 @@ export class Xtz extends BaseCoin { async verifyTransaction(params: VerifyTransactionOptions): Promise { const { txParams } = params; if (Array.isArray(txParams.recipients) && txParams.recipients.length > 1) { - throw new Error(`txParams should only have 1 recipient but ${txParams?.recipients?.length} found`); + throw new Error( + `${this.getChain()} doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); } return true; } diff --git a/modules/sdk-coin-xtz/test/unit/xtz.ts b/modules/sdk-coin-xtz/test/unit/xtz.ts index 22376196e5..61100dd70a 100644 --- a/modules/sdk-coin-xtz/test/unit/xtz.ts +++ b/modules/sdk-coin-xtz/test/unit/xtz.ts @@ -218,7 +218,9 @@ describe('Tezos:', function () { await basecoin .verifyTransaction({ txParams }) - .should.be.rejectedWith('txParams should only have 1 recipient but 2 found'); + .should.be.rejectedWith( + `txtz doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); }); }); }); diff --git a/modules/sdk-coin-zketh/test/unit/zketh.ts b/modules/sdk-coin-zketh/test/unit/zketh.ts index a3e2eb5bcb..a3a1a7f584 100644 --- a/modules/sdk-coin-zketh/test/unit/zketh.ts +++ b/modules/sdk-coin-zketh/test/unit/zketh.ts @@ -400,7 +400,9 @@ describe('zkSync', function () { await basecoin .verifyTransaction({ txParams, txPrebuild, wallet, verification }) - .should.be.rejectedWith('txPrebuild should only have 1 recipient but 2 found'); + .should.be.rejectedWith( + `tzketh doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` + ); }); it('should reject a hop txPrebuild that does not send to its hop address', async function () {