Skip to content
Snippets Groups Projects
Commit 3902e66b authored by inso's avatar inso
Browse files

Merge branch 'dev' into sync_refactor

parents 4248aecb d9d46a82
Branches
Tags
No related merge requests found
...@@ -16,7 +16,9 @@ const Membership = require('../entity/membership'); ...@@ -16,7 +16,9 @@ const Membership = require('../entity/membership');
const Block = require('../entity/block'); const Block = require('../entity/block');
const Transaction = require('../entity/transaction'); const Transaction = require('../entity/transaction');
module.exports = (mainContext, prover) => new BlockGenerator(mainContext, prover); module.exports = (mainContext, prover) => {
return new BlockGenerator(mainContext, prover);
};
function BlockGenerator(mainContext, prover) { function BlockGenerator(mainContext, prover) {
......
...@@ -17,7 +17,7 @@ const AbstractService = require('./AbstractService'); ...@@ -17,7 +17,7 @@ const AbstractService = require('./AbstractService');
const CHECK_ALL_RULES = true; const CHECK_ALL_RULES = true;
module.exports = function() { module.exports = () => {
return new BlockchainService(); return new BlockchainService();
}; };
...@@ -291,8 +291,12 @@ function BlockchainService () { ...@@ -291,8 +291,12 @@ function BlockchainService () {
outdistanced = yield rules.HELPERS.isOver3Hops(pubkey, newLinks, someNewcomers, current, conf, dal); outdistanced = yield rules.HELPERS.isOver3Hops(pubkey, newLinks, someNewcomers, current, conf, dal);
// Expiration of current membershship // Expiration of current membershship
if (join.identity.currentMSN >= 0) { if (join.identity.currentMSN >= 0) {
if (join.identity.member) {
const msBlock = yield dal.getBlockOrNull(join.identity.currentMSN); const msBlock = yield dal.getBlockOrNull(join.identity.currentMSN);
expiresMS = Math.max(0, (msBlock.medianTime + conf.msValidity - currentTime)); expiresMS = Math.max(0, (msBlock.medianTime + conf.msValidity - currentTime));
} else {
expiresMS = 0;
}
} }
// Expiration of pending membership // Expiration of pending membership
const lastJoin = yield dal.lastJoinOfIdentity(idty.hash); const lastJoin = yield dal.lastJoinOfIdentity(idty.hash);
......
...@@ -10,7 +10,9 @@ const Revocation = require('../../app/lib/entity/revocation'); ...@@ -10,7 +10,9 @@ const Revocation = require('../../app/lib/entity/revocation');
const AbstractService = require('./AbstractService'); const AbstractService = require('./AbstractService');
const co = require('co'); const co = require('co');
module.exports = () => new IdentityService(); module.exports = () => {
return new IdentityService();
};
function IdentityService () { function IdentityService () {
......
...@@ -7,7 +7,9 @@ const constants = require('../lib/constants'); ...@@ -7,7 +7,9 @@ const constants = require('../lib/constants');
const Membership = require('../lib/entity/membership'); const Membership = require('../lib/entity/membership');
const AbstractService = require('./AbstractService'); const AbstractService = require('./AbstractService');
module.exports = () => new MembershipService(); module.exports = () => {
return new MembershipService();
};
function MembershipService () { function MembershipService () {
......
...@@ -7,7 +7,9 @@ const rules = require('../lib/rules'); ...@@ -7,7 +7,9 @@ const rules = require('../lib/rules');
const Transaction = require('../lib/entity/transaction'); const Transaction = require('../lib/entity/transaction');
const AbstractService = require('./AbstractService'); const AbstractService = require('./AbstractService');
module.exports = () => new TransactionService(); module.exports = () => {
return new TransactionService();
};
function TransactionService () { function TransactionService () {
......
...@@ -1348,7 +1348,8 @@ So if a transaction only carries amounts with the same `AmountBase`, no conversi ...@@ -1348,7 +1348,8 @@ So if a transaction only carries amounts with the same `AmountBase`, no conversi
* input_0 of value 45 with `AmountBase = 5` * input_0 of value 45 with `AmountBase = 5`
* input_1 of value 75 with `AmountBase = 5` * input_1 of value 75 with `AmountBase = 5`
* output_0 of value 12 with `AmountBase = 6` * input_2 of value 3 with `AmountBase = 6`
* output_0 of value 15 with `AmountBase = 6`
Then the output value has to be converted before being compared: Then the output value has to be converted before being compared:
...@@ -1358,25 +1359,32 @@ CommonBase = 5 ...@@ -1358,25 +1359,32 @@ CommonBase = 5
output_0(5) = output_0(6) x POW(10, 6 - 5) output_0(5) = output_0(6) x POW(10, 6 - 5)
output_0(5) = output_0(6) x POW(10, 1) output_0(5) = output_0(6) x POW(10, 1)
output_0(5) = output_0(6) x 10 output_0(5) = output_0(6) x 10
output_0(5) = 12 x 10 output_0(5) = 15 x 10
output_0(5) = 120 output_0(5) = 150
input_0(5) = input_0(5) input_0(5) = input_0(5)
input_0(5) = 45 input_0(5) = 45
input_1(5) = input_1(5) input_1(5) = input_1(5)
input_1(5) = 75 input_1(5) = 75
input_2(5) = input_2(6) x POW(10, 6 - 5)
input_2(5) = input_2(6) x POW(10, 1)
input_2(5) = input_2(6) x 10
input_2(5) = 3 x 10
input_2(5) = 30
``` ```
The equality of inputs and outputs is then verified because: The equality of inputs and outputs is then verified because:
``` ```
output_0(5) = 120 output_0(5) = 150
input_0(5) = 45 input_0(5) = 45
input_1(5) = 75 input_1(5) = 75
input_2(5) = 30
output_0(5) = input_0(5) + input_1(5) output_0(5) = input_0(5) + input_1(5) + input_2(5)
120 = 45 + 75 150 = 45 + 75 + 30
TRUE TRUE
``` ```
......
...@@ -184,11 +184,6 @@ function Server (dbConf, overrideConf) { ...@@ -184,11 +184,6 @@ function Server (dbConf, overrideConf) {
this.submitP = (obj, isInnerWrite) => Q.nbind(this.submit, this)(obj, isInnerWrite); this.submitP = (obj, isInnerWrite) => Q.nbind(this.submit, this)(obj, isInnerWrite);
this.readConfFile = () => co(function *() {
let dal = yield fileDAL.file(home);
return yield dal.loadConf();
});
this.initDAL = () => this.dal.init(); this.initDAL = () => this.dal.init();
this.start = () => co(function*(){ this.start = () => co(function*(){
......
"use strict";
const _ = require('underscore');
const co = require('co');
const should = require('should');
const duniter = require('../../index');
const bma = require('../../app/lib/streams/bma');
const user = require('./tools/user');
const constants = require('../../app/lib/constants');
const rp = require('request-promise');
const httpTest = require('./tools/http');
const commit = require('./tools/commit');
const expectAnswer = httpTest.expectAnswer;
const MEMORY_MODE = true;
const commonConf = {
ipv4: '127.0.0.1',
currency: 'bb',
httpLogs: true,
forksize: 3,
xpercent: 0.9,
sigValidity: 1600, // 1600 second of duration
msValidity: 3600, // 3600 second of duration
parcatipate: false, // TODO: to remove when startGeneration will be an explicit call
sigQty: 1
};
const s1 = duniter({
memory: MEMORY_MODE,
name: 'bb11'
}, _.extend({
port: '8561',
pair: {
pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd',
sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'
}
}, commonConf));
const cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 });
const tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 });
const toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 });
describe("Identities kicking", function() {
before(function() {
const commitS1 = commit(s1);
return co(function *() {
const now = Math.round(new Date().getTime() / 1000);
yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections());
yield cat.selfCert();
yield tac.selfCert();
yield cat.cert(tac);
yield tac.cert(cat);
yield cat.join();
yield tac.join();
yield commitS1({
time: now
});
yield commitS1({
time: now + 2000
});
yield commitS1({
time: now + 2000
});
// Update their membership
yield cat.join();
yield tac.join();
// toc joins thereafter
yield toc.selfCert();
yield toc.join();
yield cat.cert(toc);
yield tac.cert(toc);
yield toc.cert(cat);
yield commitS1({
time: now
});
yield commitS1({
time: now + 5000
});
yield commitS1({
time: now + 5000
});
yield commitS1({
time: now
});
});
});
/**
*
*/
it('membershipExpiresIn should be positive for cat (actualized member)', function() {
return expectAnswer(rp('http://127.0.0.1:8561/wot/requirements/HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', { json: true }), (res) => {
res.should.have.property('identities').length(1);
res.identities[0].should.have.property('pubkey').equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd');
res.identities[0].should.have.property('uid').equal('cat');
res.identities[0].should.have.property('expired').equal(false);
res.identities[0].should.have.property('membershipExpiresIn').equal(2045);
});
});
it('membershipExpiresIn should be positive for toc (member)', function() {
return expectAnswer(rp('http://127.0.0.1:8561/wot/requirements/DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', { json: true }), (res) => {
res.should.have.property('identities').length(1);
res.identities[0].should.have.property('pubkey').equal('DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo');
res.identities[0].should.have.property('uid').equal('toc');
res.identities[0].should.have.property('expired').equal(false);
res.identities[0].should.have.property('membershipExpiresIn').equal(2045);
});
});
it('membershipExpiresIn should equal 0 for a kicked member', function() {
return expectAnswer(rp('http://127.0.0.1:8561/wot/requirements/2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', { json: true }), (res) => {
res.should.have.property('identities').length(1);
res.identities[0].should.have.property('pubkey').equal('2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc');
res.identities[0].should.have.property('uid').equal('tac');
res.identities[0].should.have.property('expired').equal(false);
res.identities[0].should.have.property('membershipExpiresIn').equal(0);
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment