From 008533dd35f968ed2ca975a3924649db671ff17d Mon Sep 17 00:00:00 2001 From: mikera Date: Thu, 21 Dec 2023 15:36:49 +0000 Subject: [PATCH] Prep for CNS demos --- convex-core/src/main/cvx/convex/registry.cvx | 11 +++++++++ .../src/main/java/convex/core/init/Init.java | 23 +++++++++++++++++++ .../src/test/java/convex/lib/CNSTest.java | 6 ++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/convex-core/src/main/cvx/convex/registry.cvx b/convex-core/src/main/cvx/convex/registry.cvx index 2897c1fd0..74550de6d 100644 --- a/convex-core/src/main/cvx/convex/registry.cvx +++ b/convex-core/src/main/cvx/convex/registry.cvx @@ -134,8 +134,19 @@ )) ) ) + sym )) +(def update create) + +(defn control + [sym cont] + (if-let [rec (read sym)] + (let [[v c m] rec] + (update sym v cont m)) + (fail :STATE "CNS record does not exist"))) + + (defn change-control ^{:callable? true :doc {:description "Changes controller for a CNS node." diff --git a/convex-core/src/main/java/convex/core/init/Init.java b/convex-core/src/main/java/convex/core/init/Init.java index 34da5a570..49b4fb6b2 100644 --- a/convex-core/src/main/java/convex/core/init/Init.java +++ b/convex-core/src/main/java/convex/core/init/Init.java @@ -201,6 +201,8 @@ public static State createState(List genesisKeys) { State s=createBaseState(genesisKeys); s = addStandardLibraries(s); s = addTestingCurrencies(s); + + s = addCNSTree(s); // Final funds check long finalTotal = s.computeTotalFunds(); @@ -249,6 +251,27 @@ private static State addStandardLibraries(State s) { s = doActorDeploy(s, "convex/governance.cvx"); return s; } + + private static State addCNSTree(State s) { + Context ctx=Context.createFake(s, INIT_ADDRESS); + ctx=ctx.eval(Reader.read("(do (*registry*/create 'user.init))")); + ctx.getResult(); + + + ctx=ctx.eval(Reader.read("(import convex.trust.monitors :as mon)")); + ctx.getResult(); + + ctx=ctx.eval(Reader.read("(def tmon (mon/permit-actions :create))")); + ctx.getResult(); + + + ctx=ctx.eval(Reader.read("(do ("+TRUST_ADDRESS+"/change-control [*registry* [\"user\"]] tmon))")); + ctx.getResult(); + + + s=ctx.getState(); + return s; + } public static Address calcPeerAddress(int userCount, int index) { return Address.create(GENESIS_ADDRESS.longValue() + userCount + index); diff --git a/convex-core/src/test/java/convex/lib/CNSTest.java b/convex-core/src/test/java/convex/lib/CNSTest.java index b3062b927..98e992f4d 100644 --- a/convex-core/src/test/java/convex/lib/CNSTest.java +++ b/convex-core/src/test/java/convex/lib/CNSTest.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import org.junit.jupiter.api.Test; @@ -37,10 +38,13 @@ public class CNSTest extends ACVMTest { assertEquals(eval("[#1 #1 nil]"), eval("(*registry*/read 'init)")); } - @Test public void testCreateFromTop() { + @Test public void testCreateNestedFromTop() { Context ctx=context().forkWithAddress(Init.INIT_ADDRESS); ctx=(step(ctx,"(*registry*/create 'foo.bar.bax #17)")); assertNotError(ctx); + + assertEquals(Address.create(17),eval(ctx,"(*registry*/resolve 'foo.bar.bax)")); + assertNull(eval(ctx,"(*registry*/resolve 'foo.null.boo)")); } @Test public void testCreateTopLevel() {