Skip to content

Commit

Permalink
ConvexDirect updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Jan 2, 2025
1 parent 2dcd50f commit b928d70
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion convex-core/src/main/java/convex/core/cvm/Ops.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static <T extends ACell> AOp<T> ensureOp(ACell a) {
* @return
*/
@SuppressWarnings("unchecked")
public static <T extends ACell> AOp<T> castOp(AOp<?> a) {
public static <T extends ACell> AOp<T> castOp(ACell a) {
if (a==null) return Constant.nil();
if (a instanceof AOp) {
return (AOp<T>)a;
Expand Down
8 changes: 7 additions & 1 deletion convex-peer/src/main/java/convex/api/ConvexDirect.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException;

import convex.core.ErrorCodes;
import convex.core.Result;
import convex.core.ResultContext;
import convex.core.cpos.Block;
Expand Down Expand Up @@ -67,11 +68,16 @@ public synchronized CompletableFuture<Result> transact(SignedData<ATransaction>
p=p.updateTimestamp(ts);
p=p.proposeBlock(block);
p=p.mergeBeliefs();
p=p.mergeBeliefs();
p=p.mergeBeliefs();
p=p.updateState();
long blockNum=p.getPeerOrder().count()-1;
long blockNum=p.getPeerOrder().getBlockCount()-1;
peer=p;

Result result= p.getResult(blockNum, 0);
if (result==null) {
result=Result.error(ErrorCodes.UNEXPECTED, "No result available?");
}
return CompletableFuture.completedFuture(result.withID(id));
} catch (Exception e) {
return CompletableFuture.completedFuture(Result.fromException(e));
Expand Down
8 changes: 3 additions & 5 deletions convex-peer/src/test/java/convex/api/ConvexDirectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
import convex.core.cvm.State;
import convex.core.data.prim.CVMLong;
import convex.core.init.Init;
import convex.core.init.InitTest;
import convex.core.lang.ACVMTest;

/**
* Tests for Convex Direct client
*/
public class ConvexDirectTest extends ACVMTest {
public class ConvexDirectTest {
static final AKeyPair peerKey=AKeyPair.createSeeded(5675675);

@Test public void testSetup() throws InterruptedException {
Expand All @@ -29,12 +27,12 @@ public class ConvexDirectTest extends ACVMTest {
Address addr=convex.getAddress();

assertTrue(convex.isConnected());
assertEquals(InitTest.FIRST_PEER_ADDRESS,addr);
assertEquals(Init.GENESIS_PEER_ADDRESS,addr);

assertEquals(addr,convex.query("*address*").join().getValue());

Result r=convex.transactSync("(+ 1 2)");
assertFalse(r.isError(),()->"Expected ed error: "+r);
assertFalse(r.isError(),()->"Expected no error but got: "+r);
assertEquals(CVMLong.create(3),r.getValue());
}
}

0 comments on commit b928d70

Please sign in to comment.