multi: Use regression test network in unit tests.

This modifies the majority of the tests that make use of chain
parameters and the RPC tests to use the resurrected regression test
network.

It also bumps the affected module versions as follows:

- github.com/decred/dcrd/txscript@v1.0.2
- github.com/decred/dcrd/blockchain/stake@v1.0.3
- github.com/decred/dcrd/mempool@v1.0.2

The blockchain and dcrutil modules are also affected, but since their
version has already been bumped since their last release tags, they are
not bumped again.
This commit is contained in:
Dave Collins 2018-10-04 23:49:52 -05:00
parent 47ade78c1a
commit 6f9b6f1c6e
No known key found for this signature in database
GPG Key ID: B8904D9D9C93D1F2
28 changed files with 224 additions and 116 deletions

View File

@ -179,5 +179,5 @@ func testLNFeaturesDeployment(t *testing.T, params *chaincfg.Params, deploymentV
// activate the expected changes.
func TestLNFeaturesDeployment(t *testing.T) {
testLNFeaturesDeployment(t, &chaincfg.MainNetParams, 5)
testLNFeaturesDeployment(t, &chaincfg.SimNetParams, 6)
testLNFeaturesDeployment(t, &chaincfg.RegNetParams, 6)
}

View File

@ -32,7 +32,7 @@ func mustParseHash(s string) *chainhash.Hash {
func TestBlockNodeHeader(t *testing.T) {
// Create a fake chain and block header with all fields set to nondefault
// values.
params := &chaincfg.SimNetParams
params := &chaincfg.RegNetParams
bc := newFakeChain(params)
tip := bc.bestChain.Tip()
testHeader := wire.BlockHeader{
@ -150,7 +150,15 @@ func TestCalcPastMedianTime(t *testing.T) {
},
}
params := &chaincfg.SimNetParams
// Ensure the genesis block timestamp of the test params is before the test
// data. Also, clone the provided parameters first to avoid mutating them.
//
// The timestamp corresponds to 2018-01-01 00:00:00 +0000 UTC.
params := cloneParams(&chaincfg.RegNetParams)
params.GenesisBlock.Header.Timestamp = time.Unix(1514764800, 0)
genesisHash := params.GenesisBlock.BlockHash()
params.GenesisHash = &genesisHash
for _, test := range tests {
// Create a synthetic chain with the correct number of nodes and the
// timestamps as specified by the test.
@ -176,7 +184,7 @@ func TestCalcPastMedianTime(t *testing.T) {
// TestChainTips ensures the chain tip tracking in the block index works
// as expected.
func TestChainTips(t *testing.T) {
params := &chaincfg.SimNetParams
params := &chaincfg.RegNetParams
bc := newFakeChain(params)
genesis := bc.bestChain.NodeByHeight(0)

View File

@ -14,6 +14,7 @@ import (
"path/filepath"
"reflect"
"testing"
"time"
"github.com/decred/dcrd/blockchain/chaingen"
"github.com/decred/dcrd/chaincfg"
@ -40,10 +41,19 @@ func cloneParams(params *chaincfg.Params) *chaincfg.Params {
// TestBlockchainFunction tests the various blockchain API to ensure proper
// functionality.
func TestBlockchainFunctions(t *testing.T) {
// Update simnet parameters to reflect what is expected by the legacy
// data.
params := cloneParams(&chaincfg.SimNetParams)
// Update parameters to reflect what is expected by the legacy data.
params := cloneParams(&chaincfg.RegNetParams)
params.GenesisBlock.Header.MerkleRoot = *mustParseHash("a216ea043f0d481a072424af646787794c32bcefd3ed181a090319bbf8a37105")
params.GenesisBlock.Header.Timestamp = time.Unix(1401292357, 0)
params.GenesisBlock.Transactions[0].TxIn[0].ValueIn = 0
params.PubKeyHashAddrID = [2]byte{0x0e, 0x91}
params.StakeBaseSigScript = []byte{0xde, 0xad, 0xbe, 0xef}
params.OrganizationPkScript = hexToBytes("a914cbb08d6ca783b533b2c7d24a51fbca92d937bf9987")
params.BlockOneLedger = []*chaincfg.TokenPayout{
{Address: "Sshw6S86G2bV6W32cbc7EhtFy8f93rU6pae", Amount: 100000 * 1e8},
{Address: "SsjXRK6Xz6CFuBt6PugBvrkdAa4xGbcZ18w", Amount: 100000 * 1e8},
{Address: "SsfXiYkYkCoo31CuVQw428N6wWKus2ZEw5X", Amount: 100000 * 1e8},
}
genesisHash := params.GenesisBlock.BlockHash()
params.GenesisHash = &genesisHash
@ -125,7 +135,7 @@ func TestForceHeadReorg(t *testing.T) {
// Create a test generator instance initialized with the genesis block
// as the tip as well as some cached payment scripts to be used
// throughout the tests.
params := &chaincfg.SimNetParams
params := &chaincfg.RegNetParams
g, err := chaingen.MakeGenerator(params)
if err != nil {
t.Fatalf("Failed to create generator: %v", err)

View File

@ -15,7 +15,7 @@ import (
// generate the required premine block and enough blocks to have mature coinbase
// outputs to work with along with asserting the generator state along the way.
func Example_basicUsage() {
params := &chaincfg.SimNetParams
params := &chaincfg.RegNetParams
g, err := chaingen.MakeGenerator(params)
if err != nil {
fmt.Println(err)

View File

@ -1056,9 +1056,9 @@ nextTest:
// minimum required difficulty, when the network params allow it, works as
// expected.
func TestMinDifficultyReduction(t *testing.T) {
// Create chain params based on simnet params, but set the fields related to
// Create chain params based on regnet params, but set the fields related to
// proof-of-work difficulty to specific values expected by the tests.
params := chaincfg.SimNetParams
params := chaincfg.RegNetParams
params.ReduceMinDifficulty = true
params.TargetTimePerBlock = time.Minute * 2
params.MinDiffReductionTime = time.Minute * 10 // ~99.3% chance to be mined

View File

@ -133,7 +133,7 @@ func TestFullBlocks(t *testing.T) {
// Create a new database and chain instance to run tests against.
chain, teardownFunc, err := chainSetup("fullblocktest",
&chaincfg.SimNetParams)
&chaincfg.RegNetParams)
if err != nil {
t.Fatalf("Failed to setup chain instance: %v", err)
}

View File

@ -19,7 +19,7 @@ func TestStakeVersion(t *testing.T) {
// Create a test generator instance initialized with the genesis block
// as the tip as well as some cached payment scripts to be used
// throughout the tests.
params := &chaincfg.SimNetParams
params := &chaincfg.RegNetParams
g, err := chaingen.MakeGenerator(params)
if err != nil {
t.Fatalf("Failed to create generator: %v", err)

View File

@ -370,7 +370,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
// Create a generator instance initialized with the genesis block as the
// tip as well as some cached payment scripts to be used throughout the
// tests.
g, err := chaingen.MakeGenerator(simNetParams)
g, err := chaingen.MakeGenerator(regNetParams)
if err != nil {
return nil, err
}

View File

@ -44,13 +44,13 @@ var (
// the overhead of creating it multiple times.
bigOne = big.NewInt(1)
// simNetPowLimit is the highest proof of work value a Decred block
// can have for the simulation test network. It is the value 2^255 - 1.
simNetPowLimit = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 255), bigOne)
// regNetPowLimit is the highest proof of work value a Decred block
// can have for the regression test network. It is the value 2^255 - 1.
regNetPowLimit = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 255), bigOne)
// simNetGenesisBlock defines the genesis block of the block chain which serves
// as the public transaction ledger for the simulation test network.
simNetGenesisBlock = wire.MsgBlock{
// regNetGenesisBlock defines the genesis block of the block chain which
// serves as the public transaction ledger for the regression test network.
regNetGenesisBlock = wire.MsgBlock{
Header: wire.BlockHeader{
Version: 1,
PrevBlock: *newHashFromStr("0000000000000000000000000000000000000000000000000000000000000000"),
@ -61,7 +61,7 @@ var (
Voters: uint16(0x0000),
FreshStake: uint8(0x00),
Revocations: uint8(0x00),
Timestamp: time.Unix(1401292357, 0), // 2009-01-08 20:54:25 -0600 CST
Timestamp: time.Unix(1538524800, 0), // 2018-10-03 00:00:00 +0000 UTC
PoolSize: uint32(0),
Bits: 0x207fffff, // 545259519
SBits: int64(0x0000000000000000),
@ -76,20 +76,15 @@ var (
Hash: chainhash.Hash{},
Index: 0xffffffff,
},
SignatureScript: fromHex("04ffff001d010445" +
"5468652054696d65732030332f4a616e2f" +
"32303039204368616e63656c6c6f72206f" +
"6e206272696e6b206f66207365636f6e64" +
"206261696c6f757420666f72206261686b73"),
Sequence: 0xffffffff,
SignatureScript: fromHex("0000"),
Sequence: 0xffffffff,
BlockIndex: 0xffffffff,
ValueIn: -1,
}},
TxOut: []*wire.TxOut{{
Value: 0,
PkScript: fromHex("4104678afdb0fe5548271967f1" +
"a67130b7105cd6a828e03909a67962e0ea1f" +
"61deb649f6bc3f4cef38c4f35504e51ec138" +
"c4f35504e51ec112de5c384df7ba0b8d578a" +
"4c702b6bf11d5fac"),
PkScript: fromHex("801679e98561ada96caec2949a" +
"5d41c4cab3851eb740d951c10ecbcf265c1fd9"),
}},
LockTime: 0,
Expiry: 0,
@ -98,23 +93,22 @@ var (
}
)
// simNetParams defines the network parameters for the simulation test Decred
// network.
// regNetParams defines the network parameters for the regression test network.
//
// NOTE: The test generator intentionally does not use the existing definitions
// in the chaincfg package since the intent is to be able to generate known
// good tests which exercise that code. Using the chaincfg parameters would
// allow them to change without the tests failing as desired.
var simNetParams = &chaincfg.Params{
Name: "simnet",
Net: wire.SimNet,
DefaultPort: "18555",
var regNetParams = &chaincfg.Params{
Name: "regnet",
Net: wire.RegNet,
DefaultPort: "18655",
DNSSeeds: nil, // NOTE: There must NOT be any seeds.
// Chain parameters
GenesisBlock: &simNetGenesisBlock,
GenesisHash: newHashFromStr("5bec7567af40504e0994db3b573c186fffcc4edefe096ff2e58d00523bd7e8a6"),
PowLimit: simNetPowLimit,
GenesisBlock: &regNetGenesisBlock,
GenesisHash: newHashFromStr("2ced94b4ae95bba344cfa043268732d230649c640f92dce2d9518823d3057cb0"),
PowLimit: regNetPowLimit,
PowLimitBits: 0x207fffff,
ReduceMinDifficulty: false,
MinDiffReductionTime: 0, // Does not apply since ReduceMinDifficulty false
@ -140,7 +134,7 @@ var simNetParams = &chaincfg.Params{
// Checkpoints ordered from oldest to newest.
Checkpoints: nil,
// BIP0009 consensus rule change deployments.
// Consensus rule change deployments.
//
// The miner confirmation window is defined as:
// target proof of work timespan / target proof of work spacing
@ -250,46 +244,49 @@ var simNetParams = &chaincfg.Params{
AcceptNonStdTxs: true,
// Address encoding magics
NetworkAddressPrefix: "S",
PubKeyAddrID: [2]byte{0x27, 0x6f}, // starts with Sk
PubKeyHashAddrID: [2]byte{0x0e, 0x91}, // starts with Ss
PKHEdwardsAddrID: [2]byte{0x0e, 0x71}, // starts with Se
PKHSchnorrAddrID: [2]byte{0x0e, 0x53}, // starts with SS
ScriptHashAddrID: [2]byte{0x0e, 0x6c}, // starts with Sc
PrivateKeyID: [2]byte{0x23, 0x07}, // starts with Ps
NetworkAddressPrefix: "R",
PubKeyAddrID: [2]byte{0x25, 0xe5}, // starts with Rk
PubKeyHashAddrID: [2]byte{0x0e, 0x00}, // starts with Rs
PKHEdwardsAddrID: [2]byte{0x0d, 0xe0}, // starts with Re
PKHSchnorrAddrID: [2]byte{0x0d, 0xc2}, // starts with RS
ScriptHashAddrID: [2]byte{0x0d, 0xdb}, // starts with Rc
PrivateKeyID: [2]byte{0x22, 0xfe}, // starts with Pr
// BIP32 hierarchical deterministic extended key magics
HDPrivateKeyID: [4]byte{0x04, 0x20, 0xb9, 0x03}, // starts with sprv
HDPublicKeyID: [4]byte{0x04, 0x20, 0xbd, 0x3d}, // starts with spub
HDPrivateKeyID: [4]byte{0xea, 0xb4, 0x04, 0x48}, // starts with rprv
HDPublicKeyID: [4]byte{0xea, 0xb4, 0xf9, 0x87}, // starts with rpub
// BIP44 coin type used in the hierarchical deterministic path for
// address generation.
SLIP0044CoinType: 1, // SLIP0044, Testnet (all coins)
LegacyCoinType: 115, // ASCII for s, for backwards compatibility
SLIP0044CoinType: 1, // SLIP0044, Testnet (all coins)
LegacyCoinType: 1,
// Decred PoS parameters
MinimumStakeDiff: 20000,
TicketPoolSize: 64,
TicketsPerBlock: 5,
TicketMaturity: 16,
TicketExpiry: 384, // 6*TicketPoolSize
CoinbaseMaturity: 16,
SStxChangeMaturity: 1,
TicketPoolSizeWeight: 4,
StakeDiffAlpha: 1,
StakeDiffWindowSize: 8,
StakeDiffWindows: 8,
MaxFreshStakePerBlock: 20, // 4*TicketsPerBlock
StakeEnabledHeight: 16 + 16, // CoinbaseMaturity + TicketMaturity
StakeValidationHeight: 16 + (64 * 2), // CoinbaseMaturity + TicketPoolSize*2
StakeBaseSigScript: []byte{0xde, 0xad, 0xbe, 0xef},
MinimumStakeDiff: 20000,
TicketPoolSize: 64,
TicketsPerBlock: 5,
TicketMaturity: 16,
TicketExpiry: 384, // 6*TicketPoolSize
CoinbaseMaturity: 16,
SStxChangeMaturity: 1,
TicketPoolSizeWeight: 4,
StakeDiffAlpha: 1,
StakeDiffWindowSize: 8,
StakeDiffWindows: 8,
StakeVersionInterval: 8 * 2 * 7,
MaxFreshStakePerBlock: 20, // 4*TicketsPerBlock
StakeEnabledHeight: 16 + 16, // CoinbaseMaturity + TicketMaturity
StakeValidationHeight: 16 + (64 * 2), // CoinbaseMaturity + TicketPoolSize*2
StakeBaseSigScript: []byte{0x73, 0x57},
StakeMajorityMultiplier: 3,
StakeMajorityDivisor: 4,
// Decred organization related parameters
OrganizationPkScript: fromHex("a914cbb08d6ca783b533b2c7d24a51fbca92d937bf9987"),
OrganizationPkScript: fromHex("a9146913bcc838bd0087fb3f6b3c868423d5e300078d87"),
OrganizationPkScriptVersion: 0,
BlockOneLedger: []*chaincfg.TokenPayout{
{Address: "Sshw6S86G2bV6W32cbc7EhtFy8f93rU6pae", Amount: 100000 * 1e8},
{Address: "SsjXRK6Xz6CFuBt6PugBvrkdAa4xGbcZ18w", Amount: 100000 * 1e8},
{Address: "SsfXiYkYkCoo31CuVQw428N6wWKus2ZEw5X", Amount: 100000 * 1e8},
{Address: "RsKrWb7Vny1jnzL1sDLgKTAteh9RZcRr5g6", Amount: 100000 * 1e8},
{Address: "Rs8ca5cDALtsMVD4PV3xvFTC7dmuU1juvLv", Amount: 100000 * 1e8},
{Address: "RsHzbGt6YajuHpurtpqXXHz57LmYZK8w9tX", Amount: 100000 * 1e8},
},
}

View File

@ -34,7 +34,7 @@ func TestCalcSequenceLock(t *testing.T) {
// Generate a synthetic simnet chain with enough nodes to properly test
// the sequence lock functionality.
numBlocks := uint32(20)
params := &chaincfg.SimNetParams
params := &chaincfg.RegNetParams
bc := newFakeChain(params)
node := bc.bestChain.Tip()
blockTime := time.Unix(node.timestamp, 0)

View File

@ -1,13 +1,13 @@
module github.com/decred/dcrd/blockchain/stake
require (
github.com/decred/dcrd/chaincfg v1.1.1
github.com/decred/dcrd/chaincfg v1.2.0
github.com/decred/dcrd/chaincfg/chainhash v1.0.1
github.com/decred/dcrd/database v1.0.1
github.com/decred/dcrd/dcrec v0.0.0-20180801202239-0761de129164
github.com/decred/dcrd/dcrutil v1.1.1
github.com/decred/dcrd/txscript v1.0.1
github.com/decred/dcrd/wire v1.1.0
github.com/decred/dcrd/wire v1.2.0
github.com/decred/slog v1.0.0
github.com/fsnotify/fsnotify v1.4.7 // indirect
github.com/golang/protobuf v1.1.0 // indirect

View File

@ -425,7 +425,7 @@ func TestLiveDatabase(t *testing.T) {
t.Fatalf("unable to create test db path: %v", err)
}
defer os.RemoveAll(dbPath)
testDb, err := database.Create(testDbType, dbPath, chaincfg.SimNetParams.Net)
testDb, err := database.Create(testDbType, dbPath, chaincfg.RegNetParams.Net)
if err != nil {
t.Fatalf("error creating db: %v", err)
}

View File

@ -892,7 +892,7 @@ func TestGetSSGenStakeOutputInfo(t *testing.T) {
correctamt := int64(0x2123e300)
typs, pkhs, amts, err := stake.TxSSGenStakeOutputInfo(ssgen.MsgTx(),
&chaincfg.SimNetParams)
&chaincfg.RegNetParams)
if err != nil {
t.Errorf("Got unexpected error: %v", err.Error())
}
@ -970,7 +970,7 @@ func TestGetSSRtxStakeOutputInfo(t *testing.T) {
correctAmt := int64(0x2122e300)
typs, pkhs, amts, err := stake.TxSSRtxStakeOutputInfo(ssrtx.MsgTx(),
&chaincfg.SimNetParams)
&chaincfg.RegNetParams)
if err != nil {
t.Errorf("Got unexpected error: %v", err.Error())
}

View File

@ -208,7 +208,7 @@ func nodesEqual(a *Node, b *Node) error {
func TestTicketDBLongChain(t *testing.T) {
// Declare some useful variables.
params := &chaincfg.SimNetParams
params := &chaincfg.RegNetParams
testBCHeight := int64(1001)
filename := filepath.Join("testdata", "testexpiry.bz2")
fi, err := os.Open(filename)
@ -588,7 +588,7 @@ func TestTicketDBLongChain(t *testing.T) {
func TestTicketDBGeneral(t *testing.T) {
// Declare some useful variables.
params := &chaincfg.SimNetParams
params := &chaincfg.RegNetParams
testBCHeight := int64(168)
filename := filepath.Join("testdata", "blocks0to168.bz2")
fi, err := os.Open(filename)

View File

@ -321,7 +321,7 @@ func TestCalcStakeVersion(t *testing.T) {
// TestIsStakeMajorityVersion ensures that determining the current majority
// stake version works as intended under a wide variety of scenarios.
func TestIsStakeMajorityVersion(t *testing.T) {
params := &chaincfg.MainNetParams
params := &chaincfg.RegNetParams
svh := params.StakeValidationHeight
svi := params.StakeVersionInterval
tpb := params.TicketsPerBlock

View File

@ -113,12 +113,12 @@ var (
// TestThresholdState ensures that the threshold state function progresses
// through the states correctly.
func TestThresholdState(t *testing.T) {
// Create chain params based on simnet params, but add a specific test
// Create chain params based on regnet params, but add a specific test
// dummy deployment and set the proof-of-work difficulty readjustment
// size to a really large number so that the test chain can be generated
// more quickly.
posVersion := uint32(4)
params := chaincfg.SimNetParams
params := chaincfg.RegNetParams
params.WorkDiffWindowSize = 200000
params.WorkDiffWindows = 1
params.TargetTimespan = params.TargetTimePerBlock *

View File

@ -27,10 +27,19 @@ import (
// TestBlockchainSpendJournal tests for whether or not the spend journal is being
// written to disk correctly on a live blockchain.
func TestBlockchainSpendJournal(t *testing.T) {
// Update simnet parameters to reflect what is expected by the legacy
// data.
params := cloneParams(&chaincfg.SimNetParams)
// Update parameters to reflect what is expected by the legacy data.
params := cloneParams(&chaincfg.RegNetParams)
params.GenesisBlock.Header.MerkleRoot = *mustParseHash("a216ea043f0d481a072424af646787794c32bcefd3ed181a090319bbf8a37105")
params.GenesisBlock.Header.Timestamp = time.Unix(1401292357, 0)
params.GenesisBlock.Transactions[0].TxIn[0].ValueIn = 0
params.PubKeyHashAddrID = [2]byte{0x0e, 0x91}
params.StakeBaseSigScript = []byte{0xde, 0xad, 0xbe, 0xef}
params.OrganizationPkScript = hexToBytes("a914cbb08d6ca783b533b2c7d24a51fbca92d937bf9987")
params.BlockOneLedger = []*chaincfg.TokenPayout{
{Address: "Sshw6S86G2bV6W32cbc7EhtFy8f93rU6pae", Amount: 100000 * 1e8},
{Address: "SsjXRK6Xz6CFuBt6PugBvrkdAa4xGbcZ18w", Amount: 100000 * 1e8},
{Address: "SsfXiYkYkCoo31CuVQw428N6wWKus2ZEw5X", Amount: 100000 * 1e8},
}
genesisHash := params.GenesisBlock.BlockHash()
params.GenesisHash = &genesisHash
@ -222,7 +231,7 @@ func TestSequenceLocksActive(t *testing.T) {
// TestCheckBlockSanity tests the context free block sanity checks with blocks
// not on a chain.
func TestCheckBlockSanity(t *testing.T) {
params := &chaincfg.SimNetParams
params := &chaincfg.RegNetParams
timeSource := NewMedianTime()
block := dcrutil.NewBlock(&badBlock)
err := CheckBlockSanity(block, timeSource, params)
@ -234,7 +243,7 @@ func TestCheckBlockSanity(t *testing.T) {
// TestCheckWorklessBlockSanity tests the context free workless block sanity
// checks with blocks not on a chain.
func TestCheckWorklessBlockSanity(t *testing.T) {
params := &chaincfg.SimNetParams
params := &chaincfg.RegNetParams
timeSource := NewMedianTime()
block := dcrutil.NewBlock(&badBlock)
err := CheckWorklessBlockSanity(block, timeSource, params)
@ -247,7 +256,7 @@ func TestCheckWorklessBlockSanity(t *testing.T) {
// because its parent is nil.
func TestCheckBlockHeaderContext(t *testing.T) {
// Create a new database for the blocks.
params := &chaincfg.SimNetParams
params := &chaincfg.RegNetParams
dbPath := filepath.Join(os.TempDir(), "examplecheckheadercontext")
_ = os.RemoveAll(dbPath)
db, err := database.Create("ffldb", dbPath, params.Net)
@ -323,7 +332,7 @@ func TestTxValidationErrors(t *testing.T) {
var badBlock = wire.MsgBlock{
Header: wire.BlockHeader{
Version: 1,
MerkleRoot: chaincfg.SimNetParams.GenesisBlock.Header.MerkleRoot,
MerkleRoot: chaincfg.RegNetParams.GenesisBlock.Header.MerkleRoot,
VoteBits: uint16(0x0000),
FinalState: [6]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
Voters: uint16(0x0000),
@ -347,7 +356,7 @@ func TestCheckConnectBlockTemplate(t *testing.T) {
// Create a test generator instance initialized with the genesis block
// as the tip as well as some cached payment scripts to be used
// throughout the tests.
params := &chaincfg.SimNetParams
params := &chaincfg.RegNetParams
g, err := chaingen.MakeGenerator(params)
if err != nil {
t.Fatalf("Failed to create generator: %v", err)

View File

@ -96,8 +96,10 @@ var (
}
)
// defaultParams returns net parameters modified to have a single known
// deployment that is used throughout the various votebit tests.
func defaultParams(vote chaincfg.Vote) chaincfg.Params {
params := chaincfg.SimNetParams
params := chaincfg.RegNetParams
params.Deployments = make(map[uint32][]chaincfg.ConsensusDeployment)
params.Deployments[posVersion] = []chaincfg.ConsensusDeployment{{
Vote: vote,
@ -1496,8 +1498,10 @@ func TestVoting(t *testing.T) {
}
}
// defaultParallelParams returns net parameters modified to have two known
// deployments that are used throughout the parallel votebit tests.
func defaultParallelParams() chaincfg.Params {
params := chaincfg.SimNetParams
params := chaincfg.RegNetParams
params.Deployments = make(map[uint32][]chaincfg.ConsensusDeployment)
params.Deployments[posVersion] = []chaincfg.ConsensusDeployment{
{

View File

@ -230,8 +230,7 @@ type AddressPubKeyHash struct {
// NewAddressPubKeyHash returns a new AddressPubKeyHash. pkHash must
// be 20 bytes.
func NewAddressPubKeyHash(pkHash []byte, net *chaincfg.Params,
algo dcrec.SignatureType) (*AddressPubKeyHash, error) {
func NewAddressPubKeyHash(pkHash []byte, net *chaincfg.Params, algo dcrec.SignatureType) (*AddressPubKeyHash, error) {
var addrID [2]byte
switch algo {
case dcrec.STEcdsaSecp256k1:
@ -256,8 +255,7 @@ func NewAddressPubKeyHash(pkHash []byte, net *chaincfg.Params,
// it up through its parameters. This is useful when creating a new address
// structure from a string encoding where the identifer byte is already
// known.
func newAddressPubKeyHash(pkHash []byte, netID [2]byte) (*AddressPubKeyHash,
error) {
func newAddressPubKeyHash(pkHash []byte, netID [2]byte) (*AddressPubKeyHash, error) {
// Check for a valid pubkey hash length.
if len(pkHash) != ripemd160.Size {
return nil, errors.New("pkHash must be 20 bytes")

View File

@ -40,7 +40,6 @@ func TestAddresses(t *testing.T) {
[ripemd160.Size]byte{
0x27, 0x89, 0xd5, 0x8c, 0xfa, 0x09, 0x57, 0xd2, 0x06, 0xf0,
0x25, 0xc2, 0xaf, 0x05, 0x6f, 0xc8, 0xa7, 0x7c, 0xeb, 0xb0},
chaincfg.MainNetParams.PubKeyHashAddrID),
f: func() (dcrutil.Address, error) {
pkHash := []byte{
@ -89,6 +88,25 @@ func TestAddresses(t *testing.T) {
},
net: testNetParams,
},
{
name: "regnet p2pkh",
addr: "RsWM2w5LPJip56uxcZ1Scq7Tcbg97EfiwPA",
encoded: "RsWM2w5LPJip56uxcZ1Scq7Tcbg97EfiwPA",
valid: true,
result: dcrutil.TstAddressPubKeyHash(
[ripemd160.Size]byte{
0xf1, 0x5d, 0xa1, 0xcb, 0x8d, 0x1b, 0xcb, 0x16, 0x2c, 0x6a,
0xb4, 0x46, 0xc9, 0x57, 0x57, 0xa6, 0xe7, 0x91, 0xc9, 0x16},
chaincfg.RegNetParams.PubKeyHashAddrID),
f: func() (dcrutil.Address, error) {
pkHash := []byte{
0xf1, 0x5d, 0xa1, 0xcb, 0x8d, 0x1b, 0xcb, 0x16, 0x2c, 0x6a,
0xb4, 0x46, 0xc9, 0x57, 0x57, 0xa6, 0xe7, 0x91, 0xc9, 0x16}
return dcrutil.NewAddressPubKeyHash(pkHash,
&chaincfg.RegNetParams, dcrec.STEcdsaSecp256k1)
},
net: &chaincfg.RegNetParams,
},
// Negative P2PKH tests.
{
@ -176,6 +194,25 @@ func TestAddresses(t *testing.T) {
},
net: testNetParams,
},
{
name: "regnet p2sh",
addr: "RcKq28Eheeo2eJvWakqWWAr5pqCUWykwDHe",
encoded: "RcKq28Eheeo2eJvWakqWWAr5pqCUWykwDHe",
valid: true,
result: dcrutil.TstAddressScriptHash(
[ripemd160.Size]byte{
0x36, 0xc1, 0xca, 0x10, 0xa8, 0xa6, 0xa4, 0xb5, 0xd4, 0x20,
0x4a, 0xc9, 0x70, 0x85, 0x39, 0x79, 0x90, 0x3a, 0xa2, 0x84},
chaincfg.RegNetParams.ScriptHashAddrID),
f: func() (dcrutil.Address, error) {
hash := []byte{
0x36, 0xc1, 0xca, 0x10, 0xa8, 0xa6, 0xa4, 0xb5, 0xd4, 0x20,
0x4a, 0xc9, 0x70, 0x85, 0x39, 0x79, 0x90, 0x3a, 0xa2, 0x84}
return dcrutil.NewAddressScriptHashFromHash(hash,
&chaincfg.RegNetParams)
},
net: &chaincfg.RegNetParams,
},
// Negative P2SH tests.
{
@ -339,6 +376,52 @@ func TestAddresses(t *testing.T) {
},
net: testNetParams,
},
{
name: "regnet p2pk compressed (0x02)",
addr: "RsWUYqptu9hWfQyT8gs4pFd5uhroR5yjiVg",
encoded: "RsWUYqptu9hWfQyT8gs4pFd5uhroR5yjiVg",
valid: true,
result: dcrutil.TstAddressPubKey(
[]byte{
0x02, 0x6a, 0x40, 0xc4, 0x03, 0xe7, 0x46, 0x70, 0xc4, 0xde,
0x76, 0x56, 0xa0, 0x9c, 0xaa, 0x23, 0x53, 0xd4, 0xb3, 0x83,
0xa9, 0xce, 0x66, 0xee, 0xf5, 0x1e, 0x12, 0x20, 0xea, 0xcf,
0x4b, 0xe0, 0x6e},
dcrutil.PKFCompressed, chaincfg.RegNetParams.PubKeyHashAddrID),
f: func() (dcrutil.Address, error) {
serializedPubKey := []byte{
0x02, 0x6a, 0x40, 0xc4, 0x03, 0xe7, 0x46, 0x70, 0xc4, 0xde,
0x76, 0x56, 0xa0, 0x9c, 0xaa, 0x23, 0x53, 0xd4, 0xb3, 0x83,
0xa9, 0xce, 0x66, 0xee, 0xf5, 0x1e, 0x12, 0x20, 0xea, 0xcf,
0x4b, 0xe0, 0x6e}
return dcrutil.NewAddressSecpPubKey(serializedPubKey,
&chaincfg.RegNetParams)
},
net: &chaincfg.RegNetParams,
},
{
name: "regnet p2pk compressed (0x03)",
addr: "RsDsggcqZ7XSiq3sC9J4oq3kuj7NefnBshc",
encoded: "RsDsggcqZ7XSiq3sC9J4oq3kuj7NefnBshc",
valid: true,
result: dcrutil.TstAddressPubKey(
[]byte{
0x03, 0x08, 0x44, 0xee, 0x70, 0xd8, 0x38, 0x4d, 0x52, 0x50,
0xe9, 0xbb, 0x3a, 0x6a, 0x73, 0xd4, 0xb5, 0xbe, 0xc7, 0x70,
0xe8, 0xb3, 0x1d, 0x6a, 0x0a, 0xe9, 0xfb, 0x73, 0x90, 0x09,
0xd9, 0x1a, 0xf5},
dcrutil.PKFCompressed, chaincfg.RegNetParams.PubKeyHashAddrID),
f: func() (dcrutil.Address, error) {
serializedPubKey := []byte{
0x03, 0x08, 0x44, 0xee, 0x70, 0xd8, 0x38, 0x4d, 0x52, 0x50,
0xe9, 0xbb, 0x3a, 0x6a, 0x73, 0xd4, 0xb5, 0xbe, 0xc7, 0x70,
0xe8, 0xb3, 0x1d, 0x6a, 0x0a, 0xe9, 0xfb, 0x73, 0x90, 0x09,
0xd9, 0x1a, 0xf5}
return dcrutil.NewAddressSecpPubKey(serializedPubKey,
&chaincfg.RegNetParams)
},
net: &chaincfg.RegNetParams,
},
// Negative P2PK tests.
{

7
go.mod
View File

@ -12,24 +12,23 @@ require (
github.com/decred/base58 v1.0.0
github.com/decred/dcrd/addrmgr v1.0.2
github.com/decred/dcrd/blockchain v1.1.0
github.com/decred/dcrd/blockchain/stake v1.0.2
github.com/decred/dcrd/blockchain/stake v1.0.3
github.com/decred/dcrd/certgen v1.0.1
github.com/decred/dcrd/chaincfg v1.2.0
github.com/decred/dcrd/chaincfg/chainhash v1.0.1
github.com/decred/dcrd/connmgr v1.0.1
github.com/decred/dcrd/database v1.0.2
github.com/decred/dcrd/dcrec v0.0.0-20180801202239-0761de129164
github.com/decred/dcrd/dcrec/edwards v0.0.0-20180808153611-f0e65ec62f91 // indirect
github.com/decred/dcrd/dcrec/secp256k1 v1.0.0
github.com/decred/dcrd/dcrjson v1.0.0
github.com/decred/dcrd/dcrutil v1.2.0
github.com/decred/dcrd/gcs v1.0.2
github.com/decred/dcrd/hdkeychain v1.1.1
github.com/decred/dcrd/mempool v1.0.1
github.com/decred/dcrd/mempool v1.0.2
github.com/decred/dcrd/mining v1.0.1
github.com/decred/dcrd/peer v1.1.0
github.com/decred/dcrd/rpcclient v1.0.2
github.com/decred/dcrd/txscript v1.0.1
github.com/decred/dcrd/txscript v1.0.2
github.com/decred/dcrd/wire v1.2.0
github.com/decred/slog v1.0.0
github.com/gorilla/websocket v1.2.0

View File

@ -3,7 +3,7 @@ module github.com/decred/dcrd/mempool
require (
github.com/decred/dcrd/blockchain v1.0.1
github.com/decred/dcrd/blockchain/stake v1.0.1
github.com/decred/dcrd/chaincfg v1.1.1
github.com/decred/dcrd/chaincfg v1.2.0
github.com/decred/dcrd/chaincfg/chainhash v1.0.1
github.com/decred/dcrd/dcrec v0.0.0-20180801202239-0761de129164
github.com/decred/dcrd/dcrec/secp256k1 v1.0.0
@ -12,7 +12,7 @@ require (
github.com/decred/dcrd/gcs v1.0.1
github.com/decred/dcrd/mining v1.0.0
github.com/decred/dcrd/txscript v1.0.1
github.com/decred/dcrd/wire v1.1.0
github.com/decred/dcrd/wire v1.2.0
github.com/decred/slog v1.0.0
)

View File

@ -321,7 +321,7 @@ func TestCheckTransactionStandard(t *testing.T) {
}
addrHash := [20]byte{0x01}
addr, err := dcrutil.NewAddressPubKeyHash(addrHash[:],
&chaincfg.SimNetParams, dcrec.STEcdsaSecp256k1)
&chaincfg.RegNetParams, dcrec.STEcdsaSecp256k1)
if err != nil {
t.Fatalf("NewAddressPubKeyHash: unexpected error: %v", err)
}

View File

@ -110,7 +110,7 @@ func TestMain(m *testing.M) {
// ensure that non-standard transactions aren't accepted into the
// mempool or relayed.
args := []string{"--rejectnonstd"}
primaryHarness, err = rpctest.New(&chaincfg.SimNetParams, nil, args)
primaryHarness, err = rpctest.New(&chaincfg.RegNetParams, nil, args)
if err != nil {
fmt.Println("unable to create primary harness: ", err)
os.Exit(1)

View File

@ -117,7 +117,7 @@ func assertConnectedTo(t *testing.T, nodeA *Harness, nodeB *Harness) {
func testConnectNode(r *Harness, t *testing.T) {
// Create a fresh test harness.
harness, err := New(&chaincfg.SimNetParams, nil, nil)
harness, err := New(&chaincfg.RegNetParams, nil, nil)
if err != nil {
t.Fatal(err)
}
@ -165,7 +165,7 @@ func testActiveHarnesses(r *Harness, t *testing.T) {
numInitialHarnesses := len(ActiveHarnesses())
// Create a single test harness.
harness1, err := New(&chaincfg.SimNetParams, nil, nil)
harness1, err := New(&chaincfg.RegNetParams, nil, nil)
if err != nil {
t.Fatal(err)
}
@ -193,7 +193,7 @@ func testJoinMempools(r *Harness, t *testing.T) {
// Create a local test harness with only the genesis block. The nodes
// will be synced below so the same transaction can be sent to both
// nodes without it being an orphan.
harness, err := New(&chaincfg.SimNetParams, nil, nil)
harness, err := New(&chaincfg.RegNetParams, nil, nil)
if err != nil {
t.Fatal(err)
}
@ -296,7 +296,7 @@ func testJoinMempools(r *Harness, t *testing.T) {
func testJoinBlocks(r *Harness, t *testing.T) {
// Create a second harness with only the genesis block so it is behind
// the main harness.
harness, err := New(&chaincfg.SimNetParams, nil, nil)
harness, err := New(&chaincfg.RegNetParams, nil, nil)
if err != nil {
t.Fatal(err)
}
@ -343,7 +343,7 @@ func testJoinBlocks(r *Harness, t *testing.T) {
func testMemWalletReorg(r *Harness, t *testing.T) {
// Create a fresh harness, we'll be using the main harness to force a
// re-org on this local harness.
harness, err := New(&chaincfg.SimNetParams, nil, nil)
harness, err := New(&chaincfg.RegNetParams, nil, nil)
if err != nil {
t.Fatal(err)
}
@ -434,7 +434,7 @@ var mainHarness *Harness
func TestMain(m *testing.M) {
var err error
mainHarness, err = New(&chaincfg.SimNetParams, nil, nil)
mainHarness, err = New(&chaincfg.RegNetParams, nil, nil)
if err != nil {
fmt.Println("unable to create main harness: ", err)
os.Exit(1)

View File

@ -1,13 +1,13 @@
module github.com/decred/dcrd/txscript
require (
github.com/decred/dcrd/chaincfg v1.1.1
github.com/decred/dcrd/chaincfg v1.2.0
github.com/decred/dcrd/chaincfg/chainhash v1.0.1
github.com/decred/dcrd/dcrec v0.0.0-20180721031028-5369a485acf6
github.com/decred/dcrd/dcrec/edwards v0.0.0-20180721031028-5369a485acf6
github.com/decred/dcrd/dcrec/secp256k1 v1.0.0
github.com/decred/dcrd/dcrutil v1.1.1
github.com/decred/dcrd/wire v1.1.0
github.com/decred/dcrd/wire v1.2.0
github.com/decred/slog v1.0.0
golang.org/x/crypto v0.0.0-20180718160520-a2144134853f
)

View File

@ -22,7 +22,7 @@ import (
// testingParams defines the chain params to use throughout these tests so it
// can more easily be changed if desired.
var testingParams = &chaincfg.SimNetParams
var testingParams = &chaincfg.RegNetParams
const testValueIn = 12345

View File

@ -501,7 +501,7 @@ func (b *bogusAddress) DSA(chainParams *chaincfg.Params) dcrec.SignatureType {
// Net returns the network for the bogus address. It exists to satisfy the
// dcrutil.Address interface.
func (b *bogusAddress) Net() *chaincfg.Params {
return &chaincfg.SimNetParams
return &chaincfg.RegNetParams
}
// TestPayToAddrScript ensures the PayToAddrScript function generates the