dao-governance-framework/forum-network/public/tests/validation-pool.html

110 lines
3.1 KiB
HTML

<!DOCTYPE html>
<head>
<title>Validation Pool test</title>
<link type="text/css" rel="stylesheet" href="/index.css" />
</head>
<body>
<div id="validation-pool"></div>
</body>
<script type="module">
import { Box } from "/classes/box.js";
import { Scene } from "/classes/scene.js";
import { Member } from "/classes/member.js";
import { Bench } from "/classes/bench.js";
import { delay } from "/util.js";
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 member1 = (window.member1 = await new Member(
"Member1",
scene
).initialize());
const member2 = (window.member2 = await new Member(
"Member2",
scene
).initialize());
const bench = (window.bench = new Bench("Bench", scene));
const updateDisplayValues = async () => {
member1.setValue(
"rep",
bench.reputations.getTokens(member1.reputationPublicKey)
);
member2.setValue(
"rep",
bench.reputations.getTokens(member2.reputationPublicKey)
);
bench.setValue("total rep", bench.getTotalReputation());
// With params.lockingTimeExponent = 0 and params.activeVoterThreshold = null,
// these next 3 propetries are all equal to total rep
// bench.setValue('available rep', bench.getTotalAvailableReputation());
// bench.setValue('active rep', bench.getTotalActiveReputation());
// bench.setValue('active available rep', bench.getTotalActiveAvailableReputation());
await scene.renderSequenceDiagram();
};
updateDisplayValues();
await delay(1000);
// First member can self-approve
{
const pool = await member1.initiateValidationPool(bench, {
fee: 7,
duration: 1000,
tokenLossRatio: 1,
});
await member1.revealIdentity(pool);
await delay(1000);
await pool.evaluateWinningConditions(); // Vote passes
await updateDisplayValues();
await delay(1000);
}
// Failure example: second member can not self-approve
try {
const pool = await member2.initiateValidationPool(bench, {
fee: 1,
duration: 1000,
tokenLossRatio: 1,
});
await member2.revealIdentity(pool);
await delay(1000);
await pool.evaluateWinningConditions(); // Quorum not met!
await updateDisplayValues();
await delay(1000);
} catch (e) {
if (e.message.match(/Quorum is not met/)) {
console.log("Caught expected error: Quorum not met");
} else {
console.error("Unexpected error");
throw e;
}
}
// Second member must be approved by first member
{
const pool = await member2.initiateValidationPool(bench, {
fee: 1,
duration: 1000,
tokenLossRatio: 1,
});
await member1.castVote(pool, { position: true, stake: 4, lockingTime: 0 });
await member1.revealIdentity(pool);
await member2.revealIdentity(pool);
await delay(1000);
await pool.evaluateWinningConditions(); // Vote passes
await updateDisplayValues();
await delay(1000);
}
await updateDisplayValues();
scene.deactivateAll();
await updateDisplayValues();
</script>