PathrockNetwork Gno Explorer
HomeBlocksTransactionsTokensRealmsPackagesValidatorsAnalytics

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/v0

Package
Open in gnoweb ↗

Overview

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

Files (22)

  • gnomod.tomltoml
  • board.gnogno
  • flag_storage.gnogno
  • id.gnogno
  • permission_set.gnogno
  • permissions.gnogno
  • post_storage.gnogno
  • post.gnogno
  • reply.gnogno
  • repost_storage.gnogno
  • storage.gnogno
  • thread.gnogno
  • board_test.gnogno
  • flag_storage_test.gnogno
  • id_test.gnogno
  • permission_set_test.gnogno
  • post_storage_test.gnogno
  • post_test.gnogno
  • reply_test.gnogno
  • repost_storage_test.gnogno
  • storage_test.gnogno
  • thread_test.gnogno
  • thread_test.gnogno
    1package boards_test23import (4	"testing"56	"gno.land/p/nt/urequire/v0"78

    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/gnoland/boards/v0"
    9)
    10
    11func TestNewThread(t *testing.T) {
    12 tests := []struct {
    13 name string
    14 board *boards.Board
    15 creator address
    16 title, body string
    17 errMsg string
    18 }{
    19 {
    20 name: "ok",
    21 board: boards.New(1),
    22 creator: "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",
    23 title: "Test",
    24 body: "Foo",
    25 },
    26 {
    27 name: "nil board",
    28 board: nil,
    29 errMsg: "thread requires a parent board",
    30 },
    31 {
    32 name: "invalid creator",
    33 board: boards.New(1),
    34 creator: "foo",
    35 errMsg: "invalid thread creator address: foo",
    36 },
    37 {
    38 name: "empty title",
    39 board: boards.New(1),
    40 creator: "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",
    41 title: "",
    42 errMsg: "thread title is required",
    43 },
    44 {
    45 name: "empty body",
    46 board: boards.New(1),
    47 creator: "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",
    48 title: "Test",
    49 body: "",
    50 errMsg: "thread body is required",
    51 },
    52 }
    53
    54 for _, tt := range tests {
    55 t.Run(tt.name, func(t *testing.T) {
    56 thread, err := boards.NewThread(tt.board, tt.creator, tt.title, tt.body)
    57
    58 if tt.errMsg != "" {
    59 urequire.Error(t, err, "expect an error")
    60 urequire.ErrorContains(t, err, tt.errMsg, "expect error to match")
    61 return
    62 }
    63
    64 urequire.NoError(t, err, "expect no error")
    65 urequire.True(t, tt.board.ThreadsSequence.Last() == thread.ID, "expect ID to match")
    66 urequire.True(t, thread.ThreadID == thread.ID, "expect thread ID to match")
    67 urequire.False(t, thread.Board == nil, "expect board to be assigned")
    68 urequire.True(t, tt.board.ID == thread.Board.ID, "expect board ID to match")
    69 urequire.Equal(t, tt.title, thread.Title, "expect title to match")
    70 urequire.Equal(t, tt.body, thread.Body, "expect body to match")
    71 urequire.True(t, thread.Replies != nil, "expect thread to support sub-replies")
    72 urequire.True(t, thread.Reposts != nil, "expect thread to support reposts")
    73 urequire.True(t, thread.Flags != nil, "expect thread to support flagging")
    74 urequire.Equal(t, tt.creator, thread.Creator, "expect creator to match")
    75 urequire.False(t, thread.CreatedAt.IsZero(), "expect creation date to be assigned")
    76 })
    77 }
    78}
    79
    80func TestNewRepost(t *testing.T) {
    81 tests := []struct {
    82 name string
    83 origThread *boards.Post
    84 dstBoard *boards.Board
    85 creator address
    86 errMsg string
    87 }{
    88 {
    89 name: "ok",
    90 origThread: boards.MustNewThread(
    91 boards.New(1),
    92 "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",
    93 "Title",
    94 "Body",
    95 ),
    96 dstBoard: boards.New(2),
    97 creator: "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",
    98 },
    99 {
    100 name: "nil original thread",
    101 origThread: nil,
    102 errMsg: "thread to repost is required",
    103 },
    104 {
    105 name: "original thread without board",
    106 origThread: &boards.Post{ID: 1},
    107 errMsg: "original thread has no board assigned",
    108 },
    109 {
    110 name: "nil destination board",
    111 origThread: boards.MustNewThread(
    112 boards.New(1),
    113 "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",
    114 "Title",
    115 "Body",
    116 ),
    117 dstBoard: nil,
    118 errMsg: "thread repost requires a destination board",
    119 },
    120 {
    121 name: "original thread is not a thread",
    122 origThread: &boards.Post{
    123 ID: 1,
    124 ThreadID: 2,
    125 Board: boards.New(1),
    126 },
    127 dstBoard: boards.New(2),
    128 errMsg: "post must be a thread to be reposted to another board",
    129 },
    130 {
    131 name: "original thread is a repost",
    132 origThread: &boards.Post{
    133 ID: 1,
    134 ThreadID: 1,
    135 OriginalBoardID: 1,
    136 Board: boards.New(1),
    137 },
    138 dstBoard: boards.New(2),
    139 errMsg: "reposting a thread that is a repost is not allowed",
    140 },
    141 {
    142 name: "invalid creator",
    143 origThread: boards.MustNewThread(
    144 boards.New(1),
    145 "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",
    146 "Title",
    147 "Body",
    148 ),
    149 dstBoard: boards.New(2),
    150 creator: "foo",
    151 errMsg: "invalid thread repost creator address: foo",
    152 },
    153 }
    154
    155 for _, tt := range tests {
    156 t.Run(tt.name, func(t *testing.T) {
    157 thread, err := boards.NewRepost(tt.origThread, tt.dstBoard, tt.creator)
    158
    159 if tt.errMsg != "" {
    160 urequire.Error(t, err, "expect an error")
    161 urequire.ErrorContains(t, err, tt.errMsg, "expect error to match")
    162 return
    163 }
    164
    165 urequire.NoError(t, err, "expect no error")
    166 urequire.True(t, thread.ID == tt.dstBoard.ThreadsSequence.Last(), "expect ID to match")
    167 urequire.True(t, thread.ThreadID == thread.ID, "expect thread ID to match")
    168 urequire.True(t, thread.ParentID == tt.origThread.ID, "expect parent ID to match")
    169 urequire.True(t, thread.OriginalBoardID == tt.origThread.Board.ID, "expect original board ID to match")
    170 urequire.False(t, thread.Board == nil, "expect board to be assigned")
    171 urequire.True(t, thread.Board.ID == tt.dstBoard.ID, "expect board ID to match")
    172 urequire.Empty(t, thread.Title, "expect title to be empty")
    173 urequire.Empty(t, thread.Body, "expect body to be empty")
    174 urequire.True(t, thread.Replies != nil, "expect thread to support sub-replies")
    175 urequire.True(t, thread.Reposts != nil, "expect thread to support reposts")
    176 urequire.True(t, thread.Flags != nil, "expect thread to support flagging")
    177 urequire.Equal(t, tt.creator, thread.Creator, "expect creator to match")
    178 urequire.False(t, thread.CreatedAt.IsZero(), "expect creation date to be assigned")
    179 })
    180 }
    181}
    182