diff options
| author | Fuwn <[email protected]> | 2026-02-26 15:07:03 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-26 15:07:03 -0800 |
| commit | f1b26a68534e4299de7b5fe6b15d2b248fac40e1 (patch) | |
| tree | 4003d041bc46866b7d4b7f0bfb6c6924d991cbb6 /internal/checkpoint/checkpoint_test.go | |
| parent | feat: initial Plutia release — verifiable high-performance PLC mirror (mirr... (diff) | |
| download | plutia-test-f1b26a68534e4299de7b5fe6b15d2b248fac40e1.tar.xz plutia-test-f1b26a68534e4299de7b5fe6b15d2b248fac40e1.zip | |
feat: harden launch readiness with versioning, metrics, and resilience
Diffstat (limited to 'internal/checkpoint/checkpoint_test.go')
| -rw-r--r-- | internal/checkpoint/checkpoint_test.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/internal/checkpoint/checkpoint_test.go b/internal/checkpoint/checkpoint_test.go index 9ca9b2a..8149129 100644 --- a/internal/checkpoint/checkpoint_test.go +++ b/internal/checkpoint/checkpoint_test.go @@ -1,9 +1,11 @@ package checkpoint import ( + "context" "crypto/ed25519" "crypto/rand" "encoding/base64" + "encoding/json" "os" "path/filepath" "testing" @@ -103,3 +105,52 @@ func TestCheckpointRootStability(t *testing.T) { t.Fatalf("block root changed for identical block set: %s vs %s", cp1.BlockMerkleRoot, cp2.BlockMerkleRoot) } } + +func TestBuildDIDProofAtCheckpointHonorsContextCancellation(t *testing.T) { + tmp := t.TempDir() + store, err := storage.OpenPebble(tmp) + if err != nil { + t.Fatalf("open pebble: %v", err) + } + defer store.Close() + + _, priv, err := ed25519.GenerateKey(rand.Reader) + if err != nil { + t.Fatalf("generate key: %v", err) + } + keyPath := filepath.Join(tmp, "mirror.key") + if err := os.WriteFile(keyPath, []byte(base64.RawURLEncoding.EncodeToString(priv)), 0o600); err != nil { + t.Fatalf("write key: %v", err) + } + checkpointsDir := filepath.Join(tmp, "checkpoints") + if err := os.MkdirAll(checkpointsDir, 0o755); err != nil { + t.Fatalf("mkdir checkpoints: %v", err) + } + leaves := make([]types.DIDLeaf, 500) + for i := range leaves { + leaves[i] = types.DIDLeaf{ + DID: "did:plc:test-" + string(rune('a'+(i%26))), + ChainTipHash: "tip", + } + } + snapshot := types.CheckpointStateSnapshotV1{ + Version: 1, + Sequence: 10, + CreatedAt: "2026-02-26T00:00:00Z", + Leaves: leaves, + } + b, err := json.Marshal(snapshot) + if err != nil { + t.Fatalf("marshal snapshot: %v", err) + } + if err := os.WriteFile(filepath.Join(checkpointsDir, "00000000000000000010.state.json"), b, 0o644); err != nil { + t.Fatalf("write snapshot: %v", err) + } + + mgr := NewManager(store, tmp, keyPath) + ctx, cancel := context.WithCancel(context.Background()) + cancel() + if _, _, _, err := mgr.BuildDIDProofAtCheckpoint(ctx, "did:plc:test-a", "tip", 10); err == nil { + t.Fatalf("expected context cancellation error") + } +} |