From 64ae90693c4fbe0289962bc4ae1a9e851546cea0 Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Fri, 23 Aug 2019 12:42:38 +0200 Subject: [PATCH] :bug: Fix peer entity definition to allow null for optional fields --- .../components/storage/entities/peer.js | 8 ++++++- .../components/storage/entities/peer.js | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/framework/src/modules/network/components/storage/entities/peer.js b/framework/src/modules/network/components/storage/entities/peer.js index 9d10babe966..25e27e34cf2 100644 --- a/framework/src/modules/network/components/storage/entities/peer.js +++ b/framework/src/modules/network/components/storage/entities/peer.js @@ -26,7 +26,13 @@ const { }, } = require('../../../../../components/storage'); -const defaultCreateValues = {}; +const defaultCreateValues = { + os: null, + version: null, + broadhash: null, + height: 1, + protocolVersion: null, +}; const readOnlyFields = []; diff --git a/framework/test/mocha/unit/modules/network/components/storage/entities/peer.js b/framework/test/mocha/unit/modules/network/components/storage/entities/peer.js index c5760cd2990..838986b6fac 100644 --- a/framework/test/mocha/unit/modules/network/components/storage/entities/peer.js +++ b/framework/test/mocha/unit/modules/network/components/storage/entities/peer.js @@ -37,6 +37,7 @@ describe('Peer', () => { let invalidOptions; let validOptions; let validPeer; + let incompletePeer; let invalidPeer; let storage; @@ -142,6 +143,12 @@ describe('Peer', () => { height: 6857664, }; + incompletePeer = { + ip: '100.187.70.20', + wsPort: 7001, + state: 1, + }; + invalidPeer = { ip: 'a.b.c.d', wsPort: 7001, @@ -316,6 +323,20 @@ describe('Peer', () => { expect(result).to.be.eql(validPeer); }); + it('should create a peer object successfully with incomplete peer', async () => { + await storage.entities.Peer.create(incompletePeer); + const result = await storage.entities.Peer.getOne({ ip: validPeer.ip }); + delete result.id; + expect(result).to.be.eql({ + ...incompletePeer, + os: null, + version: null, + broadhash: null, + height: 1, + protocolVersion: null, + }); + }); + it('should skip if any invalid attribute is provided'); it('should reject with invalid data provided', async () =>