-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtmp-kac_test.go
54 lines (49 loc) · 1.43 KB
/
tmp-kac_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2014-2014 PPCD developers.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package ppcutil_test
import (
"github.com/mably/btcnet"
"github.com/mably/ppcd/database"
_ "github.com/mably/ppcd/database/ldb" // init only
"github.com/mably/ppcutil"
"testing"
)
func TestPoWTargetCalculation(t *testing.T) {
params := btcnet.MainNetParams
db, err := database.OpenDB("leveldb", "testdata/db_512")
if err != nil {
t.Errorf("db error %v", err)
return
}
defer db.Close()
lastBlock, _ := db.FetchBlockBySha(params.GenesisHash)
for height := 1; height < 512; height++ {
sha, _ := db.FetchBlockShaByHeight(int64(height))
block, _ := db.FetchBlockBySha(sha)
if !block.MsgBlock().IsProofOfStake() {
targetRequired := ppcutil.GetNextTargetRequired(params, db, lastBlock, false)
if targetRequired != block.MsgBlock().Header.Bits {
t.Errorf("bad target for block #%d %v, have %x want %x", height, sha, targetRequired, block.MsgBlock().Header.Bits)
return
}
}
lastBlock = block
}
if lastBlock.Height() != 511 {
t.Error("test ended too early")
}
return
}
func TestReadCBlockIndex(t *testing.T) {
r := ppcutil.ReadCBlockIndex("testdata/blkindex.csv")
if r.Height != 0 {
t.Errorf("bad root height, have %d, want %d", r.Height, 0)
}
for r.Next != nil {
r = r.Next
}
if r.Height != 131325 {
t.Errorf("bad head height, have %d, want %d", r.Height, 131325)
}
}