-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathamount-test.js
More file actions
43 lines (40 loc) · 1.2 KB
/
amount-test.js
File metadata and controls
43 lines (40 loc) · 1.2 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
38
39
40
41
42
const _ = require('lodash');
const assert = require('assert-diff');
const utils = require('./utils');
const {Amount} = require('../src/coretypes');
const {loadFixture} = utils;
const fixtures = loadFixture('data-driven-tests.json');
function amountErrorTests() {
_.filter(fixtures.values_tests, {type: 'Amount'}).forEach(f => {
// We only want these with errors
if (!f.error) {
return
}
const testName = `${JSON.stringify(f.test_json)}\n\tis invalid ` +
`because: ${f.error}`
it(testName, () => {
assert.throws(() => {
Amount.from(f.test_json);
}, JSON.stringify(f.test_json));
});
});
}
describe('Amount', function() {
it('can be parsed from', function() {
assert(Amount.from('1000000') instanceof Amount);
assert.equal(Amount.from('1000000').valueString(), '1000000');
const fixture = {
'value': '1',
'issuer': '0000000000000000000000000000000000000000',
'currency': 'USD'
};
const amt = Amount.from(fixture);
const rewritten = {
'value': '1',
'issuer': 'rrrrrrrrrrrrrrrrrrrrrhoLvTp',
'currency': 'USD'
};
assert.deepEqual(amt.toJSON(), rewritten);
});
amountErrorTests()
});