ceremonyclient/node/store/hypergraph_test.go
Cassandra Heart 12996487c3
v2.1.0.18 (#508)
* experiment: reject bad peer info messages

* v2.1.0.18 preview

* add tagged sync

* Add missing hypergraph changes

* small tweaks to sync

* allow local sync, use it for provers with workers

* missing file

* resolve build error

* resolve sync issue, remove raw sync

* resolve deletion promotion bug

* resolve sync abstraction leak from tree deletion changes

* rearrange prover sync

* remove pruning from sync

* restore removed sync flag

* fix: sync, event stream deadlock, heuristic scoring of better shards

* resolve hanging shutdown + pubsub proxy issue

* further bugfixes: sync (restore old leaf sync), pubsub shutdown, merge events

* fix: clean up rust ffi, background coverage events, and sync tweaks

* fix: linking issue for channel, connectivity test aggression, sync regression, join tests

* fix: disjoint sync, improper application of filter

* resolve sync/reel/validation deadlock

* adjust sync to handle no leaf edge cases, multi-path segment traversal

* use simpler sync

* faster, simpler sync with some debug extras

* migration to recalculate

* don't use batch

* square up the roots

* fix nil pointer

* fix: seniority calculation, sync race condition, migration

* make sync dumber

* fix: tree deletion issue

* fix: missing seniority merge request canonical serialization

* address issues from previous commit test

* stale workers should be cleared

* remove missing gap check

* rearrange collect, reduce sync logging noise

* fix: the disjoint leaf/branch sync case

* nuclear option on sync failures

* v2.1.0.18, finalized
2026-02-08 23:51:51 -06:00

126 lines
4.0 KiB
Go

package store
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"source.quilibrium.com/quilibrium/monorepo/config"
"source.quilibrium.com/quilibrium/monorepo/types/tries"
)
func setupTestHypergraphStore(t *testing.T) *PebbleHypergraphStore {
logger := zap.NewNop()
cfg := &config.DBConfig{
InMemoryDONOTUSE: true,
Path: ".test/hypergraph",
}
db := NewPebbleDB(logger, cfg, 0)
require.NotNil(t, db)
t.Cleanup(func() { db.Close() })
return NewPebbleHypergraphStore(cfg, db, logger, nil, nil)
}
func TestGetRootCommits_IncludesAllCommitTypes(t *testing.T) {
hgStore := setupTestHypergraphStore(t)
// Create a test shard address
shardAddress := bytes.Repeat([]byte{0x42}, 32)
frameNumber := uint64(100)
// Create test commits (64 bytes each)
vertexAddsCommit := bytes.Repeat([]byte{0xAA}, 64)
vertexRemovesCommit := bytes.Repeat([]byte{0xBB}, 64)
hyperedgeAddsCommit := bytes.Repeat([]byte{0xCC}, 64)
hyperedgeRemovesCommit := bytes.Repeat([]byte{0xDD}, 64)
// Start a transaction and write all four commit types
txn, err := hgStore.NewTransaction(false)
require.NoError(t, err)
err = hgStore.SetShardCommit(txn, frameNumber, "adds", "vertex", shardAddress, vertexAddsCommit)
require.NoError(t, err)
err = hgStore.SetShardCommit(txn, frameNumber, "removes", "vertex", shardAddress, vertexRemovesCommit)
require.NoError(t, err)
err = hgStore.SetShardCommit(txn, frameNumber, "adds", "hyperedge", shardAddress, hyperedgeAddsCommit)
require.NoError(t, err)
err = hgStore.SetShardCommit(txn, frameNumber, "removes", "hyperedge", shardAddress, hyperedgeRemovesCommit)
require.NoError(t, err)
err = txn.Commit()
require.NoError(t, err)
// Now retrieve all commits using GetRootCommits
commits, err := hgStore.GetRootCommits(frameNumber)
require.NoError(t, err)
// Find the shard key for our test address
var foundShardKey *tries.ShardKey
for sk := range commits {
if bytes.Equal(sk.L2[:], shardAddress) {
foundShardKey = &sk
break
}
}
require.NotNil(t, foundShardKey, "Should find the shard in commits")
shardCommits := commits[*foundShardKey]
require.Len(t, shardCommits, 4, "Should have 4 commit slots")
// Verify each commit type was retrieved
assert.Equal(t, vertexAddsCommit, shardCommits[0], "Vertex adds commit should match")
assert.Equal(t, vertexRemovesCommit, shardCommits[1], "Vertex removes commit should match")
assert.Equal(t, hyperedgeAddsCommit, shardCommits[2], "Hyperedge adds commit should match")
assert.Equal(t, hyperedgeRemovesCommit, shardCommits[3], "Hyperedge removes commit should match")
}
func TestGetRootCommits_HyperedgeRemovesOnly(t *testing.T) {
// This test specifically checks if hyperedge removes are retrieved
// when they are the only commit type for a shard
hgStore := setupTestHypergraphStore(t)
// Create a test shard address
shardAddress := bytes.Repeat([]byte{0x99}, 32)
frameNumber := uint64(200)
// Only write hyperedge removes commit
hyperedgeRemovesCommit := bytes.Repeat([]byte{0xEE}, 64)
txn, err := hgStore.NewTransaction(false)
require.NoError(t, err)
err = hgStore.SetShardCommit(txn, frameNumber, "removes", "hyperedge", shardAddress, hyperedgeRemovesCommit)
require.NoError(t, err)
err = txn.Commit()
require.NoError(t, err)
// Now retrieve all commits using GetRootCommits
commits, err := hgStore.GetRootCommits(frameNumber)
require.NoError(t, err)
// Find the shard key for our test address
var foundShardKey *tries.ShardKey
for sk := range commits {
if bytes.Equal(sk.L2[:], shardAddress) {
foundShardKey = &sk
break
}
}
// This assertion will fail if hyperedge removes are not included in the range scan
require.NotNil(t, foundShardKey, "Should find the shard with only hyperedge removes in commits")
shardCommits := commits[*foundShardKey]
require.Len(t, shardCommits, 4, "Should have 4 commit slots")
// The hyperedge removes should be at index 3
assert.Equal(t, hyperedgeRemovesCommit, shardCommits[3], "Hyperedge removes commit should match")
}