Check unknown serialization fields

This commit is contained in:
wltsmrz
2015-05-20 18:09:02 -07:00
parent 65f7485497
commit 8596dcef21
3 changed files with 93 additions and 23 deletions

View File

@@ -12,6 +12,7 @@
/* eslint-disable quotes*/
var assert = require('assert');
var lodash = require('lodash');
var SerializedObject = require('ripple-lib').SerializedObject;
var Amount = require('ripple-lib').Amount;
var sjcl = require('ripple-lib').sjcl;
@@ -150,6 +151,52 @@ describe('Serialized object', function() {
assert.equal("DirectoryNode", output_json.LedgerEntryType);
});
it('checks for missing required fields', function() {
var input_json = {
TransactionType: 'Payment',
// no non required fields
Account: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS',
Amount: '274579388',
Destination: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS',
Fee: '15',
Sequence: 351,
SigningPubKey: '02'
};
Object.keys(input_json).slice(1).forEach(function(k) {
var bad_json = lodash.merge({}, input_json);
delete bad_json[k];
assert.strictEqual(bad_json[k], undefined);
assert.throws(function() {
SerializedObject.from_json(bad_json);
}, new RegExp('Payment is missing fields: \\["' + k + '"\\]'));
});
});
it('checks for unknown fields', function() {
var input_json = {
TransactionType: 'Payment',
// no non required fields
Account: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS',
Amount: '274579388',
Destination: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS',
Fee: '15',
Sequence: 351,
SigningPubKey: '02'
};
Object.keys(input_json).slice(1).forEach(function(k) {
var bad_json = lodash.merge({}, input_json);
bad_json[k + 'z'] = bad_json[k];
assert.throws(function() {
SerializedObject.from_json(bad_json);
}, new RegExp('Payment has unknown fields: \\["' + k + 'z"\\]'));
});
});
describe('Format validation', function() {
// Peercover actually had a problem submitting transactions without a `Fee`
// and rippled was only informing of "transaction is invalid"