Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add error message in GetByteCode() #742

Merged
merged 5 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
zemyblue marked this conversation as resolved.
Show resolved Hide resolved
}
k.cdc.MustUnmarshal(codeInfoBz, &codeInfo)
return k.wasmVM.GetCode(codeInfo.CodeHash)
Expand Down
37 changes: 37 additions & 0 deletions x/wasm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

})
}
}