From 7fdb132d168495ef1d7a6f04b5bb0e0fc790d2d5 Mon Sep 17 00:00:00 2001 From: Markus Waas Date: Wed, 4 Jun 2025 18:13:45 +0200 Subject: [PATCH 1/5] chore: update to latest chain --- Cargo.lock | 517 +++++++----------- Cargo.toml | 14 +- build_release.sh | 10 +- contracts/swap/src/swap.rs | 5 +- ...egration_realistic_tests_exact_quantity.rs | 246 +++++---- ...ntegration_realistic_tests_min_quantity.rs | 195 ++++--- contracts/swap/src/testing/migration_test.rs | 14 +- contracts/swap/src/testing/test_utils.rs | 102 +++- 8 files changed, 568 insertions(+), 535 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0e021d7..ec8ffa4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -93,7 +93,7 @@ dependencies = [ "derivative", "digest 0.10.7", "itertools 0.10.5", - "num-bigint 0.4.6", + "num-bigint", "num-traits", "paste", "rayon", @@ -117,7 +117,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" dependencies = [ - "num-bigint 0.4.6", + "num-bigint", "num-traits", "proc-macro2", "quote", @@ -146,7 +146,7 @@ dependencies = [ "ark-serialize-derive", "ark-std", "digest 0.10.7", - "num-bigint 0.4.6", + "num-bigint", ] [[package]] @@ -173,13 +173,9 @@ dependencies = [ [[package]] name = "arrayvec" -version = "0.3.25" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06f59fe10306bb78facd90d28c2038ad23ffaaefa85bac43c8a434cde383334f" -dependencies = [ - "nodrop", - "odds", -] +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "async-trait" @@ -230,12 +226,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" -[[package]] -name = "base64" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" - [[package]] name = "base64" version = "0.21.7" @@ -299,6 +289,22 @@ dependencies = [ "zeroize", ] +[[package]] +name = "bitcoin-io" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b47c4ab7a93edb0c7198c5535ed9b52b63095f4e9b45279c6736cec4b856baf" + +[[package]] +name = "bitcoin_hashes" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" +dependencies = [ + "bitcoin-io", + "hex-conservative", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -362,7 +368,7 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" dependencies = [ - "serde 1.0.214", + "serde", ] [[package]] @@ -466,20 +472,19 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cosmos-sdk-proto" -version = "0.20.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32560304ab4c365791fd307282f76637213d8083c1a98490c35159cd67852237" +checksum = "e8ce7f4797cdf5cd18be6555ff3f0a8d37023c2d60f3b2708895d601b85c1c46" dependencies = [ - "prost 0.12.6", - "prost-types 0.12.6", - "tendermint-proto 0.34.1", + "prost", + "tendermint-proto", ] [[package]] name = "cosmrs" -version = "0.15.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47126f5364df9387b9d8559dcef62e99010e1d4098f39eb3f7ee4b5c254e40ea" +checksum = "09f90935b72d9fa65a2a784e09f25778637b7e88e9d6f87c717081470f7fa726" dependencies = [ "bip32", "cosmos-sdk-proto", @@ -487,8 +492,8 @@ dependencies = [ "eyre", "k256", "rand_core 0.6.4", - "serde 1.0.214", - "serde_json 1.0.132", + "serde", + "serde_json", "signature", "subtle-encoding", "tendermint", @@ -544,8 +549,8 @@ checksum = "f86b4d949b6041519c58993a73f4bbfba8083ba14f7001eae704865a09065845" dependencies = [ "cosmwasm-schema-derive", "schemars", - "serde 1.0.214", - "serde_json 1.0.132", + "serde", + "serde_json", "thiserror", ] @@ -576,7 +581,7 @@ dependencies = [ "hex", "rand_core 0.6.4", "schemars", - "serde 1.0.214", + "serde", "serde-json-wasm", "sha2 0.10.8", "static_assertions 1.1.0", @@ -698,9 +703,9 @@ dependencies = [ "cw-utils", "derivative", "itertools 0.13.0", - "prost 0.13.3", + "prost", "schemars", - "serde 1.0.214", + "serde", "sha2 0.10.8", "thiserror", ] @@ -713,7 +718,7 @@ checksum = "f13360e9007f51998d42b1bc6b7fa0141f74feae61ed5fd1e5b0a89eec7b5de1" dependencies = [ "cosmwasm-std", "schemars", - "serde 1.0.214", + "serde", ] [[package]] @@ -725,7 +730,7 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "schemars", - "serde 1.0.214", + "serde", "thiserror", ] @@ -740,7 +745,7 @@ dependencies = [ "cw-storage-plus", "schemars", "semver", - "serde 1.0.214", + "serde", "thiserror", ] @@ -1015,7 +1020,7 @@ dependencies = [ "ethbloom", "ethereum-types-serialize", "fixed-hash 0.3.2", - "serde 1.0.214", + "serde", "uint 0.5.0", ] @@ -1025,7 +1030,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1873d77b32bc1891a79dad925f2acbc318ee942b38b9110f9dbc5fbeffcea350" dependencies = [ - "serde 1.0.214", + "serde", ] [[package]] @@ -1168,12 +1173,6 @@ dependencies = [ "pin-utils", ] -[[package]] -name = "gcc" -version = "0.3.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" - [[package]] name = "generic-array" version = "0.14.7" @@ -1301,7 +1300,16 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" dependencies = [ - "serde 1.0.214", + "serde", +] + +[[package]] +name = "hex-conservative" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd" +dependencies = [ + "arrayvec", ] [[package]] @@ -1431,7 +1439,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58e3cae7e99c7ff5a995da2cf78dd0a5383740eda71d98cf7b1910c301ac69b8" dependencies = [ - "serde 1.0.214", + "serde", ] [[package]] @@ -1462,9 +1470,9 @@ dependencies = [ [[package]] name = "injective-cosmwasm" -version = "0.3.0" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e93e9438844b10add3eb40ed1e8c92689824ac080d207f856412a73551c221" +checksum = "7734038badc19fad9bead5584004313843a527c8ec902448e17de675d0b2a73a" dependencies = [ "cosmwasm-std", "cw-storage-plus", @@ -1472,7 +1480,7 @@ dependencies = [ "hex", "injective-math", "schemars", - "serde 1.0.214", + "serde", "serde_repr", "subtle-encoding", "tiny-keccak", @@ -1480,39 +1488,37 @@ dependencies = [ [[package]] name = "injective-math" -version = "0.3.0" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194fb5cb49537b0b9137d02a563b7019003220fb4affff05ad6cdc6fee3509c9" +checksum = "6acb63f2c2e4c8831b63b71a710f79da09981f8e6ff2b01975b87b12bc016fb5" dependencies = [ "cosmwasm-std", - "ethereum-types", "primitive-types", "schemars", - "serde 1.0.214", - "subtle-encoding", + "serde", ] [[package]] name = "injective-std" -version = "1.13.0" +version = "1.16.0-beta.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0e5193cb9520754f60b9e9af08a662ddf298d2e1a579200b9a447064b64db8b" +checksum = "05f8fe66be84f5660728856c6cfce222351bab86f3be29fb7043d1dd52cb0094" dependencies = [ "chrono", "cosmwasm-std", "injective-std-derive", - "prost 0.12.6", - "prost-types 0.12.6", + "prost", + "prost-types", "schemars", - "serde 1.0.214", + "serde", "serde-cw-value", ] [[package]] name = "injective-std-derive" -version = "1.13.0" +version = "1.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2721d8c2fed1fd1dff4cd6d119711a74acf27a6eeea6bf09cd44d192119e52ea" +checksum = "6cfe3fc8519277af8e09e51b8987435e401d345d4466402e6a5b991143fdfa53" dependencies = [ "cosmwasm-std", "itertools 0.10.5", @@ -1523,42 +1529,41 @@ dependencies = [ [[package]] name = "injective-test-tube" -version = "1.13.2" +version = "1.16.0-beta.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a45747c74fca8aedafd94df74c6b9edf091c586ead96957e3c17e96abd6228b" +checksum = "65f435f2d37b4166ac18426f0975d532e0f1abd6a216a5e3fbe449d05a7f8cf8" dependencies = [ - "base64 0.21.7", "bindgen", "cosmrs", "cosmwasm-std", - "hex", "injective-cosmwasm", "injective-std", - "prost 0.12.6", - "serde 1.0.214", - "serde_json 1.0.132", + "prost", + "serde", + "serde_json", "test-tube-inj", - "thiserror", ] [[package]] name = "injective-testing" -version = "1.1.2" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0012164e64110a7a630ab7352679b456c1b3fde71d641c2951c285c9ebe20daa" +checksum = "209600d76244fc6295d824b8ea40dd0c577b919a3afc2e231b970da57ea3ddf6" dependencies = [ "anyhow", - "base64 0.13.1", + "base64 0.21.7", "cosmwasm-std", "cw-multi-test", "injective-cosmwasm", "injective-math", "injective-std", "injective-test-tube", - "prost 0.12.6", + "prost", "rand 0.4.6", + "regex", "secp256k1", - "serde 1.0.214", + "serde", + "test-tube-inj", "tiny-keccak", ] @@ -1577,15 +1582,6 @@ 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 = "itertools" version = "0.13.0" @@ -1701,12 +1697,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "nodrop" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" - [[package]] name = "nom" version = "7.1.3" @@ -1717,32 +1707,6 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "num" -version = "0.1.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" -dependencies = [ - "num-bigint 0.1.44", - "num-complex", - "num-integer", - "num-iter", - "num-rational", - "num-traits", -] - -[[package]] -name = "num-bigint" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e63899ad0da84ce718c14936262a41cee2c79c981fc0a0e7c7beb47d5a07e8c1" -dependencies = [ - "num-integer", - "num-traits", - "rand 0.4.6", - "rustc-serialize", -] - [[package]] name = "num-bigint" version = "0.4.6" @@ -1753,33 +1717,12 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-complex" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b288631d7878aaf59442cffd36910ea604ecd7745c36054328595114001c9656" -dependencies = [ - "num-traits", - "rustc-serialize", -] - [[package]] name = "num-conv" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" -[[package]] -name = "num-derive" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "num-integer" version = "0.1.46" @@ -1789,29 +1732,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-iter" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-rational" -version = "0.1.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee314c74bd753fc86b4780aa9475da469155f3848473a261d2d18e35245a784e" -dependencies = [ - "num-bigint 0.1.44", - "num-integer", - "num-traits", - "rustc-serialize", -] - [[package]] name = "num-traits" version = "0.2.19" @@ -1830,12 +1750,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "odds" -version = "0.2.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eae0151b9dacf24fcc170d9995e511669a082856a91f958a2fe380bfab3fb22" - [[package]] name = "once_cell" version = "1.20.2" @@ -2004,65 +1918,19 @@ dependencies = [ [[package]] name = "prost" -version = "0.11.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" -dependencies = [ - "bytes", - "prost-derive 0.11.9", -] - -[[package]] -name = "prost" -version = "0.12.6" +version = "0.13.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deb1435c188b76130da55f17a466d252ff7b1418b2ad3e037d127b94e3411f29" +checksum = "2796faa41db3ec313a31f7624d9286acf277b52de526150b7e69f3debf891ee5" dependencies = [ "bytes", - "prost-derive 0.12.6", -] - -[[package]] -name = "prost" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0487d90e047de87f984913713b85c601c05609aad5b0df4b4573fbf69aa13f" -dependencies = [ - "bytes", - "prost-derive 0.13.3", + "prost-derive", ] [[package]] name = "prost-derive" -version = "0.11.9" +version = "0.13.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" -dependencies = [ - "anyhow", - "itertools 0.10.5", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "prost-derive" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" -dependencies = [ - "anyhow", - "itertools 0.12.1", - "proc-macro2", - "quote", - "syn 2.0.85", -] - -[[package]] -name = "prost-derive" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9552f850d5f0964a4e4d0bf306459ac29323ddfbae05e35a7c0d35cb0803cc5" +checksum = "8a56d757972c98b346a9b766e3f02746cde6dd1cd1d1d563472929fdd74bec4d" dependencies = [ "anyhow", "itertools 0.13.0", @@ -2073,20 +1941,11 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.11.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213622a1460818959ac1181aaeb2dc9c7f63df720db7d788b3e24eacd1983e13" -dependencies = [ - "prost 0.11.9", -] - -[[package]] -name = "prost-types" -version = "0.12.6" +version = "0.13.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9091c90b0a32608e984ff2fa4091273cbdd755d54935c51d520887f4a1dbd5b0" +checksum = "52c2c1bf36ddb1a1c396b3601a3cec27c2462e45f07c386894ec3ccf5332bd16" dependencies = [ - "prost 0.12.6", + "prost", ] [[package]] @@ -2098,16 +1957,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.3.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" -dependencies = [ - "libc", - "rand 0.4.6", -] - [[package]] name = "rand" version = "0.4.6" @@ -2263,8 +2112,8 @@ dependencies = [ "rustls", "rustls-native-certs", "rustls-pemfile", - "serde 1.0.214", - "serde_json 1.0.132", + "serde", + "serde_json", "serde_urlencoded", "sync_wrapper", "system-configuration", @@ -2339,12 +2188,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" -[[package]] -name = "rustc-serialize" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe834bc780604f4674073badbad26d7219cadfb4a2275802db12cbae17498401" - [[package]] name = "rustc_version" version = "0.4.1" @@ -2443,8 +2286,8 @@ dependencies = [ "dyn-clone", "enumset", "schemars_derive", - "serde 1.0.214", - "serde_json 1.0.132", + "serde", + "serde_json", ] [[package]] @@ -2485,17 +2328,22 @@ dependencies = [ [[package]] name = "secp256k1" -version = "0.6.3" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10915a2fa4f8016ed747eb847f096b0d44b22c6b624a36d3cc76964f6af4821a" +checksum = "b50c5943d326858130af85e049f2661ba3c78b26589b8ab98e65e80ae44a1252" dependencies = [ - "arrayvec", - "gcc", - "libc", - "rand 0.3.23", - "rustc-serialize", - "serde 0.6.15", - "serde_json 0.6.1", + "bitcoin_hashes", + "rand 0.8.5", + "secp256k1-sys", +] + +[[package]] +name = "secp256k1-sys" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4387882333d3aa8cb20530a17c69a3752e97837832f34f6dccc760e715001d9" +dependencies = [ + "cc", ] [[package]] @@ -2527,15 +2375,6 @@ version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" -[[package]] -name = "serde" -version = "0.6.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c97b18e9e53de541f11e497357d6c5eaeb39f0cb9c8734e274abe4935f6991fa" -dependencies = [ - "num", -] - [[package]] name = "serde" version = "1.0.214" @@ -2551,7 +2390,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75d32da6b8ed758b7d850b6c3c08f1d7df51a4df3cb201296e63e34a78e99d4" dependencies = [ - "serde 1.0.214", + "serde", ] [[package]] @@ -2560,7 +2399,7 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f05da0d153dd4595bdffd5099dc0e9ce425b205ee648eb93437ff7302af8c9a5" dependencies = [ - "serde 1.0.214", + "serde", ] [[package]] @@ -2569,7 +2408,7 @@ version = "0.11.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "387cc504cb06bb40a96c8e04e951fe01854cf6bc921053c954e4a606d9675c6a" dependencies = [ - "serde 1.0.214", + "serde", ] [[package]] @@ -2594,16 +2433,6 @@ dependencies = [ "syn 2.0.85", ] -[[package]] -name = "serde_json" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5aaee47e038bf9552d30380d3973fff2593ee0a76d81ad4c581f267cdcadf36" -dependencies = [ - "num", - "serde 0.6.15", -] - [[package]] name = "serde_json" version = "1.0.132" @@ -2613,7 +2442,7 @@ dependencies = [ "itoa", "memchr", "ryu", - "serde 1.0.214", + "serde", ] [[package]] @@ -2627,6 +2456,15 @@ dependencies = [ "syn 2.0.85", ] +[[package]] +name = "serde_spanned" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -2636,7 +2474,7 @@ dependencies = [ "form_urlencoded", "itoa", "ryu", - "serde 1.0.214", + "serde", ] [[package]] @@ -2767,9 +2605,9 @@ dependencies = [ "injective-std", "injective-test-tube", "injective-testing", - "prost 0.12.6", + "prost", "schemars", - "serde 1.0.214", + "serde", "serde-json-wasm", "test-tube-inj", "thiserror", @@ -2826,9 +2664,9 @@ dependencies = [ [[package]] name = "tendermint" -version = "0.34.1" +version = "0.39.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15ab8f0a25d0d2ad49ac615da054d6a76aa6603ff95f7d18bafdd34450a1a04b" +checksum = "2f3afea7809ffaaf1e5d9c3c9997cb3a834df7e94fbfab2fad2bc4577f1cde41" dependencies = [ "bytes", "digest 0.10.7", @@ -2839,31 +2677,30 @@ dependencies = [ "k256", "num-traits", "once_cell", - "prost 0.12.6", - "prost-types 0.12.6", + "prost", "ripemd", - "serde 1.0.214", + "serde", "serde_bytes", - "serde_json 1.0.132", + "serde_json", "serde_repr", "sha2 0.10.8", "signature", "subtle", "subtle-encoding", - "tendermint-proto 0.34.1", + "tendermint-proto", "time", "zeroize", ] [[package]] name = "tendermint-config" -version = "0.34.1" +version = "0.39.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1a02da769166e2052cd537b1a97c78017632c2d9e19266367b27e73910434fc" +checksum = "d8add7b85b0282e5901521f78fe441956ac1e2752452f4e1f2c0ce7e1f10d485" dependencies = [ "flex-error", - "serde 1.0.214", - "serde_json 1.0.132", + "serde", + "serde_json", "tendermint", "toml", "url", @@ -2871,35 +2708,14 @@ dependencies = [ [[package]] name = "tendermint-proto" -version = "0.32.2" +version = "0.39.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0cec054567d16d85e8c3f6a3139963d1a66d9d3051ed545d31562550e9bcc3d" +checksum = "bf3abf34ecf33125621519e9952688e7a59a98232d51538037ba21fbe526a802" dependencies = [ "bytes", "flex-error", - "num-derive", - "num-traits", - "prost 0.11.9", - "prost-types 0.11.9", - "serde 1.0.214", - "serde_bytes", - "subtle-encoding", - "time", -] - -[[package]] -name = "tendermint-proto" -version = "0.34.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b797dd3d2beaaee91d2f065e7bdf239dc8d80bba4a183a288bc1279dd5a69a1e" -dependencies = [ - "bytes", - "flex-error", - "num-derive", - "num-traits", - "prost 0.12.6", - "prost-types 0.12.6", - "serde 1.0.214", + "prost", + "serde", "serde_bytes", "subtle-encoding", "time", @@ -2907,9 +2723,9 @@ dependencies = [ [[package]] name = "tendermint-rpc" -version = "0.34.1" +version = "0.39.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71afae8bb5f6b14ed48d4e1316a643b6c2c3cbad114f510be77b4ed20b7b3e42" +checksum = "9693f42544bf3b41be3cbbfa418650c86e137fb8f5a57981659a84b677721ecf" dependencies = [ "async-trait", "bytes", @@ -2921,14 +2737,14 @@ dependencies = [ "rand 0.8.5", "reqwest", "semver", - "serde 1.0.214", + "serde", "serde_bytes", - "serde_json 1.0.132", + "serde_json", "subtle", "subtle-encoding", "tendermint", "tendermint-config", - "tendermint-proto 0.34.1", + "tendermint-proto", "thiserror", "time", "tokio", @@ -2949,17 +2765,15 @@ dependencies = [ [[package]] name = "test-tube-inj" -version = "2.0.1" +version = "2.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c3a4e34619e6417613fab682de9a196848f4a56653ac71b95b5860b6d87c7cd" +checksum = "53b48106d63f1b03d59ad5cd7d29386b22117da3e7f2eebd779ddcc3b0f6a9d1" dependencies = [ "base64 0.21.7", "cosmrs", "cosmwasm-std", - "prost 0.12.6", - "serde 1.0.214", - "serde_json 1.0.132", - "tendermint-proto 0.32.2", + "prost", + "serde_json", "thiserror", ] @@ -2998,7 +2812,7 @@ dependencies = [ "deranged", "num-conv", "powerfmt", - "serde 1.0.214", + "serde", "time-core", "time-macros", ] @@ -3095,13 +2909,45 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.11" +version = "0.8.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05ae329d1f08c4d17a59bed7ff5b5a769d062e64a62d34a3261b219e62cd5aae" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3da5db5a963e24bc68be8b17b6fa82814bb22ee8660f192bb182771d498f09a3" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +checksum = "310068873db2c5b3e7659d2cc35d21855dbafa50d1ce336397c666e3cb08137e" dependencies = [ - "serde 1.0.214", + "indexmap 2.6.0", + "serde", + "serde_spanned", + "toml_datetime", + "toml_write", + "winnow", ] +[[package]] +name = "toml_write" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfb942dfe1d8e29a7ee7fcbde5bd2b9a25fb89aa70caea2eba3bee836ff41076" + [[package]] name = "tower-service" version = "0.3.3" @@ -3512,6 +3358,15 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "winnow" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.50.0" diff --git a/Cargo.toml b/Cargo.toml index 363f194..569da3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,17 +11,17 @@ cosmwasm-std = { version = "2.1.0", features = [ "abort", "cosmwasm_1_2", cw-storage-plus = { version = "2.0.0" } cw-utils = { version = "2.0.0" } cw2 = { version = "2.0.0" } -injective-cosmwasm = { version = "=0.3.0" } -injective-math = { version = "0.3.0" } -injective-std = { version = "1.13.0" } -injective-test-tube = { version = "1.13.2" } -injective-testing = { version = "1.1.2" } -prost = { version = "0.12.6" } +injective-cosmwasm = { version = "0.3.3" } +injective-math = { version = "0.3.3" } +injective-std = { version = "1.16.0-beta.2" } +injective-test-tube = { version = "1.16.0-beta.2.1" } +injective-testing = { version = "1.1.9" } +prost = { version = "0.13.5" } schemars = { version = "0.8.16", features = [ "enumset" ] } serde = { version = "1.0.193", default-features = false, features = [ "derive" ] } serde-json-wasm = { version = "1.0.1" } serde_json = { version = "1.0.120" } -test-tube-inj = { version = "=2.0.1" } +test-tube-inj = { version = "2.0.6" } thiserror = { version = "1.0.52" } [profile.release] diff --git a/build_release.sh b/build_release.sh index 6d3a3dc..c91c33e 100755 --- a/build_release.sh +++ b/build_release.sh @@ -5,9 +5,7 @@ if [[ $(arch) = "arm64" ]]; then ARCH=-arm64 fi -for contract_dir in contracts/*; do - docker run --rm -v "$(pwd)":/code -v "$HOME/.cargo/git":/usr/local/cargo/git \ - --mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \ - --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ - cosmwasm/workspace-optimizer${ARCH}:0.15.0 "$contract_dir" -done \ No newline at end of file +docker run --rm -v "$(pwd)":/code -v "$HOME/.cargo/git":/usr/local/cargo/git \ + --mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \ + --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ + cosmwasm/workspace-optimizer${ARCH}:0.16.1 "./" diff --git a/contracts/swap/src/swap.rs b/contracts/swap/src/swap.rs index 89b9826..dc66891 100644 --- a/contracts/swap/src/swap.rs +++ b/contracts/swap/src/swap.rs @@ -260,9 +260,8 @@ pub fn handle_atomic_order_reply(deps: DepsMut, env: Env, pub fn parse_market_order_response(msg: Reply) -> StdResult { let binding = msg.result.into_result().map_err(ContractError::SubMsgFailure).unwrap(); - let first_messsage = binding.msg_responses.first(); - - let order_response = MsgCreateSpotMarketOrderResponse::decode(first_messsage.unwrap().value.as_slice()) + let first_message = binding.msg_responses.first(); + let order_response = MsgCreateSpotMarketOrderResponse::decode(first_message.unwrap().value.as_slice()) .map_err(|err| ContractError::ReplyParseFailure { id: msg.id, err: err.to_string(), diff --git a/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs b/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs index 60cf4c9..ad102aa 100644 --- a/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs +++ b/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs @@ -1,5 +1,9 @@ +use cosmwasm_std::Coin; use injective_math::FPDecimal; use injective_test_tube::{Account, Bank, Exchange, InjectiveTestApp, Module, Wasm}; +use injective_testing::test_tube::bank::send; +use injective_testing::test_tube::exchange::add_denom_notional_and_decimal; +use std::collections::HashMap; use std::ops::Neg; use crate::helpers::Scaled; @@ -10,10 +14,10 @@ use crate::testing::test_utils::{ create_realistic_atom_usdt_sell_orders_from_spreadsheet, create_realistic_eth_usdt_buy_orders_from_spreadsheet, create_realistic_eth_usdt_sell_orders_from_spreadsheet, create_realistic_inj_usdt_buy_orders_from_spreadsheet, create_realistic_inj_usdt_sell_orders_from_spreadsheet, create_realistic_limit_order, create_realistic_usdt_usdc_both_side_orders, human_to_dec, - init_rich_account, init_self_relaying_contract_and_get_address, launch_realistic_atom_usdt_spot_market, launch_realistic_inj_usdt_spot_market, - launch_realistic_ninja_inj_spot_market, launch_realistic_usdt_usdc_spot_market, launch_realistic_weth_usdt_spot_market, - must_init_account_with_funds, query_all_bank_balances, query_bank_balance, set_route_and_assert_success, str_coin, Decimals, OrderSide, ATOM, - ETH, INJ, INJ_2, NINJA, USDC, USDT, + init_rich_account, init_self_relaying_contract_and_get_address, initial_coin, launch_realistic_atom_usdt_spot_market, + launch_realistic_inj_usdt_spot_market, launch_realistic_ninja_inj_spot_market, launch_realistic_usdt_usdc_spot_market, + launch_realistic_weth_usdt_spot_market, must_init_account_with_funds_and_setting_denoms, query_all_bank_balances, query_bank_balance, + set_route_and_assert_success, str_coin, Decimals, OrderSide, ATOM, ETH, INJ, INJ_2, NINJA, USDC, USDT, }; use crate::types::{FPCoin, SwapEstimationResult}; @@ -67,16 +71,17 @@ fn it_correctly_swaps_eth_to_get_very_high_exact_amount_of_atom() { let exchange = Exchange::new(&app); let bank = Bank::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let _signer = must_init_account_with_funds_and_setting_denoms(&app, &validator, &[initial_coin("1", INJ, Decimals::Eighteen)]); - let _validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); - let owner = must_init_account_with_funds( + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("1", ETH, Decimals::Eighteen), + initial_coin("1", ATOM, Decimals::Six), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), ], ); @@ -125,9 +130,13 @@ fn it_correctly_swaps_eth_to_get_very_high_exact_amount_of_atom() { let eth_to_swap = "4.4"; - let swapper = must_init_account_with_funds( + let swapper = must_init_account_with_funds_and_setting_denoms( &app, - &[str_coin(eth_to_swap, ETH, Decimals::Eighteen), str_coin("1", INJ, Decimals::Eighteen)], + &validator, + &[ + initial_coin(eth_to_swap, ETH, Decimals::Eighteen), + initial_coin("1", INJ, Decimals::Eighteen), + ], ); let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); @@ -235,17 +244,18 @@ fn it_correctly_swaps_inj_to_get_very_high_exact_amount_of_atom() { let exchange = Exchange::new(&app); let bank = Bank::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let _signer = must_init_account_with_funds_and_setting_denoms(&app, &validator, &[initial_coin("1", INJ, Decimals::Eighteen)]); - let _validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); - let owner = must_init_account_with_funds( + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("10_000", INJ_2, Decimals::Eighteen), + initial_coin("1", ETH, Decimals::Eighteen), + initial_coin("1", ATOM, Decimals::Six), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("10_000", INJ_2, Decimals::Eighteen), ], ); @@ -294,9 +304,13 @@ fn it_correctly_swaps_inj_to_get_very_high_exact_amount_of_atom() { let inj_to_swap = "1100.1"; - let swapper = must_init_account_with_funds( + let swapper = must_init_account_with_funds_and_setting_denoms( &app, - &[str_coin(inj_to_swap, INJ_2, Decimals::Eighteen), str_coin("1", INJ, Decimals::Eighteen)], + &validator, + &[ + initial_coin(inj_to_swap, INJ_2, Decimals::Eighteen), + initial_coin("1", INJ, Decimals::Eighteen), + ], ); let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); @@ -401,16 +415,17 @@ fn it_swaps_inj_to_get_very_high_exact_amount_of_eth() { let exchange = Exchange::new(&app); let bank = Bank::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let _signer = must_init_account_with_funds_and_setting_denoms(&app, &validator, &[initial_coin("1", INJ, Decimals::Eighteen)]); - let _validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); - let owner = must_init_account_with_funds( + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("10_000", INJ_2, Decimals::Eighteen), + initial_coin("1", ETH, Decimals::Eighteen), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("10_000", INJ_2, Decimals::Eighteen), ], ); @@ -459,9 +474,13 @@ fn it_swaps_inj_to_get_very_high_exact_amount_of_eth() { let inj_to_swap = "2855.259"; let exact_quantity_to_receive = human_to_dec("11.2", Decimals::Eighteen); - let swapper = must_init_account_with_funds( + let swapper = must_init_account_with_funds_and_setting_denoms( &app, - &[str_coin(inj_to_swap, INJ_2, Decimals::Eighteen), str_coin("1", INJ, Decimals::Eighteen)], + &validator, + &[ + initial_coin(inj_to_swap, INJ_2, Decimals::Eighteen), + initial_coin("1", INJ, Decimals::Eighteen), + ], ); let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); @@ -544,16 +563,17 @@ fn it_correctly_swaps_between_markets_using_different_quote_assets_self_relaying let exchange = Exchange::new(&app); let bank = Bank::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - let _validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let _signer = must_init_account_with_funds_and_setting_denoms(&app, &validator, &[initial_coin("1", INJ, Decimals::Eighteen)]); - let owner = must_init_account_with_funds( + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1_000", USDT, Decimals::Six), - str_coin("1_000", USDC, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("1", INJ_2, Decimals::Eighteen), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("1_000", USDC, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("1", INJ_2, Decimals::Eighteen), ], ); @@ -582,7 +602,11 @@ fn it_correctly_swaps_between_markets_using_different_quote_assets_self_relaying app.increase_time(1); - let swapper = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen), str_coin("1", INJ_2, Decimals::Eighteen)]); + let swapper = must_init_account_with_funds_and_setting_denoms( + &app, + &validator, + &[initial_coin("1", INJ, Decimals::Eighteen), initial_coin("1", INJ_2, Decimals::Eighteen)], + ); let inj_to_swap = "1"; let to_output_quantity = human_to_dec("8", Decimals::Six); @@ -708,17 +732,18 @@ fn it_correctly_swaps_between_markets_using_different_quote_assets_self_relaying let exchange = Exchange::new(&app); let bank = Bank::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - let _validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let _signer = must_init_account_with_funds_and_setting_denoms(&app, &validator, &[initial_coin("1", INJ, Decimals::Eighteen)]); - let owner = must_init_account_with_funds( + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1_000", USDT, Decimals::Six), - str_coin("1_000", USDC, Decimals::Six), - str_coin("1_000", NINJA, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("101", INJ_2, Decimals::Eighteen), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("1_000", USDC, Decimals::Six), + initial_coin("1_000", NINJA, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("101", INJ_2, Decimals::Eighteen), ], ); @@ -750,7 +775,11 @@ fn it_correctly_swaps_between_markets_using_different_quote_assets_self_relaying app.increase_time(1); - let swapper = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen), str_coin("100000", USDT, Decimals::Six)]); + let swapper = must_init_account_with_funds_and_setting_denoms( + &app, + &validator, + &[initial_coin("1", INJ, Decimals::Eighteen), initial_coin("100000", USDT, Decimals::Six)], + ); let usdt_to_swap = "100000"; let to_output_quantity = human_to_dec("501000", Decimals::Six); @@ -799,17 +828,17 @@ fn it_doesnt_lose_buffer_if_exact_swap_of_eth_to_atom_is_executed_multiple_times let exchange = Exchange::new(&app); let bank = Bank::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let _signer = must_init_account_with_funds_and_setting_denoms(&app, &validator, &[initial_coin("1", INJ, Decimals::Eighteen)]); - let _validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); - - let owner = must_init_account_with_funds( + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("1", ETH, Decimals::Eighteen), + initial_coin("1", ATOM, Decimals::Six), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), ], ); @@ -834,15 +863,16 @@ fn it_doesnt_lose_buffer_if_exact_swap_of_eth_to_atom_is_executed_multiple_times let eth_to_swap = "4.08"; let iterations = 100i128; - let swapper = must_init_account_with_funds( + let swapper = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin( + initial_coin( (FPDecimal::must_from_str(eth_to_swap) * FPDecimal::from(iterations)).to_string().as_str(), ETH, Decimals::Eighteen, ), - str_coin("1", INJ, Decimals::Eighteen), + initial_coin("1", INJ, Decimals::Eighteen), ], ); @@ -902,17 +932,18 @@ fn it_reverts_when_funds_provided_are_below_required_to_get_exact_amount() { let exchange = Exchange::new(&app); let bank = Bank::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let _signer = must_init_account_with_funds_and_setting_denoms(&app, &validator, &[initial_coin("1", INJ, Decimals::Eighteen)]); - let _validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); - let owner = must_init_account_with_funds( + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("10_000", INJ_2, Decimals::Eighteen), + initial_coin("1", ETH, Decimals::Eighteen), + initial_coin("1", ATOM, Decimals::Six), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("10_000", INJ_2, Decimals::Eighteen), ], ); @@ -940,9 +971,13 @@ fn it_reverts_when_funds_provided_are_below_required_to_get_exact_amount() { let inj_to_swap = "608"; - let swapper = must_init_account_with_funds( + let swapper = must_init_account_with_funds_and_setting_denoms( &app, - &[str_coin(inj_to_swap, INJ_2, Decimals::Eighteen), str_coin("1", INJ, Decimals::Eighteen)], + &validator, + &[ + initial_coin(inj_to_swap, INJ_2, Decimals::Eighteen), + initial_coin("1", INJ, Decimals::Eighteen), + ], ); let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); @@ -1009,16 +1044,17 @@ fn exact_two_hop_eth_atom_swap_test_template(exact_quantity_to_receive: FPDecima let exchange = Exchange::new(&app); let bank = Bank::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let _signer = must_init_account_with_funds_and_setting_denoms(&app, &validator, &[initial_coin("1", INJ, Decimals::Eighteen)]); - let _validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); - let owner = must_init_account_with_funds( + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("1", ETH, Decimals::Eighteen), + initial_coin("1", ATOM, Decimals::Six), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), ], ); @@ -1046,9 +1082,13 @@ fn exact_two_hop_eth_atom_swap_test_template(exact_quantity_to_receive: FPDecima let eth_to_swap = "4.08"; - let swapper = must_init_account_with_funds( + let swapper = must_init_account_with_funds_and_setting_denoms( &app, - &[str_coin(eth_to_swap, ETH, Decimals::Eighteen), str_coin("1", INJ, Decimals::Eighteen)], + &validator, + &[ + initial_coin(eth_to_swap, ETH, Decimals::Eighteen), + initial_coin("1", INJ, Decimals::Eighteen), + ], ); let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); @@ -1130,17 +1170,18 @@ fn exact_two_hop_inj_atom_swap_test_template(exact_quantity_to_receive: FPDecima let exchange = Exchange::new(&app); let bank = Bank::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let _signer = must_init_account_with_funds_and_setting_denoms(&app, &validator, &[initial_coin("1", INJ, Decimals::Eighteen)]); - let _validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); - let owner = must_init_account_with_funds( + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("10_000", INJ_2, Decimals::Eighteen), + initial_coin("1", ETH, Decimals::Eighteen), + initial_coin("1", ATOM, Decimals::Six), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("10_000", INJ_2, Decimals::Eighteen), ], ); @@ -1168,9 +1209,13 @@ fn exact_two_hop_inj_atom_swap_test_template(exact_quantity_to_receive: FPDecima let inj_to_swap = "973.258"; - let swapper = must_init_account_with_funds( + let swapper = must_init_account_with_funds_and_setting_denoms( &app, - &[str_coin(inj_to_swap, INJ_2, Decimals::Eighteen), str_coin("1", INJ, Decimals::Eighteen)], + &validator, + &[ + initial_coin(inj_to_swap, INJ_2, Decimals::Eighteen), + initial_coin("1", INJ, Decimals::Eighteen), + ], ); let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); @@ -1252,16 +1297,17 @@ fn exact_two_hop_inj_eth_swap_test_template(exact_quantity_to_receive: FPDecimal let exchange = Exchange::new(&app); let bank = Bank::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let _signer = must_init_account_with_funds_and_setting_denoms(&app, &validator, &[initial_coin("1", INJ, Decimals::Eighteen)]); - let _validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); - let owner = must_init_account_with_funds( + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("10_000", INJ_2, Decimals::Eighteen), + initial_coin("1", ETH, Decimals::Eighteen), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("10_000", INJ_2, Decimals::Eighteen), ], ); @@ -1289,9 +1335,13 @@ fn exact_two_hop_inj_eth_swap_test_template(exact_quantity_to_receive: FPDecimal let inj_to_swap = "973.258"; - let swapper = must_init_account_with_funds( + let swapper = must_init_account_with_funds_and_setting_denoms( &app, - &[str_coin(inj_to_swap, INJ_2, Decimals::Eighteen), str_coin("1", INJ, Decimals::Eighteen)], + &validator, + &[ + initial_coin(inj_to_swap, INJ_2, Decimals::Eighteen), + initial_coin("1", INJ, Decimals::Eighteen), + ], ); let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); diff --git a/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs b/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs index 3e2e961..d46aab9 100644 --- a/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs +++ b/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs @@ -9,10 +9,10 @@ use crate::testing::test_utils::{ are_fpdecimals_approximately_equal, assert_fee_is_as_expected, create_realistic_atom_usdt_sell_orders_from_spreadsheet, create_realistic_eth_usdt_buy_orders_from_spreadsheet, create_realistic_eth_usdt_sell_orders_from_spreadsheet, create_realistic_inj_usdt_buy_orders_from_spreadsheet, create_realistic_usdt_usdc_both_side_orders, human_to_dec, init_rich_account, - init_self_relaying_contract_and_get_address, launch_realistic_atom_usdt_spot_market, launch_realistic_inj_usdt_spot_market, - launch_realistic_usdt_usdc_spot_market, launch_realistic_weth_usdt_spot_market, must_init_account_with_funds, query_all_bank_balances, - query_bank_balance, set_route_and_assert_success, str_coin, Decimals, ATOM, DEFAULT_ATOMIC_MULTIPLIER, DEFAULT_SELF_RELAYING_FEE_PART, - DEFAULT_TAKER_FEE, ETH, INJ, INJ_2, USDC, USDT, + init_self_relaying_contract_and_get_address, initial_coin, launch_realistic_atom_usdt_spot_market, launch_realistic_inj_usdt_spot_market, + launch_realistic_usdt_usdc_spot_market, launch_realistic_weth_usdt_spot_market, must_init_account_with_funds_and_setting_denoms, + query_all_bank_balances, query_bank_balance, set_route_and_assert_success, str_coin, Decimals, ATOM, DEFAULT_ATOMIC_MULTIPLIER, + DEFAULT_SELF_RELAYING_FEE_PART, DEFAULT_TAKER_FEE, ETH, INJ, INJ_2, USDC, USDT, }; use crate::types::{FPCoin, SwapEstimationResult}; @@ -38,6 +38,8 @@ pub fn happy_path_two_hops_test(app: InjectiveTestApp, owner: SigningAccount, co let spot_market_1_id = launch_realistic_weth_usdt_spot_market(&exchange, &owner); let spot_market_2_id = launch_realistic_atom_usdt_spot_market(&exchange, &owner); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + set_route_and_assert_success( &wasm, &owner, @@ -58,9 +60,13 @@ pub fn happy_path_two_hops_test(app: InjectiveTestApp, owner: SigningAccount, co let eth_to_swap = "4.08"; - let swapper = must_init_account_with_funds( + let swapper = must_init_account_with_funds_and_setting_denoms( &app, - &[str_coin(eth_to_swap, ETH, Decimals::Eighteen), str_coin("1", INJ, Decimals::Eighteen)], + &validator, + &[ + initial_coin(eth_to_swap, ETH, Decimals::Eighteen), + initial_coin("1", INJ, Decimals::Eighteen), + ], ); let mut query_result: SwapEstimationResult = wasm @@ -162,16 +168,18 @@ fn happy_path_two_hops_swap_eth_atom_realistic_values_self_relaying() { let app = InjectiveTestApp::new(); let wasm = Wasm::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); - let _validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); - let owner = must_init_account_with_funds( + let _signer = must_init_account_with_funds_and_setting_denoms(&app, &validator, &[initial_coin("1", INJ, Decimals::Eighteen)]); + + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("1", ETH, Decimals::Eighteen), + initial_coin("1", ATOM, Decimals::Six), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), ], ); @@ -187,16 +195,17 @@ fn happy_path_two_hops_swap_inj_eth_realistic_values_self_relaying() { let exchange = Exchange::new(&app); let bank = Bank::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let _signer = must_init_account_with_funds_and_setting_denoms(&app, &validator, &[initial_coin("1", INJ, Decimals::Eighteen)]); - let _validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); - let owner = must_init_account_with_funds( + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("1", INJ_2, Decimals::Eighteen), + initial_coin("1", ETH, Decimals::Eighteen), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("1", INJ_2, Decimals::Eighteen), ], ); @@ -224,9 +233,13 @@ fn happy_path_two_hops_swap_inj_eth_realistic_values_self_relaying() { let inj_to_swap = "973.258"; - let swapper = must_init_account_with_funds( + let swapper = must_init_account_with_funds_and_setting_denoms( &app, - &[str_coin(inj_to_swap, INJ_2, Decimals::Eighteen), str_coin("1", INJ, Decimals::Eighteen)], + &validator, + &[ + initial_coin(inj_to_swap, INJ_2, Decimals::Eighteen), + initial_coin("1", INJ, Decimals::Eighteen), + ], ); let mut query_result: SwapEstimationResult = wasm @@ -330,17 +343,18 @@ fn happy_path_two_hops_swap_inj_atom_realistic_values_self_relaying() { let exchange = Exchange::new(&app); let bank = Bank::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let _signer = must_init_account_with_funds_and_setting_denoms(&app, &validator, &[initial_coin("1", INJ, Decimals::Eighteen)]); - let _validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); - let owner = must_init_account_with_funds( + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("1", INJ_2, Decimals::Eighteen), + initial_coin("1", ETH, Decimals::Eighteen), + initial_coin("1", ATOM, Decimals::Six), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("1", INJ_2, Decimals::Eighteen), ], ); @@ -368,9 +382,13 @@ fn happy_path_two_hops_swap_inj_atom_realistic_values_self_relaying() { let inj_to_swap = "973.258"; - let swapper = must_init_account_with_funds( + let swapper = must_init_account_with_funds_and_setting_denoms( &app, - &[str_coin(inj_to_swap, INJ_2, Decimals::Eighteen), str_coin("1", INJ, Decimals::Eighteen)], + &validator, + &[ + initial_coin(inj_to_swap, INJ_2, Decimals::Eighteen), + initial_coin("1", INJ, Decimals::Eighteen), + ], ); let mut query_result: SwapEstimationResult = wasm @@ -474,16 +492,17 @@ fn it_executes_swap_between_markets_using_different_quote_assets_self_relaying() let exchange = Exchange::new(&app); let bank = Bank::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - let _validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let _signer = must_init_account_with_funds_and_setting_denoms(&app, &validator, &[initial_coin("1", INJ, Decimals::Eighteen)]); - let owner = must_init_account_with_funds( + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1_000", USDT, Decimals::Six), - str_coin("1_000", USDC, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("1", INJ_2, Decimals::Eighteen), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("1_000", USDC, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("1", INJ_2, Decimals::Eighteen), ], ); @@ -512,7 +531,11 @@ fn it_executes_swap_between_markets_using_different_quote_assets_self_relaying() app.increase_time(1); - let swapper = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen), str_coin("1", INJ_2, Decimals::Eighteen)]); + let swapper = must_init_account_with_funds_and_setting_denoms( + &app, + &validator, + &[initial_coin("1", INJ, Decimals::Eighteen), initial_coin("1", INJ_2, Decimals::Eighteen)], + ); let inj_to_swap = "1"; @@ -640,17 +663,17 @@ fn it_doesnt_lose_buffer_if_executed_multiple_times() { let exchange = Exchange::new(&app); let bank = Bank::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - - let _validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let _signer = must_init_account_with_funds_and_setting_denoms(&app, &validator, &[initial_coin("1", INJ, Decimals::Eighteen)]); - let owner = must_init_account_with_funds( + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("1", ETH, Decimals::Eighteen), + initial_coin("1", ATOM, Decimals::Six), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), ], ); @@ -674,15 +697,16 @@ fn it_doesnt_lose_buffer_if_executed_multiple_times() { let eth_to_swap = "4.08"; - let swapper = must_init_account_with_funds( + let swapper = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin( + initial_coin( (FPDecimal::must_from_str(eth_to_swap) * FPDecimal::from(100u128)).to_string().as_str(), ETH, Decimals::Eighteen, ), - str_coin("1", INJ, Decimals::Eighteen), + initial_coin("1", INJ, Decimals::Eighteen), ], ); @@ -754,16 +778,17 @@ fn it_correctly_calculates_required_funds_when_querying_buy_with_minimum_buffer_ let exchange = Exchange::new(&app); let bank = Bank::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let _signer = must_init_account_with_funds_and_setting_denoms(&app, &validator, &[initial_coin("1", INJ, Decimals::Eighteen)]); - let _validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); - let owner = must_init_account_with_funds( + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("1", ETH, Decimals::Eighteen), + initial_coin("1", ATOM, Decimals::Six), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), ], ); @@ -791,9 +816,13 @@ fn it_correctly_calculates_required_funds_when_querying_buy_with_minimum_buffer_ let eth_to_swap = "4.08"; - let swapper = must_init_account_with_funds( + let swapper = must_init_account_with_funds_and_setting_denoms( &app, - &[str_coin(eth_to_swap, ETH, Decimals::Eighteen), str_coin("1", INJ, Decimals::Eighteen)], + &validator, + &[ + initial_coin(eth_to_swap, ETH, Decimals::Eighteen), + initial_coin("1", INJ, Decimals::Eighteen), + ], ); let query_result: FPDecimal = wasm @@ -877,16 +906,17 @@ fn it_correctly_calculates_required_funds_when_executing_buy_with_minimum_buffer let exchange = Exchange::new(&app); let bank = Bank::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + let _signer = must_init_account_with_funds_and_setting_denoms(&app, &validator, &[initial_coin("1", INJ, Decimals::Eighteen)]); - let _validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); - let owner = must_init_account_with_funds( + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("1", ETH, Decimals::Eighteen), + initial_coin("1", ATOM, Decimals::Six), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), ], ); @@ -915,9 +945,13 @@ fn it_correctly_calculates_required_funds_when_executing_buy_with_minimum_buffer let eth_to_swap = "4.08"; - let swapper = must_init_account_with_funds( + let swapper = must_init_account_with_funds_and_setting_denoms( &app, - &[str_coin(eth_to_swap, ETH, Decimals::Eighteen), str_coin("0.01", INJ, Decimals::Eighteen)], + &validator, + &[ + initial_coin(eth_to_swap, ETH, Decimals::Eighteen), + initial_coin("0.01", INJ, Decimals::Eighteen), + ], ); let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); @@ -975,16 +1009,17 @@ fn it_returns_all_funds_if_there_is_not_enough_buffer_realistic_values() { let exchange = Exchange::new(&app); let bank = Bank::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); - let _validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); - let owner = must_init_account_with_funds( + let _signer = must_init_account_with_funds_and_setting_denoms(&app, &validator, &[initial_coin("1", INJ, Decimals::Eighteen)]); + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("1", ETH, Decimals::Eighteen), + initial_coin("1", ATOM, Decimals::Six), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), ], ); @@ -1013,9 +1048,13 @@ fn it_returns_all_funds_if_there_is_not_enough_buffer_realistic_values() { let eth_to_swap = "4.08"; - let swapper = must_init_account_with_funds( + let swapper = must_init_account_with_funds_and_setting_denoms( &app, - &[str_coin(eth_to_swap, ETH, Decimals::Eighteen), str_coin("1", INJ, Decimals::Eighteen)], + &validator, + &[ + initial_coin(eth_to_swap, ETH, Decimals::Eighteen), + initial_coin("1", INJ, Decimals::Eighteen), + ], ); let query_result: RunnerResult = wasm.query( diff --git a/contracts/swap/src/testing/migration_test.rs b/contracts/swap/src/testing/migration_test.rs index bf9370d..07177bc 100644 --- a/contracts/swap/src/testing/migration_test.rs +++ b/contracts/swap/src/testing/migration_test.rs @@ -2,7 +2,7 @@ use crate::{ msg::{FeeRecipient, InstantiateMsg, MigrateMsg}, testing::{ integration_realistic_tests_min_quantity::happy_path_two_hops_test, - test_utils::{must_init_account_with_funds, str_coin, Decimals, ATOM, ETH, INJ, USDT}, + test_utils::{initial_coin, must_init_account_with_funds_and_setting_denoms, str_coin, Decimals, ATOM, ETH, INJ, USDT}, }, }; @@ -20,14 +20,16 @@ fn test_migration() { let wasm = Wasm::new(&app); let wasm_byte_code = std::fs::read("../../contracts/swap/src/testing/test_artifacts/swap-contract-v101.wasm").unwrap(); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); - let owner = must_init_account_with_funds( + let owner = must_init_account_with_funds_and_setting_denoms( &app, + &validator, &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), + initial_coin("1", ETH, Decimals::Eighteen), + initial_coin("1", ATOM, Decimals::Six), + initial_coin("1_000", USDT, Decimals::Six), + initial_coin("10_000", INJ, Decimals::Eighteen), ], ); diff --git a/contracts/swap/src/testing/test_utils.rs b/contracts/swap/src/testing/test_utils.rs index 85c8ca5..e644c5a 100644 --- a/contracts/swap/src/testing/test_utils.rs +++ b/contracts/swap/src/testing/test_utils.rs @@ -1,13 +1,14 @@ use crate::helpers::Scaled; use cosmwasm_std::testing::{MockApi, MockStorage}; -use cosmwasm_std::{coin, to_json_binary, Addr, Coin, ContractResult, OwnedDeps, QuerierResult, SystemError, SystemResult}; +use cosmwasm_std::{coin, to_json_binary, Addr, Coin, ContractResult, OwnedDeps, QuerierResult, SystemError, SystemResult, Uint128}; use injective_cosmwasm::{ create_orderbook_response_handler, create_spot_multi_market_handler, get_default_subaccount_id_for_checked_address, inj_mock_deps, test_market_ids, HandlesMarketIdQuery, InjectiveQueryWrapper, MarketId, PriceLevel, QueryMarketAtomicExecutionFeeMultiplierResponse, SpotMarket, WasmMockQuerier, TEST_MARKET_ID_1, TEST_MARKET_ID_2, }; use injective_math::FPDecimal; +use injective_std::types::injective::exchange::v1beta1::MsgInstantSpotMarketLaunch; use injective_std::{ shim::{Any, Timestamp}, types::{ @@ -20,12 +21,12 @@ use injective_std::{ }, }; use injective_test_tube::{Account, Authz, Bank, Exchange, InjectiveTestApp, Module, SigningAccount, Wasm}; -use injective_testing::{ - test_tube::{exchange::launch_spot_market_custom, utils::store_code}, - utils::scale_price_quantity_spot_market, -}; -use prost::Message; +use injective_testing::test_tube::bank::send; +use injective_testing::test_tube::exchange::{add_denom_notional_and_decimal, get_spot_market_id}; +use injective_testing::utils::dec_to_proto; +use injective_testing::{test_tube::utils::store_code, utils::scale_price_quantity_spot_market}; use std::{collections::HashMap, str::FromStr}; +use test_tube_inj::cosmrs::proto::prost::Message; use crate::{ msg::{ExecuteMsg, FeeRecipient, InstantiateMsg}, @@ -47,6 +48,37 @@ pub const DEFAULT_TAKER_FEE: f64 = 0.001; pub const DEFAULT_ATOMIC_MULTIPLIER: f64 = 2.5; pub const DEFAULT_SELF_RELAYING_FEE_PART: f64 = 0.6; +pub fn launch_spot_market_custom( + exchange: &Exchange, + signer: &SigningAccount, + ticker: String, + base_denom: String, + quote_denom: String, + min_price_tick_size: String, + min_quantity_tick_size: String, + base_decimals: i32, + quote_decimals: i32, +) -> String { + exchange + .instant_spot_market_launch( + MsgInstantSpotMarketLaunch { + sender: signer.address(), + ticker: ticker.clone(), + base_denom, + quote_denom, + min_price_tick_size: dec_to_proto(FPDecimal::must_from_str(&min_price_tick_size)), + min_quantity_tick_size: dec_to_proto(FPDecimal::must_from_str(&min_quantity_tick_size)), + min_notional: dec_to_proto(FPDecimal::must_from_str("1")), + base_decimals: base_decimals as u32, + quote_decimals: quote_decimals as u32, + }, + signer, + ) + .unwrap(); + + get_spot_market_id(exchange, ticker) +} + #[derive(PartialEq, Eq, Debug, Copy, Clone)] #[repr(i32)] pub enum Decimals { @@ -272,6 +304,7 @@ fn create_mock_spot_market(base: &str, min_price_tick_size: FPDecimal, min_quant status: injective_cosmwasm::MarketStatus::Active, min_price_tick_size, min_quantity_tick_size, + min_notional: FPDecimal::from_str("0.000000001").unwrap(), } } @@ -284,6 +317,8 @@ pub fn launch_realistic_inj_usdt_spot_market(exchange: &Exchange SigningAccount { app.init_account(initial_funds).unwrap() } +pub fn must_init_account_with_funds_and_setting_denoms( + app: &InjectiveTestApp, + validator: &SigningAccount, + initial_funds: &[InitialCoin], +) -> SigningAccount { + let mut initial_funds_coin: Vec = initial_funds + .iter() + .map(|ic| coin(ic.coin.amount.into(), ic.coin.denom.clone())) + .collect(); + let mut initial_funds_decimals = initial_funds.iter().map(|ic| ic.decimals).collect::>(); + + // add 1000000000000000000000 inj to initial funds with adding to element if inj already in it + if let Some(pos) = initial_funds_coin.iter().position(|c| c.denom == INJ) { + initial_funds_coin[pos].amount += Uint128::from(1_000_000_000_000_000_000_000u128); + } else { + initial_funds_coin.push(coin(1_000_000_000_000_000_000_000u128, INJ.to_string())); + initial_funds_decimals.push(18); + } + + let account = app.init_account_decimals(&initial_funds_coin, &initial_funds_decimals).unwrap(); + send(&Bank::new(app), "1000000000000000000000", "inj", &account, validator); + + for initial_coin in initial_funds { + add_denom_notional_and_decimal( + app, + validator, + initial_coin.coin.denom.to_string(), + "1".to_string(), + initial_coin.decimals as u64, + ); + } + + account +} + pub fn query_all_bank_balances(bank: &Bank, address: &str) -> Vec { bank.query_all_balances(&QueryAllBalancesRequest { address: address.to_string(), @@ -724,6 +807,13 @@ pub fn str_coin(human_amount: &str, denom: &str, decimals: Decimals) -> Coin { coin(as_int, denom) } +pub fn initial_coin(human_amount: &str, denom: &str, decimals: Decimals) -> InitialCoin { + InitialCoin { + coin: str_coin(human_amount, denom, decimals), + decimals: decimals.get_decimals() as u32, + } +} + mod tests { use crate::testing::test_utils::{human_to_dec, human_to_proto, scale_price_quantity_spot_market, Decimals}; use injective_math::FPDecimal; From 8000847b33ac4f8b21560933fc2ac4c98656a784 Mon Sep 17 00:00:00 2001 From: Markus Waas Date: Fri, 13 Jun 2025 11:01:47 +0200 Subject: [PATCH 2/5] chore: use latest test-tube --- Cargo.lock | 10 ++++------ Cargo.toml | 4 ++-- contracts/swap/src/testing/authz_tests.rs | 11 ++++++++++- .../integration_realistic_tests_exact_quantity.rs | 4 ---- contracts/swap/src/testing/test_utils.rs | 1 + 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ec8ffa4..e79fa32 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1529,9 +1529,9 @@ dependencies = [ [[package]] name = "injective-test-tube" -version = "1.16.0-beta.2.1" +version = "1.16.0-beta.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65f435f2d37b4166ac18426f0975d532e0f1abd6a216a5e3fbe449d05a7f8cf8" +checksum = "643bd3780018d0c26d0f1a6efb623e94578e3ede1e59984e131be34d761571b9" dependencies = [ "bindgen", "cosmrs", @@ -1546,12 +1546,11 @@ dependencies = [ [[package]] name = "injective-testing" -version = "1.1.9" +version = "1.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "209600d76244fc6295d824b8ea40dd0c577b919a3afc2e231b970da57ea3ddf6" +checksum = "8c55058dfa8a8c7c99cda659a7b746c7cc13a906ed1a7b4efe63c07045284994" dependencies = [ "anyhow", - "base64 0.21.7", "cosmwasm-std", "cw-multi-test", "injective-cosmwasm", @@ -1563,7 +1562,6 @@ dependencies = [ "regex", "secp256k1", "serde", - "test-tube-inj", "tiny-keccak", ] diff --git a/Cargo.toml b/Cargo.toml index 569da3e..f45ca1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,8 @@ cw2 = { version = "2.0.0" } injective-cosmwasm = { version = "0.3.3" } injective-math = { version = "0.3.3" } injective-std = { version = "1.16.0-beta.2" } -injective-test-tube = { version = "1.16.0-beta.2.1" } -injective-testing = { version = "1.1.9" } +injective-test-tube = { version = "1.16.0-beta.3" } +injective-testing = { version = "1.1.11" } prost = { version = "0.13.5" } schemars = { version = "0.8.16", features = [ "enumset" ] } serde = { version = "1.0.193", default-features = false, features = [ "derive" ] } diff --git a/contracts/swap/src/testing/authz_tests.rs b/contracts/swap/src/testing/authz_tests.rs index 680a57c..0316470 100644 --- a/contracts/swap/src/testing/authz_tests.rs +++ b/contracts/swap/src/testing/authz_tests.rs @@ -12,7 +12,9 @@ use injective_std::{ shim::Any, types::{cosmos::authz::v1beta1::MsgExec, cosmwasm::wasm::v1::MsgExecuteContract}, }; -use injective_test_tube::{Account, Authz, Exchange, InjectiveTestApp, Module, Wasm}; +use injective_test_tube::{Account, Authz, Bank, Exchange, InjectiveTestApp, Module, Wasm}; +use injective_testing::test_tube::bank::send; +use injective_testing::test_tube::exchange::add_denom_notional_and_decimal; use prost::Message; #[test] @@ -32,6 +34,13 @@ pub fn set_route_for_third_party_test() { ], ); + let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap(); + send(&Bank::new(&app), "1000000000000000000000", "inj", &owner, &validator); + add_denom_notional_and_decimal(&app, &validator, INJ.to_string(), "1".to_string(), 18); + add_denom_notional_and_decimal(&app, &validator, ETH.to_string(), "1".to_string(), 18); + add_denom_notional_and_decimal(&app, &validator, ATOM.to_string(), "1".to_string(), 6); + add_denom_notional_and_decimal(&app, &validator, USDT.to_string(), "1".to_string(), 6); + let spot_market_1_id = launch_realistic_weth_usdt_spot_market(&exchange, &owner); let spot_market_2_id = launch_realistic_atom_usdt_spot_market(&exchange, &owner); diff --git a/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs b/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs index ad102aa..6b5143f 100644 --- a/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs +++ b/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs @@ -1,9 +1,5 @@ -use cosmwasm_std::Coin; use injective_math::FPDecimal; use injective_test_tube::{Account, Bank, Exchange, InjectiveTestApp, Module, Wasm}; -use injective_testing::test_tube::bank::send; -use injective_testing::test_tube::exchange::add_denom_notional_and_decimal; -use std::collections::HashMap; use std::ops::Neg; use crate::helpers::Scaled; diff --git a/contracts/swap/src/testing/test_utils.rs b/contracts/swap/src/testing/test_utils.rs index e644c5a..07bd3aa 100644 --- a/contracts/swap/src/testing/test_utils.rs +++ b/contracts/swap/src/testing/test_utils.rs @@ -48,6 +48,7 @@ pub const DEFAULT_TAKER_FEE: f64 = 0.001; pub const DEFAULT_ATOMIC_MULTIPLIER: f64 = 2.5; pub const DEFAULT_SELF_RELAYING_FEE_PART: f64 = 0.6; +#[allow(clippy::too_many_arguments)] pub fn launch_spot_market_custom( exchange: &Exchange, signer: &SigningAccount, From 4ee2e98b8de598bdd591fa4401d90918455dd270 Mon Sep 17 00:00:00 2001 From: Markus Waas Date: Fri, 13 Jun 2025 11:04:22 +0200 Subject: [PATCH 3/5] chore: update github action --- .github/workflows/rust.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml index fa9c5b6..c313119 100644 --- a/.github/workflows/rust.yaml +++ b/.github/workflows/rust.yaml @@ -39,7 +39,7 @@ jobs: components: llvm-tools-preview - name: Set up cargo cache - uses: actions/cache@v3 + uses: actions/cache@v4 continue-on-error: false with: path: | @@ -78,7 +78,7 @@ jobs: # ./grcov . -s . --binary-path ./target/debug/ -t lcov --branch --ignore-not-existing -o ./target/debug/lcov.info --ignore *_test.rs - name: Setup Pages - uses: actions/configure-pages@v3 + uses: actions/configure-pages@v4 - name: Upload artifact uses: actions/upload-pages-artifact@v1 with: @@ -103,7 +103,7 @@ jobs: components: rustfmt, clippy - name: Set up cargo cache - uses: actions/cache@v3 + uses: actions/cache@v4 continue-on-error: false with: path: | From 5e7170a3937161ce190d5069220fa87a7e42af33 Mon Sep 17 00:00:00 2001 From: Markus Waas Date: Fri, 13 Jun 2025 11:06:37 +0200 Subject: [PATCH 4/5] chore: update upload-artifact --- .github/workflows/rust.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml index c313119..5970f5f 100644 --- a/.github/workflows/rust.yaml +++ b/.github/workflows/rust.yaml @@ -80,12 +80,12 @@ jobs: - name: Setup Pages uses: actions/configure-pages@v4 - name: Upload artifact - uses: actions/upload-pages-artifact@v1 + uses: actions/upload-pages-artifact@v3 with: path: "./target/debug/coverage/" - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v2 + uses: actions/deploy-pages@v4 lints: name: Lints From 44d166b1b375bb31f371b21e474299c0d4e24918 Mon Sep 17 00:00:00 2001 From: jose Date: Fri, 13 Jun 2025 12:56:25 +0200 Subject: [PATCH 5/5] chore: small import refactor --- Cargo.lock | 86 ++++++++++++------- Cargo.toml | 4 +- contracts/swap/src/admin.rs | 12 +-- contracts/swap/src/testing/authz_tests.rs | 3 +- contracts/swap/src/testing/config_tests.rs | 14 +-- ...egration_realistic_tests_exact_quantity.rs | 31 +++---- ...ntegration_realistic_tests_min_quantity.rs | 31 +++---- contracts/swap/src/testing/queries_tests.rs | 37 ++++---- contracts/swap/src/testing/storage_tests.rs | 12 +-- contracts/swap/src/testing/swap_tests.rs | 16 ++-- contracts/swap/src/testing/test_utils.rs | 30 ++++--- 11 files changed, 154 insertions(+), 122 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e79fa32..738bbb5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -185,7 +185,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -498,7 +498,7 @@ dependencies = [ "subtle-encoding", "tendermint", "tendermint-rpc", - "thiserror", + "thiserror 1.0.65", ] [[package]] @@ -527,7 +527,7 @@ dependencies = [ "rand_core 0.6.4", "rayon", "sha2 0.10.8", - "thiserror", + "thiserror 1.0.65", ] [[package]] @@ -538,7 +538,7 @@ checksum = "1b5658b1dc64e10b56ae7a449f678f96932a96f6cfad1769d608d1d1d656480a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -551,7 +551,7 @@ dependencies = [ "schemars", "serde", "serde_json", - "thiserror", + "thiserror 1.0.65", ] [[package]] @@ -562,7 +562,7 @@ checksum = "c8ef1b5835a65fcca3ab8b9a02b4f4dacc78e233a5c2f20b270efb9db0666d12" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -585,7 +585,7 @@ dependencies = [ "serde-json-wasm", "sha2 0.10.8", "static_assertions 1.1.0", - "thiserror", + "thiserror 1.0.65", ] [[package]] @@ -674,7 +674,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -707,7 +707,7 @@ dependencies = [ "schemars", "serde", "sha2 0.10.8", - "thiserror", + "thiserror 1.0.65", ] [[package]] @@ -731,7 +731,7 @@ dependencies = [ "cosmwasm-std", "schemars", "serde", - "thiserror", + "thiserror 1.0.65", ] [[package]] @@ -746,7 +746,7 @@ dependencies = [ "schemars", "semver", "serde", - "thiserror", + "thiserror 1.0.65", ] [[package]] @@ -769,7 +769,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -780,7 +780,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -830,7 +830,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "unicode-xid", ] @@ -965,7 +965,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1846,7 +1846,7 @@ checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1934,7 +1934,7 @@ dependencies = [ "itertools 0.13.0", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -2297,7 +2297,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -2417,7 +2417,7 @@ checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -2428,7 +2428,7 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -2451,7 +2451,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -2608,7 +2608,7 @@ dependencies = [ "serde", "serde-json-wasm", "test-tube-inj", - "thiserror", + "thiserror 2.0.12", ] [[package]] @@ -2624,9 +2624,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.85" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -2743,7 +2743,7 @@ dependencies = [ "tendermint", "tendermint-config", "tendermint-proto", - "thiserror", + "thiserror 1.0.65", "time", "tokio", "tracing", @@ -2772,7 +2772,7 @@ dependencies = [ "cosmwasm-std", "prost", "serde_json", - "thiserror", + "thiserror 1.0.65", ] [[package]] @@ -2787,7 +2787,16 @@ version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.65", +] + +[[package]] +name = "thiserror" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +dependencies = [ + "thiserror-impl 2.0.12", ] [[package]] @@ -2798,7 +2807,18 @@ checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", ] [[package]] @@ -2879,7 +2899,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -3110,7 +3130,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "wasm-bindgen-shared", ] @@ -3144,7 +3164,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3393,7 +3413,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -3413,5 +3433,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] diff --git a/Cargo.toml b/Cargo.toml index f45ca1b..9c2d651 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,8 +21,8 @@ schemars = { version = "0.8.16", features = [ "enumset" ] } serde = { version = "1.0.193", default-features = false, features = [ "derive" ] } serde-json-wasm = { version = "1.0.1" } serde_json = { version = "1.0.120" } -test-tube-inj = { version = "2.0.6" } -thiserror = { version = "1.0.52" } +test-tube-inj = { version = "2.0.7" } +thiserror = { version = "2.0.12" } [profile.release] codegen-units = 1 diff --git a/contracts/swap/src/admin.rs b/contracts/swap/src/admin.rs index 90aa4ca..462644a 100644 --- a/contracts/swap/src/admin.rs +++ b/contracts/swap/src/admin.rs @@ -1,8 +1,10 @@ -use crate::msg::FeeRecipient; -use crate::state::{remove_swap_route, store_swap_route, CONFIG}; -use crate::types::{Config, SwapRoute}; -use crate::ContractError; -use crate::ContractError::CustomError; +use crate::{ + msg::FeeRecipient, + state::{remove_swap_route, store_swap_route, CONFIG}, + types::{Config, SwapRoute}, + ContractError, + ContractError::CustomError, +}; use cosmwasm_std::{ensure, ensure_eq, Addr, Attribute, BankMsg, Coin, Deps, DepsMut, Env, Event, Response, StdResult}; use injective_cosmwasm::{InjectiveMsgWrapper, InjectiveQuerier, InjectiveQueryWrapper, MarketId}; use std::collections::HashSet; diff --git a/contracts/swap/src/testing/authz_tests.rs b/contracts/swap/src/testing/authz_tests.rs index 0316470..195f35a 100644 --- a/contracts/swap/src/testing/authz_tests.rs +++ b/contracts/swap/src/testing/authz_tests.rs @@ -13,8 +13,7 @@ use injective_std::{ types::{cosmos::authz::v1beta1::MsgExec, cosmwasm::wasm::v1::MsgExecuteContract}, }; use injective_test_tube::{Account, Authz, Bank, Exchange, InjectiveTestApp, Module, Wasm}; -use injective_testing::test_tube::bank::send; -use injective_testing::test_tube::exchange::add_denom_notional_and_decimal; +use injective_testing::test_tube::{bank::send, exchange::add_denom_notional_and_decimal}; use prost::Message; #[test] diff --git a/contracts/swap/src/testing/config_tests.rs b/contracts/swap/src/testing/config_tests.rs index 68ed7cc..87d526a 100644 --- a/contracts/swap/src/testing/config_tests.rs +++ b/contracts/swap/src/testing/config_tests.rs @@ -1,14 +1,16 @@ +use crate::{ + contract::execute, + msg::{ExecuteMsg, FeeRecipient}, + state::CONFIG, + testing::test_utils::{TEST_CONTRACT_ADDR, TEST_USER_ADDR}, + types::Config, +}; + use cosmwasm_std::testing::{message_info, mock_env}; use cosmwasm_std::{coins, Addr}; use injective_cosmwasm::{inj_mock_deps, OwnedDepsExt}; -use crate::contract::execute; -use crate::msg::{ExecuteMsg, FeeRecipient}; -use crate::state::CONFIG; -use crate::testing::test_utils::{TEST_CONTRACT_ADDR, TEST_USER_ADDR}; -use crate::types::Config; - #[test] pub fn admin_can_update_config() { let mut deps = inj_mock_deps(|_| {}); diff --git a/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs b/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs index 6b5143f..7ed102d 100644 --- a/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs +++ b/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs @@ -1,22 +1,23 @@ +use crate::{ + helpers::Scaled, + msg::{ExecuteMsg, QueryMsg}, + testing::test_utils::{ + are_fpdecimals_approximately_equal, assert_fee_is_as_expected, create_ninja_inj_both_side_orders, + create_realistic_atom_usdt_sell_orders_from_spreadsheet, create_realistic_eth_usdt_buy_orders_from_spreadsheet, + create_realistic_eth_usdt_sell_orders_from_spreadsheet, create_realistic_inj_usdt_buy_orders_from_spreadsheet, + create_realistic_inj_usdt_sell_orders_from_spreadsheet, create_realistic_limit_order, create_realistic_usdt_usdc_both_side_orders, + human_to_dec, init_rich_account, init_self_relaying_contract_and_get_address, initial_coin, launch_realistic_atom_usdt_spot_market, + launch_realistic_inj_usdt_spot_market, launch_realistic_ninja_inj_spot_market, launch_realistic_usdt_usdc_spot_market, + launch_realistic_weth_usdt_spot_market, must_init_account_with_funds_and_setting_denoms, query_all_bank_balances, query_bank_balance, + set_route_and_assert_success, str_coin, Decimals, OrderSide, ATOM, ETH, INJ, INJ_2, NINJA, USDC, USDT, + }, + types::{FPCoin, SwapEstimationResult}, +}; + use injective_math::FPDecimal; use injective_test_tube::{Account, Bank, Exchange, InjectiveTestApp, Module, Wasm}; use std::ops::Neg; -use crate::helpers::Scaled; - -use crate::msg::{ExecuteMsg, QueryMsg}; -use crate::testing::test_utils::{ - are_fpdecimals_approximately_equal, assert_fee_is_as_expected, create_ninja_inj_both_side_orders, - create_realistic_atom_usdt_sell_orders_from_spreadsheet, create_realistic_eth_usdt_buy_orders_from_spreadsheet, - create_realistic_eth_usdt_sell_orders_from_spreadsheet, create_realistic_inj_usdt_buy_orders_from_spreadsheet, - create_realistic_inj_usdt_sell_orders_from_spreadsheet, create_realistic_limit_order, create_realistic_usdt_usdc_both_side_orders, human_to_dec, - init_rich_account, init_self_relaying_contract_and_get_address, initial_coin, launch_realistic_atom_usdt_spot_market, - launch_realistic_inj_usdt_spot_market, launch_realistic_ninja_inj_spot_market, launch_realistic_usdt_usdc_spot_market, - launch_realistic_weth_usdt_spot_market, must_init_account_with_funds_and_setting_denoms, query_all_bank_balances, query_bank_balance, - set_route_and_assert_success, str_coin, Decimals, OrderSide, ATOM, ETH, INJ, INJ_2, NINJA, USDC, USDT, -}; -use crate::types::{FPCoin, SwapEstimationResult}; - /* This test suite focuses on using using realistic values both for spot markets and for orders and focuses on swaps requesting exact amount. This works as expected apart, when we are converting very diff --git a/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs b/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs index d46aab9..47416a3 100644 --- a/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs +++ b/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs @@ -1,20 +1,21 @@ -use injective_test_tube::{Account, Bank, Exchange, InjectiveTestApp, Module, RunnerResult, SigningAccount, Wasm}; -use std::ops::Neg; +use crate::{ + helpers::Scaled, + msg::{ExecuteMsg, QueryMsg}, + testing::test_utils::{ + are_fpdecimals_approximately_equal, assert_fee_is_as_expected, create_realistic_atom_usdt_sell_orders_from_spreadsheet, + create_realistic_eth_usdt_buy_orders_from_spreadsheet, create_realistic_eth_usdt_sell_orders_from_spreadsheet, + create_realistic_inj_usdt_buy_orders_from_spreadsheet, create_realistic_usdt_usdc_both_side_orders, human_to_dec, init_rich_account, + init_self_relaying_contract_and_get_address, initial_coin, launch_realistic_atom_usdt_spot_market, launch_realistic_inj_usdt_spot_market, + launch_realistic_usdt_usdc_spot_market, launch_realistic_weth_usdt_spot_market, must_init_account_with_funds_and_setting_denoms, + query_all_bank_balances, query_bank_balance, set_route_and_assert_success, str_coin, Decimals, ATOM, DEFAULT_ATOMIC_MULTIPLIER, + DEFAULT_SELF_RELAYING_FEE_PART, DEFAULT_TAKER_FEE, ETH, INJ, INJ_2, USDC, USDT, + }, + types::{FPCoin, SwapEstimationResult}, +}; -use crate::helpers::Scaled; use injective_math::FPDecimal; - -use crate::msg::{ExecuteMsg, QueryMsg}; -use crate::testing::test_utils::{ - are_fpdecimals_approximately_equal, assert_fee_is_as_expected, create_realistic_atom_usdt_sell_orders_from_spreadsheet, - create_realistic_eth_usdt_buy_orders_from_spreadsheet, create_realistic_eth_usdt_sell_orders_from_spreadsheet, - create_realistic_inj_usdt_buy_orders_from_spreadsheet, create_realistic_usdt_usdc_both_side_orders, human_to_dec, init_rich_account, - init_self_relaying_contract_and_get_address, initial_coin, launch_realistic_atom_usdt_spot_market, launch_realistic_inj_usdt_spot_market, - launch_realistic_usdt_usdc_spot_market, launch_realistic_weth_usdt_spot_market, must_init_account_with_funds_and_setting_denoms, - query_all_bank_balances, query_bank_balance, set_route_and_assert_success, str_coin, Decimals, ATOM, DEFAULT_ATOMIC_MULTIPLIER, - DEFAULT_SELF_RELAYING_FEE_PART, DEFAULT_TAKER_FEE, ETH, INJ, INJ_2, USDC, USDT, -}; -use crate::types::{FPCoin, SwapEstimationResult}; +use injective_test_tube::{Account, Bank, Exchange, InjectiveTestApp, Module, RunnerResult, SigningAccount, Wasm}; +use std::ops::Neg; /* This test suite focuses on using using realistic values both for spot markets and for orders and diff --git a/contracts/swap/src/testing/queries_tests.rs b/contracts/swap/src/testing/queries_tests.rs index e79372e..01b9c07 100644 --- a/contracts/swap/src/testing/queries_tests.rs +++ b/contracts/swap/src/testing/queries_tests.rs @@ -1,23 +1,26 @@ -use std::ops::Neg; -use std::str::FromStr; - -use cosmwasm_std::testing::{message_info, mock_env}; -use cosmwasm_std::{coin, Addr}; - -use crate::admin::set_route; -use crate::contract::instantiate; -use crate::helpers::Scaled; +use crate::{ + admin::set_route, + contract::instantiate, + helpers::Scaled, + msg::{FeeRecipient, InstantiateMsg}, + queries::{estimate_swap_result, SwapQuantity}, + state::get_all_swap_routes, + testing::test_utils::{ + are_fpdecimals_approximately_equal, human_to_dec, mock_deps_eth_inj, mock_realistic_deps_eth_atom, Decimals, MultiplierQueryBehavior, + TEST_USER_ADDR, + }, + types::{FPCoin, SwapRoute}, +}; +use cosmwasm_std::{ + coin, + testing::{message_info, mock_env}, + Addr, +}; use injective_cosmwasm::{OwnedDepsExt, TEST_MARKET_ID_1, TEST_MARKET_ID_2}; use injective_math::FPDecimal; -use crate::msg::{FeeRecipient, InstantiateMsg}; -use crate::queries::{estimate_swap_result, SwapQuantity}; -use crate::state::get_all_swap_routes; -use crate::testing::test_utils::{ - are_fpdecimals_approximately_equal, human_to_dec, mock_deps_eth_inj, mock_realistic_deps_eth_atom, Decimals, MultiplierQueryBehavior, - TEST_USER_ADDR, -}; -use crate::types::{FPCoin, SwapRoute}; +use std::ops::Neg; +use std::str::FromStr; /* Tests focusing on queries with all values were taken from this spreadsheet: diff --git a/contracts/swap/src/testing/storage_tests.rs b/contracts/swap/src/testing/storage_tests.rs index 7690721..f8e2316 100644 --- a/contracts/swap/src/testing/storage_tests.rs +++ b/contracts/swap/src/testing/storage_tests.rs @@ -1,12 +1,12 @@ +use crate::{ + admin::{delete_route, set_route}, + state::{read_swap_route, store_swap_route, CONFIG}, + testing::test_utils::{mock_deps_eth_inj, MultiplierQueryBehavior, TEST_CONTRACT_ADDR, TEST_USER_ADDR}, + types::{Config, SwapRoute}, +}; use cosmwasm_std::Addr; - -use crate::admin::{delete_route, set_route}; use injective_cosmwasm::{inj_mock_deps, MarketId, OwnedDepsExt, TEST_MARKET_ID_1, TEST_MARKET_ID_2, TEST_MARKET_ID_3}; -use crate::state::{read_swap_route, store_swap_route, CONFIG}; -use crate::testing::test_utils::{mock_deps_eth_inj, MultiplierQueryBehavior, TEST_CONTRACT_ADDR, TEST_USER_ADDR}; -use crate::types::{Config, SwapRoute}; - #[test] fn it_can_store_and_read_swap_route() { let mut deps = mock_deps_eth_inj(MultiplierQueryBehavior::Success); diff --git a/contracts/swap/src/testing/swap_tests.rs b/contracts/swap/src/testing/swap_tests.rs index 19b8c7b..c983020 100644 --- a/contracts/swap/src/testing/swap_tests.rs +++ b/contracts/swap/src/testing/swap_tests.rs @@ -1,14 +1,14 @@ -use cosmwasm_std::testing::mock_env; -use cosmwasm_std::Addr; +use crate::{ + admin::set_route, + queries::estimate_single_swap_execution, + state::CONFIG, + testing::test_utils::{mock_deps_eth_inj, str_coin, Decimals, MultiplierQueryBehavior, TEST_USER_ADDR}, + types::{Config, FPCoin, SwapEstimationAmount}, +}; +use cosmwasm_std::{testing::mock_env, Addr}; use injective_cosmwasm::{MarketId, OwnedDepsExt, TEST_MARKET_ID_1, TEST_MARKET_ID_2}; -use crate::admin::set_route; -use crate::queries::estimate_single_swap_execution; -use crate::state::CONFIG; -use crate::testing::test_utils::{mock_deps_eth_inj, str_coin, Decimals, MultiplierQueryBehavior, TEST_USER_ADDR}; -use crate::types::{Config, FPCoin, SwapEstimationAmount}; - #[test] fn it_reverts_if_atomic_fee_multiplier_query_fails() { let env = mock_env(); diff --git a/contracts/swap/src/testing/test_utils.rs b/contracts/swap/src/testing/test_utils.rs index 07bd3aa..3f5976e 100644 --- a/contracts/swap/src/testing/test_utils.rs +++ b/contracts/swap/src/testing/test_utils.rs @@ -1,16 +1,23 @@ -use crate::helpers::Scaled; +use crate::{ + helpers::Scaled, + msg::{ExecuteMsg, FeeRecipient, InstantiateMsg}, + types::FPCoin, +}; -use cosmwasm_std::testing::{MockApi, MockStorage}; -use cosmwasm_std::{coin, to_json_binary, Addr, Coin, ContractResult, OwnedDeps, QuerierResult, SystemError, SystemResult, Uint128}; +use cosmwasm_std::{ + coin, + testing::{MockApi, MockStorage}, + to_json_binary, Addr, Coin, ContractResult, OwnedDeps, QuerierResult, SystemError, SystemResult, Uint128, +}; use injective_cosmwasm::{ create_orderbook_response_handler, create_spot_multi_market_handler, get_default_subaccount_id_for_checked_address, inj_mock_deps, test_market_ids, HandlesMarketIdQuery, InjectiveQueryWrapper, MarketId, PriceLevel, QueryMarketAtomicExecutionFeeMultiplierResponse, SpotMarket, WasmMockQuerier, TEST_MARKET_ID_1, TEST_MARKET_ID_2, }; use injective_math::FPDecimal; -use injective_std::types::injective::exchange::v1beta1::MsgInstantSpotMarketLaunch; use injective_std::{ shim::{Any, Timestamp}, + types::injective::exchange::v1beta1::MsgInstantSpotMarketLaunch, types::{ cosmos::{ authz::v1beta1::{Grant, MsgGrant}, @@ -21,18 +28,15 @@ use injective_std::{ }, }; use injective_test_tube::{Account, Authz, Bank, Exchange, InjectiveTestApp, Module, SigningAccount, Wasm}; -use injective_testing::test_tube::bank::send; -use injective_testing::test_tube::exchange::{add_denom_notional_and_decimal, get_spot_market_id}; -use injective_testing::utils::dec_to_proto; -use injective_testing::{test_tube::utils::store_code, utils::scale_price_quantity_spot_market}; +use injective_testing::{ + test_tube::bank::send, + test_tube::exchange::{add_denom_notional_and_decimal, get_spot_market_id}, + utils::dec_to_proto, + {test_tube::utils::store_code, utils::scale_price_quantity_spot_market}, +}; use std::{collections::HashMap, str::FromStr}; use test_tube_inj::cosmrs::proto::prost::Message; -use crate::{ - msg::{ExecuteMsg, FeeRecipient, InstantiateMsg}, - types::FPCoin, -}; - pub const TEST_CONTRACT_ADDR: &str = "inj14hj2tavq8fpesdwxxcu44rty3hh90vhujaxlnz"; pub const TEST_USER_ADDR: &str = "inj1p7z8p649xspcey7wp5e4leqf7wa39kjjj6wja8";