Refactor and timestamp test

This commit is contained in:
Gav
2018-01-19 08:49:38 +01:00
parent f179adbc4e
commit ba0d71a551
9 changed files with 110 additions and 72 deletions
@@ -1,6 +1,6 @@
use runtime::{staking, session};
use primitives::AccountID;
use streamreader::StreamReader;
use runtime::{staking, session, timestamp};
/// The functions that a transaction can call (and be dispatched to).
#[cfg_attr(test, derive(PartialEq, Debug))]
@@ -8,8 +8,9 @@ use streamreader::StreamReader;
pub enum Function {
StakingStake,
StakingUnstake,
StakingTransferStake,
StakingTransferInactive,
SessionSetKey,
TimestampSet,
}
impl Function {
@@ -17,8 +18,9 @@ impl Function {
match value {
x if x == Function::StakingStake as u8 => Some(Function::StakingStake),
x if x == Function::StakingUnstake as u8 => Some(Function::StakingUnstake),
x if x == Function::StakingTransferStake as u8 => Some(Function::StakingTransferStake),
x if x == Function::StakingTransferInactive as u8 => Some(Function::StakingTransferInactive),
x if x == Function::SessionSetKey as u8 => Some(Function::SessionSetKey),
x if x == Function::TimestampSet as u8 => Some(Function::TimestampSet),
_ => None,
}
}
@@ -35,15 +37,19 @@ impl Function {
Function::StakingUnstake => {
staking::unstake(transactor);
}
Function::StakingTransferStake => {
Function::StakingTransferInactive => {
let dest = params.read().unwrap();
let value = params.read().unwrap();
staking::transfer_stake(transactor, &dest, value);
staking::transfer_inactive(transactor, &dest, value);
}
Function::SessionSetKey => {
let session = params.read().unwrap();
session::set_key(transactor, &session);
}
Function::TimestampSet => {
let t = params.read().unwrap();
timestamp::set(t);
}
}
}
}
@@ -6,4 +6,5 @@ pub mod storage;
#[cfg(test)]
pub mod statichex;
#[cfg(test)]
#[macro_use]
pub mod testing;
@@ -253,7 +253,7 @@ mod tests {
let tx = Transaction {
signed: one.clone(),
nonce: 69,
function: Function::StakingTransferStake,
function: Function::StakingTransferInactive,
input_data: Vec::new().join(&two).join(&69u64),
};
let serialised = tx.to_vec();
@@ -274,7 +274,7 @@ mod tests {
let tx = Transaction {
signed: one.clone(),
nonce: 69,
function: Function::StakingTransferStake,
function: Function::StakingTransferInactive,
input_data: Vec::new().join(&two).join(&69u64),
};
let data = [
@@ -344,7 +344,7 @@ mod tests {
transaction: Transaction {
signed: one.clone(),
nonce: 69,
function: Function::StakingTransferStake,
function: Function::StakingTransferInactive,
input_data: Vec::new().join(&two).join(&69u64),
},
signature: [1u8; 64],
@@ -408,7 +408,7 @@ mod tests {
transaction: Transaction {
signed: one.clone(),
nonce: 69,
function: Function::StakingTransferStake,
function: Function::StakingTransferInactive,
input_data: Vec::new().join(&two).join(&69u64),
},
signature: [1u8; 64],
@@ -1,5 +1,7 @@
use runtime_support::{NoError, Externalities};
use std::collections::HashMap;
use primitives::AccountID;
use statichex::StaticHexInto;
#[derive(Debug, Default)]
pub struct TestExternalities {
@@ -20,6 +22,20 @@ impl Externalities for TestExternalities {
fn chain_id(&self) -> u64 { 42 }
}
#[macro_export]
macro_rules! map {
($( $name:expr => $value:expr ),*) => (
vec![ $( ( $name, $value ) ),* ].into_iter().collect()
)
}
pub fn one() -> AccountID {
"2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee".convert()
}
pub fn two() -> AccountID {
"d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a".convert()
}
pub struct HexDisplay<'a>(&'a [u8]);
impl<'a> HexDisplay<'a> {