kaspad/dagconfig/genesis_test.go
2018-10-15 15:17:41 +03:00

276 lines
13 KiB
Go

// Copyright (c) 2014-2016 The btcsuite developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package dagconfig
import (
"bytes"
"testing"
"github.com/davecgh/go-spew/spew"
)
// TestGenesisBlock tests the genesis block of the main network for validity by
// checking the encoded bytes and hashes.
func TestGenesisBlock(t *testing.T) {
// Encode the genesis block to raw bytes.
var buf bytes.Buffer
err := MainNetParams.GenesisBlock.Serialize(&buf)
if err != nil {
t.Fatalf("TestGenesisBlock: %v", err)
}
// Ensure the encoded block matches the expected bytes.
if !bytes.Equal(buf.Bytes(), genesisBlockBytes) {
t.Fatalf("TestGenesisBlock: Genesis block does not appear valid - "+
"got %v, want %v", spew.Sdump(buf.Bytes()),
spew.Sdump(genesisBlockBytes))
}
// Check hash of the block against expected hash.
hash := MainNetParams.GenesisBlock.BlockHash()
if !MainNetParams.GenesisHash.IsEqual(&hash) {
t.Fatalf("TestGenesisBlock: Genesis block hash does not "+
"appear valid - got %v, want %v", spew.Sdump(hash),
spew.Sdump(MainNetParams.GenesisHash))
}
}
// TestRegTestGenesisBlock tests the genesis block of the regression test
// network for validity by checking the encoded bytes and hashes.
func TestRegTestGenesisBlock(t *testing.T) {
// Encode the genesis block to raw bytes.
var buf bytes.Buffer
err := RegressionNetParams.GenesisBlock.Serialize(&buf)
if err != nil {
t.Fatalf("TestRegTestGenesisBlock: %v", err)
}
// Ensure the encoded block matches the expected bytes.
if !bytes.Equal(buf.Bytes(), regTestGenesisBlockBytes) {
t.Fatalf("TestRegTestGenesisBlock: Genesis block does not "+
"appear valid - got %v, want %v",
spew.Sdump(buf.Bytes()),
spew.Sdump(regTestGenesisBlockBytes))
}
// Check hash of the block against expected hash.
hash := RegressionNetParams.GenesisBlock.BlockHash()
if !RegressionNetParams.GenesisHash.IsEqual(&hash) {
t.Fatalf("TestRegTestGenesisBlock: Genesis block hash does "+
"not appear valid - got %v, want %v", spew.Sdump(hash),
spew.Sdump(RegressionNetParams.GenesisHash))
}
}
// TestTestNet3GenesisBlock tests the genesis block of the test network (version
// 3) for validity by checking the encoded bytes and hashes.
func TestTestNet3GenesisBlock(t *testing.T) {
// Encode the genesis block to raw bytes.
var buf bytes.Buffer
err := TestNet3Params.GenesisBlock.Serialize(&buf)
if err != nil {
t.Fatalf("TestTestNet3GenesisBlock: %v", err)
}
// Ensure the encoded block matches the expected bytes.
if !bytes.Equal(buf.Bytes(), testNet3GenesisBlockBytes) {
t.Fatalf("TestTestNet3GenesisBlock: Genesis block does not "+
"appear valid - got %v, want %v",
spew.Sdump(buf.Bytes()),
spew.Sdump(testNet3GenesisBlockBytes))
}
// Check hash of the block against expected hash.
hash := TestNet3Params.GenesisBlock.BlockHash()
if !TestNet3Params.GenesisHash.IsEqual(&hash) {
t.Fatalf("TestTestNet3GenesisBlock: Genesis block hash does "+
"not appear valid - got %v, want %v", spew.Sdump(hash),
spew.Sdump(TestNet3Params.GenesisHash))
}
}
// TestSimNetGenesisBlock tests the genesis block of the simulation test network
// for validity by checking the encoded bytes and hashes.
func TestSimNetGenesisBlock(t *testing.T) {
// Encode the genesis block to raw bytes.
var buf bytes.Buffer
err := SimNetParams.GenesisBlock.Serialize(&buf)
if err != nil {
t.Fatalf("TestSimNetGenesisBlock: %v", err)
}
// Ensure the encoded block matches the expected bytes.
if !bytes.Equal(buf.Bytes(), simNetGenesisBlockBytes) {
t.Fatalf("TestSimNetGenesisBlock: Genesis block does not "+
"appear valid - got %v, want %v",
spew.Sdump(buf.Bytes()),
spew.Sdump(simNetGenesisBlockBytes))
}
// Check hash of the block against expected hash.
hash := SimNetParams.GenesisBlock.BlockHash()
if !SimNetParams.GenesisHash.IsEqual(&hash) {
t.Fatalf("TestSimNetGenesisBlock: Genesis block hash does "+
"not appear valid - got %v, want %v", spew.Sdump(hash),
spew.Sdump(SimNetParams.GenesisHash))
}
}
// genesisBlockBytes are the wire encoded bytes for the genesis block of the
// main network as of protocol version 60002.
var genesisBlockBytes = []byte{
0x01, 0x00, 0x00, 0x00, 0x00, 0x69, 0x1f, 0x2e, /* |.....i..| */
0x9c, 0x49, 0x12, 0x54, 0xc5, 0xde, 0x1d, 0x8f, /* |.I.T....| */
0xd0, 0x95, 0x40, 0x07, 0xf0, 0xda, 0x1b, 0x4c, /* |..@....L| */
0x84, 0x3c, 0x07, 0x94, 0x87, 0x6a, 0xd3, 0x0e, /* |.<...j..| */
0xca, 0x87, 0xcc, 0x4b, 0xb9, 0x6c, 0x07, 0xbe, /* |...K.l..| */
0x5b, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, /* |[.......| */
0x1e, 0x96, 0x87, 0x0d, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x80, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* |........| */
0xff, 0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, /* |...M....| */
0x1d, 0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, /* |...EThe | */
0x54, 0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, /* |Times 03| */
0x2f, 0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, /* |/Jan/200| */
0x39, 0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, /* |9 Chance| */
0x6c, 0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, /* |llor on | */
0x62, 0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, /* |brink of| */
0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, /* | second | */
0x62, 0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, /* |bailout | */
0x66, 0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, /* |for bank| */
0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* |s.......| */
0xff, 0x01, 0x00, 0xf2, 0x05, 0x2a, 0x01, 0x00, /* |.....*..| */
0x00, 0x00, 0x43, 0x41, 0x04, 0x67, 0x8a, 0xfd, /* |..CA.g..| */
0xb0, 0xfe, 0x55, 0x48, 0x27, 0x19, 0x67, 0xf1, /* |..UH'.g.| */
0xa6, 0x71, 0x30, 0xb7, 0x10, 0x5c, 0xd6, 0xa8, /* |.q0..\..| */
0x28, 0xe0, 0x39, 0x09, 0xa6, 0x79, 0x62, 0xe0, /* |(.9..yb.| */
0xea, 0x1f, 0x61, 0xde, 0xb6, 0x49, 0xf6, 0xbc, /* |..a..I..| */
0x3f, 0x4c, 0xef, 0x38, 0xc4, 0xf3, 0x55, 0x04, /* |?L.8..U.| */
0xe5, 0x1e, 0xc1, 0x12, 0xde, 0x5c, 0x38, 0x4d, /* |.....\8M| */
0xf7, 0xba, 0x0b, 0x8d, 0x57, 0x8a, 0x4c, 0x70, /* |....W.Lp| */
0x2b, 0x6b, 0xf1, 0x1d, 0x5f, 0xac, 0x00, 0x00, /* |+k.._...| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |......| */
}
// regTestGenesisBlockBytes are the wire encoded bytes for the genesis block of
// the regression test network as of protocol version 60002.
var regTestGenesisBlockBytes = []byte{
0x01, 0x00, 0x00, 0x00, 0x00, 0x69, 0x1f, 0x2e, /* |.....i..| */
0x9c, 0x49, 0x12, 0x54, 0xc5, 0xde, 0x1d, 0x8f, /* |.I.T....| */
0xd0, 0x95, 0x40, 0x07, 0xf0, 0xda, 0x1b, 0x4c, /* |..@....L| */
0x84, 0x3c, 0x07, 0x94, 0x87, 0x6a, 0xd3, 0x0e, /* |.<...j..| */
0xca, 0x87, 0xcc, 0x4b, 0xb9, 0x4b, 0x0d, 0xbe, /* |...K.K..| */
0x5b, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, /* |[.......| */
0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* | .......| */
0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* |........| */
0xff, 0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, /* |...M....| */
0x1d, 0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, /* |...EThe | */
0x54, 0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, /* |Times 03| */
0x2f, 0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, /* |/Jan/200| */
0x39, 0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, /* |9 Chance| */
0x6c, 0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, /* |llor on | */
0x62, 0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, /* |brink of| */
0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, /* | second | */
0x62, 0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, /* |bailout | */
0x66, 0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, /* |for bank| */
0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* |s.......| */
0xff, 0x01, 0x00, 0xf2, 0x05, 0x2a, 0x01, 0x00, /* |.....*..| */
0x00, 0x00, 0x43, 0x41, 0x04, 0x67, 0x8a, 0xfd, /* |..CA.g..| */
0xb0, 0xfe, 0x55, 0x48, 0x27, 0x19, 0x67, 0xf1, /* |..UH'.g.| */
0xa6, 0x71, 0x30, 0xb7, 0x10, 0x5c, 0xd6, 0xa8, /* |.q0..\..| */
0x28, 0xe0, 0x39, 0x09, 0xa6, 0x79, 0x62, 0xe0, /* |(.9..yb.| */
0xea, 0x1f, 0x61, 0xde, 0xb6, 0x49, 0xf6, 0xbc, /* |..a..I..| */
0x3f, 0x4c, 0xef, 0x38, 0xc4, 0xf3, 0x55, 0x04, /* |?L.8..U.| */
0xe5, 0x1e, 0xc1, 0x12, 0xde, 0x5c, 0x38, 0x4d, /* |.....\8M| */
0xf7, 0xba, 0x0b, 0x8d, 0x57, 0x8a, 0x4c, 0x70, /* |....W.Lp| */
0x2b, 0x6b, 0xf1, 0x1d, 0x5f, 0xac, 0x00, 0x00, /* |+k.._...| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |......| */
}
// testNet3GenesisBlockBytes are the wire encoded bytes for the genesis block of
// the test network (version 3) as of protocol version 60002.
var testNet3GenesisBlockBytes = []byte{
0x01, 0x00, 0x00, 0x00, 0x00, 0x69, 0x1f, 0x2e, /* |.....i..| */
0x9c, 0x49, 0x12, 0x54, 0xc5, 0xde, 0x1d, 0x8f, /* |.I.T....| */
0xd0, 0x95, 0x40, 0x07, 0xf0, 0xda, 0x1b, 0x4c, /* |..@....L| */
0x84, 0x3c, 0x07, 0x94, 0x87, 0x6a, 0xd3, 0x0e, /* |.<...j..| */
0xca, 0x87, 0xcc, 0x4b, 0xb9, 0x49, 0x0e, 0xbe, /* |...K.I..| */
0x5b, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, /* |[.......| */
0x1e, 0x0b, 0x56, 0x32, 0x00, 0x00, 0x00, 0x00, /* |..V2....| */
0xc0, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* |........| */
0xff, 0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, /* |...M....| */
0x1d, 0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, /* |...EThe | */
0x54, 0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, /* |Times 03| */
0x2f, 0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, /* |/Jan/200| */
0x39, 0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, /* |9 Chance| */
0x6c, 0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, /* |llor on | */
0x62, 0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, /* |brink of| */
0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, /* | second | */
0x62, 0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, /* |bailout | */
0x66, 0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, /* |for bank| */
0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* |s.......| */
0xff, 0x01, 0x00, 0xf2, 0x05, 0x2a, 0x01, 0x00, /* |.....*..| */
0x00, 0x00, 0x43, 0x41, 0x04, 0x67, 0x8a, 0xfd, /* |..CA.g..| */
0xb0, 0xfe, 0x55, 0x48, 0x27, 0x19, 0x67, 0xf1, /* |..UH'.g.| */
0xa6, 0x71, 0x30, 0xb7, 0x10, 0x5c, 0xd6, 0xa8, /* |.q0..\..| */
0x28, 0xe0, 0x39, 0x09, 0xa6, 0x79, 0x62, 0xe0, /* |(.9..yb.| */
0xea, 0x1f, 0x61, 0xde, 0xb6, 0x49, 0xf6, 0xbc, /* |..a..I..| */
0x3f, 0x4c, 0xef, 0x38, 0xc4, 0xf3, 0x55, 0x04, /* |?L.8..U.| */
0xe5, 0x1e, 0xc1, 0x12, 0xde, 0x5c, 0x38, 0x4d, /* |.....\8M| */
0xf7, 0xba, 0x0b, 0x8d, 0x57, 0x8a, 0x4c, 0x70, /* |....W.Lp| */
0x2b, 0x6b, 0xf1, 0x1d, 0x5f, 0xac, 0x00, 0x00, /* |+k.._...| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |......| */
}
// simNetGenesisBlockBytes are the wire encoded bytes for the genesis block of
// the simulation test network as of protocol version 70002.
var simNetGenesisBlockBytes = []byte{
0x01, 0x00, 0x00, 0x00, 0x00, 0x69, 0x1f, 0x2e, /* |.....i..| */
0x9c, 0x49, 0x12, 0x54, 0xc5, 0xde, 0x1d, 0x8f, /* |.I.T....| */
0xd0, 0x95, 0x40, 0x07, 0xf0, 0xda, 0x1b, 0x4c, /* |..@....L| */
0x84, 0x3c, 0x07, 0x94, 0x87, 0x6a, 0xd3, 0x0e, /* |.<...j..| */
0xca, 0x87, 0xcc, 0x4b, 0xb9, 0xfe, 0x00, 0xbe, /* |...K....| */
0x5b, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, /* |[.......| */
0x20, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* | .......| */
0xdf, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |........| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* |........| */
0xff, 0xff, 0xff, 0x4d, 0x04, 0xff, 0xff, 0x00, /* |...M....| */
0x1d, 0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, /* |...EThe | */
0x54, 0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, /* |Times 03| */
0x2f, 0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, /* |/Jan/200| */
0x39, 0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, /* |9 Chance| */
0x6c, 0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, /* |llor on | */
0x62, 0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, /* |brink of| */
0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, /* | second | */
0x62, 0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, /* |bailout | */
0x66, 0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, /* |for bank| */
0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* |s.......| */
0xff, 0x01, 0x00, 0xf2, 0x05, 0x2a, 0x01, 0x00, /* |.....*..| */
0x00, 0x00, 0x43, 0x41, 0x04, 0x67, 0x8a, 0xfd, /* |..CA.g..| */
0xb0, 0xfe, 0x55, 0x48, 0x27, 0x19, 0x67, 0xf1, /* |..UH'.g.| */
0xa6, 0x71, 0x30, 0xb7, 0x10, 0x5c, 0xd6, 0xa8, /* |.q0..\..| */
0x28, 0xe0, 0x39, 0x09, 0xa6, 0x79, 0x62, 0xe0, /* |(.9..yb.| */
0xea, 0x1f, 0x61, 0xde, 0xb6, 0x49, 0xf6, 0xbc, /* |..a..I..| */
0x3f, 0x4c, 0xef, 0x38, 0xc4, 0xf3, 0x55, 0x04, /* |?L.8..U.| */
0xe5, 0x1e, 0xc1, 0x12, 0xde, 0x5c, 0x38, 0x4d, /* |.....\8M| */
0xf7, 0xba, 0x0b, 0x8d, 0x57, 0x8a, 0x4c, 0x70, /* |....W.Lp| */
0x2b, 0x6b, 0xf1, 0x1d, 0x5f, 0xac, 0x00, 0x00, /* |+k.._...| */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* |......| */
}