From a7c11d51a0f7bf1a24b99ca5ad131cbc95850d5e Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Thu, 22 Sep 2022 21:47:29 +0530 Subject: [PATCH] fix testcases --- params/config.go | 3 ++- tests/bor/bor_filter_test.go | 24 ++++++++++++++++++---- tests/bor/bor_sprint_length_change_test.go | 5 +++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/params/config.go b/params/config.go index 13e3565f9d..6233d10381 100644 --- a/params/config.go +++ b/params/config.go @@ -603,7 +603,8 @@ func (c *BorConfig) calculateBorConfigHelper(field map[string]uint64, number uin for i := 0; i < len(keys)-1; i++ { valUint, _ := strconv.ParseUint(keys[i], 10, 64) valUintNext, _ := strconv.ParseUint(keys[i+1], 10, 64) - if number > valUint && number < valUintNext { + + if number >= valUint && number < valUintNext { return field[keys[i]] } } diff --git a/tests/bor/bor_filter_test.go b/tests/bor/bor_filter_test.go index 8b7213a50b..8a22d99a44 100644 --- a/tests/bor/bor_filter_test.go +++ b/tests/bor/bor_filter_test.go @@ -31,12 +31,17 @@ func TestBorFilters(t *testing.T) { hash2 = common.BytesToHash([]byte("topic2")) hash3 = common.BytesToHash([]byte("topic3")) hash4 = common.BytesToHash([]byte("topic4")) + hash5 = common.BytesToHash([]byte("topic5")) ) defer db.Close() genesis := core.GenesisBlockForTesting(db, addr, big.NewInt(1000000)) 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) { switch i { @@ -73,7 +78,7 @@ func TestBorFilters(t *testing.T) { gen.AddUncheckedReceipt(receipt) 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.Logs = []*types.Log{ { @@ -82,6 +87,17 @@ func TestBorFilters(t *testing.T) { }, } 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)) } }) @@ -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()) - if len(logs) != 4 { - t.Error("expected 4 log, got", len(logs)) + if len(logs) != 5 { + t.Error("expected 5 log, got", len(logs)) } filter = filters.NewBorBlockLogsRangeFilter(backend, testBorConfig, 900, 999, []common.Address{addr}, [][]common.Hash{{hash3}}) diff --git a/tests/bor/bor_sprint_length_change_test.go b/tests/bor/bor_sprint_length_change_test.go index 6a131eadce..7420fcd285 100644 --- a/tests/bor/bor_sprint_length_change_test.go +++ b/tests/bor/bor_sprint_length_change_test.go @@ -158,7 +158,8 @@ func TestSprintLengths(t *testing.T) { "0": 16, "8": 4, } - assert.Equal(t, testBorConfig.CalculateSprint(0), 16) - assert.Equal(t, testBorConfig.CalculateSprint(9), 4) + assert.Equal(t, testBorConfig.CalculateSprint(0), uint64(16)) + assert.Equal(t, testBorConfig.CalculateSprint(8), uint64(4)) + assert.Equal(t, testBorConfig.CalculateSprint(9), uint64(4)) }