-
Notifications
You must be signed in to change notification settings - Fork 456
Provide API endpoint for transactions of an account - Closes #1892 #1920
Provide API endpoint for transactions of an account - Closes #1892 #1920
Conversation
schema/swagger.yml
Outdated
senderIdOrRecipientId: | ||
type: string | ||
format: address | ||
example: 12668885769632475474L |
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.
@Tschakki senderIdOrRecipientId
is just a request param. It would not be part of POST /transactions
request.
schema/swagger.yml
Outdated
senderIdOrRecipientId: | ||
type: string | ||
format: address | ||
example: 12668885769632475474L |
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.
@Tschakki senderIdOrRecipientId
is just a request param. It would not be part of GET /transactions
response.
modules/transactions.js
Outdated
@@ -102,6 +102,8 @@ __private.list = function(filter, cb) { | |||
const params = {}; | |||
const where = []; | |||
const allowedFieldsMap = { | |||
senderIdOrRecipientId: | |||
't_senderId" IN (${senderId:csv}) OR t_recipientId" IN (${recipientId:csv})', |
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 seems to be missing double quote in the beginning of t_senderId
and t_recipientId
schema/swagger.yml
Outdated
maxLength: 22 | ||
name: senderIdOrRecipientId | ||
in: query | ||
description: Public key to query |
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.
@Tschakki Its the address not the public key
. Seems you forget to update it.
modules/transactions.js
Outdated
@@ -102,6 +102,8 @@ __private.list = function(filter, cb) { | |||
const params = {}; | |||
const where = []; | |||
const allowedFieldsMap = { | |||
senderIdOrRecipientId: | |||
'"t_senderId" IN (${senderId:csv}) OR "t_recipientId" IN (${recipientId:csv})', |
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.
(${senderId:csv})
and (${recipientId:csv})
should be (${senderIdOrRecipientId:csv})
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.
haha yes, just found it out myself ^^
rather than having another query param |
@shuse2 Yes probably it would be nice to have a Current implementation is a the shortest and easy way to meet the requirements we have. After 1.0.0 release will probably be doing improvements in API specially providing feature to compose filters with custom modifiers. That will be the permanent fix for requirement. |
.then(res => { | ||
expectSwaggerParamError(res, 'senderIdOrRecipientId'); | ||
}); | ||
}); |
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.
@Tschakki This case handles the case fo empty
string. You should also add a case where you specify value but invalid value.
} | ||
}); | ||
expect(sender).to.have.length(1); | ||
expect(recipient).to.have.length(1); |
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.
The transactions you posted are deterministic and you know there are only two such transactions. So having more clear expectations will be nice.
expect(res.body.data).to.not.empty;
expect(res.body.data[0].recipientId).to.be.eql(accountId);
expect(res.body.data[1].senderId).to.be.eql(accountId);
Notice how clean three line expectations look like and easy to understand.
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 is true there are only these 2 transactions, but are they returned always in the same chronological order inside of res.body.data
?
If not these expectations could fail randomly.
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.
Logically there should be one specific order whatever it would be. There can't be random order.
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, will change it then!
.then(res => { | ||
expectSwaggerParamError(res, 'senderIdOrRecipientId'); | ||
}); | ||
}); |
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.
This definitely will fail, as the format of the param you specified in swagger is string
not the array. So I don't think its a right test to be added.
modules/transactions.js
Outdated
@@ -102,6 +102,8 @@ __private.list = function(filter, cb) { | |||
const params = {}; | |||
const where = []; | |||
const allowedFieldsMap = { | |||
senderIdOrRecipientId: | |||
'"t_senderId" IN (${senderIdOrRecipientId:csv}) OR "t_recipientId" IN (${senderIdOrRecipientId:csv})', |
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 test case you should add is to check :csv
formatter. Means send comma separated string value of this param. I believe it will fail because of address
format we specified in swagger. So either you have to create new format for it or drop :csv
here.
c2f3f89
to
b5cd640
Compare
modules/transactions.js
Outdated
@@ -102,6 +102,8 @@ __private.list = function(filter, cb) { | |||
const params = {}; | |||
const where = []; | |||
const allowedFieldsMap = { | |||
senderIdOrRecipientId: | |||
'"t_senderId" IN (${senderIdOrRecipientId}) OR "t_recipientId" IN (${senderIdOrRecipientId})', |
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.
@Tschakki That needs to be changed, now as you are doing checking for only one variable then you should do with the direct assignment.
"t_senderId" = (${senderIdOrRecipientId}) OR "t_recipientId" = (${senderIdOrRecipientId})
What was the problem?
The new API had no endpoint to collect all the transactions of a specific address at once.
How did I fix it?
Create new filter
senderIdOrRecipientId
for transactions.How to test it?
Make API call:
/api/transactions?senderIdOrRecipientId=<address>
Review checklist