mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 04:35:49 +00:00
cover api/common/validate.js with tests
This commit is contained in:
@@ -16,9 +16,7 @@ function validateAddressAndSecret(obj) {
|
||||
throw error('Parameter missing: secret');
|
||||
}
|
||||
try {
|
||||
if (!core.Seed.from_json(secret).get_key(address)) {
|
||||
throw error('secret does not match address');
|
||||
}
|
||||
core.Seed.from_json(secret).get_key(address);
|
||||
} catch (exception) {
|
||||
throw error('secret does not match address');
|
||||
}
|
||||
|
||||
@@ -629,7 +629,25 @@ describe('RippleAPI', function() {
|
||||
|
||||
});
|
||||
|
||||
it('validator', function() {
|
||||
describe('validator', function() {
|
||||
|
||||
it('validateLedgerRange', function() {
|
||||
const options = {
|
||||
minLedgerVersion: 20000,
|
||||
maxLedgerVersion: 10000
|
||||
};
|
||||
assert.throws(_.partial(validate.getTransactionsOptions, options),
|
||||
this.api.errors.ValidationError);
|
||||
assert.throws(_.partial(validate.getTransactionsOptions, options),
|
||||
/minLedgerVersion must not be greater than maxLedgerVersion/);
|
||||
});
|
||||
|
||||
it('addressAndSecret', function() {
|
||||
const wrongSecret = {address: address,
|
||||
secret: 'shzjfakiK79YQdMjy4h8cGGfQSV6u'
|
||||
};
|
||||
assert.throws(_.partial(validate.addressAndSecret, wrongSecret),
|
||||
this.api.errors.ValidationError);
|
||||
const noSecret = {address: address};
|
||||
assert.throws(_.partial(validate.addressAndSecret, noSecret),
|
||||
this.api.errors.ValidationError);
|
||||
@@ -644,6 +662,9 @@ describe('RippleAPI', function() {
|
||||
secret: 'shzjfakiK79YQdMjy4h8cGGfQSV6u'
|
||||
};
|
||||
assert.doesNotThrow(_.partial(validate.addressAndSecret, goodWallet));
|
||||
});
|
||||
|
||||
it('secret', function() {
|
||||
assert.doesNotThrow(_.partial(validate.secret,
|
||||
'shzjfakiK79YQdMjy4h8cGGfQSV6u'));
|
||||
assert.throws(_.partial(validate.secret, 1),
|
||||
@@ -661,3 +682,5 @@ describe('RippleAPI', function() {
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user