mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 20:55:48 +00:00
Initial change from Babel/JS to TypeScript (#70)
* 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(...)
This commit is contained in:
121
packages/ripple-binary-codec/test/tx-encode-decode.test.js
Normal file
121
packages/ripple-binary-codec/test/tx-encode-decode.test.js
Normal file
@@ -0,0 +1,121 @@
|
||||
const {
|
||||
encode,
|
||||
decode
|
||||
} = require('../dist')
|
||||
|
||||
// Notice: no Amount or Fee
|
||||
const tx_json = {
|
||||
Account: 'r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ',
|
||||
// Amount: '1000',
|
||||
Destination: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
|
||||
// Fee: '10',
|
||||
|
||||
// JavaScript converts operands to 32-bit signed ints after doing bitwise
|
||||
// operations. We need to convert it back to an unsigned int with >>> 0.
|
||||
Flags: ((1 << 31) >>> 0), // tfFullyCanonicalSig
|
||||
|
||||
Sequence: 1,
|
||||
TransactionType: 'Payment'
|
||||
// TxnSignature,
|
||||
// Signature,
|
||||
// SigningPubKey
|
||||
}
|
||||
|
||||
const amount_parameters_message = input => {
|
||||
// disables the ESLint rule on the whole rest of the file
|
||||
/* eslint-disable max-len */
|
||||
return `${input} is an illegal amount
|
||||
|
||||
Native values must be described in drops, a million of which equal one XRP.
|
||||
This must be an integer number, with the absolute value not exceeding 100000000000000000
|
||||
|
||||
IOU values must have a maximum precision of 16 significant digits. They are serialized as
|
||||
a canonicalised mantissa and exponent.
|
||||
|
||||
The valid range for a mantissa is between 1000000000000000 and 9999999999999999
|
||||
The exponent must be >= -96 and <= 80
|
||||
|
||||
Thus the largest serializable IOU value is:
|
||||
999999999999999900000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
|
||||
And the smallest:
|
||||
0.000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||
`
|
||||
}
|
||||
|
||||
describe('encoding and decoding tx_json', function () {
|
||||
test('can encode tx_json without Amount or Fee', function () {
|
||||
const encoded = encode(tx_json)
|
||||
const decoded = decode(encoded)
|
||||
expect(tx_json).toEqual(decoded)
|
||||
})
|
||||
test('can encode tx_json with Amount and Fee', function () {
|
||||
const my_tx = Object.assign({}, tx_json, {
|
||||
Amount: '1000',
|
||||
Fee: '10'
|
||||
})
|
||||
const encoded = encode(my_tx)
|
||||
const decoded = decode(encoded)
|
||||
expect(my_tx).toEqual(decoded)
|
||||
})
|
||||
test('throws when Amount is invalid', function () {
|
||||
const my_tx = Object.assign({}, tx_json, {
|
||||
Amount: '1000.001',
|
||||
Fee: '10'
|
||||
})
|
||||
expect(() => {
|
||||
encode(my_tx)
|
||||
}).toThrow({
|
||||
name: 'Error',
|
||||
message: amount_parameters_message('1000.001')
|
||||
})
|
||||
})
|
||||
test('throws when Fee is invalid', function () {
|
||||
const my_tx = Object.assign({}, tx_json, {
|
||||
Amount: '1000',
|
||||
Fee: '10.123'
|
||||
})
|
||||
expect(() => {
|
||||
encode(my_tx)
|
||||
}).toThrow({
|
||||
name: 'Error',
|
||||
message: amount_parameters_message('10.123')
|
||||
})
|
||||
})
|
||||
test('throws when Amount and Fee are invalid', function () {
|
||||
const my_tx = Object.assign({}, tx_json, {
|
||||
Amount: '1000.789',
|
||||
Fee: '10.123'
|
||||
})
|
||||
expect(() => {
|
||||
encode(my_tx)
|
||||
}).toThrow({
|
||||
name: 'Error',
|
||||
message: amount_parameters_message('1000.789')
|
||||
})
|
||||
})
|
||||
test('throws when Amount is a number instead of a string-encoded integer',
|
||||
function () {
|
||||
const my_tx = Object.assign({}, tx_json, {
|
||||
Amount: 1000.789
|
||||
})
|
||||
expect(() => {
|
||||
encode(my_tx)
|
||||
}).toThrow({
|
||||
name: 'Error',
|
||||
message: 'unsupported value: 1000.789'
|
||||
})
|
||||
})
|
||||
test('throws when Fee is a number instead of a string-encoded integer',
|
||||
function () {
|
||||
const my_tx = Object.assign({}, tx_json, {
|
||||
Amount: 1234.56
|
||||
})
|
||||
expect(() => {
|
||||
encode(my_tx)
|
||||
}).toThrow({
|
||||
name: 'Error',
|
||||
message: 'unsupported value: 1234.56'
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user