Skip to content

Commit 4dd8db9

Browse files
committed
made all current tests work, fixed cpuminer
1 parent 19057d2 commit 4dd8db9

12 files changed

Lines changed: 120 additions & 36 deletions

File tree

blockchain/fullblocktests/generate.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,8 @@ func solveBlock(header *wire.BlockHeader) bool {
342342
return
343343
default:
344344
hdr.Nonce = i
345-
hash := hdr.BlockHash()
346-
if blockchain.HashToBig(&hash).Cmp(
347-
targetDifficulty) <= 0 {
348-
345+
hash := hdr.BlockPoWHash()
346+
if blockchain.HashToBig(&hash).Cmp(targetDifficulty) <= 0 {
349347
results <- sbResult{true, i}
350348
return
351349
}
@@ -1444,7 +1442,7 @@ func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error) {
14441442
// Keep incrementing the nonce until the hash treated as
14451443
// a uint256 is higher than the limit.
14461444
b46.Header.Nonce++
1447-
blockHash := b46.BlockHash()
1445+
blockHash := b46.Header.BlockPoWHash()
14481446
hashNum := blockchain.HashToBig(&blockHash)
14491447
if hashNum.Cmp(g.params.PowLimit) >= 0 {
14501448
break

btcjson/chainsvrresults.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type GetBlockHeaderVerboseResult struct {
2525
Version int32 `json:"version"`
2626
VersionHex string `json:"versionHex"`
2727
MerkleRoot string `json:"merkleroot"`
28-
ClaimTrie string `json:"claimtrie,omitempty"`
28+
ClaimTrie string `json:"nameclaimroot,omitempty"`
2929
Time int64 `json:"time"`
3030
Nonce uint64 `json:"nonce"`
3131
Bits string `json:"bits"`
@@ -83,7 +83,7 @@ type GetBlockVerboseResultBase struct {
8383
PreviousHash string `json:"previousblockhash,omitempty"`
8484
NextHash string `json:"nextblockhash,omitempty"`
8585

86-
ClaimTrie string `json:"claimTrie,omitempty"`
86+
ClaimTrie string `json:"nameclaimroot,omitempty"`
8787
TxCount int `json:"nTx"` // For backwards compatibility only
8888
}
8989

btcjson/help.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,12 @@ func GenerateHelp(method string, descs map[string]string, resultTypes ...interfa
547547
return desc
548548
}
549549

550+
if strings.Contains(key, "base-") {
551+
if desc, ok := descs[strings.ReplaceAll(key, "base-", "-")]; ok {
552+
return desc
553+
}
554+
}
555+
550556
missingKey = key
551557
return key
552558
}

claimtrie/claimtrie_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ func TestFixedHashes(t *testing.T) {
7070
r.Equal(expected[:], ct.MerkleHash()[:])
7171
}
7272

73+
func TestEmptyHashFork(t *testing.T) {
74+
r := require.New(t)
75+
76+
setup(t)
77+
param.ActiveParams.AllClaimsInMerkleForkHeight = 2
78+
ct, err := New(cfg)
79+
r.NoError(err)
80+
r.NotNil(ct)
81+
defer ct.Close()
82+
83+
for i := 0; i < 5; i++ {
84+
err := ct.AppendBlock()
85+
r.NoError(err)
86+
}
87+
}
88+
7389
func TestNormalizationFork(t *testing.T) {
7490
r := require.New(t)
7591

claimtrie/merkletrie/ramtrie.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func NewRamTrie() *RamTrie {
3030
return new(bytes.Buffer)
3131
},
3232
},
33-
collapsedTrie: collapsedTrie{Root: &collapsedVertex{}},
33+
collapsedTrie: collapsedTrie{Root: &collapsedVertex{merkleHash: EmptyTrieHash}},
3434
}
3535
}
3636

integration/bip0009_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func assertSoftForkStatus(r *rpctest.Harness, t *testing.T, forkKey string, stat
130130
// specific soft fork deployment to test.
131131
func testBIP0009(t *testing.T, forkKey string, deploymentID uint32) {
132132
// Initialize the primary mining node with only the genesis block.
133-
r, err := rpctest.New(&chaincfg.RegressionNetParams, nil, nil, "")
133+
r, err := rpctest.New(&chaincfg.SimNetParams, nil, nil, "")
134134
if err != nil {
135135
t.Fatalf("unable to create primary harness: %v", err)
136136
}
@@ -321,7 +321,7 @@ func TestBIP0009Mining(t *testing.T) {
321321
t.Parallel()
322322

323323
// Initialize the primary mining node with only the genesis block.
324-
r, err := rpctest.New(&chaincfg.SimNetParams, nil, nil, "")
324+
r, err := rpctest.New(&chaincfg.RegressionNetParams, nil, nil, "")
325325
if err != nil {
326326
t.Fatalf("unable to create primary harness: %v", err)
327327
}

integration/csv_fork_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,17 @@ func TestBIP0113Activation(t *testing.T) {
110110
t.Parallel()
111111

112112
btcdCfg := []string{"--rejectnonstd"}
113-
r, err := rpctest.New(&chaincfg.RegressionNetParams, nil, btcdCfg, "")
113+
r, err := rpctest.New(&chaincfg.SimNetParams, nil, btcdCfg, "")
114114
if err != nil {
115115
t.Fatal("unable to create primary harness: ", err)
116116
}
117-
if err := r.SetUp(true, 110); err != nil {
117+
if err := r.SetUp(true, 10); err != nil {
118118
t.Fatalf("unable to setup test chain: %v", err)
119119
}
120120
defer r.TearDown()
121121

122122
// Create a fresh output for usage within the test below.
123-
const outputValue = btcutil.SatoshiPerBitcoin
123+
const outputValue = btcutil.SatoshiPerBitcoin / 50
124124
outputKey, testOutput, testPkScript, err := makeTestOutput(r, t,
125125
outputValue)
126126
if err != nil {
@@ -190,7 +190,7 @@ func TestBIP0113Activation(t *testing.T) {
190190
// to create a single mature output, then an additional block to create
191191
// a new output, and then mined a single block above to include our
192192
// transaction.
193-
assertChainHeight(r, t, 103)
193+
assertChainHeight(r, t, 112)
194194

195195
// Next, mine enough blocks to ensure that the soft-fork becomes
196196
// activated. Assert that the block version of the second-to-last block
@@ -206,7 +206,7 @@ func TestBIP0113Activation(t *testing.T) {
206206
t.Fatalf("unable to generate blocks: %v", err)
207207
}
208208

209-
assertChainHeight(r, t, 299)
209+
assertChainHeight(r, t, 308)
210210
assertSoftForkStatus(r, t, csvKey, blockchain.ThresholdActive)
211211

212212
// The timeLockDeltas slice represents a series of deviations from the
@@ -427,7 +427,7 @@ func TestBIP0068AndBIP0112Activation(t *testing.T) {
427427
}
428428

429429
const (
430-
outputAmt = btcutil.SatoshiPerBitcoin
430+
outputAmt = btcutil.SatoshiPerBitcoin / 50
431431
relativeBlockLock = 10
432432
)
433433

integration/rpctest/blockgen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func solveBlock(header *wire.BlockHeader, targetDifficulty *big.Int) bool {
4444
return
4545
default:
4646
hdr.Nonce = i
47-
hash := hdr.BlockHash()
47+
hash := hdr.BlockPoWHash()
4848
if blockchain.HashToBig(&hash).Cmp(targetDifficulty) <= 0 {
4949
select {
5050
case results <- sbResult{true, i}:

integration/rpctest/rpc_harness_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func testSendOutputs(r *Harness, t *testing.T) {
6464

6565
// First, generate a small spend which will require only a single
6666
// input.
67-
txid := genSpend(btcutil.Amount(5 * btcutil.SatoshiPerBitcoin))
67+
txid := genSpend(btcutil.Amount(btcutil.SatoshiPerBitcoin))
6868

6969
// Generate a single block, the transaction the wallet created should
7070
// be found in this block.
@@ -76,7 +76,7 @@ func testSendOutputs(r *Harness, t *testing.T) {
7676

7777
// Next, generate a spend much greater than the block reward. This
7878
// transaction should also have been mined properly.
79-
txid = genSpend(btcutil.Amount(500 * btcutil.SatoshiPerBitcoin))
79+
txid = genSpend(btcutil.Amount(10 * btcutil.SatoshiPerBitcoin))
8080
blockHashes, err = r.Client.Generate(1)
8181
if err != nil {
8282
t.Fatalf("unable to generate single block: %v", err)
@@ -154,7 +154,7 @@ func testActiveHarnesses(r *Harness, t *testing.T) {
154154
numInitialHarnesses := len(ActiveHarnesses())
155155

156156
// Create a single test harness.
157-
harness1, err := New(&chaincfg.SimNetParams, nil, nil, "")
157+
harness1, err := New(&chaincfg.RegressionNetParams, nil, nil, "")
158158
if err != nil {
159159
t.Fatal(err)
160160
}
@@ -182,7 +182,7 @@ func testJoinMempools(r *Harness, t *testing.T) {
182182
// Create a local test harness with only the genesis block. The nodes
183183
// will be synced below so the same transaction can be sent to both
184184
// nodes without it being an orphan.
185-
harness, err := New(&chaincfg.SimNetParams, nil, nil, "")
185+
harness, err := New(&chaincfg.RegressionNetParams, nil, nil, "")
186186
if err != nil {
187187
t.Fatal(err)
188188
}
@@ -282,7 +282,7 @@ func testJoinMempools(r *Harness, t *testing.T) {
282282
func testJoinBlocks(r *Harness, t *testing.T) {
283283
// Create a second harness with only the genesis block so it is behind
284284
// the main harness.
285-
harness, err := New(&chaincfg.SimNetParams, nil, nil, "")
285+
harness, err := New(&chaincfg.RegressionNetParams, nil, nil, "")
286286
if err != nil {
287287
t.Fatal(err)
288288
}
@@ -336,7 +336,7 @@ func testGenerateAndSubmitBlock(r *Harness, t *testing.T) {
336336
if err != nil {
337337
t.Fatalf("unable to create script: %v", err)
338338
}
339-
output := wire.NewTxOut(btcutil.SatoshiPerBitcoin, pkScript)
339+
output := wire.NewTxOut(btcutil.SatoshiPerBitcoin/50, pkScript)
340340

341341
const numTxns = 5
342342
txns := make([]*btcutil.Tx, 0, numTxns)
@@ -470,7 +470,7 @@ func testGenerateAndSubmitBlockWithCustomCoinbaseOutputs(r *Harness,
470470
func testMemWalletReorg(r *Harness, t *testing.T) {
471471
// Create a fresh harness, we'll be using the main harness to force a
472472
// re-org on this local harness.
473-
harness, err := New(&chaincfg.SimNetParams, nil, nil, "")
473+
harness, err := New(&chaincfg.RegressionNetParams, nil, nil, "")
474474
if err != nil {
475475
t.Fatal(err)
476476
}
@@ -479,8 +479,8 @@ func testMemWalletReorg(r *Harness, t *testing.T) {
479479
}
480480
defer harness.TearDown()
481481

482-
// The internal wallet of this harness should now have 250 BTC.
483-
expectedBalance := btcutil.Amount(250 * btcutil.SatoshiPerBitcoin)
482+
// The internal wallet of this harness should now have 250 BTC, but BTC is 50x LBC per generated coin.
483+
expectedBalance := btcutil.Amount(5 * btcutil.SatoshiPerBitcoin)
484484
walletBalance := harness.ConfirmedBalance()
485485
if expectedBalance != walletBalance {
486486
t.Fatalf("wallet balance incorrect: expected %v, got %v",
@@ -521,7 +521,7 @@ func testMemWalletLockedOutputs(r *Harness, t *testing.T) {
521521
if err != nil {
522522
t.Fatalf("unable to create script: %v", err)
523523
}
524-
outputAmt := btcutil.Amount(50 * btcutil.SatoshiPerBitcoin)
524+
outputAmt := btcutil.Amount(btcutil.SatoshiPerBitcoin)
525525
output := wire.NewTxOut(int64(outputAmt), pkScript)
526526
tx, err := r.CreateTransaction([]*wire.TxOut{output}, 10, true)
527527
if err != nil {
@@ -567,7 +567,7 @@ const (
567567

568568
func TestMain(m *testing.M) {
569569
var err error
570-
mainHarness, err = New(&chaincfg.SimNetParams, nil, nil, "")
570+
mainHarness, err = New(&chaincfg.RegressionNetParams, nil, nil, "")
571571
if err != nil {
572572
fmt.Println("unable to create main harness: ", err)
573573
os.Exit(1)

mining/cpuminer/cpuminer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func (m *CPUMiner) solveBlock(msgBlock *wire.MsgBlock, blockHeight int32,
274274
// increment the number of hashes completed for each
275275
// attempt accordingly.
276276
header.Nonce = i
277-
hash := header.BlockHash()
277+
hash := header.BlockPoWHash()
278278
hashesCompleted += 2
279279

280280
// The block is solved when the new block hash is less

0 commit comments

Comments
 (0)