@@ -6,6 +6,7 @@ package chaincfg
6
6
7
7
import (
8
8
"bytes"
9
+ "github.com/stretchr/testify/require"
9
10
"testing"
10
11
11
12
"github.com/davecgh/go-spew/spew"
@@ -91,6 +92,34 @@ func TestTestNet3GenesisBlock(t *testing.T) {
91
92
}
92
93
}
93
94
95
+ // TestTestNet4GenesisBlock tests the genesis block of the test network (version
96
+ // 4) for validity by checking the encoded bytes and hashes.
97
+ func TestTestNet4GenesisBlock (t * testing.T ) {
98
+ // Encode the genesis block to raw bytes.
99
+ var buf bytes.Buffer
100
+ err := TestNet4Params .GenesisBlock .Serialize (& buf )
101
+ if err != nil {
102
+ t .Fatalf ("TestTestNet4GenesisBlock: %v" , err )
103
+ }
104
+
105
+ // Ensure the encoded block matches the expected bytes.
106
+ if ! bytes .Equal (buf .Bytes (), testNet4GenesisBlockBytes ) {
107
+ t .Fatalf ("TestTestNet4GenesisBlock: Genesis block does not " +
108
+ "appear valid - got %v, want %v" ,
109
+ spew .Sdump (buf .Bytes ()),
110
+ spew .Sdump (testNet4GenesisBlockBytes ))
111
+ }
112
+
113
+ // Check hash of the block against expected hash.
114
+ hash := TestNet4Params .GenesisBlock .BlockHash ()
115
+ if ! TestNet4Params .GenesisHash .IsEqual (& hash ) {
116
+ t .Fatalf ("TestTestNet4GenesisBlock: Genesis block hash does " +
117
+ "not appear valid - got %v, want %v" , spew .Sdump (hash ),
118
+ spew .Sdump (TestNet4Params .GenesisHash ))
119
+ }
120
+ require .Equal (t , "00000000da84f2bafbbc53dee25a72ae507ff4914b867c565be350b0da8bf043" , hash .String ())
121
+ }
122
+
94
123
// TestSimNetGenesisBlock tests the genesis block of the simulation test network
95
124
// for validity by checking the encoded bytes and hashes.
96
125
func TestSimNetGenesisBlock (t * testing.T ) {
@@ -268,6 +297,44 @@ var testNet3GenesisBlockBytes = []byte{
268
297
0xac , 0x00 , 0x00 , 0x00 , 0x00 , /* |.....| */
269
298
}
270
299
300
+ // testNet4GenesisBlockBytes are the wire encoded bytes for the genesis block of
301
+ // the test network (version 4)
302
+ var testNet4GenesisBlockBytes = []byte {
303
+ 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
304
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
305
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
306
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
307
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x4e , 0x7b , 0x2b , 0x91 ,
308
+ 0x28 , 0xfe , 0x02 , 0x91 , 0xdb , 0x06 , 0x93 , 0xaf ,
309
+ 0x2a , 0xe4 , 0x18 , 0xb7 , 0x67 , 0xe6 , 0x57 , 0xcd ,
310
+ 0x40 , 0x7e , 0x80 , 0xcb , 0x14 , 0x34 , 0x22 , 0x1e ,
311
+ 0xae , 0xa7 , 0xa0 , 0x7a , 0x04 , 0x6f , 0x35 , 0x66 ,
312
+ 0xff , 0xff , 0x00 , 0x1d , 0xbb , 0x0c , 0x78 , 0x17 ,
313
+ 0x01 , 0x01 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 ,
314
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
315
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
316
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
317
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0xff , 0xff ,
318
+ 0xff , 0xff , 0x55 , 0x04 , 0xff , 0xff , 0x00 , 0x1d ,
319
+ 0x01 , 0x04 , 0x4c , 0x4c , 0x30 , 0x33 , 0x2f , 0x4d ,
320
+ 0x61 , 0x79 , 0x2f , 0x32 , 0x30 , 0x32 , 0x34 , 0x20 ,
321
+ 0x30 , 0x30 , 0x30 , 0x30 , 0x30 , 0x30 , 0x30 , 0x30 ,
322
+ 0x30 , 0x30 , 0x30 , 0x30 , 0x30 , 0x30 , 0x30 , 0x30 ,
323
+ 0x30 , 0x30 , 0x30 , 0x30 , 0x31 , 0x65 , 0x62 , 0x64 ,
324
+ 0x35 , 0x38 , 0x63 , 0x32 , 0x34 , 0x34 , 0x39 , 0x37 ,
325
+ 0x30 , 0x62 , 0x33 , 0x61 , 0x61 , 0x39 , 0x64 , 0x37 ,
326
+ 0x38 , 0x33 , 0x62 , 0x62 , 0x30 , 0x30 , 0x31 , 0x30 ,
327
+ 0x31 , 0x31 , 0x66 , 0x62 , 0x65 , 0x38 , 0x65 , 0x61 ,
328
+ 0x38 , 0x65 , 0x39 , 0x38 , 0x65 , 0x30 , 0x30 , 0x65 ,
329
+ 0xff , 0xff , 0xff , 0xff , 0x01 , 0x00 , 0xf2 , 0x05 ,
330
+ 0x2a , 0x01 , 0x00 , 0x00 , 0x00 , 0x23 , 0x21 , 0x00 ,
331
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
332
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
333
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
334
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
335
+ 0xac , 0x00 , 0x00 , 0x00 , 0x00 ,
336
+ }
337
+
271
338
// simNetGenesisBlockBytes are the wire encoded bytes for the genesis block of
272
339
// the simulation test network as of protocol version 70002.
273
340
var simNetGenesisBlockBytes = []byte {
0 commit comments