Files
proto/p/warp/test_helpers_test.go
zeekay 7dfb687462 proto/p: rip luxfi/codec from api/, warp/, warp/message/, warp/payload/
Wave 2A of the codec rip (#101). Eliminates github.com/luxfi/codec imports
from the api/, warp/, warp/message/, and warp/payload/ subtrees of proto/p.

* api/{height,staking}.go now use github.com/luxfi/node/utils/json instead
  of github.com/luxfi/codec/jsonrpc — same byte format, no transitive
  codec dependency.

* warp/codec.go, warp/payload/codec.go, warp/message/codec.go each define
  a local Codec / Registry interface (structurally identical to
  codec.Manager / codec.Registry) and a RegisterTypes(r) function. The
  package-level Codec singleton is gone — every Parse*, New*, *.Initialize,
  TeleportMessage.{ToWarpMessage,DecryptPayload}, TeleportTransferPayload.
  Bytes and ParseTransferPayload now take a Codec parameter and the
  caller threads it through.

* proto/internal/pcodectest is the canonical test wiring (mirrors
  proto/internal/xcodectest from Wave 1A). It exposes NewPayloadCodec,
  NewMessageCodec, and NewWarpCodec — each constructs a linearcodec-
  backed codec.Manager with the appropriate types pre-registered.

* In-package warp tests converted to `package warp_test` to avoid the
  cycle pcodectest → warp → warp/*_test.go → pcodectest. warp's prod
  `test_helpers.go` was renamed to `_test.go` (it was already test-only
  in spirit) and unexported helpers stay unexported in `warp_test`. The
  dead `test_signer_test.go` (//go:build test, unused) was removed.

* No backwards-compat shim. No deprecated alias. proto/p/api/warp/* is
  now byte-compatible with the legacy wire format but constructs its
  codec dependency externally.

Cascade breaks (Wave 2D territory, not fixed here):
  sdk/wallet/chain/p/wallet/backend_visitor.go — warp.ParseMessage,
    payload.ParseAddressedCall now require Codec
  sdk/validatormanager/root.go — payload.* calls need Codec
  vm/rpc/{,dag/,chain/}warp_adapter.go — warp.* calls need Codec

Grep zero confirmation under the subtrees migrated:
  proto/p/api/ — no codec import
  proto/p/warp/, proto/p/warp/message/, proto/p/warp/payload/ — no
  codec import (signertest subpackage also clean)
2026-06-06 00:47:45 -07:00

62 lines
1.2 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package warp_test
import (
"bytes"
"errors"
"slices"
"github.com/luxfi/crypto/bls"
"github.com/luxfi/crypto/bls/signer/localsigner"
"github.com/luxfi/ids"
"github.com/luxfi/proto/p/warp"
)
const pChainHeight uint64 = 1337
var (
errTest = errors.New("non-nil error")
testVdrs []*testValidator
)
type testValidator struct {
nodeID ids.NodeID
sk *localsigner.LocalSigner
vdr *warp.Validator
}
func (v *testValidator) Compare(other *testValidator) int {
return bytes.Compare(v.vdr.PublicKeyBytes, other.vdr.PublicKeyBytes)
}
func newTestValidator() *testValidator {
sk, err := localsigner.New()
if err != nil {
panic(err)
}
nodeID := ids.GenerateTestNodeID()
pk := sk.PublicKey()
return &testValidator{
nodeID: nodeID,
sk: sk,
vdr: &warp.Validator{
PublicKey: pk,
PublicKeyBytes: bls.PublicKeyToUncompressedBytes(pk),
Weight: 3,
NodeIDs: []ids.NodeID{nodeID},
},
}
}
func init() {
testVdrs = []*testValidator{
newTestValidator(),
newTestValidator(),
newTestValidator(),
}
slices.SortFunc(testVdrs, (*testValidator).Compare)
}