Use encode/decode

This commit is contained in:
Nicholas Dudfield
2015-10-01 06:55:23 +07:00
parent 65987a83fd
commit 8a49bec48b
2 changed files with 5 additions and 5 deletions

View File

@@ -4,12 +4,12 @@ const assert = require('assert');
const coreTypes = require('@niq/ripple-core-types');
const {binary: {bytesToHex, binaryToJSON, serializeObject}} = coreTypes;
exports.binaryToJSON = function(binary) {
exports.decode = function(binary) {
assert(typeof binary === 'string');
return binaryToJSON(binary);
};
exports.jsonToBinary = function (json) {
exports.encode = function(json) {
assert(typeof json === 'object');
return bytesToHex(serializeObject(json));
};

View File

@@ -2,7 +2,7 @@
const assert = require('assert');
const fixtures = require('./fixtures/codec-fixtures.json');
const {binaryToJSON, jsonToBinary} = require('../src');
const {decode, encode} = require('../src');
function json(object) {
return JSON.stringify(object);
@@ -14,11 +14,11 @@ describe('ripple-binary-codec', function() {
entries.forEach((t, test_n) => {
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)}`,
() => {
const decoded = binaryToJSON(t.binary);
const decoded = decode(t.binary);
assert.deepEqual(t.json, decoded);
});
});