Skip to content

Commit

Permalink
minor refactor and pallet_xcm weights
Browse files Browse the repository at this point in the history
  • Loading branch information
gitofdeepanshu committed Oct 9, 2023
1 parent 1e920cf commit 532694f
Show file tree
Hide file tree
Showing 11 changed files with 916 additions and 8 deletions.
8 changes: 4 additions & 4 deletions precompiles/xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ where
input.expect_arguments(6)?;

// Raw call arguments
let parachain_id: u32 = input
let para_id: u32 = input
.read::<U256>()?
.try_into()
.map_err(|_| revert("error converting parachain_id, maybe value too large"))?;
.map_err(|_| revert("error converting para_id, maybe value too large"))?;

let is_relay = input.read::<bool>()?;

Expand All @@ -307,13 +307,13 @@ where

log::trace!(target: "xcm-precompile:remote_transact", "Raw arguments: para_id: {}, is_relay: {}, fee_asset_addr: {:?}, \
fee_amount: {:?}, remote_call: {:?}, transact_weight: {}",
parachain_id, is_relay, fee_asset_addr, fee_amount, remote_call, transact_weight);
para_id, is_relay, fee_asset_addr, fee_amount, remote_call, transact_weight);

// Process arguments
let dest = if is_relay {
MultiLocation::parent()
} else {
X1(Junction::Parachain(parachain_id)).into_exterior(1)
X1(Junction::Parachain(para_id)).into_exterior(1)
};

let fee_asset = {
Expand Down
79 changes: 78 additions & 1 deletion precompiles/xcm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ mod xcm_old_interface_test {
.expect_no_logs()
.execute_returns(EvmDataWriter::new().write(true).build());

// H160
// Checking for non-relay destination case
precompiles()
.prepare_test(
TestAccount::Alice,
Expand Down Expand Up @@ -193,6 +193,45 @@ mod xcm_old_interface_test {
)
.expect_no_logs()
.execute_returns(EvmDataWriter::new().write(true).build());

for (location, Xcm(instructions)) in take_sent_xcm() {
assert_eq!(
location,
MultiLocation {
parents: 1,
interior: Here
}
);

let non_native_asset = MultiAsset {
fun: Fungible(42000),
id: xcm::v3::AssetId::from(MultiLocation {
parents: 0,
interior: Here,
}),
};
dbg!(instructions.clone());
assert!(matches!(
instructions.as_slice(),
[
WithdrawAsset(assets),
ClearOrigin,
BuyExecution {
fees,
..
},
DepositAsset {
beneficiary: MultiLocation {
parents: 0,
interior: X1(_),
},
..
}
]

if fees.contains(&non_native_asset) && assets.contains(&non_native_asset)
));
}
});
}

Expand Down Expand Up @@ -230,6 +269,44 @@ mod xcm_old_interface_test {
)
.expect_no_logs()
.execute_returns(EvmDataWriter::new().write(true).build());

for (location, Xcm(instructions)) in take_sent_xcm() {
assert_eq!(
location,
MultiLocation {
parents: 1,
interior: Here
}
);

let native_asset = MultiAsset {
fun: Fungible(42000),
id: xcm::v3::AssetId::from(MultiLocation {
parents: 0,
interior: X1(Parachain(123)),
}),
};

assert!(matches!(
instructions.as_slice(),
[
ReserveAssetDeposited(assets),
ClearOrigin,
BuyExecution {
fees,
..
},
DepositAsset {
beneficiary: MultiLocation {
parents: 0,
interior: X1(_),
},
..
}
]
if fees.contains(&native_asset) && assets.contains(&native_asset)
));
}
});
}

Expand Down
1 change: 1 addition & 0 deletions runtime/astar/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
// along with Astar. If not, see <http://www.gnu.org/licenses/>.

pub mod pallet_assets;
pub mod pallet_xcm;
Loading

0 comments on commit 532694f

Please sign in to comment.