Persist last code update with contract lookup index

This commit is contained in:
Alex Peters
2021-04-23 13:28:52 +02:00
parent 144a85ae00
commit 8ef2d2695b
5 changed files with 63 additions and 32 deletions

View File

@@ -950,20 +950,29 @@ func TestMigrateReplacesTheSecondIndex(t *testing.T) {
store := ctx.KVStore(keepers.WasmKeeper.storeKey)
oldContractInfo := keepers.WasmKeeper.GetContractInfo(ctx, example.Contract)
require.NotNil(t, oldContractInfo)
exists := store.Has(types.GetContractByCreatedSecondaryIndexKey(example.Contract, oldContractInfo))
createHistoryEntry := types.ContractCodeHistoryEntry{
CodeID: example.CodeID,
Updated: types.NewAbsoluteTxPosition(ctx),
}
exists := store.Has(types.GetContractByCreatedSecondaryIndexKey(example.Contract, createHistoryEntry))
require.True(t, exists)
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) // increment for different block
// when do migrate
newCodeExample := StoreBurnerExampleContract(t, ctx, keepers)
migMsgBz := BurnerExampleInitMsg{Payout: example.CreatorAddr}.GetBytes(t)
_, err := keepers.ContractKeeper.Migrate(ctx, example.Contract, example.CreatorAddr, newCodeExample.CodeID, migMsgBz)
require.NoError(t, err)
// then the new index exists
newContractInfo := keepers.WasmKeeper.GetContractInfo(ctx, example.Contract)
exists = store.Has(types.GetContractByCreatedSecondaryIndexKey(example.Contract, newContractInfo))
migrateHistoryEntry := types.ContractCodeHistoryEntry{
CodeID: newCodeExample.CodeID,
Updated: types.NewAbsoluteTxPosition(ctx),
}
exists = store.Has(types.GetContractByCreatedSecondaryIndexKey(example.Contract, migrateHistoryEntry))
require.True(t, exists)
// and the old index was removed
exists = store.Has(types.GetContractByCreatedSecondaryIndexKey(example.Contract, oldContractInfo))
exists = store.Has(types.GetContractByCreatedSecondaryIndexKey(example.Contract, createHistoryEntry))
require.False(t, exists)
}