41 lines
1.7 KiB
JavaScript
41 lines
1.7 KiB
JavaScript
import { Box } from './classes/box.js';
|
|
import { Scene } from './classes/scene.js';
|
|
import { Member } from './classes/member.js';
|
|
import { ValidationPool } from './classes/validation-pool/index.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 pool = window.validationPool = new ValidationPool("validationPool", scene);
|
|
|
|
const member1 = window.member1 = (await new Member("member1", scene).initialize()).setValue('rep', 0);
|
|
const member2 = window.member2 = (await new Member("member2", scene).initialize()).setValue('rep', 0);
|
|
|
|
await delay(1000);
|
|
|
|
// First member can self-approve
|
|
const vote1 = member1.initiateVote(pool, {fee: 1, duration: 1000, tokenLossRatio: 1});
|
|
await member1.castVote(pool, vote1, true, 0, 0);
|
|
await member1.revealIdentity(pool, vote1); // Vote passes
|
|
member1.setValue('rep', pool.reputations.getTokens(member1.reputationPublicKey));
|
|
|
|
// const vote2 = member2.initiateVote(pool, {fee: 1, duration: 1000, tokenLossRatio: 1});
|
|
// await member2.castVote(pool, vote2, true, 0);
|
|
// await member2.revealIdentity(pool, vote2); // Quorum is not met!
|
|
|
|
await delay(1000);
|
|
|
|
// Second member must be approved by first member
|
|
const vote2 = member2.initiateVote(pool, {fee: 1, duration: 1000, tokenLossRatio: 1});
|
|
await member1.castVote(pool, vote2, true, 0.5, 1);
|
|
await member1.revealIdentity(pool, vote2); // Vote passes
|
|
|
|
member1.setValue('rep', pool.reputations.getTokens(member1.reputationPublicKey));
|
|
member2.setValue('rep', pool.reputations.getTokens(member2.reputationPublicKey));
|