Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth: divide test cases and verify with exact values #4691

Merged
merged 1 commit into from
Jul 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions eth/stagedsync/stage_log_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func genReceipts(t *testing.T, tx kv.RwTx, blocks uint64) (map[common.Address]ui
return expectAddrs, expectTopics
}

func TestLogIndex(t *testing.T) {
require, tmpDir, ctx := require.New(t), t.TempDir(), context.Background()
func TestPromoteLogIndex(t *testing.T) {
require, ctx := require.New(t), context.Background()
_, tx := memdb.NewTestTx(t)

expectAddrs, expectTopics := genReceipts(t, tx, 100)
Expand All @@ -100,6 +100,7 @@ func TestLogIndex(t *testing.T) {
cfgCopy := cfg
cfgCopy.bufLimit = 10
cfgCopy.flushEvery = time.Nanosecond

err := promoteLogIndex("logPrefix", tx, 0, cfgCopy, ctx)
require.NoError(err)

Expand All @@ -114,6 +115,20 @@ func TestLogIndex(t *testing.T) {
require.NoError(err)
require.Equal(expect, m.GetCardinality())
}
}

func TestPruneLogIndex(t *testing.T) {
require, tmpDir, ctx := require.New(t), t.TempDir(), context.Background()
_, tx := memdb.NewTestTx(t)

_, _ = genReceipts(t, tx, 100)

cfg := StageLogIndexCfg(nil, prune.DefaultMode, "")
cfgCopy := cfg
cfgCopy.bufLimit = 10
cfgCopy.flushEvery = time.Nanosecond
err := promoteLogIndex("logPrefix", tx, 0, cfgCopy, ctx)
require.NoError(err)

// Mode test
err = pruneLogIndex("", tx, tmpDir, 50, ctx)
Expand All @@ -122,23 +137,41 @@ func TestLogIndex(t *testing.T) {
{
total := 0
err = tx.ForEach(kv.LogAddressIndex, nil, func(k, v []byte) error {
require.True(binary.BigEndian.Uint32(k[length.Addr:]) >= 50)
require.True(binary.BigEndian.Uint32(k[length.Addr:]) == 4294967295)
total++
return nil
})
require.NoError(err)
require.True(total > 0)
require.True(total == 3)
}
{
total := 0
err = tx.ForEach(kv.LogTopicIndex, nil, func(k, v []byte) error {
require.True(binary.BigEndian.Uint32(k[length.Hash:]) >= 50)
require.True(binary.BigEndian.Uint32(k[length.Hash:]) == 4294967295)
total++
return nil
})
require.NoError(err)
require.True(total > 0)
require.True(total == 3)
}
}

func TestUnwindLogIndex(t *testing.T) {
require, tmpDir, ctx := require.New(t), t.TempDir(), context.Background()
_, tx := memdb.NewTestTx(t)

expectAddrs, expectTopics := genReceipts(t, tx, 100)

cfg := StageLogIndexCfg(nil, prune.DefaultMode, "")
cfgCopy := cfg
cfgCopy.bufLimit = 10
cfgCopy.flushEvery = time.Nanosecond
err := promoteLogIndex("logPrefix", tx, 0, cfgCopy, ctx)
require.NoError(err)

// Mode test
err = pruneLogIndex("", tx, tmpDir, 50, ctx)
require.NoError(err)

// Unwind test
err = unwindLogIndex("logPrefix", tx, 70, cfg, nil)
Expand Down