test mailboxes and RPCs from the command line, fix some minor errors

This commit is contained in:
ansuz
2019-09-06 13:35:36 +02:00
parent 75b655e1e8
commit dc078c1ca1
6 changed files with 246 additions and 98 deletions

View File

@@ -3,19 +3,9 @@ var WebSocket = require("ws"); // jshint ignore:line
var nThen = require("nthen");
var Util = require("../../www/common/common-util");
var Rpc = require("../../www/common/rpc");
var Nacl = require("tweetnacl");
var makeKeys = function () {
var keys = Nacl.sign.keyPair.fromSeed(Nacl.randomBytes(Nacl.sign.seedLength));
return {
secret: Nacl.util.encodeBase64(keys.secretKey),
public: Nacl.util.encodeBase64(keys.publicKey),
};
};
var Client = module.exports;
var createNetwork = Client.createNetwork = function (url, cb) {
@@ -30,8 +20,7 @@ var createNetwork = Client.createNetwork = function (url, cb) {
.on('error', function (err) {
CB(err);
})
.on('close', function (err) {
console.log("CLOSE_ERROR", err);
.on('close', function (/* err */) {
delete info.websocket;
});
return info.websocket;
@@ -102,21 +91,6 @@ Client.create = function (config, cb) {
w.abort();
CB(err);
});
}).nThen(function (w) {
// connect to the anonRpc
Rpc.createAnonymous(config.network, w(function (err, rpc) {
if (err) {
return void CB('ANON_RPC_CONNECT_ERR');
}
client.anonRpc = rpc;
}));
var keys = makeKeys();
Rpc.create(config.network, keys.secret, keys.public, w(function (err, rpc) {
if (err) {
return void CB('RPC_CONNECT_ERR');
}
client.rpc = rpc;
}));
}).nThen(function () {
CB(void 0, client);
});