Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Add cmd get transactions by senderID and state filters - Closes #648 #651

Merged
merged 11 commits into from
Nov 22, 2018

Conversation

ishantiw
Copy link
Contributor

@ishantiw ishantiw commented Nov 19, 2018

Description

Add command to get transactions based on senderID, default, limit and offset values.

Also related to #600

Example,
lisk transaction:get --sender-id=14523483941411160698L --state=unsigned
lisk transaction:get 7397859286435869218 --state=unprocessed
lisk transaction:get --limit=10 --offset=15
lisk transaction:get

Review checklist

@ishantiw ishantiw added this to the Version 2.1.0 milestone Nov 19, 2018
@ishantiw ishantiw self-assigned this Nov 19, 2018
@ishantiw ishantiw changed the title 648 add cmd get transactions by state filters Add cmd get transactions by senderID and state filters. Closes #648 Nov 19, 2018
@ishantiw ishantiw changed the title Add cmd get transactions by senderID and state filters. Closes #648 Add cmd get transactions by senderID and state filters - Closes #648 Nov 19, 2018
Copy link
Contributor

@shuse2 shuse2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review for test not done yet

docs/transaction.md Outdated Show resolved Hide resolved
src/commands/transaction/get.js Outdated Show resolved Hide resolved
src/commands/transaction/get.js Outdated Show resolved Hide resolved
src/commands/transaction/get.js Outdated Show resolved Hide resolved
@@ -26,7 +26,7 @@ export const handleResponse = (endpoint, res, placeholder) => {
}
throw new Error(`No ${endpoint} found using specified parameters.`);
}
return res.data[0];
return res.data;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this affect other queries?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not returning a list of transactions from API so I had to change but I also tested all the commands which are using it and it works fine and also all the tests are passing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think test passes because we stub the API response, but it changes the format ='(

> ./bin/run account:get 123L,456L                                                             
[
        {
                "0": {
                        "address": "123L",
                        "unconfirmedBalance": "6122216612",
                        "balance": "6122216612",
                        "publicKey": "",
                        "secondPublicKey": ""
                }
        },
        {
                "0": {
                        "address": "456L",
                        "unconfirmedBalance": "1000",
                        "balance": "1000",
                        "publicKey": "",
                        "secondPublicKey": ""
                }
        }
]

src/commands/transaction/get.js Outdated Show resolved Hide resolved
Copy link
Contributor

@mitsuaki-u mitsuaki-u left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested ./bin/run transaction:get --senderId=13214966370334815499L --pretty --limit=3 and it seems to return transactions with senderId !== to provided id

return this.print(results);
}

if (senderAddress) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should show some error if provided senderId does not exist or invalid. currently doesn't seem to throw.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good catch, but actually right nowsenderId is made to work only with transaction state. So, if you don't use state field it will simply ignore senderId. But yes, we need to implement get transactions by senderId without state field too. I will update it.

@ishantiw
Copy link
Contributor Author

Addressed above concerns.

Considering all the arguments and flags, below are some examples for testing

transaction:get 10041151099734832021
transaction:get 10041151099734832021,1260076503909567890
transaction:get 10041151099734832021,1260076503909567890 --state=unprocessed
transaction:get --state=unsigned --sender-id=1813095620424213569L
transaction:get 10041151099734832021 --state=unsigned --sender-id=1813095620424213569L
transaction:get --sender-id=1813095620424213569L
transaction:get --limit=10 --sort=amount:desc
transaction:get --limit=10 --offset=5

src/commands/transaction/get.js Outdated Show resolved Hide resolved
src/commands/transaction/get.js Outdated Show resolved Hide resolved
test/commands/transaction/get.test.js Outdated Show resolved Hide resolved
@@ -26,7 +26,7 @@ export const handleResponse = (endpoint, res, placeholder) => {
}
throw new Error(`No ${endpoint} found using specified parameters.`);
}
return res.data[0];
return res.data;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think test passes because we stub the API response, but it changes the format ='(

> ./bin/run account:get 123L,456L                                                             
[
        {
                "0": {
                        "address": "123L",
                        "unconfirmedBalance": "6122216612",
                        "balance": "6122216612",
                        "publicKey": "",
                        "secondPublicKey": ""
                }
        },
        {
                "0": {
                        "address": "456L",
                        "unconfirmedBalance": "1000",
                        "balance": "1000",
                        "publicKey": "",
                        "secondPublicKey": ""
                }
        }
]

Copy link
Contributor

@mitsuaki-u mitsuaki-u left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, mostly some changes to test suite format.

@@ -163,6 +158,109 @@ describe('transaction:get', () => {
return expect(printMethodStub).to.be.calledWithExactly(queryResult);
},
);
describe('transaction: get --sender-id', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer empty line before describe blocks

return expect(printMethodStub).to.be.calledWithExactly(queryResult);
});
});
describe('transaction: get --limit --offset', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above (empty line before)

.stub(api, 'default', sandbox.stub().returns(apiClientStub))
.stub(queryHandler, 'query', sandbox.stub().resolves(queryResult))
.command(['transaction:get', '--sender-id=12668885769632475474L'])
.it('should get all transactions info limited by limit value', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update description to mention --sender-id flag

.stub(queryHandler, 'query', sandbox.stub().resolves(queryResult))
.command(['transaction:get'])
.it(
'should get all transactions based on default value of limit(20) and offset(0).',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description should be updated to limit(10)

return expect(printMethodStub).to.be.calledWithExactly(queryResult);
},
);
setupTest()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above (empty line before)

]);
});
.it(
'should get a transaction’s info and display as an array for a state.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should get an unprocessed transaction’s info and display as an array.

])
.it(
'should get transactions info only using non-empty args and display as an array',
'should get transaction’s info and display as an array for a state.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should get an unsigned transaction’s info and display as an array.

])
.it(
'should get transactions info only using non-empty args and display as an array',
'should get a transaction’s info for a given txn Id, senders address and state and display as an array.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sender's address

.stub(api, 'default', sandbox.stub().returns(apiClientStubNode))
.command(['transaction:get', '--state=unprocessed', '--limit=10'])
.it(
'should get transactions for a given state taking limit or offset or default.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should get transactions for a given state without specified txn id.

@@ -194,60 +292,94 @@ describe('transaction:get', () => {
},
};

describe('transaction: get transactions --state-unprocessed', () => {
setupTest()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add queryHandler expects for all tests in this test suite below(transaction:get transactions --state)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all queries related to getting transactions by a state is not using the general query handler but its own handler so it's not used for these test suits.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I think we should also test for custom queryNode handler in the same way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mitsujutsu discussed with @shuse2, I will add it in testing

@ishantiw
Copy link
Contributor Author

@shuse2 fixed query handler, updated it to handle arrays more than 1 records. This time I tested it with the right build 😅 but please test it again on your end also.

@mitsujutsu addressed 👍

shuse2
shuse2 previously approved these changes Nov 22, 2018
},
];

setupTest()
.stub(api, 'default', sandbox.stub().returns(apiClientStub))
.stub(queryHandler, 'query', sandbox.stub().resolves(queryResult))
.command(['transaction:get', transactionIds.join(',')])
.it('should get two transactions’ info and display as an array', () => {
.it('should get two transactions’ info and display as an array.', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transactions’ --> transaction's

Copy link
Contributor

@mitsuaki-u mitsuaki-u left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one missing test

.command(['transaction:get', transactionId, '--state=unprocessed'])
.it(
'should get an unprocessed transaction’s info and display as an array.',
() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this test also have queryNodeTransaction expect?

@shuse2 shuse2 merged commit 838ee16 into development Nov 22, 2018
@shuse2 shuse2 deleted the 648-add-cmd-get-transactions-by-state-filters branch November 22, 2018 14:15
@shuse2 shuse2 removed this from the Version 2.1.0 milestone Nov 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants