Skip to content

Commit

Permalink
fix : testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
0xsharma committed Jan 10, 2024
1 parent 8c088c7 commit c0bf289
Show file tree
Hide file tree
Showing 43 changed files with 199 additions and 223 deletions.
2 changes: 1 addition & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ var defaultCacheConfig = &CacheConfig{
TrieTimeLimit: 5 * time.Minute,
SnapshotLimit: 256,
SnapshotWait: true,
TriesInMemory: 1024,
TriesInMemory: 128,
StateScheme: rawdb.HashScheme,
}

Expand Down
18 changes: 13 additions & 5 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ func testBlockChainImport(chain types.Blocks, blockchain *BlockChain) error {
}

func TestParallelBlockChainImport(t *testing.T) {
t.Parallel()

testParallelBlockChainImport(t, rawdb.HashScheme)
testParallelBlockChainImport(t, rawdb.PathScheme)
}

func testParallelBlockChainImport(t *testing.T, scheme string) {
t.Parallel()

db, _, blockchain, err := newCanonical(ethash.NewFaker(), 10, true, scheme)
blockchain.parallelProcessor = NewParallelStateProcessor(blockchain.chainConfig, blockchain, blockchain.engine)

Expand Down Expand Up @@ -3321,18 +3321,26 @@ func testSideImportPrunedBlocks(t *testing.T, scheme string) {
if n, err := chain.InsertChain(blocks); err != nil {
t.Fatalf("block %d: failed to insert into chain: %v", n, err)
}
states := int(chain.cacheConfig.TriesInMemory) + 1

// In path-based trie database implementation, it will keep 128 diff + 1 disk
// layers, totally 129 latest states available. In hash-based it's 128.
states := int(defaultCacheConfig.TriesInMemory)
if scheme == rawdb.PathScheme {
states = int(defaultCacheConfig.TriesInMemory) + 1
}

lastPrunedIndex := len(blocks) - states - 1
lastPrunedBlock := blocks[lastPrunedIndex]

// Verify pruning of lastPrunedBlock
t.Errorf("Block %d not pruned", lastPrunedBlock.NumberU64())
if chain.HasBlockAndState(lastPrunedBlock.Hash(), lastPrunedBlock.NumberU64()) {
t.Errorf("Block %d not pruned", lastPrunedBlock.NumberU64())
}

firstNonPrunedBlock := blocks[len(blocks)-states]
// Verify firstNonPrunedBlock is not pruned
if !chain.HasBlockAndState(firstNonPrunedBlock.Hash(), firstNonPrunedBlock.NumberU64()) {
t.Errorf("Block %d pruned", firstNonPrunedBlock.NumberU64())
t.Errorf("Block %d pruned, scheme : %s", firstNonPrunedBlock.NumberU64(), scheme)
}
// Now re-import some old blocks
blockToReimport := blocks[5:8]
Expand Down
55 changes: 28 additions & 27 deletions core/chain_makers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ func TestGeneratePOSChain(t *testing.T) {
config.TerminalTotalDifficultyPassed = true
config.TerminalTotalDifficulty = common.Big0
config.ShanghaiBlock = common.Big0
gspec.Config.CancunBlock = common.Big0
gspec.Config.PragueBlock = common.Big0
gspec.Config.VerkleBlock = common.Big0
config.CancunBlock = common.Big0
config.PragueBlock = common.Big0
config.VerkleBlock = common.Big0

// init 0xaa with some storage elements
storage := make(map[common.Hash]common.Hash)
Expand Down Expand Up @@ -98,32 +98,33 @@ func TestGeneratePOSChain(t *testing.T) {
})
gen.AddTx(tx)

// Withdrawls disabled in bor
// Add withdrawals.
if i == 1 {
gen.AddWithdrawal(&types.Withdrawal{
Validator: 42,
Address: common.Address{0xee},
Amount: 1337,
})
gen.AddWithdrawal(&types.Withdrawal{
Validator: 13,
Address: common.Address{0xee},
Amount: 1,
})
}
// if i == 1 {
// gen.AddWithdrawal(&types.Withdrawal{
// Validator: 42,
// Address: common.Address{0xee},
// Amount: 1337,
// })
// gen.AddWithdrawal(&types.Withdrawal{
// Validator: 13,
// Address: common.Address{0xee},
// Amount: 1,
// })
// }

if i == 3 {
gen.AddWithdrawal(&types.Withdrawal{
Validator: 42,
Address: common.Address{0xee},
Amount: 1337,
})
gen.AddWithdrawal(&types.Withdrawal{
Validator: 13,
Address: common.Address{0xee},
Amount: 1,
})
}
// if i == 3 {
// gen.AddWithdrawal(&types.Withdrawal{
// Validator: 42,
// Address: common.Address{0xee},
// Amount: 1337,
// })
// gen.AddWithdrawal(&types.Withdrawal{
// Validator: 13,
// Address: common.Address{0xee},
// Amount: 1,
// })
// }
})

// Import the chain. This runs all block validation rules.
Expand Down
1 change: 1 addition & 0 deletions core/forkid/forkid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ func TestEncoding(t *testing.T) {
// Tests that time-based forks which are active at genesis are not included in
// forkid hash.
func TestTimeBasedForkInGenesis(t *testing.T) {
t.Skip("This test is not valid in bor since bor has block based hardforks")
var (
time = uint64(1690475657)
genesis = types.NewBlockWithHeader(&types.Header{Time: time})
Expand Down
16 changes: 3 additions & 13 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,23 +492,13 @@ func (g *Genesis) ToBlock() *types.Block {
if conf := g.Config; conf != nil {
num := big.NewInt(int64(g.Number))
if conf.IsShanghai(num) {
head.WithdrawalsHash = nil
head.WithdrawalsHash = &types.EmptyWithdrawalsHash
withdrawals = nil
}
if conf.IsCancun(num) {
// EIP-4788: The parentBeaconBlockRoot of the genesis block is always
// the zero hash. This is because the genesis block does not have a parent
// by definition.
head.ParentBeaconRoot = new(common.Hash)
// EIP-4844 fields
head.ExcessBlobGas = g.ExcessBlobGas
head.BlobGasUsed = g.BlobGasUsed
if head.ExcessBlobGas == nil {
head.ExcessBlobGas = new(uint64)
}
if head.BlobGasUsed == nil {
head.BlobGasUsed = new(uint64)
}
head.ExcessBlobGas = nil
head.BlobGasUsed = nil
}
}

Expand Down
2 changes: 0 additions & 2 deletions core/txpool/legacypool/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ func (m *sortedMap) Len() int {
}

func (m *sortedMap) flatten() types.Transactions {
m.cacheMu.Lock()
defer m.cacheMu.Unlock()
// If the sorting was not cached yet, create and cache it
m.cacheMu.Lock()
defer m.cacheMu.Unlock()
Expand Down
2 changes: 2 additions & 0 deletions eth/catalyst/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,8 @@ func TestBlockToPayloadWithBlobs(t *testing.T) {

// This checks that beaconRoot is applied to the state from the engine API.
func TestParentBeaconBlockRoot(t *testing.T) {
t.Skip("This test is not compatible with bor")

log.Root().SetHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(colorable.NewColorableStderr(), log.TerminalFormat(true))))

genesis, blocks := generateMergeChain(10, true)
Expand Down
2 changes: 2 additions & 0 deletions eth/filters/filter_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@ func TestInvalidGetRangeLogsRequest(t *testing.T) {
api = NewFilterAPI(sys, false, true)
)

api.SetChainConfig(params.BorTestChainConfig)

if _, err := api.GetLogs(context.Background(), FilterCriteria{FromBlock: big.NewInt(2), ToBlock: big.NewInt(1)}); err != errInvalidBlockRange {
t.Errorf("Expected Logs for invalid range return error, but got: %v", err)
}
Expand Down
Loading

0 comments on commit c0bf289

Please sign in to comment.