From cf379851b7dac7b53781d473c32d0da37c0d63c8 Mon Sep 17 00:00:00 2001 From: leohhhn Date: Tue, 15 Apr 2025 12:13:43 +0200 Subject: [PATCH] save --- .../gno.land/r/leon/hof/datasource_test.gno | 171 ------ examples/gno.land/r/leon/hof/hof.gno | 158 +++--- examples/gno.land/r/leon/hof/hof_test.gno | 498 +++++++++--------- 3 files changed, 329 insertions(+), 498 deletions(-) delete mode 100644 examples/gno.land/r/leon/hof/datasource_test.gno diff --git a/examples/gno.land/r/leon/hof/datasource_test.gno b/examples/gno.land/r/leon/hof/datasource_test.gno deleted file mode 100644 index b5dfcbf7f60..00000000000 --- a/examples/gno.land/r/leon/hof/datasource_test.gno +++ /dev/null @@ -1,171 +0,0 @@ -package hof - -import ( - "strings" - "testing" - - "gno.land/p/demo/avl" - "gno.land/p/demo/uassert" - "gno.land/p/demo/ufmt" - "gno.land/p/demo/urequire" - "gno.land/p/jeronimoalbi/datasource" - "gno.land/p/moul/addrset" - "gno.land/p/moul/md" - "gno.land/p/moul/txlink" -) - -var ( - _ datasource.Datasource = (*Datasource)(nil) - _ datasource.Record = (*record)(nil) - _ datasource.ContentRecord = (*record)(nil) - _ datasource.Iterator = (*iterator)(nil) -) - -func TestDatasourceRecords(t *testing.T) { - cases := []struct { - name string - items []*Item - recordIDs []string - options []datasource.QueryOption - }{ - { - name: "all items", - items: []*Item{{id: 1}, {id: 2}, {id: 3}}, - recordIDs: []string{"0000001", "0000002", "0000003"}, - }, - { - name: "with offset", - items: []*Item{{id: 1}, {id: 2}, {id: 3}}, - recordIDs: []string{"0000002", "0000003"}, - options: []datasource.QueryOption{datasource.WithOffset(1)}, - }, - { - name: "with count", - items: []*Item{{id: 1}, {id: 2}, {id: 3}}, - recordIDs: []string{"0000001", "0000002"}, - options: []datasource.QueryOption{datasource.WithCount(2)}, - }, - { - name: "with offset and count", - items: []*Item{{id: 1}, {id: 2}, {id: 3}}, - recordIDs: []string{"0000002"}, - options: []datasource.QueryOption{ - datasource.WithOffset(1), - datasource.WithCount(1), - }, - }, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - // Initialize a local instance of exhibition - exhibition := &Exhibition{items: avl.NewTree()} - for _, item := range tc.items { - exhibition.items.Set(item.id.String(), item) - } - - // Get a records iterator - ds := Datasource{exhibition} - query := datasource.NewQuery(tc.options...) - iter := ds.Records(query) - - // Start asserting - urequire.Equal(t, len(tc.items), ds.Size(), "datasource size") - - var records []datasource.Record - for iter.Next() { - records = append(records, iter.Record()) - } - urequire.Equal(t, len(tc.recordIDs), len(records), "record count") - - for i, r := range records { - uassert.Equal(t, tc.recordIDs[i], r.ID()) - } - }) - } -} - -func TestDatasourceRecord(t *testing.T) { - cases := []struct { - name string - items []*Item - id string - err string - }{ - { - name: "found", - items: []*Item{{id: 1}, {id: 2}, {id: 3}}, - id: "0000001", - }, - { - name: "no found", - items: []*Item{{id: 1}, {id: 2}, {id: 3}}, - id: "42", - err: "realm submission not found", - }, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - // Initialize a local instance of exhibition - exhibition := &Exhibition{items: avl.NewTree()} - for _, item := range tc.items { - exhibition.items.Set(item.id.String(), item) - } - - // Get a single record - ds := Datasource{exhibition} - r, err := ds.Record(tc.id) - - // Start asserting - if tc.err != "" { - uassert.ErrorContains(t, err, tc.err) - return - } - - urequire.NoError(t, err, "no error") - urequire.NotEqual(t, nil, r, "record not nil") - uassert.Equal(t, tc.id, r.ID()) - }) - } -} - -func TestItemRecord(t *testing.T) { - pkgpath := "gno.land/r/demo/test" - item := Item{ - id: 1, - pkgpath: pkgpath, - title: "Test Realm", - description: "This is a test realm in the Hall of Fame", - blockNum: 42, - upvote: &addrset.Set{}, - downvote: &addrset.Set{}, - } - item.downvote.Add("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") - item.upvote.Add("g1w4ek2u33ta047h6lta047h6lta047h6ldvdwpn") - item.upvote.Add("g1w4ek2u3jta047h6lta047h6lta047h6l9huexc") - - r := record{&item} - - uassert.Equal(t, "0000001", r.ID()) - uassert.Equal(t, pkgpath, r.String()) - - fields, _ := r.Fields() - details, found := fields.Get("details") - urequire.True(t, found, "details field") - uassert.Equal(t, "Votes: ⏶ 2 - ⏷ 1", details) - - content, _ := r.Content() - wantContent := md.H1(item.title) + - md.H2(r.item.description) + - ufmt.Sprintf("\n%s\n\n", md.CodeBlock(item.pkgpath)) + - ufmt.Sprintf("%s\n\n", item.description) + - ufmt.Sprintf("by %s\n\n", strings.Split(item.pkgpath, "/")[2]) + - md.Link("View Realm", strings.TrimPrefix(item.pkgpath, "gno.land")) + "\n\n" + - ufmt.Sprintf("Submitted at Block #%d\n\n", item.blockNum) + - md.Bold(ufmt.Sprintf("[%d👍](%s) - [%d👎](%s)", - item.upvote.Size(), txlink.Call("Upvote", "pkgpath", item.pkgpath), - item.downvote.Size(), txlink.Call("Downvote", "pkgpath", item.pkgpath), - )) - uassert.Equal(t, wantContent, content) -} diff --git a/examples/gno.land/r/leon/hof/hof.gno b/examples/gno.land/r/leon/hof/hof.gno index 82b7333d1d2..b0e5ae679bc 100644 --- a/examples/gno.land/r/leon/hof/hof.gno +++ b/examples/gno.land/r/leon/hof/hof.gno @@ -13,7 +13,6 @@ import ( "gno.land/p/demo/pausable" "gno.land/p/demo/seqid" "gno.land/p/moul/addrset" - "gno.land/r/leon/config" ) const ( @@ -58,13 +57,15 @@ func init() { itemsSortedByDownvotes: avl.NewTree(), } - Ownable = ownable.NewWithAddress(config.OwnableMain.Owner()) // OrigSendOwnable? - Pausable = pausable.NewFromOwnable(Ownable) + //Ownable = ownable.NewWithAddress(config.OwnableMain.Owner()) // OrigSendOwnable? + //Pausable = pausable.NewFromOwnable(Ownable) } // Register registers your realm to the Hall of Fame // Should be called from within code func Register(title, description string) { + crossing() + if Pausable.IsPaused() { return } @@ -111,81 +112,82 @@ func Register(title, description string) { std.Emit("Registration") } -func Upvote(pkgpath string) { - rawItem, ok := exhibition.items.Get(pkgpath) - if !ok { - panic(ErrNoSuchItem) - } - - item := rawItem.(*Item) - caller := std.PreviousRealm().Address() - - if item.upvote.Has(caller) { - panic(ErrDoubleUpvote) - } - - if _, exists := exhibition.itemsSortedByUpvotes.Remove(getVoteSortKey(item.upvote.Size(), item.id)); !exists { - panic("error removing old upvote entry") - } - - item.upvote.Add(caller) - - exhibition.itemsSortedByUpvotes.Set(getVoteSortKey(item.upvote.Size(), item.id), item) -} - -func Downvote(pkgpath string) { - rawItem, ok := exhibition.items.Get(pkgpath) - if !ok { - panic(ErrNoSuchItem) - } - - item := rawItem.(*Item) - caller := std.PreviousRealm().Address() - - if item.downvote.Has(caller) { - panic(ErrDoubleDownvote) - } - - if _, exist := exhibition.itemsSortedByDownvotes.Remove(getVoteSortKey(item.downvote.Size(), item.id)); !exist { - panic("error removing old downvote entry") - - } - - item.downvote.Add(caller) - - exhibition.itemsSortedByDownvotes.Set(getVoteSortKey(item.downvote.Size(), item.id), item) -} - -func Delete(pkgpath string) { - if !Ownable.CallerIsOwner() { - panic(ownable.ErrUnauthorized) - } - - i, ok := exhibition.items.Get(pkgpath) - if !ok { - panic(ErrNoSuchItem) - } - - item := i.(*Item) - upvoteKey := getVoteSortKey(item.upvote.Size(), item.id) - downvoteKey := getVoteSortKey(item.downvote.Size(), item.id) - - if _, removed := exhibition.items.Remove(pkgpath); !removed { - panic(ErrNoSuchItem) - } - - if _, removed := exhibition.itemsSortedByUpvotes.Remove(upvoteKey); !removed { - panic(ErrNoSuchItem) - } - - if _, removed := exhibition.itemsSortedByDownvotes.Remove(downvoteKey); !removed { - panic(ErrNoSuchItem) - } - - if _, removed := exhibition.itemsSortedByCreation.Remove(getCreationSortKey(item.blockNum, item.id)); !removed { - panic(ErrNoSuchItem) - } -} +// +//func Upvote(pkgpath string) { +// rawItem, ok := exhibition.items.Get(pkgpath) +// if !ok { +// panic(ErrNoSuchItem) +// } +// +// item := rawItem.(*Item) +// caller := std.PreviousRealm().Address() +// +// if item.upvote.Has(caller) { +// panic(ErrDoubleUpvote) +// } +// +// if _, exists := exhibition.itemsSortedByUpvotes.Remove(getVoteSortKey(item.upvote.Size(), item.id)); !exists { +// panic("error removing old upvote entry") +// } +// +// item.upvote.Add(caller) +// +// exhibition.itemsSortedByUpvotes.Set(getVoteSortKey(item.upvote.Size(), item.id), item) +//} +// +//func Downvote(pkgpath string) { +// rawItem, ok := exhibition.items.Get(pkgpath) +// if !ok { +// panic(ErrNoSuchItem) +// } +// +// item := rawItem.(*Item) +// caller := std.PreviousRealm().Address() +// +// if item.downvote.Has(caller) { +// panic(ErrDoubleDownvote) +// } +// +// if _, exist := exhibition.itemsSortedByDownvotes.Remove(getVoteSortKey(item.downvote.Size(), item.id)); !exist { +// panic("error removing old downvote entry") +// +// } +// +// item.downvote.Add(caller) +// +// exhibition.itemsSortedByDownvotes.Set(getVoteSortKey(item.downvote.Size(), item.id), item) +//} +// +//func Delete(pkgpath string) { +// if !Ownable.CallerIsOwner() { +// panic(ownable.ErrUnauthorized) +// } +// +// i, ok := exhibition.items.Get(pkgpath) +// if !ok { +// panic(ErrNoSuchItem) +// } +// +// item := i.(*Item) +// upvoteKey := getVoteSortKey(item.upvote.Size(), item.id) +// downvoteKey := getVoteSortKey(item.downvote.Size(), item.id) +// +// if _, removed := exhibition.items.Remove(pkgpath); !removed { +// panic(ErrNoSuchItem) +// } +// +// if _, removed := exhibition.itemsSortedByUpvotes.Remove(upvoteKey); !removed { +// panic(ErrNoSuchItem) +// } +// +// if _, removed := exhibition.itemsSortedByDownvotes.Remove(downvoteKey); !removed { +// panic(ErrNoSuchItem) +// } +// +// if _, removed := exhibition.itemsSortedByCreation.Remove(getCreationSortKey(item.blockNum, item.id)); !removed { +// panic(ErrNoSuchItem) +// } +//} func getVoteSortKey(votes int, id seqid.ID) string { votesStr := strconv.Itoa(votes) diff --git a/examples/gno.land/r/leon/hof/hof_test.gno b/examples/gno.land/r/leon/hof/hof_test.gno index 3ee2ac29a4b..52c25853f84 100644 --- a/examples/gno.land/r/leon/hof/hof_test.gno +++ b/examples/gno.land/r/leon/hof/hof_test.gno @@ -70,258 +70,258 @@ func TestRegister(t *testing.T) { uassert.False(t, itemExists(t, rlmPath2)) } -func TestUpvote(t *testing.T) { - raw, _ := exhibition.items.Get(rlmPath) - item := raw.(*Item) - - // 0 upvotes by default - urequire.Equal(t, item.upvote.Size(), 0) - - testing.SetRealm(adminRealm) - - urequire.NotPanics(t, func() { - Upvote(rlmPath) - }) - - // Check both trees for 1 upvote - uassert.Equal(t, item.upvote.Size(), 1) - - // Check double upvote - uassert.PanicsWithMessage(t, ErrDoubleUpvote.Error(), func() { - Upvote(rlmPath) - }) -} - -func TestDownvote(t *testing.T) { - raw, _ := exhibition.items.Get(rlmPath) - item := raw.(*Item) - - // 0 downvotes by default - urequire.Equal(t, item.downvote.Size(), 0) - - userRealm := std.NewUserRealm(alice) - testing.SetRealm(userRealm) - - urequire.NotPanics(t, func() { - Downvote(rlmPath) - }) - - // Check both trees for 1 upvote - uassert.Equal(t, item.downvote.Size(), 1) - - // Check double downvote - uassert.PanicsWithMessage(t, ErrDoubleDownvote.Error(), func() { - Downvote(rlmPath) - }) -} - -func TestDelete(t *testing.T) { - userRealm := std.NewUserRealm(admin) - testing.SetRealm(userRealm) - testing.SetOriginCaller(admin) - - uassert.PanicsWithMessage(t, ErrNoSuchItem.Error(), func() { - Delete("nonexistentpkgpath") - }) - - i, _ := exhibition.items.Get(rlmPath) - id := i.(*Item).id - - uassert.NotPanics(t, func() { - Delete(rlmPath) - }) - - uassert.False(t, exhibition.items.Has(rlmPath)) -} - +//func TestUpvote(t *testing.T) { +// raw, _ := exhibition.items.Get(rlmPath) +// item := raw.(*Item) +// +// // 0 upvotes by default +// urequire.Equal(t, item.upvote.Size(), 0) +// +// testing.SetRealm(adminRealm) +// +// urequire.NotPanics(t, func() { +// Upvote(rlmPath) +// }) +// +// // Check both trees for 1 upvote +// uassert.Equal(t, item.upvote.Size(), 1) +// +// // Check double upvote +// uassert.PanicsWithMessage(t, ErrDoubleUpvote.Error(), func() { +// Upvote(rlmPath) +// }) +//} + +// func TestDownvote(t *testing.T) { +// raw, _ := exhibition.items.Get(rlmPath) +// item := raw.(*Item) +// +// // 0 downvotes by default +// urequire.Equal(t, item.downvote.Size(), 0) +// +// userRealm := std.NewUserRealm(alice) +// testing.SetRealm(userRealm) +// +// urequire.NotPanics(t, func() { +// Downvote(rlmPath) +// }) +// +// // Check both trees for 1 upvote +// uassert.Equal(t, item.downvote.Size(), 1) +// +// // Check double downvote +// uassert.PanicsWithMessage(t, ErrDoubleDownvote.Error(), func() { +// Downvote(rlmPath) +// }) +// } +// +// func TestDelete(t *testing.T) { +// userRealm := std.NewUserRealm(admin) +// testing.SetRealm(userRealm) +// testing.SetOriginCaller(admin) +// +// uassert.PanicsWithMessage(t, ErrNoSuchItem.Error(), func() { +// Delete("nonexistentpkgpath") +// }) +// +// i, _ := exhibition.items.Get(rlmPath) +// id := i.(*Item).id +// +// uassert.NotPanics(t, func() { +// Delete(rlmPath) +// }) +// +// uassert.False(t, exhibition.items.Has(rlmPath)) +// } func itemExists(t *testing.T, rlmPath string) bool { t.Helper() - i, ok1 := exhibition.items.Get(rlmPath) + _, ok := exhibition.items.Get(rlmPath) - return ok1 + return ok } -func TestgetVoteSortKey(t *testing.T) { - i := &Item{ - id: 1, - title: validTitle, - description: validDesc, - pkgpath: rlmPath, - blockNum: std.ChainHeight(), - upvote: &addrset.Set{}, - downvote: &addrset.Set{}, - } - - i.upvote.Add(alice) - - generatedKey := getVoteSortKey(i.upvote.Size(), i.id) - expectedKey := "0000000001:1" - - urequire.Equal(t, generatedKey, expectedKey) -} - -func TestSortByUpvote(t *testing.T) { - // Remove all items from all trees - exhibition.items.Iterate("", "", func(key string, value interface{}) bool { - exhibition.items.Remove(key) - return false - }) - exhibition.itemsSortedByUpvotes.Iterate("", "", func(key string, value interface{}) bool { - exhibition.itemsSortedByUpvotes.Remove(key) - return false - }) - exhibition.itemsSortedByDownvotes.Iterate("", "", func(key string, value interface{}) bool { - exhibition.itemsSortedByDownvotes.Remove(key) - return false - }) - exhibition.itemsSortedByCreation.Iterate("", "", func(key string, value interface{}) bool { - exhibition.itemsSortedByCreation.Remove(key) - return false - }) - - // Add items - testing.SetRealm(std.NewCodeRealm(rlmPath3)) - Register(validTitle, validDesc) - - testing.SetRealm(std.NewCodeRealm(rlmPath4)) - Register(validTitle, validDesc) - - testing.SetRealm(std.NewCodeRealm(rlmPath5)) - Register(validTitle, validDesc) - - user1 := testutils.TestAddress("user1") - user2 := testutils.TestAddress("user2") - user3 := testutils.TestAddress("user3") - - testing.SetOriginCaller(user1) - testing.SetRealm(std.NewUserRealm(user1)) - Upvote(rlmPath3) - Upvote(rlmPath4) - Upvote(rlmPath5) - - testing.SetOriginCaller(user2) - testing.SetRealm(std.NewUserRealm(user2)) - Upvote(rlmPath4) - Upvote(rlmPath5) - - testing.SetOriginCaller(user3) - testing.SetRealm(std.NewUserRealm(user3)) - Upvote(rlmPath5) - - // We are displaying data in reverse order in render, so items should be sorted in reverse order - firstKey, firstRawValue := exhibition.itemsSortedByUpvotes.GetByIndex(0) - firstValue := firstRawValue.(*Item) - uassert.Equal(t, firstValue.pkgpath, rlmPath3) - - secondKey, secondRawValue := exhibition.itemsSortedByUpvotes.GetByIndex(1) - secondValue := secondRawValue.(*Item) - uassert.Equal(t, secondValue.pkgpath, rlmPath4) -} - -func TestSortByDownvote(t *testing.T) { - // Remove all items from all trees - exhibition.items.Iterate("", "", func(key string, value interface{}) bool { - exhibition.items.Remove(key) - return false - }) - exhibition.itemsSortedByUpvotes.Iterate("", "", func(key string, value interface{}) bool { - exhibition.itemsSortedByUpvotes.Remove(key) - return false - }) - exhibition.itemsSortedByDownvotes.Iterate("", "", func(key string, value interface{}) bool { - exhibition.itemsSortedByDownvotes.Remove(key) - return false - }) - exhibition.itemsSortedByCreation.Iterate("", "", func(key string, value interface{}) bool { - exhibition.itemsSortedByCreation.Remove(key) - return false - }) - - // Add items - testing.SetRealm(std.NewCodeRealm(rlmPath3)) - Register(validTitle, validDesc) - - testing.SetRealm(std.NewCodeRealm(rlmPath4)) - Register(validTitle, validDesc) - - testing.SetRealm(std.NewCodeRealm(rlmPath5)) - Register(validTitle, validDesc) - - user1 := testutils.TestAddress("user1") - user2 := testutils.TestAddress("user2") - user3 := testutils.TestAddress("user3") - - testing.SetOriginCaller(user1) - testing.SetRealm(std.NewUserRealm(user1)) - Downvote(rlmPath3) - Downvote(rlmPath4) - Downvote(rlmPath5) - - testing.SetOriginCaller(user2) - testing.SetRealm(std.NewUserRealm(user2)) - Downvote(rlmPath4) - Downvote(rlmPath5) - - testing.SetOriginCaller(user3) - testing.SetRealm(std.NewUserRealm(user3)) - Downvote(rlmPath5) - - // We are dispalying data is reverse order in render, so items should be sorted in reverse order - firstKey, firstRawValue := exhibition.itemsSortedByDownvotes.GetByIndex(0) - - firstValue := firstRawValue.(*Item) - - uassert.Equal(t, firstValue.pkgpath, rlmPath3) - - secondKey, secondRawValue := exhibition.itemsSortedByDownvotes.GetByIndex(1) - - secondValue := secondRawValue.(*Item) - - uassert.Equal(t, secondValue.pkgpath, rlmPath4) -} - -func TestSortByCreation(t *testing.T) { - // Remove all items from all trees - exhibition.items.Iterate("", "", func(key string, value interface{}) bool { - exhibition.items.Remove(key) - return false - }) - exhibition.itemsSortedByUpvotes.Iterate("", "", func(key string, value interface{}) bool { - exhibition.itemsSortedByUpvotes.Remove(key) - return false - }) - exhibition.itemsSortedByDownvotes.Iterate("", "", func(key string, value interface{}) bool { - exhibition.itemsSortedByDownvotes.Remove(key) - return false - }) - exhibition.itemsSortedByCreation.Iterate("", "", func(key string, value interface{}) bool { - exhibition.itemsSortedByCreation.Remove(key) - return false - }) - - testing.SkipHeights(10) - testing.SetRealm(std.NewCodeRealm(rlmPath3)) - Register(validTitle, validDesc) - - testing.SkipHeights(10) - testing.SetRealm(std.NewCodeRealm(rlmPath4)) - Register(validTitle, validDesc) - - testing.SkipHeights(10) - testing.SetRealm(std.NewCodeRealm(rlmPath5)) - Register(validTitle, validDesc) - - // We are dispalying data is reverse order in render, so items should be sorted in reverse order - firstKey, firstRawValue := exhibition.itemsSortedByCreation.GetByIndex(0) - - firstValue := firstRawValue.(*Item) - - uassert.Equal(t, firstValue.pkgpath, rlmPath3) - - secondKey, secondRawValue := exhibition.itemsSortedByCreation.GetByIndex(1) - - secondValue := secondRawValue.(*Item) - - uassert.Equal(t, secondValue.pkgpath, rlmPath4) -} +// +//func TestgetVoteSortKey(t *testing.T) { +// i := &Item{ +// id: 1, +// title: validTitle, +// description: validDesc, +// pkgpath: rlmPath, +// blockNum: std.ChainHeight(), +// upvote: &addrset.Set{}, +// downvote: &addrset.Set{}, +// } +// +// i.upvote.Add(alice) +// +// generatedKey := getVoteSortKey(i.upvote.Size(), i.id) +// expectedKey := "0000000001:1" +// +// urequire.Equal(t, generatedKey, expectedKey) +//} +// +//func TestSortByUpvote(t *testing.T) { +// // Remove all items from all trees +// exhibition.items.Iterate("", "", func(key string, value interface{}) bool { +// exhibition.items.Remove(key) +// return false +// }) +// exhibition.itemsSortedByUpvotes.Iterate("", "", func(key string, value interface{}) bool { +// exhibition.itemsSortedByUpvotes.Remove(key) +// return false +// }) +// exhibition.itemsSortedByDownvotes.Iterate("", "", func(key string, value interface{}) bool { +// exhibition.itemsSortedByDownvotes.Remove(key) +// return false +// }) +// exhibition.itemsSortedByCreation.Iterate("", "", func(key string, value interface{}) bool { +// exhibition.itemsSortedByCreation.Remove(key) +// return false +// }) +// +// // Add items +// testing.SetRealm(std.NewCodeRealm(rlmPath3)) +// Register(validTitle, validDesc) +// +// testing.SetRealm(std.NewCodeRealm(rlmPath4)) +// Register(validTitle, validDesc) +// +// testing.SetRealm(std.NewCodeRealm(rlmPath5)) +// Register(validTitle, validDesc) +// +// user1 := testutils.TestAddress("user1") +// user2 := testutils.TestAddress("user2") +// user3 := testutils.TestAddress("user3") +// +// testing.SetOriginCaller(user1) +// testing.SetRealm(std.NewUserRealm(user1)) +// Upvote(rlmPath3) +// Upvote(rlmPath4) +// Upvote(rlmPath5) +// +// testing.SetOriginCaller(user2) +// testing.SetRealm(std.NewUserRealm(user2)) +// Upvote(rlmPath4) +// Upvote(rlmPath5) +// +// testing.SetOriginCaller(user3) +// testing.SetRealm(std.NewUserRealm(user3)) +// Upvote(rlmPath5) +// +// // We are displaying data in reverse order in render, so items should be sorted in reverse order +// firstKey, firstRawValue := exhibition.itemsSortedByUpvotes.GetByIndex(0) +// firstValue := firstRawValue.(*Item) +// uassert.Equal(t, firstValue.pkgpath, rlmPath3) +// +// secondKey, secondRawValue := exhibition.itemsSortedByUpvotes.GetByIndex(1) +// secondValue := secondRawValue.(*Item) +// uassert.Equal(t, secondValue.pkgpath, rlmPath4) +//} +// +//func TestSortByDownvote(t *testing.T) { +// // Remove all items from all trees +// exhibition.items.Iterate("", "", func(key string, value interface{}) bool { +// exhibition.items.Remove(key) +// return false +// }) +// exhibition.itemsSortedByUpvotes.Iterate("", "", func(key string, value interface{}) bool { +// exhibition.itemsSortedByUpvotes.Remove(key) +// return false +// }) +// exhibition.itemsSortedByDownvotes.Iterate("", "", func(key string, value interface{}) bool { +// exhibition.itemsSortedByDownvotes.Remove(key) +// return false +// }) +// exhibition.itemsSortedByCreation.Iterate("", "", func(key string, value interface{}) bool { +// exhibition.itemsSortedByCreation.Remove(key) +// return false +// }) +// +// // Add items +// testing.SetRealm(std.NewCodeRealm(rlmPath3)) +// Register(validTitle, validDesc) +// +// testing.SetRealm(std.NewCodeRealm(rlmPath4)) +// Register(validTitle, validDesc) +// +// testing.SetRealm(std.NewCodeRealm(rlmPath5)) +// Register(validTitle, validDesc) +// +// user1 := testutils.TestAddress("user1") +// user2 := testutils.TestAddress("user2") +// user3 := testutils.TestAddress("user3") +// +// testing.SetOriginCaller(user1) +// testing.SetRealm(std.NewUserRealm(user1)) +// Downvote(rlmPath3) +// Downvote(rlmPath4) +// Downvote(rlmPath5) +// +// testing.SetOriginCaller(user2) +// testing.SetRealm(std.NewUserRealm(user2)) +// Downvote(rlmPath4) +// Downvote(rlmPath5) +// +// testing.SetOriginCaller(user3) +// testing.SetRealm(std.NewUserRealm(user3)) +// Downvote(rlmPath5) +// +// // We are dispalying data is reverse order in render, so items should be sorted in reverse order +// firstKey, firstRawValue := exhibition.itemsSortedByDownvotes.GetByIndex(0) +// +// firstValue := firstRawValue.(*Item) +// +// uassert.Equal(t, firstValue.pkgpath, rlmPath3) +// +// secondKey, secondRawValue := exhibition.itemsSortedByDownvotes.GetByIndex(1) +// +// secondValue := secondRawValue.(*Item) +// +// uassert.Equal(t, secondValue.pkgpath, rlmPath4) +//} +// +//func TestSortByCreation(t *testing.T) { +// // Remove all items from all trees +// exhibition.items.Iterate("", "", func(key string, value interface{}) bool { +// exhibition.items.Remove(key) +// return false +// }) +// exhibition.itemsSortedByUpvotes.Iterate("", "", func(key string, value interface{}) bool { +// exhibition.itemsSortedByUpvotes.Remove(key) +// return false +// }) +// exhibition.itemsSortedByDownvotes.Iterate("", "", func(key string, value interface{}) bool { +// exhibition.itemsSortedByDownvotes.Remove(key) +// return false +// }) +// exhibition.itemsSortedByCreation.Iterate("", "", func(key string, value interface{}) bool { +// exhibition.itemsSortedByCreation.Remove(key) +// return false +// }) +// +// testing.SkipHeights(10) +// testing.SetRealm(std.NewCodeRealm(rlmPath3)) +// Register(validTitle, validDesc) +// +// testing.SkipHeights(10) +// testing.SetRealm(std.NewCodeRealm(rlmPath4)) +// Register(validTitle, validDesc) +// +// testing.SkipHeights(10) +// testing.SetRealm(std.NewCodeRealm(rlmPath5)) +// Register(validTitle, validDesc) +// +// // We are dispalying data is reverse order in render, so items should be sorted in reverse order +// firstKey, firstRawValue := exhibition.itemsSortedByCreation.GetByIndex(0) +// +// firstValue := firstRawValue.(*Item) +// +// uassert.Equal(t, firstValue.pkgpath, rlmPath3) +// +// secondKey, secondRawValue := exhibition.itemsSortedByCreation.GetByIndex(1) +// +// secondValue := secondRawValue.(*Item) +// +// uassert.Equal(t, secondValue.pkgpath, rlmPath4) +//}