Skip to content

Commit

Permalink
refactor(sdk-api): send many uniform error messages fix
Browse files Browse the repository at this point in the history
Ticket: WIN-3945
  • Loading branch information
krupanand-bitgo committed Dec 7, 2024
1 parent 986e2f1 commit 27ed6c5
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 18 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions modules/abstract-eth/src/abstractEthLikeNewCoins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion modules/abstract-eth/test/unit/coin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
4 changes: 3 additions & 1 deletion modules/sdk-coin-arbeth/test/unit/arbeth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
6 changes: 4 additions & 2 deletions modules/sdk-coin-avaxc/src/avaxc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion modules/sdk-coin-avaxc/test/unit/avaxc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
4 changes: 3 additions & 1 deletion modules/sdk-coin-bera/test/unit/bera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
4 changes: 3 additions & 1 deletion modules/sdk-coin-celo/src/celo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export class Celo extends AbstractEthLikeCoin {
async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
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;
}
Expand Down
4 changes: 3 additions & 1 deletion modules/sdk-coin-dot/src/dot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,9 @@ export class Dot extends BaseCoin {
async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
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;
}
Expand Down
4 changes: 3 additions & 1 deletion modules/sdk-coin-eth/test/unit/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
4 changes: 3 additions & 1 deletion modules/sdk-coin-opeth/test/unit/opeth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
5 changes: 3 additions & 2 deletions modules/sdk-coin-polygon/test/unit/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {});

Expand Down
4 changes: 3 additions & 1 deletion modules/sdk-coin-stx/src/stx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export class Stx extends BaseCoin {
async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
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;
}
Expand Down
4 changes: 3 additions & 1 deletion modules/sdk-coin-xrp/src/xrp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion modules/sdk-coin-xtz/src/xtz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ export class Xtz extends BaseCoin {
async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
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;
}
Expand Down
4 changes: 3 additions & 1 deletion modules/sdk-coin-zketh/test/unit/zketh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 27ed6c5

Please sign in to comment.