-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
224e0a4
commit 6c52055
Showing
4 changed files
with
263 additions
and
1 deletion.
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,37 @@ | ||
package govdao | ||
import ( | ||
"std" | ||
) | ||
|
||
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 address != std.PrevRealm().Addr().String() { | ||
panic("caller is should be the claimer") | ||
} | ||
|
||
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.Write(ufmt.Sprintf("# GovDao Claimable tiers\n\n", name)) | ||
// res.Write(ufmt.Sprintf("To claim you tier you first need to link your account github\n", name)) | ||
// for handle,tier := range UserTiers { | ||
// res.Write(ufmt.Sprintf("- **%s**: %s\n", i, tier)) | ||
// } | ||
//} |
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,116 @@ | ||
package govdao | ||
import ( | ||
"testing" | ||
"strings" | ||
"gno.land/p/demo/testutils" | ||
"gno.land/p/teritori/basedao" | ||
"gno.land/p/demo/urequire" | ||
"gno.land/p/demo/ufmt" | ||
"std" | ||
) | ||
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 not the claimer":{ | ||
panicError: "caller is should be the claimer", | ||
githubHandle: ghHandle, | ||
seedContent: map[string]string{ | ||
ghHandle: "T1", | ||
}, | ||
getAddressByHandleFunc: allVerified, | ||
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") | ||
} | ||
} | ||
}() | ||
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())) | ||
} | ||
}) | ||
} | ||
} |
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,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", | ||
} |