Skip to content

Commit db433f4

Browse files
committed
added self test option for randomness beacon
1 parent 9ba26e9 commit db433f4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

examples/randomness-beacon/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { Beacon } from './model/Beacon';
2020
import { BeaconValueOp } from './model/BeaconValueOp';
2121

2222
import * as readline from 'readline';
23+
import { VDF } from './model/VDF';
2324

2425

2526
const STEPS = 10000;
@@ -108,7 +109,17 @@ async function main() {
108109
});
109110

110111
let space: Space;
111-
if (command.trim() === '') {
112+
if (command.trim() === 'selftest') {
113+
114+
console.log('starting self test...');
115+
console.log();
116+
await VDF.compute(new RNGImpl().randomHexString(160), 10000);
117+
console.log();
118+
console.log('self test done');
119+
120+
return;
121+
122+
} else if (command.trim() === '') {
112123

113124
space = await createBeaconSpace(resources);
114125

examples/randomness-beacon/model/VDF.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ class VDF {
1111

1212
static async compute(challenge: string, steps: number): Promise<string> {
1313

14-
VDF.log.debug('Computing VDF...');
15-
14+
VDF.log.debug('Creating VDF instance...');
1615
const vdfInstance = await createVdf();
16+
VDF.log.debug('Computing VDF...');
1717
const result = vdfInstance.generate(steps, Buffer.from(challenge, 'hex'), VDF.BITS, true);
18-
1918
VDF.log.debug('Done computing VDF.')
2019

2120
const t = Date.now();

0 commit comments

Comments
 (0)