11import _ from 'lodash' ;
22import { BitGoAPI } from '@bitgo/sdk-api' ;
33import { TestBitGo , TestBitGoAPI } from '@bitgo/sdk-test' ;
4- import { BaseCoin , ITransactionRecipient , Wallet } from '@bitgo/sdk-core' ;
4+ import { ITransactionRecipient , Wallet } from '@bitgo/sdk-core' ;
55
66import { Sip10Token } from '../../src' ;
77import * as testData from '../fixtures' ;
88
99describe ( 'Sip10Token:' , function ( ) {
1010 const sip10TokenName = 'tstx:tsip6dp' ;
1111 let bitgo : TestBitGoAPI ;
12- let basecoin : BaseCoin ;
12+ let basecoin : Sip10Token ;
1313 let newTxPrebuild : ( ) => { txHex : string ; txInfo : Record < string , unknown > } ;
1414 let newTxParams : ( ) => { recipients : ITransactionRecipient [ ] } ;
1515 let wallet : Wallet ;
@@ -23,6 +23,11 @@ describe('Sip10Token:', function () {
2323 recipients : testData . recipients ,
2424 } ;
2525
26+ const memo = {
27+ type : '' ,
28+ value : '1' ,
29+ } ;
30+
2631 before ( function ( ) {
2732 bitgo = TestBitGo . decorate ( BitGoAPI , {
2833 env : 'mock' ,
@@ -37,7 +42,7 @@ describe('Sip10Token:', function () {
3742 newTxParams = ( ) => {
3843 return _ . cloneDeep ( txParams ) ;
3944 } ;
40- basecoin = bitgo . coin ( sip10TokenName ) ;
45+ basecoin = bitgo . coin ( sip10TokenName ) as Sip10Token ;
4146 wallet = new Wallet ( bitgo , basecoin , { } ) ;
4247 } ) ;
4348
@@ -51,6 +56,7 @@ describe('Sip10Token:', function () {
5156 txPrebuild,
5257 verification,
5358 wallet,
59+ memo,
5460 } ) ;
5561 isTransactionVerified . should . equal ( true ) ;
5662 } ) ;
@@ -69,6 +75,74 @@ describe('Sip10Token:', function () {
6975 txPrebuild,
7076 verification,
7177 wallet,
78+ memo,
79+ } ) ;
80+ isTransactionVerified . should . equal ( true ) ;
81+ } ) ;
82+
83+ it ( 'should succeed to verify when memo is passed' , async function ( ) {
84+ const txPrebuild = newTxPrebuild ( ) ;
85+ txPrebuild . txHex = testData . txForExplainFungibleTokenTransferWithMemoId10 ;
86+ const txParams = newTxParams ( ) ;
87+ const verification = { } ;
88+ const memo = {
89+ type : '' ,
90+ value : '10' ,
91+ } ;
92+ const isTransactionVerified = await basecoin . verifyTransaction ( {
93+ txParams : txParams ,
94+ txPrebuild,
95+ verification,
96+ wallet,
97+ memo,
98+ } ) ;
99+ isTransactionVerified . should . equal ( true ) ;
100+ } ) ;
101+
102+ it ( 'should succeed to verify when memo is zero' , async function ( ) {
103+ const txPrebuild = newTxPrebuild ( ) ;
104+ const txParams = newTxParams ( ) ;
105+ txPrebuild . txHex = testData . txForExplainFungibleTokenTransferWithMemoZero ;
106+ const memo = {
107+ type : '' ,
108+ value : '0' ,
109+ } ;
110+ const verification = { } ;
111+ const isTransactionVerified = await basecoin . verifyTransaction ( {
112+ txParams : txParams ,
113+ txPrebuild,
114+ verification,
115+ wallet,
116+ memo,
117+ } ) ;
118+ isTransactionVerified . should . equal ( true ) ;
119+ } ) ;
120+
121+ it ( 'should succeed to verify when memo is passed inside recipient address' , async function ( ) {
122+ const txPrebuild = newTxPrebuild ( ) ;
123+ const txParams = newTxParams ( ) ;
124+ txParams . recipients [ 0 ] . address = 'SN2NN1JP9AEP5BVE19RNJ6T2MP7NDGRZYST1VDF3M?memoId=10' ;
125+ txPrebuild . txHex = testData . txForExplainFungibleTokenTransferWithMemoId10 ;
126+ const verification = { } ;
127+ const isTransactionVerified = await basecoin . verifyTransaction ( {
128+ txParams : txParams ,
129+ txPrebuild,
130+ verification,
131+ wallet,
132+ } ) ;
133+ isTransactionVerified . should . equal ( true ) ;
134+ } ) ;
135+
136+ it ( 'should succeed to verify when memo is not passed' , async function ( ) {
137+ const txPrebuild = newTxPrebuild ( ) ;
138+ const txParams = newTxParams ( ) ;
139+ txPrebuild . txHex = testData . txForExplainFungibleTokenTransferWithoutMemo ;
140+ const verification = { } ;
141+ const isTransactionVerified = await basecoin . verifyTransaction ( {
142+ txParams : txParams ,
143+ txPrebuild,
144+ verification,
145+ wallet,
72146 } ) ;
73147 isTransactionVerified . should . equal ( true ) ;
74148 } ) ;
@@ -148,7 +222,7 @@ describe('Sip10Token:', function () {
148222 verification,
149223 wallet,
150224 } )
151- . should . rejectedWith ( 'Tx outputs does not match with expected txParams recipients ' ) ;
225+ . should . rejectedWith ( 'Tx memo does not match with expected txParams recipient memo ' ) ;
152226 } ) ;
153227
154228 it ( 'should fail to verify transaction with wrong token' , async function ( ) {
0 commit comments