Files
xahau.js/packages/ripple-binary-codec/test/lower-case-hex.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

47 lines
1.4 KiB
TypeScript

import { encode, decode } from '../src'
let str =
'1100612200000000240000000125000068652D0000000055B6632D6376A2D9319F20A1C6DCCB486432D1E4A79951229D4C3DE2946F51D56662400009184E72A00081140DD319918CD5AE792BF7EC80D63B0F01B4573BBC'
let lower = str.toLowerCase()
let bin =
'1100612200000000240000000125000000082D00000000550735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E56240000002540BE400811479927BAFFD3D04A26096C0C97B1B0D45B01AD3C0'
let json = {
OwnerCount: 0,
Account: 'rUnFEsHjxqTswbivzL2DNHBb34rhAgZZZK',
PreviousTxnLgrSeq: 8,
LedgerEntryType: 'AccountRoot',
PreviousTxnID:
'0735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E5'.toLowerCase(),
Flags: 0,
Sequence: 1,
Balance: '10000000000',
}
let jsonUpper = {
OwnerCount: 0,
Account: 'rUnFEsHjxqTswbivzL2DNHBb34rhAgZZZK',
PreviousTxnLgrSeq: 8,
LedgerEntryType: 'AccountRoot',
PreviousTxnID:
'0735A0B32B2A3F4C938B76D6933003E29447DB8C7CE382BBE089402FF12A03E5',
Flags: 0,
Sequence: 1,
Balance: '10000000000',
}
describe('Lowercase hex test', () => {
it('Correctly decodes', () => {
expect(decode(lower)).toEqual(decode(str))
})
it('Re-encodes to uppercase hex', () => {
expect(encode(decode(lower))).toEqual(str)
})
it('Encode when hex field lowercase', () => {
expect(encode(json)).toBe(bin)
})
it('Re-decodes to uppercase hex', () => {
expect(decode(encode(json))).toEqual(jsonUpper)
})
})