|
1 | 1 | #![cfg(test)]
|
2 | 2 |
|
3 | 3 | use super::*;
|
| 4 | +use codec::Encode; |
4 | 5 | use cumulus_primitives_core::ParaId;
|
5 |
| -use frame_support::{assert_noop, assert_ok, traits::Currency}; |
| 6 | +use frame_support::{assert_err, assert_noop, assert_ok, traits::Currency}; |
6 | 7 | use mock::*;
|
7 | 8 | use orml_traits::MultiCurrency;
|
8 | 9 | // use polkadot_parachain::primitives::{AccountIdConversion, Sibling};
|
9 | 10 | use polkadot_parachain::primitives::AccountIdConversion;
|
10 | 11 | use sp_runtime::AccountId32;
|
11 |
| -use xcm::v0::{Junction, NetworkId}; |
| 12 | +use xcm::v0::{Junction, NetworkId, Order}; |
12 | 13 | use xcm_simulator::TestExt;
|
13 | 14 |
|
14 | 15 | fn para_a_account() -> AccountId32 {
|
@@ -325,3 +326,88 @@ fn transfer_to_invalid_dest_fails() {
|
325 | 326 | );
|
326 | 327 | });
|
327 | 328 | }
|
| 329 | + |
| 330 | +#[test] |
| 331 | +fn send_as_sovereign() { |
| 332 | + TestNet::reset(); |
| 333 | + |
| 334 | + Relay::execute_with(|| { |
| 335 | + let _ = RelayBalances::deposit_creating(¶_a_account(), 1_000_000_000_000); |
| 336 | + }); |
| 337 | + |
| 338 | + ParaA::execute_with(|| { |
| 339 | + use xcm::v0::OriginKind::SovereignAccount; |
| 340 | + |
| 341 | + let call = relay::Call::System(frame_system::Call::<relay::Runtime>::remark_with_event(vec![1, 1, 1])); |
| 342 | + assert_ok!(para::OrmlXcm::send_as_sovereign( |
| 343 | + para::Origin::root(), |
| 344 | + Junction::Parent.into(), |
| 345 | + WithdrawAsset { |
| 346 | + assets: vec![MultiAsset::ConcreteFungible { |
| 347 | + id: MultiLocation::Null, |
| 348 | + amount: 1_000_000_000_000 |
| 349 | + }], |
| 350 | + effects: vec![Order::BuyExecution { |
| 351 | + fees: MultiAsset::All, |
| 352 | + weight: 10_000_000, |
| 353 | + debt: 10_000_000, |
| 354 | + halt_on_error: true, |
| 355 | + xcm: vec![Transact { |
| 356 | + origin_type: SovereignAccount, |
| 357 | + require_weight_at_most: 1_000_000_000, |
| 358 | + call: call.encode().into(), |
| 359 | + }], |
| 360 | + }] |
| 361 | + } |
| 362 | + )); |
| 363 | + }); |
| 364 | + |
| 365 | + Relay::execute_with(|| { |
| 366 | + relay::System::events().iter().any(|r| { |
| 367 | + if let relay::Event::System(frame_system::Event::<relay::Runtime>::Remarked(_, _)) = r.event { |
| 368 | + true |
| 369 | + } else { |
| 370 | + false |
| 371 | + } |
| 372 | + }); |
| 373 | + }) |
| 374 | +} |
| 375 | + |
| 376 | +#[test] |
| 377 | +fn send_as_sovereign_fails_if_bad_origin() { |
| 378 | + TestNet::reset(); |
| 379 | + |
| 380 | + Relay::execute_with(|| { |
| 381 | + let _ = RelayBalances::deposit_creating(¶_a_account(), 1_000_000_000_000); |
| 382 | + }); |
| 383 | + |
| 384 | + ParaA::execute_with(|| { |
| 385 | + use xcm::v0::OriginKind::SovereignAccount; |
| 386 | + |
| 387 | + let call = relay::Call::System(frame_system::Call::<relay::Runtime>::remark_with_event(vec![1, 1, 1])); |
| 388 | + assert_err!( |
| 389 | + para::OrmlXcm::send_as_sovereign( |
| 390 | + para::Origin::signed(ALICE), |
| 391 | + Junction::Parent.into(), |
| 392 | + WithdrawAsset { |
| 393 | + assets: vec![MultiAsset::ConcreteFungible { |
| 394 | + id: MultiLocation::Null, |
| 395 | + amount: 1_000_000_000_000 |
| 396 | + }], |
| 397 | + effects: vec![Order::BuyExecution { |
| 398 | + fees: MultiAsset::All, |
| 399 | + weight: 10_000_000, |
| 400 | + debt: 10_000_000, |
| 401 | + halt_on_error: true, |
| 402 | + xcm: vec![Transact { |
| 403 | + origin_type: SovereignAccount, |
| 404 | + require_weight_at_most: 1_000_000_000, |
| 405 | + call: call.encode().into(), |
| 406 | + }], |
| 407 | + }] |
| 408 | + } |
| 409 | + ), |
| 410 | + DispatchError::BadOrigin, |
| 411 | + ); |
| 412 | + }); |
| 413 | +} |
0 commit comments