Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Claim tiers functionality #1506

Merged
merged 7 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions gno/r/govdao/claim.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package govdao

import (
"gno.land/p/demo/mux"
"gno.land/p/demo/ufmt"
)

const CLAIM_PATH = "claim"

func ClaimTier(handle string) {
tier := UserTiers[handle]
if tier == "" {
panic("user does not have a assigned tier")
}

address := getAddressByHandle(handle)
if address == "" {
panic("user address is not yet verified")
}

if dao.Members.IsMember(address) {
panic("user already claimed his tier")
}

dao.Members.AddMember(address, []string{tier})

// Remove github handle from claimable tiers
delete(UserTiers, handle)
}

func renderClaimableTiers(res *mux.ResponseWriter, req *mux.Request) {
res.Write("# GovDao Claimable tiers\n\n")
res.Write("To claim you tier you first need to link your account github\n")
for handle, tier := range UserTiers {
res.Write(ufmt.Sprintf("- **%s**: %s\n", handle, tier))
}
}
111 changes: 111 additions & 0 deletions gno/r/govdao/claim_test.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package govdao

import (
"std"
"testing"

"gno.land/p/demo/testutils"
"gno.land/p/demo/ufmt"
"gno.land/p/demo/urequire"
"gno.land/p/teritori/basedao"
)

var (
addr1 = testutils.TestAddress("test1")
someCaller = testutils.TestAddress("callerx")
nobodyVerified = func(string) string { return "" }
allVerified = func(login string) string { return addr1.String() }
)

func TestClaimTier(t *testing.T) {
const ghHandle = "villaquiranm"
type claimTest struct {
panicError string
githubHandle string
seedContent map[string]string
getAddressByHandleFunc func(string) string
caller std.Address
alreadyMember bool
expectNewMember bool
}

tests := map[string]claimTest{
"handle is not present on seed": {
panicError: "user does not have a assigned tier",
githubHandle: ghHandle,
seedContent: map[string]string{},
caller: someCaller,
},
"user is not yet verified": {
panicError: "user address is not yet verified",
githubHandle: ghHandle,
seedContent: map[string]string{
ghHandle: "T1",
},
getAddressByHandleFunc: nobodyVerified,
caller: someCaller,
},
"caller is already member": {
panicError: "user already claimed his tier",
githubHandle: ghHandle,
seedContent: map[string]string{
ghHandle: "T1",
},
getAddressByHandleFunc: allVerified,
caller: addr1,
alreadyMember: true,
},
"OK": {
panicError: "",
githubHandle: ghHandle,
seedContent: map[string]string{
ghHandle: "T1",
},
getAddressByHandleFunc: allVerified,
caller: addr1,
expectNewMember: true,
},
}

for tName, testData := range tests {
t.Run(tName, func(t *testing.T) {
defer func() {
err := recover()
if err != nil {
ufmt.Println(err)
errStr := err.(string)
if testData.panicError != errStr {
t.Error("expected error got nil")
}
} else {
urequire.Equal(t, "", testData.panicError)
}
}()
initialRoles := []string{"T1", "T2", "T3"}
initialMembers := []basedao.Member{}

if testData.alreadyMember {
initialMembers = append(initialMembers, basedao.Member{Address: addr1.String(), Roles: []string{"T1"}})
}

dao = basedao.New(&basedao.Config{
Name: "GovDAO",
Description: "This is a GovDAO demo",
NoDefaultHandlers: true,
Members: basedao.NewMembersStore(initialRoles, initialMembers),
GetProfileString: func(std.Address, string, string) string { return "" },
})

UserTiers = testData.seedContent
getAddressByHandle = testData.getAddressByHandleFunc

std.TestSetOrigCaller(testData.caller)

ClaimTier(testData.githubHandle)

if testData.expectNewMember {
urequire.True(t, dao.Members.IsMember(testData.caller.String()))
}
})
}
}
8 changes: 7 additions & 1 deletion gno/r/govdao/govdao.gno
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"gno.land/p/teritori/daocond"
"gno.land/p/teritori/daokit"
"gno.land/r/demo/profile"
"gno.land/r/gnoland/ghverify"
)

const (
Expand All @@ -13,7 +14,10 @@ const (
Tier3 = "T3"
)

var dao *basedao.DAO
var (
dao *basedao.DAO
getAddressByHandle func(handle string) string
)

func init() {
initialRoles := []string{Tier1, Tier2, Tier3}
Expand Down Expand Up @@ -53,6 +57,8 @@ func init() {
for _, r := range resources {
dao.Core.SetResource(r)
}
getAddressByHandle = ghverify.GetAddressByHandle
dao.RenderRouter.HandleFunc(CLAIM_PATH, renderClaimableTiers)
}

func Propose(proposal daokit.ProposalRequest) {
Expand Down
104 changes: 104 additions & 0 deletions gno/r/govdao/seed.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package govdao

var UserTiers = map[string]string{
"moul": "T1",
"jaekwon": "T1",
"thehowl": "T1",
"zivkovicmilos": "T1",
"leohhhn": "T1",
"gfanton": "T1",
"harry-hov": "T1",
"deelawn": "T1",
"ajnavarro": "T1",
"ltzmaxwell": "T1",
"tbruyelle": "T2",
"r3v4s": "T2",
"notJoon": "T2",
"albttx": "T2",
"omarsy": "T2",
"piux2": "T2",
"aeddi": "T2",
"jefft0": "T2",
"n0izn0iz": "T2",
"alexiscolin": "T2",
"mvertes": "T2",
"petar-dambovaliev": "T2",
"Villaquiranm": "T2",
"grepsuzette": "T2",
"odeke-em": "T2",
"sw360cab": "T2",
"linhpn99": "T2",
"waymobetta": "T2",
"jeronimoalbi": "T2",
"kazai777": "T2",
"hthieu1110": "T2",
"stefann-01": "T2",
"Kouteki": "T2",
"MikaelVallenet": "T2",
"MalekLahbib": "T2",
"schollz": "T2",
"agherasie": "T2",
"kristovatlas": "T2",
"n2p5": "T2",
"faddat": "T2",
"x1unix": "T3",
"wyhaines": "T3",
"anarcher": "T3",
"RezaRahemtola": "T3",
"thinhnx-var": "T3",
"giansalex": "T3",
"peter7891": "T3",
"sunspirit99": "T3",
"ilgooz": "T3",
"salmad3": "T3",
"matijamarjanovic": "T3",
"michelleellen": "T3",
"mazzy89": "T3",
"D4ryl00": "T3",
"pushkar803": "T3",
"DIGIX666": "T3",
"JJOptimist": "T3",
"iuricmp": "T3",
"Nemanya8": "T3",
"yassinouider": "T3",
"alikhil": "T3",
"WALL-E": "T3",
"irreverentsimplicity": "T3",
"mous1985": "T3",
"Halimao": "T3",
"masonmcbride": "T3",
"wolkykim": "T3",
"lumtis": "T3",
"jinoosss": "T3",
"Ursulovic": "T3",
"omahs": "T3",
"tranhoaison": "T3",
"adr-sk": "T3",
"loicttn": "T3",
"nir1218": "T3",
"nettijoe96": "T3",
"wwqiu": "T3",
"Jammyaa": "T3",
"Molaryy": "T3",
"gfant": "T3",
"MichaelFrazzy": "T3",
"amritkumarj": "T3",
"0xtekgrinder": "T3",
"jubnzv": "T3",
"KemalBekir": "T3",
"biki-cloud": "T3",
"Milerius": "T3",
"jackthgu": "T3",
"Ticojohnny": "T3",
"inFocus7": "T3",
"Dedok1": "T3",
"qdm12": "T3",
"poroburu": "T3",
"GoodDaisy": "T3",
"eltociear": "T3",
"rusttech": "T3",
"0xbeny": "T3",
"Juneezee": "T3",
"mdqst": "T3",
"mariajdab": "T3",
}
Loading