mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-10-14 00:59:33 +00:00

* [DEV-234] add TxAcceptedInBlock and TxBlocks * [DEV-234] test TxAcceptedInBlock and TxBlocks * [DEV-234] test TxAcceptedInBlock and TxFirstBlockRegion * [DEV-234] rename selectedPathSet to selectedPathChain * [DEV-234] set indexers db as part of index manager initialization * [DEV-234] remove redudant dag instance in txindex * [DEV-234] fix TestTxIndexConnectBlock and add DAGParams as part of config in DAGSetup * [DEV-234] TestTxIndexConnectBlock make K=1 to make calculations easier * [DEV-234] rename TxAcceptingBlock to BlockThatAcceptedTx * [DEV-234] update block fields names in txindex_test.go * [DEV-234] rename selectedPathChain -> selectedPathChainSet
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package blockdag
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"bou.ke/monkey"
|
|
"github.com/daglabs/btcd/dagconfig"
|
|
"github.com/daglabs/btcd/database"
|
|
)
|
|
|
|
func TestAncestorErrors(t *testing.T) {
|
|
node := newTestNode(newSet(), int32(0x10000000), 0, time.Unix(0, 0), dagconfig.MainNetParams.K)
|
|
node.height = 2
|
|
ancestor := node.Ancestor(3)
|
|
if ancestor != nil {
|
|
t.Errorf("TestAncestorErrors: Ancestor() unexpectedly returned a node. Expected: <nil>")
|
|
}
|
|
}
|
|
|
|
func TestFlushToDBErrors(t *testing.T) {
|
|
// Create a new database and DAG instance to run tests against.
|
|
dag, teardownFunc, err := DAGSetup("TestFlushToDBErrors", Config{
|
|
DAGParams: &dagconfig.SimNetParams,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("TestFlushToDBErrors: Failed to setup DAG instance: %s", err)
|
|
}
|
|
defer teardownFunc()
|
|
|
|
// Call flushToDB without anything to flush. This should succeed
|
|
err = dag.index.flushToDB()
|
|
if err != nil {
|
|
t.Errorf("TestFlushToDBErrors: flushToDB without anything to flush: "+
|
|
"Unexpected flushToDB error: %s", err)
|
|
}
|
|
|
|
// Mark the genesis block as dirty
|
|
dag.index.SetStatusFlags(dag.genesis, statusValid)
|
|
|
|
// Test flushToDB failure due to database error
|
|
databaseErrorMessage := "database error"
|
|
guard := monkey.Patch(dbStoreBlockNode, func(_ database.Tx, _ *blockNode) error {
|
|
return errors.New(databaseErrorMessage)
|
|
})
|
|
defer guard.Unpatch()
|
|
err = dag.index.flushToDB()
|
|
if err == nil {
|
|
t.Errorf("TestFlushToDBErrors: flushToDB failure due to database error: "+
|
|
"Expected: %s, got: <nil>", databaseErrorMessage)
|
|
}
|
|
if !strings.Contains(err.Error(), databaseErrorMessage) {
|
|
t.Errorf("TestFlushToDBErrors: flushToDB failure due to database error: "+
|
|
"Unexpected flushToDB error. Expected: %s, got: %s", databaseErrorMessage, err)
|
|
}
|
|
}
|