Skip to content

Commit

Permalink
Prep for CNS demos
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 21, 2023
1 parent f6c5624 commit 008533d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
11 changes: 11 additions & 0 deletions convex-core/src/main/cvx/convex/registry.cvx
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
23 changes: 23 additions & 0 deletions convex-core/src/main/java/convex/core/init/Init.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ public static State createState(List<AccountKey> genesisKeys) {
State s=createBaseState(genesisKeys);
s = addStandardLibraries(s);
s = addTestingCurrencies(s);

s = addCNSTree(s);

// Final funds check
long finalTotal = s.computeTotalFunds();
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion convex-core/src/test/java/convex/lib/CNSTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 008533d

Please sign in to comment.