feat: Rebrand Polkadot/Substrate references to PezkuwiChain

This commit systematically rebrands various references from Parity Technologies'
Polkadot/Substrate ecosystem to PezkuwiChain within the kurdistan-sdk.

Key changes include:
- Updated external repository URLs (zombienet-sdk, parity-db, parity-scale-codec, wasm-instrument) to point to pezkuwichain forks.
- Modified internal documentation and code comments to reflect PezkuwiChain naming and structure.
- Replaced direct references to  with  or specific paths within the  for XCM, Pezkuwi, and other modules.
- Cleaned up deprecated  issue and PR references in various  and  files, particularly in  and  modules.
- Adjusted image and logo URLs in documentation to point to PezkuwiChain assets.
- Removed or rephrased comments related to external Polkadot/Substrate PRs and issues.

This is a significant step towards fully customizing the SDK for the PezkuwiChain ecosystem.
This commit is contained in:
2025-12-14 00:04:10 +03:00
parent 286de54384
commit 1c0e57d984
9084 changed files with 997839 additions and 997557 deletions
@@ -0,0 +1,75 @@
// This file is part of Bizinikiwi.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! The tests for cancellation functionality.
use super::*;
#[test]
fn cancel_referendum_should_work() {
new_test_ext().execute_with(|| {
let r = Democracy::inject_referendum(
2,
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
assert_ok!(Democracy::cancel_referendum(RuntimeOrigin::root(), r.into()));
assert_eq!(LowestUnbaked::<Test>::get(), 0);
next_block();
next_block();
assert_eq!(LowestUnbaked::<Test>::get(), 1);
assert_eq!(LowestUnbaked::<Test>::get(), ReferendumCount::<Test>::get());
assert_eq!(Balances::free_balance(42), 0);
});
}
#[test]
fn emergency_cancel_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
let r = Democracy::inject_referendum(
2,
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
2,
);
assert!(Democracy::referendum_status(r).is_ok());
assert_noop!(Democracy::emergency_cancel(RuntimeOrigin::signed(3), r), BadOrigin);
assert_ok!(Democracy::emergency_cancel(RuntimeOrigin::signed(4), r));
assert!(ReferendumInfoOf::<Test>::get(r).is_none());
// some time later...
let r = Democracy::inject_referendum(
2,
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
2,
);
assert!(Democracy::referendum_status(r).is_ok());
assert_noop!(
Democracy::emergency_cancel(RuntimeOrigin::signed(4), r),
Error::<Test>::AlreadyCanceled,
);
});
}
@@ -0,0 +1,57 @@
// This file is part of Bizinikiwi.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! The for various partial storage decoders
use super::*;
use pezframe_support::{
storage::{migration, unhashed},
BoundedVec,
};
#[test]
fn test_decode_compact_u32_at() {
new_test_ext().execute_with(|| {
let v = codec::Compact(u64::MAX);
migration::put_storage_value(b"test", b"", &[], v);
assert_eq!(decode_compact_u32_at(b"test"), None);
for v in vec![0, 10, u32::MAX] {
let compact_v = codec::Compact(v);
unhashed::put(b"test", &compact_v);
assert_eq!(decode_compact_u32_at(b"test"), Some(v));
}
unhashed::kill(b"test");
assert_eq!(decode_compact_u32_at(b"test"), None);
})
}
#[test]
fn len_of_deposit_of() {
new_test_ext().execute_with(|| {
for l in vec![0, 1, 200, 1000] {
let value: (BoundedVec<u64, _>, u64) =
((0..l).map(|_| Default::default()).collect::<Vec<_>>().try_into().unwrap(), 3u64);
DepositOf::<Test>::insert(2, value);
assert_eq!(Democracy::len_of_deposit_of(2), Some(l));
}
DepositOf::<Test>::remove(2);
assert_eq!(Democracy::len_of_deposit_of(2), None);
})
}
@@ -0,0 +1,222 @@
// This file is part of Bizinikiwi.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! The tests for functionality concerning delegation.
use super::*;
#[test]
fn single_proposal_should_work_with_delegation() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(propose_set_balance(1, 2, 1));
fast_forward_to(2);
// Delegate first vote.
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::None, 20));
let r = 0;
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
assert_eq!(tally(r), Tally { ayes: 3, nays: 0, turnout: 30 });
// Delegate a second vote.
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(3), 1, Conviction::None, 30));
assert_eq!(tally(r), Tally { ayes: 6, nays: 0, turnout: 60 });
// Reduce first vote.
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::None, 10));
assert_eq!(tally(r), Tally { ayes: 5, nays: 0, turnout: 50 });
// Second vote delegates to first; we don't do tiered delegation, so it doesn't get used.
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(3), 2, Conviction::None, 30));
assert_eq!(tally(r), Tally { ayes: 2, nays: 0, turnout: 20 });
// Main voter cancels their vote
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(1), r));
assert_eq!(tally(r), Tally { ayes: 0, nays: 0, turnout: 0 });
// First delegator delegates half funds with conviction; nothing changes yet.
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::Locked1x, 10));
assert_eq!(tally(r), Tally { ayes: 0, nays: 0, turnout: 0 });
// Main voter reinstates their vote
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
assert_eq!(tally(r), Tally { ayes: 11, nays: 0, turnout: 20 });
});
}
#[test]
fn self_delegation_not_allowed() {
new_test_ext().execute_with(|| {
assert_noop!(
Democracy::delegate(RuntimeOrigin::signed(1), 1, Conviction::None, 10),
Error::<Test>::Nonsense,
);
});
}
#[test]
fn cyclic_delegation_should_unwind() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(propose_set_balance(1, 2, 1));
fast_forward_to(2);
// Check behavior with cycle.
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::None, 20));
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(3), 2, Conviction::None, 30));
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(1), 3, Conviction::None, 10));
let r = 0;
assert_ok!(Democracy::undelegate(RuntimeOrigin::signed(3)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(3), r, aye(3)));
assert_ok!(Democracy::undelegate(RuntimeOrigin::signed(1)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, nay(1)));
// Delegated vote is counted.
assert_eq!(tally(r), Tally { ayes: 3, nays: 3, turnout: 60 });
});
}
#[test]
fn single_proposal_should_work_with_vote_and_delegation() {
// If transactor already voted, delegated vote is overwritten.
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(propose_set_balance(1, 2, 1));
fast_forward_to(2);
let r = 0;
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(2), r, nay(2)));
assert_eq!(tally(r), Tally { ayes: 1, nays: 2, turnout: 30 });
// Delegate vote.
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(2), r));
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::None, 20));
// Delegated vote replaces the explicit vote.
assert_eq!(tally(r), Tally { ayes: 3, nays: 0, turnout: 30 });
});
}
#[test]
fn single_proposal_should_work_with_undelegation() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(propose_set_balance(1, 2, 1));
// Delegate and undelegate vote.
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::None, 20));
assert_ok!(Democracy::undelegate(RuntimeOrigin::signed(2)));
fast_forward_to(2);
let r = 0;
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
// Delegated vote is not counted.
assert_eq!(tally(r), Tally { ayes: 1, nays: 0, turnout: 10 });
});
}
#[test]
fn single_proposal_should_work_with_delegation_and_vote() {
// If transactor voted, delegated vote is overwritten.
new_test_ext().execute_with(|| {
let r = begin_referendum();
// Delegate, undelegate and vote.
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::None, 20));
assert_eq!(tally(r), Tally { ayes: 3, nays: 0, turnout: 30 });
assert_ok!(Democracy::undelegate(RuntimeOrigin::signed(2)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(2), r, aye(2)));
// Delegated vote is not counted.
assert_eq!(tally(r), Tally { ayes: 3, nays: 0, turnout: 30 });
});
}
#[test]
fn conviction_should_be_honored_in_delegation() {
// If transactor voted, delegated vote is overwritten.
new_test_ext().execute_with(|| {
let r = begin_referendum();
// Delegate and vote.
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::Locked6x, 20));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
// Delegated vote is huge.
assert_eq!(tally(r), Tally { ayes: 121, nays: 0, turnout: 30 });
});
}
#[test]
fn split_vote_delegation_should_be_ignored() {
// If transactor voted, delegated vote is overwritten.
new_test_ext().execute_with(|| {
let r = begin_referendum();
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::Locked6x, 20));
assert_ok!(Democracy::vote(
RuntimeOrigin::signed(1),
r,
AccountVote::Split { aye: 10, nay: 0 }
));
// Delegated vote is huge.
assert_eq!(tally(r), Tally { ayes: 1, nays: 0, turnout: 10 });
});
}
#[test]
fn redelegation_keeps_lock() {
// If transactor voted, delegated vote is overwritten.
new_test_ext().execute_with(|| {
let r = begin_referendum();
// Delegate and vote.
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::Locked6x, 20));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
// Delegated vote is huge.
assert_eq!(tally(r), Tally { ayes: 121, nays: 0, turnout: 30 });
let mut prior_lock = vote::PriorLock::default();
// Locked balance of delegator exists
assert_eq!(VotingOf::<Test>::get(2).locked_balance(), 20);
assert_eq!(VotingOf::<Test>::get(2).prior(), &prior_lock);
// Delegate someone else at a lower conviction and amount
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 3, Conviction::None, 10));
// 6x prior should appear w/ locked balance.
prior_lock.accumulate(98, 20);
assert_eq!(VotingOf::<Test>::get(2).prior(), &prior_lock);
assert_eq!(VotingOf::<Test>::get(2).locked_balance(), 20);
// Unlock shouldn't work
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(2), 2));
assert_eq!(VotingOf::<Test>::get(2).prior(), &prior_lock);
assert_eq!(VotingOf::<Test>::get(2).locked_balance(), 20);
fast_forward_to(100);
// Now unlock can remove the prior lock and reduce the locked amount.
assert_eq!(VotingOf::<Test>::get(2).prior(), &prior_lock);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(2), 2));
assert_eq!(VotingOf::<Test>::get(2).prior(), &vote::PriorLock::default());
assert_eq!(VotingOf::<Test>::get(2).locked_balance(), 10);
});
}
@@ -0,0 +1,276 @@
// This file is part of Bizinikiwi.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! The tests for functionality concerning the "external" origin.
use super::*;
#[test]
fn veto_external_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),));
assert!(NextExternal::<Test>::exists());
let h = set_balance_proposal(2).hash();
assert_ok!(Democracy::veto_external(RuntimeOrigin::signed(3), h));
// cancelled.
assert!(!NextExternal::<Test>::exists());
// fails - same proposal can't be resubmitted.
assert_noop!(
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),),
Error::<Test>::ProposalBlacklisted
);
fast_forward_to(1);
// fails as we're still in cooloff period.
assert_noop!(
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),),
Error::<Test>::ProposalBlacklisted
);
fast_forward_to(2);
// works; as we're out of the cooloff period.
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),));
assert!(NextExternal::<Test>::exists());
// 3 can't veto the same thing twice.
assert_noop!(
Democracy::veto_external(RuntimeOrigin::signed(3), h),
Error::<Test>::AlreadyVetoed
);
// 4 vetoes.
assert_ok!(Democracy::veto_external(RuntimeOrigin::signed(4), h));
// cancelled again.
assert!(!NextExternal::<Test>::exists());
fast_forward_to(3);
// same proposal fails as we're still in cooloff
assert_noop!(
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2)),
Error::<Test>::ProposalBlacklisted
);
// different proposal works fine.
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(3),));
});
}
#[test]
fn external_blacklisting_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),));
let hash = set_balance_proposal(2).hash();
assert_ok!(Democracy::blacklist(RuntimeOrigin::root(), hash, None));
fast_forward_to(2);
assert_noop!(Democracy::referendum_status(0), Error::<Test>::ReferendumInvalid);
assert_noop!(
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2)),
Error::<Test>::ProposalBlacklisted,
);
});
}
#[test]
fn external_referendum_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_noop!(
Democracy::external_propose(RuntimeOrigin::signed(1), set_balance_proposal(2),),
BadOrigin,
);
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),));
assert_noop!(
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(1),),
Error::<Test>::DuplicateProposal
);
fast_forward_to(2);
assert_eq!(
Democracy::referendum_status(0),
Ok(ReferendumStatus {
end: 4,
proposal: set_balance_proposal(2),
threshold: VoteThreshold::SuperMajorityApprove,
delay: 2,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
})
);
});
}
#[test]
fn external_majority_referendum_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_noop!(
Democracy::external_propose_majority(RuntimeOrigin::signed(1), set_balance_proposal(2)),
BadOrigin,
);
assert_ok!(Democracy::external_propose_majority(
RuntimeOrigin::signed(3),
set_balance_proposal(2)
));
fast_forward_to(2);
assert_eq!(
Democracy::referendum_status(0),
Ok(ReferendumStatus {
end: 4,
proposal: set_balance_proposal(2),
threshold: VoteThreshold::SimpleMajority,
delay: 2,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
})
);
});
}
#[test]
fn external_default_referendum_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_noop!(
Democracy::external_propose_default(RuntimeOrigin::signed(3), set_balance_proposal(2)),
BadOrigin,
);
assert_ok!(Democracy::external_propose_default(
RuntimeOrigin::signed(1),
set_balance_proposal(2)
));
fast_forward_to(2);
assert_eq!(
Democracy::referendum_status(0),
Ok(ReferendumStatus {
end: 4,
proposal: set_balance_proposal(2),
threshold: VoteThreshold::SuperMajorityAgainst,
delay: 2,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
})
);
});
}
#[test]
fn external_and_public_interleaving_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(1),));
assert_ok!(propose_set_balance(6, 2, 2));
fast_forward_to(2);
// both waiting: external goes first.
assert_eq!(
Democracy::referendum_status(0),
Ok(ReferendumStatus {
end: 4,
proposal: set_balance_proposal(1),
threshold: VoteThreshold::SuperMajorityApprove,
delay: 2,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
})
);
// replenish external
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(3),));
fast_forward_to(4);
// both waiting: public goes next.
assert_eq!(
Democracy::referendum_status(1),
Ok(ReferendumStatus {
end: 6,
proposal: set_balance_proposal(2),
threshold: VoteThreshold::SuperMajorityApprove,
delay: 2,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
})
);
// don't replenish public
fast_forward_to(6);
// it's external "turn" again, though since public is empty that doesn't really matter
assert_eq!(
Democracy::referendum_status(2),
Ok(ReferendumStatus {
end: 8,
proposal: set_balance_proposal(3),
threshold: VoteThreshold::SuperMajorityApprove,
delay: 2,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
})
);
// replenish external
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(5),));
fast_forward_to(8);
// external goes again because there's no public waiting.
assert_eq!(
Democracy::referendum_status(3),
Ok(ReferendumStatus {
end: 10,
proposal: set_balance_proposal(5),
threshold: VoteThreshold::SuperMajorityApprove,
delay: 2,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
})
);
// replenish both
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(7),));
assert_ok!(propose_set_balance(6, 4, 2));
fast_forward_to(10);
// public goes now since external went last time.
assert_eq!(
Democracy::referendum_status(4),
Ok(ReferendumStatus {
end: 12,
proposal: set_balance_proposal(4),
threshold: VoteThreshold::SuperMajorityApprove,
delay: 2,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
})
);
// replenish public again
assert_ok!(propose_set_balance(6, 6, 2));
// cancel external
let h = set_balance_proposal(7).hash();
assert_ok!(Democracy::veto_external(RuntimeOrigin::signed(3), h));
fast_forward_to(12);
// public goes again now since there's no external waiting.
assert_eq!(
Democracy::referendum_status(5),
Ok(ReferendumStatus {
end: 14,
proposal: set_balance_proposal(6),
threshold: VoteThreshold::SuperMajorityApprove,
delay: 2,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
})
);
});
}
@@ -0,0 +1,164 @@
// This file is part of Bizinikiwi.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! The tests for fast-tracking functionality.
use super::*;
#[test]
fn fast_track_referendum_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
let h = set_balance_proposal(2).hash();
assert_noop!(
Democracy::fast_track(RuntimeOrigin::signed(5), h, 3, 2),
Error::<Test>::ProposalMissing
);
assert_ok!(Democracy::external_propose_majority(
RuntimeOrigin::signed(3),
set_balance_proposal(2)
));
let hash = note_preimage(1);
assert!(MetadataOf::<Test>::get(MetadataOwner::External).is_none());
assert_ok!(Democracy::set_metadata(
RuntimeOrigin::signed(3),
MetadataOwner::External,
Some(hash),
),);
assert!(MetadataOf::<Test>::get(MetadataOwner::External).is_some());
assert_noop!(Democracy::fast_track(RuntimeOrigin::signed(1), h, 3, 2), BadOrigin);
assert_ok!(Democracy::fast_track(RuntimeOrigin::signed(5), h, 2, 0));
assert_eq!(
Democracy::referendum_status(0),
Ok(ReferendumStatus {
end: 2,
proposal: set_balance_proposal(2),
threshold: VoteThreshold::SimpleMajority,
delay: 0,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
})
);
// metadata reset from the external proposal to the referendum.
assert!(MetadataOf::<Test>::get(MetadataOwner::External).is_none());
assert!(MetadataOf::<Test>::get(MetadataOwner::Referendum(0)).is_some());
});
}
#[test]
fn instant_referendum_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
let h = set_balance_proposal(2).hash();
assert_noop!(
Democracy::fast_track(RuntimeOrigin::signed(5), h, 3, 2),
Error::<Test>::ProposalMissing
);
assert_ok!(Democracy::external_propose_majority(
RuntimeOrigin::signed(3),
set_balance_proposal(2)
));
assert_noop!(Democracy::fast_track(RuntimeOrigin::signed(1), h, 3, 2), BadOrigin);
assert_noop!(Democracy::fast_track(RuntimeOrigin::signed(5), h, 1, 0), BadOrigin);
assert_noop!(
Democracy::fast_track(RuntimeOrigin::signed(6), h, 1, 0),
Error::<Test>::InstantNotAllowed
);
INSTANT_ALLOWED.with(|v| *v.borrow_mut() = true);
assert_noop!(
Democracy::fast_track(RuntimeOrigin::signed(6), h, 0, 0),
Error::<Test>::VotingPeriodLow
);
assert_ok!(Democracy::fast_track(RuntimeOrigin::signed(6), h, 1, 0));
assert_eq!(
Democracy::referendum_status(0),
Ok(ReferendumStatus {
end: 1,
proposal: set_balance_proposal(2),
threshold: VoteThreshold::SimpleMajority,
delay: 0,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
})
);
});
}
#[test]
fn instant_next_block_referendum_backed() {
new_test_ext().execute_with(|| {
// arrange
let start_block_number = 10;
let majority_origin_id = 3;
let instant_origin_id = 6;
let voting_period = 1;
let proposal = set_balance_proposal(2);
let delay = 2; // has no effect on test
// init
System::set_block_number(start_block_number);
InstantAllowed::set(true);
// propose with majority origin
assert_ok!(Democracy::external_propose_majority(
RuntimeOrigin::signed(majority_origin_id),
proposal.clone()
));
// fast track with instant origin and voting period pointing to the next block
assert_ok!(Democracy::fast_track(
RuntimeOrigin::signed(instant_origin_id),
proposal.hash(),
voting_period,
delay
));
// fetch the status of the only referendum at index 0
assert_eq!(
Democracy::referendum_status(0),
Ok(ReferendumStatus {
end: start_block_number + voting_period,
proposal,
threshold: VoteThreshold::SimpleMajority,
delay,
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
})
);
// referendum expected to be baked with the start of the next block
next_block();
// assert no active referendums
assert_noop!(Democracy::referendum_status(0), Error::<Test>::ReferendumInvalid);
// the only referendum in the storage is finished and not approved
assert_eq!(
ReferendumInfoOf::<Test>::get(0).unwrap(),
ReferendumInfo::Finished { approved: false, end: start_block_number + voting_period }
);
});
}
#[test]
fn fast_track_referendum_fails_when_no_simple_majority() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
let h = set_balance_proposal(2).hash();
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2)));
assert_noop!(
Democracy::fast_track(RuntimeOrigin::signed(5), h, 3, 2),
Error::<Test>::NotSimpleMajority
);
});
}
@@ -0,0 +1,364 @@
// This file is part of Bizinikiwi.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! The tests for functionality concerning locking and lock-voting.
use super::*;
fn aye(x: u8, balance: u64) -> AccountVote<u64> {
AccountVote::Standard {
vote: Vote { aye: true, conviction: Conviction::try_from(x).unwrap() },
balance,
}
}
fn nay(x: u8, balance: u64) -> AccountVote<u64> {
AccountVote::Standard {
vote: Vote { aye: false, conviction: Conviction::try_from(x).unwrap() },
balance,
}
}
fn the_lock(amount: u64) -> BalanceLock<u64> {
BalanceLock { id: DEMOCRACY_ID, amount, reasons: pezpallet_balances::Reasons::All }
}
#[test]
fn lock_voting_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
let r = Democracy::inject_referendum(
2,
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, nay(5, 10)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(2), r, aye(4, 20)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(3), r, aye(3, 30)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(4), r, aye(2, 40)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r, nay(1, 50)));
assert_eq!(tally(r), Tally { ayes: 250, nays: 100, turnout: 150 });
// All balances are currently locked.
for i in 1..=5 {
assert_eq!(pezpallet_balances::Locks::<Test>::get(&i), vec![the_lock(i * 10)]);
}
fast_forward_to(3);
// Referendum passed; 1 and 5 didn't get their way and can now reap and unlock.
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(1), r));
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 1));
// Anyone can reap and unlock anyone else's in this context.
assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(2), 5, r));
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(2), 5));
// 2, 3, 4 got their way with the vote, so they cannot be reaped by others.
assert_noop!(
Democracy::remove_other_vote(RuntimeOrigin::signed(1), 2, r),
Error::<Test>::NoPermission
);
// However, they can be unvoted by the owner, though it will make no difference to the lock.
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(2), r));
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(2), 2));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&1), vec![]);
assert_eq!(pezpallet_balances::Locks::<Test>::get(&2), vec![the_lock(20)]);
assert_eq!(pezpallet_balances::Locks::<Test>::get(&3), vec![the_lock(30)]);
assert_eq!(pezpallet_balances::Locks::<Test>::get(&4), vec![the_lock(40)]);
assert_eq!(pezpallet_balances::Locks::<Test>::get(&5), vec![]);
assert_eq!(Balances::free_balance(42), 2);
fast_forward_to(7);
// No change yet...
assert_noop!(
Democracy::remove_other_vote(RuntimeOrigin::signed(1), 4, r),
Error::<Test>::NoPermission
);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 4));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&4), vec![the_lock(40)]);
fast_forward_to(8);
// 4 should now be able to reap and unlock
assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(1), 4, r));
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 4));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&4), vec![]);
fast_forward_to(13);
assert_noop!(
Democracy::remove_other_vote(RuntimeOrigin::signed(1), 3, r),
Error::<Test>::NoPermission
);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 3));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&3), vec![the_lock(30)]);
fast_forward_to(14);
assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(1), 3, r));
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 3));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&3), vec![]);
// 2 doesn't need to reap_vote here because it was already done before.
fast_forward_to(25);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 2));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&2), vec![the_lock(20)]);
fast_forward_to(26);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(1), 2));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&2), vec![]);
});
}
#[test]
fn no_locks_without_conviction_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
let r = Democracy::inject_referendum(
2,
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(0, 10)));
fast_forward_to(3);
assert_eq!(Balances::free_balance(42), 2);
assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(2), 1, r));
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(2), 1));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&1), vec![]);
});
}
#[test]
fn lock_voting_should_work_with_delegation() {
new_test_ext().execute_with(|| {
let r = Democracy::inject_referendum(
2,
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, nay(5, 10)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(2), r, aye(4, 20)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(3), r, aye(3, 30)));
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(4), 2, Conviction::Locked2x, 40));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r, nay(1, 50)));
assert_eq!(tally(r), Tally { ayes: 250, nays: 100, turnout: 150 });
next_block();
next_block();
assert_eq!(Balances::free_balance(42), 2);
});
}
fn setup_three_referenda() -> (u32, u32, u32) {
System::set_block_number(0);
let r1 =
Democracy::inject_referendum(2, set_balance_proposal(2), VoteThreshold::SimpleMajority, 0);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r1, aye(4, 10)));
let r2 =
Democracy::inject_referendum(2, set_balance_proposal(2), VoteThreshold::SimpleMajority, 0);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r2, aye(3, 20)));
let r3 =
Democracy::inject_referendum(2, set_balance_proposal(2), VoteThreshold::SimpleMajority, 0);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r3, aye(2, 50)));
fast_forward_to(2);
(r1, r2, r3)
}
#[test]
fn prior_lockvotes_should_be_enforced() {
new_test_ext().execute_with(|| {
let r = setup_three_referenda();
// r.0 locked 10 until 2 + 8 * 3 = #26
// r.1 locked 20 until 2 + 4 * 3 = #14
// r.2 locked 50 until 2 + 2 * 3 = #8
fast_forward_to(7);
assert_noop!(
Democracy::remove_other_vote(RuntimeOrigin::signed(1), 5, r.2),
Error::<Test>::NoPermission
);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&5), vec![the_lock(50)]);
fast_forward_to(8);
assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(1), 5, r.2));
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&5), vec![the_lock(20)]);
fast_forward_to(13);
assert_noop!(
Democracy::remove_other_vote(RuntimeOrigin::signed(1), 5, r.1),
Error::<Test>::NoPermission
);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&5), vec![the_lock(20)]);
fast_forward_to(14);
assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(1), 5, r.1));
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&5), vec![the_lock(10)]);
fast_forward_to(25);
assert_noop!(
Democracy::remove_other_vote(RuntimeOrigin::signed(1), 5, r.0),
Error::<Test>::NoPermission
);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&5), vec![the_lock(10)]);
fast_forward_to(26);
assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(1), 5, r.0));
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&5), vec![]);
});
}
#[test]
fn single_consolidation_of_lockvotes_should_work_as_before() {
new_test_ext().execute_with(|| {
let r = setup_three_referenda();
// r.0 locked 10 until 2 + 8 * 3 = #26
// r.1 locked 20 until 2 + 4 * 3 = #14
// r.2 locked 50 until 2 + 2 * 3 = #8
fast_forward_to(7);
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.2));
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&5), vec![the_lock(50)]);
fast_forward_to(8);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&5), vec![the_lock(20)]);
fast_forward_to(13);
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.1));
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&5), vec![the_lock(20)]);
fast_forward_to(14);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&5), vec![the_lock(10)]);
fast_forward_to(25);
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.0));
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&5), vec![the_lock(10)]);
fast_forward_to(26);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&5), vec![]);
});
}
#[test]
fn multi_consolidation_of_lockvotes_should_be_conservative() {
new_test_ext().execute_with(|| {
let r = setup_three_referenda();
// r.0 locked 10 until 2 + 8 * 3 = #26
// r.1 locked 20 until 2 + 4 * 3 = #14
// r.2 locked 50 until 2 + 2 * 3 = #8
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.2));
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.1));
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.0));
fast_forward_to(8);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert!(pezpallet_balances::Locks::<Test>::get(&5)[0].amount >= 20);
fast_forward_to(14);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert!(pezpallet_balances::Locks::<Test>::get(&5)[0].amount >= 10);
fast_forward_to(26);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&5), vec![]);
});
}
#[test]
fn locks_should_persist_from_voting_to_delegation() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
let r = Democracy::inject_referendum(
2,
set_balance_proposal(2),
VoteThreshold::SimpleMajority,
0,
);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r, aye(4, 10)));
fast_forward_to(2);
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r));
// locked 10 until #26.
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(5), 1, Conviction::Locked3x, 20));
// locked 20.
assert!(pezpallet_balances::Locks::<Test>::get(&5)[0].amount == 20);
assert_ok!(Democracy::undelegate(RuntimeOrigin::signed(5)));
// locked 20 until #14
fast_forward_to(13);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert!(pezpallet_balances::Locks::<Test>::get(&5)[0].amount == 20);
fast_forward_to(14);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert!(pezpallet_balances::Locks::<Test>::get(&5)[0].amount >= 10);
fast_forward_to(25);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert!(pezpallet_balances::Locks::<Test>::get(&5)[0].amount >= 10);
fast_forward_to(26);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&5), vec![]);
});
}
#[test]
fn locks_should_persist_from_delegation_to_voting() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(5), 1, Conviction::Locked5x, 5));
assert_ok!(Democracy::undelegate(RuntimeOrigin::signed(5)));
// locked 5 until 16 * 3 = #48
let r = setup_three_referenda();
// r.0 locked 10 until 2 + 8 * 3 = #26
// r.1 locked 20 until 2 + 4 * 3 = #14
// r.2 locked 50 until 2 + 2 * 3 = #8
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.2));
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.1));
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r.0));
fast_forward_to(8);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert!(pezpallet_balances::Locks::<Test>::get(&5)[0].amount >= 20);
fast_forward_to(14);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert!(pezpallet_balances::Locks::<Test>::get(&5)[0].amount >= 10);
fast_forward_to(26);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert!(pezpallet_balances::Locks::<Test>::get(&5)[0].amount >= 5);
fast_forward_to(48);
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&5), vec![]);
});
}
@@ -0,0 +1,207 @@
// This file is part of Bizinikiwi.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! The tests for functionality concerning the metadata.
use super::*;
#[test]
fn set_external_metadata_works() {
new_test_ext().execute_with(|| {
// invalid preimage hash.
let invalid_hash: <Test as pezframe_system::Config>::Hash = [1u8; 32].into();
// metadata owner is an external proposal.
let owner = MetadataOwner::External;
// fails to set metadata if an external proposal does not exist.
assert_noop!(
Democracy::set_metadata(RuntimeOrigin::signed(2), owner.clone(), Some(invalid_hash)),
Error::<Test>::NoProposal,
);
// create an external proposal.
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2)));
assert!(NextExternal::<Test>::exists());
// fails to set metadata with non external origin.
assert_noop!(
Democracy::set_metadata(RuntimeOrigin::signed(1), owner.clone(), Some(invalid_hash)),
BadOrigin,
);
// fails to set non-existing preimage.
assert_noop!(
Democracy::set_metadata(RuntimeOrigin::signed(2), owner.clone(), Some(invalid_hash)),
Error::<Test>::PreimageNotExist,
);
// set metadata successful.
let hash = note_preimage(1);
assert_ok!(Democracy::set_metadata(RuntimeOrigin::signed(2), owner.clone(), Some(hash)));
System::assert_last_event(RuntimeEvent::Democracy(crate::Event::MetadataSet {
owner,
hash,
}));
});
}
#[test]
fn clear_metadata_works() {
new_test_ext().execute_with(|| {
// metadata owner is an external proposal.
let owner = MetadataOwner::External;
// create an external proposal.
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2)));
assert!(NextExternal::<Test>::exists());
// set metadata.
let hash = note_preimage(1);
assert_ok!(Democracy::set_metadata(RuntimeOrigin::signed(2), owner.clone(), Some(hash)));
// fails to clear metadata with a wrong origin.
assert_noop!(
Democracy::set_metadata(RuntimeOrigin::signed(1), owner.clone(), None),
BadOrigin,
);
// clear metadata successful.
assert_ok!(Democracy::set_metadata(RuntimeOrigin::signed(2), owner.clone(), None));
System::assert_last_event(RuntimeEvent::Democracy(crate::Event::MetadataCleared {
owner,
hash,
}));
});
}
#[test]
fn set_proposal_metadata_works() {
new_test_ext().execute_with(|| {
// invalid preimage hash.
let invalid_hash: <Test as pezframe_system::Config>::Hash = [1u8; 32].into();
// create an external proposal.
assert_ok!(propose_set_balance(1, 2, 5));
// metadata owner is a public proposal.
let owner = MetadataOwner::Proposal(PublicPropCount::<Test>::get() - 1);
// fails to set non-existing preimage.
assert_noop!(
Democracy::set_metadata(RuntimeOrigin::signed(1), owner.clone(), Some(invalid_hash)),
Error::<Test>::PreimageNotExist,
);
// note preimage.
let hash = note_preimage(1);
// fails to set a preimage if an origin is not a proposer.
assert_noop!(
Democracy::set_metadata(RuntimeOrigin::signed(3), owner.clone(), Some(hash)),
Error::<Test>::NoPermission,
);
// set metadata successful.
assert_ok!(Democracy::set_metadata(RuntimeOrigin::signed(1), owner.clone(), Some(hash)));
System::assert_last_event(RuntimeEvent::Democracy(crate::Event::MetadataSet {
owner,
hash,
}));
});
}
#[test]
fn clear_proposal_metadata_works() {
new_test_ext().execute_with(|| {
// create an external proposal.
assert_ok!(propose_set_balance(1, 2, 5));
// metadata owner is a public proposal.
let owner = MetadataOwner::Proposal(PublicPropCount::<Test>::get() - 1);
// set metadata.
let hash = note_preimage(1);
assert_ok!(Democracy::set_metadata(RuntimeOrigin::signed(1), owner.clone(), Some(hash)));
// fails to clear metadata with a wrong origin.
assert_noop!(
Democracy::set_metadata(RuntimeOrigin::signed(3), owner.clone(), None),
Error::<Test>::NoPermission,
);
// clear metadata successful.
assert_ok!(Democracy::set_metadata(RuntimeOrigin::signed(1), owner.clone(), None));
System::assert_last_event(RuntimeEvent::Democracy(crate::Event::MetadataCleared {
owner,
hash,
}));
});
}
#[test]
fn set_referendum_metadata_by_root() {
new_test_ext().execute_with(|| {
let index = Democracy::inject_referendum(
2,
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
// metadata owner is a referendum.
let owner = MetadataOwner::Referendum(index);
// note preimage.
let hash = note_preimage(1);
// fails to set if not a root.
assert_noop!(
Democracy::set_metadata(RuntimeOrigin::signed(3), owner.clone(), Some(hash)),
Error::<Test>::NoPermission,
);
// fails to clear if not a root.
assert_noop!(
Democracy::set_metadata(RuntimeOrigin::signed(3), owner.clone(), None),
Error::<Test>::NoPermission,
);
// succeed to set metadata by a root for an ongoing referendum.
assert_ok!(Democracy::set_metadata(RuntimeOrigin::root(), owner.clone(), Some(hash)));
System::assert_last_event(RuntimeEvent::Democracy(crate::Event::MetadataSet {
owner: owner.clone(),
hash,
}));
// succeed to clear metadata by a root for an ongoing referendum.
assert_ok!(Democracy::set_metadata(RuntimeOrigin::root(), owner.clone(), None));
System::assert_last_event(RuntimeEvent::Democracy(crate::Event::MetadataCleared {
owner,
hash,
}));
});
}
#[test]
fn clear_referendum_metadata_works() {
new_test_ext().execute_with(|| {
// create a referendum.
let index = Democracy::inject_referendum(
2,
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
// metadata owner is a referendum.
let owner = MetadataOwner::Referendum(index);
// set metadata.
let hash = note_preimage(1);
// referendum finished.
MetadataOf::<Test>::insert(owner.clone(), hash);
// no permission to clear metadata of an ongoing referendum.
assert_noop!(
Democracy::set_metadata(RuntimeOrigin::signed(1), owner.clone(), None),
Error::<Test>::NoPermission,
);
// referendum finished.
ReferendumInfoOf::<Test>::insert(
index,
ReferendumInfo::Finished { end: 1, approved: true },
);
// clear metadata successful.
assert_ok!(Democracy::set_metadata(RuntimeOrigin::signed(1), owner.clone(), None));
System::assert_last_event(RuntimeEvent::Democracy(crate::Event::MetadataCleared {
owner,
hash,
}));
});
}
@@ -0,0 +1,153 @@
// This file is part of Bizinikiwi.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! The tests for the public proposal queue.
use super::*;
#[test]
fn backing_for_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(propose_set_balance(1, 2, 2));
assert_ok!(propose_set_balance(1, 4, 4));
assert_ok!(propose_set_balance(1, 3, 3));
assert_eq!(Democracy::backing_for(0), Some(2));
assert_eq!(Democracy::backing_for(1), Some(4));
assert_eq!(Democracy::backing_for(2), Some(3));
});
}
#[test]
fn deposit_for_proposals_should_be_taken() {
new_test_ext().execute_with(|| {
assert_ok!(propose_set_balance(1, 2, 5));
assert_ok!(Democracy::second(RuntimeOrigin::signed(2), 0));
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0));
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0));
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0));
assert_eq!(Balances::free_balance(1), 5);
assert_eq!(Balances::free_balance(2), 15);
assert_eq!(Balances::free_balance(5), 35);
});
}
#[test]
fn deposit_for_proposals_should_be_returned() {
new_test_ext().execute_with(|| {
assert_ok!(propose_set_balance(1, 2, 5));
assert_ok!(Democracy::second(RuntimeOrigin::signed(2), 0));
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0));
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0));
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0));
fast_forward_to(3);
assert_eq!(Balances::free_balance(1), 10);
assert_eq!(Balances::free_balance(2), 20);
assert_eq!(Balances::free_balance(5), 50);
});
}
#[test]
fn proposal_with_deposit_below_minimum_should_not_work() {
new_test_ext().execute_with(|| {
assert_noop!(propose_set_balance(1, 2, 0), Error::<Test>::ValueLow);
});
}
#[test]
fn poor_proposer_should_not_work() {
new_test_ext().execute_with(|| {
assert_noop!(propose_set_balance(1, 2, 11), BalancesError::<Test, _>::InsufficientBalance);
});
}
#[test]
fn poor_seconder_should_not_work() {
new_test_ext().execute_with(|| {
assert_ok!(propose_set_balance(2, 2, 11));
assert_noop!(
Democracy::second(RuntimeOrigin::signed(1), 0),
BalancesError::<Test, _>::InsufficientBalance
);
});
}
#[test]
fn cancel_proposal_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(propose_set_balance(1, 2, 2));
assert_ok!(propose_set_balance(1, 4, 4));
assert_noop!(Democracy::cancel_proposal(RuntimeOrigin::signed(1), 0), BadOrigin);
let hash = note_preimage(1);
assert_ok!(Democracy::set_metadata(
RuntimeOrigin::signed(1),
MetadataOwner::Proposal(0),
Some(hash)
));
assert!(MetadataOf::<Test>::get(MetadataOwner::Proposal(0)).is_some());
assert_ok!(Democracy::cancel_proposal(RuntimeOrigin::root(), 0));
// metadata cleared, preimage unrequested.
assert!(MetadataOf::<Test>::get(MetadataOwner::Proposal(0)).is_none());
System::assert_has_event(crate::Event::ProposalCanceled { prop_index: 0 }.into());
System::assert_last_event(
crate::Event::MetadataCleared { owner: MetadataOwner::Proposal(0), hash }.into(),
);
assert_eq!(Democracy::backing_for(0), None);
assert_eq!(Democracy::backing_for(1), Some(4));
});
}
#[test]
fn blacklisting_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
let hash = set_balance_proposal(2).hash();
assert_ok!(propose_set_balance(1, 2, 2));
assert_ok!(propose_set_balance(1, 4, 4));
assert_noop!(Democracy::blacklist(RuntimeOrigin::signed(1), hash, None), BadOrigin);
assert_ok!(Democracy::blacklist(RuntimeOrigin::root(), hash, None));
assert_eq!(Democracy::backing_for(0), None);
assert_eq!(Democracy::backing_for(1), Some(4));
assert_noop!(propose_set_balance(1, 2, 2), Error::<Test>::ProposalBlacklisted);
fast_forward_to(2);
let hash = set_balance_proposal(4).hash();
assert_ok!(Democracy::referendum_status(0));
assert_ok!(Democracy::blacklist(RuntimeOrigin::root(), hash, Some(0)));
assert_noop!(Democracy::referendum_status(0), Error::<Test>::ReferendumInvalid);
});
}
#[test]
fn runners_up_should_come_after() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(propose_set_balance(1, 2, 2));
assert_ok!(propose_set_balance(1, 4, 4));
assert_ok!(propose_set_balance(1, 3, 3));
fast_forward_to(2);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), 0, aye(1)));
fast_forward_to(4);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), 1, aye(1)));
fast_forward_to(6);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), 2, aye(1)));
});
}
@@ -0,0 +1,161 @@
// This file is part of Bizinikiwi.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! The tests for functionality concerning normal starting, ending and enacting of referenda.
use super::*;
#[test]
fn simple_passing_should_work() {
new_test_ext().execute_with(|| {
let r = Democracy::inject_referendum(
2,
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
assert_eq!(tally(r), Tally { ayes: 1, nays: 0, turnout: 10 });
assert_eq!(LowestUnbaked::<Test>::get(), 0);
next_block();
next_block();
assert_eq!(LowestUnbaked::<Test>::get(), 1);
assert_eq!(Balances::free_balance(42), 2);
});
}
#[test]
fn simple_failing_should_work() {
new_test_ext().execute_with(|| {
let r = Democracy::inject_referendum(
2,
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, nay(1)));
assert_eq!(tally(r), Tally { ayes: 0, nays: 1, turnout: 10 });
next_block();
next_block();
assert_eq!(Balances::free_balance(42), 0);
});
}
#[test]
fn ooo_inject_referendums_should_work() {
new_test_ext().execute_with(|| {
let r1 = Democracy::inject_referendum(
3,
set_balance_proposal(3),
VoteThreshold::SuperMajorityApprove,
0,
);
let r2 = Democracy::inject_referendum(
2,
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r2, aye(1)));
assert_eq!(tally(r2), Tally { ayes: 1, nays: 0, turnout: 10 });
next_block();
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r1, aye(1)));
assert_eq!(tally(r1), Tally { ayes: 1, nays: 0, turnout: 10 });
next_block();
assert_eq!(Balances::free_balance(42), 2);
next_block();
assert_eq!(Balances::free_balance(42), 3);
});
}
#[test]
fn delayed_enactment_should_work() {
new_test_ext().execute_with(|| {
let r = Democracy::inject_referendum(
2,
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
1,
);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(2), r, aye(2)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(3), r, aye(3)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(4), r, aye(4)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r, aye(5)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(6), r, aye(6)));
assert_eq!(tally(r), Tally { ayes: 21, nays: 0, turnout: 210 });
next_block();
assert_eq!(Balances::free_balance(42), 0);
next_block();
assert_eq!(Balances::free_balance(42), 2);
});
}
#[test]
fn lowest_unbaked_should_be_sensible() {
new_test_ext().execute_with(|| {
let r1 = Democracy::inject_referendum(
3,
set_balance_proposal(1),
VoteThreshold::SuperMajorityApprove,
0,
);
let r2 = Democracy::inject_referendum(
2,
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
let r3 = Democracy::inject_referendum(
10,
set_balance_proposal(3),
VoteThreshold::SuperMajorityApprove,
0,
);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r1, aye(1)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r2, aye(1)));
// r3 is canceled
assert_ok!(Democracy::cancel_referendum(RuntimeOrigin::root(), r3.into()));
assert_eq!(LowestUnbaked::<Test>::get(), 0);
next_block();
// r2 ends with approval
assert_eq!(LowestUnbaked::<Test>::get(), 0);
next_block();
// r1 ends with approval
assert_eq!(LowestUnbaked::<Test>::get(), 3);
assert_eq!(LowestUnbaked::<Test>::get(), ReferendumCount::<Test>::get());
// r2 is executed
assert_eq!(Balances::free_balance(42), 2);
next_block();
// r1 is executed
assert_eq!(Balances::free_balance(42), 1);
});
}
@@ -0,0 +1,172 @@
// This file is part of Bizinikiwi.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! The tests for normal voting functionality.
use super::*;
#[test]
fn overvoting_should_fail() {
new_test_ext().execute_with(|| {
let r = begin_referendum();
assert_noop!(
Democracy::vote(RuntimeOrigin::signed(1), r, aye(2)),
Error::<Test>::InsufficientFunds
);
});
}
#[test]
fn split_voting_should_work() {
new_test_ext().execute_with(|| {
let r = begin_referendum();
let v = AccountVote::Split { aye: 40, nay: 20 };
assert_noop!(
Democracy::vote(RuntimeOrigin::signed(5), r, v),
Error::<Test>::InsufficientFunds
);
let v = AccountVote::Split { aye: 30, nay: 20 };
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r, v));
assert_eq!(tally(r), Tally { ayes: 3, nays: 2, turnout: 50 });
});
}
#[test]
fn split_vote_cancellation_should_work() {
new_test_ext().execute_with(|| {
let r = begin_referendum();
let v = AccountVote::Split { aye: 30, nay: 20 };
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r, v));
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(5), r));
assert_eq!(tally(r), Tally { ayes: 0, nays: 0, turnout: 0 });
assert_ok!(Democracy::unlock(RuntimeOrigin::signed(5), 5));
assert_eq!(pezpallet_balances::Locks::<Test>::get(&5), vec![]);
});
}
#[test]
fn single_proposal_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_ok!(propose_set_balance(1, 2, 1));
let r = 0;
assert!(ReferendumInfoOf::<Test>::get(r).is_none());
// start of 2 => next referendum scheduled.
fast_forward_to(2);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
assert_eq!(ReferendumCount::<Test>::get(), 1);
assert_eq!(
Democracy::referendum_status(0),
Ok(ReferendumStatus {
end: 4,
proposal: set_balance_proposal(2),
threshold: VoteThreshold::SuperMajorityApprove,
delay: 2,
tally: Tally { ayes: 1, nays: 0, turnout: 10 },
})
);
fast_forward_to(3);
// referendum still running
assert_ok!(Democracy::referendum_status(0));
// referendum runs during 2 and 3, ends @ start of 4.
fast_forward_to(4);
assert_noop!(Democracy::referendum_status(0), Error::<Test>::ReferendumInvalid);
assert!(pezpallet_scheduler::Agenda::<Test>::get(6)[0].is_some());
// referendum passes and wait another two blocks for enactment.
fast_forward_to(6);
assert_eq!(Balances::free_balance(42), 2);
});
}
#[test]
fn controversial_voting_should_work() {
new_test_ext().execute_with(|| {
let r = Democracy::inject_referendum(
2,
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, big_aye(1)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(2), r, big_nay(2)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(3), r, big_nay(3)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(4), r, big_aye(4)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r, big_nay(5)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(6), r, big_aye(6)));
assert_eq!(tally(r), Tally { ayes: 110, nays: 100, turnout: 210 });
next_block();
next_block();
assert_eq!(Balances::free_balance(42), 2);
});
}
#[test]
fn controversial_low_turnout_voting_should_work() {
new_test_ext().execute_with(|| {
let r = Democracy::inject_referendum(
2,
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r, big_nay(5)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(6), r, big_aye(6)));
assert_eq!(tally(r), Tally { ayes: 60, nays: 50, turnout: 110 });
next_block();
next_block();
assert_eq!(Balances::free_balance(42), 0);
});
}
#[test]
fn passing_low_turnout_voting_should_work() {
new_test_ext().execute_with(|| {
assert_eq!(Balances::free_balance(42), 0);
assert_eq!(pezpallet_balances::TotalIssuance::<Test>::get(), 210);
let r = Democracy::inject_referendum(
2,
set_balance_proposal(2),
VoteThreshold::SuperMajorityApprove,
0,
);
assert_ok!(Democracy::vote(RuntimeOrigin::signed(4), r, big_aye(4)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r, big_nay(5)));
assert_ok!(Democracy::vote(RuntimeOrigin::signed(6), r, big_aye(6)));
assert_eq!(tally(r), Tally { ayes: 100, nays: 50, turnout: 150 });
next_block();
next_block();
assert_eq!(Balances::free_balance(42), 2);
});
}