mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-13 23:43:47 +00:00
fix testcases
This commit is contained in:
parent
9662dc7d6e
commit
a7c11d51a0
3 changed files with 25 additions and 7 deletions
|
|
@ -603,7 +603,8 @@ func (c *BorConfig) calculateBorConfigHelper(field map[string]uint64, number uin
|
||||||
for i := 0; i < len(keys)-1; i++ {
|
for i := 0; i < len(keys)-1; i++ {
|
||||||
valUint, _ := strconv.ParseUint(keys[i], 10, 64)
|
valUint, _ := strconv.ParseUint(keys[i], 10, 64)
|
||||||
valUintNext, _ := strconv.ParseUint(keys[i+1], 10, 64)
|
valUintNext, _ := strconv.ParseUint(keys[i+1], 10, 64)
|
||||||
if number > valUint && number < valUintNext {
|
|
||||||
|
if number >= valUint && number < valUintNext {
|
||||||
return field[keys[i]]
|
return field[keys[i]]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,12 +31,17 @@ func TestBorFilters(t *testing.T) {
|
||||||
hash2 = common.BytesToHash([]byte("topic2"))
|
hash2 = common.BytesToHash([]byte("topic2"))
|
||||||
hash3 = common.BytesToHash([]byte("topic3"))
|
hash3 = common.BytesToHash([]byte("topic3"))
|
||||||
hash4 = common.BytesToHash([]byte("topic4"))
|
hash4 = common.BytesToHash([]byte("topic4"))
|
||||||
|
hash5 = common.BytesToHash([]byte("topic5"))
|
||||||
)
|
)
|
||||||
|
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
genesis := core.GenesisBlockForTesting(db, addr, big.NewInt(1000000))
|
genesis := core.GenesisBlockForTesting(db, addr, big.NewInt(1000000))
|
||||||
testBorConfig := params.TestChainConfig.Bor
|
testBorConfig := params.TestChainConfig.Bor
|
||||||
|
testBorConfig.Sprint = map[string]uint64{
|
||||||
|
"0": 4,
|
||||||
|
"8": 2,
|
||||||
|
}
|
||||||
|
|
||||||
chain, receipts := core.GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 1000, func(i int, gen *core.BlockGen) {
|
chain, receipts := core.GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 1000, func(i int, gen *core.BlockGen) {
|
||||||
switch i {
|
switch i {
|
||||||
|
|
@ -73,7 +78,7 @@ func TestBorFilters(t *testing.T) {
|
||||||
gen.AddUncheckedReceipt(receipt)
|
gen.AddUncheckedReceipt(receipt)
|
||||||
gen.AddUncheckedTx(types.NewTransaction(992, common.HexToAddress("0x992"), big.NewInt(992), 992, gen.BaseFee(), nil))
|
gen.AddUncheckedTx(types.NewTransaction(992, common.HexToAddress("0x992"), big.NewInt(992), 992, gen.BaseFee(), nil))
|
||||||
|
|
||||||
case 999: //state-sync tx at block 1000
|
case 993: //state-sync tx at block 994
|
||||||
receipt := types.NewReceipt(nil, false, 0)
|
receipt := types.NewReceipt(nil, false, 0)
|
||||||
receipt.Logs = []*types.Log{
|
receipt.Logs = []*types.Log{
|
||||||
{
|
{
|
||||||
|
|
@ -82,6 +87,17 @@ func TestBorFilters(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
gen.AddUncheckedReceipt(receipt)
|
gen.AddUncheckedReceipt(receipt)
|
||||||
|
gen.AddUncheckedTx(types.NewTransaction(994, common.HexToAddress("0x994"), big.NewInt(994), 994, gen.BaseFee(), nil))
|
||||||
|
|
||||||
|
case 999: //state-sync tx at block 1000
|
||||||
|
receipt := types.NewReceipt(nil, false, 0)
|
||||||
|
receipt.Logs = []*types.Log{
|
||||||
|
{
|
||||||
|
Address: addr,
|
||||||
|
Topics: []common.Hash{hash5},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
gen.AddUncheckedReceipt(receipt)
|
||||||
gen.AddUncheckedTx(types.NewTransaction(1000, common.HexToAddress("0x1000"), big.NewInt(1000), 1000, gen.BaseFee(), nil))
|
gen.AddUncheckedTx(types.NewTransaction(1000, common.HexToAddress("0x1000"), big.NewInt(1000), 1000, gen.BaseFee(), nil))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -122,11 +138,11 @@ func TestBorFilters(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
filter := filters.NewBorBlockLogsRangeFilter(backend, testBorConfig, 0, -1, []common.Address{addr}, [][]common.Hash{{hash1, hash2, hash3, hash4}})
|
filter := filters.NewBorBlockLogsRangeFilter(backend, testBorConfig, 0, -1, []common.Address{addr}, [][]common.Hash{{hash1, hash2, hash3, hash4, hash5}})
|
||||||
|
|
||||||
logs, _ := filter.Logs(context.Background())
|
logs, _ := filter.Logs(context.Background())
|
||||||
if len(logs) != 4 {
|
if len(logs) != 5 {
|
||||||
t.Error("expected 4 log, got", len(logs))
|
t.Error("expected 5 log, got", len(logs))
|
||||||
}
|
}
|
||||||
|
|
||||||
filter = filters.NewBorBlockLogsRangeFilter(backend, testBorConfig, 900, 999, []common.Address{addr}, [][]common.Hash{{hash3}})
|
filter = filters.NewBorBlockLogsRangeFilter(backend, testBorConfig, 900, 999, []common.Address{addr}, [][]common.Hash{{hash3}})
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,8 @@ func TestSprintLengths(t *testing.T) {
|
||||||
"0": 16,
|
"0": 16,
|
||||||
"8": 4,
|
"8": 4,
|
||||||
}
|
}
|
||||||
assert.Equal(t, testBorConfig.CalculateSprint(0), 16)
|
assert.Equal(t, testBorConfig.CalculateSprint(0), uint64(16))
|
||||||
assert.Equal(t, testBorConfig.CalculateSprint(9), 4)
|
assert.Equal(t, testBorConfig.CalculateSprint(8), uint64(4))
|
||||||
|
assert.Equal(t, testBorConfig.CalculateSprint(9), uint64(4))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue