style!: lint fixes for x/tx (#15748)

This commit is contained in:
Mark Rushakoff 2023-04-10 13:55:06 -04:00 committed by GitHub
parent 4684c854d4
commit 4cb71ceb6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 120 additions and 112 deletions

2
go.mod
View File

@ -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

4
go.sum
View File

@ -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=

View File

@ -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

View File

@ -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=

View File

@ -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

View File

@ -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,
@ -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,
@ -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,
@ -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,

View File

@ -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{

View File

@ -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

View File

@ -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) {

View File

@ -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,

View File

@ -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{

View File

@ -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)
}
}

View File

@ -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,
})
}

View File

@ -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,
}
@ -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)

View File

@ -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")
}
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 signer[0], nil
}
// GetSignBytes implements signing.SignModeHandler.GetSignBytes.
@ -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,

View File

@ -66,7 +66,7 @@ func TestDirectAuxHandler(t *testing.T) {
}
signingData := signing.SignerData{
ChainId: chainID,
ChainID: chainID,
AccountNumber: accNum,
Sequence: accSeq,
Address: "",
@ -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,

View File

@ -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())
}

View File

@ -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.
//

View File

@ -12,7 +12,7 @@ import (
)
type HandlerArgumentOptions struct {
ChainId string
ChainID string
Memo string
Msg proto.Message
AccNum uint64
@ -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,

View File

@ -26,7 +26,7 @@ import (
"cosmossdk.io/x/tx/signing/textual"
)
type anyJsonTest struct {
type anyJSONTest struct {
Proto json.RawMessage
Screens []textual.Screen
}
@ -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)
@ -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)
})
}

View File

@ -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.

View File

@ -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)
@ -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

View File

@ -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)
@ -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

View File

@ -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")

View File

@ -7,6 +7,7 @@ import (
"strconv"
"strings"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
dpb "google.golang.org/protobuf/types/known/durationpb"
)
@ -23,9 +24,9 @@ func NewDurationValueRenderer() ValueRenderer {
}
const (
min_sec = 60
hour_sec = 60 * min_sec
day_sec = 24 * hour_sec
minSec = 60
hourSec = 60 * minSec
daySec = 24 * hourSec
)
type factors struct {
@ -34,12 +35,12 @@ type factors struct {
func factorSeconds(x int64) factors {
var f factors
f.days = x / day_sec
x -= f.days * day_sec
f.hours = x / hour_sec
x -= f.hours * hour_sec
f.minutes = x / min_sec
x -= f.minutes * min_sec
f.days = x / daySec
x -= f.days * daySec
f.hours = x / hourSec
x -= f.hours * hourSec
f.minutes = x / minSec
x -= f.minutes * minSec
f.seconds = x
return f
}
@ -84,8 +85,7 @@ func (dr durationValueRenderer) Format(_ context.Context, v protoreflect.Value)
if duration.Seconds < 0 || duration.Nanos < 0 {
negative = true
// copy to avoid side-effecting our input
d := *duration
duration = &d
duration = proto.Clone(duration).(*dpb.Duration)
duration.Seconds *= -1
duration.Nanos *= -1
}
@ -172,7 +172,7 @@ func (dr durationValueRenderer) Parse(_ context.Context, screens []Screen) (prot
}
dur := &dpb.Duration{}
dur.Seconds = days*day_sec + hours*hour_sec + minutes*min_sec + seconds
dur.Seconds = days*daySec + hours*hourSec + minutes*minSec + seconds
// #nosec G701
// Since there are 9 digits or fewer, this conversion is safe.
dur.Nanos = int32(nanos)

View File

@ -22,16 +22,16 @@ import (
"cosmossdk.io/x/tx/signing/textual/internal/textualpb"
)
type e2eJsonTest struct {
txJsonTest
type e2eJSONTest struct {
txJSONTest
Cbor string
}
func TestE2EJsonTestcases(t *testing.T) {
func TestE2EJSONTestcases(t *testing.T) {
raw, err := os.ReadFile("./internal/testdata/e2e.json")
require.NoError(t, err)
var testcases []e2eJsonTest
var testcases []e2eJSONTest
err = json.Unmarshal(raw, &testcases)
require.NoError(t, err)
@ -49,7 +49,7 @@ func TestE2EJsonTestcases(t *testing.T) {
AuthInfoBytes: authInfoBz,
SignerData: &textualpb.SignerData{
Address: signerData.Address,
ChainId: signerData.ChainId,
ChainId: signerData.ChainID,
AccountNumber: signerData.AccountNumber,
Sequence: signerData.Sequence,
PubKey: signerData.PubKey,

View File

@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/require"
)
type encodingJsonTest struct {
type encodingJSONTest struct {
Screens []Screen
Encoding string
}
@ -20,7 +20,7 @@ func TestEncodingJson(t *testing.T) {
raw, err := os.ReadFile("./internal/testdata/encode.json")
require.NoError(t, err)
var testcases []encodingJsonTest
var testcases []encodingJSONTest
err = json.Unmarshal(raw, &testcases)
require.NoError(t, err)

View File

@ -22,7 +22,7 @@ type enumTest struct {
Text string
}
func TestEnumJsonTestcases(t *testing.T) {
func TestEnumJSONTestcases(t *testing.T) {
var testcases []enumTest
raw, err := os.ReadFile("./internal/testdata/enum.json")
require.NoError(t, err)
@ -61,11 +61,16 @@ func TestEnumJsonTestcases(t *testing.T) {
// treats empty and default values as the same, we actually parse the protojson
// encoded string to retrieve which field is set.
func getFd(proto json.RawMessage, m *testpb.Baz) protoreflect.FieldDescriptor {
if strings.Contains(string(proto), `"ee"`) {
return m.ProtoReflect().Descriptor().Fields().ByNumber(1)
} else if strings.Contains(string(proto), `"ie"`) {
return m.ProtoReflect().Descriptor().Fields().ByNumber(2)
} else {
return m.ProtoReflect().Descriptor().Fields().ByNumber(3)
var fnum protoreflect.FieldNumber
switch {
case strings.Contains(string(proto), `"ee"`):
fnum = 1
case strings.Contains(string(proto), `"ie"`):
fnum = 2
default:
fnum = 3
}
return m.ProtoReflect().Descriptor().Fields().ByNumber(fnum)
}

View File

@ -62,7 +62,7 @@ func FuzzTimestampJSONParseToParseRoundTrip(f *testing.F) {
f.Add(seed)
f.Fuzz(func(t *testing.T, input []byte) {
var testCases []timestampJsonTest
var testCases []timestampJSONTest
if err := json.Unmarshal(input, &testCases); err != nil {
return
}

View File

@ -163,7 +163,7 @@ func (r *SignModeHandler) GetMessageValueRenderer(md protoreflect.MessageDescrip
func (r *SignModeHandler) init() {
if r.scalars == nil {
r.scalars = map[string]ValueRendererCreator{}
r.scalars["cosmos.Int"] = func(fd protoreflect.FieldDescriptor) ValueRenderer { return NewIntValueRenderer(fd) }
r.scalars["cosmos.Int"] = NewIntValueRenderer
r.scalars["cosmos.Dec"] = func(_ protoreflect.FieldDescriptor) ValueRenderer { return NewDecValueRenderer() }
}
if r.messages == nil {
@ -195,7 +195,7 @@ func (r *SignModeHandler) GetSignBytes(ctx context.Context, signerData signing.S
AuthInfoBytes: txData.AuthInfoBytes,
SignerData: &textualpb.SignerData{
Address: signerData.Address,
ChainId: signerData.ChainId,
ChainId: signerData.ChainID,
AccountNumber: signerData.AccountNumber,
Sequence: signerData.Sequence,
PubKey: signerData.PubKey,

View File

@ -15,7 +15,7 @@ import (
"cosmossdk.io/x/tx/signing/textual"
)
func TestIntJsonTestcases(t *testing.T) {
func TestIntJSONTestcases(t *testing.T) {
type integerTest []string
var testcases []integerTest
raw, err := os.ReadFile("./internal/testdata/integers.json")

View File

@ -23,20 +23,22 @@ func EmptyCoinMetadataQuerier(ctx context.Context, denom string) (*bankv1beta1.M
return nil, nil
}
type messageJsonTest struct {
type messageJSONTest struct {
Proto *testpb.Foo
Screens []textual.Screen
}
func TestMessageJsonTestcases(t *testing.T) {
func TestMessageJSONTestcases(t *testing.T) {
raw, err := os.ReadFile("./internal/testdata/message.json")
require.NoError(t, err)
var testcases []messageJsonTest
var testcases []messageJSONTest
err = json.Unmarshal(raw, &testcases)
require.NoError(t, err)
tr, err := textual.NewSignModeHandler(textual.SignModeOptions{CoinMetadataQuerier: EmptyCoinMetadataQuerier})
require.NoError(t, err)
for i, tc := range testcases {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
rend := textual.NewMessageValueRenderer(tr, (&testpb.Foo{}).ProtoReflect().Descriptor())

View File

@ -16,16 +16,16 @@ import (
"cosmossdk.io/x/tx/signing/textual"
)
type repeatedJsonTest struct {
type repeatedJSONTest struct {
Proto *testpb.Qux
Screens []textual.Screen
}
func TestRepeatedJsonTestcases(t *testing.T) {
func TestRepeatedJSONTestcases(t *testing.T) {
raw, err := os.ReadFile("./internal/testdata/repeated.json")
require.NoError(t, err)
var testcases []repeatedJsonTest
var testcases []repeatedJSONTest
err = json.Unmarshal(raw, &testcases)
require.NoError(t, err)

View File

@ -12,15 +12,15 @@ import (
"google.golang.org/protobuf/reflect/protoreflect"
)
type stringJsonTest struct {
type stringJSONTest struct {
Text string
}
func TestStringJsonTestcases(t *testing.T) {
func TestStringJSONTestcases(t *testing.T) {
raw, err := os.ReadFile("./internal/testdata/string.json")
require.NoError(t, err)
var testcases []stringJsonTest
var testcases []stringJSONTest
err = json.Unmarshal(raw, &testcases)
require.NoError(t, err)

View File

@ -16,7 +16,7 @@ import (
tspb "google.golang.org/protobuf/types/known/timestamppb"
)
// timestampJsonTest is the type of test cases in the testdata file.
// timestampJSONTest 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
@ -24,26 +24,26 @@ import (
//
// The Timestamp proto seconds field is int64, but restricted in range
// by convention and will fit within a JSON number.
type timestampJsonTest struct {
type timestampJSONTest struct {
Proto *tspb.Timestamp
Error bool
Text string
}
func TestTimestampJsonTestcasesTestData(t *testing.T) {
func TestTimestampJSONTestcasesTestData(t *testing.T) {
raw, err := os.ReadFile("./internal/testdata/timestamp.json")
require.NoError(t, err)
testTimestampJsonTestcases(t, raw)
testTimestampJSONTestcases(t, raw)
}
// Tests to ensure that we compare standardized forms of the final timestamppb.Timestamp.
// Please see issue https://github.com/cosmos/cosmos-sdk/issues/15761
func TestTimestampJsonTestcasesExtraneousNanos(t *testing.T) {
testTimestampJsonTestcases(t, []byte(`[{"proto":{"nAnos":1000000000},"text":"1970-01-01T00:00:01Z"}]`))
testTimestampJSONTestcases(t, []byte(`[{"proto":{"nAnos":1000000000},"text":"1970-01-01T00:00:01Z"}]`))
}
func testTimestampJsonTestcases(t *testing.T, raw []byte) {
var testcases []timestampJsonTest
func testTimestampJSONTestcases(t *testing.T, raw []byte) {
var testcases []timestampJSONTest
err := json.Unmarshal(raw, &testcases)
require.NoError(t, err)

View File

@ -26,29 +26,29 @@ import (
"cosmossdk.io/x/tx/signing/textual/internal/textualpb"
)
// txJsonTestTx represents the type that in the JSON test
// txJSONTestTx represents the type that in the JSON test
// cases `proto` field. The inner contents are protojson
// encoded, so we represent them as []byte here, and decode
// them inside the test.
type txJsonTestTx struct {
type txJSONTestTx struct {
Body json.RawMessage
AuthInfo json.RawMessage `json:"auth_info"`
}
type txJsonTest struct {
type txJSONTest struct {
Name string
Proto txJsonTestTx
Proto txJSONTestTx
SignerData json.RawMessage `json:"signer_data"`
Metadata *bankv1beta1.Metadata
Error bool
Screens []textual.Screen
}
func TestTxJsonTestcases(t *testing.T) {
func TestTxJSONTestcases(t *testing.T) {
raw, err := os.ReadFile("./internal/testdata/tx.json")
require.NoError(t, err)
var testcases []txJsonTest
var testcases []txJSONTest
err = json.Unmarshal(raw, &testcases)
require.NoError(t, err)
@ -57,6 +57,8 @@ func TestTxJsonTestcases(t *testing.T) {
txBody, bodyBz, txAuthInfo, authInfoBz, signerData := createTextualData(t, tc.Proto, tc.SignerData)
tr, err := textual.NewSignModeHandler(textual.SignModeOptions{CoinMetadataQuerier: mockCoinMetadataQuerier})
require.NoError(t, err)
rend := textual.NewTxValueRenderer(tr)
ctx := addMetadataToContext(context.Background(), tc.Metadata)
@ -65,7 +67,7 @@ func TestTxJsonTestcases(t *testing.T) {
AuthInfoBytes: authInfoBz,
SignerData: &textualpb.SignerData{
Address: signerData.Address,
ChainId: signerData.ChainId,
ChainId: signerData.ChainID,
AccountNumber: signerData.AccountNumber,
Sequence: signerData.Sequence,
PubKey: signerData.PubKey,
@ -115,7 +117,7 @@ func TestTxJsonTestcases(t *testing.T) {
// createTextualData creates a Textual data give then JSON
// test case.
func createTextualData(t *testing.T, jsonTx txJsonTestTx, jsonSignerData json.RawMessage) (*txv1beta1.TxBody, []byte, *txv1beta1.AuthInfo, []byte, signing.SignerData) {
func createTextualData(t *testing.T, jsonTx txJSONTestTx, jsonSignerData json.RawMessage) (*txv1beta1.TxBody, []byte, *txv1beta1.AuthInfo, []byte, signing.SignerData) {
body := &txv1beta1.TxBody{}
authInfo := &txv1beta1.AuthInfo{}
protoSignerData := &textualpb.SignerData{}
@ -142,7 +144,7 @@ func createTextualData(t *testing.T, jsonTx txJsonTestTx, jsonSignerData json.Ra
func signerDataFromProto(d *textualpb.SignerData) signing.SignerData {
return signing.SignerData{
Address: d.Address,
ChainId: d.ChainId,
ChainID: d.ChainId,
AccountNumber: d.AccountNumber,
Sequence: d.Sequence,
PubKey: d.PubKey,