diff --git a/CHANGELOG.md b/CHANGELOG.md index d2594697cc..43b86a943c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,6 +88,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/foundation) [\#729](https://github.com/line/lbm-sdk/pull/729) add UpdateParams to x/foundation * (amino) [\#736](https://github.com/line/lbm-sdk/pull/736) apply the missing amino codec registratoin of cosmos-sdk * (x/foundation) [\#744](https://github.com/line/lbm-sdk/pull/744) revisit foundation operator +* (store,x/wasm) [\#742](https://github.com/line/lbm-sdk/pull/742) fix to add error message in GetByteCode() ### Bug Fixes * (x/wasm) [\#453](https://github.com/line/lbm-sdk/pull/453) modify wasm grpc query api path @@ -102,7 +103,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/token) [\#599](https://github.com/line/lbm-sdk/pull/599) fix the order of events * (x/wasm) [\#640](https://github.com/line/lbm-sdk/pull/640) remove legacy codes of wasm * (amino) [\#635](https://github.com/line/lbm-sdk/pull/635) change some minor things that haven't been fixed in #549 -* (store) [\#666](https://github.com/line/lbm-sdk/pull/666) change default `iavl-cache-size` and description +* (store) [\#666](https://github.com/line/lbm-sdk/pull/666) change default `iavl-cache-size` and description * (simapp) [\#679](https://github.com/line/lbm-sdk/pull/679) fix the bug not setting `iavl-cache-size` value of `app.toml` * (x/foundation) [\#687](https://github.com/line/lbm-sdk/pull/687) fix bugs on aborting x/foundation proposals * (global) [\#694](https://github.com/line/lbm-sdk/pull/694) replace deprecated functions since go 1.16 or 1.17 diff --git a/store/types/store.go b/store/types/store.go index 99eec0ae6a..6f9733245c 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -203,7 +203,7 @@ type CommitMultiStore interface { type KVStore interface { Store - // Get returns nil iff key doesn't exist. Panics on nil key. + // Get returns nil if key doesn't exist. Panics on nil key. Get(key []byte) []byte // Has checks if a key exists. Panics on nil key. diff --git a/x/wasm/keeper/keeper.go b/x/wasm/keeper/keeper.go index 299c4e64ac..0c1361645c 100644 --- a/x/wasm/keeper/keeper.go +++ b/x/wasm/keeper/keeper.go @@ -876,7 +876,7 @@ func (k Keeper) GetByteCode(ctx sdk.Context, codeID uint64) ([]byte, error) { var codeInfo types.CodeInfo codeInfoBz := store.Get(types.GetCodeKey(codeID)) if codeInfoBz == nil { - return nil, nil + return nil, types.ErrNotFound } k.cdc.MustUnmarshal(codeInfoBz, &codeInfo) return k.wasmVM.GetCode(codeInfo.CodeHash) diff --git a/x/wasm/keeper/keeper_test.go b/x/wasm/keeper/keeper_test.go index 92e1bcc0e1..402785f982 100644 --- a/x/wasm/keeper/keeper_test.go +++ b/x/wasm/keeper/keeper_test.go @@ -1928,3 +1928,40 @@ func TestIterateInactiveContracts(t *testing.T) { expectList := []sdk.AccAddress{example1.Contract, example2.Contract} assert.ElementsMatch(t, expectList, inactiveContracts) } + +func TestKeeper_GetByteCode(t *testing.T) { + + ctx, keepers := CreateTestInput(t, false, SupportedFeatures, nil, nil) + keeper := keepers.ContractKeeper + + deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) + creator := keepers.Faucet.NewFundedAccount(ctx, deposit...) + + em := sdk.NewEventManager() + _, err := keeper.Create(ctx.WithEventManager(em), creator, hackatomWasm, nil) + require.NoError(t, err) + + tests := []struct { + name string + codeID uint64 + want []byte + wantErr bool + expErr *sdkerrors.Error + }{ + {name: "success", codeID: 1, want: hackatomWasm, wantErr: false, expErr: nil}, + {name: "not found contract", codeID: 42, want: nil, wantErr: true, expErr: types.ErrNotFound}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := keepers.WasmKeeper.GetByteCode(ctx, tt.codeID) + if tt.wantErr { + require.Equal(t, err, tt.expErr) + return + } + require.NoError(t, err) + require.Equal(t, tt.want, got) + + }) + } +}