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

test: adding e2e for grandpa client recovery test #5027

Merged
merged 185 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
185 commits
Select commit Hold shift + click to select a range
01e8548
feat: add wasm light client module to feat/wasm-clients branch (#3486)
misko9 Jul 6, 2023
40337dd
Merge branch 'main' into feat/wasm-clients
crodriguezvega Jul 6, 2023
90ed894
linting
crodriguezvega Jul 7, 2023
cf6fbfe
Migrated the errors to new package (#4058)
vishal-kanna Jul 12, 2023
28d46c1
Merge branch 'main' into feat/wasm-client
charleenfei Jul 12, 2023
255905a
imp: make separate go.mod for 08-wasm (#4026)
crodriguezvega Jul 13, 2023
8bc0c68
imp: remove code id key from genesis contract (#4032)
crodriguezvega Jul 14, 2023
b6e8a3a
fix imports
crodriguezvega Jul 14, 2023
2901cf8
bump wasmvm (#4086)
crodriguezvega Jul 14, 2023
581a27f
build and test wasm client on PR (#4095)
Reecepbcups Jul 16, 2023
5a1a249
add authority param to wasm NewKeeper (#4092)
Reecepbcups Jul 16, 2023
3607dd2
Merge `storeWasmCode` and `importWasmCode` functions (#4088)
crodriguezvega Jul 17, 2023
9298fe6
Pin code to the wasm VM cache (#4093)
Reecepbcups Jul 18, 2023
731dbbf
just some renaming
crodriguezvega Jul 20, 2023
59ccad5
renaming to align with x/wasm naming (#4091)
crodriguezvega Jul 20, 2023
62ed4fb
imp: disallow submessage execution (#4130)
crodriguezvega Jul 20, 2023
341350a
use sudo (#4131)
crodriguezvega Jul 20, 2023
f822b4f
fix wrapf warning (#4172)
DimitrisJim Jul 25, 2023
bffb649
Merge branch 'main' into feat/wasm-clients
crodriguezvega Jul 30, 2023
bf9d465
Add linting for 08-wasm module (#4206)
DimitrisJim Aug 1, 2023
ed41863
add 08-wasm global store key (#4185)
crodriguezvega Aug 1, 2023
de89920
imp: delegate store operation of `clientState` and `consensusState` i…
crodriguezvega Aug 1, 2023
644367f
imp: remove `timestamp` from `consensusState` and query contract to r…
crodriguezvega Aug 1, 2023
20d4d7e
imp: remove `height` from `header` and merge `header` with `misbehavi…
crodriguezvega Aug 1, 2023
54f29ee
imp: add query and sudo message types to encapsulate all variants of …
crodriguezvega Aug 1, 2023
c4f8da4
add 08-wasm Keeper constructor that accepts pointer to Wasm VM instan…
crodriguezvega Aug 1, 2023
2e17bb2
Allow same VM to be assigned to the global vm. (#4236)
DimitrisJim Aug 3, 2023
49c5e7d
Disallow events, attributes being returned from a contract. (#4222)
DimitrisJim Aug 3, 2023
4f0a711
Clean up vm entry points (#4279)
DimitrisJim Aug 14, 2023
479f470
Merge branch 'main' into feat/wasm-clients
crodriguezvega Aug 14, 2023
2a7c242
add halborn audit report
adiraviraj Aug 15, 2023
fb9eed5
Add files via upload
adiraviraj Aug 15, 2023
03d077b
add wasm client audit reports (#4351)
adiraviraj Aug 15, 2023
16e1026
Document contract api. (#4283)
DimitrisJim Aug 15, 2023
2913dbd
oh linter you. (#4369)
DimitrisJim Aug 17, 2023
83ca9bb
deps(08-wasm): bump SDK v0.47.5 (#4540)
crodriguezvega Sep 1, 2023
fb745e8
add 08-wasm to dependabot
crodriguezvega Sep 1, 2023
1425ca2
Merge branch 'main' into feat/wasm-clients
crodriguezvega Sep 1, 2023
17d255c
cherry pick commit fixing broken links
crodriguezvega Sep 5, 2023
8f5354b
Fix dependabot file.
DimitrisJim Sep 7, 2023
120d45b
Add new cmd to store code via a gov proposal. (#4565)
DimitrisJim Sep 7, 2023
81086e4
update wasm clients branch linter to match main (#4609)
faddat Sep 9, 2023
94f380d
chore: implement `appmodule.AppModule` interface (#4607)
crodriguezvega Sep 11, 2023
12d74a9
add proposal simulator interface and tests (#4608)
crodriguezvega Sep 14, 2023
bbec01f
ci: use go1.21 for wasm clients (#4610)
faddat Sep 14, 2023
090bc9f
remove toolchain / go mod tidy
crodriguezvega Sep 14, 2023
1bc5845
Update wasm light client unit tests and tendermint/grandpa cw contrac…
misko9 Sep 15, 2023
aa8598d
PR 4306 comments
crodriguezvega Sep 15, 2023
70efe3a
fix dead links
crodriguezvega Sep 18, 2023
95c9e29
fix broken links
crodriguezvega Sep 19, 2023
c87c590
test: check nil vm and empty authority (#4722)
crodriguezvega Sep 22, 2023
2d63b4a
add extra documentation for wasmCall and wasmQuery (#4752)
crodriguezvega Sep 22, 2023
60e565b
Duplicate simapp in 08 wasm (#4532)
DimitrisJim Sep 26, 2023
4f0198c
chore: add 08-wasm events (#4605)
crodriguezvega Sep 27, 2023
43106d5
Go mod tidy. (#4776)
DimitrisJim Sep 27, 2023
540db8c
Add workflow to build image for 08-wasm (#4777)
DimitrisJim Sep 28, 2023
159343d
add comment
crodriguezvega Sep 28, 2023
61db385
Use an error when panicking. (#4791)
DimitrisJim Sep 29, 2023
18a2185
imp: use interface instead of concrete type for wasmvm (#4802)
colin-axner Oct 2, 2023
5bff313
Merge branch 'main' into cian/merge-main-wasm
chatton Oct 3, 2023
f6be1b8
chore: fixing TestVerifyMisbehaviourTendermint test suite
chatton Oct 3, 2023
64fe692
chore: fixing linting issues and making linter runnable on mac
chatton Oct 3, 2023
c7324c2
chore: updating callbacks workflow
chatton Oct 3, 2023
48cadc5
chore: change callbacks workflow to build in docker
chatton Oct 3, 2023
595b8b9
chore: updating callbacks dockerfile
chatton Oct 3, 2023
e9c0862
chore: commented out part of test matrix
chatton Oct 3, 2023
176a497
fix: rm dependency on 08-wasm in ibc-go (#4801)
charleenfei Oct 4, 2023
9a7b9b7
imp: remove unused fields, functions of contract result (#4750)
crodriguezvega Oct 4, 2023
be3e2ff
Merge branch 'feat/wasm-clients' into cian/merge-main-wasm
chatton Oct 4, 2023
b863dd3
chore: addressing PR feedback
chatton Oct 4, 2023
b61ede0
chore: pr feedback
chatton Oct 4, 2023
86478ce
Merge pull request #4805 from cosmos/cian/merge-main-wasm
chatton Oct 4, 2023
7032548
feat: add mockVM for wasm clients testing (#4804)
colin-axner Oct 4, 2023
3f4061b
Dont pull wasmvm static lib in simd dockerfile. (#4817)
DimitrisJim Oct 4, 2023
1c7e148
Remove wasm additions to main test workflow. (#4819)
DimitrisJim Oct 4, 2023
0ea6d08
uncomment init function (#4833)
charleenfei Oct 5, 2023
551fb95
chore: add has validatebasic compiler assertion (#4742)
crodriguezvega Oct 5, 2023
42ad3cf
Ensure wasmvm static library version matches wasmv import in gomod (#…
chatton Oct 5, 2023
8c9c717
align error on signer not matching authority, use expected error in s…
crodriguezvega Oct 6, 2023
32e4bd7
fix: make Verify Von/Membership calls sudo calls instead of queryMsg …
charleenfei Oct 6, 2023
bd8e201
Bump wasmvm to 1.4.1 (#4857)
DimitrisJim Oct 13, 2023
cd7b5d6
Store code before creating a wasm client. (#4851)
DimitrisJim Oct 17, 2023
10ffafa
Run grandpa e2e test in ci (#4880)
chatton Oct 17, 2023
2ff2052
Add test for types registered in 08-wasm. (#4853)
DimitrisJim Oct 17, 2023
bc380a4
Improve mock wasmvm query implementation (#4879)
chatton Oct 17, 2023
c9f3ba5
Remove codeHash const from types_test, use wasmtesting. (#4891)
DimitrisJim Oct 17, 2023
403af69
Add checks in ValidateBasic for StoreCode, add tests for messages. (#…
DimitrisJim Oct 17, 2023
2a39e7f
Only store code hashes in store. (#4292)
DimitrisJim Oct 17, 2023
bde2a2f
Add mapping for sudo payloads callbacks in mockVM (#4897)
DimitrisJim Oct 18, 2023
b54ac97
Add test case for invalid Initialize call due to unstored contract. (…
DimitrisJim Oct 18, 2023
76bae0d
imp(08-wasm): exported contract responses to tests (#4902)
srdtrk Oct 18, 2023
ab35cf4
fix(08-wasm): removed panic in 'CheckForMisbehaviour' (#4907)
srdtrk Oct 18, 2023
bcdceab
test(08-wasm): added 'TestInitialize' using mockVM (#4894)
srdtrk Oct 19, 2023
e3790f5
Use the Response types in TestStatus. (#4910)
DimitrisJim Oct 19, 2023
19368c9
Remove GetSigners from StoreCode msg. (#4911)
DimitrisJim Oct 19, 2023
335286d
style(08-wasm): renamed 'grandpaClientID' -> 'defaultWasmClientID' (#…
srdtrk Oct 19, 2023
f02c619
fix(08-wasm)!: use concrete types for json serialization (#4909)
damiannolan Oct 20, 2023
fb594f6
fix exportedd type refs (#4920)
charleenfei Oct 20, 2023
5121172
chore: make wasm contract api exported (#4927)
damiannolan Oct 23, 2023
02fe742
fix: add build flag directives to ignore e2e test (#4924)
damiannolan Oct 23, 2023
6f4102e
test: `CheckForMisbehaviour` payload using mock vm (#4901)
charleenfei Oct 24, 2023
e655794
Take your time. (#4938)
DimitrisJim Oct 24, 2023
8a0eda1
test: `VerifyClientMessage` using mockVM (#4921)
charleenfei Oct 24, 2023
40ba894
test: adding `VerifyMembership` tests with mock wasm engine (#4923)
damiannolan Oct 25, 2023
dd6d028
test(08-wasm): added 'TestUpdateState' using mockVM (#4914)
srdtrk Oct 25, 2023
e2522b2
Add additional coverage for test initialize. (#4940)
DimitrisJim Oct 25, 2023
8c1ed9a
Add mock test for VerifyUpgradeAndUpdateState (#4930)
DimitrisJim Oct 25, 2023
cb38b85
test: adding verify non membership tests for 08-wasm clients using mo…
damiannolan Oct 25, 2023
1b4ae46
test: `UpdateStateOnMisbehaviour` using mock wasmVM (#4919)
charleenfei Oct 25, 2023
4fa827a
imp(08-wasm): removed panic in `GetCodeHash` and `AddCodeHash` (#4948)
srdtrk Oct 25, 2023
6eb154c
Add ErrMockContract. (#4955)
DimitrisJim Oct 26, 2023
a48b631
Add mock height and check for it in membership tests (#4956)
DimitrisJim Oct 26, 2023
90027e4
Add testing for GetTimestampAtHeight (#4960)
DimitrisJim Oct 26, 2023
90e345a
Remove panic handling testing code for non-panicking methods. (#4957)
DimitrisJim Oct 26, 2023
1d31c73
Update Grandpa Contract Test to work with SDK v0.50 (#4959)
chatton Oct 26, 2023
0abc469
Add mock test for ExportMetadata (#4961)
DimitrisJim Oct 26, 2023
95a1237
feat(08-wasm): use 'clientID' as contract address (#4939)
srdtrk Oct 27, 2023
890ef9d
Move mock engine into testing. (#4936)
DimitrisJim Oct 27, 2023
eea9a7d
Add testing for wasmQuery/wasmCall. (#4934)
DimitrisJim Oct 30, 2023
433f1fa
No formatting necessary. (#4985)
DimitrisJim Oct 30, 2023
ddb514d
Rename entry points to match vm names. (#4986)
DimitrisJim Oct 30, 2023
56fb2af
imp: `CheckSubstituteAndUpdateState` for 08-wasm client (#4974)
charleenfei Oct 30, 2023
1fa22f3
Delete commented out test for tendermint. (#4989)
DimitrisJim Oct 30, 2023
b0142e7
Remove store-code cmd. (#4990)
DimitrisJim Oct 30, 2023
995a3bd
Add mock test for CheckSubstituteAndUpdateState. (#4950)
DimitrisJim Oct 30, 2023
9655a7b
refactor(08-wasm)!: use `collections.KeySet` for code hashes (#4973)
srdtrk Oct 30, 2023
bdcc012
cleanup - creating mock var for client state bytes (#4978)
muku314115 Oct 31, 2023
7fd07ad
Fix TestScheduleIBCUpgrade_Succeeds on wasm branch (#4997)
chatton Oct 31, 2023
16f7d6c
Modify wrappedStore to allow reads from both substitute and subject, …
DimitrisJim Oct 31, 2023
20c73fd
Remove grandpa unit tests covered by e2e. (#4996)
DimitrisJim Oct 31, 2023
0e13d2e
Build and push wasm image in PRs (#4998)
chatton Nov 1, 2023
fe602e0
Add snapshotter extension (#4723)
trinitys7 Nov 1, 2023
9e15947
chore: adding type alias for code hash byte slices (#5004)
damiannolan Nov 1, 2023
30251d4
Moving mock values in a separate file (#5021)
muku314115 Nov 6, 2023
efedb95
Sync gas_register.go with wasmd main (#5007)
chatton Nov 6, 2023
0276f79
test: adding e2e scaffolding for grandpa client recovery test
damiannolan Nov 6, 2023
147f0ca
feat(08-wasm): implement 'MigrateContract' RPC endpoint (#5000)
srdtrk Nov 6, 2023
243f36f
chore: rename code ID/checksum to code hash (#5030)
crodriguezvega Nov 7, 2023
4bfc4e4
wip: commit modified contract with altered trusting period
damiannolan Nov 7, 2023
149f65c
chore: tweek sleep period from unboding period contract changes
damiannolan Nov 8, 2023
729cb09
feat(08-wasm): implement 'RemoveCodeHash' RPC endpoint (#5006)
srdtrk Nov 8, 2023
0be3f39
Merge branch 'main' into feat/wasm-clients
crodriguezvega Nov 9, 2023
1ac7113
Rename wasmInit to wasmInstantiate and Features to Capabilities. (#5065)
DimitrisJim Nov 9, 2023
d7b99e8
chore: rm testsuite ctx and store fields (#5067)
damiannolan Nov 9, 2023
103510a
test(e2e): added migrate contract tests (#5043)
srdtrk Nov 9, 2023
c8e9a09
docs: documentation for 08-wasm (#4203)
crodriguezvega Nov 10, 2023
4d67e4c
linter
charleenfei Nov 10, 2023
3a3a998
Merge branch 'main' into feat/wasm-client
charleenfei Nov 10, 2023
d22682d
linter
charleenfei Nov 10, 2023
bc1f21a
Merge branch 'main' into feat/wasm-client
charleenfei Nov 10, 2023
8c485a1
Set wasmvm cache size to zero. (#5066)
DimitrisJim Nov 10, 2023
e30faef
chore: add new grandpa contract and fix test assertion
damiannolan Nov 13, 2023
f88b4c2
Merge branch 'feat/wasm-clients' into damian/4970-recover-client-gran…
damiannolan Nov 13, 2023
dcc1a11
chore: use GetGrandpaChains helper
damiannolan Nov 13, 2023
4f26dd1
chore: add godocs and cleanup test code
damiannolan Nov 13, 2023
1c70944
Add check that wasm contract only modifies code hash in migrateContra…
chatton Nov 13, 2023
24e5743
chore: mv contracts to e2e/tests/wasm/contracts
damiannolan Nov 13, 2023
42577bb
Merge branch 'feat/wasm-clients' into damian/4970-recover-client-gran…
damiannolan Nov 13, 2023
9b01c9a
chore: gzip everything, fix incorrect file path
damiannolan Nov 13, 2023
1f1520d
Revert "chore: gzip everything, fix incorrect file path"
damiannolan Nov 13, 2023
c048502
fix: file path in test code
damiannolan Nov 13, 2023
86d55a2
small string formatting change
crodriguezvega Nov 13, 2023
f55a685
Merge branch 'feat/wasm-clients' into damian/4970-recover-client-gran…
damiannolan Nov 13, 2023
d982d5d
chore: remove uneeded checking for static linking.
DimitrisJim Nov 13, 2023
d3f8709
chore: remove SetCodeHash from Coordinator.
DimitrisJim Nov 13, 2023
33d1315
add 08-wasm to go.work.example
crodriguezvega Nov 14, 2023
d0c05d5
Merge branch 'main' into feat/wasm-clients
charleenfei Nov 14, 2023
0bee18b
Fix Upgrade Tests (#5109)
chatton Nov 14, 2023
31ff822
Merge branch 'feat/wasm-clients' into damian/4970-recover-client-gran…
DimitrisJim Nov 14, 2023
bde614e
Merge branch 'main' into feat/wasm-clients
DimitrisJim Nov 14, 2023
826df9e
imp: unpin contract in remove code hash (#5103)
crodriguezvega Nov 14, 2023
c53bac7
imp: return `Unauthorised` if code hash is not stored (#5102)
crodriguezvega Nov 14, 2023
825bf2b
add 08-wasm code owners (#5100)
crodriguezvega Nov 14, 2023
716fcdc
imp: check response in instantiate and migrate from wasm vm calls (#5…
crodriguezvega Nov 14, 2023
f4ddaee
address review comments
crodriguezvega Nov 14, 2023
1cf7a2f
add validate genesis
crodriguezvega Nov 14, 2023
c24f8ed
gofumpt
crodriguezvega Nov 14, 2023
e71b80f
remove grandpa tests using test data
crodriguezvega Nov 15, 2023
edc525f
unused field
crodriguezvega Nov 15, 2023
7b377ea
Add an error-ing implementation for GoAPI. (#5105)
DimitrisJim Nov 15, 2023
61b64e6
Merge branch 'feat/wasm-clients' into damian/4970-recover-client-gran…
DimitrisJim Nov 15, 2023
1d5a50f
Merge branch 'main' into damian/4970-recover-client-grandpa-e2e
damiannolan Nov 20, 2023
162a820
chore: fix protodoc code hash -> checksum
damiannolan Nov 20, 2023
c2274d6
Merge branch 'main' into damian/4970-recover-client-grandpa-e2e
damiannolan Nov 20, 2023
16f375c
chore: recompile new contract from fork of fork (carlos/rename-codehash)
damiannolan Nov 20, 2023
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
Prev Previous commit
Next Next commit
Migrated the errors to new package (#4058)
* new error

* changed all the errors

* feat: Changed some more erros from sdkerrors to errorsmod

* added ibcerrors

* fixes and linting

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
  • Loading branch information
vishal-kanna and crodriguezvega authored Jul 12, 2023
commit cf6fbfe7f56f4fdf9f5e3cbb087280acd5bd39aa
1 change: 1 addition & 0 deletions e2e/tests/transfer/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/cosmos/cosmos-sdk/x/authz"
test "github.com/strangelove-ventures/interchaintest/v7/testutil"
"github.com/stretchr/testify/suite"
Expand Down
5 changes: 3 additions & 2 deletions modules/light-clients/08-wasm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

errorsmod "cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
sdkquery "github.com/cosmos/cosmos-sdk/types/query"

"github.com/cosmos/ibc-go/v7/modules/light-clients/08-wasm/types"
Expand All @@ -35,7 +36,7 @@ func (k Keeper) Code(c context.Context, req *types.QueryCodeRequest) (*types.Que
codeKey := types.CodeIDKey(codeID)
code := store.Get(codeKey)
if code == nil {
return nil, status.Error(codes.NotFound, sdkerrors.Wrap(types.ErrWasmCodeIDNotFound, req.CodeId).Error())
return nil, status.Error(codes.NotFound, errorsmod.Wrap(types.ErrWasmCodeIDNotFound, req.CodeId).Error())
}

return &types.QueryCodeResponse{
Expand Down
17 changes: 9 additions & 8 deletions modules/light-clients/08-wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (

cosmwasm "github.com/CosmWasm/wasmvm"

errorsmod "cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

Expand Down Expand Up @@ -74,7 +75,7 @@ func (k Keeper) storeWasmCode(ctx sdk.Context, code []byte) ([]byte, error) {
ctx.GasMeter().ConsumeGas(types.VMGasRegister.UncompressCosts(len(code)), "Uncompress gzip bytecode")
code, err = types.Uncompress(code, types.MaxWasmByteSize())
if err != nil {
return nil, sdkerrors.Wrap(err, "failed to store contract")
return nil, errorsmod.Wrap(err, "failed to store contract")
}
}

Expand All @@ -87,19 +88,19 @@ func (k Keeper) storeWasmCode(ctx sdk.Context, code []byte) ([]byte, error) {

// run the code through the wasm light client validation process
if err := types.ValidateWasmCode(code); err != nil {
return nil, sdkerrors.Wrapf(err, "wasm bytecode validation failed")
return nil, errorsmod.Wrapf(err, "wasm bytecode validation failed")
}

// create the code in the vm
ctx.GasMeter().ConsumeGas(types.VMGasRegister.CompileCosts(len(code)), "Compiling wasm bytecode")
codeHash, err := k.wasmVM.StoreCode(code)
if err != nil {
return nil, sdkerrors.Wrap(err, "failed to store contract")
return nil, errorsmod.Wrap(err, "failed to store contract")
}

// safety check to assert that code ID returned by WasmVM equals to code hash
if !bytes.Equal(codeHash, expectedHash) {
return nil, sdkerrors.Wrapf(types.ErrInvalidCodeID, "expected %s, got %s", hex.EncodeToString(expectedHash), hex.EncodeToString(codeHash))
return nil, errorsmod.Wrapf(types.ErrInvalidCodeID, "expected %s, got %s", hex.EncodeToString(expectedHash), hex.EncodeToString(codeHash))
}

store.Set(codeIDKey, code)
Expand All @@ -112,18 +113,18 @@ func (k Keeper) importWasmCode(ctx sdk.Context, codeIDKey, wasmCode []byte) erro
var err error
wasmCode, err = types.Uncompress(wasmCode, types.MaxWasmByteSize())
if err != nil {
return sdkerrors.Wrap(err, "failed to store contract")
return errorsmod.Wrap(err, "failed to store contract")
}
}

generatedCodeID, err := k.wasmVM.Create(wasmCode)
if err != nil {
return sdkerrors.Wrap(err, "failed to store contract")
return errorsmod.Wrap(err, "failed to store contract")
}
generatedCodeIDKey := types.CodeIDKey(generatedCodeID)

if !bytes.Equal(codeIDKey, generatedCodeIDKey) {
return sdkerrors.Wrapf(types.ErrInvalid, "expected %s, got %s", string(generatedCodeIDKey), string(codeIDKey))
return errorsmod.Wrapf(types.ErrInvalid, "expected %s, got %s", string(generatedCodeIDKey), string(codeIDKey))
}

store.Set(codeIDKey, wasmCode)
Expand Down
7 changes: 4 additions & 3 deletions modules/light-clients/08-wasm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package keeper
import (
"context"

errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/cosmos/ibc-go/v7/modules/light-clients/08-wasm/types"
Expand All @@ -15,13 +16,13 @@ var _ types.MsgServer = (*Keeper)(nil)
// StoreCode defines a rpc handler method for MsgStoreCode
func (k Keeper) StoreCode(goCtx context.Context, msg *types.MsgStoreCode) (*types.MsgStoreCodeResponse, error) {
if k.GetAuthority() != msg.Signer {
return nil, sdkerrors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority: expected %s, got %s", k.GetAuthority(), msg.Signer)
return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority: expected %s, got %s", k.GetAuthority(), msg.Signer)
}

ctx := sdk.UnwrapSDKContext(goCtx)
codeID, err := k.storeWasmCode(ctx, msg.Code)
if err != nil {
return nil, sdkerrors.Wrap(err, "failed to store wasm bytecode")
return nil, errorsmod.Wrap(err, "failed to store wasm bytecode")
}

emitStoreWasmCodeEvent(ctx, codeID)
Expand Down
21 changes: 10 additions & 11 deletions modules/light-clients/08-wasm/types/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types"
Expand Down Expand Up @@ -41,15 +40,15 @@ func (cs ClientState) GetLatestHeight() exported.Height {
// Validate performs a basic validation of the client state fields.
func (cs ClientState) Validate() error {
if len(cs.Data) == 0 {
return sdkerrors.Wrap(ErrInvalidData, "data cannot be empty")
return errorsmod.Wrap(ErrInvalidData, "data cannot be empty")
}

lenCodeID := len(cs.CodeId)
if lenCodeID == 0 {
return sdkerrors.Wrap(ErrInvalidCodeID, "code ID cannot be empty")
return errorsmod.Wrap(ErrInvalidCodeID, "code ID cannot be empty")
}
if lenCodeID > 32 { // sha256 output is 256 bits long
return sdkerrors.Wrapf(ErrInvalidCodeID, "expected 32, got %d", lenCodeID)
return errorsmod.Wrapf(ErrInvalidCodeID, "expected 32, got %d", lenCodeID)
}

return nil
Expand Down Expand Up @@ -106,7 +105,7 @@ func (cs ClientState) GetTimestampAtHeight(
// get consensus state at height from clientStore to check for expiry
consState, err := GetConsensusState(clientStore, cdc, height)
if err != nil {
return 0, sdkerrors.Wrapf(err, "height (%s)", height)
return 0, errorsmod.Wrapf(err, "height (%s)", height)
}
return consState.GetTimestamp(), nil
}
Expand All @@ -117,15 +116,15 @@ func (cs ClientState) GetTimestampAtHeight(
func (cs ClientState) Initialize(ctx sdk.Context, marshaler codec.BinaryCodec, clientStore sdk.KVStore, state exported.ConsensusState) error {
consensusState, ok := state.(*ConsensusState)
if !ok {
return sdkerrors.Wrapf(clienttypes.ErrInvalidConsensus, "invalid initial consensus state. expected type: %T, got: %T",
return errorsmod.Wrapf(clienttypes.ErrInvalidConsensus, "invalid initial consensus state. expected type: %T, got: %T",
&ConsensusState{}, state)
}
setClientState(clientStore, marshaler, &cs)
setConsensusState(clientStore, marshaler, consensusState, cs.GetLatestHeight())

_, err := initContract(ctx, clientStore, cs.CodeId)
if err != nil {
return sdkerrors.Wrapf(err, "failed to initialize contract")
return errorsmod.Wrapf(err, "failed to initialize contract")
}
return nil
}
Expand Down Expand Up @@ -250,17 +249,17 @@ func call[T ContractResult](ctx sdk.Context, clientStore sdk.KVStore, cs *Client
var output T
encodedData, err := json.Marshal(payload)
if err != nil {
return output, sdkerrors.Wrapf(err, "failed to marshal wasm contract payload")
return output, errorsmod.Wrapf(err, "failed to marshal wasm contract payload")
}
out, err := callContract(ctx, clientStore, cs.CodeId, encodedData)
if err != nil {
return output, sdkerrors.Wrapf(err, "call to wasm contract failed")
return output, errorsmod.Wrapf(err, "call to wasm contract failed")
}
if err := json.Unmarshal(out.Data, &output); err != nil {
return output, sdkerrors.Wrapf(err, "failed unmarshal wasm contract payload")
return output, errorsmod.Wrapf(err, "failed unmarshal wasm contract payload")
}
if !output.Validate() {
return output, sdkerrors.Wrapf(errors.New(output.Error()), "error occurred while calling contract with code ID %s", hex.EncodeToString(cs.CodeId))
return output, errorsmod.Wrapf(errors.New(output.Error()), "error occurred while calling contract with code ID %s", hex.EncodeToString(cs.CodeId))
}
return output, nil
}
6 changes: 3 additions & 3 deletions modules/light-clients/08-wasm/types/consensus_state.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
errorsmod "cosmossdk.io/errors"

clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
Expand Down Expand Up @@ -30,11 +30,11 @@ func (cs ConsensusState) GetTimestamp() uint64 {
// ValidateBasic defines a basic validation for the wasm client consensus state.
func (cs ConsensusState) ValidateBasic() error {
if cs.Timestamp == 0 {
return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "timestamp must be a positive Unix time")
return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "timestamp must be a positive Unix time")
}

if len(cs.Data) == 0 {
return sdkerrors.Wrap(ErrInvalidData, "data cannot be empty")
return errorsmod.Wrap(ErrInvalidData, "data cannot be empty")
}

return nil
Expand Down
16 changes: 8 additions & 8 deletions modules/light-clients/08-wasm/types/errors.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package types

import sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
import errorsmod "cosmossdk.io/errors"

var (
ErrInvalid = sdkerrors.Register(ModuleName, 1, "invalid")
ErrInvalidData = sdkerrors.Register(ModuleName, 2, "invalid data")
ErrInvalidCodeID = sdkerrors.Register(ModuleName, 3, "invalid code ID")
ErrInvalid = errorsmod.Register(ModuleName, 1, "invalid")
ErrInvalidData = errorsmod.Register(ModuleName, 2, "invalid data")
ErrInvalidCodeID = errorsmod.Register(ModuleName, 3, "invalid code ID")
// Wasm specific
ErrWasmEmptyCode = sdkerrors.Register(ModuleName, 4, "empty wasm code")
ErrWasmCodeTooLarge = sdkerrors.Register(ModuleName, 5, "wasm code too large")
ErrWasmCodeExists = sdkerrors.Register(ModuleName, 6, "wasm code already exists")
ErrWasmCodeIDNotFound = sdkerrors.Register(ModuleName, 7, "wasm code id not found")
ErrWasmEmptyCode = errorsmod.Register(ModuleName, 4, "empty wasm code")
ErrWasmCodeTooLarge = errorsmod.Register(ModuleName, 5, "wasm code too large")
ErrWasmCodeExists = errorsmod.Register(ModuleName, 6, "wasm code already exists")
ErrWasmCodeIDNotFound = errorsmod.Register(ModuleName, 7, "wasm code id not found")
)
13 changes: 8 additions & 5 deletions modules/light-clients/08-wasm/types/gas_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import (
wasmvm "github.com/CosmWasm/wasmvm"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"

errorsmod "cosmossdk.io/errors"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors"
)

// Copied subset of gas features from wasmd
Expand Down Expand Up @@ -122,7 +125,7 @@ func NewDefaultWasmGasRegister() WasmGasRegister {
// NewWasmGasRegister constructor
func NewWasmGasRegister(c WasmGasRegisterConfig) WasmGasRegister {
if c.GasMultiplier == 0 {
panic(sdkerrors.Wrap(sdkerrors.ErrLogic, "GasMultiplier can not be 0"))
panic(errorsmod.Wrap(ibcerrors.ErrLogic, "GasMultiplier can not be 0"))
}
return WasmGasRegister{
c: c,
Expand All @@ -137,23 +140,23 @@ func (g WasmGasRegister) NewContractInstanceCosts(msgLen int) storetypes.Gas {
// CompileCosts costs to persist and "compile" a new wasm contract
func (g WasmGasRegister) CompileCosts(byteLength int) storetypes.Gas {
if byteLength < 0 {
panic(sdkerrors.Wrap(ErrInvalid, "negative length"))
panic(errorsmod.Wrap(ErrInvalid, "negative length"))
}
return g.c.CompileCost * uint64(byteLength)
}

// UncompressCosts costs to unpack a new wasm contract
func (g WasmGasRegister) UncompressCosts(byteLength int) sdk.Gas {
if byteLength < 0 {
panic(sdkerrors.Wrap(ErrInvalid, "negative length"))
panic(errorsmod.Wrap(ErrInvalid, "negative length"))
}
return g.c.UncompressCost.Mul(uint64(byteLength)).Floor()
}

// InstantiateContractCosts costs when interacting with a wasm contract
func (g WasmGasRegister) InstantiateContractCosts(msgLen int) sdk.Gas {
if msgLen < 0 {
panic(sdkerrors.Wrap(ErrInvalid, "negative length"))
panic(errorsmod.Wrap(ErrInvalid, "negative length"))
}
dataCosts := sdk.Gas(msgLen) * g.c.ContractMessageDataCost
return g.c.InstanceCost + dataCosts
Expand Down
4 changes: 2 additions & 2 deletions modules/light-clients/08-wasm/types/header.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
errorsmod "cosmossdk.io/errors"

"github.com/cosmos/ibc-go/v7/modules/core/exported"
)
Expand All @@ -16,7 +16,7 @@ func (h Header) ClientType() string {
// ValidateBasic defines a basic validation for the wasm client header.
func (h Header) ValidateBasic() error {
if len(h.Data) == 0 {
return sdkerrors.Wrap(ErrInvalidData, "data cannot be empty")
return errorsmod.Wrap(ErrInvalidData, "data cannot be empty")
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions modules/light-clients/08-wasm/types/misbehaviour.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
errorsmod "cosmossdk.io/errors"

exported "github.com/cosmos/ibc-go/v7/modules/core/exported"
)
Expand All @@ -16,7 +16,7 @@ func (m Misbehaviour) ClientType() string {
// ValidateBasic implements Misbehaviour interface
func (m Misbehaviour) ValidateBasic() error {
if len(m.Data) == 0 {
return sdkerrors.Wrap(ErrInvalidData, "data cannot be empty")
return errorsmod.Wrap(ErrInvalidData, "data cannot be empty")
}
return nil
}
5 changes: 3 additions & 2 deletions modules/light-clients/08-wasm/types/proposal_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package types
import (
"fmt"

errorsmod "cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
Expand Down Expand Up @@ -33,7 +34,7 @@ func (cs ClientState) CheckSubstituteAndUpdateState(

_, ok := substituteClient.(*ClientState)
if !ok {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
clienttypes.ErrInvalidClient,
fmt.Sprintf("invalid substitute client state. expected type %T, got %T", &ClientState{}, substituteClient),
)
Expand Down
9 changes: 5 additions & 4 deletions modules/light-clients/08-wasm/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (

wasmvmtypes "github.com/CosmWasm/wasmvm/types"

errorsmod "cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/cachekv"
"github.com/cosmos/cosmos-sdk/store/listenkv"
"github.com/cosmos/cosmos-sdk/store/tracekv"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
Expand Down Expand Up @@ -114,17 +115,17 @@ func setConsensusState(clientStore sdk.KVStore, cdc codec.BinaryCodec, consensus
func GetConsensusState(clientStore sdk.KVStore, cdc codec.BinaryCodec, height exported.Height) (*ConsensusState, error) {
bz := clientStore.Get(host.ConsensusStateKey(height))
if len(bz) == 0 {
return nil, sdkerrors.Wrapf(clienttypes.ErrConsensusStateNotFound, "consensus state does not exist for height %s", height)
return nil, errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "consensus state does not exist for height %s", height)
}

consensusStateI, err := clienttypes.UnmarshalConsensusState(cdc, bz)
if err != nil {
return nil, sdkerrors.Wrapf(clienttypes.ErrInvalidConsensus, "unmarshal error: %v", err)
return nil, errorsmod.Wrapf(clienttypes.ErrInvalidConsensus, "unmarshal error: %v", err)
}

consensusState, ok := consensusStateI.(*ConsensusState)
if !ok {
return nil, sdkerrors.Wrapf(clienttypes.ErrInvalidConsensus, "invalid consensus type. expected %T, got %T", &ConsensusState{}, consensusState)
return nil, errorsmod.Wrapf(clienttypes.ErrInvalidConsensus, "invalid consensus type. expected %T, got %T", &ConsensusState{}, consensusState)
}

return consensusState, nil
Expand Down
Loading