Use btcnet genesis params for examples and tests.

This commit is contained in:
Dave Collins 2014-05-28 01:29:51 -05:00
parent ae25e28d7e
commit 75e199ece8
5 changed files with 19 additions and 12 deletions

View file

@ -20,8 +20,8 @@ change.
import ( import (
"github.com/conformal/btcdb" "github.com/conformal/btcdb"
_ "github.com/conformal/btcdb/ldb" _ "github.com/conformal/btcdb/ldb"
"github.com/conformal/btcnet"
"github.com/conformal/btcutil" "github.com/conformal/btcutil"
"github.com/conformal/btcwire"
) )
// Create a database and schedule it to be closed on exit. // Create a database and schedule it to be closed on exit.
@ -34,7 +34,7 @@ change.
// Insert the main network genesis block. // Insert the main network genesis block.
genesis := btcutil.NewBlock(&btcwire.GenesisBlock) genesis := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock)
newHeight, err := db.InsertBlock(genesis) newHeight, err := db.InsertBlock(genesis)
if err != nil { if err != nil {
// Log and handle the error // Log and handle the error

View file

@ -11,6 +11,7 @@ import (
"github.com/conformal/btcdb" "github.com/conformal/btcdb"
_ "github.com/conformal/btcdb/ldb" _ "github.com/conformal/btcdb/ldb"
_ "github.com/conformal/btcdb/memdb" _ "github.com/conformal/btcdb/memdb"
"github.com/conformal/btcnet"
"github.com/conformal/btcutil" "github.com/conformal/btcutil"
"github.com/conformal/btcwire" "github.com/conformal/btcwire"
"io" "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 // Insert the main network genesis block. This is part of the initial
// database setup. // database setup.
genesisBlock := btcutil.NewBlock(&btcwire.GenesisBlock) genesisBlock := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock)
_, err = db.InsertBlock(genesisBlock) _, err = db.InsertBlock(genesisBlock)
if err != nil { if err != nil {
teardown() teardown()
@ -177,7 +178,7 @@ func loadBlocks(t *testing.T) ([]*btcutil.Block, error) {
// Set the first block as the genesis block. // Set the first block as the genesis block.
blocks := make([]*btcutil.Block, 0, 256) blocks := make([]*btcutil.Block, 0, 256)
genesis := btcutil.NewBlock(&btcwire.GenesisBlock) genesis := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock)
blocks = append(blocks, genesis) blocks = append(blocks, genesis)
for height := int64(1); err == nil; height++ { for height := int64(1); err == nil; height++ {

4
doc.go
View file

@ -33,8 +33,8 @@ referenced parent block to already exist. In a more concrete example:
import ( import (
"github.com/conformal/btcdb" "github.com/conformal/btcdb"
_ "github.com/conformal/btcdb/ldb" _ "github.com/conformal/btcdb/ldb"
"github.com/conformal/btcnet"
"github.com/conformal/btcutil" "github.com/conformal/btcutil"
"github.com/conformal/btcwire"
) )
// Create a database and schedule it to be closed on exit. // 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. // Insert the main network genesis block.
genesis := btcutil.NewBlock(&btcwire.GenesisBlock) genesis := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock)
newHeight, err := db.InsertBlock(genesis) newHeight, err := db.InsertBlock(genesis)
if err != nil { if err != nil {
// Log and handle the error // Log and handle the error

View file

@ -9,6 +9,7 @@ import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"github.com/conformal/btcdb" "github.com/conformal/btcdb"
"github.com/conformal/btcnet"
"github.com/conformal/btcutil" "github.com/conformal/btcutil"
"github.com/conformal/btcwire" "github.com/conformal/btcwire"
"io" "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. // Set the first block as the genesis block.
genesis := btcutil.NewBlock(&btcwire.GenesisBlock) genesis := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock)
blocks = append(blocks, genesis) blocks = append(blocks, genesis)
var block *btcutil.Block var block *btcutil.Block

View file

@ -7,6 +7,7 @@ package memdb_test
import ( import (
"github.com/conformal/btcdb" "github.com/conformal/btcdb"
"github.com/conformal/btcdb/memdb" "github.com/conformal/btcdb/memdb"
"github.com/conformal/btcnet"
"github.com/conformal/btcutil" "github.com/conformal/btcutil"
"github.com/conformal/btcwire" "github.com/conformal/btcwire"
"reflect" "reflect"
@ -23,13 +24,13 @@ func TestClosed(t *testing.T) {
t.Errorf("Failed to open test database %v", err) t.Errorf("Failed to open test database %v", err)
return return
} }
_, err = db.InsertBlock(btcutil.NewBlock(&btcwire.GenesisBlock)) _, err = db.InsertBlock(btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock))
if err != nil { if err != nil {
t.Errorf("InsertBlock: %v", err) t.Errorf("InsertBlock: %v", err)
} }
db.Close() db.Close()
genesisHash := &btcwire.GenesisHash genesisHash := btcnet.MainNetParams.GenesisHash
if err := db.DropAfterBlockBySha(genesisHash); err != memdb.ErrDbClosed { if err := db.DropAfterBlockBySha(genesisHash); err != memdb.ErrDbClosed {
t.Errorf("DropAfterBlockBySha: unexpected error %v", err) t.Errorf("DropAfterBlockBySha: unexpected error %v", err)
} }
@ -50,10 +51,14 @@ func TestClosed(t *testing.T) {
t.Errorf("FetchHeightRange: unexpected error %v", err) t.Errorf("FetchHeightRange: unexpected error %v", err)
} }
genesisMerkleRoot := &btcwire.GenesisMerkleRoot genesisCoinbaseTx := btcnet.MainNetParams.GenesisBlock.Transactions[0]
if exists := db.ExistsTxSha(genesisMerkleRoot); exists != false { 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", t.Errorf("ExistsTxSha: hash %v exists when it shouldn't",
genesisMerkleRoot) &coinbaseHash)
} }
if _, err := db.FetchTxBySha(genesisHash); err != memdb.ErrDbClosed { if _, err := db.FetchTxBySha(genesisHash); err != memdb.ErrDbClosed {