-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
fix(client/tx): simulate with correct pk #18472
Merged
+134
−33
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
712d4a7
fix: simulate with correct pk
JulianToledano 6cc1feb
add: check err
JulianToledano 6fdc50a
add: CHANGELOG
JulianToledano 058d220
fix: use correct SignatureData
JulianToledano 7217fba
add: tests
JulianToledano 8d3e693
update: change test package name
JulianToledano 7681068
Merge branch 'main' into julian/gas-simulation-incorrect-key
JulianToledano f78ab65
Merge branch 'main' into julian/gas-simulation-incorrect-key
JulianToledano efb92eb
update: tests
JulianToledano 9169d83
style
JulianToledano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,119 @@ | ||
package tx_test | ||
package tx | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" | ||
"github.com/cosmos/cosmos-sdk/crypto/hd" | ||
"github.com/cosmos/cosmos-sdk/crypto/keyring" | ||
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig" | ||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" | ||
"github.com/cosmos/cosmos-sdk/crypto/types" | ||
"github.com/cosmos/cosmos-sdk/testutil/testdata" | ||
"github.com/cosmos/cosmos-sdk/types/tx/signing" | ||
) | ||
|
||
func TestFactoryPrepate(t *testing.T) { | ||
func TestFactoryPrepare(t *testing.T) { | ||
t.Parallel() | ||
|
||
factory := tx.Factory{} | ||
factory := Factory{} | ||
clientCtx := client.Context{} | ||
|
||
output, err := factory.Prepare(clientCtx.WithOffline(true)) | ||
require.NoError(t, err) | ||
require.Equal(t, output, factory) | ||
|
||
factory = tx.Factory{}.WithAccountRetriever(client.MockAccountRetriever{ReturnAccNum: 10, ReturnAccSeq: 1}).WithAccountNumber(5) | ||
factory = Factory{}.WithAccountRetriever(client.MockAccountRetriever{ReturnAccNum: 10, ReturnAccSeq: 1}).WithAccountNumber(5) | ||
output, err = factory.Prepare(clientCtx.WithFrom("foo")) | ||
require.NoError(t, err) | ||
require.NotEqual(t, output, factory) | ||
require.Equal(t, output.AccountNumber(), uint64(5)) | ||
require.Equal(t, output.Sequence(), uint64(1)) | ||
|
||
factory = tx.Factory{}.WithAccountRetriever(client.MockAccountRetriever{ReturnAccNum: 10, ReturnAccSeq: 1}) | ||
factory = Factory{}.WithAccountRetriever(client.MockAccountRetriever{ReturnAccNum: 10, ReturnAccSeq: 1}) | ||
output, err = factory.Prepare(clientCtx.WithFrom("foo")) | ||
require.NoError(t, err) | ||
require.NotEqual(t, output, factory) | ||
require.Equal(t, output.AccountNumber(), uint64(10)) | ||
require.Equal(t, output.Sequence(), uint64(1)) | ||
} | ||
|
||
func TestFactory_getSimPKType(t *testing.T) { | ||
// setup keyring | ||
registry := codectypes.NewInterfaceRegistry() | ||
cryptocodec.RegisterInterfaces(registry) | ||
k := keyring.NewInMemory(codec.NewProtoCodec(registry)) | ||
|
||
tests := []struct { | ||
name string | ||
fromName string | ||
genKey func(fromName string, k keyring.Keyring) error | ||
wantType types.PubKey | ||
}{ | ||
{ | ||
name: "simple key", | ||
fromName: "testKey", | ||
genKey: func(fromName string, k keyring.Keyring) error { | ||
_, err := k.NewAccount(fromName, testdata.TestMnemonic, "", "", hd.Secp256k1) | ||
return err | ||
}, | ||
wantType: (*secp256k1.PubKey)(nil), | ||
}, | ||
{ | ||
name: "multisig key", | ||
fromName: "multiKey", | ||
genKey: func(fromName string, k keyring.Keyring) error { | ||
pk := multisig.NewLegacyAminoPubKey(1, []types.PubKey{&multisig.LegacyAminoPubKey{}}) | ||
_, err := k.SaveMultisig(fromName, pk) | ||
return err | ||
}, | ||
wantType: (*multisig.LegacyAminoPubKey)(nil), | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
JulianToledano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
err := tt.genKey(tt.fromName, k) | ||
require.NoError(t, err) | ||
f := Factory{ | ||
keybase: k, | ||
fromName: tt.fromName, | ||
simulateAndExecute: true, | ||
} | ||
got, err := f.getSimPK() | ||
require.NoError(t, err) | ||
require.IsType(t, tt.wantType, got) | ||
}) | ||
} | ||
} | ||
|
||
func TestFactory_getSimSignatureData(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
pk types.PubKey | ||
wantType any | ||
}{ | ||
{ | ||
name: "simple pubkey", | ||
pk: &secp256k1.PubKey{}, | ||
wantType: (*signing.SingleSignatureData)(nil), | ||
}, | ||
{ | ||
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.wantType, got) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tx_test | ||
package tx | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/testutil/testdata" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was there a reason to change the package name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's for testing their private function
getSimSignatureData
and setfromName
on the Factory that is usually private. For the latter, they could use clientCtx with a from name however.