-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary-json-test.js
More file actions
37 lines (34 loc) · 1.12 KB
/
binary-json-test.js
File metadata and controls
37 lines (34 loc) · 1.12 KB
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
const assert = require('assert');
const fixtures = require('./fixtures/codec-fixtures.json');
const {decode, encode, decodeLedgerData} = require('../src');
function json(object) {
return JSON.stringify(object);
}
describe('ripple-binary-codec', function() {
function makeSuite(name, entries) {
describe(name, function() {
entries.forEach((t, test_n) => {
it(`${name}[${test_n}] can encode ${json(t.json)} to ${t.binary}`,
() => {
assert.equal(t.binary, encode(t.json));
});
it(`${name}[${test_n}] can decode ${t.binary} to ${json(t.json)}`,
() => {
const decoded = decode(t.binary);
assert.deepEqual(t.json, decoded);
});
});
});
}
makeSuite('transactions', fixtures.transactions);
makeSuite('accountState', fixtures.accountState);
describe('ledgerData', function() {
fixtures.ledgerData.forEach((t, test_n) => {
it(`ledgerData[${test_n}] can decode ${t.binary} to ${json(t.json)}`,
() => {
const decoded = decodeLedgerData(t.binary);
assert.deepEqual(t.json, decoded);
});
});
})
});