From f76c480e9bf21fd584a14dfd88151828074f144d Mon Sep 17 00:00:00 2001 From: JJOptimist Date: Wed, 25 Dec 2024 13:03:40 +0100 Subject: [PATCH 1/8] feat: add JJOptimist's Homerealm --- examples/gno.land/r/jjoptimist/config.gno | 51 ++++++++++++++ examples/gno.land/r/jjoptimist/gno.mod | 5 ++ examples/gno.land/r/jjoptimist/home.gno | 32 +++++++++ examples/gno.land/r/jjoptimist/home_test.gno | 70 ++++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 examples/gno.land/r/jjoptimist/config.gno create mode 100644 examples/gno.land/r/jjoptimist/gno.mod create mode 100644 examples/gno.land/r/jjoptimist/home.gno create mode 100644 examples/gno.land/r/jjoptimist/home_test.gno diff --git a/examples/gno.land/r/jjoptimist/config.gno b/examples/gno.land/r/jjoptimist/config.gno new file mode 100644 index 00000000000..a939bd20e15 --- /dev/null +++ b/examples/gno.land/r/jjoptimist/config.gno @@ -0,0 +1,51 @@ +package home + +import ( + "std" +) + +var ( + + OWNER_ADDR = std.Address("g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj") + + owner std.Address + + config = struct { + title string + description string + github string + }{ + title: "JJOptimist's Home Realm 🏠", + description: "Exploring Gno and building on-chain", + github: "jjoptimist", + } +) + +func init() { + owner = OWNER_ADDR +} + +func IsOwner(addr std.Address) bool { + return addr == owner +} + +func GetConfig() struct { + title string + description string + github string +} { + return config +} + +func UpdateConfig(newTitle, newDescription, newGithub string) { + if !IsOwner(std.GetOrigCaller()) { + panic("not authorized") + } + config.title = newTitle + config.description = newDescription + config.github = newGithub +} + +func GetOwner() std.Address { + return owner +} \ No newline at end of file diff --git a/examples/gno.land/r/jjoptimist/gno.mod b/examples/gno.land/r/jjoptimist/gno.mod new file mode 100644 index 00000000000..b10f090f030 --- /dev/null +++ b/examples/gno.land/r/jjoptimist/gno.mod @@ -0,0 +1,5 @@ +module gno.land/r/jjoptimist/home + +require ( + gno.land/p/demo/testutils v0.0.0 +) \ No newline at end of file diff --git a/examples/gno.land/r/jjoptimist/home.gno b/examples/gno.land/r/jjoptimist/home.gno new file mode 100644 index 00000000000..35b19b5a7bb --- /dev/null +++ b/examples/gno.land/r/jjoptimist/home.gno @@ -0,0 +1,32 @@ +package home + +import ( + "time" +) + +var ( + creation time.Time +) + +func init() { + creation = time.Now() +} + +func Render(path string) string { + cfg := GetConfig() + + output := "# " + cfg.title + "\n\n" + + output += "## About Me\n" + output += "- 👋 Hi, I'm JJOptimist\n" + output += "- 🌱 " + cfg.description + "\n" + + output += "## Contact\n" + output += "- 📫 GitHub: [" + cfg.github + "](https://github.com/" + cfg.github + ")\n" + + output += "\n---\n" + output += "_Realm created: " + creation.Format("2006-01-02 15:04:05 MST") + "_\n" + output += "_Owner: " + GetOwner().String() + "_" + + return output +} \ No newline at end of file diff --git a/examples/gno.land/r/jjoptimist/home_test.gno b/examples/gno.land/r/jjoptimist/home_test.gno new file mode 100644 index 00000000000..988db09603a --- /dev/null +++ b/examples/gno.land/r/jjoptimist/home_test.gno @@ -0,0 +1,70 @@ +package home + +import ( + "std" + "testing" + "time" +) + +func TestOwnership(t *testing.T) { + + owner := GetOwner() + if owner.String() != "g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj" { + t.Errorf("Expected owner to be g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj, got %s", owner.String()) + } + + + if !IsOwner(owner) { + t.Error("Owner address should return true for IsOwner check") + } + + + nonOwner := std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") + if IsOwner(nonOwner) { + t.Error("Non-owner address should return false for IsOwner check") + } +} + +func TestConfig(t *testing.T) { + cfg := GetConfig() + + // Test initial config values + if cfg.title != "JJOptimist's Home Realm 🏠" { + t.Errorf("Expected title to be 'JJOptimist's Home Realm 🏠', got %s", cfg.title) + } + if cfg.description != "Exploring Gno and building on-chain" { + t.Errorf("Expected description to be 'Exploring Gno and building on-chain', got %s", cfg.description) + } + if cfg.github != "jjoptimist" { + t.Errorf("Expected github to be 'jjoptimist', got %s", cfg.github) + } +} + +func TestRender(t *testing.T) { + output := Render("") + + // Random test for section + expectedSections := []string{ + "# JJOptimist's Home Realm", + "## About Me", + "## Contact", + "GitHub: [jjoptimist]", + "_Owner: g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj_", + } + + for _, section := range expectedSections { + if !contains(output, section) { + t.Errorf("Expected output to contain '%s'", section) + } + } +} + + +func contains(s, substr string) bool { + for i := 0; i < len(s)-len(substr)+1; i++ { + if s[i:i+len(substr)] == substr { + return true + } + } + return false +} \ No newline at end of file From d7fec4854e41f9215fe3e417dd575cb88e0b7ce4 Mon Sep 17 00:00:00 2001 From: JJOptimist Date: Fri, 10 Jan 2025 16:13:37 +0100 Subject: [PATCH 2/8] feat: added usage of ownable and art --- examples/gno.land/r/jjoptimist/config.gno | 51 ------------ examples/gno.land/r/jjoptimist/gno.mod | 5 -- examples/gno.land/r/jjoptimist/home.gno | 32 -------- .../gno.land/r/jjoptimist/home/config.gno | 35 ++++++++ examples/gno.land/r/jjoptimist/home/gno.mod | 5 ++ examples/gno.land/r/jjoptimist/home/home.gno | 80 +++++++++++++++++++ .../gno.land/r/jjoptimist/home/home_test.gno | 41 ++++++++++ examples/gno.land/r/jjoptimist/home_test.gno | 70 ---------------- mykey_backup.armor | 0 9 files changed, 161 insertions(+), 158 deletions(-) delete mode 100644 examples/gno.land/r/jjoptimist/config.gno delete mode 100644 examples/gno.land/r/jjoptimist/gno.mod delete mode 100644 examples/gno.land/r/jjoptimist/home.gno create mode 100644 examples/gno.land/r/jjoptimist/home/config.gno create mode 100644 examples/gno.land/r/jjoptimist/home/gno.mod create mode 100644 examples/gno.land/r/jjoptimist/home/home.gno create mode 100644 examples/gno.land/r/jjoptimist/home/home_test.gno delete mode 100644 examples/gno.land/r/jjoptimist/home_test.gno create mode 100644 mykey_backup.armor diff --git a/examples/gno.land/r/jjoptimist/config.gno b/examples/gno.land/r/jjoptimist/config.gno deleted file mode 100644 index a939bd20e15..00000000000 --- a/examples/gno.land/r/jjoptimist/config.gno +++ /dev/null @@ -1,51 +0,0 @@ -package home - -import ( - "std" -) - -var ( - - OWNER_ADDR = std.Address("g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj") - - owner std.Address - - config = struct { - title string - description string - github string - }{ - title: "JJOptimist's Home Realm 🏠", - description: "Exploring Gno and building on-chain", - github: "jjoptimist", - } -) - -func init() { - owner = OWNER_ADDR -} - -func IsOwner(addr std.Address) bool { - return addr == owner -} - -func GetConfig() struct { - title string - description string - github string -} { - return config -} - -func UpdateConfig(newTitle, newDescription, newGithub string) { - if !IsOwner(std.GetOrigCaller()) { - panic("not authorized") - } - config.title = newTitle - config.description = newDescription - config.github = newGithub -} - -func GetOwner() std.Address { - return owner -} \ No newline at end of file diff --git a/examples/gno.land/r/jjoptimist/gno.mod b/examples/gno.land/r/jjoptimist/gno.mod deleted file mode 100644 index b10f090f030..00000000000 --- a/examples/gno.land/r/jjoptimist/gno.mod +++ /dev/null @@ -1,5 +0,0 @@ -module gno.land/r/jjoptimist/home - -require ( - gno.land/p/demo/testutils v0.0.0 -) \ No newline at end of file diff --git a/examples/gno.land/r/jjoptimist/home.gno b/examples/gno.land/r/jjoptimist/home.gno deleted file mode 100644 index 35b19b5a7bb..00000000000 --- a/examples/gno.land/r/jjoptimist/home.gno +++ /dev/null @@ -1,32 +0,0 @@ -package home - -import ( - "time" -) - -var ( - creation time.Time -) - -func init() { - creation = time.Now() -} - -func Render(path string) string { - cfg := GetConfig() - - output := "# " + cfg.title + "\n\n" - - output += "## About Me\n" - output += "- 👋 Hi, I'm JJOptimist\n" - output += "- 🌱 " + cfg.description + "\n" - - output += "## Contact\n" - output += "- 📫 GitHub: [" + cfg.github + "](https://github.com/" + cfg.github + ")\n" - - output += "\n---\n" - output += "_Realm created: " + creation.Format("2006-01-02 15:04:05 MST") + "_\n" - output += "_Owner: " + GetOwner().String() + "_" - - return output -} \ No newline at end of file diff --git a/examples/gno.land/r/jjoptimist/home/config.gno b/examples/gno.land/r/jjoptimist/home/config.gno new file mode 100644 index 00000000000..6393c056465 --- /dev/null +++ b/examples/gno.land/r/jjoptimist/home/config.gno @@ -0,0 +1,35 @@ +package home + +import ( + "std" + "gno.land/p/demo/ownable" +) + +var config = struct { + title string + description string + github string +}{ + title: "JJOptimist's Home Realm 🏠", + description: "Exploring Gno and building on-chain", + github: "jjoptimist", +} + +var o = ownable.NewWithAddress(std.Address("g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj")) + +func GetConfig() struct { title string; description string; github string } { + return config +} + +func UpdateConfig(newTitle, newDescription, newGithub string) { + if !o.CallerIsOwner() { + panic("not authorized") + } + config.title = newTitle + config.description = newDescription + config.github = newGithub +} + +func GetOwner() std.Address { + return o.Owner() +} \ No newline at end of file diff --git a/examples/gno.land/r/jjoptimist/home/gno.mod b/examples/gno.land/r/jjoptimist/home/gno.mod new file mode 100644 index 00000000000..a9ef13aa1a0 --- /dev/null +++ b/examples/gno.land/r/jjoptimist/home/gno.mod @@ -0,0 +1,5 @@ +module gno.land/r/jjoptimist + +require ( + gno.land/p/demo/ownable v0.0.0 +) \ No newline at end of file diff --git a/examples/gno.land/r/jjoptimist/home/home.gno b/examples/gno.land/r/jjoptimist/home/home.gno new file mode 100644 index 00000000000..8375e7fb041 --- /dev/null +++ b/examples/gno.land/r/jjoptimist/home/home.gno @@ -0,0 +1,80 @@ +package home + +import ( + "time" + "std" + "strconv" +) + +var ( + creation time.Time + gnomeArt1 = ` /\ + / \ + ,,,,, +(o.o) +(\_/) +-"-"-` + + gnomeArt2 = ` /\ + / \ + ,,,,, +(^.^) +(\_/) + -"-` + + gnomeArt3 = ` /\ + / \ + ,,,,, +(*.*) +(\_/) +"-"-"` + + gnomeArt4 = ` /\ + / \ + ,,,,, +(o.~) +(\_/) + -"-` +) + +func getGnomeArt(height int64) string { + var art string + if height%7 == 0 { + art = gnomeArt4 // winking gnome + } else if height%5 == 0 { + art = gnomeArt3 // starry-eyed gnome + } else if height%3 == 0 { + art = gnomeArt2 // happy gnome + } else if height%2 == 0 { + art = gnomeArt1 // regular gnome + } else { + art = gnomeArt1 // default + } + return "```\n" + art + "\n```\n" +} + +func init() { + creation = time.Now() +} + +func Render(path string) string { + cfg := GetConfig() + height := std.GetHeight() + + output := "# " + cfg.title + "\n\n" + + output += "## About Me\n" + output += "- 👋 Hi, I'm JJOptimist\n" + output += getGnomeArt(height) + output += "- 🌱 " + cfg.description + "\n" + + output += "## Contact\n" + output += "- 📫 GitHub: [" + cfg.github + "](https://github.com/" + cfg.github + ")\n" + + output += "\n---\n" + output += "_Realm created: " + creation.Format("2006-01-02 15:04:05 UTC") + "_\n" + output += "_Owner: " + GetOwner().String() + "_\n" + output += "_Current Block Height: " + strconv.Itoa(int(height)) + "_" + + return output +} \ No newline at end of file diff --git a/examples/gno.land/r/jjoptimist/home/home_test.gno b/examples/gno.land/r/jjoptimist/home/home_test.gno new file mode 100644 index 00000000000..387d979ffb8 --- /dev/null +++ b/examples/gno.land/r/jjoptimist/home/home_test.gno @@ -0,0 +1,41 @@ +package home + +import ( + "std" + "testing" +) + +func TestOwnership(t *testing.T) { + owner := GetOwner() + if owner.String() != "g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj" { + t.Errorf("Expected owner to be g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj, got %s", owner.String()) + } + + std.TestSetOrigCaller(owner) + if !o.CallerIsOwner() { + t.Error("Owner address should return true for CallerIsOwner check") + } + + nonOwner := std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") + std.TestSetOrigCaller(nonOwner) + if o.CallerIsOwner() { + t.Error("Non-owner address should return false for CallerIsOwner check") + } +} + +func TestConfig(t *testing.T) { + cfg := GetConfig() + + if cfg.title != "JJOptimist's Home Realm 🏠" { + t.Errorf("Expected title to be 'JJOptimist's Home Realm 🏠', got %s", cfg.title) + } + if cfg.description != "Exploring Gno and building on-chain" { + t.Errorf("Expected description to be 'Exploring Gno and building on-chain', got %s", cfg.description) + } + if cfg.github != "jjoptimist" { + t.Errorf("Expected github to be 'jjoptimist', got %s", cfg.github) + } + if cfg.css != styles { + t.Errorf("Expected css to match styles constant") + } +} \ No newline at end of file diff --git a/examples/gno.land/r/jjoptimist/home_test.gno b/examples/gno.land/r/jjoptimist/home_test.gno deleted file mode 100644 index 988db09603a..00000000000 --- a/examples/gno.land/r/jjoptimist/home_test.gno +++ /dev/null @@ -1,70 +0,0 @@ -package home - -import ( - "std" - "testing" - "time" -) - -func TestOwnership(t *testing.T) { - - owner := GetOwner() - if owner.String() != "g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj" { - t.Errorf("Expected owner to be g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj, got %s", owner.String()) - } - - - if !IsOwner(owner) { - t.Error("Owner address should return true for IsOwner check") - } - - - nonOwner := std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") - if IsOwner(nonOwner) { - t.Error("Non-owner address should return false for IsOwner check") - } -} - -func TestConfig(t *testing.T) { - cfg := GetConfig() - - // Test initial config values - if cfg.title != "JJOptimist's Home Realm 🏠" { - t.Errorf("Expected title to be 'JJOptimist's Home Realm 🏠', got %s", cfg.title) - } - if cfg.description != "Exploring Gno and building on-chain" { - t.Errorf("Expected description to be 'Exploring Gno and building on-chain', got %s", cfg.description) - } - if cfg.github != "jjoptimist" { - t.Errorf("Expected github to be 'jjoptimist', got %s", cfg.github) - } -} - -func TestRender(t *testing.T) { - output := Render("") - - // Random test for section - expectedSections := []string{ - "# JJOptimist's Home Realm", - "## About Me", - "## Contact", - "GitHub: [jjoptimist]", - "_Owner: g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj_", - } - - for _, section := range expectedSections { - if !contains(output, section) { - t.Errorf("Expected output to contain '%s'", section) - } - } -} - - -func contains(s, substr string) bool { - for i := 0; i < len(s)-len(substr)+1; i++ { - if s[i:i+len(substr)] == substr { - return true - } - } - return false -} \ No newline at end of file diff --git a/mykey_backup.armor b/mykey_backup.armor new file mode 100644 index 00000000000..e69de29bb2d From 6746b485329bc463d748093ffb6796540c26c001 Mon Sep 17 00:00:00 2001 From: JJOptimist Date: Fri, 10 Jan 2025 16:36:38 +0100 Subject: [PATCH 3/8] chore: remove mykey_backup.armor --- mykey_backup.armor | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 mykey_backup.armor diff --git a/mykey_backup.armor b/mykey_backup.armor deleted file mode 100644 index e69de29bb2d..00000000000 From 26141d380c02dbd49b6a52eeab2b55d4be687acf Mon Sep 17 00:00:00 2001 From: JJOptimist Date: Sun, 19 Jan 2025 16:46:52 +0100 Subject: [PATCH 4/8] fix: update based on feedback and registered in HoF --- .../gno.land/r/jjoptimist/home/config.gno | 38 +++++------ examples/gno.land/r/jjoptimist/home/gno.mod | 2 +- examples/gno.land/r/jjoptimist/home/home.gno | 33 +++++---- .../gno.land/r/jjoptimist/home/home_test.gno | 67 ++++++++++++------- 4 files changed, 81 insertions(+), 59 deletions(-) diff --git a/examples/gno.land/r/jjoptimist/home/config.gno b/examples/gno.land/r/jjoptimist/home/config.gno index 6393c056465..bfb4b11f485 100644 --- a/examples/gno.land/r/jjoptimist/home/config.gno +++ b/examples/gno.land/r/jjoptimist/home/config.gno @@ -2,34 +2,32 @@ package home import ( "std" + "gno.land/p/demo/ownable" ) -var config = struct { - title string - description string - github string -}{ - title: "JJOptimist's Home Realm 🏠", - description: "Exploring Gno and building on-chain", - github: "jjoptimist", +type Config struct { + Title string + Description string + Github string +} + +var config = Config { + Title: "JJOptimist's Home Realm 🏠", + Description: "Exploring Gno and building on-chain", + Github: "jjoptimist", } -var o = ownable.NewWithAddress(std.Address("g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj")) -func GetConfig() struct { title string; description string; github string } { +var Ownable = ownable.NewWithAddress(std.Address("g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj")) + +func GetConfig() Config { return config } func UpdateConfig(newTitle, newDescription, newGithub string) { - if !o.CallerIsOwner() { - panic("not authorized") - } - config.title = newTitle - config.description = newDescription - config.github = newGithub -} - -func GetOwner() std.Address { - return o.Owner() + Ownable.AssertCallerIsOwner() + config.Title = newTitle + config.Description = newDescription + config.Github = newGithub } \ No newline at end of file diff --git a/examples/gno.land/r/jjoptimist/home/gno.mod b/examples/gno.land/r/jjoptimist/home/gno.mod index a9ef13aa1a0..d53a8b627d3 100644 --- a/examples/gno.land/r/jjoptimist/home/gno.mod +++ b/examples/gno.land/r/jjoptimist/home/gno.mod @@ -1,5 +1,5 @@ module gno.land/r/jjoptimist -require ( +dependencies ( gno.land/p/demo/ownable v0.0.0 ) \ No newline at end of file diff --git a/examples/gno.land/r/jjoptimist/home/home.gno b/examples/gno.land/r/jjoptimist/home/home.gno index 8375e7fb041..0a822fe0141 100644 --- a/examples/gno.land/r/jjoptimist/home/home.gno +++ b/examples/gno.land/r/jjoptimist/home/home.gno @@ -1,13 +1,15 @@ package home import ( - "time" "std" "strconv" + "time" + + "gno.land/p/demo/ownable" + "gno.land/r/leon/hof" ) -var ( - creation time.Time +const ( gnomeArt1 = ` /\ / \ ,,,,, @@ -37,43 +39,46 @@ var ( -"-` ) +var ( + creation time.Time +) + func getGnomeArt(height int64) string { var art string - if height%7 == 0 { + switch { + case height%7 == 0: art = gnomeArt4 // winking gnome - } else if height%5 == 0 { + case height%5 == 0: art = gnomeArt3 // starry-eyed gnome - } else if height%3 == 0 { + case height%3 == 0: art = gnomeArt2 // happy gnome - } else if height%2 == 0 { + default: art = gnomeArt1 // regular gnome - } else { - art = gnomeArt1 // default } return "```\n" + art + "\n```\n" } func init() { creation = time.Now() + hof.Register() } func Render(path string) string { - cfg := GetConfig() height := std.GetHeight() - output := "# " + cfg.title + "\n\n" + output := "# " + config.Title + "\n\n" output += "## About Me\n" output += "- 👋 Hi, I'm JJOptimist\n" output += getGnomeArt(height) - output += "- 🌱 " + cfg.description + "\n" + output += "- 🌱 " + config.Description + "\n" output += "## Contact\n" - output += "- 📫 GitHub: [" + cfg.github + "](https://github.com/" + cfg.github + ")\n" + output += "- 📫 GitHub: [" + config.Github + "](https://github.com/" + config.Github + ")\n" output += "\n---\n" output += "_Realm created: " + creation.Format("2006-01-02 15:04:05 UTC") + "_\n" - output += "_Owner: " + GetOwner().String() + "_\n" + output += "_Owner: " + Ownable.Owner().String() + "_\n" output += "_Current Block Height: " + strconv.Itoa(int(height)) + "_" return output diff --git a/examples/gno.land/r/jjoptimist/home/home_test.gno b/examples/gno.land/r/jjoptimist/home/home_test.gno index 387d979ffb8..aed652b6383 100644 --- a/examples/gno.land/r/jjoptimist/home/home_test.gno +++ b/examples/gno.land/r/jjoptimist/home/home_test.gno @@ -1,41 +1,60 @@ package home import ( - "std" "testing" + "strings" ) -func TestOwnership(t *testing.T) { - owner := GetOwner() - if owner.String() != "g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj" { - t.Errorf("Expected owner to be g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj, got %s", owner.String()) +func TestConfig(t *testing.T) { + cfg := GetConfig() + + if cfg.Title != "JJOptimist's Home Realm 🏠" { + t.Errorf("Expected title to be 'JJOptimist's Home Realm 🏠', got %s", cfg.Title) } - - std.TestSetOrigCaller(owner) - if !o.CallerIsOwner() { - t.Error("Owner address should return true for CallerIsOwner check") + if cfg.Description != "Exploring Gno and building on-chain" { + t.Errorf("Expected description to be 'Exploring Gno and building on-chain', got %s", cfg.Description) } - - nonOwner := std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") - std.TestSetOrigCaller(nonOwner) - if o.CallerIsOwner() { - t.Error("Non-owner address should return false for CallerIsOwner check") + if cfg.Github != "jjoptimist" { + t.Errorf("Expected github to be 'jjoptimist', got %s", cfg.Github) } } -func TestConfig(t *testing.T) { - cfg := GetConfig() +func TestRender(t *testing.T) { + output := Render("") - if cfg.title != "JJOptimist's Home Realm 🏠" { - t.Errorf("Expected title to be 'JJOptimist's Home Realm 🏠', got %s", cfg.title) + // Test that required sections are present + if !strings.Contains(output, "# "+config.Title) { + t.Error("Rendered output missing title") } - if cfg.description != "Exploring Gno and building on-chain" { - t.Errorf("Expected description to be 'Exploring Gno and building on-chain', got %s", cfg.description) + if !strings.Contains(output, "## About Me") { + t.Error("Rendered output missing About Me section") } - if cfg.github != "jjoptimist" { - t.Errorf("Expected github to be 'jjoptimist', got %s", cfg.github) + if !strings.Contains(output, "## Contact") { + t.Error("Rendered output missing Contact section") } - if cfg.css != styles { - t.Errorf("Expected css to match styles constant") + if !strings.Contains(output, config.Description) { + t.Error("Rendered output missing description") + } + if !strings.Contains(output, config.Github) { + t.Error("Rendered output missing github link") + } +} + +func TestGetGnomeArt(t *testing.T) { + tests := []struct { + height int64 + expected string + }{ + {7, gnomeArt4}, // height divisible by 7 + {5, gnomeArt3}, // height divisible by 5 + {3, gnomeArt2}, // height divisible by 3 + {2, gnomeArt1}, // default case + } + + for _, tt := range tests { + art := getGnomeArt(tt.height) + if !strings.Contains(art, tt.expected) { + t.Errorf("For height %d, expected art containing %s, got %s", tt.height, tt.expected, art) + } } } \ No newline at end of file From 4de53c44362111f5435387aea0024bdd2942c6d1 Mon Sep 17 00:00:00 2001 From: JJOptimist Date: Mon, 20 Jan 2025 19:43:24 +0100 Subject: [PATCH 5/8] fix: clean dependencies --- examples/gno.land/r/jjoptimist/home/gno.mod | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/examples/gno.land/r/jjoptimist/home/gno.mod b/examples/gno.land/r/jjoptimist/home/gno.mod index d53a8b627d3..a0014fe33ea 100644 --- a/examples/gno.land/r/jjoptimist/home/gno.mod +++ b/examples/gno.land/r/jjoptimist/home/gno.mod @@ -1,5 +1 @@ -module gno.land/r/jjoptimist - -dependencies ( - gno.land/p/demo/ownable v0.0.0 -) \ No newline at end of file +module gno.land/r/jjoptimist \ No newline at end of file From b7f16d4004ad509b55742956236fb1b6e137968e Mon Sep 17 00:00:00 2001 From: JJOptimist Date: Tue, 21 Jan 2025 11:37:34 +0100 Subject: [PATCH 6/8] fix: path fix in gno.mod --- examples/gno.land/r/jjoptimist/home/gno.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gno.land/r/jjoptimist/home/gno.mod b/examples/gno.land/r/jjoptimist/home/gno.mod index a0014fe33ea..bfb533f92c6 100644 --- a/examples/gno.land/r/jjoptimist/home/gno.mod +++ b/examples/gno.land/r/jjoptimist/home/gno.mod @@ -1 +1 @@ -module gno.land/r/jjoptimist \ No newline at end of file +module gno.land/r/jjoptimist/home \ No newline at end of file From faba174e191f93256302e2cd264cf000c9c36d90 Mon Sep 17 00:00:00 2001 From: JJOptimist <86833563+JJOptimist@users.noreply.github.com> Date: Tue, 21 Jan 2025 11:46:13 +0100 Subject: [PATCH 7/8] Update examples/gno.land/r/jjoptimist/home/config.gno Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> --- examples/gno.land/r/jjoptimist/home/config.gno | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/gno.land/r/jjoptimist/home/config.gno b/examples/gno.land/r/jjoptimist/home/config.gno index bfb4b11f485..8b9983689c7 100644 --- a/examples/gno.land/r/jjoptimist/home/config.gno +++ b/examples/gno.land/r/jjoptimist/home/config.gno @@ -17,8 +17,6 @@ var config = Config { Description: "Exploring Gno and building on-chain", Github: "jjoptimist", } - - var Ownable = ownable.NewWithAddress(std.Address("g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj")) func GetConfig() Config { From 99a6ff4804f9b77d9627dfa600931cf06a93c5e5 Mon Sep 17 00:00:00 2001 From: JJOptimist <86833563+JJOptimist@users.noreply.github.com> Date: Tue, 21 Jan 2025 11:46:29 +0100 Subject: [PATCH 8/8] Update examples/gno.land/r/jjoptimist/home/home.gno Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> --- examples/gno.land/r/jjoptimist/home/home.gno | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/gno.land/r/jjoptimist/home/home.gno b/examples/gno.land/r/jjoptimist/home/home.gno index 0a822fe0141..4ea29d1baf9 100644 --- a/examples/gno.land/r/jjoptimist/home/home.gno +++ b/examples/gno.land/r/jjoptimist/home/home.gno @@ -39,9 +39,7 @@ const ( -"-` ) -var ( - creation time.Time -) +var creation time.Time func getGnomeArt(height int64) string { var art string