2015-08-26 06:03:18 +02:00
|
|
|
// Copyright (c) 2013-2016 The btcsuite developers
|
2015-01-08 12:08:11 +01:00
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2015-01-30 21:54:30 +01:00
|
|
|
package blockchain_test
|
2015-01-08 12:08:11 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
"testing"
|
|
|
|
|
2015-01-30 21:54:30 +01:00
|
|
|
"github.com/btcsuite/btcd/blockchain"
|
2015-02-25 21:31:46 +01:00
|
|
|
"github.com/btcsuite/btcd/txscript"
|
2015-01-08 12:08:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// TestCheckBlockScripts ensures that validating the all of the scripts in a
|
|
|
|
// known-good block doesn't return an error.
|
|
|
|
func TestCheckBlockScripts(t *testing.T) {
|
|
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
|
|
|
|
|
|
|
testBlockNum := 277647
|
|
|
|
blockDataFile := fmt.Sprintf("%d.dat.bz2", testBlockNum)
|
|
|
|
blocks, err := loadBlocks(blockDataFile)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error loading file: %v\n", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(blocks) > 1 {
|
|
|
|
t.Errorf("The test block file must only have one block in it")
|
2016-09-16 21:44:27 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(blocks) == 0 {
|
|
|
|
t.Errorf("The test block file may not be empty")
|
|
|
|
return
|
2015-01-08 12:08:11 +01:00
|
|
|
}
|
|
|
|
|
2015-08-26 06:03:18 +02:00
|
|
|
storeDataFile := fmt.Sprintf("%d.utxostore.bz2", testBlockNum)
|
|
|
|
view, err := loadUtxoView(storeDataFile)
|
2015-01-08 12:08:11 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error loading txstore: %v\n", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-02-25 21:31:46 +01:00
|
|
|
scriptFlags := txscript.ScriptBip16
|
2015-08-26 06:03:18 +02:00
|
|
|
err = blockchain.TstCheckBlockScripts(blocks[0], view, scriptFlags,
|
|
|
|
nil)
|
2015-02-25 21:31:46 +01:00
|
|
|
if err != nil {
|
2015-08-26 06:03:18 +02:00
|
|
|
t.Errorf("Transaction script validation failed: %v\n", err)
|
2015-01-08 12:08:11 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|