Skip to content
Snippets Groups Projects
Commit 5b6061c5 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

Fix #322 Side blocks were not seeing their updated fields saved in DB

parent 2af4cdda
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,7 @@ function BlockDAL(db) { ...@@ -24,6 +24,7 @@ function BlockDAL(db) {
this.fields = ['fork', 'hash', 'signature', 'currency', 'issuer', 'parameters', 'previousHash', 'previousIssuer', 'version', 'membersCount', 'monetaryMass', 'UDTime', 'medianTime', 'dividend', 'time', 'powMin', 'number', 'nonce', 'transactions', 'certifications', 'identities', 'joiners', 'actives', 'leavers', 'excluded']; this.fields = ['fork', 'hash', 'signature', 'currency', 'issuer', 'parameters', 'previousHash', 'previousIssuer', 'version', 'membersCount', 'monetaryMass', 'UDTime', 'medianTime', 'dividend', 'time', 'powMin', 'number', 'nonce', 'transactions', 'certifications', 'identities', 'joiners', 'actives', 'leavers', 'excluded'];
this.arrays = ['identities','certifications','actives','excluded','leavers','joiners','transactions']; this.arrays = ['identities','certifications','actives','excluded','leavers','joiners','transactions'];
this.bigintegers = ['monetaryMass','dividend']; this.bigintegers = ['monetaryMass','dividend'];
this.booleans = ['wrong'];
this.pkFields = ['number','hash']; this.pkFields = ['number','hash'];
this.init = () => co(function *() { this.init = () => co(function *() {
...@@ -60,6 +61,7 @@ function BlockDAL(db) { ...@@ -60,6 +61,7 @@ function BlockDAL(db) {
');' + ');' +
'CREATE INDEX IF NOT EXISTS idx_block_hash ON block (hash);' + 'CREATE INDEX IF NOT EXISTS idx_block_hash ON block (hash);' +
'CREATE INDEX IF NOT EXISTS idx_block_fork ON block (fork);' + 'CREATE INDEX IF NOT EXISTS idx_block_fork ON block (fork);' +
'ALTER TABLE block ADD COLUMN `wrong` BOOLEAN NOT NULL DEFAULT 0;' +
'COMMIT;', []); 'COMMIT;', []);
}); });
...@@ -118,11 +120,8 @@ function BlockDAL(db) { ...@@ -118,11 +120,8 @@ function BlockDAL(db) {
function saveBlockAs(block, fork) { function saveBlockAs(block, fork) {
return co(function *() { return co(function *() {
let existing = yield that.getEntity(block); block.fork = fork;
if (existing) { return yield that.saveEntity(block);
return that.query('UPDATE block SET fork = ? WHERE number = ? and hash = ?', [fork, block.number, block.hash]);
}
yield that.insert(block);
}); });
} }
......
...@@ -427,7 +427,7 @@ function PeeringService(server, pair, dal) { ...@@ -427,7 +427,7 @@ function PeeringService(server, pair, dal) {
err.code == "EINVAL" err.code == "EINVAL"
|| err.code == "ECONNREFUSED" || err.code == "ECONNREFUSED"
|| err.code == "ETIMEDOUT" || err.code == "ETIMEDOUT"
|| err.httpCode !== 404); || (err.httpCode !== undefined && err.httpCode !== 404));
} }
function processAscendingUntilNoBlock(p, node, current) { function processAscendingUntilNoBlock(p, node, current) {
......
...@@ -81,7 +81,7 @@ describe("Switch", function() { ...@@ -81,7 +81,7 @@ describe("Switch", function() {
yield commit(s2)(); yield commit(s2)();
// So we now have: // So we now have:
// S1 01234 // S1 01234
// S2 `345678 // S2 `3456789
yield sync(3, 8, s2, s1); yield sync(3, 8, s2, s1);
// S1 should have switched to the other branch // S1 should have switched to the other branch
}); });
...@@ -100,5 +100,19 @@ describe("Switch", function() { ...@@ -100,5 +100,19 @@ describe("Switch", function() {
number: 8 number: 8
}); });
}); });
it('/block/7 should have valid monetary mass', function() {
return co(function *() {
let block = yield s1.dal.getBlock(7);
block.should.have.property('UDTime').not.equal(null);
});
});
it('/block/8 should have valid monetary mass', function() {
return co(function *() {
let block = yield s1.dal.getBlock(8);
block.should.have.property('UDTime').not.equal(null);
});
});
}); });
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment