From 078cd7109b215a90a1c5387b8248e69e605a141c Mon Sep 17 00:00:00 2001
From: Hariom Verma <hariom18599@gmail.com>
Date: Tue, 26 Sep 2023 20:13:27 +0530
Subject: [PATCH 1/6] feat: implement realm for manual rewards

---
 .github/workflows/rules.yml        |  4 +-
 Makefile                           | 20 +++++--
 realm/{ => chess}/chess.gno        |  0
 realm/{ => chess}/chess_test.gno   |  0
 realm/{ => chess}/discovery.gno    |  0
 realm/{ => chess}/glicko2.gno      |  0
 realm/{ => chess}/glicko2_test.gno |  0
 realm/{ => chess}/gno.mod          |  0
 realm/{ => chess}/hash.gno         |  0
 realm/{ => chess}/lobby.gno        |  0
 realm/{ => chess}/lobby_test.gno   |  0
 realm/{ => chess}/rules.gno        |  0
 realm/{ => chess}/rules_test.gno   |  0
 realm/{ => chess}/time.gno         |  0
 realm/{ => chess}/util.gno         |  0
 realm/reward_entry/entry.gno       | 87 ++++++++++++++++++++++++++++++
 realm/reward_entry/gno.mod         |  6 +++
 realm/reward_entry/whitelist.gno   | 17 ++++++
 18 files changed, 127 insertions(+), 7 deletions(-)
 rename realm/{ => chess}/chess.gno (100%)
 rename realm/{ => chess}/chess_test.gno (100%)
 rename realm/{ => chess}/discovery.gno (100%)
 rename realm/{ => chess}/glicko2.gno (100%)
 rename realm/{ => chess}/glicko2_test.gno (100%)
 rename realm/{ => chess}/gno.mod (100%)
 rename realm/{ => chess}/hash.gno (100%)
 rename realm/{ => chess}/lobby.gno (100%)
 rename realm/{ => chess}/lobby_test.gno (100%)
 rename realm/{ => chess}/rules.gno (100%)
 rename realm/{ => chess}/rules_test.gno (100%)
 rename realm/{ => chess}/time.gno (100%)
 rename realm/{ => chess}/util.gno (100%)
 create mode 100644 realm/reward_entry/entry.gno
 create mode 100644 realm/reward_entry/gno.mod
 create mode 100644 realm/reward_entry/whitelist.gno

diff --git a/.github/workflows/rules.yml b/.github/workflows/rules.yml
index ab4b62a1..a678b147 100644
--- a/.github/workflows/rules.yml
+++ b/.github/workflows/rules.yml
@@ -3,7 +3,7 @@ name: rules
 on:
   pull_request:
     paths:
-      - "realm/rules.gno"
+      - "realm/chess/rules.gno"
   push:
     branches:
       - master
@@ -19,4 +19,4 @@ jobs:
         with:
           go-version: 'stable'
       - run: go mod download -x
-      - run: go run github.com/gnolang/gno/gnovm/cmd/gno test -verbose -run 'TestPerft' ./realm
+      - run: go run github.com/gnolang/gno/gnovm/cmd/gno test -verbose -run 'TestPerft' ./realm/chess
diff --git a/Makefile b/Makefile
index d507c237..37e18c93 100644
--- a/Makefile
+++ b/Makefile
@@ -78,13 +78,23 @@ help: ## Display this help message.
 	cd web; npm run build
 	cd web; npm run dev
 
-4_deploy_realm: ## Deploy GnoChess realm on local node.
+4_deploy_chess_realm: ## Deploy GnoChess realm on local node.
 	echo | $(GNOKEY) maketx addpkg \
 	  --insecure-password-stdin \
 	  --gas-wanted 20000000 \
 	  --gas-fee 1ugnot \
 	  --pkgpath gno.land/r/demo/chess \
-	  --pkgdir ./realm \
+	  --pkgdir ./realm/chess \
+	  --broadcast \
+	  DeployKey
+
+z_deploy_reward_entry_realm: ## Deploy reward entry realm on local node.
+	echo | $(GNOKEY) maketx addpkg \
+	  --insecure-password-stdin \
+	  --gas-wanted 2000000 \
+	  --gas-fee 1ugnot \
+	  --pkgpath gno.land/r/demo/reward_entry \
+	  --pkgdir ./realm/reward_entry \
 	  --broadcast \
 	  DeployKey
 
@@ -96,14 +106,14 @@ z_use_remote_gno: ## Use the remote 'github.com/gnolang/gno' module and remove a
 	@echo "Switching to remote gno module..."
 	@go mod edit -dropreplace github.com/gnolang/gno
 
-z_test_realm: ## Test the realm.
+z_test_realms: ## Test the realms.
 	go run github.com/gnolang/gno/gnovm/cmd/gno test --verbose ./realm
 
 z_test_integration: ## Test the realm.
 	go test -v -run='TestIntegration/.*'  .
 
-z_build_realm: ## Precompile and build the generated Go files. Assumes a working clone of gno in ../gno.
+z_build_chess_realm: ## Precompile and build the generated Go files. Assumes a working clone of gno in ../gno.
 	mkdir -p ../gno/examples/gno.land/r/gnochess
-	cp -rf realm/*.gno ../gno/examples/gno.land/r/gnochess
+	cp -rf realm/chess/*.gno ../gno/examples/gno.land/r/gnochess
 	go run github.com/gnolang/gno/gnovm/cmd/gno precompile --verbose ../gno/examples/gno.land
 	go run github.com/gnolang/gno/gnovm/cmd/gno build --verbose ../gno/examples/gno.land/r/gnochess
diff --git a/realm/chess.gno b/realm/chess/chess.gno
similarity index 100%
rename from realm/chess.gno
rename to realm/chess/chess.gno
diff --git a/realm/chess_test.gno b/realm/chess/chess_test.gno
similarity index 100%
rename from realm/chess_test.gno
rename to realm/chess/chess_test.gno
diff --git a/realm/discovery.gno b/realm/chess/discovery.gno
similarity index 100%
rename from realm/discovery.gno
rename to realm/chess/discovery.gno
diff --git a/realm/glicko2.gno b/realm/chess/glicko2.gno
similarity index 100%
rename from realm/glicko2.gno
rename to realm/chess/glicko2.gno
diff --git a/realm/glicko2_test.gno b/realm/chess/glicko2_test.gno
similarity index 100%
rename from realm/glicko2_test.gno
rename to realm/chess/glicko2_test.gno
diff --git a/realm/gno.mod b/realm/chess/gno.mod
similarity index 100%
rename from realm/gno.mod
rename to realm/chess/gno.mod
diff --git a/realm/hash.gno b/realm/chess/hash.gno
similarity index 100%
rename from realm/hash.gno
rename to realm/chess/hash.gno
diff --git a/realm/lobby.gno b/realm/chess/lobby.gno
similarity index 100%
rename from realm/lobby.gno
rename to realm/chess/lobby.gno
diff --git a/realm/lobby_test.gno b/realm/chess/lobby_test.gno
similarity index 100%
rename from realm/lobby_test.gno
rename to realm/chess/lobby_test.gno
diff --git a/realm/rules.gno b/realm/chess/rules.gno
similarity index 100%
rename from realm/rules.gno
rename to realm/chess/rules.gno
diff --git a/realm/rules_test.gno b/realm/chess/rules_test.gno
similarity index 100%
rename from realm/rules_test.gno
rename to realm/chess/rules_test.gno
diff --git a/realm/time.gno b/realm/chess/time.gno
similarity index 100%
rename from realm/time.gno
rename to realm/chess/time.gno
diff --git a/realm/util.gno b/realm/chess/util.gno
similarity index 100%
rename from realm/util.gno
rename to realm/chess/util.gno
diff --git a/realm/reward_entry/entry.gno b/realm/reward_entry/entry.gno
new file mode 100644
index 00000000..b95f53dc
--- /dev/null
+++ b/realm/reward_entry/entry.gno
@@ -0,0 +1,87 @@
+package reward_entry
+
+import (
+	"sort"
+	"std"
+	"time"
+
+	"gno.land/p/demo/avl"
+	"gno.land/p/demo/ufmt"
+)
+
+var entries avl.Tree // address -> *RewardEntry
+
+// RewardEntry represents a reward entry
+type RewardEntry struct {
+	address std.Address
+	points  uint64
+	reason  string
+
+	updatedAt time.Time
+	updatedBy std.Address
+}
+
+func SetRewardEntry(address std.Address, points uint64, reason string) {
+	std.AssertOriginCall()
+	caller := std.GetOrigCaller()
+	assertIsWhiteListed(caller)
+
+	entry := &RewardEntry{
+		address: address,
+		points:  points,
+		reason:  reason,
+
+		updatedAt: time.Now(),
+		updatedBy: caller,
+	}
+	entries.Set(address.String(), entry)
+}
+
+func rewardEntrySorted() []RewardEntry {
+	sorted := []RewardEntry{}
+	entries.Iterate("", "", func(key string, value interface{}) bool {
+		entry := value.(*RewardEntry)
+		i := sort.Search(len(sorted), func(i int) bool { return sorted[i].points <= entry.points })
+		if i > len(sorted) && sorted[i].points == entry.points {
+			i++
+		}
+		sorted = append(sorted, RewardEntry{})
+		copy(sorted[i+1:], sorted[i:])
+		sorted[i] = *entry
+		return false
+	})
+
+	return sorted
+}
+
+func Render(path string) string {
+	switch {
+	case path == "":
+		entries := rewardEntrySorted()
+		return markdown(entries)
+	default:
+		return "404\n"
+	}
+}
+
+func markdown(in []RewardEntry) string {
+	res := "# Reward entries:\n\n"
+
+	if len(in) == 0 {
+		res += "*No reward entry found*\n"
+		return res
+	}
+
+	// Create a table header
+	res += "| Address         | Points    | Reason          | Updated-by | Updated-at |\n"
+	res += "| --------------- | --------- | --------------- | ---------- | ---------- |\n"
+
+	// Iterate over reward entries and format them as Markdown rows
+	for _, entry := range in {
+		updatedAt := entry.updatedAt.Format(time.UnixDate)
+		row := ufmt.Sprintf("| %s | %dpoints | %s | %s | %s |\n", entry.address.String(), entry.points, entry.reason, entry.updatedBy.String(), updatedAt)
+		res += row
+	}
+
+	return res
+}
diff --git a/realm/reward_entry/gno.mod b/realm/reward_entry/gno.mod
new file mode 100644
index 00000000..0d2bad77
--- /dev/null
+++ b/realm/reward_entry/gno.mod
@@ -0,0 +1,6 @@
+module gno.land/r/demo/reward_entry
+
+require (
+	"gno.land/p/demo/avl" v0.0.0-latest
+	"gno.land/p/demo/ufmt" v0.0.0-latest
+)
diff --git a/realm/reward_entry/whitelist.gno b/realm/reward_entry/whitelist.gno
new file mode 100644
index 00000000..6002e8de
--- /dev/null
+++ b/realm/reward_entry/whitelist.gno
@@ -0,0 +1,17 @@
+package reward_entry
+
+import "std"
+
+// XXX: Update as required
+var whitelist = []string{
+	"g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",
+}
+
+func assertIsWhiteListed(address std.Address) {
+	for _, e := range whitelist {
+		if e == address.String() {
+			return
+		}
+	}
+	panic("restricted access")
+}

From e3bd3d4b4a250d8204b441aaf2534ba4943862d3 Mon Sep 17 00:00:00 2001
From: Hariom Verma <hariom18599@gmail.com>
Date: Tue, 26 Sep 2023 23:34:30 +0530
Subject: [PATCH 2/6] Move files from /realm -> /r

---
 .github/workflows/rules.yml             |  4 +--
 Makefile                                | 11 +++----
 {realm => r}/chess/chess.gno            |  0
 {realm => r}/chess/chess_test.gno       |  0
 {realm => r}/chess/discovery.gno        |  0
 {realm => r}/chess/glicko2.gno          |  0
 {realm => r}/chess/glicko2_test.gno     |  0
 {realm => r}/chess/gno.mod              |  0
 {realm => r}/chess/hash.gno             |  0
 {realm => r}/chess/lobby.gno            |  0
 {realm => r}/chess/lobby_test.gno       |  0
 {realm => r}/chess/rules.gno            |  0
 {realm => r}/chess/rules_test.gno       |  0
 {realm => r}/chess/time.gno             |  0
 {realm => r}/chess/util.gno             |  0
 {realm => r}/reward_entry/entry.gno     |  0
 {realm => r}/reward_entry/gno.mod       |  0
 {realm => r}/reward_entry/whitelist.gno |  0
 r/reward_entry/whitelist_test.gno       | 41 +++++++++++++++++++++++++
 19 files changed, 48 insertions(+), 8 deletions(-)
 rename {realm => r}/chess/chess.gno (100%)
 rename {realm => r}/chess/chess_test.gno (100%)
 rename {realm => r}/chess/discovery.gno (100%)
 rename {realm => r}/chess/glicko2.gno (100%)
 rename {realm => r}/chess/glicko2_test.gno (100%)
 rename {realm => r}/chess/gno.mod (100%)
 rename {realm => r}/chess/hash.gno (100%)
 rename {realm => r}/chess/lobby.gno (100%)
 rename {realm => r}/chess/lobby_test.gno (100%)
 rename {realm => r}/chess/rules.gno (100%)
 rename {realm => r}/chess/rules_test.gno (100%)
 rename {realm => r}/chess/time.gno (100%)
 rename {realm => r}/chess/util.gno (100%)
 rename {realm => r}/reward_entry/entry.gno (100%)
 rename {realm => r}/reward_entry/gno.mod (100%)
 rename {realm => r}/reward_entry/whitelist.gno (100%)
 create mode 100644 r/reward_entry/whitelist_test.gno

diff --git a/.github/workflows/rules.yml b/.github/workflows/rules.yml
index a678b147..2bd84b90 100644
--- a/.github/workflows/rules.yml
+++ b/.github/workflows/rules.yml
@@ -3,7 +3,7 @@ name: rules
 on:
   pull_request:
     paths:
-      - "realm/chess/rules.gno"
+      - "r/chess/rules.gno"
   push:
     branches:
       - master
@@ -19,4 +19,4 @@ jobs:
         with:
           go-version: 'stable'
       - run: go mod download -x
-      - run: go run github.com/gnolang/gno/gnovm/cmd/gno test -verbose -run 'TestPerft' ./realm/chess
+      - run: go run github.com/gnolang/gno/gnovm/cmd/gno test -verbose -run 'TestPerft' ./r/chess
diff --git a/Makefile b/Makefile
index 37e18c93..5cfe5df7 100644
--- a/Makefile
+++ b/Makefile
@@ -78,23 +78,22 @@ help: ## Display this help message.
 	cd web; npm run build
 	cd web; npm run dev
 
-4_deploy_chess_realm: ## Deploy GnoChess realm on local node.
+4_deploy_realms: ## Deploy realms on local node.
 	echo | $(GNOKEY) maketx addpkg \
 	  --insecure-password-stdin \
 	  --gas-wanted 20000000 \
 	  --gas-fee 1ugnot \
 	  --pkgpath gno.land/r/demo/chess \
-	  --pkgdir ./realm/chess \
+	  --pkgdir ./r/chess \
 	  --broadcast \
 	  DeployKey
-
-z_deploy_reward_entry_realm: ## Deploy reward entry realm on local node.
+	
 	echo | $(GNOKEY) maketx addpkg \
 	  --insecure-password-stdin \
 	  --gas-wanted 2000000 \
 	  --gas-fee 1ugnot \
 	  --pkgpath gno.land/r/demo/reward_entry \
-	  --pkgdir ./realm/reward_entry \
+	  --pkgdir ./r/reward_entry \
 	  --broadcast \
 	  DeployKey
 
@@ -114,6 +113,6 @@ z_test_integration: ## Test the realm.
 
 z_build_chess_realm: ## Precompile and build the generated Go files. Assumes a working clone of gno in ../gno.
 	mkdir -p ../gno/examples/gno.land/r/gnochess
-	cp -rf realm/chess/*.gno ../gno/examples/gno.land/r/gnochess
+	cp -rf r/chess/*.gno ../gno/examples/gno.land/r/gnochess
 	go run github.com/gnolang/gno/gnovm/cmd/gno precompile --verbose ../gno/examples/gno.land
 	go run github.com/gnolang/gno/gnovm/cmd/gno build --verbose ../gno/examples/gno.land/r/gnochess
diff --git a/realm/chess/chess.gno b/r/chess/chess.gno
similarity index 100%
rename from realm/chess/chess.gno
rename to r/chess/chess.gno
diff --git a/realm/chess/chess_test.gno b/r/chess/chess_test.gno
similarity index 100%
rename from realm/chess/chess_test.gno
rename to r/chess/chess_test.gno
diff --git a/realm/chess/discovery.gno b/r/chess/discovery.gno
similarity index 100%
rename from realm/chess/discovery.gno
rename to r/chess/discovery.gno
diff --git a/realm/chess/glicko2.gno b/r/chess/glicko2.gno
similarity index 100%
rename from realm/chess/glicko2.gno
rename to r/chess/glicko2.gno
diff --git a/realm/chess/glicko2_test.gno b/r/chess/glicko2_test.gno
similarity index 100%
rename from realm/chess/glicko2_test.gno
rename to r/chess/glicko2_test.gno
diff --git a/realm/chess/gno.mod b/r/chess/gno.mod
similarity index 100%
rename from realm/chess/gno.mod
rename to r/chess/gno.mod
diff --git a/realm/chess/hash.gno b/r/chess/hash.gno
similarity index 100%
rename from realm/chess/hash.gno
rename to r/chess/hash.gno
diff --git a/realm/chess/lobby.gno b/r/chess/lobby.gno
similarity index 100%
rename from realm/chess/lobby.gno
rename to r/chess/lobby.gno
diff --git a/realm/chess/lobby_test.gno b/r/chess/lobby_test.gno
similarity index 100%
rename from realm/chess/lobby_test.gno
rename to r/chess/lobby_test.gno
diff --git a/realm/chess/rules.gno b/r/chess/rules.gno
similarity index 100%
rename from realm/chess/rules.gno
rename to r/chess/rules.gno
diff --git a/realm/chess/rules_test.gno b/r/chess/rules_test.gno
similarity index 100%
rename from realm/chess/rules_test.gno
rename to r/chess/rules_test.gno
diff --git a/realm/chess/time.gno b/r/chess/time.gno
similarity index 100%
rename from realm/chess/time.gno
rename to r/chess/time.gno
diff --git a/realm/chess/util.gno b/r/chess/util.gno
similarity index 100%
rename from realm/chess/util.gno
rename to r/chess/util.gno
diff --git a/realm/reward_entry/entry.gno b/r/reward_entry/entry.gno
similarity index 100%
rename from realm/reward_entry/entry.gno
rename to r/reward_entry/entry.gno
diff --git a/realm/reward_entry/gno.mod b/r/reward_entry/gno.mod
similarity index 100%
rename from realm/reward_entry/gno.mod
rename to r/reward_entry/gno.mod
diff --git a/realm/reward_entry/whitelist.gno b/r/reward_entry/whitelist.gno
similarity index 100%
rename from realm/reward_entry/whitelist.gno
rename to r/reward_entry/whitelist.gno
diff --git a/r/reward_entry/whitelist_test.gno b/r/reward_entry/whitelist_test.gno
new file mode 100644
index 00000000..b51fb436
--- /dev/null
+++ b/r/reward_entry/whitelist_test.gno
@@ -0,0 +1,41 @@
+package reward_entry
+
+import (
+	"std"
+	"testing"
+)
+
+func TestAssertIsWhiteListed(t *testing.T) {
+	// Mock whitelist
+	whitelist := []string{std.Address("address1"), std.Address("address2"), std.Address("address3")}
+
+	// Test with a valid address
+	validAddress := std.Address("address1")
+	assertIsWhiteListed(validAddress) // This should not panic
+
+	// // Test with an invalid address
+	// invalidAddress := std.Address("invalid_address")
+
+	// // This should cause a panic
+	// func() {
+	// 	defer func() {
+	// 		if r := recover(); r == nil {
+	// 			t.Errorf("Expected panic for invalid address, but the function did not panic")
+	// 		}
+	// 	}()
+	// 	assertIsWhiteListed(invalidAddress)
+	// }()
+
+	// // Test with an empty whitelist
+	// whitelist = []string{}
+
+	// // This should cause a panic
+	// func() {
+	// 	defer func() {
+	// 		if r := recover(); r == nil {
+	// 			t.Errorf("Expected panic for empty whitelist, but the function did not panic")
+	// 		}
+	// 	}()
+	// 	assertIsWhiteListed(validAddress)
+	// }()
+}

From df7cb717deb853fc050ff2abc6e187ffcd68d6c1 Mon Sep 17 00:00:00 2001
From: Hariom Verma <hariom18599@gmail.com>
Date: Tue, 26 Sep 2023 23:37:42 +0530
Subject: [PATCH 3/6] Change remaining realm -> r

---
 .github/workflows/realm.yml | 4 ++--
 Makefile                    | 2 +-
 docker-compose.yml          | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/realm.yml b/.github/workflows/realm.yml
index 498e717e..678f1863 100644
--- a/.github/workflows/realm.yml
+++ b/.github/workflows/realm.yml
@@ -3,7 +3,7 @@ name: realm
 on:
   pull_request:
     paths:
-      - "realm/**"
+      - "r/**"
       - "Makefile"
       - "go.sum"
   push:
@@ -21,4 +21,4 @@ jobs:
         with:
           go-version: 'stable'
       - run: go mod download -x
-      - run: go run github.com/gnolang/gno/gnovm/cmd/gno test -verbose -run 'Test([^P]|P[^e])' ./realm
+      - run: go run github.com/gnolang/gno/gnovm/cmd/gno test -verbose -run 'Test([^P]|P[^e])' ./r
diff --git a/Makefile b/Makefile
index 5cfe5df7..d953c2fd 100644
--- a/Makefile
+++ b/Makefile
@@ -106,7 +106,7 @@ z_use_remote_gno: ## Use the remote 'github.com/gnolang/gno' module and remove a
 	@go mod edit -dropreplace github.com/gnolang/gno
 
 z_test_realms: ## Test the realms.
-	go run github.com/gnolang/gno/gnovm/cmd/gno test --verbose ./realm
+	go run github.com/gnolang/gno/gnovm/cmd/gno test --verbose ./r
 
 z_test_integration: ## Test the realm.
 	go test -v -run='TestIntegration/.*'  .
diff --git a/docker-compose.yml b/docker-compose.yml
index 9761ae2a..bd3f68d9 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -29,7 +29,7 @@ services:
     depends_on:
       - gnoland
     volumes:
-      - "./realm:/realm"
+      - "./r:/r"
     logging:
       driver: "json-file"
       options:

From 2a393ea24f542cc2347439b61cc9c327afbfbf40 Mon Sep 17 00:00:00 2001
From: Hariom Verma <hariom18599@gmail.com>
Date: Wed, 27 Sep 2023 00:03:24 +0530
Subject: [PATCH 4/6] fixups

---
 r/reward_entry/whitelist_test.gno    | 41 ----------------------------
 tutorial/02_move_validator/README.md |  2 +-
 util/devnet/docker-compose.yml       |  2 +-
 3 files changed, 2 insertions(+), 43 deletions(-)
 delete mode 100644 r/reward_entry/whitelist_test.gno

diff --git a/r/reward_entry/whitelist_test.gno b/r/reward_entry/whitelist_test.gno
deleted file mode 100644
index b51fb436..00000000
--- a/r/reward_entry/whitelist_test.gno
+++ /dev/null
@@ -1,41 +0,0 @@
-package reward_entry
-
-import (
-	"std"
-	"testing"
-)
-
-func TestAssertIsWhiteListed(t *testing.T) {
-	// Mock whitelist
-	whitelist := []string{std.Address("address1"), std.Address("address2"), std.Address("address3")}
-
-	// Test with a valid address
-	validAddress := std.Address("address1")
-	assertIsWhiteListed(validAddress) // This should not panic
-
-	// // Test with an invalid address
-	// invalidAddress := std.Address("invalid_address")
-
-	// // This should cause a panic
-	// func() {
-	// 	defer func() {
-	// 		if r := recover(); r == nil {
-	// 			t.Errorf("Expected panic for invalid address, but the function did not panic")
-	// 		}
-	// 	}()
-	// 	assertIsWhiteListed(invalidAddress)
-	// }()
-
-	// // Test with an empty whitelist
-	// whitelist = []string{}
-
-	// // This should cause a panic
-	// func() {
-	// 	defer func() {
-	// 		if r := recover(); r == nil {
-	// 			t.Errorf("Expected panic for empty whitelist, but the function did not panic")
-	// 		}
-	// 	}()
-	// 	assertIsWhiteListed(validAddress)
-	// }()
-}
diff --git a/tutorial/02_move_validator/README.md b/tutorial/02_move_validator/README.md
index 02220b76..2a320279 100644
--- a/tutorial/02_move_validator/README.md
+++ b/tutorial/02_move_validator/README.md
@@ -91,7 +91,7 @@ the task of doing, we will let you simply fill in the fun parts...
 
 Open up `rules.gno` -- you should see the rough structure of a move generator
 that we've implemented for this workshop. In fact, it is a trimmed down version
-of the one we're using for [the full GnoChess dApp](../../realm/rules.gno), but
+of the one we're using for [the full GnoChess dApp](../../r/chess/rules.gno), but
 let's not get ahead of ourselves.
 
 By scrolling down to the `Position.validateMove` method, you should be able to
diff --git a/util/devnet/docker-compose.yml b/util/devnet/docker-compose.yml
index 95ba4e17..b1142bb8 100644
--- a/util/devnet/docker-compose.yml
+++ b/util/devnet/docker-compose.yml
@@ -18,7 +18,7 @@ services:
     networks:
       - gnonode
     volumes:
-      - "../../realm:/realm"
+      - "../../r:/r"
     restart: on-failure
     logging:
       driver: "json-file"

From 926b00c1854400825be230ce8f6dda1d2c079a14 Mon Sep 17 00:00:00 2001
From: Hariom Verma <hariom18599@gmail.com>
Date: Wed, 27 Sep 2023 03:44:07 +0530
Subject: [PATCH 5/6] Add tests

---
 r/reward_entry/entry_test.gno     | 56 +++++++++++++++++++++++++++++++
 r/reward_entry/whitelist_test.gno | 37 ++++++++++++++++++++
 2 files changed, 93 insertions(+)
 create mode 100644 r/reward_entry/entry_test.gno
 create mode 100644 r/reward_entry/whitelist_test.gno

diff --git a/r/reward_entry/entry_test.gno b/r/reward_entry/entry_test.gno
new file mode 100644
index 00000000..83afabc7
--- /dev/null
+++ b/r/reward_entry/entry_test.gno
@@ -0,0 +1,56 @@
+package reward_entry
+
+import (
+	"std"
+	"strings"
+	"testing"
+
+	"gno.land/p/demo/ufmt"
+)
+
+func TestRewardEntry(t *testing.T) {
+	// Override whitelist for testing
+	whitelist = []string{std.Address("address1"), std.Address("address2"), std.Address("address3")}
+
+	// Add reward entry for `foo`` and `bar``
+	std.TestSetOrigCaller(std.Address("address1"))
+	SetRewardEntry("foo", 1000, "oof")
+	SetRewardEntry("bar", 1500, "rab")
+
+	// `address2` modify foo's points
+	std.TestSetOrigCaller(std.Address("address2"))
+	SetRewardEntry("foo", 1200, "oof; 200 more for good handwriting")
+
+	// `unauthorized` address tries to modify foo's points
+	std.TestSetOrigCaller(std.Address("unauthorized"))
+	func() {
+		defer func() {
+			if r := recover(); r == nil {
+				t.Errorf("expected panic for unauthorized address")
+			}
+		}()
+		SetRewardEntry("foo", 1200, "oof")
+	}()
+
+	// Note: Render() prints entries in sorted order
+	// (sorted by points; high -> low)
+	expectedRows := []string{
+		"# Reward entries:",
+		"",
+		"| Address         | Points    | Reason          | Updated-by | Updated-at |",
+		"| --------------- | --------- | --------------- | ---------- |",
+		"| bar | 1500points | rab | address1 |",
+		"| foo | 1200points | oof; 200 more for good handwriting | address2 |",
+	}
+
+	out := Render("")
+	// Split the actual output into rows
+	actualRows := strings.Split(out, "\n")
+
+	// Check each row one by one
+	for i, expectedRow := range expectedRows {
+		if !strings.HasPrefix(actualRows[i], expectedRow) {
+			t.Errorf("Row %d does not match:\nExpected:\n%s\nGot:\n%s", i+1, expectedRow, actualRows[i])
+		}
+	}
+}
diff --git a/r/reward_entry/whitelist_test.gno b/r/reward_entry/whitelist_test.gno
new file mode 100644
index 00000000..b573b7f3
--- /dev/null
+++ b/r/reward_entry/whitelist_test.gno
@@ -0,0 +1,37 @@
+package reward_entry
+
+import (
+	"std"
+	"testing"
+)
+
+func TestAssertIsWhiteListed(t *testing.T) {
+	// Override whitelist for testing
+	whitelist = []string{std.Address("address1"), std.Address("address2"), std.Address("address3")}
+
+	// Test with a valid address
+	validAddress := std.Address("address1")
+	assertIsWhiteListed(validAddress) // This should not panic
+
+	// Test with an invalid address; should cause a panic
+	invalidAddress := std.Address("invalid_address")
+	func() {
+		defer func() {
+			if r := recover(); r == nil {
+				t.Errorf("expected panic for invalid address")
+			}
+		}()
+		assertIsWhiteListed(invalidAddress)
+	}()
+
+	// Test with an empty whitelist; should cause a panic
+	whitelist = []string{}
+	func() {
+		defer func() {
+			if r := recover(); r == nil {
+				t.Errorf("expected panic for empty whitelist")
+			}
+		}()
+		assertIsWhiteListed(validAddress)
+	}()
+}

From 0f83b2d043c1e12e69cacde9f3d54f8aac73aee7 Mon Sep 17 00:00:00 2001
From: Hariom Verma <hariom18599@gmail.com>
Date: Wed, 27 Sep 2023 16:48:50 +0530
Subject: [PATCH 6/6] Apply changes in deploy-realm.yml

---
 .github/workflows/deploy-realm.yml | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/deploy-realm.yml b/.github/workflows/deploy-realm.yml
index a68c0ad0..810e1039 100644
--- a/.github/workflows/deploy-realm.yml
+++ b/.github/workflows/deploy-realm.yml
@@ -3,7 +3,7 @@ name: realm
 on:
   push:
     paths:
-      - "realm/**"
+      - "r/**"
     branches:
       - main
 
@@ -25,12 +25,20 @@ jobs:
       - run: go mod download -x
       - run: |
           printf '\n\n%s\n\n' "$MNEMONIC" | $GNOKEY add --recover --insecure-password-stdin test1'
-          cd realm
           echo "" | $GNOKEY maketx addpkg \
           --gas-wanted 50000000 \
           --gas-fee 1ugnot \
           --pkgpath gno.land/r/demo/chess_${GITHUB_SHA} \
-          --pkgdir . \
+          --pkgdir r/chess \
+          --insecure-password-stdin \
+          --remote  \
+          --broadcast test1'
+
+          echo "" | $GNOKEY maketx addpkg \
+          --gas-wanted 50000000 \
+          --gas-fee 1ugnot \
+          --pkgpath gno.land/r/demo/reward_entry_${GITHUB_SHA} \
+          --pkgdir r/reward_entry \
           --insecure-password-stdin \
           --remote  \
           --broadcast test1'