Skip to content

Commit

Permalink
fix trades account filter (#492)
Browse files Browse the repository at this point in the history
fix trades account filter
add trades for account paging tests
closes #486
  • Loading branch information
tomerweller authored Jun 6, 2018
1 parent 285a299 commit 44bc821
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions services/horizon/internal/actions_trade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
. "github.com/stellar/go/services/horizon/internal/db2/history"
. "github.com/stellar/go/services/horizon/internal/test/trades"
"github.com/stellar/go/xdr"
"github.com/stellar/go/support/render/hal"
)

func TestTradeActions_Index(t *testing.T) {
Expand Down Expand Up @@ -102,6 +103,7 @@ func TestTradeActions_Index(t *testing.T) {
ht.Assert.PageOf(2, w.Body)
}

// for other account
w = ht.Get("/accounts/GCXKG6RN4ONIEPCMNFB732A436Z5PNDSRLGWK7GBLCMQLIFO4S7EYWVU/trades")
if ht.Assert.Equal(200, w.Code) {
ht.Assert.PageOf(2, w.Body)
Expand All @@ -110,6 +112,37 @@ func TestTradeActions_Index(t *testing.T) {
ht.Assert.Contains(records[0], "base_amount")
ht.Assert.Contains(records[0], "counter_amount")
}

//test paging from account 1
w = ht.Get("/accounts/GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2/trades?order=desc&limit=1")
var links hal.Links
if ht.Assert.Equal(200, w.Code) {
ht.Assert.PageOf(1, w.Body)
links = ht.UnmarshalPage(w.Body, &records)
}

w = ht.Get(links.Next.Href)
if ht.Assert.Equal(200, w.Code) {
ht.Assert.PageOf(1, w.Body)
prevRecord := records[0]
links = ht.UnmarshalPage(w.Body, &records)
ht.Assert.NotEqual(prevRecord, records[0])
}

//test paging from account 2
w = ht.Get("/accounts/GCXKG6RN4ONIEPCMNFB732A436Z5PNDSRLGWK7GBLCMQLIFO4S7EYWVU/trades?order=desc&limit=1")
if ht.Assert.Equal(200, w.Code) {
ht.Assert.PageOf(1, w.Body)
links = ht.UnmarshalPage(w.Body, &records)
}

w = ht.Get(links.Next.Href)
if ht.Assert.Equal(200, w.Code) {
ht.Assert.PageOf(1, w.Body)
prevRecord := records[0]
links = ht.UnmarshalPage(w.Body, &records)
ht.Assert.NotEqual(prevRecord, records[0])
}
}

// setAssetQuery adds an asset filter with a given prefix to a query
Expand Down
2 changes: 1 addition & 1 deletion services/horizon/internal/db2/history/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (q *TradesQ) ForAccount(aid string) *TradesQ {
return q
}

q.sql = q.sql.Where("htrd.base_account_id = ? OR htrd.counter_account_id = ?", account.ID, account.ID)
q.sql = q.sql.Where("(htrd.base_account_id = ? OR htrd.counter_account_id = ?)", account.ID, account.ID)
return q
}

Expand Down

0 comments on commit 44bc821

Please sign in to comment.