use xcm::prelude::*;
use super::mock::*;
const SENDER: [u8; 32] = [0; 32];
const RECIPIENT: [u8; 32] = [1; 32];
#[test]
fn transactional_process_success_no_rollback() {
add_asset(SENDER, (Here, 100u128));
let xcm = Xcm::<TestCall>::builder()
.withdraw_asset((Here, 100u128))
.pay_fees((Here, 10u128))
.deposit_asset(All, RECIPIENT)
.build();
let (mut vm, _weight) = instantiate_executor(SENDER, xcm.clone());
assert!(vm.bench_process(xcm).is_ok());
assert_eq!(get_first_fungible(vm.holding()), None);
assert!(get_first_fungible(vm.fees()).is_some());
assert_eq!(asset_list(RECIPIENT), [(Here, 90u128).into()]);
}
#[test]
fn transactional_process_error_rolls_back_holding() {
add_asset(SENDER, (Here, 100u128));
let xcm = Xcm::<TestCall>(vec![
WithdrawAsset((Here, 100u128).into()),
ExchangeAsset {
give: Wild(All),
want: Assets::from(vec![(Parent, 50u128).into()]),
maximal: true,
},
]);
let (mut vm, _weight) = instantiate_executor(SENDER, xcm.clone());
assert!(vm.bench_process(xcm).is_err());
assert_eq!(get_first_fungible(vm.holding()), Some((Here, 100u128).into()));
}
#[test]
fn custom_rollback_is_invoked_on_error() {
add_asset(SENDER, (Here, 100u128));
let xcm1 = Xcm::<TestCall>(vec![
WithdrawAsset((Here, 100u128).into()),
PayFees { asset: (Parent, 10u128).into() },
]);
let (mut vm, _weight) = instantiate_executor(SENDER, xcm1.clone());
assert!(vm.bench_process(xcm1).is_err());
let xcm2 = Xcm::<TestCall>(vec![PayFees { asset: (Here, 10u128).into() }]);
assert!(vm.bench_process(xcm2).is_ok());
assert!(get_first_fungible(vm.fees()).is_some());
}