diff --git a/api/p/memeland/memeland.gno b/api/p/memeland/memeland.gno index b154d85..011a3cc 100644 --- a/api/p/memeland/memeland.gno +++ b/api/p/memeland/memeland.gno @@ -72,6 +72,10 @@ func (m *Memeland) Upvote(id string) string { // GetPostsInRange returns a JSON string of posts within the given timestamp range, supporting pagination. func (m *Memeland) GetPostsInRange(startTimestamp, endTimestamp int64, page, pageSize int, sortBy string) string { + if len(m.Posts) == 0 { + return "[]" + } + if page < 1 { panic("page count cannot be less than 1") } diff --git a/api/p/memeland/memeland_test.gno b/api/p/memeland/memeland_test.gno index 7ff7e80..92bb8da 100644 --- a/api/p/memeland/memeland_test.gno +++ b/api/p/memeland/memeland_test.gno @@ -199,6 +199,20 @@ func TestGetPostsInRangeByUpvote(t *testing.T) { } } +func TestNoPosts(t *testing.T) { + m := NewMemeland() + + // Add a post to Memeland + now := time.Now().Unix() + + jsonStr := m.GetPostsInRange(0, now, 1, 1, "DATE_CREATED") + + if jsonStr != "[]" { + t.Errorf("Expected 0 posts to return [], got %s", jsonStr) + } + +} + func TestUpvote(t *testing.T) { m := NewMemeland()