diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 919c0dabe2..4a0096c51a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -53,14 +53,12 @@ jobs: run: | grep -vF \ -e 'github.com/provenance-io/provenance/x/ibchooks' \ - -e 'github.com/provenance-io/provenance/x/ibcratelimit/module' \ -e 'github.com/provenance-io/provenance/x/ibcratelimit/simulation' \ -e 'github.com/provenance-io/provenance/x/oracle/simulation' \ pkgs.txt > pkgs.txt.tmp split -d -n l/3 pkgs.txt.tmp pkgs.txt.part. printf '%s\n' \ 'github.com/provenance-io/provenance/x/ibchooks' \ - 'github.com/provenance-io/provenance/x/ibcratelimit/module' \ 'github.com/provenance-io/provenance/x/ibcratelimit/simulation' \ 'github.com/provenance-io/provenance/x/oracle/simulation' \ > pkgs.txt.part.03 diff --git a/CHANGELOG.md b/CHANGELOG.md index 519db89618..c99ad25bc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,6 +85,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * Switch to auto-generated `String` and `Equal` methods for most proto messages [#1957](https://github.com/provenance-io/provenance/pull/1957). * Clean up the marker module's expected BankKeeper interface [#1954](https://github.com/provenance-io/provenance/pull/1954). * Add the auto-cli commands and a few others newly added by the SDK [#1971](https://github.com/provenance-io/provenance/pull/1971). +* Fix unit tests for ibcratelimit [#1977](https://github.com/provenance-io/provenance/pull/1977). ### Client Breaking diff --git a/app/app.go b/app/app.go index fe0a290edf..364105c4de 100644 --- a/app/app.go +++ b/app/app.go @@ -124,6 +124,7 @@ import ( porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper" + ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" ibctestingtypes "github.com/cosmos/ibc-go/v8/testing/types" simappparams "github.com/provenance-io/provenance/app/params" @@ -287,11 +288,12 @@ type App struct { ScopedICQKeeper capabilitykeeper.ScopedKeeper ScopedOracleKeeper capabilitykeeper.ScopedKeeper - TransferStack *ibchooks.IBCMiddleware - Ics20WasmHooks *ibchooks.WasmHooks - Ics20MarkerHooks *ibchooks.MarkerHooks - IbcHooks *ibchooks.IbcHooks - HooksICS4Wrapper ibchooks.ICS4Middleware + TransferStack *ibchooks.IBCMiddleware + Ics20WasmHooks *ibchooks.WasmHooks + Ics20MarkerHooks *ibchooks.MarkerHooks + IbcHooks *ibchooks.IbcHooks + HooksICS4Wrapper ibchooks.ICS4Middleware + RateLimitMiddleware porttypes.Middleware // the module manager mm *module.Manager @@ -542,8 +544,8 @@ func New( ) app.TransferKeeper = &transferKeeper transferModule := ibctransfer.NewIBCModule(*app.TransferKeeper) - rateLimitingTransferModule = *rateLimitingTransferModule.WithIBCModule(transferModule) - hooksTransferModule := ibchooks.NewIBCMiddleware(&rateLimitingTransferModule, &app.HooksICS4Wrapper) + app.RateLimitMiddleware = rateLimitingTransferModule.WithIBCModule(transferModule) + hooksTransferModule := ibchooks.NewIBCMiddleware(app.RateLimitMiddleware, &app.HooksICS4Wrapper) app.TransferStack = &hooksTransferModule app.NameKeeper = namekeeper.NewKeeper(appCodec, keys[nametypes.StoreKey]) @@ -775,6 +777,7 @@ func New( ibctransfer.NewAppModule(*app.TransferKeeper), icqModule, icaModule, + ibctm.AppModule{}, ) // BasicModuleManager defines the module BasicManager is in charge of setting up basic, @@ -950,6 +953,7 @@ func New( paramstypes.ModuleName, slashingtypes.ModuleName, stakingtypes.ModuleName, + ibctm.ModuleName, ibctransfertypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, diff --git a/internal/antewrapper/msg_fees_decorator.go b/internal/antewrapper/msg_fees_decorator.go index c32c94cf2b..535f3b449c 100644 --- a/internal/antewrapper/msg_fees_decorator.go +++ b/internal/antewrapper/msg_fees_decorator.go @@ -1,6 +1,8 @@ package antewrapper import ( + "strings" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" @@ -77,9 +79,9 @@ func (mfd MsgFeesDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool // This check for chain-id is exclusively for not breaking all existing sim tests which freak out when denom is anything other than stake. // and some network tests won't work without a chain id being set(but they also setup everything with stake denom) so `simapp-unit-testing` chain id is skipped also. -// This only needs to work to pio-testnet and pio-mainnet, so this is safe. +// This only needs to work to pio-testnet, pio-mainnet, and ibc tests, so this is safe. func isTestContext(ctx sdk.Context) bool { - return len(ctx.ChainID()) == 0 || ctx.ChainID() == SimAppChainID || ctx.ChainID() == pioconfig.SimAppChainID + return len(ctx.ChainID()) == 0 || ctx.ChainID() == SimAppChainID || ctx.ChainID() == pioconfig.SimAppChainID || strings.HasPrefix(ctx.ChainID(), "testchain") } // EnsureSufficientFloorAndMsgFees verifies that the given transaction has supplied diff --git a/testutil/contracts/rate-limiter/Cargo.lock b/testutil/contracts/rate-limiter/Cargo.lock index 65330d1f6a..a690545ce4 100644 --- a/testutil/contracts/rate-limiter/Cargo.lock +++ b/testutil/contracts/rate-limiter/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "ahash" -version = "0.7.6" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" dependencies = [ "getrandom", "once_cell", @@ -15,15 +15,15 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "base16ct" @@ -33,9 +33,9 @@ checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" [[package]] name = "base64" -version = "0.21.4" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "base64ct" @@ -43,6 +43,12 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "bech32" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" + [[package]] name = "block-buffer" version = "0.9.0" @@ -75,9 +81,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cfg-if" @@ -87,24 +93,24 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.31" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "num-traits", ] [[package]] name = "const-oid" -version = "0.9.5" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" [[package]] name = "cosmwasm-crypto" -version = "1.5.4" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6b4c3f9c4616d6413d4b5fc4c270a4cc32a374b9be08671e80e1a019f805d8f" +checksum = "dd50718a2b6830ce9eb5d465de5a018a12e71729d66b70807ce97e6dd14f931d" dependencies = [ "digest 0.10.7", "ecdsa", @@ -116,18 +122,18 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.5.4" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c586ced10c3b00e809ee664a895025a024f60d65d34fe4c09daed4a4db68a3f3" +checksum = "242e98e7a231c122e08f300d9db3262d1007b51758a8732cd6210b3e9faa4f3a" dependencies = [ "syn 1.0.109", ] [[package]] name = "cosmwasm-schema" -version = "1.4.1" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fef683a9c1c4eabd6d31515719d0d2cc66952c4c87f7eb192bfc90384517dc34" +checksum = "7879036156092ad1c22fe0d7316efc5a5eceec2bc3906462a2560215f2a2f929" dependencies = [ "cosmwasm-schema-derive", "schemars", @@ -138,9 +144,9 @@ dependencies = [ [[package]] name = "cosmwasm-schema-derive" -version = "1.4.1" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9567025acbb4c0c008178393eb53b3ac3c2e492c25949d3bf415b9cbe80772d8" +checksum = "0bb57855fbfc83327f8445ae0d413b1a05ac0d68c396ab4d122b2abd7bb82cb6" dependencies = [ "proc-macro2", "quote", @@ -149,11 +155,12 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.4.4" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f42ebd3c7d99389efb7f326ecef7624e200ca1d49e20ac2bbb08ee570132832" +checksum = "78c1556156fdf892a55cced6115968b961eaaadd6f724a2c2cb7d1e168e32dd3" dependencies = [ "base64", + "bech32", "bnum", "cosmwasm-crypto", "cosmwasm-derive", @@ -164,14 +171,15 @@ dependencies = [ "serde", "serde-json-wasm 0.5.2", "sha2 0.10.8", + "static_assertions", "thiserror", ] [[package]] name = "cosmwasm-storage" -version = "1.4.1" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54a1c574d30feffe4b8121e61e839c231a5ce21901221d2fb4d5c945968a4f00" +checksum = "66de2ab9db04757bcedef2b5984fbe536903ada4a8a9766717a4a71197ef34f6" dependencies = [ "cosmwasm-std", "serde", @@ -179,18 +187,18 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.9" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] [[package]] name = "crypto-bigint" -version = "0.5.3" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "740fe28e594155f10cfc383984cbefd529d7396050557148f79cb0f621204124" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" dependencies = [ "generic-array", "rand_core 0.6.4", @@ -233,7 +241,7 @@ dependencies = [ "cw-utils", "derivative", "itertools 0.11.0", - "prost 0.12.1", + "prost 0.12.4", "schemars", "serde", "sha2 0.10.8", @@ -242,9 +250,9 @@ dependencies = [ [[package]] name = "cw-storage-plus" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f0e92a069d62067f3472c62e30adedb4cab1754725c0f2a682b3128d2bf3c79" +checksum = "d5ff29294ee99373e2cd5fd21786a3c0ced99a52fec2ca347d565489c61b723c" dependencies = [ "cosmwasm-std", "schemars", @@ -253,9 +261,9 @@ dependencies = [ [[package]] name = "cw-utils" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9f351a4e4d81ef7c890e44d903f8c0bdcdc00f094fd3a181eaf70c0eec7a3a" +checksum = "1c4a657e5caacc3a0d00ee96ca8618745d050b8f757c709babafb81208d4239c" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -268,23 +276,24 @@ dependencies = [ [[package]] name = "cw2" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9431d14f64f49e41c6ef5561ed11a5391c417d0cb16455dea8cdcb9037a8d197" +checksum = "c6c120b24fbbf5c3bedebb97f2cc85fbfa1c3287e09223428e7e597b5293c1fa" dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus", "schemars", + "semver", "serde", "thiserror", ] [[package]] name = "der" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" dependencies = [ "const-oid", "zeroize", @@ -324,15 +333,15 @@ dependencies = [ [[package]] name = "dyn-clone" -version = "1.0.14" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d2f3407d9a573d666de4b5bdf10569d73ca9478087346697dcbae6244bfbcd" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" [[package]] name = "ecdsa" -version = "0.16.8" +version = "0.16.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4b1e0c257a9e9f25f90ff76d7a68360ed497ee519c8e428d1825ef0000799d4" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" dependencies = [ "der", "digest 0.10.7", @@ -359,15 +368,15 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" [[package]] name = "elliptic-curve" -version = "0.13.6" +version = "0.13.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d97ca172ae9dc9f9b779a6e3a65d308f2af74e5b8c921299075bdb4a0370e914" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" dependencies = [ "base16ct", "crypto-bigint", @@ -411,9 +420,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -479,11 +488,20 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "k256" @@ -501,30 +519,30 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.149" +version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "opaque-debug" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "pkcs8" @@ -538,9 +556,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" dependencies = [ "unicode-ident", ] @@ -557,12 +575,12 @@ dependencies = [ [[package]] name = "prost" -version = "0.12.1" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fdd22f3b9c31b53c060df4a0613a1c7f062d4115a2b984dd15b1858f7e340d" +checksum = "d0f5d036824e4761737860779c906171497f6d55681139d8312388f8fe398922" dependencies = [ "bytes", - "prost-derive 0.12.1", + "prost-derive 0.12.5", ] [[package]] @@ -580,15 +598,15 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.12.1" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "265baba7fabd416cf5078179f7d2cbeca4ce7a9041111900675ea7c4cb8a4c32" +checksum = "9554e3ab233f0a932403704f1a1d08c30d5ccd931adfdfa1e8b5a19b52c1d55a" dependencies = [ "anyhow", - "itertools 0.11.0", + "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.63", ] [[package]] @@ -611,9 +629,9 @@ dependencies = [ [[package]] name = "provwasm-mocks" -version = "2.0.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02175727ba6205cb5feac4724d3ab6f4e5833dddae517961bf820f6df4d3a6bd" +checksum = "f2e9017d25239c631bc24d731e314149dbd56ed251bba17f427ce2051fc72806" dependencies = [ "cosmwasm-std", "provwasm-common", @@ -624,21 +642,21 @@ dependencies = [ [[package]] name = "provwasm-proc-macro" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "792736fb76e0acb3118b22e5e55e456b22c67ac3ee51bfb1f7dfde09bd954560" +checksum = "59d3d936fc7e0fac992a454ec731aeded01166a894719d9161f261fc713ce251" dependencies = [ - "itertools 0.10.5", + "itertools 0.11.0", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.63", ] [[package]] name = "provwasm-std" -version = "2.0.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d216752a4c37d7bc39ee1d397f6500fa92cf1c191c60b501038aa98cafa07c69" +checksum = "e2e7f1accf41f2d20bc50a4fc74184bdde714c487556314a99b1bd178c34302f" dependencies = [ "base64", "chrono", @@ -656,9 +674,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -710,21 +728,21 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.14" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" [[package]] name = "ryu" -version = "1.0.15" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "schemars" -version = "0.8.15" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f7b0ce13155372a76ee2e1c5ffba1fe61ede73fbea5630d61eee6fac4929c0c" +checksum = "fc6e7ed6919cb46507fb01ff1654309219f62b4d603822501b0b80d42f6f21ef" dependencies = [ "dyn-clone", "schemars_derive", @@ -734,14 +752,14 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.15" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e85e2a16b12bdb763244c69ab79363d71db2b4b918a2def53f80b02e0574b13c" +checksum = "185f2b7aa7e02d418e453790dde16890256bbd2bcd04b7dc5348811052b53f49" dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 1.0.109", + "syn 2.0.63", ] [[package]] @@ -760,15 +778,15 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.20" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.189" +version = "1.0.202" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" +checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395" dependencies = [ "serde_derive", ] @@ -802,31 +820,31 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.189" +version = "1.0.202" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" +checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.63", ] [[package]] name = "serde_derive_internals" -version = "0.26.0" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.63", ] [[package]] name = "serde_json" -version = "1.0.107" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "itoa", "ryu", @@ -859,9 +877,9 @@ dependencies = [ [[package]] name = "signature" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ "digest 0.10.7", "rand_core 0.6.4", @@ -869,25 +887,31 @@ dependencies = [ [[package]] name = "spki" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" dependencies = [ "base64ct", "der", ] +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "strum_macros" -version = "0.24.3" +version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" dependencies = [ "heck", "proc-macro2", "quote", "rustversion", - "syn 1.0.109", + "syn 2.0.63", ] [[package]] @@ -909,9 +933,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.38" +version = "2.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" dependencies = [ "proc-macro2", "quote", @@ -920,22 +944,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.49" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" +checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.49" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" +checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.63", ] [[package]] @@ -964,6 +988,6 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "zeroize" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/testutil/contracts/rate-limiter/Cargo.toml b/testutil/contracts/rate-limiter/Cargo.toml index c349919121..8642166bf1 100644 --- a/testutil/contracts/rate-limiter/Cargo.toml +++ b/testutil/contracts/rate-limiter/Cargo.toml @@ -43,19 +43,19 @@ optimize-arm = """docker run --rm -v "$(pwd)":/code \ """ [dependencies] -provwasm-std = { version = "2.0.0" } -cosmwasm-schema = "1.2.5" -cosmwasm-std = { version = "1.4.4", features = ["stargate", "cosmwasm_1_1"] } -cosmwasm-storage = "1.2.5" -cw-storage-plus = { version = "1.0.1", features = ["iterator"] } +provwasm-std = { version = "2.2.0" } +cosmwasm-schema = "1.5" +cosmwasm-std = { version = "1.5", features = ["stargate", "cosmwasm_1_1"] } +cosmwasm-storage = "1.2.0" +cw-storage-plus = { version = "1.2.0", features = ["iterator"] } cw2 = "1.0.1" -schemars = "0.8.10" -serde = { version = "1.0.163", default-features = false, features = ["derive"] } -thiserror = { version = "1.0.31" } +schemars = "0.8.16" +serde = { version = "1.0.197", default-features = false, features = ["derive"] } +thiserror = { version = "1.0.58" } sha2 = "0.10.6" hex = "0.4.3" [dev-dependencies] cw-multi-test = "0.17.0" -provwasm-mocks = { version = "2.0.0" } +provwasm-mocks = { version = "2.2.0" } serde-json-wasm = "1.0.1" diff --git a/testutil/contracts/rate-limiter/artifacts/checksums.txt b/testutil/contracts/rate-limiter/artifacts/checksums.txt index 9676e9e6d7..1865d9cf5e 100644 --- a/testutil/contracts/rate-limiter/artifacts/checksums.txt +++ b/testutil/contracts/rate-limiter/artifacts/checksums.txt @@ -1 +1,2 @@ -0f88126e350653cbe13f1295bbeba80b0ff1bbe70233c4d60980275bc40187cf rate_limiter-aarch64.wasm +d6d8388278a66bd6fc0588aed01632396171e3252f7973a793634d4f4b0816c0 rate_limiter-aarch64.wasm +93f0b2316138deae96044e86418850737f7f9bc85652c4a8b9053b2c86fc6f2b rate_limiter.wasm diff --git a/testutil/contracts/rate-limiter/artifacts/checksums_intermediate.txt b/testutil/contracts/rate-limiter/artifacts/checksums_intermediate.txt index ab517fbe4f..03b908261b 100644 --- a/testutil/contracts/rate-limiter/artifacts/checksums_intermediate.txt +++ b/testutil/contracts/rate-limiter/artifacts/checksums_intermediate.txt @@ -1 +1 @@ -0b2277d8c51fe5a5bd25e97d45b85ad2de77c3aa3a39fa6366ee8b8ac38c96e3 /target/wasm32-unknown-unknown/release/rate_limiter.wasm +0e155e1ee6b2906ecf03a4d61f747c59fadcb86fd4c86d59a55afa6ecd4282a2 /target/wasm32-unknown-unknown/release/rate_limiter.wasm diff --git a/testutil/contracts/rate-limiter/artifacts/rate_limiter-aarch64.wasm b/testutil/contracts/rate-limiter/artifacts/rate_limiter-aarch64.wasm index b84afbf2ee..2ced7c0745 100644 Binary files a/testutil/contracts/rate-limiter/artifacts/rate_limiter-aarch64.wasm and b/testutil/contracts/rate-limiter/artifacts/rate_limiter-aarch64.wasm differ diff --git a/testutil/contracts/rate-limiter/artifacts/rate_limiter.wasm b/testutil/contracts/rate-limiter/artifacts/rate_limiter.wasm index ad06f6bf91..35631d0d2d 100644 Binary files a/testutil/contracts/rate-limiter/artifacts/rate_limiter.wasm and b/testutil/contracts/rate-limiter/artifacts/rate_limiter.wasm differ diff --git a/testutil/contracts/rate-limiter/src/contract_tests.rs b/testutil/contracts/rate-limiter/src/contract_tests.rs index b51009c060..51473d29aa 100644 --- a/testutil/contracts/rate-limiter/src/contract_tests.rs +++ b/testutil/contracts/rate-limiter/src/contract_tests.rs @@ -3,7 +3,7 @@ use crate::packet::Packet; use crate::{contract::*, test_msg_recv, test_msg_send, ContractError}; use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; -use cosmwasm_std::{from_binary, Addr, Attribute, Uint256}; +use cosmwasm_std::{from_json, Addr, Attribute, Uint256}; use crate::helpers::tests::verify_query_response; use crate::msg::{InstantiateMsg, PathMsg, QueryMsg, QuotaMsg, SudoMsg}; @@ -29,8 +29,8 @@ fn proper_instantiation() { assert_eq!(0, res.messages.len()); // The ibc and gov modules are properly stored - assert_eq!(IBCMODULE.load(deps.as_ref().storage).unwrap(), IBC_ADDR); - assert_eq!(GOVMODULE.load(deps.as_ref().storage).unwrap(), GOV_ADDR); + assert_eq!(IBCMODULE.load(deps.as_ref().storage).unwrap().as_str(), IBC_ADDR); + assert_eq!(GOVMODULE.load(deps.as_ref().storage).unwrap().as_str(), GOV_ADDR); } #[test] // Tests that when a packet is transferred, the peropper allowance is consummed @@ -241,7 +241,7 @@ fn query_state() { }; let res = query(deps.as_ref(), mock_env(), query_msg.clone()).unwrap(); - let value: Vec = from_binary(&res).unwrap(); + let value: Vec = from_json(&res).unwrap(); assert_eq!(value[0].quota.name, "weekly"); assert_eq!(value[0].quota.max_percentage_send, 10); assert_eq!(value[0].quota.max_percentage_recv, 10); @@ -271,7 +271,7 @@ fn query_state() { // Query let res = query(deps.as_ref(), mock_env(), query_msg.clone()).unwrap(); - let value: Vec = from_binary(&res).unwrap(); + let value: Vec = from_json(&res).unwrap(); verify_query_response( &value[0], "weekly", @@ -311,7 +311,7 @@ fn bad_quotas() { denom: format!("denom"), }; let res = query(deps.as_ref(), env.clone(), query_msg).unwrap(); - let value: Vec = from_binary(&res).unwrap(); + let value: Vec = from_json(&res).unwrap(); verify_query_response( &value[0], "bad_quota", diff --git a/testutil/contracts/rate-limiter/src/execute.rs b/testutil/contracts/rate-limiter/src/execute.rs index 047a2179dd..12e743a8c1 100644 --- a/testutil/contracts/rate-limiter/src/execute.rs +++ b/testutil/contracts/rate-limiter/src/execute.rs @@ -111,7 +111,7 @@ pub fn try_reset_path_quota( #[cfg(test)] mod tests { use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; - use cosmwasm_std::{from_binary, Addr, StdError}; + use cosmwasm_std::{from_json, Addr, StdError}; use crate::contract::{execute, query}; use crate::helpers::tests::verify_query_response; @@ -153,7 +153,7 @@ mod tests { let res = query(deps.as_ref(), mock_env(), query_msg.clone()).unwrap(); - let value: Vec = from_binary(&res).unwrap(); + let value: Vec = from_json(&res).unwrap(); verify_query_response( &value[0], "daily", @@ -201,7 +201,7 @@ mod tests { denom: format!("denom"), }; let res = query(deps.as_ref(), mock_env(), query_msg.clone()).unwrap(); - let value: Vec = from_binary(&res).unwrap(); + let value: Vec = from_json(&res).unwrap(); assert_eq!(value.len(), 1); verify_query_response( &value[0], @@ -233,7 +233,7 @@ mod tests { denom: format!("denom"), }; let res = query(deps.as_ref(), mock_env(), query_msg.clone()).unwrap(); - let value: Vec = from_binary(&res).unwrap(); + let value: Vec = from_json(&res).unwrap(); assert_eq!(value.len(), 1); verify_query_response( diff --git a/testutil/contracts/rate-limiter/src/helpers.rs b/testutil/contracts/rate-limiter/src/helpers.rs index 530d3b6cf2..3d8befc5a2 100644 --- a/testutil/contracts/rate-limiter/src/helpers.rs +++ b/testutil/contracts/rate-limiter/src/helpers.rs @@ -2,7 +2,7 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use cosmwasm_std::{to_binary, Addr, CosmosMsg, StdResult, WasmMsg}; +use cosmwasm_std::{to_json_binary, Addr, CosmosMsg, StdResult, WasmMsg}; use crate::msg::ExecuteMsg; use crate::msg::SudoMsg; @@ -18,7 +18,7 @@ impl RateLimitingContract { } pub fn call>(&self, msg: T) -> StdResult { - let msg = to_binary(&msg.into())?; + let msg = to_json_binary(&msg.into())?; Ok(WasmMsg::Execute { contract_addr: self.addr().into(), msg, @@ -28,7 +28,7 @@ impl RateLimitingContract { } pub fn sudo>(&self, msg: T) -> cw_multi_test::SudoMsg { - let msg = to_binary(&msg.into()).unwrap(); + let msg = to_json_binary(&msg.into()).unwrap(); cw_multi_test::SudoMsg::Wasm(cw_multi_test::WasmSudo { contract_addr: self.addr().into(), msg, diff --git a/testutil/contracts/rate-limiter/src/management.rs b/testutil/contracts/rate-limiter/src/management.rs index 04dc47df80..c6e47f323e 100644 --- a/testutil/contracts/rate-limiter/src/management.rs +++ b/testutil/contracts/rate-limiter/src/management.rs @@ -112,7 +112,7 @@ pub fn try_reset_path_quota( mod tests { use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; - use cosmwasm_std::{from_binary, Addr, StdError}; + use cosmwasm_std::{from_json, Addr, StdError}; use crate::contract::{execute, query}; use crate::helpers::tests::verify_query_response; @@ -154,7 +154,7 @@ mod tests { let res = query(deps.as_ref(), mock_env(), query_msg.clone()).unwrap(); - let value: Vec = from_binary(&res).unwrap(); + let value: Vec = from_json(&res).unwrap(); verify_query_response( &value[0], "daily", @@ -202,7 +202,7 @@ mod tests { denom: format!("denom"), }; let res = query(deps.as_ref(), mock_env(), query_msg.clone()).unwrap(); - let value: Vec = from_binary(&res).unwrap(); + let value: Vec = from_json(&res).unwrap(); assert_eq!(value.len(), 1); verify_query_response( &value[0], @@ -234,7 +234,7 @@ mod tests { denom: format!("denom"), }; let res = query(deps.as_ref(), mock_env(), query_msg.clone()).unwrap(); - let value: Vec = from_binary(&res).unwrap(); + let value: Vec = from_json(&res).unwrap(); assert_eq!(value.len(), 1); verify_query_response( diff --git a/testutil/contracts/rate-limiter/src/query.rs b/testutil/contracts/rate-limiter/src/query.rs index 6431a837d4..9b211fa9d6 100644 --- a/testutil/contracts/rate-limiter/src/query.rs +++ b/testutil/contracts/rate-limiter/src/query.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, Binary, Deps, StdResult}; +use cosmwasm_std::{to_json_binary, Binary, Deps, StdResult}; use crate::state::{Path, RATE_LIMIT_TRACKERS}; @@ -8,5 +8,5 @@ pub fn get_quotas( denom: impl Into, ) -> StdResult { let path = Path::new(channel_id, denom); - to_binary(&RATE_LIMIT_TRACKERS.load(deps.storage, path.into())?) + to_json_binary(&RATE_LIMIT_TRACKERS.load(deps.storage, path.into())?) } diff --git a/testutil/ibc/testchain.go b/testutil/ibc/testchain.go index 85016678ce..2ab7aabaaa 100644 --- a/testutil/ibc/testchain.go +++ b/testutil/ibc/testchain.go @@ -2,12 +2,14 @@ package ibc import ( "encoding/json" + "fmt" "math/rand" "testing" "time" "github.com/stretchr/testify/suite" + abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/baseapp" @@ -81,26 +83,37 @@ func (chain *TestChain) RegisterRateLimiterContract(suite *suite.Suite, addr []b } // SendMsgsNoCheck is an alternative to ibctesting.TestChain.SendMsgs so that it doesn't check for errors. That should be handled by the caller -func (chain *TestChain) SendMsgsNoCheck(msgs ...sdk.Msg) (*sdk.Result, error) { +func (chain *TestChain) SendMsgsNoCheck(suite *suite.Suite, msgs ...sdk.Msg) (*abci.ExecTxResult, error) { // ensure the chain has the latest time chain.Coordinator.UpdateTimeForChain(chain.TestChain) - _, r, err := SignAndDeliver( + resp, err := SignAndDeliver( + // chain.TB, chain.TxConfig, chain.App.GetBaseApp(), - chain.GetContext().BlockHeader(), msgs, chain.ChainID, []uint64{chain.SenderAccount.GetAccountNumber()}, []uint64{chain.SenderAccount.GetSequence()}, + true, + chain.CurrentHeader.GetTime(), + chain.NextVals.Hash(), chain.SenderPrivKey, ) if err != nil { return nil, err } - // SignAndDeliver calls app.Commit() - chain.NextBlock() + chain.commitBlock(suite, resp) + + chain.Coordinator.IncrementTime() + + suite.Require().Len(resp.TxResults, 1) + txResult := resp.TxResults[0] + + if txResult.Code != 0 { + return txResult, fmt.Errorf("%s/%d: %q", txResult.Codespace, txResult.Code, txResult.Log) + } // increment sequence for successful transaction execution err = chain.SenderAccount.SetSequence(chain.SenderAccount.GetSequence() + 1) @@ -110,20 +123,49 @@ func (chain *TestChain) SendMsgsNoCheck(msgs ...sdk.Msg) (*sdk.Result, error) { chain.Coordinator.IncrementTime() - return r, nil + return txResult, nil +} + +// Copied from ibctesting because it's private +func (chain *TestChain) commitBlock(suite *suite.Suite, res *abci.ResponseFinalizeBlock) { + _, err := chain.App.Commit() + suite.Require().NoError(err) + + // set the last header to the current header + // use nil trusted fields + chain.LastHeader = chain.CurrentTMClientHeader() + + // val set changes returned from previous block get applied to the next validators + // of this block. See tendermint spec for details. + chain.Vals = chain.NextVals + chain.NextVals = ibctesting.ApplyValSetChanges(chain, chain.Vals, res.ValidatorUpdates) + + // increment the current header + chain.CurrentHeader = cmtproto.Header{ + ChainID: chain.ChainID, + Height: chain.App.LastBlockHeight() + 1, + AppHash: chain.App.LastCommitID().Hash, + // NOTE: the time is increased by the coordinator to maintain time synchrony amongst + // chains. + Time: chain.CurrentHeader.Time, + ValidatorsHash: chain.Vals.Hash(), + NextValidatorsHash: chain.NextVals.Hash(), + ProposerAddress: chain.CurrentHeader.ProposerAddress, + } } // SignAndDeliver signs and delivers a transaction without asserting the results. This overrides the function // from ibctesting func SignAndDeliver( - txCfg client.TxConfig, app *baseapp.BaseApp, _ cmtproto.Header, msgs []sdk.Msg, - chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey, -) (sdk.GasInfo, *sdk.Result, error) { - tx, _ := simtestutil.GenSignedMockTx( + txCfg client.TxConfig, app *baseapp.BaseApp, msgs []sdk.Msg, + chainID string, accNums, accSeqs []uint64, expPass bool, blockTime time.Time, nextValHash []byte, priv ...cryptotypes.PrivKey, +) (*abci.ResponseFinalizeBlock, error) { + // tb.Helper() + tx, err := simtestutil.GenSignedMockTx( rand.New(rand.NewSource(time.Now().UnixNano())), txCfg, msgs, - sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 2500)}, + sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, simtestutil.DefaultGenTxGas, chainID, accNums, @@ -131,10 +173,21 @@ func SignAndDeliver( priv..., ) - // Simulate a sending a transaction and committing a block - gInfo, res, err := app.SimDeliver(txCfg.TxEncoder(), tx) + if err != nil { + return nil, err + } - return gInfo, res, err + txBytes, err := txCfg.TxEncoder()(tx) + if err != nil { + return nil, err + } + + return app.FinalizeBlock(&abci.RequestFinalizeBlock{ + Height: app.LastBlockHeight() + 1, + Time: blockTime, + NextValidatorsHash: nextValHash, + Txs: [][]byte{txBytes}, + }) } // GetProvenanceApp returns the current chain's app as an ProvenanceApp diff --git a/x/ibchooks/ibc_middleware_test.go b/x/ibchooks/ibc_middleware_test.go index be1e0701d7..7259836ca3 100644 --- a/x/ibchooks/ibc_middleware_test.go +++ b/x/ibchooks/ibc_middleware_test.go @@ -437,7 +437,7 @@ func (suite *HooksTestSuite) FullSend(msg sdk.Msg, direction Direction) (*sdk.Re case BtoA: sender = suite.chainB } - sendResult, err := sender.SendMsgsNoCheck(msg) + sendResult, err := sender.SendMsgsNoCheck(&suite.Suite, msg) suite.Require().NoError(err) packet, err := ibctesting.ParsePacketFromEvents(sendResult.Events) @@ -445,7 +445,9 @@ func (suite *HooksTestSuite) FullSend(msg sdk.Msg, direction Direction) (*sdk.Re receiveResult, ack := suite.RelayPacket(packet, direction) - return sendResult, receiveResult, string(ack), err + // TODO[1760]: ibchooks: Update tests + // return sendResult, receiveResult, string(ack), err + return nil, receiveResult, string(ack), err } func (suite *HooksTestSuite) TestAcks() { diff --git a/x/ibchooks/keeper/params.go b/x/ibchooks/keeper/params.go index e0f47e6755..f8ffe477df 100644 --- a/x/ibchooks/keeper/params.go +++ b/x/ibchooks/keeper/params.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/provenance-io/provenance/x/ibchooks/types" ) diff --git a/x/ibcratelimit/module/ibc_middleware.go b/x/ibcratelimit/module/ibc_middleware.go index cc9c51b5e4..f86b8d315b 100644 --- a/x/ibcratelimit/module/ibc_middleware.go +++ b/x/ibcratelimit/module/ibc_middleware.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" + transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" @@ -210,6 +211,14 @@ func (im *IBCMiddleware) SendPacket( timeoutTimestamp uint64, data []byte, ) (sequence uint64, err error) { + var packetdata transfertypes.FungibleTokenPacketData + if err := json.Unmarshal(data, &packetdata); err != nil { + return im.channel.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data) + } + if packetdata.Denom == "" || packetdata.Amount == "" { + return im.channel.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data) + } + if !im.keeper.IsContractConfigured(ctx) { // The contract has not been configured. Continue as usual return im.channel.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data) diff --git a/x/ibcratelimit/module/ibc_middleware_test.go b/x/ibcratelimit/module/ibc_middleware_test.go index 74d032ccba..56967ddf82 100644 --- a/x/ibcratelimit/module/ibc_middleware_test.go +++ b/x/ibcratelimit/module/ibc_middleware_test.go @@ -14,12 +14,14 @@ import ( "cosmossdk.io/log" sdkmath "cosmossdk.io/math" + abci "github.com/cometbft/cometbft/abci/types" dbm "github.com/cosmos/cosmos-db" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" ibctesting "github.com/cosmos/ibc-go/v8/testing" @@ -57,39 +59,39 @@ func SetupSimApp() (ibctesting.TestingApp, map[string]json.RawMessage) { return provenanceApp, genesis } -func (s *MiddlewareTestSuite) SetupTest() { - SkipIfWSL(s.T()) +func (suite *MiddlewareTestSuite) SetupTest() { + SkipIfWSL(suite.T()) ibctesting.DefaultTestingAppInit = SetupSimApp - s.coordinator = ibctesting.NewCoordinator(s.T(), 2) + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) - s.chainA = &testutil.TestChain{ - TestChain: s.coordinator.GetChain(ibctesting.GetChainID(1)), + suite.chainA = &testutil.TestChain{ + TestChain: suite.coordinator.GetChain(ibctesting.GetChainID(1)), } - s.chainB = &testutil.TestChain{ - TestChain: s.coordinator.GetChain(ibctesting.GetChainID(2)), + suite.chainB = &testutil.TestChain{ + TestChain: suite.coordinator.GetChain(ibctesting.GetChainID(2)), } - s.path = NewTransferPath(s.chainA, s.chainB) - s.coordinator.Setup(s.path) + suite.path = NewTransferPath(suite.chainA, suite.chainB) + suite.coordinator.Setup(suite.path) - params, err := s.chainA.GetProvenanceApp().MintKeeper.Params.Get(s.chainA.GetContext()) - s.Require().NoError(err, "getting mint keeper params") + params, err := suite.chainA.GetProvenanceApp().MintKeeper.Params.Get(suite.chainA.GetContext()) + suite.Require().NoError(err, "getting mint keeper params") params.InflationMax = sdkmath.LegacyNewDec(0) params.InflationRateChange = sdkmath.LegacyNewDec(1) params.InflationMin = sdkmath.LegacyNewDec(0) - err = s.chainA.GetProvenanceApp().MintKeeper.Params.Set(s.chainA.GetContext(), params) - s.Require().NoError(err, "setting mint keeper params for chainA") - err = s.chainB.GetProvenanceApp().MintKeeper.Params.Set(s.chainB.GetContext(), params) - s.Require().NoError(err, "setting mint keeper params for chainB") + err = suite.chainA.GetProvenanceApp().MintKeeper.Params.Set(suite.chainA.GetContext(), params) + suite.Require().NoError(err, "setting mint keeper params for chainA") + err = suite.chainB.GetProvenanceApp().MintKeeper.Params.Set(suite.chainB.GetContext(), params) + suite.Require().NoError(err, "setting mint keeper params for chainB") } // MessageFromAToB sends a message from chain A to chain B. -func (s *MiddlewareTestSuite) MessageFromAToB(denom string, amount sdkmath.Int) sdk.Msg { +func (suite *MiddlewareTestSuite) MessageFromAToB(denom string, amount sdkmath.Int) sdk.Msg { coin := sdk.NewCoin(denom, amount) - port := s.path.EndpointA.ChannelConfig.PortID - channel := s.path.EndpointA.ChannelID - accountFrom := s.chainA.SenderAccount.GetAddress().String() - accountTo := s.chainB.SenderAccount.GetAddress().String() - timeoutHeight := clienttypes.NewHeight(0, 100) + port := suite.path.EndpointA.ChannelConfig.PortID + channel := suite.path.EndpointA.ChannelID + accountFrom := suite.chainA.SenderAccount.GetAddress().String() + accountTo := suite.chainB.SenderAccount.GetAddress().String() + timeoutHeight := clienttypes.NewHeight(10, 100) memo := "" return transfertypes.NewMsgTransfer( port, @@ -104,13 +106,13 @@ func (s *MiddlewareTestSuite) MessageFromAToB(denom string, amount sdkmath.Int) } // MessageFromAToB sends a message from chain B to chain A. -func (s *MiddlewareTestSuite) MessageFromBToA(denom string, amount sdkmath.Int) sdk.Msg { +func (suite *MiddlewareTestSuite) MessageFromBToA(denom string, amount sdkmath.Int) sdk.Msg { coin := sdk.NewCoin(denom, amount) - port := s.path.EndpointB.ChannelConfig.PortID - channel := s.path.EndpointB.ChannelID - accountFrom := s.chainB.SenderAccount.GetAddress().String() - accountTo := s.chainA.SenderAccount.GetAddress().String() - timeoutHeight := clienttypes.NewHeight(0, 100) + port := suite.path.EndpointB.ChannelConfig.PortID + channel := suite.path.EndpointB.ChannelID + accountFrom := suite.chainB.SenderAccount.GetAddress().String() + accountTo := suite.chainA.SenderAccount.GetAddress().String() + timeoutHeight := clienttypes.NewHeight(10, 100) memo := "" return transfertypes.NewMsgTransfer( port, @@ -124,119 +126,91 @@ func (s *MiddlewareTestSuite) MessageFromBToA(denom string, amount sdkmath.Int) ) } -// Tests that a receiver address longer than 4096 is not accepted -func (s *MiddlewareTestSuite) TestInvalidReceiver() { - msg := transfertypes.NewMsgTransfer( - s.path.EndpointB.ChannelConfig.PortID, - s.path.EndpointB.ChannelID, - sdk.NewInt64Coin(sdk.DefaultBondDenom, 1), - s.chainB.SenderAccount.GetAddress().String(), - strings.Repeat("x", 4097), - clienttypes.NewHeight(0, 100), - 0, - "", - ) - _, ack, _ := s.FullSendBToA(msg) - s.Assert().Contains(ack, "error", - "acknowledgment is not an error") - s.Assert().Contains(ack, fmt.Sprintf("ABCI code: %d", ibcratelimit.ErrBadMessage.ABCICode()), - "acknowledgment error is not of the right type") -} - // FullSendBToA does the entire logic from sending a message from chain B to chain A. -func (s *MiddlewareTestSuite) FullSendBToA(msg sdk.Msg) (*sdk.Result, string, error) { - sendResult, err := s.chainB.SendMsgsNoCheck(msg) - s.Assert().NoError(err) - - packet, err := ibctesting.ParsePacketFromEvents(sendResult.Events) - s.Assert().NoError(err) - - err = s.path.EndpointA.UpdateClient() - s.Assert().NoError(err) +func (suite *MiddlewareTestSuite) FullSendBToA(msg sdk.Msg) (*abci.ExecTxResult, string, error) { + sendResult, err := suite.chainB.SendMsgsNoCheck(&suite.Suite, msg) + suite.Require().NoError(err) - res, err := s.path.EndpointA.RecvPacketWithResult(packet) - s.Assert().NoError(err) + packet, err := ibctesting.ParsePacketFromEvents(sendResult.GetEvents()) + suite.Require().NoError(err) + err = suite.path.EndpointA.UpdateClient() + suite.Require().NoError(err) + res, err := suite.path.EndpointA.RecvPacketWithResult(packet) + suite.Require().NoError(err) ack, err := ibctesting.ParseAckFromEvents(res.GetEvents()) - s.Assert().NoError(err) - - err = s.path.EndpointA.UpdateClient() - s.Assert().NoError(err) - err = s.path.EndpointB.UpdateClient() - s.Assert().NoError(err) - + suite.Require().NoError(err) + err = suite.path.EndpointA.UpdateClient() + suite.Require().NoError(err) + err = suite.path.EndpointB.UpdateClient() + suite.Require().NoError(err) return sendResult, string(ack), err } // FullSendAToB does the entire logic from sending a message from chain A to chain B. -func (s *MiddlewareTestSuite) FullSendAToB(msg sdk.Msg) (*sdk.Result, string, error) { - sendResult, err := s.chainA.SendMsgsNoCheck(msg) +func (suite *MiddlewareTestSuite) FullSendAToB(msg sdk.Msg) (*abci.ExecTxResult, string, error) { + sendResult, err := suite.chainA.SendMsgsNoCheck(&suite.Suite, msg) if err != nil { return nil, "", err } - packet, err := ibctesting.ParsePacketFromEvents(sendResult.Events) + packet, err := ibctesting.ParsePacketFromEvents(sendResult.GetEvents()) if err != nil { return nil, "", err } - - err = s.path.EndpointB.UpdateClient() + err = suite.path.EndpointB.UpdateClient() if err != nil { return nil, "", err } - - res, err := s.path.EndpointB.RecvPacketWithResult(packet) + res, err := suite.path.EndpointB.RecvPacketWithResult(packet) if err != nil { return nil, "", err } - ack, err := ibctesting.ParseAckFromEvents(res.GetEvents()) if err != nil { return nil, "", err } - - err = s.path.EndpointA.UpdateClient() + err = suite.path.EndpointA.UpdateClient() if err != nil { return nil, "", err } - err = s.path.EndpointB.UpdateClient() + err = suite.path.EndpointB.UpdateClient() if err != nil { return nil, "", err } - return sendResult, string(ack), nil } // AssertSend checks that a receive on A from B was successful. -func (s *MiddlewareTestSuite) AssertReceive(success bool, msg sdk.Msg) (string, error) { - _, ack, err := s.FullSendBToA(msg) +func (suite *MiddlewareTestSuite) AssertReceive(success bool, msg sdk.Msg) (string, error) { + _, ack, err := suite.FullSendBToA(msg) if success { - s.Assert().NoError(err) - s.Assert().NotContains(ack, "error", + suite.Assert().NoError(err) + suite.Assert().NotContains(ack, "error", "acknowledgment is an error") } else { - s.Assert().Contains(ack, "error", + suite.Assert().Contains(ack, "error", "acknowledgment is not an error") - s.Assert().Contains(ack, fmt.Sprintf("ABCI code: %d", ibcratelimit.ErrRateLimitExceeded.ABCICode()), + suite.Assert().Contains(ack, fmt.Sprintf("ABCI code: %d", ibcratelimit.ErrRateLimitExceeded.ABCICode()), "acknowledgment error is not of the right type") } return ack, err } // AssertSend checks that a send from A to B was successful. -func (s *MiddlewareTestSuite) AssertSend(success bool, msg sdk.Msg) (*sdk.Result, error) { - r, _, err := s.FullSendAToB(msg) +func (suite *MiddlewareTestSuite) AssertSend(success bool, msg sdk.Msg) (*abci.ExecTxResult, error) { + r, _, err := suite.FullSendAToB(msg) if success { - s.Assert().NoError(err, "IBC send failed. Expected success. %s", err) + suite.Require().NoError(err, "IBC send failed. Expected successuite. %s", err) } else { - s.Assert().Error(err, "IBC send succeeded. Expected failure") - s.ErrorContains(err, ibcratelimit.ErrRateLimitExceeded.Error(), "Bad error type") + suite.Require().Error(err, "IBC send succeeded. Expected failure") + suite.ErrorContains(err, ibcratelimit.ErrRateLimitExceeded.Error(), "Bad error type") } return r, err } // BuildChannelQuota creates a quota message. -func (s *MiddlewareTestSuite) BuildChannelQuota(name, channel, denom string, duration, send_percentage, recv_percentage uint32) string { +func (suite *MiddlewareTestSuite) BuildChannelQuota(name, channel, denom string, duration, send_percentage, recv_percentage uint32) string { return fmt.Sprintf(` {"channel_id": "%s", "denom": "%s", "quotas": [{"name":"%s", "duration": %d, "send_recv":[%d, %d]}] } `, channel, denom, name, duration, send_percentage, recv_percentage) @@ -244,24 +218,46 @@ func (s *MiddlewareTestSuite) BuildChannelQuota(name, channel, denom string, dur // Tests +// Test rate limits are reverted if a "send" fails +func (suite *MiddlewareTestSuite) TestNonICS20() { + suite.initializeEscrow() + // Setup contract + suite.chainA.StoreContractRateLimiterDirect(&suite.Suite) + quotas := suite.BuildChannelQuota("weekly", "channel-0", sdk.DefaultBondDenom, 604800, 1, 1) + + initMsg := CreateRateLimiterInitMessage(suite.chainA, quotas) + addr := suite.chainA.InstantiateContract(&suite.Suite, initMsg, 1) + suite.chainA.RegisterRateLimiterContract(&suite.Suite, addr) + + provApp := suite.chainA.GetProvenanceApp() + + data := []byte("{}") + _, err := provApp.RateLimitMiddleware.SendPacket(suite.chainA.GetContext(), capabilitytypes.NewCapability(1), "wasm.cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", "channel-0", clienttypes.NewHeight(0, 0), 1, data) + + suite.Require().Error(err) + // This will error out, but not because of rate limiting + suite.Require().NotContains(err.Error(), "rate limit") + suite.Require().Contains(err.Error(), "invalid denom") +} + // Test that Sending IBC messages works when the middleware isn't configured -func (s *MiddlewareTestSuite) TestSendTransferNoContract() { +func (suite *MiddlewareTestSuite) TestSendTransferNoContract() { one := sdkmath.NewInt(1) - _, err := s.AssertSend(true, s.MessageFromAToB(sdk.DefaultBondDenom, one)) - s.Assert().NoError(err) + _, err := suite.AssertSend(true, suite.MessageFromAToB(sdk.DefaultBondDenom, one)) + suite.Assert().NoError(err) } // Test that Receiving IBC messages works when the middleware isn't configured -func (s *MiddlewareTestSuite) TestReceiveTransferNoContract() { +func (suite *MiddlewareTestSuite) TestReceiveTransferNoContract() { one := sdkmath.NewInt(1) - _, err := s.AssertReceive(true, s.MessageFromBToA(sdk.DefaultBondDenom, one)) - s.Assert().NoError(err) + _, err := suite.AssertReceive(true, suite.MessageFromBToA(sdk.DefaultBondDenom, one)) + suite.Assert().NoError(err) } // initializeEscrow sets up the escrow on the chain. -func (s *MiddlewareTestSuite) initializeEscrow() (totalEscrow, expectedSed sdkmath.Int) { - provenanceApp := s.chainA.GetProvenanceApp() - supply := provenanceApp.BankKeeper.GetSupply(s.chainA.GetContext(), sdk.DefaultBondDenom) +func (suite *MiddlewareTestSuite) initializeEscrow() (totalEscrow, expectedSed sdkmath.Int) { + provenanceApp := suite.chainA.GetProvenanceApp() + supply := provenanceApp.BankKeeper.GetSupply(suite.chainA.GetContext(), sdk.DefaultBondDenom) // Move some funds from chainA to chainB so that there is something in escrow // Each user has 10% of the supply, so we send most of the funds from one user to chainA @@ -273,18 +269,19 @@ func (s *MiddlewareTestSuite) initializeEscrow() (totalEscrow, expectedSed sdkma sendAmount := transferAmount.QuoRaw(40) // Send from A to B - _, _, err := s.FullSendAToB(s.MessageFromAToB(sdk.DefaultBondDenom, transferAmount.Sub(sendAmount))) - s.Assert().NoError(err) + _, _, err := suite.FullSendAToB(suite.MessageFromAToB(sdk.DefaultBondDenom, transferAmount.Sub(sendAmount))) + suite.Assert().NoError(err) + // Send from A to B - _, _, err = s.FullSendBToA(s.MessageFromBToA(sdk.DefaultBondDenom, transferAmount.Sub(sendAmount))) - s.Assert().NoError(err) + _, _, err = suite.FullSendBToA(suite.MessageFromBToA(sdk.DefaultBondDenom, transferAmount.Sub(sendAmount))) + suite.Assert().NoError(err) return transferAmount, sendAmount } -func (s *MiddlewareTestSuite) fullSendTest(native bool) map[string]string { +func (suite *MiddlewareTestSuite) fullSendTest(native bool) map[string]string { quotaPercentage := 5 - s.initializeEscrow() + suite.initializeEscrow() // Get the denom and amount to send denom := sdk.DefaultBondDenom channel := "channel-0" @@ -294,10 +291,10 @@ func (s *MiddlewareTestSuite) fullSendTest(native bool) map[string]string { denom = denomTrace.IBCDenom() } - provenanceApp := s.chainA.GetProvenanceApp() + provenanceApp := suite.chainA.GetProvenanceApp() - // This is the first one. Inside the tests. It works as expected. - channelValue := CalculateChannelValue(s.chainA.GetContext(), denom, provenanceApp.BankKeeper) + // This is the first one. Inside the testsuite. It works as expected. + channelValue := CalculateChannelValue(suite.chainA.GetContext(), denom, provenanceApp.BankKeeper) // The amount to be sent is send 2.5% (quota is 5%) quota := channelValue.QuoRaw(int64(100 / quotaPercentage)) @@ -306,79 +303,79 @@ func (s *MiddlewareTestSuite) fullSendTest(native bool) map[string]string { fmt.Printf("Testing send rate limiting for denom=%s, channelValue=%s, quota=%s, sendAmount=%s\n", denom, channelValue, quota, sendAmount) // Setup contract - s.chainA.StoreContractRateLimiterDirect(&s.Suite) - quotas := s.BuildChannelQuota("weekly", channel, denom, 604800, 5, 5) + suite.chainA.StoreContractRateLimiterDirect(&suite.Suite) + quotas := suite.BuildChannelQuota("weekly", channel, denom, 604800, 5, 5) fmt.Println(quotas) - initMsg := CreateRateLimiterInitMessage(s.chainA, quotas) - addr := s.chainA.InstantiateContract(&s.Suite, initMsg, 1) - s.chainA.RegisterRateLimiterContract(&s.Suite, addr) + initMsg := CreateRateLimiterInitMessage(suite.chainA, quotas) + addr := suite.chainA.InstantiateContract(&suite.Suite, initMsg, 1) + suite.chainA.RegisterRateLimiterContract(&suite.Suite, addr) // send 2.5% (quota is 5%) fmt.Printf("Sending %s from A to B. Represented in chain A as wrapped? %v\n", denom, !native) - _, err := s.AssertSend(true, s.MessageFromAToB(denom, sendAmount)) - s.Assert().NoError(err) + _, err := suite.AssertSend(true, suite.MessageFromAToB(denom, sendAmount)) + suite.Assert().NoError(err) // send 2.5% (quota is 5%) fmt.Println("trying to send ", sendAmount) - r, _ := s.AssertSend(true, s.MessageFromAToB(denom, sendAmount)) + r, _ := suite.AssertSend(true, suite.MessageFromAToB(denom, sendAmount)) // Calculate remaining allowance in the quota attrs := ExtractAttributes(FindEvent(r.GetEvents(), "wasm")) used, ok := sdkmath.NewIntFromString(attrs["weekly_used_out"]) - s.Assert().True(ok) + suite.Assert().True(ok) - s.Assert().Equal(used, sendAmount.MulRaw(2)) + suite.Assert().Equal(used, sendAmount.MulRaw(2)) // Sending above the quota should fail. We use 2 instead of 1 here to avoid rounding issues - _, err = s.AssertSend(false, s.MessageFromAToB(denom, sdkmath.NewInt(2))) - s.Assert().Error(err) + _, err = suite.AssertSend(false, suite.MessageFromAToB(denom, sdkmath.NewInt(2))) + suite.Assert().Error(err) return attrs } // Test rate limiting on sends -func (s *MiddlewareTestSuite) TestSendTransferWithRateLimitingNative() { +func (suite *MiddlewareTestSuite) TestSendTransferWithRateLimitingNative() { // Sends denom=stake from A->B. Rate limit receives "stake" in the packet. Nothing to do in the contract - s.fullSendTest(true) + suite.fullSendTest(true) } // Test rate limiting on sends -func (s *MiddlewareTestSuite) TestSendTransferWithRateLimitingNonNative() { +func (suite *MiddlewareTestSuite) TestSendTransferWithRateLimitingNonNative() { // Sends denom=ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B77878 from A->B. // Rate limit receives "transfer/channel-0/stake" in the packet (because transfer.relay.SendTransfer is called before the middleware) // and should hash it before calculating the value - s.fullSendTest(false) + suite.fullSendTest(false) } // Test rate limits are reset when the specified time period has passed -func (s *MiddlewareTestSuite) TestSendTransferReset() { +func (suite *MiddlewareTestSuite) TestSendTransferReset() { // Same test as above, but the quotas get reset after time passes - attrs := s.fullSendTest(true) + attrs := suite.fullSendTest(true) parts := strings.Split(attrs["weekly_period_end"], ".") // Splitting timestamp into secs and nanos secs, err := strconv.ParseInt(parts[0], 10, 64) - s.Assert().NoError(err) + suite.Assert().NoError(err) nanos, err := strconv.ParseInt(parts[1], 10, 64) - s.Assert().NoError(err) + suite.Assert().NoError(err) resetTime := time.Unix(secs, nanos) // Move chainA forward one block - s.chainA.NextBlock() - err = s.chainA.SenderAccount.SetSequence(s.chainA.SenderAccount.GetSequence() + 1) - s.Assert().NoError(err) + suite.chainA.NextBlock() + err = suite.chainA.SenderAccount.SetSequence(suite.chainA.SenderAccount.GetSequence() + 1) + suite.Assert().NoError(err) // Reset time + one second oneSecAfterReset := resetTime.Add(time.Second) - s.coordinator.IncrementTimeBy(oneSecAfterReset.Sub(s.coordinator.CurrentTime)) + suite.coordinator.IncrementTimeBy(oneSecAfterReset.Sub(suite.coordinator.CurrentTime)) // Sending should succeed again - _, err = s.AssertSend(true, s.MessageFromAToB(sdk.DefaultBondDenom, sdkmath.NewInt(1))) - s.Assert().NoError(err) + _, err = suite.AssertSend(true, suite.MessageFromAToB(sdk.DefaultBondDenom, sdkmath.NewInt(1))) + suite.Assert().NoError(err) } // Test rate limiting on receives -func (s *MiddlewareTestSuite) fullRecvTest(native bool) { +func (suite *MiddlewareTestSuite) fullRecvTest(native bool) { quotaPercentage := 4 - s.initializeEscrow() + suite.initializeEscrow() // Get the denom and amount to send sendDenom := sdk.DefaultBondDenom localDenom := sdk.DefaultBondDenom @@ -391,9 +388,9 @@ func (s *MiddlewareTestSuite) fullRecvTest(native bool) { sendDenom = denomTrace.IBCDenom() } - provenanceApp := s.chainA.GetProvenanceApp() + provenanceApp := suite.chainA.GetProvenanceApp() - channelValue := CalculateChannelValue(s.chainA.GetContext(), localDenom, provenanceApp.BankKeeper) + channelValue := CalculateChannelValue(suite.chainA.GetContext(), localDenom, provenanceApp.BankKeeper) // The amount to be sent is 2% (quota is 4%) quota := channelValue.QuoRaw(int64(100 / quotaPercentage)) @@ -402,152 +399,152 @@ func (s *MiddlewareTestSuite) fullRecvTest(native bool) { fmt.Printf("Testing recv rate limiting for denom=%s, channelValue=%s, quota=%s, sendAmount=%s\n", localDenom, channelValue, quota, sendAmount) // Setup contract - s.chainA.StoreContractRateLimiterDirect(&s.Suite) - quotas := s.BuildChannelQuota("weekly", channel, localDenom, 604800, 4, 4) - initMsg := CreateRateLimiterInitMessage(s.chainA, quotas) - addr := s.chainA.InstantiateContract(&s.Suite, initMsg, 1) - s.chainA.RegisterRateLimiterContract(&s.Suite, addr) + suite.chainA.StoreContractRateLimiterDirect(&suite.Suite) + quotas := suite.BuildChannelQuota("weekly", channel, localDenom, 604800, 4, 4) + initMsg := CreateRateLimiterInitMessage(suite.chainA, quotas) + addr := suite.chainA.InstantiateContract(&suite.Suite, initMsg, 1) + suite.chainA.RegisterRateLimiterContract(&suite.Suite, addr) // receive 2.5% (quota is 5%) fmt.Printf("Sending %s from B to A. Represented in chain A as wrapped? %v\n", sendDenom, native) - _, err := s.AssertReceive(true, s.MessageFromBToA(sendDenom, sendAmount)) - s.Assert().NoError(err) + _, err := suite.AssertReceive(true, suite.MessageFromBToA(sendDenom, sendAmount)) + suite.Assert().NoError(err) // receive 2.5% (quota is 5%) - _, err = s.AssertReceive(true, s.MessageFromBToA(sendDenom, sendAmount)) - s.Assert().NoError(err) + _, err = suite.AssertReceive(true, suite.MessageFromBToA(sendDenom, sendAmount)) + suite.Assert().NoError(err) // Sending above the quota should fail. We send 2 instead of 1 to account for rounding errors - _, err = s.AssertReceive(false, s.MessageFromBToA(sendDenom, sdkmath.NewInt(2))) - s.Assert().NoError(err) + _, err = suite.AssertReceive(false, suite.MessageFromBToA(sendDenom, sdkmath.NewInt(2))) + suite.Assert().NoError(err) } -func (s *MiddlewareTestSuite) TestRecvTransferWithRateLimitingNative() { +func (suite *MiddlewareTestSuite) TestRecvTransferWithRateLimitingNative() { // Sends denom=stake from B->A. // Rate limit receives "stake" in the packet and should wrap it before calculating the value - // types.ReceiverChainIsSource(packet.GetSourcePort(), packet.GetSourceChannel(), data.Denom) should return false => Wrap the token - s.fullRecvTest(true) + // typesuite.ReceiverChainIsSource(packet.GetSourcePort(), packet.GetSourceChannel(), data.Denom) should return false => Wrap the token + suite.fullRecvTest(true) } -func (s *MiddlewareTestSuite) TestRecvTransferWithRateLimitingNonNative() { +func (suite *MiddlewareTestSuite) TestRecvTransferWithRateLimitingNonNative() { // Sends denom=ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B77878 from B->A. // Rate limit receives "transfer/channel-0/stake" in the packet and should turn it into "stake" - // types.ReceiverChainIsSource(packet.GetSourcePort(), packet.GetSourceChannel(), data.Denom) should return true => unprefix. If unprefixed is not local, hash. - s.fullRecvTest(false) + // typesuite.ReceiverChainIsSource(packet.GetSourcePort(), packet.GetSourceChannel(), data.Denom) should return true => unprefix. If unprefixed is not local, hash. + suite.fullRecvTest(false) } // Test no rate limiting occurs when the contract is set, but not quotas are condifured for the path -func (s *MiddlewareTestSuite) TestSendTransferNoQuota() { +func (suite *MiddlewareTestSuite) TestSendTransferNoQuota() { // Setup contract - s.chainA.StoreContractRateLimiterDirect(&s.Suite) - initMsg := CreateRateLimiterInitMessage(s.chainA, "") - addr := s.chainA.InstantiateContract(&s.Suite, initMsg, 1) - s.chainA.RegisterRateLimiterContract(&s.Suite, addr) + suite.chainA.StoreContractRateLimiterDirect(&suite.Suite) + initMsg := CreateRateLimiterInitMessage(suite.chainA, "") + addr := suite.chainA.InstantiateContract(&suite.Suite, initMsg, 1) + suite.chainA.RegisterRateLimiterContract(&suite.Suite, addr) // send 1 token. // If the contract doesn't have a quota for the current channel, all transfers are allowed - _, err := s.AssertSend(true, s.MessageFromAToB(sdk.DefaultBondDenom, sdkmath.NewInt(1))) - s.Assert().NoError(err) + _, err := suite.AssertSend(true, suite.MessageFromAToB(sdk.DefaultBondDenom, sdkmath.NewInt(1))) + suite.Assert().NoError(err) } // Test rate limits are reverted if a "send" fails -func (s *MiddlewareTestSuite) TestFailedSendTransfer() { - s.initializeEscrow() +func (suite *MiddlewareTestSuite) TestFailedSendTransfer() { + suite.initializeEscrow() // Setup contract - s.chainA.StoreContractRateLimiterDirect(&s.Suite) - quotas := s.BuildChannelQuota("weekly", "channel-0", sdk.DefaultBondDenom, 604800, 1, 1) - initMsg := CreateRateLimiterInitMessage(s.chainA, quotas) - addr := s.chainA.InstantiateContract(&s.Suite, initMsg, 1) - s.chainA.RegisterRateLimiterContract(&s.Suite, addr) + suite.chainA.StoreContractRateLimiterDirect(&suite.Suite) + quotas := suite.BuildChannelQuota("weekly", "channel-0", sdk.DefaultBondDenom, 604800, 1, 1) + initMsg := CreateRateLimiterInitMessage(suite.chainA, quotas) + addr := suite.chainA.InstantiateContract(&suite.Suite, initMsg, 1) + suite.chainA.RegisterRateLimiterContract(&suite.Suite, addr) // Get the escrowed amount - provenanceApp := s.chainA.GetProvenanceApp() - // ToDo: This is what we eventually want here, but using the full supply temporarily for performance reasons. See calculateChannelValue - // escrowAddress := transfertypes.GetEscrowAddress("transfer", "channel-0") - // escrowed := provenanceApp.BankKeeper.GetBalance(s.chainA.GetContext(), escrowAddress, sdk.DefaultBondDenom) - escrowed := provenanceApp.BankKeeper.GetSupply(s.chainA.GetContext(), sdk.DefaultBondDenom) + provenanceApp := suite.chainA.GetProvenanceApp() + // ToDo: This is what we eventually want here, but using the full supply temporarily for performance reasonsuite. See calculateChannelValue + // escrowAddress := transfertypesuite.GetEscrowAddress("transfer", "channel-0") + // escrowed := provenanceApp.BankKeeper.GetBalance(suite.chainA.GetContext(), escrowAddress, sdk.DefaultBondDenom) + escrowed := provenanceApp.BankKeeper.GetSupply(suite.chainA.GetContext(), sdk.DefaultBondDenom) quota := escrowed.Amount.QuoRaw(100) // 1% of the escrowed amount // Use the whole quota coins := sdk.NewCoin(sdk.DefaultBondDenom, quota) - port := s.path.EndpointA.ChannelConfig.PortID - channel := s.path.EndpointA.ChannelID - accountFrom := s.chainA.SenderAccount.GetAddress().String() - timeoutHeight := clienttypes.NewHeight(0, 100) + port := suite.path.EndpointA.ChannelConfig.PortID + channel := suite.path.EndpointA.ChannelID + accountFrom := suite.chainA.SenderAccount.GetAddress().String() + timeoutHeight := clienttypes.NewHeight(10, 100) memo := "" msg := transfertypes.NewMsgTransfer(port, channel, coins, accountFrom, "INVALID", timeoutHeight, 0, memo) - // Sending the message manually because AssertSend updates both clients. We need to update the clients manually + // Sending the message manually because AssertSend updates both clientsuite. We need to update the clients manually // for this test so that the failure to receive on chain B happens after the second packet is sent from chain A. // That way we validate that chain A is blocking as expected, but the flow is reverted after the receive failure is // acknowledged on chain A - res, err := s.chainA.SendMsgsNoCheck(msg) - s.Assert().NoError(err) + res, err := suite.chainA.SendMsgsNoCheck(&suite.Suite, msg) + suite.Assert().NoError(err) // Sending again fails as the quota is filled - _, err = s.AssertSend(false, s.MessageFromAToB(sdk.DefaultBondDenom, quota)) - s.Assert().Error(err) + _, err = suite.AssertSend(false, suite.MessageFromAToB(sdk.DefaultBondDenom, quota)) + suite.Assert().Error(err) // Move forward one block - s.chainA.NextBlock() - err = s.chainA.SenderAccount.SetSequence(s.chainA.SenderAccount.GetSequence() + 1) - s.Assert().NoError(err) - s.chainA.Coordinator.IncrementTime() + suite.chainA.NextBlock() + err = suite.chainA.SenderAccount.SetSequence(suite.chainA.SenderAccount.GetSequence() + 1) + suite.Assert().NoError(err) + suite.chainA.Coordinator.IncrementTime() // Update both clients - err = s.path.EndpointA.UpdateClient() - s.Assert().NoError(err) - err = s.path.EndpointB.UpdateClient() - s.Assert().NoError(err) + err = suite.path.EndpointA.UpdateClient() + suite.Assert().NoError(err) + err = suite.path.EndpointB.UpdateClient() + suite.Assert().NoError(err) // Execute the acknowledgement from chain B in chain A // extract the sent packet - packet, err := ibctesting.ParsePacketFromEvents(res.Events) - s.Assert().NoError(err) + packet, err := ibctesting.ParsePacketFromEvents(res.GetEvents()) + suite.Assert().NoError(err) // recv in chain b - txRes, err := s.path.EndpointB.RecvPacketWithResult(packet) - s.Assert().NoError(err) + txRes, err := suite.path.EndpointB.RecvPacketWithResult(packet) + suite.Assert().NoError(err) // get the ack from the chain b's response ack, err := ibctesting.ParseAckFromEvents(txRes.Events) - s.Assert().NoError(err) + suite.Assert().NoError(err) // manually relay it to chain a - err = s.path.EndpointA.AcknowledgePacket(packet, ack) - s.Assert().NoError(err) + err = suite.path.EndpointA.AcknowledgePacket(packet, ack) + suite.Assert().NoError(err) // We should be able to send again because the packet that exceeded the quota failed and has been reverted - _, err = s.AssertSend(true, s.MessageFromAToB(sdk.DefaultBondDenom, sdkmath.NewInt(1))) - s.Assert().NoError(err) + _, err = suite.AssertSend(true, suite.MessageFromAToB(sdk.DefaultBondDenom, sdkmath.NewInt(1))) + suite.Assert().NoError(err) } -func (s *MiddlewareTestSuite) TestUnsetRateLimitingContract() { +func (suite *MiddlewareTestSuite) TestUnsetRateLimitingContract() { // Setup contract - s.chainA.StoreContractRateLimiterDirect(&s.Suite) - msg := CreateRateLimiterInitMessage(s.chainA, "") - addr := s.chainA.InstantiateContract(&s.Suite, msg, 1) - s.chainA.RegisterRateLimiterContract(&s.Suite, addr) + suite.chainA.StoreContractRateLimiterDirect(&suite.Suite) + msg := CreateRateLimiterInitMessage(suite.chainA, "") + addr := suite.chainA.InstantiateContract(&suite.Suite, msg, 1) + suite.chainA.RegisterRateLimiterContract(&suite.Suite, addr) // Unset the contract param - s.chainA.RegisterRateLimiterContract(&s.Suite, []byte("")) - contractAddress := s.chainA.GetProvenanceApp().RateLimitingKeeper.GetContractAddress(s.chainA.GetContext()) - s.Assert().Equal("", contractAddress, "should unregister contract") + suite.chainA.RegisterRateLimiterContract(&suite.Suite, []byte("")) + contractAddress := suite.chainA.GetProvenanceApp().RateLimitingKeeper.GetContractAddress(suite.chainA.GetContext()) + suite.Assert().Equal("", contractAddress, "should unregister contract") } // FindEvent finds an event with a matching name. -func FindEvent(events []sdk.Event, name string) sdk.Event { - index := slices.IndexFunc(events, func(e sdk.Event) bool { return e.Type == name }) +func FindEvent(events []abci.Event, name string) abci.Event { + index := slices.IndexFunc(events, func(e abci.Event) bool { return e.Type == name }) if index == -1 { - return sdk.Event{} + return abci.Event{} } return events[index] } // ExtractAttributes returns the event's attributes in a map. -func ExtractAttributes(event sdk.Event) map[string]string { +func ExtractAttributes(event abci.Event) map[string]string { attrs := make(map[string]string) if event.Attributes == nil { return attrs @@ -558,7 +555,7 @@ func ExtractAttributes(event sdk.Event) map[string]string { return attrs } -// CreateRateLimiterInitMessage creates a contract init message for the rate limiter using the supplied quotas. +// CreateRateLimiterInitMessage creates a contract init message for the rate limiter using the supplied quotasuite. func CreateRateLimiterInitMessage(chain *testutil.TestChain, quotas string) string { provenanceApp := chain.GetProvenanceApp() transferModule := provenanceApp.AccountKeeper.GetModuleAddress(transfertypes.ModuleName) @@ -582,7 +579,7 @@ func CalculateChannelValue(ctx sdk.Context, denom string, bankKeeper bankkeeper. // https://github.com/cosmos/ibc-go/issues/2664 // For non-native (ibc) tokens, return the supply if the token in osmosis - //if strings.HasPrefix(denom, "ibc/") { + //if stringsuite.HasPrefix(denom, "ibc/") { // return bankKeeper.GetSupplyWithOffset(ctx, denom).Amount //} // @@ -590,7 +587,7 @@ func CalculateChannelValue(ctx sdk.Context, denom string, bankKeeper bankkeeper. //channels := channelKeeper.GetAllChannels(ctx) //balance := osmomath.NewInt(0) //for _, channel := range channels { - // escrowAddress := transfertypes.GetEscrowAddress("transfer", channel.ChannelId) + // escrowAddress := transfertypesuite.GetEscrowAddress("transfer", channel.ChannelId) // balance = balance.Add(bankKeeper.GetBalance(ctx, escrowAddress, denom).Amount) // //}