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

124 lines
3.6 KiB
HTML
Raw Normal View History

<!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";
2023-01-03 12:00:12 -06:00
import { Expert } from "/classes/expert.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"
));
2023-01-03 12:00:12 -06:00
const member1 = (window.member1 = await new Expert(
"Expert1",
scene
).initialize());
2023-01-03 12:00:12 -06:00
const member2 = (window.member2 = await new Expert(
"Expert2",
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);
2023-01-03 12:00:12 -06:00
// Attempting to evaluate winning conditions before the duration has expired
// should result in an exception
try {
await pool.evaluateWinningConditions();
} catch (e) {
if (e.message.match(/Validation pool duration has not yet elapsed/)) {
console.log(
"Caught expected error: Validation pool duration has not yet elapsed"
);
} else {
console.error("Unexpected error");
throw e;
}
}
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>