Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backwards-compatibility for UMA v0 from v1 SDK #31

Merged
merged 15 commits into from
Mar 21, 2024
173 changes: 169 additions & 4 deletions javatest/src/test/java/me/uma/javatest/UmaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void testGetLnurlpRequest() throws Exception {
}

@Test
public void testGetLnurlpResponse() throws Exception {
public void testGetLnurlpResponse_umaV1() throws Exception {
String lnurlpUrl = umaProtocolHelper.getSignedLnurlpRequestUrl(
privateKeyBytes(),
"[email protected]",
Expand All @@ -108,7 +108,7 @@ public void testGetLnurlpResponse() throws Exception {
)
),
List.of(
new Currency(
new CurrencyV1(
"USD",
"US Dollar",
"$",
Expand All @@ -131,7 +131,122 @@ public void testGetLnurlpResponse() throws Exception {
}

@Test
public void testGetPayReqResponseSync() throws Exception {
public void testGetLnurlpResponse_umaV0() throws Exception {
String lnurlpUrl = umaProtocolHelper.getSignedLnurlpRequestUrl(
privateKeyBytes(),
"[email protected]",
"https://vasp.com",
true);
LnurlpRequest request = umaProtocolHelper.parseLnurlpRequest(lnurlpUrl);
assertNotNull(request);
LnurlpResponse lnurlpResponse = umaProtocolHelper.getLnurlpResponse(
request,
privateKeyBytes(),
true,
"https://vasp2.com/callback",
"encoded metadata",
1,
10_000_000,
CounterPartyData.createCounterPartyDataOptions(
Map.of(
"name", false,
"email", false,
"identity", true,
"compliance", true
)
),
List.of(
new CurrencyV0(
"USD",
"US Dollar",
"$",
34_150,
1,
10_000_000,
2
)
),
KycStatus.VERIFIED
);
assertNotNull(lnurlpResponse);
String responseJson = lnurlpResponse.toJson();
System.out.println(responseJson);
LnurlpResponse parsedResponse = umaProtocolHelper.parseAsLnurlpResponse(responseJson);
assertNotNull(parsedResponse);
assertEquals(lnurlpResponse, parsedResponse);
assertTrue(umaProtocolHelper.verifyLnurlpResponseSignature(
parsedResponse.asUmaResponse(), new PubKeyResponse(publicKeyBytes(), publicKeyBytes()),
new InMemoryNonceCache(1L)));
}

@Test
public void testGetPayRequest_umaV1() throws Exception {
PayRequest request = umaProtocolHelper.getPayRequest(
publicKeyBytes(),
privateKeyBytes(),
"USD",
100L,
true,
"[email protected]",
KycStatus.VERIFIED,
"",
null,
null,
null,
"payerName",
"payerEmail",
null,
null,
"comment",
"1.0"
);
assertNotNull(request);
System.out.println(request);
assertTrue(request instanceof PayRequestV1);
assertTrue(umaProtocolHelper.verifyPayReqSignature(
request, new PubKeyResponse(publicKeyBytes(), publicKeyBytes()),
new InMemoryNonceCache(1L)));
String requestJson = request.toJson();
PayRequest parsedRequest = umaProtocolHelper.parseAsPayRequest(requestJson);
assertNotNull(parsedRequest);
assertEquals(request, parsedRequest);
}

@Test
public void testGetPayRequest_umaV0() throws Exception {
PayRequest request = umaProtocolHelper.getPayRequest(
publicKeyBytes(),
privateKeyBytes(),
"USD",
100L,
true,
"[email protected]",
KycStatus.VERIFIED,
"",
null,
null,
null,
"payerName",
"payerEmail",
null,
null,
"comment",
"0.3"
);
assertNotNull(request);
System.out.println(request);
assertTrue(request instanceof PayRequestV0);
assertTrue(umaProtocolHelper.verifyPayReqSignature(
request, new PubKeyResponse(publicKeyBytes(), publicKeyBytes()),
new InMemoryNonceCache(1L)));
String requestJson = request.toJson();
PayRequest parsedRequest = umaProtocolHelper.parseAsPayRequest(requestJson);
assertNotNull(parsedRequest);
assertEquals(request, parsedRequest);
}

@Test
public void testGetPayReqResponseSync_umaV1() throws Exception {
PayRequest request = umaProtocolHelper.getPayRequest(
publicKeyBytes(),
privateKeyBytes(),
Expand All @@ -154,14 +269,64 @@ public void testGetPayReqResponseSync() throws Exception {
null,
"",
privateKeyBytes(),
PayeeData.createPayeeData(null, "[email protected]")
PayeeData.createPayeeData(null, "[email protected]"),
null,
null,
"1.0"
);
assertNotNull(response);
assertEquals("lnbc12345", response.getEncodedInvoice());
System.out.println(response);
assertTrue(response instanceof PayReqResponseV1);
assertTrue(umaProtocolHelper.verifyPayReqResponseSignature(
response, new PubKeyResponse(publicKeyBytes(), publicKeyBytes()),
"[email protected]", new InMemoryNonceCache(1L)));
String responseJson = response.toJson();
PayReqResponse parsedResponse = umaProtocolHelper.parseAsPayReqResponse(responseJson);
assertNotNull(parsedResponse);
assertEquals(response, parsedResponse);
}

@Test
public void testGetPayReqResponseSync_umaV0() throws Exception {
PayRequest request = umaProtocolHelper.getPayRequest(
publicKeyBytes(),
privateKeyBytes(),
"USD",
100L,
true,
"[email protected]",
KycStatus.VERIFIED,
""
);
PayReqResponse response = umaProtocolHelper.getPayReqResponseSync(
request,
new TestSyncUmaInvoiceCreator(),
"metadata",
"USD",
2,
12345.0,
0L,
List.of(),
null,
"",
privateKeyBytes(),
PayeeData.createPayeeData(null, "[email protected]"),
null,
null,
"0.3"
);
assertNotNull(response);
assertEquals("lnbc12345", response.getEncodedInvoice());
System.out.println(response);
assertTrue(response instanceof PayReqResponseV0);
assertTrue(umaProtocolHelper.verifyPayReqResponseSignature(
response, new PubKeyResponse(publicKeyBytes(), publicKeyBytes()),
"[email protected]", new InMemoryNonceCache(1L)));
String responseJson = response.toJson();
PayReqResponse parsedResponse = umaProtocolHelper.parseAsPayReqResponse(responseJson);
assertNotNull(parsedResponse);
assertEquals(response, parsedResponse);
}

@Test
Expand Down
Loading
Loading