Files
zk/backend_registry_test.go
zeekay 3fde8e4eb7 zk: initial split from luxfi/consensus/protocol/zchain
Extracts the Z-Chain proof envelope, verifier dispatch, verifier
manifest, backend registry, hash helper, and account-ID/key-record
registry subpackage into github.com/luxfi/zk.

Consensus repo is now primitives-only; chain-side proof code lives
here. Zero consensus .go imports needed rewriting — the only
references were doc comments, confirming the modules were already
decomplected.

Coverage:
  138 test runs across github.com/luxfi/zk and github.com/luxfi/zk/registry
  138 PASS / 0 FAIL

Cross-module: registry/parity_with_auth_test.go imports
luxfi/consensus/protocol/auth to confirm DeriveAccountID byte-equal
parity across the auth/registry packages. Resolves via a local
replace github.com/luxfi/consensus => ../consensus until the
matching consensus tag drops the deleted protocol/zchain dir.
2026-05-11 19:12:15 -07:00

80 lines
2.3 KiB
Go

// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package zk
import (
"errors"
"testing"
"github.com/luxfi/consensus/config"
)
func TestRegisterBackendVerifier_HappyPath(t *testing.T) {
resetBackendVerifiersForTest()
called := false
err := RegisterBackendVerifier(
config.VerifierSP1CompressedSTARKPQ,
BackendVerifierFunc(func(_ *VerifierManifest, _ *ZPublicInputs, _ *ZProofEnvelope) (bool, error) {
called = true
return true, nil
}),
)
if err != nil {
t.Fatalf("RegisterBackendVerifier: %v", err)
}
b := lookupBackendVerifier(config.VerifierSP1CompressedSTARKPQ)
if b == nil {
t.Fatalf("lookupBackendVerifier returned nil after register")
}
ok, err := b.Verify(nil, nil, nil)
if err != nil {
t.Fatalf("Verify returned %v", err)
}
if !ok || !called {
t.Errorf("bound backend did not run")
}
}
func TestRegisterBackendVerifier_RejectsNil(t *testing.T) {
resetBackendVerifiersForTest()
err := RegisterBackendVerifier(config.VerifierSP1CompressedSTARKPQ, nil)
if !errors.Is(err, ErrBackendVerifierNil) {
t.Errorf("got %v; want ErrBackendVerifierNil", err)
}
}
func TestRegisterBackendVerifier_RejectsVerifierNone(t *testing.T) {
resetBackendVerifiersForTest()
err := RegisterBackendVerifier(
config.VerifierNone,
BackendVerifierFunc(func(_ *VerifierManifest, _ *ZPublicInputs, _ *ZProofEnvelope) (bool, error) {
return true, nil
}),
)
if !errors.Is(err, ErrBackendVerifierInvalidID) {
t.Errorf("got %v; want ErrBackendVerifierInvalidID", err)
}
}
func TestRegisterBackendVerifier_RejectsDuplicate(t *testing.T) {
resetBackendVerifiersForTest()
bv := BackendVerifierFunc(func(_ *VerifierManifest, _ *ZPublicInputs, _ *ZProofEnvelope) (bool, error) {
return true, nil
})
if err := RegisterBackendVerifier(config.VerifierSP1CompressedSTARKPQ, bv); err != nil {
t.Fatalf("first register: %v", err)
}
err := RegisterBackendVerifier(config.VerifierSP1CompressedSTARKPQ, bv)
if !errors.Is(err, ErrBackendVerifierDuplicate) {
t.Errorf("duplicate register: got %v; want ErrBackendVerifierDuplicate", err)
}
}
func TestLookupBackendVerifier_Missing(t *testing.T) {
resetBackendVerifiersForTest()
if b := lookupBackendVerifier(config.VerifierRISC0SuccinctSTARKPQ); b != nil {
t.Errorf("lookup on empty registry returned non-nil")
}
}