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

[fix] #1080 WebSocket: monetaryMass is missing in post connection block

parent 2df75a14
No related branches found
No related tags found
No related merge requests found
...@@ -167,7 +167,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain { ...@@ -167,7 +167,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
try { try {
const currentBlock = await dal.getCurrentBlockOrNull(); const currentBlock = await dal.getCurrentBlockOrNull();
block.fork = false; block.fork = false;
await this.saveBlockData(currentBlock, block, conf, dal, logger, index, HEAD); const added = await this.saveBlockData(currentBlock, block, conf, dal, logger, index, HEAD);
try { try {
await DuniterBlockchain.pushStatsForBlocks([block], dal); await DuniterBlockchain.pushStatsForBlocks([block], dal);
...@@ -176,7 +176,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain { ...@@ -176,7 +176,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
} }
logger.info('Block #' + block.number + ' added to the blockchain in %s ms', (Date.now() - start)); logger.info('Block #' + block.number + ' added to the blockchain in %s ms', (Date.now() - start));
return block; return BlockDTO.fromJSONObject(added)
} }
catch(err) { catch(err) {
throw err; throw err;
...@@ -245,7 +245,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain { ...@@ -245,7 +245,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
// Saves the block (DAL) // Saves the block (DAL)
await dal.saveBlock(dbb); await dal.saveBlock(dbb);
return block; return dbb
} }
async saveParametersForRoot(block:BlockDTO, conf:ConfDTO, dal:any) { async saveParametersForRoot(block:BlockDTO, conf:ConfDTO, dal:any) {
......
import {TransactionDTO} from "./TransactionDTO" import {TransactionDTO} from "./TransactionDTO"
import {CurrencyConfDTO} from "./ConfDTO" import {CurrencyConfDTO} from "./ConfDTO"
import {hashf} from "../common" import {hashf} from "../common"
import {Cloneable} from "./Cloneable"; import {Cloneable} from "./Cloneable"
const DEFAULT_DOCUMENT_VERSION = 10 const DEFAULT_DOCUMENT_VERSION = 10
...@@ -209,6 +209,12 @@ export class BlockDTO implements Cloneable { ...@@ -209,6 +209,12 @@ export class BlockDTO implements Cloneable {
dto.time = parseInt(obj.time) dto.time = parseInt(obj.time)
dto.powMin = parseInt(obj.powMin) dto.powMin = parseInt(obj.powMin)
dto.monetaryMass = parseInt(obj.monetaryMass) dto.monetaryMass = parseInt(obj.monetaryMass)
if (isNaN(dto.monetaryMass) && obj.mass !== undefined) {
dto.monetaryMass = parseInt(obj.mass)
}
if (isNaN(dto.monetaryMass)) {
dto.monetaryMass = 0
}
dto.unitbase = parseInt(obj.unitbase) dto.unitbase = parseInt(obj.unitbase)
dto.membersCount = parseInt(obj.membersCount) dto.membersCount = parseInt(obj.membersCount)
dto.issuersCount = parseInt(obj.issuersCount) dto.issuersCount = parseInt(obj.issuersCount)
......
...@@ -191,11 +191,11 @@ export class BlockchainService extends FIFOService { ...@@ -191,11 +191,11 @@ export class BlockchainService extends FIFOService {
while (!added && i < potentials.length) { while (!added && i < potentials.length) {
const dto = BlockDTO.fromJSONObject(potentials[i]) const dto = BlockDTO.fromJSONObject(potentials[i])
try { try {
await this.mainContext.checkAndAddBlock(dto) const addedBlock = await this.mainContext.checkAndAddBlock(dto)
added = true added = true
this.push({ this.push({
bcEvent: OtherConstants.BC_EVENT.HEAD_CHANGED, bcEvent: OtherConstants.BC_EVENT.HEAD_CHANGED,
block: dto block: addedBlock
}) })
} catch (e) { } catch (e) {
this.logger.error(e) this.logger.error(e)
......
...@@ -211,23 +211,37 @@ describe("HTTP API", function() { ...@@ -211,23 +211,37 @@ describe("HTTP API", function() {
}); });
}); });
it('/block (number 5) should send a block', () => co(function*() { it('/block (number 5,6,7) should send a block', () => co(function*() {
let completed = false let completed = false
yield commit({ time: now + 120 * 5 }); yield commit({ time: now + 120 * 5 });
const client = new ws('ws://127.0.0.1:7777/ws/block'); const client = new ws('ws://127.0.0.1:7777/ws/block');
return new Promise(res => { let resolve5, resolve6, resolve7
client.once('message', function message(data) { const p5 = new Promise(res => resolve5 = res)
const p6 = new Promise(res => resolve6 = res)
const p7 = new Promise(res => resolve7 = res)
client.on('message', function message(data) {
const block = JSON.parse(data); const block = JSON.parse(data);
should(block).have.property('number', 5); if (block.number === 5) resolve5(block)
should(block).have.property('dividend').equal(100) if (block.number === 6) resolve6(block)
should(block).have.property('monetaryMass').equal(600) if (block.number === 7) resolve7(block)
should(block).have.property('monetaryMass').not.equal("600")
if (!completed) {
completed = true;
res();
}
})
}) })
yield commit({ time: now + 120 * 6 });
yield commit({ time: now + 120 * 7 });
const b5 = yield p5
should(b5).have.property('number', 5);
should(b5).have.property('dividend').equal(100)
should(b5).have.property('monetaryMass').equal(600)
should(b5).have.property('monetaryMass').not.equal("600")
const b6 = yield p6
should(b6).have.property('number', 6);
should(b6).have.property('dividend').equal(null)
should(b6).have.property('monetaryMass').equal(600)
should(b6).have.property('monetaryMass').not.equal("600")
const b7 = yield p7
should(b7).have.property('number', 7);
should(b7).have.property('dividend').equal(100)
should(b7).have.property('monetaryMass').equal(800)
should(b7).have.property('monetaryMass').not.equal("800")
})) }))
it('/block should answer to pings', function(done) { it('/block should answer to pings', function(done) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment