|
@@ -29,9 +29,9 @@ export function councilTest(m1KeyPairs: KeyringPair[], m2KeyPairs: KeyringPair[]
|
|
|
});
|
|
|
|
|
|
it('Electing a council test', async () => {
|
|
|
+ // Setup goes here because M keypairs are generated after before() function
|
|
|
sudo = keyring.addFromUri(sudoUri);
|
|
|
let now = await apiWrapper.getBestBlock();
|
|
|
- await apiWrapper.sudoStartAnnouncingPerion(sudo, now.addn(100));
|
|
|
const applyForCouncilFee: BN = apiWrapper.estimateApplyForCouncilFee(greaterStake);
|
|
|
const voteForCouncilFee: BN = apiWrapper.estimateVoteForCouncilFee(sudo.address, sudo.address, greaterStake);
|
|
|
const salt: string[] = new Array();
|
|
@@ -39,14 +39,19 @@ export function councilTest(m1KeyPairs: KeyringPair[], m2KeyPairs: KeyringPair[]
|
|
|
salt.push(''.concat(uuid().replace(/-/g, '')));
|
|
|
});
|
|
|
const revealVoteFee: BN = apiWrapper.estimateRevealVoteFee(sudo.address, salt[0]);
|
|
|
+
|
|
|
+ // Topping the balances
|
|
|
await apiWrapper.transferBalanceToAccounts(sudo, m2KeyPairs, applyForCouncilFee.add(greaterStake));
|
|
|
await apiWrapper.transferBalanceToAccounts(
|
|
|
sudo,
|
|
|
m1KeyPairs,
|
|
|
voteForCouncilFee.add(revealVoteFee).add(greaterStake)
|
|
|
);
|
|
|
+
|
|
|
+ // First K members stake more
|
|
|
+ await apiWrapper.sudoStartAnnouncingPerion(sudo, now.addn(100));
|
|
|
await apiWrapper.batchApplyForCouncilElection(m2KeyPairs.slice(0, K), greaterStake);
|
|
|
- m2KeyPairs.forEach(keyPair =>
|
|
|
+ m2KeyPairs.slice(0, K).forEach(keyPair =>
|
|
|
apiWrapper.getCouncilElectionStake(keyPair.address).then(stake => {
|
|
|
assert(
|
|
|
stake.eq(greaterStake),
|
|
@@ -54,7 +59,19 @@ export function councilTest(m1KeyPairs: KeyringPair[], m2KeyPairs: KeyringPair[]
|
|
|
);
|
|
|
})
|
|
|
);
|
|
|
+
|
|
|
+ // Last members stake less
|
|
|
await apiWrapper.batchApplyForCouncilElection(m2KeyPairs.slice(K), lesserStake);
|
|
|
+ m2KeyPairs.slice(K).forEach(keyPair =>
|
|
|
+ apiWrapper.getCouncilElectionStake(keyPair.address).then(stake => {
|
|
|
+ assert(
|
|
|
+ stake.eq(lesserStake),
|
|
|
+ `${keyPair.address} not applied correctrly for council election with stake ${stake} versus expected ${lesserStake}`
|
|
|
+ );
|
|
|
+ })
|
|
|
+ );
|
|
|
+
|
|
|
+ // Voting
|
|
|
await apiWrapper.sudoStartVotingPerion(sudo, now.addn(100));
|
|
|
await apiWrapper.batchVoteForCouncilMember(
|
|
|
m1KeyPairs.slice(0, K),
|
|
@@ -63,14 +80,20 @@ export function councilTest(m1KeyPairs: KeyringPair[], m2KeyPairs: KeyringPair[]
|
|
|
lesserStake
|
|
|
);
|
|
|
await apiWrapper.batchVoteForCouncilMember(m1KeyPairs.slice(K), m2KeyPairs.slice(K), salt.slice(K), greaterStake);
|
|
|
+
|
|
|
+ // Revealing
|
|
|
await apiWrapper.sudoStartRevealingPerion(sudo, now.addn(100));
|
|
|
await apiWrapper.batchRevealVote(m1KeyPairs.slice(0, K), m2KeyPairs.slice(0, K), salt.slice(0, K));
|
|
|
await apiWrapper.batchRevealVote(m1KeyPairs.slice(K), m2KeyPairs.slice(K), salt.slice(K));
|
|
|
now = await apiWrapper.getBestBlock();
|
|
|
+
|
|
|
+ // Resolving election
|
|
|
+ // 3 is to ensure the revealing block is in future
|
|
|
await apiWrapper.sudoStartRevealingPerion(sudo, now.addn(3));
|
|
|
- // TODO get duration from chain
|
|
|
- await Utils.wait(12000);
|
|
|
+ await Utils.wait(apiWrapper.getBlockDuration().muln(2.5).toNumber());
|
|
|
const seats: Seat[] = await apiWrapper.getCouncil();
|
|
|
+
|
|
|
+ // Preparing collections to increase assertion readability
|
|
|
const m2addresses: string[] = m2KeyPairs.map(keyPair => keyPair.address);
|
|
|
const m1addresses: string[] = m1KeyPairs.map(keyPair => keyPair.address);
|
|
|
const members: string[] = seats.map(seat => seat.member.toString());
|
|
@@ -78,8 +101,10 @@ export function councilTest(m1KeyPairs: KeyringPair[], m2KeyPairs: KeyringPair[]
|
|
|
(array, seat) => array.concat(seat.backers.map(baker => baker.member.toString())),
|
|
|
new Array()
|
|
|
);
|
|
|
- //m2addresses.forEach(address => assert(members.includes(address), `Account ${address} is not in the council`));
|
|
|
- //m1addresses.forEach(address => assert(bakers.includes(address), `Account ${address} is not in the voters`));
|
|
|
+
|
|
|
+ // Assertions
|
|
|
+ m2addresses.forEach(address => assert(members.includes(address), `Account ${address} is not in the council`));
|
|
|
+ m1addresses.forEach(address => assert(bakers.includes(address), `Account ${address} is not in the voters`));
|
|
|
seats.forEach(seat =>
|
|
|
assert(
|
|
|
Utils.getTotalStake(seat).eq(greaterStake.add(lesserStake)),
|