@@ -6,27 +6,32 @@ var sinon = require('sinon');
6
6
7
7
var DashcoreLib = require ( '../../../index' ) ;
8
8
9
- var Script = DashcoreLib . Script ;
9
+ var Transaction = DashcoreLib . Transaction ;
10
10
var CommitmentTxPayload = DashcoreLib . Transaction . Payload . CommitmentTxPayload ;
11
11
12
12
var validCommitmentTxPayloadJSON = {
13
13
version : 1 ,
14
- height : 279326 ,
14
+ height : 137051 ,
15
15
qfcVersion : 1 ,
16
16
llmqtype : 1 ,
17
- quorumHash : '4cb9568141dded955ed90345b393fc62634be7d260ca328b89afdd0500000000' ,
17
+ quorumHash : "f015624411254dd5a806e16310e7b9989e8224796f57e42bfb01420200000000" ,
18
18
signersSize : 50 ,
19
- signers : '00000000000000' ,
19
+ signers : "ffffffffffff03" ,
20
20
validMembersSize : 50 ,
21
- validMembers : '00000000000000' ,
22
- quorumPublicKey : '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' ,
23
- quorumVvecHash : '0000000000000000000000000000000000000000000000000000000000000000' ,
24
- quorumSig : '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' ,
25
- sig : '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' ,
21
+ validMembers : "ffffffffffff03" ,
22
+ quorumPublicKey : "0ea4465cc4b2e6890e5bd37987822cabf1b79ec8dece016a3be75802482480af29f7961281405d2cb3d6e38157bda824" ,
23
+ quorumVvecHash : "e3107d64e8d2bec7dff1f6d7fd1a9d31a181c82acaf052f8d27b71507fe2db12" ,
24
+ quorumSig : "0f0a203004f025076c7c0d989464013b31a0104155946968317e6abcfafbe70a53c2b57811f0ebe888cef36eacf649401497c569a9f617c3eeaa7eacbc45969389fa229355097abe277f2452792a5f2e84e804bf2eac0843f01690fb6bd10df1" ,
25
+ sig : "195f7a49aed846bcf475a4a3500b15a626c514c9223b46ce6fef505f19af8f8e1cec554cb63a04125c2d19bf0211ea4c15f289f1413b8618abdf7295e44fb196e326a803d9d7c7c69a12314cf88e463653fde5fecb1f8c3d6791180cdc382392"
26
26
} ;
27
27
28
- var validCommitmentTxPayloadHexString = '01001e430400010001f2a1f356b9e086220d38754b1de1e4dcbd8b080c3fa0a62c2bd0961400000000320000000000000032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' ;
29
- var payload = CommitmentTxPayload . fromBuffer ( Buffer . from ( validCommitmentTxPayloadHexString , 'hex' ) ) ;
28
+ var testNetPayloadHex = '01005b170200010001f015624411254dd5a806e16310e7b9989e8224796f57e42bfb0142020000000032ffffffffffff0332ffffffffffff030ea4465cc4b2e6890e5bd37987822cabf1b79ec8dece016a3be75802482480af29f7961281405d2cb3d6e38157bda824e3107d64e8d2bec7dff1f6d7fd1a9d31a181c82acaf052f8d27b71507fe2db120f0a203004f025076c7c0d989464013b31a0104155946968317e6abcfafbe70a53c2b57811f0ebe888cef36eacf649401497c569a9f617c3eeaa7eacbc45969389fa229355097abe277f2452792a5f2e84e804bf2eac0843f01690fb6bd10df1195f7a49aed846bcf475a4a3500b15a626c514c9223b46ce6fef505f19af8f8e1cec554cb63a04125c2d19bf0211ea4c15f289f1413b8618abdf7295e44fb196e326a803d9d7c7c69a12314cf88e463653fde5fecb1f8c3d6791180cdc382392' ;
29
+ var testNetCommitmentTxHex = '03000600000000000000fd490101005b170200010001f015624411254dd5a806e16310e7b9989e8224796f57e42bfb0142020000000032ffffffffffff0332ffffffffffff030ea4465cc4b2e6890e5bd37987822cabf1b79ec8dece016a3be75802482480af29f7961281405d2cb3d6e38157bda824e3107d64e8d2bec7dff1f6d7fd1a9d31a181c82acaf052f8d27b71507fe2db120f0a203004f025076c7c0d989464013b31a0104155946968317e6abcfafbe70a53c2b57811f0ebe888cef36eacf649401497c569a9f617c3eeaa7eacbc45969389fa229355097abe277f2452792a5f2e84e804bf2eac0843f01690fb6bd10df1195f7a49aed846bcf475a4a3500b15a626c514c9223b46ce6fef505f19af8f8e1cec554cb63a04125c2d19bf0211ea4c15f289f1413b8618abdf7295e44fb196e326a803d9d7c7c69a12314cf88e463653fde5fecb1f8c3d6791180cdc382392' ;
30
+ var testNetCommitmentTxHash = 'cf4b01ce796a4f37e6af6dd62671b608160d4a39acf3bfe95f9a59d1854b63f3' ;
31
+
32
+ function getPayloadBuffer ( ) {
33
+ return Buffer . from ( testNetPayloadHex , 'hex' ) ;
34
+ }
30
35
31
36
function checkValidJSON ( payload ) {
32
37
expect ( payload . version ) . to . be . equal ( validCommitmentTxPayloadJSON . version ) ;
@@ -45,9 +50,6 @@ function checkValidJSON(payload) {
45
50
46
51
describe ( 'CommitmentTxPayload' , function ( ) {
47
52
48
- var payload = null ;
49
- var payloadBuffer = null ;
50
-
51
53
describe ( '.fromJSON' , function ( ) {
52
54
53
55
beforeEach ( function ( ) {
@@ -59,7 +61,7 @@ describe('CommitmentTxPayload', function () {
59
61
} ) ;
60
62
61
63
it ( 'Should return instance of CommitmentTxPayload and call #validate on it' , function ( ) {
62
- payload = CommitmentTxPayload . fromJSON ( validCommitmentTxPayloadJSON ) ;
64
+ var payload = CommitmentTxPayload . fromJSON ( validCommitmentTxPayloadJSON ) ;
63
65
checkValidJSON ( payload ) ;
64
66
} ) ;
65
67
} ) ;
@@ -69,33 +71,33 @@ describe('CommitmentTxPayload', function () {
69
71
sinon . spy ( CommitmentTxPayload . prototype , 'validate' ) ;
70
72
} ) ;
71
73
72
- it ( 'Should return payload buffer of specific length' , function ( ) {
74
+ after ( function ( ) {
75
+ CommitmentTxPayload . prototype . validate . restore ( ) ;
76
+ } ) ;
73
77
78
+ it ( 'Should return payload buffer of specific length' , function ( ) {
79
+ var payload = CommitmentTxPayload . fromBuffer ( getPayloadBuffer ( ) ) ;
74
80
//Manually calculated from validCommitmentTxPayloadJSON
75
- var expectedBufferLength = 329 ;
81
+ var expectedBufferLength = getPayloadBuffer ( ) . length ;
76
82
77
- payloadBuffer = payload . toBuffer ( ) ;
83
+ var payloadBuffer = payload . toBuffer ( ) ;
78
84
expect ( payloadBuffer . length ) . to . be . equal ( expectedBufferLength ) ;
79
85
} ) ;
80
-
81
- after ( function ( ) {
82
- CommitmentTxPayload . prototype . validate . restore ( ) ;
83
- } )
84
86
} ) ;
85
87
86
88
describe ( '.fromBuffer' , function ( ) {
87
89
before ( function ( ) {
88
90
sinon . spy ( CommitmentTxPayload . prototype , 'validate' ) ;
89
91
} ) ;
90
92
93
+ after ( function ( ) {
94
+ CommitmentTxPayload . prototype . validate . restore ( ) ;
95
+ } ) ;
96
+
91
97
it ( 'Should return payload from buffer' , function ( ) {
92
- var payloadFromBuffer = CommitmentTxPayload . fromBuffer ( payloadBuffer ) ;
98
+ var payloadFromBuffer = CommitmentTxPayload . fromBuffer ( getPayloadBuffer ( ) ) ;
93
99
checkValidJSON ( payloadFromBuffer ) ;
94
100
} ) ;
95
-
96
- after ( function ( ) {
97
- CommitmentTxPayload . prototype . validate . restore ( ) ;
98
- } )
99
101
} ) ;
100
102
101
103
describe ( '#toJSON' , function ( ) {
@@ -108,8 +110,24 @@ describe('CommitmentTxPayload', function () {
108
110
} ) ;
109
111
110
112
it ( 'Should be able to serialize payload JSON' , function ( ) {
113
+ var payload = CommitmentTxPayload . fromBuffer ( getPayloadBuffer ( ) ) ;
111
114
var payloadJSON = payload . toJSON ( ) ;
112
115
checkValidJSON ( payloadJSON ) ;
113
116
} ) ;
114
117
} ) ;
118
+
119
+ describe ( '#toString' , function ( ) {
120
+ it ( 'Should serizlize to the same hex string' , function ( ) {
121
+ var expectedCommitementHex = '03000600000000000000fd3d01010009020000010064b5fc275d292adda4e5c454e93f4bc47d2c77975fb0d06bb07bd6bada068bdf0c050005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' ;
122
+ var parsed = new Transaction ( expectedCommitementHex ) ;
123
+ console . log ( parsed . hash ) ;
124
+ var actualCommitementHex = parsed . toString ( ) ;
125
+ expect ( actualCommitementHex ) . to . be . equal ( expectedCommitementHex ) ;
126
+
127
+ var testnetParsedTransaction = new Transaction ( testNetCommitmentTxHex ) ;
128
+ var ped = testnetParsedTransaction . extraPayload . toJSON ( ) ;
129
+ expect ( testnetParsedTransaction . toString ( ) ) . to . be . equal ( testNetCommitmentTxHex ) ;
130
+ expect ( testnetParsedTransaction . hash ) . to . be . equal ( testNetCommitmentTxHash ) ;
131
+ } ) ;
132
+ } ) ;
115
133
} ) ;
0 commit comments