-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eventindexer): add get events by address/name param for community (
- Loading branch information
1 parent
773331b
commit 146f8d5
Showing
7 changed files
with
148 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package http | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/cyberhorsey/webutils" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
func (srv *Server) GetByAddressAndEventName(c echo.Context) error { | ||
page, err := srv.eventRepo.GetByAddressAndEventName( | ||
c.Request().Context(), | ||
c.Request(), | ||
c.QueryParam("address"), | ||
c.QueryParam("event"), | ||
) | ||
if err != nil { | ||
return webutils.LogAndRenderErrors(c, http.StatusUnprocessableEntity, err) | ||
} | ||
|
||
return c.JSON(http.StatusOK, page) | ||
} |
68 changes: 68 additions & 0 deletions
68
packages/eventindexer/http/get_by_address_and_event_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package http | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"math/big" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/cyberhorsey/webutils/testutils" | ||
"github.com/labstack/echo/v4" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/taikoxyz/taiko-mono/packages/eventindexer" | ||
) | ||
|
||
func Test_GetByAddressAndEvent(t *testing.T) { | ||
srv := newTestServer("") | ||
|
||
_, err := srv.eventRepo.Save(context.Background(), eventindexer.SaveEventOpts{ | ||
Name: "name", | ||
Data: `{"Owner": "0x0000000000000000000000000000000000000123"}`, | ||
ChainID: big.NewInt(167001), | ||
Address: "0x123", | ||
Event: eventindexer.EventNameBlockProposed, | ||
}) | ||
|
||
assert.Equal(t, nil, err) | ||
|
||
tests := []struct { | ||
name string | ||
address string | ||
event string | ||
wantStatus int | ||
wantBodyRegexpMatches []string | ||
}{ | ||
{ | ||
"successZeroEvents", | ||
"0xhasntProposedAnything", | ||
eventindexer.EventNameBlockProposed, | ||
http.StatusOK, | ||
[]string{`{"items":`}, | ||
}, | ||
{ | ||
"success", | ||
"0x123", | ||
eventindexer.EventNameBlockProposed, | ||
http.StatusOK, | ||
[]string{`{"items":`}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
req := testutils.NewUnauthenticatedRequest( | ||
echo.GET, | ||
fmt.Sprintf("/events?address=%v&event=%v", tt.address, tt.event), | ||
nil, | ||
) | ||
|
||
rec := httptest.NewRecorder() | ||
|
||
srv.ServeHTTP(rec, req) | ||
|
||
testutils.AssertStatusAndBody(t, rec, tt.wantStatus, tt.wantBodyRegexpMatches) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters