mirror of
https://github.com/luxfi/node.git
synced 2026-10-30 15:24:05 +00:00
The module already called itself github.com/luxfi/node while containing no node in Go: cmd/luxd was twenty-one lines that printed the size of a few types, and the Go column of the matrix measured a VM plugin. A repo that fetches the thing it claims to be has not replaced it, so the Go sources move in — 1515 files, the daemon and everything under it — and the build reaches outside this module for nothing. Rust and C++ sit beside it unchanged and are still measured against it by the differential. That is the point of one repo: the reference implementation and the two ports are the same checkout, so parity is a thing you can run rather than a thing you assert. Verified: builds, and the closure carries no lux-private — checked at build time rather than believed. The daemon starts twelve chains on a local network (P X C Q Z A B G K M F, plus D through its plugin) and reports healthy.
76 lines
1.9 KiB
Go
76 lines
1.9 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
//go:build test
|
|
|
|
package warp
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/luxfi/constants"
|
|
"github.com/luxfi/crypto/bls"
|
|
"github.com/luxfi/ids"
|
|
)
|
|
|
|
// SignerTests is a list of all signer tests
|
|
var SignerTests = map[string]func(t *testing.T, s Signer, sk *bls.SecretKey, networkID uint32, chainID ids.ID){
|
|
"WrongChainID": testWrongChainID,
|
|
"WrongNetworkID": testWrongNetworkID,
|
|
"Verifies": testVerifies,
|
|
}
|
|
|
|
// testWrongChainID tests that using a random SourceChainID results in an error
|
|
func testWrongChainID(t *testing.T, s Signer, _ *bls.SecretKey, _ uint32, _ ids.ID) {
|
|
require := require.New(t)
|
|
|
|
msg, err := NewUnsignedMessage(
|
|
constants.UnitTestID,
|
|
ids.GenerateTestID(),
|
|
[]byte("payload"),
|
|
)
|
|
require.NoError(err)
|
|
|
|
_, err = s.Sign(msg)
|
|
require.Error(err) //nolint:forbidigo // currently returns grpc errors too
|
|
}
|
|
|
|
// testWrongNetworkID tests that using a different networkID results in an error
|
|
func testWrongNetworkID(t *testing.T, s Signer, _ *bls.SecretKey, networkID uint32, blockchainID ids.ID) {
|
|
require := require.New(t)
|
|
|
|
msg, err := NewUnsignedMessage(
|
|
networkID+1,
|
|
blockchainID,
|
|
[]byte("payload"),
|
|
)
|
|
require.NoError(err)
|
|
|
|
_, err = s.Sign(msg)
|
|
require.Error(err) //nolint:forbidigo // currently returns grpc errors too
|
|
}
|
|
|
|
// testVerifies tests that a signature generated with the signer verifies correctly
|
|
func testVerifies(t *testing.T, s Signer, sk *bls.SecretKey, networkID uint32, chainID ids.ID) {
|
|
require := require.New(t)
|
|
|
|
msg, err := NewUnsignedMessage(
|
|
networkID,
|
|
chainID,
|
|
[]byte("payload"),
|
|
)
|
|
require.NoError(err)
|
|
|
|
sigBytes, err := s.Sign(msg)
|
|
require.NoError(err)
|
|
|
|
sig, err := bls.SignatureFromBytes(sigBytes)
|
|
require.NoError(err)
|
|
|
|
pk := bls.PublicFromSecretKey(sk)
|
|
msgBytes := msg.Bytes()
|
|
require.True(bls.Verify(pk, sig, msgBytes))
|
|
}
|