@@ -4,8 +4,9 @@ import { BitGoAPI } from '@bitgo/sdk-api';
44import { Tao , Ttao } from '../../src' ;
55import * as sinon from 'sinon' ;
66import * as testData from './fixtures' ;
7- import { txVersion , genesisHash , specVersion } from '../resources' ;
7+ import { txVersion , genesisHash , specVersion , rawTx } from '../resources' ;
88import { afterEach } from 'mocha' ;
9+ import { TxIntentMismatchRecipientError } from '@bitgo/sdk-core' ;
910
1011describe ( 'Tao:' , function ( ) {
1112 let bitgo : TestBitGoAPI ;
@@ -508,4 +509,92 @@ describe('Tao:', function () {
508509 ) ;
509510 } ) ;
510511 } ) ;
512+
513+ describe ( 'verifyTransaction' , function ( ) {
514+ const transferTo = '5EQZSJmHuFH8asYYJruSRwpJmE5aqSdhdiX9oxRbxujKUkTe' ;
515+ const transferAmount = '2' ;
516+ const sweepTo = '5EQZSJmHuFH8asYYJruSRwpJmE5aqSdhdiX9oxRbxujKUkTe' ;
517+ const wrongAddress = '5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq' ;
518+
519+ describe ( 'transfer transaction' , function ( ) {
520+ it ( 'should return true when address and amount match' , async function ( ) {
521+ const result = await baseCoin . verifyTransaction ( {
522+ txPrebuild : { txHex : rawTx . transfer . signed } ,
523+ txParams : { recipients : [ { address : transferTo , amount : transferAmount } ] } ,
524+ } ) ;
525+ result . should . be . true ( ) ;
526+ } ) ;
527+
528+ it ( 'should throw TxIntentMismatchRecipientError for address mismatch' , async function ( ) {
529+ await baseCoin
530+ . verifyTransaction ( {
531+ txPrebuild : { txHex : rawTx . transfer . signed } ,
532+ txParams : { recipients : [ { address : wrongAddress , amount : transferAmount } ] } ,
533+ } )
534+ . should . be . rejectedWith ( TxIntentMismatchRecipientError ) ;
535+ } ) ;
536+
537+ it ( 'should throw TxIntentMismatchRecipientError for amount mismatch' , async function ( ) {
538+ await baseCoin
539+ . verifyTransaction ( {
540+ txPrebuild : { txHex : rawTx . transfer . signed } ,
541+ txParams : { recipients : [ { address : transferTo , amount : '9999' } ] } ,
542+ } )
543+ . should . be . rejectedWith ( TxIntentMismatchRecipientError ) ;
544+ } ) ;
545+ } ) ;
546+
547+ describe ( 'sweep transaction' , function ( ) {
548+ it ( 'should return true when address matches (amount check skipped for sweep)' , async function ( ) {
549+ const result = await baseCoin . verifyTransaction ( {
550+ txPrebuild : { txHex : rawTx . transferAll . signed } ,
551+ txParams : { recipients : [ { address : sweepTo , amount : '9999999' } ] } ,
552+ } ) ;
553+ result . should . be . true ( ) ;
554+ } ) ;
555+
556+ it ( 'should throw TxIntentMismatchRecipientError when sweep address does not match' , async function ( ) {
557+ await baseCoin
558+ . verifyTransaction ( {
559+ txPrebuild : { txHex : rawTx . transferAll . signed } ,
560+ txParams : { recipients : [ { address : wrongAddress , amount : '0' } ] } ,
561+ } )
562+ . should . be . rejectedWith ( TxIntentMismatchRecipientError ) ;
563+ } ) ;
564+ } ) ;
565+
566+ describe ( 'guard cases' , function ( ) {
567+ it ( 'should throw when txHex is missing' , async function ( ) {
568+ await baseCoin
569+ . verifyTransaction ( {
570+ txPrebuild : { } ,
571+ txParams : { recipients : [ { address : transferTo , amount : transferAmount } ] } ,
572+ } )
573+ . should . be . rejectedWith ( 'missing txHex in txPrebuild' ) ;
574+ } ) ;
575+
576+ it ( 'should throw when recipients has more than 1 entry' , async function ( ) {
577+ await baseCoin
578+ . verifyTransaction ( {
579+ txPrebuild : { txHex : rawTx . transfer . signed } ,
580+ txParams : {
581+ recipients : [
582+ { address : transferTo , amount : transferAmount } ,
583+ { address : wrongAddress , amount : transferAmount } ,
584+ ] ,
585+ } ,
586+ } )
587+ . should . be . rejectedWith ( / d o e s n ' t s u p p o r t s e n d i n g t o m o r e t h a n 1 d e s t i n a t i o n a d d r e s s / ) ;
588+ } ) ;
589+
590+ it ( 'should throw when recipients is an empty array' , async function ( ) {
591+ await baseCoin
592+ . verifyTransaction ( {
593+ txPrebuild : { txHex : rawTx . transfer . signed } ,
594+ txParams : { recipients : [ ] } ,
595+ } )
596+ . should . be . rejectedWith ( 'missing recipients in txParams' ) ;
597+ } ) ;
598+ } ) ;
599+ } ) ;
511600} ) ;
0 commit comments