Skip to content

Commit

Permalink
Merge branch 'feature/stake'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tore19 committed Dec 7, 2019
2 parents 5cfd3d1 + 648885e commit d21720a
Show file tree
Hide file tree
Showing 8 changed files with 392 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Cargo.lock

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

8 changes: 8 additions & 0 deletions node/modules/stafi-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ edition = "2018"
[dependencies]
serde = { version = "1.0", default_features = false }
parity-codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
sr-io = { git = "https://github.com/stafiprotocol/stafi-blockchain", default-features = false }
sr-std = { git = "https://github.com/stafiprotocol/stafi-blockchain", default-features = false }
primitives = { package = "substrate-primitives", git = "https://github.com/stafiprotocol/stafi-blockchain", default-features = false }
sr-primitives = { git = "https://github.com/stafiprotocol/stafi-blockchain", default-features = false }
support = { package = "frame-support", git = "https://github.com/stafiprotocol/stafi-blockchain", default-features = false }
system = { package = "frame-system", git = "https://github.com/stafiprotocol/stafi-blockchain", default-features = false }
Expand All @@ -25,12 +27,18 @@ stafi-multisig = { path = "../stafi-multisig", default-features = false }

log = "0.4"

[dev-dependencies]
babe = { git = "https://github.com/stafiprotocol/stafi-blockchain", package = "pallet-babe", default-features = false }
timestamp = { git = "https://github.com/stafiprotocol/stafi-blockchain", package = "pallet-timestamp", default-features = false }

[features]
default = ["std"]
std = [
"serde/std",
"parity-codec/std",
"sr-io/std",
"sr-std/std",
"primitives/std",
"sr-primitives/std",
"support/std",
"system/std",
Expand Down
5 changes: 5 additions & 0 deletions node/modules/stafi-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@

#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;

pub mod atomstaking;
pub mod xtzstaking;
148 changes: 148 additions & 0 deletions node/modules/stafi-staking/src/mock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.

// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! Test utilities
#![cfg(test)]
extern crate sr_io as runtime_io;

use crate::xtzstaking::{
Module, Trait
};
use sr_primitives::Perbill;
use sr_primitives::testing::{Header, TestXt};
use sr_primitives::traits::{IdentityLookup, BlakeTwo256};
use primitives::H256;
use support::{impl_outer_origin, impl_outer_dispatch, parameter_types};
use system;
use token_balances::bondtoken;
use stafi_offchain_worker::tezosworker;
use stafi_multisig::multisigaddr;

use node_primitives::{Moment};
use node_primitives::constants::time::*;

impl_outer_origin!{
pub enum Origin for Runtime {}
}

impl_outer_dispatch! {
pub enum Call for Runtime where origin: Origin {
xtzstaking::XtzStaking,
tezosworker::TezosWorker,
}
}

pub type AccountId = u64;
pub type Balance = u64;

/// An extrinsic type used for tests.
pub type Extrinsic = TestXt<Call, ()>;
type SubmitTransaction = system::offchain::TransactionSubmitter<(), Call, Extrinsic>;


#[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();
pub const MinimumPeriod: u64 = 1;
}

impl system::Trait for Runtime {
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
type Call = Call;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
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 TransferFee: Balance = 0;
pub const CreationFee: Balance = 0;
pub const ExistentialDeposit: Balance = 0;
}
impl balances::Trait for Runtime {
type Balance = Balance;
type OnFreeBalanceZero = ();
type OnNewAccount = ();
type Event = ();
type TransferPayment = ();
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
}

parameter_types! {
pub const EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS;
pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
}

impl babe::Trait for Runtime {
type EpochDuration = EpochDuration;
type ExpectedBlockTime = ExpectedBlockTime;
type EpochChangeTrigger = babe::ExternalTrigger;
}

impl timestamp::Trait for Runtime {
type Moment = u64;
type OnTimestampSet = ();
type MinimumPeriod = MinimumPeriod;
}

impl bondtoken::Trait for Runtime {
type Event = ();
}

impl tezosworker::Trait for Runtime {
type Event = ();
type Call = Call;
type SubmitTransaction = SubmitTransaction;
}

impl multisigaddr::Trait for Runtime {
type Event = ();
}

impl stafi_staking_storage::Trait for Runtime {}

impl Trait for Runtime {
type Event = ();
}

pub fn new_test_ext() -> runtime_io::TestExternalities {
let t = system::GenesisConfig::default().build_storage::<Runtime>().unwrap();

t.into()
}

pub type XtzStaking = Module<Runtime>;
pub type TezosWorker = tezosworker::Module<Runtime>;

55 changes: 55 additions & 0 deletions node/modules/stafi-staking/src/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.

// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! Tests for the module.
#![cfg(test)]

use crate::mock::*;
use support::{assert_ok};

#[test]
fn test_custom_stake() {
let mut ext = new_test_ext();

ext.execute_with(|| {
let account_id = 10;

let multi_sig_address: Vec<u8> = Vec::new();
let stake_amount: u128 = 11000000;
let tx_hash: Vec<u8> = Vec::new();
let block_hash: Vec<u8> = Vec::new();
let pub_key: Vec<u8> = "edpktxQpBU6FcfwXzCaZHBmyk4vr91EVi7CghSw5SrE2tWoUoZZRUX".as_bytes().to_vec();
let sig: Vec<u8> = Vec::new();

let result = XtzStaking::custom_stake(
Origin::signed(account_id),
multi_sig_address,
stake_amount,
tx_hash,
block_hash,
pub_key,
sig
);

assert_ok!(result);

if let Some(stake_records) = XtzStaking::stake_records(XtzStaking::stake_of_owner_by_index((account_id, 0))) {
assert_eq!(true, stake_records.initiator == account_id);
}

});
}
7 changes: 6 additions & 1 deletion node/modules/tokenbalances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ use support::{decl_module, decl_storage, decl_event, dispatch::Result, Parameter
use system::ensure_signed;
use parity_codec::{Codec, Encode, Decode};
use sr_primitives::traits::MaybeSerialize;
use node_primitives::{Symbol};
use node_primitives::{Symbol};

#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;

pub mod bondtoken;

Expand Down
100 changes: 100 additions & 0 deletions node/modules/tokenbalances/src/mock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.

// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! Test utilities
#![cfg(test)]
extern crate sr_io as runtime_io;

use crate::{
Module, Trait, SymbolString, DescString
};
use sr_primitives::Perbill;
use sr_primitives::testing::{Header};
use sr_primitives::traits::{IdentityLookup, BlakeTwo256};
use primitives::H256;
use support::{impl_outer_origin, parameter_types};
use system;

impl_outer_origin!{
pub enum Origin for Runtime {}
}

pub type AccountId = u64;
pub type Balance = u64;


#[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();
pub const MinimumPeriod: u64 = 1;
}

impl system::Trait for Runtime {
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
type Call = ();
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
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 TransferFee: Balance = 0;
pub const CreationFee: Balance = 0;
pub const ExistentialDeposit: Balance = 0;
}
impl balances::Trait for Runtime {
type Balance = Balance;
type OnFreeBalanceZero = ();
type OnNewAccount = ();
type Event = ();
type TransferPayment = ();
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
}

impl Trait for Runtime {
const STAFI_SYMBOL: SymbolString = b"FIS";
const STAFI_TOKEN_DESC: DescString = b"STAFI";
type Event = ();
type TokenBalance = u128;
}

pub fn new_test_ext() -> runtime_io::TestExternalities {
let t = system::GenesisConfig::default().build_storage::<Runtime>().unwrap();

t.into()
}

pub type TokenBalances = Module<Runtime>;

Loading

0 comments on commit d21720a

Please sign in to comment.