-
Notifications
You must be signed in to change notification settings - Fork 4
/
casper.js
executable file
·56 lines (48 loc) · 1.11 KB
/
casper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
'use strict';
var ArgumentParser = require('argparse').ArgumentParser;
var parser = new ArgumentParser({
version: '0.0.1',
addHelp: true,
description: 'cbc-casper-js'
});
var sims = parser.addSubparsers({
title:'Simulations',
dest:"sim"
});
/*
* Random Binary Simulation
*/
var random = sims.addParser('random', {addHelp:true});
random.addArgument(
[ '-n', '--validator-count' ],
{
defaultValue: 3,
type: 'int',
help: 'The number of validators for the simulation.'
}
);
random.addArgument(
[ '-s', '--safety-ratio' ],
{
defaultValue: 2/3,
type: 'float',
help: 'The safety ratio all validators must exceed before the sim ends.'
}
);
var args = parser.parseArgs();
if(args.sim === "random") {
let binary = require('./sims/binary');
let simulator = new binary.BinarySimulator(
args.validator_count,
args.safety_ratio,
);
const result = simulator.simulate();
const output = {
intialConfig: result.initialConfig,
decisions: result.decisions,
majorityFlip: result.majorityFlip,
messageLogLength: result.log.length,
}
console.log(JSON.stringify(output, null, 2));
}