@@ -11,75 +11,81 @@ describe('Baby Custom txn Builder', () => {
1111 let bitgo : TestBitGoAPI ;
1212 let basecoin ;
1313 let factory ;
14- let testTx ;
14+ let testTxs ;
1515 before ( function ( ) {
1616 bitgo = TestBitGo . decorate ( BitGoAPI , { env : 'mock' } ) ;
1717 bitgo . safeRegister ( 'baby' , Baby . createInstance ) ;
1818 bitgo . safeRegister ( 'tbaby' , Tbaby . createInstance ) ;
1919 bitgo . initializeTestVars ( ) ;
2020 basecoin = bitgo . coin ( 'tbaby' ) ;
2121 factory = basecoin . getBuilder ( ) ;
22- testTx = testData . TEST_CUSTOM_MsgCreateBTCDelegation_TX ;
22+ testTxs = [ testData . TEST_CUSTOM_MsgCreateBTCDelegation_TX , testData . TEST_CUSTOM_MsgWithdrawReward_TX ] ;
2323 } ) ;
2424
2525 it ( 'should build a Custom tx with signature' , async function ( ) {
26- const txBuilder = factory . getCustomTransactionBuilder ( ) ;
27- txBuilder . sequence ( testTx . sequence ) ;
28- txBuilder . gasBudget ( testTx . gasBudget ) ;
29- txBuilder . messages ( [ testTx . sendMessage . value ] ) ;
30- txBuilder . publicKey ( toHex ( fromBase64 ( testTx . pubKey ) ) ) ;
31- txBuilder . addSignature ( { pub : toHex ( fromBase64 ( testTx . pubKey ) ) } , Buffer . from ( testTx . signature , 'base64' ) ) ;
26+ for ( const testTx of testTxs ) {
27+ const txBuilder = factory . getCustomTransactionBuilder ( ) ;
28+ txBuilder . sequence ( testTx . sequence ) ;
29+ txBuilder . gasBudget ( testTx . gasBudget ) ;
30+ txBuilder . messages ( [ testTx . sendMessage . value ] ) ;
31+ txBuilder . publicKey ( toHex ( fromBase64 ( testTx . pubKey ) ) ) ;
32+ txBuilder . addSignature ( { pub : toHex ( fromBase64 ( testTx . pubKey ) ) } , Buffer . from ( testTx . signature , 'base64' ) ) ;
3233
33- const tx = await txBuilder . build ( ) ;
34- const json = await ( await txBuilder . build ( ) ) . toJson ( ) ;
35- should . equal ( tx . type , TransactionType . CustomTx ) ;
36- should . deepEqual ( json . gasBudget , testTx . gasBudget ) ;
37- should . deepEqual ( json . sendMessages , [ testTx . sendMessage ] ) ;
38- should . deepEqual ( json . publicKey , toHex ( fromBase64 ( testTx . pubKey ) ) ) ;
39- should . deepEqual ( json . sequence , testTx . sequence ) ;
40- const rawTx = tx . toBroadcastFormat ( ) ;
41- should . equal ( rawTx , testTx . signedTxBase64 ) ;
42- should . deepEqual ( tx . inputs , [ ] ) ;
43- should . deepEqual ( tx . outputs , [ ] ) ;
34+ const tx = await txBuilder . build ( ) ;
35+ const json = await ( await txBuilder . build ( ) ) . toJson ( ) ;
36+ should . equal ( tx . type , TransactionType . CustomTx ) ;
37+ should . deepEqual ( json . gasBudget , testTx . gasBudget ) ;
38+ should . deepEqual ( json . sendMessages , [ testTx . sendMessage ] ) ;
39+ should . deepEqual ( json . publicKey , toHex ( fromBase64 ( testTx . pubKey ) ) ) ;
40+ should . deepEqual ( json . sequence , testTx . sequence ) ;
41+ const rawTx = tx . toBroadcastFormat ( ) ;
42+ should . equal ( rawTx , testTx . signedTxBase64 ) ;
43+ should . deepEqual ( tx . inputs , testTx . inputs ) ;
44+ should . deepEqual ( tx . outputs , testTx . outputs ) ;
45+ }
4446 } ) ;
4547
4648 it ( 'should build a Custom tx without signature' , async function ( ) {
47- const txBuilder = factory . getCustomTransactionBuilder ( ) ;
48- txBuilder . sequence ( testTx . sequence ) ;
49- txBuilder . gasBudget ( testTx . gasBudget ) ;
50- txBuilder . messages ( [ testTx . sendMessage . value ] ) ;
51- txBuilder . publicKey ( toHex ( fromBase64 ( testTx . pubKey ) ) ) ;
52- const tx = await txBuilder . build ( ) ;
53- const json = await ( await txBuilder . build ( ) ) . toJson ( ) ;
54- should . equal ( tx . type , TransactionType . CustomTx ) ;
55- should . deepEqual ( json . gasBudget , testTx . gasBudget ) ;
56- should . deepEqual ( json . sendMessages , [ testTx . sendMessage ] ) ;
57- should . deepEqual ( json . publicKey , toHex ( fromBase64 ( testTx . pubKey ) ) ) ;
58- should . deepEqual ( json . sequence , testTx . sequence ) ;
59- tx . toBroadcastFormat ( ) ;
60- should . deepEqual ( tx . inputs , [ ] ) ;
61- should . deepEqual ( tx . outputs , [ ] ) ;
49+ for ( const testTx of testTxs ) {
50+ const txBuilder = factory . getCustomTransactionBuilder ( ) ;
51+ txBuilder . sequence ( testTx . sequence ) ;
52+ txBuilder . gasBudget ( testTx . gasBudget ) ;
53+ txBuilder . messages ( [ testTx . sendMessage . value ] ) ;
54+ txBuilder . publicKey ( toHex ( fromBase64 ( testTx . pubKey ) ) ) ;
55+ const tx = await txBuilder . build ( ) ;
56+ const json = await ( await txBuilder . build ( ) ) . toJson ( ) ;
57+ should . equal ( tx . type , TransactionType . CustomTx ) ;
58+ should . deepEqual ( json . gasBudget , testTx . gasBudget ) ;
59+ should . deepEqual ( json . sendMessages , [ testTx . sendMessage ] ) ;
60+ should . deepEqual ( json . publicKey , toHex ( fromBase64 ( testTx . pubKey ) ) ) ;
61+ should . deepEqual ( json . sequence , testTx . sequence ) ;
62+ tx . toBroadcastFormat ( ) ;
63+ should . deepEqual ( tx . inputs , testTx . inputs ) ;
64+ should . deepEqual ( tx . outputs , testTx . outputs ) ;
65+ }
6266 } ) ;
6367
6468 it ( 'should sign a Custom tx' , async function ( ) {
65- const txBuilder = factory . getCustomTransactionBuilder ( ) ;
66- txBuilder . sequence ( testTx . sequence ) ;
67- txBuilder . gasBudget ( testTx . gasBudget ) ;
68- txBuilder . messages ( [ testTx . sendMessage . value ] ) ;
69- txBuilder . accountNumber ( testTx . accountNumber ) ;
70- txBuilder . chainId ( testTx . chainId ) ;
71- txBuilder . sign ( { key : toHex ( fromBase64 ( testTx . privateKey ) ) } ) ;
72- const tx = await txBuilder . build ( ) ;
73- const json = await ( await txBuilder . build ( ) ) . toJson ( ) ;
74- should . equal ( tx . type , TransactionType . CustomTx ) ;
75- should . deepEqual ( json . gasBudget , testTx . gasBudget ) ;
76- should . deepEqual ( json . sendMessages , [ testTx . sendMessage ] ) ;
77- should . deepEqual ( json . publicKey , toHex ( fromBase64 ( testTx . pubKey ) ) ) ;
78- should . deepEqual ( json . sequence , testTx . sequence ) ;
79- const rawTx = tx . toBroadcastFormat ( ) ;
80- should . equal ( tx . signature [ 0 ] , toHex ( fromBase64 ( testTx . signature ) ) ) ;
81- should . equal ( rawTx , testTx . signedTxBase64 ) ;
82- should . deepEqual ( tx . inputs , [ ] ) ;
83- should . deepEqual ( tx . outputs , [ ] ) ;
69+ for ( const testTx of testTxs ) {
70+ const txBuilder = factory . getCustomTransactionBuilder ( ) ;
71+ txBuilder . sequence ( testTx . sequence ) ;
72+ txBuilder . gasBudget ( testTx . gasBudget ) ;
73+ txBuilder . messages ( [ testTx . sendMessage . value ] ) ;
74+ txBuilder . accountNumber ( testTx . accountNumber ) ;
75+ txBuilder . chainId ( testTx . chainId ) ;
76+ txBuilder . sign ( { key : toHex ( fromBase64 ( testTx . privateKey ) ) } ) ;
77+ const tx = await txBuilder . build ( ) ;
78+ const json = await ( await txBuilder . build ( ) ) . toJson ( ) ;
79+ should . equal ( tx . type , TransactionType . CustomTx ) ;
80+ should . deepEqual ( json . gasBudget , testTx . gasBudget ) ;
81+ should . deepEqual ( json . sendMessages , [ testTx . sendMessage ] ) ;
82+ should . deepEqual ( json . publicKey , toHex ( fromBase64 ( testTx . pubKey ) ) ) ;
83+ should . deepEqual ( json . sequence , testTx . sequence ) ;
84+ const rawTx = tx . toBroadcastFormat ( ) ;
85+ should . equal ( tx . signature [ 0 ] , toHex ( fromBase64 ( testTx . signature ) ) ) ;
86+ should . equal ( rawTx , testTx . signedTxBase64 ) ;
87+ should . deepEqual ( tx . inputs , testTx . inputs ) ;
88+ should . deepEqual ( tx . outputs , testTx . outputs ) ;
89+ }
8490 } ) ;
8591} ) ;
0 commit comments