mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Use encode/decode
This commit is contained in:
@@ -4,12 +4,12 @@ const assert = require('assert');
|
|||||||
const coreTypes = require('@niq/ripple-core-types');
|
const coreTypes = require('@niq/ripple-core-types');
|
||||||
const {binary: {bytesToHex, binaryToJSON, serializeObject}} = coreTypes;
|
const {binary: {bytesToHex, binaryToJSON, serializeObject}} = coreTypes;
|
||||||
|
|
||||||
exports.binaryToJSON = function(binary) {
|
exports.decode = function(binary) {
|
||||||
assert(typeof binary === 'string');
|
assert(typeof binary === 'string');
|
||||||
return binaryToJSON(binary);
|
return binaryToJSON(binary);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.jsonToBinary = function (json) {
|
exports.encode = function(json) {
|
||||||
assert(typeof json === 'object');
|
assert(typeof json === 'object');
|
||||||
return bytesToHex(serializeObject(json));
|
return bytesToHex(serializeObject(json));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const fixtures = require('./fixtures/codec-fixtures.json');
|
const fixtures = require('./fixtures/codec-fixtures.json');
|
||||||
const {binaryToJSON, jsonToBinary} = require('../src');
|
const {decode, encode} = require('../src');
|
||||||
|
|
||||||
function json(object) {
|
function json(object) {
|
||||||
return JSON.stringify(object);
|
return JSON.stringify(object);
|
||||||
@@ -14,11 +14,11 @@ describe('ripple-binary-codec', function() {
|
|||||||
entries.forEach((t, test_n) => {
|
entries.forEach((t, test_n) => {
|
||||||
it(`${name}[${test_n}] can encode ${json(t.json)} to ${t.binary}`,
|
it(`${name}[${test_n}] can encode ${json(t.json)} to ${t.binary}`,
|
||||||
() => {
|
() => {
|
||||||
assert.equal(t.binary, jsonToBinary(t.json));
|
assert.equal(t.binary, encode(t.json));
|
||||||
});
|
});
|
||||||
it(`${name}[${test_n}] can decode ${t.binary} to ${json(t.json)}`,
|
it(`${name}[${test_n}] can decode ${t.binary} to ${json(t.json)}`,
|
||||||
() => {
|
() => {
|
||||||
const decoded = binaryToJSON(t.binary);
|
const decoded = decode(t.binary);
|
||||||
assert.deepEqual(t.json, decoded);
|
assert.deepEqual(t.json, decoded);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user