mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Check unknown serialization fields
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user