Skip to content

Commit ac8d3c6

Browse files
committed
Merge branch 'main' into alex/testnet
* main: refactor(x/simulation)!: remove accounts string (cosmos#20056) fix(baseapp): don't share global gas meter in tx execution (cosmos#19616) feat(x/accounts): use router service from env (cosmos#20003) refactor(x): remove Address.String() (cosmos#20048) build(deps): Bump github.com/jhump/protoreflect from 1.15.6 to 1.16.0 in /tests (cosmos#20040) feat(collections): add `NewJSONValueCodec` (cosmos#19861)
2 parents 066f11d + 9d6c6ef commit ac8d3c6

32 files changed

Lines changed: 255 additions & 200 deletions

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,11 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
116116
* (crypto) [#20027](https://github.com/cosmos/cosmos-sdk/pull/20027) secp256r1 keys now implement gogoproto's customtype interface.
117117
* (x/bank) [#20028](https://github.com/cosmos/cosmos-sdk/pull/20028) Align query with multi denoms for send-enabled.
118118
* (cli) [#20020](https://github.com/cosmos/cosmos-sdk/pull/20020) Make bootstrap-state command support both new and legacy genesis format.
119+
* (baseapp) [#19616](https://github.com/cosmos/cosmos-sdk/pull/19616) Don't share gas meter in tx execution.
119120

120121
### API Breaking Changes
121122

123+
* (x/simulation)[#20056](https://github.com/cosmos/cosmos-sdk/pull/20056) `SimulateFromSeed` now takes an address codec as argument.
122124
* (x/crisis) [#20043](https://github.com/cosmos/cosmos-sdk/pull/20043) Changed `NewMsgVerifyInvariant` to accept a string as argument instead of an `AccAddress`.
123125
* (x/genutil) [#19926](https://github.com/cosmos/cosmos-sdk/pull/19926) Removal of the Address.String() method and related changes:
124126
* Added an address codec as an argument to `CollectTxs`, `GenAppStateFromConfig`, and `AddGenesisAccount`.

baseapp/baseapp.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,8 @@ func (app *BaseApp) getContextForTx(mode execMode, txBytes []byte) sdk.Context {
666666
panic(fmt.Sprintf("state is nil for mode %v", mode))
667667
}
668668
ctx := modeState.Context().
669-
WithTxBytes(txBytes)
669+
WithTxBytes(txBytes).
670+
WithGasMeter(storetypes.NewInfiniteGasMeter())
670671
// WithVoteInfos(app.voteInfos) // TODO: identify if this is needed
671672

672673
ctx = ctx.WithIsSigverifyTx(app.sigverifyTx)

collections/CHANGELOG.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,20 @@ Ref: https://keepachangelog.com/en/1.0.0/
3333

3434
### Features
3535

36-
* [#19343](https://github.com/cosmos/cosmos-sdk/pull/19343) – Simplify IndexedMap creation by allowing to infer indexes through reflection.
37-
* [#18933](https://github.com/cosmos/cosmos-sdk/pull/18933) – Add LookupMap implementation. It is basic wrapping of the standard Map methods but is not iterable.
38-
* [#17656](https://github.com/cosmos/cosmos-sdk/pull/17656) – Introduces `Vec`, a collection type that allows to represent a growable array on top of a KVStore.
36+
* [#19343](https://github.com/cosmos/cosmos-sdk/pull/19343) Simplify IndexedMap creation by allowing to infer indexes through reflection.
37+
* [#18933](https://github.com/cosmos/cosmos-sdk/pull/18933) Add LookupMap implementation. It is basic wrapping of the standard Map methods but is not iterable.
38+
* [#17656](https://github.com/cosmos/cosmos-sdk/pull/17656) Introduces `Vec`, a collection type that allows to represent a growable array on top of a KVStore.
39+
* [#19861](https://github.com/cosmos/cosmos-sdk/pull/19861) Add `NewJSONValueCodec` value codec as an alternative for `codec.CollValue` from the SDK for non protobuf types.
3940

4041
## [v0.4.0](https://github.com/cosmos/cosmos-sdk/releases/tag/collections%2Fv0.4.0)
4142

4243
### Features
4344

44-
* [#17024](https://github.com/cosmos/cosmos-sdk/pull/17024) - Introduces `Triple`, a composite key with three keys.
45+
* [#17024](https://github.com/cosmos/cosmos-sdk/pull/17024) Introduces `Triple`, a composite key with three keys.
4546

4647
### API Breaking
4748

48-
* [#17290](https://github.com/cosmos/cosmos-sdk/pull/17290) - Collections iteration methods (Iterate, Walk) will not error when the collection is empty.
49+
* [#17290](https://github.com/cosmos/cosmos-sdk/pull/17290) Collections iteration methods (Iterate, Walk) will not error when the collection is empty.
4950

5051
### Improvements
5152

@@ -55,20 +56,20 @@ Ref: https://keepachangelog.com/en/1.0.0/
5556

5657
### Features
5758

58-
* [#16074](https://github.com/cosmos/cosmos-sdk/pull/16607) - Introduces `Clear` method for `Map` and `KeySet`
59+
* [#16074](https://github.com/cosmos/cosmos-sdk/pull/16607) Introduces `Clear` method for `Map` and `KeySet`
5960
* [#16773](https://github.com/cosmos/cosmos-sdk/pull/16773)
60-
* Adds `AltValueCodec` which provides a way to decode a value in two ways.
61-
* Adds the possibility to specify an alternative way to decode the values of `KeySet`, `indexes.Multi`, `indexes.ReversePair`.
61+
* Adds `AltValueCodec` which provides a way to decode a value in two ways.
62+
* Adds the possibility to specify an alternative way to decode the values of `KeySet`, `indexes.Multi`, `indexes.ReversePair`.
6263

6364
## [v0.2.0](https://github.com/cosmos/cosmos-sdk/releases/tag/collections%2Fv0.2.0)
6465

6566
### Features
6667

67-
* [#16074](https://github.com/cosmos/cosmos-sdk/pull/16074) Makes the generic Collection interface public, still highly unstable.
68+
* [#16074](https://github.com/cosmos/cosmos-sdk/pull/16074) Makes the generic Collection interface public, still highly unstable.
6869

6970
### API Breaking
7071

71-
* [#16127](https://github.com/cosmos/cosmos-sdk/pull/16127) In the `Walk` method the call back function being passed is allowed to error.
72+
* [#16127](https://github.com/cosmos/cosmos-sdk/pull/16127) In the `Walk` method the call back function being passed is allowed to error.
7273

7374
## [v0.1.0](https://github.com/cosmos/cosmos-sdk/releases/tag/collections%2Fv0.1.0)
7475

collections/json.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package collections
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
7+
"cosmossdk.io/collections/codec"
8+
)
9+
10+
func NewJSONValueCodec[T any]() codec.ValueCodec[T] {
11+
return jsonValue[T]{
12+
typeName: fmt.Sprintf("%T", new(T)),
13+
}
14+
}
15+
16+
type jsonValue[T any] struct {
17+
typeName string
18+
}
19+
20+
// Decode implements codec.ValueCodec.
21+
func (jsonValue[T]) Decode(b []byte) (T, error) {
22+
var t T
23+
if err := json.Unmarshal(b, &t); err != nil {
24+
return t, err
25+
}
26+
27+
return t, nil
28+
}
29+
30+
// DecodeJSON implements codec.ValueCodec.
31+
func (jsonValue[T]) DecodeJSON(b []byte) (T, error) {
32+
var t T
33+
if err := json.Unmarshal(b, &t); err != nil {
34+
return t, err
35+
}
36+
37+
return t, nil
38+
}
39+
40+
// Encode implements codec.ValueCodec.
41+
func (jsonValue[T]) Encode(value T) ([]byte, error) {
42+
return json.Marshal(value)
43+
}
44+
45+
// EncodeJSON implements codec.ValueCodec.
46+
func (jsonValue[T]) EncodeJSON(value T) ([]byte, error) {
47+
return json.Marshal(value)
48+
}
49+
50+
// Stringify implements codec.ValueCodec.
51+
func (jsonValue[T]) Stringify(value T) string {
52+
return fmt.Sprintf("%v", value)
53+
}
54+
55+
// ValueType implements codec.ValueCodec.
56+
func (jv jsonValue[T]) ValueType() string {
57+
return fmt.Sprintf("json(%s)", jv.typeName)
58+
}

simapp/app.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,8 @@ func NewSimApp(
287287
// add keepers
288288
accountsKeeper, err := accounts.NewKeeper(
289289
appCodec,
290-
runtime.NewEnvironment(runtime.NewKVStoreService(keys[accounts.StoreKey]), logger),
290+
runtime.NewEnvironment(runtime.NewKVStoreService(keys[accounts.StoreKey]), logger, runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())),
291291
signingCtx.AddressCodec(),
292-
app.MsgServiceRouter(),
293-
app.GRPCQueryRouter(),
294292
appCodec.InterfaceRegistry(),
295293
// TESTING: do not add
296294
accountstd.AddAccount("counter", counter.NewAccount),

simapp/app_di.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func NewSimApp(
306306
return app
307307
}
308308

309-
// overwritte default ante handlers with custom ante handlers
309+
// overwrite default ante handlers with custom ante handlers
310310
// set SkipAnteHandler to true in app config and set custom ante handler on baseapp
311311
func (app *SimApp) setCustomAnteHandler() {
312312
anteHandler, err := NewAnteHandler(

simapp/sim_bench_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/cosmos/cosmos-sdk/baseapp"
1212
"github.com/cosmos/cosmos-sdk/client/flags"
13+
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
1314
"github.com/cosmos/cosmos-sdk/server"
1415
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
1516
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
@@ -72,6 +73,7 @@ func BenchmarkFullAppSimulation(b *testing.B) {
7273
BlockedAddresses(),
7374
config,
7475
app.AppCodec(),
76+
codectestutil.CodecOptions{}.GetAddressCodec(),
7577
)
7678

7779
// export state and simParams before the simulation error is checked

simapp/sim_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/cosmos/cosmos-sdk/baseapp"
2828
"github.com/cosmos/cosmos-sdk/client/flags"
29+
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
2930
"github.com/cosmos/cosmos-sdk/server"
3031
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
3132
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
@@ -92,6 +93,7 @@ func TestFullAppSimulation(t *testing.T) {
9293
BlockedAddresses(),
9394
config,
9495
app.AppCodec(),
96+
codectestutil.CodecOptions{}.GetAddressCodec(),
9597
)
9698

9799
// export state and simParams before the simulation error is checked
@@ -140,6 +142,7 @@ func TestAppImportExport(t *testing.T) {
140142
BlockedAddresses(),
141143
config,
142144
app.AppCodec(),
145+
codectestutil.CodecOptions{}.GetAddressCodec(),
143146
)
144147

145148
// export state and simParams before the simulation error is checked
@@ -261,6 +264,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
261264
BlockedAddresses(),
262265
config,
263266
app.AppCodec(),
267+
codectestutil.CodecOptions{}.GetAddressCodec(),
264268
)
265269

266270
// export state and simParams before the simulation error is checked
@@ -313,6 +317,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
313317
BlockedAddresses(),
314318
config,
315319
app.AppCodec(),
320+
codectestutil.CodecOptions{}.GetAddressCodec(),
316321
)
317322
require.NoError(t, err)
318323
}
@@ -392,6 +397,7 @@ func TestAppStateDeterminism(t *testing.T) {
392397
BlockedAddresses(),
393398
config,
394399
app.AppCodec(),
400+
codectestutil.CodecOptions{}.GetAddressCodec(),
395401
)
396402
require.NoError(t, err)
397403

simapp/upgrades.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
epochstypes "cosmossdk.io/x/epochs/types"
99
protocolpooltypes "cosmossdk.io/x/protocolpool/types"
1010
upgradetypes "cosmossdk.io/x/upgrade/types"
11+
1112
"github.com/cosmos/cosmos-sdk/types/module"
1213
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
1314
)

tests/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ require (
3030
github.com/spf13/cobra v1.8.0
3131
github.com/stretchr/testify v1.9.0
3232
google.golang.org/grpc v1.63.2
33-
google.golang.org/protobuf v1.33.0
33+
google.golang.org/protobuf v1.33.1-0.20240408130810-98873a205002
3434
gotest.tools/v3 v3.5.1
3535
pgregory.net/rapid v1.1.0
3636
)
@@ -47,7 +47,7 @@ require (
4747
cosmossdk.io/x/slashing v0.0.0-00010101000000-000000000000
4848
cosmossdk.io/x/staking v0.0.0-20240226161501-23359a0b6d91
4949
github.com/google/go-cmp v0.6.0
50-
github.com/jhump/protoreflect v1.15.6
50+
github.com/jhump/protoreflect v1.16.0
5151
)
5252

5353
require (
@@ -74,7 +74,7 @@ require (
7474
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
7575
github.com/bits-and-blooms/bitset v1.10.0 // indirect
7676
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
77-
github.com/bufbuild/protocompile v0.8.0 // indirect
77+
github.com/bufbuild/protocompile v0.10.0 // indirect
7878
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
7979
github.com/cespare/xxhash v1.1.0 // indirect
8080
github.com/cespare/xxhash/v2 v2.2.0 // indirect

0 commit comments

Comments
 (0)