Use btcnet genesis params for examples and tests.
This commit is contained in:
parent
ae25e28d7e
commit
75e199ece8
5 changed files with 19 additions and 12 deletions
|
@ -20,8 +20,8 @@ change.
|
|||
import (
|
||||
"github.com/conformal/btcdb"
|
||||
_ "github.com/conformal/btcdb/ldb"
|
||||
"github.com/conformal/btcnet"
|
||||
"github.com/conformal/btcutil"
|
||||
"github.com/conformal/btcwire"
|
||||
)
|
||||
|
||||
// Create a database and schedule it to be closed on exit.
|
||||
|
@ -34,7 +34,7 @@ change.
|
|||
|
||||
|
||||
// Insert the main network genesis block.
|
||||
genesis := btcutil.NewBlock(&btcwire.GenesisBlock)
|
||||
genesis := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock)
|
||||
newHeight, err := db.InsertBlock(genesis)
|
||||
if err != nil {
|
||||
// Log and handle the error
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/conformal/btcdb"
|
||||
_ "github.com/conformal/btcdb/ldb"
|
||||
_ "github.com/conformal/btcdb/memdb"
|
||||
"github.com/conformal/btcnet"
|
||||
"github.com/conformal/btcutil"
|
||||
"github.com/conformal/btcwire"
|
||||
"io"
|
||||
|
@ -138,7 +139,7 @@ func setupDB(dbType, dbName string) (btcdb.Db, func(), error) {
|
|||
|
||||
// Insert the main network genesis block. This is part of the initial
|
||||
// database setup.
|
||||
genesisBlock := btcutil.NewBlock(&btcwire.GenesisBlock)
|
||||
genesisBlock := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock)
|
||||
_, err = db.InsertBlock(genesisBlock)
|
||||
if err != nil {
|
||||
teardown()
|
||||
|
@ -177,7 +178,7 @@ func loadBlocks(t *testing.T) ([]*btcutil.Block, error) {
|
|||
|
||||
// Set the first block as the genesis block.
|
||||
blocks := make([]*btcutil.Block, 0, 256)
|
||||
genesis := btcutil.NewBlock(&btcwire.GenesisBlock)
|
||||
genesis := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock)
|
||||
blocks = append(blocks, genesis)
|
||||
|
||||
for height := int64(1); err == nil; height++ {
|
||||
|
|
4
doc.go
4
doc.go
|
@ -33,8 +33,8 @@ referenced parent block to already exist. In a more concrete example:
|
|||
import (
|
||||
"github.com/conformal/btcdb"
|
||||
_ "github.com/conformal/btcdb/ldb"
|
||||
"github.com/conformal/btcnet"
|
||||
"github.com/conformal/btcutil"
|
||||
"github.com/conformal/btcwire"
|
||||
)
|
||||
|
||||
// Create a database and schedule it to be closed on exit.
|
||||
|
@ -47,7 +47,7 @@ referenced parent block to already exist. In a more concrete example:
|
|||
|
||||
|
||||
// Insert the main network genesis block.
|
||||
genesis := btcutil.NewBlock(&btcwire.GenesisBlock)
|
||||
genesis := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock)
|
||||
newHeight, err := db.InsertBlock(genesis)
|
||||
if err != nil {
|
||||
// Log and handle the error
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"encoding/binary"
|
||||
"fmt"
|
||||
"github.com/conformal/btcdb"
|
||||
"github.com/conformal/btcnet"
|
||||
"github.com/conformal/btcutil"
|
||||
"github.com/conformal/btcwire"
|
||||
"io"
|
||||
|
@ -246,7 +247,7 @@ func loadBlocks(t *testing.T, file string) (blocks []*btcutil.Block, err error)
|
|||
}()
|
||||
|
||||
// Set the first block as the genesis block.
|
||||
genesis := btcutil.NewBlock(&btcwire.GenesisBlock)
|
||||
genesis := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock)
|
||||
blocks = append(blocks, genesis)
|
||||
|
||||
var block *btcutil.Block
|
||||
|
|
|
@ -7,6 +7,7 @@ package memdb_test
|
|||
import (
|
||||
"github.com/conformal/btcdb"
|
||||
"github.com/conformal/btcdb/memdb"
|
||||
"github.com/conformal/btcnet"
|
||||
"github.com/conformal/btcutil"
|
||||
"github.com/conformal/btcwire"
|
||||
"reflect"
|
||||
|
@ -23,13 +24,13 @@ func TestClosed(t *testing.T) {
|
|||
t.Errorf("Failed to open test database %v", err)
|
||||
return
|
||||
}
|
||||
_, err = db.InsertBlock(btcutil.NewBlock(&btcwire.GenesisBlock))
|
||||
_, err = db.InsertBlock(btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock))
|
||||
if err != nil {
|
||||
t.Errorf("InsertBlock: %v", err)
|
||||
}
|
||||
db.Close()
|
||||
|
||||
genesisHash := &btcwire.GenesisHash
|
||||
genesisHash := btcnet.MainNetParams.GenesisHash
|
||||
if err := db.DropAfterBlockBySha(genesisHash); err != memdb.ErrDbClosed {
|
||||
t.Errorf("DropAfterBlockBySha: unexpected error %v", err)
|
||||
}
|
||||
|
@ -50,10 +51,14 @@ func TestClosed(t *testing.T) {
|
|||
t.Errorf("FetchHeightRange: unexpected error %v", err)
|
||||
}
|
||||
|
||||
genesisMerkleRoot := &btcwire.GenesisMerkleRoot
|
||||
if exists := db.ExistsTxSha(genesisMerkleRoot); exists != false {
|
||||
genesisCoinbaseTx := btcnet.MainNetParams.GenesisBlock.Transactions[0]
|
||||
coinbaseHash, err := genesisCoinbaseTx.TxSha()
|
||||
if err != nil {
|
||||
t.Errorf("TxSha: unexpected error %v", err)
|
||||
}
|
||||
if exists := db.ExistsTxSha(&coinbaseHash); exists != false {
|
||||
t.Errorf("ExistsTxSha: hash %v exists when it shouldn't",
|
||||
genesisMerkleRoot)
|
||||
&coinbaseHash)
|
||||
}
|
||||
|
||||
if _, err := db.FetchTxBySha(genesisHash); err != memdb.ErrDbClosed {
|
||||
|
|
Loading…
Reference in a new issue