Skip to content

Commit

Permalink
style!: lint fixes for x/tx (#15748)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-rushakoff authored Apr 10, 2023
1 parent 4684c85 commit 4cb71ce
Show file tree
Hide file tree
Showing 36 changed files with 120 additions and 112 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
cosmossdk.io/log v1.0.0
cosmossdk.io/math v1.0.0
cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc
cosmossdk.io/x/tx v0.5.0
cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63
github.com/99designs/keyring v1.2.1
github.com/armon/go-metrics v0.4.1
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw=
cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k=
cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+SyMPtMoboLw/djgDbrI3dD5TG020Tnk=
cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ=
cosmossdk.io/x/tx v0.5.0 h1:01wPSoiYDHlfudV0fn867SBXI3uI/8tpatBgVVSnFzI=
cosmossdk.io/x/tx v0.5.0/go.mod h1:kDcwrN6QbCj+9NXVHL8qipMzA9YlMr9NpZa08SHCdLA=
cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 h1:zHqj2VwZ/MStFmR7SUe/7gErOFhL9v2rkjmWPB/st34=
cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek=
filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
Expand Down
2 changes: 1 addition & 1 deletion simapp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require (
cloud.google.com/go/storage v1.30.0 // indirect
cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba // indirect
cosmossdk.io/errors v1.0.0-beta.7 // indirect
cosmossdk.io/x/tx v0.5.0 // indirect
cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions simapp/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ cosmossdk.io/log v1.0.0 h1:NGKZ/A5rd4PduDfoscgABklX557PWjQINbosZy/m3Jk=
cosmossdk.io/log v1.0.0/go.mod h1:CwX9BLiBruZb7lzLlRr3R231d/fVPUXk8gAdV4LQap0=
cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw=
cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k=
cosmossdk.io/x/tx v0.5.0 h1:01wPSoiYDHlfudV0fn867SBXI3uI/8tpatBgVVSnFzI=
cosmossdk.io/x/tx v0.5.0/go.mod h1:kDcwrN6QbCj+9NXVHL8qipMzA9YlMr9NpZa08SHCdLA=
cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 h1:zHqj2VwZ/MStFmR7SUe/7gErOFhL9v2rkjmWPB/st34=
cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek=
filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
Expand Down
2 changes: 1 addition & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
cosmossdk.io/x/evidence v0.1.0
cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff
cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc
cosmossdk.io/x/tx v0.5.0
cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63
cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335
github.com/cometbft/cometbft v0.37.0
github.com/cosmos/cosmos-db v1.0.0-rc.1
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/aminojson/aminojson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func TestAminoJSON_Equivalence(t *testing.T) {
}

handlerOptions := signing_testutil.HandlerArgumentOptions{
ChainId: "test-chain",
ChainID: "test-chain",
Memo: "sometestmemo",
Msg: tt.pulsar,
AccNum: 1,
Expand All @@ -408,7 +408,7 @@ func TestAminoJSON_Equivalence(t *testing.T) {
theTx := txBuilder.GetTx()

legacySigningData := signing.SignerData{
ChainID: handlerOptions.ChainId,
ChainID: handlerOptions.ChainID,
Address: handlerOptions.SignerAddress,
AccountNumber: handlerOptions.AccNum,
Sequence: handlerOptions.AccSeq,
Expand Down Expand Up @@ -683,7 +683,7 @@ func TestAminoJSON_LegacyParity(t *testing.T) {
}

handlerOptions := signing_testutil.HandlerArgumentOptions{
ChainId: "test-chain",
ChainID: "test-chain",
Memo: "sometestmemo",
Msg: tc.pulsar,
AccNum: 1,
Expand All @@ -709,7 +709,7 @@ func TestAminoJSON_LegacyParity(t *testing.T) {
theTx := txBuilder.GetTx()

legacySigningData := signing.SignerData{
ChainID: handlerOptions.ChainId,
ChainID: handlerOptions.ChainID,
Address: handlerOptions.SignerAddress,
AccountNumber: handlerOptions.AccNum,
Sequence: handlerOptions.AccSeq,
Expand Down
2 changes: 1 addition & 1 deletion x/auth/tx/textual.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (h signModeTextualHandler) GetSignBytesWithContext(ctx context.Context, mod

return h.t.GetSignBytes(ctx, txsigning.SignerData{
Address: data.Address,
ChainId: data.ChainID,
ChainID: data.ChainID,
AccountNumber: data.AccountNumber,
Sequence: data.Sequence,
PubKey: &anypb.Any{
Expand Down
1 change: 1 addition & 0 deletions x/tx/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#15581](https://github.com/cosmos/cosmos-sdk/pull/15581) `GetSignersOptions` and `directaux.SignModeHandlerOptions` now
require a `signing.ProtoFileResolver` interface instead of `protodesc.Resolver`.
* [#15742](https://github.com/cosmos/cosmos-sdk/pull/15742) The `direct_aux` package has been renamed to `directaux` in line with Go conventions. No other types were changed during the package rename.
* [#15748](https://github.com/cosmos/cosmos-sdk/pull/15748) Rename signing.SignerData.ChainId to .ChainID, in line with Go conventions.

### Bug Fixes

Expand Down
4 changes: 0 additions & 4 deletions x/tx/decode/unknown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ func errUnknownField(typ string, tagNum int, wireType protowire.Type) error {
return decode.ErrUnknownField.Wrapf("%s: {TagNum: %d, WireType:%q}", typ, tagNum, wt)
}

func errMismatchedField(typ string, wireType protowire.Type) error {
return fmt.Errorf("invalid wire type %s for field %s", decode.WireTypeToString(wireType), typ)
}

var ProtoResolver = protoregistry.GlobalFiles

func TestRejectUnknownFieldsRepeated(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion x/tx/signing/aminojson/aminojson.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (h SignModeHandler) GetSignBytes(_ context.Context, signerData signing.Sign
signDoc := &aminojsonpb.AminoSignDoc{
AccountNumber: signerData.AccountNumber,
TimeoutHeight: body.TimeoutHeight,
ChainId: signerData.ChainId,
ChainId: signerData.ChainID,
Sequence: signerData.Sequence,
Memo: body.Memo,
Msgs: txData.Body.Messages,
Expand Down
2 changes: 1 addition & 1 deletion x/tx/signing/aminojson/aminojson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestAminoJsonSignMode(t *testing.T) {
Amount: []*basev1beta1.Coin{{Denom: "uatom", Amount: "1000"}},
}
handlerOptions := testutil.HandlerArgumentOptions{
ChainId: "test-chain",
ChainID: "test-chain",
Memo: "sometestmemo",
Tip: &txv1beta1.Tip{Tipper: "tipper", Amount: []*basev1beta1.Coin{{Denom: "Tip-token", Amount: "10"}}},
Msg: &bankv1beta1.MsgSend{
Expand Down
9 changes: 5 additions & 4 deletions x/tx/signing/aminojson/json_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,16 @@ func (enc Encoder) marshalMessage(msg protoreflect.Message, writer io.Writer) er
if !msg.Has(f) {
// msg.WhichOneof(oneof) == nil: no field of the oneof has been set
// !emptyOneOfWritten: we haven't written a null for this oneof yet (only write one null per empty oneof)
if isOneOf && msg.WhichOneof(oneof) == nil && !emptyOneOfWritten[oneofFieldName] {
switch {
case isOneOf && msg.WhichOneof(oneof) == nil && !emptyOneOfWritten[oneofFieldName]:
name = oneofFieldName
writeNil = true
emptyOneOfWritten[oneofFieldName] = true
} else if omitEmpty(f) {
case omitEmpty(f):
continue
} else if f.Kind() == protoreflect.MessageKind &&
case f.Kind() == protoreflect.MessageKind &&
f.Cardinality() != protoreflect.Repeated &&
!v.Message().IsValid() {
!v.Message().IsValid():
return errors.Errorf("not supported: dont_omit_empty=true on invalid (nil?) message field: %s", name)
}
}
Expand Down
2 changes: 1 addition & 1 deletion x/tx/signing/direct/direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (SignModeHandler) GetSignBytes(_ context.Context, signerData signing.Signer
return proto.Marshal(&txv1beta1.SignDoc{
BodyBytes: txData.BodyBytes,
AuthInfoBytes: txData.AuthInfoBytes,
ChainId: signerData.ChainId,
ChainId: signerData.ChainID,
AccountNumber: signerData.AccountNumber,
})
}
Expand Down
6 changes: 3 additions & 3 deletions x/tx/signing/direct/direct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ func TestDirectModeHandler(t *testing.T) {

directHandler := direct.SignModeHandler{}

chainId := "test-chain"
chainID := "test-chain"
accNum := uint64(1)

signingData := signing.SignerData{
Address: "",
ChainId: chainId,
ChainID: chainID,
AccountNumber: accNum,
PubKey: pk,
}
Expand All @@ -89,7 +89,7 @@ func TestDirectModeHandler(t *testing.T) {
signBytes2, err := proto.Marshal(&txv1beta1.SignDoc{
BodyBytes: txData.BodyBytes,
AuthInfoBytes: txData.AuthInfoBytes,
ChainId: chainId,
ChainId: chainID,
AccountNumber: accNum,
})
require.NoError(t, err)
Expand Down
25 changes: 13 additions & 12 deletions x/tx/signing/directaux/direct_aux.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,19 @@ func (h SignModeHandler) Mode() signingv1beta1.SignMode {
// getFirstSigner returns the first signer from the first message in the tx. It replicates behavior in
// https://github.com/cosmos/cosmos-sdk/blob/4a6a1e3cb8de459891cb0495052589673d14ef51/x/auth/tx/builder.go#L142
func (h SignModeHandler) getFirstSigner(txData signing.TxData) (string, error) {
for _, anyMsg := range txData.Body.Messages {
msg, err := anyutil.Unpack(anyMsg, h.fileResolver, h.typeResolver)
if err != nil {
return "", err
}
signer, err := h.signersContext.GetSigners(msg)
if err != nil {
return "", err
}
return signer[0], nil
if len(txData.Body.Messages) == 0 {
return "", fmt.Errorf("no signer found")
}

msg, err := anyutil.Unpack(txData.Body.Messages[0], h.fileResolver, h.typeResolver)
if err != nil {
return "", err
}
signer, err := h.signersContext.GetSigners(msg)
if err != nil {
return "", err
}
return "", fmt.Errorf("no signer found")
return signer[0], nil
}

// GetSignBytes implements signing.SignModeHandler.GetSignBytes.
Expand All @@ -106,7 +107,7 @@ func (h SignModeHandler) GetSignBytes(
signDocDirectAux := &txv1beta1.SignDocDirectAux{
BodyBytes: txData.BodyBytes,
PublicKey: signerData.PubKey,
ChainId: signerData.ChainId,
ChainId: signerData.ChainID,
AccountNumber: signerData.AccountNumber,
Sequence: signerData.Sequence,
Tip: txData.AuthInfo.Tip,
Expand Down
4 changes: 2 additions & 2 deletions x/tx/signing/directaux/direct_aux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestDirectAuxHandler(t *testing.T) {
}

signingData := signing.SignerData{
ChainId: chainID,
ChainID: chainID,
AccountNumber: accNum,
Sequence: accSeq,
Address: "",
Expand All @@ -88,7 +88,7 @@ func TestDirectAuxHandler(t *testing.T) {

t.Log("verify fee payer cannot use SIGN_MODE_DIRECT_AUX")
feePayerSigningData := signing.SignerData{
ChainId: chainID,
ChainID: chainID,
AccountNumber: accNum,
Address: feePayerAddr,
PubKey: anyPk,
Expand Down
2 changes: 1 addition & 1 deletion x/tx/signing/get_signers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type getSignersFunc func(proto.Message) []string

func getSignersFieldNames(descriptor protoreflect.MessageDescriptor) ([]string, error) {
signersFields := proto.GetExtension(descriptor.Options(), msgv1.E_Signer).([]string)
if signersFields == nil || len(signersFields) == 0 {
if len(signersFields) == 0 {
return nil, fmt.Errorf("no cosmos.msg.v1.signer option found for message %s", descriptor.FullName())
}

Expand Down
4 changes: 2 additions & 2 deletions x/tx/signing/signer_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ type SignerData struct {
// In case of multisigs, this should be the multisig's address.
Address string

// ChainId is the chain that this transaction is targeted
ChainId string
// ChainID is the chain that this transaction is targeting.
ChainID string

// AccountNumber is the account number of the signer.
//
Expand Down
4 changes: 2 additions & 2 deletions x/tx/signing/testutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

type HandlerArgumentOptions struct {
ChainId string
ChainID string
Memo string
Msg proto.Message
AccNum uint64
Expand Down Expand Up @@ -79,7 +79,7 @@ func MakeHandlerArguments(options HandlerArgumentOptions) (signing.SignerData, s

signerAddress := options.SignerAddress
signerData := signing.SignerData{
ChainId: options.ChainId,
ChainID: options.ChainID,
AccountNumber: options.AccNum,
Sequence: options.AccSeq,
Address: signerAddress,
Expand Down
6 changes: 3 additions & 3 deletions x/tx/signing/textual/any_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"cosmossdk.io/x/tx/signing/textual"
)

type anyJsonTest struct {
type anyJSONTest struct {
Proto json.RawMessage
Screens []textual.Screen
}
Expand All @@ -35,7 +35,7 @@ func TestAny(t *testing.T) {
raw, err := os.ReadFile("./internal/testdata/any.json")
require.NoError(t, err)

var testcases []anyJsonTest
var testcases []anyJSONTest
err = json.Unmarshal(raw, &testcases)
require.NoError(t, err)

Expand All @@ -59,7 +59,7 @@ func TestAny(t *testing.T) {
parsedMsg := val.Message().Interface()
require.IsType(t, &anypb.Any{}, parsedMsg)
parsedAny := parsedMsg.(*anypb.Any)
diff := cmp.Diff(anyMsg, parsedAny, protocmp.Transform())
diff := cmp.Diff(&anyMsg, parsedAny, protocmp.Transform())
require.Empty(t, diff)
})
}
Expand Down
2 changes: 1 addition & 1 deletion x/tx/signing/textual/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"cosmossdk.io/x/tx/signing/textual"
)

func TestBytesJsonTestCases(t *testing.T) {
func TestBytesJSONTestCases(t *testing.T) {
var testcases []bytesTest
// Bytes.json contains bytes that are represented in base64 format, and
// their expected results in hex.
Expand Down
6 changes: 3 additions & 3 deletions x/tx/signing/textual/coin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func TestMetadataQuerier(t *testing.T) {
require.ErrorIs(t, err, expErr)
}

func TestCoinJsonTestcases(t *testing.T) {
var testcases []coinJsonTest
func TestCoinJSONTestcases(t *testing.T) {
var testcases []coinJSONTest
raw, err := os.ReadFile("./internal/testdata/coin.json")
require.NoError(t, err)
err = json.Unmarshal(raw, &testcases)
Expand Down Expand Up @@ -121,7 +121,7 @@ func TestCoinJsonTestcases(t *testing.T) {
// an error, otherwise match Text, then Parse() the text and expect it to
// match (via proto.Equals()) the original Proto. If the test case has no
// Proto, try to Parse() the Text and expect an error if Error is set.
type coinJsonTest struct {
type coinJSONTest struct {
Proto *basev1beta1.Coin
Metadata *bankv1beta1.Metadata
Error bool
Expand Down
8 changes: 4 additions & 4 deletions x/tx/signing/textual/coins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"cosmossdk.io/x/tx/signing/textual"
)

func TestCoinsJsonTestcases(t *testing.T) {
var testcases []coinsJsonTest
func TestCoinsJSONTestcases(t *testing.T) {
var testcases []coinsJSONTest
raw, err := os.ReadFile("./internal/testdata/coins.json")
require.NoError(t, err)
err = json.Unmarshal(raw, &testcases)
Expand Down Expand Up @@ -93,12 +93,12 @@ func checkCoinEqual(t *testing.T, coin, coin1 *basev1beta1.Coin) {
require.True(t, v.Equal(v1))
}

// coinsJsonTest is the type of test cases in the testdata file.
// coinsJSONTest is the type of test cases in the testdata file.
// If the test case has a Proto, try to Format() it. If Error is set, expect
// an error, otherwise match Text, then Parse() the text and expect it to
// match (via proto.Equals()) the original Proto. If the test case has no
// Proto, try to Parse() the Text and expect an error if Error is set.
type coinsJsonTest struct {
type coinsJSONTest struct {
Proto []*basev1beta1.Coin
Metadata map[string]*bankv1beta1.Metadata
Text string
Expand Down
2 changes: 1 addition & 1 deletion x/tx/signing/textual/dec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"cosmossdk.io/x/tx/signing/textual"
)

func TestDecJsonTestcases(t *testing.T) {
func TestDecJSONTestcases(t *testing.T) {
type decimalTest []string
var testcases []decimalTest
raw, err := os.ReadFile("./internal/testdata/decimals.json")
Expand Down
Loading

0 comments on commit 4cb71ce

Please sign in to comment.