Skip to content

Commit

Permalink
Extra local server tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Jul 17, 2024
1 parent 884ce48 commit 57a5844
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
1 change: 0 additions & 1 deletion convex-peer/src/main/java/convex/api/ConvexLocal.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ public InetSocketAddress getHostAddress() {

@Override
public Long getBalance() {
// TODO Auto-generated method stub
return server.getPeer().getConsensusState().getBalance(address);
}

Expand Down
33 changes: 33 additions & 0 deletions convex-peer/src/test/java/convex/peer/ServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 57a5844

Please sign in to comment.