Skip to content

Commit 7006cc3

Browse files
committed
fix(sdk-coin-near): unit tests for tokenEnablementValidation
Unit tests for tokenEnablementValidation changes and Making sure there is 1 user in the txParams.recipients TICKET: WP-5782
1 parent 2a4e859 commit 7006cc3

File tree

2 files changed

+97
-166
lines changed

2 files changed

+97
-166
lines changed

modules/sdk-coin-near/src/near.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import * as request from 'superagent';
1111
import { auditEddsaPrivateKey } from '@bitgo/sdk-lib-mpc';
1212
import {
1313
AuditDecryptedKeyParams,
14-
BaseAddress,
1514
BaseCoin,
1615
BaseTransaction,
1716
BitGoBase,
@@ -1075,23 +1074,6 @@ export class Near extends BaseCoin {
10751074
auditEddsaPrivateKey(prv, publicKey ?? '');
10761075
}
10771076

1078-
protected async verifyConsolidationToBaseAddress(
1079-
params: VerifyTransactionOptions,
1080-
explainedTx: TransactionExplanation
1081-
): Promise<void> {
1082-
const baseAddresses: BaseAddress[] | undefined = await params.wallet.addresses({ sort: -1, limit: 1 });
1083-
if (!baseAddresses || baseAddresses.length === 0) {
1084-
throw new Error('No base address found on wallet');
1085-
}
1086-
const baseAddress = baseAddresses[0];
1087-
1088-
for (const output of explainedTx.outputs) {
1089-
if (output.address !== baseAddress.address) {
1090-
throw new Error('tx outputs does not match with expected address');
1091-
}
1092-
}
1093-
}
1094-
10951077
private validateTokenEnablementTransaction(
10961078
transaction: Transaction,
10971079
explainedTx: TransactionExplanation,
@@ -1119,8 +1101,21 @@ export class Near extends BaseCoin {
11191101
throw new Error('Error on token enablements: transaction has no outputs to validate beneficiary');
11201102
}
11211103

1104+
// NEAR token enablements only support a single recipient
1105+
if (!txParams.recipients || txParams.recipients.length === 0) {
1106+
throw new Error('Error on token enablements: missing recipients in transaction parameters');
1107+
}
1108+
1109+
if (txParams.recipients.length !== 1) {
1110+
throw new Error('Error on token enablements: token enablement only supports a single recipient');
1111+
}
1112+
1113+
if (explainedTx.outputs.length !== 1) {
1114+
throw new Error('Error on token enablements: transaction must have exactly 1 output');
1115+
}
1116+
11221117
const output = explainedTx.outputs[0];
1123-
const recipient = txParams.recipients?.[0];
1118+
const recipient = txParams.recipients[0];
11241119

11251120
if (!recipient?.address) {
11261121
throw new Error('Error on token enablements: missing beneficiary address in transaction parameters');

0 commit comments

Comments
 (0)