-
Notifications
You must be signed in to change notification settings - Fork 30
Add cmd get transactions by senderID and state filters - Closes #648 #651
Add cmd get transactions by senderID and state filters - Closes #648 #651
Conversation
There was a problem hiding this 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
src/utils/query.js
Outdated
@@ -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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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": ""
}
}
]
There was a problem hiding this 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
src/commands/transaction/get.js
Outdated
return this.print(results); | ||
} | ||
|
||
if (senderAddress) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Addressed above concerns. Considering all the arguments and flags, below are some examples for testing
|
src/utils/query.js
Outdated
@@ -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; |
There was a problem hiding this comment.
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": ""
}
}
]
There was a problem hiding this 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', () => { |
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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).', |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.', |
There was a problem hiding this comment.
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.', |
There was a problem hiding this comment.
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.', |
There was a problem hiding this comment.
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.', |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
@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 👍 |
}, | ||
]; | ||
|
||
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.', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transactions’
--> transaction's
There was a problem hiding this 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.', | ||
() => { |
There was a problem hiding this comment.
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?
Description
Add command to get transactions based on
senderID
,default
,limit
andoffset
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