|
1 | 1 | import 'should'; |
| 2 | +import assert from 'assert'; |
2 | 3 |
|
3 | 4 | import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test'; |
4 | 5 | import { BitGoAPI } from '@bitgo/sdk-api'; |
@@ -39,4 +40,123 @@ describe('Native BNB', function () { |
39 | 40 | tbsc.allowsAccountConsolidations().should.equal(true); |
40 | 41 | }); |
41 | 42 | }); |
| 43 | + |
| 44 | + describe('verifyTssTransaction', function () { |
| 45 | + let bsc: Bsc; |
| 46 | + |
| 47 | + before(function () { |
| 48 | + bsc = bitgo.coin('bsc') as Bsc; |
| 49 | + }); |
| 50 | + |
| 51 | + const baseTxPrebuild = { txHex: '0xdeadbeef' } as any; |
| 52 | + const baseWallet = {} as any; |
| 53 | + |
| 54 | + it('returns true immediately when skipTssRecipientVerification is true', async function () { |
| 55 | + const result = await bsc.verifyTssTransaction({ |
| 56 | + txParams: {} as any, |
| 57 | + txPrebuild: baseTxPrebuild, |
| 58 | + wallet: baseWallet, |
| 59 | + verification: { skipTssRecipientVerification: true }, |
| 60 | + }); |
| 61 | + assert.strictEqual(result, true); |
| 62 | + }); |
| 63 | + |
| 64 | + it('throws when no recipients and skipTssRecipientVerification is false', async function () { |
| 65 | + await assert.rejects( |
| 66 | + () => |
| 67 | + bsc.verifyTssTransaction({ |
| 68 | + txParams: {} as any, |
| 69 | + txPrebuild: baseTxPrebuild, |
| 70 | + wallet: baseWallet, |
| 71 | + verification: { skipTssRecipientVerification: false }, |
| 72 | + }), |
| 73 | + /missing txParams/ |
| 74 | + ); |
| 75 | + }); |
| 76 | + |
| 77 | + it('throws when no recipients and verification is not set', async function () { |
| 78 | + await assert.rejects( |
| 79 | + () => |
| 80 | + bsc.verifyTssTransaction({ |
| 81 | + txParams: {} as any, |
| 82 | + txPrebuild: baseTxPrebuild, |
| 83 | + wallet: baseWallet, |
| 84 | + }), |
| 85 | + /missing txParams/ |
| 86 | + ); |
| 87 | + }); |
| 88 | + |
| 89 | + it('returns true for exempt type without skipTssRecipientVerification', async function () { |
| 90 | + const result = await bsc.verifyTssTransaction({ |
| 91 | + txParams: { type: 'delegate' } as any, |
| 92 | + txPrebuild: baseTxPrebuild, |
| 93 | + wallet: baseWallet, |
| 94 | + }); |
| 95 | + assert.strictEqual(result, true); |
| 96 | + }); |
| 97 | + |
| 98 | + it('returns true when recipients are present without flag', async function () { |
| 99 | + const result = await bsc.verifyTssTransaction({ |
| 100 | + txParams: { recipients: [{ address: '0xabc', amount: '100' }] } as any, |
| 101 | + txPrebuild: baseTxPrebuild, |
| 102 | + wallet: baseWallet, |
| 103 | + }); |
| 104 | + assert.strictEqual(result, true); |
| 105 | + }); |
| 106 | + |
| 107 | + it('still throws missing params when wallet is missing even with skipTssRecipientVerification', async function () { |
| 108 | + await assert.rejects( |
| 109 | + () => |
| 110 | + bsc.verifyTssTransaction({ |
| 111 | + txParams: {} as any, |
| 112 | + txPrebuild: baseTxPrebuild, |
| 113 | + wallet: undefined as any, |
| 114 | + verification: { skipTssRecipientVerification: true }, |
| 115 | + }), |
| 116 | + /missing params/ |
| 117 | + ); |
| 118 | + }); |
| 119 | + |
| 120 | + it('still throws missing params when txPrebuild is missing even with skipTssRecipientVerification', async function () { |
| 121 | + await assert.rejects( |
| 122 | + () => |
| 123 | + bsc.verifyTssTransaction({ |
| 124 | + txParams: {} as any, |
| 125 | + txPrebuild: undefined as any, |
| 126 | + wallet: baseWallet, |
| 127 | + verification: { skipTssRecipientVerification: true }, |
| 128 | + }), |
| 129 | + /missing params/ |
| 130 | + ); |
| 131 | + }); |
| 132 | + |
| 133 | + it('still throws hop error even with skipTssRecipientVerification', async function () { |
| 134 | + await assert.rejects( |
| 135 | + () => |
| 136 | + bsc.verifyTssTransaction({ |
| 137 | + txParams: { |
| 138 | + hop: true, |
| 139 | + recipients: [ |
| 140 | + { address: '0xabc', amount: '100' }, |
| 141 | + { address: '0xdef', amount: '200' }, |
| 142 | + ], |
| 143 | + } as any, |
| 144 | + txPrebuild: baseTxPrebuild, |
| 145 | + wallet: baseWallet, |
| 146 | + verification: { skipTssRecipientVerification: true }, |
| 147 | + }), |
| 148 | + /tx cannot be both a batch and hop transaction/ |
| 149 | + ); |
| 150 | + }); |
| 151 | + |
| 152 | + it('skips recipient check but passes other validation with skipTssRecipientVerification', async function () { |
| 153 | + const result = await bsc.verifyTssTransaction({ |
| 154 | + txParams: {} as any, |
| 155 | + txPrebuild: baseTxPrebuild, |
| 156 | + wallet: baseWallet, |
| 157 | + verification: { skipTssRecipientVerification: true }, |
| 158 | + }); |
| 159 | + assert.strictEqual(result, true); |
| 160 | + }); |
| 161 | + }); |
42 | 162 | }); |
0 commit comments