69 lines
2.5 KiB
JavaScript
69 lines
2.5 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';
|
||
|
import { Business } from './classes/business.js';
|
||
|
import { Availability } from './classes/availability.js';
|
||
|
import { delay } from './util.js';
|
||
|
import { Forum } from './classes/forum.js';
|
||
|
|
||
|
const rootElement = document.getElementById('availability-test');
|
||
|
const rootBox = new Box('rootBox', rootElement).flex();
|
||
|
|
||
|
const scene = window.scene = new Scene('Availability 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 forum = window.forum = new Forum(bench, 'Forum', scene);
|
||
|
const availability = window.bench = new Availability(bench, 'Availability', scene);
|
||
|
const business = window.bench = new Business(bench, forum, availability, 'Business', 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());
|
||
|
await scene.renderSequenceDiagram();
|
||
|
};
|
||
|
|
||
|
updateDisplayValues();
|
||
|
|
||
|
// const post1 = window.post1 = new PostContent({ message: 'hi' });
|
||
|
// const post2 = window.post2 = new PostContent({ message: 'hello' }).addCitation(window.post1.id, 1.0);
|
||
|
|
||
|
// Populate availability pool
|
||
|
availability.register(member1.reputationPublicKey, 1);
|
||
|
availability.register(member2.reputationPublicKey, 1);
|
||
|
|
||
|
await delay(500);
|
||
|
|
||
|
// Submit work request
|
||
|
const requestId = await business.submitRequest(100, { please: 'do some work' });
|
||
|
await scene.renderSequenceDiagram();
|
||
|
await delay(500);
|
||
|
|
||
|
// Submit work evidence
|
||
|
const pool = await business.submitWork(member1.reputationPublicKey, requestId, {
|
||
|
here: 'is some evidence of work product',
|
||
|
}, {
|
||
|
tokenLossRatio: 1,
|
||
|
duration: 1000,
|
||
|
});
|
||
|
|
||
|
await scene.renderSequenceDiagram();
|
||
|
await delay(500);
|
||
|
|
||
|
// Vote on work evidence
|
||
|
await member2.castVote(pool, { position: true, stake: 1 });
|
||
|
await scene.renderSequenceDiagram();
|
||
|
await delay(500);
|
||
|
|
||
|
await member2.revealIdentity(pool);
|
||
|
await scene.renderSequenceDiagram();
|
||
|
await delay(500);
|
||
|
|
||
|
await member1.revealIdentity(pool, member1.reputationPublicKey);
|
||
|
await scene.renderSequenceDiagram();
|
||
|
|
||
|
// Distribute reputation awards
|
||
|
// Distribute fees
|