From 25e7e223f51f8e4ac9f4dbe1bc5b7f82097ae5b4 Mon Sep 17 00:00:00 2001 From: William Freudenberger Date: Thu, 27 Jun 2024 17:14:48 +0200 Subject: [PATCH] feat: `CheckMetadataHash` extension (#1865) * set dependency versions * upgrade libs/* * upgrade pallet-anchors * upgrade pallet-fees * upgrade pallet-bridge * migrate simple pallets * migrate pallet-order-book * migrated collator-allowlist & swaps * upgrade rewards * upgraded pallet-mux * upgrade transfer-allowlist * fix hold reason in restricted tokens * simplify set_balance removing the holding part * upgrade restricted-xtokens * upgrade some pallets * upgrade pallet-ethereum-transaction * upgrade pallet-loans * upgrade pool-system * upgrade pool-fees * upgrade pool-registry * upgrade liquidity-pools stuffs * avoid duplicated polkadot-sdk repos * minor fixes * upgraded runtime-common * CfgLocation to RestrictedTransferLocation * restricted tokens with NativeIndex for native fungibles * rename dependency * upgraded development-runtime * fix partially benchmarks * fix benchmarks * overpass xcmp-queue integrity tests * minor coments * upgrade altair & centrifuge * remove some benchmarking pallets that are not needed * fix runtime upgrades * upgrade integration-test proc * upgrade integration-tests framework * upgraded all tests except liquidity pools * 99% upgraded liquidity-pools tests * fix lookup * cargo fmt * taplo fmt * using nightly cargo in CI * restore set_balance as it was * allow nightly support in CI * use restricted_tokens again to fetch from investement portfolio * Install rust-src for docs * fix tests * remove unused restricted tokens * fix block rewards * fix WrongWitness for some tests in IT * fix liquidity-pools * minor fixes * fix clippy * remove unneeded tests * feat: Update client to Polkadot v1.7.2 (#1844) * wip: update client * chore: update crate versions * chore: update anchor rpc api * chore: remove rewards, pools rpc * chore: compile with development runtime * fix: client for all runtimes * fix: build spec * feat: update relay docker images * fix: apply deprecation of export genesis state to scripts * fmt: taplo * refactor: use xcm v4 sugar * fix: revert tmp change in local para run * refactor: simplify xcm v4 locations in chain spec * cargo fmt * fix clippy * feat: Polkadot v1.7.2 migrations (#1849) * feat: add hold reason migration * feat: centrifuge migrations * feat: altair migrations * feat: dev + demo migrations * fix: clippy * fix: build * fmt: fix using nightly * last William iteration review * increase passed blocks * use rococo instead of polkadot-test-runtime * fix tests * remove line * dirty fix to fix Hrmp test issue * use default weights for treasury * remove getrandom unused dep * upgrade to last polkadot-sdk version * feat: `CheckMetadataHash` extension * fix it (#1866) * fmt: taplo * refactor: signed ext order * fix: signed ext order for ITs * IT: more support for router tests (#1885) * move routers to its own module * remove outdated markers * for all runtimes * remove previous tests * minor fixes * v0.11.2 rc * panic if event is not found in the expected blocks (#1880) * fix: ci * remove generic module (#1887) * revert check metadata hash disable * fix: disable metadata hash check for integration tests --------- Co-authored-by: lemunozm --- Cargo.lock | 64 +++- Cargo.toml | 1 + .../routers/src/lib.rs | 1 - .../routers/src/routers/axelar_evm.rs | 4 +- .../routers/src/routers/axelar_xcm.rs | 2 - .../routers/src/routers/ethereum_xcm.rs | 3 +- .../routers/src/tests.rs | 15 - pallets/pool-system/src/mock.rs | 1 + runtime/altair/Cargo.toml | 12 + runtime/altair/build.rs | 19 +- runtime/altair/src/lib.rs | 1 + runtime/centrifuge/Cargo.toml | 12 + runtime/centrifuge/build.rs | 19 +- runtime/centrifuge/src/lib.rs | 2 + runtime/common/src/gateway.rs | 16 +- runtime/development/Cargo.toml | 12 + runtime/development/build.rs | 19 +- runtime/development/src/lib.rs | 1 + runtime/integration-tests/Cargo.toml | 1 + .../src/{generic => }/README.md | 12 +- runtime/integration-tests/src/cases.rs | 16 + .../{generic => }/cases/account_derivation.rs | 2 +- .../src/{generic => }/cases/assets.rs | 5 +- .../src/{generic => }/cases/block_rewards.rs | 18 +- .../cases/currency_conversions.rs | 2 +- .../cases/ethereum_transaction.rs | 2 +- .../src/{generic => }/cases/example.rs | 15 +- .../src/{generic => }/cases/investments.rs | 20 +- .../{generic => }/cases/liquidity_pools.rs | 354 +----------------- .../src/{generic => }/cases/loans.rs | 20 +- .../src/{generic => }/cases/lp/investments.rs | 29 +- .../src/{generic => }/cases/lp/mod.rs | 67 ++-- .../{generic => }/cases/lp/pool_management.rs | 28 +- .../src/{generic => }/cases/lp/transfers.rs | 17 +- .../src/{generic => }/cases/oracles.rs | 2 +- .../src/{generic => }/cases/precompile.rs | 2 +- .../src/{generic => }/cases/proxy.rs | 18 +- .../cases/restricted_transfers.rs | 20 +- .../integration-tests/src/cases/routers.rs | 180 +++++++++ .../src/{generic => }/cases/xcm_transfers.rs | 33 +- .../src/{generic => }/config.rs | 1 + .../src/{generic => }/env.rs | 17 +- .../src/{generic => }/envs/evm_env.rs | 16 +- .../src/{generic => }/envs/fudge_env.rs | 8 +- .../{generic => }/envs/fudge_env/handle.rs | 2 +- .../src/{generic => }/envs/runtime_env.rs | 10 +- runtime/integration-tests/src/generic/mod.rs | 61 --- .../src/generic/utils/mod.rs | 227 ----------- .../src/{generic => }/impls.rs | 6 +- runtime/integration-tests/src/lib.rs | 43 ++- .../src/{generic => }/utils/currency.rs | 2 +- .../src/{generic => }/utils/evm.rs | 2 +- .../src/{generic => }/utils/genesis.rs | 2 +- runtime/integration-tests/src/utils/mod.rs | 219 +++++++++++ .../src/{generic => }/utils/pool.rs | 2 +- .../src/{generic => }/utils/tokens.rs | 2 +- .../src/{generic => }/utils/xcm.rs | 2 +- scripts/export_parachain_files.sh | 2 +- 58 files changed, 795 insertions(+), 896 deletions(-) rename runtime/integration-tests/src/{generic => }/README.md (71%) create mode 100644 runtime/integration-tests/src/cases.rs rename runtime/integration-tests/src/{generic => }/cases/account_derivation.rs (98%) rename runtime/integration-tests/src/{generic => }/cases/assets.rs (91%) rename runtime/integration-tests/src/{generic => }/cases/block_rewards.rs (96%) rename runtime/integration-tests/src/{generic => }/cases/currency_conversions.rs (99%) rename runtime/integration-tests/src/{generic => }/cases/ethereum_transaction.rs (99%) rename runtime/integration-tests/src/{generic => }/cases/example.rs (95%) rename runtime/integration-tests/src/{generic => }/cases/investments.rs (95%) rename runtime/integration-tests/src/{generic => }/cases/liquidity_pools.rs (92%) rename runtime/integration-tests/src/{generic => }/cases/loans.rs (98%) rename runtime/integration-tests/src/{generic => }/cases/lp/investments.rs (97%) rename runtime/integration-tests/src/{generic => }/cases/lp/mod.rs (97%) rename runtime/integration-tests/src/{generic => }/cases/lp/pool_management.rs (97%) rename runtime/integration-tests/src/{generic => }/cases/lp/transfers.rs (95%) rename runtime/integration-tests/src/{generic => }/cases/oracles.rs (99%) rename runtime/integration-tests/src/{generic => }/cases/precompile.rs (99%) rename runtime/integration-tests/src/{generic => }/cases/proxy.rs (96%) rename runtime/integration-tests/src/{generic => }/cases/restricted_transfers.rs (97%) create mode 100644 runtime/integration-tests/src/cases/routers.rs rename runtime/integration-tests/src/{generic => }/cases/xcm_transfers.rs (92%) rename runtime/integration-tests/src/{generic => }/config.rs (99%) rename runtime/integration-tests/src/{generic => }/env.rs (95%) rename runtime/integration-tests/src/{generic => }/envs/evm_env.rs (97%) rename runtime/integration-tests/src/{generic => }/envs/fudge_env.rs (97%) rename runtime/integration-tests/src/{generic => }/envs/fudge_env/handle.rs (99%) rename runtime/integration-tests/src/{generic => }/envs/runtime_env.rs (98%) delete mode 100644 runtime/integration-tests/src/generic/mod.rs delete mode 100644 runtime/integration-tests/src/generic/utils/mod.rs rename runtime/integration-tests/src/{generic => }/impls.rs (97%) rename runtime/integration-tests/src/{generic => }/utils/currency.rs (99%) rename runtime/integration-tests/src/{generic => }/utils/evm.rs (99%) rename runtime/integration-tests/src/{generic => }/utils/genesis.rs (99%) rename runtime/integration-tests/src/{generic => }/utils/pool.rs (98%) rename runtime/integration-tests/src/{generic => }/utils/tokens.rs (95%) rename runtime/integration-tests/src/{generic => }/utils/xcm.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index 995c610e64..7abc1104d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -121,7 +121,7 @@ checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "altair-runtime" -version = "0.11.1" +version = "0.11.3" dependencies = [ "axelar-gateway-precompile", "cfg-primitives", @@ -141,6 +141,7 @@ dependencies = [ "fp-self-contained", "frame-benchmarking", "frame-executive", + "frame-metadata-hash-extension", "frame-support", "frame-system", "frame-system-benchmarking", @@ -1371,7 +1372,7 @@ dependencies = [ [[package]] name = "centrifuge-chain" -version = "0.11.1" +version = "0.11.3" dependencies = [ "altair-runtime", "async-trait", @@ -1464,7 +1465,7 @@ dependencies = [ [[package]] name = "centrifuge-runtime" -version = "0.11.1" +version = "0.11.3" dependencies = [ "axelar-gateway-precompile", "cfg-primitives", @@ -1484,6 +1485,7 @@ dependencies = [ "fp-self-contained", "frame-benchmarking", "frame-executive", + "frame-metadata-hash-extension", "frame-support", "frame-system", "frame-system-benchmarking", @@ -3093,7 +3095,7 @@ dependencies = [ [[package]] name = "development-runtime" -version = "0.11.1" +version = "0.11.3" dependencies = [ "axelar-gateway-precompile", "cfg-primitives", @@ -3113,6 +3115,7 @@ dependencies = [ "fp-self-contained", "frame-benchmarking", "frame-executive", + "frame-metadata-hash-extension", "frame-support", "frame-system", "frame-system-benchmarking", @@ -6524,6 +6527,20 @@ dependencies = [ "hash-db", ] +[[package]] +name = "merkleized-metadata" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f313fcff1d2a4bcaa2deeaa00bf7530d77d5f7bd0467a117dde2e29a75a7a17a" +dependencies = [ + "array-bytes 6.2.3", + "blake3", + "frame-metadata", + "parity-scale-codec", + "scale-decode", + "scale-info", +] + [[package]] name = "merlin" version = "3.0.0" @@ -11739,6 +11756,7 @@ dependencies = [ "ethereum", "fp-evm", "fp-self-contained", + "frame-metadata-hash-extension", "frame-support", "frame-system", "fudge", @@ -13187,6 +13205,29 @@ dependencies = [ "sp-arithmetic", ] +[[package]] +name = "scale-bits" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e57b1e7f6b65ed1f04e79a85a57d755ad56d76fdf1e9bddcc9ae14f71fcdcf54" +dependencies = [ + "parity-scale-codec", + "scale-type-resolver", +] + +[[package]] +name = "scale-decode" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e98f3262c250d90e700bb802eb704e1f841e03331c2eb815e46516c4edbf5b27" +dependencies = [ + "derive_more", + "parity-scale-codec", + "scale-bits", + "scale-type-resolver", + "smallvec", +] + [[package]] name = "scale-info" version = "2.11.3" @@ -13213,6 +13254,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "scale-type-resolver" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0cded6518aa0bd6c1be2b88ac81bf7044992f0f154bfbabd5ad34f43512abcb" + [[package]] name = "schannel" version = "0.1.23" @@ -14982,12 +15029,21 @@ name = "substrate-wasm-builder" version = "17.0.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.2#c00ca35b403a95e344d03e229b3f85baa3b96c89" dependencies = [ + "array-bytes 6.2.3", "build-helper", "cargo_metadata", "console", "filetime", + "frame-metadata", + "merkleized-metadata", + "parity-scale-codec", "parity-wasm", + "sc-executor", + "sp-core", + "sp-io", "sp-maybe-compressed-blob", + "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.2)", + "sp-version", "strum 0.24.1", "tempfile", "toml 0.8.14", diff --git a/Cargo.toml b/Cargo.toml index 4c854938e1..ac804712a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -173,6 +173,7 @@ sp-staking = { git = "https://github.com/paritytech/polkadot-sdk", default-featu sp-trie = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" } frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" } frame-executive = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" } +frame-metadata-hash-extension = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" } frame-support = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, features = [ "tuples-96", ], branch = "release-polkadot-v1.7.2" } # Check when tuples-96 can be removed diff --git a/pallets/liquidity-pools-gateway/routers/src/lib.rs b/pallets/liquidity-pools-gateway/routers/src/lib.rs index 4d8ed5f3cb..a2e9f4184c 100644 --- a/pallets/liquidity-pools-gateway/routers/src/lib.rs +++ b/pallets/liquidity-pools-gateway/routers/src/lib.rs @@ -234,7 +234,6 @@ where T: frame_system::Config + pallet_xcm_transactor::Config, { pub xcm_domain: XcmDomain, - pub _marker: PhantomData, } impl XCMRouter diff --git a/pallets/liquidity-pools-gateway/routers/src/routers/axelar_evm.rs b/pallets/liquidity-pools-gateway/routers/src/routers/axelar_evm.rs index 76af791461..7aea971fc8 100644 --- a/pallets/liquidity-pools-gateway/routers/src/routers/axelar_evm.rs +++ b/pallets/liquidity-pools-gateway/routers/src/routers/axelar_evm.rs @@ -22,7 +22,7 @@ use scale_info::{ TypeInfo, }; use sp_core::{bounded::BoundedVec, ConstU32, H160}; -use sp_std::{collections::btree_map::BTreeMap, marker::PhantomData, vec, vec::Vec}; +use sp_std::{collections::btree_map::BTreeMap, vec, vec::Vec}; use crate::{ AccountIdOf, EVMRouter, MessageOf, AXELAR_DESTINATION_CHAIN_PARAM, @@ -44,7 +44,6 @@ where pub router: EVMRouter, pub evm_chain: BoundedVec>, pub liquidity_pools_contract_address: H160, - pub _marker: PhantomData, } impl AxelarEVMRouter @@ -66,7 +65,6 @@ where router, evm_chain, liquidity_pools_contract_address, - _marker: Default::default(), } } diff --git a/pallets/liquidity-pools-gateway/routers/src/routers/axelar_xcm.rs b/pallets/liquidity-pools-gateway/routers/src/routers/axelar_xcm.rs index 74d4de14be..fa245b0036 100644 --- a/pallets/liquidity-pools-gateway/routers/src/routers/axelar_xcm.rs +++ b/pallets/liquidity-pools-gateway/routers/src/routers/axelar_xcm.rs @@ -16,7 +16,6 @@ use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_core::{bounded::BoundedVec, ConstU32, H160}; use sp_runtime::DispatchError; -use sp_std::marker::PhantomData; use crate::{ axelar_evm::get_axelar_encoded_msg, AccountIdOf, CurrencyIdOf, MessageOf, XCMRouter, XcmDomain, @@ -37,7 +36,6 @@ where pub router: XCMRouter, pub axelar_target_chain: BoundedVec>, pub axelar_target_contract: H160, - pub _marker: PhantomData, } impl AxelarXCMRouter diff --git a/pallets/liquidity-pools-gateway/routers/src/routers/ethereum_xcm.rs b/pallets/liquidity-pools-gateway/routers/src/routers/ethereum_xcm.rs index a92569b277..26aa2c7afc 100644 --- a/pallets/liquidity-pools-gateway/routers/src/routers/ethereum_xcm.rs +++ b/pallets/liquidity-pools-gateway/routers/src/routers/ethereum_xcm.rs @@ -17,7 +17,7 @@ use frame_support::{ }; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; -use sp_std::{collections::btree_map::BTreeMap, marker::PhantomData, vec, vec::Vec}; +use sp_std::{collections::btree_map::BTreeMap, vec, vec::Vec}; use crate::{AccountIdOf, MessageOf, XCMRouter, FUNCTION_NAME, MESSAGE_PARAM}; @@ -30,7 +30,6 @@ where + pallet_liquidity_pools_gateway::Config, { pub router: XCMRouter, - pub _marker: PhantomData, } impl EthereumXCMRouter diff --git a/pallets/liquidity-pools-gateway/routers/src/tests.rs b/pallets/liquidity-pools-gateway/routers/src/tests.rs index dc69b1c606..88dfdd17dd 100644 --- a/pallets/liquidity-pools-gateway/routers/src/tests.rs +++ b/pallets/liquidity-pools-gateway/routers/src/tests.rs @@ -229,7 +229,6 @@ mod xcm_router { let router = XCMRouter:: { xcm_domain: test_data.xcm_domain.clone(), - _marker: Default::default(), }; assert_ok!(router.do_init()); @@ -247,7 +246,6 @@ mod xcm_router { let router = XCMRouter:: { xcm_domain: test_data.xcm_domain.clone(), - _marker: Default::default(), }; assert_ok!(router.do_send(test_data.sender, test_data.msg.clone())); @@ -293,7 +291,6 @@ mod xcm_router { let router = XCMRouter:: { xcm_domain: test_data.xcm_domain.clone(), - _marker: Default::default(), }; assert_ok!(router.do_init()); @@ -383,7 +380,6 @@ mod axelar_evm { evm_chain: TEST_EVM_CHAIN.clone(), liquidity_pools_contract_address: test_data .liquidity_pools_contract_address, - _marker: Default::default(), }); assert_ok!(domain_router.init()); @@ -404,7 +400,6 @@ mod axelar_evm { evm_chain: TEST_EVM_CHAIN.clone(), liquidity_pools_contract_address: test_data .liquidity_pools_contract_address, - _marker: Default::default(), }); assert_noop!( @@ -453,7 +448,6 @@ mod axelar_evm { evm_chain: TEST_EVM_CHAIN.clone(), liquidity_pools_contract_address: test_data .liquidity_pools_contract_address, - _marker: Default::default(), }); assert_ok!(domain_router.send(test_data.sender, test_data.msg)); @@ -474,7 +468,6 @@ mod axelar_evm { evm_chain: TEST_EVM_CHAIN.clone(), liquidity_pools_contract_address: test_data .liquidity_pools_contract_address, - _marker: Default::default(), }); let res = domain_router.send(test_data.sender, test_data.msg); @@ -551,11 +544,9 @@ mod axelar_xcm { DomainRouter::::AxelarXCM(AxelarXCMRouter:: { router: XCMRouter { xcm_domain: test_data.xcm_domain.clone(), - _marker: Default::default(), }, axelar_target_chain: test_data.axelar_target_chain, axelar_target_contract: test_data.axelar_target_contract, - _marker: Default::default(), }); assert_ok!(domain_router.init()); @@ -575,11 +566,9 @@ mod axelar_xcm { DomainRouter::::AxelarXCM(AxelarXCMRouter:: { router: XCMRouter { xcm_domain: test_data.xcm_domain.clone(), - _marker: Default::default(), }, axelar_target_chain: test_data.axelar_target_chain.clone(), axelar_target_contract: test_data.axelar_target_contract, - _marker: Default::default(), }); assert_ok!(domain_router.init()); @@ -694,9 +683,7 @@ mod ethereum_xcm { DomainRouter::::EthereumXCM(EthereumXCMRouter:: { router: XCMRouter { xcm_domain: test_data.xcm_domain.clone(), - _marker: Default::default(), }, - _marker: Default::default(), }); assert_ok!(domain_router.init()); @@ -716,9 +703,7 @@ mod ethereum_xcm { DomainRouter::::EthereumXCM(EthereumXCMRouter:: { router: XCMRouter { xcm_domain: test_data.xcm_domain.clone(), - _marker: Default::default(), }, - _marker: Default::default(), }); assert_ok!(domain_router.init()); diff --git a/pallets/pool-system/src/mock.rs b/pallets/pool-system/src/mock.rs index a385b59856..da4ec270df 100644 --- a/pallets/pool-system/src/mock.rs +++ b/pallets/pool-system/src/mock.rs @@ -393,6 +393,7 @@ impl EnsureOriginWithArg for All { #[cfg(feature = "runtime-benchmarks")] fn try_successful_origin(_: &PoolId) -> Result { + use frame_support::dispatch::RawOrigin; Ok(RawOrigin::Root.into()) } } diff --git a/runtime/altair/Cargo.toml b/runtime/altair/Cargo.toml index 0f6ee23f09..6097a909c5 100644 --- a/runtime/altair/Cargo.toml +++ b/runtime/altair/Cargo.toml @@ -35,6 +35,7 @@ sp-version = { workspace = true } frame-benchmarking = { workspace = true, optional = true } # For benchmarking frame-executive = { workspace = true } +frame-metadata-hash-extension = { workspace = true } frame-support = { workspace = true } frame-system = { workspace = true } frame-system-benchmarking = { workspace = true, optional = true } # For benchmarking @@ -169,6 +170,7 @@ std = [ "frame-system/std", "frame-system-rpc-runtime-api/std", "frame-executive/std", + "frame-metadata-hash-extension/std", "frame-try-runtime?/std", "frame-system-benchmarking?/std", "frame-benchmarking?/std", @@ -433,12 +435,22 @@ try-runtime = [ "staging-parachain-info/try-runtime", ] +# Enable the metadata hash generation. +# +# This is hidden behind a feature because it increases the compile time. +# The wasm binary needs to be compiled twice, once to fetch the metadata, +# generate the metadata hash and then a second time with the +# `RUNTIME_METADATA_HASH` environment variable set for the `CheckMetadataHash` +# extension. +metadata-hash = ["substrate-wasm-builder/metadata-hash"] + # A feature that should be enabled when the runtime should be build for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller like logging for example. on-chain-release-build = [ "sp-api/disable-logging", "runtime-common/on-chain-release-build", + "metadata-hash", ] # Set timing constants (e.g. session period) to faster versions to speed up testing. diff --git a/runtime/altair/build.rs b/runtime/altair/build.rs index 9b53d2457d..5e223d08bf 100644 --- a/runtime/altair/build.rs +++ b/runtime/altair/build.rs @@ -1,9 +1,16 @@ -use substrate_wasm_builder::WasmBuilder; +#[cfg(all(feature = "std", feature = "metadata-hash"))] +fn main() { + substrate_wasm_builder::WasmBuilder::init_with_defaults() + .enable_metadata_hash("AIR", 18) + .build(); +} +#[cfg(all(feature = "std", not(feature = "metadata-hash")))] fn main() { - WasmBuilder::new() - .with_current_project() - .export_heap_base() - .import_memory() - .build() + substrate_wasm_builder::WasmBuilder::build_using_defaults(); } + +/// The wasm builder is deactivated when compiling +/// this crate for wasm to speed up the compilation. +#[cfg(not(feature = "std"))] +fn main() {} diff --git a/runtime/altair/src/lib.rs b/runtime/altair/src/lib.rs index 736cbcd370..7384883f43 100644 --- a/runtime/altair/src/lib.rs +++ b/runtime/altair/src/lib.rs @@ -1948,6 +1948,7 @@ pub type SignedExtra = ( frame_system::CheckNonce, frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, + frame_metadata_hash_extension::CheckMetadataHash, runtime_common::transfer_filter::PreBalanceTransferExtension, ); diff --git a/runtime/centrifuge/Cargo.toml b/runtime/centrifuge/Cargo.toml index c1f0321c59..a2bdc31e62 100644 --- a/runtime/centrifuge/Cargo.toml +++ b/runtime/centrifuge/Cargo.toml @@ -35,6 +35,7 @@ sp-version = { workspace = true } frame-benchmarking = { workspace = true, optional = true } # For benchmarking frame-executive = { workspace = true } +frame-metadata-hash-extension = { workspace = true } frame-support = { workspace = true } frame-system = { workspace = true } frame-system-benchmarking = { workspace = true, optional = true } # For benchmarking @@ -169,6 +170,7 @@ std = [ "frame-system/std", "frame-system-rpc-runtime-api/std", "frame-executive/std", + "frame-metadata-hash-extension/std", "frame-try-runtime?/std", "frame-system-benchmarking?/std", "frame-benchmarking?/std", @@ -432,12 +434,22 @@ try-runtime = [ "staging-parachain-info/try-runtime", ] +# Enable the metadata hash generation. +# +# This is hidden behind a feature because it increases the compile time. +# The wasm binary needs to be compiled twice, once to fetch the metadata, +# generate the metadata hash and then a second time with the +# `RUNTIME_METADATA_HASH` environment variable set for the `CheckMetadataHash` +# extension. +metadata-hash = ["substrate-wasm-builder/metadata-hash"] + # A feature that should be enabled when the runtime should be build for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller like logging for example. on-chain-release-build = [ "sp-api/disable-logging", "runtime-common/on-chain-release-build", + "metadata-hash", ] # Set timing constants (e.g. session period) to faster versions to speed up testing. diff --git a/runtime/centrifuge/build.rs b/runtime/centrifuge/build.rs index 9b53d2457d..fe85940ad8 100644 --- a/runtime/centrifuge/build.rs +++ b/runtime/centrifuge/build.rs @@ -1,9 +1,16 @@ -use substrate_wasm_builder::WasmBuilder; +#[cfg(all(feature = "std", feature = "metadata-hash"))] +fn main() { + substrate_wasm_builder::WasmBuilder::init_with_defaults() + .enable_metadata_hash("CFG", 18) + .build(); +} +#[cfg(all(feature = "std", not(feature = "metadata-hash")))] fn main() { - WasmBuilder::new() - .with_current_project() - .export_heap_base() - .import_memory() - .build() + substrate_wasm_builder::WasmBuilder::build_using_defaults(); } + +/// The wasm builder is deactivated when compiling +/// this crate for wasm to speed up the compilation. +#[cfg(not(feature = "std"))] +fn main() {} diff --git a/runtime/centrifuge/src/lib.rs b/runtime/centrifuge/src/lib.rs index 988d83b1a3..bff5b9355b 100644 --- a/runtime/centrifuge/src/lib.rs +++ b/runtime/centrifuge/src/lib.rs @@ -2062,8 +2062,10 @@ pub type SignedExtra = ( frame_system::CheckNonce, frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, + frame_metadata_hash_extension::CheckMetadataHash, runtime_common::transfer_filter::PreBalanceTransferExtension, ); + /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = fp_self_contained::UncheckedExtrinsic; diff --git a/runtime/common/src/gateway.rs b/runtime/common/src/gateway.rs index 5b75077ac7..99f06d651a 100644 --- a/runtime/common/src/gateway.rs +++ b/runtime/common/src/gateway.rs @@ -12,18 +12,18 @@ use cfg_primitives::AccountId; use polkadot_parachain_primitives::primitives::Sibling; -use sp_core::{crypto::AccountId32, Get, H160}; +use sp_core::{crypto::AccountId32, H160}; use sp_runtime::traits::AccountIdConversion; use crate::account_conversion::AccountConverter; +pub fn get_gateway_h160_account() -> H160 { + let para_id = staging_parachain_info::Pallet::::parachain_id(); + let sender_account = Sibling::from(para_id).into_account_truncating(); + H160::from_slice(&>::as_ref(&sender_account)[0..20]) +} + pub fn get_gateway_account( ) -> AccountId { - let sender_account: AccountId = - Sibling::from(staging_parachain_info::Pallet::::get()).into_account_truncating(); - - let truncated_sender_account = - H160::from_slice(&>::as_ref(&sender_account)[0..20]); - - AccountConverter::evm_address_to_account::(truncated_sender_account) + AccountConverter::evm_address_to_account::(get_gateway_h160_account::()) } diff --git a/runtime/development/Cargo.toml b/runtime/development/Cargo.toml index e5c4c4989e..62c00bdaf2 100644 --- a/runtime/development/Cargo.toml +++ b/runtime/development/Cargo.toml @@ -35,6 +35,7 @@ sp-version = { workspace = true } frame-benchmarking = { workspace = true, optional = true } # For benchmarking frame-executive = { workspace = true } +frame-metadata-hash-extension = { workspace = true } frame-support = { workspace = true } frame-system = { workspace = true } frame-system-benchmarking = { workspace = true, optional = true } # For benchmarking @@ -170,6 +171,7 @@ std = [ "frame-system/std", "frame-system-rpc-runtime-api/std", "frame-executive/std", + "frame-metadata-hash-extension/std", "frame-try-runtime?/std", "frame-system-benchmarking?/std", "frame-benchmarking?/std", @@ -436,12 +438,22 @@ try-runtime = [ "staging-parachain-info/try-runtime", ] +# Enable the metadata hash generation. +# +# This is hidden behind a feature because it increases the compile time. +# The wasm binary needs to be compiled twice, once to fetch the metadata, +# generate the metadata hash and then a second time with the +# `RUNTIME_METADATA_HASH` environment variable set for the `CheckMetadataHash` +# extension. +metadata-hash = ["substrate-wasm-builder/metadata-hash"] + # A feature that should be enabled when the runtime should be build for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller like logging for example. on-chain-release-build = [ "sp-api/disable-logging", "runtime-common/on-chain-release-build", + "metadata-hash", ] # Used by integration testing diff --git a/runtime/development/build.rs b/runtime/development/build.rs index 9b53d2457d..7ea8ab14ba 100644 --- a/runtime/development/build.rs +++ b/runtime/development/build.rs @@ -1,9 +1,16 @@ -use substrate_wasm_builder::WasmBuilder; +#[cfg(all(feature = "std", feature = "metadata-hash"))] +fn main() { + substrate_wasm_builder::WasmBuilder::init_with_defaults() + .enable_metadata_hash("DEVEL", 18) + .build(); +} +#[cfg(all(feature = "std", not(feature = "metadata-hash")))] fn main() { - WasmBuilder::new() - .with_current_project() - .export_heap_base() - .import_memory() - .build() + substrate_wasm_builder::WasmBuilder::build_using_defaults(); } + +/// The wasm builder is deactivated when compiling +/// this crate for wasm to speed up the compilation. +#[cfg(not(feature = "std"))] +fn main() {} diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index 0a147349c3..4d0360b097 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -2052,6 +2052,7 @@ pub type SignedExtra = ( frame_system::CheckNonce, frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, + frame_metadata_hash_extension::CheckMetadataHash, runtime_common::transfer_filter::PreBalanceTransferExtension, ); /// Unchecked extrinsic type as expected by this runtime. diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index 47d561f010..58082f1977 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -44,6 +44,7 @@ sp-timestamp = { workspace = true, features = ["std"] } sp-tracing = { workspace = true, features = ["std"] } sp-transaction-pool = { workspace = true, features = ["std"] } +frame-metadata-hash-extension = { workspace = true, features = ["std"] } frame-support = { workspace = true, features = ["std"] } frame-system = { workspace = true, features = ["std"] } diff --git a/runtime/integration-tests/src/generic/README.md b/runtime/integration-tests/src/README.md similarity index 71% rename from runtime/integration-tests/src/generic/README.md rename to runtime/integration-tests/src/README.md index 403192b0dc..9e84267658 100644 --- a/runtime/integration-tests/src/generic/README.md +++ b/runtime/integration-tests/src/README.md @@ -1,23 +1,21 @@ # Runtime Generic tests -The aim of this module is to make integration-tests independently for all runtimes at once. - You can choose the environment for each of your use cases: - - `RuntimeEnv`: Simple environment that acts as a wrapper over the runtime - - `FudgeEnv`: Advanced environment that use a client and connect the runtime to a relay chain. + - `RuntimeEnv`: Simple environment that acts as a wrapper over the runtime (< 1sec per test case) + - `FudgeEnv`: Advanced environment that use a client and connect the runtime to a relay chain. (> 1min per test case) -Both environment uses the same interface so jumping from one to the another should be something "smooth". +Both environment uses the "same" interface so jumping from one to the another should be something "smooth". ## Where I start? - Create a new file in `cases/` for the use case you want to test. -- Maybe you need to update the `Runtime` trait in `config.rs` file with extra information from your new pallet. +- Maybe you need to update the `Runtime` trait in `config.rs` file with extra information from a new pallet. This could imply: - Adding bounds to the `Runtime` trait with your new pallet. - Adding bounds to `T::RuntimeCallExt` to support calls from your pallet. - Adding bounds to `T::EventExt` to support events from your pallet. - Adding bounds to `T::Api` to support new api calls. - You can add `GenesisBuild` builders for setting the initial state of your pallet for others in `utils/genesis.rs`. - Please be as generic and simple as possible to leave others to compose its own requirement using your method, + Please be **as much generic and simple** as possible to leave others to compose its own requirement using your method, without hidden initializations. - You can add any utility that helps to initialize states for others under `utils` folder. Again, focus in simplity but without side effects or hidden / non-obvious state changes. diff --git a/runtime/integration-tests/src/cases.rs b/runtime/integration-tests/src/cases.rs new file mode 100644 index 0000000000..0e7eec6162 --- /dev/null +++ b/runtime/integration-tests/src/cases.rs @@ -0,0 +1,16 @@ +mod account_derivation; +mod assets; +mod block_rewards; +mod currency_conversions; +mod ethereum_transaction; +mod example; +mod investments; +mod liquidity_pools; +mod loans; +mod lp; +mod oracles; +mod precompile; +mod proxy; +mod restricted_transfers; +mod routers; +mod xcm_transfers; diff --git a/runtime/integration-tests/src/generic/cases/account_derivation.rs b/runtime/integration-tests/src/cases/account_derivation.rs similarity index 98% rename from runtime/integration-tests/src/generic/cases/account_derivation.rs rename to runtime/integration-tests/src/cases/account_derivation.rs index a6bf2cbf4b..745450d7bb 100644 --- a/runtime/integration-tests/src/generic/cases/account_derivation.rs +++ b/runtime/integration-tests/src/cases/account_derivation.rs @@ -20,7 +20,7 @@ use staging_xcm::v4::{ Location, NetworkId, }; -use crate::generic::{config::Runtime, env::Env, envs::runtime_env::RuntimeEnv}; +use crate::{config::Runtime, env::Env, envs::runtime_env::RuntimeEnv}; const KEY_20: [u8; 20] = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, diff --git a/runtime/integration-tests/src/generic/cases/assets.rs b/runtime/integration-tests/src/cases/assets.rs similarity index 91% rename from runtime/integration-tests/src/generic/cases/assets.rs rename to runtime/integration-tests/src/cases/assets.rs index 093cb4f842..9ae8147d0e 100644 --- a/runtime/integration-tests/src/generic/cases/assets.rs +++ b/runtime/integration-tests/src/cases/assets.rs @@ -2,10 +2,7 @@ use cfg_types::tokens::{default_metadata, CurrencyId}; use frame_support::{assert_noop, assert_ok, dispatch::RawOrigin}; use sp_runtime::{DispatchError, DispatchError::BadOrigin}; -use crate::{ - generic::{config::Runtime, env::Env, envs::runtime_env::RuntimeEnv}, - utils::orml_asset_registry, -}; +use crate::{config::Runtime, env::Env, envs::runtime_env::RuntimeEnv, utils::orml_asset_registry}; #[test_runtimes(all)] fn authority_configured() { diff --git a/runtime/integration-tests/src/generic/cases/block_rewards.rs b/runtime/integration-tests/src/cases/block_rewards.rs similarity index 96% rename from runtime/integration-tests/src/generic/cases/block_rewards.rs rename to runtime/integration-tests/src/cases/block_rewards.rs index 020a724423..adbcdd4c80 100644 --- a/runtime/integration-tests/src/generic/cases/block_rewards.rs +++ b/runtime/integration-tests/src/cases/block_rewards.rs @@ -9,17 +9,15 @@ use runtime_common::{ use sp_runtime::traits::{Get, Zero}; use crate::{ - generic::{ - config::{Runtime, RuntimeKind}, - env::Env, - envs::runtime_env::RuntimeEnv, - utils, - utils::{ - currency::cfg, - genesis::{self, Genesis}, - }, + config::{Runtime, RuntimeKind}, + env::Env, + envs::runtime_env::RuntimeEnv, + utils, + utils::{ + accounts::{default_accounts, Keyring}, + currency::cfg, + genesis::{self, Genesis}, }, - utils::accounts::{default_accounts, Keyring}, }; #[test_runtimes(all)] diff --git a/runtime/integration-tests/src/generic/cases/currency_conversions.rs b/runtime/integration-tests/src/cases/currency_conversions.rs similarity index 99% rename from runtime/integration-tests/src/generic/cases/currency_conversions.rs rename to runtime/integration-tests/src/cases/currency_conversions.rs index 4cbed8080f..6c657b3459 100644 --- a/runtime/integration-tests/src/generic/cases/currency_conversions.rs +++ b/runtime/integration-tests/src/cases/currency_conversions.rs @@ -7,7 +7,7 @@ use staging_xcm::{ VersionedLocation, }; -use crate::generic::{ +use crate::{ config::Runtime, env::Env, envs::runtime_env::RuntimeEnv, diff --git a/runtime/integration-tests/src/generic/cases/ethereum_transaction.rs b/runtime/integration-tests/src/cases/ethereum_transaction.rs similarity index 99% rename from runtime/integration-tests/src/generic/cases/ethereum_transaction.rs rename to runtime/integration-tests/src/cases/ethereum_transaction.rs index bdf4c43bbe..1d00a2d44a 100644 --- a/runtime/integration-tests/src/generic/cases/ethereum_transaction.rs +++ b/runtime/integration-tests/src/cases/ethereum_transaction.rs @@ -5,7 +5,7 @@ use frame_support::{assert_err, assert_ok}; use pallet_evm::{ExitReason, ExitSucceed}; use sp_core::{H160, U256}; -use crate::generic::{ +use crate::{ config::Runtime, env::Env, envs::runtime_env::RuntimeEnv, diff --git a/runtime/integration-tests/src/generic/cases/example.rs b/runtime/integration-tests/src/cases/example.rs similarity index 95% rename from runtime/integration-tests/src/generic/cases/example.rs rename to runtime/integration-tests/src/cases/example.rs index 2268081251..9979c95a71 100644 --- a/runtime/integration-tests/src/generic/cases/example.rs +++ b/runtime/integration-tests/src/cases/example.rs @@ -4,16 +4,13 @@ use frame_support::traits::Get; use sp_api::runtime_decl_for_core::CoreV4; use crate::{ - generic::{ - config::Runtime, - env::{Blocks, Env}, - envs::{ - fudge_env::{FudgeEnv, FudgeSupport}, - runtime_env::RuntimeEnv, - }, - utils::genesis::Genesis, + config::Runtime, + env::{Blocks, Env}, + envs::{ + fudge_env::{FudgeEnv, FudgeSupport}, + runtime_env::RuntimeEnv, }, - utils::accounts::Keyring, + utils::{accounts::Keyring, genesis::Genesis}, }; #[test_runtimes([development, altair, centrifuge])] diff --git a/runtime/integration-tests/src/generic/cases/investments.rs b/runtime/integration-tests/src/cases/investments.rs similarity index 95% rename from runtime/integration-tests/src/generic/cases/investments.rs rename to runtime/integration-tests/src/cases/investments.rs index 3f2869ff3e..4e49f806f0 100644 --- a/runtime/integration-tests/src/generic/cases/investments.rs +++ b/runtime/integration-tests/src/cases/investments.rs @@ -12,18 +12,16 @@ use runtime_common::apis::{ use sp_core::Get; use crate::{ - generic::{ - config::Runtime, - env::{Blocks, Env}, - envs::runtime_env::RuntimeEnv, - utils::{ - self, - currency::{cfg, usd6, CurrencyInfo, Usd6}, - genesis::{self, Genesis}, - pool::POOL_MIN_EPOCH_TIME, - }, + config::Runtime, + env::{Blocks, Env}, + envs::runtime_env::RuntimeEnv, + utils::{ + self, + accounts::Keyring, + currency::{cfg, usd6, CurrencyInfo, Usd6}, + genesis::{self, Genesis}, + pool::POOL_MIN_EPOCH_TIME, }, - utils::accounts::Keyring, }; const POOL_ADMIN: Keyring = Keyring::Admin; diff --git a/runtime/integration-tests/src/generic/cases/liquidity_pools.rs b/runtime/integration-tests/src/cases/liquidity_pools.rs similarity index 92% rename from runtime/integration-tests/src/generic/cases/liquidity_pools.rs rename to runtime/integration-tests/src/cases/liquidity_pools.rs index b9da600a28..db171c340e 100644 --- a/runtime/integration-tests/src/generic/cases/liquidity_pools.rs +++ b/runtime/integration-tests/src/cases/liquidity_pools.rs @@ -3,7 +3,7 @@ use cfg_primitives::{ }; use cfg_traits::{ investments::{Investment, OrderManager, TrancheCurrency}, - liquidity_pools::{InboundQueue, OutboundQueue}, + liquidity_pools::InboundQueue, IdentityCurrencyConversion, Permissions, PoolInspect, PoolMutate, Seconds, }; use cfg_types::{ @@ -24,22 +24,20 @@ use frame_support::{ }, }; use liquidity_pools_gateway_routers::{ - AxelarEVMRouter, AxelarXCMRouter, DomainRouter, EVMDomain, EVMRouter, EthereumXCMRouter, - FeeValues, XCMRouter, XcmDomain, DEFAULT_PROOF_SIZE, MAX_AXELAR_EVM_CHAIN_SIZE, + DomainRouter, EthereumXCMRouter, XCMRouter, XcmDomain, DEFAULT_PROOF_SIZE, }; use orml_traits::MultiCurrency; use pallet_investments::CollectOutcome; use pallet_liquidity_pools::Message; use pallet_liquidity_pools_gateway::Call as LiquidityPoolsGatewayCall; use pallet_pool_system::tranches::{TrancheInput, TrancheLoc, TrancheType}; -use polkadot_core_primitives::BlakeTwo256; use runtime_common::{ account_conversion::AccountConverter, foreign_investments::IdentityPoolCurrencyConverter, xcm::general_key, }; -use sp_core::{Get, H160, U256}; +use sp_core::{Get, H160}; use sp_runtime::{ - traits::{AccountIdConversion, BadOrigin, ConstU32, Convert, EnsureAdd, Hash, One, Zero}, + traits::{AccountIdConversion, BadOrigin, Convert, EnsureAdd, One, Zero}, BoundedVec, DispatchError, FixedPointNumber, Perquintill, SaturatedConversion, }; use staging_xcm::{ @@ -48,13 +46,10 @@ use staging_xcm::{ }; use crate::{ - generic::{ - config::Runtime, - env::{Blocks, Env}, - envs::fudge_env::{handle::SIBLING_ID, FudgeEnv, FudgeSupport}, - utils::{genesis, genesis::Genesis, xcm::enable_para_to_sibling_communication}, - }, - utils::{accounts::Keyring, orml_asset_registry}, + config::Runtime, + env::Env, + envs::fudge_env::{handle::SIBLING_ID, FudgeEnv, FudgeSupport}, + utils::{accounts::Keyring, genesis, genesis::Genesis, orml_asset_registry}, }; /// The AUSD asset id @@ -245,9 +240,7 @@ mod utils { // 0.2 token fee_amount: 200000000000000000, }, - _marker: Default::default(), }, - _marker: Default::default(), }; let domain_router = DomainRouter::EthereumXCM(ethereum_xcm_router); @@ -462,7 +455,7 @@ mod utils { DEFAULT_VALIDITY, )), ) { - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( investor.clone(), pool_id, PoolRole::TrancheInvestor(default_tranche_id::(pool_id), DEFAULT_VALIDITY), @@ -555,7 +548,7 @@ mod utils { ); // Make investor the MembersListAdmin of this Pool - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( investor.clone(), pool_id, PoolRole::TrancheInvestor(default_tranche_id::(pool_id), DEFAULT_VALIDITY), @@ -665,20 +658,16 @@ mod utils { ::RuntimeOrigin::root(), Feeder::root(), )); - crate::generic::utils::oracle::update_feeders::( - POOL_ADMIN.id(), - POOL_ID, - [Feeder::root()], - ); + crate::utils::oracle::update_feeders::(POOL_ADMIN.id(), POOL_ID, [Feeder::root()]); if enable_foreign_to_pool_pair { - crate::generic::utils::oracle::feed_from_root::( + crate::utils::oracle::feed_from_root::( OracleKey::ConversionRatio(foreign_currency, pool_currency), Ratio::one(), ); } if enable_pool_to_foreign_pair { - crate::generic::utils::oracle::feed_from_root::( + crate::utils::oracle::feed_from_root::( OracleKey::ConversionRatio(pool_currency, foreign_currency), Ratio::one(), ); @@ -747,7 +736,7 @@ mod add_allow_upgrade { ); // Whitelist destination as TrancheInvestor of this Pool - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( AccountConverter::convert(new_member.clone()), pool_id, PoolRole::TrancheInvestor(default_tranche_id::(pool_id), DEFAULT_VALIDITY), @@ -3756,318 +3745,3 @@ mod foreign_investments { } } } - -mod routers { - use super::*; - - mod axelar_evm { - use std::ops::AddAssign; - - use super::*; - - #[test_runtimes([development])] - fn test_via_outbound_queue() { - let mut env = FudgeEnv::::from_parachain_storage( - Genesis::default() - .add(genesis::balances::(cfg(1_000))) - .storage(), - ); - - let test_domain = Domain::EVM(1); - - let axelar_contract_address = H160::from_low_u64_be(1); - let axelar_contract_code: Vec = vec![0, 0, 0]; - let axelar_contract_hash = BlakeTwo256::hash_of(&axelar_contract_code); - let liquidity_pools_contract_address = H160::from_low_u64_be(2); - - env.parachain_state_mut(|| { - pallet_evm::AccountCodes::::insert(axelar_contract_address, axelar_contract_code) - }); - - let transaction_call_cost = - env.parachain_state(|| ::config().gas_transaction_call); - - let evm_domain = EVMDomain { - target_contract_address: axelar_contract_address, - target_contract_hash: axelar_contract_hash, - fee_values: FeeValues { - value: U256::from(0), - gas_limit: U256::from(transaction_call_cost + 1_000_000), - gas_price: U256::from(10), - }, - }; - - let axelar_evm_router = AxelarEVMRouter:: { - router: EVMRouter { - evm_domain, - _marker: Default::default(), - }, - evm_chain: BoundedVec::>::try_from( - "ethereum".as_bytes().to_vec(), - ) - .unwrap(), - _marker: Default::default(), - liquidity_pools_contract_address, - }; - - let test_router = DomainRouter::::AxelarEVM(axelar_evm_router); - - env.parachain_state_mut(|| { - assert_ok!( - pallet_liquidity_pools_gateway::Pallet::::set_domain_router( - ::RuntimeOrigin::root(), - test_domain.clone(), - test_router, - ) - ); - }); - - let sender = Keyring::Alice.id(); - let gateway_sender = env - .parachain_state(|| ::Sender::get()); - - let gateway_sender_h160: H160 = H160::from_slice( - &>::as_ref(&gateway_sender)[0..20], - ); - - let msg = LiquidityPoolMessage::Transfer { - currency: 0, - sender: Keyring::Alice.id().into(), - receiver: Keyring::Bob.id().into(), - amount: 1_000u128, - }; - - // Failure - gateway sender account is not funded. - assert_ok!(env.parachain_state_mut(|| { - as OutboundQueue>::submit( - sender.clone(), - test_domain.clone(), - msg.clone(), - ) - })); - - let mut nonce = T::OutboundMessageNonce::one(); - - let expected_event = - pallet_liquidity_pools_gateway::Event::::OutboundMessageExecutionFailure { - sender: gateway_sender.clone(), - domain: test_domain.clone(), - message: msg.clone(), - error: pallet_evm::Error::::BalanceLow.into(), - nonce, - }; - - env.pass(Blocks::UntilEvent { - event: expected_event.clone().into(), - limit: 3, - }); - - env.check_event(expected_event) - .expect("expected RouterExecutionFailure event"); - - nonce.add_assign(T::OutboundMessageNonce::one()); - - assert_ok!(env.parachain_state_mut(|| { - // Note how both the target address and the gateway sender need to have some - // balance. - crate::generic::utils::evm::mint_balance_into_derived_account::( - axelar_contract_address, - cfg(1_000_000_000), - ); - crate::generic::utils::evm::mint_balance_into_derived_account::( - gateway_sender_h160, - cfg(1_000_000), - ); - - as OutboundQueue>::submit( - sender.clone(), - test_domain.clone(), - msg.clone(), - ) - })); - - let expected_event = - pallet_liquidity_pools_gateway::Event::::OutboundMessageExecutionSuccess { - sender: gateway_sender.clone(), - domain: test_domain.clone(), - message: msg.clone(), - nonce, - }; - - env.pass(Blocks::UntilEvent { - event: expected_event.clone().into(), - limit: 3, - }); - - env.check_event(expected_event) - .expect("expected OutboundMessageExecutionSuccess event"); - - // Router not found - let unused_domain = Domain::EVM(1234); - - env.parachain_state_mut(|| { - assert_noop!( - as OutboundQueue>::submit( - sender, - unused_domain.clone(), - msg, - ), - pallet_liquidity_pools_gateway::Error::::RouterNotFound - ); - }); - } - } - - mod ethereum_xcm { - use super::*; - - mod utils { - use super::*; - - pub fn submit_test_fn( - router_creation_fn: RouterCreationFn, - ) { - let mut env = FudgeEnv::::from_parachain_storage( - Genesis::default() - .add(genesis::balances::(cfg(1_000))) - .storage(), - ); - - setup_test(&mut env); - - enable_para_to_sibling_communication::(&mut env); - - let msg = Message::::Transfer { - currency: 0, - sender: Keyring::Alice.into(), - receiver: Keyring::Bob.into(), - amount: 1_000u128, - }; - - env.parachain_state_mut(|| { - let domain_router = router_creation_fn( - Location::new(1, Parachain(SIBLING_ID)).into(), - GLMR_CURRENCY_ID, - ); - - assert_ok!( - pallet_liquidity_pools_gateway::Pallet::::set_domain_router( - ::RuntimeOrigin::root(), - TEST_DOMAIN, - domain_router, - ) - ); - - assert_ok!( - as OutboundQueue>::submit( - Keyring::Alice.into(), - TEST_DOMAIN, - msg.clone(), - ) - ); - }); - - let gateway_sender = env.parachain_state(|| { - ::Sender::get() - }); - - let expected_event = - pallet_liquidity_pools_gateway::Event::::OutboundMessageExecutionSuccess { - sender: gateway_sender, - domain: TEST_DOMAIN, - message: msg, - nonce: T::OutboundMessageNonce::one(), - }; - - env.pass(Blocks::UntilEvent { - event: expected_event.clone().into(), - limit: 3, - }); - - env.check_event(expected_event) - .expect("expected OutboundMessageExecutionSuccess event"); - } - - type RouterCreationFn = - Box DomainRouter>; - - pub fn get_axelar_xcm_router_fn() -> RouterCreationFn { - Box::new( - |location: VersionedLocation, currency_id: CurrencyId| -> DomainRouter { - let router = AxelarXCMRouter:: { - router: XCMRouter { - xcm_domain: XcmDomain { - location: Box::new( - location.try_into().expect("Bad xcm domain location"), - ), - ethereum_xcm_transact_call_index: BoundedVec::truncate_from( - vec![38, 0], - ), - contract_address: H160::from_low_u64_be(11), - max_gas_limit: 700_000, - transact_required_weight_at_most: Default::default(), - overall_weight: Default::default(), - fee_currency: currency_id, - fee_amount: decimals(18).saturating_div(5), - }, - _marker: Default::default(), - }, - axelar_target_chain: BoundedVec::< - u8, - ConstU32, - >::try_from("ethereum".as_bytes().to_vec()) - .unwrap(), - axelar_target_contract: H160::from_low_u64_be(111), - _marker: Default::default(), - }; - - DomainRouter::AxelarXCM(router) - }, - ) - } - - pub fn get_ethereum_xcm_router_fn() -> RouterCreationFn { - Box::new( - |location: VersionedLocation, currency_id: CurrencyId| -> DomainRouter { - let router = EthereumXCMRouter:: { - router: XCMRouter { - xcm_domain: XcmDomain { - location: Box::new( - location.try_into().expect("Bad xcm domain location"), - ), - ethereum_xcm_transact_call_index: BoundedVec::truncate_from( - vec![38, 0], - ), - contract_address: H160::from_low_u64_be(11), - max_gas_limit: 700_000, - transact_required_weight_at_most: Default::default(), - overall_weight: Default::default(), - fee_currency: currency_id, - fee_amount: decimals(18).saturating_div(5), - }, - _marker: Default::default(), - }, - _marker: Default::default(), - }; - - DomainRouter::EthereumXCM(router) - }, - ) - } - } - - use utils::*; - - const TEST_DOMAIN: Domain = Domain::EVM(1); - - #[test_runtimes([development])] - fn submit_ethereum_xcm() { - submit_test_fn::(get_ethereum_xcm_router_fn::()); - } - - #[test_runtimes([development])] - fn submit_axelar_xcm() { - submit_test_fn::(get_axelar_xcm_router_fn::()); - } - } -} diff --git a/runtime/integration-tests/src/generic/cases/loans.rs b/runtime/integration-tests/src/cases/loans.rs similarity index 98% rename from runtime/integration-tests/src/generic/cases/loans.rs rename to runtime/integration-tests/src/cases/loans.rs index 61f6ce7349..91fdda814a 100644 --- a/runtime/integration-tests/src/generic/cases/loans.rs +++ b/runtime/integration-tests/src/cases/loans.rs @@ -34,18 +34,16 @@ use sp_runtime::FixedPointNumber; use sp_std::collections::btree_map::BTreeMap; use crate::{ - generic::{ - config::Runtime, - env::{Blocks, Env}, - envs::runtime_env::RuntimeEnv, - utils::{ - self, - currency::{self, cfg, usd6, CurrencyInfo, Usd6}, - genesis::{self, Genesis}, - pool::POOL_MIN_EPOCH_TIME, - }, + config::Runtime, + env::{Blocks, Env}, + envs::runtime_env::RuntimeEnv, + utils::{ + self, + accounts::Keyring, + currency::{self, cfg, usd6, CurrencyInfo, Usd6}, + genesis::{self, Genesis}, + pool::POOL_MIN_EPOCH_TIME, }, - utils::accounts::Keyring, }; const POOL_ADMIN: Keyring = Keyring::Admin; diff --git a/runtime/integration-tests/src/generic/cases/lp/investments.rs b/runtime/integration-tests/src/cases/lp/investments.rs similarity index 97% rename from runtime/integration-tests/src/generic/cases/lp/investments.rs rename to runtime/integration-tests/src/cases/lp/investments.rs index 773524a346..131e893ac8 100644 --- a/runtime/integration-tests/src/generic/cases/lp/investments.rs +++ b/runtime/integration-tests/src/cases/lp/investments.rs @@ -17,15 +17,13 @@ use sp_core::U256; use sp_runtime::traits::Zero; use crate::{ - generic::{ - cases::lp::{ - self, names, setup_full, - utils::{pool_c_tranche_1_id, Decoder}, - DECIMALS_6, POOL_C, - }, - config::Runtime, - env::{Blocks, Env, EnvEvmExtension, EvmEnv}, + cases::lp::{ + self, names, setup_full, + utils::{pool_c_tranche_1_id, Decoder}, + DECIMALS_6, POOL_C, }, + config::Runtime, + env::{Blocks, Env, EnvEvmExtension, EvmEnv}, utils::accounts::Keyring, }; @@ -40,13 +38,10 @@ mod utils { use sp_core::U256; use crate::{ - generic::{ - cases::lp::{investments::DEFAULT_INVESTMENT_AMOUNT, names, utils::Decoder}, - config::Runtime, - env::EvmEnv, - utils::{collect_investments, pool::close_epoch}, - }, - utils::accounts::Keyring, + cases::lp::{investments::DEFAULT_INVESTMENT_AMOUNT, names, utils::Decoder}, + config::Runtime, + env::EvmEnv, + utils::{accounts::Keyring, collect_investments, pool::close_epoch}, }; pub fn index_lp(evm: &mut impl EvmEnv, name: &str) -> GeneralCurrencyIndexType { @@ -168,7 +163,7 @@ mod utils { mod with_pool_currency { use super::{utils, *}; - use crate::generic::cases::lp::utils as lp_utils; + use crate::cases::lp::utils as lp_utils; #[test_runtimes(all)] fn currency_invest() { @@ -344,7 +339,7 @@ mod with_foreign_currency { }; use super::{utils, *}; - use crate::generic::cases::lp::{ + use crate::cases::lp::{ investments::utils::close_and_collect, utils as lp_utils, utils::pool_a_tranche_1_id, POOL_A, }; diff --git a/runtime/integration-tests/src/generic/cases/lp/mod.rs b/runtime/integration-tests/src/cases/lp/mod.rs similarity index 97% rename from runtime/integration-tests/src/generic/cases/lp/mod.rs rename to runtime/integration-tests/src/cases/lp/mod.rs index 87669e43ec..f3f1ec9188 100644 --- a/runtime/integration-tests/src/generic/cases/lp/mod.rs +++ b/runtime/integration-tests/src/cases/lp/mod.rs @@ -36,23 +36,19 @@ use sp_core::Get; use sp_runtime::traits::{BlakeTwo256, Hash}; use crate::{ - generic::{ - cases::lp::utils::{ - pool_a_tranche_1_id, pool_b_tranche_1_id, pool_b_tranche_2_id, Decoder, - }, - config::Runtime, - env::{Blocks, Env, EnvEvmExtension, EvmEnv}, - envs::runtime_env::RuntimeEnv, - utils::{ - currency::{register_currency, CurrencyInfo}, - genesis, - genesis::Genesis, - give_balance, - oracle::set_order_book_feeder, - tokens::evm_balances, - }, + cases::lp::utils::{pool_a_tranche_1_id, pool_b_tranche_1_id, pool_b_tranche_2_id, Decoder}, + config::Runtime, + env::{Blocks, Env, EnvEvmExtension, EvmEnv}, + envs::runtime_env::RuntimeEnv, + utils::{ + accounts::{default_investors, Keyring}, + currency::{register_currency, CurrencyInfo}, + genesis, + genesis::Genesis, + give_balance, + oracle::set_order_book_feeder, + tokens::evm_balances, }, - utils::accounts::{default_investors, Keyring}, }; pub mod investments; @@ -83,12 +79,9 @@ pub mod utils { }; use crate::{ - generic::{ - cases::lp::{EVM_DOMAIN_CHAIN_ID, POOL_A, POOL_B, POOL_C}, - config::Runtime, - utils::{evm::receipt_ok, last_event, pool::get_tranche_ids}, - }, - utils::accounts::Keyring, + cases::lp::{EVM_DOMAIN_CHAIN_ID, POOL_A, POOL_B, POOL_C}, + config::Runtime, + utils::{accounts::Keyring, evm::receipt_ok, last_event, pool::get_tranche_ids}, }; pub fn remote_account_of( @@ -1435,11 +1428,7 @@ pub fn setup_tranches(evm: &mut impl EvmEnv) { /// * Pool A with 1 tranche /// * Pool B with 2 tranches pub fn setup_pools(_evm: &mut impl EvmEnv) { - crate::generic::utils::pool::create_one_tranched::( - Keyring::Admin.into(), - POOL_A, - LocalUSDC.id(), - ); + crate::utils::pool::create_one_tranched::(Keyring::Admin.into(), POOL_A, LocalUSDC.id()); assert_ok!(pallet_liquidity_pools::Pallet::::add_pool( OriginFor::::signed(Keyring::Admin.into()), @@ -1449,11 +1438,7 @@ pub fn setup_pools(_evm: &mut impl EvmEnv) { utils::process_outbound::(utils::verify_outbound_success::); - crate::generic::utils::pool::create_two_tranched::( - Keyring::Admin.into(), - POOL_B, - LocalUSDC.id(), - ); + crate::utils::pool::create_two_tranched::(Keyring::Admin.into(), POOL_B, LocalUSDC.id()); assert_ok!(pallet_liquidity_pools::Pallet::::add_pool( OriginFor::::signed(Keyring::Admin.into()), @@ -1461,7 +1446,7 @@ pub fn setup_pools(_evm: &mut impl EvmEnv) { Domain::EVM(EVM_DOMAIN_CHAIN_ID) )); - crate::generic::utils::pool::create_one_tranched::(Keyring::Admin.into(), POOL_C, USDC.id()); + crate::utils::pool::create_one_tranched::(Keyring::Admin.into(), POOL_C, USDC.id()); assert_ok!(pallet_liquidity_pools::Pallet::::add_pool( OriginFor::::signed(Keyring::Admin.into()), @@ -1701,13 +1686,13 @@ pub fn setup_currencies(evm: &mut impl EvmEnv) { pub fn setup_investors(evm: &mut impl EvmEnv) { default_investors().into_iter().for_each(|investor| { // Allow investor to locally invest - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( investor.into(), POOL_A, PoolRole::TrancheInvestor(pool_a_tranche_1_id::(), SECONDS_PER_YEAR), ); // Centrifuge Chain setup: Add permissions and dispatch LP message - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( AccountConverter::convert_evm_address(EVM_DOMAIN_CHAIN_ID, investor.into()), POOL_A, PoolRole::TrancheInvestor(pool_a_tranche_1_id::(), SECONDS_PER_YEAR), @@ -1721,12 +1706,12 @@ pub fn setup_investors(evm: &mut impl EvmEnv) { )); // Allow investor to locally invest - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( investor.into(), POOL_B, PoolRole::TrancheInvestor(pool_b_tranche_1_id::(), SECONDS_PER_YEAR), ); - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( AccountConverter::convert_evm_address(EVM_DOMAIN_CHAIN_ID, investor.into()), POOL_B, PoolRole::TrancheInvestor(pool_b_tranche_1_id::(), SECONDS_PER_YEAR), @@ -1740,12 +1725,12 @@ pub fn setup_investors(evm: &mut impl EvmEnv) { )); // Allow investor to locally invest - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( investor.into(), POOL_B, PoolRole::TrancheInvestor(pool_b_tranche_2_id::(), SECONDS_PER_YEAR), ); - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( AccountConverter::convert_evm_address(EVM_DOMAIN_CHAIN_ID, investor.into()), POOL_B, PoolRole::TrancheInvestor(pool_b_tranche_2_id::(), SECONDS_PER_YEAR), @@ -1759,12 +1744,12 @@ pub fn setup_investors(evm: &mut impl EvmEnv) { )); // Allow investor to locally invest - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( investor.into(), POOL_C, PoolRole::TrancheInvestor(utils::pool_c_tranche_1_id::(), SECONDS_PER_YEAR), ); - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( AccountConverter::convert_evm_address(EVM_DOMAIN_CHAIN_ID, investor.into()), POOL_C, PoolRole::TrancheInvestor(utils::pool_c_tranche_1_id::(), SECONDS_PER_YEAR), diff --git a/runtime/integration-tests/src/generic/cases/lp/pool_management.rs b/runtime/integration-tests/src/cases/lp/pool_management.rs similarity index 97% rename from runtime/integration-tests/src/generic/cases/lp/pool_management.rs rename to runtime/integration-tests/src/cases/lp/pool_management.rs index e4ec810d97..6950fae46b 100644 --- a/runtime/integration-tests/src/generic/cases/lp/pool_management.rs +++ b/runtime/integration-tests/src/cases/lp/pool_management.rs @@ -25,17 +25,17 @@ use runtime_common::account_conversion::AccountConverter; use sp_runtime::FixedPointNumber; use crate::{ - generic::{ - cases::lp::{ - names, utils, - utils::{pool_a_tranche_1_id, Decoder}, - LocalUSDC, EVM_DOMAIN_CHAIN_ID, POOL_A, USDC, - }, - config::Runtime, - env::{EnvEvmExtension, EvmEnv}, - utils::currency::{register_currency, CurrencyInfo}, + cases::lp::{ + names, utils, + utils::{pool_a_tranche_1_id, Decoder}, + LocalUSDC, EVM_DOMAIN_CHAIN_ID, POOL_A, USDC, + }, + config::Runtime, + env::{EnvEvmExtension, EvmEnv}, + utils::{ + accounts::Keyring, + currency::{register_currency, CurrencyInfo}, }, - utils::accounts::Keyring, }; #[test_runtimes(all)] @@ -133,11 +133,7 @@ fn add_pool() { const POOL: PoolId = 1; env.state_mut(|evm| { - crate::generic::utils::pool::create_one_tranched::( - Keyring::Admin.into(), - POOL, - LocalUSDC.id(), - ); + crate::utils::pool::create_one_tranched::(Keyring::Admin.into(), POOL, LocalUSDC.id()); assert_ok!(pallet_liquidity_pools::Pallet::::add_pool( OriginFor::::signed(Keyring::Admin.into()), @@ -387,7 +383,7 @@ fn update_member() { }); env.state_mut(|_| { - crate::generic::utils::pool::give_role::( + crate::utils::pool::give_role::( AccountConverter::convert_evm_address(EVM_DOMAIN_CHAIN_ID, Keyring::Bob.into()), POOL_A, PoolRole::TrancheInvestor(pool_a_tranche_1_id::(), SECONDS_PER_YEAR), diff --git a/runtime/integration-tests/src/generic/cases/lp/transfers.rs b/runtime/integration-tests/src/cases/lp/transfers.rs similarity index 95% rename from runtime/integration-tests/src/generic/cases/lp/transfers.rs rename to runtime/integration-tests/src/cases/lp/transfers.rs index 0aff7d8415..a267c1a541 100644 --- a/runtime/integration-tests/src/generic/cases/lp/transfers.rs +++ b/runtime/integration-tests/src/cases/lp/transfers.rs @@ -23,17 +23,14 @@ use sp_core::ByteArray; use sp_runtime::traits::Convert; use crate::{ - generic::{ - cases::lp::{ - self, names, - utils::{as_h160_32bytes, pool_a_tranche_1_id, Decoder}, - LocalUSDC, DECIMALS_6, DEFAULT_BALANCE, EVM_DOMAIN_CHAIN_ID, POOL_A, USDC, - }, - config::Runtime, - env::{Blocks, Env, EnvEvmExtension, EvmEnv}, - utils::{currency::CurrencyInfo, give_tokens, invest_and_collect}, + cases::lp::{ + self, names, + utils::{as_h160_32bytes, pool_a_tranche_1_id, Decoder}, + LocalUSDC, DECIMALS_6, DEFAULT_BALANCE, EVM_DOMAIN_CHAIN_ID, POOL_A, USDC, }, - utils::accounts::Keyring, + config::Runtime, + env::{Blocks, Env, EnvEvmExtension, EvmEnv}, + utils::{accounts::Keyring, currency::CurrencyInfo, give_tokens, invest_and_collect}, }; // The default amount of invested stable coins diff --git a/runtime/integration-tests/src/generic/cases/oracles.rs b/runtime/integration-tests/src/cases/oracles.rs similarity index 99% rename from runtime/integration-tests/src/generic/cases/oracles.rs rename to runtime/integration-tests/src/cases/oracles.rs index d194c50ea8..12860cd147 100644 --- a/runtime/integration-tests/src/generic/cases/oracles.rs +++ b/runtime/integration-tests/src/cases/oracles.rs @@ -23,7 +23,7 @@ mod ratio_provider { use runtime_common::oracle::Feeder; use sp_runtime::{traits::One, FixedPointNumber}; - use crate::generic::{ + use crate::{ config::Runtime, env::Env, envs::runtime_env::RuntimeEnv, diff --git a/runtime/integration-tests/src/generic/cases/precompile.rs b/runtime/integration-tests/src/cases/precompile.rs similarity index 99% rename from runtime/integration-tests/src/generic/cases/precompile.rs rename to runtime/integration-tests/src/cases/precompile.rs index d7f71c405a..92086d3629 100644 --- a/runtime/integration-tests/src/generic/cases/precompile.rs +++ b/runtime/integration-tests/src/cases/precompile.rs @@ -15,7 +15,7 @@ use runtime_common::evm::precompile::LP_AXELAR_GATEWAY; use sp_core::{H160, H256, U256}; use sp_runtime::traits::{BlakeTwo256, Hash}; -use crate::generic::{ +use crate::{ config::Runtime, env::Env, envs::runtime_env::RuntimeEnv, diff --git a/runtime/integration-tests/src/generic/cases/proxy.rs b/runtime/integration-tests/src/cases/proxy.rs similarity index 96% rename from runtime/integration-tests/src/generic/cases/proxy.rs rename to runtime/integration-tests/src/cases/proxy.rs index a1ce753c5e..a3b1cb2268 100644 --- a/runtime/integration-tests/src/generic/cases/proxy.rs +++ b/runtime/integration-tests/src/cases/proxy.rs @@ -5,17 +5,15 @@ use sp_runtime::{traits::StaticLookup, DispatchResult}; use staging_xcm::v4::WeightLimit; use crate::{ - generic::{ - config::Runtime, - env::Env, - envs::runtime_env::RuntimeEnv, - utils::{ - currency::{cfg, CurrencyInfo, CustomCurrency}, - genesis::{self, Genesis}, - xcm::{account_location, transferable_metadata}, - }, + config::Runtime, + env::Env, + envs::runtime_env::RuntimeEnv, + utils::{ + accounts::Keyring, + currency::{cfg, CurrencyInfo, CustomCurrency}, + genesis::{self, Genesis}, + xcm::{account_location, transferable_metadata}, }, - utils::accounts::Keyring, }; const FROM: Keyring = Keyring::Charlie; diff --git a/runtime/integration-tests/src/generic/cases/restricted_transfers.rs b/runtime/integration-tests/src/cases/restricted_transfers.rs similarity index 97% rename from runtime/integration-tests/src/generic/cases/restricted_transfers.rs rename to runtime/integration-tests/src/cases/restricted_transfers.rs index 30f3e2d6e7..b1699afed5 100644 --- a/runtime/integration-tests/src/generic/cases/restricted_transfers.rs +++ b/runtime/integration-tests/src/cases/restricted_transfers.rs @@ -29,18 +29,16 @@ use staging_xcm::{ }; use crate::{ - generic::{ - config::Runtime, - env::Env, - envs::runtime_env::RuntimeEnv, - utils::{ - currency::{cfg, CurrencyInfo, CustomCurrency}, - genesis, - genesis::Genesis, - xcm::{account_location, transferable_metadata}, - }, + config::Runtime, + env::Env, + envs::runtime_env::RuntimeEnv, + utils::{ + accounts::Keyring, + currency::{cfg, CurrencyInfo, CustomCurrency}, + genesis, + genesis::Genesis, + xcm::{account_location, transferable_metadata}, }, - utils::accounts::Keyring, }; mod local { diff --git a/runtime/integration-tests/src/cases/routers.rs b/runtime/integration-tests/src/cases/routers.rs new file mode 100644 index 0000000000..eb07d58409 --- /dev/null +++ b/runtime/integration-tests/src/cases/routers.rs @@ -0,0 +1,180 @@ +use cfg_primitives::Balance; +use cfg_traits::liquidity_pools::OutboundQueue; +use cfg_types::{ + domain_address::Domain, + tokens::{AssetMetadata, CurrencyId}, +}; +use frame_support::{assert_ok, dispatch::RawOrigin}; +use liquidity_pools_gateway_routers::{ + AxelarEVMRouter, AxelarXCMRouter, DomainRouter, EVMDomain, EVMRouter, EthereumXCMRouter, + FeeValues, XCMRouter, XcmDomain, +}; +use pallet_liquidity_pools::MessageOf; +use polkadot_core_primitives::BlakeTwo256; +use runtime_common::gateway::get_gateway_h160_account; +use sp_core::{Get, H160, U256}; +use sp_runtime::{ + traits::{Hash, One}, + BoundedVec, +}; +use staging_xcm::v4::{Junction::*, Location}; + +use crate::{ + config::Runtime, + env::{Blocks, Env}, + envs::fudge_env::{handle::SIBLING_ID, FudgeEnv, FudgeSupport}, + utils::{ + self, + accounts::Keyring, + currency::{cfg, CurrencyInfo, CustomCurrency}, + genesis, + genesis::Genesis, + xcm::{enable_para_to_sibling_communication, transferable_metadata}, + }, +}; + +const INITIAL: Balance = 100; +const TEST_DOMAIN: Domain = Domain::EVM(1); + +const AXELAR_CONTRACT_ADDRESS: H160 = H160::repeat_byte(1); +const AXELAR_CONTRACT_CODE: &[u8] = &[0, 0, 0]; + +lazy_static::lazy_static! { + static ref CURR: CustomCurrency = CustomCurrency( + CurrencyId::ForeignAsset(1), + AssetMetadata { + decimals: 18, + ..transferable_metadata(Some(SIBLING_ID)) + }, + ); +} + +fn xcm_router() -> XCMRouter { + XCMRouter { + xcm_domain: XcmDomain { + location: Box::new(Location::new(1, Parachain(SIBLING_ID)).into()), + ethereum_xcm_transact_call_index: BoundedVec::truncate_from(vec![38, 0]), + contract_address: H160::from_low_u64_be(11), + max_gas_limit: 700_000, + transact_required_weight_at_most: Default::default(), + overall_weight: Default::default(), + fee_currency: CURR.id(), + fee_amount: CURR.val(1), + }, + } +} + +fn environment_for_evm() -> FudgeEnv { + let mut env = FudgeEnv::::from_parachain_storage( + Genesis::default() + .add(genesis::balances::(cfg(1_000))) + .storage(), + ); + + env.parachain_state_mut(|| { + pallet_evm::AccountCodes::::insert(AXELAR_CONTRACT_ADDRESS, AXELAR_CONTRACT_CODE); + + utils::evm::mint_balance_into_derived_account::(AXELAR_CONTRACT_ADDRESS, cfg(1)); + utils::evm::mint_balance_into_derived_account::(get_gateway_h160_account::(), cfg(1)); + }); + + env +} + +fn environment_for_xcm() -> FudgeEnv { + let mut env = FudgeEnv::::from_parachain_storage( + Genesis::default() + .add(genesis::balances::(cfg(1_000))) + .add(genesis::assets::([(CURR.id(), CURR.metadata())])) + .storage(), + ); + + enable_para_to_sibling_communication::(&mut env); + + env.parachain_state_mut(|| { + utils::give_tokens::(T::Sender::get(), CURR.id(), CURR.val(50)); + }); + + env +} + +fn check_submission(mut env: impl Env, domain_router: DomainRouter) { + let expected_event = env.parachain_state_mut(|| { + assert_ok!( + pallet_liquidity_pools_gateway::Pallet::::set_domain_router( + RawOrigin::Root.into(), + TEST_DOMAIN, + domain_router, + ) + ); + + let msg = MessageOf::::Transfer { + currency: 0, + sender: Keyring::Alice.into(), + receiver: Keyring::Bob.into(), + amount: 1_000, + }; + + assert_ok!( + as OutboundQueue>::submit( + Keyring::Alice.into(), + TEST_DOMAIN, + msg.clone(), + ) + ); + + pallet_liquidity_pools_gateway::Event::::OutboundMessageExecutionSuccess { + sender: T::Sender::get(), + domain: TEST_DOMAIN, + message: msg, + nonce: T::OutboundMessageNonce::one(), + } + }); + + env.pass(Blocks::UntilEvent { + event: expected_event.into(), + limit: 3, + }); +} + +#[test_runtimes(all)] +fn submit_by_axelar_evm() { + let router = DomainRouter::AxelarEVM(AxelarEVMRouter:: { + router: EVMRouter { + evm_domain: EVMDomain { + target_contract_address: AXELAR_CONTRACT_ADDRESS, + target_contract_hash: BlakeTwo256::hash_of(&AXELAR_CONTRACT_CODE), + fee_values: FeeValues { + value: U256::from(0), + gas_limit: U256::from(T::config().gas_transaction_call + 1_000_000), + gas_price: U256::from(10), + }, + }, + _marker: Default::default(), + }, + evm_chain: Vec::from(b"ethereum").try_into().unwrap(), + liquidity_pools_contract_address: H160::from_low_u64_be(2), + }); + + check_submission(environment_for_evm::(), router); +} + +#[test_runtimes(all)] +fn submit_by_ethereum_xcm() { + let router = DomainRouter::EthereumXCM(EthereumXCMRouter:: { + router: xcm_router(), + }); + + check_submission(environment_for_xcm::(), router); +} + +#[test_runtimes(all)] +fn submit_by_axelar_xcm() { + let router = DomainRouter::AxelarXCM(AxelarXCMRouter:: { + router: xcm_router(), + axelar_target_chain: Vec::from(b"ethereum").try_into().unwrap(), + axelar_target_contract: AXELAR_CONTRACT_ADDRESS, + }); + + check_submission(environment_for_xcm::(), router); +} diff --git a/runtime/integration-tests/src/generic/cases/xcm_transfers.rs b/runtime/integration-tests/src/cases/xcm_transfers.rs similarity index 92% rename from runtime/integration-tests/src/generic/cases/xcm_transfers.rs rename to runtime/integration-tests/src/cases/xcm_transfers.rs index 04f471144b..093ff65441 100644 --- a/runtime/integration-tests/src/generic/cases/xcm_transfers.rs +++ b/runtime/integration-tests/src/cases/xcm_transfers.rs @@ -4,25 +4,24 @@ use orml_traits::MultiCurrency; use staging_xcm::v4::{Junction::*, Junctions::Here, WeightLimit}; use crate::{ - generic::{ - config::Runtime, - env::{Blocks, Env}, - envs::fudge_env::{ - handle::{PARA_ID, SIBLING_ID}, - FudgeEnv, FudgeSupport, RelayRuntime, - }, - utils::{ - currency::{cfg, CurrencyInfo, CustomCurrency}, - genesis, - genesis::Genesis, - xcm::{ - account_location, enable_para_to_relay_communication, - enable_para_to_sibling_communication, enable_relay_to_para_communication, - transferable_metadata, - }, + config::Runtime, + env::{Blocks, Env}, + envs::fudge_env::{ + handle::{PARA_ID, SIBLING_ID}, + FudgeEnv, FudgeSupport, RelayRuntime, + }, + utils::{ + accounts::Keyring, + approx::Approximate, + currency::{cfg, CurrencyInfo, CustomCurrency}, + genesis, + genesis::Genesis, + xcm::{ + account_location, enable_para_to_relay_communication, + enable_para_to_sibling_communication, enable_relay_to_para_communication, + transferable_metadata, }, }, - utils::{accounts::Keyring, approx::Approximate}, }; const INITIAL: u32 = 100; diff --git a/runtime/integration-tests/src/generic/config.rs b/runtime/integration-tests/src/config.rs similarity index 99% rename from runtime/integration-tests/src/generic/config.rs rename to runtime/integration-tests/src/config.rs index cbb6c00aae..8c026eb113 100644 --- a/runtime/integration-tests/src/generic/config.rs +++ b/runtime/integration-tests/src/config.rs @@ -298,6 +298,7 @@ pub trait Runtime: frame_system::CheckNonce, frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, + frame_metadata_hash_extension::CheckMetadataHash, runtime_common::transfer_filter::PreBalanceTransferExtension, ), >, diff --git a/runtime/integration-tests/src/generic/env.rs b/runtime/integration-tests/src/env.rs similarity index 95% rename from runtime/integration-tests/src/generic/env.rs rename to runtime/integration-tests/src/env.rs index c6e58ed7f2..fd1666ac16 100644 --- a/runtime/integration-tests/src/generic/env.rs +++ b/runtime/integration-tests/src/env.rs @@ -12,11 +12,11 @@ use sp_runtime::{ use sp_std::ops::Range; use crate::{ - generic::{ - config::Runtime, - utils::evm::{ContractInfo, DeployedContractInfo}, + config::Runtime, + utils::{ + accounts::Keyring, + evm::{ContractInfo, DeployedContractInfo}, }, - utils::accounts::Keyring, }; /// Used by Env::pass() to determine how many blocks should be passed @@ -111,15 +111,23 @@ pub trait Env: Default { ) }); + let mut found_event = false; for i in blocks.range_for(current, slot) { self.__priv_build_block(i); if let Blocks::UntilEvent { event, .. } = blocks.clone() { if self.check_event(event).is_some() { + found_event = true; break; } } } + + if let Blocks::UntilEvent { event, limit } = blocks.clone() { + if !found_event { + panic!("Event {event:?} was not found producing {limit} blocks"); + } + } } /// Allows to mutate the relay storage state through the closure. @@ -247,6 +255,7 @@ pub mod utils { frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(0), + frame_metadata_hash_extension::CheckMetadataHash::::new(false), runtime_common::transfer_filter::PreBalanceTransferExtension::::new(), ); diff --git a/runtime/integration-tests/src/generic/envs/evm_env.rs b/runtime/integration-tests/src/envs/evm_env.rs similarity index 97% rename from runtime/integration-tests/src/generic/envs/evm_env.rs rename to runtime/integration-tests/src/envs/evm_env.rs index cdcf52cc59..b753474a7b 100644 --- a/runtime/integration-tests/src/generic/envs/evm_env.rs +++ b/runtime/integration-tests/src/envs/evm_env.rs @@ -6,16 +6,14 @@ use sp_core::{H160, U256}; use sp_runtime::DispatchError; use crate::{ - generic::{ - config::Runtime, - env, - utils::{ - evm, - evm::{ContractInfo, DeployedContractInfo}, - ESSENTIAL, - }, + config::Runtime, + env, + utils::{ + accounts::Keyring, + evm, + evm::{ContractInfo, DeployedContractInfo}, + ESSENTIAL, }, - utils::accounts::Keyring, }; const GAS_LIMIT: u64 = 105_000_000; diff --git a/runtime/integration-tests/src/generic/envs/fudge_env.rs b/runtime/integration-tests/src/envs/fudge_env.rs similarity index 97% rename from runtime/integration-tests/src/generic/envs/fudge_env.rs rename to runtime/integration-tests/src/envs/fudge_env.rs index 4c9cc28d0c..87cb2cc993 100644 --- a/runtime/integration-tests/src/generic/envs/fudge_env.rs +++ b/runtime/integration-tests/src/envs/fudge_env.rs @@ -11,10 +11,8 @@ use sp_core::H256; use sp_runtime::{DispatchError, Storage}; use crate::{ - generic::{ - config::Runtime, - env::{utils, Env}, - }, + config::Runtime, + env::{utils, Env}, utils::accounts::Keyring, }; @@ -154,7 +152,7 @@ mod tests { use cfg_primitives::CFG; use super::*; - use crate::generic::{env::Blocks, utils::genesis::Genesis}; + use crate::{env::Blocks, utils::genesis::Genesis}; #[test_runtimes(all)] fn correct_nonce_for_submit_later() { diff --git a/runtime/integration-tests/src/generic/envs/fudge_env/handle.rs b/runtime/integration-tests/src/envs/fudge_env/handle.rs similarity index 99% rename from runtime/integration-tests/src/generic/envs/fudge_env/handle.rs rename to runtime/integration-tests/src/envs/fudge_env/handle.rs index 07d3af10e7..f22330c9d4 100644 --- a/runtime/integration-tests/src/generic/envs/fudge_env/handle.rs +++ b/runtime/integration-tests/src/envs/fudge_env/handle.rs @@ -27,7 +27,7 @@ use sp_runtime::{BuildStorage, Storage}; use sp_transaction_pool::runtime_api::TaggedTransactionQueue; use tokio::runtime::Handle; -use crate::generic::config::Runtime; +use crate::config::Runtime; /// Start date used for timestamps in test-enviornments /// Sat Jan 01 2022 00:00:00 GMT+0000 diff --git a/runtime/integration-tests/src/generic/envs/runtime_env.rs b/runtime/integration-tests/src/envs/runtime_env.rs similarity index 98% rename from runtime/integration-tests/src/generic/envs/runtime_env.rs rename to runtime/integration-tests/src/envs/runtime_env.rs index 3a339b8eb2..dc066afb86 100644 --- a/runtime/integration-tests/src/generic/envs/runtime_env.rs +++ b/runtime/integration-tests/src/envs/runtime_env.rs @@ -24,11 +24,9 @@ use sp_runtime::{ use sp_timestamp::Timestamp; use crate::{ - generic::{ - config::Runtime, - env::{utils, Env, EnvEvmExtension}, - envs::evm_env::EvmEnv, - }, + config::Runtime, + env::{utils, Env, EnvEvmExtension}, + envs::evm_env::EvmEnv, utils::accounts::Keyring, }; @@ -308,7 +306,7 @@ mod tests { use cfg_primitives::CFG; use super::*; - use crate::generic::{env::Blocks, utils::genesis::Genesis}; + use crate::{env::Blocks, utils::genesis::Genesis}; #[test_runtimes(all)] fn correct_nonce_for_submit_now() { diff --git a/runtime/integration-tests/src/generic/mod.rs b/runtime/integration-tests/src/generic/mod.rs deleted file mode 100644 index 4dc2de2226..0000000000 --- a/runtime/integration-tests/src/generic/mod.rs +++ /dev/null @@ -1,61 +0,0 @@ -pub mod env; -pub mod envs { - pub mod evm_env; - pub mod fudge_env; - pub mod runtime_env; -} -pub mod config; -mod impls; -pub mod utils; - -// Test cases -mod cases { - mod account_derivation; - mod assets; - mod block_rewards; - mod currency_conversions; - mod ethereum_transaction; - mod example; - mod investments; - mod liquidity_pools; - mod loans; - mod lp; - mod oracles; - mod precompile; - mod proxy; - mod restricted_transfers; - mod xcm_transfers; -} - -/// Generate tests for the specified runtimes or all runtimes. -/// Usage. Used as building block for #[test_runtimes] procedural macro. -/// -/// NOTE: Do not use it direclty, use `#[test_runtimes]` proc macro instead -#[macro_export] -macro_rules! __test_for_runtimes { - ( [ $($runtime_name:ident),* ], $test_name:ident ) => { - #[cfg(test)] - mod $test_name { - use super::*; - - #[allow(unused)] - use development_runtime as development; - - #[allow(unused)] - use altair_runtime as altair; - - #[allow(unused)] - use centrifuge_runtime as centrifuge; - - $( - #[tokio::test] - async fn $runtime_name() { - $test_name::<$runtime_name::Runtime>() - } - )* - } - }; - ( all , $test_name:ident ) => { - $crate::__test_for_runtimes!([development, altair, centrifuge], $test_name); - }; -} diff --git a/runtime/integration-tests/src/generic/utils/mod.rs b/runtime/integration-tests/src/generic/utils/mod.rs deleted file mode 100644 index ddc868451d..0000000000 --- a/runtime/integration-tests/src/generic/utils/mod.rs +++ /dev/null @@ -1,227 +0,0 @@ -//! PLEASE be as much generic as possible because no domain or use cases are -//! considered at util level and below modules. If you need utilities related to -//! your use case, add them under `cases/`. -//! -//! Trying to use methods that map to real extrinsic will make easy life to -//! frontend applications, having a source of the real calls they can replicate -//! to simulate some scenarios. -//! -//! Divide this utilities into files when it grows - -pub mod currency; -pub mod evm; -pub mod genesis; -pub mod pool; -pub mod tokens; -pub mod xcm; - -use cfg_primitives::{AccountId, Balance, CollectionId, ItemId, PoolId, TrancheId}; -use cfg_traits::{investments::TrancheCurrency as _, Seconds, TimeAsSecs}; -use cfg_types::{ - fixed_point::Ratio, - oracles::OracleKey, - tokens::{CurrencyId, TrancheCurrency}, -}; -use frame_system::RawOrigin; -use pallet_oracle_collection::types::CollectionInfo; -use runtime_common::oracle::Feeder; -use sp_runtime::traits::StaticLookup; - -use crate::{ - generic::{config::Runtime, utils::pool::close_epoch}, - utils::accounts::Keyring, -}; - -pub const ESSENTIAL: &str = - "Essential part of the test codebase failed. Assumed infallible under sane circumstances"; - -pub fn now_secs() -> Seconds { - as TimeAsSecs>::now() -} - -pub fn find_event(f: impl Fn(E) -> Option) -> Option -where - T::RuntimeEventExt: TryInto, -{ - frame_system::Pallet::::events() - .into_iter() - .rev() - .find_map(|record| record.event.try_into().map(|e| f(e)).ok()) - .flatten() -} - -pub fn last_event() -> E -where - T::RuntimeEventExt: TryInto, -{ - frame_system::Pallet::::events() - .pop() - .unwrap() - .event - .try_into() - .ok() - .unwrap() -} - -pub fn give_nft(dest: AccountId, (collection_id, item_id): (CollectionId, ItemId)) { - pallet_uniques::Pallet::::force_create( - RawOrigin::Root.into(), - collection_id, - T::Lookup::unlookup(dest.clone()), - true, - ) - .unwrap(); - - pallet_uniques::Pallet::::mint( - RawOrigin::Signed(dest.clone()).into(), - collection_id, - item_id, - T::Lookup::unlookup(dest), - ) - .unwrap() -} - -pub fn give_balance(dest: AccountId, amount: Balance) { - let data = pallet_balances::Account::::get(dest.clone()); - pallet_balances::Pallet::::force_set_balance( - RawOrigin::Root.into(), - T::Lookup::unlookup(dest), - data.free + amount, - ) - .unwrap(); -} - -pub fn give_tokens(dest: AccountId, currency_id: CurrencyId, amount: Balance) { - let data = orml_tokens::Accounts::::get(dest.clone(), currency_id); - orml_tokens::Pallet::::set_balance( - RawOrigin::Root.into(), - T::Lookup::unlookup(dest), - currency_id, - data.free + amount, - data.reserved, - ) - .unwrap(); -} - -pub fn invest( - investor: AccountId, - pool_id: PoolId, - tranche_id: TrancheId, - amount: Balance, -) { - pallet_investments::Pallet::::update_invest_order( - RawOrigin::Signed(investor).into(), - TrancheCurrency::generate(pool_id, tranche_id), - amount, - ) - .unwrap(); -} - -pub fn redeem( - investor: AccountId, - pool_id: PoolId, - tranche_id: TrancheId, - amount: Balance, -) { - pallet_investments::Pallet::::update_redeem_order( - RawOrigin::Signed(investor).into(), - TrancheCurrency::generate(pool_id, tranche_id), - amount, - ) - .unwrap(); -} - -pub fn collect_investments( - investor: AccountId, - pool_id: PoolId, - tranche_id: TrancheId, -) { - pallet_investments::Pallet::::collect_investments( - RawOrigin::Signed(investor).into(), - TrancheCurrency::generate(pool_id, tranche_id), - ) - .unwrap(); -} - -pub fn collect_redemptions( - investor: AccountId, - pool_id: PoolId, - tranche_id: TrancheId, -) { - pallet_investments::Pallet::::collect_redemptions( - RawOrigin::Signed(investor).into(), - TrancheCurrency::generate(pool_id, tranche_id), - ) - .unwrap(); -} - -pub fn invest_and_collect( - investor: AccountId, - admin: Keyring, - pool_id: PoolId, - tranche_id: TrancheId, - amount: Balance, -) { - invest::(investor.clone(), pool_id, tranche_id, amount); - close_epoch::(admin.into(), pool_id); - collect_investments::(investor, pool_id, tranche_id); -} - -pub fn last_change_id() -> T::Hash { - find_event::(|e| match e { - pallet_pool_system::Event::::ProposedChange { change_id, .. } => Some(change_id), - _ => None, - }) - .unwrap() -} - -pub mod oracle { - use frame_support::traits::OriginTrait; - - use super::*; - - pub fn set_order_book_feeder(origin: T::RuntimeOriginExt) { - pallet_order_book::Pallet::::set_market_feeder( - T::RuntimeOriginExt::root(), - Feeder(origin.into_caller()), - ) - .unwrap() - } - - pub fn feed_from_root(key: OracleKey, value: Ratio) { - pallet_oracle_feed::Pallet::::feed(RawOrigin::Root.into(), key, value).unwrap(); - } - - pub fn update_feeders( - admin: AccountId, - pool_id: PoolId, - feeders: impl IntoIterator>, - ) { - pallet_oracle_collection::Pallet::::propose_update_collection_info( - RawOrigin::Signed(admin.clone()).into(), - pool_id, - CollectionInfo { - feeders: pallet_oracle_collection::util::feeders_from(feeders).unwrap(), - ..Default::default() - }, - ) - .unwrap(); - - let change_id = last_change_id::(); - - pallet_oracle_collection::Pallet::::apply_update_collection_info( - RawOrigin::Signed(admin).into(), //or any account - pool_id, - change_id, - ) - .unwrap(); - } - - pub fn update_collection(any: AccountId, pool_id: PoolId) { - pallet_oracle_collection::Pallet::::update_collection( - RawOrigin::Signed(any).into(), - pool_id, - ) - .unwrap(); - } -} diff --git a/runtime/integration-tests/src/generic/impls.rs b/runtime/integration-tests/src/impls.rs similarity index 97% rename from runtime/integration-tests/src/generic/impls.rs rename to runtime/integration-tests/src/impls.rs index 8c0791ac0d..27db638e2c 100644 --- a/runtime/integration-tests/src/generic/impls.rs +++ b/runtime/integration-tests/src/impls.rs @@ -10,7 +10,7 @@ macro_rules! impl_runtime { const _: () = { use sp_core::sr25519::Public; - use crate::generic::config::{Runtime, RuntimeKind}; + use crate::config::{Runtime, RuntimeKind}; impl Runtime for $runtime_path::Runtime { type Api = Self; @@ -53,7 +53,7 @@ macro_rules! impl_fudge_support { use sp_api::ConstructRuntimeApi; use sp_runtime::Storage; - use crate::generic::envs::fudge_env::{ + use crate::envs::fudge_env::{ handle::{ FudgeHandle, ParachainBuilder, ParachainClient, RelayClient, RelaychainBuilder, PARA_ID, SIBLING_ID, @@ -74,7 +74,7 @@ macro_rules! impl_fudge_support { pub sibling: ParachainBuilder<$parachain_path::Block, $parachain_path::RuntimeApi>, } - // Implement for T only one time when fudge::companion + // TODO: Implement for T only one time when fudge::companion // supports generic in the struct signature. impl FudgeHandle<$parachain_path::Runtime> for $fudge_companion_type { type ParachainApi = <$parachain_path::RuntimeApi as ConstructRuntimeApi< diff --git a/runtime/integration-tests/src/lib.rs b/runtime/integration-tests/src/lib.rs index 76a1eb4c3f..459781a7e1 100644 --- a/runtime/integration-tests/src/lib.rs +++ b/runtime/integration-tests/src/lib.rs @@ -20,5 +20,46 @@ #[macro_use] extern crate runtime_integration_tests_proc_macro; -mod generic; +mod cases; +mod env; mod utils; +mod envs { + pub mod evm_env; + pub mod fudge_env; + pub mod runtime_env; +} +mod config; +mod impls; + +/// Generate tests for the specified runtimes or all runtimes. +/// Usage. Used as building block for #[test_runtimes] procedural macro. +/// +/// NOTE: Do not use it direclty, use `#[test_runtimes]` proc macro instead +#[macro_export] +macro_rules! __test_for_runtimes { + ( [ $($runtime_name:ident),* ], $test_name:ident ) => { + #[cfg(test)] + mod $test_name { + use super::*; + + #[allow(unused)] + use development_runtime as development; + + #[allow(unused)] + use altair_runtime as altair; + + #[allow(unused)] + use centrifuge_runtime as centrifuge; + + $( + #[tokio::test] + async fn $runtime_name() { + $test_name::<$runtime_name::Runtime>() + } + )* + } + }; + ( all , $test_name:ident ) => { + $crate::__test_for_runtimes!([development, altair, centrifuge], $test_name); + }; +} diff --git a/runtime/integration-tests/src/generic/utils/currency.rs b/runtime/integration-tests/src/utils/currency.rs similarity index 99% rename from runtime/integration-tests/src/generic/utils/currency.rs rename to runtime/integration-tests/src/utils/currency.rs index 40e0a3d2da..9cad254c4d 100644 --- a/runtime/integration-tests/src/generic/utils/currency.rs +++ b/runtime/integration-tests/src/utils/currency.rs @@ -7,7 +7,7 @@ use frame_support::{assert_ok, traits::OriginTrait}; use sp_runtime::FixedPointNumber; use staging_xcm::VersionedLocation; -use crate::generic::config::Runtime; +use crate::config::Runtime; const fn amount_pow(amount: Balance, exp: u32) -> Balance { amount * 10u128.pow(exp) diff --git a/runtime/integration-tests/src/generic/utils/evm.rs b/runtime/integration-tests/src/utils/evm.rs similarity index 99% rename from runtime/integration-tests/src/generic/utils/evm.rs rename to runtime/integration-tests/src/utils/evm.rs index 9b486e4fec..4c91a4aef9 100644 --- a/runtime/integration-tests/src/generic/utils/evm.rs +++ b/runtime/integration-tests/src/utils/evm.rs @@ -12,7 +12,7 @@ use pallet_evm::FeeCalculator; use runtime_common::account_conversion::AccountConverter; use sp_runtime::traits::Get; -use crate::generic::{config::Runtime, utils::ESSENTIAL}; +use crate::{config::Runtime, utils::ESSENTIAL}; /// Liquidity-Pool solidity artifacts generated by build-script. /// All needed contracts can be loaded from here. diff --git a/runtime/integration-tests/src/generic/utils/genesis.rs b/runtime/integration-tests/src/utils/genesis.rs similarity index 99% rename from runtime/integration-tests/src/generic/utils/genesis.rs rename to runtime/integration-tests/src/utils/genesis.rs index 1648a95ba7..d6a721d0b5 100644 --- a/runtime/integration-tests/src/generic/utils/genesis.rs +++ b/runtime/integration-tests/src/utils/genesis.rs @@ -11,7 +11,7 @@ use sp_core::Get; use sp_runtime::{BuildStorage, FixedPointNumber, Storage}; use crate::{ - generic::config::Runtime, + config::Runtime, utils::accounts::{default_accounts, Keyring}, }; diff --git a/runtime/integration-tests/src/utils/mod.rs b/runtime/integration-tests/src/utils/mod.rs index 3ee465c7a6..3dc636ce3d 100644 --- a/runtime/integration-tests/src/utils/mod.rs +++ b/runtime/integration-tests/src/utils/mod.rs @@ -10,8 +10,33 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +// Divide this utilities into files when it grows + pub mod accounts; +pub mod currency; +pub mod evm; +pub mod genesis; pub mod logs; +pub mod pool; +pub mod tokens; +pub mod xcm; + +use cfg_primitives::{AccountId, Balance, CollectionId, ItemId, PoolId, TrancheId}; +use cfg_traits::{investments::TrancheCurrency as _, Seconds, TimeAsSecs}; +use cfg_types::{ + fixed_point::Ratio, + oracles::OracleKey, + tokens::{CurrencyId, TrancheCurrency}, +}; +use frame_system::RawOrigin; +use pallet_oracle_collection::types::CollectionInfo; +use runtime_common::oracle::Feeder; +use sp_runtime::traits::StaticLookup; + +use crate::{ + config::Runtime, + utils::{accounts::Keyring, pool::close_epoch}, +}; pub mod orml_asset_registry { // orml_asset_registry has remove the reexport of all pallet stuff, @@ -82,3 +107,197 @@ pub mod approx { assert_ne!(1000u128, 1500.approx(0.1)); } } + +pub const ESSENTIAL: &str = + "Essential part of the test codebase failed. Assumed infallible under sane circumstances"; + +pub fn now_secs() -> Seconds { + as TimeAsSecs>::now() +} + +pub fn find_event(f: impl Fn(E) -> Option) -> Option +where + T::RuntimeEventExt: TryInto, +{ + frame_system::Pallet::::events() + .into_iter() + .rev() + .find_map(|record| record.event.try_into().map(|e| f(e)).ok()) + .flatten() +} + +pub fn last_event() -> E +where + T::RuntimeEventExt: TryInto, +{ + frame_system::Pallet::::events() + .pop() + .unwrap() + .event + .try_into() + .ok() + .unwrap() +} + +pub fn give_nft(dest: AccountId, (collection_id, item_id): (CollectionId, ItemId)) { + pallet_uniques::Pallet::::force_create( + RawOrigin::Root.into(), + collection_id, + T::Lookup::unlookup(dest.clone()), + true, + ) + .unwrap(); + + pallet_uniques::Pallet::::mint( + RawOrigin::Signed(dest.clone()).into(), + collection_id, + item_id, + T::Lookup::unlookup(dest), + ) + .unwrap() +} + +pub fn give_balance(dest: AccountId, amount: Balance) { + let data = pallet_balances::Account::::get(dest.clone()); + pallet_balances::Pallet::::force_set_balance( + RawOrigin::Root.into(), + T::Lookup::unlookup(dest), + data.free + amount, + ) + .unwrap(); +} + +pub fn give_tokens(dest: AccountId, currency_id: CurrencyId, amount: Balance) { + let data = orml_tokens::Accounts::::get(dest.clone(), currency_id); + orml_tokens::Pallet::::set_balance( + RawOrigin::Root.into(), + T::Lookup::unlookup(dest), + currency_id, + data.free + amount, + data.reserved, + ) + .unwrap(); +} + +pub fn invest( + investor: AccountId, + pool_id: PoolId, + tranche_id: TrancheId, + amount: Balance, +) { + pallet_investments::Pallet::::update_invest_order( + RawOrigin::Signed(investor).into(), + TrancheCurrency::generate(pool_id, tranche_id), + amount, + ) + .unwrap(); +} + +pub fn redeem( + investor: AccountId, + pool_id: PoolId, + tranche_id: TrancheId, + amount: Balance, +) { + pallet_investments::Pallet::::update_redeem_order( + RawOrigin::Signed(investor).into(), + TrancheCurrency::generate(pool_id, tranche_id), + amount, + ) + .unwrap(); +} + +pub fn collect_investments( + investor: AccountId, + pool_id: PoolId, + tranche_id: TrancheId, +) { + pallet_investments::Pallet::::collect_investments( + RawOrigin::Signed(investor).into(), + TrancheCurrency::generate(pool_id, tranche_id), + ) + .unwrap(); +} + +pub fn collect_redemptions( + investor: AccountId, + pool_id: PoolId, + tranche_id: TrancheId, +) { + pallet_investments::Pallet::::collect_redemptions( + RawOrigin::Signed(investor).into(), + TrancheCurrency::generate(pool_id, tranche_id), + ) + .unwrap(); +} + +pub fn invest_and_collect( + investor: AccountId, + admin: Keyring, + pool_id: PoolId, + tranche_id: TrancheId, + amount: Balance, +) { + invest::(investor.clone(), pool_id, tranche_id, amount); + close_epoch::(admin.into(), pool_id); + collect_investments::(investor, pool_id, tranche_id); +} + +pub fn last_change_id() -> T::Hash { + find_event::(|e| match e { + pallet_pool_system::Event::::ProposedChange { change_id, .. } => Some(change_id), + _ => None, + }) + .unwrap() +} + +pub mod oracle { + use frame_support::traits::OriginTrait; + + use super::*; + + pub fn set_order_book_feeder(origin: T::RuntimeOriginExt) { + pallet_order_book::Pallet::::set_market_feeder( + T::RuntimeOriginExt::root(), + Feeder(origin.into_caller()), + ) + .unwrap() + } + + pub fn feed_from_root(key: OracleKey, value: Ratio) { + pallet_oracle_feed::Pallet::::feed(RawOrigin::Root.into(), key, value).unwrap(); + } + + pub fn update_feeders( + admin: AccountId, + pool_id: PoolId, + feeders: impl IntoIterator>, + ) { + pallet_oracle_collection::Pallet::::propose_update_collection_info( + RawOrigin::Signed(admin.clone()).into(), + pool_id, + CollectionInfo { + feeders: pallet_oracle_collection::util::feeders_from(feeders).unwrap(), + ..Default::default() + }, + ) + .unwrap(); + + let change_id = last_change_id::(); + + pallet_oracle_collection::Pallet::::apply_update_collection_info( + RawOrigin::Signed(admin).into(), //or any account + pool_id, + change_id, + ) + .unwrap(); + } + + pub fn update_collection(any: AccountId, pool_id: PoolId) { + pallet_oracle_collection::Pallet::::update_collection( + RawOrigin::Signed(any).into(), + pool_id, + ) + .unwrap(); + } +} diff --git a/runtime/integration-tests/src/generic/utils/pool.rs b/runtime/integration-tests/src/utils/pool.rs similarity index 98% rename from runtime/integration-tests/src/generic/utils/pool.rs rename to runtime/integration-tests/src/utils/pool.rs index f22f10fe8d..ffa4fca521 100644 --- a/runtime/integration-tests/src/generic/utils/pool.rs +++ b/runtime/integration-tests/src/utils/pool.rs @@ -25,7 +25,7 @@ use sp_runtime::{ FixedPointNumber, FixedPointOperand, Perquintill, }; -use crate::generic::config::{Runtime, RuntimeKind}; +use crate::config::{Runtime, RuntimeKind}; pub const POOL_MIN_EPOCH_TIME: Seconds = 24; diff --git a/runtime/integration-tests/src/generic/utils/tokens.rs b/runtime/integration-tests/src/utils/tokens.rs similarity index 95% rename from runtime/integration-tests/src/generic/utils/tokens.rs rename to runtime/integration-tests/src/utils/tokens.rs index 8ea7ab93d2..5f10b5b955 100644 --- a/runtime/integration-tests/src/generic/utils/tokens.rs +++ b/runtime/integration-tests/src/utils/tokens.rs @@ -15,7 +15,7 @@ use cfg_primitives::Balance; use cfg_types::tokens::CurrencyId; use frame_support::traits::{fungible::Mutate as _, fungibles::Mutate as _}; -use crate::{generic::config::Runtime, utils::accounts::default_accounts}; +use crate::{config::Runtime, utils::accounts::default_accounts}; pub fn evm_balances(balance: Balance) { let mut accounts = Vec::new(); diff --git a/runtime/integration-tests/src/generic/utils/xcm.rs b/runtime/integration-tests/src/utils/xcm.rs similarity index 99% rename from runtime/integration-tests/src/generic/utils/xcm.rs rename to runtime/integration-tests/src/utils/xcm.rs index 0380bf0ddf..615c283109 100644 --- a/runtime/integration-tests/src/generic/utils/xcm.rs +++ b/runtime/integration-tests/src/utils/xcm.rs @@ -10,7 +10,7 @@ use staging_xcm::{ VersionedLocation, }; -use crate::generic::{ +use crate::{ config::Runtime, env::{Blocks, Env}, envs::fudge_env::{ diff --git a/scripts/export_parachain_files.sh b/scripts/export_parachain_files.sh index 8fef73db32..74b8ebbce2 100755 --- a/scripts/export_parachain_files.sh +++ b/scripts/export_parachain_files.sh @@ -25,5 +25,5 @@ if [[ $should_build == "true" ]]; then fi echo "Exporting State & Wasm" -$PWD/target/release/centrifuge-chain export-genesis-state --chain node/res/$chain_name-spec-raw.json > $chain_name-genesis-state +$PWD/target/release/centrifuge-chain export-genesis-head --chain node/res/$chain_name-spec-raw.json > $chain_name-genesis-state $PWD/target/release/centrifuge-chain export-genesis-wasm --chain node/res/$chain_name-spec-raw.json > $chain_name-genesis-wasm