Skip to content

Commit

Permalink
Improves integration test.
Browse files Browse the repository at this point in the history
  • Loading branch information
conradoqg committed Apr 30, 2017
1 parent d087aef commit fedc3ee
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Expand Up @@ -4,7 +4,7 @@
"commonjs": true,
"es6": true,
"node": true,
"mocha": true
"mocha": true
},
"parserOptions": {
"ecmaFeatures": {
Expand All @@ -13,6 +13,7 @@
"sourceType": "module"
},
"globals": {
"step": true
},
"rules": {
"no-const-assign": "warn",
Expand Down
11 changes: 6 additions & 5 deletions package.json
Expand Up @@ -14,15 +14,15 @@
"scripts": {
"start": "node bin/naivecoin.js",
"compose:up": "docker-compose up",
"test": "node node_modules/mocha/bin/_mocha -u tdd --colors test/"
"test": "node node_modules/mocha/bin/_mocha -u bdd --colors test/"
},
"dependencies": {
"body-parser": "^1.17.1",
"cli-color": "^1.2.0",
"elliptic": "^6.4.0",
"es6-error": "^4.0.2",
"express": "~4.11.1",
"fs-extra": "^2.1.2",
"fs-extra": "^2.1.2",
"ramda": "^0.23.0",
"statuses": "^1.3.1",
"superagent": "^3.5.2",
Expand All @@ -34,8 +34,9 @@
"engines": {
"node": ">=6"
},
"devDependencies": {
"supertest": "^1.0.0",
"mocha": "^3.3.0"
"devDependencies": {
"mocha": "^3.3.0",
"mocha-steps": "^1.0.2",
"supertest": "^1.0.0"
}
}
83 changes: 57 additions & 26 deletions test/integrationTest.js
@@ -1,3 +1,4 @@
require('mocha-steps');
const supertest = require('supertest');
const assert = require('assert');
const HttpServer = require('../lib/httpServer');
Expand All @@ -10,54 +11,66 @@ const fs = require('fs-extra');
const name = 'integrationTest';
require('../lib/util/consoleWrapper.js')(name, 0);

describe('HTTP server', () => {
it('should create wallet, address, mine, create transaction and mine again', () => {

fs.removeSync('data/' + name + '/');
describe('Integration Test', () => {
fs.removeSync('data/' + name + '/');

let blockchain = new Blockchain(name);
let operator = new Operator(name, blockchain);
let miner = new Miner(blockchain, 0);
let node = new Node('localhost', 3001, [], blockchain);
let httpServer = new HttpServer(node, blockchain, operator, miner);
let blockchain = new Blockchain(name);
let operator = new Operator(name, blockchain);
let miner = new Miner(blockchain, 0);
let node = new Node('localhost', 3001, [], blockchain);
let httpServer = new HttpServer(node, blockchain, operator, miner);

let context = {};
const walletPassword = 't t t t t';
const walletPassword = 't t t t t';
let context = {};

step('create wallet', () => {
return Promise.resolve()
.then(() => {
return supertest(httpServer.app)
.post('/operator/wallets')
.send({ password: walletPassword })
.expect(201);
})
.then((res) => {
}).then((res) => {
context.walletId = res.body.id;
});
});

step('create address 1', () => {
return Promise.resolve()
.then(() => {
return supertest(httpServer.app)
.post(`/operator/wallets/${context.walletId}/addresses`)
.set({ password: walletPassword })
.expect(201);
})
.then((res) => {
}).then((res) => {
context.address1 = res.text;
});
});

step('create address 2', () => {
return Promise.resolve()
.then(() => {
return supertest(httpServer.app)
.post(`/operator/wallets/${context.walletId}/addresses`)
.set({ password: walletPassword })
.expect(201);
})
.then((res) => {
}).then((res) => {
context.address2 = res.text;
return supertest(httpServer.app)
.post(`/operator/wallets/${context.walletId}/addresses`)
.set({ password: walletPassword })
.expect(201);
})
});
});

step('mine an empty block', () => {
return Promise.resolve()
.then(() => {
return supertest(httpServer.app)
.post('/miner/mine')
.send({ rewardAddress: context.address1 })
.expect(201);
})
});
});

step('create a transaction', () => {
return Promise.resolve()
.then(() => {
return supertest(httpServer.app)
.post(`/operator/wallets/${context.walletId}/transactions`)
Expand All @@ -72,27 +85,45 @@ describe('HTTP server', () => {
})
.then((res) => {
context.transactionId = res.body.id;
});
});

step('mine a block with transactions', () => {
return Promise.resolve()
.then(() => {
return supertest(httpServer.app)
.post('/miner/mine')
.send({ rewardAddress: context.address1 })
.expect(201);
})
});
});

step('check confirmations for the created transaction', () => {
return Promise.resolve()
.then(() => {
return supertest(httpServer.app)
.get(`/node/transactions/${context.transactionId}/confirmations`)
.expect(200)
.expect((res) => {
assert(res.text == 1);
});
})
});
});

step('check address 1 balance', () => {
return Promise.resolve()
.then(() => {
return supertest(httpServer.app)
.get(`/operator/wallets/${context.walletId}/addresses/${context.address1}/balance`)
.expect(200)
.expect((res) => {
assert(res.text == 9000000000);
});
})
});
});

step('check address 2 balance', () => {
return Promise.resolve()
.then(() => {
return supertest(httpServer.app)
.get(`/operator/wallets/${context.walletId}/addresses/${context.address2}/balance`)
Expand Down

0 comments on commit fedc3ee

Please sign in to comment.