bitmessage-js/tests/functional.js

71 lines
1.9 KiB
JavaScript
Raw Normal View History

2015-02-05 19:55:36 +00:00
var expect = require("chai").expect;
2015-02-02 15:30:05 +00:00
var bitmessage = require("../lib");
var structs = bitmessage.structs;
var message = structs.message;
2015-02-06 09:47:40 +00:00
var WsTransport = require("../lib/net/ws");
2015-02-02 15:30:05 +00:00
2015-02-05 18:38:36 +00:00
var TcpTransport, tcp;
2015-02-02 15:30:05 +00:00
if (!process.browser) {
2015-02-06 09:47:40 +00:00
TcpTransport = require("../lib/net/tcp");
2015-02-02 15:30:05 +00:00
describe("TCP transport", function() {
2015-02-05 18:38:36 +00:00
before(function(done) {
tcp = new TcpTransport();
tcp.on("error", function(err) {
console.log("TCP transport error:", err);
});
// Wait some time for server.
setTimeout(done, 1000);
});
2015-02-05 19:55:36 +00:00
it("should return nothing on bootstrap by default", function() {
return tcp.bootstrap().then(function(nodes) {
expect(nodes).to.be.empty;
});
});
it("should resolve DNS seeds on bootstrap", function() {
var tcp2 = new TcpTransport({
dnsSeeds: [["bootstrap8444.bitmessage.org", 8444]],
});
return tcp2.bootstrap().then(function(nodes) {
expect(nodes).to.be.not.empty;
expect(nodes[0][1]).to.be.equal(8444);
});
});
it("should return hardcoded seeds on bootstrap", function() {
var tcp3 = new TcpTransport({
seeds: [["1.1.1.1", 8080]],
dnsSeeds: [["bootstrap8444.bitmessage.org", 8444]],
});
return tcp3.bootstrap().then(function(nodes) {
expect(nodes).to.have.length.at.least(2);
expect(nodes[0][1]).to.be.equal(8444);
expect(nodes[nodes.length - 1][0]).to.equal("1.1.1.1");
expect(nodes[nodes.length - 1][1]).to.equal(8080);
});
});
2015-02-05 18:38:36 +00:00
it("should allow to interconnect two nodes", function(done) {
tcp.connect(22333, "127.0.0.1");
tcp.on("open", function() {
done();
});
});
it("should allow to close connection", function(done) {
tcp.close();
tcp.on("close", function() {
done();
});
});
2015-02-02 15:30:05 +00:00
});
}
describe("WebSocket transport", function() {
it("should allow to communicate between two nodes");
});