1// Copyright (c) 2013-2017 The btcsuite developers 2// Use of this source code is governed by an ISC 3// license that can be found in the LICENSE file. 4 5package blockchain 6 7import ( 8 "fmt" 9 "runtime" 10 "testing" 11 12 "github.com/btcsuite/btcd/txscript" 13) 14 15// TestCheckBlockScripts ensures that validating the all of the scripts in a 16// known-good block doesn't return an error. 17func TestCheckBlockScripts(t *testing.T) { 18 runtime.GOMAXPROCS(runtime.NumCPU()) 19 20 testBlockNum := 277647 21 blockDataFile := fmt.Sprintf("%d.dat.bz2", testBlockNum) 22 blocks, err := loadBlocks(blockDataFile) 23 if err != nil { 24 t.Errorf("Error loading file: %v\n", err) 25 return 26 } 27 if len(blocks) > 1 { 28 t.Errorf("The test block file must only have one block in it") 29 return 30 } 31 if len(blocks) == 0 { 32 t.Errorf("The test block file may not be empty") 33 return 34 } 35 36 storeDataFile := fmt.Sprintf("%d.utxostore.bz2", testBlockNum) 37 view, err := loadUtxoView(storeDataFile) 38 if err != nil { 39 t.Errorf("Error loading txstore: %v\n", err) 40 return 41 } 42 43 scriptFlags := txscript.ScriptBip16 44 err = checkBlockScripts(blocks[0], view, scriptFlags, nil, nil) 45 if err != nil { 46 t.Errorf("Transaction script validation failed: %v\n", err) 47 return 48 } 49} 50