51 lines
2.0 KiB
JavaScript
51 lines
2.0 KiB
JavaScript
import { Box } from './classes/box.js';
|
|
import { Scene } from './classes/scene.js';
|
|
import { Member } from './classes/member.js';
|
|
import { Bench } from './classes/bench.js';
|
|
|
|
const delay = async (ms) => {
|
|
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
};
|
|
|
|
const rootElement = document.getElementById('validation-pool');
|
|
const rootBox = new Box('rootBox', rootElement).flex();
|
|
|
|
const scene = window.scene = new Scene('Validation Pool test', rootBox).log('sequenceDiagram');
|
|
|
|
const bench = window.bench = new Bench("Bench", scene);
|
|
|
|
const member1 = window.member1 = await new Member("member1", scene).initialize();
|
|
const member2 = window.member2 = await new Member("member2", scene).initialize();
|
|
|
|
const updateDisplayValues = () => {
|
|
member1.setValue('rep', bench.reputations.getTokens(member1.reputationPublicKey));
|
|
member2.setValue('rep', bench.reputations.getTokens(member2.reputationPublicKey));
|
|
bench.setValue('total rep', bench.getTotalReputation());
|
|
bench.setValue('available rep', bench.getTotalAvailableReputation());
|
|
bench.setValue('active rep', bench.getTotalActiveReputation());
|
|
bench.setValue('active available rep', bench.getTotalActiveAvailableReputation());
|
|
};
|
|
|
|
updateDisplayValues();
|
|
|
|
await delay(1000);
|
|
|
|
// First member can self-approve
|
|
const vote1 = member1.initiateValidationPool(bench, {fee: 1, duration: 1000, tokenLossRatio: 1});
|
|
await member1.castVote(bench, vote1, true, 0, 0);
|
|
await member1.revealIdentity(bench, vote1); // Vote passes
|
|
updateDisplayValues();
|
|
|
|
// const vote2 = member2.initiateValidationPool(bench, {fee: 1, duration: 1000, tokenLossRatio: 1});
|
|
// await member2.castVote(bench, vote2, true, 0);
|
|
// await member2.revealIdentity(bench, vote2); // Quorum is not met!
|
|
|
|
await delay(1000);
|
|
|
|
// Second member must be approved by first member
|
|
const vote2 = member2.initiateValidationPool(bench, {fee: 1, duration: 1000, tokenLossRatio: 1});
|
|
await member1.castVote(bench, vote2, true, 0.5, 1);
|
|
await member1.revealIdentity(bench, vote2); // Vote passes
|
|
|
|
updateDisplayValues();
|