mirror of
https://github.com/luxfi/proto.git
synced 2026-11-02 15:24:16 +00:00
Adds .hanzo/workflows/cicd.yml calling the canonical pipeline and drops the GitHub-hosted workflows it replaces. Lands here because this is where the repo is written — git.hanzo.ai is upstream and github.com is its push mirror, so the same change made on github.com never reaches the runner fleet.
77 lines
2.0 KiB
Go
77 lines
2.0 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package signertest
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/luxfi/constants"
|
|
"github.com/luxfi/crypto/bls"
|
|
"github.com/luxfi/ids"
|
|
"github.com/luxfi/proto/p/warp"
|
|
)
|
|
|
|
// SignerTests is a list of all signer tests
|
|
var SignerTests = map[string]func(t *testing.T, s warp.Signer, sk bls.Signer, networkID uint32, chainID ids.ID){
|
|
"WrongChainID": TestWrongChainID,
|
|
"WrongNetworkID": TestWrongNetworkID,
|
|
"Verifies": TestVerifies,
|
|
}
|
|
|
|
// Test that using a random SourceChainID results in an error
|
|
func TestWrongChainID(t *testing.T, s warp.Signer, _ bls.Signer, _ uint32, _ ids.ID) {
|
|
require := require.New(t)
|
|
|
|
msg, err := warp.NewUnsignedMessage(
|
|
constants.UnitTestID,
|
|
ids.GenerateTestID(),
|
|
[]byte("payload"),
|
|
)
|
|
require.NoError(err)
|
|
|
|
_, err = s.Sign(msg)
|
|
// Error type varies between local and gRPC signers; checking Error() suffices.
|
|
require.Error(err) //nolint:forbidigo // currently returns grpc errors too
|
|
}
|
|
|
|
// Test that using a different networkID results in an error
|
|
func TestWrongNetworkID(t *testing.T, s warp.Signer, _ bls.Signer, networkID uint32, blockchainID ids.ID) {
|
|
require := require.New(t)
|
|
|
|
msg, err := warp.NewUnsignedMessage(
|
|
networkID+1,
|
|
blockchainID,
|
|
[]byte("payload"),
|
|
)
|
|
require.NoError(err)
|
|
|
|
_, err = s.Sign(msg)
|
|
// Error type varies between local and gRPC signers; checking Error() suffices.
|
|
require.Error(err) //nolint:forbidigo // currently returns grpc errors too
|
|
}
|
|
|
|
// Test that a signature generated with the signer verifies correctly
|
|
func TestVerifies(t *testing.T, s warp.Signer, sk bls.Signer, networkID uint32, chainID ids.ID) {
|
|
require := require.New(t)
|
|
|
|
msg, err := warp.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 := sk.PublicKey()
|
|
msgBytes := msg.Bytes()
|
|
require.True(bls.Verify(pk, sig, msgBytes))
|
|
}
|