aboutsummaryrefslogtreecommitdiffstats
path: root/RPCTests/modules/testutils.js
blob: 7128c6972f2bd65f44ba74168b4796dfd2ff36e4 (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
const fs = require('fs');
var utils = require('./utils.js');
var tests = {};
var testCount = 0;

module.exports = {

generateCustomGenesis: function generateCustomGenesis(path, originalPath, accountName, finished)
{
    var onFileRead = function (err, data) {};
    fs.readFile(originalPath, 'utf8',  (err, data) => { onFileRead (err,data) });

    onFileRead = function (err, data)
    {
      if (err) 
        throw err;

      data = data.replace("[ADDRESS]", accountName);
      fs.writeFile(path, data, (err) => { 
                   if (err) 
                    throw err;
                    finished();
                });
    }
},

readTestsInFolder: function readTestsInFolder(path)
{
    var res = utils.listFiles(path);
    res.forEach(function(file) {
        var testn = file.indexOf("test");
        var slashn = file.indexOf("_");
        if (testn != -1 && slashn != -1)
        {
            testNumber = parseInt(file.substring(testn + 4, slashn));
            var noden = file.indexOf("node");
            var slashn = file.indexOf("_", slashn+1);
            var tmpFile = file.indexOf("~");
            if (noden != -1 && slashn != -1 && tmpFile == -1)
            {
                if (tests[testNumber])
                    console.log("Error: dublicate test found " + file);
                else
                {
                    var testObject = {};
                    testObject.file = file;
                    testObject.node = file.substring(noden + 4, slashn);
                    tests[testNumber] = testObject;
                    testCount++;
                }
            }
        }
    });
},

getTestCount: function getTestCount()
{
    return testCount;
},

getTestNumber: function getTestNumber(n)
{
    if(n < testCount);
        return tests[n];
}


}//modules