-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 'TestTransferOwnership' don't pass * add test for func TransferOwnership * fist test for func TestTransferOwnership * func TestTransferOwnership PASS * func TestTransferOwnership PASS --------- Co-authored-by: théo dub <[email protected]>
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
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 memeland | ||
|
||
import ( | ||
"std" | ||
"testing" | ||
"time" | ||
"sort" | ||
|
||
"gno.land/p/demo/memeland" | ||
"gno.land/p/demo/testutils" | ||
) | ||
|
||
func TestPostMeme(t *testing.T) { | ||
m := memeland.NewMemeland() | ||
data := "Test meme data" | ||
timestamp := time.Now().Unix() | ||
id := m.PostMeme(data, timestamp) | ||
if id == "" { | ||
t.Errorf("Expected valid ID, got empty string") | ||
} | ||
} | ||
|
||
|
||
func TestUpvote(t *testing.T) { | ||
m := memeland.NewMemeland() | ||
id := m.PostMeme("Another test meme", time.Now().Unix()) | ||
result := m.Upvote(id) | ||
if result != "upvote successful" { | ||
t.Errorf("Expected 'upvote successful', got %s", result) | ||
} | ||
} | ||
|
||
|
||
func TestGetPostsInRange(t *testing.T) { | ||
m := memeland.NewMemeland() | ||
startTimestamp := time.Now().Add(-24 * time.Hour).Unix() | ||
endTimestamp := time.Now().Unix() | ||
page, pageSize := 1, 10 | ||
sortBy := "DATE_CREATED" | ||
m.PostMeme("Old Meme", startTimestamp-10) | ||
m.PostMeme("New Meme", endTimestamp-10) | ||
result := m.GetPostsInRange(startTimestamp, endTimestamp, page, pageSize, sortBy) | ||
if result == "" || result == "[]" { | ||
t.Errorf("Expected non-empty result, got %s", result) | ||
} | ||
} | ||
|
||
|
||
func TestRemovePost(t *testing.T) { | ||
m := memeland.NewMemeland() | ||
id := m.PostMeme("Meme to be deleted", time.Now().Unix()) | ||
removedID := m.RemovePost(id) | ||
if removedID != id { | ||
t.Errorf("Expected %s to be removed, got %s", id, removedID) | ||
} | ||
} | ||
|
||
func TestTransferOwnership(t *testing.T) { | ||
m := memeland.NewMemeland() | ||
newOwner := testutils.TestAddress("g1newowneraddress") | ||
err := m.TransferOwnership(std.Address(newOwner)) | ||
if err != nil { | ||
t.Errorf("Expected no error, got %s", err) | ||
} | ||
if m.Owner() != std.Address(newOwner) { | ||
t.Errorf("Expected new owner to be %s, got %s", newOwner, m.Owner()) | ||
} | ||
} |