diff --git a/bench_test.go b/bench_test.go index dda4fb14..45aec7b7 100644 --- a/bench_test.go +++ b/bench_test.go @@ -11,6 +11,50 @@ import ( "testing" ) +// genesisCoinbaseTx is the coinbase transaction for the genesis blocks for +// the main network, regression test network, and test network (version 3). +var genesisCoinbaseTx = btcwire.MsgTx{ + Version: 1, + TxIn: []*btcwire.TxIn{ + { + PreviousOutpoint: btcwire.OutPoint{ + Hash: btcwire.ShaHash{}, + Index: 0xffffffff, + }, + SignatureScript: []byte{ + 0x04, 0xff, 0xff, 0x00, 0x1d, 0x01, 0x04, 0x45, /* |.......E| */ + 0x54, 0x68, 0x65, 0x20, 0x54, 0x69, 0x6d, 0x65, /* |The Time| */ + 0x73, 0x20, 0x30, 0x33, 0x2f, 0x4a, 0x61, 0x6e, /* |s 03/Jan| */ + 0x2f, 0x32, 0x30, 0x30, 0x39, 0x20, 0x43, 0x68, /* |/2009 Ch| */ + 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x6c, 0x6f, 0x72, /* |ancellor| */ + 0x20, 0x6f, 0x6e, 0x20, 0x62, 0x72, 0x69, 0x6e, /* | on brin| */ + 0x6b, 0x20, 0x6f, 0x66, 0x20, 0x73, 0x65, 0x63, /* |k of sec|*/ + 0x6f, 0x6e, 0x64, 0x20, 0x62, 0x61, 0x69, 0x6c, /* |ond bail| */ + 0x6f, 0x75, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, /* |out for |*/ + 0x62, 0x61, 0x6e, 0x6b, 0x73, /* |banks| */ + }, + Sequence: 0xffffffff, + }, + }, + TxOut: []*btcwire.TxOut{ + { + Value: 0x12a05f200, + PkScript: []byte{ + 0x41, 0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, /* |A.g....U| */ + 0x48, 0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, /* |H'.g..q0| */ + 0xb7, 0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, /* |..\..(.9| */ + 0x09, 0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, /* |..yb...a| */ + 0xde, 0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, /* |..I..?L.| */ + 0x38, 0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, /* |8..U....| */ + 0x12, 0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, /* |..\8M...| */ + 0x8d, 0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, /* |.W.Lp+k.| */ + 0x1d, 0x5f, 0xac, /* |._.| */ + }, + }, + }, + LockTime: 0, +} + // BenchmarkWriteVarInt1 performs a benchmark on how long it takes to write // a single byte variable length integer. func BenchmarkWriteVarInt1(b *testing.B) { @@ -285,8 +329,7 @@ func BenchmarkWriteBlockHeader(b *testing.B) { // BenchmarkTxSha performs a benchmark on how long it takes to hash a // transaction. func BenchmarkTxSha(b *testing.B) { - tx := btcwire.GenesisBlock.Transactions[0] for i := 0; i < b.N; i++ { - tx.TxSha() + genesisCoinbaseTx.TxSha() } } diff --git a/blockheader_test.go b/blockheader_test.go index 903e7c34..d5054a05 100644 --- a/blockheader_test.go +++ b/blockheader_test.go @@ -21,8 +21,8 @@ func TestBlockHeader(t *testing.T) { } nonce := uint32(nonce64) - hash := btcwire.GenesisHash - merkleHash := btcwire.GenesisMerkleRoot + hash := mainNetGenesisHash + merkleHash := mainNetGenesisMerkleRoot bits := uint32(0x1d00ffff) bh := btcwire.NewBlockHeader(&hash, &merkleHash, bits, nonce) @@ -51,13 +51,11 @@ func TestBlockHeaderWire(t *testing.T) { nonce := uint32(123123) // 0x1e0f3 // baseBlockHdr is used in the various tests as a baseline BlockHeader. - hash := btcwire.GenesisHash - merkleHash := btcwire.GenesisMerkleRoot bits := uint32(0x1d00ffff) baseBlockHdr := &btcwire.BlockHeader{ Version: 1, - PrevBlock: hash, - MerkleRoot: merkleHash, + PrevBlock: mainNetGenesisHash, + MerkleRoot: mainNetGenesisMerkleRoot, Timestamp: time.Unix(0x495fab29, 0), // 2009-01-03 12:15:05 -0600 CST Bits: bits, Nonce: nonce, @@ -162,13 +160,11 @@ func TestBlockHeaderSerialize(t *testing.T) { nonce := uint32(123123) // 0x1e0f3 // baseBlockHdr is used in the various tests as a baseline BlockHeader. - hash := btcwire.GenesisHash - merkleHash := btcwire.GenesisMerkleRoot bits := uint32(0x1d00ffff) baseBlockHdr := &btcwire.BlockHeader{ Version: 1, - PrevBlock: hash, - MerkleRoot: merkleHash, + PrevBlock: mainNetGenesisHash, + MerkleRoot: mainNetGenesisMerkleRoot, Timestamp: time.Unix(0x495fab29, 0), // 2009-01-03 12:15:05 -0600 CST Bits: bits, Nonce: nonce, diff --git a/common_test.go b/common_test.go index b9418974..4e5fe59b 100644 --- a/common_test.go +++ b/common_test.go @@ -15,6 +15,24 @@ import ( "testing" ) +// mainNetGenesisHash is the hash of the first block in the block chain for the +// main network (genesis block). +var mainNetGenesisHash = btcwire.ShaHash{ + 0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72, + 0xc1, 0xa6, 0xa2, 0x46, 0xae, 0x63, 0xf7, 0x4f, + 0x93, 0x1e, 0x83, 0x65, 0xe1, 0x5a, 0x08, 0x9c, + 0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, +} + +// mainNetGenesisMerkleRoot is the hash of the first transaction in the genesis +// block for the main network. +var mainNetGenesisMerkleRoot = btcwire.ShaHash{ + 0x3b, 0xa3, 0xed, 0xfd, 0x7a, 0x7b, 0x12, 0xb2, + 0x7a, 0xc7, 0x2c, 0x3e, 0x67, 0x76, 0x8f, 0x61, + 0x7f, 0xc8, 0x1b, 0xc3, 0x88, 0x8a, 0x51, 0x32, + 0x3a, 0x9f, 0xb8, 0xaa, 0x4b, 0x1e, 0x5e, 0x4a, +} + // fakeRandReader implements the io.Reader interface and is used to force // errors in the RandomUint64 function. type fakeRandReader struct { diff --git a/genesis.go b/genesis.go deleted file mode 100644 index adbfbb0b..00000000 --- a/genesis.go +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright (c) 2013-2014 Conformal Systems LLC. -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -package btcwire - -import ( - "time" -) - -// genesisCoinbaseTx is the coinbase transaction for the genesis blocks for -// the main network, regression test network, and test network (version 3). -var genesisCoinbaseTx = MsgTx{ - Version: 1, - TxIn: []*TxIn{ - { - PreviousOutpoint: OutPoint{ - Hash: ShaHash{}, - Index: 0xffffffff, - }, - SignatureScript: []byte{ - 0x04, 0xff, 0xff, 0x00, 0x1d, 0x01, 0x04, 0x45, /* |.......E| */ - 0x54, 0x68, 0x65, 0x20, 0x54, 0x69, 0x6d, 0x65, /* |The Time| */ - 0x73, 0x20, 0x30, 0x33, 0x2f, 0x4a, 0x61, 0x6e, /* |s 03/Jan| */ - 0x2f, 0x32, 0x30, 0x30, 0x39, 0x20, 0x43, 0x68, /* |/2009 Ch| */ - 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x6c, 0x6f, 0x72, /* |ancellor| */ - 0x20, 0x6f, 0x6e, 0x20, 0x62, 0x72, 0x69, 0x6e, /* | on brin| */ - 0x6b, 0x20, 0x6f, 0x66, 0x20, 0x73, 0x65, 0x63, /* |k of sec|*/ - 0x6f, 0x6e, 0x64, 0x20, 0x62, 0x61, 0x69, 0x6c, /* |ond bail| */ - 0x6f, 0x75, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, /* |out for |*/ - 0x62, 0x61, 0x6e, 0x6b, 0x73, /* |banks| */ - }, - Sequence: 0xffffffff, - }, - }, - TxOut: []*TxOut{ - { - Value: 0x12a05f200, - PkScript: []byte{ - 0x41, 0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, /* |A.g....U| */ - 0x48, 0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, /* |H'.g..q0| */ - 0xb7, 0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, /* |..\..(.9| */ - 0x09, 0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, /* |..yb...a| */ - 0xde, 0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, /* |..I..?L.| */ - 0x38, 0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, /* |8..U....| */ - 0x12, 0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, /* |..\8M...| */ - 0x8d, 0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, /* |.W.Lp+k.| */ - 0x1d, 0x5f, 0xac, /* |._.| */ - }, - }, - }, - LockTime: 0, -} - -// GenesisHash is the hash of the first block in the block chain for the main -// network (genesis block). -var GenesisHash = ShaHash{ - 0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72, - 0xc1, 0xa6, 0xa2, 0x46, 0xae, 0x63, 0xf7, 0x4f, - 0x93, 0x1e, 0x83, 0x65, 0xe1, 0x5a, 0x08, 0x9c, - 0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, -} - -// GenesisMerkleRoot is the hash of the first transaction in the genesis block -// for the main network. -var GenesisMerkleRoot = ShaHash{ - 0x3b, 0xa3, 0xed, 0xfd, 0x7a, 0x7b, 0x12, 0xb2, - 0x7a, 0xc7, 0x2c, 0x3e, 0x67, 0x76, 0x8f, 0x61, - 0x7f, 0xc8, 0x1b, 0xc3, 0x88, 0x8a, 0x51, 0x32, - 0x3a, 0x9f, 0xb8, 0xaa, 0x4b, 0x1e, 0x5e, 0x4a, -} - -// GenesisBlock defines the genesis block of the block chain which serves as the -// public transaction ledger for the main network. -var GenesisBlock = MsgBlock{ - Header: BlockHeader{ - Version: 1, - PrevBlock: ShaHash{}, // 0000000000000000000000000000000000000000000000000000000000000000 - MerkleRoot: GenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b - Timestamp: time.Unix(0x495fab29, 0), // 2009-01-03 18:15:05 +0000 UTC - Bits: 0x1d00ffff, // 486604799 [00000000ffff0000000000000000000000000000000000000000000000000000] - Nonce: 0x7c2bac1d, // 2083236893 - }, - Transactions: []*MsgTx{&genesisCoinbaseTx}, -} - -// TestNetGenesisHash is the hash of the first block in the block chain for the -// regression test network (genesis block). -var TestNetGenesisHash = ShaHash{ - 0x06, 0x22, 0x6e, 0x46, 0x11, 0x1a, 0x0b, 0x59, - 0xca, 0xaf, 0x12, 0x60, 0x43, 0xeb, 0x5b, 0xbf, - 0x28, 0xc3, 0x4f, 0x3a, 0x5e, 0x33, 0x2a, 0x1f, - 0xc7, 0xb2, 0xb7, 0x3c, 0xf1, 0x88, 0x91, 0x0f, -} - -// TestNetGenesisMerkleRoot is the hash of the first transaction in the genesis -// block for the regression test network. It is the same as the merkle root for -// the main network. -var TestNetGenesisMerkleRoot = GenesisMerkleRoot - -// TestNetGenesisBlock defines the genesis block of the block chain which serves -// as the public transaction ledger for the regression test network. -var TestNetGenesisBlock = MsgBlock{ - Header: BlockHeader{ - Version: 1, - PrevBlock: ShaHash{}, // 0000000000000000000000000000000000000000000000000000000000000000 - MerkleRoot: TestNetGenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b - Timestamp: time.Unix(1296688602, 0), // 2011-02-02 23:16:42 +0000 UTC - Bits: 0x207fffff, // 545259519 [7fffff0000000000000000000000000000000000000000000000000000000000] - Nonce: 2, - }, - Transactions: []*MsgTx{&genesisCoinbaseTx}, -} - -// TestNet3GenesisHash is the hash of the first block in the block chain for the -// test network (version 3). -var TestNet3GenesisHash = ShaHash{ - 0x43, 0x49, 0x7f, 0xd7, 0xf8, 0x26, 0x95, 0x71, - 0x08, 0xf4, 0xa3, 0x0f, 0xd9, 0xce, 0xc3, 0xae, - 0xba, 0x79, 0x97, 0x20, 0x84, 0xe9, 0x0e, 0xad, - 0x01, 0xea, 0x33, 0x09, 0x00, 0x00, 0x00, 0x00, -} - -// TestNet3GenesisMerkleRoot is the hash of the first transaction in the genesis -// block for the test network (version 3). It is the same as the merkle root -// for the main network. -var TestNet3GenesisMerkleRoot = GenesisMerkleRoot - -// TestNet3GenesisBlock defines the genesis block of the block chain which -// serves as the public transaction ledger for the test network (version 3). -var TestNet3GenesisBlock = MsgBlock{ - Header: BlockHeader{ - Version: 1, - PrevBlock: ShaHash{}, // 0000000000000000000000000000000000000000000000000000000000000000 - MerkleRoot: TestNet3GenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b - Timestamp: time.Unix(1296688602, 0), // 2011-02-02 23:16:42 +0000 UTC - Bits: 0x1d00ffff, // 486604799 [00000000ffff0000000000000000000000000000000000000000000000000000] - Nonce: 0x18aea41a, // 414098458 - }, - Transactions: []*MsgTx{&genesisCoinbaseTx}, -} diff --git a/genesis_test.go b/genesis_test.go deleted file mode 100644 index 5e0529e0..00000000 --- a/genesis_test.go +++ /dev/null @@ -1,233 +0,0 @@ -// Copyright (c) 2013-2014 Conformal Systems LLC. -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -package btcwire_test - -import ( - "bytes" - "github.com/conformal/btcwire" - "github.com/davecgh/go-spew/spew" - "testing" -) - -// 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 := btcwire.GenesisBlock.Serialize(&buf) - if err != nil { - t.Errorf("TestGenesisBlock: %v", err) - return - } - - // Ensure the encoded block matches the expected bytes. - if !bytes.Equal(buf.Bytes(), genesisBlockBytes) { - t.Errorf("TestGenesisBlock: Genesis block does not appear valid - "+ - "got %v, want %v", spew.Sdump(buf.Bytes()), - spew.Sdump(genesisBlockBytes)) - return - } - - // Check hash of the block against expected hash. - hash, err := btcwire.GenesisBlock.BlockSha() - if err != nil { - t.Errorf("BlockSha: %v", err) - } - if !btcwire.GenesisHash.IsEqual(&hash) { - t.Errorf("TestGenesisBlock: Genesis block hash does not appear valid - "+ - "got %v, want %v", spew.Sdump(hash), - spew.Sdump(btcwire.GenesisHash)) - return - } -} - -// TestTestNetGenesisBlock tests the genesis block of the regression test -// network for validity by checking the encoded bytes and hashes. -func TestTestNetGenesisBlock(t *testing.T) { - // Encode the genesis block to raw bytes. - var buf bytes.Buffer - err := btcwire.TestNetGenesisBlock.Serialize(&buf) - if err != nil { - t.Errorf("TestTestNetGenesisBlock: %v", err) - return - } - - // Ensure the encoded block matches the expected bytes. - if !bytes.Equal(buf.Bytes(), testNetGenesisBlockBytes) { - t.Errorf("TestTestNetGenesisBlock: Genesis block does not "+ - "appear valid - got %v, want %v", - spew.Sdump(buf.Bytes()), - spew.Sdump(testNetGenesisBlockBytes)) - return - } - - // Check hash of the block against expected hash. - hash, err := btcwire.TestNetGenesisBlock.BlockSha() - if err != nil { - t.Errorf("BlockSha: %v", err) - } - if !btcwire.TestNetGenesisHash.IsEqual(&hash) { - t.Errorf("TestTestNetGenesisBlock: Genesis block hash does "+ - "not appear valid - got %v, want %v", spew.Sdump(hash), - spew.Sdump(btcwire.TestNetGenesisHash)) - return - } -} - -// 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 := btcwire.TestNet3GenesisBlock.Serialize(&buf) - if err != nil { - t.Errorf("TestTestNet3GenesisBlock: %v", err) - return - } - - // Ensure the encoded block matches the expected bytes. - if !bytes.Equal(buf.Bytes(), testNet3GenesisBlockBytes) { - t.Errorf("TestTestNet3GenesisBlock: Genesis block does not "+ - "appear valid - got %v, want %v", - spew.Sdump(buf.Bytes()), - spew.Sdump(testNet3GenesisBlockBytes)) - return - } - - // Check hash of the block against expected hash. - hash, err := btcwire.TestNet3GenesisBlock.BlockSha() - if err != nil { - t.Errorf("BlockSha: %v", err) - } - if !btcwire.TestNet3GenesisHash.IsEqual(&hash) { - t.Errorf("TestTestNet3GenesisBlock: Genesis block hash does "+ - "not appear valid - got %v, want %v", spew.Sdump(hash), - spew.Sdump(btcwire.TestNet3GenesisHash)) - return - } -} - -// 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, 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, 0x3b, 0xa3, 0xed, 0xfd, /* |....;...| */ - 0x7a, 0x7b, 0x12, 0xb2, 0x7a, 0xc7, 0x2c, 0x3e, /* |z{..z.,>| */ - 0x67, 0x76, 0x8f, 0x61, 0x7f, 0xc8, 0x1b, 0xc3, /* |gv.a....| */ - 0x88, 0x8a, 0x51, 0x32, 0x3a, 0x9f, 0xb8, 0xaa, /* |..Q2:...| */ - 0x4b, 0x1e, 0x5e, 0x4a, 0x29, 0xab, 0x5f, 0x49, /* |K.^J)._I| */ - 0xff, 0xff, 0x00, 0x1d, 0x1d, 0xac, 0x2b, 0x7c, /* |......+|| */ - 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, 0x1d, /* |..M.....| */ - 0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, 0x54, /* |..EThe T| */ - 0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, 0x2f, /* |imes 03/| */ - 0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, 0x39, /* |Jan/2009| */ - 0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, 0x6c, /* | Chancel| */ - 0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, 0x62, /* |lor on b| */ - 0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, 0x20, /* |rink of | */ - 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x62, /* |second b| */ - 0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, 0x66, /* |ailout f| */ - 0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, 0x73, /* |or banks| */ - 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, 0x05, /* |........| */ - 0x2a, 0x01, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, /* |*....CA.| */ - 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, 0x27, /* |g....UH'| */ - 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, 0x10, /* |.g..q0..| */ - 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, 0xa6, /* |\..(.9..| */ - 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, 0xb6, /* |yb...a..| */ - 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, 0xc4, /* |I..?L.8.| */ - 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, 0xde, /* |.U......| */ - 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57, /* |\8M....W| */ - 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, 0x5f, /* |.Lp+k.._|*/ - 0xac, 0x00, 0x00, 0x00, 0x00, /* |.....| */ -} - -// testNetGenesisBlockBytes are the wire encoded bytes for the genesis block of -// the regression test network as of protocol version 60002. -var testNetGenesisBlockBytes = []byte{ - 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, 0x00, 0x00, 0x00, 0x3b, 0xa3, 0xed, 0xfd, /* |....;...| */ - 0x7a, 0x7b, 0x12, 0xb2, 0x7a, 0xc7, 0x2c, 0x3e, /* |z{..z.,>| */ - 0x67, 0x76, 0x8f, 0x61, 0x7f, 0xc8, 0x1b, 0xc3, /* |gv.a....| */ - 0x88, 0x8a, 0x51, 0x32, 0x3a, 0x9f, 0xb8, 0xaa, /* |..Q2:...| */ - 0x4b, 0x1e, 0x5e, 0x4a, 0xda, 0xe5, 0x49, 0x4d, /* |K.^J)._I| */ - 0xff, 0xff, 0x7f, 0x20, 0x02, 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, 0x1d, /* |..M.....| */ - 0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, 0x54, /* |..EThe T| */ - 0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, 0x2f, /* |imes 03/| */ - 0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, 0x39, /* |Jan/2009| */ - 0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, 0x6c, /* | Chancel| */ - 0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, 0x62, /* |lor on b| */ - 0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, 0x20, /* |rink of | */ - 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x62, /* |second b| */ - 0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, 0x66, /* |ailout f| */ - 0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, 0x73, /* |or banks| */ - 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, 0x05, /* |........| */ - 0x2a, 0x01, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, /* |*....CA.| */ - 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, 0x27, /* |g....UH'| */ - 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, 0x10, /* |.g..q0..| */ - 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, 0xa6, /* |\..(.9..| */ - 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, 0xb6, /* |yb...a..| */ - 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, 0xc4, /* |I..?L.8.| */ - 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, 0xde, /* |.U......| */ - 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57, /* |\8M....W| */ - 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, 0x5f, /* |.Lp+k.._|*/ - 0xac, 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, 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, 0x3b, 0xa3, 0xed, 0xfd, /* |....;...| */ - 0x7a, 0x7b, 0x12, 0xb2, 0x7a, 0xc7, 0x2c, 0x3e, /* |z{..z.,>| */ - 0x67, 0x76, 0x8f, 0x61, 0x7f, 0xc8, 0x1b, 0xc3, /* |gv.a....| */ - 0x88, 0x8a, 0x51, 0x32, 0x3a, 0x9f, 0xb8, 0xaa, /* |..Q2:...| */ - 0x4b, 0x1e, 0x5e, 0x4a, 0xda, 0xe5, 0x49, 0x4d, /* |K.^J)._I| */ - 0xff, 0xff, 0x00, 0x1d, 0x1a, 0xa4, 0xae, 0x18, /* |......+|| */ - 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, 0x1d, /* |..M.....| */ - 0x01, 0x04, 0x45, 0x54, 0x68, 0x65, 0x20, 0x54, /* |..EThe T| */ - 0x69, 0x6d, 0x65, 0x73, 0x20, 0x30, 0x33, 0x2f, /* |imes 03/| */ - 0x4a, 0x61, 0x6e, 0x2f, 0x32, 0x30, 0x30, 0x39, /* |Jan/2009| */ - 0x20, 0x43, 0x68, 0x61, 0x6e, 0x63, 0x65, 0x6c, /* | Chancel| */ - 0x6c, 0x6f, 0x72, 0x20, 0x6f, 0x6e, 0x20, 0x62, /* |lor on b| */ - 0x72, 0x69, 0x6e, 0x6b, 0x20, 0x6f, 0x66, 0x20, /* |rink of | */ - 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x62, /* |second b| */ - 0x61, 0x69, 0x6c, 0x6f, 0x75, 0x74, 0x20, 0x66, /* |ailout f| */ - 0x6f, 0x72, 0x20, 0x62, 0x61, 0x6e, 0x6b, 0x73, /* |or banks| */ - 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf2, 0x05, /* |........| */ - 0x2a, 0x01, 0x00, 0x00, 0x00, 0x43, 0x41, 0x04, /* |*....CA.| */ - 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, 0x27, /* |g....UH'| */ - 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, 0x10, /* |.g..q0..| */ - 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, 0xa6, /* |\..(.9..| */ - 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, 0xb6, /* |yb...a..| */ - 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, 0xc4, /* |I..?L.8.| */ - 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, 0xde, /* |.U......| */ - 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57, /* |\8M....W| */ - 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, 0x5f, /* |.Lp+k.._|*/ - 0xac, 0x00, 0x00, 0x00, 0x00, /* |.....| */ -} diff --git a/msggetblocks_test.go b/msggetblocks_test.go index 2b8482d8..3fea8c59 100644 --- a/msggetblocks_test.go +++ b/msggetblocks_test.go @@ -316,10 +316,10 @@ func TestGetBlocksWireErrors(t *testing.T) { // block locator hashes. maxGetBlocks := btcwire.NewMsgGetBlocks(hashStop) for i := 0; i < btcwire.MaxBlockLocatorsPerMsg; i++ { - maxGetBlocks.AddBlockLocatorHash(&btcwire.GenesisHash) + maxGetBlocks.AddBlockLocatorHash(&mainNetGenesisHash) } maxGetBlocks.BlockLocatorHashes = append(maxGetBlocks.BlockLocatorHashes, - &btcwire.GenesisHash) + &mainNetGenesisHash) maxGetBlocksEncoded := []byte{ 0x62, 0xea, 0x00, 0x00, // Protocol version 60002 0xfd, 0xf5, 0x01, // Varint for number of block loc hashes (501) diff --git a/msggetheaders_test.go b/msggetheaders_test.go index ca8a2ebc..a5e61edd 100644 --- a/msggetheaders_test.go +++ b/msggetheaders_test.go @@ -307,10 +307,10 @@ func TestGetHeadersWireErrors(t *testing.T) { // block locator hashes. maxGetHeaders := btcwire.NewMsgGetHeaders() for i := 0; i < btcwire.MaxBlockLocatorsPerMsg; i++ { - maxGetHeaders.AddBlockLocatorHash(&btcwire.GenesisHash) + maxGetHeaders.AddBlockLocatorHash(&mainNetGenesisHash) } maxGetHeaders.BlockLocatorHashes = append(maxGetHeaders.BlockLocatorHashes, - &btcwire.GenesisHash) + &mainNetGenesisHash) maxGetHeadersEncoded := []byte{ 0x62, 0xea, 0x00, 0x00, // Protocol version 60002 0xfd, 0xf5, 0x01, // Varint for number of block loc hashes (501) diff --git a/msgheaders_test.go b/msgheaders_test.go index 1eec69e1..99911fbc 100644 --- a/msgheaders_test.go +++ b/msgheaders_test.go @@ -62,7 +62,7 @@ func TestHeaders(t *testing.T) { // TestHeadersWire tests the MsgHeaders wire encode and decode for various // numbers of headers and protocol versions. func TestHeadersWire(t *testing.T) { - hash := btcwire.GenesisHash + hash := mainNetGenesisHash merkleHash := blockOne.Header.MerkleRoot bits := uint32(0x1d00ffff) nonce := uint32(0x9962e301) @@ -219,7 +219,7 @@ func TestHeadersWireErrors(t *testing.T) { pver := btcwire.ProtocolVersion btcwireErr := &btcwire.MessageError{} - hash := btcwire.GenesisHash + hash := mainNetGenesisHash merkleHash := blockOne.Header.MerkleRoot bits := uint32(0x1d00ffff) nonce := uint32(0x9962e301) diff --git a/msgreject_test.go b/msgreject_test.go index 33d3165c..ca425ac1 100644 --- a/msgreject_test.go +++ b/msgreject_test.go @@ -50,7 +50,7 @@ func TestRejectLatest(t *testing.T) { rejCommand := (&btcwire.MsgBlock{}).Command() rejCode := btcwire.RejectDuplicate rejReason := "duplicate block" - rejHash := btcwire.GenesisHash + rejHash := mainNetGenesisHash // Ensure we get the correct data back out. msg := btcwire.NewMsgReject(rejCommand, rejCode, rejReason) @@ -128,7 +128,7 @@ func TestRejectBeforeAdded(t *testing.T) { rejCommand := (&btcwire.MsgBlock{}).Command() rejCode := btcwire.RejectDuplicate rejReason := "duplicate block" - rejHash := btcwire.GenesisHash + rejHash := mainNetGenesisHash msg := btcwire.NewMsgReject(rejCommand, rejCode, rejReason) msg.Hash = rejHash @@ -184,7 +184,7 @@ func TestRejectCrossProtocol(t *testing.T) { rejCommand := (&btcwire.MsgBlock{}).Command() rejCode := btcwire.RejectDuplicate rejReason := "duplicate block" - rejHash := btcwire.GenesisHash + rejHash := mainNetGenesisHash msg := btcwire.NewMsgReject(rejCommand, rejCode, rejReason) msg.Hash = rejHash @@ -251,7 +251,7 @@ func TestRejectWire(t *testing.T) { Cmd: "block", Code: btcwire.RejectDuplicate, Reason: "duplicate block", - Hash: btcwire.GenesisHash, + Hash: mainNetGenesisHash, }, []byte{ 0x05, 0x62, 0x6c, 0x6f, 0x63, 0x6b, // "block" @@ -261,7 +261,7 @@ func TestRejectWire(t *testing.T) { 0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72, 0xc1, 0xa6, 0xa2, 0x46, 0xae, 0x63, 0xf7, 0x4f, 0x93, 0x1e, 0x83, 0x65, 0xe1, 0x5a, 0x08, 0x9c, - 0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, // btcwire.GenesisHash + 0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, // mainNetGenesisHash }, btcwire.ProtocolVersion, }, @@ -307,7 +307,7 @@ func TestRejectWireErrors(t *testing.T) { baseReject := btcwire.NewMsgReject("block", btcwire.RejectDuplicate, "duplicate block") - baseReject.Hash = btcwire.GenesisHash + baseReject.Hash = mainNetGenesisHash baseRejectEncoded := []byte{ 0x05, 0x62, 0x6c, 0x6f, 0x63, 0x6b, // "block" 0x12, // btcwire.RejectDuplicate @@ -316,7 +316,7 @@ func TestRejectWireErrors(t *testing.T) { 0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72, 0xc1, 0xa6, 0xa2, 0x46, 0xae, 0x63, 0xf7, 0x4f, 0x93, 0x1e, 0x83, 0x65, 0xe1, 0x5a, 0x08, 0x9c, - 0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, // btcwire.GenesisHash + 0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, // mainNetGenesisHash } tests := []struct { diff --git a/shahash_test.go b/shahash_test.go index e13c5849..af6565ef 100644 --- a/shahash_test.go +++ b/shahash_test.go @@ -104,14 +104,14 @@ func TestNewShaHashFromStr(t *testing.T) { // Genesis hash. { "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f", - btcwire.GenesisHash, + mainNetGenesisHash, nil, }, // Genesis hash with stripped leading zeros. { "19d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f", - btcwire.GenesisHash, + mainNetGenesisHash, nil, },