mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 12:45:50 +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,35 +629,58 @@ describe('RippleAPI', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('validator', function() {
|
describe('validator', function() {
|
||||||
const noSecret = {address: address};
|
|
||||||
assert.throws(_.partial(validate.addressAndSecret, noSecret),
|
it('validateLedgerRange', function() {
|
||||||
this.api.errors.ValidationError);
|
const options = {
|
||||||
assert.throws(_.partial(validate.addressAndSecret, noSecret),
|
minLedgerVersion: 20000,
|
||||||
/Parameter missing/);
|
maxLedgerVersion: 10000
|
||||||
const badSecret = {address: address, secret: 'bad'};
|
};
|
||||||
assert.throws(_.partial(validate.addressAndSecret, badSecret),
|
assert.throws(_.partial(validate.getTransactionsOptions, options),
|
||||||
this.api.errors.ValidationError);
|
this.api.errors.ValidationError);
|
||||||
assert.throws(_.partial(validate.addressAndSecret, badSecret),
|
assert.throws(_.partial(validate.getTransactionsOptions, options),
|
||||||
/not match/);
|
/minLedgerVersion must not be greater than maxLedgerVersion/);
|
||||||
const goodWallet = {address: 'rpZMK8hwyrBvLorFNWHRCGt88nCJWbixur',
|
});
|
||||||
secret: 'shzjfakiK79YQdMjy4h8cGGfQSV6u'
|
|
||||||
};
|
it('addressAndSecret', function() {
|
||||||
assert.doesNotThrow(_.partial(validate.addressAndSecret, goodWallet));
|
const wrongSecret = {address: address,
|
||||||
assert.doesNotThrow(_.partial(validate.secret,
|
secret: 'shzjfakiK79YQdMjy4h8cGGfQSV6u'
|
||||||
'shzjfakiK79YQdMjy4h8cGGfQSV6u'));
|
};
|
||||||
assert.throws(_.partial(validate.secret, 1),
|
assert.throws(_.partial(validate.addressAndSecret, wrongSecret),
|
||||||
/Invalid parameter/);
|
this.api.errors.ValidationError);
|
||||||
assert.throws(_.partial(validate.secret, ''),
|
const noSecret = {address: address};
|
||||||
this.api.errors.ValidationError);
|
assert.throws(_.partial(validate.addressAndSecret, noSecret),
|
||||||
assert.throws(_.partial(validate.secret, 's!!!'),
|
this.api.errors.ValidationError);
|
||||||
this.api.errors.ValidationError);
|
assert.throws(_.partial(validate.addressAndSecret, noSecret),
|
||||||
assert.throws(_.partial(validate.secret, 'passphrase'),
|
/Parameter missing/);
|
||||||
this.api.errors.ValidationError);
|
const badSecret = {address: address, secret: 'bad'};
|
||||||
// 32 0s is a valid hex repr of seed bytes
|
assert.throws(_.partial(validate.addressAndSecret, badSecret),
|
||||||
const hex = new Array(33).join('0');
|
this.api.errors.ValidationError);
|
||||||
assert.throws(_.partial(validate.secret, hex),
|
assert.throws(_.partial(validate.addressAndSecret, badSecret),
|
||||||
this.api.errors.ValidationError);
|
/not match/);
|
||||||
|
const goodWallet = {address: 'rpZMK8hwyrBvLorFNWHRCGt88nCJWbixur',
|
||||||
|
secret: 'shzjfakiK79YQdMjy4h8cGGfQSV6u'
|
||||||
|
};
|
||||||
|
assert.doesNotThrow(_.partial(validate.addressAndSecret, goodWallet));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('secret', function() {
|
||||||
|
assert.doesNotThrow(_.partial(validate.secret,
|
||||||
|
'shzjfakiK79YQdMjy4h8cGGfQSV6u'));
|
||||||
|
assert.throws(_.partial(validate.secret, 1),
|
||||||
|
/Invalid parameter/);
|
||||||
|
assert.throws(_.partial(validate.secret, ''),
|
||||||
|
this.api.errors.ValidationError);
|
||||||
|
assert.throws(_.partial(validate.secret, 's!!!'),
|
||||||
|
this.api.errors.ValidationError);
|
||||||
|
assert.throws(_.partial(validate.secret, 'passphrase'),
|
||||||
|
this.api.errors.ValidationError);
|
||||||
|
// 32 0s is a valid hex repr of seed bytes
|
||||||
|
const hex = new Array(33).join('0');
|
||||||
|
assert.throws(_.partial(validate.secret, hex),
|
||||||
|
this.api.errors.ValidationError);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user