mirror of
https://github.com/kaspanet/kaspad.git
synced 2026-03-14 12:24:58 +00:00
* [NOD-215] Implement difficulty adjustment algorithm * [NOD-215] Handle blocks with genesis parent, and fix adjustment factor calculation * [NOD-215] Fix tests * [NOD-215] fix calcNextRequiredDifficulty * [NOD-215] Add TestDifficulty * [NOD-215] Fix delay to be positive, and add tests for delayed blocks * [NOD-215] Split calcBlockWindowMinMaxAndMedianTimestamps to two functions * [NOD-215] Make explicit loop for padding blue block window with genesis * [NOD-215] Name return values * [NOD-215] Fix delay != 0 error messages * [NOD-215] Fix comments * [NOD-215] Fix blueBlockWindow * [NOD-215] Add TestBlueBlockWindow * [NOD-215] Rename PowLimit -> PowMax * [NOD-215] Fix delay != 0 error messages * [NOD-215] Move PowMaxBits to BlockDAG * [NOD-215] Make blockWindow type * [NOD-215] Make blueBlockWindow always pad with genesis * [NOD-215] Remove redundant line in checkWindowIDs * [NOD-215] Make medianTimestamp return error for empty window
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package blockdag
|
|
|
|
import (
|
|
"bou.ke/monkey"
|
|
"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")
|
|
}
|
|
}
|