Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
blockchain: check errors and remove ineffectual assignments.
Browse files Browse the repository at this point in the history
  • Loading branch information
dajohi authored and davecgh committed Jul 17, 2017
1 parent 9c5f4d3 commit 59db139
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
3 changes: 3 additions & 0 deletions blockchain/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func TestBlockchainFunctions(t *testing.T) {
// Load up the rest of the blocks up to HEAD~1.
filename := filepath.Join("testdata/", "blocks0to168.bz2")
fi, err := os.Open(filename)
if err != nil {
t.Errorf("Unable to open %s: %v", filename, err)
}
bcStream := bzip2.NewReader(fi)
defer fi.Close()

Expand Down
4 changes: 2 additions & 2 deletions blockchain/fullblocktests/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ func Generate() (tests [][]TestInstance, err error) {
//
// OP_CHECKMULTISIG counts for 20 sigops.
tooManySigOps = repeatOpcode(txscript.OP_CHECKMULTISIG, maxBlockSigOps/20)
tooManySigOps = append(manySigOps, txscript.OP_CHECKSIG)
tooManySigOps = append(tooManySigOps, txscript.OP_CHECKSIG)
g.NextBlock("b38", outs[10], ticketOuts[10], replaceSpendScript(tooManySigOps))
g.AssertTipBlockSigOpsCount(maxBlockSigOps + 1)
rejected(blockchain.ErrTooManySigOps)
Expand All @@ -1067,7 +1067,7 @@ func Generate() (tests [][]TestInstance, err error) {
// \-> b40(11)
//
tooManySigOps = repeatOpcode(txscript.OP_CHECKMULTISIGVERIFY, maxBlockSigOps/20)
tooManySigOps = append(manySigOps, txscript.OP_CHECKSIG)
tooManySigOps = append(tooManySigOps, txscript.OP_CHECKSIG)
g.NextBlock("b40", outs[11], ticketOuts[11], replaceSpendScript(tooManySigOps))
g.AssertTipBlockSigOpsCount(maxBlockSigOps + 1)
rejected(blockchain.ErrTooManySigOps)
Expand Down
12 changes: 12 additions & 0 deletions blockchain/reorganization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func reorgTestLong(t *testing.T) {
// Load up the rest of the blocks up to HEAD.
filename := filepath.Join("testdata/", "reorgto179.bz2")
fi, err := os.Open(filename)
if err != nil {
t.Errorf("Unable to open %s: %v", filename, err)
}
bcStream := bzip2.NewReader(fi)
defer fi.Close()

Expand Down Expand Up @@ -75,6 +78,9 @@ func reorgTestLong(t *testing.T) {
// Load up the rest of the blocks up to HEAD.
filename = filepath.Join("testdata/", "reorgto180.bz2")
fi, err = os.Open(filename)
if err != nil {
t.Errorf("Unable to open %s: %v", filename, err)
}
bcStream = bzip2.NewReader(fi)
defer fi.Close()

Expand Down Expand Up @@ -149,6 +155,9 @@ func reorgTestShort(t *testing.T) {
// Load up the rest of the blocks up to HEAD.
filename := filepath.Join("testdata/", "reorgto179.bz2")
fi, err := os.Open(filename)
if err != nil {
t.Errorf("Unable to open %s: %v", filename, err)
}
bcStream := bzip2.NewReader(fi)
defer fi.Close()

Expand All @@ -170,6 +179,9 @@ func reorgTestShort(t *testing.T) {
// Load up the rest of the blocks up to HEAD.
filename = filepath.Join("testdata/", "reorgto180.bz2")
fi, err = os.Open(filename)
if err != nil {
t.Errorf("Unable to open %s: %v", filename, err)
}
bcStream = bzip2.NewReader(fi)
defer fi.Close()

Expand Down
6 changes: 6 additions & 0 deletions blockchain/stake/staketx.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ func TxSSGenStakeOutputInfo(tx *wire.MsgTx, params *chaincfg.Params) ([]bool,
"ssgen tagged output in idx %v", idx)
}
subClass, err := txscript.GetStakeOutSubclass(out.PkScript)
if err != nil {
return nil, nil, nil, err
}
if !(subClass == txscript.PubKeyHashTy ||
subClass == txscript.ScriptHashTy) {
return nil, nil, nil, fmt.Errorf("bad script type")
Expand Down Expand Up @@ -494,6 +497,9 @@ func TxSSRtxStakeOutputInfo(tx *wire.MsgTx, params *chaincfg.Params) ([]bool,
"ssrtx tagged output in idx %v", idx)
}
subClass, err := txscript.GetStakeOutSubclass(out.PkScript)
if err != nil {
return nil, nil, nil, err
}
if !(subClass == txscript.PubKeyHashTy ||
subClass == txscript.ScriptHashTy) {
return nil, nil, nil, fmt.Errorf("bad script type")
Expand Down
1 change: 0 additions & 1 deletion blockchain/stakeversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ func TestCalcStakeVersionCorners(t *testing.T) {
bc.bestNode = currentNode

}
height += runCount

if !bc.isStakeMajorityVersion(0, currentNode) {
t.Fatalf("invalid StakeVersion expected 0 -> true")
Expand Down
3 changes: 3 additions & 0 deletions blockchain/subsidy.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ func BlockOneCoinbasePaysTokens(tx *dcrutil.Tx,
// There should only be one address.
_, addrs, _, err :=
txscript.ExtractPkScriptAddrs(txout.Version, txout.PkScript, params)
if err != nil {
return ruleError(ErrBlockOneOutputs, err.Error())
}
if len(addrs) != 1 {
errStr := fmt.Sprintf("too many addresses in output")
return ruleError(ErrBlockOneOutputs, errStr)
Expand Down

0 comments on commit 59db139

Please sign in to comment.