-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
89 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ mod governance; | |
mod oracle; | ||
mod reserve_backed_transfers; | ||
mod vest; | ||
mod xcm_config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use crate::{PolimecAccountId, PolimecCall, PolimecForeignAssets, PolimecNet, PolimecRuntime}; | ||
use parity_scale_codec::Encode; | ||
use polimec_runtime::{xcm_config::SupportedAssets, ForeignAssets, TreasuryAccount}; | ||
use sp_runtime::traits::MaybeEquivalence; | ||
use xcm::prelude::*; | ||
use xcm_emulator::TestExt; | ||
|
||
pub fn fake_message_hash<T>(message: &Xcm<T>) -> XcmHash { | ||
message.using_encoded(sp_io::hashing::blake2_256) | ||
} | ||
#[test] | ||
fn execution_fees_go_to_treasury() { | ||
let relay = MultiLocation::parent(); | ||
let asset_hub = MultiLocation::new(1, X1(Parachain(1000))); | ||
let dot_amount = MultiAsset { id: Concrete(relay), fun: Fungible(100_0_000_000_000) }; | ||
let usdt_amount = MultiAsset { | ||
id: Concrete(MultiLocation { | ||
parents: 1, | ||
interior: X3(Parachain(1000), PalletInstance(50), GeneralIndex(1984)), | ||
}), | ||
fun: Fungible(100_000_000), | ||
}; | ||
let usdc_amount = MultiAsset { | ||
id: Concrete(MultiLocation { | ||
parents: 1, | ||
interior: X3(Parachain(1000), PalletInstance(50), GeneralIndex(1337)), | ||
}), | ||
fun: Fungible(100_000_000), | ||
}; | ||
|
||
let plmc_amount = MultiAsset { id: Concrete(relay), fun: Fungible(100_0_000_000_000) }; | ||
let beneficiary: PolimecAccountId = [0u8; 32].into(); | ||
|
||
let assert_fee_goes_to_treasury = |multi_asset: MultiAsset| { | ||
let asset_multilocation = | ||
if let Concrete(asset_multilocation) = multi_asset.id { asset_multilocation } else { unreachable!() }; | ||
let asset_id = SupportedAssets::convert(&asset_multilocation).unwrap(); | ||
let asset_amount = if let Fungible(amount) = multi_asset.fun { amount } else { unreachable!() }; | ||
|
||
let xcm = Xcm::<PolimecCall>(vec![ | ||
ReserveAssetDeposited(vec![multi_asset.clone()].into()), | ||
ClearOrigin, | ||
BuyExecution { fees: multi_asset, weight_limit: Unlimited }, | ||
DepositAsset { | ||
assets: WildMultiAsset::All.into(), | ||
beneficiary: MultiLocation::new(0, X1(AccountId32 { network: None, id: beneficiary.clone().into() })), | ||
}, | ||
]) | ||
.into(); | ||
PolimecNet::execute_with(|| { | ||
let outcome = <PolimecRuntime as pallet_xcm::Config>::XcmExecutor::execute_xcm( | ||
asset_hub, | ||
xcm.clone(), | ||
fake_message_hash(&xcm), | ||
Weight::MAX, | ||
); | ||
assert!(outcome.ensure_complete().is_ok()); | ||
|
||
let treasury_balance = PolimecForeignAssets::balance(asset_id, TreasuryAccount::get()); | ||
let beneficiary_balance = PolimecForeignAssets::balance(asset_id, beneficiary.clone()); | ||
assert_eq!(asset_amount, treasury_balance + beneficiary_balance); | ||
}); | ||
}; | ||
|
||
assert_fee_goes_to_treasury(dot_amount); | ||
assert_fee_goes_to_treasury(usdt_amount); | ||
assert_fee_goes_to_treasury(usdc_amount); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters