Skip to content

Commit

Permalink
Run rustfmt over code (paritytech#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
vgeddes authored Oct 29, 2021
1 parent 85f0599 commit 929e2ed
Show file tree
Hide file tree
Showing 109 changed files with 2,468 additions and 2,647 deletions.
9 changes: 4 additions & 5 deletions parachain/pallets/basic-channel/src/inbound/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use super::*;

use frame_system::{RawOrigin, self, EventRecord};
use frame_benchmarking::{benchmarks, whitelisted_caller, impl_benchmark_test_suite};
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_system::{self, EventRecord, RawOrigin};
use hex_literal::hex;
use sp_std::convert::TryInto;
use sp_std::prelude::*;
use sp_std::{convert::TryInto, prelude::*};

use snowbridge_core::{ChannelId, Message, MessageId, Proof};
use snowbridge_ethereum::{Log, Header};
use snowbridge_ethereum::{Header, Log};

#[allow(unused_imports)]
use crate::inbound::Pallet as BasicInboundChannel;
Expand Down
43 changes: 20 additions & 23 deletions parachain/pallets/basic-channel/src/inbound/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use ethabi::{Event, Param, ParamKind, Token};
use snowbridge_ethereum::{log::Log, H160};

use sp_core::RuntimeDebug;
use sp_std::prelude::*;
use sp_std::convert::TryFrom;
use sp_std::{convert::TryFrom, prelude::*};

// Used to decode a raw Ethereum log into an [`Envelope`].
static EVENT_ABI: &Event = &Event {
Expand All @@ -13,7 +12,7 @@ static EVENT_ABI: &Event = &Event {
Param { kind: ParamKind::Uint(64), indexed: false },
Param { kind: ParamKind::Bytes, indexed: false },
],
anonymous: false
anonymous: false,
};

/// An inbound message that has had its outer envelope decoded.
Expand All @@ -36,34 +35,26 @@ impl TryFrom<Log> for Envelope {
type Error = EnvelopeDecodeError;

fn try_from(log: Log) -> Result<Self, Self::Error> {
let tokens = EVENT_ABI.decode(log.topics, log.data)
.map_err(|_| EnvelopeDecodeError)?;
let tokens = EVENT_ABI.decode(log.topics, log.data).map_err(|_| EnvelopeDecodeError)?;

let mut iter = tokens.into_iter();

let source = match iter.next().ok_or(EnvelopeDecodeError)? {
Token::Address(source) => source,
_ => return Err(EnvelopeDecodeError)
_ => return Err(EnvelopeDecodeError),
};

let nonce = match iter.next().ok_or(EnvelopeDecodeError)? {
Token::Uint(value) => {
value.low_u64()
}
_ => return Err(EnvelopeDecodeError)
Token::Uint(value) => value.low_u64(),
_ => return Err(EnvelopeDecodeError),
};

let payload = match iter.next().ok_or(EnvelopeDecodeError)? {
Token::Bytes(payload) => payload,
_ => return Err(EnvelopeDecodeError)
_ => return Err(EnvelopeDecodeError),
};

Ok(Self {
channel: log.address,
source,
nonce,
payload,
})
Ok(Self { channel: log.address, source, nonce, payload })
}
}

Expand All @@ -72,7 +63,8 @@ mod tests {
use super::*;
use hex_literal::hex;

const LOG: [u8; 284] = hex!("
const LOG: [u8; 284] = hex!(
"
f901199430d2da52e36f80b17fe2694a5e4900b81cf26344e1a0779b38144a38
cfc4351816442048b17fe24ba2b0e0c63446b576e8281160b15bb8e000000000
0000000000000000abe98e5ef4dc7a5c4f317823986fe48649f0edbb00000000
Expand All @@ -82,23 +74,28 @@ mod tests {
269a6d3d28d07b1fd834ebe4e703368ed43593c715fdd31c61141abd04a99fd6
822c8558854ccde39a5684e7a56da27d00010000000000000000000000000000
00000000000000000000000000000000000000000000000000000000
");
"
);

#[test]
fn test_try_from_log() {
let log: Log = rlp::decode(&LOG).unwrap();
let envelope = Envelope::try_from(log).unwrap();

assert_eq!(envelope,
assert_eq!(
envelope,
Envelope {
channel: hex!["30d2da52e36f80b17fe2694a5e4900b81cf26344"].into(),
source: hex!["abe98e5ef4dc7a5c4f317823986fe48649f0edbb"].into(),
nonce: 0,
payload: hex!("
payload: hex!(
"
1ed28b61269a6d3d28d07b1fd834ebe4e703368ed43593c715fdd31c61141abd
04a99fd6822c8558854ccde39a5684e7a56da27d000100000000000000000000
0000000000000000000000000000000000000000"
).into(),
})
)
.into(),
}
)
}
}
11 changes: 3 additions & 8 deletions parachain/pallets/basic-channel/src/inbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ pub mod weights;
mod test;

use frame_system::ensure_signed;
use snowbridge_core::{ChannelId, Message, MessageDispatch, MessageId, Verifier};
use sp_core::H160;
use sp_std::convert::TryFrom;
use snowbridge_core::{
ChannelId, Message, MessageId,
MessageDispatch, Verifier,
};

use envelope::Envelope;
pub use weights::WeightInfo;
Expand Down Expand Up @@ -79,9 +76,7 @@ pub mod pallet {
#[cfg(feature = "std")]
impl Default for GenesisConfig {
fn default() -> Self {
Self {
source_channel: Default::default(),
}
Self { source_channel: Default::default() }
}
}

Expand All @@ -106,7 +101,7 @@ pub mod pallet {
// Verify that the message was submitted to us from a known
// outbound channel on the ethereum side
if envelope.channel != <SourceChannel<T>>::get() {
return Err(Error::<T>::InvalidSourceChannel.into())
return Err(Error::<T>::InvalidSourceChannel.into());
}

// Verify message nonce
Expand Down
47 changes: 24 additions & 23 deletions parachain/pallets/basic-channel/src/inbound/test.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
use super::*;

use frame_support::traits::GenesisBuild;
use sp_core::{H160, H256};
use frame_support::{
assert_ok, assert_noop,
parameter_types,
dispatch::DispatchError
assert_noop, assert_ok, dispatch::DispatchError, parameter_types, traits::GenesisBuild,
};
use sp_core::{H160, H256};
use sp_keyring::AccountKeyring as Keyring;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup, IdentifyAccount, Verify}, testing::Header, MultiSignature
testing::Header,
traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Verify},
MultiSignature,
};
use sp_keyring::AccountKeyring as Keyring;
use sp_std::convert::From;

use snowbridge_core::{MessageDispatch, Message, Proof};
use snowbridge_core::{Message, MessageDispatch, Proof};
use snowbridge_ethereum::{Header as EthereumHeader, Log, U256};

use hex_literal::hex;

use crate::inbound::Error;
use crate::inbound as basic_inbound_channel;
use crate::{inbound as basic_inbound_channel, inbound::Error};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
Expand Down Expand Up @@ -101,12 +99,12 @@ impl basic_inbound_channel::Config for Test {
}

pub fn new_tester(source_channel: H160) -> sp_io::TestExternalities {
new_tester_with_config(basic_inbound_channel::GenesisConfig {
source_channel,
})
new_tester_with_config(basic_inbound_channel::GenesisConfig { source_channel })
}

pub fn new_tester_with_config(config: basic_inbound_channel::GenesisConfig) -> sp_io::TestExternalities {
pub fn new_tester_with_config(
config: basic_inbound_channel::GenesisConfig,
) -> sp_io::TestExternalities {
let mut storage = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();

GenesisBuild::<Test>::assimilate_storage(&config, &mut storage).unwrap();
Expand All @@ -116,7 +114,6 @@ pub fn new_tester_with_config(config: basic_inbound_channel::GenesisConfig) -> s
ext
}


// The originating channel address for the messages below
const SOURCE_CHANNEL_ADDR: [u8; 20] = hex!["2d02f2234d0B6e35D8d8fD77705f535ACe681327"];

Expand All @@ -127,7 +124,8 @@ const SOURCE_CHANNEL_ADDR: [u8; 20] = hex!["2d02f2234d0B6e35D8d8fD77705f535ACe68
// source: 0x8f5acf5f15d4c3d654a759b96bb674a236c8c0f3 (ETH bank contract)
// nonce: 1
// payload ...
const MESSAGE_DATA_0: [u8; 284] = hex!("
const MESSAGE_DATA_0: [u8; 284] = hex!(
"
f90119942d02f2234d0b6e35d8d8fd77705f535ace681327e1a0779b38144a38
cfc4351816442048b17fe24ba2b0e0c63446b576e8281160b15bb8e000000000
00000000000000000a42cba2b7960a0ce216ade5d6a82574257023d800000000
Expand All @@ -137,7 +135,8 @@ const MESSAGE_DATA_0: [u8; 284] = hex!("
dae5f9c236beab905c8305cb159c5fa1aae500d43593c715fdd31c61141abd04
a99fd6822c8558854ccde39a5684e7a56da27d0000d9e9ac2d78030000000000
00000000000000000000000000000000000000000000000000000000
");
"
);

// Ethereum Log:
// address: 0xe4ab635d0bdc5668b3fcb4eaee1dec587998f4af (outbound channel contract)
Expand All @@ -146,7 +145,8 @@ const MESSAGE_DATA_0: [u8; 284] = hex!("
// source: 0x8f5acf5f15d4c3d654a759b96bb674a236c8c0f3 (ETH bank contract)
// nonce: 1
// payload ...
const MESSAGE_DATA_1: [u8; 284] = hex!("
const MESSAGE_DATA_1: [u8; 284] = hex!(
"
f90119942d02f2234d0b6e35d8d8fd77705f535ace681327e1a0779b38144a38
cfc4351816442048b17fe24ba2b0e0c63446b576e8281160b15bb8e000000000
00000000000000000a42cba2b7960a0ce216ade5d6a82574257023d800000000
Expand All @@ -156,7 +156,8 @@ const MESSAGE_DATA_1: [u8; 284] = hex!("
dae5f9c236beab905c8305cb159c5fa1aae500d43593c715fdd31c61141abd04
a99fd6822c8558854ccde39a5684e7a56da27d0000d9e9ac2d78030000000000
00000000000000000000000000000000000000000000000000000000
");
"
);

#[test]
fn test_submit_with_invalid_source_channel() {
Expand All @@ -170,7 +171,7 @@ fn test_submit_with_invalid_source_channel() {
proof: Proof {
block_hash: Default::default(),
tx_index: Default::default(),
data: Default::default()
data: Default::default(),
},
};
assert_noop!(
Expand All @@ -192,7 +193,7 @@ fn test_submit() {
proof: Proof {
block_hash: Default::default(),
tx_index: Default::default(),
data: Default::default()
data: Default::default(),
},
};
assert_ok!(BasicInboundChannel::submit(origin.clone(), message_1));
Expand All @@ -205,7 +206,7 @@ fn test_submit() {
proof: Proof {
block_hash: Default::default(),
tx_index: Default::default(),
data: Default::default()
data: Default::default(),
},
};
assert_ok!(BasicInboundChannel::submit(origin.clone(), message_2));
Expand All @@ -226,7 +227,7 @@ fn test_submit_with_invalid_nonce() {
proof: Proof {
block_hash: Default::default(),
tx_index: Default::default(),
data: Default::default()
data: Default::default(),
},
};
assert_ok!(BasicInboundChannel::submit(origin.clone(), message.clone()));
Expand Down
4 changes: 3 additions & 1 deletion parachain/pallets/basic-channel/src/inbound/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ pub trait WeightInfo {
}

impl WeightInfo for () {
fn submit() -> Weight { 0 }
fn submit() -> Weight {
0
}
}
6 changes: 1 addition & 5 deletions parachain/pallets/basic-channel/src/outbound/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
//! BasicOutboundChannel pallet benchmarking
use super::*;

use frame_benchmarking::{
benchmarks,
impl_benchmark_test_suite,
account,
};
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite};
use frame_support::traits::OnInitialize;

#[allow(unused_imports)]
Expand Down
Loading

0 comments on commit 929e2ed

Please sign in to comment.