mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-07 22:35:48 +00:00
* will compile as typescript * migrated test suite to use JestJS * Migrated to Jest testing framework and typescript source files * updated deps * updated prepublish * resolved 1 failing test * changed decimal .0 on four tests, it appears that these were the only four tests expecting integer values to have '.0' * added linter * added package-lock * removed tslint in favor of eslint * changed yarn to npm * updated version 2.6->3.0 * removing package lock * updated node version in nvmrc and jest version in package * removed nvmrc * removed some unused functions * replaced data driven with file from master * commitint yarn.lock * removing babel as a dependency in favor of typescript compiling to es5 * removing babel deps * resolved testing issues by migrating helper function * added partial linting functionality for test suite * updated imports for decodeLedgerData * updated test * updated yarn.lock * removed a console.log * added eslint-jest-plugin to package * reverting to old linting, will add linting in next PR * removed comments in shamap * re-adding .nvmrc * npm -> yarn * added . to .eslintrc * added .eslintrc * removing linting for this PR * Changed linting to print a message so that linting doesnt fail in CI * changing back * added newline so diff wont show * removed eslint deps, since linting will be dealt with in a later PR * changed function calls to describe(...)
57 lines
2.0 KiB
JavaScript
57 lines
2.0 KiB
JavaScript
const { coreTypes } = require('../dist/types')
|
|
const { Hash160, Hash256, Currency, AccountID } = coreTypes
|
|
|
|
describe('Hash160', function () {
|
|
test('has a static width membmer', function () {
|
|
expect(Hash160.width).toBe(20)
|
|
})
|
|
test('inherited by subclasses', function () {
|
|
expect(AccountID.width).toBe(20)
|
|
expect(Currency.width).toBe(20)
|
|
})
|
|
test('can be compared against another', function () {
|
|
const h1 = Hash160.from('1000000000000000000000000000000000000000')
|
|
const h2 = Hash160.from('2000000000000000000000000000000000000000')
|
|
const h3 = Hash160.from('0000000000000000000000000000000000000003')
|
|
expect(h1.lt(h2)).toBe(true)
|
|
expect(h3.lt(h2)).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('Hash256', function () {
|
|
test('has a static width membmer', function () {
|
|
expect(Hash256.width).toBe(32)
|
|
})
|
|
test('has a ZERO_256 member', function () {
|
|
expect(Hash256.ZERO_256.toJSON()).toBe('0000000000000000000000000000000000000000000000000000000000000000')
|
|
})
|
|
test('supports getting the nibblet values at given positions', function () {
|
|
const h = Hash256.from(
|
|
'1359BD0000000000000000000000000000000000000000000000000000000000')
|
|
expect(h.nibblet(0)).toBe(0x1)
|
|
expect(h.nibblet(1)).toBe(0x3)
|
|
expect(h.nibblet(2)).toBe(0x5)
|
|
expect(h.nibblet(3)).toBe(0x9)
|
|
expect(h.nibblet(4)).toBe(0x0b)
|
|
expect(h.nibblet(5)).toBe(0xd)
|
|
})
|
|
})
|
|
|
|
describe('Currency', function () {
|
|
test('Will have a null iso() for dodgy XRP ', function () {
|
|
const bad = Currency.from('0000000000000000000000005852500000000000')
|
|
expect(bad.iso()).toBeNull()
|
|
expect(bad.isNative()).toBe(false)
|
|
})
|
|
test('can be constructed from an Array', function () {
|
|
const xrp = Currency.from(new Uint8Array(20))
|
|
expect(xrp.iso()).toBe('XRP')
|
|
})
|
|
test('throws on invalid reprs', function () {
|
|
expect(() => Currency.from(new Uint8Array(19))).toThrow()
|
|
expect(() => Currency.from(1)).toThrow()
|
|
expect(() => Currency.from(
|
|
'00000000000000000000000000000000000000m')).toThrow()
|
|
})
|
|
})
|