diff --git a/examples/gno.land/r/demo/keystore/keystore.gno b/examples/gno.land/r/demo/keystore/keystore.gno index ebe123d6198..7c545ab8959 100644 --- a/examples/gno.land/r/demo/keystore/keystore.gno +++ b/examples/gno.land/r/demo/keystore/keystore.gno @@ -128,13 +128,11 @@ func size(owner string) string { return ufmt.Sprintf("%d", keystore.Data.Size()) } -// Render provides url access to the functions of the keystore +// Render provides read-only url access to the functions of the keystore // "" -> show all keystores listed by owner // "owner" -> show all keys for that owner's keystore // "owner:size" -> returns size of owner's keystore // "owner:get:key" -> show value for that key in owner's keystore -// "owner:set:key:value" -> sets a key-value pair for owner's keystore (owner must be caller) -// "owner:remove:key" -> removes key from owner keystore (owner must be caller) func Render(p string) string { var response string args := strings.Split(p, ":") @@ -175,18 +173,6 @@ func Render(p string) string { key := args[2] if cmd == "get" { return get(owner, key) - } else if cmd == "remove" { - // remove will only work if caller is owner - return remove(owner, key) - } - } else if numArgs == 4 { - owner := args[0] - cmd := args[1] - key := args[2] - val := args[3] - if cmd == "set" { - // set only works if caller is owner - return set(owner, key, val) } } return response diff --git a/examples/gno.land/r/demo/keystore/keystore_test.gno b/examples/gno.land/r/demo/keystore/keystore_test.gno index 9f689ae6c14..998c8457751 100644 --- a/examples/gno.land/r/demo/keystore/keystore_test.gno +++ b/examples/gno.land/r/demo/keystore/keystore_test.gno @@ -42,8 +42,6 @@ func TestRender(t *testing.T) { {author1, author2, []string{"get", "hello"}, "universe"}, // either author can get the other info {author2, author1, []string{"get", "hello"}, "world"}, - // cannot perform write operations is owner (author2) is not caller (author1) - {author1, author2, []string{"set", "hello", "should not work"}, StatusNoWriteAccess}, {author1, author2, []string{"get", "hello"}, "universe"}, // anyone can view the databases {author1, author2, []string{}, `- [g1v96hg6r0wgc47h6lta047h6lta047h6lm33tq6](/r/demo/keystore:g1v96hg6r0wgc47h6lta047h6lta047h6lm33tq6) (2 keys) @@ -64,7 +62,14 @@ func TestRender(t *testing.T) { p = strings.TrimSuffix(p, ":") t.Run(p, func(t *testing.T) { std.TestSetOrigCaller(tc.caller) - act := strings.TrimSpace(Render(p)) + var act string + if len(tc.ps) > 0 && tc.ps[0] == "set" { + act = strings.TrimSpace(Set(tc.ps[1], tc.ps[2])) + } else if len(tc.ps) > 0 && tc.ps[0] == "remove" { + act = strings.TrimSpace(Remove(tc.ps[1])) + } else { + act = strings.TrimSpace(Render(p)) + } if act != tc.exp { t.Errorf("%v -> '%s', got '%s', wanted '%s'", tc.ps, p, act, tc.exp) }