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');
|
throw error('Parameter missing: secret');
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (!core.Seed.from_json(secret).get_key(address)) {
|
core.Seed.from_json(secret).get_key(address);
|
||||||
throw error('secret does not match address');
|
|
||||||
}
|
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
throw error('secret does not match address');
|
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};
|
const noSecret = {address: address};
|
||||||
assert.throws(_.partial(validate.addressAndSecret, noSecret),
|
assert.throws(_.partial(validate.addressAndSecret, noSecret),
|
||||||
this.api.errors.ValidationError);
|
this.api.errors.ValidationError);
|
||||||
@@ -644,6 +662,9 @@ describe('RippleAPI', function() {
|
|||||||
secret: 'shzjfakiK79YQdMjy4h8cGGfQSV6u'
|
secret: 'shzjfakiK79YQdMjy4h8cGGfQSV6u'
|
||||||
};
|
};
|
||||||
assert.doesNotThrow(_.partial(validate.addressAndSecret, goodWallet));
|
assert.doesNotThrow(_.partial(validate.addressAndSecret, goodWallet));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('secret', function() {
|
||||||
assert.doesNotThrow(_.partial(validate.secret,
|
assert.doesNotThrow(_.partial(validate.secret,
|
||||||
'shzjfakiK79YQdMjy4h8cGGfQSV6u'));
|
'shzjfakiK79YQdMjy4h8cGGfQSV6u'));
|
||||||
assert.throws(_.partial(validate.secret, 1),
|
assert.throws(_.partial(validate.secret, 1),
|
||||||
@@ -660,4 +681,6 @@ describe('RippleAPI', function() {
|
|||||||
this.api.errors.ValidationError);
|
this.api.errors.ValidationError);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user