Skip to content

Commit

Permalink
update: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianToledano committed Nov 17, 2023
1 parent f78ab65 commit efb92eb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
23 changes: 11 additions & 12 deletions client/tx/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,19 +454,18 @@ func (f Factory) getSimPK() (cryptotypes.PubKey, error) {
// getSimSignatureData based on the pubKey type gets the correct SignatureData type
// to use for building a simulation tx.
func (f Factory) getSimSignatureData(pk cryptotypes.PubKey) signing.SignatureData {
if multisigPubKey, ok := pk.(*multisig.LegacyAminoPubKey); ok {
multiSignatureData := make([]signing.SignatureData, 0, multisigPubKey.Threshold)
for i := uint32(0); i < multisigPubKey.Threshold; i++ {
multiSignatureData = append(multiSignatureData, &signing.SingleSignatureData{
SignMode: f.SignMode(),
})
}
return &signing.MultiSignatureData{
Signatures: multiSignatureData,
}
multisigPubKey, ok := pk.(*multisig.LegacyAminoPubKey)
if !ok {
return &signing.SingleSignatureData{SignMode: f.signMode}
}
multiSignatureData := make([]signing.SignatureData, 0, multisigPubKey.Threshold)
for i := uint32(0); i < multisigPubKey.Threshold; i++ {
multiSignatureData = append(multiSignatureData, &signing.SingleSignatureData{
SignMode: f.SignMode(),
})
}
return &signing.SingleSignatureData{
SignMode: f.signMode,
return &signing.MultiSignatureData{
Signatures: multiSignatureData,
}
}

Expand Down
32 changes: 17 additions & 15 deletions client/tx/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestFactoryPrepare(t *testing.T) {
require.Equal(t, output.Sequence(), uint64(1))
}

func TestFactory_getSimPK(t *testing.T) {
func TestFactory_getSimPKType(t *testing.T) {
// setup keyring
registry := codectypes.NewInterfaceRegistry()
cryptocodec.RegisterInterfaces(registry)
Expand All @@ -53,7 +53,7 @@ func TestFactory_getSimPK(t *testing.T) {
name string
fromName string
genKey func(fromName string, k keyring.Keyring) error
want types.PubKey
wantType types.PubKey
}{
{
name: "simple key",
Expand All @@ -62,7 +62,7 @@ func TestFactory_getSimPK(t *testing.T) {
_, err := k.NewAccount(fromName, testdata.TestMnemonic, "", "", hd.Secp256k1)
return err
},
want: &secp256k1.PubKey{},
wantType: (*secp256k1.PubKey)(nil),
},
{
name: "multisig key",
Expand All @@ -72,9 +72,10 @@ func TestFactory_getSimPK(t *testing.T) {
_, err := k.SaveMultisig(fromName, pk)
return err
},
want: &multisig.LegacyAminoPubKey{},
wantType: (*multisig.LegacyAminoPubKey)(nil),
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.genKey(tt.fromName, k)
Expand All @@ -86,32 +87,33 @@ func TestFactory_getSimPK(t *testing.T) {
}
got, err := f.getSimPK()
require.NoError(t, err)
require.IsType(t, tt.want, got)
require.IsType(t, tt.wantType, got)
})
}
}

func TestFactory_getSimSignatureData(t *testing.T) {
tests := []struct {
name string
pk types.PubKey
want signing.SignatureData
name string
pk types.PubKey
wantType any
}{
{
name: "simple pubkey",
pk: &secp256k1.PubKey{},
want: &signing.SingleSignatureData{},
name: "simple pubkey",
pk: &secp256k1.PubKey{},
wantType: (*signing.SingleSignatureData)(nil),
},
{
name: "multisig pubkey",
pk: &multisig.LegacyAminoPubKey{},
want: &signing.MultiSignatureData{},
name: "multisig pubkey",
pk: &multisig.LegacyAminoPubKey{},
wantType: (*signing.MultiSignatureData)(nil),
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := Factory{}.getSimSignatureData(tt.pk)
require.IsType(t, tt.want, got)
require.IsType(t, tt.wantType, got)
})
}
}

0 comments on commit efb92eb

Please sign in to comment.