Skip to content

Commit

Permalink
Merge branch 'feat/api-transfers-pagination' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
altergui committed Aug 6, 2024
2 parents 4b888e4 + e3da561 commit adea584
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 29 deletions.
16 changes: 7 additions & 9 deletions apiclient/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,21 +290,19 @@ func (c *HTTPclient) AccountSetMetadata(metadata *api.AccountMetadata) (types.He
}

// ListTokenTransfers returns the list of sent and received token transfers associated with an account
func (c *HTTPclient) ListTokenTransfers(account common.Address, page int) (indexertypes.TokenTransfersAccount, error) {
func (c *HTTPclient) ListTokenTransfers(account common.Address, page int) (*api.TransfersList, error) {
resp, code, err := c.Request(HTTPGET, nil, "accounts", account.Hex(), "transfers", "page", strconv.Itoa(page))
if err != nil {
return indexertypes.TokenTransfersAccount{}, err
return nil, err
}
if code != apirest.HTTPstatusOK {
return indexertypes.TokenTransfersAccount{}, fmt.Errorf("%s: %d (%s)", errCodeNot200, code, resp)
return nil, fmt.Errorf("%s: %d (%s)", errCodeNot200, code, resp)
}
tokenTxs := new(struct {
Transfers indexertypes.TokenTransfersAccount `json:"transfers"`
})
if err := json.Unmarshal(resp, &tokenTxs); err != nil {
return indexertypes.TokenTransfersAccount{}, err
tokenTxs := &api.TransfersList{}
if err := json.Unmarshal(resp, tokenTxs); err != nil {
return nil, err
}
return tokenTxs.Transfers, nil
return tokenTxs, nil
}

// SetSIK function allows to update the Secret Identity Key for the current
Expand Down
6 changes: 2 additions & 4 deletions cmd/end2endtest/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,12 @@ func checkTokenTransfersCount(api *apiclient.HTTPclient, address common.Address)
if err != nil {
return err
}
countTokenTxs := uint64(len(tokenTxs.Received) + len(tokenTxs.Sent))

count, err := api.CountTokenTransfers(address)
if err != nil {
return err
}
if count != countTokenTxs {
return fmt.Errorf("expected %s to match transfers count %d and %d", address, count, countTokenTxs)
if count != tokenTxs.Pagination.TotalItems {
return fmt.Errorf("expected %s to match transfers count %d and %d", address, count, tokenTxs.Pagination.TotalItems)
}

log.Infow("current transfers count", "account", address.String(), "count", count)
Expand Down
15 changes: 4 additions & 11 deletions test/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,7 @@ func TestAPIAccountTokentxs(t *testing.T) {
resp, code = c.Request("GET", nil, "accounts", signer.Address().Hex(), "transfers", "page", "0")
qt.Assert(t, code, qt.Equals, 200, qt.Commentf("response: %s", resp))

tokenTxs := new(struct {
Transfers indexertypes.TokenTransfersAccount `json:"transfers"`
})
tokenTxs := &api.TransfersList{}
err := json.Unmarshal(resp, tokenTxs)
qt.Assert(t, err, qt.IsNil)

Expand All @@ -407,18 +405,14 @@ func TestAPIAccountTokentxs(t *testing.T) {
err = json.Unmarshal(resp, &countTnsAcc)
qt.Assert(t, err, qt.IsNil)

totalTokenTxs := uint64(len(tokenTxs.Transfers.Received) + len(tokenTxs.Transfers.Sent))

// compare count of total token transfers for the account 1 using the two response
qt.Assert(t, totalTokenTxs, qt.Equals, countTnsAcc.Count)
qt.Assert(t, tokenTxs.Pagination.TotalItems, qt.Equals, countTnsAcc.Count)

// get the token transfers received and sent for account 2
resp, code = c.Request("GET", nil, "accounts", signer2.Address().Hex(), "transfers", "page", "0")
qt.Assert(t, code, qt.Equals, 200, qt.Commentf("response: %s", resp))

tokenTxs2 := new(struct {
Transfers indexertypes.TokenTransfersAccount `json:"transfers"`
})
tokenTxs2 := &api.TransfersList{}
err = json.Unmarshal(resp, tokenTxs2)
qt.Assert(t, err, qt.IsNil)

Expand All @@ -432,9 +426,8 @@ func TestAPIAccountTokentxs(t *testing.T) {
err = json.Unmarshal(resp, &countTnsAcc2)
qt.Assert(t, err, qt.IsNil)

totalTokenTxs2 := uint64(len(tokenTxs2.Transfers.Received) + len(tokenTxs2.Transfers.Sent))
// compare count of total token transfers for the account 2 using the two response
qt.Assert(t, totalTokenTxs2, qt.Equals, countTnsAcc2.Count)
qt.Assert(t, tokenTxs2.Pagination.TotalItems, qt.Equals, countTnsAcc2.Count)

resp, code = c.Request("GET", nil, "accounts", "page", "0")
qt.Assert(t, code, qt.Equals, 200, qt.Commentf("response: %s", resp))
Expand Down
4 changes: 0 additions & 4 deletions test/apierror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ func TestAPIerror(t *testing.T) {
args: args{"POST", hugeFile, []string{"files", "cid"}},
want: api.ErrFileSizeTooBig,
},
{
args: args{"GET", nil, []string{"accounts", "totallyWrong!@#$", "transfers", "page", "0"}},
want: api.ErrCantParseAccountID,
},
{
args: args{"GET", nil, []string{
"votes", "verify",
Expand Down
2 changes: 1 addition & 1 deletion vochain/indexer/indexertypes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ type TokenTransferMeta struct {
Amount uint64 `json:"amount"`
From types.AccountID `json:"from"`
Height uint64 `json:"height"`
TxHash types.Hash `json:"txHash"`
TxHash types.HexBytes `json:"txHash"`
Timestamp time.Time `json:"timestamp"`
To types.AccountID `json:"to"`
}
Expand Down

0 comments on commit adea584

Please sign in to comment.