Skip to content

Commit

Permalink
test(boards2): add missing filetests for board rename (#3625)
Browse files Browse the repository at this point in the history
Add a missing filetests for `RenameBoard()` function.

Related to #3623.

This covers all tests for the function:
- Rename success by default board owner
- Fail w/ empty board name
- Fail w/ existing board name
- Fail when renaming unexisting board
- Fail w/ an address as board name
- Rename success by another board owner
- Fail because name is registered and not owned in `users` realm
- Fail w/ short name
- Rename success with owned name registered in `users` realm
- Fail for non board DAO member
  • Loading branch information
jeronimoalbi authored Jan 28, 2025
1 parent 69960ec commit 33fb889
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 32 deletions.
21 changes: 10 additions & 11 deletions examples/gno.land/r/nt/boards2/z_3_a_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ import (
)

const (
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
name = "foo123"
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
name = "foo123"
newName = "bar123"
)

var bid boards2.BoardID // Operate on board DAO

func init() {
std.TestSetOrigCaller(owner)
boards2.CreateBoard(name)
bid = boards2.CreateBoard(name)
}

func main() {
newName := "bar123"
_, exists := boards2.GetBoardIDFromName(newName)
println("Exists =", exists)

boards2.RenameBoard(name, newName)

bid, _ := boards2.GetBoardIDFromName(newName)
println("ID =", bid)
// Ensure board is renamed by the default board owner
bid2, _ := boards2.GetBoardIDFromName(newName)
println("IDs match =", bid == bid2)
}

// Output:
// Exists = false
// ID = 1
// IDs match = true
20 changes: 9 additions & 11 deletions examples/gno.land/r/nt/boards2/z_3_f_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,31 @@ import (
const (
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
member = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
bid = boards2.BoardID(0) // Operate on realm DAO members instead of individual boards
name = "foo123"
newName = "barbaz"
)

var bid boards2.BoardID // Operate on board DAO

func init() {
std.TestSetOrigCaller(owner)

bid = boards2.CreateBoard(name)
boards2.InviteMember(bid, member, boards2.RoleOwner)

// Test1 is the boards owner and its address has a user already registered
// so a new member must register a user with the new board name.
boards2.InviteMember(bid, member, boards2.RoleOwner)
std.TestSetOrigCaller(member)
users.Register("", newName, "")

boards2.CreateBoard(name)
}

func main() {
_, exists := boards2.GetBoardIDFromName(newName)
println("Exists =", exists)

boards2.RenameBoard(name, newName)

bid, _ := boards2.GetBoardIDFromName(newName)
println("ID =", bid)
// Ensure board is renamed by another board owner
bid2, _ := boards2.GetBoardIDFromName(newName)
println("IDs match =", bid == bid2)
}

// Output:
// Exists = false
// ID = 1
// IDs match = true
15 changes: 5 additions & 10 deletions examples/gno.land/r/nt/boards2/z_3_g_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,30 @@ const (
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
member = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
member2 = std.Address("g1vh7krmmzfua5xjmkatvmx09z37w34lsvd2mxa5")
bid = boards2.BoardID(0) // Operate on realm DAO members instead of individual boards
name = "foo123"
newName = "barbaz"
)

var bid boards2.BoardID // Operate on board DAO

func init() {
std.TestSetOrigCaller(owner)

bid = boards2.CreateBoard(name)
boards2.InviteMember(bid, member, boards2.RoleOwner)

// Test1 is the boards owner and its address has a user already registered
// so a new member must register a user with the new board name.
boards2.InviteMember(bid, member, boards2.RoleOwner)
std.TestSetOrigCaller(member)
users.Register("", newName, "")

// Invite a new member that doesn't own the user that matches the new board name
boards2.InviteMember(bid, member2, boards2.RoleOwner)
std.TestSetOrigCaller(member2)

boards2.CreateBoard(name)
}

func main() {
_, exists := boards2.GetBoardIDFromName(newName)
println("Exists =", exists)

boards2.RenameBoard(name, newName)

bid, _ := boards2.GetBoardIDFromName(newName)
println("ID =", bid)
}

// Error:
Expand Down
24 changes: 24 additions & 0 deletions examples/gno.land/r/nt/boards2/z_3_h_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"std"

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

const (
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
name = "foo123"
)

func init() {
std.TestSetOrigCaller(owner)
boards2.CreateBoard(name)
}

func main() {
boards2.RenameBoard(name, "short")
}

// Error:
// the minimum allowed board name length is 6 characters
43 changes: 43 additions & 0 deletions examples/gno.land/r/nt/boards2/z_3_i_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

// SEND: 200000000ugnot

import (
"std"

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

const (
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
member = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
member2 = std.Address("g1vh7krmmzfua5xjmkatvmx09z37w34lsvd2mxa5")
name = "foo123"
newName = "barbaz"
)

var bid boards2.BoardID // Operate on board DAO

func init() {
std.TestSetOrigCaller(owner)

bid = boards2.CreateBoard(name)
boards2.InviteMember(bid, member, boards2.RoleOwner)

// Test1 is the boards owner and its address has a user already registered
// so a new member must register a user with the new board name.
std.TestSetOrigCaller(member)
users.Register("", newName, "")

// Invite a new member that doesn't own the user that matches the new board name
boards2.InviteMember(bid, member2, boards2.RoleOwner)
std.TestSetOrigCaller(member2)
}

func main() {
boards2.RenameBoard(name, newName)
}

// Error:
// board name is a user name registered to a different user
27 changes: 27 additions & 0 deletions examples/gno.land/r/nt/boards2/z_3_j_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"std"

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

const (
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
user = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2
name = "foo123"
)

func init() {
std.TestSetOrigCaller(owner)
boards2.CreateBoard(name)

std.TestSetOrigCaller(user)
}

func main() {
boards2.RenameBoard(name, "barbaz")
}

// Error:
// unauthorized

0 comments on commit 33fb889

Please sign in to comment.