Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3719 from LiskHQ/3717-asset-as-object
Browse files Browse the repository at this point in the history
Support {} behavior for asset field accounts - Closes #3717
  • Loading branch information
shuse2 authored May 27, 2019
2 parents d6ed894 + 44d3dde commit 59c6884
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const defaultCreateValues = {
nameExist: false,
multiMin: 0,
multiLifetime: 0,
asset: null,
asset: {},
};

const readOnlyFields = ['address'];
Expand Down Expand Up @@ -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;
});

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const defaultAccount = {
nameExist: false,
multiMin: 0,
multiLifetime: 0,
asset: null,
asset: {},
};

class AccountStore {
Expand Down
4 changes: 2 additions & 2 deletions framework/test/mocha/fixtures/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const Account = stampit({
votedDelegatesPublicKeys: null,
membersPublicKeys: null,
productivity: 0,
asset: null,
asset: {},
},
init({
isDelegate,
Expand Down Expand Up @@ -138,7 +138,7 @@ const dbAccount = stampit({
secondSignature: 0,
username: null,
vote: '0',
asset: null,
asset: {},
},
init({ address, balance }) {
this.address = address || this.address;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ describe('GET /accounts', () => {
delegate.vote,
constansts.supply
);

expect(delegate.approval).to.be.eql(calculatedApproval);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -281,7 +280,7 @@ describe('ChainAccount', () => {
productivity: 0,
votedDelegatesPublicKeys: null,
membersPublicKeys: null,
asset: null,
asset: {},
};
expect(accountFromDB).to.be.eql(expectedObject);
});
Expand Down
2 changes: 1 addition & 1 deletion framework/test/mocha/unit/modules/chain/logic/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const validAccount = {
productivity: 0,
membersPublicKeys: null,
votedDelegatesPublicKeys: null,
asset: null,
asset: {},
};

describe('account', () => {
Expand Down

0 comments on commit 59c6884

Please sign in to comment.