PathrockNetwork Gno Explorer
HomeBlocksTransactionsRealmsPackagesValidators

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/p/gnoland/boards/exts/hub/v0

Package
Open in gnoweb ↗

Overview

Kind
Pure package
Name
v0
Namespace
gnoland / boards / exts / hub
Files
12 (README)(gnomod.toml)
Exported functions
n/a — not supported for pure packages by the node (vm/qfuncs)
Module
gno.land/p/gnoland/boards/exts/hub/v0
gno
0.9

Files (12)

  • README.mdmarkdown
  • gnomod.tomltoml
  • board.gnogno
  • comment.gnogno
  • flag.gnogno
  • format.gnogno
  • member.gnogno
  • thread.gnogno
  • board_test.gnogno
  • comment_test.gnogno
  • member_test.gnogno
  • thread_test.gnogno
  • thread_test.gnogno
    1package hub_test23import (4	"testing"56	"gno.land/p/gnoland/boards/exts/hub/v0"7	"gno.land/p/gnoland/boards/v0"8

    Functions

    not supported for pure packages by the node (vm/qfuncs)

    Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.

    "gno.land/p/nt/urequire/v0"
    9)
    10
    11func TestNewSafeThread(t *testing.T) {
    12 board := boards.New(1)
    13 ref := boards.MustNewThread(board, alice, "Title", "Body")
    14 ref.Flags.Add(boards.Flag{User: bob, Reason: "Spam"})
    15
    16 thread := hub.NewSafeThread(ref)
    17
    18 urequire.Equal(t, uint64(ref.ID), thread.ID(), "expect ID to match")
    19 urequire.Equal(t, uint64(1), thread.BoardID(), "expect board ID to match")
    20 urequire.Equal(t, "Title", thread.Title(), "expect title to match")
    21 urequire.Equal(t, "Body", thread.Body(), "expect body to match")
    22 urequire.Equal(t, alice, thread.Creator(), "expect creator to match")
    23 urequire.False(t, thread.Hidden(), "expect thread not to be hidden")
    24 urequire.False(t, thread.Readonly(), "expect thread not to be readonly")
    25 urequire.Equal(t, 0, thread.CommentCount(), "expect no comments")
    26 urequire.Equal(t, 0, thread.RepostCount(), "expect no reposts")
    27 urequire.Equal(t, 1, thread.FlagCount(), "expect one flag")
    28 urequire.Equal(t, testTime, thread.CreatedAt(), "expect creation time to match")
    29 urequire.Equal(t, int64(0), thread.UpdatedAt(), "expect zero update time to map to zero")
    30}
    31
    32func TestNewSafeThreadCounts(t *testing.T) {
    33 board := boards.New(1)
    34 ref := boards.MustNewThread(board, alice, "Title", "Body")
    35 ref.Replies.Add(boards.MustNewReply(ref, bob, "Comment 1"))
    36 ref.Replies.Add(boards.MustNewReply(ref, bob, "Comment 2"))
    37
    38 thread := hub.NewSafeThread(ref)
    39
    40 urequire.Equal(t, 2, thread.CommentCount(), "expect comment count to match")
    41 urequire.Equal(t, 0, thread.FlagCount(), "expect no flags")
    42}
    43
    44// TestNewSafeThreadNilStorages covers the branches that skip counting when a
    45// post carries no reply, repost or flag storage.
    46func TestNewSafeThreadNilStorages(t *testing.T) {
    47 ref := &boards.Post{ID: 1, ThreadID: 1, Board: boards.New(1)}
    48
    49 thread := hub.NewSafeThread(ref)
    50
    51 urequire.Equal(t, 0, thread.CommentCount(), "expect no comments")
    52 urequire.Equal(t, 0, thread.RepostCount(), "expect no reposts")
    53 urequire.Equal(t, 0, thread.FlagCount(), "expect no flags")
    54 urequire.Equal(t, int64(0), thread.CreatedAt(), "expect zero creation time to map to zero")
    55}
    56
    57func TestNewSafeThreadRejectsInvalidRefs(cur realm, t *testing.T) {
    58 board := boards.New(1)
    59 thread := boards.MustNewThread(board, alice, "Title", "Body")
    60 comment := boards.MustNewReply(thread, alice, "Comment")
    61
    62 urequire.PanicsWithMessage(t, cur, "post reference is nil", func() {
    63 hub.NewSafeThread(nil)
    64 }, "expect a nil post reference to be rejected")
    65
    66 urequire.PanicsWithMessage(t, cur, "post is not a thread", func() {
    67 hub.NewSafeThread(comment)
    68 }, "expect a comment to be rejected")
    69}
    70
    71func TestNewSafeFlag(t *testing.T) {
    72 flag := hub.NewSafeFlag(boards.Flag{User: alice, Reason: "Spam"})
    73
    74 urequire.Equal(t, alice, flag.User(), "expect user to match")
    75 urequire.Equal(t, "Spam", flag.Reason(), "expect reason to match")
    76}
    77