Files
xahau.js/packages/ripple-binary-codec/test/amount.test.ts
Caleb Kniffen e2433101cb test: run binary-codec tests in the browser (#2566)
- Convert tests to typescript
- Update type definitions causing errors in tests
  - `makeParser` to accept a `Buffer` in addition to `string`
  - `SerializedType` constructor allows not passing in a byte array
  - `Comparable` is now a generic type so that it allows `compareTo`
methods to take more that the type itself. Example: `Uint64.compareTo`
can accept `number`
- Update tests to use jasmine compatible functions
  - Switching from `test` to `it`.
  - Updated test checking if coretypes all implement SerializedType
  - Import fixtures directly instead of using `loadFixture` utility
- Remove importing of `buffer/` explicitly.  It was throwing off type
checking in tests.  Buffer is going away in a future PR anyway.
- Fixed `npm run clean` not clearing `.tsbuildinfo` files for keypairs
- Remove unused account-tx-transactions.db. It was likely used in the
past to test historical ledgers.
2024-02-01 13:53:40 -06:00

43 lines
1.1 KiB
TypeScript

import { coreTypes } from '../src/types'
import fixtures from './fixtures/data-driven-tests.json'
const { Amount } = coreTypes
function amountErrorTests() {
fixtures.values_tests
.filter((obj) => obj.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()
})