Files
xahau.js/packages/ripple-binary-codec/test/amount.test.js
Nathan Nichols 383ab88d62 refactored src/types (#86)
Final refactor of the src/types directory. Refactored Amount and STObject classes, and finalized SerializedType and Comparable classes.
2020-07-20 11:02:59 -05:00

43 lines
1.2 KiB
JavaScript

const _ = require('lodash')
const { loadFixture } = require('./utils')
const { coreTypes } = require('../dist/types')
const { Amount } = coreTypes
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, () => {
expect(() => {
Amount.from(f.test_json)
JSON.stringify(f.test_json)
}).toThrow()
})
})
}
describe('Amount', function () {
it('can be parsed from', function () {
expect(Amount.from('1000000') instanceof Amount).toBe(true)
expect(Amount.from('1000000').toJSON()).toEqual('1000000')
const fixture = {
value: '1',
issuer: '0000000000000000000000000000000000000000',
currency: 'USD'
}
const amt = Amount.from(fixture)
const rewritten = {
value: '1',
issuer: 'rrrrrrrrrrrrrrrrrrrrrhoLvTp',
currency: 'USD'
}
expect(amt.toJSON()).toEqual(rewritten)
})
amountErrorTests()
})