github.com/lbryio/lbcd@v0.22.119/chaincfg/genesis_test.go (about) 1 // Copyright (c) 2014-2016 The btcsuite developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 package chaincfg 6 7 import ( 8 "bytes" 9 "testing" 10 11 "github.com/davecgh/go-spew/spew" 12 ) 13 14 // TestGenesisBlock tests the genesis block of the main network for validity by 15 // checking the encoded bytes and hashes. 16 func TestGenesisBlock(t *testing.T) { 17 // Encode the genesis block to raw bytes. 18 var buf bytes.Buffer 19 err := MainNetParams.GenesisBlock.Serialize(&buf) 20 if err != nil { 21 t.Fatalf("TestGenesisBlock: %v", err) 22 } 23 24 // Check hash of the block against expected hash. 25 hash := MainNetParams.GenesisBlock.BlockHash() 26 if !MainNetParams.GenesisHash.IsEqual(&hash) { 27 t.Fatalf("TestGenesisBlock: Genesis block hash does not "+ 28 "appear valid - got %v, want %v", spew.Sdump(hash), 29 spew.Sdump(MainNetParams.GenesisHash)) 30 } 31 } 32 33 // TestRegTestGenesisBlock tests the genesis block of the regression test 34 // network for validity by checking the encoded bytes and hashes. 35 func TestRegTestGenesisBlock(t *testing.T) { 36 // Encode the genesis block to raw bytes. 37 var buf bytes.Buffer 38 err := RegressionNetParams.GenesisBlock.Serialize(&buf) 39 if err != nil { 40 t.Fatalf("TestRegTestGenesisBlock: %v", err) 41 } 42 43 // Check hash of the block against expected hash. 44 hash := RegressionNetParams.GenesisBlock.BlockHash() 45 if !RegressionNetParams.GenesisHash.IsEqual(&hash) { 46 t.Fatalf("TestRegTestGenesisBlock: Genesis block hash does "+ 47 "not appear valid - got %v, want %v", spew.Sdump(hash), 48 spew.Sdump(RegressionNetParams.GenesisHash)) 49 } 50 } 51 52 // TestTestNet3GenesisBlock tests the genesis block of the test network (version 53 // 3) for validity by checking the encoded bytes and hashes. 54 func TestTestNet3GenesisBlock(t *testing.T) { 55 // Encode the genesis block to raw bytes. 56 var buf bytes.Buffer 57 err := TestNet3Params.GenesisBlock.Serialize(&buf) 58 if err != nil { 59 t.Fatalf("TestTestNet3GenesisBlock: %v", err) 60 } 61 62 // Check hash of the block against expected hash. 63 hash := TestNet3Params.GenesisBlock.BlockHash() 64 if !TestNet3Params.GenesisHash.IsEqual(&hash) { 65 t.Fatalf("TestTestNet3GenesisBlock: Genesis block hash does "+ 66 "not appear valid - got %v, want %v", spew.Sdump(hash), 67 spew.Sdump(TestNet3Params.GenesisHash)) 68 } 69 } 70 71 // TestSimNetGenesisBlock tests the genesis block of the simulation test network 72 // for validity by checking the encoded bytes and hashes. 73 func TestSimNetGenesisBlock(t *testing.T) { 74 // Encode the genesis block to raw bytes. 75 var buf bytes.Buffer 76 err := SimNetParams.GenesisBlock.Serialize(&buf) 77 if err != nil { 78 t.Fatalf("TestSimNetGenesisBlock: %v", err) 79 } 80 81 // Check hash of the block against expected hash. 82 hash := SimNetParams.GenesisBlock.BlockHash() 83 if !SimNetParams.GenesisHash.IsEqual(&hash) { 84 t.Fatalf("TestSimNetGenesisBlock: Genesis block hash does "+ 85 "not appear valid - got %v, want %v", spew.Sdump(hash), 86 spew.Sdump(SimNetParams.GenesisHash)) 87 } 88 } 89 90 // TestSigNetGenesisBlock tests the genesis block of the signet test network for 91 // validity by checking the encoded bytes and hashes. 92 func TestSigNetGenesisBlock(t *testing.T) { 93 // Encode the genesis block to raw bytes. 94 var buf bytes.Buffer 95 err := SigNetParams.GenesisBlock.Serialize(&buf) 96 if err != nil { 97 t.Fatalf("TestSigNetGenesisBlock: %v", err) 98 } 99 100 // Check hash of the block against expected hash. 101 hash := SigNetParams.GenesisBlock.BlockHash() 102 if !SigNetParams.GenesisHash.IsEqual(&hash) { 103 t.Fatalf("TestSigNetGenesisBlock: Genesis block hash does "+ 104 "not appear valid - got %v, want %v", spew.Sdump(hash), 105 spew.Sdump(SigNetParams.GenesisHash)) 106 } 107 }