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

erigon-lib/state: parallel tests #12046

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions erigon-lib/commitment/commitment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func generateCellRow(tb testing.TB, size int) (row []*cell, bitmap uint16) {
}

func TestBranchData_MergeHexBranches2(t *testing.T) {
t.Parallel()
row, bm := generateCellRow(t, 16)

be := NewBranchEncoder(1024, t.TempDir())
Expand Down Expand Up @@ -102,6 +103,8 @@ func TestBranchData_MergeHexBranches2(t *testing.T) {
}

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

// Create a BranchMerger instance with sufficient capacity for testing.
merger := NewHexBranchMerger(1024)

Expand All @@ -123,6 +126,8 @@ func TestBranchData_MergeHexBranchesEmptyBranches(t *testing.T) {
// Additional tests for error cases, edge cases, and other scenarios can be added here.

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

encs := "0405040b04080f0b080d030204050b0502090805050d01060e060d070f0903090c04070a0d0a000e090b060b0c040c0700020e0b0c060b0106020c0607050a0b0209070d06040808"
enc, err := hex.DecodeString(encs)
require.NoError(t, err)
Expand Down Expand Up @@ -159,6 +164,8 @@ func unfoldBranchDataFromString(tb testing.TB, encs string) (row []*cell, am uin
}

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

row, bm := generateCellRow(t, 16)

cells, am := unfoldBranchDataFromString(t, "86e586e5082035e72a782b51d9c98548467e3f868294d923cdbbdf4ce326c867bd972c4a2395090109203b51781a76dc87640aea038e3fdd8adca94049aaa436735b162881ec159f6fb408201aa2fa41b5fb019e8abf8fc32800805a2743cfa15373cf64ba16f4f70e683d8e0404a192d9050404f993d9050404e594d90508208642542ff3ce7d63b9703e85eb924ab3071aa39c25b1651c6dda4216387478f10404bd96d905")
Expand Down Expand Up @@ -224,6 +231,8 @@ func TestBranchData_ReplacePlainKeys(t *testing.T) {
}

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

row, bm := generateCellRow(t, 16)

cg := func(nibble int, skip bool) (*cell, error) {
Expand Down Expand Up @@ -271,6 +280,8 @@ func TestBranchData_ReplacePlainKeys_WithEmpty(t *testing.T) {
}

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

t.Run("ModeUpdate", func(t *testing.T) {
ut := NewUpdates(ModeUpdate, t.TempDir(), keyHasherNoop)

Expand All @@ -291,6 +302,8 @@ func TestNewUpdates(t *testing.T) {
}

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

utUpdate := NewUpdates(ModeUpdate, t.TempDir(), keyHasherNoop)
utDirect := NewUpdates(ModeDirect, t.TempDir(), keyHasherNoop)

Expand Down
28 changes: 28 additions & 0 deletions erigon-lib/commitment/hex_patricia_hashed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
)

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

ctx := context.Background()
ms := NewMockState(t)
hph := NewHexPatriciaHashed(1, ms, ms.TempDir())
Expand Down Expand Up @@ -100,6 +102,8 @@ func Test_HexPatriciaHashed_ResetThenSingularUpdates(t *testing.T) {
}

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

ms := NewMockState(t)
ctx := context.Background()
hph := NewHexPatriciaHashed(1, ms, ms.TempDir())
Expand Down Expand Up @@ -143,6 +147,8 @@ func Test_HexPatriciaHashed_EmptyUpdate(t *testing.T) {
}

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

msOne := NewMockState(t)
msTwo := NewMockState(t)
ctx := context.Background()
Expand Down Expand Up @@ -260,6 +266,8 @@ func sortUpdatesByHashIncrease(t *testing.T, hph *HexPatriciaHashed, plainKeys [
}

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

ctx := context.Background()

uniqTest := func(t *testing.T, sortHashedKeys bool, trace bool) {
Expand Down Expand Up @@ -416,6 +424,8 @@ func Test_HexPatriciaHashed_UniqueRepresentation(t *testing.T) {
}

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

state := NewMockState(t)
ctx := context.Background()

Expand Down Expand Up @@ -480,6 +490,8 @@ func Test_HexPatriciaHashed_Sepolia(t *testing.T) {
}

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

rnd := rand.New(rand.NewSource(time.Now().UnixMilli()))
first := &cell{
hashLen: length.Hash,
Expand Down Expand Up @@ -520,6 +532,8 @@ func Test_Cell_EncodeDecode(t *testing.T) {
}

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

//trie := NewHexPatriciaHashed(length.Hash, nil, nil, nil)
var s state
s.Root = make([]byte, 128)
Expand Down Expand Up @@ -566,6 +580,8 @@ func Test_HexPatriciaHashed_StateEncode(t *testing.T) {
}

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

ms := NewMockState(t)
ctx := context.Background()

Expand Down Expand Up @@ -629,6 +645,8 @@ func Test_HexPatriciaHashed_StateEncodeDecodeSetup(t *testing.T) {
}

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

msOne := NewMockState(t)
msTwo := NewMockState(t)
ctx := context.Background()
Expand Down Expand Up @@ -716,6 +734,8 @@ func Test_HexPatriciaHashed_StateRestoreAndContinue(t *testing.T) {
}

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

ctx := context.Background()
ms := NewMockState(t)

Expand Down Expand Up @@ -792,6 +812,8 @@ func Test_HexPatriciaHashed_RestoreAndContinue(t *testing.T) {
}

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

ctx := context.Background()
stateSeq := NewMockState(t)
stateBatch := NewMockState(t)
Expand Down Expand Up @@ -868,6 +890,8 @@ func Test_HexPatriciaHashed_ProcessUpdates_UniqueRepresentation_AfterStateRestor
}

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

ctx := context.Background()
stateSeq := NewMockState(t)
stateBatch := NewMockState(t)
Expand Down Expand Up @@ -974,6 +998,8 @@ func Test_HexPatriciaHashed_ProcessUpdates_UniqueRepresentationInTheMiddle(t *te
}

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

updates := []Update{
{Flags: BalanceUpdate, Balance: *uint256.NewInt(123), CodeHash: [32]byte(EmptyCodeHash)},
{Flags: BalanceUpdate | NonceUpdate, Balance: *uint256.NewInt(45639015), Nonce: 123, CodeHash: [32]byte(EmptyCodeHash)},
Expand Down Expand Up @@ -1052,6 +1078,8 @@ func TestUpdate_Merge(t *testing.T) {
}

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

rnd := rand.New(rand.NewSource(42))

b := uint256.NewInt(rnd.Uint64())
Expand Down
10 changes: 10 additions & 0 deletions erigon-lib/state/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import (
)

func TestAggregatorV3_Merge(t *testing.T) {
t.Parallel()
db, agg := testDbAndAggregatorv3(t, 10)
rwTx, err := db.BeginRwNosync(context.Background())
require.NoError(t, err)
Expand Down Expand Up @@ -169,6 +170,7 @@ func TestAggregatorV3_Merge(t *testing.T) {
}

func TestAggregatorV3_MergeValTransform(t *testing.T) {
t.Parallel()
db, agg := testDbAndAggregatorv3(t, 10)
rwTx, err := db.BeginRwNosync(context.Background())
require.NoError(t, err)
Expand Down Expand Up @@ -258,6 +260,7 @@ func TestAggregatorV3_MergeValTransform(t *testing.T) {
}

func TestAggregatorV3_RestartOnDatadir(t *testing.T) {
t.Parallel()
//t.Skip()
t.Run("BPlus", func(t *testing.T) {
rc := runCfg{
Expand Down Expand Up @@ -416,6 +419,7 @@ func aggregatorV3_RestartOnDatadir(t *testing.T, rc runCfg) {
}

func TestNewBtIndex(t *testing.T) {
t.Parallel()
keyCount := 10000
kvPath := generateKV(t, t.TempDir(), 20, 10, keyCount, log.New(), seg.CompressNone)

Expand All @@ -437,6 +441,7 @@ func TestNewBtIndex(t *testing.T) {
}

func TestAggregatorV3_PruneSmallBatches(t *testing.T) {
t.Parallel()
aggStep := uint64(10)
db, agg := testDbAndAggregatorv3(t, aggStep)

Expand Down Expand Up @@ -755,6 +760,7 @@ func generateSharedDomainsUpdatesForTx(t *testing.T, domains *SharedDomains, txN
}

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

logger := log.New()
aggStep := uint64(100)
Expand Down Expand Up @@ -889,6 +895,7 @@ func TestAggregatorV3_RestartOnFiles(t *testing.T) {
}

func TestAggregatorV3_ReplaceCommittedKeys(t *testing.T) {
t.Parallel()
ctx := context.Background()
aggStep := uint64(500)

Expand Down Expand Up @@ -991,6 +998,7 @@ func TestAggregatorV3_ReplaceCommittedKeys(t *testing.T) {
}

func Test_EncodeCommitmentState(t *testing.T) {
t.Parallel()
cs := commitmentState{
txNum: rand.Uint64(),
trieState: make([]byte, 1024),
Expand Down Expand Up @@ -1148,6 +1156,7 @@ func generateInputData(tb testing.TB, keySize, valueSize, keyCount int) ([][]byt
}

func TestAggregatorV3_SharedDomains(t *testing.T) {
t.Parallel()
db, agg := testDbAndAggregatorv3(t, 20)
ctx := context.Background()

Expand Down Expand Up @@ -1275,6 +1284,7 @@ func TestAggregatorV3_SharedDomains(t *testing.T) {

// also useful to decode given input into v3 account
func Test_helper_decodeAccountv3Bytes(t *testing.T) {
t.Parallel()
input, err := hex.DecodeString("000114000101")
require.NoError(t, err)

Expand Down
12 changes: 12 additions & 0 deletions erigon-lib/state/btree_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
)

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

//mainnet: storage.128-160.kv 110mil keys, 100mb bloomfilter of 0.01 (1%) miss-probability
//no much reason to merge bloomfilter - can merge them on startup
//1B keys: 1Gb
Expand All @@ -51,6 +53,8 @@ func Test_BtreeIndex_Init2(t *testing.T) {

}
func Test_BtreeIndex_Init(t *testing.T) {
t.Parallel()

logger := log.New()
tmp := t.TempDir()

Expand All @@ -70,6 +74,8 @@ func Test_BtreeIndex_Init(t *testing.T) {
}

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

tmp := t.TempDir()
logger := log.New()
keyCount, M := 120, 30
Expand Down Expand Up @@ -152,6 +158,8 @@ func Test_BtreeIndex_Seek(t *testing.T) {
}

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

tmp := t.TempDir()
logger := log.New()
keyCount, M := 20000, 510
Expand Down Expand Up @@ -202,6 +210,8 @@ func buildBtreeIndex(tb testing.TB, dataPath, indexPath string, compressed seg.F
}

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

tmp := t.TempDir()
logger := log.New()
keyCount, M := 1_200_000, 1024
Expand Down Expand Up @@ -271,6 +281,8 @@ func Test_BtreeIndex_Seek2(t *testing.T) {
}

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

keyCount, M := 48, 4
tmp := t.TempDir()

Expand Down
8 changes: 8 additions & 0 deletions erigon-lib/state/domain_shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import (
)

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

stepSize := uint64(100)
db, agg := testDbAndAggregatorv3(t, stepSize)

Expand Down Expand Up @@ -109,6 +111,8 @@ func TestSharedDomain_CommitmentKeyReplacement(t *testing.T) {
}

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

stepSize := uint64(100)
db, agg := testDbAndAggregatorv3(t, stepSize)

Expand Down Expand Up @@ -203,6 +207,8 @@ Loop:
}

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

stepSize := uint64(8)
require := require.New(t)
db, agg := testDbAndAggregatorv3(t, stepSize)
Expand Down Expand Up @@ -371,6 +377,8 @@ func TestSharedDomain_IteratePrefix(t *testing.T) {
}

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

log.Root().SetHandler(log.LvlFilterHandler(log.LvlWarn, log.StderrHandler))

stepSize := uint64(10)
Expand Down
Loading
Loading