2013-10-14 01:16:11 +02:00
|
|
|
// Copyright (c) 2013 Conformal Systems LLC.
|
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package btcdb_test
|
|
|
|
|
|
|
|
import (
|
2013-10-14 05:13:47 +02:00
|
|
|
"github.com/conformal/btcdb"
|
2013-10-14 17:21:17 +02:00
|
|
|
"github.com/conformal/btcutil"
|
|
|
|
"github.com/conformal/btcwire"
|
2013-10-14 04:30:19 +02:00
|
|
|
"github.com/davecgh/go-spew/spew"
|
|
|
|
"reflect"
|
2013-10-14 01:16:11 +02:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2013-10-14 17:21:17 +02:00
|
|
|
// testContext is used to store context information about a running test which
|
|
|
|
// is passed into helper functions.
|
|
|
|
type testContext struct {
|
|
|
|
t *testing.T
|
|
|
|
dbType string
|
|
|
|
db btcdb.Db
|
|
|
|
blockHeight int64
|
|
|
|
blockHash *btcwire.ShaHash
|
|
|
|
block *btcutil.Block
|
|
|
|
}
|
|
|
|
|
|
|
|
// testInsertBlock ensures InsertBlock conforms to the interface contract.
|
|
|
|
func testInsertBlock(tc *testContext) bool {
|
|
|
|
// The block must insert without any errors.
|
|
|
|
newHeight, err := tc.db.InsertBlock(tc.block)
|
|
|
|
if err != nil {
|
|
|
|
tc.t.Errorf("InsertBlock (%s): failed to insert block %v "+
|
|
|
|
"err %v", tc.dbType, tc.blockHeight, err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// The returned height must be the expected value.
|
|
|
|
if newHeight != tc.blockHeight {
|
|
|
|
tc.t.Errorf("InsertBlock (%s): height mismatch got: %v, "+
|
|
|
|
"want: %v", tc.dbType, newHeight, tc.blockHeight)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// testExistsSha ensures ExistsSha conforms to the interface contract.
|
|
|
|
func testExistsSha(tc *testContext) bool {
|
|
|
|
// The block must exist in the database.
|
|
|
|
if exists := tc.db.ExistsSha(tc.blockHash); !exists {
|
|
|
|
tc.t.Errorf("ExistsSha (%s): block %v does not exist",
|
|
|
|
tc.dbType, tc.blockHash)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// testFetchBlockBySha ensures FetchBlockBySha conforms to the interface
|
|
|
|
// contract.
|
|
|
|
func testFetchBlockBySha(tc *testContext) bool {
|
|
|
|
// The block must be fetchable by its hash without any errors.
|
|
|
|
blockFromDb, err := tc.db.FetchBlockBySha(tc.blockHash)
|
|
|
|
if err != nil {
|
|
|
|
tc.t.Errorf("FetchBlockBySha (%s): %v", tc.dbType, err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// The block fetched from the database must give back the same MsgBlock
|
|
|
|
// and raw bytes that were stored.
|
|
|
|
if !reflect.DeepEqual(tc.block.MsgBlock(), blockFromDb.MsgBlock()) {
|
|
|
|
tc.t.Errorf("FetchBlockBySha (%s): block from database "+
|
|
|
|
"does not match stored block\ngot: %v\n"+
|
|
|
|
"want: %v", tc.dbType,
|
|
|
|
spew.Sdump(blockFromDb.MsgBlock()),
|
|
|
|
spew.Sdump(tc.block.MsgBlock()))
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
blockBytes, err := tc.block.Bytes()
|
|
|
|
if err != nil {
|
|
|
|
tc.t.Errorf("block.Bytes: %v", err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
blockFromDbBytes, err := blockFromDb.Bytes()
|
|
|
|
if err != nil {
|
|
|
|
tc.t.Errorf("blockFromDb.Bytes: %v", err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(blockBytes, blockFromDbBytes) {
|
|
|
|
tc.t.Errorf("FetchBlockBySha (%s): block bytes from "+
|
|
|
|
"database do not match stored block bytes\n"+
|
|
|
|
"got: %v\nwant: %v", tc.dbType,
|
|
|
|
spew.Sdump(blockFromDbBytes), spew.Sdump(blockBytes))
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// testFetchBlockShaByHeight ensures FetchBlockShaByHeight conforms to the
|
|
|
|
// interface contract.
|
|
|
|
func testFetchBlockShaByHeight(tc *testContext) bool {
|
|
|
|
// The hash returned for the block by its height must be the expected
|
|
|
|
// value.
|
|
|
|
hashFromDb, err := tc.db.FetchBlockShaByHeight(tc.blockHeight)
|
|
|
|
if err != nil {
|
|
|
|
tc.t.Errorf("FetchBlockShaByHeight (%s): %v", tc.dbType, err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !hashFromDb.IsEqual(tc.blockHash) {
|
|
|
|
tc.t.Errorf("FetchBlockShaByHeight (%s): returned hash "+
|
|
|
|
"does not match expected value - got: %v, "+
|
|
|
|
"want: %v", tc.dbType, hashFromDb, tc.blockHash)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invalid heights must error and return a nil hash.
|
|
|
|
tests := []int64{-1, tc.blockHeight + 1, tc.blockHeight + 2}
|
2013-10-14 05:13:47 +02:00
|
|
|
for i, wantHeight := range tests {
|
2013-10-14 17:21:17 +02:00
|
|
|
hashFromDb, err := tc.db.FetchBlockShaByHeight(wantHeight)
|
2013-10-14 05:13:47 +02:00
|
|
|
if err == nil {
|
2013-10-14 17:21:17 +02:00
|
|
|
tc.t.Errorf("FetchBlockShaByHeight #%d (%s): did not "+
|
2013-10-14 05:13:47 +02:00
|
|
|
"return error on invalid index: %d - got: %v, "+
|
2013-10-14 17:21:17 +02:00
|
|
|
"want: non-nil", i, tc.dbType, wantHeight, err)
|
2013-10-14 05:13:47 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
if hashFromDb != nil {
|
2013-10-14 17:21:17 +02:00
|
|
|
tc.t.Errorf("FetchBlockShaByHeight #%d (%s): returned "+
|
2013-10-14 05:13:47 +02:00
|
|
|
"hash is not nil on invalid index: %d - got: "+
|
2013-10-14 17:21:17 +02:00
|
|
|
"%v, want: nil", i, tc.dbType, wantHeight, err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// testExistsTxSha ensures ExistsTxSha conforms to the interface contract.
|
|
|
|
func testExistsTxSha(tc *testContext) bool {
|
|
|
|
txHashes, err := tc.block.TxShas()
|
|
|
|
if err != nil {
|
|
|
|
tc.t.Errorf("block.TxShas: %v", err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range txHashes {
|
|
|
|
// The transaction must exist in the database.
|
|
|
|
txHash := txHashes[i]
|
|
|
|
if exists := tc.db.ExistsTxSha(txHash); !exists {
|
|
|
|
tc.t.Errorf("ExistsTxSha (%s): tx %v does not exist",
|
|
|
|
tc.dbType, txHash)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// testFetchTxBySha ensures FetchTxBySha conforms to the interface contract.
|
|
|
|
func testFetchTxBySha(tc *testContext) bool {
|
|
|
|
txHashes, err := tc.block.TxShas()
|
|
|
|
if err != nil {
|
|
|
|
tc.t.Errorf("block.TxShas: %v", err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tx := range tc.block.MsgBlock().Transactions {
|
|
|
|
txHash := txHashes[i]
|
|
|
|
txReplyList, err := tc.db.FetchTxBySha(txHash)
|
|
|
|
if err != nil {
|
|
|
|
tc.t.Errorf("FetchTxBySha (%s): %v", tc.dbType, err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if len(txReplyList) == 0 {
|
|
|
|
tc.t.Errorf("FetchTxBySha (%s): tx %v did not "+
|
|
|
|
"return reply data", tc.dbType, txHash)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
txFromDb := txReplyList[len(txReplyList)-1].Tx
|
|
|
|
if !reflect.DeepEqual(tx, txFromDb) {
|
|
|
|
tc.t.Errorf("FetchTxBySha (%s): tx %v from "+
|
|
|
|
"database does not match stored tx\n"+
|
|
|
|
"got: %v\nwant: %v", tc.dbType, txHash,
|
|
|
|
spew.Sdump(txFromDb), spew.Sdump(tx))
|
2013-10-14 05:13:47 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-14 17:21:17 +02:00
|
|
|
return true
|
2013-10-14 05:13:47 +02:00
|
|
|
}
|
|
|
|
|
2013-10-14 20:49:10 +02:00
|
|
|
// testFetchTxByShaList ensures FetchTxByShaList conforms to the interface
|
|
|
|
// contract.
|
|
|
|
func testFetchTxByShaList(tc *testContext) bool {
|
|
|
|
txHashes, err := tc.block.TxShas()
|
|
|
|
if err != nil {
|
|
|
|
tc.t.Errorf("block.TxShas: %v", err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
txReplyList := tc.db.FetchTxByShaList(txHashes)
|
|
|
|
if len(txReplyList) != len(txHashes) {
|
|
|
|
tc.t.Errorf("FetchTxByShaList (%s): tx reply list for "+
|
|
|
|
"block #%d (%v) does not match expected length "+
|
|
|
|
"- got: %v, want: %v", tc.dbType, tc.blockHeight,
|
|
|
|
tc.blockHash, len(txReplyList), len(txHashes))
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i, tx := range tc.block.MsgBlock().Transactions {
|
|
|
|
txHash := txHashes[i]
|
|
|
|
txD := txReplyList[i]
|
|
|
|
|
|
|
|
// The transaction hash in the reply must be the expected value.
|
|
|
|
if !txD.Sha.IsEqual(txHash) {
|
|
|
|
tc.t.Errorf("FetchTxByShaList (%s): tx #%d hash "+
|
|
|
|
"does not match expected - got %v, "+
|
|
|
|
"want %v", tc.dbType, i, txD.Sha, txHashes[i])
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// The reply must not indicate any errors.
|
|
|
|
if txD.Err != nil {
|
|
|
|
tc.t.Errorf("FetchTxByShaList (%s): tx #%d (%v) "+
|
|
|
|
"returned unexpected error - got %v, "+
|
|
|
|
"want nil", tc.dbType, i, txD.Sha, txD.Err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// The transaction in the reply fetched from the database must
|
|
|
|
// be the same MsgTx that was stored.
|
|
|
|
if !reflect.DeepEqual(tx, txD.Tx) {
|
|
|
|
tc.t.Errorf("FetchTxByShaList (%s): tx #%d (%v) from "+
|
|
|
|
"database does not match stored tx\n"+
|
|
|
|
"got: %v\nwant: %v", tc.dbType, i, txHash,
|
|
|
|
spew.Sdump(txD.Tx), spew.Sdump(tx))
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// The block hash in the reply from the database must be the
|
|
|
|
// expected value.
|
|
|
|
if txD.BlkSha == nil {
|
|
|
|
tc.t.Errorf("FetchTxByShaList (%s): tx #%d (%v) "+
|
|
|
|
"returned nil block hash", tc.dbType, i, txD.Sha)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !txD.BlkSha.IsEqual(tc.blockHash) {
|
|
|
|
tc.t.Errorf("FetchTxByShaList (%s): tx #%d (%v) "+
|
|
|
|
"returned unexpected block hash - got %v, "+
|
|
|
|
"want %v", tc.dbType, i, txD.Sha, txD.BlkSha,
|
|
|
|
tc.blockHash)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// The block height in the reply from the database must be the
|
|
|
|
// expected value.
|
|
|
|
if txD.Height != tc.blockHeight {
|
|
|
|
tc.t.Errorf("FetchTxByShaList (%s): tx #%d (%v) "+
|
|
|
|
"returned unexpected block height - got %v, "+
|
|
|
|
"want %v", tc.dbType, i, txD.Sha, txD.Height,
|
|
|
|
tc.blockHeight)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// The spend data in the reply from the database must not
|
|
|
|
// indicate any of the transactions that were just inserted are
|
|
|
|
// spent.
|
|
|
|
if txD.TxSpent == nil {
|
|
|
|
tc.t.Errorf("FetchTxByShaList (%s): tx #%d (%v) "+
|
|
|
|
"returned nil spend data", tc.dbType, i, txD.Sha)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
noSpends := make([]bool, len(tx.TxOut))
|
|
|
|
if !reflect.DeepEqual(txD.TxSpent, noSpends) {
|
|
|
|
tc.t.Errorf("FetchTxByShaList (%s): tx #%d (%v) "+
|
|
|
|
"returned unexpected spend data - got %v, "+
|
|
|
|
"want %v", tc.dbType, i, txD.Sha, txD.TxSpent,
|
|
|
|
noSpends)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2013-10-14 20:56:21 +02:00
|
|
|
// testFetchUnSpentTxByShaList ensures FetchUnSpentTxByShaList conforms to the
|
|
|
|
// interface contract.
|
|
|
|
func testFetchUnSpentTxByShaList(tc *testContext) bool {
|
|
|
|
txHashes, err := tc.block.TxShas()
|
|
|
|
if err != nil {
|
|
|
|
tc.t.Errorf("block.TxShas: %v", err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
txReplyList := tc.db.FetchUnSpentTxByShaList(txHashes)
|
|
|
|
if len(txReplyList) != len(txHashes) {
|
|
|
|
tc.t.Errorf("FetchUnSpentTxByShaList (%s): tx reply list for "+
|
|
|
|
"block #%d (%v) does not match expected length "+
|
|
|
|
"- got: %v, want: %v", tc.dbType, tc.blockHeight,
|
|
|
|
tc.blockHash, len(txReplyList), len(txHashes))
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i, tx := range tc.block.MsgBlock().Transactions {
|
|
|
|
txHash := txHashes[i]
|
|
|
|
txD := txReplyList[i]
|
|
|
|
|
|
|
|
// The transaction hash in the reply must be the expected value.
|
|
|
|
if !txD.Sha.IsEqual(txHash) {
|
|
|
|
tc.t.Errorf("FetchUnSpentTxByShaList (%s): tx #%d hash "+
|
|
|
|
"does not match expected - got %v, "+
|
|
|
|
"want %v", tc.dbType, i, txD.Sha, txHashes[i])
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// The reply must not indicate any errors.
|
|
|
|
if txD.Err != nil {
|
|
|
|
tc.t.Errorf("FetchUnSpentTxByShaList (%s): tx #%d (%v) "+
|
|
|
|
"returned unexpected error - got %v, "+
|
|
|
|
"want nil", tc.dbType, i, txD.Sha, txD.Err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// The transaction in the reply fetched from the database must
|
|
|
|
// be the same MsgTx that was stored.
|
|
|
|
if !reflect.DeepEqual(tx, txD.Tx) {
|
|
|
|
tc.t.Errorf("FetchUnSpentTxByShaList (%s): tx #%d (%v) "+
|
|
|
|
"from database does not match stored tx\n"+
|
|
|
|
"got: %v\nwant: %v", tc.dbType, i, txHash,
|
|
|
|
spew.Sdump(txD.Tx), spew.Sdump(tx))
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// The block hash in the reply from the database must be the
|
|
|
|
// expected value.
|
|
|
|
if txD.BlkSha == nil {
|
|
|
|
tc.t.Errorf("FetchUnSpentTxByShaList (%s): tx #%d (%v) "+
|
|
|
|
"returned nil block hash", tc.dbType, i, txD.Sha)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !txD.BlkSha.IsEqual(tc.blockHash) {
|
|
|
|
tc.t.Errorf("FetchUnSpentTxByShaList (%s): tx #%d (%v) "+
|
|
|
|
"returned unexpected block hash - got %v, "+
|
|
|
|
"want %v", tc.dbType, i, txD.Sha, txD.BlkSha,
|
|
|
|
tc.blockHash)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// The block height in the reply from the database must be the
|
|
|
|
// expected value.
|
|
|
|
if txD.Height != tc.blockHeight {
|
|
|
|
tc.t.Errorf("FetchUnSpentTxByShaList (%s): tx #%d (%v) "+
|
|
|
|
"returned unexpected block height - got %v, "+
|
|
|
|
"want %v", tc.dbType, i, txD.Sha, txD.Height,
|
|
|
|
tc.blockHeight)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// The spend data in the reply from the database must not
|
|
|
|
// indicate any of the transactions that were just inserted are
|
|
|
|
// spent.
|
|
|
|
if txD.TxSpent == nil {
|
|
|
|
tc.t.Errorf("FetchUnSpentTxByShaList (%s): tx #%d (%v) "+
|
|
|
|
"returned nil spend data", tc.dbType, i, txD.Sha)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
noSpends := make([]bool, len(tx.TxOut))
|
|
|
|
if !reflect.DeepEqual(txD.TxSpent, noSpends) {
|
|
|
|
tc.t.Errorf("FetchUnSpentTxByShaList (%s): tx #%d (%v) "+
|
|
|
|
"returned unexpected spend data - got %v, "+
|
|
|
|
"want %v", tc.dbType, i, txD.Sha, txD.TxSpent,
|
|
|
|
noSpends)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2013-10-14 03:24:03 +02:00
|
|
|
// testInterface tests performs tests for the various interfaces of btcdb which
|
|
|
|
// require state in the database for the given database type.
|
|
|
|
func testInterface(t *testing.T, dbType string) {
|
|
|
|
db, teardown, err := setupDB(dbType, "interface")
|
|
|
|
if err != nil {
|
2013-10-14 05:11:12 +02:00
|
|
|
t.Errorf("Failed to create test database (%s) %v", dbType, err)
|
2013-10-14 03:24:03 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
// Load up a bunch of test blocks.
|
|
|
|
blocks, err := loadBlocks(t)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to load blocks from test data %v: %v",
|
|
|
|
blockDataFile, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2013-10-14 17:21:17 +02:00
|
|
|
// Create a test context to pass around.
|
|
|
|
context := testContext{t: t, dbType: dbType, db: db}
|
|
|
|
|
2013-10-14 03:24:03 +02:00
|
|
|
t.Logf("Loaded %d blocks", len(blocks))
|
|
|
|
for height := int64(1); height < int64(len(blocks)); height++ {
|
2013-10-14 17:21:17 +02:00
|
|
|
// Get the appropriate block and hash and update the test
|
|
|
|
// context accordingly.
|
2013-10-14 03:24:03 +02:00
|
|
|
block := blocks[height]
|
2013-10-14 17:21:17 +02:00
|
|
|
blockHash, err := block.Sha()
|
2013-10-14 04:30:19 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("block.Sha: %v", err)
|
|
|
|
return
|
|
|
|
}
|
2013-10-14 17:21:17 +02:00
|
|
|
context.blockHeight = height
|
|
|
|
context.blockHash = blockHash
|
|
|
|
context.block = block
|
2013-10-14 04:30:19 +02:00
|
|
|
|
2013-10-14 17:21:17 +02:00
|
|
|
// The block must insert without any errors and return the
|
|
|
|
// expected height.
|
|
|
|
if !testInsertBlock(&context) {
|
2013-10-14 04:30:19 +02:00
|
|
|
return
|
|
|
|
}
|
2013-10-14 17:21:17 +02:00
|
|
|
|
|
|
|
// The block must now exist in the database.
|
|
|
|
if !testExistsSha(&context) {
|
2013-10-14 04:30:19 +02:00
|
|
|
return
|
|
|
|
}
|
2013-10-14 17:21:17 +02:00
|
|
|
|
|
|
|
// Loading the block back from the database must give back
|
|
|
|
// the same MsgBlock and raw bytes that were stored.
|
|
|
|
if !testFetchBlockBySha(&context) {
|
2013-10-14 04:30:19 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2013-10-14 17:21:17 +02:00
|
|
|
// The hash returned for the block by its height must be the
|
2013-10-14 05:03:50 +02:00
|
|
|
// expected value.
|
2013-10-14 17:21:17 +02:00
|
|
|
if !testFetchBlockShaByHeight(&context) {
|
2013-10-14 05:03:50 +02:00
|
|
|
return
|
|
|
|
}
|
2013-10-14 17:21:17 +02:00
|
|
|
|
|
|
|
// All of the transactions in the block must now exist in the
|
|
|
|
// database.
|
|
|
|
if !testExistsTxSha(&context) {
|
2013-10-14 05:03:50 +02:00
|
|
|
return
|
|
|
|
}
|
2013-10-14 07:27:11 +02:00
|
|
|
|
2013-10-14 17:21:17 +02:00
|
|
|
// Loading all of the transactions in the block back from the
|
|
|
|
// database must give back the same MsgTx that was stored.
|
|
|
|
if !testFetchTxBySha(&context) {
|
2013-10-14 07:27:11 +02:00
|
|
|
return
|
|
|
|
}
|
2013-10-14 20:49:10 +02:00
|
|
|
|
|
|
|
// All of the transactions in the block must be fetchable via
|
|
|
|
// FetchTxByShaList and all of the list replies must have the
|
|
|
|
// expected values.
|
|
|
|
if !testFetchTxByShaList(&context) {
|
|
|
|
return
|
|
|
|
}
|
2013-10-14 20:56:21 +02:00
|
|
|
|
|
|
|
// All of the transactions in the block must be fetchable via
|
|
|
|
// FetchUnSpentTxByShaList and all of the list replies must have
|
|
|
|
// the expected values.
|
|
|
|
if !testFetchUnSpentTxByShaList(&context) {
|
|
|
|
return
|
|
|
|
}
|
2013-10-14 05:13:47 +02:00
|
|
|
}
|
|
|
|
|
2013-10-14 03:24:03 +02:00
|
|
|
// TODO(davec): Need to figure out how to handle the special checks
|
|
|
|
// required for the duplicate transactions allowed by blocks 91842 and
|
|
|
|
// 91880 on the main network due to the old miner + Satoshi client bug.
|
|
|
|
|
|
|
|
// TODO(davec): Add tests for the following functions:
|
|
|
|
/*
|
|
|
|
Close()
|
|
|
|
DropAfterBlockBySha(*btcwire.ShaHash) (err error)
|
2013-10-14 04:30:19 +02:00
|
|
|
- ExistsSha(sha *btcwire.ShaHash) (exists bool)
|
|
|
|
- FetchBlockBySha(sha *btcwire.ShaHash) (blk *btcutil.Block, err error)
|
2013-10-14 05:13:47 +02:00
|
|
|
- FetchBlockShaByHeight(height int64) (sha *btcwire.ShaHash, err error)
|
2013-10-14 03:24:03 +02:00
|
|
|
FetchHeightRange(startHeight, endHeight int64) (rshalist []btcwire.ShaHash, err error)
|
2013-10-14 07:27:11 +02:00
|
|
|
- ExistsTxSha(sha *btcwire.ShaHash) (exists bool)
|
2013-10-14 07:42:58 +02:00
|
|
|
- FetchTxBySha(txsha *btcwire.ShaHash) ([]*TxListReply, error)
|
2013-10-14 20:49:10 +02:00
|
|
|
- FetchTxByShaList(txShaList []*btcwire.ShaHash) []*TxListReply
|
2013-10-14 20:56:21 +02:00
|
|
|
- FetchUnSpentTxByShaList(txShaList []*btcwire.ShaHash) []*TxListReply
|
2013-10-14 03:24:03 +02:00
|
|
|
- InsertBlock(block *btcutil.Block) (height int64, err error)
|
|
|
|
InvalidateBlockCache()
|
|
|
|
InvalidateCache()
|
|
|
|
InvalidateTxCache()
|
|
|
|
NewIterateBlocks() (pbi BlockIterator, err error)
|
|
|
|
NewestSha() (sha *btcwire.ShaHash, height int64, err error)
|
|
|
|
RollbackClose()
|
|
|
|
SetDBInsertMode(InsertMode)
|
|
|
|
Sync()
|
|
|
|
*/
|
|
|
|
}
|