Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup warp signer tests #2651

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions vms/platformvm/warp/gwarp/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ func setupSigner(t testing.TB) *testSigner {
}

func TestInterface(t *testing.T) {
for _, test := range warp.SignerTests {
s := setupSigner(t)
test(t, s.client, s.sk, s.networkID, s.chainID)
s.closeFn()
for name, test := range warp.SignerTests {
t.Run(name, func(t *testing.T) {
s := setupSigner(t)
test(t, s.client, s.sk, s.networkID, s.chainID)
s.closeFn()
})
}
}
14 changes: 8 additions & 6 deletions vms/platformvm/warp/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import (
)

func TestSigner(t *testing.T) {
for _, test := range SignerTests {
sk, err := bls.NewSecretKey()
require.NoError(t, err)
for name, test := range SignerTests {
t.Run(name, func(t *testing.T) {
sk, err := bls.NewSecretKey()
require.NoError(t, err)

chainID := ids.GenerateTestID()
s := NewSigner(sk, constants.UnitTestID, chainID)
chainID := ids.GenerateTestID()
s := NewSigner(sk, constants.UnitTestID, chainID)

test(t, s, sk, constants.UnitTestID, chainID)
test(t, s, sk, constants.UnitTestID, chainID)
})
}
}
13 changes: 7 additions & 6 deletions vms/platformvm/warp/test_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import (
)

// SignerTests is a list of all signer tests
var SignerTests = []func(t *testing.T, s Signer, sk *bls.SecretKey, networkID uint32, chainID ids.ID){
TestSignerWrongChainID,
TestSignerVerifies,
var SignerTests = map[string]func(t *testing.T, s Signer, sk *bls.SecretKey, networkID uint32, chainID ids.ID){
"WrongChainID": TestWrongChainID,
"WrongNetworkID": TestWrongNetworkID,
"Verifies": TestVerifies,
}

// Test that using a random SourceChainID results in an error
func TestSignerWrongChainID(t *testing.T, s Signer, _ *bls.SecretKey, _ uint32, _ ids.ID) {
func TestWrongChainID(t *testing.T, s Signer, _ *bls.SecretKey, _ uint32, _ ids.ID) {
require := require.New(t)

msg, err := NewUnsignedMessage(
Expand All @@ -36,7 +37,7 @@ func TestSignerWrongChainID(t *testing.T, s Signer, _ *bls.SecretKey, _ uint32,
}

// Test that using a different networkID results in an error
func TestSignerWrongNetworkID(t *testing.T, s Signer, _ *bls.SecretKey, networkID uint32, blockchainID ids.ID) {
func TestWrongNetworkID(t *testing.T, s Signer, _ *bls.SecretKey, networkID uint32, blockchainID ids.ID) {
require := require.New(t)

msg, err := NewUnsignedMessage(
Expand All @@ -52,7 +53,7 @@ func TestSignerWrongNetworkID(t *testing.T, s Signer, _ *bls.SecretKey, networkI
}

// Test that a signature generated with the signer verifies correctly
func TestSignerVerifies(t *testing.T, s Signer, sk *bls.SecretKey, networkID uint32, chainID ids.ID) {
func TestVerifies(t *testing.T, s Signer, sk *bls.SecretKey, networkID uint32, chainID ids.ID) {
require := require.New(t)

msg, err := NewUnsignedMessage(
Expand Down
Loading