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
move spec_version and weight to arguments
  • Loading branch information
svyatonik committed Jul 29, 2021
commit 1c58024a97d77fffb941ed762b1870c45671c370
32 changes: 26 additions & 6 deletions modules/token-swap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ pub mod pallet {
/// Converter from raw hash (derived from swap) to This chain account.
type FromSwapToThisAccountIdConverter: Convert<H256, Self::AccountId>;

/// Current `spec_version` of the Bridged chain.
type BridgedChainSpecVersion: Get<u32>;
/// Current weight of the transfer call at the Bridged chain.
type BridgedChainTransferWeight: Get<Weight>;
/// Tokens balance type at the Bridged chain.
type BridgedBalance: Parameter;
/// Account identifier type at the Bridged chain.
Expand Down Expand Up @@ -199,7 +195,9 @@ pub mod pallet {
origin: OriginFor<T>,
swap: TokenSwapOf<T, I>,
target_public_at_bridged_chain: T::BridgedAccountPublic,
bridged_chain_spec_version: u32,
bridged_currency_transfer: RawBridgedTransferCall,
bridged_currency_transfer_weight: Weight,
bridged_currency_transfer_signature: T::BridgedAccountSignature,
) -> DispatchResultWithPostInfo {
// ensure that the `origin` is the same account that is mentioned in the `swap` intention
Expand Down Expand Up @@ -265,8 +263,8 @@ pub mod pallet {
swap_account.clone(),
T::OutboundMessageLaneId::get(),
bp_message_dispatch::MessagePayload {
spec_version: T::BridgedChainSpecVersion::get(),
weight: T::BridgedChainTransferWeight::get(),
spec_version: bridged_chain_spec_version,
weight: bridged_currency_transfer_weight,
origin: bp_message_dispatch::CallOrigin::TargetAccount(
swap_account,
target_public_at_bridged_chain,
Expand Down Expand Up @@ -546,6 +544,8 @@ mod tests {
const BRIDGED_CHAIN_ACCOUNT_PUBLIC: BridgedAccountPublic = 1;
const BRIDGED_CHAIN_ACCOUNT_SIGNATURE: BridgedAccountSignature = 2;
const BRIDGED_CHAIN_ACCOUNT: BridgedAccountId = 3;
const BRIDGED_CHAIN_SPEC_VERSION: u32 = 4;
const BRIDGED_CHAIN_CALL_WEIGHT: Balance = 5;

fn test_swap() -> TokenSwapOf<TestRuntime, ()> {
bp_token_swap::TokenSwap {
Expand All @@ -570,7 +570,9 @@ mod tests {
Origin::signed(THIS_CHAIN_ACCOUNT),
test_swap(),
BRIDGED_CHAIN_ACCOUNT_PUBLIC,
BRIDGED_CHAIN_SPEC_VERSION,
test_transfer(),
BRIDGED_CHAIN_CALL_WEIGHT,
BRIDGED_CHAIN_ACCOUNT_SIGNATURE,
));
}
Expand All @@ -590,7 +592,9 @@ mod tests {
Origin::signed(THIS_CHAIN_ACCOUNT + 1),
test_swap(),
BRIDGED_CHAIN_ACCOUNT_PUBLIC,
BRIDGED_CHAIN_SPEC_VERSION,
test_transfer(),
BRIDGED_CHAIN_CALL_WEIGHT,
BRIDGED_CHAIN_ACCOUNT_SIGNATURE,
),
Error::<TestRuntime, ()>::MismatchedSwapSourceOrigin
Expand All @@ -608,7 +612,9 @@ mod tests {
Origin::signed(THIS_CHAIN_ACCOUNT),
swap,
BRIDGED_CHAIN_ACCOUNT_PUBLIC,
BRIDGED_CHAIN_SPEC_VERSION,
test_transfer(),
BRIDGED_CHAIN_CALL_WEIGHT,
BRIDGED_CHAIN_ACCOUNT_SIGNATURE,
),
Error::<TestRuntime, ()>::TooLowBalanceOnThisChain
Expand All @@ -626,7 +632,9 @@ mod tests {
Origin::signed(THIS_CHAIN_ACCOUNT),
swap,
BRIDGED_CHAIN_ACCOUNT_PUBLIC,
BRIDGED_CHAIN_SPEC_VERSION,
test_transfer(),
BRIDGED_CHAIN_CALL_WEIGHT,
BRIDGED_CHAIN_ACCOUNT_SIGNATURE,
),
Error::<TestRuntime, ()>::FailedToTransferToSwapAccount
Expand All @@ -644,7 +652,9 @@ mod tests {
Origin::signed(THIS_CHAIN_ACCOUNT),
test_swap(),
BRIDGED_CHAIN_ACCOUNT_PUBLIC,
BRIDGED_CHAIN_SPEC_VERSION,
transfer,
BRIDGED_CHAIN_CALL_WEIGHT,
BRIDGED_CHAIN_ACCOUNT_SIGNATURE,
),
Error::<TestRuntime, ()>::FailedToSendTransferMessage
Expand All @@ -659,7 +669,9 @@ mod tests {
Origin::signed(THIS_CHAIN_ACCOUNT),
test_swap(),
BRIDGED_CHAIN_ACCOUNT_PUBLIC,
BRIDGED_CHAIN_SPEC_VERSION,
test_transfer(),
BRIDGED_CHAIN_CALL_WEIGHT,
BRIDGED_CHAIN_ACCOUNT_SIGNATURE,
));

Expand All @@ -668,7 +680,9 @@ mod tests {
Origin::signed(THIS_CHAIN_ACCOUNT),
test_swap(),
BRIDGED_CHAIN_ACCOUNT_PUBLIC,
BRIDGED_CHAIN_SPEC_VERSION,
test_transfer(),
BRIDGED_CHAIN_CALL_WEIGHT,
BRIDGED_CHAIN_ACCOUNT_SIGNATURE,
),
Error::<TestRuntime, ()>::SwapAlreadyStarted
Expand All @@ -685,7 +699,9 @@ mod tests {
Origin::signed(THIS_CHAIN_ACCOUNT),
test_swap(),
BRIDGED_CHAIN_ACCOUNT_PUBLIC,
BRIDGED_CHAIN_SPEC_VERSION,
test_transfer(),
BRIDGED_CHAIN_CALL_WEIGHT,
BRIDGED_CHAIN_ACCOUNT_SIGNATURE,
),
Error::<TestRuntime, ()>::SwapPeriodIsFinished
Expand All @@ -701,7 +717,9 @@ mod tests {
Origin::signed(THIS_CHAIN_ACCOUNT),
test_swap(),
BRIDGED_CHAIN_ACCOUNT_PUBLIC,
BRIDGED_CHAIN_SPEC_VERSION,
test_transfer(),
BRIDGED_CHAIN_CALL_WEIGHT,
BRIDGED_CHAIN_ACCOUNT_SIGNATURE,
));
});
Expand All @@ -717,7 +735,9 @@ mod tests {
Origin::signed(THIS_CHAIN_ACCOUNT),
test_swap(),
BRIDGED_CHAIN_ACCOUNT_PUBLIC,
BRIDGED_CHAIN_SPEC_VERSION,
test_transfer(),
BRIDGED_CHAIN_CALL_WEIGHT,
BRIDGED_CHAIN_ACCOUNT_SIGNATURE,
));

Expand Down
4 changes: 0 additions & 4 deletions modules/token-swap/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ impl pallet_balances::Config for TestRuntime {
frame_support::parameter_types! {
pub const BridgeChainId: ChainId = *b"inst";
pub const OutboundMessageLaneId: LaneId = *b"lane";
pub const BridgedChainSpecVersion: u32 = 42;
pub const BridgedChainTransferWeight: Weight = 1;
pub const MessageDeliveryAndDispatchFee: Balance = 1;
}

Expand All @@ -124,8 +122,6 @@ impl pallet_bridge_token_swap::Config for TestRuntime {
type ThisCurrency = pallet_balances::Pallet<TestRuntime>;
type FromSwapToThisAccountIdConverter = TestAccountConverter;

type BridgedChainSpecVersion = BridgedChainSpecVersion;
type BridgedChainTransferWeight = BridgedChainTransferWeight;
type BridgedBalance = BridgedBalance;
type BridgedAccountId = BridgedAccountId;
type BridgedAccountPublic = BridgedAccountPublic;
Expand Down