forked from celo-org/celo-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runTests.js
130 lines (118 loc) · 3.39 KB
/
runTests.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
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
128
129
130
const ganache = require('@celo/ganache-cli')
const glob = require('glob-fs')({
gitignore: false,
})
const { exec, waitForPortOpen } = require('./lib/test-utils')
const minimist = require('minimist')
const network = require('./truffle-config.js').networks.development
const sleep = (seconds) => new Promise((resolve) => setTimeout(resolve, 1000 * seconds))
// As documented https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables
const isCI = process.env.CI === 'true'
// Migration overrides specifically for unit tests
const migrationOverrides = {
downtimeSlasher: {
slashableDowntime: 60, // epoch length is 100 for unit tests
},
election: {
minElectableValidators: '10',
},
epochRewards: {
frozen: false,
},
exchange: {
frozen: false,
minimumReports: 1,
},
goldToken: {
frozen: false,
},
governanceApproverMultiSig: {
signatories: [network.from],
numRequiredConfirmations: 1,
numInternalRequiredConfirmations: 1,
},
reserve: {
initialBalance: 100000000,
otherAddresses: ['0x7457d5E02197480Db681D3fdF256c7acA21bDc12'], // Add an arbitrary "otherReserveAddress" so that reserve spending can be tested.
},
reserveSpenderMultiSig: {
signatories: [network.from],
numRequiredConfirmations: 1,
numInternalRequiredConfirmations: 1,
},
stableToken: {
oracles: [network.from],
frozen: false,
},
}
async function startGanache() {
const server = ganache.server({
default_balance_ether: network.defaultBalance,
network_id: network.network_id,
mnemonic: network.mnemonic,
gasPrice: network.gasPrice,
gasLimit: 20000000,
allowUnlimitedContractSize: true,
})
await new Promise((resolve, reject) => {
server.listen(8545, (err, blockchain) => {
if (err) {
reject(err)
} else {
resolve(blockchain)
}
})
})
return () =>
new Promise((resolve, reject) => {
server.close((err) => {
if (err) {
reject(err)
} else {
resolve()
}
})
})
}
async function test() {
const argv = minimist(process.argv.slice(2), {
boolean: ['gas', 'coverage', 'verbose-rpc'],
})
try {
const closeGanache = await startGanache()
if (isCI) {
// If we are running on circle ci we need to wait for ganache to be up.
await waitForPortOpen('localhost', 8545, 60)
}
let testArgs = ['run', 'truffle', 'test']
if (argv['verbose-rpc']) {
testArgs.push('--verbose-rpc')
}
if (argv.coverage) {
testArgs = testArgs.concat(['--network', 'coverage'])
}
if (argv.gas) {
testArgs = testArgs.concat(['--color', '--gas'])
}
// Add test specific migration overrides
testArgs = testArgs.concat(['--migration_override', JSON.stringify(migrationOverrides)])
const testGlob =
argv._.length > 0
? argv._.map((testName) => `test/\*\*/${testName}.ts`).join(' ')
: `test/\*\*/*.ts`
const testFiles = glob.readdirSync(testGlob)
if (testFiles.length === 0) {
// tslint:disable-next-line: no-console
console.error(`No test files matched with ${testGlob}`)
process.exit(1)
}
testArgs = testArgs.concat(testFiles)
await exec('yarn', testArgs)
await closeGanache()
} catch (e) {
// tslint:disable-next-line: no-console
console.error(e.stdout ? e.stdout : e)
process.nextTick(() => process.exit(1))
}
}
test()