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));
assert!(!NextExternal::<Test>::exists());
assert_noop!(
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),),
Error::<Test>::ProposalBlacklisted
);
fast_forward_to(1);
assert_noop!(
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),),
Error::<Test>::ProposalBlacklisted
);
fast_forward_to(2);
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),));
assert!(NextExternal::<Test>::exists());
assert_noop!(
Democracy::veto_external(RuntimeOrigin::signed(3), h),
Error::<Test>::AlreadyVetoed
);
assert_ok!(Democracy::veto_external(RuntimeOrigin::signed(4), h));
assert!(!NextExternal::<Test>::exists());
fast_forward_to(3);
assert_noop!(
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2)),
Error::<Test>::ProposalBlacklisted
);
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);
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 },
})
);
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(3),));
fast_forward_to(4);
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 },
})
);
fast_forward_to(6);
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 },
})
);
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(5),));
fast_forward_to(8);
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 },
})
);
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(7),));
assert_ok!(propose_set_balance(6, 4, 2));
fast_forward_to(10);
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 },
})
);
assert_ok!(propose_set_balance(6, 6, 2));
let h = set_balance_proposal(7).hash();
assert_ok!(Democracy::veto_external(RuntimeOrigin::signed(3), h));
fast_forward_to(12);
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 },
})
);
});
}