mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-27 07:35:52 +00:00
Add test case for createPathFind and convert snake case function calls to camel case
This commit is contained in:
@@ -68,7 +68,7 @@ function Account(remote, account) {
|
|||||||
|
|
||||||
function attachAccount(request) {
|
function attachAccount(request) {
|
||||||
if (self._account.is_valid() && self._subs) {
|
if (self._account.is_valid() && self._subs) {
|
||||||
request.add_account(self._account_id);
|
request.addAccount(self._account_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ util.inherits(PathFind, EventEmitter);
|
|||||||
PathFind.prototype.create = function () {
|
PathFind.prototype.create = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var req = this.remote.request_path_find_create(
|
var req = this.remote.requestPathFindCreate(
|
||||||
this.src_account,
|
this.src_account,
|
||||||
this.dst_account,
|
this.dst_account,
|
||||||
this.dst_amount,
|
this.dst_amount,
|
||||||
|
|||||||
@@ -469,7 +469,7 @@ Remote.prototype.disconnect = function(callback_) {
|
|||||||
server.disconnect();
|
server.disconnect();
|
||||||
});
|
});
|
||||||
|
|
||||||
this._set_state('offline');
|
this._setState('offline');
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
@@ -744,20 +744,18 @@ Remote.prototype.getServer = function() {
|
|||||||
* @param {Request} request
|
* @param {Request} request
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Remote.prototype.request = function(request_) {
|
Remote.prototype.request = function(request) {
|
||||||
let request = request_;
|
|
||||||
|
|
||||||
if (typeof request === 'string') {
|
if (typeof request === 'string') {
|
||||||
if (!/^request_/.test(request)) {
|
const prefix = /^request_/.test(request) ? '' : 'request_';
|
||||||
request = 'request_' + request;
|
const requestName = prefix + request;
|
||||||
}
|
const methodName = requestName.replace(/(\_\w)/g, m => m[1].toUpperCase());
|
||||||
|
|
||||||
if (typeof this[request] === 'function') {
|
if (typeof this[methodName] === 'function') {
|
||||||
const args = _.slice(arguments, 1);
|
const args = _.slice(arguments, 1);
|
||||||
return this[request].apply(this, args);
|
return this[methodName].apply(this, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('Command does not exist: ' + request);
|
throw new Error('Command does not exist: ' + requestName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(request instanceof Request)) {
|
if (!(request instanceof Request)) {
|
||||||
|
|||||||
@@ -524,7 +524,7 @@ TransactionManager.prototype._prepareRequest = function(tx) {
|
|||||||
tx.sign();
|
tx.sign();
|
||||||
|
|
||||||
const serialized = tx.serialize();
|
const serialized = tx.serialize();
|
||||||
submitRequest.tx_blob(serialized.to_hex());
|
submitRequest.txBlob(serialized.to_hex());
|
||||||
|
|
||||||
const hash = tx.hash(null, null, serialized);
|
const hash = tx.hash(null, null, serialized);
|
||||||
tx.addId(hash);
|
tx.addId(hash);
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ const TX_JSON = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function makeServer(url) {
|
||||||
|
const server = new Server(new process.EventEmitter(), url);
|
||||||
|
server._connected = true;
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
describe('Remote', function() {
|
describe('Remote', function() {
|
||||||
const initialLogEngine = Log.getEngine();
|
const initialLogEngine = Log.getEngine();
|
||||||
|
|
||||||
@@ -1941,6 +1947,27 @@ describe('Remote', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('createPathFind', function() {
|
||||||
|
const servers = [
|
||||||
|
makeServer('wss://localhost:5006'),
|
||||||
|
makeServer('wss://localhost:5007')
|
||||||
|
];
|
||||||
|
|
||||||
|
remote._servers = servers;
|
||||||
|
|
||||||
|
const pathfind = remote.createPathFind({
|
||||||
|
src_account: 'rGr9PjmVe7MqEXTSbd3njhgJc2s5vpHV54',
|
||||||
|
dst_account: 'rwxBjBC9fPzyQ9GgPZw6YYLNeRTSx5c2W6',
|
||||||
|
dst_amount: '1/USD/rGr9PjmVe7MqEXTSbd3njhgJc2s5vpHV54',
|
||||||
|
src_currencies: [{
|
||||||
|
currency: 'BTC', issuer: 'rwxBjBC9fPzyQ9GgPZw6YYLNeRTSx5c2W6'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: setup a mock server to provide a response
|
||||||
|
pathfind.on('update', message => console.log(message));
|
||||||
|
});
|
||||||
|
|
||||||
it('Construct path_find create request', function() {
|
it('Construct path_find create request', function() {
|
||||||
const request = remote.requestPathFindCreate({
|
const request = remote.requestPathFindCreate({
|
||||||
src_account: 'rGr9PjmVe7MqEXTSbd3njhgJc2s5vpHV54',
|
src_account: 'rGr9PjmVe7MqEXTSbd3njhgJc2s5vpHV54',
|
||||||
|
|||||||
@@ -345,7 +345,7 @@ describe('Transaction', function() {
|
|||||||
const dst = 'rGihwhaqU8g7ahwAvTq6iX5rvsfcbgZw6v';
|
const dst = 'rGihwhaqU8g7ahwAvTq6iX5rvsfcbgZw6v';
|
||||||
|
|
||||||
transaction.payment(src, dst, '100');
|
transaction.payment(src, dst, '100');
|
||||||
remote.set_secret(src, 'masterpassphrase');
|
remote.setSecret(src, 'masterpassphrase');
|
||||||
|
|
||||||
assert(transaction.complete());
|
assert(transaction.complete());
|
||||||
const json = transaction.serialize().to_json();
|
const json = transaction.serialize().to_json();
|
||||||
|
|||||||
Reference in New Issue
Block a user