-
Notifications
You must be signed in to change notification settings - Fork 49
EthRelay module tests #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
395f64c
add tests for eth relay
hackfisher 10bd5ad
reciept can be read from proof, removing from parameter, but test fail
hackfisher df6284e
remove receipt parameter from call, Fixed #128
hackfisher efc566a
Eliminate warning, Fixed #136
hackfisher 7dd455c
move #[cfg(test)] to lib.rs
hackfisher b2c2275
resolve conflicts
hackfisher 6d3a754
rename token migrate module to eth-backing
hackfisher 24e53e1
add relay header tests, leaving genesis total Difficulty settings to do.
hackfisher 914f3f5
add genesis total difficulty and more tests
hackfisher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| //! Test utilities | ||
|
|
||
| #![cfg(test)] | ||
hackfisher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| use crate::{GenesisConfig, Module, Trait}; | ||
| use primitives::H256; | ||
| use runtime_io; | ||
| use sr_primitives::{ | ||
| testing::Header, | ||
| traits::{ConvertInto, IdentityLookup}, | ||
| weights::{DispatchInfo, Weight}, | ||
| Perbill, | ||
| }; | ||
| use std::cell::RefCell; | ||
| use support::traits::Get; | ||
| use support::{impl_outer_origin, parameter_types}; | ||
|
|
||
| impl_outer_origin! { | ||
| pub enum Origin for Runtime {} | ||
| } | ||
|
|
||
| thread_local! { | ||
| static EXISTENTIAL_DEPOSIT: RefCell<u64> = RefCell::new(0); | ||
| static TRANSFER_FEE: RefCell<u64> = RefCell::new(0); | ||
| static CREATION_FEE: RefCell<u64> = RefCell::new(0); | ||
| } | ||
|
|
||
| pub struct ExistentialDeposit; | ||
| impl Get<u64> for ExistentialDeposit { | ||
| fn get() -> u64 { | ||
| EXISTENTIAL_DEPOSIT.with(|v| *v.borrow()) | ||
| } | ||
| } | ||
|
|
||
| pub struct TransferFee; | ||
| impl Get<u64> for TransferFee { | ||
| fn get() -> u64 { | ||
| TRANSFER_FEE.with(|v| *v.borrow()) | ||
| } | ||
| } | ||
|
|
||
| pub struct CreationFee; | ||
| impl Get<u64> for CreationFee { | ||
| fn get() -> u64 { | ||
| CREATION_FEE.with(|v| *v.borrow()) | ||
| } | ||
| } | ||
|
|
||
| // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted. | ||
| #[derive(Clone, PartialEq, Eq, Debug)] | ||
| pub struct Runtime; | ||
| parameter_types! { | ||
| pub const BlockHashCount: u64 = 250; | ||
| pub const MaximumBlockWeight: u32 = 1024; | ||
| pub const MaximumBlockLength: u32 = 2 * 1024; | ||
| pub const AvailableBlockRatio: Perbill = Perbill::one(); | ||
| } | ||
| impl system::Trait for Runtime { | ||
| type Origin = Origin; | ||
| type Index = u64; | ||
| type BlockNumber = u64; | ||
| type Call = (); | ||
| type Hash = H256; | ||
| type Hashing = ::sr_primitives::traits::BlakeTwo256; | ||
| type AccountId = u64; | ||
| type Lookup = IdentityLookup<Self::AccountId>; | ||
| type Header = Header; | ||
| type Event = (); | ||
| type BlockHashCount = BlockHashCount; | ||
| type MaximumBlockWeight = MaximumBlockWeight; | ||
| type MaximumBlockLength = MaximumBlockLength; | ||
| type AvailableBlockRatio = AvailableBlockRatio; | ||
| type Version = (); | ||
| } | ||
| parameter_types! { | ||
| pub const TransactionBaseFee: u64 = 0; | ||
| pub const TransactionByteFee: u64 = 1; | ||
| } | ||
|
|
||
| impl Trait for Runtime { | ||
| type Event = (); | ||
| } | ||
|
|
||
| parameter_types! { | ||
| pub const MinimumPeriod: u64 = 5; | ||
| } | ||
|
|
||
| pub struct ExtBuilder { | ||
| existential_deposit: u64, | ||
| transfer_fee: u64, | ||
| creation_fee: u64, | ||
| monied: bool, | ||
| vesting: bool, | ||
| } | ||
| impl Default for ExtBuilder { | ||
| fn default() -> Self { | ||
| Self { | ||
| existential_deposit: 0, | ||
| transfer_fee: 0, | ||
| creation_fee: 0, | ||
| monied: false, | ||
| vesting: false, | ||
| } | ||
| } | ||
| } | ||
| impl ExtBuilder { | ||
| pub fn existential_deposit(mut self, existential_deposit: u64) -> Self { | ||
| self.existential_deposit = existential_deposit; | ||
| self | ||
| } | ||
| #[allow(dead_code)] | ||
| pub fn transfer_fee(mut self, transfer_fee: u64) -> Self { | ||
| self.transfer_fee = transfer_fee; | ||
| self | ||
| } | ||
| pub fn creation_fee(mut self, creation_fee: u64) -> Self { | ||
| self.creation_fee = creation_fee; | ||
| self | ||
| } | ||
| pub fn monied(mut self, monied: bool) -> Self { | ||
| self.monied = monied; | ||
| if self.existential_deposit == 0 { | ||
| self.existential_deposit = 1; | ||
| } | ||
| self | ||
| } | ||
| pub fn vesting(mut self, vesting: bool) -> Self { | ||
| self.vesting = vesting; | ||
| self | ||
| } | ||
| pub fn set_associated_consts(&self) { | ||
| EXISTENTIAL_DEPOSIT.with(|v| *v.borrow_mut() = self.existential_deposit); | ||
| TRANSFER_FEE.with(|v| *v.borrow_mut() = self.transfer_fee); | ||
| CREATION_FEE.with(|v| *v.borrow_mut() = self.creation_fee); | ||
| } | ||
| pub fn build(self) -> runtime_io::TestExternalities { | ||
| self.set_associated_consts(); | ||
| let mut t = system::GenesisConfig::default().build_storage::<Runtime>().unwrap(); | ||
|
|
||
| t.into() | ||
| } | ||
| } | ||
|
|
||
| pub type System = system::Module<Runtime>; | ||
| pub type EthRelay = Module<Runtime>; | ||
|
|
||
| pub const CALL: &<Runtime as system::Trait>::Call = &(); | ||
|
|
||
| /// create a transaction info struct from weight. Handy to avoid building the whole struct. | ||
| pub fn info_from_weight(w: Weight) -> DispatchInfo { | ||
| DispatchInfo { | ||
| weight: w, | ||
| ..Default::default() | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.