@agoric/cosmos 0.35.0-u19.2 → 0.35.0-u21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/.clang-format +116 -0
  2. package/CHANGELOG.md +18 -18
  3. package/Makefile +38 -67
  4. package/ante/ante.go +2 -2
  5. package/ante/inbound_test.go +1 -1
  6. package/app/app.go +173 -142
  7. package/app/export.go +6 -6
  8. package/app/genesis.go +4 -0
  9. package/app/sim_test.go +299 -50
  10. package/app/upgrade.go +142 -96
  11. package/app/upgrade_test.go +63 -0
  12. package/cmd/agd/agvm.go +1 -1
  13. package/cmd/agd/main.go +1 -1
  14. package/cmd/libdaemon/main.go +34 -1
  15. package/daemon/cmd/root.go +26 -35
  16. package/daemon/cmd/root_test.go +5 -4
  17. package/daemon/cmd/testnet.go +221 -95
  18. package/daemon/main.go +1 -0
  19. package/git-revision.txt +1 -1
  20. package/go.mod +93 -58
  21. package/go.sum +148 -95
  22. package/package.json +6 -3
  23. package/proto/agoric/swingset/genesis.proto +7 -11
  24. package/proto/agoric/swingset/msgs.proto +56 -75
  25. package/proto/agoric/swingset/query.proto +7 -10
  26. package/proto/agoric/swingset/swingset.proto +79 -108
  27. package/proto/agoric/vbank/genesis.proto +5 -5
  28. package/proto/agoric/vbank/msgs.proto +1 -2
  29. package/proto/agoric/vbank/vbank.proto +42 -52
  30. package/proto/agoric/vibc/msgs.proto +8 -11
  31. package/proto/agoric/vstorage/genesis.proto +6 -9
  32. package/proto/agoric/vstorage/query.proto +19 -48
  33. package/proto/agoric/vstorage/vstorage.proto +4 -10
  34. package/proto/agoric/vtransfer/genesis.proto +7 -7
  35. package/proto/buf.gen.gogo.yaml +8 -0
  36. package/proto/buf.gen.pulsar.yaml +17 -0
  37. package/proto/buf.gen.swagger.yaml +5 -0
  38. package/proto/buf.yaml +10 -0
  39. package/scripts/protocgen.sh +14 -21
  40. package/third_party/proto/amino/amino.proto +79 -0
  41. package/third_party/proto/cosmos/base/v1beta1/coin.proto +7 -2
  42. package/third_party/proto/cosmos/ics23/v1/proofs.proto +243 -0
  43. package/third_party/proto/cosmos/msg/v1/msg.proto +30 -0
  44. package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +17 -5
  45. package/third_party/proto/cosmos_proto/cosmos.proto +16 -1
  46. package/third_party/proto/gogoproto/gogo.proto +2 -2
  47. package/third_party/proto/google/protobuf/any.proto +6 -3
  48. package/third_party/proto/ibc/core/channel/v1/channel.proto +1 -1
  49. package/third_party/proto/ibc/core/client/v1/client.proto +4 -2
  50. package/types/address_hooks.go +5 -12
  51. package/types/address_hooks_test.go +34 -34
  52. package/types/codec.go +23 -0
  53. package/types/ibc_packet.go +64 -0
  54. package/types/ibc_packet_test.go +117 -0
  55. package/vm/client.go +32 -7
  56. package/vm/proto_json.go +2 -2
  57. package/x/swingset/abci.go +1 -1
  58. package/x/swingset/alias.go +0 -1
  59. package/x/swingset/config.go +1 -1
  60. package/x/swingset/keeper/extension_snapshotter.go +1 -1
  61. package/x/swingset/keeper/extension_snapshotter_test.go +1 -1
  62. package/x/swingset/keeper/keeper.go +1 -1
  63. package/x/swingset/keeper/keeper_test.go +1 -1
  64. package/x/swingset/keeper/querier.go +1 -30
  65. package/x/swingset/keeper/swing_store_exports_handler.go +1 -1
  66. package/x/swingset/keeper/swing_store_exports_handler_test.go +1 -1
  67. package/x/swingset/module.go +1 -14
  68. package/x/swingset/types/default-params.go +24 -16
  69. package/x/swingset/types/genesis.pb.go +2 -2
  70. package/x/swingset/types/msgs.pb.go +4 -3
  71. package/x/swingset/types/msgs_test.go +1 -1
  72. package/x/swingset/types/query.pb.go +4 -3
  73. package/x/swingset/types/swingset.pb.go +2 -2
  74. package/x/vbank/genesis.go +1 -1
  75. package/x/vbank/keeper/querier.go +1 -21
  76. package/x/vbank/module.go +1 -16
  77. package/x/vbank/types/genesis.pb.go +2 -2
  78. package/x/vbank/types/msgs.pb.go +3 -2
  79. package/x/vbank/types/query.pb.go +4 -3
  80. package/x/vbank/types/vbank.pb.go +2 -2
  81. package/x/vbank/vbank_test.go +95 -16
  82. package/x/vibc/keeper/keeper.go +8 -5
  83. package/x/vibc/keeper/migrations.go +36 -0
  84. package/x/vibc/keeper/triggers.go +6 -32
  85. package/x/vibc/module.go +9 -17
  86. package/x/vibc/types/expected_keepers.go +6 -10
  87. package/x/vibc/types/ibc_module.go +30 -20
  88. package/x/vibc/types/msgs.go +1 -1
  89. package/x/vibc/types/msgs.pb.go +5 -4
  90. package/x/vibc/types/receiver.go +17 -17
  91. package/x/vlocalchain/keeper/keeper.go +3 -3
  92. package/x/vlocalchain/types/vlocalchain.pb.go +1 -1
  93. package/x/vlocalchain/vlocalchain_test.go +6 -6
  94. package/x/vstorage/README.md +0 -8
  95. package/x/vstorage/alias.go +0 -1
  96. package/x/vstorage/client/cli/query.go +1 -1
  97. package/x/vstorage/genesis.go +1 -1
  98. package/x/vstorage/keeper/keeper.go +40 -5
  99. package/x/vstorage/keeper/keeper_test.go +24 -24
  100. package/x/vstorage/keeper/querier.go +1 -32
  101. package/x/vstorage/keeper/querier_test.go +41 -6
  102. package/x/vstorage/module.go +1 -14
  103. package/x/vstorage/types/genesis.pb.go +2 -2
  104. package/x/vstorage/types/path_keys.go +7 -8
  105. package/x/vstorage/types/query.pb.go +8 -5
  106. package/x/vstorage/types/vstorage.pb.go +2 -2
  107. package/x/vstorage/vstorage_test.go +3 -3
  108. package/x/vtransfer/genesis.go +1 -1
  109. package/x/vtransfer/handler.go +4 -2
  110. package/x/vtransfer/ibc_middleware.go +4 -4
  111. package/x/vtransfer/ibc_middleware_test.go +14 -16
  112. package/x/vtransfer/keeper/keeper.go +38 -48
  113. package/x/vtransfer/module.go +1 -14
  114. package/x/vtransfer/types/expected_keepers.go +2 -18
  115. package/x/vtransfer/types/genesis.pb.go +2 -2
  116. package/x/vtransfer/utils_test.go +15 -15
  117. package/daemon/cmd/genaccounts.go +0 -195
  118. package/e2e_test/Makefile +0 -29
  119. package/e2e_test/README.md +0 -100
  120. package/e2e_test/go.mod +0 -239
  121. package/e2e_test/go.sum +0 -1323
  122. package/e2e_test/ibc_conformance_test.go +0 -56
  123. package/e2e_test/pfm_test.go +0 -613
  124. package/e2e_test/util.go +0 -271
package/app/export.go CHANGED
@@ -2,9 +2,10 @@ package gaia
2
2
 
3
3
  import (
4
4
  "encoding/json"
5
+ "fmt"
5
6
  "log"
6
7
 
7
- tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
8
+ tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
8
9
 
9
10
  servertypes "github.com/cosmos/cosmos-sdk/server/types"
10
11
  sdk "github.com/cosmos/cosmos-sdk/types"
@@ -16,7 +17,7 @@ import (
16
17
  // ExportAppStateAndValidators exports the state of the application for a genesis
17
18
  // file.
18
19
  func (app *GaiaApp) ExportAppStateAndValidators(
19
- forZeroHeight bool, jailAllowedAddrs []string,
20
+ forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string,
20
21
  ) (servertypes.ExportedApp, error) {
21
22
  // as if they could withdraw from the start of the next block
22
23
  ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
@@ -25,17 +26,16 @@ func (app *GaiaApp) ExportAppStateAndValidators(
25
26
  // Tendermint will start InitChain.
26
27
  height := app.LastBlockHeight() + 1
27
28
  if forZeroHeight {
28
- height = 0
29
- app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs)
29
+ return servertypes.ExportedApp{}, fmt.Errorf("forZeroHeight not supported")
30
30
  }
31
31
 
32
- genState := app.mm.ExportGenesis(ctx, app.appCodec)
32
+ genState := app.ModuleManager.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
33
33
  appState, err := json.MarshalIndent(genState, "", " ")
34
34
  if err != nil {
35
35
  return servertypes.ExportedApp{}, err
36
36
  }
37
37
 
38
- validators, err := staking.WriteValidators(ctx, app.StakingKeeper)
38
+ validators, err := staking.WriteValidators(ctx, &app.StakingKeeper)
39
39
  return servertypes.ExportedApp{
40
40
  AppState: appState,
41
41
  Validators: validators,
package/app/genesis.go CHANGED
@@ -18,3 +18,7 @@ func NewDefaultGenesisState() GenesisState {
18
18
  encCfg := MakeEncodingConfig()
19
19
  return ModuleBasics.DefaultGenesis(encCfg.Marshaler)
20
20
  }
21
+
22
+ func (_app *GaiaApp) DefaultGenesis() GenesisState {
23
+ return NewDefaultGenesisState()
24
+ }
package/app/sim_test.go CHANGED
@@ -1,112 +1,361 @@
1
- package gaia_test
1
+ package gaia
2
2
 
3
3
  import (
4
4
  "encoding/json"
5
5
  "fmt"
6
+ "math/rand"
6
7
  "os"
8
+ "runtime/debug"
9
+ "strings"
7
10
  "testing"
8
11
 
9
- gaia "github.com/Agoric/agoric-sdk/golang/cosmos/app"
10
-
11
- "github.com/Agoric/agoric-sdk/golang/cosmos/app/helpers"
12
+ dbm "github.com/cometbft/cometbft-db"
13
+ abci "github.com/cometbft/cometbft/abci/types"
14
+ "github.com/cometbft/cometbft/libs/log"
15
+ tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
12
16
  "github.com/stretchr/testify/require"
13
- "github.com/tendermint/tendermint/libs/log"
14
- "github.com/tendermint/tendermint/libs/rand"
15
- dbm "github.com/tendermint/tm-db"
17
+
18
+ "github.com/cosmos/cosmos-sdk/client/flags"
19
+ "github.com/cosmos/cosmos-sdk/server"
20
+ storetypes "github.com/cosmos/cosmos-sdk/store/types"
16
21
 
17
22
  "github.com/cosmos/cosmos-sdk/baseapp"
18
- "github.com/cosmos/cosmos-sdk/simapp"
19
23
  "github.com/cosmos/cosmos-sdk/store"
20
- simulation2 "github.com/cosmos/cosmos-sdk/types/simulation"
24
+ simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
25
+ sdk "github.com/cosmos/cosmos-sdk/types"
26
+ simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
27
+ authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
28
+ authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
29
+ banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
30
+ capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
31
+ distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
32
+ evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
33
+ govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
34
+ minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
35
+ paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
21
36
  "github.com/cosmos/cosmos-sdk/x/simulation"
37
+ simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli"
38
+ slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
39
+ stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
22
40
  )
23
41
 
42
+ // SimAppChainID hardcoded chainID for simulation
43
+ const SimAppChainID = "simulation-app"
44
+
45
+ // Get flags every time the simulator is run
24
46
  func init() {
25
- simapp.GetSimulatorFlags()
47
+ simcli.GetSimulatorFlags()
48
+ }
49
+
50
+ type StoreKeysPrefixes struct {
51
+ A storetypes.StoreKey
52
+ B storetypes.StoreKey
53
+ Prefixes [][]byte
54
+ }
55
+
56
+ // fauxMerkleModeOpt returns a BaseApp option to use a dbStoreAdapter instead of
57
+ // an IAVLStore for faster simulation speed.
58
+ func fauxMerkleModeOpt(bapp *baseapp.BaseApp) {
59
+ bapp.SetFauxMerkleMode()
60
+ }
61
+
62
+ // interBlockCacheOpt returns a BaseApp option function that sets the persistent
63
+ // inter-block write-through cache.
64
+ func interBlockCacheOpt() func(*baseapp.BaseApp) {
65
+ return baseapp.SetInterBlockCache(store.NewCommitKVStoreCacheManager())
26
66
  }
27
67
 
28
- // Profile with:
29
- // /usr/local/go/bin/go test -benchmem -run=^$ github.com/cosmos/cosmos-sdk/GaiaApp -bench ^BenchmarkFullAppSimulation$ -Commit=true -cpuprofile cpu.out
30
- func BenchmarkFullAppSimulation(b *testing.B) {
31
- config, db, dir, logger, _, err := simapp.SetupSimulation("goleveldb-app-sim", "Simulation")
32
- if err != nil {
33
- b.Fatalf("simulation setup failed: %s", err.Error())
68
+ func TestFullAppSimulation(t *testing.T) {
69
+ config := simcli.NewConfigFromFlags()
70
+ config.ChainID = SimAppChainID
71
+
72
+ db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "leveldb-app-sim", "Simulation", simcli.FlagVerboseValue, simcli.FlagEnabledValue)
73
+ if skip {
74
+ t.Skip("skipping application simulation")
34
75
  }
76
+ require.NoError(t, err, "simulation setup failed")
35
77
 
36
78
  defer func() {
37
- db.Close()
38
- err = os.RemoveAll(dir)
39
- if err != nil {
40
- b.Fatal(err)
41
- }
79
+ require.NoError(t, db.Close())
80
+ require.NoError(t, os.RemoveAll(dir))
42
81
  }()
43
82
 
44
- app := gaia.NewGaiaApp(logger, db, nil, true, map[int64]bool{}, gaia.DefaultNodeHome, simapp.FlagPeriodValue, gaia.MakeEncodingConfig(), simapp.EmptyAppOptions{}, interBlockCacheOpt())
83
+ appOptions := make(simtestutil.AppOptionsMap, 0)
84
+ appOptions[flags.FlagHome] = DefaultNodeHome
85
+ appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue
45
86
 
46
- // Run randomized simulation:w
87
+ app := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
88
+ require.Equal(t, "SimApp", app.Name())
89
+
90
+ // run randomized simulation
47
91
  _, simParams, simErr := simulation.SimulateFromSeed(
48
- b,
92
+ t,
49
93
  os.Stdout,
50
94
  app.BaseApp,
51
- simapp.AppStateFn(app.AppCodec(), app.SimulationManager()),
52
- simulation2.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
53
- simapp.SimulationOperations(app, app.AppCodec(), config),
54
- app.ModuleAccountAddrs(),
95
+ simtestutil.AppStateFn(app.AppCodec(), app.SimulationManager(), app.DefaultGenesis()),
96
+ simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
97
+ simtestutil.SimulationOperations(app, app.AppCodec(), config),
98
+ BlockedAddresses(),
55
99
  config,
56
100
  app.AppCodec(),
57
101
  )
58
102
 
59
103
  // export state and simParams before the simulation error is checked
60
- if err = simapp.CheckExportSimulation(app, config, simParams); err != nil {
61
- b.Fatal(err)
104
+ err = simtestutil.CheckExportSimulation(app, config, simParams)
105
+ require.NoError(t, err)
106
+ require.NoError(t, simErr)
107
+
108
+ if config.Commit {
109
+ simtestutil.PrintStats(db)
62
110
  }
111
+ }
112
+
113
+ func TestAppImportExport(t *testing.T) {
114
+ config := simcli.NewConfigFromFlags()
115
+ config.ChainID = SimAppChainID
63
116
 
64
- if simErr != nil {
65
- b.Fatal(simErr)
117
+ db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "leveldb-app-sim", "Simulation", simcli.FlagVerboseValue, simcli.FlagEnabledValue)
118
+ if skip {
119
+ t.Skip("skipping application import/export simulation")
66
120
  }
121
+ require.NoError(t, err, "simulation setup failed")
122
+
123
+ defer func() {
124
+ require.NoError(t, db.Close())
125
+ require.NoError(t, os.RemoveAll(dir))
126
+ }()
127
+
128
+ appOptions := make(simtestutil.AppOptionsMap, 0)
129
+ appOptions[flags.FlagHome] = DefaultNodeHome
130
+ appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue
131
+
132
+ app := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
133
+ require.Equal(t, "SimApp", app.Name())
134
+
135
+ // Run randomized simulation
136
+ _, simParams, simErr := simulation.SimulateFromSeed(
137
+ t,
138
+ os.Stdout,
139
+ app.BaseApp,
140
+ simtestutil.AppStateFn(app.AppCodec(), app.SimulationManager(), app.DefaultGenesis()),
141
+ simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
142
+ simtestutil.SimulationOperations(app, app.AppCodec(), config),
143
+ BlockedAddresses(),
144
+ config,
145
+ app.AppCodec(),
146
+ )
147
+
148
+ // export state and simParams before the simulation error is checked
149
+ err = simtestutil.CheckExportSimulation(app, config, simParams)
150
+ require.NoError(t, err)
151
+ require.NoError(t, simErr)
67
152
 
68
153
  if config.Commit {
69
- simapp.PrintStats(db)
154
+ simtestutil.PrintStats(db)
155
+ }
156
+
157
+ fmt.Printf("exporting genesis...\n")
158
+
159
+ exported, err := app.ExportAppStateAndValidators(false, []string{}, []string{})
160
+ require.NoError(t, err)
161
+
162
+ fmt.Printf("importing genesis...\n")
163
+
164
+ newDB, newDir, _, _, err := simtestutil.SetupSimulation(config, "leveldb-app-sim-2", "Simulation-2", simcli.FlagVerboseValue, simcli.FlagEnabledValue)
165
+ require.NoError(t, err, "simulation setup failed")
166
+
167
+ defer func() {
168
+ require.NoError(t, newDB.Close())
169
+ require.NoError(t, os.RemoveAll(newDir))
170
+ }()
171
+
172
+ newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
173
+ require.Equal(t, "SimApp", newApp.Name())
174
+
175
+ var genesisState GenesisState
176
+ err = json.Unmarshal(exported.AppState, &genesisState)
177
+ require.NoError(t, err)
178
+
179
+ defer func() {
180
+ if r := recover(); r != nil {
181
+ err := fmt.Sprintf("%v", r)
182
+ if !strings.Contains(err, "validator set is empty after InitGenesis") {
183
+ panic(r)
184
+ }
185
+ logger.Info("Skipping simulation as all validators have been unbonded")
186
+ logger.Info("err", err, "stacktrace", string(debug.Stack()))
187
+ }
188
+ }()
189
+
190
+ ctxA := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
191
+ ctxB := newApp.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
192
+ newApp.ModuleManager.InitGenesis(ctxB, app.AppCodec(), genesisState)
193
+ newApp.StoreConsensusParams(ctxB, exported.ConsensusParams)
194
+
195
+ fmt.Printf("comparing stores...\n")
196
+
197
+ storeKeysPrefixes := []StoreKeysPrefixes{
198
+ {app.GetKey(authtypes.StoreKey), newApp.GetKey(authtypes.StoreKey), [][]byte{}},
199
+ {
200
+ app.GetKey(stakingtypes.StoreKey), newApp.GetKey(stakingtypes.StoreKey),
201
+ [][]byte{
202
+ stakingtypes.UnbondingQueueKey, stakingtypes.RedelegationQueueKey, stakingtypes.ValidatorQueueKey,
203
+ stakingtypes.HistoricalInfoKey, stakingtypes.UnbondingIDKey, stakingtypes.UnbondingIndexKey, stakingtypes.UnbondingTypeKey, stakingtypes.ValidatorUpdatesKey,
204
+ },
205
+ }, // ordering may change but it doesn't matter
206
+ {app.GetKey(slashingtypes.StoreKey), newApp.GetKey(slashingtypes.StoreKey), [][]byte{}},
207
+ {app.GetKey(minttypes.StoreKey), newApp.GetKey(minttypes.StoreKey), [][]byte{}},
208
+ {app.GetKey(distrtypes.StoreKey), newApp.GetKey(distrtypes.StoreKey), [][]byte{}},
209
+ {app.GetKey(banktypes.StoreKey), newApp.GetKey(banktypes.StoreKey), [][]byte{banktypes.BalancesPrefix}},
210
+ {app.GetKey(paramtypes.StoreKey), newApp.GetKey(paramtypes.StoreKey), [][]byte{}},
211
+ {app.GetKey(govtypes.StoreKey), newApp.GetKey(govtypes.StoreKey), [][]byte{}},
212
+ {app.GetKey(evidencetypes.StoreKey), newApp.GetKey(evidencetypes.StoreKey), [][]byte{}},
213
+ {app.GetKey(capabilitytypes.StoreKey), newApp.GetKey(capabilitytypes.StoreKey), [][]byte{}},
214
+ {app.GetKey(authzkeeper.StoreKey), newApp.GetKey(authzkeeper.StoreKey), [][]byte{authzkeeper.GrantKey, authzkeeper.GrantQueuePrefix}},
215
+ }
216
+
217
+ for _, skp := range storeKeysPrefixes {
218
+ storeA := ctxA.KVStore(skp.A)
219
+ storeB := ctxB.KVStore(skp.B)
220
+
221
+ failedKVAs, failedKVBs := sdk.DiffKVStores(storeA, storeB, skp.Prefixes)
222
+ require.Equal(t, len(failedKVAs), len(failedKVBs), "unequal sets of key-values to compare")
223
+
224
+ fmt.Printf("compared %d different key/value pairs between %s and %s\n", len(failedKVAs), skp.A, skp.B)
225
+ require.Equal(t, 0, len(failedKVAs), simtestutil.GetSimulationLog(skp.A.Name(), app.SimulationManager().StoreDecoders, failedKVAs, failedKVBs))
70
226
  }
71
227
  }
72
228
 
73
- // interBlockCacheOpt returns a BaseApp option function that sets the persistent
74
- // inter-block write-through cache.
75
- func interBlockCacheOpt() func(*baseapp.BaseApp) {
76
- return baseapp.SetInterBlockCache(store.NewCommitKVStoreCacheManager())
229
+ func TestAppSimulationAfterImport(t *testing.T) {
230
+ config := simcli.NewConfigFromFlags()
231
+ config.ChainID = SimAppChainID
232
+
233
+ db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "leveldb-app-sim", "Simulation", simcli.FlagVerboseValue, simcli.FlagEnabledValue)
234
+ if skip {
235
+ t.Skip("skipping application simulation after import")
236
+ }
237
+ require.NoError(t, err, "simulation setup failed")
238
+
239
+ defer func() {
240
+ require.NoError(t, db.Close())
241
+ require.NoError(t, os.RemoveAll(dir))
242
+ }()
243
+
244
+ appOptions := make(simtestutil.AppOptionsMap, 0)
245
+ appOptions[flags.FlagHome] = DefaultNodeHome
246
+ appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue
247
+
248
+ app := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
249
+ require.Equal(t, "SimApp", app.Name())
250
+
251
+ // Run randomized simulation
252
+ stopEarly, simParams, simErr := simulation.SimulateFromSeed(
253
+ t,
254
+ os.Stdout,
255
+ app.BaseApp,
256
+ simtestutil.AppStateFn(app.AppCodec(), app.SimulationManager(), app.DefaultGenesis()),
257
+ simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
258
+ simtestutil.SimulationOperations(app, app.AppCodec(), config),
259
+ BlockedAddresses(),
260
+ config,
261
+ app.AppCodec(),
262
+ )
263
+
264
+ // export state and simParams before the simulation error is checked
265
+ err = simtestutil.CheckExportSimulation(app, config, simParams)
266
+ require.NoError(t, err)
267
+ require.NoError(t, simErr)
268
+
269
+ if config.Commit {
270
+ simtestutil.PrintStats(db)
271
+ }
272
+
273
+ if stopEarly {
274
+ fmt.Println("can't export or import a zero-validator genesis, exiting test...")
275
+ return
276
+ }
277
+
278
+ fmt.Printf("exporting genesis...\n")
279
+
280
+ exported, err := app.ExportAppStateAndValidators(true, []string{}, []string{})
281
+ require.NoError(t, err)
282
+
283
+ fmt.Printf("importing genesis...\n")
284
+
285
+ newDB, newDir, _, _, err := simtestutil.SetupSimulation(config, "leveldb-app-sim-2", "Simulation-2", simcli.FlagVerboseValue, simcli.FlagEnabledValue)
286
+ require.NoError(t, err, "simulation setup failed")
287
+
288
+ defer func() {
289
+ require.NoError(t, newDB.Close())
290
+ require.NoError(t, os.RemoveAll(newDir))
291
+ }()
292
+
293
+ newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
294
+ require.Equal(t, "SimApp", newApp.Name())
295
+
296
+ newApp.InitChain(abci.RequestInitChain{
297
+ ChainId: SimAppChainID,
298
+ AppStateBytes: exported.AppState,
299
+ })
300
+
301
+ _, _, err = simulation.SimulateFromSeed(
302
+ t,
303
+ os.Stdout,
304
+ newApp.BaseApp,
305
+ simtestutil.AppStateFn(app.AppCodec(), app.SimulationManager(), app.DefaultGenesis()),
306
+ simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
307
+ simtestutil.SimulationOperations(newApp, newApp.AppCodec(), config),
308
+ BlockedAddresses(),
309
+ config,
310
+ app.AppCodec(),
311
+ )
312
+ require.NoError(t, err)
77
313
  }
78
314
 
79
- // // TODO: Make another test for the fuzzer itself, which just has noOp txs
80
- // // and doesn't depend on the application.
315
+ // TODO: Make another test for the fuzzer itself, which just has noOp txs
316
+ // and doesn't depend on the application.
81
317
  func TestAppStateDeterminism(t *testing.T) {
82
- if !simapp.FlagEnabledValue {
318
+ if !simcli.FlagEnabledValue {
83
319
  t.Skip("skipping application simulation")
84
320
  }
85
321
 
86
- config := simapp.NewConfigFromFlags()
322
+ config := simcli.NewConfigFromFlags()
87
323
  config.InitialBlockHeight = 1
88
324
  config.ExportParamsPath = ""
89
325
  config.OnOperation = false
90
326
  config.AllInvariants = false
91
- config.ChainID = helpers.SimAppChainID
327
+ config.ChainID = SimAppChainID
92
328
 
93
329
  numSeeds := 3
94
330
  numTimesToRunPerSeed := 5
331
+
332
+ // We will be overriding the random seed and just run a single simulation on the provided seed value
333
+ if config.Seed != simcli.DefaultSeedValue {
334
+ numSeeds = 1
335
+ }
336
+
95
337
  appHashList := make([]json.RawMessage, numTimesToRunPerSeed)
338
+ appOptions := make(simtestutil.AppOptionsMap, 0)
339
+ appOptions[flags.FlagHome] = DefaultNodeHome
340
+ appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue
96
341
 
97
342
  for i := 0; i < numSeeds; i++ {
98
- config.Seed = rand.Int63()
343
+ if config.Seed == simcli.DefaultSeedValue {
344
+ config.Seed = rand.Int63()
345
+ }
346
+
347
+ fmt.Println("config.Seed: ", config.Seed)
99
348
 
100
349
  for j := 0; j < numTimesToRunPerSeed; j++ {
101
350
  var logger log.Logger
102
- if simapp.FlagVerboseValue {
351
+ if simcli.FlagVerboseValue {
103
352
  logger = log.TestingLogger()
104
353
  } else {
105
354
  logger = log.NewNopLogger()
106
355
  }
107
356
 
108
357
  db := dbm.NewMemDB()
109
- app := gaia.NewGaiaApp(logger, db, nil, true, map[int64]bool{}, gaia.DefaultNodeHome, simapp.FlagPeriodValue, gaia.MakeEncodingConfig(), simapp.EmptyAppOptions{}, interBlockCacheOpt())
358
+ app := NewSimApp(logger, db, nil, true, appOptions, interBlockCacheOpt(), baseapp.SetChainID(SimAppChainID))
110
359
 
111
360
  fmt.Printf(
112
361
  "running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
@@ -117,17 +366,17 @@ func TestAppStateDeterminism(t *testing.T) {
117
366
  t,
118
367
  os.Stdout,
119
368
  app.BaseApp,
120
- simapp.AppStateFn(app.AppCodec(), app.SimulationManager()),
121
- simulation2.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
122
- simapp.SimulationOperations(app, app.AppCodec(), config),
123
- app.ModuleAccountAddrs(),
369
+ simtestutil.AppStateFn(app.AppCodec(), app.SimulationManager(), app.DefaultGenesis()),
370
+ simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
371
+ simtestutil.SimulationOperations(app, app.AppCodec(), config),
372
+ BlockedAddresses(),
124
373
  config,
125
374
  app.AppCodec(),
126
375
  )
127
376
  require.NoError(t, err)
128
377
 
129
378
  if config.Commit {
130
- simapp.PrintStats(db)
379
+ simtestutil.PrintStats(db)
131
380
  }
132
381
 
133
382
  appHash := app.LastCommitID().Hash