mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-02 20:26:43 +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
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
package blockdag
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"bou.ke/monkey"
|
|
"github.com/daglabs/btcd/dagconfig"
|
|
"github.com/daglabs/btcd/database"
|
|
)
|
|
|
|
func TestIsSupportedDbType(t *testing.T) {
|
|
if !isSupportedDbType("ffldb") {
|
|
t.Errorf("ffldb should be a supported DB driver")
|
|
}
|
|
if isSupportedDbType("madeUpDb") {
|
|
t.Errorf("madeUpDb should not be a supported DB driver")
|
|
}
|
|
}
|
|
|
|
// TestDAGSetupErrors tests all error-cases in DAGSetup.
|
|
// The non-error-cases are tested in the more general tests.
|
|
func TestDAGSetupErrors(t *testing.T) {
|
|
os.RemoveAll(testDbRoot)
|
|
testDAGSetupErrorThroughPatching(t, "unable to create test db root: ", os.MkdirAll, func(path string, perm os.FileMode) error {
|
|
return errors.New("Made up error")
|
|
})
|
|
|
|
testDAGSetupErrorThroughPatching(t, "failed to create dag instance: ", New, func(config *Config) (*BlockDAG, error) {
|
|
return nil, errors.New("Made up error")
|
|
})
|
|
|
|
testDAGSetupErrorThroughPatching(t, "unsupported db type ", isSupportedDbType, func(dbType string) bool {
|
|
return false
|
|
})
|
|
|
|
testDAGSetupErrorThroughPatching(t, "error creating db: ", database.Create, func(dbType string, args ...interface{}) (database.DB, error) {
|
|
return nil, errors.New("Made up error")
|
|
})
|
|
}
|
|
|
|
func testDAGSetupErrorThroughPatching(t *testing.T, expectedErrorMessage string, targetFunction interface{}, replacementFunction interface{}) {
|
|
guard := monkey.Patch(targetFunction, replacementFunction)
|
|
defer guard.Unpatch()
|
|
_, tearDown, err := DAGSetup("TestDAGSetup", Config{
|
|
DAGParams: &dagconfig.MainNetParams,
|
|
})
|
|
if tearDown != nil {
|
|
defer tearDown()
|
|
}
|
|
if err == nil || !strings.HasPrefix(err.Error(), expectedErrorMessage) {
|
|
t.Errorf("DAGSetup: expected error to have prefix '%s' but got error '%v'", expectedErrorMessage, err)
|
|
}
|
|
}
|