Skip to content

Commit

Permalink
test(boards2): add missing filetests for member role change (#3636)
Browse files Browse the repository at this point in the history
Add missing filetests for `ChangeMemberRole()` function.

Related to #3623

This covers all tests for the function:
- Successful role change for realm member
- Successful role change for board member
- Fail for an admin removing an owner role
- Fail for an admin changing a role to owner
- Success changing a role to owner by another owner
- Fail when role doesn't exist
- Fail when user is not found
- Fail for non member (unauthorized)
  • Loading branch information
jeronimoalbi authored Jan 30, 2025
1 parent dc173c2 commit 63007ab
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 38 deletions.
21 changes: 7 additions & 14 deletions examples/gno.land/r/nt/boards2/z_4_a_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import (
)

const (
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
member = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
initialRole = boards2.RoleGuest
newRole = boards2.RoleAdmin
bid = boards2.BoardID(0) // Operate on realm DAO members instead of individual boards
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
member = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
newRole = boards2.RoleAdmin
bid = boards2.BoardID(0) // Operate on realm DAO instead of individual boards
)

func init() {
Expand All @@ -20,17 +19,11 @@ func init() {
}

func main() {
if boards2.HasMemberRole(bid, member, initialRole) {
println("ok")
}

boards2.ChangeMemberRole(bid, member, newRole)

if boards2.HasMemberRole(bid, member, newRole) {
println("ok")
}
// Ensure that new role has been changed
println(boards2.HasMemberRole(bid, member, newRole))
}

// Output:
// ok
// ok
// true
23 changes: 8 additions & 15 deletions examples/gno.land/r/nt/boards2/z_4_b_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,25 @@ import (
)

const (
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
member = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
initialRole = boards2.RoleGuest
newRole = boards2.RoleAdmin
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
member = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
newRole = boards2.RoleAdmin
)

var bid boards2.BoardID
var bid boards2.BoardID // Operate on board DAO

func init() {
std.TestSetOrigCaller(owner)
bid = boards2.CreateBoard("foo123") // Operate on board DAO members
bid = boards2.CreateBoard("foo123")
boards2.InviteMember(bid, member, boards2.RoleGuest)
}

func main() {
if boards2.HasMemberRole(bid, member, initialRole) {
println("ok")
}

boards2.ChangeMemberRole(bid, member, newRole)

if boards2.HasMemberRole(bid, member, newRole) {
println("ok")
}
// Ensure that new role has been changed
println(boards2.HasMemberRole(bid, member, newRole))
}

// Output:
// ok
// ok
// true
2 changes: 1 addition & 1 deletion examples/gno.land/r/nt/boards2/z_4_c_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
owner2 = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
admin = std.Address("g1vh7krmmzfua5xjmkatvmx09z37w34lsvd2mxa5")
bid = boards2.BoardID(0) // Operate on realm DAO members instead of individual boards
bid = boards2.BoardID(0) // Operate on realm DAO instead of individual boards
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/nt/boards2/z_4_d_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
admin = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
admin2 = std.Address("g1vh7krmmzfua5xjmkatvmx09z37w34lsvd2mxa5")
bid = boards2.BoardID(0) // Operate on realm DAO members instead of individual boards
bid = boards2.BoardID(0) // Operate on realm DAO instead of individual boards
)

func init() {
Expand Down
17 changes: 10 additions & 7 deletions examples/gno.land/r/nt/boards2/z_4_e_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ import (
)

const (
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
admin = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
bid = boards2.BoardID(0) // Operate on realm DAO members instead of individual boards
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
member = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
bid = boards2.BoardID(0) // Operate on realm DAO members instead of individual boards
newRole = boards2.RoleOwner
)

func init() {
std.TestSetOrigCaller(owner)
boards2.InviteMember(bid, admin, boards2.RoleAdmin)
boards2.InviteMember(bid, member, boards2.RoleAdmin)
}

func main() {
boards2.ChangeMemberRole(bid, admin, boards2.RoleOwner) // Owner can promote other members to Owner
println("ok")
boards2.ChangeMemberRole(bid, member, newRole) // Owner can promote other members to Owner

// Ensure that new role has been changed to owner
println(boards2.HasMemberRole(bid, member, newRole))
}

// Output:
// ok
// true
20 changes: 20 additions & 0 deletions examples/gno.land/r/nt/boards2/z_4_h_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"std"

"gno.land/r/nt/boards2"
)

const owner = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2

func init() {
std.TestSetOrigCaller(owner)
}

func main() {
boards2.ChangeMemberRole(0, "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj", boards2.RoleGuest)
}

// Error:
// unauthorized

0 comments on commit 63007ab

Please sign in to comment.