Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trinhdn2 committed Jul 18, 2023
1 parent 327c90d commit 4d22f8d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions core/bench_test.go
Expand Up @@ -18,7 +18,6 @@ package core

import (
"crypto/ecdsa"
"github.com/tomochain/tomochain/core/rawdb"
"io/ioutil"
"math/big"
"os"
Expand All @@ -27,6 +26,7 @@ import (
"github.com/tomochain/tomochain/common"
"github.com/tomochain/tomochain/common/math"
"github.com/tomochain/tomochain/consensus/ethash"
"github.com/tomochain/tomochain/core/rawdb"
"github.com/tomochain/tomochain/core/types"
"github.com/tomochain/tomochain/core/vm"
"github.com/tomochain/tomochain/crypto"
Expand Down Expand Up @@ -238,10 +238,16 @@ func makeChainForBench(db ethdb.Database, full bool, count uint64) {
WriteHeader(db, header)
WriteCanonicalHash(db, hash, n)
WriteTd(db, hash, n, big.NewInt(int64(n+1)))
if n == 0 {
WriteChainConfig(db, hash, params.AllEthashProtocolChanges)
}
WriteHeadHeaderHash(db, hash)

if full || n == 0 {
block := types.NewBlockWithHeader(header)
WriteBody(db, hash, n, block.Body())
WriteBlockReceipts(db, hash, n, nil)
WriteHeadBlockHash(db, hash)
}
}
}
Expand Down Expand Up @@ -275,6 +281,8 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
}
makeChainForBench(db, full, count)
db.Close()
cacheConfig := defaultCacheConfig
cacheConfig.Disabled = true

b.ReportAllocs()
b.ResetTimer()
Expand All @@ -284,7 +292,7 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
if err != nil {
b.Fatalf("error opening database at %v: %v", dir, err)
}
chain, err := NewBlockChain(db, nil, params.TestChainConfig, ethash.NewFaker(), vm.Config{})
chain, err := NewBlockChain(db, cacheConfig, params.TestChainConfig, ethash.NewFaker(), vm.Config{})
if err != nil {
b.Fatalf("error creating chain: %v", err)
}
Expand Down
8 changes: 8 additions & 0 deletions core/blockchain.go
Expand Up @@ -82,6 +82,14 @@ type CacheConfig struct {
TrieNodeLimit int // Memory limit (MB) at which to flush the current in-memory trie to disk
TrieTimeLimit time.Duration // Time limit after which to flush the current in-memory trie to disk
}

// defaultCacheConfig are the default caching values if none are specified by the
// user (also used during testing).
var defaultCacheConfig = &CacheConfig{
TrieNodeLimit: 256,
TrieTimeLimit: 5 * time.Minute,
}

type ResultProcessBlock struct {
logs []*types.Log
receipts []*types.Receipt
Expand Down

0 comments on commit 4d22f8d

Please sign in to comment.