7 "github.com/bytom/consensus"
8 "github.com/bytom/protocol/bc/types"
11 func TestCalcNextRequiredDifficulty(t *testing.T) {
12 targetTimeSpan := uint64(consensus.BlocksPerRetarget * consensus.TargetSecondsPerBlock)
14 lastBH *types.BlockHeader
15 compareBH *types.BlockHeader
18 //{nil, nil, powMinBits},
19 //{&types.BlockHeader{Height: BlocksPerRetarget, Bits: 87654321}, nil, 87654321},
21 &types.BlockHeader{Height: consensus.BlocksPerRetarget, Timestamp: targetTimeSpan, Bits: BigToCompact(big.NewInt(1000))},
22 &types.BlockHeader{Height: 0, Timestamp: 0},
23 BigToCompact(big.NewInt(1000)),
26 &types.BlockHeader{Height: consensus.BlocksPerRetarget, Timestamp: targetTimeSpan * 2, Bits: BigToCompact(big.NewInt(1000))},
27 &types.BlockHeader{Height: 0, Timestamp: 0},
28 BigToCompact(big.NewInt(2000)),
31 &types.BlockHeader{Height: consensus.
32 BlocksPerRetarget, Timestamp: targetTimeSpan / 2, Bits: BigToCompact(big.NewInt(1000))},
33 &types.BlockHeader{Height: 0, Timestamp: 0},
34 BigToCompact(big.NewInt(500)),
38 for i, c := range cases {
39 if got := CalcNextRequiredDifficulty(c.lastBH, c.compareBH); got != c.want {
40 t.Errorf("Compile(%d) = %d want %d", i, got, c.want)