This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
forked from mrlahaye/turtlecoin-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
327 lines (311 loc) · 18.9 KB
/
index.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#!/usr/bin/env node
// Copyright (c) 2018, Brandon Lehmann, The TurtleCoin Developers
//
// Please see the included LICENSE file for more information.
'use strict'
const seedNode = 'https://api.turtlenode.io/seed.turtlenode.io/getinfo'
const request = require('request-promise-native')
const TurtleCoind = require('turtlecoin-rpc').TurtleCoind
const Client = require('turtlecoin-rpc').Client
const TurtleService = require('turtlecoin-rpc').Service
const info = require('./package.json')
const author = (typeof info.author === 'object') ? `${info.author.name} <${info.author.email}>` : info.author.toString()
const license = info.license.toString()
const readline = require('readline')
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: 'TurtleCoin> '
})
console.log('\n\n',
'████████╗██╗ ██╗██████╗ ████████╗██╗ ██████╗ █████╗ █████╗ ██╗███╗ ██╗\n',
'╚══██╔══╝██║ ██║██╔══██╗╚══██╔══╝██║ ██╔═══╝██╔═══╝██╔══██╗██║████╗ ██║\n',
' ██║ ██║ ██║██████╔╝ ██║ ██║ ████╗ ██║ ██║ ██║██║██╔██╗ ██║\n',
' ██║ ██║ ██║██╔══██╗ ██║ ██║ ██╔═╝ ██║ ██║ ██║██║██║╚██╗██║\n',
' ██║ ╚█████╔╝██║ ██║ ██║ ██████╗██████╗╚█████╗╚█████╔╝██║██║ ╚████║\n',
' ╚═╝ ╚════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═════╝ ╚════╝ ╚════╝ ╚═╝╚═╝ ╚═══╝\n')
console.log(` TurtleCoin Test Suite v${info.version}\n`)
console.log(` By: ${author}`)
console.log(` Open Sourced Under ${license} since 2018`)
console.log('')
console.log(' Type "help" for information on available commands\n\n')
function question (string) {
return new Promise((resolve, reject) => {
console.log(string)
rl.question('', (answer) => {
return resolve(answer.trim())
})
})
}
function checkPass (func) {
return new Promise((resolve, reject) => {
func.then((result) => {
result = result || {}
return resolve({ pass: true, info: result })
}).catch(() => {
return resolve({ pass: false, info: {} })
})
})
}
function getSeedInfo () {
return new Promise((resolve, reject) => {
request({
url: seedNode,
json: true
}).then((info) => {
return resolve({ pass: true, info: info })
}).catch(() => {
return resolve({ pass: false, info: {} })
})
})
}
function daemonTests () {
var ip, port, daemon, client, seedInfo
var lastblockhash = '2ef060801dd27327533580cfa538849f9e1968d13418f2dd2535774a8c494bf4'
console.log('')
question('What is the address of the daemon you would like to test? [127.0.0.1] ').then((daemonIp) => {
ip = (daemonIp.length > 0) ? daemonIp : '127.0.0.1'
return question('What is the port number of the daemon you would like to test? [11898] ')
}).then((daemonPort) => {
port = (daemonPort.length > 0) ? daemonPort : 11898
daemon = new TurtleCoind({
host: ip,
port: port
})
client = new Client({
host: ip,
port: port
})
console.log('')
console.log(`Attempting to retrieve information from seed node...`)
return getSeedInfo()
}).then((result) => {
console.log('')
if (result.pass) {
seedInfo = result.info
console.log(`Information retrieved from seed node. Height: ${seedInfo.height}, Difficulty: ${seedInfo.difficulty}, Hashrate: ${seedInfo.hashrate}`)
} else {
console.log(`Could not retrieve information from seed node. Continuing without...`)
}
console.log('')
console.log(`Starting tests against ${ip}:${port}...\n`)
return checkPass(daemon.getInfo())
}).then((result) => {
console.log(`getinfo passing: ${result.pass} ${(result.pass && result.info.version) ? result.info.version : 'unknown'}`)
if (result.pass && seedInfo.height && result.info.synced && seedInfo.synced) {
var matchHeight = (seedInfo.height === result.info.height)
var matchDifficulty = (seedInfo.difficulty === result.info.difficulty)
console.log(` - height match passing: ${matchHeight}`)
console.log(` - difficulty match passing: ${matchDifficulty}`)
} else {
console.log(` - height match passing: skipped`)
console.log(` - difficulty match passing: skipped`)
}
return checkPass(daemon.getHeight())
}).then((result) => {
console.log(`getheight passing: ${result.pass} ${(result.pass && result.info.height) ? result.info.height : 'unknown'}`)
return checkPass(daemon.feeInfo())
}).then((result) => {
console.log(`feeinfo passing: ${result.pass} ${(result.pass && result.info.status) ? result.info.status : 'unknown'}`)
return checkPass(daemon.getPeers())
}).then((result) => {
console.log(`getpeers passing: ${result.pass} ${(result.pass && result.info.peers) ? result.info.peers.length : 'unknown'}`)
return checkPass(daemon.getCurrencyId())
}).then((result) => {
console.log(`getcurrencyid passing: ${result.pass} ${(result.pass && result.info.length > 0) ? result.info : 'unknown'}`)
return checkPass(daemon.getBlockHeaderByHeight({ height: 2 }))
}).then((result) => {
console.log(`getblockheaderbyheight passing: ${result.pass} ${(result.pass && result.info.hash) ? result.info.hash : 'unknown'}`)
return checkPass(daemon.getBlockHeaderByHash({ hash: '2ef060801dd27327533580cfa538849f9e1968d13418f2dd2535774a8c494bf4' }))
}).then((result) => {
console.log(`getblockheaderbyhash passing: ${result.pass} ${(result.pass && result.info.height) ? result.info.height : 'unknown'}`)
return checkPass(daemon.getLastBlockHeader())
}).then((result) => {
if (result.pass && result.info.hash) lastblockhash = result.info.hash
console.log(`getlastblockheader passing: ${result.pass} ${(result.pass && result.info.hash) ? result.info.hash : 'unknown'}`)
return checkPass(daemon.getBlockTemplate({ walletAddress: 'TRTLuxN6FVALYxeAEKhtWDYNS9Vd9dHVp3QHwjKbo76ggQKgUfVjQp8iPypECCy3MwZVyu89k1fWE2Ji6EKedbrqECHHWouZN6g', reserveSize: 200 }))
}).then((result) => {
console.log(`getblocktemplate passing: ${result.pass} ${(result.pass && result.info.difficulty) ? result.info.difficulty : 'unknown'}`)
return checkPass(daemon.getBlockHash({ height: 2 }))
}).then((result) => {
console.log(`on_getblockhash passing: ${result.pass} ${(result.pass && result.info) ? result.info : 'unknown'}`)
return checkPass(daemon.getBlockCount())
}).then((result) => {
console.log(`getblockcount passing: ${result.pass} ${(result.pass && result.info) ? result.info : 'unknown'}`)
return checkPass(daemon.getTransactionPool())
}).then((result) => {
console.log('')
if (!result.pass) {
console.log('')
console.log('It looks like you did not start daemon with --enable-blockexplorer')
console.log('The next few f_ tests will fail')
console.log('')
}
console.log(`f_on_transactions_pool_json passing: ${result.pass} ${(result.pass && result.info) ? result.info.length : 'unknown'}`)
return checkPass(daemon.getTransaction({ hash: '702ad5bd04b9eff14b080d508f69a320da1909e989d6c163c18f80ae7a5ab832' }))
}).then((result) => {
if (result.pass && !result.info.txDetails) {
result.info = {
txDetails: {
hash: ''
}
}
}
console.log(`f_transaction_json passing: ${result.pass} ${(result.pass && result.info.txDetails.hash) ? result.info.txDetails.hash : 'unknown'}`)
return checkPass(daemon.getBlock({ hash: '2ef060801dd27327533580cfa538849f9e1968d13418f2dd2535774a8c494bf4' }))
}).then((result) => {
if (!result.pass) {
result.info = { prev_hash: '' }
}
console.log(`f_block_json passing: ${result.pass} ${(result.pass && result.info.prev_hash) ? result.info.prev_hash : 'unknown'}`)
return checkPass(daemon.getBlocks({ height: 30 }))
}).then((result) => {
console.log(`f_blocks_list_json passing: ${result.pass} ${(result.pass && result.info) ? result.info.length : 'unknown'}`)
console.log('')
return checkPass(client.queryBlocksLite({ blockHashes: ['2ef060801dd27327533580cfa538849f9e1968d13418f2dd2535774a8c494bf4'] }))
}).then((result) => {
console.log(`queryblockslite passing: ${result.pass} ${(result.pass && result.info.items) ? result.info.items.length : 'unknown'}`)
return checkPass(client.getIndexes({ transactionHash: '702ad5bd04b9eff14b080d508f69a320da1909e989d6c163c18f80ae7a5ab832' }))
}).then((result) => {
console.log(`get_o_indexes passing: ${result.pass} ${(result.pass && result.info.o_indexes) ? result.info.o_indexes.length : 'unknown'}`)
return checkPass(client.getRandomOutputs({ amounts: [100, 1000], mixin: 3 }))
}).then((result) => {
console.log(`getrandom_outs passing: ${result.pass} ${(result.pass && result.info.outs) ? result.info.outs.length : 'unknown'}`)
return checkPass(client.getPoolChanges({ tailBlockHash: '2ef060801dd27327533580cfa538849f9e1968d13418f2dd2535774a8c494bf4', knownTransactionHashes: [] }))
}).then((result) => {
console.log(`get_pool_changes passing: ${result.pass} ${(result.pass && result.info.status) ? result.info.status : 'unknown - okay if failed'}`)
return checkPass(client.getPoolChangesLite({ tailBlockHash: '2ef060801dd27327533580cfa538849f9e1968d13418f2dd2535774a8c494bf4', knownTransactionHashes: [] }))
}).then((result) => {
console.log(`get_pool_changes_lite passing: ${result.pass} ${(result.pass && result.info.status) ? result.info.status : 'unknown - okay if failed'}`)
return checkPass(client.getBlockDetailsByHeight({ blockHeight: 2 }))
}).then((result) => {
console.log(`get_block_details_by_height passing: ${result.pass} ${(result.pass && result.info.block) ? result.info.block.hash : 'unknown'}`)
return checkPass(client.getBlocksDetailsByHeights({ blockHeights: [2, 4, 6, 8] }))
}).then((result) => {
console.log(`get_blocks_details_by_heights passing: ${result.pass} ${(result.pass && result.info.blocks) ? result.info.blocks.length : 'unknown'}`)
return checkPass(client.getBlocksDetailsByHashes({ blockHashes: ['2ef060801dd27327533580cfa538849f9e1968d13418f2dd2535774a8c494bf4', lastblockhash] }))
}).then((result) => {
console.log(`get_blocks_details_by_hashes passing: ${result.pass} ${(result.pass && result.info.blocks) ? result.info.blocks.length : 'unknown'}`)
return checkPass(client.getBlocksHashesByTimestamps({ timestampBegin: 1531348100, seconds: 240 }))
}).then((result) => {
console.log(`get_blocks_hashes_by_timestamps passing: ${result.pass} ${(result.pass && result.info.blockHashes) ? result.info.blockHashes.length : 'unknown'}`)
return checkPass(client.getTransactionDetailsByHashes({ transactionHashes: ['702ad5bd04b9eff14b080d508f69a320da1909e989d6c163c18f80ae7a5ab832'] }))
}).then((result) => {
console.log(`get_transaction_details_by_hashes passing: ${result.pass} ${(result.pass && result.info.transactions) ? result.info.transactions.length : 'unknown'}`)
return checkPass(client.getTransactionHashesByPaymentId({ paymentId: '80ec855eef7df4bce718442cabe086f19dfdd0d03907c7768eddb8eca8c5a667' }))
}).then((result) => {
console.log(`get_transaction_hashes_by_payment_id passing: ${result.pass} ${(result.pass && result.info.transactionHashes) ? result.info.transactionHashes.length : 'unknown'}`)
return checkPass(client.queryBlocksDetailed({ blockHashes: ['2ef060801dd27327533580cfa538849f9e1968d13418f2dd2535774a8c494bf4'], blockCount: 2 }))
}).then((result) => {
console.log(`queryblocksdetailed passing: ${result.pass} ${(result.pass && result.info.blocks) ? result.info.blocks.length : 'unknown'}`)
}).then(() => {
console.log('')
rl.prompt()
})
}
function serviceTests () {
var ip, port, password, service, address, tempaddress
console.log('')
question('What is the address of turtle-service you would like to test? [127.0.0.1] ').then((serviceIp) => {
ip = (serviceIp.length > 0) ? serviceIp : '127.0.0.1'
return question('What is the port number of turtle-service you would like to test? [8070] ')
}).then((servicePort) => {
port = (servicePort.length > 0) ? servicePort : 8070
return question('What is the password of turtle-service you would like to test? [password] ')
}).then((servicePassword) => {
password = (servicePassword.length > 0) ? servicePassword : 'password'
service = new TurtleService({
host: ip,
port: port,
rpcPassword: password,
defaultMixin: 3
})
console.log('')
console.log(`Starting tests against ${ip}:${port}...\n`)
return checkPass(service.getAddresses())
}).then((result) => {
if (result.pass && result.info.length > 0) address = result.info[0]
console.log(`getAddresses passing: ${result.pass} ${(result.pass && result.info.length > 0) ? '[' + result.info.length + '] ' + result.info[0] : 'unknown'}`)
return checkPass(service.getStatus())
}).then((result) => {
console.log(`getStatus passing: ${result.pass} ${(result.pass && result.info.blockCount) ? result.info.blockCount : 'unknown'}`)
return checkPass(service.getFeeInfo())
}).then((result) => {
console.log(`getFeeInfo passing: ${result.pass} ${(result.pass && result.info.amount) ? result.info.amount : '0.00'}`)
return checkPass(service.getViewKey())
}).then((result) => {
console.log(`getViewKey passing: ${result.pass} ${(result.pass && result.info.viewSecretKey.length > 0) ? 'Hidden' : 'unknown'}`)
return checkPass(service.getSpendKeys({ address: address }))
}).then((result) => {
console.log(`getSpendKeys passing: ${result.pass} ${(result.pass && result.info.spendPublicKey.length > 0) ? 'Hidden' : 'unknown'}`)
return checkPass(service.getMnemonicSeed({ address: address }))
}).then((result) => {
console.log(`getMnemonicSeed passing: ${result.pass} ${(result.pass && result.info.length > 0) ? 'Hidden' : 'unknown'}`)
return checkPass(service.createAddress())
}).then((result) => {
if (result.pass && result.info.length > 0) tempaddress = result.info
console.log(`createAddress passing: ${result.pass} ${(result.pass && result.info.length > 0) ? result.info : 'unknown'}`)
return checkPass(service.deleteAddress({ address: tempaddress }))
}).then((result) => {
console.log(`deleteAddress passing: ${result.pass} ${(result.pass) ? 'OK' : 'unknown'}`)
return checkPass(service.getBalance())
}).then((result) => {
console.log(`getBalance passing: ${result.pass} ${(result.pass && result.info.availableBalance !== -1) ? result.info.availableBalance : 'unknown'}`)
return checkPass(service.getBlockHashes({ firstBlockIndex: 1, blockCount: 10 }))
}).then((result) => {
console.log(`getBlockHashes passing: ${result.pass} ${(result.pass && result.info.blockHashes) ? result.info.blockHashes.length : 'unknown'}`)
return checkPass(service.getTransactionHashes({ addresses: [address], firstBlockIndex: 1, blockCount: 10 }))
}).then((result) => {
console.log(`getTransactionHashes passing: ${result.pass} ${(result.pass && result.info) ? result.info.length : 'unknown'}`)
return checkPass(service.getTransactions({ addresses: [address], firstBlockIndex: 1, blockCount: 10 }))
}).then((result) => {
console.log(`getTransactions passing: ${result.pass} ${(result.pass && result.info) ? result.info.length : 'unknown'}`)
return checkPass(service.getUnconfirmedTransactionHashes())
}).then((result) => {
console.log(`getUnconfirmedTransactionHashes passing: ${result.pass} ${(result.pass && result.info.transactionHashes) ? result.info.transactionHashes.length : 'unknown'}`)
return checkPass(service.createIntegratedAddress({ address: 'TRTLv1pacKFJk9QgSmzk2LJWn14JGmTKzReFLz1RgY3K9Ryn7783RDT2TretzfYdck5GMCGzXTuwKfePWQYViNs4avKpnUbrwfQ', paymentId: '80ec855eef7df4bce718442cabe086f19dfdd0d03907c7768eddb8eca8c5a667' }))
}).then((result) => {
console.log(`createIntegratedAddress passing: ${result.pass} ${(result.pass && result.info.length > 0) ? result.info : 'unknown'}`)
return checkPass(service.save())
}).then((result) => {
console.log(`save passing: ${result.pass} ${(result.pass) ? 'OK' : 'unknown'}`)
}).then(() => {
console.log(`getTransaction passing: skipped`)
console.log(`sendTransaction passing: skipped`)
console.log(`createDelayedTransaction passing: skipped`)
console.log(`deleteDelayedTransaction passing: skipped`)
console.log(`sendDelayedTransaction passing: skipped`)
console.log(`sendFusionTransaction passing: skipped`)
console.log(`estimateFusion passing: skipped`)
}).then(() => {
console.log('')
rl.prompt()
})
}
rl.on('line', (line) => {
switch (line.trim().toLowerCase()) {
case 'help':
console.log('\nAvailable Commands\n')
console.log('test daemon: tests daemon RPC calls to verify proper operation')
console.log('test service: tests turtle-service RPC calls to verify proper operation')
console.log('exit: exits the test suite software\n')
break
case 'test daemon':
daemonTests()
break
case 'test service':
serviceTests()
break
case 'exit':
console.log('\nThanks for using the TurtleCoin Test Suite\n')
process.exit()
break
case '':
break
default:
console.log('\nCommand not found. Please type "help" for information on avaiable commands')
break
}
rl.prompt()
})
rl.prompt()