Skip to content

Commit 9dcdc23

Browse files
committed
Tidy MCP tests
1 parent 6f9f0b1 commit 9dcdc23

File tree

1 file changed

+62
-62
lines changed
  • convex-restapi/src/test/java/convex/restapi/test

1 file changed

+62
-62
lines changed

convex-restapi/src/test/java/convex/restapi/test/McpTest.java

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void testUnknownMethod() throws IOException, InterruptedException {
119119
*/
120120
@Test
121121
public void testToolCallQuery() throws IOException, InterruptedException {
122-
AMap<AString, ACell> args = Maps.of(Strings.create("source"), Strings.create("*balance*"));
122+
AMap<AString, ACell> args = Maps.of("source", "*balance*");
123123
AMap<AString, ACell> responseMap = makeToolCall("query", args);
124124
AMap<AString, ACell> structured = expectResult(responseMap);
125125
assertNotNull(RT.getIn(structured, "value"));
@@ -132,8 +132,8 @@ public void testToolCallQuery() throws IOException, InterruptedException {
132132
@Test
133133
public void testPrepareTool() throws IOException, InterruptedException {
134134
AMap<AString, ACell> args = Maps.of(
135-
Strings.create("source"), Strings.create("(* 2 3)"),
136-
Strings.create("address"), Strings.create("#11")
135+
"source", "(* 2 3)",
136+
"address", "#11"
137137
);
138138
AMap<AString, ACell> responseMap = makeToolCall("prepare", args);
139139
AMap<AString, ACell> structured = expectResult(responseMap);
@@ -150,8 +150,8 @@ public void testPrepareToolMatchesChainAPI() throws IOException, InterruptedExce
150150
AString source = Strings.create("(* 2 3)");
151151
AString addressString = Strings.create(Init.GENESIS_ADDRESS.toString());
152152
AMap<AString, ACell> mcpArgs = Maps.of(
153-
Strings.create("source"), source,
154-
Strings.create("address"), addressString
153+
"source", source,
154+
"address", addressString
155155
);
156156

157157
AMap<AString, ACell> responseMap = makeToolCall("prepare", mcpArgs);
@@ -160,8 +160,8 @@ public void testPrepareToolMatchesChainAPI() throws IOException, InterruptedExce
160160
assertNotNull(mcpHash);
161161

162162
AMap<AString, ACell> requestMap = Maps.of(
163-
Strings.create("address"), addressString,
164-
Strings.create("source"), source
163+
"address", addressString,
164+
"source", source
165165
);
166166
HttpResponse<String> restResponse = post(API_PATH + "/transaction/prepare", JSON.toString(requestMap));
167167
assertEquals(200, restResponse.statusCode());
@@ -182,7 +182,7 @@ public void testEncodeDecodeTools() throws IOException, InterruptedException {
182182
}
183183

184184
private void assertEncodeDecodeRoundTrip(String cvxLiteral, String expectedHex) throws IOException, InterruptedException {
185-
AMap<AString, ACell> encodeArgs = Maps.of(Strings.create("cvx"), Strings.create(cvxLiteral));
185+
AMap<AString, ACell> encodeArgs = Maps.of("cvx", cvxLiteral);
186186
AMap<AString, ACell> encodeResponse = makeToolCall("encode", encodeArgs);
187187
AMap<AString, ACell> encodeResult = expectResult(encodeResponse);
188188
AString cad3 = RT.getIn(encodeResult, "cad3");
@@ -191,7 +191,7 @@ private void assertEncodeDecodeRoundTrip(String cvxLiteral, String expectedHex)
191191
AString hash = RT.getIn(encodeResult, "hash");
192192
assertNotNull(hash);
193193

194-
AMap<AString, ACell> decodeArgs = Maps.of(Strings.create("cad3"), cad3);
194+
AMap<AString, ACell> decodeArgs = Maps.of("cad3", cad3);
195195
AMap<AString, ACell> decodeResponse = makeToolCall("decode", decodeArgs);
196196
AMap<AString, ACell> decodeResult = expectResult(decodeResponse);
197197
AString cvx = RT.getIn(decodeResult, "cvx");
@@ -207,8 +207,8 @@ public void testPrepareSignSubmit() throws IOException, InterruptedException {
207207
AString source = Strings.create("(* 2 3)");
208208
AString addressString = Strings.create(Init.GENESIS_ADDRESS.toString());
209209
AMap<AString, ACell> prepareArgs = Maps.of(
210-
Strings.create("source"), source,
211-
Strings.create("address"), addressString
210+
"source", source,
211+
"address", addressString
212212
);
213213

214214
AMap<AString, ACell> prepareResponse = makeToolCall("prepare", prepareArgs);
@@ -219,8 +219,8 @@ public void testPrepareSignSubmit() throws IOException, InterruptedException {
219219

220220
AString seedHex = Strings.create(KP.getSeed().toHexString());
221221
AMap<AString, ACell> signArgs = Maps.of(
222-
Strings.create("value"), hashCell,
223-
Strings.create("seed"), seedHex
222+
"value", hashCell,
223+
"seed", seedHex
224224
);
225225
AMap<AString, ACell> signResponse = makeToolCall("sign", signArgs);
226226
AMap<AString, ACell> signed = expectResult(signResponse);
@@ -232,9 +232,9 @@ public void testPrepareSignSubmit() throws IOException, InterruptedException {
232232
assertEquals(KP.sign(hashBlob), Blob.parse(signatureHex));
233233

234234
AMap<AString, ACell> submitArgs = Maps.of(
235-
Strings.create("hash"), hashCell,
236-
Strings.create("signature"), signatureHex,
237-
Strings.create("accountKey"), accountKeyHex
235+
"hash", hashCell,
236+
"signature", signatureHex,
237+
"accountKey", accountKeyHex
238238
);
239239
AMap<AString, ACell> submitResponse = makeToolCall("submit", submitArgs);
240240
AMap<AString, ACell> submitResult = expectResult(submitResponse);
@@ -251,9 +251,9 @@ public void testTransactTool() throws IOException, InterruptedException {
251251
AString addressString = Strings.create(Init.GENESIS_ADDRESS.toString());
252252
AString seedHex = Strings.create(KP.getSeed().toHexString());
253253
AMap<AString, ACell> transactArgs = Maps.of(
254-
Strings.create("source"), source,
255-
Strings.create("address"), addressString,
256-
Strings.create("seed"), seedHex
254+
"source", source,
255+
"address", addressString,
256+
"seed", seedHex
257257
);
258258

259259
AMap<AString, ACell> transactResponse = makeToolCall("transact", transactArgs);
@@ -286,7 +286,7 @@ public void testKeyGenToolRandom() throws IOException, InterruptedException {
286286
*/
287287
@Test
288288
public void testKeyGenToolWithSeed() throws IOException, InterruptedException {
289-
AMap<AString, ACell> keyGenArgs = Maps.of(Strings.create("seed"), SEED_TEST);
289+
AMap<AString, ACell> keyGenArgs = Maps.of("seed", SEED_TEST);
290290
AMap<AString, ACell> responseMap = makeToolCall("keyGen", keyGenArgs);
291291
AMap<AString, ACell> structured = expectResult(responseMap);
292292

@@ -311,7 +311,7 @@ public void testKeyGenToolWithSeed() throws IOException, InterruptedException {
311311
@Test
312312
public void testKeyGenToolWithSeedWithPrefix() throws IOException, InterruptedException {
313313
AString seedHexWithPrefix = Strings.create("0x" + SEED_TEST.toString());
314-
AMap<AString, ACell> keyGenArgs = Maps.of(Strings.create("seed"), seedHexWithPrefix);
314+
AMap<AString, ACell> keyGenArgs = Maps.of("seed", seedHexWithPrefix);
315315

316316
AMap<AString, ACell> responseMap = makeToolCall("keyGen", keyGenArgs);
317317
AMap<AString, ACell> structured = expectResult(responseMap);
@@ -325,7 +325,7 @@ public void testKeyGenToolWithSeedWithPrefix() throws IOException, InterruptedEx
325325
assertEquals(expectedSeed, seed, "Seed should match the provided seed with 0x prefix");
326326

327327
// Verify the public key is the same whether input has 0x prefix or not
328-
AMap<AString, ACell> keyGenArgsNoPrefix = Maps.of(Strings.create("seed"), SEED_TEST);
328+
AMap<AString, ACell> keyGenArgsNoPrefix = Maps.of("seed", SEED_TEST);
329329
AMap<AString, ACell> responseMap2 = makeToolCall("keyGen", keyGenArgsNoPrefix);
330330
AMap<AString, ACell> structured2 = expectResult(responseMap2);
331331
AString publicKey2 = RT.getIn(structured2, "publicKey");
@@ -336,7 +336,7 @@ public void testKeyGenToolWithSeedWithPrefix() throws IOException, InterruptedEx
336336
* Helper method to generate a key pair and return the public key.
337337
*/
338338
private AString generateKeyPair(AString seed) throws IOException, InterruptedException {
339-
AMap<AString, ACell> keyGenArgs = Maps.of(Strings.create("seed"), seed);
339+
AMap<AString, ACell> keyGenArgs = Maps.of("seed", seed);
340340
AMap<AString, ACell> keyGenResponse = makeToolCall("keyGen", keyGenArgs);
341341
AMap<AString, ACell> keyGenResult = expectResult(keyGenResponse);
342342
return RT.getIn(keyGenResult, "publicKey");
@@ -347,8 +347,8 @@ private AString generateKeyPair(AString seed) throws IOException, InterruptedExc
347347
*/
348348
private AString signData(AString valueHex, AString seedHex) throws IOException, InterruptedException {
349349
AMap<AString, ACell> signArgs = Maps.of(
350-
Strings.create("value"), valueHex,
351-
Strings.create("seed"), seedHex
350+
"value", valueHex,
351+
"seed", seedHex
352352
);
353353
AMap<AString, ACell> signResponse = makeToolCall("sign", signArgs);
354354
AMap<AString, ACell> signResult = expectResult(signResponse);
@@ -364,9 +364,9 @@ public void testValidateToolSuccess() throws IOException, InterruptedException {
364364
AString signatureHex = signData(VALUE_HELLO, SEED_TEST);
365365

366366
AMap<AString, ACell> validateArgs = Maps.of(
367-
Strings.create("publicKey"), publicKeyHex,
368-
Strings.create("signature"), signatureHex,
369-
Strings.create("bytes"), VALUE_HELLO
367+
"publicKey", publicKeyHex,
368+
"signature", signatureHex,
369+
"bytes", VALUE_HELLO
370370
);
371371
AMap<AString, ACell> validateResponse = makeToolCall("validate", validateArgs);
372372
AMap<AString, ACell> validateResult = expectResult(validateResponse);
@@ -385,9 +385,9 @@ public void testValidateToolFailureWrongSignature() throws IOException, Interrup
385385
AString wrongSignatureHex = Strings.create("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
386386

387387
AMap<AString, ACell> validateArgs = Maps.of(
388-
Strings.create("publicKey"), publicKeyHex,
389-
Strings.create("signature"), wrongSignatureHex,
390-
Strings.create("bytes"), VALUE_HELLO
388+
"publicKey", publicKeyHex,
389+
"signature", wrongSignatureHex,
390+
"bytes", VALUE_HELLO
391391
);
392392
AMap<AString, ACell> validateResponse = makeToolCall("validate", validateArgs);
393393
AMap<AString, ACell> validateResult = expectResult(validateResponse);
@@ -406,9 +406,9 @@ public void testValidateToolFailureWrongBytes() throws IOException, InterruptedE
406406
AString signatureHex = signData(VALUE_HELLO, SEED_TEST);
407407

408408
AMap<AString, ACell> validateArgs = Maps.of(
409-
Strings.create("publicKey"), publicKeyHex,
410-
Strings.create("signature"), signatureHex,
411-
Strings.create("bytes"), VALUE_WORLD
409+
"publicKey", publicKeyHex,
410+
"signature", signatureHex,
411+
"bytes", VALUE_WORLD
412412
);
413413
AMap<AString, ACell> validateResponse = makeToolCall("validate", validateArgs);
414414
AMap<AString, ACell> validateResult = expectResult(validateResponse);
@@ -438,8 +438,8 @@ public void testSignatureE2E() throws IOException, InterruptedException {
438438
// Step 2: Sign some data using the generated seed
439439
AString valueHex = Strings.create("48656c6c6f20576f726c64");
440440
AMap<AString, ACell> signArgs = Maps.of(
441-
Strings.create("value"), valueHex,
442-
Strings.create("seed"), seedHex
441+
"value", valueHex,
442+
"seed", seedHex
443443
);
444444
AMap<AString, ACell> signResponse = makeToolCall("sign", signArgs);
445445
AMap<AString, ACell> signResult = expectResult(signResponse);
@@ -482,9 +482,9 @@ public void testValidateToolFailureWrongPublicKey() throws IOException, Interrup
482482
AString signatureHex = signData(VALUE_HELLO, seed1Hex);
483483

484484
AMap<AString, ACell> validateArgs = Maps.of(
485-
Strings.create("publicKey"), publicKey2Hex,
486-
Strings.create("signature"), signatureHex,
487-
Strings.create("bytes"), VALUE_HELLO
485+
"publicKey", publicKey2Hex,
486+
"signature", signatureHex,
487+
"bytes", VALUE_HELLO
488488
);
489489
AMap<AString, ACell> validateResponse = makeToolCall("validate", validateArgs);
490490
AMap<AString, ACell> validateResult = expectResult(validateResponse);
@@ -505,7 +505,7 @@ public void testCreateAccountTool() throws IOException, InterruptedException {
505505

506506
assertNotNull(publicKeyHex, "keyGen should return a publicKey");
507507

508-
AMap<AString, ACell> createAccountArgs = Maps.of(Strings.create("accountKey"), publicKeyHex);
508+
AMap<AString, ACell> createAccountArgs = Maps.of("accountKey", publicKeyHex);
509509
AMap<AString, ACell> createAccountResponse = makeToolCall("createAccount", createAccountArgs);
510510
AMap<AString, ACell> createAccountResult = expectResult(createAccountResponse);
511511
ACell addressCell = RT.getIn(createAccountResult, "address");
@@ -528,8 +528,8 @@ public void testCreateAccountToolWithFaucet() throws IOException, InterruptedExc
528528
assertNotNull(publicKeyHex, "keyGen should return a publicKey");
529529

530530
AMap<AString, ACell> createAccountArgs = Maps.of(
531-
Strings.create("accountKey"), publicKeyHex,
532-
Strings.create("faucet"), CVMLong.create(1000)
531+
"accountKey", publicKeyHex,
532+
"faucet", CVMLong.create(1000)
533533
);
534534
AMap<AString, ACell> createAccountResponse = makeToolCall("createAccount", createAccountArgs);
535535
AMap<AString, ACell> createAccountResult = expectResult(createAccountResponse);
@@ -555,7 +555,7 @@ public void testCreateAccountAndDescribeAccount() throws IOException, Interrupte
555555
assertNotNull(publicKeyHex, "keyGen should return a publicKey");
556556

557557
// Step 2: Create an account
558-
AMap<AString, ACell> createAccountArgs = Maps.of(Strings.create("accountKey"), publicKeyHex);
558+
AMap<AString, ACell> createAccountArgs = Maps.of("accountKey", publicKeyHex);
559559
AMap<AString, ACell> createAccountResponse = makeToolCall("createAccount", createAccountArgs);
560560
AMap<AString, ACell> createAccountResult = expectResult(createAccountResponse);
561561
ACell addressCell = RT.getIn(createAccountResult, "address");
@@ -566,7 +566,7 @@ public void testCreateAccountAndDescribeAccount() throws IOException, Interrupte
566566

567567
// Step 3: Describe the account
568568
AString addressString = Strings.create("#" + addressLong.longValue());
569-
AMap<AString, ACell> describeAccountArgs = Maps.of(Strings.create("address"), addressString);
569+
AMap<AString, ACell> describeAccountArgs = Maps.of("address", addressString);
570570
AMap<AString, ACell> describeAccountResponse = makeToolCall("describeAccount", describeAccountArgs);
571571
AMap<AString, ACell> describeAccountResult = expectResult(describeAccountResponse);
572572

@@ -607,8 +607,8 @@ public void testSignWithSeed() throws IOException, InterruptedException {
607607
ASignature expectedSignature = keyPair.sign(payload);
608608

609609
AMap<AString, ACell> arguments = Maps.of(
610-
Strings.create("value"), VALUE_HELLO,
611-
Strings.create("seed"), SEED_TEST
610+
"value", VALUE_HELLO,
611+
"seed", SEED_TEST
612612
);
613613
AMap<AString, ACell> responseMap = makeToolCall("sign", arguments);
614614
AMap<AString, ACell> structured = expectResult(responseMap);
@@ -628,7 +628,7 @@ public void testSignWithSeed() throws IOException, InterruptedException {
628628
*/
629629
@Test
630630
public void testSignMissingSeed() throws IOException, InterruptedException {
631-
AMap<AString, ACell> args = Maps.of(Strings.create("value"), Strings.create("68656c6c6f"));
631+
AMap<AString, ACell> args = Maps.of("value", "68656c6c6f");
632632
AMap<AString, ACell> responseMap = makeToolCall("sign", args);
633633
AMap<AString, ACell> structured = expectError(responseMap);
634634
assertNull(RT.getIn(structured, "value"));
@@ -640,7 +640,7 @@ public void testSignMissingSeed() throws IOException, InterruptedException {
640640
*/
641641
@Test
642642
public void testSignMissingValue() throws IOException, InterruptedException {
643-
AMap<AString, ACell> signArgs = Maps.of(Strings.create("seed"), SEED_TEST);
643+
AMap<AString, ACell> signArgs = Maps.of("seed", SEED_TEST);
644644
AMap<AString, ACell> responseMap = makeToolCall("sign", signArgs);
645645
AMap<AString, ACell> structured = expectError(responseMap);
646646
assertNull(RT.getIn(structured, "signature"));
@@ -694,14 +694,14 @@ private AMap<AString, ACell> makeToolCall(String toolName, AMap<AString, ACell>
694694
}
695695
String id = "test-" + toolName;
696696
AMap<AString, ACell> params = Maps.of(
697-
Strings.create("name"), Strings.create(toolName),
698-
Strings.create("arguments"), arguments
697+
"name", toolName,
698+
"arguments", arguments
699699
);
700700
AMap<AString, ACell> request = Maps.of(
701-
Strings.create("jsonrpc"), Strings.create("2.0"),
702-
Strings.create("method"), Strings.create("tools/call"),
703-
Strings.create("params"), params,
704-
Strings.create("id"), Strings.create(id)
701+
"jsonrpc", "2.0",
702+
"method", "tools/call",
703+
"params", params,
704+
"id", id
705705
);
706706

707707
HttpResponse<String> response = post(MCP_PATH, JSON.toString(request));
@@ -755,8 +755,8 @@ private AMap<AString, ACell> expectError(AMap<AString, ACell> responseMap) {
755755
@Test
756756
public void testLookupCountInCore() throws IOException, InterruptedException {
757757
AMap<AString, ACell> lookupArgs = Maps.of(
758-
Strings.create("address"), Strings.create("#8"),
759-
Strings.create("symbol"), Strings.create("count")
758+
"address", "#8",
759+
"symbol", "count"
760760
);
761761
AMap<AString, ACell> responseMap = makeToolCall("lookup", lookupArgs);
762762
AMap<AString, ACell> structured = expectResult(responseMap);
@@ -778,8 +778,8 @@ public void testLookupCountInCore() throws IOException, InterruptedException {
778778
@Test
779779
public void testLookupNonExistentSymbol() throws IOException, InterruptedException {
780780
AMap<AString, ACell> lookupArgs = Maps.of(
781-
Strings.create("address"), Strings.create("#0"),
782-
Strings.create("symbol"), Strings.create("foo")
781+
"address", "#0",
782+
"symbol", "foo"
783783
);
784784
AMap<AString, ACell> responseMap = makeToolCall("lookup", lookupArgs);
785785
AMap<AString, ACell> structured = expectResult(responseMap);
@@ -800,8 +800,8 @@ public void testLookupNonExistentSymbol() throws IOException, InterruptedExcepti
800800
@Test
801801
public void testLookupInvalidAddress() throws IOException, InterruptedException {
802802
AMap<AString, ACell> lookupArgs = Maps.of(
803-
Strings.create("address"), Strings.create("#-100"),
804-
Strings.create("symbol"), Strings.create("count")
803+
"address", "#-100",
804+
"symbol", "count"
805805
);
806806
AMap<AString, ACell> responseMap = makeToolCall("lookup", lookupArgs);
807807
AMap<AString, ACell> structured = expectError(responseMap);
@@ -819,8 +819,8 @@ public void testLookupInvalidAddress() throws IOException, InterruptedException
819819
@Test
820820
public void testLookupInvalidSymbol() throws IOException, InterruptedException {
821821
AMap<AString, ACell> lookupArgs = Maps.of(
822-
Strings.create("address"), Strings.create("#8"),
823-
Strings.create("symbol"), Strings.create("[]")
822+
"address", "#8",
823+
"symbol", "[]"
824824
);
825825
AMap<AString, ACell> responseMap = makeToolCall("lookup", lookupArgs);
826826
AMap<AString, ACell> structured = expectResult(responseMap);

0 commit comments

Comments
 (0)