aboutsummaryrefslogtreecommitdiffstats
path: root/RPCTests/main.js
blob: e3089f0d0f019f4638344bb05dc7d92e3e66e975 (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
//requires installed node v6
//requires ETHEREUM_TEST_PATH env variable set  (for full path to the ipc sockets)
//requires ethereum eth path

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

var ethpath = '/home/wins/Ethereum/cpp-ethereum/build/eth/eth';
var testdir = process.env.ETHEREUM_TEST_PATH + "/RPCTests/dynamic";

var dynamic = {};

function cb(){}
function main()
{

testutils.readTestsInFolder("./scripts/tests");
async.series([
function(cb) {
    utils.setDebug(true);
    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", "./scripts/testNewAccount.js", {}, cb);
    },
    function(cb) {
        dynamic["account"] = ethconsole.getLastResponse();
        utils.mkdir(testdir);
        testutils.generateCustomGenesis(testdir + '/genesis.json', "./scripts/genesis.json", dynamic["account"], cb);
    },
    function(cb) {
        ethconsole.runScriptOnNode(testdir + "/ethnode1", "./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", "./scripts/getLastBlock.js", {}, cb);
            },
            function(cb) {
                dynamic["node1_lastblock"] = ethconsole.getLastResponse();
                cb();
            },
            function(cb) {
                ethconsole.runScriptOnNode(testdir + "/ethnode2", "./scripts/getLastBlock.js", {}, cb);
            },
            function(cb) {
                dynamic["node2_lastblock"] = ethconsole.getLastResponse();
                cb();
            }
            ], function() { nextTest(); });
    }
    nextTest();
}

main();
//testutils.readTestsInFolder("./scripts/tests");