Skip to content

Commit

Permalink
98 voting pallet (Fair-Squares#108)
Browse files Browse the repository at this point in the history
* Updating branch with main updates (Fair-Squares#100)

* Runtime update

Update to polkadot-v0.9.26

* Token symbol and pallet-uniques

Added the pallet-uniques to the runtime, and changed the token Symbol to USD

* Benchmarking fixed

Co-authored-by: ndkazu <ndongmefane@gmail.com>
Co-authored-by: Kazunobu Ndong <33208377+ndkazu@users.noreply.github.com>

* Merge main into voting pallet branch (Fair-Squares#104)

* Runtime update

Update to polkadot-v0.9.26

* Token symbol and pallet-uniques

Added the pallet-uniques to the runtime, and changed the token Symbol to USD

* Benchmarking fixed

* refresh FS repo (Fair-Squares#101)

* update readme and badges

* delete diagram

* add w3f badge and adjust readme

* adjust size and position

* remove unused files

* adjusted the readme some more

* add w3f badge back

* changed from docker hub to ghcr registry

* small change to the DockerFile

* 102 automatization tasks (Fair-Squares#103)

* added a script to add a new pallet from a pallet template and configure the runtime Cargo.toml and lib.rs

* added a script to update polkadot lib in .toml files for the node, runtime, pallets and pallet template

Co-authored-by: ndkazu <ndongmefane@gmail.com>
Co-authored-by: Kazunobu Ndong <33208377+ndkazu@users.noreply.github.com>
Co-authored-by: Ilhan <29432367+ilhanu@users.noreply.github.com>
Co-authored-by: “ilhanu” <ilhanunlu@gmail.com>

* added voting pallet, added config in runtime

* added collective and democracy pallets to voting pallet and runtime config

* added collective and democracy config to runtime

* updated pallet_template

* added members to house council

* added functions to voting

* added pallet roles to voting

* update functions implementation

* added events, refactored code

* updated test configuration

* added call formating for collective::propose()

* added full process voting implementation with basic checks

* added origin check on proposal dispatching from Democracy

* added check origin call from collective pallet

* added proposal status transition management and documentation

* updated voting mockup for tests

* refactored code

* removed comments

* code review updates

* code review updates

* fix for voting benchmarking

* added fix for voting benchmarking

* fix update

* temporary deactivated voting benchmarking

* added unit tests

* added more tests

* renamed house_council to council in configuration

Co-authored-by: ndkazu <ndongmefane@gmail.com>
Co-authored-by: Kazunobu Ndong <33208377+ndkazu@users.noreply.github.com>
Co-authored-by: Ilhan <29432367+ilhanu@users.noreply.github.com>
Co-authored-by: “ilhanu” <ilhanunlu@gmail.com>
  • Loading branch information
5 people authored Aug 18, 2022
1 parent 24229d3 commit f2c046c
Show file tree
Hide file tree
Showing 5 changed files with 770 additions and 20 deletions.
4 changes: 2 additions & 2 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use fs_node_runtime::{
AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, Signature, SudoConfig,
SystemConfig, WASM_BINARY, HouseCouncilConfig
SystemConfig, WASM_BINARY, CouncilConfig
};
use sc_service::Properties;
use sc_service::ChainType;
Expand Down Expand Up @@ -163,7 +163,7 @@ fn testnet_genesis(
transaction_payment: Default::default(),
democracy: Default::default(),
treasury: Default::default(),
house_council: HouseCouncilConfig {
council: CouncilConfig {
members: vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
Expand Down
14 changes: 10 additions & 4 deletions pallets/voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ pub mod pallet {
HouseCouncilVoted(T::AccountId, T::Hash, BlockNumberOf<T>),
/// A investor has voted
InvestorVoted(T::AccountId, T::Hash, BlockNumberOf<T>),
/// The investor vote session has started
InvestorVoteSessionStarted(T::Hash, BlockNumberOf<T>),
/// TODO: to remove, Event for test purpose
CollectiveMotionChecked(BlockNumberOf<T>),
/// TODO: to remove, Event for test purpose
Expand Down Expand Up @@ -253,7 +255,7 @@ pub mod pallet {

let block_number = <frame_system::Pallet<T>>::block_number();

let collective_motion_duration = block_number.saturating_add(<T as COLL::Config<Instance1>>::MotionDuration::get()).saturating_add(T::CheckDelay::get());
let collective_motion_duration = block_number.saturating_add(<T as COLL::Config<Instance1>>::MotionDuration::get()).saturating_add(T::Delay::get());

// Add the proposal to the collective watchlist
CollectiveProposals::<T>::insert(proposal_hash, collective_motion_duration);
Expand Down Expand Up @@ -303,7 +305,8 @@ pub mod pallet {
let delay = <T as Config>::Delay::get();

// Start Democracy referendum
let referendum_index = DEMO::Pallet::<T>::internal_start_referendum(proposal_hash, threshold,delay);

let referendum_index = DEMO::Pallet::<T>::internal_start_referendum(proposal_hash.clone(), threshold,delay);

// Update the voting
let mut proposal = VotingProposals::<T>::get(proposal_id).unwrap();
Expand All @@ -323,6 +326,8 @@ pub mod pallet {
// Execute the dispatch for collective vote passed
proposal.collective_passed_call.dispatch(frame_system::RawOrigin::Signed(account_id).into());

Self::deposit_event(Event::InvestorVoteSessionStarted(proposal_hash, block_number));

Ok(().into())
}

Expand Down Expand Up @@ -540,7 +545,8 @@ impl<T: Config> Pallet<T>
let mut collectives_hash = Vec::new();

for elt in collectives_iter {
if elt.1 < now {
if elt.1 <= now {

let voting = VotingProposals::<T>::get(elt.0).unwrap();

if voting.collective_closed {
Expand All @@ -564,7 +570,7 @@ impl<T: Config> Pallet<T>
let mut democracies_hash = Vec::new();

for elt in democracies_iter {
if elt.1 < now {
if elt.1 <= now {
let voting = VotingProposals::<T>::get(elt.0).unwrap();

if !voting.proposal_executed {
Expand Down
60 changes: 47 additions & 13 deletions pallets/voting/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use frame_support::{

};

use pallet_roles::GenesisBuild;
use pallet_collective::PrimeDefaultVote;
use frame_system::{EnsureRoot,EnsureSigned};
use frame_support::pallet_prelude::Weight;
Expand Down Expand Up @@ -46,7 +47,7 @@ pub type BlockNumber = u64;
pub type Balance = u128;

parameter_types! {
pub const MotionDuration: u64 = 3;
pub const MotionDuration: u64 = 2;
pub const MaxProposals: u32 = 100;
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
Expand Down Expand Up @@ -93,9 +94,9 @@ impl pallet_roles::Config for Test {

parameter_types! {
pub const Delay: BlockNumber = 0;//3 * MINUTES;
pub const CheckDelay: BlockNumber = 1 * 60_000;//3 * MINUTES;
pub const InvestorVoteAmount: u128 = 10 * 1000000;
pub const CheckPeriod: BlockNumber = 1 * 60_000;
pub const CheckDelay: BlockNumber = 1;//3 * MINUTES;
pub const InvestorVoteAmount: u128 = 1;
pub const CheckPeriod: BlockNumber = 1;
}

impl pallet_voting::Config for Test {
Expand All @@ -112,12 +113,16 @@ impl pallet_voting::Config for Test {

}

parameter_types! {
pub const CouncilMotionDuration: BlockNumber = 2;
}

type CouncilCollective = pallet_collective::Instance1;
impl COLL::Config<Instance1> for Test {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
type MotionDuration = ConstU64<3>;
type MotionDuration = CouncilMotionDuration;
type MaxProposals = MaxProposals;
type MaxMembers = MaxMembers;
type DefaultVote = PrimeDefaultVote;
Expand Down Expand Up @@ -157,15 +162,15 @@ impl pallet_balances::Config for Test {
}

parameter_types! {
pub const LaunchPeriod: BlockNumber = 5; //ok
pub const LaunchPeriod: BlockNumber = 1; //ok
pub const VotingPeriod: BlockNumber = 5; //ok
pub const FastTrackVotingPeriod: BlockNumber = 2; //ok
pub const FastTrackVotingPeriod: BlockNumber = 20; //ok
pub const InstantAllowed: bool = true; //ok
pub const MinimumDeposit: Balance = 100; //ok
pub const EnactmentPeriod: BlockNumber = 5; //ok
pub const CooloffPeriod: BlockNumber = 5; //ok
pub const PreimageByteDeposit: Balance = 1; //ok
pub const MaxVotes: u32 = 100;
pub const MinimumDeposit: Balance = 1; //ok
pub const EnactmentPeriod: BlockNumber = 200; //ok
pub const CooloffPeriod: BlockNumber = 200; //ok
pub const PreimageByteDeposit: Balance = 10; //ok
pub const MaxVotes: u32 = 4;
}

impl pallet_democracy::Config for Test {
Expand Down Expand Up @@ -200,9 +205,38 @@ impl pallet_democracy::Config for Test {
}


pub const ALICE: u64 = 1;
pub const BOB: u64 = 2;
pub const CHARLIE: u64 = 3;
pub const DAVE: u64 = 4;
pub const EVE: u64 = 5;


// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
frame_system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
// frame_system::GenesisConfig::default().build_storage::<Test>().unwrap().into()

let mut storage = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();

// Initialize balances
pallet_balances::GenesisConfig::<Test> {
balances: vec![(ALICE, 200_000 ), (BOB, 200_000_000 ), (CHARLIE, 200_000_000 ), (DAVE, 150_000), (EVE, 150_000 )],
}
.assimilate_storage(&mut storage)
.unwrap();

pallet_collective::GenesisConfig::<Test, pallet_collective::Instance1> {
members: vec![ALICE, BOB, CHARLIE, DAVE],
phantom: Default::default(),
}
.assimilate_storage(&mut storage)
.unwrap();

pallet_sudo::GenesisConfig::<Test> { key: Some(ALICE) }
.assimilate_storage(&mut storage)
.unwrap();

let mut externalities = sp_io::TestExternalities::new(storage);
externalities.execute_with(|| System::set_block_number(1));
externalities
}
Loading

0 comments on commit f2c046c

Please sign in to comment.