diff --git a/framework/src/modules/chain/components/storage/entities/account.js b/framework/src/modules/chain/components/storage/entities/account.js index b9116a8abf6..4e73cd943a6 100644 --- a/framework/src/modules/chain/components/storage/entities/account.js +++ b/framework/src/modules/chain/components/storage/entities/account.js @@ -37,7 +37,7 @@ const defaultCreateValues = { nameExist: false, multiMin: 0, multiLifetime: 0, - asset: null, + asset: {}, }; const readOnlyFields = ['address']; @@ -164,8 +164,6 @@ class ChainAccount extends AccountEntity { accounts = accounts.map(account => { const parsedAccount = _.defaults(account, defaultCreateValues); - parsedAccount.asset = parsedAccount.asset ? parsedAccount.asset : null; - return parsedAccount; }); diff --git a/framework/src/modules/chain/components/storage/sql/migrations/updates/20190524120600_add_default_value_asset_mem_account.sql b/framework/src/modules/chain/components/storage/sql/migrations/updates/20190524120600_add_default_value_asset_mem_account.sql new file mode 100644 index 00000000000..a6cec8afcea --- /dev/null +++ b/framework/src/modules/chain/components/storage/sql/migrations/updates/20190524120600_add_default_value_asset_mem_account.sql @@ -0,0 +1,22 @@ +/* + * Copyright © 2019 Lisk Foundation + * + * See the LICENSE file at the top-level directory of this distribution + * for licensing information. + * + * Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, + * no part of this software, including this file, may be copied, modified, + * propagated, or distributed except according to the terms contained in the + * LICENSE file. + * + * Removal or modification of this copyright notice is prohibited. + */ + + +/* + DESCRIPTION: Alter null value to empty JSON object {} for asset field for mem_accounts column + PARAMETERS: None +*/ + + -- Alter asset field to empty JSON +UPDATE mem_accounts SET asset = '{}'::json WHERE asset IS NULL; \ No newline at end of file diff --git a/framework/src/modules/chain/logic/state_store/account_store.js b/framework/src/modules/chain/logic/state_store/account_store.js index b7dad9d9254..cc78529f878 100644 --- a/framework/src/modules/chain/logic/state_store/account_store.js +++ b/framework/src/modules/chain/logic/state_store/account_store.js @@ -32,7 +32,7 @@ const defaultAccount = { nameExist: false, multiMin: 0, multiLifetime: 0, - asset: null, + asset: {}, }; class AccountStore { diff --git a/framework/test/mocha/fixtures/accounts.js b/framework/test/mocha/fixtures/accounts.js index e290162214f..2a053d104ce 100644 --- a/framework/test/mocha/fixtures/accounts.js +++ b/framework/test/mocha/fixtures/accounts.js @@ -84,7 +84,7 @@ const Account = stampit({ votedDelegatesPublicKeys: null, membersPublicKeys: null, productivity: 0, - asset: null, + asset: {}, }, init({ isDelegate, @@ -138,7 +138,7 @@ const dbAccount = stampit({ secondSignature: 0, username: null, vote: '0', - asset: null, + asset: {}, }, init({ address, balance }) { this.address = address || this.address; diff --git a/framework/test/mocha/functional/http/get/accounts/accounts.js b/framework/test/mocha/functional/http/get/accounts/accounts.js index 0761add4510..2624717fb7f 100644 --- a/framework/test/mocha/functional/http/get/accounts/accounts.js +++ b/framework/test/mocha/functional/http/get/accounts/accounts.js @@ -449,6 +449,7 @@ describe('GET /accounts', () => { delegate.vote, constansts.supply ); + expect(delegate.approval).to.be.eql(calculatedApproval); }); diff --git a/framework/test/mocha/unit/modules/chain/components/storage/entities/account.js b/framework/test/mocha/unit/modules/chain/components/storage/entities/account.js index 69bff7af66a..b84300df3a8 100644 --- a/framework/test/mocha/unit/modules/chain/components/storage/entities/account.js +++ b/framework/test/mocha/unit/modules/chain/components/storage/entities/account.js @@ -160,7 +160,6 @@ describe('ChainAccount', () => { await AccountEntity.create(account); const mergedObject = Object.assign({}, defaultCreateValues, account); - mergedObject.asset = mergedObject.asset ? mergedObject.asset : null; expect(AccountEntity.getValuesSet.firstCall.args[0]).to.be.eql([ mergedObject, @@ -281,7 +280,7 @@ describe('ChainAccount', () => { productivity: 0, votedDelegatesPublicKeys: null, membersPublicKeys: null, - asset: null, + asset: {}, }; expect(accountFromDB).to.be.eql(expectedObject); }); diff --git a/framework/test/mocha/unit/modules/chain/logic/account.js b/framework/test/mocha/unit/modules/chain/logic/account.js index bfa866c2e21..68cfdcbbafa 100644 --- a/framework/test/mocha/unit/modules/chain/logic/account.js +++ b/framework/test/mocha/unit/modules/chain/logic/account.js @@ -45,7 +45,7 @@ const validAccount = { productivity: 0, membersPublicKeys: null, votedDelegatesPublicKeys: null, - asset: null, + asset: {}, }; describe('account', () => {