From ccdc49e38781ed7db3c29f1733b52d5cf7cb50be Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Mon, 13 Dec 2021 20:28:46 -0800 Subject: [PATCH 1/8] Multi-agent integration test Signed-off-by: Ian Costanzo --- .../aries/MultiIntegrationTestBase.java | 91 +++++++++++ .../connection/MultiConnectionRecordTest.java | 154 ++++++++++++++++++ 2 files changed, 245 insertions(+) create mode 100644 src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java create mode 100644 src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java diff --git a/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java b/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java new file mode 100644 index 00000000..b8214e06 --- /dev/null +++ b/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/acapy-java-client + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.aries; + +import org.junit.jupiter.api.BeforeEach; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.containers.output.Slf4jLogConsumer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +@Testcontainers +public abstract class MultiIntegrationTestBase { + + private final Logger log = LoggerFactory.getLogger(IntegrationTestBase.class); + + public static final String ARIES_VERSION = "bcgovimages/aries-cloudagent:py36-1.16-1_0.7.2"; + public static final Integer ARIES_ENDPOINT_PORT = 8030; + public static final Integer ARIES_ADMIN_PORT = 8031; + public static final Integer ARIES_ENDPOINT_PORT_2 = 8040; + public static final Integer ARIES_ADMIN_PORT_2 = 8041; + + protected AriesClient ac; + protected AriesClient ac2; + + Network network = Network.newNetwork(); + + @Container + protected GenericContainer ariesContainer = new GenericContainer<>(ARIES_VERSION) + .withNetwork(network) + .withNetworkAliases("agent_1") + .withExposedPorts(ARIES_ADMIN_PORT) + .withCommand("start" + + " -it http 0.0.0.0 " + ARIES_ENDPOINT_PORT + + " -ot http" + + " --admin 0.0.0.0 " + ARIES_ADMIN_PORT + + " --admin-insecure-mode" + + " --log-level debug" + + " -e http://agent_1:" + ARIES_ENDPOINT_PORT + + " --genesis-url https://indy-test.bosch-digital.de/genesis" + + " --auto-ping-connection" + + " --wallet-type indy" + + " --wallet-name agent1" + + " --wallet-key agent1key" + + " --auto-provision" + + " --plugin aries_cloudagent.messaging.jsonld") + .waitingFor(Wait.defaultWaitStrategy()) + .withLogConsumer(new Slf4jLogConsumer(log)) + ; + + @Container + protected GenericContainer ariesContainer2 = new GenericContainer<>(ARIES_VERSION) + .withExposedPorts(ARIES_ADMIN_PORT_2) + .withNetwork(network) + .withNetworkAliases("agent_2") + .withCommand("start" + + " -it http 0.0.0.0 " + ARIES_ENDPOINT_PORT_2 + + " -ot http" + + " --admin 0.0.0.0 " + ARIES_ADMIN_PORT_2 + + " --admin-insecure-mode" + + " --log-level debug" + + " -e http://agent_2:" + ARIES_ENDPOINT_PORT_2 + + " --genesis-url https://indy-test.bosch-digital.de/genesis" + + " --auto-ping-connection" + + " --wallet-type indy" + + " --wallet-name agent2" + + " --wallet-key agent2key" + + " --auto-provision" + + " --plugin aries_cloudagent.messaging.jsonld") + .waitingFor(Wait.defaultWaitStrategy()) + .withLogConsumer(new Slf4jLogConsumer(log)) + ; + + @BeforeEach + void setup() { + ac = AriesClient.builder() + .url("http://" + ariesContainer.getHost() + ":" + ariesContainer.getMappedPort(ARIES_ADMIN_PORT)) + .build(); + ac2 = AriesClient.builder() + .url("http://" + ariesContainer.getHost() + ":" + ariesContainer2.getMappedPort(ARIES_ADMIN_PORT_2)) + .build(); + } +} diff --git a/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java b/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java new file mode 100644 index 00000000..1b8351f8 --- /dev/null +++ b/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/acapy-java-client + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.aries.api.connection; + +import lombok.extern.slf4j.Slf4j; +import org.hyperledger.aries.IntegrationTestBase; +import org.hyperledger.aries.api.exception.AriesException; +import org.hyperledger.acy_py.generated.model.ConnectionInvitation; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; + +@Slf4j +public class ConnectionRecordTest extends IntegrationTestBase { + + @Test + void testDeleteConnection() { + assertThrows(AriesException.class, () -> ac.connectionsRemove("1")); + } + + @Test + void testGetConnections() throws Exception { + final Optional> connections = ac.connections( + ConnectionFilter.builder().state(ConnectionState.ACTIVE).build()); + assertTrue(connections.isPresent()); + assertEquals(0, connections.get().size()); + } + + @Test + void testGetConnectionsWrongFilter() { + assertThrows(AriesException.class, () -> ac.connections( + ConnectionFilter.builder().myDid("wrong_format").build())); + } + + @Test + void testCreateInvitation() throws Exception { + final Optional inv = ac.connectionsCreateInvitation( + CreateInvitationRequest + .builder() + .recipientKeys(List.of()) + .build(), + CreateInvitationParams + .builder() + .autoAccept(Boolean.TRUE) + .build()); + assertTrue(inv.isPresent()); + assertNotNull(inv.get().getInvitationUrl()); + log.debug("{}", inv.get()); + } + + @Test + void testMetadata() throws Exception { + ac.connectionsCreateInvitation( + CreateInvitationRequest + .builder() + .recipientKeys(List.of()) + .build(), + CreateInvitationParams + .builder() + .autoAccept(Boolean.TRUE) + .build()); + + Optional> connections = ac.connections(); + Assertions.assertTrue(connections.isPresent()); + Assertions.assertEquals(1, connections.get().size()); + + String connectionId = connections.get().get(0).getConnectionId(); + Optional> metadata = ac.connectionsSetMetadata(connectionId, ConnectionSetMetaDataRequest + .builder() + .metadata(Map.of("key1", "value1", "key2", "value2")) + .build()); + Assertions.assertTrue(metadata.isPresent()); + Assertions.assertEquals("value2", metadata.get().get("key2")); + + metadata = ac.connectionsGetMetadata(connectionId); + Assertions.assertTrue(metadata.isPresent()); + Assertions.assertEquals("value2", metadata.get().get("key2")); + + Optional singleValue = ac.connectionsGetMetadata(connectionId, "key1"); + Assertions.assertTrue(singleValue.isPresent()); + Assertions.assertEquals("value1", singleValue.get()); + } + + @Test + void testCreateConnectionBetweenAgents() throws Exception { + String alias_1 = "my_test_1"; + String alias_2 = "my_test_2"; + final Optional inv = ac.connectionsCreateInvitation( + CreateInvitationRequest + .builder() + .recipientKeys(List.of()) + .build(), + CreateInvitationParams + .builder() + .autoAccept(Boolean.TRUE) + .alias(alias_1) + .build()); + assertTrue(inv.isPresent()); + assertNotNull(inv.get().getInvitationUrl()); + + ConnectionInvitation conn_inv = inv.get().getInvitation(); + final Optional conn2 = ac2.connectionsReceiveInvitation( + ReceiveInvitationRequest + .builder() + .id(conn_inv.getAtId()) + .type(conn_inv.getAtType()) + .did(conn_inv.getDid()) + .imageUrl(conn_inv.getImageUrl()) + .label(conn_inv.getLabel()) + .recipientKeys(conn_inv.getRecipientKeys()) + .routingKeys(conn_inv.getRoutingKeys()) + .serviceEndpoint(conn_inv.getServiceEndpoint()) + .build(), + ConnectionReceiveInvitationFilter + .builder() + .alias(alias_2) + .autoAccept(false) + .build()); + assertTrue(conn2.isPresent()); + + final Optional conn2_updated = ac2.connectionsAcceptInvitation( + conn2.get().getConnectionId(), + null); + assertTrue(conn2_updated.isPresent()); + + // pause to allow the agent chatter to complete + Thread.sleep(4000); + + // now fetch connections and confirm everything completed successfully + final Optional> connections = ac.connections( + ConnectionFilter.builder().alias(alias_1).build()); + assertTrue(connections.isPresent()); + assertEquals(1, connections.get().size()); + assertEquals(alias_1, connections.get().get(0).getAlias()); + assertEquals(ConnectionState.ACTIVE, connections.get().get(0).getState()); + + final Optional> connections2 = ac2.connections( + ConnectionFilter.builder().alias(alias_2).build()); + assertTrue(connections2.isPresent()); + assertEquals(1, connections2.get().size()); + assertEquals(alias_2, connections2.get().get(0).getAlias()); + assertEquals(ConnectionState.ACTIVE, connections2.get().get(0).getState()); + } +} From 67bdf2ffb03495465f51ac1148bf87a3c91e21cf Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Mon, 13 Dec 2021 20:35:10 -0800 Subject: [PATCH 2/8] Fix typos Signed-off-by: Ian Costanzo --- .../aries/MultiIntegrationTestBase.java | 2 +- .../connection/MultiConnectionRecordTest.java | 72 +------------------ 2 files changed, 3 insertions(+), 71 deletions(-) diff --git a/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java b/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java index b8214e06..1c264bfc 100644 --- a/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java +++ b/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java @@ -20,7 +20,7 @@ @Testcontainers public abstract class MultiIntegrationTestBase { - private final Logger log = LoggerFactory.getLogger(IntegrationTestBase.class); + private final Logger log = LoggerFactory.getLogger(MultiIntegrationTestBase.class); public static final String ARIES_VERSION = "bcgovimages/aries-cloudagent:py36-1.16-1_0.7.2"; public static final Integer ARIES_ENDPOINT_PORT = 8030; diff --git a/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java b/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java index 1b8351f8..67c9bfa8 100644 --- a/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java +++ b/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java @@ -8,7 +8,7 @@ package org.hyperledger.aries.api.connection; import lombok.extern.slf4j.Slf4j; -import org.hyperledger.aries.IntegrationTestBase; +import org.hyperledger.aries.MultiIntegrationTestBase; import org.hyperledger.aries.api.exception.AriesException; import org.hyperledger.acy_py.generated.model.ConnectionInvitation; import org.junit.jupiter.api.Assertions; @@ -21,75 +21,7 @@ import static org.junit.jupiter.api.Assertions.*; @Slf4j -public class ConnectionRecordTest extends IntegrationTestBase { - - @Test - void testDeleteConnection() { - assertThrows(AriesException.class, () -> ac.connectionsRemove("1")); - } - - @Test - void testGetConnections() throws Exception { - final Optional> connections = ac.connections( - ConnectionFilter.builder().state(ConnectionState.ACTIVE).build()); - assertTrue(connections.isPresent()); - assertEquals(0, connections.get().size()); - } - - @Test - void testGetConnectionsWrongFilter() { - assertThrows(AriesException.class, () -> ac.connections( - ConnectionFilter.builder().myDid("wrong_format").build())); - } - - @Test - void testCreateInvitation() throws Exception { - final Optional inv = ac.connectionsCreateInvitation( - CreateInvitationRequest - .builder() - .recipientKeys(List.of()) - .build(), - CreateInvitationParams - .builder() - .autoAccept(Boolean.TRUE) - .build()); - assertTrue(inv.isPresent()); - assertNotNull(inv.get().getInvitationUrl()); - log.debug("{}", inv.get()); - } - - @Test - void testMetadata() throws Exception { - ac.connectionsCreateInvitation( - CreateInvitationRequest - .builder() - .recipientKeys(List.of()) - .build(), - CreateInvitationParams - .builder() - .autoAccept(Boolean.TRUE) - .build()); - - Optional> connections = ac.connections(); - Assertions.assertTrue(connections.isPresent()); - Assertions.assertEquals(1, connections.get().size()); - - String connectionId = connections.get().get(0).getConnectionId(); - Optional> metadata = ac.connectionsSetMetadata(connectionId, ConnectionSetMetaDataRequest - .builder() - .metadata(Map.of("key1", "value1", "key2", "value2")) - .build()); - Assertions.assertTrue(metadata.isPresent()); - Assertions.assertEquals("value2", metadata.get().get("key2")); - - metadata = ac.connectionsGetMetadata(connectionId); - Assertions.assertTrue(metadata.isPresent()); - Assertions.assertEquals("value2", metadata.get().get("key2")); - - Optional singleValue = ac.connectionsGetMetadata(connectionId, "key1"); - Assertions.assertTrue(singleValue.isPresent()); - Assertions.assertEquals("value1", singleValue.get()); - } +public class MultiConnectionRecordTest extends MultiIntegrationTestBase { @Test void testCreateConnectionBetweenAgents() throws Exception { From 33474db9d3b26dd127da4337d284209cbda23208 Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Tue, 14 Dec 2021 06:54:53 -0800 Subject: [PATCH 3/8] Parametrize agent startup args by test Signed-off-by: Ian Costanzo --- .../aries/MultiIntegrationTestBase.java | 22 +++++++------------ .../connection/MultiConnectionRecordTest.java | 21 ++++++++++++++++++ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java b/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java index 1c264bfc..abd7a7cf 100644 --- a/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java +++ b/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java @@ -45,13 +45,8 @@ public abstract class MultiIntegrationTestBase { + " --admin-insecure-mode" + " --log-level debug" + " -e http://agent_1:" + ARIES_ENDPOINT_PORT - + " --genesis-url https://indy-test.bosch-digital.de/genesis" - + " --auto-ping-connection" - + " --wallet-type indy" - + " --wallet-name agent1" - + " --wallet-key agent1key" - + " --auto-provision" - + " --plugin aries_cloudagent.messaging.jsonld") + + " --plugin aries_cloudagent.messaging.jsonld" + + this.extraAgentArgs(1)) .waitingFor(Wait.defaultWaitStrategy()) .withLogConsumer(new Slf4jLogConsumer(log)) ; @@ -68,17 +63,16 @@ public abstract class MultiIntegrationTestBase { + " --admin-insecure-mode" + " --log-level debug" + " -e http://agent_2:" + ARIES_ENDPOINT_PORT_2 - + " --genesis-url https://indy-test.bosch-digital.de/genesis" - + " --auto-ping-connection" - + " --wallet-type indy" - + " --wallet-name agent2" - + " --wallet-key agent2key" - + " --auto-provision" - + " --plugin aries_cloudagent.messaging.jsonld") + + " --plugin aries_cloudagent.messaging.jsonld" + + this.extraAgentArgs(2)) .waitingFor(Wait.defaultWaitStrategy()) .withLogConsumer(new Slf4jLogConsumer(log)) ; + protected String extraAgentArgs(int agentNum) { + return " --no-ledger"; + } + @BeforeEach void setup() { ac = AriesClient.builder() diff --git a/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java b/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java index 67c9bfa8..b1605836 100644 --- a/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java +++ b/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java @@ -23,6 +23,27 @@ @Slf4j public class MultiConnectionRecordTest extends MultiIntegrationTestBase { + protected String extraAgentArgs(int agentNum) { + switch (agentNum) { + case 1: + return " --genesis-url https://indy-test.bosch-digital.de/genesis" + + " --auto-ping-connection" + + " --wallet-type indy" + + " --wallet-name agent1" + + " --wallet-key agent1key" + + " --auto-provision"; + case 2: + return " --genesis-url https://indy-test.bosch-digital.de/genesis" + + " --auto-ping-connection" + + " --wallet-type indy" + + " --wallet-name agent2" + + " --wallet-key agent2key" + + " --auto-provision"; + default: + return super.extraAgentArgs(agentNum); + } + } + @Test void testCreateConnectionBetweenAgents() throws Exception { String alias_1 = "my_test_1"; From 324aae13d7f2d6c487f7e454fa8cd367aa9b521f Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Tue, 14 Dec 2021 10:53:47 -0800 Subject: [PATCH 4/8] Add ledger service (create DIDs), initial endorser test WIP Signed-off-by: Ian Costanzo --- .../org/hyperledger/aries/LedgerClient.java | 111 +++++++++++ .../aries/MultiIntegrationTestBase.java | 3 +- .../EndorserConnectionRecordTest.java | 183 ++++++++++++++++++ .../aries/util/ledger/LedgerDIDCreate.java | 51 +++++ .../aries/util/ledger/LedgerDIDResponse.java | 43 ++++ 5 files changed, 390 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/hyperledger/aries/LedgerClient.java create mode 100644 src/test/java/org/hyperledger/aries/api/connection/EndorserConnectionRecordTest.java create mode 100644 src/test/java/org/hyperledger/aries/util/ledger/LedgerDIDCreate.java create mode 100644 src/test/java/org/hyperledger/aries/util/ledger/LedgerDIDResponse.java diff --git a/src/test/java/org/hyperledger/aries/LedgerClient.java b/src/test/java/org/hyperledger/aries/LedgerClient.java new file mode 100644 index 00000000..71f43044 --- /dev/null +++ b/src/test/java/org/hyperledger/aries/LedgerClient.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/acapy-java-client + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.aries; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import lombok.Builder; +import lombok.NonNull; +import lombok.extern.slf4j.Slf4j; +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import org.apache.commons.lang3.StringUtils; + +import org.hyperledger.aries.util.ledger.LedgerDIDCreate; +import org.hyperledger.aries.util.ledger.LedgerDIDResponse; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.lang.reflect.Type; +import java.time.Duration; +import java.time.Instant; +import java.util.*; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +/** + * ACA-PY client + */ +@Slf4j +@SuppressWarnings("unused") +public class LedgerClient extends BaseClient { + + public static final String LEDGER_GENESIS_TXN_URL = "/genesis"; + public static final String LEDGER_DID_REGISTRATION_URL = "/register"; + public static final String LEDGER_DID_ENDORSER_ROLE = "ENDORSER"; + + private final String url; + + /** + * @param url The ledger URL without a path e.g. protocol://host:[port] + * @param client {@link OkHttpClient} if null a default client is created + */ + @Builder + public LedgerClient(@NonNull String url, + @Nullable OkHttpClient client) { + super(client); + this.url = StringUtils.trim(url); + } + + // ---------------------------------------------------- + // Register a new public DID on the ledger + // ---------------------------------------------------- + + /** + * Create a public DID + * @param didCreate {@link DIDCreate} + * @return {@link DID} + * @throws IOException if the request could not be executed due to cancellation, a connectivity problem or timeout. + */ + public Optional ledgerDidCreate(@NonNull LedgerDIDCreate didCreate) throws IOException { + Request req = buildPost(url + LEDGER_DID_REGISTRATION_URL, didCreate); + return call(req, LedgerDIDResponse.class); + } + + + // ---------------------------------------------------- + // Internal + // ---------------------------------------------------- + + private Request buildPost(String u, Object body) { + return request(u) + .post(jsonBody(gson.toJson(body))) + .build(); + } + + private Request buildPut(String u, Object body) { + return request(u) + .put(jsonBody(gson.toJson(body))) + .build(); + } + + private Request buildPatch(String u, Object body) { + return request(u) + .patch(jsonBody(gson.toJson(body))) + .build(); + } + + private Request buildGet(String u) { + return request(u) + .get() + .build(); + } + + private Request buildDelete(String u) { + return request(u) + .delete() + .build(); + } + + private Request.Builder request(String u) { + Request.Builder b = new Request.Builder() + .url(u); + return b; + } +} diff --git a/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java b/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java index abd7a7cf..9997a05d 100644 --- a/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java +++ b/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java @@ -28,6 +28,7 @@ public abstract class MultiIntegrationTestBase { public static final Integer ARIES_ENDPOINT_PORT_2 = 8040; public static final Integer ARIES_ADMIN_PORT_2 = 8041; + protected LedgerClient lc; protected AriesClient ac; protected AriesClient ac2; @@ -79,7 +80,7 @@ void setup() { .url("http://" + ariesContainer.getHost() + ":" + ariesContainer.getMappedPort(ARIES_ADMIN_PORT)) .build(); ac2 = AriesClient.builder() - .url("http://" + ariesContainer.getHost() + ":" + ariesContainer2.getMappedPort(ARIES_ADMIN_PORT_2)) + .url("http://" + ariesContainer2.getHost() + ":" + ariesContainer2.getMappedPort(ARIES_ADMIN_PORT_2)) .build(); } } diff --git a/src/test/java/org/hyperledger/aries/api/connection/EndorserConnectionRecordTest.java b/src/test/java/org/hyperledger/aries/api/connection/EndorserConnectionRecordTest.java new file mode 100644 index 00000000..a591b5d9 --- /dev/null +++ b/src/test/java/org/hyperledger/aries/api/connection/EndorserConnectionRecordTest.java @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/acapy-java-client + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.aries.api.connection; + +import lombok.extern.slf4j.Slf4j; +import org.hyperledger.aries.MultiIntegrationTestBase; +import org.hyperledger.aries.api.exception.AriesException; +import org.hyperledger.acy_py.generated.model.ConnectionInvitation; +import org.hyperledger.acy_py.generated.model.DID; +import org.hyperledger.acy_py.generated.model.DIDCreate; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import org.hyperledger.aries.LedgerClient; +import org.hyperledger.aries.util.ledger.LedgerDIDCreate; +import org.hyperledger.aries.util.ledger.LedgerDIDResponse; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; + +@Slf4j +public class EndorserConnectionRecordTest extends MultiIntegrationTestBase { + + public static final String INDY_LEDGER_URL = "http://test.bcovrin.vonx.io"; + public static final String ENDORSER_CONNECTION_ALIAS = "endorser"; + + protected String getLedgerUrl() { + return INDY_LEDGER_URL; + } + + protected String extraAgentArgs(int agentNum) { + switch (agentNum) { + case 1: + // agent 1 is the Author + return " --genesis-url " + INDY_LEDGER_URL + "/genesis" + + " --auto-ping-connection" + + " --wallet-type indy" + + " --wallet-name agent1" + + " --wallet-key agent1key" + + " --auto-provision" + + " --endorser-protocol-role author" + + " --endorser-alias " + ENDORSER_CONNECTION_ALIAS + + " --auto-request-endorsement" + + " --auto-write-transactions"; + case 2: + // agent 2 is the Endorser + return " --genesis-url " + INDY_LEDGER_URL + "/genesis" + + " --auto-ping-connection" + + " --wallet-type indy" + + " --wallet-name agent2" + + " --wallet-key agent2key" + + " --auto-provision" + + " --endorser-protocol-role endorser" + + " --auto-endorse-transactions"; + default: + return super.extraAgentArgs(agentNum); + } + } + + @Test + void testCreateConnectionBetweenAuthorAndEndorser() throws Exception { + String alias_1 = "my_agent_1"; + String alias_2 = "my_agent_2"; + + // create a DID for each agent and make public + lc = LedgerClient.builder() + .url(INDY_LEDGER_URL) + .build(); + + DID localDid1 = ac.walletDidCreate(DIDCreate + .builder() + .build()) + .orElseThrow(); + assertNotNull(localDid1.getVerkey()); + Optional agent1Did = lc.ledgerDidCreate( + LedgerDIDCreate + .builder() + .alias(alias_1) + .did(localDid1.getDid()) + .verkey(localDid1.getVerkey()) + .build()); + assertTrue(agent1Did.isPresent()); + assertNotNull(agent1Did.get().getDid()); + Optional localPublicDid1 = ac.walletDidPublic(localDid1.getDid()); + assertTrue(localPublicDid1.isPresent()); + assertNotNull(localPublicDid1.get().getVerkey()); + + DID localDid2 = ac2.walletDidCreate(DIDCreate + .builder() + .build()) + .orElseThrow(); + assertNotNull(localDid2.getVerkey()); + Optional agent2Did = lc.ledgerDidCreate( + LedgerDIDCreate + .builder() + .alias(alias_2) + .role(LedgerClient.LEDGER_DID_ENDORSER_ROLE) + .did(localDid2.getDid()) + .verkey(localDid2.getVerkey()) + .build()); + assertTrue(agent2Did.isPresent()); + assertNotNull(agent2Did.get().getDid()); + Optional localPublicDid2 = ac2.walletDidPublic(localDid2.getDid()); + assertTrue(localPublicDid2.isPresent()); + assertNotNull(localPublicDid2.get().getVerkey()); + + // get (verify) public DID for each agent + final Optional agent1PublicDid = ac.walletDidPublic(); + assertTrue(agent1PublicDid.isPresent()); + assertNotNull(agent1PublicDid.get().getDid()); + final Optional agent2PublicDid = ac2.walletDidPublic(); + assertTrue(agent2PublicDid.isPresent()); + assertNotNull(agent2PublicDid.get().getDid()); + + // establish Endorser/Author connection for endorsements + final Optional inv = ac.connectionsCreateInvitation( + CreateInvitationRequest + .builder() + .recipientKeys(List.of()) + .build(), + CreateInvitationParams + .builder() + .autoAccept(Boolean.TRUE) + .alias(ENDORSER_CONNECTION_ALIAS) + .build()); + assertTrue(inv.isPresent()); + assertNotNull(inv.get().getInvitationUrl()); + + ConnectionInvitation conn_inv = inv.get().getInvitation(); + final Optional conn2 = ac2.connectionsReceiveInvitation( + ReceiveInvitationRequest + .builder() + .id(conn_inv.getAtId()) + .type(conn_inv.getAtType()) + .did(conn_inv.getDid()) + .imageUrl(conn_inv.getImageUrl()) + .label(conn_inv.getLabel()) + .recipientKeys(conn_inv.getRecipientKeys()) + .routingKeys(conn_inv.getRoutingKeys()) + .serviceEndpoint(conn_inv.getServiceEndpoint()) + .build(), + ConnectionReceiveInvitationFilter + .builder() + .alias(alias_2) + .autoAccept(false) + .build()); + assertTrue(conn2.isPresent()); + + final Optional conn2_updated = ac2.connectionsAcceptInvitation( + conn2.get().getConnectionId(), + null); + assertTrue(conn2_updated.isPresent()); + + // pause to allow the agent chatter to complete + Thread.sleep(4000); + + // now fetch connections and confirm everything completed successfully + final Optional> connections = ac.connections( + ConnectionFilter.builder().alias(ENDORSER_CONNECTION_ALIAS).build()); + assertTrue(connections.isPresent()); + assertEquals(1, connections.get().size()); + assertEquals(ENDORSER_CONNECTION_ALIAS, connections.get().get(0).getAlias()); + assertEquals(ConnectionState.ACTIVE, connections.get().get(0).getState()); + + final Optional> connections2 = ac2.connections( + ConnectionFilter.builder().alias(alias_2).build()); + assertTrue(connections2.isPresent()); + assertEquals(1, connections2.get().size()); + assertEquals(alias_2, connections2.get().get(0).getAlias()); + assertEquals(ConnectionState.ACTIVE, connections2.get().get(0).getState()); + + // add endorser metadata to connections + // TODO + } +} diff --git a/src/test/java/org/hyperledger/aries/util/ledger/LedgerDIDCreate.java b/src/test/java/org/hyperledger/aries/util/ledger/LedgerDIDCreate.java new file mode 100644 index 00000000..8f543e02 --- /dev/null +++ b/src/test/java/org/hyperledger/aries/util/ledger/LedgerDIDCreate.java @@ -0,0 +1,51 @@ +/* + * aca-py client + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: v0.7.2 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package org.hyperledger.aries.util.ledger; + +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + +import java.io.IOException; + +/** + * DID + */ + +@lombok.Data +@lombok.AllArgsConstructor +@lombok.NoArgsConstructor +@lombok.Builder +public class LedgerDIDCreate { + public static final String SERIALIZED_NAME_ALIAS = "alias"; + @SerializedName(SERIALIZED_NAME_ALIAS) + private String alias; + + public static final String SERIALIZED_NAME_DID = "did"; + @SerializedName(SERIALIZED_NAME_DID) + private String did; + + public static final String SERIALIZED_NAME_ROLE = "role"; + @SerializedName(SERIALIZED_NAME_ROLE) + private String role; + + public static final String SERIALIZED_NAME_SEED = "seed"; + @SerializedName(SERIALIZED_NAME_SEED) + private String seed; + + public static final String SERIALIZED_NAME_VERKEY = "verkey"; + @SerializedName(SERIALIZED_NAME_VERKEY) + private String verkey; +} diff --git a/src/test/java/org/hyperledger/aries/util/ledger/LedgerDIDResponse.java b/src/test/java/org/hyperledger/aries/util/ledger/LedgerDIDResponse.java new file mode 100644 index 00000000..9fcd31ce --- /dev/null +++ b/src/test/java/org/hyperledger/aries/util/ledger/LedgerDIDResponse.java @@ -0,0 +1,43 @@ +/* + * aca-py client + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: v0.7.2 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package org.hyperledger.aries.util.ledger; + +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + +import java.io.IOException; + +/** + * DID + */ + +@lombok.Data +@lombok.AllArgsConstructor +@lombok.NoArgsConstructor +@lombok.Builder +public class LedgerDIDResponse { + public static final String SERIALIZED_NAME_DID = "did"; + @SerializedName(SERIALIZED_NAME_DID) + private String did; + + public static final String SERIALIZED_NAME_SEED = "seed"; + @SerializedName(SERIALIZED_NAME_SEED) + private String seed; + + public static final String SERIALIZED_NAME_VERKEY = "verkey"; + @SerializedName(SERIALIZED_NAME_VERKEY) + private String verkey; +} From 901af3465ab5557877543fc0ecf7ca1c2730058e Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Tue, 14 Dec 2021 12:41:04 -0800 Subject: [PATCH 5/8] Test author/endorser flow with auto flags Signed-off-by: Ian Costanzo --- .../EndorserConnectionRecordTest.java | 90 ++++++++++++++++++- .../aries/util/ledger/LedgerDIDCreate.java | 13 +-- .../aries/util/ledger/LedgerDIDResponse.java | 13 +-- 3 files changed, 96 insertions(+), 20 deletions(-) diff --git a/src/test/java/org/hyperledger/aries/api/connection/EndorserConnectionRecordTest.java b/src/test/java/org/hyperledger/aries/api/connection/EndorserConnectionRecordTest.java index a591b5d9..088ef8f3 100644 --- a/src/test/java/org/hyperledger/aries/api/connection/EndorserConnectionRecordTest.java +++ b/src/test/java/org/hyperledger/aries/api/connection/EndorserConnectionRecordTest.java @@ -9,10 +9,21 @@ import lombok.extern.slf4j.Slf4j; import org.hyperledger.aries.MultiIntegrationTestBase; +import org.hyperledger.aries.api.credential_definition.CredentialDefinition; +import org.hyperledger.aries.api.credential_definition.CredentialDefinition.CredentialDefinitionRequest; +import org.hyperledger.aries.api.credential_definition.CredentialDefinition.CredentialDefinitionsCreated; import org.hyperledger.aries.api.exception.AriesException; +import org.hyperledger.aries.api.endorser.EndorserInfoFilter; +import org.hyperledger.aries.api.endorser.SetEndorserRoleFilter; +import org.hyperledger.aries.api.endorser.SetEndorserInfoFilter; +import org.hyperledger.aries.api.schema.SchemaSendRequest; import org.hyperledger.acy_py.generated.model.ConnectionInvitation; import org.hyperledger.acy_py.generated.model.DID; import org.hyperledger.acy_py.generated.model.DIDCreate; +import org.hyperledger.acy_py.generated.model.EndorserInfo; +import org.hyperledger.acy_py.generated.model.TransactionJobs; +import org.hyperledger.acy_py.generated.model.TxnOrCredentialDefinitionSendResult; +import org.hyperledger.acy_py.generated.model.TxnOrSchemaSendResult; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -29,7 +40,7 @@ @Slf4j public class EndorserConnectionRecordTest extends MultiIntegrationTestBase { - public static final String INDY_LEDGER_URL = "http://test.bcovrin.vonx.io"; + public static final String INDY_LEDGER_URL = "https://indy-test.bosch-digital.de"; public static final String ENDORSER_CONNECTION_ALIAS = "endorser"; protected String getLedgerUrl() { @@ -169,6 +180,7 @@ void testCreateConnectionBetweenAuthorAndEndorser() throws Exception { assertEquals(1, connections.get().size()); assertEquals(ENDORSER_CONNECTION_ALIAS, connections.get().get(0).getAlias()); assertEquals(ConnectionState.ACTIVE, connections.get().get(0).getState()); + ConnectionRecord authorConnection = connections.get().get(0); final Optional> connections2 = ac2.connections( ConnectionFilter.builder().alias(alias_2).build()); @@ -176,8 +188,82 @@ void testCreateConnectionBetweenAuthorAndEndorser() throws Exception { assertEquals(1, connections2.get().size()); assertEquals(alias_2, connections2.get().get(0).getAlias()); assertEquals(ConnectionState.ACTIVE, connections2.get().get(0).getState()); + ConnectionRecord endorserConnection = connections2.get().get(0); // add endorser metadata to connections - // TODO + Optional endorserJob = ac2.endorseTransactionSetEndorserRole( + endorserConnection.getConnectionId(), + SetEndorserRoleFilter + .builder() + .transactionMyJob(TransactionJobs.TransactionMyJobEnum.TRANSACTION_ENDORSER.getValue()) + .build()); + assertTrue(endorserJob.isPresent()); + Thread.sleep(1000); + Optional authorJob = ac.endorseTransactionSetEndorserRole( + authorConnection.getConnectionId(), + SetEndorserRoleFilter + .builder() + .transactionMyJob(TransactionJobs.TransactionMyJobEnum.TRANSACTION_AUTHOR.getValue()) + .build()); + assertTrue(authorJob.isPresent()); + Thread.sleep(1000); + Optional endorserInfo = ac.endorseTransactionSetEndorserInfo( + authorConnection.getConnectionId(), + SetEndorserInfoFilter + .builder() + .endorserDid(agent1PublicDid.get().getDid()) + .endorserName(ENDORSER_CONNECTION_ALIAS) + .build()); + assertTrue(endorserInfo.isPresent()); + + // confirm author has no schemas or cred defs + Optional> schemasPre = ac.schemasCreated(null); + assertTrue(schemasPre.isPresent()); + assertEquals(0, schemasPre.get().size()); + Optional credDefsPre = ac.credentialDefinitionsCreated(null); + assertTrue(credDefsPre.isPresent()); + assertEquals(0, credDefsPre.get().getCredentialDefinitionIds().size()); + + // author - create schema and credential definition + // (all auto flags are on so the endorsement and ledger write should happen automatically) + Optional schemaResult = ac.schemas( + SchemaSendRequest + .builder() + .schemaName("author_test_schema") + .schemaVersion("1.0.0") + .attributes(List.of("test_attribute")) + .build(), + EndorserInfoFilter + .builder() + .build()); + assertTrue(schemaResult.isPresent()); + assertNotNull(schemaResult.get().getTxn()); + Thread.sleep(4000); // wait for endorsement + + // check that schema is created + Optional> schemasPost = ac.schemasCreated(null); + assertTrue(schemasPost.isPresent()); + assertEquals(1, schemasPost.get().size()); + String schemaId = schemasPost.get().get(0); + + // create cred def + Optional credDefResult = ac.credentialDefinitionsCreate( + CredentialDefinitionRequest + .builder() + .schemaId(schemaId) + .tag("tester") + .supportRevocation(false) + .build(), + EndorserInfoFilter + .builder() + .build()); + assertTrue(credDefResult.isPresent()); + assertNotNull(credDefResult.get().getTxn()); + Thread.sleep(4000); // wait for endorsement + + // check that cred def is created + Optional credDefsPost = ac.credentialDefinitionsCreated(null); + assertTrue(credDefsPost.isPresent()); + assertEquals(1, credDefsPost.get().getCredentialDefinitionIds().size()); } } diff --git a/src/test/java/org/hyperledger/aries/util/ledger/LedgerDIDCreate.java b/src/test/java/org/hyperledger/aries/util/ledger/LedgerDIDCreate.java index 8f543e02..7bef5300 100644 --- a/src/test/java/org/hyperledger/aries/util/ledger/LedgerDIDCreate.java +++ b/src/test/java/org/hyperledger/aries/util/ledger/LedgerDIDCreate.java @@ -1,15 +1,10 @@ /* - * aca-py client - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/acapy-java-client * - * The version of the OpenAPI document: v0.7.2 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. + * SPDX-License-Identifier: Apache-2.0 */ - package org.hyperledger.aries.util.ledger; import com.google.gson.TypeAdapter; diff --git a/src/test/java/org/hyperledger/aries/util/ledger/LedgerDIDResponse.java b/src/test/java/org/hyperledger/aries/util/ledger/LedgerDIDResponse.java index 9fcd31ce..10ded435 100644 --- a/src/test/java/org/hyperledger/aries/util/ledger/LedgerDIDResponse.java +++ b/src/test/java/org/hyperledger/aries/util/ledger/LedgerDIDResponse.java @@ -1,15 +1,10 @@ /* - * aca-py client - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/acapy-java-client * - * The version of the OpenAPI document: v0.7.2 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. + * SPDX-License-Identifier: Apache-2.0 */ - package org.hyperledger.aries.util.ledger; import com.google.gson.TypeAdapter; From bc3a8b4e6f9507437b637ce58ede64edafa649b6 Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Tue, 21 Dec 2021 09:33:47 -0800 Subject: [PATCH 6/8] Didexchange connection integration tests Signed-off-by: Ian Costanzo --- .../connection/MultiConnectionRecordTest.java | 2 +- .../did_exchange/MultiDidExchangeTest.java | 129 ++++++++++++++++++ 2 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/hyperledger/aries/api/did_exchange/MultiDidExchangeTest.java diff --git a/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java b/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java index b1605836..7cea8ac7 100644 --- a/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java +++ b/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java @@ -77,7 +77,7 @@ void testCreateConnectionBetweenAgents() throws Exception { ConnectionReceiveInvitationFilter .builder() .alias(alias_2) - .autoAccept(false) + .autoAccept(Boolean.FALSE) .build()); assertTrue(conn2.isPresent()); diff --git a/src/test/java/org/hyperledger/aries/api/did_exchange/MultiDidExchangeTest.java b/src/test/java/org/hyperledger/aries/api/did_exchange/MultiDidExchangeTest.java new file mode 100644 index 00000000..6b778798 --- /dev/null +++ b/src/test/java/org/hyperledger/aries/api/did_exchange/MultiDidExchangeTest.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/acapy-java-client + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.aries.api.did_exchange; + +import lombok.extern.slf4j.Slf4j; +import org.hyperledger.acy_py.generated.model.DID; +import org.hyperledger.acy_py.generated.model.DIDCreate; +import org.hyperledger.aries.MultiIntegrationTestBase; +import org.hyperledger.aries.api.connection.ConnectionAcceptRequestFilter; +import org.hyperledger.aries.api.connection.ConnectionFilter; +import org.hyperledger.aries.api.connection.ConnectionRecord; +import org.hyperledger.aries.api.connection.ConnectionState; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import org.hyperledger.aries.LedgerClient; +import org.hyperledger.aries.util.ledger.LedgerDIDCreate; +import org.hyperledger.aries.util.ledger.LedgerDIDResponse; + +import java.util.List; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; + +@Slf4j +class MultiDidExchangeTest extends MultiIntegrationTestBase { + + public static final String INDY_LEDGER_URL = "https://indy-test.bosch-digital.de"; + + protected String getLedgerUrl() { + return INDY_LEDGER_URL; + } + + protected String extraAgentArgs(int agentNum) { + switch (agentNum) { + case 1: + return " --genesis-url https://indy-test.bosch-digital.de/genesis" + + " --auto-ping-connection" + + " --public-invites" + + " --wallet-type indy" + + " --wallet-name agent1" + + " --wallet-key agent1key" + + " --auto-provision"; + case 2: + return " --genesis-url https://indy-test.bosch-digital.de/genesis" + + " --auto-ping-connection" + + " --public-invites" + + " --wallet-type indy" + + " --wallet-name agent2" + + " --wallet-key agent2key" + + " --auto-provision"; + default: + return super.extraAgentArgs(agentNum); + } + } + + @Test + void testCreateRequest() throws Exception { + String alias_1 = "my_didex_test_1"; + String alias_2 = "my_didex_test_2"; + + // create a DID for one agent and make it public + lc = LedgerClient.builder() + .url(INDY_LEDGER_URL) + .build(); + + DID localDid1 = ac.walletDidCreate(DIDCreate + .builder() + .build()) + .orElseThrow(); + assertNotNull(localDid1.getVerkey()); + Optional agent1Did = lc.ledgerDidCreate( + LedgerDIDCreate + .builder() + .alias(alias_1) + .did(localDid1.getDid()) + .verkey(localDid1.getVerkey()) + .build()); + assertTrue(agent1Did.isPresent()); + assertNotNull(agent1Did.get().getDid()); + Optional localPublicDid1 = ac.walletDidPublic(localDid1.getDid()); + assertTrue(localPublicDid1.isPresent()); + assertNotNull(localPublicDid1.get().getVerkey()); + + final Optional agent1PublicDid = ac.walletDidPublic(); + assertTrue(agent1PublicDid.isPresent()); + assertNotNull(agent1PublicDid.get().getDid()); + String theirDid = agent1PublicDid.get().getDid(); + + // agent 2 makes an implicit connection request using agent 1's public DID + // TODO include the "alias" parameter when available in aca-py + final Optional c = ac2.didExchangeCreateRequest(DidExchangeCreateRequestFilter + .builder() + .theirPublicDid(theirDid) + .build()); + Assertions.assertTrue(c.isPresent()); + Assertions.assertEquals(ConnectionRecord.ConnectionProtocol.DID_EXCHANGE_V1, c.get().getConnectionProtocol()); + + // wait for the connection to complete and then verify each agent has an active connection + Thread.sleep(1000); + + // now fetch connections and confirm everything completed successfully + // TODO include the "alias" parameter when available in aca-py + final Optional> connections = ac.connections( + ConnectionFilter.builder()/*.alias(alias_1)*/.build()); + assertTrue(connections.isPresent()); + assertEquals(1, connections.get().size()); + //assertEquals(alias_1, connections.get().get(0).getAlias()); + assertEquals(ConnectionState.REQUEST, connections.get().get(0).getState()); + + // accept request (can't "auto"?) + final Optional connection1 = ac.connectionsAcceptRequest( + connections.get().get(0).getConnectionId(), + ConnectionAcceptRequestFilter.builder().build()); + Thread.sleep(2000); + + final Optional> connections2 = ac2.connections( + ConnectionFilter.builder()/*.alias(alias_2)*/.build()); + assertTrue(connections2.isPresent()); + assertEquals(1, connections2.get().size()); + //assertEquals(alias_2, connections2.get().get(0).getAlias()); + assertEquals(ConnectionState.ACTIVE, connections2.get().get(0).getState()); + } +} From e674b4afff9fe8ff1c0267b93ad7796397f54fb8 Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Thu, 13 Jan 2022 09:03:08 -0800 Subject: [PATCH 7/8] Updates from PR feedback Signed-off-by: Ian Costanzo --- .../aries/IntegrationTestBase.java | 3 ++- .../org/hyperledger/aries/LedgerClient.java | 24 ------------------- .../aries/MultiIntegrationTestBase.java | 6 ++--- .../EndorserConnectionRecordTest.java | 2 ++ .../connection/MultiConnectionRecordTest.java | 2 ++ 5 files changed, 9 insertions(+), 28 deletions(-) diff --git a/src/test/java/org/hyperledger/aries/IntegrationTestBase.java b/src/test/java/org/hyperledger/aries/IntegrationTestBase.java index 53210c96..7b638375 100644 --- a/src/test/java/org/hyperledger/aries/IntegrationTestBase.java +++ b/src/test/java/org/hyperledger/aries/IntegrationTestBase.java @@ -22,6 +22,7 @@ public abstract class IntegrationTestBase { private final Logger log = LoggerFactory.getLogger(IntegrationTestBase.class); public static final String ARIES_VERSION = "bcgovimages/aries-cloudagent:py36-1.16-1_0.7.3"; + public static final Integer ARIES_ENDPOINT_PORT = 8030; public static final Integer ARIES_ADMIN_PORT = 8031; protected AriesClient ac; @@ -30,7 +31,7 @@ public abstract class IntegrationTestBase { protected GenericContainer ariesContainer = new GenericContainer<>(ARIES_VERSION) .withExposedPorts(ARIES_ADMIN_PORT) .withCommand("start" - + " -it http 0.0.0.0 8030" + + " -it http 0.0.0.0 " + ARIES_ENDPOINT_PORT + " -ot http --admin 0.0.0.0 " + ARIES_ADMIN_PORT + " --admin-insecure-mode" + " --log-level debug" diff --git a/src/test/java/org/hyperledger/aries/LedgerClient.java b/src/test/java/org/hyperledger/aries/LedgerClient.java index 71f43044..ab148bad 100644 --- a/src/test/java/org/hyperledger/aries/LedgerClient.java +++ b/src/test/java/org/hyperledger/aries/LedgerClient.java @@ -79,30 +79,6 @@ private Request buildPost(String u, Object body) { .build(); } - private Request buildPut(String u, Object body) { - return request(u) - .put(jsonBody(gson.toJson(body))) - .build(); - } - - private Request buildPatch(String u, Object body) { - return request(u) - .patch(jsonBody(gson.toJson(body))) - .build(); - } - - private Request buildGet(String u) { - return request(u) - .get() - .build(); - } - - private Request buildDelete(String u) { - return request(u) - .delete() - .build(); - } - private Request.Builder request(String u) { Request.Builder b = new Request.Builder() .url(u); diff --git a/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java b/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java index 9997a05d..f2cc29a3 100644 --- a/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java +++ b/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java @@ -22,9 +22,9 @@ public abstract class MultiIntegrationTestBase { private final Logger log = LoggerFactory.getLogger(MultiIntegrationTestBase.class); - public static final String ARIES_VERSION = "bcgovimages/aries-cloudagent:py36-1.16-1_0.7.2"; - public static final Integer ARIES_ENDPOINT_PORT = 8030; - public static final Integer ARIES_ADMIN_PORT = 8031; + public static final String ARIES_VERSION = IntegrationTestBase.ARIES_VERSION; + public static final Integer ARIES_ENDPOINT_PORT = IntegrationTestBase.ARIES_ENDPOINT_PORT; + public static final Integer ARIES_ADMIN_PORT = IntegrationTestBase.ARIES_ADMIN_PORT; public static final Integer ARIES_ENDPOINT_PORT_2 = 8040; public static final Integer ARIES_ADMIN_PORT_2 = 8041; diff --git a/src/test/java/org/hyperledger/aries/api/connection/EndorserConnectionRecordTest.java b/src/test/java/org/hyperledger/aries/api/connection/EndorserConnectionRecordTest.java index 088ef8f3..f09b566e 100644 --- a/src/test/java/org/hyperledger/aries/api/connection/EndorserConnectionRecordTest.java +++ b/src/test/java/org/hyperledger/aries/api/connection/EndorserConnectionRecordTest.java @@ -25,6 +25,7 @@ import org.hyperledger.acy_py.generated.model.TxnOrCredentialDefinitionSendResult; import org.hyperledger.acy_py.generated.model.TxnOrSchemaSendResult; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.hyperledger.aries.LedgerClient; @@ -77,6 +78,7 @@ protected String extraAgentArgs(int agentNum) { } @Test + @Tag("IntegrationTest") void testCreateConnectionBetweenAuthorAndEndorser() throws Exception { String alias_1 = "my_agent_1"; String alias_2 = "my_agent_2"; diff --git a/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java b/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java index 7cea8ac7..661c23d6 100644 --- a/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java +++ b/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java @@ -12,6 +12,7 @@ import org.hyperledger.aries.api.exception.AriesException; import org.hyperledger.acy_py.generated.model.ConnectionInvitation; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import java.util.List; @@ -45,6 +46,7 @@ protected String extraAgentArgs(int agentNum) { } @Test + @Tag("IntegrationTest") void testCreateConnectionBetweenAgents() throws Exception { String alias_1 = "my_test_1"; String alias_2 = "my_test_2"; From 5d1f4eaab3a6907f174572f9d4f76cd0eba76680 Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Wed, 19 Jan 2022 09:16:10 -0800 Subject: [PATCH 8/8] Fix license headers Signed-off-by: Ian Costanzo --- src/test/java/org/hyperledger/aries/LedgerClient.java | 2 +- .../java/org/hyperledger/aries/MultiIntegrationTestBase.java | 2 +- .../aries/api/connection/EndorserConnectionRecordTest.java | 2 +- .../aries/api/connection/MultiConnectionRecordTest.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/hyperledger/aries/LedgerClient.java b/src/test/java/org/hyperledger/aries/LedgerClient.java index ab148bad..b98f8c25 100644 --- a/src/test/java/org/hyperledger/aries/LedgerClient.java +++ b/src/test/java/org/hyperledger/aries/LedgerClient.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 - for information on the respective copyright owner + * Copyright (c) 2020-2022 - for information on the respective copyright owner * see the NOTICE file and/or the repository at * https://github.com/hyperledger-labs/acapy-java-client * diff --git a/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java b/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java index f2cc29a3..e7fa5cef 100644 --- a/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java +++ b/src/test/java/org/hyperledger/aries/MultiIntegrationTestBase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 - for information on the respective copyright owner + * Copyright (c) 2020-2022 - for information on the respective copyright owner * see the NOTICE file and/or the repository at * https://github.com/hyperledger-labs/acapy-java-client * diff --git a/src/test/java/org/hyperledger/aries/api/connection/EndorserConnectionRecordTest.java b/src/test/java/org/hyperledger/aries/api/connection/EndorserConnectionRecordTest.java index f09b566e..66177cf9 100644 --- a/src/test/java/org/hyperledger/aries/api/connection/EndorserConnectionRecordTest.java +++ b/src/test/java/org/hyperledger/aries/api/connection/EndorserConnectionRecordTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 - for information on the respective copyright owner + * Copyright (c) 2020-2022 - for information on the respective copyright owner * see the NOTICE file and/or the repository at * https://github.com/hyperledger-labs/acapy-java-client * diff --git a/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java b/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java index 661c23d6..f5be58ba 100644 --- a/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java +++ b/src/test/java/org/hyperledger/aries/api/connection/MultiConnectionRecordTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 - for information on the respective copyright owner + * Copyright (c) 2020-2022 - for information on the respective copyright owner * see the NOTICE file and/or the repository at * https://github.com/hyperledger-labs/acapy-java-client *