Skip to content

Commit

Permalink
Merge pull request cosmos#493 from CosmWasm/pin_codes_fix
Browse files Browse the repository at this point in the history
Fix InitializePinnedCodes
  • Loading branch information
ethanfrey committed Apr 16, 2021
2 parents d90bf6e + aabc575 commit 69e59fe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ func (k Keeper) InitializePinnedCodes(ctx sdk.Context) error {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PinnedCodeIndexPrefix)
iter := store.Iterator(nil, nil)
for ; iter.Valid(); iter.Next() {
codeInfo := k.GetCodeInfo(ctx, types.ParsePinnedCodeIndex(iter.Value()))
codeInfo := k.GetCodeInfo(ctx, types.ParsePinnedCodeIndex(iter.Key()))
if codeInfo == nil {
return sdkerrors.Wrap(types.ErrNotFound, "code info")
}
Expand Down
31 changes: 31 additions & 0 deletions x/wasm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1278,3 +1278,34 @@ func TestClearContractAdmin(t *testing.T) {
})
}
}

func TestInitializePinnedCodes(t *testing.T) {
ctx, keepers := CreateTestInput(t, false, SupportedFeatures)
k := keepers.WasmKeeper

var capturedChecksums []wasmvm.Checksum
mock := wasmtesting.MockWasmer{PinFn: func(checksum wasmvm.Checksum) error {
capturedChecksums = append(capturedChecksums, checksum)
return nil
}}
wasmtesting.MakeIBCInstantiable(&mock)

const testItems = 3
myCodeIDs := make([]uint64, testItems)
for i := 0; i < testItems; i++ {
myCodeIDs[i] = StoreRandomContract(t, ctx, keepers, &mock).CodeID
require.NoError(t, k.pinCode(ctx, myCodeIDs[i]))
}
capturedChecksums = nil

// when
gotErr := k.InitializePinnedCodes(ctx)

// then
require.NoError(t, gotErr)
require.Len(t, capturedChecksums, testItems)
for i, c := range myCodeIDs {
var exp wasmvm.Checksum = k.GetCodeInfo(ctx, c).CodeHash
assert.Equal(t, exp, capturedChecksums[i])
}
}

0 comments on commit 69e59fe

Please sign in to comment.