Skip to content

Commit

Permalink
refactor(account)!: remove extra object wrapping json output
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `account spend` returns unwrapped JSON
```diff
- aecli account spend ... | jq .tx.tx.amount
+ aecli account spend ... | jq .tx.amount
```
  • Loading branch information
davidyuk committed Apr 20, 2023
1 parent c5ef769 commit b1d4585
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
8 changes: 2 additions & 6 deletions src/actions/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,8 @@ export async function spend(
},
);

if (json) {
print({ tx });
} else {
print('Transaction mined');
printTransaction(tx, json);
}
if (!json) print('Transaction mined');
printTransaction(tx, json);
}

// ## Get `balance` function
Expand Down
36 changes: 17 additions & 19 deletions test/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,23 @@ describe('Account Module', () => {
expect(+receiverBalance).to.be.equal(amount);

expect(resJson).to.eql({
blockHash: resJson.blockHash,
blockHeight: resJson.blockHeight,
hash: resJson.hash,
rawTx: resJson.rawTx,
signatures: [resJson.signatures[0]],
tx: {
blockHash: resJson.tx.blockHash,
blockHeight: resJson.tx.blockHeight,
hash: resJson.tx.hash,
rawTx: resJson.tx.rawTx,
signatures: [resJson.tx.signatures[0]],
tx: {
amount: '100',
fee: '16660000000000',
nonce: 1,
payload: 'ba_Xfbg4g==',
recipientId: resJson.tx.tx.recipientId,
senderId: resJson.tx.tx.senderId,
type: 'SpendTx',
version: 1,
},
amount: '100',
fee: '16660000000000',
nonce: 1,
payload: 'ba_Xfbg4g==',
recipientId: resJson.tx.recipientId,
senderId: resJson.tx.senderId,
type: 'SpendTx',
version: 1,
},
});

const res = await executeAccount([
'spend', WALLET_NAME, '--password', 'test', publicKey, amount,
]);
Expand All @@ -108,8 +106,8 @@ Block hash ______________________________ ${lineEndings[2]}
Block height ____________________________ ${lineEndings[3]}
Signatures ______________________________ ${lineEndings[4]}
Tx Type _________________________________ SpendTx
Sender account __________________________ ${resJson.tx.tx.senderId}
Recipient account _______________________ ${resJson.tx.tx.recipientId}
Sender account __________________________ ${resJson.tx.senderId}
Recipient account _______________________ ${resJson.tx.recipientId}
Amount __________________________________ 100
Payload _________________________________ ba_Xfbg4g==
Fee _____________________________________ 16660000000000
Expand All @@ -121,7 +119,7 @@ Version _________________________________ 1

it('Spend coins to another wallet in ae', async () => {
const receiverKeys = generateKeyPair();
const { tx: { tx: { fee } } } = await executeAccount([
const { tx: { fee } } = await executeAccount([
'spend', WALLET_NAME, '--password', 'test', '--json',
receiverKeys.publicKey, '1ae', '--fee', '0.02ae',
]);
Expand Down
4 changes: 2 additions & 2 deletions test/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe('AENS Module', () => {

it('Spend by name', async () => {
const amount = 100000009;
const spendTx = await executeAccount([
const { tx: { recipientId } } = await executeAccount([
'spend',
WALLET_NAME,
'--password',
Expand All @@ -179,7 +179,7 @@ describe('AENS Module', () => {
]);

const nameObject = await sdk.aensQuery(name2);
spendTx.tx.tx.recipientId.should.be.equal(nameObject.id);
recipientId.should.be.equal(nameObject.id);
const balance = await sdk.getBalance(publicKey);
balance.should.be.equal(`${amount}`);
});
Expand Down

0 comments on commit b1d4585

Please sign in to comment.