aboutsummaryrefslogtreecommitdiffstats
path: root/RPCTests/main.js
blob: fce4327d2c05427c09c92c118945a189bfa5349b (plain) (blame)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//requires npm
//requires installed node v6
//requires ethereum eth path on input

var async = require("async");
var utils = require('./modules/utils.js');
var testutils = require('./modules/testutils.js');
var ethconsole = require('./modules/ethconsole.js');

var ethpath = process.argv[2];
var testdir = __dirname + "/dynamic";
var workdir = __dirname;

var dynamic = {};

function cb(){}
function main()
{
if (!ethpath || !utils.fileExists(ethpath))
{
    utils.cLog("Executable '" + ethpath + "' not found!");
    utils.cLog("Please, set eth path. Usage: node main.js <ethpath>");
    return;
}

testutils.readTestsInFolder(workdir + "/scripts/tests");
async.series([
function(cb) {
    utils.setDebug(false);
    ethconsole.startNode(ethpath, testdir + "/ethnode1", testdir + "/genesis.json", 30305, cb);
},
function(cb) {
    prepareDynamicVars(cb);
},
function(cb) {
    ethconsole.stopNode(testdir + "/ethnode1", cb);
},
function(cb) {
    ethconsole.startNode(ethpath, testdir + "/ethnode1", testdir + "/genesis.json", 30305, cb);
    dynamic["node1_port"] = "30305";
},
function(cb) {
    ethconsole.startNode(ethpath, testdir + "/ethnode2", testdir + "/genesis.json", 30306, cb);
    dynamic["node2_port"] = "30306";
},
function(cb) {
    runAllTests(cb);    
},
function(cb) {
    ethconsole.stopNode(testdir + "/ethnode1", cb);
    ethconsole.stopNode(testdir + "/ethnode2", cb);
}
], function() { 
    utils.rmdir(testdir); }
)
}//main



function prepareDynamicVars(finished)
{
  async.series([
    function(cb) {      
        ethconsole.runScriptOnNode(testdir + "/ethnode1", workdir + "/scripts/testNewAccount.js", {}, cb);
    },
    function(cb) {
        dynamic["account"] = ethconsole.getLastResponse();
        utils.mkdir(testdir);
        testutils.generateCustomGenesis(testdir + '/genesis.json', workdir + "/scripts/genesis.json", dynamic["account"], cb);
    },
    function(cb) {
        ethconsole.runScriptOnNode(testdir + "/ethnode1", workdir + "/scripts/getNodeInfo.js", {}, cb);
    },
    function(cb) {
        dynamic["node1_ID"] = ethconsole.getLastResponse().id;
        cb();
    }
  ], function() { finished(); })
}

function runAllTests(finished)
{
    var currentTest = -1;
    var updateDynamic = function(){};

    function nextTest()
    {
       currentTest++;
       if (currentTest == testutils.getTestCount())
        finished();
       else
       {
        var testObject = testutils.getTestNumber(currentTest);
        var nodepath;
        if (testObject.node == '01')
            nodepath = testdir + "/ethnode1";
        if (testObject.node == '02')
            nodepath = testdir + "/ethnode2";

        ethconsole.runScriptOnNode(nodepath, testObject.file, dynamic, updateDynamic);
       }
    }

    updateDynamic = function updateDynamic()
    {
        async.series([
            function(cb) {
                ethconsole.runScriptOnNode(testdir + "/ethnode1", workdir + "/scripts/getLastBlock.js", {}, cb);
            },
            function(cb) {
                dynamic["node1_lastblock"] = ethconsole.getLastResponse();
                cb();
            },
            function(cb) {
                ethconsole.runScriptOnNode(testdir + "/ethnode2", workdir +  "/scripts/getLastBlock.js", {}, cb);
            },
            function(cb) {
                dynamic["node2_lastblock"] = ethconsole.getLastResponse();
                cb();
            }
            ], function() { nextTest(); });
    }
    nextTest();
}

main();