refactored src/types (#86)

Final refactor of the src/types directory. Refactored Amount and STObject classes, and finalized SerializedType and Comparable classes.
This commit is contained in:
Nathan Nichols
2020-07-20 11:02:59 -05:00
parent 2bfb8fc191
commit 383ab88d62
19 changed files with 384 additions and 424 deletions

View File

@@ -138,19 +138,19 @@ function transactionParsingTests () {
{
const [field, value] = readField()
expect(field).toEqual(Field.TakerPays)
expect(value.currency.isNative()).toEqual(true)
expect(value.currency.toJSON()).toEqual('XRP')
expect(value.isNative()).toEqual(true)
expect(value.toJSON()).toEqual('98957503520')
}
{
const [field, value] = readField()
expect(field).toEqual(Field.TakerGets)
expect(value.currency.isNative()).toEqual(false)
expect(value.issuer.toJSON()).toEqual(tx_json.TakerGets.issuer)
expect(value.isNative()).toEqual(false)
expect(value.toJSON().issuer).toEqual(tx_json.TakerGets.issuer)
}
{
const [field, value] = readField()
expect(field).toEqual(Field.Fee)
expect(value.currency.isNative()).toEqual(true)
expect(value.isNative()).toEqual(true)
}
{
const [field, value] = readField()
@@ -197,9 +197,11 @@ function amountParsingTests () {
const value = parser.readType(Amount)
// May not actually be in canonical form. The fixtures are to be used
// also for json -> binary;
assertEqualAmountJSON(toJSON(value), (f.test_json))
const json = toJSON(value)
assertEqualAmountJSON(json, (f.test_json))
if (f.exponent) {
expect(value.exponent()).toEqual(f.exponent)
const exponent = new Decimal(json.value);
expect(exponent.e-15).toEqual(f.exponent)
}
})
})