From 57a584402abe802b774401e6444d122dc6dfa0bf Mon Sep 17 00:00:00 2001 From: mikera Date: Wed, 17 Jul 2024 14:01:16 +0100 Subject: [PATCH] Extra local server tests --- .../src/main/java/convex/api/ConvexLocal.java | 1 - .../src/test/java/convex/peer/ServerTest.java | 33 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/convex-peer/src/main/java/convex/api/ConvexLocal.java b/convex-peer/src/main/java/convex/api/ConvexLocal.java index d8cbb8860..12e8f30d5 100644 --- a/convex-peer/src/main/java/convex/api/ConvexLocal.java +++ b/convex-peer/src/main/java/convex/api/ConvexLocal.java @@ -158,7 +158,6 @@ public InetSocketAddress getHostAddress() { @Override public Long getBalance() { - // TODO Auto-generated method stub return server.getPeer().getConsensusState().getBalance(address); } diff --git a/convex-peer/src/test/java/convex/peer/ServerTest.java b/convex-peer/src/test/java/convex/peer/ServerTest.java index c84be2fed..4a74241fe 100644 --- a/convex-peer/src/test/java/convex/peer/ServerTest.java +++ b/convex-peer/src/test/java/convex/peer/ServerTest.java @@ -6,6 +6,9 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; + +import static convex.test.Assertions.*; + import java.io.IOException; import java.net.InetSocketAddress; import java.util.HashMap; @@ -88,6 +91,36 @@ protected synchronized void handleError(long id, ACell code, ACell message) { results.put(id, code); } }; + + /** + * Smoke test for ConvexLocal connection + * @throws IOException + * @throws InterruptedException + * @throws TimeoutException + */ + @Test + public void testLocalConnect() throws IOException, InterruptedException, TimeoutException { + Server server=network.SERVER; + + AKeyPair kp=server.getKeyPair(); + + Convex convex = network.CONVEX; + assertTrue(convex.getBalance()>0); + + Result r=convex.transactSync("(create-account "+kp.getAccountKey()+")"); + Address user=r.getValue(); + assertNotNull(user); + + r=convex.transactSync("(transfer "+user+" 10000000)"); + assertFalse(r.isError()); + + convex=Convex.connect(server, user, kp); + assertEquals(10000000,convex.getBalance()); + + r=convex.transactSync("(do (transfer "+user+" 100000) *balance*)"); + assertCVMEquals(10000000,r.getValue()); + + } @Test public void testServerConnect() throws IOException, InterruptedException, TimeoutException {