Files
zeekay 45df2649d9 feat: ZAP-native wire schemas — activation 2025-12-25T16:20:00-08:00
Adds github.com/luxfi/utxo/wire package + per-fx wire.go adapters so
that luxfi/node's vms/{platformvm,xvm}/txs/codec.go can be deleted.

wire/ package mirrors luxfi/node/vms/wire — every fxs primitive carries
a (TypeKind, ShapeKind) discriminator pair on its wire envelope, then
a ZAP message describing its fields. Decomposes the legacy
codec.Manager slot map (which braided "fx family" and "primitive shape"
into a single dense uint32 slot id) into two orthogonal 1-byte tags.

PQ-specific schemas (pq_output_owners, pq_transfer_output,
pq_mint_output) handle the mldsafx/slhdsafx case where addresses are
full PQ pubkeys (1312-2592 bytes) rather than 20-byte hashed ShortIDs.
The wire layer is stride-agnostic — the per-fx wire.go resolves
SecurityLevel → pubkey stride before parsing.

Per-fx wire.go adapters provide (value T).Bytes() []byte (Go type →
wire envelope) and Wrap*(b []byte) (*T, error) (wire envelope → Go
type). The Initialize(vm)/codec.Manager.RegisterType chain stays in
place pending downstream coordination; this commit gets the wire/
package + adapters in so consumer agents (platformvm/warp,
platformvm/state, xvm) can pin a SHA and start their migrations.

UTXO.WireBytes() builds the outer envelope by calling the polymorphic
Out's Bytes() (any fxs primitive implementing wireSerializable).
WrapUTXOBytes(b) parses the outer envelope; the inner output is
dispatched by the caller via OutputDiscriminator() → fx-package
WrapTransferOutput / WrapMintOutput / WrapAttestationOutput.

Tests: 35 round-trip tests across 9 packages. go vet clean. go test
-race clean. gofmt clean.

Activation: 2025-12-25T16:20:00-08:00 (unix 1766708400). No
backwards compat — pre-activation legacy codec blobs are a
protocol-violation reject after activation.
2026-06-03 09:34:23 -07:00

116 lines
2.8 KiB
Go

// Copyright (C) 2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package schnorrfx
import (
"bytes"
"testing"
"github.com/luxfi/ids"
)
func TestWire_OutputOwners_RoundTrip(t *testing.T) {
in := &OutputOwners{
Locktime: 1234,
Threshold: 1,
Addrs: []ids.ShortID{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}},
}
got, err := WrapOutputOwners(in.Bytes())
if err != nil {
t.Fatalf("WrapOutputOwners: %v", err)
}
if !in.Equals(got) {
t.Errorf("OutputOwners mismatch")
}
}
func TestWire_TransferOutput_RoundTrip(t *testing.T) {
in := &TransferOutput{
Amt: 1_000_000,
OutputOwners: OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}},
},
}
got, err := WrapTransferOutput(in.Bytes())
if err != nil {
t.Fatalf("WrapTransferOutput: %v", err)
}
if got.Amt != in.Amt {
t.Errorf("Amt: got %d, want %d", got.Amt, in.Amt)
}
}
func TestWire_TransferInput_RoundTrip(t *testing.T) {
in := &TransferInput{
Amt: 500,
Input: Input{SigIndices: []uint32{0, 2}},
}
got, err := WrapTransferInput(in.Bytes())
if err != nil {
t.Fatalf("WrapTransferInput: %v", err)
}
if got.Amt != in.Amt {
t.Errorf("Amt: got %d, want %d", got.Amt, in.Amt)
}
}
func TestWire_MintOutput_RoundTrip(t *testing.T) {
in := &MintOutput{
OutputOwners: OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}},
},
}
got, err := WrapMintOutput(in.Bytes())
if err != nil {
t.Fatalf("WrapMintOutput: %v", err)
}
if !in.OutputOwners.Equals(&got.OutputOwners) {
t.Errorf("OutputOwners mismatch")
}
}
func TestWire_MintOperation_RoundTrip(t *testing.T) {
addr := ids.ShortID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
owners := OutputOwners{Threshold: 1, Addrs: []ids.ShortID{addr}}
in := &MintOperation{
MintInput: Input{SigIndices: []uint32{0}},
MintOutput: MintOutput{OutputOwners: owners},
TransferOutput: TransferOutput{Amt: 100, OutputOwners: owners},
}
got, err := WrapMintOperation(in.Bytes())
if err != nil {
t.Fatalf("WrapMintOperation: %v", err)
}
if got.TransferOutput.Amt != 100 {
t.Errorf("TransferOutput.Amt: got %d, want 100", got.TransferOutput.Amt)
}
}
func TestWire_Credential_RoundTrip(t *testing.T) {
var s [SigLen]byte
for i := range s {
s[i] = byte(i)
}
pk := make([]byte, PubKeyLen)
for i := range pk {
pk[i] = byte(i)
}
in := &Credential{
Sigs: [][SigLen]byte{s},
PubKeys: [][]byte{pk},
}
got, err := WrapCredential(in.Bytes())
if err != nil {
t.Fatalf("WrapCredential: %v", err)
}
if !bytes.Equal(got.Sigs[0][:], s[:]) {
t.Errorf("Sigs[0] mismatch")
}
if !bytes.Equal(got.PubKeys[0], pk) {
t.Errorf("PubKeys[0] mismatch")
}
}