-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.fetchLedger.js
46 lines (31 loc) · 1.16 KB
/
test.fetchLedger.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
'use strict'
// ----------------------------------------------------------------------------
const assert = require ('assert')
, testLedgerItem = require ('./test.ledgerItem')
// ----------------------------------------------------------------------------
module.exports = async (exchange, code) => {
let method = 'fetchLedger'
if (exchange.has[method]) {
const items = await exchange[method] (code)
assert (items instanceof Array)
console.log ('Fetched', items.length, 'ledger items')
const now = Date.now ()
for (let i = 0; i < items.length; i++) {
testLedgerItem (exchange, items[i], code, now)
if (i > 0) {
assert (items[i].timestamp >= items[i - 1].timestamp)
}
}
method = 'fetchLedgerItem';
if (exchange.has[method]) {
const { id } = items.pop ()
let item = await exchange[method] (id)
if (Array.isArray (item)) {
item = item[0]
}
testLedgerItem (exchange, item, code, now)
}
} else {
console.log (method + '() is not supported')
}
}