From f76c480e9bf21fd584a14dfd88151828074f144d Mon Sep 17 00:00:00 2001 From: JJOptimist Date: Wed, 25 Dec 2024 13:03:40 +0100 Subject: [PATCH 1/3] 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/3] 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/3] 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