scriptval_test.go raw
1 package blockchain
2
3 import (
4 "fmt"
5 "runtime"
6 "testing"
7
8 "github.com/p9c/p9/pkg/txscript"
9 )
10
11 // TestCheckBlockScripts ensures that validating the all of the scripts in a known-good block doesn't return an error.
12 func TestCheckBlockScripts(t *testing.T) {
13 runtime.GOMAXPROCS(runtime.NumCPU())
14 testBlockNum := 277647
15 blockDataFile := fmt.Sprintf("%d.dat.bz2", testBlockNum)
16 blocks, e := loadBlocks(blockDataFile)
17 if e != nil {
18 t.Errorf("ScriptError loading file: %v\n", e)
19 return
20 }
21 if len(blocks) > 1 {
22 t.Errorf("The test block file must only have one block in it")
23 return
24 }
25 if len(blocks) == 0 {
26 t.Errorf("The test block file may not be empty")
27 return
28 }
29 storeDataFile := fmt.Sprintf("%d.utxostore.bz2", testBlockNum)
30 view, e := loadUtxoView(storeDataFile)
31 if e != nil {
32 t.Errorf("ScriptError loading txstore: %v\n", e)
33 return
34 }
35 scriptFlags := txscript.ScriptBip16
36 e = checkBlockScripts(blocks[0], view, scriptFlags, nil, nil)
37 if e != nil {
38 t.Errorf("Transaction script validation failed: %v\n", e)
39 return
40 }
41 }
42