From 6b9ccc9ede9a0b5dcd873e2756067c90b5a185fe Mon Sep 17 00:00:00 2001 From: leohhhn Date: Wed, 14 Aug 2024 14:04:03 +0200 Subject: [PATCH 1/5] update test4 text on homepage --- examples/gno.land/r/gnoland/home/home.gno | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gno.land/r/gnoland/home/home.gno b/examples/gno.land/r/gnoland/home/home.gno index e5f24f87135..a1eab3bfeed 100644 --- a/examples/gno.land/r/gnoland/home/home.gno +++ b/examples/gno.land/r/gnoland/home/home.gno @@ -269,7 +269,7 @@ func discoverLinks() ui.Element { - [Discover demo packages](https://github.com/gnolang/gno/tree/master/examples) - [Gnoscan](https://gnoscan.io) - [Portal Loop](https://docs.gno.land/concepts/portal-loop) -- Testnet 4 (upcoming) +- [Testnet 4](https://test4.gno.land/) (July 2024) - [Testnet 3](https://test3.gno.land/) (archive) - [Testnet 2](https://test2.gno.land/) (archive) - Testnet Faucet Hub (soon) From 3ead37ddd1701af7ca5a71a2d6c15b08adc4a33c Mon Sep 17 00:00:00 2001 From: leohhhn Date: Wed, 14 Aug 2024 14:30:45 +0200 Subject: [PATCH 2/5] fix bug, update tests --- examples/gno.land/r/gnoland/events/errors.gno | 4 +- .../gno.land/r/gnoland/events/events_test.gno | 38 +++++++++++++++++++ .../gno.land/r/gnoland/events/rendering.gno | 6 +-- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/examples/gno.land/r/gnoland/events/errors.gno b/examples/gno.land/r/gnoland/events/errors.gno index 788115015a4..fb44d3c9f82 100644 --- a/examples/gno.land/r/gnoland/events/errors.gno +++ b/examples/gno.land/r/gnoland/events/errors.gno @@ -8,8 +8,8 @@ import ( var ( ErrEmptyName = errors.New("event name cannot be empty") ErrNoSuchID = errors.New("event with specified ID does not exist") - ErrWidgetMinAmt = errors.New("you need to request at least 1 event to render") - ErrWidgetMaxAmt = errors.New("maximum number of events in widget is" + strconv.Itoa(MaxWidgetSize)) + ErrMinWidgetSize = errors.New("you need to request at least 1 event to render") + ErrMaxWidgetSize = errors.New("maximum number of events in widget is" + strconv.Itoa(MaxWidgetSize)) ErrDescriptionTooLong = errors.New("event description is too long") ErrInvalidStartTime = errors.New("invalid start time format") ErrInvalidEndTime = errors.New("invalid end time format") diff --git a/examples/gno.land/r/gnoland/events/events_test.gno b/examples/gno.land/r/gnoland/events/events_test.gno index 1e5625e0b2c..953081331f3 100644 --- a/examples/gno.land/r/gnoland/events/events_test.gno +++ b/examples/gno.land/r/gnoland/events/events_test.gno @@ -7,6 +7,7 @@ import ( "time" "gno.land/p/demo/uassert" + "gno.land/p/demo/urequire" ) var ( @@ -159,3 +160,40 @@ func TestParseTimes(t *testing.T) { _, _, err = parseTimes("2009-02-10T23:30:30+02:00", "2009-02-13T21:30:33+05:00") uassert.ErrorContains(t, err, ErrStartEndTimezonemMismatch.Error()) } + +func TestRenderEventWidget(t *testing.T) { + events = nil // remove elements from previous tests - see issue #1982 + + // No events yet + out, err := RenderEventWidget(1) + uassert.NoError(t, err) + uassert.Equal(t, out, "No events.") + + // Too big of a widget + out, err = RenderEventWidget(MaxWidgetSize + 1) + uassert.ErrorIs(t, err, ErrMaxWidgetSize) + + out, err = RenderEventWidget(0) + uassert.ErrorIs(t, err, ErrMinWidgetSize) + + // Ordering & if requested amt is larger than the num of events that exist + e1Start := parsedTimeNow.Add(time.Hour * 24 * 5) + e1End := e1Start.Add(time.Hour * 4) + + e2Start := parsedTimeNow.Add(time.Hour * 24 * 10) // event 2 is after event 1 + e2End := e2Start.Add(time.Hour * 4) + + _, err = AddEvent("Event 1", "description", "gno.land", "loc", e1Start.Format(time.RFC3339), e1End.Format(time.RFC3339)) + urequire.NoError(t, err) + + _, err = AddEvent("Event 2", "description", "gno.land", "loc", e2Start.Format(time.RFC3339), e2End.Format(time.RFC3339)) + urequire.NoError(t, err) + + out, err = RenderEventWidget(MaxWidgetSize) + urequire.NoError(t, err) + + uniqueSequence := "- [" // sequence that is displayed once per each event to test against + uassert.Equal(t, 2, strings.Count(out, uniqueSequence)) + + uassert.True(t, strings.Index(out, "Event 1") > strings.Index(out, "Event 2")) +} diff --git a/examples/gno.land/r/gnoland/events/rendering.gno b/examples/gno.land/r/gnoland/events/rendering.gno index bde32065d27..d98879c68f6 100644 --- a/examples/gno.land/r/gnoland/events/rendering.gno +++ b/examples/gno.land/r/gnoland/events/rendering.gno @@ -19,11 +19,11 @@ func RenderEventWidget(eventsToRender int) (string, error) { } if eventsToRender > MaxWidgetSize { - return "", ErrWidgetMaxAmt + return "", ErrMaxWidgetSize } if eventsToRender < 1 { - return "", ErrWidgetMinAmt + return "", ErrMinWidgetSize } if eventsToRender > numOfEvents { @@ -32,7 +32,7 @@ func RenderEventWidget(eventsToRender int) (string, error) { output := "" - for _, event := range events[eventsToRender:] { + for _, event := range events[:eventsToRender] { output += ufmt.Sprintf("- [%s](%s)\n", event.name, event.link) } From f145946c576c8947c5f61d06de0945123c4cc229 Mon Sep 17 00:00:00 2001 From: leohhhn Date: Wed, 14 Aug 2024 14:34:59 +0200 Subject: [PATCH 3/5] mod tidy --- examples/gno.land/r/gnoland/events/gno.mod | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/gno.land/r/gnoland/events/gno.mod b/examples/gno.land/r/gnoland/events/gno.mod index 5a4c6ac56f3..bd3e4652b04 100644 --- a/examples/gno.land/r/gnoland/events/gno.mod +++ b/examples/gno.land/r/gnoland/events/gno.mod @@ -5,4 +5,5 @@ require ( gno.land/p/demo/seqid v0.0.0-latest gno.land/p/demo/uassert v0.0.0-latest gno.land/p/demo/ufmt v0.0.0-latest + gno.land/p/demo/urequire v0.0.0-latest ) From 0e83e9e60c95524e060e9e852ac7e7f5aa99c7d1 Mon Sep 17 00:00:00 2001 From: leohhhn Date: Wed, 14 Aug 2024 14:43:37 +0200 Subject: [PATCH 4/5] home tests --- examples/gno.land/r/gnoland/home/home.gno | 2 +- examples/gno.land/r/gnoland/home/home_filetest.gno | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gno.land/r/gnoland/home/home.gno b/examples/gno.land/r/gnoland/home/home.gno index a1eab3bfeed..921492d81b4 100644 --- a/examples/gno.land/r/gnoland/home/home.gno +++ b/examples/gno.land/r/gnoland/home/home.gno @@ -269,7 +269,7 @@ func discoverLinks() ui.Element { - [Discover demo packages](https://github.com/gnolang/gno/tree/master/examples) - [Gnoscan](https://gnoscan.io) - [Portal Loop](https://docs.gno.land/concepts/portal-loop) -- [Testnet 4](https://test4.gno.land/) (July 2024) +- [Testnet 4](https://test4.gno.land/) (Launched July 2024!) - [Testnet 3](https://test3.gno.land/) (archive) - [Testnet 2](https://test2.gno.land/) (archive) - Testnet Faucet Hub (soon) diff --git a/examples/gno.land/r/gnoland/home/home_filetest.gno b/examples/gno.land/r/gnoland/home/home_filetest.gno index 15f329683f4..b70b22c80af 100644 --- a/examples/gno.land/r/gnoland/home/home_filetest.gno +++ b/examples/gno.land/r/gnoland/home/home_filetest.gno @@ -56,7 +56,7 @@ func main() { // - [Discover demo packages](https://github.com/gnolang/gno/tree/master/examples) // - [Gnoscan](https://gnoscan.io) // - [Portal Loop](https://docs.gno.land/concepts/portal-loop) -// - Testnet 4 (upcoming) +// - [Testnet 4](https://test4.gno.land/) (Launched July 2024!) // - [Testnet 3](https://test3.gno.land/) (archive) // - [Testnet 2](https://test2.gno.land/) (archive) // - Testnet Faucet Hub (soon) From 58b5bfa0f3fe170fb07f131ff916bd822f51c8e6 Mon Sep 17 00:00:00 2001 From: leohhhn Date: Wed, 14 Aug 2024 15:47:18 +0200 Subject: [PATCH 5/5] update comments --- examples/gno.land/r/gnoland/events/events_test.gno | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/gno.land/r/gnoland/events/events_test.gno b/examples/gno.land/r/gnoland/events/events_test.gno index 953081331f3..357857352d8 100644 --- a/examples/gno.land/r/gnoland/events/events_test.gno +++ b/examples/gno.land/r/gnoland/events/events_test.gno @@ -169,10 +169,11 @@ func TestRenderEventWidget(t *testing.T) { uassert.NoError(t, err) uassert.Equal(t, out, "No events.") - // Too big of a widget + // Too many events out, err = RenderEventWidget(MaxWidgetSize + 1) uassert.ErrorIs(t, err, ErrMaxWidgetSize) + // Too little events out, err = RenderEventWidget(0) uassert.ErrorIs(t, err, ErrMinWidgetSize) @@ -192,7 +193,7 @@ func TestRenderEventWidget(t *testing.T) { out, err = RenderEventWidget(MaxWidgetSize) urequire.NoError(t, err) - uniqueSequence := "- [" // sequence that is displayed once per each event to test against + uniqueSequence := "- [" // sequence that is displayed once per each event as per the RenderEventWidget function uassert.Equal(t, 2, strings.Count(out, uniqueSequence)) uassert.True(t, strings.Index(out, "Event 1") > strings.Index(out, "Event 2"))