2016-08-08 21:04:33 +02:00
|
|
|
// Copyright (c) 2014-2016 The btcsuite developers
|
2014-05-28 07:23:10 +02:00
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2016-04-11 21:21:40 +02:00
|
|
|
package chaincfg
|
2014-05-28 07:23:10 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2014-07-03 02:42:07 +02:00
|
|
|
"testing"
|
|
|
|
|
2014-05-28 07:23:10 +02:00
|
|
|
"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
|
2016-04-11 21:21:40 +02:00
|
|
|
err := MainNetParams.GenesisBlock.Serialize(&buf)
|
2014-05-28 07:23:10 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("TestGenesisBlock: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check hash of the block against expected hash.
|
2016-08-08 21:04:33 +02:00
|
|
|
hash := MainNetParams.GenesisBlock.BlockHash()
|
2016-04-11 21:21:40 +02:00
|
|
|
if !MainNetParams.GenesisHash.IsEqual(&hash) {
|
2014-05-28 07:23:10 +02:00
|
|
|
t.Fatalf("TestGenesisBlock: Genesis block hash does not "+
|
|
|
|
"appear valid - got %v, want %v", spew.Sdump(hash),
|
2016-04-11 21:21:40 +02:00
|
|
|
spew.Sdump(MainNetParams.GenesisHash))
|
2014-05-28 07:23:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2016-04-11 21:21:40 +02:00
|
|
|
err := RegressionNetParams.GenesisBlock.Serialize(&buf)
|
2014-05-28 07:23:10 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("TestRegTestGenesisBlock: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check hash of the block against expected hash.
|
2016-08-08 21:04:33 +02:00
|
|
|
hash := RegressionNetParams.GenesisBlock.BlockHash()
|
2016-04-11 21:21:40 +02:00
|
|
|
if !RegressionNetParams.GenesisHash.IsEqual(&hash) {
|
2014-05-28 07:23:10 +02:00
|
|
|
t.Fatalf("TestRegTestGenesisBlock: Genesis block hash does "+
|
|
|
|
"not appear valid - got %v, want %v", spew.Sdump(hash),
|
2016-04-11 21:21:40 +02:00
|
|
|
spew.Sdump(RegressionNetParams.GenesisHash))
|
2014-05-28 07:23:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2016-04-11 21:21:40 +02:00
|
|
|
err := TestNet3Params.GenesisBlock.Serialize(&buf)
|
2014-05-28 07:23:10 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("TestTestNet3GenesisBlock: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check hash of the block against expected hash.
|
2016-08-08 21:04:33 +02:00
|
|
|
hash := TestNet3Params.GenesisBlock.BlockHash()
|
2016-04-11 21:21:40 +02:00
|
|
|
if !TestNet3Params.GenesisHash.IsEqual(&hash) {
|
2014-05-28 07:23:10 +02:00
|
|
|
t.Fatalf("TestTestNet3GenesisBlock: Genesis block hash does "+
|
|
|
|
"not appear valid - got %v, want %v", spew.Sdump(hash),
|
2016-04-11 21:21:40 +02:00
|
|
|
spew.Sdump(TestNet3Params.GenesisHash))
|
2014-05-28 07:23:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-28 08:46:13 +02:00
|
|
|
// 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
|
2016-04-11 21:21:40 +02:00
|
|
|
err := SimNetParams.GenesisBlock.Serialize(&buf)
|
2014-05-28 08:46:13 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("TestSimNetGenesisBlock: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check hash of the block against expected hash.
|
2016-08-08 21:04:33 +02:00
|
|
|
hash := SimNetParams.GenesisBlock.BlockHash()
|
2016-04-11 21:21:40 +02:00
|
|
|
if !SimNetParams.GenesisHash.IsEqual(&hash) {
|
2014-05-28 08:46:13 +02:00
|
|
|
t.Fatalf("TestSimNetGenesisBlock: Genesis block hash does "+
|
|
|
|
"not appear valid - got %v, want %v", spew.Sdump(hash),
|
2016-04-11 21:21:40 +02:00
|
|
|
spew.Sdump(SimNetParams.GenesisHash))
|
2014-05-28 08:46:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-24 16:51:59 +01:00
|
|
|
// TestSigNetGenesisBlock tests the genesis block of the signet test network for
|
|
|
|
// validity by checking the encoded bytes and hashes.
|
|
|
|
func TestSigNetGenesisBlock(t *testing.T) {
|
|
|
|
// Encode the genesis block to raw bytes.
|
|
|
|
var buf bytes.Buffer
|
|
|
|
err := SigNetParams.GenesisBlock.Serialize(&buf)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("TestSigNetGenesisBlock: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check hash of the block against expected hash.
|
|
|
|
hash := SigNetParams.GenesisBlock.BlockHash()
|
|
|
|
if !SigNetParams.GenesisHash.IsEqual(&hash) {
|
|
|
|
t.Fatalf("TestSigNetGenesisBlock: Genesis block hash does "+
|
|
|
|
"not appear valid - got %v, want %v", spew.Sdump(hash),
|
|
|
|
spew.Sdump(SigNetParams.GenesisHash))
|
|
|
|
}
|
|
|
|
}
|