Skip to content

Commit

Permalink
SubBridge pallets: Fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
jasl committed Jul 15, 2022
1 parent 232d25b commit c36542a
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 65 deletions.
12 changes: 6 additions & 6 deletions pallets/assets-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ pub mod pallet {
fn reserve_location(&self) -> Option<MultiLocation> {
match (self.at(0), self.at(1)) {
(Some(GeneralKey(cb_key)), Some(GeneralIndex(chain_id)))
if &cb_key == &CB_ASSET_KEY =>
if cb_key.clone().into_inner() == CB_ASSET_KEY.to_vec() =>
{
Some(
(
0,
X2(GeneralKey((&cb_key).to_vec()), GeneralIndex(*chain_id)),
X2(GeneralKey(cb_key.clone()), GeneralIndex(*chain_id)),
)
.into(),
)
Expand Down Expand Up @@ -637,7 +637,7 @@ pub mod pallet {
let reserve_location: MultiLocation = (
0,
X2(
GeneralKey(CB_ASSET_KEY.to_vec()),
GeneralKey(CB_ASSET_KEY.to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(chain_id as u128),
),
)
Expand Down Expand Up @@ -799,7 +799,7 @@ pub mod pallet {
#[test]
fn test_withdraw_fund_of_pha() {
let recipient: AccountId32 =
MultiLocation::new(0, X1(GeneralKey(b"recipient".to_vec())))
MultiLocation::new(0, X1(GeneralKey(b"recipient".to_vec().try_into().expect("less than length limit; qed"))))
.into_account()
.into();
new_test_ext().execute_with(|| {
Expand All @@ -824,7 +824,7 @@ pub mod pallet {
#[test]
fn test_withdraw_fund_of_asset() {
let recipient: AccountId32 =
MultiLocation::new(0, X1(GeneralKey(b"recipient".to_vec())))
MultiLocation::new(0, X1(GeneralKey(b"recipient".to_vec().try_into().expect("less than length limit; qed"))))
.into_account()
.into();
let fund_account: <Test as frame_system::Config>::AccountId =
Expand Down Expand Up @@ -866,7 +866,7 @@ pub mod pallet {
fn test_force_mint_burn_asset() {
new_test_ext().execute_with(|| {
let recipient: AccountId32 =
MultiLocation::new(0, X1(GeneralKey(b"recipient".to_vec())))
MultiLocation::new(0, X1(GeneralKey(b"recipient".to_vec().try_into().expect("less than length limit; qed"))))
.into_account()
.into();
let asset_location = MultiLocation::new(1, Here);
Expand Down
67 changes: 34 additions & 33 deletions pallets/subbridge/src/chainbridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ pub mod pallet {
let src_reserve_location: MultiLocation = (
0,
X2(
GeneralKey(CB_ASSET_KEY.to_vec()),
GeneralKey(CB_ASSET_KEY.to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(src_chainid.into()),
),
)
Expand Down Expand Up @@ -967,7 +967,7 @@ pub mod pallet {
let dest_reserve_location: MultiLocation = (
0,
X2(
GeneralKey(CB_ASSET_KEY.to_vec()),
GeneralKey(CB_ASSET_KEY.to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(dest_id.into()),
),
)
Expand Down Expand Up @@ -1069,6 +1069,7 @@ pub mod pallet {
};
use assets_registry::*;
use frame_support::{assert_noop, assert_ok};
use sp_runtime::{bounded_vec, WeakBoundedVec};
use xcm_simulator::TestExt;

pub fn new_test_ext_initialized(
Expand Down Expand Up @@ -1203,9 +1204,9 @@ pub mod pallet {
MultiLocation::new(
0,
X3(
GeneralKey(b"cb".to_vec()),
GeneralKey(b"cb".to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(bad_dest_id.into()),
GeneralKey(b"recipient".to_vec())
GeneralKey(b"recipient".to_vec().try_into().expect("less than length limit; qed"))
)
),
None,
Expand Down Expand Up @@ -1260,7 +1261,7 @@ pub mod pallet {
#[test]
fn create_sucessful_proposal() {
let src_id = 1;
let r_id = MultiLocation::new(1, X1(GeneralKey(b"remark".to_vec()))).into_rid(src_id);
let r_id = MultiLocation::new(1, X1(GeneralKey(b"remark".to_vec().try_into().expect("less than length limit; qed")))).into_rid(src_id);

new_test_ext_initialized(src_id, r_id, b"System.remark".to_vec()).execute_with(|| {
let prop_id = 1;
Expand Down Expand Up @@ -1330,7 +1331,7 @@ pub mod pallet {
#[test]
fn create_unsucessful_proposal() {
let src_id = 1;
let r_id = MultiLocation::new(1, X1(GeneralKey(b"transfer".to_vec()))).into_rid(src_id);
let r_id = MultiLocation::new(1, X1(GeneralKey(b"transfer".to_vec().try_into().expect("less than length limit; qed")))).into_rid(src_id);

new_test_ext_initialized(src_id, r_id, b"System.remark".to_vec()).execute_with(|| {
let prop_id = 1;
Expand Down Expand Up @@ -1405,7 +1406,7 @@ pub mod pallet {
#[test]
fn execute_after_threshold_change() {
let src_id = 1;
let r_id = MultiLocation::new(1, X1(GeneralKey(b"transfer".to_vec()))).into_rid(src_id);
let r_id = MultiLocation::new(1, X1(GeneralKey(b"transfer".to_vec().try_into().expect("less than length limit; qed")))).into_rid(src_id);

new_test_ext_initialized(src_id, r_id, b"System.remark".to_vec()).execute_with(|| {
let prop_id = 1;
Expand Down Expand Up @@ -1466,7 +1467,7 @@ pub mod pallet {
#[test]
fn proposal_expires() {
let src_id = 1;
let r_id = MultiLocation::new(1, X1(GeneralKey(b"remark".to_vec()))).into_rid(src_id);
let r_id = MultiLocation::new(1, X1(GeneralKey(b"remark".to_vec().try_into().expect("less than length limit; qed")))).into_rid(src_id);

new_test_ext_initialized(src_id, r_id, b"System.remark".to_vec()).execute_with(|| {
let prop_id = 1;
Expand Down Expand Up @@ -1559,13 +1560,13 @@ pub mod pallet {
1,
X4(
Parachain(2004),
GeneralKey(CB_ASSET_KEY.to_vec()),
GeneralKey(CB_ASSET_KEY.to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(0),
GeneralKey(b"an asset".to_vec()),
GeneralKey(b"an asset".to_vec().try_into().expect("less than length limit; qed")),
),
);
let amount: Balance = 100;
let recipient = vec![99];
let recipient: WeakBoundedVec<u8, ConstU32<32>> = bounded_vec![99];

assert_ok!(ChainBridge::whitelist_chain(Origin::root(), dest_chain));
assert_ok!(ChainBridge::update_fee(Origin::root(), 2, dest_chain));
Expand All @@ -1578,7 +1579,7 @@ pub mod pallet {
MultiLocation::new(
0,
X3(
GeneralKey(b"cb".to_vec()),
GeneralKey(b"cb".to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(dest_chain.into()),
GeneralKey(recipient)
)
Expand All @@ -1601,13 +1602,13 @@ pub mod pallet {
1,
X4(
Parachain(2004),
GeneralKey(CB_ASSET_KEY.to_vec()),
GeneralKey(CB_ASSET_KEY.to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(0),
GeneralKey(b"an asset".to_vec()),
GeneralKey(b"an asset".to_vec().try_into().expect("less than length limit; qed")),
),
);
let amount: Balance = 100;
let recipient = vec![99];
let recipient: WeakBoundedVec<u8, ConstU32<32>> = bounded_vec![99];

assert_ok!(ChainBridge::whitelist_chain(Origin::root(), dest_chain));
assert_ok!(ChainBridge::update_fee(Origin::root(), 2, dest_chain));
Expand Down Expand Up @@ -1642,7 +1643,7 @@ pub mod pallet {
MultiLocation::new(
0,
X3(
GeneralKey(b"cb".to_vec()),
GeneralKey(b"cb".to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(dest_chain.into()),
GeneralKey(recipient)
)
Expand All @@ -1663,14 +1664,14 @@ pub mod pallet {
let dest_reserve_location: MultiLocation = (
0,
X2(
GeneralKey(CB_ASSET_KEY.to_vec()),
GeneralKey(CB_ASSET_KEY.to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(dest_chain.into()),
),
)
.into();
let bridge_asset_location = SoloChain0AssetLocation::get();
let amount: Balance = 100;
let recipient = vec![99];
let recipient: WeakBoundedVec<u8, ConstU32<32>> = bounded_vec![99];

assert_ok!(ChainBridge::whitelist_chain(Origin::root(), dest_chain));
assert_ok!(ChainBridge::update_fee(Origin::root(), 2, dest_chain));
Expand Down Expand Up @@ -1712,7 +1713,7 @@ pub mod pallet {
MultiLocation::new(
0,
X3(
GeneralKey(b"cb".to_vec()),
GeneralKey(b"cb".to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(dest_chain.into()),
GeneralKey(recipient)
)
Expand Down Expand Up @@ -1742,14 +1743,14 @@ pub mod pallet {
let dest_reserve_location: MultiLocation = (
0,
X2(
GeneralKey(CB_ASSET_KEY.to_vec()),
GeneralKey(CB_ASSET_KEY.to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(dest_chain.into()),
),
)
.into();
let bridge_asset_location = SoloChain2AssetLocation::get();
let amount: Balance = 100;
let recipient = vec![99];
let recipient: WeakBoundedVec<u8, ConstU32<32>> = bounded_vec![99];

assert_ok!(ChainBridge::whitelist_chain(Origin::root(), dest_chain));
assert_ok!(ChainBridge::update_fee(Origin::root(), 2, dest_chain));
Expand Down Expand Up @@ -1797,7 +1798,7 @@ pub mod pallet {
MultiLocation::new(
0,
X3(
GeneralKey(b"cb".to_vec()),
GeneralKey(b"cb".to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(dest_chain.into()),
GeneralKey(recipient)
)
Expand Down Expand Up @@ -1828,7 +1829,7 @@ pub mod pallet {
let resource_id = ChainBridge::gen_pha_rid(dest_chain);
let free_balance: u128 = Balances::free_balance(RELAYER_A).into();
let amount: Balance = 100;
let recipient = vec![99];
let recipient: WeakBoundedVec<u8, ConstU32<32>> = bounded_vec![99];

assert_ok!(ChainBridge::whitelist_chain(Origin::root(), dest_chain));
assert_ok!(ChainBridge::update_fee(Origin::root(), 2, dest_chain));
Expand All @@ -1845,7 +1846,7 @@ pub mod pallet {
MultiLocation::new(
0,
X3(
GeneralKey(b"cb".to_vec()),
GeneralKey(b"cb".to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(dest_chain.into()),
GeneralKey(recipient.clone())
)
Expand All @@ -1862,7 +1863,7 @@ pub mod pallet {
MultiLocation::new(
0,
X3(
GeneralKey(b"cb".to_vec()),
GeneralKey(b"cb".to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(dest_chain.into()),
GeneralKey(recipient.clone())
)
Expand All @@ -1875,7 +1876,7 @@ pub mod pallet {
1,
resource_id,
(amount - 2).into(),
recipient,
recipient.to_vec(),
));

assert_eq!(
Expand Down Expand Up @@ -1959,9 +1960,9 @@ pub mod pallet {
1,
X4(
Parachain(2004),
GeneralKey(CB_ASSET_KEY.to_vec()),
GeneralKey(CB_ASSET_KEY.to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(src_chainid.into()),
GeneralKey(b"an asset".to_vec()),
GeneralKey(b"an asset".to_vec().try_into().expect("less than length limit; qed")),
),
);
let r_id: [u8; 32] = bridge_asset_location.clone().into_rid(src_chainid);
Expand All @@ -1977,7 +1978,7 @@ pub mod pallet {
let src_reserve_location: MultiLocation = (
0,
X2(
GeneralKey(CB_ASSET_KEY.to_vec()),
GeneralKey(CB_ASSET_KEY.to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(src_chainid.into()),
),
)
Expand Down Expand Up @@ -2049,7 +2050,7 @@ pub mod pallet {
1,
X2(
Parachain(2000),
GeneralKey(b"an asset from karura".to_vec()),
GeneralKey(b"an asset from karura".to_vec().try_into().expect("less than length limit; qed")),
),
);
let amount: Balance = 100;
Expand All @@ -2063,7 +2064,7 @@ pub mod pallet {
let src_reserve_location: MultiLocation = (
0,
X2(
GeneralKey(CB_ASSET_KEY.to_vec()),
GeneralKey(CB_ASSET_KEY.to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(src_chainid.into()),
),
)
Expand Down Expand Up @@ -2287,9 +2288,9 @@ pub mod pallet {
ParaA::execute_with(|| {
let dest_chain: u8 = 2;
let bridge_fee = 2;
let test_asset_location = MultiLocation::new(1, X1(GeneralKey(b"test".to_vec())));
let test_asset_location = MultiLocation::new(1, X1(GeneralKey(b"test".to_vec().try_into().expect("less than length limit; qed"))));
let unregistered_asset_location =
MultiLocation::new(1, X1(GeneralKey(b"unregistered".to_vec())));
MultiLocation::new(1, X1(GeneralKey(b"unregistered".to_vec().try_into().expect("less than length limit; qed"))));

// Register asset, decimals: 18, rate with pha: 1 : 1
assert_ok!(AssetsRegistry::force_register_asset(
Expand Down
2 changes: 1 addition & 1 deletion pallets/subbridge/src/fungible_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<

// Deposit asset into temporary account, then forward through other bridges
let temporary_account =
MultiLocation::new(0, X1(GeneralKey(b"bridge_transfer".to_vec())))
MultiLocation::new(0, X1(GeneralKey(b"bridge_transfer".to_vec().try_into().expect("less than length limit; qed"))))
.into_account();
if NativeChecker::is_native_asset(what) {
NativeAdapter::deposit_asset(
Expand Down
2 changes: 1 addition & 1 deletion pallets/subbridge/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mod subbridge_v3_migration_common {
T: chainbridge::Config + xcmbridge::Config + xtransfer::Config,
{
// Remove old chainbridge::BridgeFee storage
frame_support::migration::remove_storage_prefix(b"ChainBridge", b"BridgeFee", &[]);
let _ = frame_support::migration::clear_storage_prefix(b"ChainBridge", b"BridgeFee", &[], None, None);

// Create new storage items of fee setting in pallet ChainBridge
chainbridge::BridgeFee::<T>::insert(0, 300_000_000_000_000);
Expand Down
8 changes: 4 additions & 4 deletions pallets/subbridge/src/mock/para.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,18 @@ parameter_types! {
1,
X4(
Parachain(2004),
GeneralKey(assets_registry::CB_ASSET_KEY.to_vec()),
GeneralKey(assets_registry::CB_ASSET_KEY.to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(0),
GeneralKey(b"an asset".to_vec()),
GeneralKey(b"an asset".to_vec().try_into().expect("less than length limit; qed")),
),
);
pub SoloChain2AssetLocation: MultiLocation = MultiLocation::new(
1,
X4(
Parachain(2004),
GeneralKey(assets_registry::CB_ASSET_KEY.to_vec()),
GeneralKey(assets_registry::CB_ASSET_KEY.to_vec().try_into().expect("less than length limit; qed")),
GeneralIndex(2),
GeneralKey(b"an asset".to_vec()),
GeneralKey(b"an asset".to_vec().try_into().expect("less than length limit; qed")),
),
);
pub NativeExecutionPrice: u128 = 1;
Expand Down
Loading

0 comments on commit c36542a

Please sign in to comment.