Skip to content

Commit

Permalink
Extra OpenAPI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Aug 12, 2024
1 parent 4d6f0b8 commit cc0741c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
7 changes: 5 additions & 2 deletions convex-restapi/src/main/java/convex/restapi/api/ChainAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ public void faucetRequest(Context ctx) {
from=TransactionPrepareResponse.class,
type = "application/json",
exampleObjects = {
@OpenApiExampleProperty(name = "value", value = "6")
@OpenApiExampleProperty(name = "sequence", value = "14"),
@OpenApiExampleProperty(name = "address", value = "12"),
@OpenApiExampleProperty(name = "source", value = "(* 2 3)"),
@OpenApiExampleProperty(name = "hash", value = "d00c0e81031103110232012a")
}
)}),
@OpenApiResponse(status = "503",
Expand Down Expand Up @@ -442,7 +445,7 @@ public void runTransact(Context ctx) {
// Get ED25519 seed
ABlob seed = Blobs.parse(req.get("seed"));
if (!(seed instanceof ABlob))
throw new BadRequestResponse("Ed25519 seed required for transact (e.g. as hex string)");
throw new BadRequestResponse("Valid Ed25519 seed required for transact (hex string)");
if (seed.count() != AKeyPair.SEED_LENGTH)
throw new BadRequestResponse("Seed must be 32 bytes");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import org.junit.jupiter.api.Test;

import convex.core.crypto.AKeyPair;
import convex.core.data.AccountKey;
import convex.core.data.Address;
import convex.core.init.Init;
import convex.core.lang.Symbols;
import convex.java.Convex;
import convex.java.JSON;
Expand All @@ -25,6 +27,8 @@ public class RemoteClientTest {
static RESTServer server;
static int port;
static String host;
static AKeyPair skp;
static Address genesis=Init.GENESIS_ADDRESS;

@BeforeAll
public static void init() {
Expand All @@ -33,6 +37,7 @@ public static void init() {
rs.start(0);
port=rs.getPort();
server=rs;
skp=s.getKeyPair();
host="http://localhost:"+port;
}

Expand Down Expand Up @@ -73,7 +78,7 @@ public void testFaucet() {
}

@Test
public void testQuery() {
public void testAccount() {
Convex c=Convex.connect(host);
AKeyPair kp=AKeyPair.generate();
Address addr=c.createAccount(kp);
Expand All @@ -90,6 +95,19 @@ public void testQuery() {
assertEquals(JSON.toString(kp.getAccountKey()),res.get("value"));
}

@Test
public void testAccountGenesisInfo() {
Convex c=Convex.connect(host);
Address addr=genesis;
c.setAddress(addr);

// Test values for basic new account
Map<String,Object> res=c.queryAccount();
assertEquals(addr.longValue(),res.get("address"));
assertTrue(res.get("balance") instanceof Long);
assertEquals(skp.getAccountKey(),AccountKey.parse(res.get("key")));
}

@Test
public void testQueryAccount() {
Convex c=Convex.connect(host);
Expand All @@ -111,6 +129,20 @@ public void testQueryAccount() {
assertNull(res);
}

@Test
public void testTransactGenesis() {
Convex c=Convex.connect(host);
AKeyPair kp=skp;
Address addr=genesis;
c.setKeyPair(kp);
c.setAddress(addr);

Map<String,Object> rm=c.transact("(+ 1 2)");
// System.out.println(JSON.toPrettyString(rm));
assertEquals(3L,rm.get("value"));
}


@Test
public void testTransactNoFunds() {
Convex c=Convex.connect(host);
Expand Down

0 comments on commit cc0741c

Please sign in to comment.