From 41f92723399ef0affa90c6b3d8e7b47b82361280 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 5 Mar 2024 21:57:30 +0100 Subject: [PATCH 1/3] feat(x/tx): add enum as string encoder option (#19618) --- client/v2/CHANGELOG.md | 1 + client/v2/autocli/query.go | 1 + x/tx/CHANGELOG.md | 22 ++++--- x/tx/go.mod | 6 +- x/tx/go.sum | 6 +- x/tx/signing/aminojson/aminojson.go | 1 + x/tx/signing/aminojson/encoder.go | 4 +- x/tx/signing/aminojson/json_marshal.go | 30 +++++++--- x/tx/signing/aminojson/json_marshal_test.go | 59 +++++++++++++++++++ .../textual/internal/testdata/e2e.json | 6 +- .../signing/textual/internal/testdata/tx.json | 8 +-- 11 files changed, 113 insertions(+), 31 deletions(-) diff --git a/client/v2/CHANGELOG.md b/client/v2/CHANGELOG.md index 3d2b21baa384..00ebfc727d27 100644 --- a/client/v2/CHANGELOG.md +++ b/client/v2/CHANGELOG.md @@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* [#19618](https://github.com/cosmos/cosmos-sdk/pull/19618) Marshal enum as string in queries. * [#19060](https://github.com/cosmos/cosmos-sdk/pull/19060) Use client context from root (or enhanced) command in autocli commands. * Note, the given command must have a `client.Context` in its context. * [#19216](https://github.com/cosmos/cosmos-sdk/pull/19216) Do not overwrite TxConfig, use directly the one provided in context. TxConfig should always be set in the `client.Context` in `root.go` of an app. diff --git a/client/v2/autocli/query.go b/client/v2/autocli/query.go index 7b9d8bdcbf00..d93edb4dfce7 100644 --- a/client/v2/autocli/query.go +++ b/client/v2/autocli/query.go @@ -111,6 +111,7 @@ func (b *Builder) BuildQueryMethodCommand(ctx context.Context, descriptor protor outputType := util.ResolveMessageType(b.TypeResolver, descriptor.Output()) encoderOptions := aminojson.EncoderOptions{ Indent: " ", + EnumAsString: true, DoNotSortFields: true, TypeResolver: b.TypeResolver, FileResolver: b.FileResolver, diff --git a/x/tx/CHANGELOG.md b/x/tx/CHANGELOG.md index bb5705875b16..4d475d2c64d0 100644 --- a/x/tx/CHANGELOG.md +++ b/x/tx/CHANGELOG.md @@ -31,14 +31,20 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] -### Bug Fixes +## v0.13.1 -* [#19265](https://github.com/cosmos/cosmos-sdk/pull/19265) Reject denoms that contain a comma. +### Features + +* [#19618](https://github.com/cosmos/cosmos-sdk/pull/19618) Add enum as string option to encoder. ### Improvements * [#18857](https://github.com/cosmos/cosmos-sdk/pull/18857) Moved `FormatCoins` from `core/coins` to this package under `signing/textual`. +### Bug Fixes + +* [#19265](https://github.com/cosmos/cosmos-sdk/pull/19265) Reject denoms that contain a comma. + ## v0.13.0 ### Improvements @@ -107,18 +113,18 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements * [#15871](https://github.com/cosmos/cosmos-sdk/pull/15871) - * `HandlerMap` now has a `DefaultMode()` getter method - * Textual types use `signing.ProtoFileResolver` instead of `protoregistry.Files` + * `HandlerMap` now has a `DefaultMode()` getter method + * Textual types use `signing.ProtoFileResolver` instead of `protoregistry.Files` ## v0.6.0 ### API Breaking * [#15709](https://github.com/cosmos/cosmos-sdk/pull/15709): - * `GetSignersContext` has been renamed to `signing.Context` - * `GetSigners` now returns `[][]byte` instead of `[]string` - * `GetSignersOptions` has been renamed to `signing.Options` and requires `address.Codec`s for account and validator addresses - * `GetSignersOptions.ProtoFiles` has been renamed to `signing.Options.FileResolver` + * `GetSignersContext` has been renamed to `signing.Context` + * `GetSigners` now returns `[][]byte` instead of `[]string` + * `GetSignersOptions` has been renamed to `signing.Options` and requires `address.Codec`s for account and validator addresses + * `GetSignersOptions.ProtoFiles` has been renamed to `signing.Options.FileResolver` ### Bug Fixes diff --git a/x/tx/go.mod b/x/tx/go.mod index 969b7b360261..b6841dc64c4c 100644 --- a/x/tx/go.mod +++ b/x/tx/go.mod @@ -21,8 +21,6 @@ require ( ) require ( - buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.32.0-20230509103710-5e5b9fdd0180.1 // indirect - buf.build/gen/go/tendermint/tendermint/protocolbuffers/go v1.32.0-20231117195010-33ed361a9051.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect @@ -37,4 +35,6 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace cosmossdk.io/api => ../../api +// NOTE: we do not want to replace to the development version of cosmossdk.io/api yet +// Until https://github.com/cosmos/cosmos-sdk/issues/19228 is resolved +// We are tagging x/tx from main and must keep using released versions of x/tx dependencies diff --git a/x/tx/go.sum b/x/tx/go.sum index 5065aad27c35..68c6a1e7ee63 100644 --- a/x/tx/go.sum +++ b/x/tx/go.sum @@ -1,7 +1,5 @@ -buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.32.0-20230509103710-5e5b9fdd0180.1 h1:7LKjxs607BNfGhtKLf+bi3SDJgpiGuTgOvemojsH8Hc= -buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.32.0-20230509103710-5e5b9fdd0180.1/go.mod h1:5GqIYthcy/ASmnKcaT26APpxMhZirnIHXHKki69zjWI= -buf.build/gen/go/tendermint/tendermint/protocolbuffers/go v1.32.0-20231117195010-33ed361a9051.1 h1:VooqQ3rklp3PwMTAE890M76w/8Z01OPa7RdgU9posFE= -buf.build/gen/go/tendermint/tendermint/protocolbuffers/go v1.32.0-20231117195010-33ed361a9051.1/go.mod h1:9KmeMJUsSG3IiIwK63Lh1ipZJrwd7KHrWZseJeHukcs= +cosmossdk.io/api v0.7.3 h1:V815i8YOwOAQa1rLCsSMjVG5Gnzs02JLq+l7ks8s1jk= +cosmossdk.io/api v0.7.3/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo= cosmossdk.io/core v0.11.0/go.mod h1:LaTtayWBSoacF5xNzoF8tmLhehqlA9z1SWiPuNC6X1w= cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= diff --git a/x/tx/signing/aminojson/aminojson.go b/x/tx/signing/aminojson/aminojson.go index 331087ed548e..5b0d9e4d0547 100644 --- a/x/tx/signing/aminojson/aminojson.go +++ b/x/tx/signing/aminojson/aminojson.go @@ -44,6 +44,7 @@ func NewSignModeHandler(options SignModeHandlerOptions) *SignModeHandler { h.encoder = NewEncoder(EncoderOptions{ FileResolver: options.FileResolver, TypeResolver: options.TypeResolver, + EnumAsString: false, // ensure enum as string is disabled }) } else { h.encoder = *options.Encoder diff --git a/x/tx/signing/aminojson/encoder.go b/x/tx/signing/aminojson/encoder.go index ddde5373b883..07a7c8ea0792 100644 --- a/x/tx/signing/aminojson/encoder.go +++ b/x/tx/signing/aminojson/encoder.go @@ -75,7 +75,7 @@ func nullSliceAsEmptyEncoder(enc *Encoder, v protoreflect.Value, w io.Writer) er _, err := io.WriteString(w, "[]") return err } - return enc.marshalList(list, w) + return enc.marshalList(list, nil /* no field descriptor available here */, w) default: return fmt.Errorf("unsupported type %T", list) } @@ -161,7 +161,7 @@ func thresholdStringEncoder(enc *Encoder, msg protoreflect.Message, w io.Writer) pubkeysField := fields.ByName("public_keys") pubkeys := msg.Get(pubkeysField).List() - err = enc.marshalList(pubkeys, w) + err = enc.marshalList(pubkeys, pubkeysField, w) if err != nil { return err } diff --git a/x/tx/signing/aminojson/json_marshal.go b/x/tx/signing/aminojson/json_marshal.go index aa8aa76b945e..800dfc7fd320 100644 --- a/x/tx/signing/aminojson/json_marshal.go +++ b/x/tx/signing/aminojson/json_marshal.go @@ -28,6 +28,9 @@ type EncoderOptions struct { Indent string // DoNotSortFields when set turns off sorting of field names. DoNotSortFields bool + // EnumAsString when set will encode enums as strings instead of integers. + // Caution: Enabling this option produce different sign bytes. + EnumAsString bool // TypeResolver is used to resolve protobuf message types by TypeURL when marshaling any packed messages. TypeResolver signing.TypeResolver // FileResolver is used to resolve protobuf file descriptors TypeURL when TypeResolver fails. @@ -45,6 +48,7 @@ type Encoder struct { typeResolver protoregistry.MessageTypeResolver doNotSortFields bool indent string + enumsAsString bool } // NewEncoder returns a new Encoder capable of serializing protobuf messages to JSON using the Amino JSON encoding @@ -78,6 +82,7 @@ func NewEncoder(options EncoderOptions) Encoder { typeResolver: options.TypeResolver, doNotSortFields: options.DoNotSortFields, indent: options.Indent, + enumsAsString: options.EnumAsString, } return enc } @@ -189,7 +194,7 @@ func (enc Encoder) beginMarshal(msg protoreflect.Message, writer io.Writer, isAn } } - err := enc.marshal(protoreflect.ValueOfMessage(msg), writer) + err := enc.marshal(protoreflect.ValueOfMessage(msg), nil /* no field descriptor needed here */, writer) if err != nil { return err } @@ -204,7 +209,7 @@ func (enc Encoder) beginMarshal(msg protoreflect.Message, writer io.Writer, isAn return nil } -func (enc Encoder) marshal(value protoreflect.Value, writer io.Writer) error { +func (enc Encoder) marshal(value protoreflect.Value, fd protoreflect.FieldDescriptor, writer io.Writer) error { switch val := value.Interface().(type) { case protoreflect.Message: err := enc.marshalMessage(val, writer) @@ -218,9 +223,20 @@ func (enc Encoder) marshal(value protoreflect.Value, writer io.Writer) error { _, err := io.WriteString(writer, "null") return err } - return enc.marshalList(val, writer) + return enc.marshalList(val, fd, writer) + + case string, bool, int32, uint32, []byte: + return jsonMarshal(writer, val) + + case protoreflect.EnumNumber: + if enc.enumsAsString && fd != nil { + desc := fd.Enum().Values().ByNumber(val) + if desc != nil { + _, err := io.WriteString(writer, fmt.Sprintf(`"%s"`, desc.Name())) + return err + } + } - case string, bool, int32, uint32, []byte, protoreflect.EnumNumber: return jsonMarshal(writer, val) case uint64, int64: @@ -342,7 +358,7 @@ func (enc Encoder) marshalMessage(msg protoreflect.Message, writer io.Writer) er return err } } else { - err = enc.marshal(v, writer) + err = enc.marshal(v, f, writer) if err != nil { return err } @@ -371,7 +387,7 @@ func jsonMarshal(w io.Writer, v interface{}) error { return err } -func (enc Encoder) marshalList(list protoreflect.List, writer io.Writer) error { +func (enc Encoder) marshalList(list protoreflect.List, fd protoreflect.FieldDescriptor, writer io.Writer) error { n := list.Len() _, err := io.WriteString(writer, "[") @@ -389,7 +405,7 @@ func (enc Encoder) marshalList(list protoreflect.List, writer io.Writer) error { } first = false - err = enc.marshal(list.Get(i), writer) + err = enc.marshal(list.Get(i), fd, writer) if err != nil { return err } diff --git a/x/tx/signing/aminojson/json_marshal_test.go b/x/tx/signing/aminojson/json_marshal_test.go index 7a2ff37c5c38..be8caf8c7364 100644 --- a/x/tx/signing/aminojson/json_marshal_test.go +++ b/x/tx/signing/aminojson/json_marshal_test.go @@ -268,3 +268,62 @@ func TestIndent(t *testing.T) { } }`, string(bz)) } + +func TestEnumAsString(t *testing.T) { + encoder := aminojson.NewEncoder(aminojson.EncoderOptions{Indent: " ", EnumAsString: true}) + + msg := &testpb.ABitOfEverything{ + Message: &testpb.NestedMessage{ + Foo: "test", + Bar: 0, // this is the default value and should be omitted from output + }, + Enum: testpb.AnEnum_ONE, + Repeated: []int32{3, -7, 2, 6, 4}, + Str: `abcxyz"foo"def`, + Bool: true, + Bytes: []byte{0, 1, 2, 3}, + I32: -15, + F32: 1001, + U32: 1200, + Si32: -376, + Sf32: -1000, + I64: 14578294827584932, + F64: 9572348124213523654, + U64: 4759492485, + Si64: -59268425823934, + Sf64: -659101379604211154, + } + + bz, err := encoder.Marshal(msg) + require.NoError(t, err) + fmt.Println(string(bz)) + require.Equal(t, `{ + "type": "ABitOfEverything", + "value": { + "bool": true, + "bytes": "AAECAw==", + "enum": "ONE", + "f32": 1001, + "f64": "9572348124213523654", + "i32": -15, + "i64": "14578294827584932", + "message": { + "foo": "test" + }, + "repeated": [ + 3, + -7, + 2, + 6, + 4 + ], + "sf32": -1000, + "sf64": "-659101379604211154", + "si32": -376, + "si64": "-59268425823934", + "str": "abcxyz\"foo\"def", + "u32": 1200, + "u64": "4759492485" + } +}`, string(bz)) +} diff --git a/x/tx/signing/textual/internal/testdata/e2e.json b/x/tx/signing/textual/internal/testdata/e2e.json index aaf11f9428b8..2ab0e30f5b96 100644 --- a/x/tx/signing/textual/internal/testdata/e2e.json +++ b/x/tx/signing/textual/internal/testdata/e2e.json @@ -213,7 +213,7 @@ "@type": "/cosmos.gov.v1.MsgVote", "proposal_id": 1, "voter": "cosmos1ulav3hsenupswqfkw2y3sup5kgtqwnvqa8eyhs", - "option": "VOTE_OPTION_ONE", + "option": "VOTE_OPTION_YES", "metadata": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Also it ends in a single ampersand @" } ], @@ -326,7 +326,7 @@ { "title": "Message (2/2)", "content": "/cosmos.gov.v1.MsgVote", "indent": 1 }, { "title": "Proposal id", "content": "1", "indent": 2 }, { "title": "Voter", "content": "cosmos1ulav3hsenupswqfkw2y3sup5kgtqwnvqa8eyhs", "indent": 2 }, - { "title": "Option", "content": "VOTE_OPTION_ONE", "indent": 2 }, + { "title": "Option", "content": "VOTE_OPTION_YES", "indent": 2 }, { "title": "Metadata", "content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Also it ends in a single ampersand @", @@ -374,6 +374,6 @@ { "content": "End of Non critical extension options", "expert": true }, { "title": "Hash of raw bytes", "content": "e7be7808de4985bd609811d2a32805cb233c168c7d247d61d37f4a6dd4cf3a2a", "expert": true } ], - "cbor": "a101983da20168436861696e20696402686d792d636861696ea2016e4163636f756e74206e756d626572026131a2016853657175656e6365026132a301674164647265737302782d636f736d6f7331756c6176336873656e7570737771666b77327933737570356b677471776e767161386579687304f5a3016a5075626c6963206b657902781f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657904f5a401634b657902785230324542204444374620453446442045423736204443384120323035452046363544203739304320443330452038413337203541354320323532382045423341203932334120463146422034443739203444030104f5a102781f54686973207472616e73616374696f6e206861732032204d65737361676573a3016d4d6573736167652028312f322902781d2f636f736d6f732e617574687a2e763162657461312e4d7367457865630301a301674772616e74656502782d636f736d6f7331756c6176336873656e7570737771666b77327933737570356b677471776e76716138657968730302a301644d73677302653120416e790302a3016a4d7367732028312f312902781c2f636f736d6f732e62616e6b2e763162657461312e4d736753656e640303a3016c46726f6d206164647265737302782d636f736d6f7331756c6176336873656e7570737771666b77327933737570356b677471776e76716138657968730304a3016a546f206164647265737302782d636f736d6f7331656a726634637572327779366b667572673966326a707070326833616665356836706b6835740304a30166416d6f756e74026731302041544f4d0304a2026b456e64206f66204d7367730302a3016d4d6573736167652028322f322902762f636f736d6f732e676f762e76312e4d7367566f74650301a3016b50726f706f73616c2069640261310302a30165566f74657202782d636f736d6f7331756c6176336873656e7570737771666b77327933737570356b677471776e76716138657968730302a301664f7074696f6e026f564f54455f4f5054494f4e5f4f4e450302a301684d65746164617461027901e34c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742c2073656420646f20656975736d6f642074656d706f7220696e6369646964756e74207574206c61626f726520657420646f6c6f7265206d61676e6120616c697175612e20557420656e696d206164206d696e696d2076656e69616d2c2071756973206e6f737472756420657865726369746174696f6e20756c6c616d636f206c61626f726973206e69736920757420616c697175697020657820656120636f6d6d6f646f20636f6e7365717561742e2044756973206175746520697275726520646f6c6f7220696e20726570726568656e646572697420696e20766f6c7570746174652076656c697420657373652063696c6c756d20646f6c6f726520657520667567696174206e756c6c612070617269617475722e204578636570746575722073696e74206f6363616563617420637570696461746174206e6f6e2070726f6964656e742c2073756e7420696e2063756c706120717569206f666669636961206465736572756e74206d6f6c6c697420616e696d20696420657374206c61626f72756d2e20416c736f20697420656e647320696e2020612073696e676c6520616d70657273616e6420400302a1026e456e64206f66204d657373616765a201644d656d6f0278193e20e29a9befb88f5c7532363942e29a9befb88f2020202020a2016446656573026a302e3030322041544f4da3016946656520706179657202782d636f736d6f7331656a726634637572327779366b667572673966326a707070326833616665356836706b68357404f5a3016b466565206772616e74657202782d636f736d6f7331756c6176336873656e7570737771666b77327933737570356b677471776e767161386579687304f5a30169476173206c696d697402673130302730303004f5a3016e54696d656f7574206865696768740262323004f5a3016c4f74686572207369676e6572026c31205369676e6572496e666f04f5a401724f74686572207369676e65722028312f312902715369676e6572496e666f206f626a656374030104f5a4016a5075626c6963206b65790278292f636f736d6f732e63727970746f2e6d756c74697369672e4c6567616379416d696e6f5075624b6579030204f5a401695468726573686f6c64026132030304f5a4016b5075626c6963206b65797302653220416e79030304f5a401715075626c6963206b6579732028312f322902781f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b6579030404f5a401634b657902785230323537203445424520304246432037353446203539363720334241312031423237203530304620393135382041444532204531374520314130312038324230204341384220433635322034444230203933030504f5a401715075626c6963206b6579732028322f322902781d2f636f736d6f732e63727970746f2e656432353531392e5075624b6579030404f5a401634b657902785230333135203043343720463138412041333237203136413620353437452044413842203733363920303637442043453131204431343120363234352042373738203735364320463833352039363738203737030504f5a30272456e64206f66205075626c6963206b657973030304f5a401694d6f646520696e666f026f4d6f6465496e666f206f626a656374030204f5a401654d756c7469026c4d756c7469206f626a656374030304f5a4016842697461727261790276436f6d706163744269744172726179206f626a656374030404f5a40171457874726120626974732073746f726564026135030504f5a40165456c656d7302623438030504f5a4016a4d6f646520696e666f73026a32204d6f6465496e666f030404f5a401704d6f646520696e666f732028312f3229026f4d6f6465496e666f206f626a656374030504f5a4016653696e676c65026d53696e676c65206f626a656374030604f5a401644d6f646502781b5349474e5f4d4f44455f4c45474143595f414d494e4f5f4a534f4e030704f5a401704d6f646520696e666f732028322f3229026f4d6f6465496e666f206f626a656374030504f5a4016653696e676c65026d53696e676c65206f626a656374030604f5a401644d6f646502781b5349474e5f4d4f44455f4c45474143595f414d494e4f5f4a534f4e030704f5a30271456e64206f66204d6f646520696e666f73030404f5a4016853657175656e6365026135030204f5a20273456e64206f66204f74686572207369676e657204f5a30171457874656e73696f6e206f7074696f6e7302653120416e7904f5a40177457874656e73696f6e206f7074696f6e732028312f31290278192f636f736d6f732e626173652e763162657461312e436f696e030104f5a30266352041544f4d030204f5a2027818456e64206f6620457874656e73696f6e206f7074696f6e7304f5a301781e4e6f6e20637269746963616c20657874656e73696f6e206f7074696f6e7302653120416e7904f5a40178244e6f6e20637269746963616c20657874656e73696f6e206f7074696f6e732028312f312902781b2f636f736d6f732e617574682e763162657461312e506172616d73030104f5a401734d6178206d656d6f206368617261637465727302623130030204f5a2027825456e64206f66204e6f6e20637269746963616c20657874656e73696f6e206f7074696f6e7304f5a3017148617368206f66207261772062797465730278406537626537383038646534393835626436303938313164326133323830356362323333633136386337643234376436316433376634613664643463663361326104f5" + "cbor": "a101983da20168436861696e20696402686d792d636861696ea2016e4163636f756e74206e756d626572026131a2016853657175656e6365026132a301674164647265737302782d636f736d6f7331756c6176336873656e7570737771666b77327933737570356b677471776e767161386579687304f5a3016a5075626c6963206b657902781f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657904f5a401634b657902785230324542204444374620453446442045423736204443384120323035452046363544203739304320443330452038413337203541354320323532382045423341203932334120463146422034443739203444030104f5a102781f54686973207472616e73616374696f6e206861732032204d65737361676573a3016d4d6573736167652028312f322902781d2f636f736d6f732e617574687a2e763162657461312e4d7367457865630301a301674772616e74656502782d636f736d6f7331756c6176336873656e7570737771666b77327933737570356b677471776e76716138657968730302a301644d73677302653120416e790302a3016a4d7367732028312f312902781c2f636f736d6f732e62616e6b2e763162657461312e4d736753656e640303a3016c46726f6d206164647265737302782d636f736d6f7331756c6176336873656e7570737771666b77327933737570356b677471776e76716138657968730304a3016a546f206164647265737302782d636f736d6f7331656a726634637572327779366b667572673966326a707070326833616665356836706b6835740304a30166416d6f756e74026731302041544f4d0304a2026b456e64206f66204d7367730302a3016d4d6573736167652028322f322902762f636f736d6f732e676f762e76312e4d7367566f74650301a3016b50726f706f73616c2069640261310302a30165566f74657202782d636f736d6f7331756c6176336873656e7570737771666b77327933737570356b677471776e76716138657968730302a301664f7074696f6e026f564f54455f4f5054494f4e5f5945530302a301684d65746164617461027901e34c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742c2073656420646f20656975736d6f642074656d706f7220696e6369646964756e74207574206c61626f726520657420646f6c6f7265206d61676e6120616c697175612e20557420656e696d206164206d696e696d2076656e69616d2c2071756973206e6f737472756420657865726369746174696f6e20756c6c616d636f206c61626f726973206e69736920757420616c697175697020657820656120636f6d6d6f646f20636f6e7365717561742e2044756973206175746520697275726520646f6c6f7220696e20726570726568656e646572697420696e20766f6c7570746174652076656c697420657373652063696c6c756d20646f6c6f726520657520667567696174206e756c6c612070617269617475722e204578636570746575722073696e74206f6363616563617420637570696461746174206e6f6e2070726f6964656e742c2073756e7420696e2063756c706120717569206f666669636961206465736572756e74206d6f6c6c697420616e696d20696420657374206c61626f72756d2e20416c736f20697420656e647320696e2020612073696e676c6520616d70657273616e6420400302a1026e456e64206f66204d657373616765a201644d656d6f0278193e20e29a9befb88f5c7532363942e29a9befb88f2020202020a2016446656573026a302e3030322041544f4da3016946656520706179657202782d636f736d6f7331656a726634637572327779366b667572673966326a707070326833616665356836706b68357404f5a3016b466565206772616e74657202782d636f736d6f7331756c6176336873656e7570737771666b77327933737570356b677471776e767161386579687304f5a30169476173206c696d697402673130302730303004f5a3016e54696d656f7574206865696768740262323004f5a3016c4f74686572207369676e6572026c31205369676e6572496e666f04f5a401724f74686572207369676e65722028312f312902715369676e6572496e666f206f626a656374030104f5a4016a5075626c6963206b65790278292f636f736d6f732e63727970746f2e6d756c74697369672e4c6567616379416d696e6f5075624b6579030204f5a401695468726573686f6c64026132030304f5a4016b5075626c6963206b65797302653220416e79030304f5a401715075626c6963206b6579732028312f322902781f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b6579030404f5a401634b657902785230323537203445424520304246432037353446203539363720334241312031423237203530304620393135382041444532204531374520314130312038324230204341384220433635322034444230203933030504f5a401715075626c6963206b6579732028322f322902781d2f636f736d6f732e63727970746f2e656432353531392e5075624b6579030404f5a401634b657902785230333135203043343720463138412041333237203136413620353437452044413842203733363920303637442043453131204431343120363234352042373738203735364320463833352039363738203737030504f5a30272456e64206f66205075626c6963206b657973030304f5a401694d6f646520696e666f026f4d6f6465496e666f206f626a656374030204f5a401654d756c7469026c4d756c7469206f626a656374030304f5a4016842697461727261790276436f6d706163744269744172726179206f626a656374030404f5a40171457874726120626974732073746f726564026135030504f5a40165456c656d7302623438030504f5a4016a4d6f646520696e666f73026a32204d6f6465496e666f030404f5a401704d6f646520696e666f732028312f3229026f4d6f6465496e666f206f626a656374030504f5a4016653696e676c65026d53696e676c65206f626a656374030604f5a401644d6f646502781b5349474e5f4d4f44455f4c45474143595f414d494e4f5f4a534f4e030704f5a401704d6f646520696e666f732028322f3229026f4d6f6465496e666f206f626a656374030504f5a4016653696e676c65026d53696e676c65206f626a656374030604f5a401644d6f646502781b5349474e5f4d4f44455f4c45474143595f414d494e4f5f4a534f4e030704f5a30271456e64206f66204d6f646520696e666f73030404f5a4016853657175656e6365026135030204f5a20273456e64206f66204f74686572207369676e657204f5a30171457874656e73696f6e206f7074696f6e7302653120416e7904f5a40177457874656e73696f6e206f7074696f6e732028312f31290278192f636f736d6f732e626173652e763162657461312e436f696e030104f5a30266352041544f4d030204f5a2027818456e64206f6620457874656e73696f6e206f7074696f6e7304f5a301781e4e6f6e20637269746963616c20657874656e73696f6e206f7074696f6e7302653120416e7904f5a40178244e6f6e20637269746963616c20657874656e73696f6e206f7074696f6e732028312f312902781b2f636f736d6f732e617574682e763162657461312e506172616d73030104f5a401734d6178206d656d6f206368617261637465727302623130030204f5a2027825456e64206f66204e6f6e20637269746963616c20657874656e73696f6e206f7074696f6e7304f5a3017148617368206f66207261772062797465730278406537626537383038646534393835626436303938313164326133323830356362323333633136386337643234376436316433376634613664643463663361326104f5" } ] diff --git a/x/tx/signing/textual/internal/testdata/tx.json b/x/tx/signing/textual/internal/testdata/tx.json index db7ea86eea75..bbafe3b14120 100644 --- a/x/tx/signing/textual/internal/testdata/tx.json +++ b/x/tx/signing/textual/internal/testdata/tx.json @@ -142,7 +142,7 @@ "@type": "/cosmos.gov.v1.MsgVote", "proposal_id": 1, "voter": "cosmos1ulav3hsenupswqfkw2y3sup5kgtqwnvqa8eyhs", - "option": "VOTE_OPTION_ONE", + "option": "VOTE_OPTION_YES", "metadata": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Also it ends in a single ampersand @" } ] @@ -193,7 +193,7 @@ { "title": "Message (1/1)", "content": "/cosmos.gov.v1.MsgVote", "indent": 1 }, { "title": "Proposal id", "content": "1", "indent": 2 }, { "title": "Voter", "content": "cosmos1ulav3hsenupswqfkw2y3sup5kgtqwnvqa8eyhs", "indent": 2 }, - { "title": "Option", "content": "VOTE_OPTION_ONE", "indent": 2 }, + { "title": "Option", "content": "VOTE_OPTION_YES", "indent": 2 }, { "title": "Metadata", "content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Also it ends in a single ampersand @", @@ -226,7 +226,7 @@ "@type": "/cosmos.gov.v1.MsgVote", "proposal_id": 1, "voter": "cosmos1ulav3hsenupswqfkw2y3sup5kgtqwnvqa8eyhs", - "option": "VOTE_OPTION_ONE", + "option": "VOTE_OPTION_YES", "metadata": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Also it ends in a single ampersand @" } ], @@ -339,7 +339,7 @@ { "title": "Message (2/2)", "content": "/cosmos.gov.v1.MsgVote", "indent": 1 }, { "title": "Proposal id", "content": "1", "indent": 2 }, { "title": "Voter", "content": "cosmos1ulav3hsenupswqfkw2y3sup5kgtqwnvqa8eyhs", "indent": 2 }, - { "title": "Option", "content": "VOTE_OPTION_ONE", "indent": 2 }, + { "title": "Option", "content": "VOTE_OPTION_YES", "indent": 2 }, { "title": "Metadata", "content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Also it ends in a single ampersand @", From 06a398931e0e4e0e1d0bac6832381e458e45ad24 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 6 Mar 2024 20:45:26 +0800 Subject: [PATCH 2/3] refactor(x/auth): allow empty public keys for GetSignBytesAdapter (#19651) --- CHANGELOG.md | 1 + x/auth/signing/adapter.go | 20 ++++++++++++-------- x/auth/signing/adapter_test.go | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 x/auth/signing/adapter_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index c5d15e6869f4..ddb50a0f026f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (crypto/keys) [#18026](https://github.com/cosmos/cosmos-sdk/pull/18026) Made public key generation constant time on `secp256k1` * (crypto | x/auth) [#14372](https://github.com/cosmos/cosmos-sdk/pull/18194) Key checks on signatures antehandle. * (types) [#18963](https://github.com/cosmos/cosmos-sdk/pull/18963) Swap out amino json encoding of `ABCIMessageLogs` for std lib json encoding +* (x/auth) [#19651](https://github.com/cosmos/cosmos-sdk/pull/19651) Allow empty public keys in `GetSignBytesAdapter`. ### Bug Fixes diff --git a/x/auth/signing/adapter.go b/x/auth/signing/adapter.go index bb0def2f230f..42b1b82fdc48 100644 --- a/x/auth/signing/adapter.go +++ b/x/auth/signing/adapter.go @@ -41,20 +41,24 @@ func GetSignBytesAdapter( return nil, err } - anyPk, err := codectypes.NewAnyWithValue(signerData.PubKey) - if err != nil { - return nil, err - } + var pubKey *anypb.Any + if signerData.PubKey != nil { + anyPk, err := codectypes.NewAnyWithValue(signerData.PubKey) + if err != nil { + return nil, err + } + pubKey = &anypb.Any{ + TypeUrl: anyPk.TypeUrl, + Value: anyPk.Value, + } + } txSignerData := txsigning.SignerData{ ChainID: signerData.ChainID, AccountNumber: signerData.AccountNumber, Sequence: signerData.Sequence, Address: signerData.Address, - PubKey: &anypb.Any{ - TypeUrl: anyPk.TypeUrl, - Value: anyPk.Value, - }, + PubKey: pubKey, } // Generate the bytes to be signed. return handlerMap.GetSignBytes(ctx, txSignMode, txSignerData, txData) diff --git a/x/auth/signing/adapter_test.go b/x/auth/signing/adapter_test.go new file mode 100644 index 000000000000..2a90b7030a36 --- /dev/null +++ b/x/auth/signing/adapter_test.go @@ -0,0 +1,34 @@ +package signing_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + + authsign "cosmossdk.io/x/auth/signing" + + "github.com/cosmos/cosmos-sdk/testutil/testdata" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/types/tx/signing" +) + +func TestGetSignBytesAdapterNoPublicKey(t *testing.T) { + encodingConfig := moduletestutil.MakeTestEncodingConfig() + txConfig := encodingConfig.TxConfig + _, _, addr := testdata.KeyTestPubAddr() + signerData := authsign.SignerData{ + Address: addr.String(), + ChainID: "test-chain", + AccountNumber: 11, + Sequence: 15, + } + w := txConfig.NewTxBuilder() + _, err := authsign.GetSignBytesAdapter( + context.Background(), + txConfig.SignModeHandler(), + signing.SignMode_SIGN_MODE_DIRECT, + signerData, + w.GetTx()) + require.NoError(t, err) +} From 25aea8af8a52823553ddc34bd91f46857d7a54dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Toledano?= Date: Wed, 6 Mar 2024 14:14:16 +0100 Subject: [PATCH 3/3] refactor!: remove global config from x/auth and client (#19447) --- CHANGELOG.md | 1 + UPGRADING.md | 9 ++- baseapp/abci_utils_test.go | 6 +- baseapp/baseapp_test.go | 9 +-- baseapp/msg_service_router_test.go | 3 +- client/context.go | 16 +++++ client/context_test.go | 3 +- client/grpc_query_test.go | 3 +- client/keys/add.go | 2 +- client/keys/add_ledger_test.go | 7 +- client/keys/add_test.go | 9 +-- client/keys/delete_test.go | 3 +- client/keys/export_test.go | 3 +- client/keys/import_test.go | 7 +- client/keys/list_test.go | 5 +- client/keys/migrate_test.go | 3 +- client/keys/parse.go | 34 +++++----- client/keys/parse_test.go | 6 +- client/keys/rename_test.go | 3 +- client/keys/show.go | 2 +- client/keys/show_test.go | 3 +- client/tx/aux_builder_test.go | 3 +- client/tx/tx_test.go | 9 ++- client/v2/autocli/common_test.go | 7 +- codec/any_test.go | 5 +- codec/testutil/codec.go | 64 +++++++++++++++---- codec/unknownproto/regression_test.go | 3 +- crypto/ledger/ledger_test.go | 2 +- server/util_test.go | 3 +- simapp/app.go | 15 +++-- simapp/simd/cmd/root.go | 9 ++- simapp/simd/cmd/root_v2.go | 8 ++- simapp/simd/cmd/testnet_test.go | 3 +- .../integration/auth/client/cli/suite_test.go | 3 +- tests/integration/bank/app_test.go | 9 +-- tests/integration/bank/bench_test.go | 5 +- .../bank/keeper/deterministic_test.go | 15 +++-- tests/integration/distribution/cli_tx_test.go | 3 +- .../distribution/keeper/msg_server_test.go | 21 +++--- .../evidence/keeper/infraction_test.go | 21 +++--- tests/integration/example/example_test.go | 11 +++- tests/integration/gov/keeper/keeper_test.go | 19 ++++-- .../slashing/keeper/keeper_test.go | 17 +++-- .../integration/staking/keeper/common_test.go | 17 +++-- .../staking/keeper/deterministic_test.go | 17 +++-- .../tx/aminojson/aminojson_test.go | 11 ++-- tests/integration/tx/decode_test.go | 5 +- testutil/integration/router.go | 5 +- testutil/key_test.go | 7 +- testutil/sims/simulation_helpers.go | 3 +- types/address.go | 25 ++++++++ types/config.go | 10 --- types/mempool/mempool_test.go | 3 +- types/module/testutil/codec.go | 22 ++++--- x/auth/CHANGELOG.md | 1 + x/auth/ante/feegrant_test.go | 4 +- x/auth/ante/sigverify_test.go | 19 +++++- x/auth/ante/testutil_test.go | 3 +- x/auth/client/cli/encode_test.go | 5 +- x/auth/client/tx_test.go | 7 +- x/auth/keeper/deterministic_test.go | 3 +- x/auth/keeper/keeper_test.go | 3 +- x/auth/signing/adapter_test.go | 3 +- x/auth/tx/aux_test.go | 3 +- x/auth/tx/config.go | 28 ++++---- x/auth/tx/config_test.go | 12 ++-- x/auth/types/genesis_test.go | 3 +- x/auth/vesting/types/vesting_account_test.go | 3 +- x/authz/client/cli/tx_test.go | 3 +- x/authz/keeper/genesis_test.go | 3 +- x/authz/keeper/keeper_test.go | 3 +- x/authz/migrations/v2/store_test.go | 3 +- x/authz/module/abci_test.go | 3 +- x/authz/simulation/decoder_test.go | 3 +- x/authz/simulation/genesis_test.go | 3 +- x/bank/client/cli/tx_test.go | 3 +- x/bank/keeper/collections_test.go | 3 +- x/bank/keeper/keeper_test.go | 5 +- x/circuit/ante/circuit_test.go | 3 +- x/circuit/keeper/genesis_test.go | 3 +- x/circuit/keeper/keeper_test.go | 3 +- x/consensus/keeper/keeper_test.go | 3 +- x/crisis/keeper/genesis_test.go | 3 +- x/crisis/keeper/keeper_test.go | 7 +- x/crisis/keeper/msg_server_test.go | 5 +- x/distribution/keeper/allocation_test.go | 7 +- x/distribution/keeper/delegation_test.go | 19 +++--- x/distribution/keeper/keeper_test.go | 3 +- .../migrations/v4/migrate_funds_test.go | 3 +- x/distribution/migrations/v4/migrate_test.go | 3 +- x/distribution/simulation/decoder_test.go | 3 +- x/evidence/keeper/keeper_test.go | 5 +- x/feegrant/client/cli/tx_test.go | 3 +- x/feegrant/filtered_fee_test.go | 3 +- x/feegrant/grant_test.go | 3 +- x/feegrant/keeper/genesis_test.go | 3 +- x/feegrant/keeper/keeper_test.go | 3 +- x/feegrant/migrations/v2/store_test.go | 3 +- x/feegrant/module/abci_test.go | 3 +- x/feegrant/simulation/decoder_test.go | 3 +- x/feegrant/simulation/genesis_test.go | 3 +- x/genutil/client/cli/genaccount_test.go | 3 +- x/genutil/client/cli/gentx_test.go | 3 +- x/genutil/client/cli/migrate_test.go | 3 +- x/genutil/gentx_test.go | 3 +- x/genutil/types/genesis_state_test.go | 5 +- x/gov/client/cli/tx_test.go | 3 +- x/gov/client/utils/query_test.go | 3 +- x/gov/keeper/common_test.go | 3 +- x/gov/migrations/v5/store_test.go | 3 +- x/gov/migrations/v6/store_test.go | 3 +- x/group/client/cli/tx_test.go | 3 +- x/group/keeper/genesis_test.go | 3 +- x/group/keeper/grpc_query_test.go | 3 +- x/group/keeper/keeper_test.go | 3 +- x/group/migrations/v2/migrate_test.go | 3 +- x/group/proposal_test.go | 3 +- x/group/simulation/decoder_test.go | 3 +- x/group/simulation/genesis_test.go | 3 +- x/mint/keeper/genesis_test.go | 3 +- x/mint/keeper/grpc_query_test.go | 3 +- x/mint/keeper/keeper_test.go | 3 +- x/mint/simulation/genesis_test.go | 5 +- x/nft/keeper/keeper_test.go | 3 +- x/nft/simulation/decoder_test.go | 3 +- x/nft/simulation/genesis_test.go | 3 +- x/params/keeper/common_test.go | 3 +- x/params/keeper/keeper_test.go | 3 +- x/params/types/subspace_test.go | 3 +- x/protocolpool/keeper/keeper_test.go | 3 +- x/slashing/keeper/keeper_test.go | 3 +- x/slashing/migrations/v4/migrate_test.go | 3 +- x/slashing/simulation/decoder_test.go | 3 +- x/staking/client/cli/tx_test.go | 3 +- x/staking/keeper/keeper_test.go | 3 +- x/staking/migrations/v5/migrations_test.go | 5 +- x/staking/simulation/decoder_test.go | 3 +- x/upgrade/keeper/abci_test.go | 5 +- x/upgrade/keeper/grpc_query_test.go | 3 +- x/upgrade/keeper/keeper_test.go | 3 +- 140 files changed, 570 insertions(+), 298 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ddb50a0f026f..49db792990e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -96,6 +96,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i ### API Breaking Changes +* (types) [#19447](https://github.com/cosmos/cosmos-sdk/pull/19447) `module.testutil.MakeTestEncodingConfig` now takes `CodecOptions` as argument. * (types) [#19512](https://github.com/cosmos/cosmos-sdk/pull/19512) Remove basic manager and all related functions (`module.BasicManager`, `module.NewBasicManager`, `module.NewBasicManagerFromManager`, `NewGenesisOnlyAppModule`). * The module manager now can do everything that the basic manager was doing. * When using runtime, just inject the module manager when needed using your app config. diff --git a/UPGRADING.md b/UPGRADING.md index b044b0265b3c..06e3f67ac225 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -12,16 +12,19 @@ In this section we describe the changes made in Cosmos SDK' SimApp. #### Client (`root.go`) -The `client` package has been refactored to make use of the address codecs (address, validator address, consensus address, etc.). +The `client` package has been refactored to make use of the address codecs (address, validator address, consensus address, etc.) +and address bech32 prefixes (address and validator address). This is part of the work of abstracting the SDK from the global bech32 config. -This means the address codecs must be provided in the `client.Context` in the application client (usually `root.go`). +This means the address codecs and prefixes must be provided in the `client.Context` in the application client (usually `root.go`). ```diff clientCtx = clientCtx. + WithAddressCodec(addressCodec). + WithValidatorAddressCodec(validatorAddressCodec). -+ WithConsensusAddressCodec(consensusAddressCodec) ++ WithConsensusAddressCodec(consensusAddressCodec). ++ WithAddressPrefix("cosmos"). ++ WithValidatorPrefix("cosmosvaloper") ``` **When using `depinject` / `app v2`, the client codecs can be provided directly from application config.** diff --git a/baseapp/abci_utils_test.go b/baseapp/abci_utils_test.go index f2b636fc39d3..a99177ac5225 100644 --- a/baseapp/abci_utils_test.go +++ b/baseapp/abci_utils_test.go @@ -469,9 +469,10 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection() // create a codec for marshaling cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) + signingCtx := cdc.InterfaceRegistry().SigningContext() // create a baseapp along with a tx config for tx generation - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) app := baseapp.NewBaseApp(s.T().Name(), log.NewNopLogger(), dbm.NewMemDB(), txConfig.TxDecoder()) // create a proposal handler @@ -566,7 +567,8 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection() func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_PriorityNonceMempoolTxSelection() { cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) + signingCtx := cdc.InterfaceRegistry().SigningContext() + txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) var ( secret1 = []byte("secret1") diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 68bea9795016..910be1a93e84 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -29,7 +29,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -65,8 +64,9 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite t.Helper() cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) + signingCtx := cdc.InterfaceRegistry().SigningContext() - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) db := dbm.NewMemDB() logBuffer := new(bytes.Buffer) logger := log.NewLogger(logBuffer, log.ColorOption(false)) @@ -499,11 +499,12 @@ func TestBaseAppOptionSeal(t *testing.T) { } func TestTxDecoder(t *testing.T) { - cdc := codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) + cdc := codectestutil.CodecOptions{}.NewCodec() baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) + signingCtx := cdc.InterfaceRegistry().SigningContext() // patch in TxConfig instead of using an output from x/auth/tx - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) tx := newTxCounter(t, txConfig, 1, 0) txBytes, err := txConfig.TxEncoder()(tx) diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index 2f9807997e25..725e90d79264 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -136,9 +136,10 @@ func TestMsgService(t *testing.T) { ), &appBuilder, &cdc, &interfaceRegistry) require.NoError(t, err) app := appBuilder.Build(dbm.NewMemDB(), nil) + signingCtx := interfaceRegistry.SigningContext() // patch in TxConfig instead of using an output from x/auth/tx - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) // set the TxDecoder in the BaseApp for minimal tx simulations app.SetTxDecoder(txConfig.TxDecoder()) diff --git a/client/context.go b/client/context.go index b93fab97840c..b4f8e54fe024 100644 --- a/client/context.go +++ b/client/context.go @@ -79,6 +79,10 @@ type Context struct { AddressCodec address.Codec ValidatorAddressCodec address.Codec ConsensusAddressCodec address.Codec + + // Bech32 address prefixes. + AddressPrefix string + ValidatorPrefix string } // WithCmdContext returns a copy of the context with an updated context.Context, @@ -337,6 +341,18 @@ func (ctx Context) WithConsensusAddressCodec(consensusAddressCodec address.Codec return ctx } +// WithAddressPrefix returns the context with the provided address bech32 prefix. +func (ctx Context) WithAddressPrefix(addressPrefix string) Context { + ctx.AddressPrefix = addressPrefix + return ctx +} + +// WithValidatorPrefix returns the context with the provided validator bech32 prefix. +func (ctx Context) WithValidatorPrefix(validatorPrefix string) Context { + ctx.ValidatorPrefix = validatorPrefix + return ctx +} + // PrintString prints the raw string to ctx.Output if it's defined, otherwise to os.Stdout func (ctx Context) PrintString(str string) error { return ctx.PrintBytes([]byte(str)) diff --git a/client/context_test.go b/client/context_test.go index 7c0397540c50..98c6d9f76752 100644 --- a/client/context_test.go +++ b/client/context_test.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -98,7 +99,7 @@ x: "10" } func TestGetFromFields(t *testing.T) { - cfg := testutil.MakeTestEncodingConfig() + cfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) path := hd.CreateHDPath(118, 0, 0).String() testCases := []struct { diff --git a/client/grpc_query_test.go b/client/grpc_query_test.go index a493fc548ff1..a07226e118b4 100644 --- a/client/grpc_query_test.go +++ b/client/grpc_query_test.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/integration" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -39,7 +40,7 @@ func (s *IntegrationTestSuite) SetupSuite() { keys := storetypes.NewKVStoreKeys(countertypes.StoreKey) cms := integration.CreateMultiStore(keys, logger) s.ctx = sdk.NewContext(cms, true, logger) - cfg := moduletestutil.MakeTestEncodingConfig(counter.AppModule{}) + cfg := moduletestutil.MakeTestEncodingConfig(testutil.CodecOptions{}, counter.AppModule{}) s.cdc = cfg.Codec queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, cfg.InterfaceRegistry) diff --git a/client/keys/add.go b/client/keys/add.go index 4e6e4f27f756..e61715f37399 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -269,7 +269,7 @@ func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf // If we're using ledger, only thing we need is the path and the bech32 prefix. if useLedger { - bech32PrefixAccAddr := sdk.GetConfig().GetBech32AccountAddrPrefix() + bech32PrefixAccAddr := ctx.AddressPrefix k, err := kb.SaveLedgerKey(name, hd.Secp256k1, bech32PrefixAccAddr, coinType, account, index) if err != nil { return err diff --git a/client/keys/add_ledger_test.go b/client/keys/add_ledger_test.go index 2e1865823c30..3d04cc5e3b92 100644 --- a/client/keys/add_ledger_test.go +++ b/client/keys/add_ledger_test.go @@ -15,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -39,7 +40,7 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) { // Prepare a keybase kbHome := t.TempDir() - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec clientCtx := client.Context{}. WithKeyringDir(kbHome). WithCodec(cdc). @@ -97,7 +98,7 @@ func Test_runAddCmdLedger(t *testing.T) { mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kbHome := t.TempDir() - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec clientCtx := client.Context{}. WithKeyringDir(kbHome). @@ -144,7 +145,7 @@ func Test_runAddCmdLedger(t *testing.T) { } func Test_runAddCmdLedgerDryRun(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec testData := []struct { name string args []string diff --git a/client/keys/add_test.go b/client/keys/add_test.go index 95cf3347810a..687aff609235 100644 --- a/client/keys/add_test.go +++ b/client/keys/add_test.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -28,7 +29,7 @@ func Test_runAddCmdBasic(t *testing.T) { mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kbHome := t.TempDir() - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, cdc) require.NoError(t, err) @@ -149,7 +150,7 @@ func Test_runAddCmdMultisigDupKeys(t *testing.T) { mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kbHome := t.TempDir() - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, cdc) require.NoError(t, err) @@ -217,7 +218,7 @@ func Test_runAddCmdDryRun(t *testing.T) { pubkey1 := `{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AtObiFVE4s+9+RX5SP8TN9r2mxpoaT4eGj9CJfK7VRzN"}` pubkey2 := `{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A/se1vkqgdQ7VJQCM4mxN+L+ciGhnnJ4XYsQCRBMrdRi"}` b64Pubkey := "QWhnOHhpdXBJcGZ2UlR2ak5la1ExclROUThTOW96YjdHK2RYQmFLVjl4aUo=" - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec testData := []struct { name string @@ -349,7 +350,7 @@ func Test_runAddCmdDryRun(t *testing.T) { func TestAddRecoverFileBackend(t *testing.T) { cmd := AddKeyCommand() cmd.Flags().AddFlagSet(Commands().PersistentFlags()) - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kbHome := t.TempDir() diff --git a/client/keys/delete_test.go b/client/keys/delete_test.go index dd1a38bd875b..69a5b8571207 100644 --- a/client/keys/delete_test.go +++ b/client/keys/delete_test.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -34,7 +35,7 @@ func Test_runDeleteCmd(t *testing.T) { fakeKeyName2 := "runDeleteCmd_Key2" path := sdk.GetFullBIP44Path() - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec cmd.SetArgs([]string{"blah", fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome)}) kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, cdc) diff --git a/client/keys/export_test.go b/client/keys/export_test.go index db49eb5b8c37..8da6922ca908 100644 --- a/client/keys/export_test.go +++ b/client/keys/export_test.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -19,7 +20,7 @@ import ( ) func Test_runExportCmd(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec testCases := []struct { name string keyringBackend string diff --git a/client/keys/import_test.go b/client/keys/import_test.go index 006f8ce672b2..bc9c5d34abb7 100644 --- a/client/keys/import_test.go +++ b/client/keys/import_test.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -18,7 +19,7 @@ import ( ) func Test_runImportCmd(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec testCases := []struct { name string keyringBackend string @@ -122,7 +123,7 @@ HbP+c6JmeJy9JXe2rbbF1QtCX1gLqGcDQPBXiCtFvP7/8wTZtVOPj8vREzhZ9ElO } func Test_runImportHexCmd(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec testCases := []struct { name string keyringBackend string @@ -184,7 +185,7 @@ func Test_runImportCmdWithEmptyName(t *testing.T) { mockIn := testutil.ApplyMockIODiscardOutErr(cmd) // Now add a temporary keybase kbHome := t.TempDir() - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, cdc) require.NoError(t, err) diff --git a/client/keys/list_test.go b/client/keys/list_test.go index b81a9d9aabaa..8f2752e5af9f 100644 --- a/client/keys/list_test.go +++ b/client/keys/list_test.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -39,7 +40,7 @@ func Test_runListCmd(t *testing.T) { kbHome2 := t.TempDir() mockIn := testutil.ApplyMockIODiscardOutErr(cmd) - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome2, mockIn, cdc) assert.NilError(t, err) @@ -92,7 +93,7 @@ func Test_runListCmd(t *testing.T) { func Test_runListKeyTypeCmd(t *testing.T) { cmd := ListKeyTypesCmd() - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec kbHome := t.TempDir() mockIn := testutil.ApplyMockIODiscardOutErr(cmd) diff --git a/client/keys/migrate_test.go b/client/keys/migrate_test.go index 4d3abe0007da..0e7adb4e6ca1 100644 --- a/client/keys/migrate_test.go +++ b/client/keys/migrate_test.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" @@ -41,7 +42,7 @@ func TestMigrateTestSuite(t *testing.T) { func (s *MigrateTestSuite) SetupSuite() { s.dir = s.T().TempDir() - s.cdc = moduletestutil.MakeTestEncodingConfig().Codec + s.cdc = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec s.appName = "cosmos" s.priv = cryptotypes.PrivKey(secp256k1.GenPrivKey()) s.pub = s.priv.PubKey() diff --git a/client/keys/parse.go b/client/keys/parse.go index 5fb34935c477..62bb5f75011a 100644 --- a/client/keys/parse.go +++ b/client/keys/parse.go @@ -11,19 +11,20 @@ import ( "github.com/spf13/cobra" "sigs.k8s.io/yaml" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/bech32" ) -func bech32Prefixes(config *sdk.Config) []string { +func bech32Prefixes(mainBech32Prefix string) []string { return []string{ - config.GetBech32AccountAddrPrefix(), - config.GetBech32AccountPubPrefix(), - config.GetBech32ValidatorAddrPrefix(), - config.GetBech32ValidatorPubPrefix(), - config.GetBech32ConsensusAddrPrefix(), - config.GetBech32ConsensusPubPrefix(), + mainBech32Prefix, + sdk.GetBech32PrefixAccPub(mainBech32Prefix), + sdk.GetBech32PrefixValAddr(mainBech32Prefix), + sdk.GetBech32PrefixValPub(mainBech32Prefix), + sdk.GetBech32PrefixConsAddr(mainBech32Prefix), + sdk.GetBech32PrefixConsPub(mainBech32Prefix), } } @@ -44,8 +45,8 @@ type bech32Output struct { Formats []string `json:"formats"` } -func newBech32Output(config *sdk.Config, bs []byte) bech32Output { - bech32Prefixes := bech32Prefixes(config) +func newBech32Output(bech32Prefix string, bs []byte) bech32Output { + bech32Prefixes := bech32Prefixes(bech32Prefix) out := bech32Output{Formats: make([]string, len(bech32Prefixes))} for i, prefix := range bech32Prefixes { @@ -80,15 +81,18 @@ hexadecimal into bech32 cosmos prefixed format and vice versa. `, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - config, _ := sdk.GetSealedConfig(cmd.Context()) - return doParseKey(cmd, config, args) + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + return doParseKey(cmd, clientCtx.AddressPrefix, args) }, } return cmd } -func doParseKey(cmd *cobra.Command, config *sdk.Config, args []string) error { +func doParseKey(cmd *cobra.Command, bech32Prefix string, args []string) error { addr := strings.TrimSpace(args[0]) outstream := cmd.OutOrStdout() @@ -97,7 +101,7 @@ func doParseKey(cmd *cobra.Command, config *sdk.Config, args []string) error { } output, _ := cmd.Flags().GetString(flags.FlagOutput) - if !(runFromBech32(outstream, addr, output) || runFromHex(config, outstream, addr, output)) { + if !(runFromBech32(outstream, addr, output) || runFromHex(bech32Prefix, outstream, addr, output)) { return errors.New("couldn't find valid bech32 nor hex data") } @@ -117,13 +121,13 @@ func runFromBech32(w io.Writer, bech32str, output string) bool { } // print info from hex -func runFromHex(config *sdk.Config, w io.Writer, hexstr, output string) bool { +func runFromHex(bech32Prefix string, w io.Writer, hexstr, output string) bool { bz, err := hex.DecodeString(hexstr) if err != nil { return false } - displayParseKeyInfo(w, newBech32Output(config, bz), output) + displayParseKeyInfo(w, newBech32Output(bech32Prefix, bz), output) return true } diff --git a/client/keys/parse_test.go b/client/keys/parse_test.go index 687922db3c6c..650cb7c501f0 100644 --- a/client/keys/parse_test.go +++ b/client/keys/parse_test.go @@ -4,16 +4,12 @@ import ( "testing" "github.com/stretchr/testify/require" - - sdk "github.com/cosmos/cosmos-sdk/types" ) func TestParseKey(t *testing.T) { bech32str := "cosmos104ytdpvrx9284zd50v9ep8c6j7pua7dkk0x3ek" hexstr := "EB5AE9872103497EC092EF901027049E4F39200C60040D3562CD7F104A39F62E6E5A39A818F4" - config := sdk.NewConfig() - tests := []struct { name string args []string @@ -27,7 +23,7 @@ func TestParseKey(t *testing.T) { for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { - require.Equal(t, tt.wantErr, doParseKey(ParseKeyStringCommand(), config, tt.args) != nil) + require.Equal(t, tt.wantErr, doParseKey(ParseKeyStringCommand(), "cosmos", tt.args) != nil) }) } } diff --git a/client/keys/rename_test.go b/client/keys/rename_test.go index 62253d382be5..e67d0df8d4c8 100644 --- a/client/keys/rename_test.go +++ b/client/keys/rename_test.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -33,7 +34,7 @@ func Test_runRenameCmd(t *testing.T) { path := sdk.GetFullBIP44Path() - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, cdc) require.NoError(t, err) diff --git a/client/keys/show.go b/client/keys/show.go index fd2abe33b720..22c14ddaeb58 100644 --- a/client/keys/show.go +++ b/client/keys/show.go @@ -175,7 +175,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) { return err } - return ledger.ShowAddress(*ledgerItem.Path, pk, sdk.GetConfig().GetBech32AccountAddrPrefix()) + return ledger.ShowAddress(*ledgerItem.Path, pk, clientCtx.AddressPrefix) } return nil diff --git a/client/keys/show_test.go b/client/keys/show_test.go index 5d7f9c033263..ac6c162b5076 100644 --- a/client/keys/show_test.go +++ b/client/keys/show_test.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" @@ -56,7 +57,7 @@ func Test_runShowCmd(t *testing.T) { mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kbHome := t.TempDir() - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, cdc) require.NoError(t, err) diff --git a/client/tx/aux_builder_test.go b/client/tx/aux_builder_test.go index f177ba730a89..b0c7e3e874eb 100644 --- a/client/tx/aux_builder_test.go +++ b/client/tx/aux_builder_test.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -33,7 +34,7 @@ var ( func TestAuxTxBuilder(t *testing.T) { counterModule := counter.AppModule{} - cdc := moduletestutil.MakeTestEncodingConfig(counterModule).Codec + cdc := moduletestutil.MakeTestEncodingConfig(testutil.CodecOptions{}, counterModule).Codec reg := codectypes.NewInterfaceRegistry() testdata.RegisterInterfaces(reg) diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index 205f388fdbe3..8859531dbdd2 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -15,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -28,8 +29,10 @@ import ( ) func newTestTxConfig() (client.TxConfig, codec.Codec) { - encodingConfig := moduletestutil.MakeTestEncodingConfig() - return authtx.NewTxConfig(codec.NewProtoCodec(encodingConfig.InterfaceRegistry), authtx.DefaultSignModes), encodingConfig.Codec + encodingConfig := moduletestutil.MakeTestEncodingConfig(testutil.CodecOptions{}) + cdc := codec.NewProtoCodec(encodingConfig.InterfaceRegistry) + signingCtx := encodingConfig.InterfaceRegistry.SigningContext() + return authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes), encodingConfig.Codec } // mockContext is a mock client.Context to return arbitrary simulation response, used to @@ -153,7 +156,7 @@ func TestBuildUnsignedTx(t *testing.T) { } func TestBuildUnsignedTxWithWithExtensionOptions(t *testing.T) { - txCfg := moduletestutil.MakeBuilderTestTxConfig() + txCfg := moduletestutil.MakeBuilderTestTxConfig(testutil.CodecOptions{}) extOpts := []*codectypes.Any{ { TypeUrl: "/test", diff --git a/client/v2/autocli/common_test.go b/client/v2/autocli/common_test.go index c75eaa5b17a4..2850abc226f3 100644 --- a/client/v2/autocli/common_test.go +++ b/client/v2/autocli/common_test.go @@ -22,6 +22,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + "github.com/cosmos/cosmos-sdk/codec/testutil" sdkkeyring "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -51,7 +52,7 @@ func initFixture(t *testing.T) *fixture { clientConn, err := grpc.Dial(listener.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials())) assert.NilError(t, err) - encodingConfig := moduletestutil.MakeTestEncodingConfig(bank.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(testutil.CodecOptions{}, bank.AppModule{}) kr, err := sdkkeyring.New(sdk.KeyringServiceName(), sdkkeyring.BackendMemory, home, nil, encodingConfig.Codec) assert.NilError(t, err) @@ -62,8 +63,8 @@ func initFixture(t *testing.T) *fixture { banktypes.RegisterInterfaces(interfaceRegistry) clientCtx := client.Context{}. - WithAddressCodec(addresscodec.NewBech32Codec("cosmos")). - WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")). + WithAddressCodec(interfaceRegistry.SigningContext().AddressCodec()). + WithValidatorAddressCodec(interfaceRegistry.SigningContext().ValidatorAddressCodec()). WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons")). WithKeyring(kr). WithKeyringDir(home). diff --git a/codec/any_test.go b/codec/any_test.go index ccb63f129682..d9996ec3d3c4 100644 --- a/codec/any_test.go +++ b/codec/any_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -71,7 +72,7 @@ func TestMarshalAny(t *testing.T) { func TestMarshalProtoPubKey(t *testing.T) { require := require.New(t) - ccfg := testutil.MakeTestEncodingConfig() + ccfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) privKey := ed25519.GenPrivKey() pk := privKey.PubKey() @@ -111,7 +112,7 @@ func TestMarshalProtoPubKey(t *testing.T) { // helper functions func TestMarshalProtoInterfacePubKey(t *testing.T) { require := require.New(t) - ccfg := testutil.MakeTestEncodingConfig() + ccfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) privKey := ed25519.GenPrivKey() pk := privKey.PubKey() diff --git a/codec/testutil/codec.go b/codec/testutil/codec.go index 4887aa2727b5..c3c14ee1f40e 100644 --- a/codec/testutil/codec.go +++ b/codec/testutil/codec.go @@ -3,6 +3,7 @@ package testutil import ( "github.com/cosmos/gogoproto/proto" + coreaddress "cosmossdk.io/core/address" "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/codec" @@ -10,34 +11,45 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" ) -// CodecOptions are options for creating a test codec. +// CodecOptions are options for creating a test codec. If set, provided address codecs will be prioritized when +// building the InterfaceRegistry and ProtoCodec. If not set, new address bech32 codecs will be created using +// the provided prefixes. type CodecOptions struct { AccAddressPrefix string ValAddressPrefix string + AddressCodec coreaddress.Codec + ValidatorCodec coreaddress.Codec } -// NewInterfaceRegistry returns a new InterfaceRegistry with the given options. -func (o CodecOptions) NewInterfaceRegistry() codectypes.InterfaceRegistry { - accAddressPrefix := o.AccAddressPrefix - if accAddressPrefix == "" { - accAddressPrefix = "cosmos" +// NewCodecOptionsWithPrefixes returns CodecOptions with provided prefixes. +func NewCodecOptionsWithPrefixes(addressPrefix, validatorPrefix string) CodecOptions { + return CodecOptions{ + AccAddressPrefix: addressPrefix, + ValAddressPrefix: validatorPrefix, } +} - valAddressPrefix := o.ValAddressPrefix - if valAddressPrefix == "" { - valAddressPrefix = "cosmosvaloper" +// NewCodecOptionsWithCodecs returns CodecOptions with provided address codecs. +func NewCodecOptionsWithCodecs(addressCodec, validatorCodec coreaddress.Codec) CodecOptions { + return CodecOptions{ + AddressCodec: addressCodec, + ValidatorCodec: validatorCodec, } +} +// NewInterfaceRegistry returns a new InterfaceRegistry with the given options. +func (o CodecOptions) NewInterfaceRegistry() codectypes.InterfaceRegistry { ir, err := codectypes.NewInterfaceRegistryWithOptions(codectypes.InterfaceRegistryOptions{ ProtoFiles: proto.HybridResolver, SigningOptions: signing.Options{ - AddressCodec: address.NewBech32Codec(accAddressPrefix), - ValidatorAddressCodec: address.NewBech32Codec(valAddressPrefix), + AddressCodec: o.GetAddressCodec(), + ValidatorAddressCodec: o.GetValidatorCodec(), }, }) if err != nil { panic(err) } + return ir } @@ -45,3 +57,33 @@ func (o CodecOptions) NewInterfaceRegistry() codectypes.InterfaceRegistry { func (o CodecOptions) NewCodec() *codec.ProtoCodec { return codec.NewProtoCodec(o.NewInterfaceRegistry()) } + +// GetAddressCodec returns the address codec. If not address codec was provided it'll create a new one based on the +// bech32 prefix. +func (o CodecOptions) GetAddressCodec() coreaddress.Codec { + if o.AddressCodec != nil { + return o.AddressCodec + } + + accAddressPrefix := o.AccAddressPrefix + if accAddressPrefix == "" { + accAddressPrefix = "cosmos" + } + + return address.NewBech32Codec(accAddressPrefix) +} + +// GetValidatorCodec returns the validator address codec. If not validator codec was provided it'll create a new one +// based on the bech32 prefix. +func (o CodecOptions) GetValidatorCodec() coreaddress.Codec { + if o.ValidatorCodec != nil { + return o.ValidatorCodec + } + + valAddressPrefix := o.ValAddressPrefix + if valAddressPrefix == "" { + valAddressPrefix = "cosmosvaloper" + } + + return address.NewBech32Codec(valAddressPrefix) +} diff --git a/codec/unknownproto/regression_test.go b/codec/unknownproto/regression_test.go index 3473e6481c14..84ee71cc5838 100644 --- a/codec/unknownproto/regression_test.go +++ b/codec/unknownproto/regression_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/types/module/testutil" ) @@ -14,7 +15,7 @@ import ( // protowire.ConsumeFieldValue. Discovered from fuzzing. func TestBadBytesPassedIntoDecoder(t *testing.T) { data, _ := hex.DecodeString("0A9F010A9C200A2D2F6962632E636F72652E636F6E6E656374696F6E2E76312E4D7367436F6E6E656374696F584F75656E496E6974126B0A0D6962637A65726F636C69656E74120B6962637A65726F636F6E6E1A1C0A0C6962636F6E65636C69656E74120A6962636F6E65636F6E6E00002205312E302E302A283235454635364341373935313335453430393336384536444238313130463232413442453035433212080A0612040A0208011A40143342993E25DA936CDDC7BE3D8F603CA6E9661518D536D0C482E18A0154AA096E438A6B9BCADFCFC2F0D689DCCAF55B96399D67A8361B70F5DA13091E2F929") - cfg := testutil.MakeTestEncodingConfig() + cfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) decoder := cfg.TxConfig.TxDecoder() tx, err := decoder(data) diff --git a/crypto/ledger/ledger_test.go b/crypto/ledger/ledger_test.go index 1c742791a35f..a0ff890b935c 100644 --- a/crypto/ledger/ledger_test.go +++ b/crypto/ledger/ledger_test.go @@ -95,7 +95,7 @@ func TestPublicKeySafe(t *testing.T) { require.NoError(t, err) require.NotNil(t, priv) - require.Nil(t, ShowAddress(path, priv.PubKey(), sdk.GetConfig().GetBech32AccountAddrPrefix())) + require.Nil(t, ShowAddress(path, priv.PubKey(), "cosmos")) checkDefaultPubKey(t, priv) addr2 := sdk.AccAddress(priv.PubKey().Address()).String() diff --git a/server/util_test.go b/server/util_test.go index 2ec1a27bc6e7..11f5cbb208c9 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" @@ -450,7 +451,7 @@ func TestEmptyMinGasPrices(t *testing.T) { tempDir := t.TempDir() err := os.Mkdir(filepath.Join(tempDir, "config"), os.ModePerm) require.NoError(t, err) - encCfg := testutil.MakeTestEncodingConfig() + encCfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) // Run InitCmd to create necessary config files. clientCtx := client.Context{}.WithHomeDir(tempDir).WithCodec(encCfg.Codec) diff --git a/simapp/app.go b/simapp/app.go index 834c576c0f9e..be410d5d70dc 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -207,7 +207,8 @@ func NewSimApp( }) appCodec := codec.NewProtoCodec(interfaceRegistry) legacyAmino := codec.NewLegacyAmino() - txConfig := authtx.NewTxConfig(appCodec, authtx.DefaultSignModes) + signingCtx := interfaceRegistry.SigningContext() + txConfig := authtx.NewTxConfig(appCodec, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) std.RegisterLegacyAminoCodec(legacyAmino) std.RegisterInterfaces(interfaceRegistry) @@ -278,13 +279,11 @@ func NewSimApp( app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), logger), authtypes.NewModuleAddress(govtypes.ModuleName).String()) bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore) - addressCodec := authcodec.NewBech32Codec(sdk.Bech32MainPrefix) - // add keepers accountsKeeper, err := accounts.NewKeeper( appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[accounts.StoreKey]), logger), - addressCodec, + signingCtx.AddressCodec(), appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter(), @@ -300,7 +299,7 @@ func NewSimApp( } app.AccountsKeeper = accountsKeeper - app.AuthKeeper = authkeeper.NewAccountKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), logger), appCodec, authtypes.ProtoBaseAccount, maccPerms, addressCodec, sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + app.AuthKeeper = authkeeper.NewAccountKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), logger), appCodec, authtypes.ProtoBaseAccount, maccPerms, signingCtx.AddressCodec(), sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String()) app.BankKeeper = bankkeeper.NewBaseKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(keys[banktypes.StoreKey]), logger), @@ -315,6 +314,10 @@ func NewSimApp( txConfigOpts := authtx.ConfigOptions{ EnabledSignModes: enabledSignModes, TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper), + SigningOptions: &signing.Options{ + AddressCodec: signingCtx.AddressCodec(), + ValidatorAddressCodec: signingCtx.ValidatorAddressCodec(), + }, } txConfig, err = authtx.NewTxConfigWithOptions( appCodec, @@ -326,7 +329,7 @@ func NewSimApp( app.txConfig = txConfig app.StakingKeeper = stakingkeeper.NewKeeper( - appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), logger), app.AuthKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), authcodec.NewBech32Codec(sdk.Bech32PrefixValAddr), authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), + appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), logger), app.AuthKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), signingCtx.ValidatorAddressCodec(), authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), ) app.MintKeeper = mintkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[minttypes.StoreKey]), logger), app.StakingKeeper, app.AuthKeeper, app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String()) diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index f15e3d0c4966..e2c0fec47604 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -14,6 +14,7 @@ import ( "cosmossdk.io/x/auth/tx" authtxconfig "cosmossdk.io/x/auth/tx/config" "cosmossdk.io/x/auth/types" + txsigning "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" @@ -49,7 +50,9 @@ func NewRootCmd() *cobra.Command { WithValidatorAddressCodec(addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix())). WithConsensusAddressCodec(addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix())). WithHomeDir(simapp.DefaultNodeHome). - WithViper("") // uses by default the binary name as prefix + WithViper(""). // uses by default the binary name as prefix + WithAddressPrefix(sdk.GetConfig().GetBech32AccountAddrPrefix()). + WithValidatorPrefix(sdk.GetConfig().GetBech32ValidatorAddrPrefix()) rootCmd := &cobra.Command{ Use: "simd", @@ -80,6 +83,10 @@ func NewRootCmd() *cobra.Command { txConfigOpts := tx.ConfigOptions{ EnabledSignModes: enabledSignModes, TextualCoinMetadataQueryFn: authtxconfig.NewGRPCCoinMetadataQueryFn(initClientCtx), + SigningOptions: &txsigning.Options{ + AddressCodec: initClientCtx.InterfaceRegistry.SigningContext().AddressCodec(), + ValidatorAddressCodec: initClientCtx.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), + }, } txConfig, err := tx.NewTxConfigWithOptions( initClientCtx.Codec, diff --git a/simapp/simd/cmd/root_v2.go b/simapp/simd/cmd/root_v2.go index edbf0ea2cf50..796a4ce85ff2 100644 --- a/simapp/simd/cmd/root_v2.go +++ b/simapp/simd/cmd/root_v2.go @@ -7,6 +7,8 @@ import ( "github.com/spf13/cobra" + authv1 "cosmossdk.io/api/cosmos/auth/module/v1" + stakingv1 "cosmossdk.io/api/cosmos/staking/module/v1" "cosmossdk.io/client/v2/autocli" clientv2keyring "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/core/address" @@ -103,6 +105,8 @@ func ProvideClientContext( addressCodec address.Codec, validatorAddressCodec runtime.ValidatorAddressCodec, consensusAddressCodec runtime.ConsensusAddressCodec, + authConfig *authv1.Module, + stakingConfig *stakingv1.Module, ) client.Context { var err error @@ -116,7 +120,9 @@ func ProvideClientContext( WithValidatorAddressCodec(validatorAddressCodec). WithConsensusAddressCodec(consensusAddressCodec). WithHomeDir(simapp.DefaultNodeHome). - WithViper("") // uses by default the binary name as prefix + WithViper(""). // uses by default the binary name as prefix + WithAddressPrefix(authConfig.Bech32Prefix). + WithValidatorPrefix(stakingConfig.Bech32PrefixValidator) // Read the config to overwrite the default values with the values from the config file customClientTemplate, customClientConfig := initClientConfig() diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go index 60ba6126fb97..c78f3408dc9c 100644 --- a/simapp/simd/cmd/testnet_test.go +++ b/simapp/simd/cmd/testnet_test.go @@ -16,6 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/testutil/configurator" "github.com/cosmos/cosmos-sdk/types/module" @@ -46,7 +47,7 @@ func Test_TestnetCmd(t *testing.T) { require.Len(t, moduleManager.Modules, 7) home := t.TempDir() - encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, staking.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, staking.AppModule{}) logger := log.NewNopLogger() cfg, err := genutiltest.CreateDefaultCometConfig(home) require.NoError(t, err) diff --git a/tests/integration/auth/client/cli/suite_test.go b/tests/integration/auth/client/cli/suite_test.go index 454ff4e1b82e..963a313045c5 100644 --- a/tests/integration/auth/client/cli/suite_test.go +++ b/tests/integration/auth/client/cli/suite_test.go @@ -25,6 +25,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" @@ -56,7 +57,7 @@ func TestCLITestSuite(t *testing.T) { } func (s *CLITestSuite) SetupSuite() { - s.encCfg = testutilmod.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}, gov.AppModule{}) + s.encCfg = testutilmod.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, bank.AppModule{}, gov.AppModule{}) s.kr = keyring.NewInMemory(s.encCfg.Codec) s.baseCtx = client.Context{}. WithKeyring(s.kr). diff --git a/tests/integration/bank/app_test.go b/tests/integration/bank/app_test.go index e51ad0137323..eeca54284fff 100644 --- a/tests/integration/bank/app_test.go +++ b/tests/integration/bank/app_test.go @@ -26,6 +26,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" + cdctestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/runtime" @@ -175,7 +176,7 @@ func TestSendNotEnoughBalance(t *testing.T) { require.NoError(t, err) sendMsg := types.NewMsgSend(addr1Str, addr2Str, sdk.Coins{sdk.NewInt64Coin("foocoin", 100)}) header := header.Info{Height: baseApp.LastBlockHeight() + 1} - txConfig := moduletestutil.MakeTestTxConfig() + txConfig := moduletestutil.MakeTestTxConfig(cdctestutil.CodecOptions{}) _, _, err = simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, []sdk.Msg{sendMsg}, "", []uint64{origAccNum}, []uint64{origSeq}, false, false, priv1) require.Error(t, err) @@ -255,7 +256,7 @@ func TestMsgMultiSendWithAccounts(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { header := header.Info{Height: baseApp.LastBlockHeight() + 1} - txConfig := moduletestutil.MakeTestTxConfig() + txConfig := moduletestutil.MakeTestTxConfig(cdctestutil.CodecOptions{}) _, _, err := simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) if tc.expPass { require.NoError(t, err) @@ -308,7 +309,7 @@ func TestMsgMultiSendMultipleOut(t *testing.T) { for _, tc := range testCases { header := header.Info{Height: baseApp.LastBlockHeight() + 1} - txConfig := moduletestutil.MakeTestTxConfig() + txConfig := moduletestutil.MakeTestTxConfig(cdctestutil.CodecOptions{}) _, _, err := simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) require.NoError(t, err) @@ -363,7 +364,7 @@ func TestMsgMultiSendDependent(t *testing.T) { for _, tc := range testCases { header := header.Info{Height: baseApp.LastBlockHeight() + 1} - txConfig := moduletestutil.MakeTestTxConfig() + txConfig := moduletestutil.MakeTestTxConfig(cdctestutil.CodecOptions{}) _, _, err := simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) require.NoError(t, err) diff --git a/tests/integration/bank/bench_test.go b/tests/integration/bank/bench_test.go index 628d85a50eeb..b953a3f39ec9 100644 --- a/tests/integration/bank/bench_test.go +++ b/tests/integration/bank/bench_test.go @@ -15,6 +15,7 @@ import ( stakingtypes "cosmossdk.io/x/staking/types" "github.com/cosmos/cosmos-sdk/client" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" @@ -82,7 +83,7 @@ func BenchmarkOneBankSendTxPerBlock(b *testing.B) { _, err = baseApp.Commit() require.NoError(b, err) - txGen := moduletestutil.MakeTestTxConfig() + txGen := moduletestutil.MakeTestTxConfig(codectestutil.CodecOptions{}) txEncoder := txGen.TxEncoder() // pre-compute all txs @@ -140,7 +141,7 @@ func BenchmarkOneBankMultiSendTxPerBlock(b *testing.B) { _, err = baseApp.Commit() require.NoError(b, err) - txGen := moduletestutil.MakeTestTxConfig() + txGen := moduletestutil.MakeTestTxConfig(codectestutil.CodecOptions{}) txEncoder := txGen.TxEncoder() // pre-compute all txs diff --git a/tests/integration/bank/keeper/deterministic_test.go b/tests/integration/bank/keeper/deterministic_test.go index 3023f5f9248f..54d51b0e20b3 100644 --- a/tests/integration/bank/keeper/deterministic_test.go +++ b/tests/integration/bank/keeper/deterministic_test.go @@ -23,6 +23,7 @@ import ( _ "cosmossdk.io/x/staking" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/integration" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -63,7 +64,8 @@ type deterministicFixture struct { func initDeterministicFixture(t *testing.T) *deterministicFixture { t.Helper() keys := storetypes.NewKVStoreKeys(authtypes.StoreKey, banktypes.StoreKey) - cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}).Codec + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, bank.AppModule{}) + cdc := encodingCfg.Codec logger := log.NewTestLogger(t) cms := integration.CreateMultiStore(keys, logger) @@ -101,10 +103,13 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { authModule := auth.NewAppModule(cdc, accountKeeper, authsims.RandomGenesisAccounts) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper) - integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, map[string]appmodule.AppModule{ - authtypes.ModuleName: authModule, - banktypes.ModuleName: bankModule, - }) + integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, + encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), + encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), + map[string]appmodule.AppModule{ + authtypes.ModuleName: authModule, + banktypes.ModuleName: bankModule, + }) sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()) diff --git a/tests/integration/distribution/cli_tx_test.go b/tests/integration/distribution/cli_tx_test.go index e45c228a032b..f7e6767558e8 100644 --- a/tests/integration/distribution/cli_tx_test.go +++ b/tests/integration/distribution/cli_tx_test.go @@ -16,6 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" @@ -38,7 +39,7 @@ func TestCLITestSuite(t *testing.T) { } func (s *CLITestSuite) SetupSuite() { - s.encCfg = testutilmod.MakeTestEncodingConfig() + s.encCfg = testutilmod.MakeTestEncodingConfig(codectestutil.CodecOptions{}) s.kr = keyring.NewInMemory(s.encCfg.Codec) s.baseCtx = client.Context{}. WithKeyring(s.kr). diff --git a/tests/integration/distribution/keeper/msg_server_test.go b/tests/integration/distribution/keeper/msg_server_test.go index 4c4ee67abc76..962d6c8779e9 100644 --- a/tests/integration/distribution/keeper/msg_server_test.go +++ b/tests/integration/distribution/keeper/msg_server_test.go @@ -33,6 +33,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/integration" sdk "github.com/cosmos/cosmos-sdk/types" @@ -66,7 +67,8 @@ func initFixture(t *testing.T) *fixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, distrtypes.StoreKey, pooltypes.StoreKey, stakingtypes.StoreKey, ) - cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, distribution.AppModule{}, protocolpool.AppModule{}).Codec + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, bank.AppModule{}) + cdc := encodingCfg.Codec logger := log.NewTestLogger(t) cms := integration.CreateMultiStore(keys, logger) @@ -138,13 +140,16 @@ func initFixture(t *testing.T) *fixture { }, }) - integrationApp := integration.NewIntegrationApp(ctx, logger, keys, cdc, map[string]appmodule.AppModule{ - authtypes.ModuleName: authModule, - banktypes.ModuleName: bankModule, - stakingtypes.ModuleName: stakingModule, - distrtypes.ModuleName: distrModule, - pooltypes.ModuleName: poolModule, - }) + integrationApp := integration.NewIntegrationApp(ctx, logger, keys, cdc, + encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), + encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), + map[string]appmodule.AppModule{ + authtypes.ModuleName: authModule, + banktypes.ModuleName: bankModule, + stakingtypes.ModuleName: stakingModule, + distrtypes.ModuleName: distrModule, + pooltypes.ModuleName: poolModule, + }) sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()) diff --git a/tests/integration/evidence/keeper/infraction_test.go b/tests/integration/evidence/keeper/infraction_test.go index 1b0241ff87f8..5c9977d6c7c6 100644 --- a/tests/integration/evidence/keeper/infraction_test.go +++ b/tests/integration/evidence/keeper/infraction_test.go @@ -41,6 +41,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/runtime" @@ -87,7 +88,8 @@ func initFixture(tb testing.TB) *fixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, consensusparamtypes.StoreKey, evidencetypes.StoreKey, stakingtypes.StoreKey, slashingtypes.StoreKey, ) - cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, evidence.AppModule{}).Codec + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, evidence.AppModule{}) + cdc := encodingCfg.Codec logger := log.NewTestLogger(tb) cms := integration.CreateMultiStore(keys, logger) @@ -141,13 +143,16 @@ func initFixture(tb testing.TB) *fixture { slashingModule := slashing.NewAppModule(cdc, slashingKeeper, accountKeeper, bankKeeper, stakingKeeper, cdc.InterfaceRegistry()) evidenceModule := evidence.NewAppModule(*evidenceKeeper) - integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, map[string]appmodule.AppModule{ - authtypes.ModuleName: authModule, - banktypes.ModuleName: bankModule, - stakingtypes.ModuleName: stakingModule, - slashingtypes.ModuleName: slashingModule, - evidencetypes.ModuleName: evidenceModule, - }) + integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, + encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), + encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), + map[string]appmodule.AppModule{ + authtypes.ModuleName: authModule, + banktypes.ModuleName: bankModule, + stakingtypes.ModuleName: stakingModule, + slashingtypes.ModuleName: slashingModule, + evidencetypes.ModuleName: evidenceModule, + }) sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()) diff --git a/tests/integration/example/example_test.go b/tests/integration/example/example_test.go index 71a9acb8770c..e921c175021b 100644 --- a/tests/integration/example/example_test.go +++ b/tests/integration/example/example_test.go @@ -18,6 +18,7 @@ import ( minttypes "cosmossdk.io/x/mint/types" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/integration" sdk "github.com/cosmos/cosmos-sdk/types" @@ -29,7 +30,9 @@ import ( func Example() { // in this example we are testing the integration of the following modules: // - mint, which directly depends on auth, bank and staking - encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, mint.AppModule{}) + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, mint.AppModule{}) + signingCtx := encodingCfg.InterfaceRegistry.SigningContext() + keys := storetypes.NewKVStoreKeys(authtypes.StoreKey, minttypes.StoreKey) authority := authtypes.NewModuleAddress("gov").String() @@ -63,6 +66,8 @@ func Example() { logger, keys, encodingCfg.Codec, + signingCtx.AddressCodec(), + signingCtx.ValidatorAddressCodec(), map[string]appmodule.AppModule{ authtypes.ModuleName: authModule, minttypes.ModuleName: mintModule, @@ -118,7 +123,7 @@ func Example() { // That module has no dependency on other modules. func Example_oneModule() { // in this example we are testing the integration of the auth module: - encodingCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) keys := storetypes.NewKVStoreKeys(authtypes.StoreKey) authority := authtypes.NewModuleAddress("gov").String() @@ -147,6 +152,8 @@ func Example_oneModule() { logger, keys, encodingCfg.Codec, + encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), + encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), map[string]appmodule.AppModule{ authtypes.ModuleName: authModule, }, diff --git a/tests/integration/gov/keeper/keeper_test.go b/tests/integration/gov/keeper/keeper_test.go index 39e7bcd0fb9e..1a7b2608163c 100644 --- a/tests/integration/gov/keeper/keeper_test.go +++ b/tests/integration/gov/keeper/keeper_test.go @@ -29,6 +29,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/integration" sdk "github.com/cosmos/cosmos-sdk/types" @@ -52,7 +53,8 @@ func initFixture(tb testing.TB) *fixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, pooltypes.StoreKey, types.StoreKey, ) - cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}, gov.AppModule{}).Codec + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, bank.AppModule{}, gov.AppModule{}) + cdc := encodingCfg.Codec logger := log.NewTestLogger(tb) cms := integration.CreateMultiStore(keys, logger) @@ -128,12 +130,15 @@ func initFixture(tb testing.TB) *fixture { stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper) govModule := gov.NewAppModule(cdc, govKeeper, accountKeeper, bankKeeper, poolKeeper) - integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, map[string]appmodule.AppModule{ - authtypes.ModuleName: authModule, - banktypes.ModuleName: bankModule, - stakingtypes.ModuleName: stakingModule, - types.ModuleName: govModule, - }) + integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, + encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), + encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), + map[string]appmodule.AppModule{ + authtypes.ModuleName: authModule, + banktypes.ModuleName: bankModule, + stakingtypes.ModuleName: stakingModule, + types.ModuleName: govModule, + }) sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()) diff --git a/tests/integration/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go index 14936367c4a8..a74665167221 100644 --- a/tests/integration/slashing/keeper/keeper_test.go +++ b/tests/integration/slashing/keeper/keeper_test.go @@ -30,6 +30,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/integration" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -56,7 +57,8 @@ func initFixture(tb testing.TB) *fixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, slashingtypes.StoreKey, stakingtypes.StoreKey, ) - cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}).Codec + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) + cdc := encodingCfg.Codec logger := log.NewTestLogger(tb) cms := integration.CreateMultiStore(keys, logger) @@ -100,11 +102,14 @@ func initFixture(tb testing.TB) *fixture { stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper) slashingModule := slashing.NewAppModule(cdc, slashingKeeper, accountKeeper, bankKeeper, stakingKeeper, cdc.InterfaceRegistry()) - integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, map[string]appmodule.AppModule{ - banktypes.ModuleName: bankModule, - stakingtypes.ModuleName: stakingModule, - slashingtypes.ModuleName: slashingModule, - }) + integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, + encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), + encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), + map[string]appmodule.AppModule{ + banktypes.ModuleName: bankModule, + stakingtypes.ModuleName: stakingModule, + slashingtypes.ModuleName: slashingModule, + }) sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()) diff --git a/tests/integration/staking/keeper/common_test.go b/tests/integration/staking/keeper/common_test.go index 35f617450db3..f864019603c0 100644 --- a/tests/integration/staking/keeper/common_test.go +++ b/tests/integration/staking/keeper/common_test.go @@ -26,6 +26,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/integration" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -103,7 +104,8 @@ func initFixture(tb testing.TB) *fixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, types.StoreKey, ) - cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, staking.AppModule{}).Codec + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, staking.AppModule{}) + cdc := encodingCfg.Codec logger := log.NewTestLogger(tb) cms := integration.CreateMultiStore(keys, logger) @@ -147,11 +149,14 @@ func initFixture(tb testing.TB) *fixture { bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper) stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper) - integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, map[string]appmodule.AppModule{ - authtypes.ModuleName: authModule, - banktypes.ModuleName: bankModule, - types.ModuleName: stakingModule, - }) + integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, + encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), + encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), + map[string]appmodule.AppModule{ + authtypes.ModuleName: authModule, + banktypes.ModuleName: bankModule, + types.ModuleName: stakingModule, + }) sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()) diff --git a/tests/integration/staking/keeper/deterministic_test.go b/tests/integration/staking/keeper/deterministic_test.go index b8b9d134196d..961059c272f1 100644 --- a/tests/integration/staking/keeper/deterministic_test.go +++ b/tests/integration/staking/keeper/deterministic_test.go @@ -27,6 +27,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/runtime" @@ -68,7 +69,8 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, ) - cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, distribution.AppModule{}).Codec + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, distribution.AppModule{}) + cdc := encodingCfg.Codec logger := log.NewTestLogger(t) cms := integration.CreateMultiStore(keys, logger) @@ -111,11 +113,14 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper) stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper) - integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, map[string]appmodule.AppModule{ - authtypes.ModuleName: authModule, - banktypes.ModuleName: bankModule, - stakingtypes.ModuleName: stakingModule, - }) + integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, + encodingCfg.InterfaceRegistry.SigningContext().AddressCodec(), + encodingCfg.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), + map[string]appmodule.AppModule{ + authtypes.ModuleName: authModule, + banktypes.ModuleName: bankModule, + stakingtypes.ModuleName: stakingModule, + }) ctx := integrationApp.Context() diff --git a/tests/integration/tx/aminojson/aminojson_test.go b/tests/integration/tx/aminojson/aminojson_test.go index c66d43e7c991..c28ce9c0994f 100644 --- a/tests/integration/tx/aminojson/aminojson_test.go +++ b/tests/integration/tx/aminojson/aminojson_test.go @@ -61,6 +61,7 @@ import ( signing_testutil "cosmossdk.io/x/tx/signing/testutil" "cosmossdk.io/x/upgrade" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" ed25519types "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" @@ -92,8 +93,8 @@ import ( // by the mutation of genOpts passed to the generator. func TestAminoJSON_Equivalence(t *testing.T) { encCfg := testutil.MakeTestEncodingConfig( - auth.AppModule{}, authzmodule.AppModule{}, bank.AppModule{}, consensus.AppModule{}, - distribution.AppModule{}, evidence.AppModule{}, feegrantmodule.AppModule{}, + codectestutil.CodecOptions{}, auth.AppModule{}, authzmodule.AppModule{}, bank.AppModule{}, + consensus.AppModule{}, distribution.AppModule{}, evidence.AppModule{}, feegrantmodule.AppModule{}, gov.AppModule{}, groupmodule.AppModule{}, mint.AppModule{}, slashing.AppModule{}, staking.AppModule{}, upgrade.AppModule{}, vesting.AppModule{}) legacytx.RegressionTestingAminoCodec = encCfg.Amino @@ -208,7 +209,7 @@ func newAny(t *testing.T, msg proto.Message) *anypb.Any { // TestAminoJSON_LegacyParity tests that the Encoder encoder produces the same output as the Encoder encoder. func TestAminoJSON_LegacyParity(t *testing.T) { - encCfg := testutil.MakeTestEncodingConfig(auth.AppModule{}, authzmodule.AppModule{}, + encCfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, authzmodule.AppModule{}, bank.AppModule{}, distribution.AppModule{}, slashing.AppModule{}, staking.AppModule{}, vesting.AppModule{}, gov.AppModule{}) legacytx.RegressionTestingAminoCodec = encCfg.Amino @@ -512,7 +513,7 @@ func TestAminoJSON_LegacyParity(t *testing.T) { } func TestSendAuthorization(t *testing.T) { - encCfg := testutil.MakeTestEncodingConfig(auth.AppModule{}, authzmodule.AppModule{}, + encCfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, authzmodule.AppModule{}, distribution.AppModule{}, bank.AppModule{}) aj := aminojson.NewEncoder(aminojson.EncoderOptions{}) @@ -562,7 +563,7 @@ func TestSendAuthorization(t *testing.T) { } func TestDecimalMutation(t *testing.T) { - encCfg := testutil.MakeTestEncodingConfig(staking.AppModule{}) + encCfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, staking.AppModule{}) rates := &stakingtypes.CommissionRates{} rateBz, _ := encCfg.Amino.MarshalJSON(rates) require.Equal(t, `{"rate":"0","max_rate":"0","max_change_rate":"0"}`, string(rateBz)) diff --git a/tests/integration/tx/decode_test.go b/tests/integration/tx/decode_test.go index 8e228951823f..fae669f89f61 100644 --- a/tests/integration/tx/decode_test.go +++ b/tests/integration/tx/decode_test.go @@ -30,6 +30,7 @@ import ( "cosmossdk.io/x/upgrade" "github.com/cosmos/cosmos-sdk/codec/legacy" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/tests/integration/rapidgen" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -43,8 +44,8 @@ import ( // TestDecode tests that the tx decoder can decode all the txs in the test suite. func TestDecode(t *testing.T) { encCfg := testutil.MakeTestEncodingConfig( - auth.AppModule{}, authzmodule.AppModule{}, bank.AppModule{}, consensus.AppModule{}, - distribution.AppModule{}, evidence.AppModule{}, feegrantmodule.AppModule{}, + codectestutil.CodecOptions{}, auth.AppModule{}, authzmodule.AppModule{}, bank.AppModule{}, + consensus.AppModule{}, distribution.AppModule{}, evidence.AppModule{}, feegrantmodule.AppModule{}, gov.AppModule{}, groupmodule.AppModule{}, mint.AppModule{}, slashing.AppModule{}, staking.AppModule{}, upgrade.AppModule{}, vesting.AppModule{}) legacytx.RegressionTestingAminoCodec = encCfg.Amino diff --git a/testutil/integration/router.go b/testutil/integration/router.go index dafaa7f9d011..45fa80dbbf44 100644 --- a/testutil/integration/router.go +++ b/testutil/integration/router.go @@ -8,6 +8,7 @@ import ( cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" dbm "github.com/cosmos/cosmos-db" + "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" "cosmossdk.io/log" "cosmossdk.io/store" @@ -46,6 +47,8 @@ func NewIntegrationApp( logger log.Logger, keys map[string]*storetypes.KVStoreKey, appCodec codec.Codec, + addressCodec address.Codec, + validatorCodec address.Codec, modules map[string]appmodule.AppModule, ) *App { db := dbm.NewMemDB() @@ -54,7 +57,7 @@ func NewIntegrationApp( moduleManager := module.NewManagerFromMap(modules) moduleManager.RegisterInterfaces(interfaceRegistry) - txConfig := authtx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), authtx.DefaultSignModes) + txConfig := authtx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), addressCodec, validatorCodec, authtx.DefaultSignModes) bApp := baseapp.NewBaseApp(appName, logger, db, txConfig.TxDecoder(), baseapp.SetChainID(appName)) bApp.MountKVStores(keys) diff --git a/testutil/key_test.go b/testutil/key_test.go index 26847d764752..4a44bb4a6b75 100644 --- a/testutil/key_test.go +++ b/testutil/key_test.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/require" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/types" @@ -13,7 +14,7 @@ import ( func TestGenerateCoinKey(t *testing.T) { t.Parallel() - cdc := testutil.MakeTestEncodingConfig().Codec + cdc := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec addr, mnemonic, err := GenerateCoinKey(hd.Secp256k1, cdc) require.NoError(t, err) @@ -28,7 +29,7 @@ func TestGenerateCoinKey(t *testing.T) { func TestGenerateSaveCoinKey(t *testing.T) { t.Parallel() - encCfg := testutil.MakeTestEncodingConfig() + encCfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) kb, err := keyring.New(t.Name(), "test", t.TempDir(), nil, encCfg.Codec) require.NoError(t, err) @@ -53,7 +54,7 @@ func TestGenerateSaveCoinKey(t *testing.T) { func TestGenerateSaveCoinKeyOverwriteFlag(t *testing.T) { t.Parallel() - encCfg := testutil.MakeTestEncodingConfig() + encCfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) kb, err := keyring.New(t.Name(), "test", t.TempDir(), nil, encCfg.Codec) require.NoError(t, err) diff --git a/testutil/sims/simulation_helpers.go b/testutil/sims/simulation_helpers.go index a1147231c64b..ac2d5b871cf7 100644 --- a/testutil/sims/simulation_helpers.go +++ b/testutil/sims/simulation_helpers.go @@ -52,10 +52,11 @@ func SetupSimulation(config simtypes.Config, dirPrefix, dbName string, verbose, // SimulationOperations retrieves the simulation params from the provided file path // and returns all the modules weighted operations func SimulationOperations(app runtime.AppSimI, cdc codec.Codec, config simtypes.Config) []simtypes.WeightedOperation { + signingCtx := cdc.InterfaceRegistry().SigningContext() simState := module.SimulationState{ AppParams: make(simtypes.AppParams), Cdc: cdc, - TxConfig: authtx.NewTxConfig(cdc, authtx.DefaultSignModes), // TODO(tip): we should extract this from app + TxConfig: authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes), // TODO(tip): we should extract this from app BondDenom: sdk.DefaultBondDenom, } diff --git a/types/address.go b/types/address.go index 3cafd383eb87..8bb0d56fc4c8 100644 --- a/types/address.go +++ b/types/address.go @@ -71,6 +71,31 @@ const ( Bech32PrefixConsPub = Bech32MainPrefix + PrefixValidator + PrefixConsensus + PrefixPublic ) +// GetBech32PrefixAccPub returns the Bech32 prefix of an account's public key. +func GetBech32PrefixAccPub(mainPrefix string) string { + return mainPrefix + PrefixPublic +} + +// GetBech32PrefixValAddr returns the Bech32 prefix of a validator's operator address. +func GetBech32PrefixValAddr(mainPrefix string) string { + return mainPrefix + PrefixValidator + PrefixOperator +} + +// GetBech32PrefixValPub returns the Bech32 prefix of a validator's operator public key. +func GetBech32PrefixValPub(mainPrefix string) string { + return mainPrefix + PrefixValidator + PrefixOperator + PrefixPublic +} + +// GetBech32PrefixConsAddr returns the Bech32 prefix of a consensus node address. +func GetBech32PrefixConsAddr(mainPrefix string) string { + return mainPrefix + PrefixValidator + PrefixConsensus +} + +// GetBech32PrefixConsPub returns the Bech32 prefix of a consensus node public key. +func GetBech32PrefixConsPub(mainPrefix string) string { + return mainPrefix + PrefixValidator + PrefixConsensus + PrefixPublic +} + // cache variables var ( // AccAddress.String() is expensive and if unoptimized dominantly showed up in profiles, diff --git a/types/config.go b/types/config.go index 7f638f255e34..7089ceaff74b 100644 --- a/types/config.go +++ b/types/config.go @@ -13,7 +13,6 @@ const DefaultKeyringServiceName = "cosmos" // Config is the structure that holds the SDK configuration parameters. // This could be used to initialize certain configuration parameters for the SDK. type Config struct { - fullFundraiserPath string bech32AddressPrefix map[string]string mtx sync.RWMutex @@ -39,7 +38,6 @@ func NewConfig() *Config { "validator_pub": Bech32PrefixValPub, "consensus_pub": Bech32PrefixConsPub, }, - fullFundraiserPath: FullFundraiserPath, } } @@ -96,14 +94,6 @@ func (config *Config) SetBech32PrefixForConsensusNode(addressPrefix, pubKeyPrefi config.bech32AddressPrefix["consensus_pub"] = pubKeyPrefix } -// Set the FullFundraiserPath (BIP44Prefix) on the config. -// -// Deprecated: This method is supported for backward compatibility only and will be removed in a future release. Use SetPurpose and SetCoinType instead. -func (config *Config) SetFullFundraiserPath(fullFundraiserPath string) { - config.assertNotSealed() - config.fullFundraiserPath = fullFundraiserPath -} - // Seal seals the config such that the config state could not be modified further func (config *Config) Seal() *Config { config.mtx.Lock() diff --git a/types/mempool/mempool_test.go b/types/mempool/mempool_test.go index bab941ae611b..3dbd5f1349b0 100644 --- a/types/mempool/mempool_test.go +++ b/types/mempool/mempool_test.go @@ -14,6 +14,7 @@ import ( "cosmossdk.io/log" "cosmossdk.io/x/auth/signing" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/mempool" @@ -236,7 +237,7 @@ func (s *MempoolTestSuite) TestSampleTxs() { } func unmarshalTx(txBytes []byte) (sdk.Tx, error) { - cfg := moduletestutil.MakeTestEncodingConfig(counter.AppModule{}) + cfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, counter.AppModule{}) return cfg.TxConfig.TxJSONDecoder()(txBytes) } diff --git a/types/module/testutil/codec.go b/types/module/testutil/codec.go index 12bc63d9bacf..c6753e6b271e 100644 --- a/types/module/testutil/codec.go +++ b/types/module/testutil/codec.go @@ -22,15 +22,16 @@ type TestEncodingConfig struct { Amino *codec.LegacyAmino } -func MakeTestEncodingConfig(modules ...module.AppModule) TestEncodingConfig { +func MakeTestEncodingConfig(codecOpt testutil.CodecOptions, modules ...module.AppModule) TestEncodingConfig { aminoCodec := codec.NewLegacyAmino() - interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() - codec := codec.NewProtoCodec(interfaceRegistry) + interfaceRegistry := codecOpt.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(interfaceRegistry) + signingCtx := cdc.InterfaceRegistry().SigningContext() encCfg := TestEncodingConfig{ InterfaceRegistry: interfaceRegistry, - Codec: codec, - TxConfig: tx.NewTxConfig(codec, tx.DefaultSignModes), + Codec: cdc, + TxConfig: tx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes), Amino: aminoCodec, } @@ -43,10 +44,11 @@ func MakeTestEncodingConfig(modules ...module.AppModule) TestEncodingConfig { return encCfg } -func MakeTestTxConfig() client.TxConfig { - interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() +func MakeTestTxConfig(codecOpt testutil.CodecOptions) client.TxConfig { + interfaceRegistry := codecOpt.NewInterfaceRegistry() cdc := codec.NewProtoCodec(interfaceRegistry) - return tx.NewTxConfig(cdc, tx.DefaultSignModes) + signingCtx := interfaceRegistry.SigningContext() + return tx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes) } type TestBuilderTxConfig struct { @@ -54,9 +56,9 @@ type TestBuilderTxConfig struct { TxBuilder *TestTxBuilder } -func MakeBuilderTestTxConfig() TestBuilderTxConfig { +func MakeBuilderTestTxConfig(codecOpt testutil.CodecOptions) TestBuilderTxConfig { return TestBuilderTxConfig{ - TxConfig: MakeTestTxConfig(), + TxConfig: MakeTestTxConfig(codecOpt), } } diff --git a/x/auth/CHANGELOG.md b/x/auth/CHANGELOG.md index 33c4017bf38e..585075a9d39e 100644 --- a/x/auth/CHANGELOG.md +++ b/x/auth/CHANGELOG.md @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* [#19447](https://github.com/cosmos/cosmos-sdk/pull/19447) Address and validator address codecs are now arguments of `NewTxConfig`. `NewDefaultSigningOptions` has been replaced with `NewSigningOptions` which takes address and validator address codecs as arguments. * [#17985](https://github.com/cosmos/cosmos-sdk/pull/17985) Remove `StdTxConfig` * [#19161](https://github.com/cosmos/cosmos-sdk/pull/19161) Remove `simulate` from `SetGasMeter` * [#19363](https://github.com/cosmos/cosmos-sdk/pull/19363) Remove `IterateAccounts` and `GetAllAccounts` methods from the AccountKeeper interface and Keeper. diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index 3a0f60c1f690..80f858b042f6 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -145,7 +145,9 @@ func TestDeductFeesNoDelegation(t *testing.T) { tc := stc // to make scopelint happy t.Run(name, func(t *testing.T) { suite := SetupTestSuite(t, false) - protoTxCfg := tx.NewTxConfig(codec.NewProtoCodec(suite.encCfg.InterfaceRegistry), tx.DefaultSignModes) + cdc := codec.NewProtoCodec(suite.encCfg.InterfaceRegistry) + signingCtx := suite.encCfg.InterfaceRegistry.SigningContext() + protoTxCfg := tx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes) // this just tests our handler dfd := ante.NewDeductFeeDecorator(suite.accountKeeper, suite.bankKeeper, suite.feeGrantKeeper, nil) feeAnteHandler := sdk.ChainAnteDecorators(dfd) diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index d157866e0d10..ab21482b48c8 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -15,6 +15,7 @@ import ( authtx "cosmossdk.io/x/auth/tx" txmodule "cosmossdk.io/x/auth/tx/config" "cosmossdk.io/x/auth/types" + txsigning "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" @@ -99,13 +100,18 @@ func TestSigVerification(t *testing.T) { enabledSignModes := []signing.SignMode{signing.SignMode_SIGN_MODE_DIRECT, signing.SignMode_SIGN_MODE_TEXTUAL, signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON} // Since TEXTUAL is not enabled by default, we create a custom TxConfig // here which includes it. + cdc := codec.NewProtoCodec(suite.encCfg.InterfaceRegistry) txConfigOpts := authtx.ConfigOptions{ TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(suite.clientCtx), EnabledSignModes: enabledSignModes, + SigningOptions: &txsigning.Options{ + AddressCodec: cdc.InterfaceRegistry().SigningContext().AddressCodec(), + ValidatorAddressCodec: cdc.InterfaceRegistry().SigningContext().ValidatorAddressCodec(), + }, } var err error suite.clientCtx.TxConfig, err = authtx.NewTxConfigWithOptions( - codec.NewProtoCodec(suite.encCfg.InterfaceRegistry), + cdc, txConfigOpts, ) require.NoError(t, err) @@ -138,6 +144,10 @@ func TestSigVerification(t *testing.T) { txConfigOpts = authtx.ConfigOptions{ TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(suite.txBankKeeper), EnabledSignModes: enabledSignModes, + SigningOptions: &txsigning.Options{ + AddressCodec: cdc.InterfaceRegistry().SigningContext().AddressCodec(), + ValidatorAddressCodec: cdc.InterfaceRegistry().SigningContext().ValidatorAddressCodec(), + }, } anteTxConfig, err := authtx.NewTxConfigWithOptions( codec.NewProtoCodec(suite.encCfg.InterfaceRegistry), @@ -303,13 +313,18 @@ func TestAnteHandlerChecks(t *testing.T) { enabledSignModes := []signing.SignMode{signing.SignMode_SIGN_MODE_DIRECT, signing.SignMode_SIGN_MODE_TEXTUAL, signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON} // Since TEXTUAL is not enabled by default, we create a custom TxConfig // here which includes it. + cdc := codec.NewProtoCodec(suite.encCfg.InterfaceRegistry) txConfigOpts := authtx.ConfigOptions{ TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(suite.clientCtx), EnabledSignModes: enabledSignModes, + SigningOptions: &txsigning.Options{ + AddressCodec: cdc.InterfaceRegistry().SigningContext().AddressCodec(), + ValidatorAddressCodec: cdc.InterfaceRegistry().SigningContext().ValidatorAddressCodec(), + }, } anteTxConfig, err := authtx.NewTxConfigWithOptions( - codec.NewProtoCodec(suite.encCfg.InterfaceRegistry), + cdc, txConfigOpts, ) require.NoError(t, err) diff --git a/x/auth/ante/testutil_test.go b/x/auth/ante/testutil_test.go index c49cebdcdf5e..1814e94f2b29 100644 --- a/x/auth/ante/testutil_test.go +++ b/x/auth/ante/testutil_test.go @@ -25,6 +25,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -67,7 +68,7 @@ func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite { key := storetypes.NewKVStoreKey(types.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) suite.ctx = testCtx.Ctx.WithIsCheckTx(isCheckTx).WithBlockHeight(1) - suite.encCfg = moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + suite.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) maccPerms := map[string][]string{ "fee_collector": nil, diff --git a/x/auth/client/cli/encode_test.go b/x/auth/client/cli/encode_test.go index d5b116ca733c..1234de797ac9 100644 --- a/x/auth/client/cli/encode_test.go +++ b/x/auth/client/cli/encode_test.go @@ -11,13 +11,14 @@ import ( "cosmossdk.io/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/client" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) func TestGetCommandEncode(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) txConfig := encodingConfig.TxConfig cdc := encodingConfig.Codec @@ -47,7 +48,7 @@ func TestGetCommandEncode(t *testing.T) { } func TestGetCommandDecode(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) txConfig := encodingConfig.TxConfig cdc := encodingConfig.Codec diff --git a/x/auth/client/tx_test.go b/x/auth/client/tx_test.go index 130e8af7e564..61ab3349a094 100644 --- a/x/auth/client/tx_test.go +++ b/x/auth/client/tx_test.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -38,7 +39,7 @@ func TestParseQueryResponse(t *testing.T) { func TestReadTxFromFile(t *testing.T) { t.Parallel() - encodingConfig := moduletestutil.MakeTestEncodingConfig() + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) interfaceRegistry := encodingConfig.InterfaceRegistry txConfig := encodingConfig.TxConfig @@ -74,7 +75,7 @@ func TestReadTxFromFile(t *testing.T) { func TestReadTxsFromFile(t *testing.T) { t.Parallel() - encodingConfig := moduletestutil.MakeTestEncodingConfig() + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) interfaceRegistry := encodingConfig.InterfaceRegistry txConfig := encodingConfig.TxConfig @@ -138,7 +139,7 @@ func TestReadTxsFromFile(t *testing.T) { func TestBatchScanner_Scan(t *testing.T) { t.Parallel() - encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) txConfig := encodingConfig.TxConfig clientCtx := client.Context{} diff --git a/x/auth/keeper/deterministic_test.go b/x/auth/keeper/deterministic_test.go index 95bbef98b4ee..61baa01c2835 100644 --- a/x/auth/keeper/deterministic_test.go +++ b/x/auth/keeper/deterministic_test.go @@ -19,6 +19,7 @@ import ( "cosmossdk.io/x/auth/types" "github.com/cosmos/cosmos-sdk/baseapp" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -52,7 +53,7 @@ func TestDeterministicTestSuite(t *testing.T) { } func (suite *DeterministicTestSuite) SetupTest() { - suite.encCfg = moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + suite.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) suite.Require() key := storetypes.NewKVStoreKey(types.StoreKey) diff --git a/x/auth/keeper/keeper_test.go b/x/auth/keeper/keeper_test.go index 8ed4c8d00de2..02a25bb6ec83 100644 --- a/x/auth/keeper/keeper_test.go +++ b/x/auth/keeper/keeper_test.go @@ -15,6 +15,7 @@ import ( "cosmossdk.io/x/auth/types" "github.com/cosmos/cosmos-sdk/baseapp" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/runtime" @@ -46,7 +47,7 @@ type KeeperTestSuite struct { } func (suite *KeeperTestSuite) SetupTest() { - suite.encCfg = moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + suite.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) diff --git a/x/auth/signing/adapter_test.go b/x/auth/signing/adapter_test.go index 2a90b7030a36..432a0194ba77 100644 --- a/x/auth/signing/adapter_test.go +++ b/x/auth/signing/adapter_test.go @@ -8,13 +8,14 @@ import ( authsign "cosmossdk.io/x/auth/signing" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/types/tx/signing" ) func TestGetSignBytesAdapterNoPublicKey(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig() + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) txConfig := encodingConfig.TxConfig _, _, addr := testdata.KeyTestPubAddr() signerData := authsign.SignerData{ diff --git a/x/auth/tx/aux_test.go b/x/auth/tx/aux_test.go index 7321464f054c..4d1ae10b3271 100644 --- a/x/auth/tx/aux_test.go +++ b/x/auth/tx/aux_test.go @@ -9,6 +9,7 @@ import ( authsigning "cosmossdk.io/x/auth/signing" clienttx "github.com/cosmos/cosmos-sdk/client/tx" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" _ "github.com/cosmos/cosmos-sdk/testutil/testdata/testpb" @@ -39,7 +40,7 @@ var ( // client.TxBuilder created by the fee payer. func TestBuilderWithAux(t *testing.T) { t.Skip("restore when we re-enable aux on the TX builder") - encodingConfig := moduletestutil.MakeTestEncodingConfig() + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) interfaceRegistry := encodingConfig.InterfaceRegistry txConfig := encodingConfig.TxConfig diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index e796902ee910..90fbb8e39f27 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -1,10 +1,10 @@ package tx import ( + "errors" "fmt" "cosmossdk.io/core/address" - authcodec "cosmossdk.io/x/auth/codec" txdecode "cosmossdk.io/x/tx/decode" txsigning "cosmossdk.io/x/tx/signing" "cosmossdk.io/x/tx/signing/aminojson" @@ -76,12 +76,15 @@ var DefaultSignModes = []signingtypes.SignMode{ // We prefer to use depinject to provide client.TxConfig, but we permit this constructor usage. Within the SDK, // this constructor is primarily used in tests, but also sees usage in app chains like: // https://github.com/evmos/evmos/blob/719363fbb92ff3ea9649694bd088e4c6fe9c195f/encoding/config.go#L37 -func NewTxConfig(protoCodec codec.Codec, enabledSignModes []signingtypes.SignMode, - customSignModes ...txsigning.SignModeHandler, +func NewTxConfig(protoCodec codec.Codec, addressCodec, validatorAddressCodec address.Codec, enabledSignModes []signingtypes.SignMode, customSignModes ...txsigning.SignModeHandler, ) client.TxConfig { txConfig, err := NewTxConfigWithOptions(protoCodec, ConfigOptions{ EnabledSignModes: enabledSignModes, CustomSignModes: customSignModes, + SigningOptions: &txsigning.Options{ + AddressCodec: addressCodec, + ValidatorAddressCodec: validatorAddressCodec, + }, }) if err != nil { panic(err) @@ -89,13 +92,12 @@ func NewTxConfig(protoCodec codec.Codec, enabledSignModes []signingtypes.SignMod return txConfig } -// NewDefaultSigningOptions returns the sdk default signing options used by x/tx. This includes account and +// NewSigningOptions returns signing options used by x/tx. This includes account and // validator address prefix enabled codecs. -func NewDefaultSigningOptions() (*txsigning.Options, error) { - sdkConfig := sdk.GetConfig() +func NewSigningOptions(addressCodec, validatorAddressCodec address.Codec) (*txsigning.Options, error) { return &txsigning.Options{ - AddressCodec: authcodec.NewBech32Codec(sdkConfig.GetBech32AccountAddrPrefix()), - ValidatorAddressCodec: authcodec.NewBech32Codec(sdkConfig.GetBech32ValidatorAddrPrefix()), + AddressCodec: addressCodec, + ValidatorAddressCodec: validatorAddressCodec, }, nil } @@ -105,10 +107,7 @@ func NewDefaultSigningOptions() (*txsigning.Options, error) { func NewSigningHandlerMap(configOpts ConfigOptions) (*txsigning.HandlerMap, error) { var err error if configOpts.SigningOptions == nil { - configOpts.SigningOptions, err = NewDefaultSigningOptions() - if err != nil { - return nil, err - } + return nil, errors.New("signing options not provided") } if configOpts.SigningContext == nil { configOpts.SigningContext, err = txsigning.NewContext(*configOpts.SigningOptions) @@ -179,10 +178,7 @@ func NewTxConfigWithOptions(protoCodec codec.Codec, configOptions ConfigOptions) var err error if configOptions.SigningContext == nil { if configOptions.SigningOptions == nil { - configOptions.SigningOptions, err = NewDefaultSigningOptions() - if err != nil { - return nil, err - } + return nil, errors.New("signing options not provided") } if configOptions.SigningOptions.FileResolver == nil { configOptions.SigningOptions.FileResolver = protoCodec.InterfaceRegistry() diff --git a/x/auth/tx/config_test.go b/x/auth/tx/config_test.go index 10cc68e94515..888bf0eda5d0 100644 --- a/x/auth/tx/config_test.go +++ b/x/auth/tx/config_test.go @@ -9,10 +9,10 @@ import ( _ "cosmossdk.io/api/cosmos/crypto/secp256k1" "cosmossdk.io/x/auth/tx" txtestutil "cosmossdk.io/x/auth/tx/testutil" + "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/testutil" - "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -23,13 +23,17 @@ func TestGenerator(t *testing.T) { std.RegisterInterfaces(interfaceRegistry) interfaceRegistry.RegisterImplementations((*sdk.Msg)(nil), &testdata.TestMsg{}) protoCodec := codec.NewProtoCodec(interfaceRegistry) - suite.Run(t, txtestutil.NewTxConfigTestSuite(tx.NewTxConfig(protoCodec, tx.DefaultSignModes))) + signingCtx := protoCodec.InterfaceRegistry().SigningContext() + suite.Run(t, txtestutil.NewTxConfigTestSuite(tx.NewTxConfig(protoCodec, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), tx.DefaultSignModes))) } func TestConfigOptions(t *testing.T) { - interfaceRegistry := types.NewInterfaceRegistry() + interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry() protoCodec := codec.NewProtoCodec(interfaceRegistry) - configOptions := tx.ConfigOptions{} + configOptions := tx.ConfigOptions{SigningOptions: &signing.Options{ + AddressCodec: interfaceRegistry.SigningContext().AddressCodec(), + ValidatorAddressCodec: interfaceRegistry.SigningContext().ValidatorAddressCodec(), + }} txConfig, err := tx.NewTxConfigWithOptions(protoCodec, configOptions) require.NoError(t, err) require.NotNil(t, txConfig) diff --git a/x/auth/types/genesis_test.go b/x/auth/types/genesis_test.go index 8a3bf204bad2..c8be155e8ffa 100644 --- a/x/auth/types/genesis_test.go +++ b/x/auth/types/genesis_test.go @@ -10,6 +10,7 @@ import ( "cosmossdk.io/x/auth" "cosmossdk.io/x/auth/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" @@ -54,7 +55,7 @@ func TestValidateGenesisDuplicateAccounts(t *testing.T) { } func TestGenesisAccountIterator(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) cdc := encodingConfig.Codec acc1 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr1)) diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index ba1b289f2474..83273f32bbad 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -16,6 +16,7 @@ import ( "cosmossdk.io/x/auth/vesting" "cosmossdk.io/x/auth/vesting/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -38,7 +39,7 @@ type VestingAccountTestSuite struct { } func (s *VestingAccountTestSuite) SetupTest() { - encCfg := moduletestutil.MakeTestEncodingConfig(vesting.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, vesting.AppModule{}) key := storetypes.NewKVStoreKey(authtypes.StoreKey) env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()) diff --git a/x/authz/client/cli/tx_test.go b/x/authz/client/cli/tx_test.go index 2b7df03f8052..d4b2b5f0aa9f 100644 --- a/x/authz/client/cli/tx_test.go +++ b/x/authz/client/cli/tx_test.go @@ -23,6 +23,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -51,7 +52,7 @@ func TestCLITestSuite(t *testing.T) { } func (s *CLITestSuite) SetupSuite() { - s.encCfg = testutilmod.MakeTestEncodingConfig(bank.AppModule{}, authz.AppModule{}) + s.encCfg = testutilmod.MakeTestEncodingConfig(codectestutil.CodecOptions{}, bank.AppModule{}, authz.AppModule{}) s.kr = keyring.NewInMemory(s.encCfg.Codec) s.baseCtx = client.Context{}. diff --git a/x/authz/keeper/genesis_test.go b/x/authz/keeper/genesis_test.go index 8ae9811c019c..78c15797d297 100644 --- a/x/authz/keeper/genesis_test.go +++ b/x/authz/keeper/genesis_test.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -48,7 +49,7 @@ func (suite *GenesisTestSuite) SetupTest() { testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) suite.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) - suite.encCfg = moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{}) + suite.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, authzmodule.AppModule{}) // gomock initializations ctrl := gomock.NewController(suite.T()) diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index 444787fcdf7d..b0c77f497dae 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -51,7 +52,7 @@ func (s *TestSuite) SetupTest() { storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) s.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now().Round(0).UTC()}) - s.encCfg = moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{}) + s.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, authzmodule.AppModule{}) s.baseApp = baseapp.NewBaseApp( "authz", diff --git a/x/authz/migrations/v2/store_test.go b/x/authz/migrations/v2/store_test.go index 00cdc53071ea..4440ae5b4fbe 100644 --- a/x/authz/migrations/v2/store_test.go +++ b/x/authz/migrations/v2/store_test.go @@ -16,6 +16,7 @@ import ( "cosmossdk.io/x/bank" banktypes "cosmossdk.io/x/bank/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/runtime" @@ -25,7 +26,7 @@ import ( ) func TestMigration(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{}, bank.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, authzmodule.AppModule{}, bank.AppModule{}) cdc := encodingConfig.Codec authzKey := storetypes.NewKVStoreKey("authz") diff --git a/x/authz/module/abci_test.go b/x/authz/module/abci_test.go index f45f7e004974..ba2ae1914a85 100644 --- a/x/authz/module/abci_test.go +++ b/x/authz/module/abci_test.go @@ -19,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -30,7 +31,7 @@ func TestExpiredGrantsQueue(t *testing.T) { key := storetypes.NewKVStoreKey(keeper.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, authzmodule.AppModule{}) ctx := testCtx.Ctx baseApp := baseapp.NewBaseApp( diff --git a/x/authz/simulation/decoder_test.go b/x/authz/simulation/decoder_test.go index 5e9697443908..dbeee176732a 100644 --- a/x/authz/simulation/decoder_test.go +++ b/x/authz/simulation/decoder_test.go @@ -13,13 +13,14 @@ import ( "cosmossdk.io/x/authz/simulation" banktypes "cosmossdk.io/x/bank/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) func TestDecodeStore(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, authzmodule.AppModule{}) banktypes.RegisterInterfaces(encCfg.InterfaceRegistry) dec := simulation.NewDecodeStore(encCfg.Codec) diff --git a/x/authz/simulation/genesis_test.go b/x/authz/simulation/genesis_test.go index 19c0508de678..6578c21644f3 100644 --- a/x/authz/simulation/genesis_test.go +++ b/x/authz/simulation/genesis_test.go @@ -13,13 +13,14 @@ import ( "cosmossdk.io/x/authz/simulation" banktypes "cosmossdk.io/x/bank/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/types/module" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) func TestRandomizedGenState(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, authzmodule.AppModule{}) banktypes.RegisterInterfaces(encCfg.InterfaceRegistry) s := rand.NewSource(1) diff --git a/x/bank/client/cli/tx_test.go b/x/bank/client/cli/tx_test.go index 17a73e5f6725..e73d59bb32f2 100644 --- a/x/bank/client/cli/tx_test.go +++ b/x/bank/client/cli/tx_test.go @@ -16,6 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keyring" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" "github.com/cosmos/cosmos-sdk/testutil" @@ -37,7 +38,7 @@ func TestCLITestSuite(t *testing.T) { } func (s *CLITestSuite) SetupSuite() { - s.encCfg = testutilmod.MakeTestEncodingConfig(bank.AppModule{}) + s.encCfg = testutilmod.MakeTestEncodingConfig(codectestutil.CodecOptions{}, bank.AppModule{}) s.kr = keyring.NewInMemory(s.encCfg.Codec) s.baseCtx = client.Context{}. WithKeyring(s.kr). diff --git a/x/bank/keeper/collections_test.go b/x/bank/keeper/collections_test.go index b372f4edc84b..8e77b664f395 100644 --- a/x/bank/keeper/collections_test.go +++ b/x/bank/keeper/collections_test.go @@ -18,6 +18,7 @@ import ( banktypes "cosmossdk.io/x/bank/types" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -28,7 +29,7 @@ func TestBankStateCompatibility(t *testing.T) { key := storetypes.NewKVStoreKey(banktypes.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) - encCfg := moduletestutil.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()) diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 7d5e90ccac4b..e44423e352ff 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -27,6 +27,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -129,7 +130,7 @@ func (suite *KeeperTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(banktypes.StoreKey) testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) - encCfg := moduletestutil.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()) @@ -303,7 +304,7 @@ func (suite *KeeperTestSuite) TestGetAuthority() { NewKeeperWithAuthority := func(authority string) keeper.BaseKeeper { return keeper.NewBaseKeeper( env, - moduletestutil.MakeTestEncodingConfig().Codec, + moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec, suite.authKeeper, nil, authority, diff --git a/x/circuit/ante/circuit_test.go b/x/circuit/ante/circuit_test.go index 6c1e8693f135..9bf328a3466c 100644 --- a/x/circuit/ante/circuit_test.go +++ b/x/circuit/ante/circuit_test.go @@ -12,6 +12,7 @@ import ( cbtypes "cosmossdk.io/x/circuit/types" "github.com/cosmos/cosmos-sdk/client" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -37,7 +38,7 @@ func (m MockCircuitBreaker) IsAllowed(ctx context.Context, typeURL string) (bool func initFixture(t *testing.T) *fixture { t.Helper() mockStoreKey := storetypes.NewKVStoreKey("test") - encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) mockclientCtx := client.Context{}. WithTxConfig(encCfg.TxConfig) diff --git a/x/circuit/keeper/genesis_test.go b/x/circuit/keeper/genesis_test.go index 16f8362ba239..cc4e3b6cbaad 100644 --- a/x/circuit/keeper/genesis_test.go +++ b/x/circuit/keeper/genesis_test.go @@ -15,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -37,7 +38,7 @@ func TestGenesisTestSuite(t *testing.T) { func (s *GenesisTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(types.ModuleName) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(circuit.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, circuit.AppModule{}) sdkCtx := testCtx.Ctx s.ctx = sdkCtx diff --git a/x/circuit/keeper/keeper_test.go b/x/circuit/keeper/keeper_test.go index 29464b66b72f..38ce34b1e14a 100644 --- a/x/circuit/keeper/keeper_test.go +++ b/x/circuit/keeper/keeper_test.go @@ -16,6 +16,7 @@ import ( "cosmossdk.io/x/circuit/types" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -40,7 +41,7 @@ type fixture struct { func initFixture(t *testing.T) *fixture { t.Helper() - encCfg := moduletestutil.MakeTestEncodingConfig(circuit.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, circuit.AppModule{}) ac := addresscodec.NewBech32Codec("cosmos") mockStoreKey := storetypes.NewKVStoreKey("test") diff --git a/x/consensus/keeper/keeper_test.go b/x/consensus/keeper/keeper_test.go index 3ab63dc3cf61..64edfe1018f4 100644 --- a/x/consensus/keeper/keeper_test.go +++ b/x/consensus/keeper/keeper_test.go @@ -12,6 +12,7 @@ import ( authtypes "cosmossdk.io/x/auth/types" "github.com/cosmos/cosmos-sdk/baseapp" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -32,7 +33,7 @@ func (s *KeeperTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(consensusparamkeeper.StoreKey) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx - encCfg := moduletestutil.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()) keeper := consensusparamkeeper.NewKeeper(encCfg.Codec, env, authtypes.NewModuleAddress("gov").String()) diff --git a/x/crisis/keeper/genesis_test.go b/x/crisis/keeper/genesis_test.go index d111beebafe0..a2b392c3a6a0 100644 --- a/x/crisis/keeper/genesis_test.go +++ b/x/crisis/keeper/genesis_test.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -37,7 +38,7 @@ func (s *GenesisTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, crisis.AppModule{}) // gomock initializations ctrl := gomock.NewController(s.T()) diff --git a/x/crisis/keeper/keeper_test.go b/x/crisis/keeper/keeper_test.go index 4a9237d3e92f..84910f934568 100644 --- a/x/crisis/keeper/keeper_test.go +++ b/x/crisis/keeper/keeper_test.go @@ -9,6 +9,7 @@ import ( storetypes "cosmossdk.io/store/types" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -26,7 +27,7 @@ func TestLogger(t *testing.T) { key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, crisis.AppModule{}) keeper := keeper.NewKeeper(encCfg.Codec, storeService, 5, supplyKeeper, "", "", addresscodec.NewBech32Codec("cosmos")) require.Equal(t, @@ -40,7 +41,7 @@ func TestInvariants(t *testing.T) { key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) - encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, crisis.AppModule{}) keeper := keeper.NewKeeper(encCfg.Codec, storeService, 5, supplyKeeper, "", "", addresscodec.NewBech32Codec("cosmos")) require.Equal(t, keeper.InvCheckPeriod(), uint(5)) @@ -57,7 +58,7 @@ func TestAssertInvariants(t *testing.T) { key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, crisis.AppModule{}) keeper := keeper.NewKeeper(encCfg.Codec, storeService, 5, supplyKeeper, "", "", addresscodec.NewBech32Codec("cosmos")) keeper.RegisterRoute("testModule", "testRoute1", func(sdk.Context) (string, bool) { return "", false }) diff --git a/x/crisis/keeper/msg_server_test.go b/x/crisis/keeper/msg_server_test.go index b86fbf724528..ea60b9ac9fe8 100644 --- a/x/crisis/keeper/msg_server_test.go +++ b/x/crisis/keeper/msg_server_test.go @@ -10,6 +10,7 @@ import ( storetypes "cosmossdk.io/store/types" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -37,7 +38,7 @@ func (s *KeeperTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, crisis.AppModule{}) keeper := keeper.NewKeeper(encCfg.Codec, storeService, 5, supplyKeeper, "", sdk.AccAddress([]byte("addr1_______________")).String(), addresscodec.NewBech32Codec("cosmos")) s.ctx = testCtx.Ctx @@ -51,7 +52,7 @@ func (s *KeeperTestSuite) TestMsgVerifyInvariant() { err := s.keeper.ConstantFee.Set(s.ctx, constantFee) s.Require().NoError(err) - encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, crisis.AppModule{}) kr := keyring.NewInMemory(encCfg.Codec) testutil.CreateKeyringAccounts(s.T(), kr, 1) diff --git a/x/distribution/keeper/allocation_test.go b/x/distribution/keeper/allocation_test.go index fbc79d8f514a..d0286dd64131 100644 --- a/x/distribution/keeper/allocation_test.go +++ b/x/distribution/keeper/allocation_test.go @@ -21,6 +21,7 @@ import ( stakingtypes "cosmossdk.io/x/staking/types" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -31,7 +32,7 @@ func TestAllocateTokensToValidatorWithCommission(t *testing.T) { ctrl := gomock.NewController(t) key := storetypes.NewKVStoreKey(disttypes.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -91,7 +92,7 @@ func TestAllocateTokensToManyValidators(t *testing.T) { ctrl := gomock.NewController(t) key := storetypes.NewKVStoreKey(disttypes.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -223,7 +224,7 @@ func TestAllocateTokensTruncation(t *testing.T) { ctrl := gomock.NewController(t) key := storetypes.NewKVStoreKey(disttypes.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) diff --git a/x/distribution/keeper/delegation_test.go b/x/distribution/keeper/delegation_test.go index 09970ed39a55..fc11b8b27d7f 100644 --- a/x/distribution/keeper/delegation_test.go +++ b/x/distribution/keeper/delegation_test.go @@ -19,6 +19,7 @@ import ( stakingtypes "cosmossdk.io/x/staking/types" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -29,7 +30,7 @@ func TestCalculateRewardsBasic(t *testing.T) { ctrl := gomock.NewController(t) key := storetypes.NewKVStoreKey(disttypes.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -132,7 +133,7 @@ func TestCalculateRewardsAfterSlash(t *testing.T) { ctrl := gomock.NewController(t) key := storetypes.NewKVStoreKey(disttypes.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -238,7 +239,7 @@ func TestCalculateRewardsAfterManySlashes(t *testing.T) { ctrl := gomock.NewController(t) key := storetypes.NewKVStoreKey(disttypes.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -365,7 +366,7 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) { ctrl := gomock.NewController(t) key := storetypes.NewKVStoreKey(disttypes.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -465,7 +466,7 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) { ctrl := gomock.NewController(t) key := storetypes.NewKVStoreKey(disttypes.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -543,7 +544,7 @@ func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) { ctrl := gomock.NewController(t) key := storetypes.NewKVStoreKey(disttypes.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -662,7 +663,7 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) { ctrl := gomock.NewController(t) key := storetypes.NewKVStoreKey(disttypes.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -804,7 +805,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { ctrl := gomock.NewController(t) key := storetypes.NewKVStoreKey(disttypes.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) @@ -1006,7 +1007,7 @@ func Test100PercentCommissionReward(t *testing.T) { ctrl := gomock.NewController(t) key := storetypes.NewKVStoreKey(disttypes.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) diff --git a/x/distribution/keeper/keeper_test.go b/x/distribution/keeper/keeper_test.go index 0a1a64eb53e2..3456466401f9 100644 --- a/x/distribution/keeper/keeper_test.go +++ b/x/distribution/keeper/keeper_test.go @@ -18,6 +18,7 @@ import ( "cosmossdk.io/x/distribution/types" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -38,7 +39,7 @@ func initFixture(t *testing.T) (sdk.Context, []sdk.AccAddress, keeper.Keeper, de ctrl := gomock.NewController(t) key := storetypes.NewKVStoreKey(types.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) addrs := simtestutil.CreateIncrementalAccounts(2) diff --git a/x/distribution/migrations/v4/migrate_funds_test.go b/x/distribution/migrations/v4/migrate_funds_test.go index 9ccf4f81ad4f..b8994061cbd8 100644 --- a/x/distribution/migrations/v4/migrate_funds_test.go +++ b/x/distribution/migrations/v4/migrate_funds_test.go @@ -22,6 +22,7 @@ import ( pooltypes "cosmossdk.io/x/protocolpool/types" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/integration" sdk "github.com/cosmos/cosmos-sdk/types" @@ -34,7 +35,7 @@ func TestFundsMigration(t *testing.T) { ) logger := log.NewTestLogger(t) cms := integration.CreateMultiStore(keys, logger) - encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, bank.AppModule{}, distribution.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, bank.AppModule{}, distribution.AppModule{}) ctx := sdk.NewContext(cms, true, logger) maccPerms := map[string][]string{ diff --git a/x/distribution/migrations/v4/migrate_test.go b/x/distribution/migrations/v4/migrate_test.go index ed4cc8f79868..6f00fea79e00 100644 --- a/x/distribution/migrations/v4/migrate_test.go +++ b/x/distribution/migrations/v4/migrate_test.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/x/distribution" v4 "cosmossdk.io/x/distribution/migrations/v4" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -20,7 +21,7 @@ import ( ) func TestMigration(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}).Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}).Codec storeKey := storetypes.NewKVStoreKey("distribution") storeService := runtime.NewKVStoreService(storeKey) tKey := storetypes.NewTransientStoreKey("transient_test") diff --git a/x/distribution/simulation/decoder_test.go b/x/distribution/simulation/decoder_test.go index 71eb414442cb..98a5c91fe317 100644 --- a/x/distribution/simulation/decoder_test.go +++ b/x/distribution/simulation/decoder_test.go @@ -11,6 +11,7 @@ import ( "cosmossdk.io/x/distribution/simulation" "cosmossdk.io/x/distribution/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" @@ -24,7 +25,7 @@ var ( ) func TestDecodeDistributionStore(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(distribution.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, distribution.AppModule{}) cdc := encodingConfig.Codec dec := simulation.NewDecodeStore(cdc) diff --git a/x/evidence/keeper/keeper_test.go b/x/evidence/keeper/keeper_test.go index 6513aa581a11..61f9eb0ef4a2 100644 --- a/x/evidence/keeper/keeper_test.go +++ b/x/evidence/keeper/keeper_test.go @@ -21,6 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/runtime" @@ -84,7 +85,7 @@ type KeeperTestSuite struct { } func (suite *KeeperTestSuite) SetupTest() { - encCfg := moduletestutil.MakeTestEncodingConfig(evidence.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, evidence.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()) tkey := storetypes.NewTransientStoreKey("evidence_transient_store") @@ -115,7 +116,7 @@ func (suite *KeeperTestSuite) SetupTest() { evidenceKeeper.SetRouter(router) suite.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) - suite.encCfg = moduletestutil.MakeTestEncodingConfig(evidence.AppModule{}) + suite.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, evidence.AppModule{}) suite.accountKeeper = accountKeeper diff --git a/x/feegrant/client/cli/tx_test.go b/x/feegrant/client/cli/tx_test.go index d691821f26ec..ffdbcbb584f2 100644 --- a/x/feegrant/client/cli/tx_test.go +++ b/x/feegrant/client/cli/tx_test.go @@ -25,6 +25,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -61,7 +62,7 @@ func TestCLITestSuite(t *testing.T) { func (s *CLITestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - s.encCfg = testutilmod.MakeTestEncodingConfig(module.AppModule{}, gov.AppModule{}) + s.encCfg = testutilmod.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}, gov.AppModule{}) s.kr = keyring.NewInMemory(s.encCfg.Codec) s.baseCtx = client.Context{}. WithKeyring(s.kr). diff --git a/x/feegrant/filtered_fee_test.go b/x/feegrant/filtered_fee_test.go index f5deee9e3d96..d8e3fe81684a 100644 --- a/x/feegrant/filtered_fee_test.go +++ b/x/feegrant/filtered_fee_test.go @@ -14,6 +14,7 @@ import ( "cosmossdk.io/x/feegrant/module" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -22,7 +23,7 @@ import ( func TestFilteredFeeValidAllow(t *testing.T) { key := storetypes.NewKVStoreKey(feegrant.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) diff --git a/x/feegrant/grant_test.go b/x/feegrant/grant_test.go index 0dcad40a7379..a333a51e7756 100644 --- a/x/feegrant/grant_test.go +++ b/x/feegrant/grant_test.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/x/feegrant/module" codecaddress "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -21,7 +22,7 @@ func TestGrant(t *testing.T) { addressCodec := codecaddress.NewBech32Codec("cosmos") key := storetypes.NewKVStoreKey(feegrant.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) diff --git a/x/feegrant/keeper/genesis_test.go b/x/feegrant/keeper/genesis_test.go index eb2eff20d467..9d321fe11518 100644 --- a/x/feegrant/keeper/genesis_test.go +++ b/x/feegrant/keeper/genesis_test.go @@ -17,6 +17,7 @@ import ( feegranttestutil "cosmossdk.io/x/feegrant/testutil" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/runtime" @@ -43,7 +44,7 @@ func initFixture(t *testing.T) *genesisFixture { t.Helper() key := storetypes.NewKVStoreKey(feegrant.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) ctrl := gomock.NewController(t) accountKeeper := feegranttestutil.NewMockAccountKeeper(ctrl) diff --git a/x/feegrant/keeper/keeper_test.go b/x/feegrant/keeper/keeper_test.go index e68f798d94d2..64e3dd711a54 100644 --- a/x/feegrant/keeper/keeper_test.go +++ b/x/feegrant/keeper/keeper_test.go @@ -17,6 +17,7 @@ import ( feegranttestutil "cosmossdk.io/x/feegrant/testutil" codecaddress "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -44,7 +45,7 @@ func (suite *KeeperTestSuite) SetupTest() { suite.addrs = simtestutil.CreateIncrementalAccounts(20) key := storetypes.NewKVStoreKey(feegrant.StoreKey) testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) // setup gomock and initialize some globally expected executions ctrl := gomock.NewController(suite.T()) diff --git a/x/feegrant/migrations/v2/store_test.go b/x/feegrant/migrations/v2/store_test.go index 747e6f74fb6f..2d8bca9b8c9c 100644 --- a/x/feegrant/migrations/v2/store_test.go +++ b/x/feegrant/migrations/v2/store_test.go @@ -15,6 +15,7 @@ import ( "cosmossdk.io/x/feegrant/module" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -23,7 +24,7 @@ import ( ) func TestMigration(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) cdc := encodingConfig.Codec ac := addresscodec.NewBech32Codec("cosmos") diff --git a/x/feegrant/module/abci_test.go b/x/feegrant/module/abci_test.go index 1fb1685aa3c9..9676ae4ffd83 100644 --- a/x/feegrant/module/abci_test.go +++ b/x/feegrant/module/abci_test.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -28,7 +29,7 @@ import ( func TestFeegrantPruning(t *testing.T) { key := storetypes.NewKVStoreKey(feegrant.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) addrs := simtestutil.CreateIncrementalAccounts(4) granter1 := addrs[0] diff --git a/x/feegrant/simulation/decoder_test.go b/x/feegrant/simulation/decoder_test.go index 37526f596526..f29fa98977ad 100644 --- a/x/feegrant/simulation/decoder_test.go +++ b/x/feegrant/simulation/decoder_test.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/x/feegrant/simulation" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" @@ -25,7 +26,7 @@ var ( ) func TestDecodeStore(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) cdc := encodingConfig.Codec dec := simulation.NewDecodeStore(cdc) ac := addresscodec.NewBech32Codec("cosmos") diff --git a/x/feegrant/simulation/genesis_test.go b/x/feegrant/simulation/genesis_test.go index 1271cd5bb001..7bdd29c2e38f 100644 --- a/x/feegrant/simulation/genesis_test.go +++ b/x/feegrant/simulation/genesis_test.go @@ -12,13 +12,14 @@ import ( "cosmossdk.io/x/feegrant/module" "cosmossdk.io/x/feegrant/simulation" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" moduletypes "github.com/cosmos/cosmos-sdk/types/module" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) func TestRandomizedGenState(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) s := rand.NewSource(1) r := rand.New(s) diff --git a/x/genutil/client/cli/genaccount_test.go b/x/genutil/client/cli/genaccount_test.go index 2c5b8a923b33..f269ca7d6537 100644 --- a/x/genutil/client/cli/genaccount_test.go +++ b/x/genutil/client/cli/genaccount_test.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/server" @@ -69,7 +70,7 @@ func TestAddGenesisAccountCmd(t *testing.T) { cfg, err := genutiltest.CreateDefaultCometConfig(home) require.NoError(t, err) - appCodec := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}).Codec + appCodec := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}).Codec err = genutiltest.ExecInitCmd(testMbm, home, appCodec) require.NoError(t, err) diff --git a/x/genutil/client/cli/gentx_test.go b/x/genutil/client/cli/gentx_test.go index 76ea4856d592..a4c698398805 100644 --- a/x/genutil/client/cli/gentx_test.go +++ b/x/genutil/client/cli/gentx_test.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keyring" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" @@ -42,7 +43,7 @@ func TestCLITestSuite(t *testing.T) { } func (s *CLITestSuite) SetupSuite() { - s.encCfg = testutilmod.MakeTestEncodingConfig(genutil.AppModule{}) + s.encCfg = testutilmod.MakeTestEncodingConfig(codectestutil.CodecOptions{}, genutil.AppModule{}) s.kr = keyring.NewInMemory(s.encCfg.Codec) s.baseCtx = client.Context{}. WithKeyring(s.kr). diff --git a/x/genutil/client/cli/migrate_test.go b/x/genutil/client/cli/migrate_test.go index 55a97fa079d5..7e84b491b132 100644 --- a/x/genutil/client/cli/migrate_test.go +++ b/x/genutil/client/cli/migrate_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/client" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -54,7 +55,7 @@ func TestMigrateGenesis(t *testing.T) { genesisFile := testutil.WriteToNewTempFile(t, tc.genesis) jsonOutput, err := clitestutil.ExecTestCLICmd( // the codec does not contain any modules so that genutil does not bring unnecessary dependencies in the test - client.Context{Codec: moduletestutil.MakeTestEncodingConfig().Codec}, + client.Context{Codec: moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec}, cli.MigrateGenesisCmd(cli.MigrationMap), []string{tc.target, genesisFile.Name()}, ) diff --git a/x/genutil/gentx_test.go b/x/genutil/gentx_test.go index 4ce47e3a3dfd..862e19042364 100644 --- a/x/genutil/gentx_test.go +++ b/x/genutil/gentx_test.go @@ -19,6 +19,7 @@ import ( stakingtypes "cosmossdk.io/x/staking/types" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -52,7 +53,7 @@ type GenTxTestSuite struct { } func (suite *GenTxTestSuite) SetupTest() { - suite.encodingConfig = moduletestutil.MakeTestEncodingConfig(genutil.AppModule{}) + suite.encodingConfig = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, genutil.AppModule{}) key := storetypes.NewKVStoreKey("a_Store_Key") tkey := storetypes.NewTransientStoreKey("a_transient_store") suite.ctx = testutil.DefaultContext(key, tkey) diff --git a/x/genutil/types/genesis_state_test.go b/x/genutil/types/genesis_state_test.go index 95a6aef6d2d4..bb97c2f00c85 100644 --- a/x/genutil/types/genesis_state_test.go +++ b/x/genutil/types/genesis_state_test.go @@ -13,6 +13,7 @@ import ( stakingtypes "cosmossdk.io/x/staking/types" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -48,7 +49,7 @@ func TestValidateGenesisMultipleMessages(t *testing.T) { sdk.NewInt64Coin(sdk.DefaultBondDenom, 50), desc, comm, math.OneInt()) require.NoError(t, err) - txConfig := moduletestutil.MakeTestEncodingConfig(staking.AppModule{}, genutil.AppModule{}).TxConfig + txConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, staking.AppModule{}, genutil.AppModule{}).TxConfig txBuilder := txConfig.NewTxBuilder() require.NoError(t, txBuilder.SetMsgs(msg1, msg2)) @@ -64,7 +65,7 @@ func TestValidateGenesisBadMessage(t *testing.T) { msg1 := stakingtypes.NewMsgEditValidator(sdk.ValAddress(pk1.Address()).String(), desc, nil, nil) - txConfig := moduletestutil.MakeTestEncodingConfig(staking.AppModule{}, genutil.AppModule{}).TxConfig + txConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, staking.AppModule{}, genutil.AppModule{}).TxConfig txBuilder := txConfig.NewTxBuilder() err := txBuilder.SetMsgs(msg1) require.NoError(t, err) diff --git a/x/gov/client/cli/tx_test.go b/x/gov/client/cli/tx_test.go index 05ffcb92d806..4cbaf6972d96 100644 --- a/x/gov/client/cli/tx_test.go +++ b/x/gov/client/cli/tx_test.go @@ -22,6 +22,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" @@ -43,7 +44,7 @@ func TestCLITestSuite(t *testing.T) { } func (s *CLITestSuite) SetupSuite() { - s.encCfg = testutilmod.MakeTestEncodingConfig(gov.AppModule{}) + s.encCfg = testutilmod.MakeTestEncodingConfig(codectestutil.CodecOptions{}, gov.AppModule{}) s.kr = keyring.NewInMemory(s.encCfg.Codec) s.baseCtx = client.Context{}. WithKeyring(s.kr). diff --git a/x/gov/client/utils/query_test.go b/x/gov/client/utils/query_test.go index 3e539f71b4c5..5c0aed3ac7fa 100644 --- a/x/gov/client/utils/query_test.go +++ b/x/gov/client/utils/query_test.go @@ -15,6 +15,7 @@ import ( v1 "cosmossdk.io/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/client" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) @@ -54,7 +55,7 @@ func (mock TxSearchMock) Block(ctx context.Context, height *int64) (*coretypes.R } func TestGetPaginatedVotes(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig(gov.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, gov.AppModule{}) type testCase struct { description string diff --git a/x/gov/keeper/common_test.go b/x/gov/keeper/common_test.go index 5cde59811d31..1ab164143397 100644 --- a/x/gov/keeper/common_test.go +++ b/x/gov/keeper/common_test.go @@ -22,6 +22,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -98,7 +99,7 @@ func setupGovKeeper(t *testing.T, expectations ...func(sdk.Context, mocks)) ( storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) - encCfg := moduletestutil.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) v1.RegisterInterfaces(encCfg.InterfaceRegistry) v1beta1.RegisterInterfaces(encCfg.InterfaceRegistry) banktypes.RegisterInterfaces(encCfg.InterfaceRegistry) diff --git a/x/gov/migrations/v5/store_test.go b/x/gov/migrations/v5/store_test.go index c84ee38e0a34..b790aaf971ae 100644 --- a/x/gov/migrations/v5/store_test.go +++ b/x/gov/migrations/v5/store_test.go @@ -13,13 +13,14 @@ import ( v5 "cosmossdk.io/x/gov/migrations/v5" v1 "cosmossdk.io/x/gov/types/v1" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) func TestMigrateStore(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig(gov.AppModule{}, bank.AppModule{}).Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, gov.AppModule{}, bank.AppModule{}).Codec govKey := storetypes.NewKVStoreKey("gov") ctx := testutil.DefaultContext(govKey, storetypes.NewTransientStoreKey("transient_test")) store := ctx.KVStore(govKey) diff --git a/x/gov/migrations/v6/store_test.go b/x/gov/migrations/v6/store_test.go index f356f59cca43..76a6aa654e6a 100644 --- a/x/gov/migrations/v6/store_test.go +++ b/x/gov/migrations/v6/store_test.go @@ -13,13 +13,14 @@ import ( v1 "cosmossdk.io/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) func TestMigrateStore(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig(gov.AppModule{}).Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, gov.AppModule{}).Codec govKey := storetypes.NewKVStoreKey("gov") ctx := testutil.DefaultContext(govKey, storetypes.NewTransientStoreKey("transient_test")) storeService := runtime.NewKVStoreService(govKey) diff --git a/x/group/client/cli/tx_test.go b/x/group/client/cli/tx_test.go index d46599c17634..dbc768f2d4e7 100644 --- a/x/group/client/cli/tx_test.go +++ b/x/group/client/cli/tx_test.go @@ -22,6 +22,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" @@ -49,7 +50,7 @@ func TestCLITestSuite(t *testing.T) { } func (s *CLITestSuite) SetupSuite() { - s.encCfg = testutilmod.MakeTestEncodingConfig(groupmodule.AppModule{}) + s.encCfg = testutilmod.MakeTestEncodingConfig(codectestutil.CodecOptions{}, groupmodule.AppModule{}) s.kr = keyring.NewInMemory(s.encCfg.Codec) s.baseCtx = client.Context{}. WithKeyring(s.kr). diff --git a/x/group/keeper/genesis_test.go b/x/group/keeper/genesis_test.go index 00e66b436069..0af3c8678d86 100644 --- a/x/group/keeper/genesis_test.go +++ b/x/group/keeper/genesis_test.go @@ -21,6 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -52,7 +53,7 @@ func (s *GenesisTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(group.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) ctrl := gomock.NewController(s.T()) accountKeeper := grouptestutil.NewMockAccountKeeper(ctrl) diff --git a/x/group/keeper/grpc_query_test.go b/x/group/keeper/grpc_query_test.go index 95ddd1e200ea..dccc77656925 100644 --- a/x/group/keeper/grpc_query_test.go +++ b/x/group/keeper/grpc_query_test.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -44,7 +45,7 @@ func initKeeper(t *testing.T) *fixture { key := storetypes.NewKVStoreKey(group.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) ctx := testCtx.Ctx diff --git a/x/group/keeper/keeper_test.go b/x/group/keeper/keeper_test.go index 1c19479bcf43..4188ccd91299 100644 --- a/x/group/keeper/keeper_test.go +++ b/x/group/keeper/keeper_test.go @@ -24,6 +24,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -54,7 +55,7 @@ func (s *TestSuite) SetupTest() { key := storetypes.NewKVStoreKey(group.StoreKey) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}, bank.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}, bank.AppModule{}) s.addrs = simtestutil.CreateIncrementalAccounts(6) // setup gomock and initialize some globally expected executions diff --git a/x/group/migrations/v2/migrate_test.go b/x/group/migrations/v2/migrate_test.go index 098586580620..c06b975c826c 100644 --- a/x/group/migrations/v2/migrate_test.go +++ b/x/group/migrations/v2/migrate_test.go @@ -19,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -34,7 +35,7 @@ var ( ) func TestMigrate(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModule{}, groupmodule.AppModule{}).Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, groupmodule.AppModule{}).Codec storeKey := storetypes.NewKVStoreKey(v2.ModuleName) storeService := runtime.NewKVStoreService(storeKey) tKey := storetypes.NewTransientStoreKey("transient_test") diff --git a/x/group/proposal_test.go b/x/group/proposal_test.go index d7a5748d5f53..eff18529ff7d 100644 --- a/x/group/proposal_test.go +++ b/x/group/proposal_test.go @@ -8,6 +8,7 @@ import ( "cosmossdk.io/x/group" "cosmossdk.io/x/group/module" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) @@ -16,7 +17,7 @@ import ( // This test serves as a showcase that we need to be careful when unmarshalling // multiple times into the same reference. func TestGogoUnmarshalProposal(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) cdc := encodingConfig.Codec p1 := group.Proposal{Proposers: []string{"foo"}} diff --git a/x/group/simulation/decoder_test.go b/x/group/simulation/decoder_test.go index 303490e02b8a..6eee5a2fbd63 100644 --- a/x/group/simulation/decoder_test.go +++ b/x/group/simulation/decoder_test.go @@ -12,13 +12,14 @@ import ( "cosmossdk.io/x/group/module" "cosmossdk.io/x/group/simulation" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/cosmos/cosmos-sdk/types/kv" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) func TestDecodeStore(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) cdc := encodingConfig.Codec dec := simulation.NewDecodeStore(cdc) diff --git a/x/group/simulation/genesis_test.go b/x/group/simulation/genesis_test.go index 7bc06aa2ccc7..9d129fca7af7 100644 --- a/x/group/simulation/genesis_test.go +++ b/x/group/simulation/genesis_test.go @@ -13,13 +13,14 @@ import ( groupmodule "cosmossdk.io/x/group/module" "cosmossdk.io/x/group/simulation" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/types/module" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) func TestRandomizedGenState(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(groupmodule.AppModule{}, bank.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, groupmodule.AppModule{}, bank.AppModule{}) cdc := encodingConfig.Codec s := rand.NewSource(1) diff --git a/x/mint/keeper/genesis_test.go b/x/mint/keeper/genesis_test.go index c21dbc4fc421..5fc6e9e03678 100644 --- a/x/mint/keeper/genesis_test.go +++ b/x/mint/keeper/genesis_test.go @@ -17,6 +17,7 @@ import ( "cosmossdk.io/x/mint/types" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -42,7 +43,7 @@ func TestGenesisTestSuite(t *testing.T) { func (s *GenesisTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(types.StoreKey) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) - encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, mint.AppModule{}) // gomock initializations ctrl := gomock.NewController(s.T()) diff --git a/x/mint/keeper/grpc_query_test.go b/x/mint/keeper/grpc_query_test.go index 5b190ae5d444..f2f80689b759 100644 --- a/x/mint/keeper/grpc_query_test.go +++ b/x/mint/keeper/grpc_query_test.go @@ -16,6 +16,7 @@ import ( "cosmossdk.io/x/mint/types" "github.com/cosmos/cosmos-sdk/baseapp" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -31,7 +32,7 @@ type MintTestSuite struct { } func (suite *MintTestSuite) SetupTest() { - encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, mint.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()) testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) diff --git a/x/mint/keeper/keeper_test.go b/x/mint/keeper/keeper_test.go index 0f22cb763ae1..fb4fa58c1827 100644 --- a/x/mint/keeper/keeper_test.go +++ b/x/mint/keeper/keeper_test.go @@ -15,6 +15,7 @@ import ( minttestutil "cosmossdk.io/x/mint/testutil" "cosmossdk.io/x/mint/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -38,7 +39,7 @@ func TestKeeperTestSuite(t *testing.T) { } func (s *IntegrationTestSuite) SetupTest() { - encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, mint.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) env := runtime.NewEnvironment(storeService, log.NewNopLogger()) diff --git a/x/mint/simulation/genesis_test.go b/x/mint/simulation/genesis_test.go index a4a79ef3f31b..8a3858e3d293 100644 --- a/x/mint/simulation/genesis_test.go +++ b/x/mint/simulation/genesis_test.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/x/mint/simulation" "cosmossdk.io/x/mint/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -21,7 +22,7 @@ import ( // TestRandomizedGenState tests the normal scenario of applying RandomizedGenState. // Abonormal scenarios are not tested here. func TestRandomizedGenState(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, mint.AppModule{}) s := rand.NewSource(1) r := rand.New(s) @@ -60,7 +61,7 @@ func TestRandomizedGenState(t *testing.T) { // TestRandomizedGenState tests abnormal scenarios of applying RandomizedGenState. func TestRandomizedGenState1(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, mint.AppModule{}) s := rand.NewSource(1) r := rand.New(s) diff --git a/x/nft/keeper/keeper_test.go b/x/nft/keeper/keeper_test.go index 2332a68b38e1..823553727bd5 100644 --- a/x/nft/keeper/keeper_test.go +++ b/x/nft/keeper/keeper_test.go @@ -17,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -52,7 +53,7 @@ type TestSuite struct { func (s *TestSuite) SetupTest() { // suite setup s.addrs = simtestutil.CreateIncrementalAccounts(3) - s.encCfg = moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + s.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) key := storetypes.NewKVStoreKey(nft.StoreKey) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) diff --git a/x/nft/simulation/decoder_test.go b/x/nft/simulation/decoder_test.go index 4c4b4a9941ec..7498ee7e8f58 100644 --- a/x/nft/simulation/decoder_test.go +++ b/x/nft/simulation/decoder_test.go @@ -11,6 +11,7 @@ import ( "cosmossdk.io/x/nft/module" "cosmossdk.io/x/nft/simulation" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" @@ -23,7 +24,7 @@ var ( ) func TestDecodeStore(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) dec := simulation.NewDecodeStore(encCfg.Codec) class := nft.Class{ diff --git a/x/nft/simulation/genesis_test.go b/x/nft/simulation/genesis_test.go index cd82052df323..3aa6928943c0 100644 --- a/x/nft/simulation/genesis_test.go +++ b/x/nft/simulation/genesis_test.go @@ -13,13 +13,14 @@ import ( "cosmossdk.io/x/nft/simulation" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/types/module" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) func TestRandomizedGenState(t *testing.T) { - encCfg := moduletestutil.MakeTestEncodingConfig(nftmodule.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, nftmodule.AppModule{}) s := rand.NewSource(1) r := rand.New(s) diff --git a/x/params/keeper/common_test.go b/x/params/keeper/common_test.go index 2511b1e77eb3..5a577e51b649 100644 --- a/x/params/keeper/common_test.go +++ b/x/params/keeper/common_test.go @@ -6,13 +6,14 @@ import ( paramskeeper "cosmossdk.io/x/params/keeper" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" sdktestutil "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) func testComponents() (*codec.LegacyAmino, sdk.Context, storetypes.StoreKey, storetypes.StoreKey, paramskeeper.Keeper) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(params.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, params.AppModule{}) cdc := encodingConfig.Codec legacyAmino := createTestCodec() diff --git a/x/params/keeper/keeper_test.go b/x/params/keeper/keeper_test.go index 382b5ed9e8f0..d82db839dd35 100644 --- a/x/params/keeper/keeper_test.go +++ b/x/params/keeper/keeper_test.go @@ -16,6 +16,7 @@ import ( "cosmossdk.io/x/params/types/proposal" "github.com/cosmos/cosmos-sdk/baseapp" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -30,7 +31,7 @@ type KeeperTestSuite struct { } func (suite *KeeperTestSuite) SetupTest() { - encodingCfg := moduletestutil.MakeTestEncodingConfig(params.AppModule{}) + encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, params.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) tkey := storetypes.NewTransientStoreKey("params_transient_test") diff --git a/x/params/types/subspace_test.go b/x/params/types/subspace_test.go index f7aeeca28ca6..34f384922924 100644 --- a/x/params/types/subspace_test.go +++ b/x/params/types/subspace_test.go @@ -17,6 +17,7 @@ import ( "cosmossdk.io/x/params/types" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) @@ -38,7 +39,7 @@ func (suite *SubspaceTestSuite) SetupTest() { ms.MountStoreWithDB(tkey, storetypes.StoreTypeTransient, db) suite.NoError(ms.LoadLatestVersion()) - encodingConfig := moduletestutil.MakeTestEncodingConfig(paramsmodule.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, paramsmodule.AppModule{}) suite.cdc = encodingConfig.Codec suite.amino = encodingConfig.Amino diff --git a/x/protocolpool/keeper/keeper_test.go b/x/protocolpool/keeper/keeper_test.go index 30df28d01a3c..fec0abd80cbc 100644 --- a/x/protocolpool/keeper/keeper_test.go +++ b/x/protocolpool/keeper/keeper_test.go @@ -19,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -50,7 +51,7 @@ func (s *KeeperTestSuite) SetupTest() { environment := runtime.NewEnvironment(storeService, log.NewNopLogger()) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) - encCfg := moduletestutil.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) // gomock initializations ctrl := gomock.NewController(s.T()) diff --git a/x/slashing/keeper/keeper_test.go b/x/slashing/keeper/keeper_test.go index 9e22a710e5e0..b78f42b8dc96 100644 --- a/x/slashing/keeper/keeper_test.go +++ b/x/slashing/keeper/keeper_test.go @@ -20,6 +20,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" sdktestutil "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -48,7 +49,7 @@ func (s *KeeperTestSuite) SetupTest() { env := runtime.NewEnvironment(storeService, log.NewNopLogger()) testCtx := sdktestutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now().Round(0).UTC()}) - encCfg := moduletestutil.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) // gomock initializations ctrl := gomock.NewController(s.T()) diff --git a/x/slashing/migrations/v4/migrate_test.go b/x/slashing/migrations/v4/migrate_test.go index de31d92e3e5e..41d8995af6e4 100644 --- a/x/slashing/migrations/v4/migrate_test.go +++ b/x/slashing/migrations/v4/migrate_test.go @@ -12,6 +12,7 @@ import ( v4 "cosmossdk.io/x/slashing/migrations/v4" slashingtypes "cosmossdk.io/x/slashing/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -20,7 +21,7 @@ import ( var consAddr = sdk.ConsAddress(sdk.AccAddress([]byte("addr1_______________"))) func TestMigrate(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig(slashing.AppModule{}).Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, slashing.AppModule{}).Codec storeKey := storetypes.NewKVStoreKey(slashingtypes.ModuleName) tKey := storetypes.NewTransientStoreKey("transient_test") ctx := testutil.DefaultContext(storeKey, tKey) diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index d786b64de306..50d9887a491d 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/x/slashing/types" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" @@ -24,7 +25,7 @@ var ( ) func TestDecodeStore(t *testing.T) { - encodingConfig := moduletestutil.MakeTestEncodingConfig(slashing.AppModule{}) + encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, slashing.AppModule{}) cdc := encodingConfig.Codec dec := simulation.NewDecodeStore(cdc) diff --git a/x/staking/client/cli/tx_test.go b/x/staking/client/cli/tx_test.go index 10edb4c1344c..39d8957bc640 100644 --- a/x/staking/client/cli/tx_test.go +++ b/x/staking/client/cli/tx_test.go @@ -17,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" @@ -44,7 +45,7 @@ func TestCLITestSuite(t *testing.T) { } func (s *CLITestSuite) SetupSuite() { - s.encCfg = testutilmod.MakeTestEncodingConfig(staking.AppModule{}) + s.encCfg = testutilmod.MakeTestEncodingConfig(codectestutil.CodecOptions{}, staking.AppModule{}) s.kr = keyring.NewInMemory(s.encCfg.Codec) s.baseCtx = client.Context{}. WithKeyring(s.kr). diff --git a/x/staking/keeper/keeper_test.go b/x/staking/keeper/keeper_test.go index 16b87cbbeec1..de6cfe138b5f 100644 --- a/x/staking/keeper/keeper_test.go +++ b/x/staking/keeper/keeper_test.go @@ -21,6 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" @@ -58,7 +59,7 @@ func (s *KeeperTestSuite) SetupTest() { testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) s.key = key ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) - encCfg := moduletestutil.MakeTestEncodingConfig() + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) s.cdc = encCfg.Codec ctrl := gomock.NewController(s.T()) diff --git a/x/staking/migrations/v5/migrations_test.go b/x/staking/migrations/v5/migrations_test.go index 1f731415f342..07e19b3fcb8e 100644 --- a/x/staking/migrations/v5/migrations_test.go +++ b/x/staking/migrations/v5/migrations_test.go @@ -18,6 +18,7 @@ import ( stakingtypes "cosmossdk.io/x/staking/types" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" @@ -50,7 +51,7 @@ func TestHistoricalKeysMigration(t *testing.T) { testCases[int64(height)] = testCase{} } - cdc := moduletestutil.MakeTestEncodingConfig().Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec for height := range testCases { testCases[height] = testCase{ oldKey: v5.GetLegacyHistoricalInfoKey(height), @@ -80,7 +81,7 @@ func createHistoricalInfo(height int64, chainID string) *stakingtypes.Historical } func TestDelegationsByValidatorMigrations(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig(staking.AppModule{}).Codec + cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, staking.AppModule{}).Codec storeKey := storetypes.NewKVStoreKey(v5.ModuleName) tKey := storetypes.NewTransientStoreKey("transient_test") ctx := testutil.DefaultContext(storeKey, tKey) diff --git a/x/staking/simulation/decoder_test.go b/x/staking/simulation/decoder_test.go index 308d054220bb..897219b86cce 100644 --- a/x/staking/simulation/decoder_test.go +++ b/x/staking/simulation/decoder_test.go @@ -10,6 +10,7 @@ import ( "cosmossdk.io/x/staking/simulation" "cosmossdk.io/x/staking/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" @@ -22,7 +23,7 @@ var ( ) func TestDecodeStore(t *testing.T) { - cdc := testutil.MakeTestEncodingConfig().Codec + cdc := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec dec := simulation.NewDecodeStore(cdc) oneIntBz, err := math.OneInt().Marshal() diff --git a/x/upgrade/keeper/abci_test.go b/x/upgrade/keeper/abci_test.go index e74005dd8949..831d39cf1957 100644 --- a/x/upgrade/keeper/abci_test.go +++ b/x/upgrade/keeper/abci_test.go @@ -21,6 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -111,7 +112,7 @@ func (s *TestSuite) VerifySet(t *testing.T, skipUpgradeHeights map[int64]bool) { func setupTest(t *testing.T, height int64, skip map[int64]bool) *TestSuite { t.Helper() s := TestSuite{} - s.encCfg = moduletestutil.MakeTestEncodingConfig(upgrade.AppModule{}) + s.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, upgrade.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) env := runtime.NewEnvironment(storeService, log.NewNopLogger()) @@ -458,7 +459,7 @@ func TestBinaryVersion(t *testing.T) { func TestDowngradeVerification(t *testing.T) { // could not use setupTest() here, because we have to use the same key // for the two keepers. - encCfg := moduletestutil.MakeTestEncodingConfig(upgrade.AppModule{}) + encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, upgrade.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) env := runtime.NewEnvironment(storeService, log.NewNopLogger()) diff --git a/x/upgrade/keeper/grpc_query_test.go b/x/upgrade/keeper/grpc_query_test.go index 2911f11380c7..c866df64e767 100644 --- a/x/upgrade/keeper/grpc_query_test.go +++ b/x/upgrade/keeper/grpc_query_test.go @@ -17,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -35,7 +36,7 @@ type UpgradeTestSuite struct { } func (suite *UpgradeTestSuite) SetupTest() { - suite.encCfg = moduletestutil.MakeTestEncodingConfig(upgrade.AppModule{}) + suite.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, upgrade.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) env := runtime.NewEnvironment(storeService, log.NewNopLogger()) diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index 798c93d9ce99..f17d6ae870d8 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -19,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -43,7 +44,7 @@ type KeeperTestSuite struct { } func (s *KeeperTestSuite) SetupTest() { - s.encCfg = moduletestutil.MakeTestEncodingConfig(upgrade.AppModule{}) + s.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, upgrade.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) storeService := runtime.NewKVStoreService(key) env := runtime.NewEnvironment(storeService, log.NewNopLogger())