Skip to content

Commit

Permalink
Cleanup warp signer tests (#2651)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrubabasu authored Jan 23, 2024
1 parent 1f29ab5 commit de0887b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
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

0 comments on commit de0887b

Please sign in to comment.