@@ -147,14 +147,15 @@ describe('Internet computer', function () {
147147 } ) ;
148148
149149 describe ( 'Verify a transaction' , ( ) => {
150- it ( 'should successfully verify a transaction' , async ( ) => {
150+ it ( 'should successfully verify a transaction with signable Hex ' , async ( ) => {
151151 const unsignedTxn = txBuilder . transaction . unsignedTransaction ;
152152 unsignedTxn . should . be . a . String ( ) ;
153153 const payloadsData = txBuilder . transaction . payloadsData ;
154154 const serializedTxFormat = {
155155 serializedTxHex : payloadsData ,
156156 publicKey : testData . Accounts . account1 . publicKey ,
157157 } ;
158+ const signableHex = payloadsData . payloads [ 0 ] . hex_bytes ;
158159 const serializedTxHex = Buffer . from ( JSON . stringify ( serializedTxFormat ) , 'utf-8' ) . toString ( 'hex' ) ;
159160 const txParams = {
160161 recipients : [
@@ -167,10 +168,69 @@ describe('Internet computer', function () {
167168 const response = await basecoin . verifyTransaction ( {
168169 txPrebuild : {
169170 txHex : serializedTxHex ,
171+ txInfo : signableHex ,
170172 } ,
171173 txParams : txParams ,
172174 } ) ;
173175 assert ( response ) ;
174176 } ) ;
177+
178+ it ( 'should successfully verify a transaction without signable Hex' , async ( ) => {
179+ const unsignedTxn = txBuilder . transaction . unsignedTransaction ;
180+ unsignedTxn . should . be . a . String ( ) ;
181+ const payloadsData = txBuilder . transaction . payloadsData ;
182+ const serializedTxFormat = {
183+ serializedTxHex : payloadsData ,
184+ publicKey : testData . Accounts . account1 . publicKey ,
185+ } ;
186+ const serializedTxHex = Buffer . from ( JSON . stringify ( serializedTxFormat ) , 'utf-8' ) . toString ( 'hex' ) ;
187+ const txParams = {
188+ recipients : [
189+ {
190+ address : testData . Accounts . account2 . address ,
191+ amount : '10' ,
192+ } ,
193+ ] ,
194+ } ;
195+ const response = await basecoin . verifyTransaction ( {
196+ txPrebuild : {
197+ txHex : serializedTxHex ,
198+ } ,
199+ txParams : txParams ,
200+ } ) ;
201+ assert ( response ) ;
202+ } ) ;
203+
204+ it ( 'should fail to verify a transaction with wrong signable Hex' , async ( ) => {
205+ const unsignedTxn = txBuilder . transaction . unsignedTransaction ;
206+ unsignedTxn . should . be . a . String ( ) ;
207+ const payloadsData = txBuilder . transaction . payloadsData ;
208+ const serializedTxFormat = {
209+ serializedTxHex : payloadsData ,
210+ publicKey : testData . Accounts . account1 . publicKey ,
211+ } ;
212+ const serializedTxHex = Buffer . from ( JSON . stringify ( serializedTxFormat ) , 'utf-8' ) . toString ( 'hex' ) ;
213+ const txParams = {
214+ recipients : [
215+ {
216+ address : testData . Accounts . account2 . address ,
217+ amount : '10' ,
218+ } ,
219+ ] ,
220+ } ;
221+
222+ const wrongSignableHexValues =
223+ '0a69632d72657175657374523de3c7c5b4613155b74ede2e54493f6acbe8bf6d910154fbbb3a98ba3e0098' ;
224+
225+ await basecoin
226+ . verifyTransaction ( {
227+ txPrebuild : {
228+ txHex : serializedTxHex ,
229+ txInfo : wrongSignableHexValues ,
230+ } ,
231+ txParams : txParams ,
232+ } )
233+ . should . rejectedWith ( 'generated signableHex is not equal to params.signableHex' ) ;
234+ } ) ;
175235 } ) ;
176236} ) ;
0 commit comments