Commit 3abd4db4 authored by Cédric Moreau's avatar Cédric Moreau

NodeCoin can now be installed via NPM and run (with no HTTP API implementation)

parent 3e4bc704
#!/usr/bin/env node
var config = require('../config'),
http = require('http'),
nodecoin = require('../lib/nodecoin'),
program = require('commander');
program
.version('0.0.1')
.option('-p, --port <port>', 'Port to listen for requests', parseInt)
.parse(process.argv);
config.server.port = program.port || config.server.port;
var app = nodecoin.express.app(config);
http.createServer(app).listen(app.get('port'), function(){
console.log('NodeCoin server listening on port ' + app.get('port'));
});
\ No newline at end of file
/**
This file is for development purposes only.
*/
var config = require('../config'),
http = require('http'),
nodecoin = require('../lib/nodecoin');
var app = nodecoin.express.app(config);
http.createServer(app).listen(app.get('port'), function(){
console.log('NodeCoin server listening on port ' + app.get('port'));
});
exports.server = {
port : 8081
};
function emptyArray(){
return [];
}
module.exports = emptyArray;
\ No newline at end of file
var pks = require('./pks'),
udc = require('./udc'),
express = require('express'),
path = require('path'),
nodecoin = require('../lib/nodecoin');
// orm = require('orm');
module.exports.pks = pks;
module.exports.udc = udc;
module.exports.express = {
route: function(app){
function notImplemented (req, res) {
res.writeHead(501);
res.end();
}
app.get( '/pks/lookup', notImplemented);
app.post( '/pks/add', notImplemented);
app.post( '/udc/amendments/submit', notImplemented);
app.get( '/udc/amendments/view/:amendment_id/members', notImplemented);
app.get( '/udc/amendments/view/:amendment_id/self', notImplemented);
app.get( '/udc/amendments/view/:amendment_id/voters', notImplemented);
app.post( '/udc/coins/submit', notImplemented);
app.get( '/udc/coins/view/:coin_id', notImplemented);
app.get( '/udc/peer/list', notImplemented);
app.post( '/udc/peer/register', notImplemented);
app.get( '/udc/peer/self', notImplemented);
app.get( '/udc/transactions/coin/:coin_id', notImplemented);
app.get( '/udc/transactions/recipient/:fingerprint', notImplemented);
app.get( '/udc/transactions/search', notImplemented);
app.get( '/udc/transactions/sender/:fingerprint', notImplemented);
app.post( '/udc/transactions/submit', notImplemented);
app.get( '/udc/transactions/view/:transaction_id', notImplemented);
},
app: function (someConfig) {
var app = express();
var config = someConfig || {
server: { port: 8001 },
db: "somedb"
};
// all environments
app.set('port', process.env.PORT || config.server.port);
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(express.session());
app.use(app.router);
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
this.route(app);
return app;
}
};
\ No newline at end of file
module.exports = {
lookup: function (req, res) {
},
add: function (req, res) {
}
};
\ No newline at end of file
module.exports = {};
\ No newline at end of file
......@@ -2,7 +2,7 @@
"name": "nodecoin",
"version": "0.0.1",
"description": "OpenUDC-like implementation using Node.js",
"main": "lib/main.js",
"main": "lib/nodecoin.js",
"directories": {
"test": "test"
},
......@@ -24,8 +24,17 @@
"bugs": {
"url": "https://github.com/c-geek/nodecoin/issues"
},
"dependencies": {
"express": "",
"commander": ""
},
"devDependencies": {
"mocha": "",
"should": ""
"should": "",
"supertest": ""
},
"private": true,
"bin": {
"nodecoin": "./bin/nodecoin"
}
}
var should = require('should');
var emptyArray = require('../lib/main');
describe('emptyArray', function () {
describe('with no arguments', function () {
it('returns an empty array', function () {
var result = emptyArray();
result.should.eql([]);
});
});
var request = require('supertest');
var nodecoin = require('../lib/nodecoin');
var app = nodecoin.express.app();
//----------- PKS -----------
describe('Request on /pks/lookup', function(){
it('GET should respond 501', function(done){
request(app)
.get('/pks/lookup')
.expect(501, done);
});
it('POST should respond 404', function(done){
request(app)
.post('/pks/lookup')
.expect(404, done);
});
});
describe('Request on /pks/add', function(){
it('POST should respond 501', function(done){
request(app)
.post('/pks/add')
.expect(501, done);
});
it('GET should respond 404', function(done){
request(app)
.get('/pks/add')
.expect(404, done);
});
});
//----------- AMENDMENTS -----------
describe('Request on /udc/amendments/view/:amendment_id/members', function(){
it('GET should respond 501', function(done){
request(app)
.get('/udc/amendments/view/1/members')
.expect(501, done);
});
});
describe('Request on /udc/amendments/view/:amendment_id/voters', function(){
it('GET should respond 501', function(done){
request(app)
.get('/udc/amendments/view/1/voters')
.expect(501, done);
});
});
describe('Request on /udc/amendments/view/:amendment_id/self', function(){
it('GET should respond 501', function(done){
request(app)
.get('/udc/amendments/view/1/self')
.expect(501, done);
});
});
describe('Request on /udc/amendments/submit', function(){
it('POST should respond 501', function(done){
request(app)
.post('/udc/amendments/submit')
.expect(501, done);
});
});
//----------- COINS -----------
describe('Request on /udc/coins/submit', function(){
it('POST should respond 501', function(done){
request(app)
.post('/udc/coins/submit')
.expect(501, done);
});
});
describe('Request on /udc/coins/view/:coin_id', function(){
it('GET should respond 501', function(done){
request(app)
.get('/udc/coins/view/2')
.expect(501, done);
});
});
//----------- PEER -----------
describe('Request on /udc/peer/register', function(){
it('POST should respond 501', function(done){
request(app)
.post('/udc/peer/register')
.expect(501, done);
});
});
describe('Request on /udc/peer/list', function(){
it('GET should respond 501', function(done){
request(app)
.get('/udc/peer/list')
.expect(501, done);
});
});
describe('Request on /udc/peer/self', function(){
it('GET should respond 501', function(done){
request(app)
.get('/udc/peer/self')
.expect(501, done);
});
});
//----------- TRANSACTIONS -----------
describe('Request on /udc/transactions/submit', function(){
it('POST should respond 501', function(done){
request(app)
.post('/udc/transactions/submit')
.expect(501, done);
});
});
describe('Request on /udc/transactions/search', function(){
it('GET should respond 501', function(done){
request(app)
.get('/udc/transactions/search')
.expect(501, done);
});
});
describe('Request on /udc/transactions/coin/:coin_id', function(){
it('GET should respond 501', function(done){
request(app)
.get('/udc/transactions/coin/2')
.expect(501, done);
});
});
describe('Request on /udc/transactions/recipient/:fingerprint', function(){
it('GET should respond 501', function(done){
request(app)
.get('/udc/transactions/recipient/RECIPIENT_FPR')
.expect(501, done);
});
});
describe('Request on /udc/transactions/sender/:fingerprint', function(){
it('GET should respond 501', function(done){
request(app)
.get('/udc/transactions/sender/SENDER_FPR')
.expect(501, done);
});
});
describe('Request on /udc/transactions/view/:transaction_id', function(){
it('GET should respond 501', function(done){
request(app)
.get('/udc/transactions/view/TX_ID')
.expect(501, done);
});
});
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment