Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
post-merge fixes
  • Loading branch information
svyatonik committed Jun 21, 2021
commit 5cd1b54b9ba892b6601309d45d3d20a3d80166f5
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions modules/token-swap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ serde = { version = "1.0", optional = true }

# Bridge dependencies

bp-message-dispatch = { path = "../../primitives/message-dispatch", default-features = false }
bp-messages = { path = "../../primitives/messages", default-features = false }
bp-runtime = { path = "../../primitives/runtime", default-features = false }
bp-token-swap = { path = "../../primitives/token-swap", default-features = false }
Expand All @@ -34,6 +35,7 @@ pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "m
default = ["std"]
std = [
"codec/std",
"bp-message-dispatch/std",
"bp-messages/std",
"bp-runtime/std",
"bp-token-swap/std",
Expand Down
33 changes: 16 additions & 17 deletions modules/token-swap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
//! temporary `swap_account_at_this_chain` account. It is destroyed upon swap completion.

use bp_messages::{
source_chain::{MessagesBridge, OnMessagesDelivered},
source_chain::{MessagesBridge, OnDeliveryConfirmed},
DeliveredMessages, LaneId, MessageNonce,
};
use bp_runtime::{messages::DispatchFeePayment, InstanceId};
use bp_runtime::{messages::DispatchFeePayment, ChainId};
use bp_token_swap::{TokenSwap, TokenSwapType};
use codec::{Decode, Encode};
use frame_support::{
Expand Down Expand Up @@ -98,7 +98,7 @@ pub mod pallet {
type Event: From<Event<Self, I>> + IsType<<Self as frame_system::Config>::Event>;

/// Id of the bridge with the Bridged chain.
type BridgeInstanceId: Get<InstanceId>;
type BridgeChainId: Get<ChainId>;
/// The identifier of outbound message lane on This chain used to send token transfer
/// messages to the Bridged chain.
///
Expand Down Expand Up @@ -138,7 +138,7 @@ pub mod pallet {
/// SCALE-encoded `Currency::transfer` call on the bridged chain.
pub type RawBridgedTransferCall = Vec<u8>;
/// Bridge message payload used by the pallet.
pub type MessagePayloadOf<T, I> = pallet_bridge_dispatch::MessagePayload<
pub type MessagePayloadOf<T, I> = bp_message_dispatch::MessagePayload<
<T as frame_system::Config>::AccountId,
<T as Config<I>>::BridgedAccountPublic,
<T as Config<I>>::BridgedAccountSignature,
Expand Down Expand Up @@ -251,10 +251,10 @@ pub mod pallet {
let send_message_result = T::MessagesBridge::send_message(
swap_account.clone(),
T::OutboundMessageLaneId::get(),
pallet_bridge_dispatch::MessagePayload {
bp_message_dispatch::MessagePayload {
spec_version: T::BridgedChainSpecVersion::get(),
weight: T::BridgedChainTransferWeight::get(),
origin: pallet_bridge_dispatch::CallOrigin::TargetAccount(
origin: bp_message_dispatch::CallOrigin::TargetAccount(
swap_account,
target_public_at_bridged_chain,
bridged_currency_transfer_signature,
Expand Down Expand Up @@ -430,7 +430,7 @@ pub mod pallet {
#[pallet::storage]
pub type PendingMessages<T: Config<I>, I: 'static = ()> = StorageMap<_, Identity, MessageNonce, H256>;

impl<T: Config<I>, I: 'static> OnMessagesDelivered for Pallet<T, I> {
impl<T: Config<I>, I: 'static> OnDeliveryConfirmed for Pallet<T, I> {
fn on_messages_delivered(lane: &LaneId, delivered_messages: &DeliveredMessages) {
// we're only interested in our lane messages
if *lane != T::OutboundMessageLaneId::get() {
Expand Down Expand Up @@ -463,7 +463,7 @@ pub mod pallet {
/// Expected target account representation on This chain (aka `target_account_at_this_chain`).
pub(crate) fn target_account_at_this_chain<T: Config<I>, I: 'static>(swap: &TokenSwapOf<T, I>) -> T::AccountId {
T::FromBridgedToThisAccountIdConverter::convert(bp_runtime::derive_account_id(
T::BridgeInstanceId::get(),
T::BridgeChainId::get(),
bp_runtime::SourceAccount::Account(swap.target_account_at_bridged_chain.clone()),
))
}
Expand Down Expand Up @@ -676,11 +676,10 @@ mod tests {
test_swap().source_balance_at_this_chain + MessageDeliveryAndDispatchFee::get(),
);
assert!(
frame_system::Pallet::<TestRuntime>::events().iter().any(|e| e.event
== crate::mock::Event::pallet_bridge_token_swap(crate::Event::SwapStarted(
swap_hash,
MESSAGE_NONCE,
))),
frame_system::Pallet::<TestRuntime>::events()
.iter()
.any(|e| e.event
== crate::mock::Event::TokenSwap(crate::Event::SwapStarted(swap_hash, MESSAGE_NONCE,))),
"Missing SwapStarted event: {:?}",
frame_system::Pallet::<TestRuntime>::events(),
);
Expand Down Expand Up @@ -806,8 +805,7 @@ mod tests {
assert!(
frame_system::Pallet::<TestRuntime>::events()
.iter()
.any(|e| e.event
== crate::mock::Event::pallet_bridge_token_swap(crate::Event::SwapClaimed(swap_hash,))),
.any(|e| e.event == crate::mock::Event::TokenSwap(crate::Event::SwapClaimed(swap_hash,))),
"Missing SwapClaimed event: {:?}",
frame_system::Pallet::<TestRuntime>::events(),
);
Expand Down Expand Up @@ -904,8 +902,9 @@ mod tests {
THIS_CHAIN_ACCOUNT_BALANCE - MessageDeliveryAndDispatchFee::get(),
);
assert!(
frame_system::Pallet::<TestRuntime>::events().iter().any(|e| e.event
== crate::mock::Event::pallet_bridge_token_swap(crate::Event::SwapCancelled(swap_hash,))),
frame_system::Pallet::<TestRuntime>::events()
.iter()
.any(|e| e.event == crate::mock::Event::TokenSwap(crate::Event::SwapCancelled(swap_hash,))),
"Missing SwapCancelled event: {:?}",
frame_system::Pallet::<TestRuntime>::events(),
);
Expand Down
9 changes: 6 additions & 3 deletions modules/token-swap/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate as pallet_bridge_token_swap;
use crate::MessagePayloadOf;

use bp_messages::{source_chain::MessagesBridge, LaneId, MessageNonce};
use bp_runtime::InstanceId;
use bp_runtime::ChainId;
use frame_support::weights::Weight;
use sp_core::H256;
use sp_runtime::{
Expand Down Expand Up @@ -90,6 +90,7 @@ impl frame_system::Config for TestRuntime {

frame_support::parameter_types! {
pub const ExistentialDeposit: u64 = 10;
pub const MaxReserves: u32 = 50;
}

impl pallet_balances::Config for TestRuntime {
Expand All @@ -100,10 +101,12 @@ impl pallet_balances::Config for TestRuntime {
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = frame_system::Pallet<TestRuntime>;
type WeightInfo = ();
type MaxReserves = MaxReserves;
type ReserveIdentifier = [u8; 8];
}

frame_support::parameter_types! {
pub const BridgeInstanceId: InstanceId = *b"inst";
pub const BridgeChainId: ChainId = *b"inst";
pub const OutboundMessageLaneId: LaneId = *b"lane";
pub const BridgedChainSpecVersion: u32 = 42;
pub const BridgedChainTransferWeight: Weight = 1;
Expand All @@ -113,7 +116,7 @@ frame_support::parameter_types! {
impl pallet_bridge_token_swap::Config for TestRuntime {
type Event = Event;

type BridgeInstanceId = BridgeInstanceId;
type BridgeChainId = BridgeChainId;
type OutboundMessageLaneId = OutboundMessageLaneId;
type MessagesBridge = TestMessagesBridge;
type MessageDeliveryAndDispatchFee = MessageDeliveryAndDispatchFee;
Expand Down