Skip to content

Commit

Permalink
fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alistair-singh committed Dec 18, 2023
1 parent 83650f2 commit baa041f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
11 changes: 2 additions & 9 deletions parachain/pallets/outbound-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::*;

use frame_support::{
parameter_types,
traits::{Contains, Everything, Hooks},
traits::{Everything, Hooks},
weights::IdentityFee,
};

Expand Down Expand Up @@ -93,13 +93,6 @@ parameter_types! {

pub const DOT: u128 = 10_000_000_000;

pub struct MockChannels;
impl Contains<ChannelId> for MockChannels {
fn contains(_: &ChannelId) -> bool {
true
}
}

impl crate::Config for Test {
type RuntimeEvent = RuntimeEvent;
type Hashing = Keccak256;
Expand All @@ -110,7 +103,7 @@ impl crate::Config for Test {
type GasMeter = ConstantGasMeter;
type Balance = u128;
type PricingParameters = Parameters;
type Channels = MockChannels;
type Channels = Everything;
type WeightToFee = IdentityFee<u128>;
type WeightInfo = ();
}
Expand Down
1 change: 1 addition & 0 deletions parachain/pallets/system/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ mod benchmarks {
let origin = T::Helper::make_xcm_origin(origin_location);
fund_sovereign_account::<T>(origin_para_id.into())?;
SnowbridgeControl::<T>::create_agent(origin.clone())?;
SnowbridgeControl::<T>::create_channel(origin.clone(), OperatingMode::Normal)?;

#[extrinsic_call]
_(origin as T::RuntimeOrigin, H160::default(), 1);
Expand Down
25 changes: 16 additions & 9 deletions parachain/pallets/system/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ fn update_channel() {

// First create the channel
let _ = Balances::mint_into(&sovereign_account, 10000);
EthereumSystem::create_agent(origin.clone()).unwrap();
EthereumSystem::create_channel(origin.clone(), OperatingMode::Normal).unwrap();
assert_ok!(EthereumSystem::create_agent(origin.clone()));
assert_ok!(EthereumSystem::create_channel(origin.clone(), OperatingMode::Normal));

// Now try to update it
assert_ok!(EthereumSystem::update_channel(origin, OperatingMode::Normal));
Expand Down Expand Up @@ -405,8 +405,8 @@ fn force_update_channel() {

// First create the channel
let _ = Balances::mint_into(&sovereign_account, 10000);
EthereumSystem::create_agent(origin.clone()).unwrap();
EthereumSystem::create_channel(origin.clone(), OperatingMode::Normal).unwrap();
assert_ok!(EthereumSystem::create_agent(origin.clone()));
assert_ok!(EthereumSystem::create_channel(origin.clone(), OperatingMode::Normal));

// Now try to force update it
let force_origin = RuntimeOrigin::root();
Expand Down Expand Up @@ -444,11 +444,13 @@ fn force_update_channel_bad_origin() {
fn transfer_native_from_agent() {
new_test_ext(true).execute_with(|| {
let origin_location = MultiLocation { parents: 1, interior: X1(Parachain(2000)) };
let origin = make_xcm_origin(origin_location);
let recipient: H160 = [27u8; 20].into();
let amount = 103435;

// First create the agent
Agents::<Test>::insert(make_agent_id(origin_location), ());
// First create the agent and channel
assert_ok!(EthereumSystem::create_agent(origin.clone()));
assert_ok!(EthereumSystem::create_channel(origin, OperatingMode::Normal));

let origin = make_xcm_origin(origin_location);
assert_ok!(EthereumSystem::transfer_native_from_agent(origin, recipient, amount),);
Expand Down Expand Up @@ -549,23 +551,28 @@ fn charge_fee_for_create_agent() {
let sovereign_account = sibling_sovereign_account::<Test>(para_id.into());
let (_, agent_id) = ensure_sibling::<Test>(&origin_location).unwrap();

let initial_sovereign_balance = Balances::balance(&sovereign_account);
assert_ok!(EthereumSystem::create_agent(origin.clone()));
let fee_charged = initial_sovereign_balance - Balances::balance(&sovereign_account);

assert_ok!(EthereumSystem::create_channel(origin, OperatingMode::Normal));

// assert sovereign_balance decreased by (fee.base_fee + fee.delivery_fee)
let message = Message {
id: None,
channel_id: ParaId::from(para_id).into(),
command: Command::CreateAgent { agent_id },
};
let (_, fee) = OutboundQueue::validate(&message).unwrap();
let sovereign_balance = Balances::balance(&sovereign_account);
assert_eq!(sovereign_balance + fee.local + fee.remote, InitialFunding::get());
assert_eq!(fee.local + fee.remote, fee_charged);

// and treasury_balance increased
let treasury_balance = Balances::balance(&TreasuryAccount::get());
assert!(treasury_balance > InitialFunding::get());

let final_sovereign_balance = Balances::balance(&sovereign_account);
// (sovereign_balance + treasury_balance) keeps the same
assert_eq!(sovereign_balance + treasury_balance, { InitialFunding::get() * 2 });
assert_eq!(final_sovereign_balance + treasury_balance, { InitialFunding::get() * 2 });
});
}

Expand Down

0 comments on commit baa041f

Please sign in to comment.