mirror of
https://github.com/kaspanet/kaspad.git
synced 2026-03-15 04:45:17 +00:00
* [NOD-256] Add error log * [NOD-256] Add error log * [NOD-256] Fix typo and comment * [NOD-256] Remove btclog dir * [NOD-256] Format project * [NOD-256] Add error log files * [NOD-256] Add an option to add a log file to write into to an existing backend logger * [NOD-256] Get rid of redundant logs initialization * [NOD-256] rename initLogRotators to initLog * [NOD-256] Get rid ExampleSignTxOutput and convert ExampleBlockDAG_ProcessBlock to a regular test * [NOD-256] Show error message if os.Exiting from initLog
68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
package blockdag
|
|
|
|
import (
|
|
"bou.ke/monkey"
|
|
"fmt"
|
|
"github.com/daglabs/btcd/dagconfig"
|
|
"github.com/daglabs/btcd/util"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestProcessBlock(t *testing.T) {
|
|
dag, teardownFunc, err := DAGSetup("TestProcessBlock", Config{
|
|
DAGParams: &dagconfig.SimNetParams,
|
|
})
|
|
if err != nil {
|
|
t.Errorf("Failed to setup dag instance: %v", err)
|
|
return
|
|
}
|
|
defer teardownFunc()
|
|
|
|
// Check that BFAfterDelay skip checkBlockSanity
|
|
called := false
|
|
guard := monkey.Patch((*BlockDAG).checkBlockSanity, func(_ *BlockDAG, _ *util.Block, _ BehaviorFlags) (time.Duration, error) {
|
|
called = true
|
|
return 0, nil
|
|
})
|
|
defer guard.Unpatch()
|
|
|
|
isOrphan, delay, err := dag.ProcessBlock(util.NewBlock(&Block100000), BFNoPoWCheck)
|
|
if err != nil {
|
|
t.Errorf("ProcessBlock: %s", err)
|
|
}
|
|
if delay != 0 {
|
|
t.Errorf("ProcessBlock: block is too far in the future")
|
|
}
|
|
if !isOrphan {
|
|
t.Errorf("ProcessBlock: unexpected returned non orphan block")
|
|
}
|
|
if !called {
|
|
t.Errorf("ProcessBlock: expected checkBlockSanity to be called")
|
|
}
|
|
|
|
Block100000Copy := Block100000
|
|
// Change nonce to change block hash
|
|
Block100000Copy.Header.Nonce++
|
|
called = false
|
|
isOrphan, delay, err = dag.ProcessBlock(util.NewBlock(&Block100000Copy), BFAfterDelay|BFNoPoWCheck)
|
|
if err != nil {
|
|
t.Errorf("ProcessBlock: %s", err)
|
|
}
|
|
if delay != 0 {
|
|
t.Errorf("ProcessBlock: block is too far in the future")
|
|
}
|
|
if !isOrphan {
|
|
t.Errorf("ProcessBlock: unexpected returned non orphan block")
|
|
}
|
|
if called {
|
|
t.Errorf("ProcessBlock: Didn't expected checkBlockSanity to be called")
|
|
}
|
|
|
|
isOrphan, delay, err = dag.ProcessBlock(util.NewBlock(dagconfig.SimNetParams.GenesisBlock), BFNone)
|
|
expectedErrMsg := fmt.Sprintf("already have block %s", dagconfig.SimNetParams.GenesisHash)
|
|
if err == nil || err.Error() != expectedErrMsg {
|
|
t.Errorf("ProcessBlock: Expected error \"%s\" but got \"%s\"", expectedErrMsg, err)
|
|
}
|
|
}
|