Skip to content

Commit

Permalink
feat: done flag post + exec
Browse files Browse the repository at this point in the history
  • Loading branch information
hthieu1110 committed Aug 22, 2023
1 parent c5b3f9f commit ea6a39b
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 20 deletions.
42 changes: 42 additions & 0 deletions examples/gno.land/r/demo/social_feeds/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,47 @@ flag_post:
get_post:
gnokey query vm/qeval --data 'gno.land/r/demo/social_feeds\nGetPosts(1, "", []uint64{}, 0, 10)'

.PHONY: propose_ban_post
propose_ban_post:
${GNOKEY} \
-pkgpath "gno.land/r/demo/social_feeds_dao" \
-func "Propose" \
-args "0" \
-args "Ban Post" \
-args "" \
-args "" \
${KEY}

.PHONY: vote_yes
vote_yes:
${GNOKEY} \
-pkgpath "gno.land/r/demo/social_feeds_dao" \
-func "Vote" \
-args "0" \
-args "0" \
-args "0" \
-args "This is not good" \
${KEY}

.PHONY: execute_proposal
execute_proposal:
${GNOKEY} \
-pkgpath "gno.land/r/demo/social_feeds_dao" \
-func "Execute" \
-args "0" \
-args "0" \
${KEY}

.PHONY: add_member
add_member:
${GNOKEY} \
-pkgpath "gno.land/r/demo/groups_v6" \
-func "AddMember" \
-args "0000000001" \
-args "g1kcdd3n0d472g2p5l8svyg9t0wq6h5857nq992f" \
-args "1" \
-args "" \
${KEY}

.PHONY: init
init: create_feed create_post create_post tip_post flag_post
3 changes: 2 additions & 1 deletion examples/gno.land/r/demo/social_feeds/feed.gno
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ func (feed *Feed) Render() string {
pkgpath := std.CurrentRealmPath()

str := ""
str += "There are " + intToString(feed.posts.Size()) + " post(s) \n\n"
str += ufmt.Sprintf("Feed: %s (ID: %s) - Owner: %s", feed.name, feed.id, feed.owner)
str += "\n\n There are " + intToString(feed.posts.Size()) + " post(s) \n\n"

if feed.posts.Size() > 0 {
feed.posts.Iterate("", "", func(key string, value interface{}) bool {
Expand Down
27 changes: 9 additions & 18 deletions examples/gno.land/r/demo/social_feeds/feeds_test.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package social_feeds

// SEND: 200000000ugnot

import (
"encoding/base64"
"std"
Expand Down Expand Up @@ -37,15 +35,16 @@ func getPost1() *Post {
}

func testCreateFeed(t *testing.T) {
feedID := CreateFeed("teritori")
feedID := CreateFeed("teritori1")
feed := mustGetFeed(feedID)

if feedID != 1 {
t.Fatalf("expected feedID: 1, got %q.", feedID)
// We have default teritori feed so total should be 2
if feedID != 2 {
t.Fatalf("expected feedID: 2, got %q.", feedID)
}

if feed.name != "teritori" {
t.Fatalf("expected feedName: teritori, got %q.", feed.name)
if feed.name != "teritori1" {
t.Fatalf("expected feedName: teritori1, got %q.", feed.name)
}
}

Expand Down Expand Up @@ -439,15 +438,6 @@ func testHidePostForMe(t *testing.T) {
}

func Test(t *testing.T) {
// Setup ================================================================
// NOTE: Dont know why std.GetOrigCaller in users.Register is always = std.GetCallerAt(1) here
admin := std.GetCallerAt(1)

std.TestSetOrigCaller(admin)
std.TestSetOrigSend(std.Coins{{"ugnot", 200_000_000}}, nil)

users.Register("", "social_feeds_admin", "")

testCreateFeed(t)

testCreatePost(t)
Expand All @@ -464,7 +454,8 @@ func Test(t *testing.T) {

testFlagPost(t)

testMigrate(t)

testHidePostForMe(t)

// TODO: complete migration when having time
// testMigrate(t)
}
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/social_feeds/messages.gno
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ExecutableMessageBanPost struct {
}

func (msg *ExecutableMessageBanPost) Type() string {
return PKG_PATH + ".BanPost"
return "BanPost"
}

func (msg *ExecutableMessageBanPost) String() string {
Expand Down
1 change: 1 addition & 0 deletions examples/gno.land/r/demo/social_feeds_dao/gno.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module gno.land/r/demo/social_feeds_dao

require (

)
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@ var (
)

func init() {
// NOTE: why creator is: g16lcthjkpr9emfj2yemnsfmyc563jw98p4wwvgg ??????
groupID = groups.CreateGroup(mainFeedName)

// Create Feed
currentRealm := std.CurrentRealm()
feedID := social_feeds.CreateFeed(mainFeedName)

// For testing purpose we add 2 users
groups.AddMember(groupID, "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5", 1, "")
groups.AddMember(groupID, "g1kcdd3n0d472g2p5l8svyg9t0wq6h5857nq992f", 1, "")

registry.Register(groups.NewAddMemberHandler())
registry.Register(groups.NewDeleteMemberHandler())

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package social_feeds_dao

import (
"testing"
)

// var (
// rootPostID = PostID(0)
// postID1 = PostID(1)
// feedID1 = FeedID(1)
// cat1 = uint64(1)
// cat2 = uint64(2)
// user = testutils.TestAddress("user")
// filter_all = []uint64{}
// )

func Test(t *testing.T) {
// Prepare feed, post
// feedID := CreateFeed("teritori")
// feed := mustGetFeed(feedID)

// // Create Posts
// postToBanID := CreatePost(feed.id, rootPostID, cat1, "metadata1")
// CreatePost(feed.id, rootPostID, cat1, "metadata2")

// Make proposal
// Propose(0, "Ban Post "+postToBanID.String(), "We want to delete this post", "")
}

0 comments on commit ea6a39b

Please sign in to comment.