Merge pull request #581 from clark800/binary-codec

Decouple UInt from non-serialization code
This commit is contained in:
Chris Clark
2015-10-05 16:39:17 -07:00
15 changed files with 217 additions and 158 deletions

View File

@@ -2,8 +2,6 @@
'use strict';
const assert = require('assert');
const Amount = require('ripple-lib').Amount;
const UInt160 = require('ripple-lib').UInt160;
describe('Amount', function() {
describe('Negatives', function() {
@@ -292,26 +290,6 @@ describe('Amount', function() {
assert.strictEqual('1', Amount.json_rewrite(1));
});
});
describe('UInt160', function() {
it('Parse 0 export', function() {
assert.strictEqual(UInt160.ACCOUNT_ZERO, UInt160.from_generic('0').set_version(0).to_json());
});
it('Parse 1', function() {
assert.deepEqual(UInt160.ACCOUNT_ONE, UInt160.from_generic('1').set_version(0).to_json());
});
it('Parse rrrrrrrrrrrrrrrrrrrrrhoLvTp export', function() {
assert.strictEqual(UInt160.ACCOUNT_ZERO, UInt160.from_json('rrrrrrrrrrrrrrrrrrrrrhoLvTp').to_json());
});
it('Parse rrrrrrrrrrrrrrrrrrrrBZbvji export', function() {
assert.strictEqual(UInt160.ACCOUNT_ONE, UInt160.from_json('rrrrrrrrrrrrrrrrrrrrBZbvji').to_json());
});
it('is_valid rrrrrrrrrrrrrrrrrrrrrhoLvTp', function() {
assert(UInt160.is_valid('rrrrrrrrrrrrrrrrrrrrrhoLvTp'));
});
it('!is_valid rrrrrrrrrrrrrrrrrrrrrhoLvT', function() {
assert(!UInt160.is_valid('rrrrrrrrrrrrrrrrrrrrrhoLvT'));
});
});
describe('Amount validity', function() {
it('is_valid 1', function() {
assert(Amount.is_valid(1));

View File

@@ -3,5 +3,5 @@
"title": "ledgerhash",
"description": "A ledger hash",
"type": "string",
"format": "ledgerHash"
"pattern": "^[A-F0-9]{64}$"
}

View File

@@ -4,15 +4,14 @@
const assert = require('assert-diff');
const lodash = require('lodash');
const ripple = require('ripple-lib');
const Remote = require('ripple-lib').Remote;
const Server = require('ripple-lib').Server;
const Transaction = require('ripple-lib').Transaction;
const UInt160 = require('ripple-lib').UInt160;
const Currency = require('ripple-lib').Currency;
const Amount = require('ripple-lib').Amount;
const PathFind = require('ripple-lib')._test.PathFind;
const Log = require('ripple-lib')._test.Log;
const ACCOUNT_ONE = require('ripple-lib')._test.constants.ACCOUNT_ONE;
let options;
let remote;
@@ -30,7 +29,7 @@ const TX_JSON = {
Flags: 0,
TransactionType: 'Payment',
Account: ADDRESS,
Destination: ripple.UInt160.ACCOUNT_ONE,
Destination: ACCOUNT_ONE,
Amount: {
value: '1',
currency: 'USD',
@@ -1492,7 +1491,7 @@ describe('Remote', function() {
it('Construct account_tx request', function() {
let request = remote.requestAccountTransactions({
account: UInt160.ACCOUNT_ONE,
account: ACCOUNT_ONE,
ledger_index_min: -1,
ledger_index_max: -1,
limit: 5,
@@ -1503,7 +1502,7 @@ describe('Remote', function() {
assert.deepEqual(request.message, {
command: 'account_tx',
id: undefined,
account: UInt160.ACCOUNT_ONE,
account: ACCOUNT_ONE,
ledger_index_min: -1,
ledger_index_max: -1,
binary: true,
@@ -1513,14 +1512,14 @@ describe('Remote', function() {
});
request = remote.requestAccountTransactions({
account: UInt160.ACCOUNT_ONE,
account: ACCOUNT_ONE,
min_ledger: -1,
max_ledger: -1
});
assert.deepEqual(request.message, {
command: 'account_tx',
id: undefined,
account: UInt160.ACCOUNT_ONE,
account: ACCOUNT_ONE,
binary: true,
ledger_index_min: -1,
ledger_index_max: -1
@@ -1528,7 +1527,7 @@ describe('Remote', function() {
});
it('Construct account_tx request -- no binary', function() {
const request = remote.requestAccountTransactions({
account: UInt160.ACCOUNT_ONE,
account: ACCOUNT_ONE,
ledger_index_min: -1,
ledger_index_max: -1,
limit: 5,
@@ -1540,7 +1539,7 @@ describe('Remote', function() {
assert.deepEqual(request.message, {
command: 'account_tx',
id: undefined,
account: UInt160.ACCOUNT_ONE,
account: ACCOUNT_ONE,
ledger_index_min: -1,
ledger_index_max: -1,
binary: false,
@@ -1618,7 +1617,7 @@ describe('Remote', function() {
taker_pays: {
currency: Currency.from_human('XRP').to_hex()
},
taker: UInt160.ACCOUNT_ONE
taker: ACCOUNT_ONE
});
});
@@ -1645,7 +1644,7 @@ describe('Remote', function() {
taker_pays: {
currency: Currency.from_human('XRP').to_hex()
},
taker: UInt160.ACCOUNT_ONE,
taker: ACCOUNT_ONE,
ledger_hash: LEDGER_HASH,
limit: 10
});

View File

@@ -10,6 +10,7 @@ const Transaction = require('ripple-lib').Transaction;
const TransactionQueue = require('ripple-lib').TransactionQueue;
const Remote = require('ripple-lib').Remote;
const Server = require('ripple-lib').Server;
const {decodeAddress} = require('ripple-address-codec');
const transactionResult = {
engine_result: 'tesSUCCESS',
@@ -2257,7 +2258,7 @@ describe('Transaction', function() {
const tbytes = ripple.SerializedObject.from_json(
lodash.merge(transaction.tx_json, {SigningPubKey: ''})).buffer;
const abytes = ripple.UInt160.from_json(a1).to_bytes();
const abytes = decodeAddress(a1);
const prefix = require('ripple-lib')._test.HashPrefixes.HASH_TX_MULTISIGN_BYTES;
assert.deepEqual(d1.buffer, prefix.concat(tbytes, abytes));

View File

@@ -4,8 +4,9 @@
const _ = require('lodash');
const assert = require('assert-diff');
const lodash = require('lodash');
const ripple = require('ripple-lib');
const ripple = require('ripple-lib')._test;
const fixtures = require('./fixtures/uint');
const UInt160 = ripple.UInt160;
function resultError(test, result) {
function type(e) {
@@ -101,4 +102,25 @@ function makeTests(uIntType) {
});
}
describe('UInt160', function() {
it('Parse 0 export', function() {
assert.strictEqual(UInt160.ACCOUNT_ZERO, UInt160.from_generic('0').set_version(0).to_json());
});
it('Parse 1', function() {
assert.deepEqual(UInt160.ACCOUNT_ONE, UInt160.from_generic('1').set_version(0).to_json());
});
it('Parse rrrrrrrrrrrrrrrrrrrrrhoLvTp export', function() {
assert.strictEqual(UInt160.ACCOUNT_ZERO, UInt160.from_json('rrrrrrrrrrrrrrrrrrrrrhoLvTp').to_json());
});
it('Parse rrrrrrrrrrrrrrrrrrrrBZbvji export', function() {
assert.strictEqual(UInt160.ACCOUNT_ONE, UInt160.from_json('rrrrrrrrrrrrrrrrrrrrBZbvji').to_json());
});
it('is_valid rrrrrrrrrrrrrrrrrrrrrhoLvTp', function() {
assert(UInt160.is_valid('rrrrrrrrrrrrrrrrrrrrrhoLvTp'));
});
it('!is_valid rrrrrrrrrrrrrrrrrrrrrhoLvT', function() {
assert(!UInt160.is_valid('rrrrrrrrrrrrrrrrrrrrrhoLvT'));
});
});
['UInt128', 'UInt160', 'UInt256'].forEach(makeTests);