@@ -2,21 +2,19 @@ import { Transaction } from '../../src';
22import { coins } from '@bitgo/statics' ;
33import assert from 'assert' ;
44import should from 'should' ;
5- import { Utils } from '../../src/lib/utils' ;
5+ import utils from '../../src/lib/utils' ;
66import { InvalidTransactionError } from '@bitgo/sdk-core' ;
77import * as testData from '../resources/icp' ;
88import { getBuilderFactory } from './getBuilderFactory' ;
99import sinon from 'sinon' ;
1010
1111describe ( 'ICP Transaction' , ( ) => {
1212 let tx : Transaction ;
13- let utils : Utils ;
1413 let serializedTxHex : any ;
1514 const config = coins . get ( 'ticp' ) ;
1615
1716 beforeEach ( ( ) => {
18- utils = new Utils ( ) ;
19- tx = new Transaction ( config , utils ) ;
17+ tx = new Transaction ( config ) ;
2018 const serializedTxFormat = {
2119 serializedTxHex : testData . PayloadsData ,
2220 publicKey : testData . Accounts . account1 . publicKey ,
@@ -25,76 +23,65 @@ describe('ICP Transaction', () => {
2523 sinon . stub ( utils , 'validateExpireTime' ) . returns ( true ) ;
2624 } ) ;
2725
28- describe ( 'empty transaction' , ( ) => {
29- it ( 'should throw an empty transaction error' , ( ) => {
30- assert . throws (
31- ( ) => tx . toBroadcastFormat ( ) ,
32- ( err ) => err instanceof InvalidTransactionError && err . message === 'Empty transaction' ,
33- 'Expected an InvalidTransactionError with message "Empty transaction"'
34- ) ;
35- assert . throws (
36- ( ) => tx . toJson ( ) ,
37- ( err ) => err instanceof InvalidTransactionError && err . message === 'Empty transaction' ,
38- 'Expected an InvalidTransactionError with message "Empty transaction"'
39- ) ;
40- } ) ;
26+ afterEach ( ( ) => {
27+ sinon . restore ( ) ;
4128 } ) ;
4229
43- describe ( 'build a txn from init() method' , ( ) => {
44- it ( 'start and build a txn with builder init method' , async ( ) => {
45- const txn = new Transaction ( config , utils ) ;
46- txn . icpTransactionData = testData . IcpTransactionData ;
47- const factory = getBuilderFactory ( 'ticp' ) ;
48- const txBuilder = factory . getTransferBuilder ( ) ;
49- txBuilder . initBuilder ( txn ) ;
50- await txBuilder . build ( ) ;
30+ it ( 'should throw an empty transaction error' , ( ) => {
31+ assert . throws (
32+ ( ) => tx . toBroadcastFormat ( ) ,
33+ ( err ) => err instanceof InvalidTransactionError && err . message === 'Empty transaction' ,
34+ 'Expected an InvalidTransactionError with message "Empty transaction"'
35+ ) ;
36+ assert . throws (
37+ ( ) => tx . toJson ( ) ,
38+ ( err ) => err instanceof InvalidTransactionError && err . message === 'Empty transaction' ,
39+ 'Expected an InvalidTransactionError with message "Empty transaction"'
40+ ) ;
41+ } ) ;
42+
43+ it ( 'start and build a txn with builder init method' , async ( ) => {
44+ const txn = new Transaction ( config ) ;
45+ txn . icpTransactionData = testData . IcpTransactionData ;
46+ const factory = getBuilderFactory ( 'ticp' ) ;
47+ const txBuilder = factory . getTransferBuilder ( ) ;
48+ txBuilder . initBuilder ( txn ) ;
49+ await txBuilder . build ( ) ;
5150
52- const icpTransaction = txBuilder . transaction . icpTransaction ;
53- const payloadsData = txBuilder . transaction . payloadsData ;
54- should . equal ( icpTransaction . metadata . memo , testData . IcpTransactionData . memo ) ;
55- should . equal ( icpTransaction . operations [ 0 ] . account . address , testData . IcpTransactionData . senderAddress ) ;
56- should . equal ( icpTransaction . operations [ 1 ] . account . address , testData . IcpTransactionData . receiverAddress ) ;
57- should . equal ( icpTransaction . operations [ 1 ] . amount . value , testData . IcpTransactionData . amount ) ;
58- should . equal ( icpTransaction . operations [ 2 ] . amount . value , testData . IcpTransactionData . fee ) ;
59- should . equal ( icpTransaction . public_keys [ 0 ] . hex_bytes , testData . IcpTransactionData . senderPublicKeyHex ) ;
60- payloadsData . payloads . should . be . an . Array ( ) ;
61- payloadsData . payloads . length . should . equal ( 1 ) ;
62- } ) ;
51+ const icpTransaction = txBuilder . transaction . icpTransaction ;
52+ const payloadsData = txBuilder . transaction . payloadsData ;
53+ should . equal ( icpTransaction . metadata . memo , testData . IcpTransactionData . memo ) ;
54+ should . equal ( icpTransaction . operations [ 0 ] . account . address , testData . IcpTransactionData . senderAddress ) ;
55+ should . equal ( icpTransaction . operations [ 1 ] . account . address , testData . IcpTransactionData . receiverAddress ) ;
56+ should . equal ( icpTransaction . operations [ 1 ] . amount . value , testData . IcpTransactionData . amount ) ;
57+ should . equal ( icpTransaction . operations [ 2 ] . amount . value , testData . IcpTransactionData . fee ) ;
58+ should . equal ( icpTransaction . public_keys [ 0 ] . hex_bytes , testData . IcpTransactionData . senderPublicKeyHex ) ;
59+ payloadsData . payloads . should . be . an . Array ( ) ;
60+ payloadsData . payloads . length . should . equal ( 1 ) ;
6361 } ) ;
6462
65- describe ( 'from raw transaction' , ( ) => {
66- it ( 'build a json transaction from raw hex' , async ( ) => {
67- await tx . fromRawTransaction ( serializedTxHex ) ;
68- const json = tx . toJson ( ) ;
69- should . equal ( json . memo , testData . ParsedRawTransaction . metadata . memo ) ;
70- should . equal ( json . feeAmount , testData . ParsedRawTransaction . operations [ 2 ] . amount . value ) ;
71- should . equal ( json . sender , testData . ParsedRawTransaction . operations [ 0 ] . account . address ) ;
72- should . equal ( json . recipient , testData . ParsedRawTransaction . operations [ 1 ] . account . address ) ;
73- should . equal ( json . senderPublicKey , testData . Accounts . account1 . publicKey ) ;
74- should . equal ( json . id , testData . OnChainTransactionHash ) ;
75- } ) ;
63+ it ( 'build a json transaction from raw hex' , async ( ) => {
64+ await tx . fromRawTransaction ( serializedTxHex ) ;
65+ const json = tx . toJson ( ) ;
66+ should . equal ( json . memo , testData . ParsedRawTransaction . metadata . memo ) ;
67+ should . equal ( json . feeAmount , testData . ParsedRawTransaction . operations [ 2 ] . amount . value ) ;
68+ should . equal ( json . sender , testData . ParsedRawTransaction . operations [ 0 ] . account . address ) ;
69+ should . equal ( json . recipient , testData . ParsedRawTransaction . operations [ 1 ] . account . address ) ;
70+ should . equal ( json . senderPublicKey , testData . Accounts . account1 . publicKey ) ;
71+ should . equal ( json . id , testData . OnChainTransactionHash ) ;
7672 } ) ;
7773
78- describe ( 'Explain' , ( ) => {
79- it ( 'explain transaction' , async ( ) => {
80- await tx . fromRawTransaction ( serializedTxHex ) ;
81- const explain = tx . explainTransaction ( ) ;
74+ it ( 'explain transaction' , async ( ) => {
75+ await tx . fromRawTransaction ( serializedTxHex ) ;
76+ const explain = tx . explainTransaction ( ) ;
8277
83- explain . outputAmount . should . equal ( '10' ) ;
84- explain . outputs [ 0 ] . amount . should . equal ( '10' ) ;
85- explain . outputs [ 0 ] . address . should . equal ( testData . Accounts . account2 . address ) ;
86- explain . fee . fee . should . equal ( '-10000' ) ;
87- explain . changeAmount . should . equal ( '0' ) ;
88- if ( explain . displayOrder !== undefined ) {
89- explain . displayOrder . should . deepEqual ( [
90- 'id' ,
91- 'outputAmount' ,
92- 'changeAmount' ,
93- 'outputs' ,
94- 'changeOutputs' ,
95- 'fee' ,
96- ] ) ;
97- }
98- } ) ;
78+ explain . outputAmount . should . equal ( '10' ) ;
79+ explain . outputs [ 0 ] . amount . should . equal ( '10' ) ;
80+ explain . outputs [ 0 ] . address . should . equal ( testData . Accounts . account2 . address ) ;
81+ explain . fee . fee . should . equal ( '-10000' ) ;
82+ explain . changeAmount . should . equal ( '0' ) ;
83+ if ( explain . displayOrder !== undefined ) {
84+ explain . displayOrder . should . deepEqual ( [ 'id' , 'outputAmount' , 'changeAmount' , 'outputs' , 'changeOutputs' , 'fee' ] ) ;
85+ }
9986 } ) ;
10087} ) ;
0 commit comments