@@ -6,6 +6,10 @@ import (
6
6
"os"
7
7
"path/filepath"
8
8
"testing"
9
+ "time"
10
+
11
+ "github.com/cosmos/cosmos-sdk/store"
12
+ "github.com/cosmos/cosmos-sdk/store/prefix"
9
13
10
14
"github.com/cosmos/cosmos-sdk/baseapp"
11
15
"github.com/cosmos/cosmos-sdk/codec"
@@ -192,6 +196,37 @@ func TestAppImportExport(t *testing.T) {
192
196
// delete persistent tx counter value
193
197
ctxA .KVStore (app .keys [wasm .StoreKey ]).Delete (wasmtypes .TXCounterPrefix )
194
198
199
+ // reset contract code index in source DB for comparison with dest DB
200
+ dropContractHistory := func (s store.KVStore , keys ... []byte ) {
201
+ for _ , key := range keys {
202
+ prefixStore := prefix .NewStore (s , key )
203
+ iter := prefixStore .Iterator (nil , nil )
204
+ for ; iter .Valid (); iter .Next () {
205
+ prefixStore .Delete (iter .Key ())
206
+ }
207
+ iter .Close ()
208
+ }
209
+ }
210
+ prefixes := [][]byte {wasmtypes .ContractCodeHistoryElementPrefix , wasmtypes .ContractByCodeIDAndCreatedSecondaryIndexPrefix }
211
+ dropContractHistory (ctxA .KVStore (app .keys [wasm .StoreKey ]), prefixes ... )
212
+ dropContractHistory (ctxB .KVStore (newApp .keys [wasm .StoreKey ]), prefixes ... )
213
+
214
+ normalizeContractInfo := func (ctx sdk.Context , app * WasmApp ) {
215
+ var index uint64
216
+ app .wasmKeeper .IterateContractInfo (ctx , func (address sdk.AccAddress , info wasmtypes.ContractInfo ) bool {
217
+ created := & wasmtypes.AbsoluteTxPosition {
218
+ BlockHeight : uint64 (0 ),
219
+ TxIndex : index ,
220
+ }
221
+ info .Created = created
222
+ store := ctx .KVStore (app .keys [wasm .StoreKey ])
223
+ store .Set (wasmtypes .GetContractAddressKey (address ), app .appCodec .MustMarshal (& info ))
224
+ index ++
225
+ return false
226
+ })
227
+ }
228
+ normalizeContractInfo (ctxA , app )
229
+ normalizeContractInfo (ctxB , newApp )
195
230
// diff both stores
196
231
for _ , skp := range storeKeysPrefixes {
197
232
storeA := ctxA .KVStore (skp .A )
@@ -250,5 +285,8 @@ func TestFullAppSimulation(t *testing.T) {
250
285
func AppStateFn (codec codec.Codec , manager * module.SimulationManager ) simtypes.AppStateFn {
251
286
// quick hack to setup app state genesis with our app modules
252
287
simapp .ModuleBasics = ModuleBasics
288
+ if simapp .FlagGenesisTimeValue == 0 { // always set to have a block time
289
+ simapp .FlagGenesisTimeValue = time .Now ().Unix ()
290
+ }
253
291
return simapp .AppStateFn (codec , manager )
254
292
}
0 commit comments