github.com/lbryio/lbcd@v0.22.119/blockchain/scriptval_test.go (about)

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