mirror of
https://github.com/kaspanet/kaspad.git
synced 2026-03-02 15:13:13 +00:00
This commit adds all of the infrastructure needed to support BIP0009
soft forks.
The following is an overview of the changes:
- Add new configuration options to the chaincfg package which allows the
rule deployments to be defined per chain
- Implement code to calculate the threshold state as required by BIP0009
- Use threshold state caches that are stored to the database in order
to accelerate startup time
- Remove caches that are invalid due to definition changes in the
params including additions, deletions, and changes to existing
entries
- Detect and warn when a new unknown rule is about to activate or has
been activated in the block connection code
- Detect and warn when 50% of the last 100 blocks have unexpected
versions.
- Remove the latest block version from wire since it no longer applies
- Add a version parameter to the wire.NewBlockHeader function since the
default is no longer available
- Update the miner block template generation code to use the calculated
block version based on the currently defined rule deployments and
their threshold states as of the previous block
- Add tests for new error type
- Add tests for threshold state cache
132 lines
4.0 KiB
Go
132 lines
4.0 KiB
Go
// Copyright (c) 2014 The btcsuite developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package blockchain_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/btcsuite/btcd/blockchain"
|
|
)
|
|
|
|
// TestErrorCodeStringer tests the stringized output for the ErrorCode type.
|
|
func TestErrorCodeStringer(t *testing.T) {
|
|
tests := []struct {
|
|
in blockchain.ErrorCode
|
|
want string
|
|
}{
|
|
{blockchain.ErrDuplicateBlock, "ErrDuplicateBlock"},
|
|
{blockchain.ErrBlockTooBig, "ErrBlockTooBig"},
|
|
{blockchain.ErrBlockVersionTooOld, "ErrBlockVersionTooOld"},
|
|
{blockchain.ErrInvalidTime, "ErrInvalidTime"},
|
|
{blockchain.ErrTimeTooOld, "ErrTimeTooOld"},
|
|
{blockchain.ErrTimeTooNew, "ErrTimeTooNew"},
|
|
{blockchain.ErrDifficultyTooLow, "ErrDifficultyTooLow"},
|
|
{blockchain.ErrUnexpectedDifficulty, "ErrUnexpectedDifficulty"},
|
|
{blockchain.ErrHighHash, "ErrHighHash"},
|
|
{blockchain.ErrBadMerkleRoot, "ErrBadMerkleRoot"},
|
|
{blockchain.ErrBadCheckpoint, "ErrBadCheckpoint"},
|
|
{blockchain.ErrForkTooOld, "ErrForkTooOld"},
|
|
{blockchain.ErrCheckpointTimeTooOld, "ErrCheckpointTimeTooOld"},
|
|
{blockchain.ErrNoTransactions, "ErrNoTransactions"},
|
|
{blockchain.ErrTooManyTransactions, "ErrTooManyTransactions"},
|
|
{blockchain.ErrNoTxInputs, "ErrNoTxInputs"},
|
|
{blockchain.ErrNoTxOutputs, "ErrNoTxOutputs"},
|
|
{blockchain.ErrTxTooBig, "ErrTxTooBig"},
|
|
{blockchain.ErrBadTxOutValue, "ErrBadTxOutValue"},
|
|
{blockchain.ErrDuplicateTxInputs, "ErrDuplicateTxInputs"},
|
|
{blockchain.ErrBadTxInput, "ErrBadTxInput"},
|
|
{blockchain.ErrBadCheckpoint, "ErrBadCheckpoint"},
|
|
{blockchain.ErrMissingTx, "ErrMissingTx"},
|
|
{blockchain.ErrUnfinalizedTx, "ErrUnfinalizedTx"},
|
|
{blockchain.ErrDuplicateTx, "ErrDuplicateTx"},
|
|
{blockchain.ErrOverwriteTx, "ErrOverwriteTx"},
|
|
{blockchain.ErrImmatureSpend, "ErrImmatureSpend"},
|
|
{blockchain.ErrDoubleSpend, "ErrDoubleSpend"},
|
|
{blockchain.ErrSpendTooHigh, "ErrSpendTooHigh"},
|
|
{blockchain.ErrBadFees, "ErrBadFees"},
|
|
{blockchain.ErrTooManySigOps, "ErrTooManySigOps"},
|
|
{blockchain.ErrFirstTxNotCoinbase, "ErrFirstTxNotCoinbase"},
|
|
{blockchain.ErrMultipleCoinbases, "ErrMultipleCoinbases"},
|
|
{blockchain.ErrBadCoinbaseScriptLen, "ErrBadCoinbaseScriptLen"},
|
|
{blockchain.ErrBadCoinbaseValue, "ErrBadCoinbaseValue"},
|
|
{blockchain.ErrMissingCoinbaseHeight, "ErrMissingCoinbaseHeight"},
|
|
{blockchain.ErrBadCoinbaseHeight, "ErrBadCoinbaseHeight"},
|
|
{blockchain.ErrScriptMalformed, "ErrScriptMalformed"},
|
|
{blockchain.ErrScriptValidation, "ErrScriptValidation"},
|
|
{0xffff, "Unknown ErrorCode (65535)"},
|
|
}
|
|
|
|
t.Logf("Running %d tests", len(tests))
|
|
for i, test := range tests {
|
|
result := test.in.String()
|
|
if result != test.want {
|
|
t.Errorf("String #%d\n got: %s want: %s", i, result,
|
|
test.want)
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestRuleError tests the error output for the RuleError type.
|
|
func TestRuleError(t *testing.T) {
|
|
tests := []struct {
|
|
in blockchain.RuleError
|
|
want string
|
|
}{
|
|
{
|
|
blockchain.RuleError{Description: "duplicate block"},
|
|
"duplicate block",
|
|
},
|
|
{
|
|
blockchain.RuleError{Description: "human-readable error"},
|
|
"human-readable error",
|
|
},
|
|
}
|
|
|
|
t.Logf("Running %d tests", len(tests))
|
|
for i, test := range tests {
|
|
result := test.in.Error()
|
|
if result != test.want {
|
|
t.Errorf("Error #%d\n got: %s want: %s", i, result,
|
|
test.want)
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestDeploymentError tests the stringized output for the DeploymentError type.
|
|
func TestDeploymentError(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
in blockchain.DeploymentError
|
|
want string
|
|
}{
|
|
{
|
|
blockchain.DeploymentError(0),
|
|
"deployment ID 0 does not exist",
|
|
},
|
|
{
|
|
blockchain.DeploymentError(10),
|
|
"deployment ID 10 does not exist",
|
|
},
|
|
{
|
|
blockchain.DeploymentError(123),
|
|
"deployment ID 123 does not exist",
|
|
},
|
|
}
|
|
|
|
t.Logf("Running %d tests", len(tests))
|
|
for i, test := range tests {
|
|
result := test.in.Error()
|
|
if result != test.want {
|
|
t.Errorf("Error #%d\n got: %s want: %s", i, result,
|
|
test.want)
|
|
continue
|
|
}
|
|
}
|
|
|
|
}
|