11import 'should' ;
22import { TestBitGo , TestBitGoAPI } from '@bitgo/sdk-test' ;
33import { BitGoAPI } from '@bitgo/sdk-api' ;
4- import { Apt , Tapt } from '../../src' ;
4+ import { Apt , Tapt , TransferTransaction } from '../../src' ;
55import * as testData from '../resources/apt' ;
66import _ from 'lodash' ;
77import sinon from 'sinon' ;
@@ -18,6 +18,7 @@ import {
1818 Network ,
1919} from '@aptos-labs/ts-sdk' ;
2020import utils from '../../src/lib/utils' ;
21+ import { coins } from '@bitgo/statics' ;
2122
2223describe ( 'APT:' , function ( ) {
2324 let bitgo : TestBitGoAPI ;
@@ -100,7 +101,7 @@ describe('APT:', function () {
100101 } ) ;
101102 } ) ;
102103
103- describe ( 'Parse Transactions: ' , ( ) => {
104+ describe ( 'Parse and Explain Transactions: ' , ( ) => {
104105 const transferInputsResponse = [
105106 {
106107 address : testData . sender2 . address ,
@@ -126,6 +127,48 @@ describe('APT:', function () {
126127 } ) ;
127128 } ) ;
128129
130+ it ( 'should explain a transfer transaction' , async function ( ) {
131+ const rawTx = newTxPrebuild ( ) . txHex ;
132+ const transaction = new TransferTransaction ( coins . get ( 'tapt' ) ) ;
133+ transaction . fromRawTransaction ( rawTx ) ;
134+ const explainedTx = transaction . explainTransaction ( ) ;
135+ console . log ( explainedTx ) ;
136+ explainedTx . should . deepEqual ( {
137+ displayOrder : [
138+ 'id' ,
139+ 'outputs' ,
140+ 'outputAmount' ,
141+ 'changeOutputs' ,
142+ 'changeAmount' ,
143+ 'fee' ,
144+ 'withdrawAmount' ,
145+ 'sender' ,
146+ 'type' ,
147+ ] ,
148+ id : '0x43ea7697550d5effb68c47488fd32a7756ee418e8d2be7d6b7f634f3ac0d7766' ,
149+ outputs : [
150+ {
151+ address : '0xf7405c28a02cf5bab4ea4498240bb3579db45951794eb1c843bef0534c093ad9' ,
152+ amount : '1000' ,
153+ } ,
154+ ] ,
155+ outputAmount : '1000' ,
156+ changeOutputs : [ ] ,
157+ changeAmount : '0' ,
158+ fee : { fee : 'UNKNOWN' } ,
159+ sender : '0xc8f02d25aa698b3e9fbd8a08e8da4c8ee261832a25a4cde8731b5ec356537d09' ,
160+ type : 0 ,
161+ } ) ;
162+ } ) ;
163+
164+ it ( 'should fail to explain a invalid raw transaction' , async function ( ) {
165+ const rawTx = 'invalidRawTransaction' ;
166+ const transaction = new TransferTransaction ( coins . get ( 'tapt' ) ) ;
167+ await assert . rejects ( async ( ) => transaction . fromRawTransaction ( rawTx ) , {
168+ message : 'invalid raw transaction' ,
169+ } ) ;
170+ } ) ;
171+
129172 it ( 'should fail to parse a transfer transaction when explainTransaction response is undefined' , async function ( ) {
130173 const stub = sinon . stub ( Apt . prototype , 'explainTransaction' ) ;
131174 stub . resolves ( undefined ) ;
0 commit comments