Skip to content

Commit

Permalink
feat(boards2): add freeze tests
Browse files Browse the repository at this point in the history
  • Loading branch information
x1unix committed Feb 25, 2025
1 parent add669f commit 69c3c63
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/gno.land/r/nt/boards2/v1/z_19_a_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"std"

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

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

var (
bid boards2.BoardID
tid boards2.PostID
)

func init() {
std.TestSetOriginCaller(owner)
bid = boards2.CreateBoard("test123")
tid = boards2.CreateThread(bid, "foo", "bar")

boards2.FreezeBoard(bid)
}

func main() {
// Attempt to freeze a thread on frozen board
boards2.FreezeThread(bid, tid)
}

// Error:
// board is frozen
30 changes: 30 additions & 0 deletions examples/gno.land/r/nt/boards2/v1/z_19_b_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"std"

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

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

var (
bid boards2.BoardID
tid boards2.PostID
)

func init() {
std.TestSetOriginCaller(owner)
bid = boards2.CreateBoard("test123")
tid = boards2.CreateThread(bid, "foo", "bar")

boards2.FreezeThread(bid, tid)
}

func main() {
// Attempt to freeze a frozen thread
boards2.FreezeThread(bid, tid)
}

// Error:
// thread is frozen
30 changes: 30 additions & 0 deletions examples/gno.land/r/nt/boards2/v1/z_19_c_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"std"

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

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

var (
bid boards2.BoardID
tid boards2.PostID
)

func init() {
std.TestSetOriginCaller(owner)
bid = boards2.CreateBoard("test123")
tid = boards2.CreateThread(bid, "foo", "bar")
}

func main() {
println(boards2.IsThreadFrozen(bid, tid))
boards2.FreezeThread(bid, tid)
println(boards2.IsThreadFrozen(bid, tid))
}

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

import (
"std"

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

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

var (
bid boards2.BoardID
tid boards2.PostID
)

func init() {
std.TestSetOriginCaller(owner)
bid = boards2.CreateBoard("test123")
tid = boards2.CreateThread(bid, "foo", "bar")
boards2.FreezeThread(bid, tid)
}

func main() {
// cannot reply to a frozen thread
boards2.CreateReply(bid, tid, 0, "foobar")
}

// Error:
// thread is frozen
32 changes: 32 additions & 0 deletions examples/gno.land/r/nt/boards2/v1/z_20_a_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"std"

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

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

var (
bid boards2.BoardID
tid boards2.PostID
rid boards2.PostID
)

func init() {
std.TestSetOriginCaller(owner)
bid = boards2.CreateBoard("test123")
tid = boards2.CreateThread(bid, "foo", "bar")
rid = boards2.CreateReply(bid, tid, 0, "reply")

boards2.FreezeThread(bid, tid)
}

func main() {
// Attempt to freeze a reply on frozen thread
boards2.FreezeReply(bid, tid, rid)
}

// Error:
// thread is frozen
32 changes: 32 additions & 0 deletions examples/gno.land/r/nt/boards2/v1/z_20_b_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"std"

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

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

var (
bid boards2.BoardID
tid boards2.PostID
rid boards2.PostID
)

func init() {
std.TestSetOriginCaller(owner)
bid = boards2.CreateBoard("test123")
tid = boards2.CreateThread(bid, "foo", "bar")
rid = boards2.CreateReply(bid, tid, 0, "reply")

boards2.FreezeReply(bid, tid, rid)
}

func main() {
// Attempt to freeze already frozen reply
boards2.FreezeReply(bid, tid, rid)
}

// Error:
// reply is frozen
52 changes: 52 additions & 0 deletions examples/gno.land/r/nt/boards2/v1/z_20_c_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"std"

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

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

var (
bid boards2.BoardID
tid boards2.PostID
rid boards2.PostID
)

func init() {
std.TestSetOriginCaller(owner)
bid = boards2.CreateBoard("test123")
tid = boards2.CreateThread(bid, "foo", "bar")
rid = boards2.CreateReply(bid, tid, 0, "reply")
}

func main() {
// reply frozen
println(boards2.IsReplyFrozen(bid, tid, rid))
boards2.FreezeReply(bid, tid, rid)
println(boards2.IsReplyFrozen(bid, tid, rid))
boards2.UnfreezeReply(bid, tid, rid)
println(boards2.IsReplyFrozen(bid, tid, rid))

// thread frozen
boards2.FreezeThread(bid, tid)
println(boards2.IsReplyFrozen(bid, tid, rid))
boards2.UnfreezeThread(bid, tid)
println(boards2.IsReplyFrozen(bid, tid, rid))

// board frozen
boards2.FreezeBoard(bid)
println(boards2.IsReplyFrozen(bid, tid, rid))
boards2.UnfreezeBoard(bid)
println(boards2.IsReplyFrozen(bid, tid, rid))
}

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

import (
"std"

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

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

var (
bid boards2.BoardID
tid boards2.PostID
rid boards2.PostID
)

func init() {
std.TestSetOriginCaller(owner)
bid = boards2.CreateBoard("test123")
tid = boards2.CreateThread(bid, "foo", "bar")
rid = boards2.CreateReply(bid, tid, 0, "reply")
}

func main() {
// unfrozen thread - should work
r2 := boards2.CreateReply(bid, tid, rid, "child 1")

// frozen thread - can't reply
boards2.FreezeReply(bid, tid, rid)
boards2.CreateReply(bid, tid, r2, "child 2")
}

// Error:
// reply is frozen

0 comments on commit 69c3c63

Please sign in to comment.