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
......@@ -167,7 +167,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
try {
const currentBlock = await dal.getCurrentBlockOrNull();
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 {
await DuniterBlockchain.pushStatsForBlocks([block], dal);
......@@ -176,7 +176,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
}
logger.info('Block #' + block.number + ' added to the blockchain in %s ms', (Date.now() - start));
return block;
return BlockDTO.fromJSONObject(added)
}
catch(err) {
throw err;
......@@ -245,7 +245,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
// Saves the block (DAL)
await dal.saveBlock(dbb);
return block;
return dbb
}
async saveParametersForRoot(block:BlockDTO, conf:ConfDTO, dal:any) {
......
import {TransactionDTO} from "./TransactionDTO"
import {CurrencyConfDTO} from "./ConfDTO"
import {hashf} from "../common"
import {Cloneable} from "./Cloneable";
import {Cloneable} from "./Cloneable"
const DEFAULT_DOCUMENT_VERSION = 10
......@@ -209,6 +209,12 @@ export class BlockDTO implements Cloneable {
dto.time = parseInt(obj.time)
dto.powMin = parseInt(obj.powMin)
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.membersCount = parseInt(obj.membersCount)
dto.issuersCount = parseInt(obj.issuersCount)
......
......@@ -191,11 +191,11 @@ export class BlockchainService extends FIFOService {
while (!added && i < potentials.length) {
const dto = BlockDTO.fromJSONObject(potentials[i])
try {
await this.mainContext.checkAndAddBlock(dto)
const addedBlock = await this.mainContext.checkAndAddBlock(dto)
added = true
this.push({
bcEvent: OtherConstants.BC_EVENT.HEAD_CHANGED,
block: dto
block: addedBlock
})
} catch (e) {
this.logger.error(e)
......
......@@ -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
yield commit({ time: now + 120 * 5 });
const client = new ws('ws://127.0.0.1:7777/ws/block');
return new Promise(res => {
client.once('message', function message(data) {
const block = JSON.parse(data);
should(block).have.property('number', 5);
should(block).have.property('dividend').equal(100)
should(block).have.property('monetaryMass').equal(600)
should(block).have.property('monetaryMass').not.equal("600")
if (!completed) {
completed = true;
res();
}
})
let resolve5, resolve6, resolve7
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);
if (block.number === 5) resolve5(block)
if (block.number === 6) resolve6(block)
if (block.number === 7) resolve7(block)
})
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) {
......
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