Skip to content

Commit

Permalink
update subtree
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden authored and claravanstaden committed Dec 21, 2023
2 parents 152d0bf + c5a3b48 commit 9b7c50e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 17 deletions.
11 changes: 8 additions & 3 deletions bridges/snowbridge/parachain/pallets/inbound-queue/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ fn test_submit_happy_path() {
}
.into()]);

let reward = Parameters::get().rewards.local;
assert!(Balances::balance(&relayer) >= reward, "relayer was rewarded");
let delivery_cost = InboundQueue::calculate_delivery_cost(message.encode().len() as u32);
assert!(
Balances::balance(&channel_sovereign) <= initial_fund - reward,
Parameters::get().rewards.local < delivery_cost,
"delivery cost exceeds pure reward"
);

assert_eq!(Balances::balance(&relayer), delivery_cost, "relayer was rewarded");
assert!(
Balances::balance(&channel_sovereign) <= initial_fund - delivery_cost,
"sovereign account paid reward"
);
});
Expand Down
6 changes: 2 additions & 4 deletions bridges/snowbridge/parachain/pallets/system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ use xcm_executor::traits::ConvertLocation;

use snowbridge_core::{
gwei, meth, outbound::ConstantGasMeter, sibling_sovereign_account, AgentId, AllowSiblingsOnly,
DescribeHere, ParaId, PricingParameters, Rewards,
ParaId, PricingParameters, Rewards,
};
use sp_runtime::{
traits::{AccountIdConversion, BlakeTwo256, IdentityLookup, Keccak256},
AccountId32, BuildStorage, FixedU128,
};
use xcm::prelude::*;
use xcm_builder::{DescribeAllTerminal, DescribeFamily, HashedDescription};

#[cfg(feature = "runtime-benchmarks")]
use crate::BenchmarkHelper;
Expand Down Expand Up @@ -221,8 +220,7 @@ impl crate::Config for Test {
type RuntimeEvent = RuntimeEvent;
type OutboundQueue = OutboundQueue;
type SiblingOrigin = pallet_xcm_origin::EnsureXcm<AllowSiblingsOnly>;
type AgentIdOf =
HashedDescription<AgentId, (DescribeHere, DescribeFamily<DescribeAllTerminal>)>;
type AgentIdOf = snowbridge_core::AgentIdOf;
type TreasuryAccount = TreasuryAccount;
type Token = Balances;
type DefaultPricingParameters = Parameters;
Expand Down
6 changes: 5 additions & 1 deletion bridges/snowbridge/parachain/primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use xcm::prelude::{
Junctions::{Here, X1},
MultiLocation,
};
use xcm_builder::DescribeLocation;
use xcm_builder::{DescribeAllTerminal, DescribeFamily, DescribeLocation, HashedDescription};

/// The ID of an agent contract
pub type AgentId = H256;
Expand Down Expand Up @@ -168,3 +168,7 @@ impl DescribeLocation for DescribeHere {
}
}
}

/// Creates an AgentId from a MultiLocation. An AgentId is a unique mapping to a Agent contract on
/// Ethereum which acts as the sovereign account for the MultiLocation.
pub type AgentIdOf = HashedDescription<H256, (DescribeHere, DescribeFamily<DescribeAllTerminal>)>;
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,11 @@ where
SendError::Unroutable
})?;

// local_sub is relative to the relaychain. No conversion needed.
let local_sub_location: MultiLocation = local_sub.into();
let agent_id = match AgentHashedDescription::convert_location(&local_sub_location) {
let source_location: MultiLocation = MultiLocation { parents: 1, interior: local_sub };
let agent_id = match AgentHashedDescription::convert_location(&source_location) {
Some(id) => id,
None => {
log::error!(target: "xcm::ethereum_blob_exporter", "unroutable due to not being able to create agent id. '{local_sub_location:?}'");
log::error!(target: "xcm::ethereum_blob_exporter", "unroutable due to not being able to create agent id. '{source_location:?}'");
return Err(SendError::Unroutable)
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use frame_support::parameter_types;
use hex_literal::hex;
use snowbridge_core::outbound::{Fee, SendError, SendMessageFeeProvider};

use snowbridge_core::{
outbound::{Fee, SendError, SendMessageFeeProvider},
AgentIdOf,
};
use xcm::v3::prelude::SendError as XcmSendError;
use xcm_builder::{DescribeAllTerminal, DescribeFamily, HashedDescription};

pub type AgentIdOf = HashedDescription<H256, DescribeFamily<DescribeAllTerminal>>;

use super::*;

Expand Down Expand Up @@ -1035,3 +1034,30 @@ fn xcm_converter_convert_with_non_ethereum_chain_beneficiary_yields_beneficiary_
let result = converter.convert();
assert_eq!(result.err(), Some(XcmConverterError::BeneficiaryResolutionFailed));
}

#[test]
fn test_describe_asset_hub() {
let legacy_location: MultiLocation =
MultiLocation { parents: 0, interior: X1(Parachain(1000)) };
let legacy_agent_id = AgentIdOf::convert_location(&legacy_location).unwrap();
assert_eq!(
legacy_agent_id,
hex!("72456f48efed08af20e5b317abf8648ac66e86bb90a411d9b0b713f7364b75b4").into()
);
let location: MultiLocation = MultiLocation { parents: 1, interior: X1(Parachain(1000)) };
let agent_id = AgentIdOf::convert_location(&location).unwrap();
assert_eq!(
agent_id,
hex!("81c5ab2571199e3188135178f3c2c8e2d268be1313d029b30f534fa579b69b79").into()
)
}

#[test]
fn test_describe_here() {
let location: MultiLocation = MultiLocation { parents: 0, interior: Here };
let agent_id = AgentIdOf::convert_location(&location).unwrap();
assert_eq!(
agent_id,
hex!("03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314").into()
)
}

0 comments on commit 9b7c50e

Please sign in to comment.