Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Convex-Dev/convex.git into
Browse files Browse the repository at this point in the history
develop
  • Loading branch information
mikera committed Jun 18, 2024
1 parent 8231f99 commit 26fc81a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 69 deletions.
48 changes: 24 additions & 24 deletions convex-core/src/test/java/convex/actors/RegistryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected RegistryTest() throws IOException {

@Test
public void testRegistryContract() throws IOException {
Context ctx =context();
Context ctx = context();

AHashMap<Keyword, ACell> ddo = Maps.of(Keyword.create("name"), "Bob");
ctx = ctx.actorCall(REG, 0, Symbol.create("register"), ddo);
Expand All @@ -41,67 +41,67 @@ public void testRegistryContract() throws IOException {

@Test
public void testRegistryCNS() throws IOException {
Context ctx=context();
Context ctx = context();

assertEquals(REG,eval(ctx,"(call *registry* (cns-resolve 'convex.registry))"));
assertEquals(REG, eval(ctx, "(call *registry* (cns-resolve 'convex.registry))"));
}

@Test
public void testRegistryCNSUpdate() throws IOException {
Context ctx=context();
Context ctx = context();

assertNull(eval(ctx,"(call *registry* (cns-resolve 'convex.test.foo))"));
assertNull(eval(ctx, "(call *registry* (cns-resolve 'convex.test.foo))"));

// Real Address we want for CNS mapping
final Address badAddr=Samples.BAD_ADDRESS;
final Address badAddr = Samples.BAD_ADDRESS;

ctx=step(ctx,"(call *registry* (cns-update 'convex.test.foo "+badAddr+"))");
ctx = step(ctx, "(call *registry* (cns-update 'convex.test.foo " + badAddr + "))");
assertNobodyError(ctx);

// Should fail, not a Symbol
ctx=step(ctx,"(call *registry* (cns-update \"convex.test.foo\" #1))");
ctx = step(ctx, "(call *registry* (cns-update \"convex.test.foo\" #1))");
assertArgumentError(ctx);

final Address realAddr=Address.create(1); // Init address, FWIW
ctx=exec(ctx,"(call *registry* (cns-update 'convex.test.foo "+realAddr+"))");
final Address realAddr = Address.create(1); // Init address, FWIW
ctx = exec(ctx, "(call *registry* (cns-update 'convex.test.foo " + realAddr + "))");

assertEquals(realAddr,eval(ctx,"(call *registry* (cns-resolve 'convex.test.foo))"));
assertEquals(realAddr, eval(ctx, "(call *registry* (cns-resolve 'convex.test.foo))"));

{ // Check VILLAIN can't steal CNS mapping
Context c=ctx.forkWithAddress(VILLAIN);
Context c = ctx.forkWithAddress(VILLAIN);

// VILLAIN shouldn't be able to use update on existing CNS mapping
assertTrustError(step(c,"(call *registry* (cns-update 'convex.test.foo *address*))"));
assertTrustError(step(c, "(call *registry* (cns-update 'convex.test.foo *address*))"));

// original mapping should be held
assertEquals(realAddr,eval(c,"(call *registry* (cns-resolve 'convex.test.foo))"));
assertEquals(realAddr, eval(c, "(call *registry* (cns-resolve 'convex.test.foo))"));
}

{ // Check Transfer of control to VILLAIN
Context c=exec(ctx,"(call *registry* (cns-control 'convex.test.foo "+VILLAIN+"))");
Context c = exec(ctx, "(call *registry* (cns-control 'convex.test.foo " + VILLAIN + "))");

// HERO shouldn't be able to use update or control any more
assertTrustError(step(c,"(call *registry* (cns-update 'convex.test.foo *address*))"));
assertTrustError(step(c,"(call *registry* (cns-control 'convex.test.foo *address*))"));
assertTrustError(step(c, "(call *registry* (cns-update 'convex.test.foo *address*))"));
assertTrustError(step(c, "(call *registry* (cns-control 'convex.test.foo *address*))"));

// Switch to VILLAIN
c=c.forkWithAddress(VILLAIN);
c = c.forkWithAddress(VILLAIN);

// Change mapping
c=exec(c,"(call *registry* (cns-update 'convex.test.foo *address*))");
assertEquals(VILLAIN,eval(c,"(call *registry* (cns-resolve 'convex.test.foo))"));
c = exec(c, "(call *registry* (cns-update 'convex.test.foo *address*))");
assertEquals(VILLAIN, eval(c, "(call *registry* (cns-resolve 'convex.test.foo))"));
}

{ // Check VILLAIN can create new mapping
// TODO probably shouldn't be free-for-all?

Context c=ctx.forkWithAddress(VILLAIN);
Context c = ctx.forkWithAddress(VILLAIN);

// VILLAIN shouldn't be able to use update on existing CNS mapping
c=exec(c,"(call *registry* (cns-update 'convex.villain *address*))");
c = exec(c, "(call *registry* (cns-update 'convex.villain *address*))");

// original mapping should be held
assertEquals(VILLAIN,eval(c,"(call *registry* (cns-resolve 'convex.villain))"));
assertEquals(VILLAIN, eval(c, "(call *registry* (cns-resolve 'convex.villain))"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ private void updateData() {
messageArea.setText(msg);
}

@SuppressWarnings("null")
private void updateHashLabel(ACell v, Blob b) {
StringBuilder sb=new StringBuilder();
boolean empty=(b==null);
Expand Down
91 changes: 46 additions & 45 deletions convex-restapi/src/test/java/convex/restapi/StressTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,82 +20,83 @@ public class StressTest {

static RESTServer server;
static int port;
static int CLIENTCOUNT=100;
static int TRANSCOUNT=100;
static AKeyPair KP=AKeyPair.generate();
static int CLIENTCOUNT = 100;
static int TRANSCOUNT = 100;
static AKeyPair KP = AKeyPair.generate();

static {
Server s=API.launchPeer();
RESTServer rs=RESTServer.create(s);
Server s = API.launchPeer();
RESTServer rs = RESTServer.create(s);
rs.start(0);
port=rs.getPort();
server=rs;
port = rs.getPort();
server = rs;
}

public static void main(String... args) throws InterruptedException, ExecutionException, TimeoutException {
try {
Convex convex=Convex.connect("http://localhost:"+port);
long startTime=Utils.getTimeMillis();
ArrayList<Convex> clients=new ArrayList<>(CLIENTCOUNT);
for (int i=0; i<CLIENTCOUNT; i++) {
AKeyPair kp=KP;
Convex convex = Convex.connect("http://localhost:" + port);
long startTime = Utils.getTimeMillis();

ArrayList<Convex> clients = new ArrayList<>(CLIENTCOUNT);
for (int i = 0; i < CLIENTCOUNT; i++) {
AKeyPair kp = KP;
Address clientAddr = convex.createAccount(kp);
Convex cc=Convex.connect("http://localhost:"+port);
Convex cc = Convex.connect("http://localhost:" + port);
cc.setAddress(clientAddr);
cc.setKeyPair(kp);
clients.add(cc);
}
long genTime=Utils.getTimeMillis();
System.out.println(CLIENTCOUNT+ " REST clients connected in "+compTime(startTime,genTime));
ExecutorService ex=ThreadUtils.getVirtualExecutor();
ArrayList<CompletableFuture<Object>> cfutures=ThreadUtils.futureMap (ex,cc->{

long genTime = Utils.getTimeMillis();
System.out.println(CLIENTCOUNT + " REST clients connected in " + compTime(startTime, genTime));

ExecutorService ex = ThreadUtils.getVirtualExecutor();

ArrayList<CompletableFuture<Object>> cfutures = ThreadUtils.futureMap(ex, cc -> {
for (int i = 0; i < TRANSCOUNT; i++) {
String source = "*timestamp*";
cc.query(source);
}
return null;
},clients);
}, clients);
// wait for everything to be sent
ThreadUtils.awaitAll(cfutures);
long queryTime=Utils.getTimeMillis();
System.out.println(CLIENTCOUNT * TRANSCOUNT+ " REST queries in "+compTime(queryTime,genTime));
cfutures=ThreadUtils.futureMap (ex,cc->{

long queryTime = Utils.getTimeMillis();
System.out.println(CLIENTCOUNT * TRANSCOUNT + " REST queries in " + compTime(queryTime, genTime));

cfutures = ThreadUtils.futureMap(ex, cc -> {
return cc.faucet(cc.getAddress(), 1000000);
},clients);
}, clients);
// wait for everything to be sent
ThreadUtils.awaitAll(cfutures);
long faucetTime=Utils.getTimeMillis();
System.out.println(CLIENTCOUNT+ " Faucet transactions completed in "+compTime(faucetTime,queryTime));
cfutures=ThreadUtils.futureMap (ex,cc->{

long faucetTime = Utils.getTimeMillis();
System.out.println(CLIENTCOUNT + " Faucet transactions completed in " + compTime(faucetTime, queryTime));

cfutures = ThreadUtils.futureMap(ex, cc -> {
// System.out.println(cc.queryAccount());
Map<String,Object> res = cc.transact("(def a 1)");
if (res.get("errorCode")!=null) throw new Error(JSON.toPrettyString(res));
Map<String, Object> res = cc.transact("(def a 1)");
if (res.get("errorCode") != null)
throw new Error(JSON.toPrettyString(res));
return res;
},clients);
}, clients);
// wait for everything to be sent
ThreadUtils.awaitAll(cfutures);
long transTime=Utils.getTimeMillis();
System.out.println(CLIENTCOUNT+ " transactions executed in "+compTime(faucetTime,transTime));

long transTime = Utils.getTimeMillis();
System.out.println(CLIENTCOUNT + " transactions executed in " + compTime(faucetTime, transTime));

} catch (Throwable t) {
t.printStackTrace();
} finally {
} finally {
System.exit(0);
}

}

private static String compTime(long a, long b) {
long d=Math.abs(a-b);
return d+"ms";
long d = Math.abs(a - b);
return d + "ms";
}
}

0 comments on commit 26fc81a

Please sign in to comment.