From 77697f74585dc2b67adbbc012bced82d74a9fc60 Mon Sep 17 00:00:00 2001 From: peacekeeper Date: Tue, 20 Jun 2017 17:49:43 +0200 Subject: [PATCH 001/349] add .gitignore for Java project --- wrappers/java/.gitignore | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 wrappers/java/.gitignore diff --git a/wrappers/java/.gitignore b/wrappers/java/.gitignore new file mode 100644 index 0000000000..1c08a5aa39 --- /dev/null +++ b/wrappers/java/.gitignore @@ -0,0 +1,6 @@ +.classpath +.project +/.settings/ +/target/ +/bin/ + From bc3bfded4283edeb9b30893b84f9fff53ca45529 Mon Sep 17 00:00:00 2001 From: peacekeeper Date: Tue, 20 Jun 2017 18:39:55 +0200 Subject: [PATCH 002/349] add agent.rs wrapper --- .../org/hyperledger/indy/sdk/LibSovrin.java | 8 + .../org/hyperledger/indy/sdk/agent/Agent.java | 237 ++++++++++++++++++ .../indy/sdk/agent/AgentJSONParameters.java | 11 + .../indy/sdk/agent/AgentResults.java | 42 ++++ 4 files changed, 298 insertions(+) create mode 100644 wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java create mode 100644 wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentJSONParameters.java create mode 100644 wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentResults.java diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibSovrin.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibSovrin.java index 6a4560baea..36aaf0ec7c 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibSovrin.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibSovrin.java @@ -72,6 +72,14 @@ public interface API extends Library { public int sovrin_prover_get_claims_for_proof_req(int command_handle, int wallet_handle, String proof_request_json, Callback cb); public int sovrin_prover_create_proof(int command_handle, int wallet_handle, String proof_req_json, String requested_claims_json, String schemas_json, String master_secret_name, String claim_defs_json, String revoc_regs_json, Callback cb); public int sovrin_verifier_verify_proof(int command_handle, int wallet_handle, String proof_request_json, String proof_json, String schemas_json, String claim_defs_jsons, String revoc_regs_json, Callback cb); + + // agent.rs + + public int sovrin_agent_connect(int command_handle, int wallet_handle, String sender_did, String receiver_did, Callback connection_cb, Callback message_cb); + public int sovrin_agent_listen(int command_handle, int wallet_handle, String endpoint, Callback listener_cb, Callback connection_cb, Callback message_cb); + public int sovrin_agent_send(int command_handle, int connection_handle, String message, Callback cb); + public int sovrin_agent_close_connection(int command_handle, int connection_handle, Callback cb); + public int sovrin_agent_close_listener(int command_handle, int listener_handle, Callback cb); } /* diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java new file mode 100644 index 0000000000..788a671145 --- /dev/null +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java @@ -0,0 +1,237 @@ +package org.hyperledger.indy.sdk.agent; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; + +import org.hyperledger.indy.sdk.LibSovrin; +import org.hyperledger.indy.sdk.SovrinException; +import org.hyperledger.indy.sdk.SovrinJava; +import org.hyperledger.indy.sdk.agent.AgentResults.AgentCloseConnectionResult; +import org.hyperledger.indy.sdk.agent.AgentResults.AgentCloseListenerResult; +import org.hyperledger.indy.sdk.agent.AgentResults.AgentConnectResult; +import org.hyperledger.indy.sdk.agent.AgentResults.AgentListenResult; +import org.hyperledger.indy.sdk.agent.AgentResults.AgentSendResult; +import org.hyperledger.indy.sdk.wallet.Wallet; + +import com.sun.jna.Callback; + +/** + * agent.rs API + */ +public class Agent extends SovrinJava.API { + + private Agent() { + + } + + /* + * STATIC METHODS + */ + + public static Future agentConnect( + Wallet wallet, + String senderDid, + String receiverDid, + Callback messageCb) throws SovrinException { + + final CompletableFuture future = new CompletableFuture<> (); + + Callback connectionCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(int xcommand_handle, int err, int connection_handle) { + + if (! checkCallback(future, xcommand_handle, err)) return; + + Agent.Connection connection = new Agent.Connection(connection_handle); + + AgentConnectResult result = new AgentConnectResult(connection); + future.complete(result); + } + }; + + int walletHandle = wallet.getWalletHandle(); + + int result = LibSovrin.api.sovrin_agent_connect( + FIXED_COMMAND_HANDLE, + walletHandle, + senderDid, + receiverDid, + connectionCb, + messageCb); + + checkResult(result); + + return future; + } + + public static Future agentListen( + Wallet wallet, + String endpoint, + Callback connectionCb, + Callback messageCb) throws SovrinException { + + final CompletableFuture future = new CompletableFuture<> (); + + Callback listenerCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(int xcommand_handle, int err, int listener_handle) { + + if (! checkCallback(future, xcommand_handle, err)) return; + + Agent.Listener connection = new Agent.Listener(listener_handle); + + AgentListenResult result = new AgentListenResult(connection); + future.complete(result); + } + }; + + int walletHandle = wallet.getWalletHandle(); + + int result = LibSovrin.api.sovrin_agent_listen( + FIXED_COMMAND_HANDLE, + walletHandle, + endpoint, + listenerCb, + connectionCb, + messageCb); + + checkResult(result); + + return future; + } + + public static Future agentSend( + Agent.Connection connection, + String message) throws SovrinException { + + final CompletableFuture future = new CompletableFuture<> (); + + Callback callback = new Callback() { + + @SuppressWarnings("unused") + public void callback(int xcommand_handle, int err) { + + if (! checkCallback(future, xcommand_handle, err)) return; + + AgentSendResult result = new AgentSendResult(); + future.complete(result); + } + }; + + int connectionHandle = connection.getConnectionHandle(); + + int result = LibSovrin.api.sovrin_agent_send( + FIXED_COMMAND_HANDLE, + connectionHandle, + message, + callback); + + checkResult(result); + + return future; + } + + public static Future agentCloseConnection( + Agent.Connection connection) throws SovrinException { + + final CompletableFuture future = new CompletableFuture<> (); + + Callback callback = new Callback() { + + @SuppressWarnings("unused") + public void callback(int xcommand_handle, int err) { + + if (! checkCallback(future, xcommand_handle, err)) return; + + AgentCloseConnectionResult result = new AgentCloseConnectionResult(); + future.complete(result); + } + }; + + int connectionHandle = connection.getConnectionHandle(); + + int result = LibSovrin.api.sovrin_agent_close_connection( + FIXED_COMMAND_HANDLE, + connectionHandle, + callback); + + checkResult(result); + + return future; + } + + public static Future agentCloseListener( + Agent.Listener listener) throws SovrinException { + + final CompletableFuture future = new CompletableFuture<> (); + + Callback callback = new Callback() { + + @SuppressWarnings("unused") + public void callback(int xcommand_handle, int err) { + + if (! checkCallback(future, xcommand_handle, err)) return; + + AgentCloseListenerResult result = new AgentCloseListenerResult(); + future.complete(result); + } + }; + + int listenerHandle = listener.getListenerHandle(); + + int result = LibSovrin.api.sovrin_agent_close_connection( + FIXED_COMMAND_HANDLE, + listenerHandle, + callback); + + checkResult(result); + + return future; + } + + /* + * NESTED CLASSES WITH INSTANCE METHODS + */ + + public static class Connection { + + private final int connectionHandle; + + private Connection(int connectionHandle) { + + this.connectionHandle = connectionHandle; + } + + public int getConnectionHandle() { + + return this.connectionHandle; + } + + public Future agentCloseConnection() throws SovrinException { + + return Agent.agentCloseConnection(this); + } + } + + public static class Listener { + + private final int listenerHandle; + + private Listener(int listenerHandle) { + + this.listenerHandle = listenerHandle; + } + + public int getListenerHandle() { + + return this.listenerHandle; + } + + public Future agentCloseListener() throws SovrinException { + + return Agent.agentCloseListener(this); + } + } +} diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentJSONParameters.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentJSONParameters.java new file mode 100644 index 0000000000..a165b15296 --- /dev/null +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentJSONParameters.java @@ -0,0 +1,11 @@ +package org.hyperledger.indy.sdk.agent; + +/** + * agent.rs JSON parameters + */ +public class AgentJSONParameters { + + private AgentJSONParameters() { + + } +} diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentResults.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentResults.java new file mode 100644 index 0000000000..509df602b6 --- /dev/null +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentResults.java @@ -0,0 +1,42 @@ +package org.hyperledger.indy.sdk.agent; + +import org.hyperledger.indy.sdk.SovrinJava; + +/** + * agent.rs results + */ +public final class AgentResults { + + private AgentResults() { + + } + + public static class AgentConnectResult extends SovrinJava.Result { + + private Agent.Connection connection; + AgentConnectResult(Agent.Connection connection) { this.connection = connection; } + public Agent.Connection getConnection() { return this.connection; } + } + + public static class AgentListenResult extends SovrinJava.Result { + + private Agent.Listener listener; + AgentListenResult(Agent.Listener listener) { this.listener = listener; } + public Agent.Listener getListener() { return this.listener; } + } + + public static class AgentSendResult extends SovrinJava.Result { + + AgentSendResult() { } + } + + public static class AgentCloseConnectionResult extends SovrinJava.Result { + + AgentCloseConnectionResult() { } + } + + public static class AgentCloseListenerResult extends SovrinJava.Result { + + AgentCloseListenerResult() { } + } +} From b9dd26ed26fe0a2ad23e264955fd894022520539 Mon Sep 17 00:00:00 2001 From: peacekeeper Date: Tue, 20 Jun 2017 18:40:48 +0200 Subject: [PATCH 003/349] private constructors for Pool and Wallet --- .../java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java | 2 +- .../src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java index f2475ae3eb..e46af482b9 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java @@ -23,7 +23,7 @@ public class Pool extends SovrinJava.API { private final int poolHandle; - Pool(int poolHandle) { + private Pool(int poolHandle) { this.poolHandle = poolHandle; } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java index a245e43438..786a2cc770 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java @@ -21,7 +21,7 @@ public class Wallet extends SovrinJava.API { private final int walletHandle; - Wallet(int walletHandle) { + private Wallet(int walletHandle) { this.walletHandle = walletHandle; } From b4cc89b9cba062a6e6dccd2c75759798dc46241f Mon Sep 17 00:00:00 2001 From: peacekeeper Date: Tue, 20 Jun 2017 18:43:26 +0200 Subject: [PATCH 004/349] use instance objects instead of handles --- .../org/hyperledger/indy/sdk/pool/Pool.java | 22 +++++++++++-------- .../hyperledger/indy/sdk/wallet/Wallet.java | 22 +++++++++++-------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java index e46af482b9..8df2d67fb4 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java @@ -29,14 +29,14 @@ private Pool(int poolHandle) { } public int getPoolHandle() { - + return this.poolHandle; } - + /* * STATIC METHODS */ - + public static Future createPoolLedgerConfig( String configName, CreatePoolLedgerConfigJSONParameter config) throws SovrinException { @@ -59,7 +59,7 @@ public void callback(int xcommand_handle, int err) { FIXED_COMMAND_HANDLE, configName, config == null ? null : config.toJson(), - callback); + callback); checkResult(result); @@ -90,7 +90,7 @@ public void callback(int xcommand_handle, int err, int pool_handle) { FIXED_COMMAND_HANDLE, configName, config == null ? null : config.toJson(), - callback); + callback); checkResult(result); @@ -98,7 +98,7 @@ public void callback(int xcommand_handle, int err, int pool_handle) { } private static Future refreshPoolLedger( - int handle) throws SovrinException { + Pool pool) throws SovrinException { final CompletableFuture future = new CompletableFuture<> (); @@ -114,6 +114,8 @@ public void callback(int xcommand_handle, int err) { } }; + int handle = pool.getPoolHandle(); + int result = LibSovrin.api.sovrin_refresh_pool_ledger( FIXED_COMMAND_HANDLE, handle, @@ -125,7 +127,7 @@ public void callback(int xcommand_handle, int err) { } private static Future closePoolLedger( - int handle) throws SovrinException { + Pool pool) throws SovrinException { final CompletableFuture future = new CompletableFuture<> (); @@ -141,6 +143,8 @@ public void callback(int xcommand_handle, int err) { } }; + int handle = pool.getPoolHandle(); + int result = LibSovrin.api.sovrin_refresh_pool_ledger( FIXED_COMMAND_HANDLE, handle, @@ -185,12 +189,12 @@ public void callback(int xcommand_handle, int err) { public Future refreshPoolLedger( ) throws SovrinException { - return refreshPoolLedger(this.poolHandle); + return refreshPoolLedger(this); } public Future closePoolLedger( ) throws SovrinException { - return closePoolLedger(this.poolHandle); + return closePoolLedger(this); } } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java index 786a2cc770..a4d3d453d4 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java @@ -27,7 +27,7 @@ private Wallet(int walletHandle) { } public int getWalletHandle() { - + return this.walletHandle; } @@ -89,12 +89,12 @@ public void callback(int xcommand_handle, int err, int handle) { if (! checkCallback(future, xcommand_handle, err)) return; Wallet wallet = new Wallet(handle); - + OpenWalletResult result = new OpenWalletResult(wallet); future.complete(result); } }; - + int result = LibSovrin.api.sovrin_open_wallet( FIXED_COMMAND_HANDLE, name, @@ -108,7 +108,7 @@ public void callback(int xcommand_handle, int err, int handle) { } private static Future closeWallet( - int handle) throws SovrinException { + Wallet wallet) throws SovrinException { final CompletableFuture future = new CompletableFuture<> (); @@ -124,6 +124,8 @@ public void callback(int xcommand_handle, int err) { } }; + int handle = wallet.getWalletHandle(); + int result = LibSovrin.api.sovrin_close_wallet( FIXED_COMMAND_HANDLE, handle, @@ -164,7 +166,7 @@ public void callback(int xcommand_handle, int err) { } private static Future walletSetSeqNoForValue( - int walletHandle, + Wallet wallet, String walletKey, String configName) throws SovrinException { @@ -182,6 +184,8 @@ public void callback(int xcommand_handle, int err) { } }; + int walletHandle = wallet.getWalletHandle(); + int result = LibSovrin.api.sovrin_wallet_set_seq_no_for_value( FIXED_COMMAND_HANDLE, walletHandle, @@ -199,14 +203,14 @@ public void callback(int xcommand_handle, int err) { public Future closeWallet( ) throws SovrinException { - - return closeWallet(this.walletHandle); + + return closeWallet(this); } public Future walletSetSeqNoForValue( String walletKey, String configName) throws SovrinException { - - return walletSetSeqNoForValue(this.walletHandle, walletKey, configName); + + return walletSetSeqNoForValue(this, walletKey, configName); } } From 6a70912c085e69148f2df041f2b4048d16ad46d2 Mon Sep 17 00:00:00 2001 From: peacekeeper Date: Tue, 20 Jun 2017 18:46:49 +0200 Subject: [PATCH 005/349] rename "callback" variable to "cb" --- .../org/hyperledger/indy/sdk/agent/Agent.java | 12 ++--- .../indy/sdk/anoncreds/Anoncreds.java | 24 +++++----- .../hyperledger/indy/sdk/ledger/Ledger.java | 48 +++++++++---------- .../org/hyperledger/indy/sdk/pool/Pool.java | 20 ++++---- .../hyperledger/indy/sdk/signus/Signus.java | 28 +++++------ .../hyperledger/indy/sdk/wallet/Wallet.java | 20 ++++---- 6 files changed, 76 insertions(+), 76 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java index 788a671145..715eb363b7 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java @@ -108,7 +108,7 @@ public static Future agentSend( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err) { @@ -126,7 +126,7 @@ public void callback(int xcommand_handle, int err) { FIXED_COMMAND_HANDLE, connectionHandle, message, - callback); + cb); checkResult(result); @@ -138,7 +138,7 @@ public static Future agentCloseConnection( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err) { @@ -155,7 +155,7 @@ public void callback(int xcommand_handle, int err) { int result = LibSovrin.api.sovrin_agent_close_connection( FIXED_COMMAND_HANDLE, connectionHandle, - callback); + cb); checkResult(result); @@ -167,7 +167,7 @@ public static Future agentCloseListener( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err) { @@ -184,7 +184,7 @@ public void callback(int xcommand_handle, int err) { int result = LibSovrin.api.sovrin_agent_close_connection( FIXED_COMMAND_HANDLE, listenerHandle, - callback); + cb); checkResult(result); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java index da7672956a..0e527e12a9 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java @@ -37,7 +37,7 @@ public static Future issuerCreateAndStoreCla final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String claim_def_json, String claim_def_uuid) { @@ -57,7 +57,7 @@ public void callback(int xcommand_handle, int err, String claim_def_json, String schemaJson, signatureType, createNonRevoc, - callback); + cb); checkResult(result); @@ -71,7 +71,7 @@ public static Future issuerCreateAndStoreRev final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String revoc_reg_json, String revoc_reg_uuid) { @@ -90,7 +90,7 @@ public void callback(int xcommand_handle, int err, String revoc_reg_json, String walletHandle, claimDefSeqNo, maxClaimNum, - callback); + cb); checkResult(result); @@ -106,7 +106,7 @@ public static Future issuerCreateClaim( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String revoc_reg_update_json, String xclaim_json) { @@ -127,7 +127,7 @@ public void callback(int xcommand_handle, int err, String revoc_reg_update_json, claimJson, revocRegSeqNo, userRevocIndex, - callback); + cb); checkResult(result); @@ -142,7 +142,7 @@ public static Future issuerRevokeClaim( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String revoc_reg_update_json) { @@ -162,7 +162,7 @@ public void callback(int xcommand_handle, int err, String revoc_reg_update_json) claimDefSeqNo, revocRegSeqNo, userRevocIndex, - callback); + cb); checkResult(result); @@ -175,7 +175,7 @@ public static Future proverStoreClaimOffer( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err) { @@ -193,7 +193,7 @@ public void callback(int xcommand_handle, int err) { FIXED_COMMAND_HANDLE, walletHandle, claimOfferJson, - callback); + cb); checkResult(result); @@ -206,7 +206,7 @@ public static Future proverGetClaimOffers( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String claim_offers_json) { @@ -224,7 +224,7 @@ public void callback(int xcommand_handle, int err, String claim_offers_json) { FIXED_COMMAND_HANDLE, walletHandle, filterJson, - callback); + cb); checkResult(result); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java index 7c233a52c4..f35fa4e1cb 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java @@ -44,7 +44,7 @@ public static Future signAndSubmitRequest( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String request_result_json) { @@ -65,7 +65,7 @@ public void callback(int xcommand_handle, int err, String request_result_json) { walletHandle, submitterDid, requestJson, - callback); + cb); checkResult(result); @@ -78,7 +78,7 @@ public static Future submitRequest( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String request_result_json) { @@ -96,7 +96,7 @@ public void callback(int xcommand_handle, int err, String request_result_json) { FIXED_COMMAND_HANDLE, poolHandle, requestJson, - callback); + cb); checkResult(result); @@ -110,7 +110,7 @@ public static Future buildGetDdoRequest( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String request_json) { @@ -126,7 +126,7 @@ public void callback(int xcommand_handle, int err, String request_json) { FIXED_COMMAND_HANDLE, submitterDid, targetDid, - callback); + cb); checkResult(result); @@ -142,7 +142,7 @@ public static Future buildNymRequest( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String request_json) { @@ -161,7 +161,7 @@ public void callback(int xcommand_handle, int err, String request_json) { verkey, alias, role, - callback); + cb); checkResult(result); @@ -177,7 +177,7 @@ public static Future buildAttribRequest( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String request_json) { @@ -196,7 +196,7 @@ public void callback(int xcommand_handle, int err, String request_json) { hash, raw, enc, - callback); + cb); checkResult(result); @@ -210,7 +210,7 @@ public static Future buildGetAttribRequest( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String request_json) { @@ -227,7 +227,7 @@ public void callback(int xcommand_handle, int err, String request_json) { submitterDid, targetDid, data, - callback); + cb); checkResult(result); @@ -240,7 +240,7 @@ public static Future buildGetNymRequest( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String request_json) { @@ -256,7 +256,7 @@ public void callback(int xcommand_handle, int err, String request_json) { FIXED_COMMAND_HANDLE, submitterDid, targetDid, - callback); + cb); checkResult(result); @@ -269,7 +269,7 @@ public static Future buildSchemaRequest( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String request_json) { @@ -285,7 +285,7 @@ public void callback(int xcommand_handle, int err, String request_json) { FIXED_COMMAND_HANDLE, submitterDid, data, - callback); + cb); checkResult(result); @@ -298,7 +298,7 @@ public static Future buildGetSchemaRequest( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String request_json) { @@ -314,7 +314,7 @@ public void callback(int xcommand_handle, int err, String request_json) { FIXED_COMMAND_HANDLE, submitterDid, data, - callback); + cb); checkResult(result); @@ -328,7 +328,7 @@ public static Future buildClaimDefTxn( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String request_json) { @@ -345,7 +345,7 @@ public void callback(int xcommand_handle, int err, String request_json) { submitterDid, xref, data, - callback); + cb); checkResult(result); @@ -358,7 +358,7 @@ public static Future buildGetClaimDefTxn( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String request_json) { @@ -374,7 +374,7 @@ public void callback(int xcommand_handle, int err, String request_json) { FIXED_COMMAND_HANDLE, submitterDid, xref, - callback); + cb); checkResult(result); @@ -388,7 +388,7 @@ public static Future buildNodeRequest( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String request_json) { @@ -405,7 +405,7 @@ public void callback(int xcommand_handle, int err, String request_json) { submitterDid, targetDid, data, - callback); + cb); checkResult(result); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java index 8df2d67fb4..0ea1422979 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java @@ -43,7 +43,7 @@ public static Future createPoolLedgerConfig( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err) { @@ -59,7 +59,7 @@ public void callback(int xcommand_handle, int err) { FIXED_COMMAND_HANDLE, configName, config == null ? null : config.toJson(), - callback); + cb); checkResult(result); @@ -72,7 +72,7 @@ public static Future openPoolLedger( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, int pool_handle) { @@ -90,7 +90,7 @@ public void callback(int xcommand_handle, int err, int pool_handle) { FIXED_COMMAND_HANDLE, configName, config == null ? null : config.toJson(), - callback); + cb); checkResult(result); @@ -102,7 +102,7 @@ private static Future refreshPoolLedger( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err) { @@ -119,7 +119,7 @@ public void callback(int xcommand_handle, int err) { int result = LibSovrin.api.sovrin_refresh_pool_ledger( FIXED_COMMAND_HANDLE, handle, - callback); + cb); checkResult(result); @@ -131,7 +131,7 @@ private static Future closePoolLedger( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err) { @@ -148,7 +148,7 @@ public void callback(int xcommand_handle, int err) { int result = LibSovrin.api.sovrin_refresh_pool_ledger( FIXED_COMMAND_HANDLE, handle, - callback); + cb); checkResult(result); @@ -160,7 +160,7 @@ public static Future deletePoolLedgerConfig( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err) { @@ -175,7 +175,7 @@ public void callback(int xcommand_handle, int err) { int result = LibSovrin.api.sovrin_delete_pool_ledger_config( FIXED_COMMAND_HANDLE, configName, - callback); + cb); checkResult(result); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java index 950bcd79a7..a0d2db63c7 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java @@ -38,7 +38,7 @@ public static Future createAndStoreMyDid( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String did, String verkey, String pk) { @@ -56,7 +56,7 @@ public void callback(int xcommand_handle, int err, String did, String verkey, St FIXED_COMMAND_HANDLE, walletHandle, didJson == null ? null : didJson.toJson(), - callback); + cb); checkResult(result); @@ -70,7 +70,7 @@ public static Future replaceKeys( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String verkey, String pk) { @@ -89,7 +89,7 @@ public void callback(int xcommand_handle, int err, String verkey, String pk) { walletHandle, did, identityJson, - callback); + cb); checkResult(result); @@ -102,7 +102,7 @@ public static Future storeTheirDid( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err) { @@ -120,7 +120,7 @@ public void callback(int xcommand_handle, int err) { FIXED_COMMAND_HANDLE, walletHandle, identityJson, - callback); + cb); checkResult(result); @@ -134,7 +134,7 @@ public static Future sign( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String signature) { @@ -153,7 +153,7 @@ public void callback(int xcommand_handle, int err, String signature) { walletHandle, did, msg, - callback); + cb); checkResult(result); @@ -168,7 +168,7 @@ public static Future verifySignature( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, boolean valid) { @@ -189,7 +189,7 @@ public void callback(int xcommand_handle, int err, boolean valid) { poolHandle, did, signedMsg, - callback); + cb); checkResult(result); @@ -203,7 +203,7 @@ public static Future encrypt( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String encryptedMsg) { @@ -222,7 +222,7 @@ public void callback(int xcommand_handle, int err, String encryptedMsg) { walletHandle, did, msg, - callback); + cb); checkResult(result); @@ -236,7 +236,7 @@ public static Future decrypt( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, String decryptedMsg) { @@ -255,7 +255,7 @@ public void callback(int xcommand_handle, int err, String decryptedMsg) { walletHandle, did, encryptedMsg, - callback); + cb); checkResult(result); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java index a4d3d453d4..1f0c4c21c0 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java @@ -48,7 +48,7 @@ public static Future createWallet( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err) { @@ -67,7 +67,7 @@ public void callback(int xcommand_handle, int err) { xtype, config, credentials, - callback); + cb); checkResult(result); @@ -81,7 +81,7 @@ public static Future openWallet( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, int handle) { @@ -100,7 +100,7 @@ public void callback(int xcommand_handle, int err, int handle) { name, runtimeConfig, credentials, - callback); + cb); checkResult(result); @@ -112,7 +112,7 @@ private static Future closeWallet( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err) { @@ -129,7 +129,7 @@ public void callback(int xcommand_handle, int err) { int result = LibSovrin.api.sovrin_close_wallet( FIXED_COMMAND_HANDLE, handle, - callback); + cb); checkResult(result); @@ -142,7 +142,7 @@ public static Future deleteWallet( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err) { @@ -158,7 +158,7 @@ public void callback(int xcommand_handle, int err) { FIXED_COMMAND_HANDLE, name, credentials, - callback); + cb); checkResult(result); @@ -172,7 +172,7 @@ private static Future walletSetSeqNoForValue( final CompletableFuture future = new CompletableFuture<> (); - Callback callback = new Callback() { + Callback cb = new Callback() { @SuppressWarnings("unused") public void callback(int xcommand_handle, int err) { @@ -190,7 +190,7 @@ public void callback(int xcommand_handle, int err) { FIXED_COMMAND_HANDLE, walletHandle, walletKey, - callback); + cb); checkResult(result); From d737eb15ef4600dc693d2cd55d4610f701ef3061 Mon Sep 17 00:00:00 2001 From: peacekeeper Date: Wed, 21 Jun 2017 22:20:28 +0200 Subject: [PATCH 006/349] helper classes for agent.rs callbacks --- .../indy/sdk/agent/AgentCallbacks.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentCallbacks.java diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentCallbacks.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentCallbacks.java new file mode 100644 index 0000000000..7e3ed0033a --- /dev/null +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentCallbacks.java @@ -0,0 +1,27 @@ +package org.hyperledger.indy.sdk.agent; + +import com.sun.jna.Callback; + +/** + * agent.rs callbacks + */ +public final class AgentCallbacks { + + private AgentCallbacks() { + + } + + public static class AgentMessageCallback implements Callback { + + public final void callback(int xconnection_handle, int err, String message) { + + } + } + + public static class AgentConnectionCallback implements Callback { + + public final void callback(int xlistener_handle, int err, int connection_handle, String sender_did, String receiver_did) { + + } + } +} From 7bece0b395840091040e9441aa586c513d4c86e1 Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Thu, 29 Jun 2017 23:44:36 +0200 Subject: [PATCH 007/349] additional callback check method --- .../main/java/org/hyperledger/indy/sdk/SovrinJava.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/SovrinJava.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/SovrinJava.java index b246e08508..30db8d1b9c 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/SovrinJava.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/SovrinJava.java @@ -34,6 +34,14 @@ protected static boolean checkCallback(CompletableFuture future, int err) { + + ErrorCode errorCode = ErrorCode.valueOf(err); + if (! ErrorCode.Success.equals(errorCode)) { future.completeExceptionally(SovrinException.fromErrorCode(errorCode, err)); return false; } + + return true; + } + protected static void checkResult(int result) throws SovrinException { ErrorCode errorCode = ErrorCode.valueOf(result); From 43632596c7013bba400017f4e83d0c1887455df3 Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Fri, 30 Jun 2017 00:12:39 +0200 Subject: [PATCH 008/349] sync agent.rs wrapper to upstream method changes --- .../org/hyperledger/indy/sdk/LibSovrin.java | 6 +- .../org/hyperledger/indy/sdk/agent/Agent.java | 85 ++++++++++++++++++- .../indy/sdk/agent/AgentResults.java | 10 +++ 3 files changed, 95 insertions(+), 6 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibSovrin.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibSovrin.java index 36aaf0ec7c..9e119f057a 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibSovrin.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibSovrin.java @@ -75,8 +75,10 @@ public interface API extends Library { // agent.rs - public int sovrin_agent_connect(int command_handle, int wallet_handle, String sender_did, String receiver_did, Callback connection_cb, Callback message_cb); - public int sovrin_agent_listen(int command_handle, int wallet_handle, String endpoint, Callback listener_cb, Callback connection_cb, Callback message_cb); + public int sovrin_agent_connect(int command_handle, int pool_handle, int wallet_handle, String sender_did, String receiver_did, Callback connection_cb, Callback message_cb); + public int sovrin_agent_listen(int command_handle, String endpoint, Callback listener_cb, Callback connection_cb, Callback message_cb); + public int sovrin_agent_add_identity(int command_handle, int listener_handle, int pool_handle, int wallet_handle, String did, Callback add_identity_cb); + public int sovrin_agent_remove_identity(int command_handle, int listener_handle, int wallet_handle, String did, Callback rm_identity_cb); public int sovrin_agent_send(int command_handle, int connection_handle, String message, Callback cb); public int sovrin_agent_close_connection(int command_handle, int connection_handle, Callback cb); public int sovrin_agent_close_listener(int command_handle, int listener_handle, Callback cb); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java index 715eb363b7..702d4c7afa 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java @@ -6,11 +6,14 @@ import org.hyperledger.indy.sdk.LibSovrin; import org.hyperledger.indy.sdk.SovrinException; import org.hyperledger.indy.sdk.SovrinJava; +import org.hyperledger.indy.sdk.agent.AgentResults.AgentAddIdentityResult; import org.hyperledger.indy.sdk.agent.AgentResults.AgentCloseConnectionResult; import org.hyperledger.indy.sdk.agent.AgentResults.AgentCloseListenerResult; import org.hyperledger.indy.sdk.agent.AgentResults.AgentConnectResult; import org.hyperledger.indy.sdk.agent.AgentResults.AgentListenResult; +import org.hyperledger.indy.sdk.agent.AgentResults.AgentRemoveIdentityResult; import org.hyperledger.indy.sdk.agent.AgentResults.AgentSendResult; +import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.wallet.Wallet; import com.sun.jna.Callback; @@ -29,6 +32,7 @@ private Agent() { */ public static Future agentConnect( + Pool pool, Wallet wallet, String senderDid, String receiverDid, @@ -50,10 +54,12 @@ public void callback(int xcommand_handle, int err, int connection_handle) { } }; + int poolHandle = pool.getPoolHandle(); int walletHandle = wallet.getWalletHandle(); int result = LibSovrin.api.sovrin_agent_connect( FIXED_COMMAND_HANDLE, + poolHandle, walletHandle, senderDid, receiverDid, @@ -66,7 +72,6 @@ public void callback(int xcommand_handle, int err, int connection_handle) { } public static Future agentListen( - Wallet wallet, String endpoint, Callback connectionCb, Callback messageCb) throws SovrinException { @@ -87,11 +92,8 @@ public void callback(int xcommand_handle, int err, int listener_handle) { } }; - int walletHandle = wallet.getWalletHandle(); - int result = LibSovrin.api.sovrin_agent_listen( FIXED_COMMAND_HANDLE, - walletHandle, endpoint, listenerCb, connectionCb, @@ -102,6 +104,81 @@ public void callback(int xcommand_handle, int err, int listener_handle) { return future; } + public static Future agentAddIdentity( + Agent.Listener listener, + Pool pool, + Wallet wallet, + String did, + Callback connectionCb, + Callback messageCb) throws SovrinException { + + final CompletableFuture future = new CompletableFuture<> (); + + Callback addIdentityCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(int xcommand_handle, int err, int listener_handle) { + + if (! checkCallback(future, xcommand_handle, err)) return; + + AgentAddIdentityResult result = new AgentAddIdentityResult(); + future.complete(result); + } + }; + + int listenerHandle = listener.getListenerHandle(); + int poolHandle = pool.getPoolHandle(); + int walletHandle = wallet.getWalletHandle(); + + int result = LibSovrin.api.sovrin_agent_add_identity( + FIXED_COMMAND_HANDLE, + listenerHandle, + poolHandle, + walletHandle, + did, + addIdentityCb); + + checkResult(result); + + return future; + } + + public static Future agentRemoveIdentity( + Agent.Listener listener, + Wallet wallet, + String did, + Callback connectionCb, + Callback messageCb) throws SovrinException { + + final CompletableFuture future = new CompletableFuture<> (); + + Callback rmIdentityCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(int xcommand_handle, int err, int listener_handle) { + + if (! checkCallback(future, xcommand_handle, err)) return; + + AgentRemoveIdentityResult result = new AgentRemoveIdentityResult(); + future.complete(result); + } + }; + + int listenerHandle = listener.getListenerHandle(); + int walletHandle = wallet.getWalletHandle(); + + int result = LibSovrin.api.sovrin_agent_remove_identity( + FIXED_COMMAND_HANDLE, + listenerHandle, + walletHandle, + did, + rmIdentityCb); + + checkResult(result); + + return future; + } + public static Future agentSend( Agent.Connection connection, String message) throws SovrinException { diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentResults.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentResults.java index 509df602b6..c54f812504 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentResults.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentResults.java @@ -30,6 +30,16 @@ public static class AgentSendResult extends SovrinJava.Result { AgentSendResult() { } } + public static class AgentAddIdentityResult extends SovrinJava.Result { + + AgentAddIdentityResult() { } + } + + public static class AgentRemoveIdentityResult extends SovrinJava.Result { + + AgentRemoveIdentityResult() { } + } + public static class AgentCloseConnectionResult extends SovrinJava.Result { AgentCloseConnectionResult() { } From d0f247a89afc58446027d8aef286cfd9da9f6bf6 Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Fri, 30 Jun 2017 13:42:39 +0200 Subject: [PATCH 009/349] add more instance methods to Connection and Listener classes --- .../org/hyperledger/indy/sdk/agent/Agent.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java index 702d4c7afa..909389585f 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java @@ -286,6 +286,11 @@ public int getConnectionHandle() { return this.connectionHandle; } + public Future agentSend(String message) throws SovrinException { + + return Agent.agentSend(this, message); + } + public Future agentCloseConnection() throws SovrinException { return Agent.agentCloseConnection(this); @@ -306,6 +311,16 @@ public int getListenerHandle() { return this.listenerHandle; } + public Future agentAddIdentity(Pool pool, Wallet wallet, String did, Callback connectionCb, Callback messageCb) throws SovrinException { + + return Agent.agentAddIdentity(this, pool, wallet, did, connectionCb, messageCb); + } + + public Future agentRemoveIdentity(Wallet wallet, String did, Callback connectionCb, Callback messageCb) throws SovrinException { + + return Agent.agentRemoveIdentity(this, wallet, did, connectionCb, messageCb); + } + public Future agentCloseListener() throws SovrinException { return Agent.agentCloseListener(this); From 42ad54dde419c0ac5e0be5b70046aa64b4077cee Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 6 Jul 2017 15:25:22 +0300 Subject: [PATCH 010/349] Updated jenkins pipeline --- Jenkinsfile | 104 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 68 insertions(+), 36 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a98946c476..59e500aa67 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,6 +16,7 @@ try { node('ubuntu') { stage('Ubuntu Test') { testUbuntu() + testRedHat() } } } @@ -51,44 +52,38 @@ try { } } -def testUbuntu() { - def poolInst - def network_name = "pool_network" - try { - echo 'Ubuntu Test: Checkout csm' - checkout scm +def createPool() { + echo "Ubuntu Test: Create docker network (${network_name}) for nodes pool and test image" + sh "docker network create --subnet=10.0.0.0/8 ${network_name}" - echo "Ubuntu Test: Create docker network (${network_name}) for nodes pool and test image" - sh "docker network create --subnet=10.0.0.0/8 ${network_name}" - - echo 'Ubuntu Test: Build docker image for nodes pool' - def poolEnv = dockerHelpers.build('sovrin_pool', 'ci/sovrin-pool.dockerfile ci') - echo 'Ubuntu Test: Run nodes pool' - poolInst = poolEnv.run("--ip=\"10.0.0.2\" --network=${network_name}") - - echo 'Ubuntu Test: Build docker image' - def testEnv = dockerHelpers.build(name) + echo 'Ubuntu Test: Build docker image for nodes pool' + def poolEnv = dockerHelpers.build('sovrin_pool', 'ci/sovrin-pool.dockerfile ci') + echo 'Ubuntu Test: Run nodes pool' + poolInst = poolEnv.run("--ip=\"10.0.0.2\" --network=${network_name}") +} - testEnv.inside("--ip=\"10.0.0.3\" --network=${network_name}") { - echo 'Ubuntu Test: Test' +def runTests(testEnv){ + testEnv.inside("--ip=\"10.0.0.3\" --network=${network_name}") { + echo 'Ubuntu Test: Test' - sh 'cargo update' + sh 'cargo update' - try { - sh 'RUST_BACKTRACE=1 RUST_TEST_THREADS=1 cargo test' - /* TODO FIXME restore after xunit will be fixed - sh 'RUST_TEST_THREADS=1 cargo test-xunit' - */ - } - finally { - /* TODO FIXME restore after xunit will be fixed - junit 'test-results.xml' - */ - } + try { + sh 'RUST_BACKTRACE=1 RUST_TEST_THREADS=1 cargo test' + /* TODO FIXME restore after xunit will be fixed + sh 'RUST_TEST_THREADS=1 cargo test-xunit' + */ + } + finally { + /* TODO FIXME restore after xunit will be fixed + junit 'test-results.xml' + */ } } - finally { - echo 'Ubuntu Test: Cleanup' +} + +def stopPool(network_name, env){ + echo '${env} Test: Cleanup' try { sh "docker network inspect ${network_name}" } catch (ignore) { @@ -99,15 +94,52 @@ def testUbuntu() { poolInst.stop() } } catch (err) { - echo "Ubuntu Tests: error while stop pool ${err}" + echo "${env} Tests: error while stop pool ${err}" } try { - echo "Ubuntu Test: remove pool network ${network_name}" + echo "{env} Test: remove pool network ${network_name}" sh "docker network rm ${network_name}" } catch (err) { - echo "Ubuntu Test: error while delete ${network_name} - ${err}" + echo "{env} Test: error while delete ${network_name} - ${err}" } - step([$class: 'WsCleanup']) + step([$class: 'WsCleanup']) +} + +def testUbuntu() { + def poolInst + def network_name = "pool_network" + try { + echo 'Ubuntu Test: Checkout csm' + checkout scm + + createPool() + + echo 'Ubuntu Test: Build docker image' + def testEnv = dockerHelpers.build(name, 'ci/ubuntu.dockerfile ci') + + runTests(testEnv) + } + finally { + stopPool(network_name, 'Ubuntu') + } +} + +def testRedHat() { + def poolInst + def network_name = "pool_network" + try { + echo 'RedHat Test: Checkout csm' + checkout scm + + createPool() + + echo 'RedHat Test: Build docker image' + def testEnv = dockerHelpers.build(name, 'ci/amazon.dockerfile ci') + + runTests(testEnv) + } + finally { + stopPool(network_name, 'RedHat') } } From 323919e5d1441e609c5c7af3c97f9fc79454b9ad Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 6 Jul 2017 15:41:07 +0300 Subject: [PATCH 011/349] Deleted zmq dependency in docker file --- Jenkinsfile | 4 ++++ ci/amazon.dockerfile | 9 --------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 59e500aa67..f4253c3a51 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,6 +16,10 @@ try { node('ubuntu') { stage('Ubuntu Test') { testUbuntu() + } + } + node('ubuntu') { + stage('RedHat Test') { testRedHat() } } diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 4bb1de06b2..8b9c5016f8 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -24,15 +24,6 @@ RUN cd /tmp && \ ENV PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib -RUN cd /tmp && \ - wget https://github.com/zeromq/libzmq/releases/download/v4.2.2/zeromq-4.2.2.tar.gz && \ - tar xfz zeromq-4.2.2.tar.gz && rm zeromq-4.2.2.tar.gz && \ - cd /tmp/zeromq-4.2.2 && \ - ./configure && \ - make && \ - make install && \ - rm -rf /tmp/zeromq-4.2.2 - ENV RUST_ARCHIVE=rust-1.16.0-x86_64-unknown-linux-gnu.tar.gz ENV RUST_DOWNLOAD_URL=https://static.rust-lang.org/dist/$RUST_ARCHIVE From db5804d890f86f4ee072b1c65e6901dd884f2e9c Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 6 Jul 2017 17:18:32 +0300 Subject: [PATCH 012/349] changas for parrallel run --- Jenkinsfile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index f4253c3a51..bfb42d02fc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,18 +12,25 @@ try { // 1. TEST stage('Test') { - parallel 'ubuntu-test': { + def tests = [:] + + tests['ubuntu-test'] = { node('ubuntu') { stage('Ubuntu Test') { testUbuntu() } } + } + + tests['redhat-test'] = { node('ubuntu') { stage('RedHat Test') { testRedHat() } } } + + parallel(tests) } if (!publishBranch) { From 198ddc82b0460ba82bc6f28c8bca2d68dfe27d7c Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 6 Jul 2017 17:45:31 +0300 Subject: [PATCH 013/349] Try only RedHat --- Jenkinsfile | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index bfb42d02fc..97c624c5b1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,25 +12,13 @@ try { // 1. TEST stage('Test') { - def tests = [:] - - tests['ubuntu-test'] = { - node('ubuntu') { - stage('Ubuntu Test') { - testUbuntu() - } - } - } - - tests['redhat-test'] = { + parallel 'redhat-test': { node('ubuntu') { stage('RedHat Test') { testRedHat() } } } - - parallel(tests) } if (!publishBranch) { From 0da8334f0455df081ccd56ece06011f6aa14db30 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 7 Jul 2017 10:20:48 +0300 Subject: [PATCH 014/349] Working pipeline --- Jenkinsfile | 150 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 96 insertions(+), 54 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 97c624c5b1..2e0d534b88 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,13 +12,26 @@ try { // 1. TEST stage('Test') { - parallel 'redhat-test': { + + def tests = [:] + + tests['ubuntu-test'] = { + node('ubuntu') { + stage('Ubuntu Test') { + testUbuntu() + } + } + } + + tests['redhat-test'] = { node('ubuntu') { stage('RedHat Test') { testRedHat() } } } + + parallel(tests) } if (!publishBranch) { @@ -51,38 +64,44 @@ try { } } -def createPool() { - echo "Ubuntu Test: Create docker network (${network_name}) for nodes pool and test image" - sh "docker network create --subnet=10.0.0.0/8 ${network_name}" +def testUbuntu() { + def poolInst + def network_name = "pool_network" + try { + echo 'Ubuntu Test: Checkout csm' + checkout scm - echo 'Ubuntu Test: Build docker image for nodes pool' - def poolEnv = dockerHelpers.build('sovrin_pool', 'ci/sovrin-pool.dockerfile ci') - echo 'Ubuntu Test: Run nodes pool' - poolInst = poolEnv.run("--ip=\"10.0.0.2\" --network=${network_name}") -} + echo "Ubuntu Test: Create docker network (${network_name}) for nodes pool and test image" + sh "docker network create --subnet=10.0.0.0/8 ${network_name}" -def runTests(testEnv){ - testEnv.inside("--ip=\"10.0.0.3\" --network=${network_name}") { - echo 'Ubuntu Test: Test' + echo 'Ubuntu Test: Build docker image for nodes pool' + def poolEnv = dockerHelpers.build('sovrin_pool', 'ci/sovrin-pool.dockerfile ci') + echo 'Ubuntu Test: Run nodes pool' + poolInst = poolEnv.run("--ip=\"10.0.0.2\" --network=${network_name}") - sh 'cargo update' + echo 'Ubuntu Test: Build docker image' + def testEnv = dockerHelpers.build(name) - try { - sh 'RUST_BACKTRACE=1 RUST_TEST_THREADS=1 cargo test' - /* TODO FIXME restore after xunit will be fixed - sh 'RUST_TEST_THREADS=1 cargo test-xunit' - */ - } - finally { - /* TODO FIXME restore after xunit will be fixed - junit 'test-results.xml' - */ + testEnv.inside("--ip=\"10.0.0.3\" --network=${network_name}") { + echo 'Ubuntu Test: Test' + + sh 'cargo update' + + try { + sh 'RUST_BACKTRACE=1 RUST_TEST_THREADS=1 cargo test' + /* TODO FIXME restore after xunit will be fixed + sh 'RUST_TEST_THREADS=1 cargo test-xunit' + */ + } + finally { + /* TODO FIXME restore after xunit will be fixed + junit 'test-results.xml' + */ + } } } -} - -def stopPool(network_name, env){ - echo '${env} Test: Cleanup' + finally { + echo 'Ubuntu Test: Cleanup' try { sh "docker network inspect ${network_name}" } catch (ignore) { @@ -93,52 +112,75 @@ def stopPool(network_name, env){ poolInst.stop() } } catch (err) { - echo "${env} Tests: error while stop pool ${err}" + echo "Ubuntu Tests: error while stop pool ${err}" } try { - echo "{env} Test: remove pool network ${network_name}" + echo "Ubuntu Test: remove pool network ${network_name}" sh "docker network rm ${network_name}" } catch (err) { - echo "{env} Test: error while delete ${network_name} - ${err}" + echo "Ubuntu Test: error while delete ${network_name} - ${err}" } - step([$class: 'WsCleanup']) + step([$class: 'WsCleanup']) + } } -def testUbuntu() { +def testRedHat() { def poolInst def network_name = "pool_network" try { - echo 'Ubuntu Test: Checkout csm' + echo 'RedHat Test: Checkout csm' checkout scm - createPool() + echo "RedHat Test: Create docker network (${network_name}) for nodes pool and test image" + sh "docker network create --subnet=10.0.0.0/8 ${network_name}" - echo 'Ubuntu Test: Build docker image' - def testEnv = dockerHelpers.build(name, 'ci/ubuntu.dockerfile ci') + echo 'RedHat Test: Build docker image for nodes pool' + def poolEnv = dockerHelpers.build('sovrin_pool', 'ci/sovrin-pool.dockerfile ci') + echo 'RedHat Test: Run nodes pool' + poolInst = poolEnv.run("--ip=\"10.0.0.2\" --network=${network_name}") - runTests(testEnv) - } - finally { - stopPool(network_name, 'Ubuntu') - } -} - -def testRedHat() { - def poolInst - def network_name = "pool_network" - try { - echo 'RedHat Test: Checkout csm' - checkout scm + echo 'RedHat Test: Build docker image' + def testEnv = dockerHelpers.build(name, 'ci/amazon.dockerfile ci') - createPool() + testEnv.inside("--ip=\"10.0.0.3\" --network=${network_name}") { + echo 'RedHat Test: Test' - echo 'RedHat Test: Build docker image' - def testEnv = dockerHelpers.build(name, 'ci/amazon.dockerfile ci') + sh 'cargo update' - runTests(testEnv) + try { + sh 'RUST_BACKTRACE=1 RUST_TEST_THREADS=1 cargo test' + /* TODO FIXME restore after xunit will be fixed + sh 'RUST_TEST_THREADS=1 cargo test-xunit' + */ + } + finally { + /* TODO FIXME restore after xunit will be fixed + junit 'test-results.xml' + */ + } + } } finally { - stopPool(network_name, 'RedHat') + echo 'RedHat Test: Cleanup' + try { + sh "docker network inspect ${network_name}" + } catch (ignore) { + } + try { + if (poolInst) { + echo 'RedHat Test: stop pool' + poolInst.stop() + } + } catch (err) { + echo "RedHat Tests: error while stop pool ${err}" + } + try { + echo "RedHat Test: remove pool network ${network_name}" + sh "docker network rm ${network_name}" + } catch (err) { + echo "RedHat Test: error while delete ${network_name} - ${err}" + } + step([$class: 'WsCleanup']) } } From 6ddf502050e0c569f780408ac3dc79cb47469bf6 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 7 Jul 2017 12:34:46 +0300 Subject: [PATCH 015/349] Replaced libsovrin --- ci/amazon.dockerfile | 15 ++------- ci/indy-sdk.spec | 73 ++++++++++++++++++++++++++++++++++++++++++++ indy-sdk.spec | 0 3 files changed, 76 insertions(+), 12 deletions(-) create mode 100644 ci/indy-sdk.spec create mode 100644 indy-sdk.spec diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 8b9c5016f8..161e4b4ace 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -4,6 +4,7 @@ ARG uid=1000 RUN \ yum clean all \ + && yum-config-manager --enable epel \ && yum upgrade -y \ && yum groupinstall -y "Development Tools" \ && yum install -y \ @@ -11,18 +12,8 @@ RUN \ cmake \ pkgconfig \ openssl-devel \ - sqlite-devel - -RUN cd /tmp && \ - curl https://download.libsodium.org/libsodium/releases/libsodium-1.0.12.tar.gz | tar -xz && \ - cd /tmp/libsodium-1.0.12 && \ - ./configure && \ - make && \ - make install && \ - rm -rf /tmp/libsodium-1.0.12 - -ENV PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig -ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib + sqlite-devel \ + libsodium-devel ENV RUST_ARCHIVE=rust-1.16.0-x86_64-unknown-linux-gnu.tar.gz ENV RUST_DOWNLOAD_URL=https://static.rust-lang.org/dist/$RUST_ARCHIVE diff --git a/ci/indy-sdk.spec b/ci/indy-sdk.spec new file mode 100644 index 0000000000..4dd4307e00 --- /dev/null +++ b/ci/indy-sdk.spec @@ -0,0 +1,73 @@ +%global commit d79396b8cb51556ea1fda75868893dec482aa326 + +Summary: Official SDK for Hyperledger Indy +Name: indy-sdk +Version: 0.1.1.d79396b8cb51556ea1fda75868893dec482aa326.%{commit} +Release: 1%{?dist} +License: Apache License 2.0 +Group: System Environment/Libraries +Source: https://github.com/hyperledger/indy-sdk/archive/%{commit}.tar.gz +URL: https://github.com/hyperledger/indy-sdk/ +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) +Requires: sqlite openssl libsodium +BuildRequires: sqlite-devel openssl-devel libsodium-devel + +%description +This is the official SDK for Hyperledger Indy, which provides a +distributed-ledger-based foundation for self-sovereign identity. +The major artifact of the SDK is a c-callable library; there are +also convenience wrappers for various programming languages. + +All bugs, stories, and backlog for this project are managed through +Hyperledger's Jira in project IS (note that regular Indy tickets are +in the INDY project instead...). Also, join us on Jira's Rocket.Chat +at #indy-sdk to discuss. + +%package devel +Summary: Development files for Hyperledger Indy +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} + +%description devel +This is the official SDK for Hyperledger Indy, which provides a +distributed-ledger-based foundation for self-sovereign identity. +The major artifact of the SDK is a c-callable library; there are +also convenience wrappers for various programming languages. + +All bugs, stories, and backlog for this project are managed through +Hyperledger's Jira in project IS (note that regular Indy tickets are +in the INDY project instead...). Also, join us on Jira's Rocket.Chat +at #indy-sdk to discuss. + +%prep +%autosetup -n %{name}-%{commit} + +%build +cargo build --release + +%install +rm -rf ${RPM_BUILD_ROOT} + +install -dm0755 $RPM_BUILD_ROOT/%{_includedir}/sovrin +install -dm0755 $RPM_BUILD_ROOT/%{_libdir} +cp -a include/*.h $RPM_BUILD_ROOT/%{_includedir}/sovrin/ +install -Dm0644 target/release/libsovrin.a $RPM_BUILD_ROOT/%{_libdir}/libsovrin.a +install -Dm0644 target/release/libsovrin.so $RPM_BUILD_ROOT/%{_libdir}/libsovrin.so + +%clean +rm -rf ${RPM_BUILD_ROOT} + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + +%files +%defattr(-,root,root) +%{_libdir}/libsovrin.so* + +%files devel +%defattr(-,root,root) +%{_libdir}/libsovrin.a +%{_includedir}/sovrin/*.h + +%changelog diff --git a/indy-sdk.spec b/indy-sdk.spec new file mode 100644 index 0000000000..e69de29bb2 From 2b76d96625b2d99ee0b09b32209f3a1d794e2322 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 7 Jul 2017 15:38:15 +0300 Subject: [PATCH 016/349] Reverted libsodium changes --- ci/amazon.dockerfile | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 161e4b4ace..07f80f4a72 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -12,8 +12,18 @@ RUN \ cmake \ pkgconfig \ openssl-devel \ - sqlite-devel \ - libsodium-devel + sqlite-devel + +RUN cd /tmp && \ + curl https://download.libsodium.org/libsodium/releases/libsodium-1.0.12.tar.gz | tar -xz && \ + cd /tmp/libsodium-1.0.12 && \ + ./configure && \ + make && \ + make install && \ + rm -rf /tmp/libsodium-1.0.12 + +ENV PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig +ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib ENV RUST_ARCHIVE=rust-1.16.0-x86_64-unknown-linux-gnu.tar.gz ENV RUST_DOWNLOAD_URL=https://static.rust-lang.org/dist/$RUST_ARCHIVE From 4646495cd4b41dd2fc7ccf7efe8240fc448ed40e Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 7 Jul 2017 16:25:56 +0300 Subject: [PATCH 017/349] Corrected amazon dockerfile --- ci/amazon.dockerfile | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 07f80f4a72..c859e7c721 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -4,7 +4,6 @@ ARG uid=1000 RUN \ yum clean all \ - && yum-config-manager --enable epel \ && yum upgrade -y \ && yum groupinstall -y "Development Tools" \ && yum install -y \ @@ -14,16 +13,10 @@ RUN \ openssl-devel \ sqlite-devel -RUN cd /tmp && \ - curl https://download.libsodium.org/libsodium/releases/libsodium-1.0.12.tar.gz | tar -xz && \ - cd /tmp/libsodium-1.0.12 && \ - ./configure && \ - make && \ - make install && \ - rm -rf /tmp/libsodium-1.0.12 - -ENV PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig -ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib +RUN \ + wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \ + && rpm -Uvh epel-release-latest-7*.rpm \ + && yum install -y libsodium-devel ENV RUST_ARCHIVE=rust-1.16.0-x86_64-unknown-linux-gnu.tar.gz ENV RUST_DOWNLOAD_URL=https://static.rust-lang.org/dist/$RUST_ARCHIVE From e65251f62e9ad778c6c2e35089bc89980f00c3ad Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 7 Jul 2017 16:51:52 +0300 Subject: [PATCH 018/349] Corrected docker file --- ci/amazon.dockerfile | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index c859e7c721..a1a75d103d 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -6,17 +6,15 @@ RUN \ yum clean all \ && yum upgrade -y \ && yum groupinstall -y "Development Tools" \ + && yum install -y epel-release \ + && yum-config-manager --enable epel \ && yum install -y \ wget \ cmake \ pkgconfig \ openssl-devel \ - sqlite-devel - -RUN \ - wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \ - && rpm -Uvh epel-release-latest-7*.rpm \ - && yum install -y libsodium-devel + sqlite-devel \ + libsodium-devel ENV RUST_ARCHIVE=rust-1.16.0-x86_64-unknown-linux-gnu.tar.gz ENV RUST_DOWNLOAD_URL=https://static.rust-lang.org/dist/$RUST_ARCHIVE From c6dc7af780f3188544037ccb7b864c8a99264ed6 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 7 Jul 2017 18:24:21 +0300 Subject: [PATCH 019/349] test upload rpm script --- ci/upload-rpm.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 ci/upload-rpm.sh diff --git a/ci/upload-rpm.sh b/ci/upload-rpm.sh new file mode 100644 index 0000000000..af903adaa8 --- /dev/null +++ b/ci/upload-rpm.sh @@ -0,0 +1,20 @@ +#!/bin/bash -x + +if [ "$1" = "--help" ] ; then + echo "Usage: $0 " +fi + +key="$1" + +echo "Uploading...." + +cat < Date: Fri, 7 Jul 2017 18:44:20 +0300 Subject: [PATCH 020/349] debug script --- ci/rpm-build.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index c98dc2f8f4..fd48b7262f 100755 --- a/ci/rpm-build.sh +++ b/ci/rpm-build.sh @@ -1,15 +1,22 @@ #!/bin/bash commit=$1 -version=$(wget -q https://raw.githubusercontent.com/hyperledger/indy-sdk/$commit/Cargo.toml -O - | grep -E '^version =' | head -n1 | cut -f2 -d= | tr -d '" ') +echo commit +echo 000 +version=$(wget -q https://raw.githubusercontent.com/hyperledger/indy-sdk/$commit/Cargo.toml -O - | grep -E '^version =' | head -n1 | cut -f2 -d= | tr -d '" ') +echo 111 [ -z $version ] && exit 1 [ -z $commit ] && exit 2 - +echo 222 sed \ -e "s|@commit@|$commit|g" \ -e "s|@version@|$version.$commit|g" \ indy-sdk.spec.in >indy-sdk.spec - +echo 333 spectool -g -R indy-sdk.spec || exit 3 + +echo 444 rpmbuild -ba indy-sdk.spec || exit 4 + +555 From 8b4bfce74f10c94cd8b59c236066f3073f936dc1 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 7 Jul 2017 19:35:01 +0300 Subject: [PATCH 021/349] added test --- tests/anoncreds.rs | 140 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index fbdb0750ac..a56878c036 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -1305,6 +1305,146 @@ mod medium_cases { mod demos { use super::*; + use std::process::Command; + use std::io::prelude::*; + use std::net::TcpStream; + use std::{thread, time}; + + #[test] + fn interoperability_test_pysovrin_is_issuer() { + + TestUtils::cleanup_storage(); + + let pool_name = "pool1"; + let issuer_wallet_name = "issuer_wallet"; + let prover_wallet_name = "prover_wallet"; + let xtype = "default"; + + //1. Create Issuer wallet, get wallet handle + let issuer_wallet_handle = WalletUtils::create_and_open_wallet(pool_name, issuer_wallet_name, xtype).unwrap(); + + //2. Create Prover wallet, get wallet handle + let prover_wallet_handle = WalletUtils::create_and_open_wallet(pool_name, prover_wallet_name, xtype).unwrap(); + + //3. Issuer create claim definition + let schema_seq_no = 1; + let schema = AnoncredsUtils::get_gvt_schema_json(schema_seq_no); + + let claim_def_json = AnoncredsUtils::issuer_create_claim_definition(issuer_wallet_handle, &ISSUER_DID, &schema, None, false).unwrap(); + + //4. Prover create Master Secret + let master_secret_name = "prover_master_secret"; + + AnoncredsUtils::prover_create_master_secret(prover_wallet_handle, master_secret_name).unwrap(); + + //5. Prover store Claim Offer received from Issuer + let claim_offer_json = AnoncredsUtils::get_claim_offer(ISSUER_DID, schema_seq_no); + + AnoncredsUtils::prover_store_claim_offer(prover_wallet_handle, &claim_offer_json).unwrap(); + + //6. Prover get Claim Offers + let filter_json = format!(r#"{{"issuer_did":"{}"}}"#, ISSUER_DID); + + let claim_offers_json = AnoncredsUtils::prover_get_claim_offers(prover_wallet_handle, &filter_json).unwrap(); + + let claim_offers: Vec = serde_json::from_str(&claim_offers_json).unwrap(); + assert!(claim_offers.len() == 1); + let claim_offer_json = serde_json::to_string(&claim_offers[0]).unwrap(); + + //7. Prover create Claim Request + let prover_did = "BzfFCYk"; + let claim_req = AnoncredsUtils::prover_create_and_store_claim_req(prover_wallet_handle, + prover_did, + &claim_offer_json, + &claim_def_json, + master_secret_name).unwrap(); + + + let mut command = Command::new("python3") + .arg("../anoncreds-fork/anoncreds/test/test_interoperability_with_libsovrin.py") + .spawn().expect("failed to execute process"); + thread::sleep(time::Duration::from_millis(3000)); +// let answer = String::from_utf8(command.stdout).unwrap(); +// let expected_answer = "Executed\n"; +// assert!(command.stdout.status.success()); +// assert!(answer == expected_answer); + if let Ok(mut stream) = TcpStream::connect("127.0.0.1:1234") { + println!("Connected to the server!"); + stream.write(format!(r#"{{"type":"issue", "data": {}}}"#, claim_req).as_bytes()); + let mut buf = vec![0; 10240]; + stream.read(&mut buf).unwrap(); + buf.retain(|&element| element != 0); + let answer = String::from_utf8(buf).unwrap(); + println!("answer: {:?}", answer); + stream.write(r#"{"type":"close"}"#.as_bytes()); + + + + + // 9. Prover store received Claim + AnoncredsUtils::prover_store_claim(prover_wallet_handle, &answer).unwrap(); + + // 10. Prover gets Claims for Proof Request + let proof_req_json = format!(r#"{{ + "nonce":"123432421212", + "name":"proof_req_1", + "version":"0.1", + "requested_attrs":{{"attr1_uuid":{{"schema_seq_no":{},"name":"name"}}, + "attr2_uuid":{{"schema_seq_no":{},"name":"sex"}}}}, + "requested_predicates":{{"predicate1_uuid":{{"attr_name":"age","p_type":"GE","value":18}}}} + }}"#, schema_seq_no, schema_seq_no); + + let claims_json = AnoncredsUtils::prover_get_claims_for_proof_req(prover_wallet_handle, &proof_req_json).unwrap(); + let claims: ProofClaimsJson = serde_json::from_str(&claims_json).unwrap(); + info!("claims_json: {}", &claims_json); + let claims_for_attr_1 = claims.attrs.get("attr1_uuid").unwrap(); + assert_eq!(1, claims_for_attr_1.len()); + let claim = claims_for_attr_1[0].clone(); + + // 11. Prover create Proof + let self_attested_value = "value"; + let requested_claims_json = format!(r#"{{ + "self_attested_attributes":{{"self1":"{}"}}, + "requested_attrs":{{"attr1_uuid":["{}",true], + "attr2_uuid":["{}", false]}}, + "requested_predicates":{{"predicate1_uuid":"{}"}} + }}"#, self_attested_value, claim.claim_uuid, claim.claim_uuid, claim.claim_uuid); + + let schemas_json = format!(r#"{{"{}":{}}}"#, claim.claim_uuid, schema); + let claim_defs_json = format!(r#"{{"{}":{}}}"#, claim.claim_uuid, claim_def_json); + let revoc_regs_jsons = "{}"; + + let proof_json = AnoncredsUtils::prover_create_proof(prover_wallet_handle, + &proof_req_json, + &requested_claims_json, + &schemas_json, + &master_secret_name, + &claim_defs_json, + &revoc_regs_jsons).unwrap(); + + let proof: ProofJson = serde_json::from_str(&proof_json).unwrap(); + + let &(_, ref value, _) = proof.requested_proof.revealed_attrs.get("attr1_uuid").unwrap(); + assert_eq!(value, "Alex"); + + proof.requested_proof.unrevealed_attrs.get("attr2_uuid").unwrap(); + + let value = proof.requested_proof.self_attested_attrs.get("self1").unwrap(); + assert_eq!(value, self_attested_value); + + // 12. Verifier verify proof + let valid = AnoncredsUtils::verifier_verify_proof(&proof_req_json, + &proof_json, + &schemas_json, + &claim_defs_json, + &revoc_regs_jsons).unwrap(); + assert!(valid); + + TestUtils::cleanup_storage(); + } else { + println!("Couldn't connect to server..."); + } + } #[test] fn verifier_verify_proof_works_for_proof_does_not_correspond_proof_request() { From 335761dba8fc568b2417703f8cf7160d217ab2c8 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Sun, 9 Jul 2017 11:17:04 +0300 Subject: [PATCH 022/349] Corected dokerfile --- ci/amazon.dockerfile | 5 +++-- ci/rpm-build.sh | 13 ++++++------- ci/upload-rpm.sh | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index a1a75d103d..652caf460a 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -14,7 +14,8 @@ RUN \ pkgconfig \ openssl-devel \ sqlite-devel \ - libsodium-devel + libsodium-devel \ + spectool ENV RUST_ARCHIVE=rust-1.16.0-x86_64-unknown-linux-gnu.tar.gz ENV RUST_DOWNLOAD_URL=https://static.rust-lang.org/dist/$RUST_ARCHIVE @@ -33,4 +34,4 @@ ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.ca RUN useradd -ms /bin/bash -u $uid sovrin USER sovrin -WORKDIR /home/sovrin +WORKDIR /home/sovrin \ No newline at end of file diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index fd48b7262f..51ea8d1b24 100755 --- a/ci/rpm-build.sh +++ b/ci/rpm-build.sh @@ -3,20 +3,19 @@ commit=$1 echo commit -echo 000 version=$(wget -q https://raw.githubusercontent.com/hyperledger/indy-sdk/$commit/Cargo.toml -O - | grep -E '^version =' | head -n1 | cut -f2 -d= | tr -d '" ') -echo 111 [ -z $version ] && exit 1 [ -z $commit ] && exit 2 -echo 222 + +mkdir -p /usr/src/rpm/SOURCES/ + +cd ci + sed \ -e "s|@commit@|$commit|g" \ -e "s|@version@|$version.$commit|g" \ indy-sdk.spec.in >indy-sdk.spec -echo 333 + spectool -g -R indy-sdk.spec || exit 3 -echo 444 rpmbuild -ba indy-sdk.spec || exit 4 - -555 diff --git a/ci/upload-rpm.sh b/ci/upload-rpm.sh index af903adaa8..5c13ef6e9b 100644 --- a/ci/upload-rpm.sh +++ b/ci/upload-rpm.sh @@ -15,6 +15,6 @@ rmdir /var/repository/repos/rpm mkdir /var/repository/repos/rpm/ cd /var/repository/repos/rpm/ put $WORK_DIR/$POD_FILE_NAME -put -r -r /usr/src/rpm/ +put -r /usr/src/rpm/ ls -l /var/repository/repos/rpm/ EOF \ No newline at end of file From 27d3553156fdeca2cbc37228cc0e05f965e53093 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Sun, 9 Jul 2017 11:31:08 +0300 Subject: [PATCH 023/349] debug build script --- ci/rpm-build.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index 51ea8d1b24..cc111a9954 100755 --- a/ci/rpm-build.sh +++ b/ci/rpm-build.sh @@ -4,18 +4,23 @@ commit=$1 echo commit version=$(wget -q https://raw.githubusercontent.com/hyperledger/indy-sdk/$commit/Cargo.toml -O - | grep -E '^version =' | head -n1 | cut -f2 -d= | tr -d '" ') +echo 000 [ -z $version ] && exit 1 +echo 111 [ -z $commit ] && exit 2 - +echo 222 mkdir -p /usr/src/rpm/SOURCES/ - +echo 333 cd ci +echo 444 + sed \ -e "s|@commit@|$commit|g" \ -e "s|@version@|$version.$commit|g" \ indy-sdk.spec.in >indy-sdk.spec - +echo 555 spectool -g -R indy-sdk.spec || exit 3 - +echo 666 rpmbuild -ba indy-sdk.spec || exit 4 +echo 777 \ No newline at end of file From 3b4bbd5a11a1ac3bf3597daeee23306000d83a5c Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Sun, 9 Jul 2017 11:44:49 +0300 Subject: [PATCH 024/349] Debug build script --- ci/rpm-build.sh | 4 +++- ci/upload-rpm.sh | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index cc111a9954..2c7303e981 100755 --- a/ci/rpm-build.sh +++ b/ci/rpm-build.sh @@ -2,9 +2,11 @@ commit=$1 -echo commit +echo $commit version=$(wget -q https://raw.githubusercontent.com/hyperledger/indy-sdk/$commit/Cargo.toml -O - | grep -E '^version =' | head -n1 | cut -f2 -d= | tr -d '" ') echo 000 +echo $version + [ -z $version ] && exit 1 echo 111 [ -z $commit ] && exit 2 diff --git a/ci/upload-rpm.sh b/ci/upload-rpm.sh index 5c13ef6e9b..3a2b19a366 100644 --- a/ci/upload-rpm.sh +++ b/ci/upload-rpm.sh @@ -14,7 +14,6 @@ rm /var/repository/repos/rpm/* rmdir /var/repository/repos/rpm mkdir /var/repository/repos/rpm/ cd /var/repository/repos/rpm/ -put $WORK_DIR/$POD_FILE_NAME put -r /usr/src/rpm/ ls -l /var/repository/repos/rpm/ EOF \ No newline at end of file From 9a1d8cd4e2b8689f816eda79970793426ff44739 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Sun, 9 Jul 2017 21:52:31 +0300 Subject: [PATCH 025/349] test with harcoded commit --- ci/rpm-build.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index 2c7303e981..bf87b22e96 100755 --- a/ci/rpm-build.sh +++ b/ci/rpm-build.sh @@ -1,14 +1,12 @@ #!/bin/bash -commit=$1 +commit='3b4bbd5a11a1ac3bf3597daeee23306000d83a5c' echo $commit version=$(wget -q https://raw.githubusercontent.com/hyperledger/indy-sdk/$commit/Cargo.toml -O - | grep -E '^version =' | head -n1 | cut -f2 -d= | tr -d '" ') -echo 000 echo $version [ -z $version ] && exit 1 -echo 111 [ -z $commit ] && exit 2 echo 222 mkdir -p /usr/src/rpm/SOURCES/ From 0fb82cc947f78a7572df6c3a353bf725347e3291 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Sun, 9 Jul 2017 21:57:57 +0300 Subject: [PATCH 026/349] Updated dokerfile --- ci/amazon.dockerfile | 2 ++ ci/rpm-build.sh | 6 +----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 652caf460a..409ca43508 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -31,6 +31,8 @@ RUN curl -fsOSL $RUST_DOWNLOAD_URL \ ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin" +RUN mkdir -p /usr/src/rpm/SOURCES/ + RUN useradd -ms /bin/bash -u $uid sovrin USER sovrin diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index bf87b22e96..5fea5648a9 100755 --- a/ci/rpm-build.sh +++ b/ci/rpm-build.sh @@ -8,12 +8,8 @@ echo $version [ -z $version ] && exit 1 [ -z $commit ] && exit 2 -echo 222 -mkdir -p /usr/src/rpm/SOURCES/ -echo 333 -cd ci -echo 444 +cd ci sed \ -e "s|@commit@|$commit|g" \ From 7360a6010de03de32639656ca77b163d0ca3fcfc Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Sun, 9 Jul 2017 22:02:28 +0300 Subject: [PATCH 027/349] updated dokerfile --- ci/amazon.dockerfile | 2 +- ci/rpm-build.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 409ca43508..5184ce1960 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -1,6 +1,7 @@ FROM amazonlinux:2017.03 ARG uid=1000 +RUN mkdir -p /usr/src/rpm/SOURCES/ RUN \ yum clean all \ @@ -31,7 +32,6 @@ RUN curl -fsOSL $RUST_DOWNLOAD_URL \ ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin" -RUN mkdir -p /usr/src/rpm/SOURCES/ RUN useradd -ms /bin/bash -u $uid sovrin USER sovrin diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index 5fea5648a9..b767091700 100755 --- a/ci/rpm-build.sh +++ b/ci/rpm-build.sh @@ -15,7 +15,7 @@ sed \ -e "s|@commit@|$commit|g" \ -e "s|@version@|$version.$commit|g" \ indy-sdk.spec.in >indy-sdk.spec -echo 555 + spectool -g -R indy-sdk.spec || exit 3 echo 666 rpmbuild -ba indy-sdk.spec || exit 4 From 5b8ee0f349b992ac1ca1698725eac92cdb9a8538 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Sun, 9 Jul 2017 22:32:00 +0300 Subject: [PATCH 028/349] try move command --- ci/amazon.dockerfile | 2 -- ci/rpm-build.sh | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 5184ce1960..652caf460a 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -1,7 +1,6 @@ FROM amazonlinux:2017.03 ARG uid=1000 -RUN mkdir -p /usr/src/rpm/SOURCES/ RUN \ yum clean all \ @@ -32,7 +31,6 @@ RUN curl -fsOSL $RUST_DOWNLOAD_URL \ ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin" - RUN useradd -ms /bin/bash -u $uid sovrin USER sovrin diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index b767091700..21ea7ac5e8 100755 --- a/ci/rpm-build.sh +++ b/ci/rpm-build.sh @@ -2,6 +2,8 @@ commit='3b4bbd5a11a1ac3bf3597daeee23306000d83a5c' +mkdir -p /usr/src/rpm/SOURCES/ + echo $commit version=$(wget -q https://raw.githubusercontent.com/hyperledger/indy-sdk/$commit/Cargo.toml -O - | grep -E '^version =' | head -n1 | cut -f2 -d= | tr -d '" ') echo $version From f5946c173294699b8a472a303091cfcc7a1ac022 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Sun, 9 Jul 2017 22:48:28 +0300 Subject: [PATCH 029/349] show user --- ci/rpm-build.sh | Bin 543 -> 557 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index 21ea7ac5e8eb2c0e60d489f02263df6d82ab2432..58744e97f032da93d017c7767c0425104ea625cc 100755 GIT binary patch delta 26 ccmbQwvX*5-C?j8aMt)*$CIb{q4rM$A0AscWp#T5? delta 11 ScmZ3>GM{BbDC6X0#!~ Date: Sun, 9 Jul 2017 23:04:38 +0300 Subject: [PATCH 030/349] corrected user creation --- ci/amazon.dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 652caf460a..225c3a1d31 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -31,7 +31,7 @@ RUN curl -fsOSL $RUST_DOWNLOAD_URL \ ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin" -RUN useradd -ms /bin/bash -u $uid sovrin +RUN useradd -g 0 sovrin USER sovrin WORKDIR /home/sovrin \ No newline at end of file From 95d407a6013ed928032e473e92267a1f81e7a7ba Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Sun, 9 Jul 2017 23:10:17 +0300 Subject: [PATCH 031/349] test --- ci/amazon.dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 225c3a1d31..304fce6dc2 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -31,7 +31,7 @@ RUN curl -fsOSL $RUST_DOWNLOAD_URL \ ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin" -RUN useradd -g 0 sovrin +RUN useradd -g 0 -u $uid sovrin USER sovrin WORKDIR /home/sovrin \ No newline at end of file From 3401b3f0c03e7bd2c85841d193e3b017ba7558a9 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 10 Jul 2017 07:47:04 +0300 Subject: [PATCH 032/349] try run script from root user --- ci/amazon.dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 304fce6dc2..a81a05f40c 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -31,7 +31,4 @@ RUN curl -fsOSL $RUST_DOWNLOAD_URL \ ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin" -RUN useradd -g 0 -u $uid sovrin -USER sovrin - WORKDIR /home/sovrin \ No newline at end of file From 45b5cb19bacf6dfdcc3c179d01fa279baa3ff429 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 10 Jul 2017 07:49:19 +0300 Subject: [PATCH 033/349] try --- ci/amazon.dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index a81a05f40c..304fce6dc2 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -31,4 +31,7 @@ RUN curl -fsOSL $RUST_DOWNLOAD_URL \ ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin" +RUN useradd -g 0 -u $uid sovrin +USER sovrin + WORKDIR /home/sovrin \ No newline at end of file From 8ace58b11e281242e44f7d75c818e62629111a19 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 10 Jul 2017 08:00:21 +0300 Subject: [PATCH 034/349] try --- ci/amazon.dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 304fce6dc2..9945b77067 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -1,6 +1,6 @@ FROM amazonlinux:2017.03 -ARG uid=1000 +ARG uid=0 RUN \ yum clean all \ @@ -31,7 +31,8 @@ RUN curl -fsOSL $RUST_DOWNLOAD_URL \ ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin" -RUN useradd -g 0 -u $uid sovrin +RUN useradd -m -G root -u $uid sovrin +RUN groups sovrin USER sovrin WORKDIR /home/sovrin \ No newline at end of file From 3a8700d9c346540d1a26d046ab66f934b76c0b14 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 10 Jul 2017 08:28:32 +0300 Subject: [PATCH 035/349] update --- ci/amazon.dockerfile | 2 +- ci/rpm-build.sh | Bin 557 -> 572 bytes 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 9945b77067..4a038ca97e 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -1,6 +1,6 @@ FROM amazonlinux:2017.03 -ARG uid=0 +ARG uid=1000 RUN \ yum clean all \ diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index 58744e97f032da93d017c7767c0425104ea625cc..d524afbe7119b274a38a326e7aacccc646274537 100755 GIT binary patch delta 25 gcmZ3>vWI1Y17C7RZhne_xv8mwera*hM*DY+0ByYpqyPW_ delta 10 RcmdnPvX*6n!$$wNi~tul1TX*q From 4298d35a2a4eb71053e1ed875f547bb408d6b40c Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 10 Jul 2017 08:31:11 +0300 Subject: [PATCH 036/349] try --- ci/rpm-build.sh | Bin 572 -> 525 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index d524afbe7119b274a38a326e7aacccc646274537..2e512fe2da9ff332265495ce60d018dedba1a9d5 100755 GIT binary patch delta 10 RcmdnP(#tZzVPpPTMgSI81P}lK delta 56 zcmeBW*~2oyK{q)gH$O$e+|*P-zqGiBD>pkOvq(X=0L;@bE=txfD#+Cj_74qmb`93w IXm_3w00+eqfdBvi From 6392847257922dc70f47f5d53cf84a5d18156bff Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 10 Jul 2017 08:47:41 +0300 Subject: [PATCH 037/349] try --- ci/amazon.dockerfile | 3 +-- ci/rpm-build.sh | Bin 525 -> 557 bytes 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 4a038ca97e..bddd9cd140 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -31,8 +31,7 @@ RUN curl -fsOSL $RUST_DOWNLOAD_URL \ ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin" -RUN useradd -m -G root -u $uid sovrin -RUN groups sovrin +RUN useradd -m -G root -g 0 -u $uid sovrin USER sovrin WORKDIR /home/sovrin \ No newline at end of file diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index 2e512fe2da9ff332265495ce60d018dedba1a9d5..58744e97f032da93d017c7767c0425104ea625cc 100755 GIT binary patch delta 41 wcmeBWS<5oPK`u8tC9_CDw?IL^w75vWxF}h_s32EA*grJL*)>>yquqH%03k~a(#tZzVPnEsMgSF)1M&a> From 7b7f7a0b1646473e24c36784accd6c9c495b71ab Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 10 Jul 2017 08:55:10 +0300 Subject: [PATCH 038/349] try --- ci/amazon.dockerfile | 2 +- ci/rpm-build.sh | Bin 557 -> 543 bytes 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index bddd9cd140..454b8b71c7 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -31,7 +31,7 @@ RUN curl -fsOSL $RUST_DOWNLOAD_URL \ ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin" -RUN useradd -m -G root -g 0 -u $uid sovrin +RUN useradd -m -G root -g 0 -u 1001 sovrin USER sovrin WORKDIR /home/sovrin \ No newline at end of file diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index 58744e97f032da93d017c7767c0425104ea625cc..21ea7ac5e8eb2c0e60d489f02263df6d82ab2432 100755 GIT binary patch delta 11 ScmZ3>GM{BbDC6X0#!~ Date: Mon, 10 Jul 2017 09:19:58 +0300 Subject: [PATCH 039/349] try --- ci/amazon.dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 454b8b71c7..b271876e2e 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -31,7 +31,7 @@ RUN curl -fsOSL $RUST_DOWNLOAD_URL \ ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin" -RUN useradd -m -G root -g 0 -u 1001 sovrin +RUN useradd -r -m -g 0 sovrin USER sovrin WORKDIR /home/sovrin \ No newline at end of file From fe75f137527fa9201a14dcfa64222d59ccd3435e Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 10 Jul 2017 10:30:38 +0300 Subject: [PATCH 040/349] try --- ci/amazon.dockerfile | 2 +- ci/rpm-build.sh | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index b271876e2e..902a9161b1 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -31,7 +31,7 @@ RUN curl -fsOSL $RUST_DOWNLOAD_URL \ ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin" -RUN useradd -r -m -g 0 sovrin +RUN useradd -ms /bin/bash -g 0 -u $uid sovrin USER sovrin WORKDIR /home/sovrin \ No newline at end of file diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index 21ea7ac5e8..a176c73c9e 100755 --- a/ci/rpm-build.sh +++ b/ci/rpm-build.sh @@ -19,6 +19,4 @@ sed \ indy-sdk.spec.in >indy-sdk.spec spectool -g -R indy-sdk.spec || exit 3 -echo 666 -rpmbuild -ba indy-sdk.spec || exit 4 -echo 777 \ No newline at end of file +rpmbuild -ba indy-sdk.spec || exit 4 \ No newline at end of file From 800e15f856855759d2843f766b37c69b1d889e37 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 10 Jul 2017 11:26:47 +0300 Subject: [PATCH 041/349] try --- ci/indy-sdk.spec.in | 2 +- ci/rpm-build.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/indy-sdk.spec.in b/ci/indy-sdk.spec.in index b3dc7a0887..6bf7a2ef47 100644 --- a/ci/indy-sdk.spec.in +++ b/ci/indy-sdk.spec.in @@ -8,7 +8,7 @@ License: Apache License 2.0 Group: System Environment/Libraries Source: https://github.com/hyperledger/indy-sdk/archive/%{commit}.tar.gz URL: https://github.com/hyperledger/indy-sdk/ -BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) +BuildRoot: /home/sovrin/rpm/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) Requires: sqlite openssl libsodium BuildRequires: sqlite-devel openssl-devel libsodium-devel diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index a176c73c9e..7e9e411dca 100755 --- a/ci/rpm-build.sh +++ b/ci/rpm-build.sh @@ -2,7 +2,7 @@ commit='3b4bbd5a11a1ac3bf3597daeee23306000d83a5c' -mkdir -p /usr/src/rpm/SOURCES/ +mkdir -p /rpm echo $commit version=$(wget -q https://raw.githubusercontent.com/hyperledger/indy-sdk/$commit/Cargo.toml -O - | grep -E '^version =' | head -n1 | cut -f2 -d= | tr -d '" ') From 880ede8514e14ceba497eda52cffc902d5e8c30f Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 10 Jul 2017 11:49:14 +0300 Subject: [PATCH 042/349] try root --- ci/amazon.dockerfile | 3 --- ci/indy-sdk.spec.in | 2 +- ci/rpm-build.sh | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 902a9161b1..a81a05f40c 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -31,7 +31,4 @@ RUN curl -fsOSL $RUST_DOWNLOAD_URL \ ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin" -RUN useradd -ms /bin/bash -g 0 -u $uid sovrin -USER sovrin - WORKDIR /home/sovrin \ No newline at end of file diff --git a/ci/indy-sdk.spec.in b/ci/indy-sdk.spec.in index 6bf7a2ef47..b3dc7a0887 100644 --- a/ci/indy-sdk.spec.in +++ b/ci/indy-sdk.spec.in @@ -8,7 +8,7 @@ License: Apache License 2.0 Group: System Environment/Libraries Source: https://github.com/hyperledger/indy-sdk/archive/%{commit}.tar.gz URL: https://github.com/hyperledger/indy-sdk/ -BuildRoot: /home/sovrin/rpm/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) Requires: sqlite openssl libsodium BuildRequires: sqlite-devel openssl-devel libsodium-devel diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index 7e9e411dca..a176c73c9e 100755 --- a/ci/rpm-build.sh +++ b/ci/rpm-build.sh @@ -2,7 +2,7 @@ commit='3b4bbd5a11a1ac3bf3597daeee23306000d83a5c' -mkdir -p /rpm +mkdir -p /usr/src/rpm/SOURCES/ echo $commit version=$(wget -q https://raw.githubusercontent.com/hyperledger/indy-sdk/$commit/Cargo.toml -O - | grep -E '^version =' | head -n1 | cut -f2 -d= | tr -d '" ') From 5f2601d85564661844c42bd11fb701413e6adb25 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 10 Jul 2017 14:27:25 +0300 Subject: [PATCH 043/349] try --- ci/upload-rpm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/upload-rpm.sh b/ci/upload-rpm.sh index 3a2b19a366..37890a15bb 100644 --- a/ci/upload-rpm.sh +++ b/ci/upload-rpm.sh @@ -8,7 +8,7 @@ key="$1" echo "Uploading...." -cat < Date: Mon, 10 Jul 2017 14:45:57 +0300 Subject: [PATCH 044/349] try upload file --- ci/upload-rpm.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/ci/upload-rpm.sh b/ci/upload-rpm.sh index 37890a15bb..624f96f335 100644 --- a/ci/upload-rpm.sh +++ b/ci/upload-rpm.sh @@ -8,12 +8,6 @@ key="$1" echo "Uploading...." -cat < Date: Mon, 10 Jul 2017 14:49:13 +0300 Subject: [PATCH 045/349] try --- ci/upload-rpm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/upload-rpm.sh b/ci/upload-rpm.sh index 624f96f335..a3a632432b 100644 --- a/ci/upload-rpm.sh +++ b/ci/upload-rpm.sh @@ -8,6 +8,6 @@ key="$1" echo "Uploading...." -cat < Date: Mon, 10 Jul 2017 14:54:38 +0300 Subject: [PATCH 046/349] try --- ci/upload-rpm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/upload-rpm.sh b/ci/upload-rpm.sh index a3a632432b..0be1266ee7 100644 --- a/ci/upload-rpm.sh +++ b/ci/upload-rpm.sh @@ -8,6 +8,6 @@ key="$1" echo "Uploading...." -cat < Date: Mon, 10 Jul 2017 15:22:28 +0300 Subject: [PATCH 047/349] added claims --- tests/anoncreds.rs | 12 +++++++++++- tests/utils/types.rs | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index a56878c036..2b1d21ad6e 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -1377,12 +1377,22 @@ mod demos { let answer = String::from_utf8(buf).unwrap(); println!("answer: {:?}", answer); stream.write(r#"{"type":"close"}"#.as_bytes()); + let mut new_answer: ClaimJson = serde_json::from_str(&answer).unwrap(); + new_answer.schema_seq_no = Some(schema_seq_no); + new_answer.issuer_did = Some(ISSUER_DID.to_string()); + println!("new_answer: {:?}", &serde_json::to_string(&new_answer).unwrap()); + //5. Issuer create Claim + let claim_json = AnoncredsUtils::get_gvt_claim_json(); + let (_, xclaim_json) = AnoncredsUtils::issuer_create_claim(issuer_wallet_handle, + &claim_req, + &claim_json).unwrap(); + println!("xclaim_json: {:?}", xclaim_json); // 9. Prover store received Claim - AnoncredsUtils::prover_store_claim(prover_wallet_handle, &answer).unwrap(); + AnoncredsUtils::prover_store_claim(prover_wallet_handle, &serde_json::to_string(&new_answer).unwrap()).unwrap(); // 10. Prover gets Claims for Proof Request let proof_req_json = format!(r#"{{ diff --git a/tests/utils/types.rs b/tests/utils/types.rs index 9e3ea7be4f..99dcb342a7 100644 --- a/tests/utils/types.rs +++ b/tests/utils/types.rs @@ -167,9 +167,9 @@ pub struct ClaimRequest { pub struct ClaimJson { pub claim: HashMap>, pub revoc_reg_seq_no: Option, - pub schema_seq_no: i32, + pub schema_seq_no: Option, pub signature: ClaimSignature, - pub issuer_did: String + pub issuer_did: Option } #[derive(Debug, Deserialize, Serialize)] From bbb556f6ffea50b2de9bca1f1ff219706979fcf5 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 10 Jul 2017 15:30:02 +0300 Subject: [PATCH 048/349] try --- ci/upload-rpm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/upload-rpm.sh b/ci/upload-rpm.sh index 0be1266ee7..dd12126835 100644 --- a/ci/upload-rpm.sh +++ b/ci/upload-rpm.sh @@ -8,6 +8,6 @@ key="$1" echo "Uploading...." -cat < Date: Mon, 10 Jul 2017 15:32:28 +0300 Subject: [PATCH 049/349] try --- ci/upload-rpm.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ci/upload-rpm.sh b/ci/upload-rpm.sh index dd12126835..ea4c85930f 100644 --- a/ci/upload-rpm.sh +++ b/ci/upload-rpm.sh @@ -10,4 +10,9 @@ echo "Uploading...." cat < Date: Mon, 10 Jul 2017 15:34:29 +0300 Subject: [PATCH 050/349] try --- ci/upload-rpm.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/upload-rpm.sh b/ci/upload-rpm.sh index ea4c85930f..35b60b11b8 100644 --- a/ci/upload-rpm.sh +++ b/ci/upload-rpm.sh @@ -14,5 +14,6 @@ rm /var/repository/repos/rpm/* rmdir /var/repository/repos/rpm mkdir /var/repository/repos/rpm/ cd /var/repository/repos/rpm/ +put -r /usr/src/rpm/ ls -l /var/repository/repos/rpm/ EOF \ No newline at end of file From 115a7931aada2a9d671bd7a32beb6cf1651ac4f4 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 10 Jul 2017 15:56:08 +0300 Subject: [PATCH 051/349] try --- ci/upload-rpm.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/upload-rpm.sh b/ci/upload-rpm.sh index 35b60b11b8..b5b714b1ad 100644 --- a/ci/upload-rpm.sh +++ b/ci/upload-rpm.sh @@ -14,6 +14,7 @@ rm /var/repository/repos/rpm/* rmdir /var/repository/repos/rpm mkdir /var/repository/repos/rpm/ cd /var/repository/repos/rpm/ -put -r /usr/src/rpm/ +put -r /usr/src/rpm/RPMS/ +put -r /usr/src/rpm/SRPMS/ ls -l /var/repository/repos/rpm/ EOF \ No newline at end of file From c0527255755bc809c0df85c8d82f96cadedf869b Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 10 Jul 2017 16:31:09 +0300 Subject: [PATCH 052/349] test_works --- tests/anoncreds.rs | 51 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index 2b1d21ad6e..3f0773c4f4 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -19,6 +19,7 @@ use utils::test::TestUtils; use std::collections::HashMap; use utils::types::{ ClaimDefinition, + ClaimDefinitionData, ClaimOffer, ProofClaimsJson, ClaimRequestJson, @@ -1351,15 +1352,6 @@ mod demos { assert!(claim_offers.len() == 1); let claim_offer_json = serde_json::to_string(&claim_offers[0]).unwrap(); - //7. Prover create Claim Request - let prover_did = "BzfFCYk"; - let claim_req = AnoncredsUtils::prover_create_and_store_claim_req(prover_wallet_handle, - prover_did, - &claim_offer_json, - &claim_def_json, - master_secret_name).unwrap(); - - let mut command = Command::new("python3") .arg("../anoncreds-fork/anoncreds/test/test_interoperability_with_libsovrin.py") .spawn().expect("failed to execute process"); @@ -1370,6 +1362,32 @@ mod demos { // assert!(answer == expected_answer); if let Ok(mut stream) = TcpStream::connect("127.0.0.1:1234") { println!("Connected to the server!"); + stream.write(r#"{"type":"get_claim_def"}"#.as_bytes()); + let mut buf = vec![0; 10240]; + stream.read(&mut buf).unwrap(); + buf.retain(|&element| element != 0); + let claim_def = String::from_utf8(buf).unwrap(); + println!("claim_def: {:?}", claim_def); + let claim_def_data: ClaimDefinitionData = serde_json::from_str(&claim_def).unwrap(); + println!("claim_def_data: {:?}", claim_def_data); + let claim_def_json = ClaimDefinition { + issuer_did: ISSUER_DID.to_string(), + signature_type: "CL".to_string(), + schema_seq_no: schema_seq_no, + data: claim_def_data + }; + let claim_def_json = serde_json::to_string(&claim_def_json).unwrap(); + println!("claim_def_json: {:?}", claim_def_json); + + //7. Prover create Claim Request + let prover_did = "BzfFCYk"; + let claim_req = AnoncredsUtils::prover_create_and_store_claim_req(prover_wallet_handle, + prover_did, + &claim_offer_json, + &claim_def_json, + master_secret_name).unwrap(); + + stream.write(format!(r#"{{"type":"issue", "data": {}}}"#, claim_req).as_bytes()); let mut buf = vec![0; 10240]; stream.read(&mut buf).unwrap(); @@ -1383,12 +1401,15 @@ mod demos { println!("new_answer: {:?}", &serde_json::to_string(&new_answer).unwrap()); - //5. Issuer create Claim - let claim_json = AnoncredsUtils::get_gvt_claim_json(); - let (_, xclaim_json) = AnoncredsUtils::issuer_create_claim(issuer_wallet_handle, - &claim_req, - &claim_json).unwrap(); - println!("xclaim_json: {:?}", xclaim_json); + + + +// //5. Issuer create Claim +// let claim_json = AnoncredsUtils::get_gvt_claim_json(); +// let (_, xclaim_json) = AnoncredsUtils::issuer_create_claim(issuer_wallet_handle, +// &claim_req, +// &claim_json).unwrap(); +// println!("xclaim_json: {:?}", xclaim_json); // 9. Prover store received Claim From d1895aa6b72119b9699f766049f6dbf7fa4732cc Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 10 Jul 2017 16:47:54 +0300 Subject: [PATCH 053/349] Worked --- Jenkinsfile | 37 +++++++++++++++++++++++++++++++++++++ ci/rpm-build.sh | 8 +++++--- ci/upload-rpm.sh | 4 ---- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2e0d534b88..ff2f652d85 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -46,6 +46,13 @@ try { } } + // 3. PUBLISH RPMS TO repo.evernym.com + stage('Publish RPM Files') { + node('ubuntu') { + publishRpmFiles() + } + } + } catch (e) { currentBuild.result = "FAILED" node('ubuntu-master') { @@ -213,4 +220,34 @@ def publishToCargo() { echo 'Publish to cargo: Cleanup' step([$class: 'WsCleanup']) } +} + +def publishRpmFiles() { + try { + echo 'Publish Rpm files: Checkout csm' + checkout scm + + echo 'Publish Rpm: Build docker image' + def testEnv = dockerHelpers.build(name, 'ci/amazon.dockerfile ci') + + testEnv.inside('-u 0:0') { + + commit = sh(returnStdout: true, script: 'git rev-parse HEAD').trim() + + sh 'chmod -R 777 ci' + + def spec_path = pwd() + "/ci/indy-sdk.spec" + sh "chown root.root $spec_path" + + sh "./ci/rpm-build.sh $commit" + + withCredentials([file(credentialsId: 'EvernymRepoSSHKey', variable: 'evernym_repo_key')]) { + sh "./ci/upload-rpm.sh $evernym_repo_key" + } + } + } + finally { + echo 'Publish RPM: Cleanup' + step([$class: 'WsCleanup']) + } } \ No newline at end of file diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index a176c73c9e..62a4614d07 100755 --- a/ci/rpm-build.sh +++ b/ci/rpm-build.sh @@ -1,12 +1,14 @@ #!/bin/bash -commit='3b4bbd5a11a1ac3bf3597daeee23306000d83a5c' +if [ "$1" = "--help" ] ; then + echo "Usage: $0 " +fi + +commit="$1" mkdir -p /usr/src/rpm/SOURCES/ -echo $commit version=$(wget -q https://raw.githubusercontent.com/hyperledger/indy-sdk/$commit/Cargo.toml -O - | grep -E '^version =' | head -n1 | cut -f2 -d= | tr -d '" ') -echo $version [ -z $version ] && exit 1 [ -z $commit ] && exit 2 diff --git a/ci/upload-rpm.sh b/ci/upload-rpm.sh index b5b714b1ad..8a5ad95cd1 100644 --- a/ci/upload-rpm.sh +++ b/ci/upload-rpm.sh @@ -6,13 +6,9 @@ fi key="$1" -echo "Uploading...." - cat < Date: Mon, 10 Jul 2017 17:21:06 +0300 Subject: [PATCH 054/349] Fix --- ci/amazon.dockerfile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index a81a05f40c..9b142ebc32 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -31,4 +31,9 @@ RUN curl -fsOSL $RUST_DOWNLOAD_URL \ ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin" -WORKDIR /home/sovrin \ No newline at end of file +RUN useradd -ms /bin/bash -u $uid sovrin +USER sovrin + +RUN cargo install --git https://github.com/DSRCorporation/cargo-test-xunit + +WORKDIR /home/sorvin \ No newline at end of file From 272930cb560a38b833c5eb7db063823a21d0d8fe Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 10 Jul 2017 17:24:47 +0300 Subject: [PATCH 055/349] refactoring --- tests/anoncreds.rs | 78 ++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 52 deletions(-) diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index 3f0773c4f4..0ea0fadd9d 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -1313,37 +1313,29 @@ mod demos { #[test] fn interoperability_test_pysovrin_is_issuer() { - TestUtils::cleanup_storage(); let pool_name = "pool1"; - let issuer_wallet_name = "issuer_wallet"; let prover_wallet_name = "prover_wallet"; let xtype = "default"; - //1. Create Issuer wallet, get wallet handle - let issuer_wallet_handle = WalletUtils::create_and_open_wallet(pool_name, issuer_wallet_name, xtype).unwrap(); - - //2. Create Prover wallet, get wallet handle + //1. Create Prover wallet, get wallet handle let prover_wallet_handle = WalletUtils::create_and_open_wallet(pool_name, prover_wallet_name, xtype).unwrap(); - //3. Issuer create claim definition let schema_seq_no = 1; let schema = AnoncredsUtils::get_gvt_schema_json(schema_seq_no); - let claim_def_json = AnoncredsUtils::issuer_create_claim_definition(issuer_wallet_handle, &ISSUER_DID, &schema, None, false).unwrap(); - - //4. Prover create Master Secret + //2. Prover create Master Secret let master_secret_name = "prover_master_secret"; AnoncredsUtils::prover_create_master_secret(prover_wallet_handle, master_secret_name).unwrap(); - //5. Prover store Claim Offer received from Issuer + //3. Prover store Claim Offer received from Issuer let claim_offer_json = AnoncredsUtils::get_claim_offer(ISSUER_DID, schema_seq_no); AnoncredsUtils::prover_store_claim_offer(prover_wallet_handle, &claim_offer_json).unwrap(); - //6. Prover get Claim Offers + //4. Prover get Claim Offers let filter_json = format!(r#"{{"issuer_did":"{}"}}"#, ISSUER_DID); let claim_offers_json = AnoncredsUtils::prover_get_claim_offers(prover_wallet_handle, &filter_json).unwrap(); @@ -1353,33 +1345,30 @@ mod demos { let claim_offer_json = serde_json::to_string(&claim_offers[0]).unwrap(); let mut command = Command::new("python3") - .arg("../anoncreds-fork/anoncreds/test/test_interoperability_with_libsovrin.py") + .arg("../anoncreds-fork/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_issuer.py") .spawn().expect("failed to execute process"); thread::sleep(time::Duration::from_millis(3000)); -// let answer = String::from_utf8(command.stdout).unwrap(); -// let expected_answer = "Executed\n"; -// assert!(command.stdout.status.success()); -// assert!(answer == expected_answer); + if let Ok(mut stream) = TcpStream::connect("127.0.0.1:1234") { - println!("Connected to the server!"); + info!(target: "anoncreds_tests", "Connected to the server!"); + stream.write(r#"{"type":"get_claim_def"}"#.as_bytes()); let mut buf = vec![0; 10240]; stream.read(&mut buf).unwrap(); buf.retain(|&element| element != 0); - let claim_def = String::from_utf8(buf).unwrap(); - println!("claim_def: {:?}", claim_def); - let claim_def_data: ClaimDefinitionData = serde_json::from_str(&claim_def).unwrap(); - println!("claim_def_data: {:?}", claim_def_data); - let claim_def_json = ClaimDefinition { + + let claim_def_data: ClaimDefinitionData = serde_json::from_str(&String::from_utf8(buf).unwrap()).unwrap(); + + let claim_def = ClaimDefinition { issuer_did: ISSUER_DID.to_string(), signature_type: "CL".to_string(), schema_seq_no: schema_seq_no, data: claim_def_data }; - let claim_def_json = serde_json::to_string(&claim_def_json).unwrap(); - println!("claim_def_json: {:?}", claim_def_json); - //7. Prover create Claim Request + let claim_def_json = serde_json::to_string(&claim_def).unwrap(); + + //5. Prover create Claim Request let prover_did = "BzfFCYk"; let claim_req = AnoncredsUtils::prover_create_and_store_claim_req(prover_wallet_handle, prover_did, @@ -1387,35 +1376,20 @@ mod demos { &claim_def_json, master_secret_name).unwrap(); - - stream.write(format!(r#"{{"type":"issue", "data": {}}}"#, claim_req).as_bytes()); + stream.write(format!(r#"{{"type":"issue_claim", "data": {}}}"#, claim_req).as_bytes()); let mut buf = vec![0; 10240]; stream.read(&mut buf).unwrap(); - buf.retain(|&element| element != 0); - let answer = String::from_utf8(buf).unwrap(); - println!("answer: {:?}", answer); stream.write(r#"{"type":"close"}"#.as_bytes()); - let mut new_answer: ClaimJson = serde_json::from_str(&answer).unwrap(); - new_answer.schema_seq_no = Some(schema_seq_no); - new_answer.issuer_did = Some(ISSUER_DID.to_string()); - println!("new_answer: {:?}", &serde_json::to_string(&new_answer).unwrap()); - - - - - -// //5. Issuer create Claim -// let claim_json = AnoncredsUtils::get_gvt_claim_json(); -// let (_, xclaim_json) = AnoncredsUtils::issuer_create_claim(issuer_wallet_handle, -// &claim_req, -// &claim_json).unwrap(); -// println!("xclaim_json: {:?}", xclaim_json); + buf.retain(|&element| element != 0); + let mut claim_json: ClaimJson = serde_json::from_str(&String::from_utf8(buf).unwrap()).unwrap(); + claim_json.schema_seq_no = Some(schema_seq_no); + claim_json.issuer_did = Some(ISSUER_DID.to_string()); - // 9. Prover store received Claim - AnoncredsUtils::prover_store_claim(prover_wallet_handle, &serde_json::to_string(&new_answer).unwrap()).unwrap(); + // 6. Prover store received Claim + AnoncredsUtils::prover_store_claim(prover_wallet_handle, &serde_json::to_string(&claim_json).unwrap()).unwrap(); - // 10. Prover gets Claims for Proof Request + // 7. Prover gets Claims for Proof Request let proof_req_json = format!(r#"{{ "nonce":"123432421212", "name":"proof_req_1", @@ -1432,7 +1406,7 @@ mod demos { assert_eq!(1, claims_for_attr_1.len()); let claim = claims_for_attr_1[0].clone(); - // 11. Prover create Proof + // 8. Prover create Proof let self_attested_value = "value"; let requested_claims_json = format!(r#"{{ "self_attested_attributes":{{"self1":"{}"}}, @@ -1463,7 +1437,7 @@ mod demos { let value = proof.requested_proof.self_attested_attrs.get("self1").unwrap(); assert_eq!(value, self_attested_value); - // 12. Verifier verify proof + // 9. Verifier verify proof let valid = AnoncredsUtils::verifier_verify_proof(&proof_req_json, &proof_json, &schemas_json, @@ -1473,7 +1447,7 @@ mod demos { TestUtils::cleanup_storage(); } else { - println!("Couldn't connect to server..."); + info!(target: "anoncreds_tests", "Couldn't connect to server..."); } } From 556b1ff4014388601ac1cc05f690d7d69c406e98 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 10 Jul 2017 18:06:05 +0300 Subject: [PATCH 056/349] refactoring --- tests/anoncreds.rs | 158 ++++++++++++++++++++++----------------------- 1 file changed, 77 insertions(+), 81 deletions(-) diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index 0ea0fadd9d..842d3c7083 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -1349,106 +1349,102 @@ mod demos { .spawn().expect("failed to execute process"); thread::sleep(time::Duration::from_millis(3000)); - if let Ok(mut stream) = TcpStream::connect("127.0.0.1:1234") { - info!(target: "anoncreds_tests", "Connected to the server!"); + let mut stream = TcpStream::connect("127.0.0.1:1234").unwrap(); - stream.write(r#"{"type":"get_claim_def"}"#.as_bytes()); - let mut buf = vec![0; 10240]; - stream.read(&mut buf).unwrap(); - buf.retain(|&element| element != 0); + stream.write(r#"{"type":"get_claim_def"}"#.as_bytes()); + let mut buf = vec![0; 10240]; + stream.read(&mut buf).unwrap(); + buf.retain(|&element| element != 0); - let claim_def_data: ClaimDefinitionData = serde_json::from_str(&String::from_utf8(buf).unwrap()).unwrap(); + let claim_def_data: ClaimDefinitionData = serde_json::from_str(&String::from_utf8(buf).unwrap()).unwrap(); - let claim_def = ClaimDefinition { - issuer_did: ISSUER_DID.to_string(), - signature_type: "CL".to_string(), - schema_seq_no: schema_seq_no, - data: claim_def_data - }; + let claim_def = ClaimDefinition { + issuer_did: ISSUER_DID.to_string(), + signature_type: "CL".to_string(), + schema_seq_no: schema_seq_no, + data: claim_def_data + }; - let claim_def_json = serde_json::to_string(&claim_def).unwrap(); + let claim_def_json = serde_json::to_string(&claim_def).unwrap(); - //5. Prover create Claim Request - let prover_did = "BzfFCYk"; - let claim_req = AnoncredsUtils::prover_create_and_store_claim_req(prover_wallet_handle, - prover_did, - &claim_offer_json, - &claim_def_json, - master_secret_name).unwrap(); + //5. Prover create Claim Request + let prover_did = "BzfFCYk"; + let claim_req = AnoncredsUtils::prover_create_and_store_claim_req(prover_wallet_handle, + prover_did, + &claim_offer_json, + &claim_def_json, + master_secret_name).unwrap(); - stream.write(format!(r#"{{"type":"issue_claim", "data": {}}}"#, claim_req).as_bytes()); - let mut buf = vec![0; 10240]; - stream.read(&mut buf).unwrap(); - stream.write(r#"{"type":"close"}"#.as_bytes()); - buf.retain(|&element| element != 0); + stream.write(format!(r#"{{"type":"issue_claim", "data": {}}}"#, claim_req).as_bytes()); + let mut buf = vec![0; 10240]; + stream.read(&mut buf).unwrap(); + stream.write(r#"{"type":"close"}"#.as_bytes()); + buf.retain(|&element| element != 0); - let mut claim_json: ClaimJson = serde_json::from_str(&String::from_utf8(buf).unwrap()).unwrap(); - claim_json.schema_seq_no = Some(schema_seq_no); - claim_json.issuer_did = Some(ISSUER_DID.to_string()); + let mut claim_json: ClaimJson = serde_json::from_str(&String::from_utf8(buf).unwrap()).unwrap(); + claim_json.schema_seq_no = Some(schema_seq_no); + claim_json.issuer_did = Some(ISSUER_DID.to_string()); - // 6. Prover store received Claim - AnoncredsUtils::prover_store_claim(prover_wallet_handle, &serde_json::to_string(&claim_json).unwrap()).unwrap(); + // 6. Prover store received Claim + AnoncredsUtils::prover_store_claim(prover_wallet_handle, &serde_json::to_string(&claim_json).unwrap()).unwrap(); - // 7. Prover gets Claims for Proof Request - let proof_req_json = format!(r#"{{ - "nonce":"123432421212", - "name":"proof_req_1", - "version":"0.1", - "requested_attrs":{{"attr1_uuid":{{"schema_seq_no":{},"name":"name"}}, - "attr2_uuid":{{"schema_seq_no":{},"name":"sex"}}}}, - "requested_predicates":{{"predicate1_uuid":{{"attr_name":"age","p_type":"GE","value":18}}}} - }}"#, schema_seq_no, schema_seq_no); + // 7. Prover gets Claims for Proof Request + let proof_req_json = format!(r#"{{ + "nonce":"123432421212", + "name":"proof_req_1", + "version":"0.1", + "requested_attrs":{{"attr1_uuid":{{"schema_seq_no":{},"name":"name"}}, + "attr2_uuid":{{"schema_seq_no":{},"name":"sex"}}}}, + "requested_predicates":{{"predicate1_uuid":{{"attr_name":"age","p_type":"GE","value":18}}}} + }}"#, schema_seq_no, schema_seq_no); - let claims_json = AnoncredsUtils::prover_get_claims_for_proof_req(prover_wallet_handle, &proof_req_json).unwrap(); - let claims: ProofClaimsJson = serde_json::from_str(&claims_json).unwrap(); - info!("claims_json: {}", &claims_json); - let claims_for_attr_1 = claims.attrs.get("attr1_uuid").unwrap(); - assert_eq!(1, claims_for_attr_1.len()); - let claim = claims_for_attr_1[0].clone(); + let claims_json = AnoncredsUtils::prover_get_claims_for_proof_req(prover_wallet_handle, &proof_req_json).unwrap(); + let claims: ProofClaimsJson = serde_json::from_str(&claims_json).unwrap(); + info!("claims_json: {}", &claims_json); + let claims_for_attr_1 = claims.attrs.get("attr1_uuid").unwrap(); + assert_eq!(1, claims_for_attr_1.len()); + let claim = claims_for_attr_1[0].clone(); - // 8. Prover create Proof - let self_attested_value = "value"; - let requested_claims_json = format!(r#"{{ - "self_attested_attributes":{{"self1":"{}"}}, - "requested_attrs":{{"attr1_uuid":["{}",true], - "attr2_uuid":["{}", false]}}, - "requested_predicates":{{"predicate1_uuid":"{}"}} - }}"#, self_attested_value, claim.claim_uuid, claim.claim_uuid, claim.claim_uuid); + // 8. Prover create Proof + let self_attested_value = "value"; + let requested_claims_json = format!(r#"{{ + "self_attested_attributes":{{"self1":"{}"}}, + "requested_attrs":{{"attr1_uuid":["{}",true], + "attr2_uuid":["{}", false]}}, + "requested_predicates":{{"predicate1_uuid":"{}"}} + }}"#, self_attested_value, claim.claim_uuid, claim.claim_uuid, claim.claim_uuid); - let schemas_json = format!(r#"{{"{}":{}}}"#, claim.claim_uuid, schema); - let claim_defs_json = format!(r#"{{"{}":{}}}"#, claim.claim_uuid, claim_def_json); - let revoc_regs_jsons = "{}"; + let schemas_json = format!(r#"{{"{}":{}}}"#, claim.claim_uuid, schema); + let claim_defs_json = format!(r#"{{"{}":{}}}"#, claim.claim_uuid, claim_def_json); + let revoc_regs_jsons = "{}"; - let proof_json = AnoncredsUtils::prover_create_proof(prover_wallet_handle, - &proof_req_json, - &requested_claims_json, - &schemas_json, - &master_secret_name, - &claim_defs_json, - &revoc_regs_jsons).unwrap(); + let proof_json = AnoncredsUtils::prover_create_proof(prover_wallet_handle, + &proof_req_json, + &requested_claims_json, + &schemas_json, + &master_secret_name, + &claim_defs_json, + &revoc_regs_jsons).unwrap(); - let proof: ProofJson = serde_json::from_str(&proof_json).unwrap(); + let proof: ProofJson = serde_json::from_str(&proof_json).unwrap(); - let &(_, ref value, _) = proof.requested_proof.revealed_attrs.get("attr1_uuid").unwrap(); - assert_eq!(value, "Alex"); + let &(_, ref value, _) = proof.requested_proof.revealed_attrs.get("attr1_uuid").unwrap(); + assert_eq!(value, "Alex"); - proof.requested_proof.unrevealed_attrs.get("attr2_uuid").unwrap(); + proof.requested_proof.unrevealed_attrs.get("attr2_uuid").unwrap(); - let value = proof.requested_proof.self_attested_attrs.get("self1").unwrap(); - assert_eq!(value, self_attested_value); + let value = proof.requested_proof.self_attested_attrs.get("self1").unwrap(); + assert_eq!(value, self_attested_value); - // 9. Verifier verify proof - let valid = AnoncredsUtils::verifier_verify_proof(&proof_req_json, - &proof_json, - &schemas_json, - &claim_defs_json, - &revoc_regs_jsons).unwrap(); - assert!(valid); + // 9. Verifier verify proof + let valid = AnoncredsUtils::verifier_verify_proof(&proof_req_json, + &proof_json, + &schemas_json, + &claim_defs_json, + &revoc_regs_jsons).unwrap(); + assert!(valid); - TestUtils::cleanup_storage(); - } else { - info!(target: "anoncreds_tests", "Couldn't connect to server..."); - } + TestUtils::cleanup_storage(); } #[test] From a8b9d4ec940dcd15ee80bc57c6763ebb6ab1658c Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 11 Jul 2017 08:08:55 +0300 Subject: [PATCH 057/349] Corrected docker file --- ci/amazon.dockerfile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 9b142ebc32..20f464a04f 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -6,17 +6,22 @@ RUN \ yum clean all \ && yum upgrade -y \ && yum groupinstall -y "Development Tools" \ - && yum install -y epel-release \ - && yum-config-manager --enable epel \ && yum install -y \ wget \ cmake \ pkgconfig \ openssl-devel \ sqlite-devel \ - libsodium-devel \ spectool +RUN cd /tmp && \ + curl https://download.libsodium.org/libsodium/releases/libsodium-1.0.12.tar.gz | tar -xz && \ + cd /tmp/libsodium-1.0.12 && \ + ./configure && \ + make && \ + make install && \ + rm -rf /tmp/libsodium-1.0.12 + Z ENV RUST_ARCHIVE=rust-1.16.0-x86_64-unknown-linux-gnu.tar.gz ENV RUST_DOWNLOAD_URL=https://static.rust-lang.org/dist/$RUST_ARCHIVE From dfb6387f3e98d0951e899084a45396d4a4f8bd30 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 11 Jul 2017 08:15:53 +0300 Subject: [PATCH 058/349] Correct --- ci/amazon.dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 20f464a04f..0154a007b2 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -21,7 +21,10 @@ RUN cd /tmp && \ make && \ make install && \ rm -rf /tmp/libsodium-1.0.12 - Z + +ENV PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig +ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib + ENV RUST_ARCHIVE=rust-1.16.0-x86_64-unknown-linux-gnu.tar.gz ENV RUST_DOWNLOAD_URL=https://static.rust-lang.org/dist/$RUST_ARCHIVE From efe63cc4eb75b990cb4522aa75fa141b3c351305 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 11 Jul 2017 08:42:38 +0300 Subject: [PATCH 059/349] deleted wrong file --- ci/indy-sdk.spec | 73 ------------------------------------------------ 1 file changed, 73 deletions(-) delete mode 100644 ci/indy-sdk.spec diff --git a/ci/indy-sdk.spec b/ci/indy-sdk.spec deleted file mode 100644 index 4dd4307e00..0000000000 --- a/ci/indy-sdk.spec +++ /dev/null @@ -1,73 +0,0 @@ -%global commit d79396b8cb51556ea1fda75868893dec482aa326 - -Summary: Official SDK for Hyperledger Indy -Name: indy-sdk -Version: 0.1.1.d79396b8cb51556ea1fda75868893dec482aa326.%{commit} -Release: 1%{?dist} -License: Apache License 2.0 -Group: System Environment/Libraries -Source: https://github.com/hyperledger/indy-sdk/archive/%{commit}.tar.gz -URL: https://github.com/hyperledger/indy-sdk/ -BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) -Requires: sqlite openssl libsodium -BuildRequires: sqlite-devel openssl-devel libsodium-devel - -%description -This is the official SDK for Hyperledger Indy, which provides a -distributed-ledger-based foundation for self-sovereign identity. -The major artifact of the SDK is a c-callable library; there are -also convenience wrappers for various programming languages. - -All bugs, stories, and backlog for this project are managed through -Hyperledger's Jira in project IS (note that regular Indy tickets are -in the INDY project instead...). Also, join us on Jira's Rocket.Chat -at #indy-sdk to discuss. - -%package devel -Summary: Development files for Hyperledger Indy -Group: Development/Libraries -Requires: %{name} = %{version}-%{release} - -%description devel -This is the official SDK for Hyperledger Indy, which provides a -distributed-ledger-based foundation for self-sovereign identity. -The major artifact of the SDK is a c-callable library; there are -also convenience wrappers for various programming languages. - -All bugs, stories, and backlog for this project are managed through -Hyperledger's Jira in project IS (note that regular Indy tickets are -in the INDY project instead...). Also, join us on Jira's Rocket.Chat -at #indy-sdk to discuss. - -%prep -%autosetup -n %{name}-%{commit} - -%build -cargo build --release - -%install -rm -rf ${RPM_BUILD_ROOT} - -install -dm0755 $RPM_BUILD_ROOT/%{_includedir}/sovrin -install -dm0755 $RPM_BUILD_ROOT/%{_libdir} -cp -a include/*.h $RPM_BUILD_ROOT/%{_includedir}/sovrin/ -install -Dm0644 target/release/libsovrin.a $RPM_BUILD_ROOT/%{_libdir}/libsovrin.a -install -Dm0644 target/release/libsovrin.so $RPM_BUILD_ROOT/%{_libdir}/libsovrin.so - -%clean -rm -rf ${RPM_BUILD_ROOT} - -%post -p /sbin/ldconfig - -%postun -p /sbin/ldconfig - -%files -%defattr(-,root,root) -%{_libdir}/libsovrin.so* - -%files devel -%defattr(-,root,root) -%{_libdir}/libsovrin.a -%{_includedir}/sovrin/*.h - -%changelog From cf277b84b963df5b38e9364d75dcad5d62e3bc63 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 11 Jul 2017 09:19:34 +0300 Subject: [PATCH 060/349] modified build script --- ci/rpm-build.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index 62a4614d07..4dd876d6ea 100755 --- a/ci/rpm-build.sh +++ b/ci/rpm-build.sh @@ -1,10 +1,11 @@ #!/bin/bash if [ "$1" = "--help" ] ; then - echo "Usage: $0 " + echo "Usage: $0 $1 " fi commit="$1" +file="$2" mkdir -p /usr/src/rpm/SOURCES/ @@ -20,5 +21,7 @@ sed \ -e "s|@version@|$version.$commit|g" \ indy-sdk.spec.in >indy-sdk.spec +chown root.root $file + spectool -g -R indy-sdk.spec || exit 3 rpmbuild -ba indy-sdk.spec || exit 4 \ No newline at end of file From 86bb4d022ca046f49d4ea83aad353d6565a41f21 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 11 Jul 2017 09:28:03 +0300 Subject: [PATCH 061/349] try --- ci/rpm-build.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index 4dd876d6ea..8987fdbcb6 100755 --- a/ci/rpm-build.sh +++ b/ci/rpm-build.sh @@ -1,11 +1,10 @@ #!/bin/bash if [ "$1" = "--help" ] ; then - echo "Usage: $0 $1 " + echo "Usage: $0 " fi commit="$1" -file="$2" mkdir -p /usr/src/rpm/SOURCES/ @@ -21,7 +20,7 @@ sed \ -e "s|@version@|$version.$commit|g" \ indy-sdk.spec.in >indy-sdk.spec -chown root.root $file +chown root.root indy-sdk.spec spectool -g -R indy-sdk.spec || exit 3 rpmbuild -ba indy-sdk.spec || exit 4 \ No newline at end of file From 8727efb6348eb74a41f3b3c9ff29bc61d92a1bf5 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 11 Jul 2017 09:30:20 +0300 Subject: [PATCH 062/349] try --- ci/amazon.dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 0154a007b2..3c7dbbf6d5 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -6,12 +6,15 @@ RUN \ yum clean all \ && yum upgrade -y \ && yum groupinstall -y "Development Tools" \ + && yum install -y epel-release \ + && yum-config-manager --enable epel \ && yum install -y \ wget \ cmake \ pkgconfig \ openssl-devel \ sqlite-devel \ + libsodium-devel \ spectool RUN cd /tmp && \ From 09f00625decc3acbef4c2e7a10eacdc4d1f1ca1a Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 11 Jul 2017 09:44:07 +0300 Subject: [PATCH 063/349] Worked pipeline --- Jenkinsfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ff2f652d85..c89c45cc47 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -236,9 +236,6 @@ def publishRpmFiles() { sh 'chmod -R 777 ci' - def spec_path = pwd() + "/ci/indy-sdk.spec" - sh "chown root.root $spec_path" - sh "./ci/rpm-build.sh $commit" withCredentials([file(credentialsId: 'EvernymRepoSSHKey', variable: 'evernym_repo_key')]) { From f14078686872e0542184da0f5e6e96df717d2bec Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 11 Jul 2017 10:30:36 +0300 Subject: [PATCH 064/349] Worked pipeline --- Jenkinsfile | 88 +++++++++++------------------------------------------ 1 file changed, 18 insertions(+), 70 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c89c45cc47..1e5a0be31f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -71,26 +71,26 @@ try { } } -def testUbuntu() { +def testPipeline(file, env_name) { def poolInst def network_name = "pool_network" try { - echo 'Ubuntu Test: Checkout csm' + echo "${env_name} Test: Checkout csm" checkout scm - echo "Ubuntu Test: Create docker network (${network_name}) for nodes pool and test image" + echo "${env_name} Test: Create docker network (${network_name}) for nodes pool and test image" sh "docker network create --subnet=10.0.0.0/8 ${network_name}" - echo 'Ubuntu Test: Build docker image for nodes pool' + echo "${env_name} Test: Build docker image for nodes pool" def poolEnv = dockerHelpers.build('sovrin_pool', 'ci/sovrin-pool.dockerfile ci') - echo 'Ubuntu Test: Run nodes pool' + echo "${env_name} Test: Run nodes pool" poolInst = poolEnv.run("--ip=\"10.0.0.2\" --network=${network_name}") - echo 'Ubuntu Test: Build docker image' - def testEnv = dockerHelpers.build(name) + echo "${env_name} Test: Build docker image" + def testEnv = dockerHelpers.build(name, file) testEnv.inside("--ip=\"10.0.0.3\" --network=${network_name}") { - echo 'Ubuntu Test: Test' + echo "${env_name} Test: Test" sh 'cargo update' @@ -108,87 +108,35 @@ def testUbuntu() { } } finally { - echo 'Ubuntu Test: Cleanup' + echo "${env_name} Test: Cleanup" try { sh "docker network inspect ${network_name}" } catch (ignore) { } try { if (poolInst) { - echo 'Ubuntu Test: stop pool' + echo "${env_name} Test: stop pool" poolInst.stop() } } catch (err) { - echo "Ubuntu Tests: error while stop pool ${err}" + echo "${env_name} Tests: error while stop pool ${err}" } try { - echo "Ubuntu Test: remove pool network ${network_name}" + echo "${env_name} Test: remove pool network ${network_name}" sh "docker network rm ${network_name}" } catch (err) { - echo "Ubuntu Test: error while delete ${network_name} - ${err}" + echo "${env_name} Test: error while delete ${network_name} - ${err}" } step([$class: 'WsCleanup']) } } -def testRedHat() { - def poolInst - def network_name = "pool_network" - try { - echo 'RedHat Test: Checkout csm' - checkout scm - - echo "RedHat Test: Create docker network (${network_name}) for nodes pool and test image" - sh "docker network create --subnet=10.0.0.0/8 ${network_name}" - - echo 'RedHat Test: Build docker image for nodes pool' - def poolEnv = dockerHelpers.build('sovrin_pool', 'ci/sovrin-pool.dockerfile ci') - echo 'RedHat Test: Run nodes pool' - poolInst = poolEnv.run("--ip=\"10.0.0.2\" --network=${network_name}") - - echo 'RedHat Test: Build docker image' - def testEnv = dockerHelpers.build(name, 'ci/amazon.dockerfile ci') - - testEnv.inside("--ip=\"10.0.0.3\" --network=${network_name}") { - echo 'RedHat Test: Test' - - sh 'cargo update' +def testUbuntu() { + testPipeline("ci/ubuntu.dockerfile ci", "Ubuntu") +} - try { - sh 'RUST_BACKTRACE=1 RUST_TEST_THREADS=1 cargo test' - /* TODO FIXME restore after xunit will be fixed - sh 'RUST_TEST_THREADS=1 cargo test-xunit' - */ - } - finally { - /* TODO FIXME restore after xunit will be fixed - junit 'test-results.xml' - */ - } - } - } - finally { - echo 'RedHat Test: Cleanup' - try { - sh "docker network inspect ${network_name}" - } catch (ignore) { - } - try { - if (poolInst) { - echo 'RedHat Test: stop pool' - poolInst.stop() - } - } catch (err) { - echo "RedHat Tests: error while stop pool ${err}" - } - try { - echo "RedHat Test: remove pool network ${network_name}" - sh "docker network rm ${network_name}" - } catch (err) { - echo "RedHat Test: error while delete ${network_name} - ${err}" - } - step([$class: 'WsCleanup']) - } +def testRedHat() { + testPipeline("ci/amazon.dockerfile ci", "RedHat") } def publishToCargo() { From be3d863194119f46f6bf2ce75fc4fc2f8a325906 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 11 Jul 2017 10:31:44 +0300 Subject: [PATCH 065/349] try without libsovrin install --- ci/amazon.dockerfile | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 3c7dbbf6d5..9b142ebc32 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -17,17 +17,6 @@ RUN \ libsodium-devel \ spectool -RUN cd /tmp && \ - curl https://download.libsodium.org/libsodium/releases/libsodium-1.0.12.tar.gz | tar -xz && \ - cd /tmp/libsodium-1.0.12 && \ - ./configure && \ - make && \ - make install && \ - rm -rf /tmp/libsodium-1.0.12 - -ENV PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig -ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib - ENV RUST_ARCHIVE=rust-1.16.0-x86_64-unknown-linux-gnu.tar.gz ENV RUST_DOWNLOAD_URL=https://static.rust-lang.org/dist/$RUST_ARCHIVE From c27942494fb376d09c9f6573e8ffed5ce08818c6 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 11 Jul 2017 15:51:32 +0300 Subject: [PATCH 066/349] Deleted tests --- tests/pool.rs | 92 ------------------------------------------------- tests/wallet.rs | 29 ---------------- 2 files changed, 121 deletions(-) diff --git a/tests/pool.rs b/tests/pool.rs index 77b8c2bb75..fdad008679 100644 --- a/tests/pool.rs +++ b/tests/pool.rs @@ -238,19 +238,6 @@ mod high_cases { TestUtils::cleanup_storage(); } - #[test] - fn sovrin_delete_pool_ledger_config_works_for_recreate_after_delete() { - TestUtils::cleanup_storage(); - - let pool_name = "sovrin_remove_pool_ledger_config_works"; - PoolUtils::create_pool_ledger_config(pool_name, None, None, None).unwrap(); - PoolUtils::delete(pool_name).unwrap(); - - PoolUtils::create_pool_ledger_config(pool_name, None, None, None).unwrap(); - - TestUtils::cleanup_storage(); - } - #[test] #[cfg(feature = "local_nodes_pool")] fn indy_delete_pool_ledger_config_works_for_opened() { @@ -263,20 +250,6 @@ mod high_cases { TestUtils::cleanup_storage(); } - - #[test] - #[cfg(feature = "local_nodes_pool")] - fn sovrin_delete_pool_ledger_config_works_for_closed() { - TestUtils::cleanup_storage(); - - let pool_name = "sovrin_delete_pool_ledger_config_works_for_closed"; - let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); - PoolUtils::close(pool_handle).unwrap(); - - PoolUtils::delete(pool_name).unwrap(); - - TestUtils::cleanup_storage(); - } } } @@ -394,70 +367,5 @@ mod medium_cases { TestUtils::cleanup_storage(); } - - #[test] - #[cfg(feature = "local_nodes_pool")] - fn open_pool_ledger_works_for_several_pools() { - TestUtils::cleanup_storage(); - let pool_name_1 = "open_pool_ledger_works_for_several_pools_1"; - let pool_name_2 = "open_pool_ledger_works_for_several_pools_2"; - - PoolUtils::create_pool_ledger_config(pool_name_1, Some(nodes), None, None).unwrap(); - PoolUtils::create_pool_ledger_config(pool_name_2, Some(nodes), None, None).unwrap(); - - TestUtils::cleanup_storage(); - } - } - - mod refresh { - use super::*; - - #[test] - #[cfg(feature = "local_nodes_pool")] - fn sovrin_refresh_pool_ledger_works_for_invalid_handle() { - TestUtils::cleanup_storage(); - - let pool_handle = PoolUtils::create_and_open_pool_ledger_config("sovrin_refresh_pool_ledger_works_for_invalid_handle").unwrap(); - - let res = PoolUtils::refresh(pool_handle + 1); - assert_eq!(res.unwrap_err(), ErrorCode::WalletInvalidHandle); - - TestUtils::cleanup_storage(); - } - } - - mod close { - use super::*; - - #[test] - #[cfg(feature = "local_nodes_pool")] - fn sovrin_close_pool_ledger_works_for_invalid_handle() { - TestUtils::cleanup_storage(); - - let pool_name = "sovrin_close_pool_ledger_works_for_invalid_handle"; - let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); - - PoolUtils::close(pool_handle + 1).unwrap(); - - TestUtils::cleanup_storage(); - } - } - - mod delete { - use super::*; - - #[test] - #[cfg(feature = "local_nodes_pool")] - fn sovrin_delete_pool_ledger_config_works_for_invalid_handle() { - TestUtils::cleanup_storage(); - - let pool_name = "sovrin_delete_pool_ledger_config_works_for_invalid_handle"; - let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); - PoolUtils::close(pool_handle).unwrap(); - - PoolUtils::delete(pool_handle + 1).unwrap(); - - TestUtils::cleanup_storage(); - } } } \ No newline at end of file diff --git a/tests/wallet.rs b/tests/wallet.rs index 21b9a3222e..4b0519f3a4 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -129,35 +129,6 @@ mod high_cases { TestUtils::cleanup_storage(); } - #[test] - #[ignore] //There is bug - fn sovrin_delete_wallet_works_for_opened() { - TestUtils::cleanup_storage(); - - let pool_name = "sovrin_delete_wallet_works_for_opened"; - let wallet_name = "wallet1"; - - WalletUtils::create_and_open_wallet(pool_name, wallet_name, "default").unwrap(); - let res = WalletUtils::delete_wallet(wallet_name); - assert_eq!(res.unwrap_err(), ErrorCode::CommonIOError); - - TestUtils::cleanup_storage(); - } - - #[test] - fn sovrin_delete_wallet_works_for_closed() { - TestUtils::cleanup_storage(); - - let pool_name = "sovrin_delete_wallet_works_for_closed"; - let wallet_name = "wallet1"; - - let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, wallet_name, "default").unwrap(); - WalletUtils::close_wallet(wallet_handle).unwrap(); - WalletUtils::delete_wallet(wallet_name).unwrap(); - - TestUtils::cleanup_storage(); - } - #[test] fn indy_delete_wallet_works_for_plugged() { TestUtils::cleanup_storage(); From c61da54c38bd62ebf7924326a18c95c238bd99ab Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Tue, 11 Jul 2017 15:15:21 +0200 Subject: [PATCH 067/349] "sovrin" -> "indy" --- .../org/hyperledger/indy/sdk/IndyJava.java | 4 +- .../org/hyperledger/indy/sdk/LibIndy.java | 10 ++++ .../org/hyperledger/indy/sdk/agent/Agent.java | 46 +++++++++---------- .../indy/sdk/agent/AgentResults.java | 16 +++---- 4 files changed, 43 insertions(+), 33 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java index 0ea4c0da8c..9411673107 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java @@ -34,10 +34,10 @@ protected static boolean checkCallback(CompletableFuture future, int err) { + protected static boolean checkCallback(CompletableFuture future, int err) { ErrorCode errorCode = ErrorCode.valueOf(err); - if (! ErrorCode.Success.equals(errorCode)) { future.completeExceptionally(SovrinException.fromErrorCode(errorCode, err)); return false; } + if (! ErrorCode.Success.equals(errorCode)) { future.completeExceptionally(IndyException.fromErrorCode(errorCode, err)); return false; } return true; } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java index ab5b5497df..ca6ccd4c7d 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java @@ -72,6 +72,16 @@ public interface API extends Library { public int indy_prover_get_claims_for_proof_req(int command_handle, int wallet_handle, String proof_request_json, Callback cb); public int indy_prover_create_proof(int command_handle, int wallet_handle, String proof_req_json, String requested_claims_json, String schemas_json, String master_secret_name, String claim_defs_json, String revoc_regs_json, Callback cb); public int indy_verifier_verify_proof(int command_handle, int wallet_handle, String proof_request_json, String proof_json, String schemas_json, String claim_defs_jsons, String revoc_regs_json, Callback cb); + + // agent.rs + + public int indy_agent_connect(int command_handle, int pool_handle, int wallet_handle, String sender_did, String receiver_did, Callback connection_cb, Callback message_cb); + public int indy_agent_listen(int command_handle, String endpoint, Callback listener_cb, Callback connection_cb, Callback message_cb); + public int indy_agent_add_identity(int command_handle, int listener_handle, int pool_handle, int wallet_handle, String did, Callback add_identity_cb); + public int indy_agent_remove_identity(int command_handle, int listener_handle, int wallet_handle, String did, Callback rm_identity_cb); + public int indy_agent_send(int command_handle, int connection_handle, String message, Callback cb); + public int indy_agent_close_connection(int command_handle, int connection_handle, Callback cb); + public int indy_agent_close_listener(int command_handle, int listener_handle, Callback cb); } /* diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java index 909389585f..d1c51b51c9 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java @@ -3,9 +3,9 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.Future; -import org.hyperledger.indy.sdk.LibSovrin; -import org.hyperledger.indy.sdk.SovrinException; -import org.hyperledger.indy.sdk.SovrinJava; +import org.hyperledger.indy.sdk.IndyException; +import org.hyperledger.indy.sdk.IndyJava; +import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.agent.AgentResults.AgentAddIdentityResult; import org.hyperledger.indy.sdk.agent.AgentResults.AgentCloseConnectionResult; import org.hyperledger.indy.sdk.agent.AgentResults.AgentCloseListenerResult; @@ -21,7 +21,7 @@ /** * agent.rs API */ -public class Agent extends SovrinJava.API { +public class Agent extends IndyJava.API { private Agent() { @@ -36,7 +36,7 @@ public static Future agentConnect( Wallet wallet, String senderDid, String receiverDid, - Callback messageCb) throws SovrinException { + Callback messageCb) throws IndyException { final CompletableFuture future = new CompletableFuture<> (); @@ -57,7 +57,7 @@ public void callback(int xcommand_handle, int err, int connection_handle) { int poolHandle = pool.getPoolHandle(); int walletHandle = wallet.getWalletHandle(); - int result = LibSovrin.api.sovrin_agent_connect( + int result = LibIndy.api.indy_agent_connect( FIXED_COMMAND_HANDLE, poolHandle, walletHandle, @@ -74,7 +74,7 @@ public void callback(int xcommand_handle, int err, int connection_handle) { public static Future agentListen( String endpoint, Callback connectionCb, - Callback messageCb) throws SovrinException { + Callback messageCb) throws IndyException { final CompletableFuture future = new CompletableFuture<> (); @@ -92,7 +92,7 @@ public void callback(int xcommand_handle, int err, int listener_handle) { } }; - int result = LibSovrin.api.sovrin_agent_listen( + int result = LibIndy.api.indy_agent_listen( FIXED_COMMAND_HANDLE, endpoint, listenerCb, @@ -110,7 +110,7 @@ public static Future agentAddIdentity( Wallet wallet, String did, Callback connectionCb, - Callback messageCb) throws SovrinException { + Callback messageCb) throws IndyException { final CompletableFuture future = new CompletableFuture<> (); @@ -130,7 +130,7 @@ public void callback(int xcommand_handle, int err, int listener_handle) { int poolHandle = pool.getPoolHandle(); int walletHandle = wallet.getWalletHandle(); - int result = LibSovrin.api.sovrin_agent_add_identity( + int result = LibIndy.api.indy_agent_add_identity( FIXED_COMMAND_HANDLE, listenerHandle, poolHandle, @@ -148,7 +148,7 @@ public static Future agentRemoveIdentity( Wallet wallet, String did, Callback connectionCb, - Callback messageCb) throws SovrinException { + Callback messageCb) throws IndyException { final CompletableFuture future = new CompletableFuture<> (); @@ -167,7 +167,7 @@ public void callback(int xcommand_handle, int err, int listener_handle) { int listenerHandle = listener.getListenerHandle(); int walletHandle = wallet.getWalletHandle(); - int result = LibSovrin.api.sovrin_agent_remove_identity( + int result = LibIndy.api.indy_agent_remove_identity( FIXED_COMMAND_HANDLE, listenerHandle, walletHandle, @@ -181,7 +181,7 @@ public void callback(int xcommand_handle, int err, int listener_handle) { public static Future agentSend( Agent.Connection connection, - String message) throws SovrinException { + String message) throws IndyException { final CompletableFuture future = new CompletableFuture<> (); @@ -199,7 +199,7 @@ public void callback(int xcommand_handle, int err) { int connectionHandle = connection.getConnectionHandle(); - int result = LibSovrin.api.sovrin_agent_send( + int result = LibIndy.api.indy_agent_send( FIXED_COMMAND_HANDLE, connectionHandle, message, @@ -211,7 +211,7 @@ public void callback(int xcommand_handle, int err) { } public static Future agentCloseConnection( - Agent.Connection connection) throws SovrinException { + Agent.Connection connection) throws IndyException { final CompletableFuture future = new CompletableFuture<> (); @@ -229,7 +229,7 @@ public void callback(int xcommand_handle, int err) { int connectionHandle = connection.getConnectionHandle(); - int result = LibSovrin.api.sovrin_agent_close_connection( + int result = LibIndy.api.indy_agent_close_connection( FIXED_COMMAND_HANDLE, connectionHandle, cb); @@ -240,7 +240,7 @@ public void callback(int xcommand_handle, int err) { } public static Future agentCloseListener( - Agent.Listener listener) throws SovrinException { + Agent.Listener listener) throws IndyException { final CompletableFuture future = new CompletableFuture<> (); @@ -258,7 +258,7 @@ public void callback(int xcommand_handle, int err) { int listenerHandle = listener.getListenerHandle(); - int result = LibSovrin.api.sovrin_agent_close_connection( + int result = LibIndy.api.indy_agent_close_connection( FIXED_COMMAND_HANDLE, listenerHandle, cb); @@ -286,12 +286,12 @@ public int getConnectionHandle() { return this.connectionHandle; } - public Future agentSend(String message) throws SovrinException { + public Future agentSend(String message) throws IndyException { return Agent.agentSend(this, message); } - public Future agentCloseConnection() throws SovrinException { + public Future agentCloseConnection() throws IndyException { return Agent.agentCloseConnection(this); } @@ -311,17 +311,17 @@ public int getListenerHandle() { return this.listenerHandle; } - public Future agentAddIdentity(Pool pool, Wallet wallet, String did, Callback connectionCb, Callback messageCb) throws SovrinException { + public Future agentAddIdentity(Pool pool, Wallet wallet, String did, Callback connectionCb, Callback messageCb) throws IndyException { return Agent.agentAddIdentity(this, pool, wallet, did, connectionCb, messageCb); } - public Future agentRemoveIdentity(Wallet wallet, String did, Callback connectionCb, Callback messageCb) throws SovrinException { + public Future agentRemoveIdentity(Wallet wallet, String did, Callback connectionCb, Callback messageCb) throws IndyException { return Agent.agentRemoveIdentity(this, wallet, did, connectionCb, messageCb); } - public Future agentCloseListener() throws SovrinException { + public Future agentCloseListener() throws IndyException { return Agent.agentCloseListener(this); } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentResults.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentResults.java index c54f812504..e265989528 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentResults.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentResults.java @@ -1,6 +1,6 @@ package org.hyperledger.indy.sdk.agent; -import org.hyperledger.indy.sdk.SovrinJava; +import org.hyperledger.indy.sdk.IndyJava; /** * agent.rs results @@ -11,41 +11,41 @@ private AgentResults() { } - public static class AgentConnectResult extends SovrinJava.Result { + public static class AgentConnectResult extends IndyJava.Result { private Agent.Connection connection; AgentConnectResult(Agent.Connection connection) { this.connection = connection; } public Agent.Connection getConnection() { return this.connection; } } - public static class AgentListenResult extends SovrinJava.Result { + public static class AgentListenResult extends IndyJava.Result { private Agent.Listener listener; AgentListenResult(Agent.Listener listener) { this.listener = listener; } public Agent.Listener getListener() { return this.listener; } } - public static class AgentSendResult extends SovrinJava.Result { + public static class AgentSendResult extends IndyJava.Result { AgentSendResult() { } } - public static class AgentAddIdentityResult extends SovrinJava.Result { + public static class AgentAddIdentityResult extends IndyJava.Result { AgentAddIdentityResult() { } } - public static class AgentRemoveIdentityResult extends SovrinJava.Result { + public static class AgentRemoveIdentityResult extends IndyJava.Result { AgentRemoveIdentityResult() { } } - public static class AgentCloseConnectionResult extends SovrinJava.Result { + public static class AgentCloseConnectionResult extends IndyJava.Result { AgentCloseConnectionResult() { } } - public static class AgentCloseListenerResult extends SovrinJava.Result { + public static class AgentCloseListenerResult extends IndyJava.Result { AgentCloseListenerResult() { } } From a7b0eaaf4d6d9fe62f3dd3e503d61e75498d7d6f Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Tue, 11 Jul 2017 15:21:31 +0200 Subject: [PATCH 068/349] remove connectionCb and messageCb parameters from agentAddIdentity() and agentRemoveIdentity() --- .../org/hyperledger/indy/sdk/agent/Agent.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java index d1c51b51c9..503f5b3613 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java @@ -108,9 +108,7 @@ public static Future agentAddIdentity( Agent.Listener listener, Pool pool, Wallet wallet, - String did, - Callback connectionCb, - Callback messageCb) throws IndyException { + String did) throws IndyException { final CompletableFuture future = new CompletableFuture<> (); @@ -146,9 +144,7 @@ public void callback(int xcommand_handle, int err, int listener_handle) { public static Future agentRemoveIdentity( Agent.Listener listener, Wallet wallet, - String did, - Callback connectionCb, - Callback messageCb) throws IndyException { + String did) throws IndyException { final CompletableFuture future = new CompletableFuture<> (); @@ -311,14 +307,14 @@ public int getListenerHandle() { return this.listenerHandle; } - public Future agentAddIdentity(Pool pool, Wallet wallet, String did, Callback connectionCb, Callback messageCb) throws IndyException { + public Future agentAddIdentity(Pool pool, Wallet wallet, String did) throws IndyException { - return Agent.agentAddIdentity(this, pool, wallet, did, connectionCb, messageCb); + return Agent.agentAddIdentity(this, pool, wallet, did); } - public Future agentRemoveIdentity(Wallet wallet, String did, Callback connectionCb, Callback messageCb) throws IndyException { + public Future agentRemoveIdentity(Wallet wallet, String did) throws IndyException { - return Agent.agentRemoveIdentity(this, wallet, did, connectionCb, messageCb); + return Agent.agentRemoveIdentity(this, wallet, did); } public Future agentCloseListener() throws IndyException { From 2c8fc025ae72f0b1d1737f13dee81710b84d0ba5 Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Tue, 11 Jul 2017 15:23:51 +0200 Subject: [PATCH 069/349] changing result type from Future to CompletableFuture in all methods --- .../org/hyperledger/indy/sdk/agent/Agent.java | 25 +++++++++-------- .../indy/sdk/anoncreds/Anoncreds.java | 15 +++++------ .../hyperledger/indy/sdk/ledger/Ledger.java | 27 +++++++++---------- .../org/hyperledger/indy/sdk/pool/Pool.java | 17 ++++++------ .../hyperledger/indy/sdk/signus/Signus.java | 17 ++++++------ .../hyperledger/indy/sdk/wallet/Wallet.java | 19 +++++++------ 6 files changed, 57 insertions(+), 63 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java index 503f5b3613..d4059c6175 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java @@ -1,7 +1,6 @@ package org.hyperledger.indy.sdk.agent; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; import org.hyperledger.indy.sdk.IndyException; import org.hyperledger.indy.sdk.IndyJava; @@ -31,7 +30,7 @@ private Agent() { * STATIC METHODS */ - public static Future agentConnect( + public static CompletableFuture agentConnect( Pool pool, Wallet wallet, String senderDid, @@ -71,7 +70,7 @@ public void callback(int xcommand_handle, int err, int connection_handle) { return future; } - public static Future agentListen( + public static CompletableFuture agentListen( String endpoint, Callback connectionCb, Callback messageCb) throws IndyException { @@ -104,7 +103,7 @@ public void callback(int xcommand_handle, int err, int listener_handle) { return future; } - public static Future agentAddIdentity( + public static CompletableFuture agentAddIdentity( Agent.Listener listener, Pool pool, Wallet wallet, @@ -141,7 +140,7 @@ public void callback(int xcommand_handle, int err, int listener_handle) { return future; } - public static Future agentRemoveIdentity( + public static CompletableFuture agentRemoveIdentity( Agent.Listener listener, Wallet wallet, String did) throws IndyException { @@ -175,7 +174,7 @@ public void callback(int xcommand_handle, int err, int listener_handle) { return future; } - public static Future agentSend( + public static CompletableFuture agentSend( Agent.Connection connection, String message) throws IndyException { @@ -206,7 +205,7 @@ public void callback(int xcommand_handle, int err) { return future; } - public static Future agentCloseConnection( + public static CompletableFuture agentCloseConnection( Agent.Connection connection) throws IndyException { final CompletableFuture future = new CompletableFuture<> (); @@ -235,7 +234,7 @@ public void callback(int xcommand_handle, int err) { return future; } - public static Future agentCloseListener( + public static CompletableFuture agentCloseListener( Agent.Listener listener) throws IndyException { final CompletableFuture future = new CompletableFuture<> (); @@ -282,12 +281,12 @@ public int getConnectionHandle() { return this.connectionHandle; } - public Future agentSend(String message) throws IndyException { + public CompletableFuture agentSend(String message) throws IndyException { return Agent.agentSend(this, message); } - public Future agentCloseConnection() throws IndyException { + public CompletableFuture agentCloseConnection() throws IndyException { return Agent.agentCloseConnection(this); } @@ -307,17 +306,17 @@ public int getListenerHandle() { return this.listenerHandle; } - public Future agentAddIdentity(Pool pool, Wallet wallet, String did) throws IndyException { + public CompletableFuture agentAddIdentity(Pool pool, Wallet wallet, String did) throws IndyException { return Agent.agentAddIdentity(this, pool, wallet, did); } - public Future agentRemoveIdentity(Wallet wallet, String did) throws IndyException { + public CompletableFuture agentRemoveIdentity(Wallet wallet, String did) throws IndyException { return Agent.agentRemoveIdentity(this, wallet, did); } - public Future agentCloseListener() throws IndyException { + public CompletableFuture agentCloseListener() throws IndyException { return Agent.agentCloseListener(this); } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java index 943093f973..77b6d15ca3 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java @@ -1,11 +1,10 @@ package org.hyperledger.indy.sdk.anoncreds; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; import org.hyperledger.indy.sdk.IndyException; -import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.IndyJava; +import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.anoncreds.AnoncredsResults.IssuerCreateAndStoreClaimDefResult; import org.hyperledger.indy.sdk.anoncreds.AnoncredsResults.IssuerCreateAndStoreRevocRegResult; import org.hyperledger.indy.sdk.anoncreds.AnoncredsResults.IssuerCreateClaimResult; @@ -29,7 +28,7 @@ private Anoncreds() { * STATIC METHODS */ - public static Future issuerCreateAndStoreClaimDef( + public static CompletableFuture issuerCreateAndStoreClaimDef( Wallet wallet, String schemaJson, String signatureType, @@ -64,7 +63,7 @@ public void callback(int xcommand_handle, int err, String claim_def_json, String return future; } - public static Future issuerCreateAndStoreRevocReg( + public static CompletableFuture issuerCreateAndStoreRevocReg( Wallet wallet, int claimDefSeqNo, int maxClaimNum) throws IndyException { @@ -97,7 +96,7 @@ public void callback(int xcommand_handle, int err, String revoc_reg_json, String return future; } - public static Future issuerCreateClaim( + public static CompletableFuture issuerCreateClaim( Wallet wallet, String claimReqJson, String claimJson, @@ -134,7 +133,7 @@ public void callback(int xcommand_handle, int err, String revoc_reg_update_json, return future; } - public static Future issuerRevokeClaim( + public static CompletableFuture issuerRevokeClaim( Wallet wallet, int claimDefSeqNo, int revocRegSeqNo, @@ -169,7 +168,7 @@ public void callback(int xcommand_handle, int err, String revoc_reg_update_json) return future; } - public static Future proverStoreClaimOffer( + public static CompletableFuture proverStoreClaimOffer( Wallet wallet, String claimOfferJson) throws IndyException { @@ -200,7 +199,7 @@ public void callback(int xcommand_handle, int err) { return future; } - public static Future proverGetClaimOffers( + public static CompletableFuture proverGetClaimOffers( Wallet wallet, String filterJson) throws IndyException { diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java index 3a6c9347c2..98f501d1f8 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java @@ -1,11 +1,10 @@ package org.hyperledger.indy.sdk.ledger; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; import org.hyperledger.indy.sdk.IndyException; -import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.IndyJava; +import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.ledger.LedgerResults.BuildAttribRequestResult; import org.hyperledger.indy.sdk.ledger.LedgerResults.BuildClaimDefTxnResult; import org.hyperledger.indy.sdk.ledger.LedgerResults.BuildGetAttribRequestResult; @@ -36,7 +35,7 @@ private Ledger() { * STATIC METHODS */ - public static Future signAndSubmitRequest( + public static CompletableFuture signAndSubmitRequest( Pool pool, Wallet wallet, String submitterDid, @@ -72,7 +71,7 @@ public void callback(int xcommand_handle, int err, String request_result_json) { return future; } - public static Future submitRequest( + public static CompletableFuture submitRequest( Pool pool, String requestJson) throws IndyException { @@ -103,7 +102,7 @@ public void callback(int xcommand_handle, int err, String request_result_json) { return future; } - public static Future buildGetDdoRequest( + public static CompletableFuture buildGetDdoRequest( String submitterDid, String targetDid, String requestJson) throws IndyException { @@ -133,7 +132,7 @@ public void callback(int xcommand_handle, int err, String request_json) { return future; } - public static Future buildNymRequest( + public static CompletableFuture buildNymRequest( String submitterDid, String targetDid, String verkey, @@ -168,7 +167,7 @@ public void callback(int xcommand_handle, int err, String request_json) { return future; } - public static Future buildAttribRequest( + public static CompletableFuture buildAttribRequest( String submitterDid, String targetDid, String hash, @@ -203,7 +202,7 @@ public void callback(int xcommand_handle, int err, String request_json) { return future; } - public static Future buildGetAttribRequest( + public static CompletableFuture buildGetAttribRequest( String submitterDid, String targetDid, String data) throws IndyException { @@ -234,7 +233,7 @@ public void callback(int xcommand_handle, int err, String request_json) { return future; } - public static Future buildGetNymRequest( + public static CompletableFuture buildGetNymRequest( String submitterDid, String targetDid) throws IndyException { @@ -263,7 +262,7 @@ public void callback(int xcommand_handle, int err, String request_json) { return future; } - public static Future buildSchemaRequest( + public static CompletableFuture buildSchemaRequest( String submitterDid, String data) throws IndyException { @@ -292,7 +291,7 @@ public void callback(int xcommand_handle, int err, String request_json) { return future; } - public static Future buildGetSchemaRequest( + public static CompletableFuture buildGetSchemaRequest( String submitterDid, String data) throws IndyException { @@ -321,7 +320,7 @@ public void callback(int xcommand_handle, int err, String request_json) { return future; } - public static Future buildClaimDefTxn( + public static CompletableFuture buildClaimDefTxn( String submitterDid, String xref, String data) throws IndyException { @@ -352,7 +351,7 @@ public void callback(int xcommand_handle, int err, String request_json) { return future; } - public static Future buildGetClaimDefTxn( + public static CompletableFuture buildGetClaimDefTxn( String submitterDid, String xref) throws IndyException { @@ -381,7 +380,7 @@ public void callback(int xcommand_handle, int err, String request_json) { return future; } - public static Future buildNodeRequest( + public static CompletableFuture buildNodeRequest( String submitterDid, String targetDid, String data) throws IndyException { diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java index e53e38819a..45cc8daa0e 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java @@ -1,11 +1,10 @@ package org.hyperledger.indy.sdk.pool; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; import org.hyperledger.indy.sdk.IndyException; -import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.IndyJava; +import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.pool.PoolJSONParameters.CreatePoolLedgerConfigJSONParameter; import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; import org.hyperledger.indy.sdk.pool.PoolResults.ClosePoolLedgerResult; @@ -37,7 +36,7 @@ public int getPoolHandle() { * STATIC METHODS */ - public static Future createPoolLedgerConfig( + public static CompletableFuture createPoolLedgerConfig( String configName, CreatePoolLedgerConfigJSONParameter config) throws IndyException { @@ -66,7 +65,7 @@ public void callback(int xcommand_handle, int err) { return future; } - public static Future openPoolLedger( + public static CompletableFuture openPoolLedger( String configName, OpenPoolLedgerJSONParameter config) throws IndyException { @@ -97,7 +96,7 @@ public void callback(int xcommand_handle, int err, int pool_handle) { return future; } - private static Future refreshPoolLedger( + private static CompletableFuture refreshPoolLedger( Pool pool) throws IndyException { final CompletableFuture future = new CompletableFuture<> (); @@ -126,7 +125,7 @@ public void callback(int xcommand_handle, int err) { return future; } - private static Future closePoolLedger( + private static CompletableFuture closePoolLedger( Pool pool) throws IndyException { final CompletableFuture future = new CompletableFuture<> (); @@ -155,7 +154,7 @@ public void callback(int xcommand_handle, int err) { return future; } - public static Future deletePoolLedgerConfig( + public static CompletableFuture deletePoolLedgerConfig( String configName) throws IndyException { final CompletableFuture future = new CompletableFuture<> (); @@ -186,13 +185,13 @@ public void callback(int xcommand_handle, int err) { * INSTANCE METHODS */ - public Future refreshPoolLedger( + public CompletableFuture refreshPoolLedger( ) throws IndyException { return refreshPoolLedger(this); } - public Future closePoolLedger( + public CompletableFuture closePoolLedger( ) throws IndyException { return closePoolLedger(this); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java index b6899e64bc..48ab83744f 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java @@ -1,11 +1,10 @@ package org.hyperledger.indy.sdk.signus; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; import org.hyperledger.indy.sdk.IndyException; -import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.IndyJava; +import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.signus.SignusJSONParameters.CreateAndStoreMyDidJSONParameter; import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; @@ -32,7 +31,7 @@ private Signus() { * STATIC METHODS */ - public static Future createAndStoreMyDid( + public static CompletableFuture createAndStoreMyDid( Wallet wallet, CreateAndStoreMyDidJSONParameter didJson) throws IndyException { @@ -63,7 +62,7 @@ public void callback(int xcommand_handle, int err, String did, String verkey, St return future; } - public static Future replaceKeys( + public static CompletableFuture replaceKeys( Wallet wallet, String did, String identityJson) throws IndyException { @@ -96,7 +95,7 @@ public void callback(int xcommand_handle, int err, String verkey, String pk) { return future; } - public static Future storeTheirDid( + public static CompletableFuture storeTheirDid( Wallet wallet, String identityJson) throws IndyException { @@ -127,7 +126,7 @@ public void callback(int xcommand_handle, int err) { return future; } - public static Future sign( + public static CompletableFuture sign( Wallet wallet, String did, String msg) throws IndyException { @@ -160,7 +159,7 @@ public void callback(int xcommand_handle, int err, String signature) { return future; } - public static Future verifySignature( + public static CompletableFuture verifySignature( Wallet wallet, Pool pool, String did, @@ -196,7 +195,7 @@ public void callback(int xcommand_handle, int err, boolean valid) { return future; } - public static Future encrypt( + public static CompletableFuture encrypt( Wallet wallet, String did, String msg) throws IndyException { @@ -229,7 +228,7 @@ public void callback(int xcommand_handle, int err, String encryptedMsg) { return future; } - public static Future decrypt( + public static CompletableFuture decrypt( Wallet wallet, String did, String encryptedMsg) throws IndyException { diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java index 690058cf68..26d5c9f2c9 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java @@ -1,11 +1,10 @@ package org.hyperledger.indy.sdk.wallet; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; import org.hyperledger.indy.sdk.IndyException; -import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.IndyJava; +import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.wallet.WalletResults.CloseWalletResult; import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; import org.hyperledger.indy.sdk.wallet.WalletResults.DeleteWalletResult; @@ -36,10 +35,10 @@ public int getWalletHandle() { */ /* IMPLEMENT LATER - * public Future<...> registerWalletType( + * public CompletableFuture<...> registerWalletType( ...) throws IndyException;*/ - public static Future createWallet( + public static CompletableFuture createWallet( String poolName, String name, String xtype, @@ -74,7 +73,7 @@ public void callback(int xcommand_handle, int err) { return future; } - public static Future openWallet( + public static CompletableFuture openWallet( String name, String runtimeConfig, String credentials) throws IndyException { @@ -107,7 +106,7 @@ public void callback(int xcommand_handle, int err, int handle) { return future; } - private static Future closeWallet( + private static CompletableFuture closeWallet( Wallet wallet) throws IndyException { final CompletableFuture future = new CompletableFuture<> (); @@ -136,7 +135,7 @@ public void callback(int xcommand_handle, int err) { return future; } - public static Future deleteWallet( + public static CompletableFuture deleteWallet( String name, String credentials) throws IndyException { @@ -165,7 +164,7 @@ public void callback(int xcommand_handle, int err) { return future; } - private static Future walletSetSeqNoForValue( + private static CompletableFuture walletSetSeqNoForValue( Wallet wallet, String walletKey, String configName) throws IndyException { @@ -201,13 +200,13 @@ public void callback(int xcommand_handle, int err) { * INSTANCE METHODS */ - public Future closeWallet( + public CompletableFuture closeWallet( ) throws IndyException { return closeWallet(this); } - public Future walletSetSeqNoForValue( + public CompletableFuture walletSetSeqNoForValue( String walletKey, String configName) throws IndyException { From 14326b46f870c2ce5d84ce6b480b1a4249e596d0 Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Tue, 11 Jul 2017 16:30:03 +0200 Subject: [PATCH 070/349] only wrap result in dedicated class in case of tuples --- .../org/hyperledger/indy/sdk/IndyJava.java | 4 +- .../org/hyperledger/indy/sdk/agent/Agent.java | 63 ++++++-------- .../indy/sdk/agent/AgentResults.java | 41 --------- .../indy/sdk/anoncreds/Anoncreds.java | 30 +++---- .../indy/sdk/anoncreds/AnoncredsResults.java | 72 ---------------- .../hyperledger/indy/sdk/ledger/Ledger.java | 84 ++++++++---------- .../indy/sdk/ledger/LedgerResults.java | 86 ------------------- .../org/hyperledger/indy/sdk/pool/Pool.java | 41 ++++----- .../indy/sdk/pool/PoolResults.java | 29 ------- .../hyperledger/indy/sdk/wallet/Wallet.java | 41 ++++----- .../indy/sdk/wallet/WalletResults.java | 29 ------- .../org/hyperledger/indy/sdk/LedgerTest.java | 13 +-- .../org/hyperledger/indy/sdk/PoolTest.java | 6 +- .../org/hyperledger/indy/sdk/SignusTest.java | 5 +- .../org/hyperledger/indy/sdk/WalletTest.java | 21 ++--- 15 files changed, 124 insertions(+), 441 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java index 9411673107..758c96fa3a 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java @@ -24,7 +24,7 @@ public static class API { protected static final int FIXED_COMMAND_HANDLE = 0; - protected static boolean checkCallback(CompletableFuture future, int xcommand_handle, int err) { + protected static boolean checkCallback(CompletableFuture future, int xcommand_handle, int err) { assert(xcommand_handle == FIXED_COMMAND_HANDLE); @@ -34,7 +34,7 @@ protected static boolean checkCallback(CompletableFuture future, int err) { + protected static boolean checkCallback(CompletableFuture future, int err) { ErrorCode errorCode = ErrorCode.valueOf(err); if (! ErrorCode.Success.equals(errorCode)) { future.completeExceptionally(IndyException.fromErrorCode(errorCode, err)); return false; } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java index d4059c6175..915c46dbce 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java @@ -5,13 +5,6 @@ import org.hyperledger.indy.sdk.IndyException; import org.hyperledger.indy.sdk.IndyJava; import org.hyperledger.indy.sdk.LibIndy; -import org.hyperledger.indy.sdk.agent.AgentResults.AgentAddIdentityResult; -import org.hyperledger.indy.sdk.agent.AgentResults.AgentCloseConnectionResult; -import org.hyperledger.indy.sdk.agent.AgentResults.AgentCloseListenerResult; -import org.hyperledger.indy.sdk.agent.AgentResults.AgentConnectResult; -import org.hyperledger.indy.sdk.agent.AgentResults.AgentListenResult; -import org.hyperledger.indy.sdk.agent.AgentResults.AgentRemoveIdentityResult; -import org.hyperledger.indy.sdk.agent.AgentResults.AgentSendResult; import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.wallet.Wallet; @@ -30,14 +23,14 @@ private Agent() { * STATIC METHODS */ - public static CompletableFuture agentConnect( + public static CompletableFuture agentConnect( Pool pool, Wallet wallet, String senderDid, String receiverDid, Callback messageCb) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback connectionCb = new Callback() { @@ -46,9 +39,7 @@ public void callback(int xcommand_handle, int err, int connection_handle) { if (! checkCallback(future, xcommand_handle, err)) return; - Agent.Connection connection = new Agent.Connection(connection_handle); - - AgentConnectResult result = new AgentConnectResult(connection); + Agent.Connection result = new Agent.Connection(connection_handle); future.complete(result); } }; @@ -70,12 +61,12 @@ public void callback(int xcommand_handle, int err, int connection_handle) { return future; } - public static CompletableFuture agentListen( + public static CompletableFuture agentListen( String endpoint, Callback connectionCb, Callback messageCb) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback listenerCb = new Callback() { @@ -84,9 +75,7 @@ public void callback(int xcommand_handle, int err, int listener_handle) { if (! checkCallback(future, xcommand_handle, err)) return; - Agent.Listener connection = new Agent.Listener(listener_handle); - - AgentListenResult result = new AgentListenResult(connection); + Agent.Listener result = new Agent.Listener(listener_handle); future.complete(result); } }; @@ -103,13 +92,13 @@ public void callback(int xcommand_handle, int err, int listener_handle) { return future; } - public static CompletableFuture agentAddIdentity( + public static CompletableFuture agentAddIdentity( Agent.Listener listener, Pool pool, Wallet wallet, String did) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback addIdentityCb = new Callback() { @@ -118,7 +107,7 @@ public void callback(int xcommand_handle, int err, int listener_handle) { if (! checkCallback(future, xcommand_handle, err)) return; - AgentAddIdentityResult result = new AgentAddIdentityResult(); + Void result = null; future.complete(result); } }; @@ -140,12 +129,12 @@ public void callback(int xcommand_handle, int err, int listener_handle) { return future; } - public static CompletableFuture agentRemoveIdentity( + public static CompletableFuture agentRemoveIdentity( Agent.Listener listener, Wallet wallet, String did) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback rmIdentityCb = new Callback() { @@ -154,7 +143,7 @@ public void callback(int xcommand_handle, int err, int listener_handle) { if (! checkCallback(future, xcommand_handle, err)) return; - AgentRemoveIdentityResult result = new AgentRemoveIdentityResult(); + Void result = null; future.complete(result); } }; @@ -174,11 +163,11 @@ public void callback(int xcommand_handle, int err, int listener_handle) { return future; } - public static CompletableFuture agentSend( + public static CompletableFuture agentSend( Agent.Connection connection, String message) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -187,7 +176,7 @@ public void callback(int xcommand_handle, int err) { if (! checkCallback(future, xcommand_handle, err)) return; - AgentSendResult result = new AgentSendResult(); + Void result = null; future.complete(result); } }; @@ -205,10 +194,10 @@ public void callback(int xcommand_handle, int err) { return future; } - public static CompletableFuture agentCloseConnection( + public static CompletableFuture agentCloseConnection( Agent.Connection connection) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -217,7 +206,7 @@ public void callback(int xcommand_handle, int err) { if (! checkCallback(future, xcommand_handle, err)) return; - AgentCloseConnectionResult result = new AgentCloseConnectionResult(); + Void result = null; future.complete(result); } }; @@ -234,10 +223,10 @@ public void callback(int xcommand_handle, int err) { return future; } - public static CompletableFuture agentCloseListener( + public static CompletableFuture agentCloseListener( Agent.Listener listener) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -246,7 +235,7 @@ public void callback(int xcommand_handle, int err) { if (! checkCallback(future, xcommand_handle, err)) return; - AgentCloseListenerResult result = new AgentCloseListenerResult(); + Void result = null; future.complete(result); } }; @@ -281,12 +270,12 @@ public int getConnectionHandle() { return this.connectionHandle; } - public CompletableFuture agentSend(String message) throws IndyException { + public CompletableFuture agentSend(String message) throws IndyException { return Agent.agentSend(this, message); } - public CompletableFuture agentCloseConnection() throws IndyException { + public CompletableFuture agentCloseConnection() throws IndyException { return Agent.agentCloseConnection(this); } @@ -306,17 +295,17 @@ public int getListenerHandle() { return this.listenerHandle; } - public CompletableFuture agentAddIdentity(Pool pool, Wallet wallet, String did) throws IndyException { + public CompletableFuture agentAddIdentity(Pool pool, Wallet wallet, String did) throws IndyException { return Agent.agentAddIdentity(this, pool, wallet, did); } - public CompletableFuture agentRemoveIdentity(Wallet wallet, String did) throws IndyException { + public CompletableFuture agentRemoveIdentity(Wallet wallet, String did) throws IndyException { return Agent.agentRemoveIdentity(this, wallet, did); } - public CompletableFuture agentCloseListener() throws IndyException { + public CompletableFuture agentCloseListener() throws IndyException { return Agent.agentCloseListener(this); } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentResults.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentResults.java index e265989528..5600668712 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentResults.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentResults.java @@ -1,7 +1,5 @@ package org.hyperledger.indy.sdk.agent; -import org.hyperledger.indy.sdk.IndyJava; - /** * agent.rs results */ @@ -10,43 +8,4 @@ public final class AgentResults { private AgentResults() { } - - public static class AgentConnectResult extends IndyJava.Result { - - private Agent.Connection connection; - AgentConnectResult(Agent.Connection connection) { this.connection = connection; } - public Agent.Connection getConnection() { return this.connection; } - } - - public static class AgentListenResult extends IndyJava.Result { - - private Agent.Listener listener; - AgentListenResult(Agent.Listener listener) { this.listener = listener; } - public Agent.Listener getListener() { return this.listener; } - } - - public static class AgentSendResult extends IndyJava.Result { - - AgentSendResult() { } - } - - public static class AgentAddIdentityResult extends IndyJava.Result { - - AgentAddIdentityResult() { } - } - - public static class AgentRemoveIdentityResult extends IndyJava.Result { - - AgentRemoveIdentityResult() { } - } - - public static class AgentCloseConnectionResult extends IndyJava.Result { - - AgentCloseConnectionResult() { } - } - - public static class AgentCloseListenerResult extends IndyJava.Result { - - AgentCloseListenerResult() { } - } } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java index 77b6d15ca3..491a503b25 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java @@ -5,12 +5,8 @@ import org.hyperledger.indy.sdk.IndyException; import org.hyperledger.indy.sdk.IndyJava; import org.hyperledger.indy.sdk.LibIndy; -import org.hyperledger.indy.sdk.anoncreds.AnoncredsResults.IssuerCreateAndStoreClaimDefResult; import org.hyperledger.indy.sdk.anoncreds.AnoncredsResults.IssuerCreateAndStoreRevocRegResult; import org.hyperledger.indy.sdk.anoncreds.AnoncredsResults.IssuerCreateClaimResult; -import org.hyperledger.indy.sdk.anoncreds.AnoncredsResults.IssuerRevokeClaimResult; -import org.hyperledger.indy.sdk.anoncreds.AnoncredsResults.ProverGetClaimOffersResult; -import org.hyperledger.indy.sdk.anoncreds.AnoncredsResults.ProverStoreClaimOfferResult; import org.hyperledger.indy.sdk.wallet.Wallet; import com.sun.jna.Callback; @@ -28,22 +24,22 @@ private Anoncreds() { * STATIC METHODS */ - public static CompletableFuture issuerCreateAndStoreClaimDef( + public static CompletableFuture issuerCreateAndStoreClaimDef( Wallet wallet, String schemaJson, String signatureType, boolean createNonRevoc) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String claim_def_json, String claim_def_uuid) { + public void callback(int xcommand_handle, int err, String claim_def_json) { if (! checkCallback(future, xcommand_handle, err)) return; - IssuerCreateAndStoreClaimDefResult result = new IssuerCreateAndStoreClaimDefResult(claim_def_json, claim_def_uuid); + String result = claim_def_json, claim_def_uuid; future.complete(result); } }; @@ -133,13 +129,13 @@ public void callback(int xcommand_handle, int err, String revoc_reg_update_json, return future; } - public static CompletableFuture issuerRevokeClaim( + public static CompletableFuture issuerRevokeClaim( Wallet wallet, int claimDefSeqNo, int revocRegSeqNo, int userRevocIndex) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -148,7 +144,7 @@ public void callback(int xcommand_handle, int err, String revoc_reg_update_json) if (! checkCallback(future, xcommand_handle, err)) return; - IssuerRevokeClaimResult result = new IssuerRevokeClaimResult(revoc_reg_update_json); + String result = revoc_reg_update_json; future.complete(result); } }; @@ -168,11 +164,11 @@ public void callback(int xcommand_handle, int err, String revoc_reg_update_json) return future; } - public static CompletableFuture proverStoreClaimOffer( + public static CompletableFuture proverStoreClaimOffer( Wallet wallet, String claimOfferJson) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -181,7 +177,7 @@ public void callback(int xcommand_handle, int err) { if (! checkCallback(future, xcommand_handle, err)) return; - ProverStoreClaimOfferResult result = new ProverStoreClaimOfferResult(); + Void result = null; future.complete(result); } }; @@ -199,11 +195,11 @@ public void callback(int xcommand_handle, int err) { return future; } - public static CompletableFuture proverGetClaimOffers( + public static CompletableFuture proverGetClaimOffers( Wallet wallet, String filterJson) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -212,7 +208,7 @@ public void callback(int xcommand_handle, int err, String claim_offers_json) { if (! checkCallback(future, xcommand_handle, err)) return; - ProverGetClaimOffersResult result = new ProverGetClaimOffersResult(claim_offers_json); + String result = claim_offers_json; future.complete(result); } }; diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/AnoncredsResults.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/AnoncredsResults.java index cb60994d94..8d784db27d 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/AnoncredsResults.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/AnoncredsResults.java @@ -11,14 +11,6 @@ private AnoncredsResults() { } - public static class IssuerCreateAndStoreClaimDefResult extends IndyJava.Result { - - private String claimDefJson, claimDefUuid; - IssuerCreateAndStoreClaimDefResult(String claimDefJson, String claimDefUuid) { this.claimDefJson = claimDefJson; this.claimDefUuid = claimDefUuid; } - public String getClaimDefJson() { return this.claimDefJson; } - public String getClaimDefUuid() { return this.claimDefUuid; } - } - public static class IssuerCreateAndStoreRevocRegResult extends IndyJava.Result { private String revocRegJson, revocRegUuid; @@ -34,68 +26,4 @@ public static class IssuerCreateClaimResult extends IndyJava.Result { public String getRevocRegUpdateJson() { return this.revocRegUpdateJson; } public String getClaimJson() { return this.claimJson; } } - - public static class IssuerRevokeClaimResult extends IndyJava.Result { - - private String revocRegUpdateJson; - IssuerRevokeClaimResult(String revocRegUpdateJson) { this.revocRegUpdateJson = revocRegUpdateJson; } - public String getRevocRegUpdateJson() { return this.revocRegUpdateJson; } - } - - public static class ProverStoreClaimOfferResult extends IndyJava.Result { - - ProverStoreClaimOfferResult() { } - } - - public static class ProverGetClaimOffersResult extends IndyJava.Result { - - private String claimOffersJson; - ProverGetClaimOffersResult(String claimOffersJson) { this.claimOffersJson = claimOffersJson; } - public String getClaimOffersJson() { return this.claimOffersJson; } - } - - public static class ProverCreateMasterSecretResult extends IndyJava.Result { - - ProverCreateMasterSecretResult() { } - } - - public static class ProverCreateAndStoreClaimReqResult extends IndyJava.Result { - - private String claimReqJson; - ProverCreateAndStoreClaimReqResult(String claimReqJson) { this.claimReqJson = claimReqJson; } - public String getClaimReqJson() { return this.claimReqJson; } - } - - public static class ProverStoreClaimResult extends IndyJava.Result { - - ProverStoreClaimResult() { } - } - - public static class ProverGetClaimsResult extends IndyJava.Result { - - private String claimsJson; - ProverGetClaimsResult(String claimsJson) { this.claimsJson = claimsJson; } - public String getClaimsJson() { return this.claimsJson; } - } - - public static class ProverGetClaimsForProofReqResult extends IndyJava.Result { - - private String claimsJson; - ProverGetClaimsForProofReqResult(String claimsJson) { this.claimsJson = claimsJson; } - public String getClaimsJson() { return this.claimsJson; } - } - - public static class ProverCreateProofResult extends IndyJava.Result { - - private String proofJson; - ProverCreateProofResult(String proofJson) { this.proofJson = proofJson; } - public String getProofJson() { return this.proofJson; } - } - - public static class VerifierVerifyProofResult extends IndyJava.Result { - - private boolean valid; - VerifierVerifyProofResult(boolean valid) { this.valid = valid; } - public boolean isValid() { return this.valid; } - } } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java index 98f501d1f8..52a8959c6d 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java @@ -5,18 +5,6 @@ import org.hyperledger.indy.sdk.IndyException; import org.hyperledger.indy.sdk.IndyJava; import org.hyperledger.indy.sdk.LibIndy; -import org.hyperledger.indy.sdk.ledger.LedgerResults.BuildAttribRequestResult; -import org.hyperledger.indy.sdk.ledger.LedgerResults.BuildClaimDefTxnResult; -import org.hyperledger.indy.sdk.ledger.LedgerResults.BuildGetAttribRequestResult; -import org.hyperledger.indy.sdk.ledger.LedgerResults.BuildGetClaimDefTxnResult; -import org.hyperledger.indy.sdk.ledger.LedgerResults.BuildGetDdoRequestResult; -import org.hyperledger.indy.sdk.ledger.LedgerResults.BuildGetNymRequestResult; -import org.hyperledger.indy.sdk.ledger.LedgerResults.BuildGetSchemaRequestResult; -import org.hyperledger.indy.sdk.ledger.LedgerResults.BuildNodeRequestResult; -import org.hyperledger.indy.sdk.ledger.LedgerResults.BuildNymRequestResult; -import org.hyperledger.indy.sdk.ledger.LedgerResults.BuildSchemaRequestResult; -import org.hyperledger.indy.sdk.ledger.LedgerResults.SignAndSubmitRequestResult; -import org.hyperledger.indy.sdk.ledger.LedgerResults.SubmitRequestResult; import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.wallet.Wallet; @@ -35,13 +23,13 @@ private Ledger() { * STATIC METHODS */ - public static CompletableFuture signAndSubmitRequest( + public static CompletableFuture signAndSubmitRequest( Pool pool, Wallet wallet, String submitterDid, String requestJson) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -50,7 +38,7 @@ public void callback(int xcommand_handle, int err, String request_result_json) { if (! checkCallback(future, xcommand_handle, err)) return; - SignAndSubmitRequestResult result = new SignAndSubmitRequestResult(request_result_json); + String result = request_result_json; future.complete(result); } }; @@ -71,11 +59,11 @@ public void callback(int xcommand_handle, int err, String request_result_json) { return future; } - public static CompletableFuture submitRequest( + public static CompletableFuture submitRequest( Pool pool, String requestJson) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -84,7 +72,7 @@ public void callback(int xcommand_handle, int err, String request_result_json) { if (! checkCallback(future, xcommand_handle, err)) return; - SubmitRequestResult result = new SubmitRequestResult(request_result_json); + String result = request_result_json; future.complete(result); } }; @@ -102,12 +90,12 @@ public void callback(int xcommand_handle, int err, String request_result_json) { return future; } - public static CompletableFuture buildGetDdoRequest( + public static CompletableFuture buildGetDdoRequest( String submitterDid, String targetDid, String requestJson) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -116,7 +104,7 @@ public void callback(int xcommand_handle, int err, String request_json) { if (! checkCallback(future, xcommand_handle, err)) return; - BuildGetDdoRequestResult result = new BuildGetDdoRequestResult(request_json); + String result = request_json; future.complete(result); } }; @@ -132,14 +120,14 @@ public void callback(int xcommand_handle, int err, String request_json) { return future; } - public static CompletableFuture buildNymRequest( + public static CompletableFuture buildNymRequest( String submitterDid, String targetDid, String verkey, String alias, String role) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -148,7 +136,7 @@ public void callback(int xcommand_handle, int err, String request_json) { if (! checkCallback(future, xcommand_handle, err)) return; - BuildNymRequestResult result = new BuildNymRequestResult(request_json); + String result = request_json; future.complete(result); } }; @@ -167,14 +155,14 @@ public void callback(int xcommand_handle, int err, String request_json) { return future; } - public static CompletableFuture buildAttribRequest( + public static CompletableFuture buildAttribRequest( String submitterDid, String targetDid, String hash, String raw, String enc) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -183,7 +171,7 @@ public void callback(int xcommand_handle, int err, String request_json) { if (! checkCallback(future, xcommand_handle, err)) return; - BuildAttribRequestResult result = new BuildAttribRequestResult(request_json); + String result = request_json; future.complete(result); } }; @@ -202,12 +190,12 @@ public void callback(int xcommand_handle, int err, String request_json) { return future; } - public static CompletableFuture buildGetAttribRequest( + public static CompletableFuture buildGetAttribRequest( String submitterDid, String targetDid, String data) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -216,7 +204,7 @@ public void callback(int xcommand_handle, int err, String request_json) { if (! checkCallback(future, xcommand_handle, err)) return; - BuildGetAttribRequestResult result = new BuildGetAttribRequestResult(request_json); + String result = request_json; future.complete(result); } }; @@ -233,11 +221,11 @@ public void callback(int xcommand_handle, int err, String request_json) { return future; } - public static CompletableFuture buildGetNymRequest( + public static CompletableFuture buildGetNymRequest( String submitterDid, String targetDid) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -246,7 +234,7 @@ public void callback(int xcommand_handle, int err, String request_json) { if (! checkCallback(future, xcommand_handle, err)) return; - BuildGetNymRequestResult result = new BuildGetNymRequestResult(request_json); + String result = request_json; future.complete(result); } }; @@ -262,11 +250,11 @@ public void callback(int xcommand_handle, int err, String request_json) { return future; } - public static CompletableFuture buildSchemaRequest( + public static CompletableFuture buildSchemaRequest( String submitterDid, String data) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -275,7 +263,7 @@ public void callback(int xcommand_handle, int err, String request_json) { if (! checkCallback(future, xcommand_handle, err)) return; - BuildSchemaRequestResult result = new BuildSchemaRequestResult(request_json); + String result = request_json; future.complete(result); } }; @@ -291,11 +279,11 @@ public void callback(int xcommand_handle, int err, String request_json) { return future; } - public static CompletableFuture buildGetSchemaRequest( + public static CompletableFuture buildGetSchemaRequest( String submitterDid, String data) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -304,7 +292,7 @@ public void callback(int xcommand_handle, int err, String request_json) { if (! checkCallback(future, xcommand_handle, err)) return; - BuildGetSchemaRequestResult result = new BuildGetSchemaRequestResult(request_json); + String result = request_json; future.complete(result); } }; @@ -320,12 +308,12 @@ public void callback(int xcommand_handle, int err, String request_json) { return future; } - public static CompletableFuture buildClaimDefTxn( + public static CompletableFuture buildClaimDefTxn( String submitterDid, String xref, String data) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -334,7 +322,7 @@ public void callback(int xcommand_handle, int err, String request_json) { if (! checkCallback(future, xcommand_handle, err)) return; - BuildClaimDefTxnResult result = new BuildClaimDefTxnResult(request_json); + String result = request_json; future.complete(result); } }; @@ -351,11 +339,11 @@ public void callback(int xcommand_handle, int err, String request_json) { return future; } - public static CompletableFuture buildGetClaimDefTxn( + public static CompletableFuture buildGetClaimDefTxn( String submitterDid, String xref) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -364,7 +352,7 @@ public void callback(int xcommand_handle, int err, String request_json) { if (! checkCallback(future, xcommand_handle, err)) return; - BuildGetClaimDefTxnResult result = new BuildGetClaimDefTxnResult(request_json); + String result = request_json; future.complete(result); } }; @@ -380,12 +368,12 @@ public void callback(int xcommand_handle, int err, String request_json) { return future; } - public static CompletableFuture buildNodeRequest( + public static CompletableFuture buildNodeRequest( String submitterDid, String targetDid, String data) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -394,7 +382,7 @@ public void callback(int xcommand_handle, int err, String request_json) { if (! checkCallback(future, xcommand_handle, err)) return; - BuildNodeRequestResult result = new BuildNodeRequestResult(request_json); + String result = request_json; future.complete(result); } }; diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/LedgerResults.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/LedgerResults.java index 714e83effb..0c7b75c102 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/LedgerResults.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/LedgerResults.java @@ -1,7 +1,5 @@ package org.hyperledger.indy.sdk.ledger; -import org.hyperledger.indy.sdk.IndyJava; - /** * ledger.rs results */ @@ -10,88 +8,4 @@ public final class LedgerResults { private LedgerResults() { } - - public static class SignAndSubmitRequestResult extends IndyJava.Result { - - private String requestResultJson; - SignAndSubmitRequestResult(String requestResultJson) { this.requestResultJson = requestResultJson; } - public String getRequestResultJson() { return this.requestResultJson; } - } - - public static class SubmitRequestResult extends IndyJava.Result { - - private String requestResultJson; - SubmitRequestResult(String requestResultJson) { this.requestResultJson = requestResultJson; } - public String getRequestResultJson() { return this.requestResultJson; } - } - - public static class BuildGetDdoRequestResult extends IndyJava.Result { - - private String requestJson; - BuildGetDdoRequestResult(String requestJson) { this.requestJson = requestJson; } - public String getRequestJson() { return this.requestJson; } - } - - public static class BuildNymRequestResult extends IndyJava.Result { - - private String requestJson; - BuildNymRequestResult(String requestJson) { this.requestJson = requestJson; } - public String getRequestJson() { return this.requestJson; } - } - - public static class BuildAttribRequestResult extends IndyJava.Result { - - private String requestJson; - BuildAttribRequestResult(String requestJson) { this.requestJson = requestJson; } - public String getRequestJson() { return this.requestJson; } - } - - public static class BuildGetAttribRequestResult extends IndyJava.Result { - - private String requestJson; - BuildGetAttribRequestResult(String requestJson) { this.requestJson = requestJson; } - public String getRequestJson() { return this.requestJson; } - } - - public static class BuildGetNymRequestResult extends IndyJava.Result { - - private String requestJson; - BuildGetNymRequestResult(String requestJson) { this.requestJson = requestJson; } - public String getRequestJson() { return this.requestJson; } - } - - public static class BuildSchemaRequestResult extends IndyJava.Result { - - private String requestJson; - BuildSchemaRequestResult(String requestJson) { this.requestJson = requestJson; } - public String getRequestJson() { return this.requestJson; } - } - - public static class BuildGetSchemaRequestResult extends IndyJava.Result { - - private String requestJson; - BuildGetSchemaRequestResult(String requestJson) { this.requestJson = requestJson; } - public String getRequestJson() { return this.requestJson; } - } - - public static class BuildClaimDefTxnResult extends IndyJava.Result { - - private String requestJson; - BuildClaimDefTxnResult(String requestJson) { this.requestJson = requestJson; } - public String getRequestJson() { return this.requestJson; } - } - - public static class BuildGetClaimDefTxnResult extends IndyJava.Result { - - private String requestResultJson; - BuildGetClaimDefTxnResult(String requestResultJson) { this.requestResultJson = requestResultJson; } - public String getRequestResultJson() { return this.requestResultJson; } - } - - public static class BuildNodeRequestResult extends IndyJava.Result { - - private String requestJson; - BuildNodeRequestResult(String requestJson) { this.requestJson = requestJson; } - public String getRequestJson() { return this.requestJson; } - } } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java index 45cc8daa0e..26eff4fdea 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java @@ -7,11 +7,6 @@ import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.pool.PoolJSONParameters.CreatePoolLedgerConfigJSONParameter; import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; -import org.hyperledger.indy.sdk.pool.PoolResults.ClosePoolLedgerResult; -import org.hyperledger.indy.sdk.pool.PoolResults.CreatePoolLedgerConfigResult; -import org.hyperledger.indy.sdk.pool.PoolResults.DeletePoolLedgerConfigResult; -import org.hyperledger.indy.sdk.pool.PoolResults.OpenPoolLedgerResult; -import org.hyperledger.indy.sdk.pool.PoolResults.RefreshPoolLedgerResult; import com.sun.jna.Callback; @@ -36,11 +31,11 @@ public int getPoolHandle() { * STATIC METHODS */ - public static CompletableFuture createPoolLedgerConfig( + public static CompletableFuture createPoolLedgerConfig( String configName, CreatePoolLedgerConfigJSONParameter config) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -49,7 +44,7 @@ public void callback(int xcommand_handle, int err) { if (! checkCallback(future, xcommand_handle, err)) return; - CreatePoolLedgerConfigResult result = new CreatePoolLedgerConfigResult(); + Void result = null; future.complete(result); } }; @@ -65,11 +60,11 @@ public void callback(int xcommand_handle, int err) { return future; } - public static CompletableFuture openPoolLedger( + public static CompletableFuture openPoolLedger( String configName, OpenPoolLedgerJSONParameter config) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -78,9 +73,7 @@ public void callback(int xcommand_handle, int err, int pool_handle) { if (! checkCallback(future, xcommand_handle, err)) return; - Pool pool = new Pool(pool_handle); - - OpenPoolLedgerResult result = new OpenPoolLedgerResult(pool); + Pool result = new Pool(pool_handle); future.complete(result); } }; @@ -96,10 +89,10 @@ public void callback(int xcommand_handle, int err, int pool_handle) { return future; } - private static CompletableFuture refreshPoolLedger( + private static CompletableFuture refreshPoolLedger( Pool pool) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -108,7 +101,7 @@ public void callback(int xcommand_handle, int err) { if (! checkCallback(future, xcommand_handle, err)) return; - RefreshPoolLedgerResult result = new RefreshPoolLedgerResult(); + Void result = null; future.complete(result); } }; @@ -125,10 +118,10 @@ public void callback(int xcommand_handle, int err) { return future; } - private static CompletableFuture closePoolLedger( + private static CompletableFuture closePoolLedger( Pool pool) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -137,7 +130,7 @@ public void callback(int xcommand_handle, int err) { if (! checkCallback(future, xcommand_handle, err)) return; - ClosePoolLedgerResult result = new ClosePoolLedgerResult(); + Void result = null; future.complete(result); } }; @@ -154,10 +147,10 @@ public void callback(int xcommand_handle, int err) { return future; } - public static CompletableFuture deletePoolLedgerConfig( + public static CompletableFuture deletePoolLedgerConfig( String configName) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -166,7 +159,7 @@ public void callback(int xcommand_handle, int err) { if (! checkCallback(future, xcommand_handle, err)) return; - DeletePoolLedgerConfigResult result = new DeletePoolLedgerConfigResult(); + Void result = null; future.complete(result); } }; @@ -185,13 +178,13 @@ public void callback(int xcommand_handle, int err) { * INSTANCE METHODS */ - public CompletableFuture refreshPoolLedger( + public CompletableFuture refreshPoolLedger( ) throws IndyException { return refreshPoolLedger(this); } - public CompletableFuture closePoolLedger( + public CompletableFuture closePoolLedger( ) throws IndyException { return closePoolLedger(this); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/PoolResults.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/PoolResults.java index 6a15c295bc..7cf6e0a931 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/PoolResults.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/PoolResults.java @@ -1,7 +1,5 @@ package org.hyperledger.indy.sdk.pool; -import org.hyperledger.indy.sdk.IndyJava; - /** * pool.rs results */ @@ -10,31 +8,4 @@ public final class PoolResults { private PoolResults() { } - - public static class CreatePoolLedgerConfigResult extends IndyJava.Result { - - CreatePoolLedgerConfigResult() { } - } - - public static class OpenPoolLedgerResult extends IndyJava.Result { - - private Pool pool; - OpenPoolLedgerResult(Pool pool) { this.pool = pool; } - public Pool getPool() { return this.pool; } - } - - public static class RefreshPoolLedgerResult extends IndyJava.Result { - - RefreshPoolLedgerResult() { } - } - - public static class ClosePoolLedgerResult extends IndyJava.Result { - - ClosePoolLedgerResult() { } - } - - public static class DeletePoolLedgerConfigResult extends IndyJava.Result { - - DeletePoolLedgerConfigResult() { } - } } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java index 26d5c9f2c9..60daeebd66 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java @@ -5,11 +5,6 @@ import org.hyperledger.indy.sdk.IndyException; import org.hyperledger.indy.sdk.IndyJava; import org.hyperledger.indy.sdk.LibIndy; -import org.hyperledger.indy.sdk.wallet.WalletResults.CloseWalletResult; -import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; -import org.hyperledger.indy.sdk.wallet.WalletResults.DeleteWalletResult; -import org.hyperledger.indy.sdk.wallet.WalletResults.OpenWalletResult; -import org.hyperledger.indy.sdk.wallet.WalletResults.WalletSetSeqNoForValueResult; import com.sun.jna.Callback; @@ -38,14 +33,14 @@ public int getWalletHandle() { * public CompletableFuture<...> registerWalletType( ...) throws IndyException;*/ - public static CompletableFuture createWallet( + public static CompletableFuture createWallet( String poolName, String name, String xtype, String config, String credentials) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -54,7 +49,7 @@ public void callback(int xcommand_handle, int err) { if (! checkCallback(future, xcommand_handle, err)) return; - CreateWalletResult result = new CreateWalletResult(); + Void result = null; future.complete(result); } }; @@ -73,12 +68,12 @@ public void callback(int xcommand_handle, int err) { return future; } - public static CompletableFuture openWallet( + public static CompletableFuture openWallet( String name, String runtimeConfig, String credentials) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -87,9 +82,7 @@ public void callback(int xcommand_handle, int err, int handle) { if (! checkCallback(future, xcommand_handle, err)) return; - Wallet wallet = new Wallet(handle); - - OpenWalletResult result = new OpenWalletResult(wallet); + Wallet result = new Wallet(handle); future.complete(result); } }; @@ -106,10 +99,10 @@ public void callback(int xcommand_handle, int err, int handle) { return future; } - private static CompletableFuture closeWallet( + private static CompletableFuture closeWallet( Wallet wallet) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -118,7 +111,7 @@ public void callback(int xcommand_handle, int err) { if (! checkCallback(future, xcommand_handle, err)) return; - CloseWalletResult result = new CloseWalletResult(); + Void result = null; future.complete(result); } }; @@ -135,11 +128,11 @@ public void callback(int xcommand_handle, int err) { return future; } - public static CompletableFuture deleteWallet( + public static CompletableFuture deleteWallet( String name, String credentials) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -148,7 +141,7 @@ public void callback(int xcommand_handle, int err) { if (! checkCallback(future, xcommand_handle, err)) return; - DeleteWalletResult result = new DeleteWalletResult(); + Void result = null; future.complete(result); } }; @@ -164,12 +157,12 @@ public void callback(int xcommand_handle, int err) { return future; } - private static CompletableFuture walletSetSeqNoForValue( + private static CompletableFuture walletSetSeqNoForValue( Wallet wallet, String walletKey, String configName) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -178,7 +171,7 @@ public void callback(int xcommand_handle, int err) { if (! checkCallback(future, xcommand_handle, err)) return; - WalletSetSeqNoForValueResult result = new WalletSetSeqNoForValueResult(); + Void result = null; future.complete(result); } }; @@ -200,13 +193,13 @@ public void callback(int xcommand_handle, int err) { * INSTANCE METHODS */ - public CompletableFuture closeWallet( + public CompletableFuture closeWallet( ) throws IndyException { return closeWallet(this); } - public CompletableFuture walletSetSeqNoForValue( + public CompletableFuture walletSetSeqNoForValue( String walletKey, String configName) throws IndyException { diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletResults.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletResults.java index 415ed83317..296aa55515 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletResults.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletResults.java @@ -1,7 +1,5 @@ package org.hyperledger.indy.sdk.wallet; -import org.hyperledger.indy.sdk.IndyJava; - /** * wallet.rs Results */ @@ -10,31 +8,4 @@ public final class WalletResults { private WalletResults() { } - - public static class CreateWalletResult extends IndyJava.Result { - - CreateWalletResult() { } - } - - public static class OpenWalletResult extends IndyJava.Result { - - private Wallet wallet; - OpenWalletResult(Wallet wallet) { this.wallet = wallet; } - public Wallet getWallet() { return this.wallet; } - } - - public static class CloseWalletResult extends IndyJava.Result { - - CloseWalletResult() { } - } - - public static class DeleteWalletResult extends IndyJava.Result { - - DeleteWalletResult() { } - } - - public static class WalletSetSeqNoForValueResult extends IndyJava.Result { - - WalletSetSeqNoForValueResult() { } - } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/LedgerTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/LedgerTest.java index 6128de908a..262dc5ec65 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/LedgerTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/LedgerTest.java @@ -2,10 +2,7 @@ import java.io.File; -import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.ledger.Ledger; -import org.hyperledger.indy.sdk.ledger.LedgerResults.BuildGetDdoRequestResult; -import org.hyperledger.indy.sdk.ledger.LedgerResults.BuildGetNymRequestResult; import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; import org.junit.Assert; @@ -22,7 +19,7 @@ protected void setUp() throws Exception { if (! LibIndy.isInitialized()) LibIndy.init(new File("./lib/libindy.so")); OpenPoolLedgerJSONParameter openPoolLedgerOptions = new OpenPoolLedgerJSONParameter(null, null, null); - this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions).get().getPool(); + this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions).get(); } @Override @@ -33,14 +30,10 @@ protected void tearDown() throws Exception { public void testLedger() throws Exception { - BuildGetDdoRequestResult result1 = Ledger.buildGetDdoRequest("did:sov:21tDAKCERh95uGgKbJNHYp", "did:sov:1yvXbmgPoUm4dl66D7KhyD", "{}").get(); + String result1 = Ledger.buildGetDdoRequest("did:sov:21tDAKCERh95uGgKbJNHYp", "did:sov:1yvXbmgPoUm4dl66D7KhyD", "{}").get(); Assert.assertNotNull(result1); - String requestJson1 = result1.getRequestJson(); - Assert.assertNotNull(requestJson1); - BuildGetNymRequestResult result2 = Ledger.buildGetNymRequest("did:sov:21tDAKCERh95uGgKbJNHYp", "did:sov:1yvXbmgPoUm4dl66D7KhyD").get(); + String result2 = Ledger.buildGetNymRequest("did:sov:21tDAKCERh95uGgKbJNHYp", "did:sov:1yvXbmgPoUm4dl66D7KhyD").get(); Assert.assertNotNull(result2); - String requestJson2 = result2.getRequestJson(); - Assert.assertNotNull(requestJson2); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java index 573f83b277..172e3d9f96 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java @@ -3,10 +3,8 @@ import java.io.File; import java.util.concurrent.Future; -import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; -import org.hyperledger.indy.sdk.pool.PoolResults.OpenPoolLedgerResult; import org.junit.Assert; import junit.framework.TestCase; @@ -32,8 +30,8 @@ public void testPool() throws Exception { Assert.assertNotNull(result1);*/ OpenPoolLedgerJSONParameter config2 = new OpenPoolLedgerJSONParameter(null, null, null); - Future future2 = Pool.openPoolLedger("myconfig", config2); - OpenPoolLedgerResult result2 = future2.get(); + Future future2 = Pool.openPoolLedger("myconfig", config2); + Pool result2 = future2.get(); Assert.assertNotNull(result2); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/SignusTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/SignusTest.java index 8a924ef53a..c0be961755 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/SignusTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/SignusTest.java @@ -3,7 +3,6 @@ import java.io.File; import java.util.concurrent.Future; -import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; import org.hyperledger.indy.sdk.signus.Signus; @@ -25,8 +24,8 @@ protected void setUp() throws Exception { if (! LibIndy.isInitialized()) LibIndy.init(new File("./lib/libindy.so")); OpenPoolLedgerJSONParameter openPoolLedgerOptions = new OpenPoolLedgerJSONParameter(null, null, null); - this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions).get().getPool(); - this.wallet = Wallet.openWallet("mywallet", null, null).get().getWallet(); + this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions).get(); + this.wallet = Wallet.openWallet("mywallet", null, null).get(); } @Override diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java index 2a95da198d..e79493fcf5 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java @@ -2,14 +2,9 @@ import java.io.File; -import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; import org.hyperledger.indy.sdk.wallet.Wallet; -import org.hyperledger.indy.sdk.wallet.WalletResults.CloseWalletResult; -import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; -import org.hyperledger.indy.sdk.wallet.WalletResults.DeleteWalletResult; -import org.hyperledger.indy.sdk.wallet.WalletResults.OpenWalletResult; import org.junit.Assert; import junit.framework.TestCase; @@ -24,7 +19,7 @@ protected void setUp() throws Exception { if (! LibIndy.isInitialized()) LibIndy.init(new File("./lib/libindy.so")); OpenPoolLedgerJSONParameter openPoolLedgerOptions = new OpenPoolLedgerJSONParameter(null, null, null); - this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions).get().getPool(); + this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions).get(); } @Override @@ -37,17 +32,13 @@ public void testWallet() throws Exception { Wallet wallet; - CreateWalletResult result1 = Wallet.createWallet("default", "mywallet", null, null, null).get(); - Assert.assertNotNull(result1); + Wallet.createWallet("default", "mywallet", null, null, null).get(); - OpenWalletResult result2 = Wallet.openWallet("mywallet", null, null).get(); - Assert.assertNotNull(result2); - wallet = result2.getWallet(); + wallet = Wallet.openWallet("mywallet", null, null).get(); + Assert.assertNotNull(wallet); - CloseWalletResult result3 = wallet.closeWallet().get(); - Assert.assertNotNull(result3); + wallet.closeWallet().get(); - DeleteWalletResult result4 = Wallet.deleteWallet("mywallet", null).get(); - Assert.assertNotNull(result4); + Wallet.deleteWallet("mywallet", null).get(); } } From 5b188b38aeac2d0382fd71121c11da6d03e92a81 Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Tue, 11 Jul 2017 16:40:37 +0200 Subject: [PATCH 071/349] sync with upstream anoncreds.rs method signatures --- .../main/java/org/hyperledger/indy/sdk/LibIndy.java | 6 +++--- .../org/hyperledger/indy/sdk/anoncreds/Anoncreds.java | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java index ca6ccd4c7d..9a7afd907a 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java @@ -59,10 +59,10 @@ public interface API extends Library { // anoncreds.rs - public int indy_issuer_create_and_store_claim_def(int command_handle, int wallet_handle, String schema_json, String signature_type, boolean create_non_revoc, Callback cb); - public int indy_issuer_create_and_store_revoc_reg(int command_handle, int wallet_handle, int claim_def_seq_no, int max_claim_num, Callback cb); + public int indy_issuer_create_and_store_claim_def(int command_handle, int wallet_handle, String issuerDid, String schema_json, String signature_type, boolean create_non_revoc, Callback cb); + public int indy_issuer_create_and_store_revoc_reg(int command_handle, int wallet_handle, String issuerDid, int schema_seq_no, int max_claim_num, Callback cb); public int indy_issuer_create_claim(int command_handle, int wallet_handle, String claim_req_json, String claim_json, int revoc_reg_seq_no, int user_revoc_index, Callback cb); - public int indy_issuer_revoke_claim(int command_handle, int wallet_handle, int claim_def_seq_no, int revoc_reg_seq_no, int user_revoc_index, Callback cb); + public int indy_issuer_revoke_claim(int command_handle, int wallet_handle, int revoc_reg_seq_no, int user_revoc_index, Callback cb); public int indy_prover_store_claim_offer(int command_handle, int wallet_handle, String claim_offer_json, Callback cb); public int indy_prover_get_claim_offers(int command_handle, int wallet_handle, String filter_json, Callback cb); public int indy_prover_create_master_secret(int command_handle, int wallet_handle, String master_secret_name, Callback cb); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java index 491a503b25..8ccb5df30f 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java @@ -26,6 +26,7 @@ private Anoncreds() { public static CompletableFuture issuerCreateAndStoreClaimDef( Wallet wallet, + String issuerDid, String schemaJson, String signatureType, boolean createNonRevoc) throws IndyException { @@ -49,6 +50,7 @@ public void callback(int xcommand_handle, int err, String claim_def_json) { int result = LibIndy.api.indy_issuer_create_and_store_claim_def( FIXED_COMMAND_HANDLE, walletHandle, + issuerDid, schemaJson, signatureType, createNonRevoc, @@ -61,7 +63,8 @@ public void callback(int xcommand_handle, int err, String claim_def_json) { public static CompletableFuture issuerCreateAndStoreRevocReg( Wallet wallet, - int claimDefSeqNo, + String issuerDid, + int schemaSeqNo, int maxClaimNum) throws IndyException { final CompletableFuture future = new CompletableFuture<> (); @@ -83,7 +86,8 @@ public void callback(int xcommand_handle, int err, String revoc_reg_json, String int result = LibIndy.api.indy_issuer_create_and_store_revoc_reg( FIXED_COMMAND_HANDLE, walletHandle, - claimDefSeqNo, + issuerDid, + schemaSeqNo, maxClaimNum, cb); @@ -131,7 +135,6 @@ public void callback(int xcommand_handle, int err, String revoc_reg_update_json, public static CompletableFuture issuerRevokeClaim( Wallet wallet, - int claimDefSeqNo, int revocRegSeqNo, int userRevocIndex) throws IndyException { @@ -154,7 +157,6 @@ public void callback(int xcommand_handle, int err, String revoc_reg_update_json) int result = LibIndy.api.indy_issuer_revoke_claim( FIXED_COMMAND_HANDLE, walletHandle, - claimDefSeqNo, revocRegSeqNo, userRevocIndex, cb); From 968c644f27b293ee59db8cfe3dc9444ccacba51d Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 11 Jul 2017 19:22:11 +0300 Subject: [PATCH 072/349] added test for verifier --- tests/anoncreds.rs | 119 ++++++++++++++++++++++++++++++++++++++++++- tests/utils/types.rs | 25 +++++++++ 2 files changed, 143 insertions(+), 1 deletion(-) diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index 842d3c7083..163078a843 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -25,7 +25,8 @@ use utils::types::{ ClaimRequestJson, ClaimInfo, ClaimJson, - ProofJson + ProofJson, + ProofRequestJson }; use sovrin::api::ErrorCode; @@ -1447,6 +1448,122 @@ mod demos { TestUtils::cleanup_storage(); } + #[test] + fn interoperability_test_pysovrin_is_verifier() { + TestUtils::cleanup_storage(); + + let pool_name = "pool1"; + let issuer_wallet_name = "issuer_wallet"; + let prover_wallet_name = "prover_wallet"; + let xtype = "default"; + + //1. Create Issuer wallet, get wallet handle + let issuer_wallet_handle = WalletUtils::create_and_open_wallet(pool_name, issuer_wallet_name, xtype).unwrap(); + + //2. Create Prover wallet, get wallet handle + let prover_wallet_handle = WalletUtils::create_and_open_wallet(pool_name, prover_wallet_name, xtype).unwrap(); + + //3. Issuer create claim definition + let schema_seq_no = 1; + let schema = AnoncredsUtils::get_gvt_schema_json(schema_seq_no); + + let claim_def_json = AnoncredsUtils::issuer_create_claim_definition(issuer_wallet_handle, &ISSUER_DID, &schema, None, false).unwrap(); + + let mut command = Command::new("python3") + .arg("../anoncreds-fork/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_verifier.py") + .spawn().expect("failed to execute process"); + thread::sleep(time::Duration::from_millis(3000)); + + let mut stream = TcpStream::connect("127.0.0.1:1234").unwrap(); + + stream.write(format!(r#"{{"type":"receive_claim_def", "data": {}}}"#, claim_def_json).as_bytes()); + + //4. Prover create Master Secret + let master_secret_name = "prover_master_secret"; + + AnoncredsUtils::prover_create_master_secret(prover_wallet_handle, master_secret_name).unwrap(); + + //5. Prover store Claim Offer received from Issuer + let claim_offer_json = AnoncredsUtils::get_claim_offer(ISSUER_DID, schema_seq_no); + + AnoncredsUtils::prover_store_claim_offer(prover_wallet_handle, &claim_offer_json).unwrap(); + + //6. Prover get Claim Offers + let filter_json = format!(r#"{{"issuer_did":"{}"}}"#, ISSUER_DID); + + let claim_offers_json = AnoncredsUtils::prover_get_claim_offers(prover_wallet_handle, &filter_json).unwrap(); + + let claim_offers: Vec = serde_json::from_str(&claim_offers_json).unwrap(); + assert!(claim_offers.len() == 1); + let claim_offer_json = serde_json::to_string(&claim_offers[0]).unwrap(); + + //7. Prover create Claim Request + let prover_did = "BzfFCYk"; + let claim_req = AnoncredsUtils::prover_create_and_store_claim_req(prover_wallet_handle, + prover_did, + &claim_offer_json, + &claim_def_json, + master_secret_name).unwrap(); + + //8. Issuer create Claim + let claim_json = AnoncredsUtils::get_gvt_claim_json(); + let (_, xclaim_json) = AnoncredsUtils::issuer_create_claim(issuer_wallet_handle, + &claim_req, + &claim_json).unwrap(); + + // 9. Prover store received Claim + AnoncredsUtils::prover_store_claim(prover_wallet_handle, &xclaim_json).unwrap(); + + stream.write(r#"{"type":"get_proof_request"}"#.as_bytes()); + let mut buf = vec![0; 10240]; + stream.read(&mut buf).unwrap(); + buf.retain(|&element| element != 0); + + let proof_req_json = String::from_utf8(buf).unwrap(); + println!("proof_req_json: {:?}", proof_req_json); + + + + let claims_json = AnoncredsUtils::prover_get_claims_for_proof_req(prover_wallet_handle, &proof_req_json).unwrap(); + let claims: ProofClaimsJson = serde_json::from_str(&claims_json).unwrap(); + info!("claims_json: {}", &claims_json); + let claims_for_attr = claims.attrs.get("attr_uuid").unwrap(); + assert_eq!(1, claims_for_attr.len()); + let claim = claims_for_attr[0].clone(); + + // 11. Prover create Proof + let self_attested_value = "value"; + let requested_claims_json = format!(r#"{{ + "self_attested_attributes":{{"self1":"{}"}}, + "requested_attrs":{{"attr_uuid":["{}",true]}}, + "requested_predicates":{{"predicate_uuid":"{}"}} + }}"#, self_attested_value, claim.claim_uuid, claim.claim_uuid); + + let schemas_json = format!(r#"{{"{}":{}}}"#, claim.claim_uuid, schema); + let claim_defs_json = format!(r#"{{"{}":{}}}"#, claim.claim_uuid, claim_def_json); + let revoc_regs_jsons = "{}"; + + let proof_json = AnoncredsUtils::prover_create_proof(prover_wallet_handle, + &proof_req_json, + &requested_claims_json, + &schemas_json, + &master_secret_name, + &claim_defs_json, + &revoc_regs_jsons).unwrap(); + println!("proof_json: {:?}", proof_json); + + stream.write(format!(r#"{{"type":"check_proof", "data": {}}}"#, proof_json).as_bytes()); + let mut buf = vec![0; 102400]; + stream.read(&mut buf).unwrap(); + stream.write(r#"{"type":"close"}"#.as_bytes()); + buf.retain(|&element| element != 0); + + let valid = String::from_utf8(buf).unwrap(); + println!("valid: {:?}", valid); + + TestUtils::cleanup_storage(); + } + #[test] fn verifier_verify_proof_works_for_proof_does_not_correspond_proof_request() { TestUtils::cleanup_storage(); diff --git a/tests/utils/types.rs b/tests/utils/types.rs index 99dcb342a7..07a5cc69ef 100644 --- a/tests/utils/types.rs +++ b/tests/utils/types.rs @@ -141,6 +141,31 @@ pub struct ProofClaimsJson { pub predicates: HashMap> } +#[derive(Debug, Deserialize, Serialize)] +pub struct ProofRequestJson { + pub nonce: String, + pub name: String, + pub version: String, + pub requested_attrs: HashMap, + pub requested_predicates: HashMap +} + +#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)] +pub struct Predicate { + pub attr_name: String, + pub p_type: String, + pub value: i32, + pub schema_seq_no: Option, + pub issuer_did: Option +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct AttributeInfo { + pub name: String, + pub schema_seq_no: Option, + pub issuer_did: Option +} + #[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Hash)] pub struct ClaimInfo { pub claim_uuid: String, From dcbd87f19300dfbf1795c4ee2c5762caf6914449 Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Tue, 11 Jul 2017 21:11:22 +0200 Subject: [PATCH 073/349] use observer pattern for agentListen and agentConnect --- .../org/hyperledger/indy/sdk/IndyJava.java | 12 ++-- .../org/hyperledger/indy/sdk/agent/Agent.java | 69 +++++++++++++++++-- .../indy/sdk/agent/AgentCallbacks.java | 27 -------- .../indy/sdk/agent/AgentObservers.java | 22 ++++++ 4 files changed, 91 insertions(+), 39 deletions(-) delete mode 100644 wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentCallbacks.java create mode 100644 wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentObservers.java diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java index 758c96fa3a..6ea1ecfa10 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java @@ -34,18 +34,16 @@ protected static boolean checkCallback(CompletableFuture future, int xcommand return true; } - protected static boolean checkCallback(CompletableFuture future, int err) { + protected static void checkCallback(int err) throws IndyException { ErrorCode errorCode = ErrorCode.valueOf(err); - if (! ErrorCode.Success.equals(errorCode)) { future.completeExceptionally(IndyException.fromErrorCode(errorCode, err)); return false; } - - return true; + if (! ErrorCode.Success.equals(errorCode)) throw IndyException.fromErrorCode(errorCode, err); } - protected static void checkResult(int result) throws IndyException { + protected static void checkResult(int err) throws IndyException { - ErrorCode errorCode = ErrorCode.valueOf(result); - if (! ErrorCode.Success.equals(errorCode)) throw IndyException.fromErrorCode(errorCode, result); + ErrorCode errorCode = ErrorCode.valueOf(err); + if (! ErrorCode.Success.equals(errorCode)) throw IndyException.fromErrorCode(errorCode, err); } @Override diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java index 915c46dbce..88dd92a591 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java @@ -1,6 +1,8 @@ package org.hyperledger.indy.sdk.agent; +import java.util.Map; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; import org.hyperledger.indy.sdk.IndyException; import org.hyperledger.indy.sdk.IndyJava; @@ -15,6 +17,9 @@ */ public class Agent extends IndyJava.API { + private static Map connections = new ConcurrentHashMap<> (); + private static Map listeners = new ConcurrentHashMap<> (); + private Agent() { } @@ -28,7 +33,7 @@ public static CompletableFuture agentConnect( Wallet wallet, String senderDid, String receiverDid, - Callback messageCb) throws IndyException { + AgentObservers.AgentConnectObserver agentConnectObserver) throws IndyException { final CompletableFuture future = new CompletableFuture<> (); @@ -39,11 +44,28 @@ public void callback(int xcommand_handle, int err, int connection_handle) { if (! checkCallback(future, xcommand_handle, err)) return; - Agent.Connection result = new Agent.Connection(connection_handle); + Agent.Connection connection = new Agent.Connection(connection_handle); + connections.put(Integer.valueOf(connection_handle), connection); + + Agent.Connection result = connection; future.complete(result); } }; + Callback messageCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(int xconnection_handle, int err, String message) throws IndyException { + + checkCallback(err); + + Agent.Connection connection = connections.get(Integer.valueOf(xconnection_handle)); + if (connection == null) return; + + agentConnectObserver.onMessage(connection, message); + } + }; + int poolHandle = pool.getPoolHandle(); int walletHandle = wallet.getWalletHandle(); @@ -63,8 +85,7 @@ public void callback(int xcommand_handle, int err, int connection_handle) { public static CompletableFuture agentListen( String endpoint, - Callback connectionCb, - Callback messageCb) throws IndyException { + AgentObservers.AgentListenObserver agentListenObserver) throws IndyException { final CompletableFuture future = new CompletableFuture<> (); @@ -75,11 +96,45 @@ public void callback(int xcommand_handle, int err, int listener_handle) { if (! checkCallback(future, xcommand_handle, err)) return; - Agent.Listener result = new Agent.Listener(listener_handle); + Agent.Listener listener = new Agent.Listener(listener_handle); + listeners.put(Integer.valueOf(listener_handle), listener); + + Agent.Listener result = listener; future.complete(result); } }; + Callback connectionCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(int xlistener_handle, int err, int connection_handle, String sender_did, String receiver_did) throws IndyException { + + checkCallback(err); + + Agent.Listener listener = listeners.get(Integer.valueOf(xlistener_handle)); + if (listener == null) return; + + Agent.Connection connection = connections.get(Integer.valueOf(connection_handle)); + if (connection == null) return; + + agentListenObserver.onConnection(listener, connection, sender_did, receiver_did); + } + }; + + Callback messageCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(int xconnection_handle, int err, String message) throws IndyException { + + checkCallback(err); + + Agent.Connection connection = connections.get(Integer.valueOf(xconnection_handle)); + if (connection == null) return; + + agentListenObserver.onMessage(connection, message); + } + }; + int result = LibIndy.api.indy_agent_listen( FIXED_COMMAND_HANDLE, endpoint, @@ -213,6 +268,8 @@ public void callback(int xcommand_handle, int err) { int connectionHandle = connection.getConnectionHandle(); + connections.remove(Integer.valueOf(connectionHandle)); + int result = LibIndy.api.indy_agent_close_connection( FIXED_COMMAND_HANDLE, connectionHandle, @@ -242,6 +299,8 @@ public void callback(int xcommand_handle, int err) { int listenerHandle = listener.getListenerHandle(); + listeners.remove(Integer.valueOf(listenerHandle)); + int result = LibIndy.api.indy_agent_close_connection( FIXED_COMMAND_HANDLE, listenerHandle, diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentCallbacks.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentCallbacks.java deleted file mode 100644 index 7e3ed0033a..0000000000 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentCallbacks.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.hyperledger.indy.sdk.agent; - -import com.sun.jna.Callback; - -/** - * agent.rs callbacks - */ -public final class AgentCallbacks { - - private AgentCallbacks() { - - } - - public static class AgentMessageCallback implements Callback { - - public final void callback(int xconnection_handle, int err, String message) { - - } - } - - public static class AgentConnectionCallback implements Callback { - - public final void callback(int xlistener_handle, int err, int connection_handle, String sender_did, String receiver_did) { - - } - } -} diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentObservers.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentObservers.java new file mode 100644 index 0000000000..9760088516 --- /dev/null +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentObservers.java @@ -0,0 +1,22 @@ +package org.hyperledger.indy.sdk.agent; + +/** + * agent.rs observers + */ +public final class AgentObservers { + + private AgentObservers() { + + } + + public interface AgentConnectObserver { + + public void onMessage(Agent.Connection connection, String message); + } + + public interface AgentListenObserver extends AgentConnectObserver { + + public void onConnection(Agent.Listener listener, Agent.Connection connection, String senderDid, String receiverDid); + public void onMessage(Agent.Connection connection, String message); + } +} From 2117495e3a28cdf5aa329f66d383edf555f18caf Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Tue, 11 Jul 2017 21:59:13 +0200 Subject: [PATCH 074/349] only wrap result in dedicated class in case of tuples (signus) --- .../hyperledger/indy/sdk/signus/Signus.java | 35 ++++++++----------- .../indy/sdk/signus/SignusResults.java | 33 ----------------- 2 files changed, 15 insertions(+), 53 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java index 48ab83744f..ad540f85fc 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java @@ -8,12 +8,7 @@ import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.signus.SignusJSONParameters.CreateAndStoreMyDidJSONParameter; import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; -import org.hyperledger.indy.sdk.signus.SignusResults.DecryptResult; -import org.hyperledger.indy.sdk.signus.SignusResults.EncryptResult; import org.hyperledger.indy.sdk.signus.SignusResults.ReplaceKeysResult; -import org.hyperledger.indy.sdk.signus.SignusResults.SignResult; -import org.hyperledger.indy.sdk.signus.SignusResults.StoreTheirDidResult; -import org.hyperledger.indy.sdk.signus.SignusResults.VerifySignatureResult; import org.hyperledger.indy.sdk.wallet.Wallet; import com.sun.jna.Callback; @@ -95,11 +90,11 @@ public void callback(int xcommand_handle, int err, String verkey, String pk) { return future; } - public static CompletableFuture storeTheirDid( + public static CompletableFuture storeTheirDid( Wallet wallet, String identityJson) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -108,7 +103,7 @@ public void callback(int xcommand_handle, int err) { if (! checkCallback(future, xcommand_handle, err)) return; - StoreTheirDidResult result = new StoreTheirDidResult(); + Void result = null; future.complete(result); } }; @@ -126,12 +121,12 @@ public void callback(int xcommand_handle, int err) { return future; } - public static CompletableFuture sign( + public static CompletableFuture sign( Wallet wallet, String did, String msg) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -140,7 +135,7 @@ public void callback(int xcommand_handle, int err, String signature) { if (! checkCallback(future, xcommand_handle, err)) return; - SignResult result = new SignResult(signature); + String result = signature; future.complete(result); } }; @@ -159,13 +154,13 @@ public void callback(int xcommand_handle, int err, String signature) { return future; } - public static CompletableFuture verifySignature( + public static CompletableFuture verifySignature( Wallet wallet, Pool pool, String did, String signedMsg) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -174,7 +169,7 @@ public void callback(int xcommand_handle, int err, boolean valid) { if (! checkCallback(future, xcommand_handle, err)) return; - VerifySignatureResult result = new VerifySignatureResult(valid); + Boolean result = Boolean.valueOf(valid); future.complete(result); } }; @@ -195,12 +190,12 @@ public void callback(int xcommand_handle, int err, boolean valid) { return future; } - public static CompletableFuture encrypt( + public static CompletableFuture encrypt( Wallet wallet, String did, String msg) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -209,7 +204,7 @@ public void callback(int xcommand_handle, int err, String encryptedMsg) { if (! checkCallback(future, xcommand_handle, err)) return; - EncryptResult result = new EncryptResult(encryptedMsg); + String result = encryptedMsg; future.complete(result); } }; @@ -228,12 +223,12 @@ public void callback(int xcommand_handle, int err, String encryptedMsg) { return future; } - public static CompletableFuture decrypt( + public static CompletableFuture decrypt( Wallet wallet, String did, String encryptedMsg) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); + final CompletableFuture future = new CompletableFuture<> (); Callback cb = new Callback() { @@ -242,7 +237,7 @@ public void callback(int xcommand_handle, int err, String decryptedMsg) { if (! checkCallback(future, xcommand_handle, err)) return; - DecryptResult result = new DecryptResult(decryptedMsg); + String result = decryptedMsg; future.complete(result); } }; diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/SignusResults.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/SignusResults.java index 7b67283b84..4182b7f8b0 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/SignusResults.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/SignusResults.java @@ -27,37 +27,4 @@ public static class ReplaceKeysResult extends IndyJava.Result { public String getVerkey() { return this.verkey; } public String getPk() { return this.pk; } } - - public static class StoreTheirDidResult extends IndyJava.Result { - - StoreTheirDidResult() { } - } - - public static class SignResult extends IndyJava.Result { - - private String signature; - SignResult(String signature) { this.signature = signature; } - public String getSignature() { return this.signature; } - } - - public static class VerifySignatureResult extends IndyJava.Result { - - private boolean valid; - VerifySignatureResult(boolean valid) { this.valid = valid; } - public boolean isValid() { return this.valid; } - } - - public static class EncryptResult extends IndyJava.Result { - - private String encryptedMsg; - EncryptResult(String encryptedMsg) { this.encryptedMsg = encryptedMsg; } - public String getEncryptedMsg() { return this.encryptedMsg; } - } - - public static class DecryptResult extends IndyJava.Result { - - private String decryptedMsg; - DecryptResult(String decryptedMsg) { this.decryptedMsg = decryptedMsg; } - public String getDecryptedMsg() { return this.decryptedMsg; } - } } From ac7be645c7c9a39cd295dc5c53a2a429fe89e9da Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 12 Jul 2017 08:03:17 +0300 Subject: [PATCH 075/349] try --- ci/upload-rpm.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ci/upload-rpm.sh b/ci/upload-rpm.sh index 8a5ad95cd1..0e79674039 100644 --- a/ci/upload-rpm.sh +++ b/ci/upload-rpm.sh @@ -8,9 +8,6 @@ key="$1" cat < Date: Wed, 12 Jul 2017 08:11:11 +0300 Subject: [PATCH 076/349] revert --- ci/upload-rpm.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ci/upload-rpm.sh b/ci/upload-rpm.sh index 0e79674039..8a5ad95cd1 100644 --- a/ci/upload-rpm.sh +++ b/ci/upload-rpm.sh @@ -8,6 +8,9 @@ key="$1" cat < Date: Wed, 12 Jul 2017 09:24:14 +0200 Subject: [PATCH 077/349] WIP static callback methods instead of new GC-unsafe callbacks every time --- .../org/hyperledger/indy/sdk/IndyJava.java | 45 +- .../org/hyperledger/indy/sdk/agent/Agent.java | 246 ++++++----- .../indy/sdk/anoncreds/Anoncreds.java | 196 +++++---- .../hyperledger/indy/sdk/ledger/Ledger.java | 388 ++++++++++-------- .../org/hyperledger/indy/sdk/pool/Pool.java | 166 ++++---- .../hyperledger/indy/sdk/signus/Signus.java | 228 +++++----- .../hyperledger/indy/sdk/wallet/Wallet.java | 166 ++++---- 7 files changed, 792 insertions(+), 643 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java index 6ea1ecfa10..d46be6e345 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java @@ -4,6 +4,8 @@ import java.util.Iterator; import java.util.Map; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; @@ -22,11 +24,34 @@ public class IndyJava { public static class API { - protected static final int FIXED_COMMAND_HANDLE = 0; + /* + * FUTURES + */ - protected static boolean checkCallback(CompletableFuture future, int xcommand_handle, int err) { + private static AtomicInteger atomicInteger = new AtomicInteger(); + private static Map> futures = new ConcurrentHashMap<> (); - assert(xcommand_handle == FIXED_COMMAND_HANDLE); + protected static int addFuture(CompletableFuture future) { + + int commandHandle = Integer.valueOf(atomicInteger.incrementAndGet()); + futures.put(Integer.valueOf(commandHandle), future); + + return commandHandle; + } + + protected static CompletableFuture removeFuture(int xcommand_handle) { + + CompletableFuture future = futures.remove(Integer.valueOf(xcommand_handle)); + assert (future != null); + + return future; + } + + /* + * ERROR CHECKING + */ + + protected static boolean checkCallback(CompletableFuture future, int err) { ErrorCode errorCode = ErrorCode.valueOf(err); if (! ErrorCode.Success.equals(errorCode)) { future.completeExceptionally(IndyException.fromErrorCode(errorCode, err)); return false; } @@ -46,6 +71,10 @@ protected static void checkResult(int err) throws IndyException { if (! ErrorCode.Success.equals(errorCode)) throw IndyException.fromErrorCode(errorCode, err); } + /* + * OBJECT METHODS + */ + @Override public int hashCode() { @@ -66,13 +95,17 @@ public String toString() { } /* - * JSON parameter + * JSON PARAMETER */ public abstract static class JsonParameter { protected Map map = new HashMap (); + /* + * JSON CREATION + */ + public final String toJson() { StringBuilder builder = new StringBuilder(); @@ -102,6 +135,10 @@ private static String escapeJson(String string) { return string.replace("\\", "\\\\").replace("\"", "\\\""); } + /* + * OBJECT METHODS + */ + @Override public int hashCode() { diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java index 88dd92a591..2294c6028e 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java @@ -24,6 +24,107 @@ private Agent() { } + /* + * STATIC CALLBACKS + */ + + private static Callback agentConnectCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, int connection_handle) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Agent.Connection connection = new Agent.Connection(connection_handle); + connections.put(Integer.valueOf(connection_handle), connection); + + Agent.Connection result = connection; + future.complete(result); + } + }; + + private static Callback agentListenCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, int listener_handle) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Agent.Listener listener = new Agent.Listener(listener_handle); + listeners.put(Integer.valueOf(listener_handle), listener); + + Agent.Listener result = listener; + future.complete(result); + } + }; + + private static Callback agentAddIdentityCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, int listener_handle) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Void result = null; + future.complete(result); + } + }; + + private static Callback agentRemoveIdentityCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, int listener_handle) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Void result = null; + future.complete(result); + } + }; + + private static Callback agentSendCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Void result = null; + future.complete(result); + } + }; + + private static Callback agentCloseConnectionCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Void result = null; + future.complete(result); + } + }; + + private static Callback agentCloseListenerCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Void result = null; + future.complete(result); + } + }; + /* * STATIC METHODS */ @@ -35,26 +136,12 @@ public static CompletableFuture agentConnect( String receiverDid, AgentObservers.AgentConnectObserver agentConnectObserver) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback connectionCb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, int connection_handle) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Agent.Connection connection = new Agent.Connection(connection_handle); - connections.put(Integer.valueOf(connection_handle), connection); - - Agent.Connection result = connection; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); Callback messageCb = new Callback() { - @SuppressWarnings("unused") + @SuppressWarnings({ "unused", "unchecked" }) public void callback(int xconnection_handle, int err, String message) throws IndyException { checkCallback(err); @@ -70,12 +157,12 @@ public void callback(int xconnection_handle, int err, String message) throws Ind int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_agent_connect( - FIXED_COMMAND_HANDLE, + commandHandle, poolHandle, walletHandle, senderDid, receiverDid, - connectionCb, + agentConnectCb, messageCb); checkResult(result); @@ -87,26 +174,12 @@ public static CompletableFuture agentListen( String endpoint, AgentObservers.AgentListenObserver agentListenObserver) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback listenerCb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, int listener_handle) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Agent.Listener listener = new Agent.Listener(listener_handle); - listeners.put(Integer.valueOf(listener_handle), listener); - - Agent.Listener result = listener; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); Callback connectionCb = new Callback() { - @SuppressWarnings("unused") + @SuppressWarnings({ "unused", "unchecked" }) public void callback(int xlistener_handle, int err, int connection_handle, String sender_did, String receiver_did) throws IndyException { checkCallback(err); @@ -123,7 +196,7 @@ public void callback(int xlistener_handle, int err, int connection_handle, Strin Callback messageCb = new Callback() { - @SuppressWarnings("unused") + @SuppressWarnings({ "unused", "unchecked" }) public void callback(int xconnection_handle, int err, String message) throws IndyException { checkCallback(err); @@ -136,9 +209,9 @@ public void callback(int xconnection_handle, int err, String message) throws Ind }; int result = LibIndy.api.indy_agent_listen( - FIXED_COMMAND_HANDLE, + commandHandle, endpoint, - listenerCb, + agentListenCb, connectionCb, messageCb); @@ -153,31 +226,20 @@ public static CompletableFuture agentAddIdentity( Wallet wallet, String did) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback addIdentityCb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, int listener_handle) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Void result = null; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int listenerHandle = listener.getListenerHandle(); int poolHandle = pool.getPoolHandle(); int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_agent_add_identity( - FIXED_COMMAND_HANDLE, + commandHandle, listenerHandle, poolHandle, walletHandle, did, - addIdentityCb); + agentAddIdentityCb); checkResult(result); @@ -189,29 +251,18 @@ public static CompletableFuture agentRemoveIdentity( Wallet wallet, String did) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback rmIdentityCb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, int listener_handle) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Void result = null; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int listenerHandle = listener.getListenerHandle(); int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_agent_remove_identity( - FIXED_COMMAND_HANDLE, + commandHandle, listenerHandle, walletHandle, did, - rmIdentityCb); + agentRemoveIdentityCb); checkResult(result); @@ -222,27 +273,16 @@ public static CompletableFuture agentSend( Agent.Connection connection, String message) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Void result = null; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int connectionHandle = connection.getConnectionHandle(); int result = LibIndy.api.indy_agent_send( - FIXED_COMMAND_HANDLE, + commandHandle, connectionHandle, message, - cb); + agentSendCb); checkResult(result); @@ -252,28 +292,17 @@ public void callback(int xcommand_handle, int err) { public static CompletableFuture agentCloseConnection( Agent.Connection connection) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Void result = null; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int connectionHandle = connection.getConnectionHandle(); connections.remove(Integer.valueOf(connectionHandle)); int result = LibIndy.api.indy_agent_close_connection( - FIXED_COMMAND_HANDLE, + commandHandle, connectionHandle, - cb); + agentCloseConnectionCb); checkResult(result); @@ -283,28 +312,17 @@ public void callback(int xcommand_handle, int err) { public static CompletableFuture agentCloseListener( Agent.Listener listener) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Void result = null; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int listenerHandle = listener.getListenerHandle(); listeners.remove(Integer.valueOf(listenerHandle)); int result = LibIndy.api.indy_agent_close_connection( - FIXED_COMMAND_HANDLE, + commandHandle, listenerHandle, - cb); + agentCloseListenerCb); checkResult(result); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java index 8ccb5df30f..d4eb36f039 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java @@ -20,6 +20,88 @@ private Anoncreds() { } + /* + * STATIC CALLBACKS + */ + + private static Callback issuerCreateAndStoreClaimDefCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String claim_def_json) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = claim_def_json, claim_def_uuid; + future.complete(result); + } + }; + + private static Callback issuerCreateAndStoreRevocRegCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String revoc_reg_json, String revoc_reg_uuid) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + IssuerCreateAndStoreRevocRegResult result = new IssuerCreateAndStoreRevocRegResult(revoc_reg_json, revoc_reg_uuid); + future.complete(result); + } + }; + + private static Callback issuerCreateClaimCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String revoc_reg_update_json, String xclaim_json) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + IssuerCreateClaimResult result = new IssuerCreateClaimResult(revoc_reg_update_json, xclaim_json); + future.complete(result); + } + }; + + private static Callback issuerRevokeClaimCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String revoc_reg_update_json) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = revoc_reg_update_json; + future.complete(result); + } + }; + + private static Callback proverStoreClaimOfferCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Void result = null; + future.complete(result); + } + }; + + private static Callback proverGetClaimOffersCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String claim_offers_json) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = claim_offers_json; + future.complete(result); + } + }; + /* * STATIC METHODS */ @@ -31,30 +113,19 @@ public static CompletableFuture issuerCreateAndStoreClaimDef( String signatureType, boolean createNonRevoc) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String claim_def_json) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - String result = claim_def_json, claim_def_uuid; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_issuer_create_and_store_claim_def( - FIXED_COMMAND_HANDLE, + commandHandle, walletHandle, issuerDid, schemaJson, signatureType, createNonRevoc, - cb); + issuerCreateAndStoreClaimDefCb); checkResult(result); @@ -67,29 +138,18 @@ public static CompletableFuture issuerCreate int schemaSeqNo, int maxClaimNum) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String revoc_reg_json, String revoc_reg_uuid) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - IssuerCreateAndStoreRevocRegResult result = new IssuerCreateAndStoreRevocRegResult(revoc_reg_json, revoc_reg_uuid); - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_issuer_create_and_store_revoc_reg( - FIXED_COMMAND_HANDLE, + commandHandle, walletHandle, issuerDid, schemaSeqNo, maxClaimNum, - cb); + issuerCreateAndStoreRevocRegCb); checkResult(result); @@ -103,30 +163,19 @@ public static CompletableFuture issuerCreateClaim( int revocRegSeqNo, int userRevocIndex) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String revoc_reg_update_json, String xclaim_json) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - IssuerCreateClaimResult result = new IssuerCreateClaimResult(revoc_reg_update_json, xclaim_json); - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_issuer_create_claim( - FIXED_COMMAND_HANDLE, + commandHandle, walletHandle, claimReqJson, claimJson, revocRegSeqNo, userRevocIndex, - cb); + issuerCreateClaimCb); checkResult(result); @@ -138,28 +187,17 @@ public static CompletableFuture issuerRevokeClaim( int revocRegSeqNo, int userRevocIndex) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String revoc_reg_update_json) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - String result = revoc_reg_update_json; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_issuer_revoke_claim( - FIXED_COMMAND_HANDLE, + commandHandle, walletHandle, revocRegSeqNo, userRevocIndex, - cb); + issuerRevokeClaimCb); checkResult(result); @@ -170,27 +208,16 @@ public static CompletableFuture proverStoreClaimOffer( Wallet wallet, String claimOfferJson) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Void result = null; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_prover_store_claim_offer( - FIXED_COMMAND_HANDLE, + commandHandle, walletHandle, claimOfferJson, - cb); + proverStoreClaimOfferCb); checkResult(result); @@ -201,27 +228,16 @@ public static CompletableFuture proverGetClaimOffers( Wallet wallet, String filterJson) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String claim_offers_json) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - String result = claim_offers_json; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_prover_get_claim_offers( - FIXED_COMMAND_HANDLE, + commandHandle, walletHandle, filterJson, - cb); + proverGetClaimOffersCb); checkResult(result); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java index 52a8959c6d..8510ab6971 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java @@ -19,6 +19,166 @@ private Ledger() { } + /* + * STATIC CALLBACKS + */ + + private static Callback signAndSubmitRequestCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String request_result_json) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = request_result_json; + future.complete(result); + } + }; + + private static Callback submitRequestCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String request_result_json) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = request_result_json; + future.complete(result); + } + }; + + private static Callback buildGetDdoRequestCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String request_json) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = request_json; + future.complete(result); + } + }; + + private static Callback buildNymRequestCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String request_json) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = request_json; + future.complete(result); + } + }; + + private static Callback buildAttribRequestCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String request_json) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = request_json; + future.complete(result); + } + }; + + private static Callback buildGetAttribRequestCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String request_json) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = request_json; + future.complete(result); + } + }; + + private static Callback buildGetNymRequestCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String request_json) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = request_json; + future.complete(result); + } + }; + + private static Callback buildSchemaRequestCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String request_json) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = request_json; + future.complete(result); + } + }; + + private static Callback buildGetSchemaRequestCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String request_json) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = request_json; + future.complete(result); + } + }; + + private static Callback buildClaimDefTxnCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String request_json) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = request_json; + future.complete(result); + } + }; + + private static Callback buildGetClaimDefTxnCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String request_json) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = request_json; + future.complete(result); + } + }; + + private static Callback buildNodeRequestCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String request_json) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = request_json; + future.complete(result); + } + }; + /* * STATIC METHODS */ @@ -29,30 +189,19 @@ public static CompletableFuture signAndSubmitRequest( String submitterDid, String requestJson) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String request_result_json) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - String result = request_result_json; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int poolHandle = pool.getPoolHandle(); int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_sign_and_submit_request( - FIXED_COMMAND_HANDLE, + commandHandle, poolHandle, walletHandle, submitterDid, requestJson, - cb); + signAndSubmitRequestCb); checkResult(result); @@ -63,27 +212,16 @@ public static CompletableFuture submitRequest( Pool pool, String requestJson) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String request_result_json) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - String result = request_result_json; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int poolHandle = pool.getPoolHandle(); int result = LibIndy.api.indy_submit_request( - FIXED_COMMAND_HANDLE, + commandHandle, poolHandle, requestJson, - cb); + submitRequestCb); checkResult(result); @@ -95,25 +233,14 @@ public static CompletableFuture buildGetDdoRequest( String targetDid, String requestJson) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String request_json) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - String result = request_json; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_get_ddo_request( - FIXED_COMMAND_HANDLE, + commandHandle, submitterDid, targetDid, - cb); + buildGetDdoRequestCb); checkResult(result); @@ -127,28 +254,17 @@ public static CompletableFuture buildNymRequest( String alias, String role) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String request_json) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - String result = request_json; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_nym_request( - FIXED_COMMAND_HANDLE, + commandHandle, submitterDid, targetDid, verkey, alias, role, - cb); + buildNymRequestCb); checkResult(result); @@ -162,28 +278,17 @@ public static CompletableFuture buildAttribRequest( String raw, String enc) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String request_json) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - String result = request_json; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_attrib_request( - FIXED_COMMAND_HANDLE, + commandHandle, submitterDid, targetDid, hash, raw, enc, - cb); + buildAttribRequestCb); checkResult(result); @@ -195,26 +300,15 @@ public static CompletableFuture buildGetAttribRequest( String targetDid, String data) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String request_json) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - String result = request_json; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_get_attrib_request( - FIXED_COMMAND_HANDLE, + commandHandle, submitterDid, targetDid, data, - cb); + buildGetAttribRequestCb); checkResult(result); @@ -225,25 +319,14 @@ public static CompletableFuture buildGetNymRequest( String submitterDid, String targetDid) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String request_json) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - String result = request_json; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_get_nym_request( - FIXED_COMMAND_HANDLE, + commandHandle, submitterDid, targetDid, - cb); + buildGetNymRequestCb); checkResult(result); @@ -254,25 +337,14 @@ public static CompletableFuture buildSchemaRequest( String submitterDid, String data) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String request_json) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - String result = request_json; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_schema_request( - FIXED_COMMAND_HANDLE, + commandHandle, submitterDid, data, - cb); + buildSchemaRequestCb); checkResult(result); @@ -283,25 +355,14 @@ public static CompletableFuture buildGetSchemaRequest( String submitterDid, String data) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String request_json) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - String result = request_json; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_get_schema_request( - FIXED_COMMAND_HANDLE, + commandHandle, submitterDid, data, - cb); + buildGetSchemaRequestCb); checkResult(result); @@ -313,26 +374,15 @@ public static CompletableFuture buildClaimDefTxn( String xref, String data) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String request_json) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - String result = request_json; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_claim_def_txn( - FIXED_COMMAND_HANDLE, + commandHandle, submitterDid, xref, data, - cb); + buildClaimDefTxnCb); checkResult(result); @@ -343,25 +393,14 @@ public static CompletableFuture buildGetClaimDefTxn( String submitterDid, String xref) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String request_json) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - String result = request_json; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_get_claim_def_txn( - FIXED_COMMAND_HANDLE, + commandHandle, submitterDid, xref, - cb); + buildGetClaimDefTxnCb); checkResult(result); @@ -373,26 +412,15 @@ public static CompletableFuture buildNodeRequest( String targetDid, String data) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String request_json) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - String result = request_json; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_node_request( - FIXED_COMMAND_HANDLE, + commandHandle, submitterDid, targetDid, data, - cb); + buildNodeRequestCb); checkResult(result); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java index 26eff4fdea..28cfa0b856 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java @@ -28,32 +28,92 @@ public int getPoolHandle() { } /* - * STATIC METHODS + * STATIC CALLBACKS */ - public static CompletableFuture createPoolLedgerConfig( - String configName, - CreatePoolLedgerConfigJSONParameter config) throws IndyException { + private static Callback createPoolLedgerConfigCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Void result = null; + future.complete(result); + } + }; + + private static Callback openPoolLedgerCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, int pool_handle) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Pool pool = new Pool(pool_handle); - final CompletableFuture future = new CompletableFuture<> (); + Pool result = pool; + future.complete(result); + } + }; - Callback cb = new Callback() { + private static Callback refreshPoolLedgerCb = new Callback() { - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err) { + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err) { - if (! checkCallback(future, xcommand_handle, err)) return; + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; - Void result = null; - future.complete(result); - } - }; + Void result = null; + future.complete(result); + } + }; + + private static Callback closePoolLedgerCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Void result = null; + future.complete(result); + } + }; + + private static Callback deletePoolLedgerConfigCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Void result = null; + future.complete(result); + } + }; + + /* + * STATIC METHODS + */ + + public static CompletableFuture createPoolLedgerConfig( + String configName, + CreatePoolLedgerConfigJSONParameter config) throws IndyException { + + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int result = LibIndy.api.indy_create_pool_ledger_config( - FIXED_COMMAND_HANDLE, + commandHandle, configName, config == null ? null : config.toJson(), - cb); + createPoolLedgerConfigCb); checkResult(result); @@ -64,25 +124,14 @@ public static CompletableFuture openPoolLedger( String configName, OpenPoolLedgerJSONParameter config) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, int pool_handle) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Pool result = new Pool(pool_handle); - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int result = LibIndy.api.indy_open_pool_ledger( - FIXED_COMMAND_HANDLE, + commandHandle, configName, config == null ? null : config.toJson(), - cb); + openPoolLedgerCb); checkResult(result); @@ -92,26 +141,15 @@ public void callback(int xcommand_handle, int err, int pool_handle) { private static CompletableFuture refreshPoolLedger( Pool pool) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Void result = null; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int handle = pool.getPoolHandle(); int result = LibIndy.api.indy_refresh_pool_ledger( - FIXED_COMMAND_HANDLE, + commandHandle, handle, - cb); + refreshPoolLedgerCb); checkResult(result); @@ -121,26 +159,15 @@ public void callback(int xcommand_handle, int err) { private static CompletableFuture closePoolLedger( Pool pool) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Void result = null; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int handle = pool.getPoolHandle(); int result = LibIndy.api.indy_close_pool_ledger( - FIXED_COMMAND_HANDLE, + commandHandle, handle, - cb); + closePoolLedgerCb); checkResult(result); @@ -150,24 +177,13 @@ public void callback(int xcommand_handle, int err) { public static CompletableFuture deletePoolLedgerConfig( String configName) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Void result = null; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int result = LibIndy.api.indy_delete_pool_ledger_config( - FIXED_COMMAND_HANDLE, + commandHandle, configName, - cb); + deletePoolLedgerConfigCb); checkResult(result); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java index ad540f85fc..721306d79a 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java @@ -23,34 +23,118 @@ private Signus() { } /* - * STATIC METHODS + * STATIC CALLBACKS */ - public static CompletableFuture createAndStoreMyDid( - Wallet wallet, - CreateAndStoreMyDidJSONParameter didJson) throws IndyException { + private static Callback createAndStoreMyDidCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String did, String verkey, String pk) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + CreateAndStoreMyDidResult result = new CreateAndStoreMyDidResult(did, verkey, pk); + future.complete(result); + } + }; + + private static Callback replaceKeysCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String verkey, String pk) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + ReplaceKeysResult result = new ReplaceKeysResult(verkey, pk); + future.complete(result); + } + }; + + private static Callback storeTheirDidCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Void result = null; + future.complete(result); + } + }; - final CompletableFuture future = new CompletableFuture<> (); + private static Callback signCb = new Callback() { - Callback cb = new Callback() { + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String signature) { - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String did, String verkey, String pk) { + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; - if (! checkCallback(future, xcommand_handle, err)) return; + String result = signature; + future.complete(result); + } + }; - CreateAndStoreMyDidResult result = new CreateAndStoreMyDidResult(did, verkey, pk); - future.complete(result); - } - }; + private static Callback verifySignatureCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, boolean valid) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Boolean result = Boolean.valueOf(valid); + future.complete(result); + } + }; + + private static Callback encryptCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String encryptedMsg) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = encryptedMsg; + future.complete(result); + } + }; + + private static Callback decryptCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String decryptedMsg) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = decryptedMsg; + future.complete(result); + } + }; + + /* + * STATIC METHODS + */ + + public static CompletableFuture createAndStoreMyDid( + Wallet wallet, + CreateAndStoreMyDidJSONParameter didJson) throws IndyException { + + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_create_and_store_my_did( - FIXED_COMMAND_HANDLE, + commandHandle, walletHandle, didJson == null ? null : didJson.toJson(), - cb); + createAndStoreMyDidCb); checkResult(result); @@ -62,28 +146,17 @@ public static CompletableFuture replaceKeys( String did, String identityJson) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String verkey, String pk) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - ReplaceKeysResult result = new ReplaceKeysResult(verkey, pk); - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_replace_keys( - FIXED_COMMAND_HANDLE, + commandHandle, walletHandle, did, identityJson, - cb); + replaceKeysCb); checkResult(result); @@ -94,27 +167,16 @@ public static CompletableFuture storeTheirDid( Wallet wallet, String identityJson) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Void result = null; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_store_their_did( - FIXED_COMMAND_HANDLE, + commandHandle, walletHandle, identityJson, - cb); + storeTheirDidCb); checkResult(result); @@ -126,28 +188,17 @@ public static CompletableFuture sign( String did, String msg) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String signature) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - String result = signature; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_sign( - FIXED_COMMAND_HANDLE, + commandHandle, walletHandle, did, msg, - cb); + signCb); checkResult(result); @@ -160,30 +211,19 @@ public static CompletableFuture verifySignature( String did, String signedMsg) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, boolean valid) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Boolean result = Boolean.valueOf(valid); - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); int poolHandle = pool.getPoolHandle(); int result = LibIndy.api.indy_verify_signature( - FIXED_COMMAND_HANDLE, + commandHandle, walletHandle, poolHandle, did, signedMsg, - cb); + verifySignatureCb); checkResult(result); @@ -195,28 +235,17 @@ public static CompletableFuture encrypt( String did, String msg) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String encryptedMsg) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - String result = encryptedMsg; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_encrypt( - FIXED_COMMAND_HANDLE, + commandHandle, walletHandle, did, msg, - cb); + encryptCb); checkResult(result); @@ -228,28 +257,17 @@ public static CompletableFuture decrypt( String did, String encryptedMsg) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, String decryptedMsg) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - String result = decryptedMsg; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_decrypt( - FIXED_COMMAND_HANDLE, + commandHandle, walletHandle, did, encryptedMsg, - cb); + decryptCb); checkResult(result); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java index 60daeebd66..11473ce02b 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java @@ -25,6 +25,77 @@ public int getWalletHandle() { return this.walletHandle; } + /* + * STATIC CALLBACKS + */ + + private static Callback createWalletCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Void result = null; + future.complete(result); + } + }; + + private static Callback openWalletCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, int handle) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Wallet wallet = new Wallet(handle); + + Wallet result = wallet; + future.complete(result); + } + }; + + private static Callback closeWalletCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Void result = null; + future.complete(result); + } + }; + + private static Callback deleteWalletCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Void result = null; + future.complete(result); + } + }; + + private static Callback walletSetSeqNoForValueCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Void result = null; + future.complete(result); + } + }; + /* * STATIC METHODS */ @@ -40,28 +111,17 @@ public static CompletableFuture createWallet( String config, String credentials) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Void result = null; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int result = LibIndy.api.indy_create_wallet( - FIXED_COMMAND_HANDLE, + commandHandle, poolName, name, xtype, config, credentials, - cb); + createWalletCb); checkResult(result); @@ -73,26 +133,15 @@ public static CompletableFuture openWallet( String runtimeConfig, String credentials) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err, int handle) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Wallet result = new Wallet(handle); - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int result = LibIndy.api.indy_open_wallet( - FIXED_COMMAND_HANDLE, + commandHandle, name, runtimeConfig, credentials, - cb); + openWalletCb); checkResult(result); @@ -102,26 +151,15 @@ public void callback(int xcommand_handle, int err, int handle) { private static CompletableFuture closeWallet( Wallet wallet) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Void result = null; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int handle = wallet.getWalletHandle(); int result = LibIndy.api.indy_close_wallet( - FIXED_COMMAND_HANDLE, + commandHandle, handle, - cb); + closeWalletCb); checkResult(result); @@ -132,25 +170,14 @@ public static CompletableFuture deleteWallet( String name, String credentials) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Void result = null; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int result = LibIndy.api.indy_delete_wallet( - FIXED_COMMAND_HANDLE, + commandHandle, name, credentials, - cb); + deleteWalletCb); checkResult(result); @@ -162,27 +189,16 @@ private static CompletableFuture walletSetSeqNoForValue( String walletKey, String configName) throws IndyException { - final CompletableFuture future = new CompletableFuture<> (); - - Callback cb = new Callback() { - - @SuppressWarnings("unused") - public void callback(int xcommand_handle, int err) { - - if (! checkCallback(future, xcommand_handle, err)) return; - - Void result = null; - future.complete(result); - } - }; + CompletableFuture future = new CompletableFuture<> (); + int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_wallet_set_seq_no_for_value( - FIXED_COMMAND_HANDLE, + commandHandle, walletHandle, walletKey, - cb); + walletSetSeqNoForValueCb); checkResult(result); From 5748e8d1cc01954aa9cff5d16d65a3a1aec47932 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 12 Jul 2017 11:49:06 +0300 Subject: [PATCH 078/349] removed println --- tests/anoncreds.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index 163078a843..d7ad9ca312 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -1520,9 +1520,6 @@ mod demos { buf.retain(|&element| element != 0); let proof_req_json = String::from_utf8(buf).unwrap(); - println!("proof_req_json: {:?}", proof_req_json); - - let claims_json = AnoncredsUtils::prover_get_claims_for_proof_req(prover_wallet_handle, &proof_req_json).unwrap(); let claims: ProofClaimsJson = serde_json::from_str(&claims_json).unwrap(); @@ -1550,7 +1547,6 @@ mod demos { &master_secret_name, &claim_defs_json, &revoc_regs_jsons).unwrap(); - println!("proof_json: {:?}", proof_json); stream.write(format!(r#"{{"type":"check_proof", "data": {}}}"#, proof_json).as_bytes()); let mut buf = vec![0; 102400]; @@ -1559,7 +1555,7 @@ mod demos { buf.retain(|&element| element != 0); let valid = String::from_utf8(buf).unwrap(); - println!("valid: {:?}", valid); + assert_eq!("true", valid); TestUtils::cleanup_storage(); } From c35f8493cd7d9bba83fb68093fac88cdde66df7a Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 12 Jul 2017 11:54:12 +0300 Subject: [PATCH 079/349] fixed tests after merge --- tests/anoncreds.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index f5c5cd5135..eab82a9bdd 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -1320,11 +1320,10 @@ mod demos { TestUtils::cleanup_storage(); let pool_name = "pool1"; - let prover_wallet_name = "prover_wallet"; let xtype = "default"; //1. Create Prover wallet, get wallet handle - let prover_wallet_handle = WalletUtils::create_and_open_wallet(pool_name, prover_wallet_name, xtype).unwrap(); + let prover_wallet_handle = WalletUtils::create_and_open_wallet(pool_name, Some(xtype)).unwrap(); let schema_seq_no = 1; let schema = AnoncredsUtils::get_gvt_schema_json(schema_seq_no); @@ -1456,15 +1455,13 @@ mod demos { TestUtils::cleanup_storage(); let pool_name = "pool1"; - let issuer_wallet_name = "issuer_wallet"; - let prover_wallet_name = "prover_wallet"; let xtype = "default"; //1. Create Issuer wallet, get wallet handle - let issuer_wallet_handle = WalletUtils::create_and_open_wallet(pool_name, issuer_wallet_name, xtype).unwrap(); + let issuer_wallet_handle = WalletUtils::create_and_open_wallet(pool_name, Some(xtype)).unwrap(); //2. Create Prover wallet, get wallet handle - let prover_wallet_handle = WalletUtils::create_and_open_wallet(pool_name, prover_wallet_name, xtype).unwrap(); + let prover_wallet_handle = WalletUtils::create_and_open_wallet(pool_name, Some(xtype)).unwrap(); //3. Issuer create claim definition let schema_seq_no = 1; From 6091135f20430ee0b7c73f974a02e6a964324b52 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 12 Jul 2017 13:47:12 +0300 Subject: [PATCH 080/349] Create wallet and open wallet tests --- wrappers/java/pom.xml | 7 ++ .../org/hyperledger/indy/sdk/ErrorCode.java | 15 +++- .../org/hyperledger/indy/sdk/WalletTest.java | 13 ++-- .../indy/sdk/helpres/InitHelper.java | 14 ++++ .../indy/sdk/helpres/StorageHelper.java | 24 +++++++ .../high_cases/create/CreateWalletTest.java | 72 +++++++++++++++++++ .../high_cases/create/OpenWalletTest.java | 54 ++++++++++++++ .../medium_cases/create/CreateWalletTest.java | 54 ++++++++++++++ .../medium_cases/create/OpenWalletTest.java | 53 ++++++++++++++ 9 files changed, 299 insertions(+), 7 deletions(-) create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/helpres/InitHelper.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/helpres/StorageHelper.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/CreateWalletTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/OpenWalletTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/CreateWalletTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/OpenWalletTest.java diff --git a/wrappers/java/pom.xml b/wrappers/java/pom.xml index b1ea3fa129..1a5121483c 100644 --- a/wrappers/java/pom.xml +++ b/wrappers/java/pom.xml @@ -94,6 +94,13 @@ 3.5 compile + + commons-io + commons-io + 2.5 + + + diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java index 226f428fd9..8e4926d849 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java @@ -36,14 +36,23 @@ public enum ErrorCode { // Caller passed invalid value as param 9 (null, invalid json and etc..) CommonInvalidParam9(108), + // Caller passed invalid value as param 10 (null, invalid json and etc..) + CommonInvalidParam10(109), + + // Caller passed invalid value as param 11 (null, invalid json and etc..) + CommonInvalidParam11(110), + + // Caller passed invalid value as param 12 (null, invalid json and etc..) + CommonInvalidParam12(111), + // Invalid library state was detected in runtime. It signals library bug - CommonInvalidState(109), + CommonInvalidState(112), // Object (json, config, key, claim and etc...) passed by library caller has invalid structure - CommonInvalidStructure(110), + CommonInvalidStructure(113), // IO Error - CommonIOError(111), + CommonIOError(114), // Wallet errors // Caller passed invalid wallet handle diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java index 2a95da198d..67b8b33fd8 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java @@ -10,6 +10,7 @@ import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; import org.hyperledger.indy.sdk.wallet.WalletResults.DeleteWalletResult; import org.hyperledger.indy.sdk.wallet.WalletResults.OpenWalletResult; +import org.hyperledger.indy.sdk.helpres.StorageHelper; import org.junit.Assert; import junit.framework.TestCase; @@ -23,20 +24,22 @@ protected void setUp() throws Exception { if (! LibIndy.isInitialized()) LibIndy.init(new File("./lib/libindy.so")); - OpenPoolLedgerJSONParameter openPoolLedgerOptions = new OpenPoolLedgerJSONParameter(null, null, null); - this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions).get().getPool(); + //OpenPoolLedgerJSONParameter openPoolLedgerOptions = new OpenPoolLedgerJSONParameter(null, null, null); + //this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions).get().getPool(); } @Override protected void tearDown() throws Exception { - this.pool.closePoolLedger(); + //this.pool.closePoolLedger(); } public void testWallet() throws Exception { + StorageHelper.cleanupStorage(); + Wallet wallet; - + CreateWalletResult result1 = Wallet.createWallet("default", "mywallet", null, null, null).get(); Assert.assertNotNull(result1); @@ -49,5 +52,7 @@ public void testWallet() throws Exception { DeleteWalletResult result4 = Wallet.deleteWallet("mywallet", null).get(); Assert.assertNotNull(result4); + + StorageHelper.cleanupStorage(); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/helpres/InitHelper.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/helpres/InitHelper.java new file mode 100644 index 0000000000..6f0df2cc64 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/helpres/InitHelper.java @@ -0,0 +1,14 @@ +package org.hyperledger.indy.sdk.helpres; + + +import org.hyperledger.indy.sdk.LibIndy; + +import java.io.File; + +public class InitHelper { + public static void init() { + + if (!LibIndy.isInitialized()) LibIndy.init(new File("./lib/libindy.so")); + + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/helpres/StorageHelper.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/helpres/StorageHelper.java new file mode 100644 index 0000000000..6cd62ba5f7 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/helpres/StorageHelper.java @@ -0,0 +1,24 @@ +package org.hyperledger.indy.sdk.helpres; + +import org.apache.commons.io.FileUtils; + +import java.io.File; + + +public class StorageHelper { + + private static void cleanDirectory(File path) throws Exception { + if (path.isDirectory()) { + FileUtils.cleanDirectory(path); + } + } + + public static void cleanupStorage() throws Exception { + + File tmpDir = new File(FileUtils.getTempDirectoryPath() + "/indy"); + File homeDir = new File(FileUtils.getUserDirectoryPath() + "/.indy"); + + StorageHelper.cleanDirectory(tmpDir); + StorageHelper.cleanDirectory(homeDir); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/CreateWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/CreateWalletTest.java new file mode 100644 index 0000000000..6fda0ddcb9 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/CreateWalletTest.java @@ -0,0 +1,72 @@ +package org.hyperledger.indy.sdk.wallet.high_cases.create; + +import java.util.concurrent.ExecutionException; + +import org.hyperledger.indy.sdk.helpres.InitHelper; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; +import org.hyperledger.indy.sdk.helpres.StorageHelper; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + + +public class CreateWalletTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void setUp() throws Exception { + InitHelper.init(); + } + + @Test + public void testCreateWalletWorks() throws Exception { + + StorageHelper.cleanupStorage(); + + CreateWalletResult result1 = Wallet.createWallet("default", "mywallet", "default", null, null).get(); + Assert.assertNotNull(result1); + + StorageHelper.cleanupStorage(); + } + + @Test + public void testCreateWalletWorksForEmptyType() throws Exception { + + StorageHelper.cleanupStorage(); + + CreateWalletResult result1 = Wallet.createWallet("default", "mywallet", null, null, null).get(); + Assert.assertNotNull(result1); + + StorageHelper.cleanupStorage(); + } + + @Test + public void testCreateWalletWorksForConfigJson() throws Exception { + + StorageHelper.cleanupStorage(); + + CreateWalletResult result1 = Wallet.createWallet("default", "mywallet", null, + "{\"freshness_time\":1000}", null).get(); + Assert.assertNotNull(result1); + + StorageHelper.cleanupStorage(); + } + + @Test + public void testCreateWalletWorksForUnknowType() throws Exception { + + StorageHelper.cleanupStorage(); + + thrown.expect(ExecutionException.class); + thrown.expectMessage("WalletUnknownTypeError: 201"); + + Wallet.createWallet("default", "mywallet", "unknow_type", null, null).get(); + + StorageHelper.cleanupStorage(); + } +} \ No newline at end of file diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/OpenWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/OpenWalletTest.java new file mode 100644 index 0000000000..c7bd052cc2 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/OpenWalletTest.java @@ -0,0 +1,54 @@ +package org.hyperledger.indy.sdk.wallet.high_cases.create; + +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.hyperledger.indy.sdk.wallet.WalletResults; +import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; +import org.hyperledger.indy.sdk.helpres.StorageHelper; +import org.hyperledger.indy.sdk.helpres.InitHelper; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + + +public class OpenWalletTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void setUp() throws Exception { + InitHelper.init(); + } + + @Test + public void testOpenWalletWorks() throws Exception { + + StorageHelper.cleanupStorage(); + + CreateWalletResult result1 = Wallet.createWallet("default", "mywallet", "default", null, null).get(); + Assert.assertNotNull(result1); + + WalletResults.OpenWalletResult result2 = Wallet.openWallet("mywallet", null, null).get(); + Assert.assertNotNull(result2); + Assert.assertNotNull(result2.getWallet()); + + StorageHelper.cleanupStorage(); + } + + @Test + public void testOpenWalletWorksForConfig() throws Exception { + + StorageHelper.cleanupStorage(); + + CreateWalletResult result1 = Wallet.createWallet("default", "mywallet", "default", null, null).get(); + Assert.assertNotNull(result1); + + WalletResults.OpenWalletResult result2 = Wallet.openWallet("mywallet", "{\"freshness_time\":1000}", null).get(); + Assert.assertNotNull(result2); + Assert.assertNotNull(result2.getWallet()); + + StorageHelper.cleanupStorage(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/CreateWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/CreateWalletTest.java new file mode 100644 index 0000000000..5f3ce65c11 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/CreateWalletTest.java @@ -0,0 +1,54 @@ +package org.hyperledger.indy.sdk.wallet.medium_cases.create; + +import java.util.concurrent.ExecutionException; + +import org.hyperledger.indy.sdk.IndyException; +import org.hyperledger.indy.sdk.helpres.InitHelper; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; +import org.hyperledger.indy.sdk.helpres.StorageHelper; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + + +public class CreateWalletTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void setUp() throws Exception { + InitHelper.init(); + } + + @Test + public void testCreateWalletWorksForEmptyName() throws Exception { + + StorageHelper.cleanupStorage(); + + thrown.expect(IndyException.class); + thrown.expectMessage("CommonInvalidParam2: 101"); + + Wallet.createWallet("", "mywallet", "default", null, null).get(); + + StorageHelper.cleanupStorage(); + } + + @Test + public void testCreateWalletWorksForDuplicateName() throws Exception { + + StorageHelper.cleanupStorage(); + + thrown.expect(ExecutionException.class); + thrown.expectMessage("WalletAlreadyExistsError: 203"); + + CreateWalletResult result1 = Wallet.createWallet("default", "mywallet", "default", null, null).get(); + Assert.assertNotNull(result1); + Wallet.createWallet("default", "mywallet", "default", null, null).get(); + + StorageHelper.cleanupStorage(); + } +} \ No newline at end of file diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/OpenWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/OpenWalletTest.java new file mode 100644 index 0000000000..66b88b3f15 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/OpenWalletTest.java @@ -0,0 +1,53 @@ +package org.hyperledger.indy.sdk.wallet.medium_cases.create; + +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.hyperledger.indy.sdk.wallet.WalletResults; +import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; +import org.hyperledger.indy.sdk.helpres.StorageHelper; +import org.hyperledger.indy.sdk.helpres.InitHelper; +import org.junit.*; +import org.junit.rules.ExpectedException; + +import java.util.concurrent.ExecutionException; + + +public class OpenWalletTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void setUp() throws Exception { + InitHelper.init(); + } + + @Test + public void testOpenWalletWorksForNotCreatedWallet() throws Exception { + + StorageHelper.cleanupStorage(); + + thrown.expect(ExecutionException.class); + thrown.expectMessage("CommonIOError: 114"); + + Wallet.openWallet("mywallet", null, null).get(); + + StorageHelper.cleanupStorage(); + } + + @Test + public void testOpenWalletWorksForTwice() throws Exception { + + StorageHelper.cleanupStorage(); + + thrown.expect(ExecutionException.class); + thrown.expectMessage("CommonIOError: 114");//TODO FIX in IndySdk + + WalletResults.OpenWalletResult result2 = Wallet.openWallet("mywallet", null, null).get(); + Assert.assertNotNull(result2); + Assert.assertNotNull(result2.getWallet()); + + Wallet.openWallet("mywallet", null, null).get(); + + StorageHelper.cleanupStorage(); + } +} \ No newline at end of file From 73c5d4271139ef822401de50b41dac3cb50b1eb6 Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Wed, 12 Jul 2017 13:57:05 +0300 Subject: [PATCH 081/349] Initial implementation and usage of ErrorCodeMatcher for integration tests. --- .../hyperledger/indy/sdk/IndyException.java | 10 ++++++-- .../org/hyperledger/indy/sdk/IndyJava.java | 4 +-- .../indy/sdk/ErrorCodeMatcher.java | 25 +++++++++++++++++++ .../high_cases/create/CreateWalletTest.java | 4 ++- 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/ErrorCodeMatcher.java diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyException.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyException.java index 5fc3d6916a..54a22122b3 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyException.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyException.java @@ -4,13 +4,19 @@ public class IndyException extends Exception { private static final long serialVersionUID = 2650355290834266477L; + private ErrorCode errorCode; + public IndyException(String message) { super(message); } - public static IndyException fromErrorCode(ErrorCode errorCode, int err) { + public IndyException(ErrorCode errorCode) { + this(String.format("%s: %d", errorCode.name(), errorCode.value())); + this.errorCode = errorCode; + } - return new IndyException("" + (errorCode == null ? null : errorCode.name()) + ": " + (errorCode == null ? null : errorCode.value()) + " (" + Integer.toString(err) + ")"); + public ErrorCode getErrorCode() { + return errorCode; } } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java index 395c6e6b24..c60cbb3546 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java @@ -29,7 +29,7 @@ protected static boolean checkCallback(CompletableFuture { + private ErrorCode expectedErrorCode; + + public ErrorCodeMatcher(ErrorCode errorCode) { + this.expectedErrorCode = errorCode; + } + + @Override + protected boolean matchesSafely(IndyException e) { + return expectedErrorCode.equals(e.getErrorCode()); + } + + @Override + public void describeTo(Description description) { + description.appendText("expect ").appendText(expectedErrorCode.name()); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/CreateWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/CreateWalletTest.java index 6fda0ddcb9..ae0d6c1503 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/CreateWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/CreateWalletTest.java @@ -2,6 +2,8 @@ import java.util.concurrent.ExecutionException; +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.helpres.InitHelper; import org.hyperledger.indy.sdk.wallet.Wallet; import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; @@ -63,7 +65,7 @@ public void testCreateWalletWorksForUnknowType() throws Exception { StorageHelper.cleanupStorage(); thrown.expect(ExecutionException.class); - thrown.expectMessage("WalletUnknownTypeError: 201"); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletUnknownTypeError)); Wallet.createWallet("default", "mywallet", "unknow_type", null, null).get(); From 88a0a9a7c6deeb32f409836e95d2dfffe5452d8d Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 12 Jul 2017 14:10:36 +0300 Subject: [PATCH 082/349] Corrected error checking in tests --- .../org/hyperledger/indy/sdk/PoolTest.java | 6 ++---- .../org/hyperledger/indy/sdk/WalletTest.java | 20 ++----------------- .../medium_cases/create/CreateWalletTest.java | 8 ++++---- .../medium_cases/create/OpenWalletTest.java | 5 +++-- 4 files changed, 11 insertions(+), 28 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java index 573f83b277..ae8b6698fc 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java @@ -1,9 +1,8 @@ package org.hyperledger.indy.sdk; -import java.io.File; import java.util.concurrent.Future; -import org.hyperledger.indy.sdk.LibIndy; +import org.hyperledger.indy.sdk.helpres.InitHelper; import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; import org.hyperledger.indy.sdk.pool.PoolResults.OpenPoolLedgerResult; @@ -15,8 +14,7 @@ public class PoolTest extends TestCase { @Override protected void setUp() throws Exception { - - if (! LibIndy.isInitialized()) LibIndy.init(new File("./lib/libindy.so")); + InitHelper.init(); } @Override diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java index 67b8b33fd8..a77576c42d 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java @@ -1,10 +1,6 @@ package org.hyperledger.indy.sdk; -import java.io.File; - -import org.hyperledger.indy.sdk.LibIndy; -import org.hyperledger.indy.sdk.pool.Pool; -import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; +import org.hyperledger.indy.sdk.helpres.InitHelper; import org.hyperledger.indy.sdk.wallet.Wallet; import org.hyperledger.indy.sdk.wallet.WalletResults.CloseWalletResult; import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; @@ -17,21 +13,9 @@ public class WalletTest extends TestCase { - private Pool pool; - @Override protected void setUp() throws Exception { - - if (! LibIndy.isInitialized()) LibIndy.init(new File("./lib/libindy.so")); - - //OpenPoolLedgerJSONParameter openPoolLedgerOptions = new OpenPoolLedgerJSONParameter(null, null, null); - //this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions).get().getPool(); - } - - @Override - protected void tearDown() throws Exception { - - //this.pool.closePoolLedger(); + InitHelper.init(); } public void testWallet() throws Exception { diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/CreateWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/CreateWalletTest.java index 5f3ce65c11..7efb89d2fd 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/CreateWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/CreateWalletTest.java @@ -2,7 +2,8 @@ import java.util.concurrent.ExecutionException; -import org.hyperledger.indy.sdk.IndyException; +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.helpres.InitHelper; import org.hyperledger.indy.sdk.wallet.Wallet; import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; @@ -29,8 +30,7 @@ public void testCreateWalletWorksForEmptyName() throws Exception { StorageHelper.cleanupStorage(); - thrown.expect(IndyException.class); - thrown.expectMessage("CommonInvalidParam2: 101"); + thrown.expect(new ErrorCodeMatcher(ErrorCode.CommonInvalidParam2)); Wallet.createWallet("", "mywallet", "default", null, null).get(); @@ -43,7 +43,7 @@ public void testCreateWalletWorksForDuplicateName() throws Exception { StorageHelper.cleanupStorage(); thrown.expect(ExecutionException.class); - thrown.expectMessage("WalletAlreadyExistsError: 203"); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletAlreadyExistsError)); CreateWalletResult result1 = Wallet.createWallet("default", "mywallet", "default", null, null).get(); Assert.assertNotNull(result1); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/OpenWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/OpenWalletTest.java index 66b88b3f15..992fa6cd1a 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/OpenWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/OpenWalletTest.java @@ -1,8 +1,9 @@ package org.hyperledger.indy.sdk.wallet.medium_cases.create; +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.wallet.Wallet; import org.hyperledger.indy.sdk.wallet.WalletResults; -import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; import org.hyperledger.indy.sdk.helpres.StorageHelper; import org.hyperledger.indy.sdk.helpres.InitHelper; import org.junit.*; @@ -40,7 +41,7 @@ public void testOpenWalletWorksForTwice() throws Exception { StorageHelper.cleanupStorage(); thrown.expect(ExecutionException.class); - thrown.expectMessage("CommonIOError: 114");//TODO FIX in IndySdk + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonIOError));//TODO FIX ERROR TYPE in IndySdk. WalletResults.OpenWalletResult result2 = Wallet.openWallet("mywallet", null, null).get(); Assert.assertNotNull(result2); From cfa4ee44443875d7d4dbf95b159d340b6ea60486 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 12 Jul 2017 16:08:34 +0300 Subject: [PATCH 083/349] added test for prover --- tests/utils/types.rs | 84 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/tests/utils/types.rs b/tests/utils/types.rs index 00ec045dcd..b2d623ac00 100644 --- a/tests/utils/types.rs +++ b/tests/utils/types.rs @@ -237,9 +237,93 @@ pub struct PrimaryClaim { #[derive(Debug, Serialize, Deserialize)] pub struct ProofJson { + pub proofs: HashMap, + pub aggregated_proof: AggregatedProof, pub requested_proof: RequestedProofJson } +#[derive(Debug, Serialize, Deserialize)] +pub struct Proof { + pub primary_proof: PrimaryProof, + pub non_revoc_proof: Option +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct NonRevocProof { + pub x_list: NonRevocProofXList, + pub c_list: NonRevocProofCList +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct NonRevocProofCList { + pub e: String, + pub d: String, + pub a: String, + pub g: String, + pub w: String, + pub s: String, + pub u: String +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct NonRevocProofXList { + pub rho: String, + pub r: String, + pub r_prime: String, + pub r_prime_prime: String, + pub r_prime_prime_prime: String, + pub o: String, + pub o_prime: String, + pub m: String, + pub m_prime: String, + pub t: String, + pub t_prime: String, + pub m2: String, + pub s: String, + pub c: String +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct PrimaryProof { + pub eq_proof: PrimaryEqualProof, + pub ge_proofs: Vec +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct PrimaryPredicateGEProof { + pub u: HashMap, + pub r: HashMap, + pub mj: String, + pub alpha: String, + pub t: HashMap, + pub predicate: Predicate +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct PrimaryEqualProof { + pub revealed_attrs: HashMap, + pub a_prime: String, + pub e: String, + pub v: String, + pub m: HashMap, + pub m1: String, + pub m2: String +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct ClaimProof { + pub proof: Proof, + pub revoc_reg_seq_no: Option, + pub schema_seq_no: i32, + pub issuer_did: String +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct AggregatedProof { + pub c_hash: String, + pub c_list: Vec> +} + #[derive(Debug, Serialize, Deserialize)] pub struct RequestedProofJson { pub revealed_attrs: HashMap, From 0af081e0892ccb929f4082bf612966be1c9aa31d Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 12 Jul 2017 16:08:59 +0300 Subject: [PATCH 084/349] added test for prover --- tests/anoncreds.rs | 130 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index eab82a9bdd..8c09d96c1e 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -1560,6 +1560,136 @@ mod demos { TestUtils::cleanup_storage(); } + #[test] + fn interoperability_test_pysovrin_is_prover() { + TestUtils::cleanup_storage(); + + let schema_seq_no = 1; + let schema = AnoncredsUtils::get_gvt_schema_json(schema_seq_no); + + let mut command = Command::new("python3") + .arg("../anoncreds-fork/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_prover.py") + .spawn().expect("failed to execute process"); + thread::sleep(time::Duration::from_millis(3000)); + + let mut stream = TcpStream::connect("127.0.0.1:1234").unwrap(); + + stream.write(r#"{"type":"get_claim_def"}"#.as_bytes()); + let mut buf = vec![0; 10240]; + stream.read(&mut buf).unwrap(); + buf.retain(|&element| element != 0); + + let claim_def_data: ClaimDefinitionData = serde_json::from_str(&String::from_utf8(buf).unwrap()).unwrap(); + + let claim_def = ClaimDefinition { + issuer_did: ISSUER_DID.to_string(), + signature_type: "CL".to_string(), + schema_seq_no: schema_seq_no, + data: claim_def_data + }; + + let claim_def_json = serde_json::to_string(&claim_def).unwrap(); + + // 7. Prover gets Claims for Proof Request + let proof_req_json = format!(r#"{{ + "nonce":"123432421212", + "name":"proof_req_1", + "version":"0.1", + "requested_attrs":{{"attr_uuid":{{"schema_seq_no":{},"name":"name"}}}}, + "requested_predicates":{{"predicate_uuid":{{"attr_name":"age","p_type":"GE","value":18}}}} + }}"#, schema_seq_no); + + stream.write(format!(r#"{{"type":"get_proof", "data": {}}}"#, proof_req_json).as_bytes()); + let mut buf = vec![0; 102400]; + stream.read(&mut buf).unwrap(); + buf.retain(|&element| element != 0); + + let proof: ProofJson = serde_json::from_str(&String::from_utf8(buf).unwrap()).unwrap(); + println!("proof: {:?}", proof); + + stream.write(r#"{"type":"close"}"#.as_bytes()); + let schemas_json = format!(r#"{{"{}":{}}}"#, 1, schema); + + let &(_, ref value, _) = proof.requested_proof.revealed_attrs.get("attr_uuid").unwrap(); + assert_eq!(value, "Alex"); + + let proof_json = serde_json::to_string(&proof).unwrap(); + let claim_defs_json = format!(r#"{{"{}":{}}}"#, 1, claim_def_json); + let revoc_regs_jsons = "{}"; + + + + ///remove + let wallet_handle = WalletUtils::create_and_open_wallet("pool1", None).unwrap(); + + //2. Issuer create claim definition + let schema_seq_no = 1; + let schema = AnoncredsUtils::get_gvt_schema_json(schema_seq_no); + + //3. Prover create Master Secret + let master_secret_name = "prover_master_secret"; + + AnoncredsUtils::prover_create_master_secret(wallet_handle, master_secret_name).unwrap(); + + //4. Prover create Claim Request + let prover_did = "BzfFCYk"; + let claim_offer_json = AnoncredsUtils::get_claim_offer(ISSUER_DID, schema_seq_no); + let claim_req = AnoncredsUtils::prover_create_and_store_claim_req(wallet_handle, + prover_did, + &claim_offer_json, + &claim_def_json, + master_secret_name).unwrap(); + + //5. Issuer create Claim + let claim_json = AnoncredsUtils::get_gvt_claim_json(); + let (_, xclaim_json) = AnoncredsUtils::issuer_create_claim(wallet_handle, + &claim_req, + &claim_json).unwrap(); + + // 6. Prover store received Claim + AnoncredsUtils::prover_store_claim(wallet_handle, &xclaim_json).unwrap(); + + let claims_json = AnoncredsUtils::prover_get_claims_for_proof_req(wallet_handle, &proof_req_json).unwrap(); + let claims: ProofClaimsJson = serde_json::from_str(&claims_json).unwrap(); + + let claims_for_attr_1 = claims.attrs.get("attr_uuid").unwrap(); + let claim = claims_for_attr_1[0].clone(); + + // 8. Prover create Proof + let requested_claims_json = format!(r#"{{ + "self_attested_attributes":{{}}, + "requested_attrs":{{"attr_uuid":["{}",true]}}, + "requested_predicates":{{}} + }}"#, claim.claim_uuid); + + let schemas_json = format!(r#"{{"{}":{}}}"#, claim.claim_uuid, schema); + let claim_defs_json = format!(r#"{{"{}":{}}}"#, claim.claim_uuid, claim_def_json); + let revoc_regs_jsons = "{}"; + + let proof_json = AnoncredsUtils::prover_create_proof(wallet_handle, + &proof_req_json, + &requested_claims_json, + &schemas_json, + &master_secret_name, + &claim_defs_json, + &revoc_regs_jsons).unwrap(); + let proof: ProofJson = serde_json::from_str(&proof_json).unwrap(); + println!("new proof from indy: {:?}", proof); + ///remove + + + + // 9. Verifier verify proof + let valid = AnoncredsUtils::verifier_verify_proof(&proof_req_json, + &proof_json, + &schemas_json, + &claim_defs_json, + &revoc_regs_jsons).unwrap(); + assert!(valid); + + TestUtils::cleanup_storage(); + } + #[test] fn verifier_verify_proof_works_for_proof_does_not_correspond_proof_request() { TestUtils::cleanup_storage(); From e6641595a30c00c365d84138d91aba8bc0555006 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 12 Jul 2017 16:25:03 +0300 Subject: [PATCH 085/349] Added tests for wallet --- .../org/hyperledger/indy/sdk/ErrorCode.java | 138 +++++++++--------- .../hyperledger/indy/sdk/wallet/Wallet.java | 8 + .../indy/sdk/ErrorCodeMatcher.java | 3 - .../org/hyperledger/indy/sdk/PoolTest.java | 2 +- .../org/hyperledger/indy/sdk/WalletTest.java | 42 ------ .../sdk/{helpres => utils}/InitHelper.java | 2 +- .../StorageUtils.java} | 8 +- .../indy/sdk/wallet/CloseWalletTest.java | 71 +++++++++ .../indy/sdk/wallet/CreateWalletTest.java | 100 +++++++++++++ .../indy/sdk/wallet/DeleteWalletTest.java | 120 +++++++++++++++ .../indy/sdk/wallet/OpenWalletTest.java | 86 +++++++++++ .../high_cases/create/CreateWalletTest.java | 74 ---------- .../high_cases/create/OpenWalletTest.java | 54 ------- .../medium_cases/create/CreateWalletTest.java | 54 ------- .../medium_cases/create/OpenWalletTest.java | 54 ------- 15 files changed, 463 insertions(+), 353 deletions(-) delete mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java rename wrappers/java/src/test/java/org/hyperledger/indy/sdk/{helpres => utils}/InitHelper.java (82%) rename wrappers/java/src/test/java/org/hyperledger/indy/sdk/{helpres/StorageHelper.java => utils/StorageUtils.java} (73%) create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java delete mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/CreateWalletTest.java delete mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/OpenWalletTest.java delete mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/CreateWalletTest.java delete mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/OpenWalletTest.java diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java index 8e4926d849..0896cdd37c 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java @@ -5,39 +5,39 @@ public enum ErrorCode { - Success(0), + Success(0), - // Common errors + // Common errors - // Caller passed invalid value as param 1 (null, invalid json and etc..) - CommonInvalidParam1(100), + // Caller passed invalid value as param 1 (null, invalid json and etc..) + CommonInvalidParam1(100), - // Caller passed invalid value as param 2 (null, invalid json and etc..) - CommonInvalidParam2(101), + // Caller passed invalid value as param 2 (null, invalid json and etc..) + CommonInvalidParam2(101), - // Caller passed invalid value as param 3 (null, invalid json and etc..) - CommonInvalidParam3(102), + // Caller passed invalid value as param 3 (null, invalid json and etc..) + CommonInvalidParam3(102), - // Caller passed invalid value as param 4 (null, invalid json and etc..) - CommonInvalidParam4(103), + // Caller passed invalid value as param 4 (null, invalid json and etc..) + CommonInvalidParam4(103), - // Caller passed invalid value as param 5 (null, invalid json and etc..) - CommonInvalidParam5(104), + // Caller passed invalid value as param 5 (null, invalid json and etc..) + CommonInvalidParam5(104), - // Caller passed invalid value as param 6 (null, invalid json and etc..) - CommonInvalidParam6(105), + // Caller passed invalid value as param 6 (null, invalid json and etc..) + CommonInvalidParam6(105), - // Caller passed invalid value as param 7 (null, invalid json and etc..) - CommonInvalidParam7(106), + // Caller passed invalid value as param 7 (null, invalid json and etc..) + CommonInvalidParam7(106), - // Caller passed invalid value as param 8 (null, invalid json and etc..) - CommonInvalidParam8(107), + // Caller passed invalid value as param 8 (null, invalid json and etc..) + CommonInvalidParam8(107), - // Caller passed invalid value as param 9 (null, invalid json and etc..) - CommonInvalidParam9(108), + // Caller passed invalid value as param 9 (null, invalid json and etc..) + CommonInvalidParam9(108), // Caller passed invalid value as param 10 (null, invalid json and etc..) - CommonInvalidParam10(109), + CommonInvalidParam10(109), // Caller passed invalid value as param 11 (null, invalid json and etc..) CommonInvalidParam11(110), @@ -45,74 +45,80 @@ public enum ErrorCode { // Caller passed invalid value as param 12 (null, invalid json and etc..) CommonInvalidParam12(111), - // Invalid library state was detected in runtime. It signals library bug - CommonInvalidState(112), + // Invalid library state was detected in runtime. It signals library bug + CommonInvalidState(112), - // Object (json, config, key, claim and etc...) passed by library caller has invalid structure - CommonInvalidStructure(113), + // Object (json, config, key, claim and etc...) passed by library caller has invalid structure + CommonInvalidStructure(113), - // IO Error - CommonIOError(114), + // IO Error + CommonIOError(114), - // Wallet errors - // Caller passed invalid wallet handle - WalletInvalidHandle(200), + // Wallet errors + // Caller passed invalid wallet handle + WalletInvalidHandle(200), - // Unknown type of wallet was passed on create_wallet - WalletUnknownTypeError(201), + // Unknown type of wallet was passed on create_wallet + WalletUnknownTypeError(201), - // Attempt to register already existing wallet type - WalletTypeAlreadyRegisteredError(202), + // Attempt to register already existing wallet type + WalletTypeAlreadyRegisteredError(202), - // Attempt to create wallet with name used for another exists wallet - WalletAlreadyExistsError(203), + // Attempt to create wallet with name used for another exists wallet + WalletAlreadyExistsError(203), - // Requested entity id isn't present in wallet - WalletNotFoundError(204), + // Requested entity id isn't present in wallet + WalletNotFoundError(204), - // Trying to use wallet with pool that has different name - WalletIncompatiblePoolError(205), + // Trying to use wallet with pool that has different name + WalletIncompatiblePoolError(205), - // Ledger errors - // Trying to open pool ledger that wasn't created before - PoolLedgerNotCreatedError(300), + // Plugged wallet error + WalletPluggedWallerError(206), - // Caller passed invalid pool ledger handle - PoolLedgerInvalidPoolHandle(301), + // Trying to use wallet with pool that has different name + WalletAlreadyOpenedError(207), - // Pool ledger terminated - PoolLedgerTerminated(302), + // Ledger errors + // Trying to open pool ledger that wasn't created before + PoolLedgerNotCreatedError(300), - // No concensus during ledger operation - LedgerNoConsensusError(303), + // Caller passed invalid pool ledger handle + PoolLedgerInvalidPoolHandle(301), - // Attempt to send unknown or incomplete transaction message - LedgerInvalidTransaction(304), + // Pool ledger terminated + PoolLedgerTerminated(302), - // Attempt to send transaction without the necessary privileges - LedgerSecurityError(305), + // No concensus during ledger operation + LedgerNoConsensusError(303), - // Crypto errors - // Revocation registry is full and creation of new registry is necessary - AnoncredsRevocationRegistryFullError(400), + // Attempt to send unknown or incomplete transaction message + LedgerInvalidTransaction(304), - AnoncredsInvalidUserRevocIndex(401), + // Attempt to send transaction without the necessary privileges + LedgerSecurityError(305), - AnoncredsAccumulatorIsFull(402), + // Crypto errors + // Revocation registry is full and creation of new registry is necessary + AnoncredsRevocationRegistryFullError(400), - AnoncredsNotIssuedError(403), + AnoncredsInvalidUserRevocIndex(401), - // Attempt to generate master secret with dupplicated name - AnoncredsMasterSecretDuplicateNameError(404), + AnoncredsAccumulatorIsFull(402), - AnoncredsProofRejected(405), + AnoncredsNotIssuedError(403), - // Signus errors - // Unknown format of DID entity keys - SignusUnknownCryptoError(500); + // Attempt to generate master secret with dupplicated name + AnoncredsMasterSecretDuplicateNameError(404), + + AnoncredsProofRejected(405), + + // Signus errors + // Unknown format of DID entity keys + SignusUnknownCryptoError(500); private int value; - private static Map map = new HashMap<> (); + private static Map map = new HashMap<>(); private ErrorCode(int value) { diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java index b53b79ac7c..a81cfc56fd 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java @@ -1,8 +1,12 @@ package org.hyperledger.indy.sdk.wallet; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Future; +import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.IndyException; import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.IndyJava; @@ -39,6 +43,8 @@ public int getWalletHandle() { * public Future<...> registerWalletType( ...) throws IndyException;*/ + private static HashSet map = new HashSet<>();//TODO FIX BUG WITH CALLBACK LIVE TIME + public static Future createWallet( String poolName, String name, @@ -60,6 +66,8 @@ public void callback(int xcommand_handle, int err) { } }; + map.add(callback); + int result = LibIndy.api.indy_create_wallet( FIXED_COMMAND_HANDLE, poolName, diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ErrorCodeMatcher.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ErrorCodeMatcher.java index 17a26889cc..a6a7658c63 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ErrorCodeMatcher.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ErrorCodeMatcher.java @@ -3,9 +3,6 @@ import org.hamcrest.Description; import org.hamcrest.TypeSafeMatcher; -/** - * Created by sminaev on 7/12/17. - */ public class ErrorCodeMatcher extends TypeSafeMatcher { private ErrorCode expectedErrorCode; diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java index ae8b6698fc..f0e148621a 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java @@ -2,7 +2,7 @@ import java.util.concurrent.Future; -import org.hyperledger.indy.sdk.helpres.InitHelper; +import org.hyperledger.indy.sdk.utils.InitHelper; import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; import org.hyperledger.indy.sdk.pool.PoolResults.OpenPoolLedgerResult; diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java deleted file mode 100644 index a77576c42d..0000000000 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.hyperledger.indy.sdk; - -import org.hyperledger.indy.sdk.helpres.InitHelper; -import org.hyperledger.indy.sdk.wallet.Wallet; -import org.hyperledger.indy.sdk.wallet.WalletResults.CloseWalletResult; -import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; -import org.hyperledger.indy.sdk.wallet.WalletResults.DeleteWalletResult; -import org.hyperledger.indy.sdk.wallet.WalletResults.OpenWalletResult; -import org.hyperledger.indy.sdk.helpres.StorageHelper; -import org.junit.Assert; - -import junit.framework.TestCase; - -public class WalletTest extends TestCase { - - @Override - protected void setUp() throws Exception { - InitHelper.init(); - } - - public void testWallet() throws Exception { - - StorageHelper.cleanupStorage(); - - Wallet wallet; - - CreateWalletResult result1 = Wallet.createWallet("default", "mywallet", null, null, null).get(); - Assert.assertNotNull(result1); - - OpenWalletResult result2 = Wallet.openWallet("mywallet", null, null).get(); - Assert.assertNotNull(result2); - wallet = result2.getWallet(); - - CloseWalletResult result3 = wallet.closeWallet().get(); - Assert.assertNotNull(result3); - - DeleteWalletResult result4 = Wallet.deleteWallet("mywallet", null).get(); - Assert.assertNotNull(result4); - - StorageHelper.cleanupStorage(); - } -} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/helpres/InitHelper.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/InitHelper.java similarity index 82% rename from wrappers/java/src/test/java/org/hyperledger/indy/sdk/helpres/InitHelper.java rename to wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/InitHelper.java index 6f0df2cc64..68f42af497 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/helpres/InitHelper.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/InitHelper.java @@ -1,4 +1,4 @@ -package org.hyperledger.indy.sdk.helpres; +package org.hyperledger.indy.sdk.utils; import org.hyperledger.indy.sdk.LibIndy; diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/helpres/StorageHelper.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java similarity index 73% rename from wrappers/java/src/test/java/org/hyperledger/indy/sdk/helpres/StorageHelper.java rename to wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java index 6cd62ba5f7..29c498698b 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/helpres/StorageHelper.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java @@ -1,11 +1,11 @@ -package org.hyperledger.indy.sdk.helpres; +package org.hyperledger.indy.sdk.utils; import org.apache.commons.io.FileUtils; import java.io.File; -public class StorageHelper { +public class StorageUtils { private static void cleanDirectory(File path) throws Exception { if (path.isDirectory()) { @@ -18,7 +18,7 @@ public static void cleanupStorage() throws Exception { File tmpDir = new File(FileUtils.getTempDirectoryPath() + "/indy"); File homeDir = new File(FileUtils.getUserDirectoryPath() + "/.indy"); - StorageHelper.cleanDirectory(tmpDir); - StorageHelper.cleanDirectory(homeDir); + StorageUtils.cleanDirectory(tmpDir); + StorageUtils.cleanDirectory(homeDir); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java new file mode 100644 index 0000000000..4db1cf787a --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java @@ -0,0 +1,71 @@ +package org.hyperledger.indy.sdk.wallet; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.utils.InitHelper; +import org.hyperledger.indy.sdk.utils.StorageUtils; +import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; +import static org.junit.Assert.assertNotNull; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.util.concurrent.ExecutionException; + + +public class CloseWalletTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void setUp() throws Exception { + InitHelper.init(); + } + + @Test + public void testCloseWalletWorks() throws Exception { + + StorageUtils.cleanupStorage(); + + Wallet wallet; + + CreateWalletResult result1 = Wallet.createWallet("default", "closeWalletWorks", "default", null, null).get(); + assertNotNull(result1); + + WalletResults.OpenWalletResult result2 = Wallet.openWallet("closeWalletWorks", null, null).get(); + assertNotNull(result2); + wallet = result2.getWallet(); + + WalletResults.CloseWalletResult result3 = wallet.closeWallet().get(); + assertNotNull(result3); + + StorageUtils.cleanupStorage(); + } + + @Test + public void testCloseWalletWorksForTwice() throws Exception { + + StorageUtils.cleanupStorage(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletInvalidHandle)); + + Wallet wallet; + + CreateWalletResult result1 = Wallet.createWallet("default", "closeWalletWorksForTwice", "default", null, null).get(); + assertNotNull(result1); + + WalletResults.OpenWalletResult result2 = Wallet.openWallet("closeWalletWorksForTwice", null, null).get(); + assertNotNull(result2); + wallet = result2.getWallet(); + + WalletResults.CloseWalletResult result3 = wallet.closeWallet().get(); + assertNotNull(result3); + + wallet.closeWallet().get(); + + StorageUtils.cleanupStorage(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java new file mode 100644 index 0000000000..c13064223c --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java @@ -0,0 +1,100 @@ +package org.hyperledger.indy.sdk.wallet; + +import java.util.concurrent.ExecutionException; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.utils.InitHelper; +import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; +import org.hyperledger.indy.sdk.utils.StorageUtils; +import static org.junit.Assert.assertNotNull; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + + +public class CreateWalletTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void setUp() throws Exception { + InitHelper.init(); + } + + @Test + public void testCreateWalletWorks() throws Exception { + + StorageUtils.cleanupStorage(); + + CreateWalletResult result1 = Wallet.createWallet("default", "createWalletWorks", "default", null, null).get(); + assertNotNull(result1); + + StorageUtils.cleanupStorage(); + } + + @Test + public void testCreateWalletWorksForEmptyType() throws Exception { + + StorageUtils.cleanupStorage(); + + CreateWalletResult result1 = Wallet.createWallet("default", "createWalletWorks", null, null, null).get(); + assertNotNull(result1); + + StorageUtils.cleanupStorage(); + } + + @Test + public void testCreateWalletWorksForConfigJson() throws Exception { + + StorageUtils.cleanupStorage(); + + CreateWalletResult result1 = Wallet.createWallet("default", "createWalletWorks", null, + "{\"freshness_time\":1000}", null).get(); + assertNotNull(result1); + + StorageUtils.cleanupStorage(); + } + + @Test + public void testCreateWalletWorksForUnknowType() throws Exception { + + StorageUtils.cleanupStorage(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletUnknownTypeError)); + + Wallet.createWallet("default", "createWalletWorks", "unknow_type", null, null).get(); + + StorageUtils.cleanupStorage(); + } + + @Test + public void testCreateWalletWorksForEmptyName() throws Exception { + + StorageUtils.cleanupStorage(); + + thrown.expect(new ErrorCodeMatcher(ErrorCode.CommonInvalidParam2)); + + Wallet.createWallet("", "createWalletWorks", "default", null, null).get(); + + StorageUtils.cleanupStorage(); + } + + @Test + public void testCreateWalletWorksForDuplicateName() throws Exception { + + StorageUtils.cleanupStorage(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletAlreadyExistsError)); + + CreateWalletResult result1 = Wallet.createWallet("default", "createWalletWorks", "default", null, null).get(); + assertNotNull(result1); + Wallet.createWallet("default", "createWalletWorks", "default", null, null).get(); + + StorageUtils.cleanupStorage(); + } +} \ No newline at end of file diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java new file mode 100644 index 0000000000..0d89187fbe --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java @@ -0,0 +1,120 @@ +package org.hyperledger.indy.sdk.wallet; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.utils.InitHelper; +import org.hyperledger.indy.sdk.utils.StorageUtils; +import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; +import static org.junit.Assert.assertNotNull; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.util.concurrent.ExecutionException; + + +public class DeleteWalletTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void setUp() throws Exception { + InitHelper.init(); + } + + @Test + public void testDeleteWalletWorks() throws Exception { + + StorageUtils.cleanupStorage(); + + CreateWalletResult result1 = Wallet.createWallet("default", "deleteWalletWorks", "default", null, null).get(); + assertNotNull(result1); + + WalletResults.DeleteWalletResult result4 = Wallet.deleteWallet("deleteWalletWorks", null).get(); + assertNotNull(result4); + + CreateWalletResult result3 = Wallet.createWallet("default", "deleteWalletWorks", "default", null, null).get(); + assertNotNull(result3); + + StorageUtils.cleanupStorage(); + } + + @Test + public void testDeleteWalletWorksForClosed() throws Exception { + + StorageUtils.cleanupStorage(); + + Wallet wallet; + + CreateWalletResult result1 = Wallet.createWallet("default", "deleteWalletWorksForClosed", + null, null, null).get(); + assertNotNull(result1); + + WalletResults.OpenWalletResult result2 = Wallet.openWallet("deleteWalletWorksForClosed", null, null).get(); + assertNotNull(result2); + wallet = result2.getWallet(); + + WalletResults.CloseWalletResult result3 = wallet.closeWallet().get(); + assertNotNull(result3); + + WalletResults.DeleteWalletResult result4 = Wallet.deleteWallet("deleteWalletWorksForClosed", null).get(); + assertNotNull(result4); + + CreateWalletResult result5 = Wallet.createWallet("default", "deleteWalletWorksForClosed", null, null, null).get(); + assertNotNull(result5); + + StorageUtils.cleanupStorage(); + } + + @Test + @Ignore//TODO THERE IS BUG IN INDY + public void testDeleteWalletWorksForOpened() throws Exception { + + StorageUtils.cleanupStorage(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonIOError)); + + CreateWalletResult result1 = Wallet.createWallet("default", "deleteWalletWorksForOpened", null, null, null).get(); + assertNotNull(result1); + + WalletResults.OpenWalletResult result2 = Wallet.openWallet("deleteWalletWorksForOpened", null, null).get(); + assertNotNull(result2); + + Wallet.deleteWallet("deleteWalletWorksForOpened", null).get(); + + StorageUtils.cleanupStorage(); + } + + @Test + public void testDeleteWalletWorksForTwice() throws Exception { + + StorageUtils.cleanupStorage(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonIOError)); + + Wallet wallet; + + CreateWalletResult result1 = Wallet.createWallet("default", "deleteWalletWorksForTwice", + null, null, null).get(); + assertNotNull(result1); + + WalletResults.OpenWalletResult result2 = Wallet.openWallet("deleteWalletWorksForTwice", null, null).get(); + assertNotNull(result2); + wallet = result2.getWallet(); + + WalletResults.CloseWalletResult result3 = wallet.closeWallet().get(); + assertNotNull(result3); + + WalletResults.DeleteWalletResult result4 = Wallet.deleteWallet("deleteWalletWorksForTwice", null).get(); + assertNotNull(result4); + + Wallet.deleteWallet("deleteWalletWorksForTwice", null).get(); + + StorageUtils.cleanupStorage(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java new file mode 100644 index 0000000000..14e7903f3e --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java @@ -0,0 +1,86 @@ +package org.hyperledger.indy.sdk.wallet; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; +import org.hyperledger.indy.sdk.utils.StorageUtils; +import org.hyperledger.indy.sdk.utils.InitHelper; +import static org.junit.Assert.assertNotNull; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.util.concurrent.ExecutionException; + + +public class OpenWalletTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void setUp() throws Exception { + InitHelper.init(); + } + + @Test + public void testOpenWalletWorks() throws Exception { + + StorageUtils.cleanupStorage(); + + CreateWalletResult result1 = Wallet.createWallet("default", "openWalletWorks", "default", null, null).get(); + assertNotNull(result1); + + WalletResults.OpenWalletResult result2 = Wallet.openWallet("openWalletWorks", null, null).get(); + assertNotNull(result2); + assertNotNull(result2.getWallet()); + + StorageUtils.cleanupStorage(); + } + + @Test + public void testOpenWalletWorksForConfig() throws Exception { + + StorageUtils.cleanupStorage(); + + CreateWalletResult result1 = Wallet.createWallet("default", "openWalletWorksForConfig", "default", null, null).get(); + assertNotNull(result1); + + WalletResults.OpenWalletResult result2 = Wallet.openWallet("openWalletWorksForConfig", "{\"freshness_time\":1000}", null).get(); + assertNotNull(result2); + assertNotNull(result2.getWallet()); + + StorageUtils.cleanupStorage(); + } + + @Test + public void testOpenWalletWorksForNotCreatedWallet() throws Exception { + + StorageUtils.cleanupStorage(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonIOError)); + + Wallet.openWallet("openWalletWorksForNotCreatedWallet", null, null).get(); + + StorageUtils.cleanupStorage(); + } + + @Test + public void testOpenWalletWorksForTwice() throws Exception { + + StorageUtils.cleanupStorage(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletAlreadyOpenedError)); + + CreateWalletResult result1 = Wallet.createWallet("default", "openWalletWorksForTwice", "default", null, null).get(); + assertNotNull(result1); + + Wallet.openWallet("openWalletWorksForTwice", null, null).get(); + Wallet.openWallet("openWalletWorksForTwice", null, null).get(); + + StorageUtils.cleanupStorage(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/CreateWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/CreateWalletTest.java deleted file mode 100644 index ae0d6c1503..0000000000 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/CreateWalletTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.hyperledger.indy.sdk.wallet.high_cases.create; - -import java.util.concurrent.ExecutionException; - -import org.hyperledger.indy.sdk.ErrorCode; -import org.hyperledger.indy.sdk.ErrorCodeMatcher; -import org.hyperledger.indy.sdk.helpres.InitHelper; -import org.hyperledger.indy.sdk.wallet.Wallet; -import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; -import org.hyperledger.indy.sdk.helpres.StorageHelper; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - - -public class CreateWalletTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Before - public void setUp() throws Exception { - InitHelper.init(); - } - - @Test - public void testCreateWalletWorks() throws Exception { - - StorageHelper.cleanupStorage(); - - CreateWalletResult result1 = Wallet.createWallet("default", "mywallet", "default", null, null).get(); - Assert.assertNotNull(result1); - - StorageHelper.cleanupStorage(); - } - - @Test - public void testCreateWalletWorksForEmptyType() throws Exception { - - StorageHelper.cleanupStorage(); - - CreateWalletResult result1 = Wallet.createWallet("default", "mywallet", null, null, null).get(); - Assert.assertNotNull(result1); - - StorageHelper.cleanupStorage(); - } - - @Test - public void testCreateWalletWorksForConfigJson() throws Exception { - - StorageHelper.cleanupStorage(); - - CreateWalletResult result1 = Wallet.createWallet("default", "mywallet", null, - "{\"freshness_time\":1000}", null).get(); - Assert.assertNotNull(result1); - - StorageHelper.cleanupStorage(); - } - - @Test - public void testCreateWalletWorksForUnknowType() throws Exception { - - StorageHelper.cleanupStorage(); - - thrown.expect(ExecutionException.class); - thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletUnknownTypeError)); - - Wallet.createWallet("default", "mywallet", "unknow_type", null, null).get(); - - StorageHelper.cleanupStorage(); - } -} \ No newline at end of file diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/OpenWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/OpenWalletTest.java deleted file mode 100644 index c7bd052cc2..0000000000 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/high_cases/create/OpenWalletTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.hyperledger.indy.sdk.wallet.high_cases.create; - -import org.hyperledger.indy.sdk.wallet.Wallet; -import org.hyperledger.indy.sdk.wallet.WalletResults; -import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; -import org.hyperledger.indy.sdk.helpres.StorageHelper; -import org.hyperledger.indy.sdk.helpres.InitHelper; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - - -public class OpenWalletTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Before - public void setUp() throws Exception { - InitHelper.init(); - } - - @Test - public void testOpenWalletWorks() throws Exception { - - StorageHelper.cleanupStorage(); - - CreateWalletResult result1 = Wallet.createWallet("default", "mywallet", "default", null, null).get(); - Assert.assertNotNull(result1); - - WalletResults.OpenWalletResult result2 = Wallet.openWallet("mywallet", null, null).get(); - Assert.assertNotNull(result2); - Assert.assertNotNull(result2.getWallet()); - - StorageHelper.cleanupStorage(); - } - - @Test - public void testOpenWalletWorksForConfig() throws Exception { - - StorageHelper.cleanupStorage(); - - CreateWalletResult result1 = Wallet.createWallet("default", "mywallet", "default", null, null).get(); - Assert.assertNotNull(result1); - - WalletResults.OpenWalletResult result2 = Wallet.openWallet("mywallet", "{\"freshness_time\":1000}", null).get(); - Assert.assertNotNull(result2); - Assert.assertNotNull(result2.getWallet()); - - StorageHelper.cleanupStorage(); - } -} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/CreateWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/CreateWalletTest.java deleted file mode 100644 index 7efb89d2fd..0000000000 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/CreateWalletTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.hyperledger.indy.sdk.wallet.medium_cases.create; - -import java.util.concurrent.ExecutionException; - -import org.hyperledger.indy.sdk.ErrorCode; -import org.hyperledger.indy.sdk.ErrorCodeMatcher; -import org.hyperledger.indy.sdk.helpres.InitHelper; -import org.hyperledger.indy.sdk.wallet.Wallet; -import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; -import org.hyperledger.indy.sdk.helpres.StorageHelper; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - - -public class CreateWalletTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Before - public void setUp() throws Exception { - InitHelper.init(); - } - - @Test - public void testCreateWalletWorksForEmptyName() throws Exception { - - StorageHelper.cleanupStorage(); - - thrown.expect(new ErrorCodeMatcher(ErrorCode.CommonInvalidParam2)); - - Wallet.createWallet("", "mywallet", "default", null, null).get(); - - StorageHelper.cleanupStorage(); - } - - @Test - public void testCreateWalletWorksForDuplicateName() throws Exception { - - StorageHelper.cleanupStorage(); - - thrown.expect(ExecutionException.class); - thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletAlreadyExistsError)); - - CreateWalletResult result1 = Wallet.createWallet("default", "mywallet", "default", null, null).get(); - Assert.assertNotNull(result1); - Wallet.createWallet("default", "mywallet", "default", null, null).get(); - - StorageHelper.cleanupStorage(); - } -} \ No newline at end of file diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/OpenWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/OpenWalletTest.java deleted file mode 100644 index 992fa6cd1a..0000000000 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/medium_cases/create/OpenWalletTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.hyperledger.indy.sdk.wallet.medium_cases.create; - -import org.hyperledger.indy.sdk.ErrorCode; -import org.hyperledger.indy.sdk.ErrorCodeMatcher; -import org.hyperledger.indy.sdk.wallet.Wallet; -import org.hyperledger.indy.sdk.wallet.WalletResults; -import org.hyperledger.indy.sdk.helpres.StorageHelper; -import org.hyperledger.indy.sdk.helpres.InitHelper; -import org.junit.*; -import org.junit.rules.ExpectedException; - -import java.util.concurrent.ExecutionException; - - -public class OpenWalletTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Before - public void setUp() throws Exception { - InitHelper.init(); - } - - @Test - public void testOpenWalletWorksForNotCreatedWallet() throws Exception { - - StorageHelper.cleanupStorage(); - - thrown.expect(ExecutionException.class); - thrown.expectMessage("CommonIOError: 114"); - - Wallet.openWallet("mywallet", null, null).get(); - - StorageHelper.cleanupStorage(); - } - - @Test - public void testOpenWalletWorksForTwice() throws Exception { - - StorageHelper.cleanupStorage(); - - thrown.expect(ExecutionException.class); - thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonIOError));//TODO FIX ERROR TYPE in IndySdk. - - WalletResults.OpenWalletResult result2 = Wallet.openWallet("mywallet", null, null).get(); - Assert.assertNotNull(result2); - Assert.assertNotNull(result2.getWallet()); - - Wallet.openWallet("mywallet", null, null).get(); - - StorageHelper.cleanupStorage(); - } -} \ No newline at end of file From f7a32d85b53651baf93b0360198678c35abcfef3 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 12 Jul 2017 17:27:37 +0300 Subject: [PATCH 086/349] fixed test --- tests/anoncreds.rs | 62 ---------------------------------------------- 1 file changed, 62 deletions(-) diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index 8c09d96c1e..cb214a5230 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -1617,68 +1617,6 @@ mod demos { let claim_defs_json = format!(r#"{{"{}":{}}}"#, 1, claim_def_json); let revoc_regs_jsons = "{}"; - - - ///remove - let wallet_handle = WalletUtils::create_and_open_wallet("pool1", None).unwrap(); - - //2. Issuer create claim definition - let schema_seq_no = 1; - let schema = AnoncredsUtils::get_gvt_schema_json(schema_seq_no); - - //3. Prover create Master Secret - let master_secret_name = "prover_master_secret"; - - AnoncredsUtils::prover_create_master_secret(wallet_handle, master_secret_name).unwrap(); - - //4. Prover create Claim Request - let prover_did = "BzfFCYk"; - let claim_offer_json = AnoncredsUtils::get_claim_offer(ISSUER_DID, schema_seq_no); - let claim_req = AnoncredsUtils::prover_create_and_store_claim_req(wallet_handle, - prover_did, - &claim_offer_json, - &claim_def_json, - master_secret_name).unwrap(); - - //5. Issuer create Claim - let claim_json = AnoncredsUtils::get_gvt_claim_json(); - let (_, xclaim_json) = AnoncredsUtils::issuer_create_claim(wallet_handle, - &claim_req, - &claim_json).unwrap(); - - // 6. Prover store received Claim - AnoncredsUtils::prover_store_claim(wallet_handle, &xclaim_json).unwrap(); - - let claims_json = AnoncredsUtils::prover_get_claims_for_proof_req(wallet_handle, &proof_req_json).unwrap(); - let claims: ProofClaimsJson = serde_json::from_str(&claims_json).unwrap(); - - let claims_for_attr_1 = claims.attrs.get("attr_uuid").unwrap(); - let claim = claims_for_attr_1[0].clone(); - - // 8. Prover create Proof - let requested_claims_json = format!(r#"{{ - "self_attested_attributes":{{}}, - "requested_attrs":{{"attr_uuid":["{}",true]}}, - "requested_predicates":{{}} - }}"#, claim.claim_uuid); - - let schemas_json = format!(r#"{{"{}":{}}}"#, claim.claim_uuid, schema); - let claim_defs_json = format!(r#"{{"{}":{}}}"#, claim.claim_uuid, claim_def_json); - let revoc_regs_jsons = "{}"; - - let proof_json = AnoncredsUtils::prover_create_proof(wallet_handle, - &proof_req_json, - &requested_claims_json, - &schemas_json, - &master_secret_name, - &claim_defs_json, - &revoc_regs_jsons).unwrap(); - let proof: ProofJson = serde_json::from_str(&proof_json).unwrap(); - println!("new proof from indy: {:?}", proof); - ///remove - - - // 9. Verifier verify proof let valid = AnoncredsUtils::verifier_verify_proof(&proof_req_json, &proof_json, From b6919c2e633e4e1cdda4f82f188a0c612b77754e Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Wed, 12 Jul 2017 17:38:25 +0300 Subject: [PATCH 087/349] Add base class for indy integration tests. --- .../indy/sdk/IndyIntegrationTest.java | 22 +++++++++++++++++++ .../indy/sdk/wallet/CloseWalletTest.java | 15 ++----------- 2 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java new file mode 100644 index 0000000000..556ddf9851 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java @@ -0,0 +1,22 @@ +package org.hyperledger.indy.sdk; + +import org.hyperledger.indy.sdk.utils.InitHelper; +import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.ExpectedException; +import org.junit.rules.Timeout; + +import java.util.concurrent.TimeUnit; + +public class IndyIntegrationTest { + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Rule + public Timeout globalTimeout= new Timeout(1, TimeUnit.SECONDS); + + @Before + public void setUp() throws Exception { + InitHelper.init(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java index 4db1cf787a..895aaae4dc 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java @@ -2,27 +2,16 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; -import org.hyperledger.indy.sdk.utils.InitHelper; +import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.utils.StorageUtils; import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; import static org.junit.Assert.assertNotNull; -import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import java.util.concurrent.ExecutionException; -public class CloseWalletTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Before - public void setUp() throws Exception { - InitHelper.init(); - } +public class CloseWalletTest extends IndyIntegrationTest { @Test public void testCloseWalletWorks() throws Exception { From 715ebbc6f60621f97d696e9c2cbf14221747a7be Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Wed, 12 Jul 2017 17:46:49 +0300 Subject: [PATCH 088/349] * Basic tests infrastructure for python wrapper was created --- .gitignore | 3 ++ wrappers/python/indy/__init__.py | 7 +++++ wrappers/python/{sovrin => indy}/anoncreds.py | 2 +- wrappers/python/indy/error.py | 12 +++++++ wrappers/python/{sovrin => indy}/ledger.py | 2 +- wrappers/python/indy/libindy.py | 31 +++++++++++++++++++ wrappers/python/{sovrin => indy}/pool.py | 2 +- wrappers/python/{sovrin => indy}/signus.py | 2 +- wrappers/python/{sovrin => indy}/wallet.py | 13 +++++++- wrappers/python/setup.py | 14 +++++++++ wrappers/python/sovrin/__init__.py | 7 ----- wrappers/python/sovrin/error.py | 12 ------- wrappers/python/tests/__init__.py | 0 wrappers/python/tests/libindy.py | 7 +++++ wrappers/python/tests/test_wallet.py | 11 ------- wrappers/python/tests/utils/__init__.py | 0 wrappers/python/tests/utils/storage.py | 28 +++++++++++++++++ wrappers/python/tests/utils/test_storage.py | 19 ++++++++++++ wrappers/python/tests/wallet/__init__.py | 0 .../python/tests/wallet/test_create_wallet.py | 23 ++++++++++++++ 20 files changed, 160 insertions(+), 35 deletions(-) create mode 100644 wrappers/python/indy/__init__.py rename wrappers/python/{sovrin => indy}/anoncreds.py (99%) create mode 100644 wrappers/python/indy/error.py rename wrappers/python/{sovrin => indy}/ledger.py (99%) create mode 100644 wrappers/python/indy/libindy.py rename wrappers/python/{sovrin => indy}/pool.py (97%) rename wrappers/python/{sovrin => indy}/signus.py (98%) rename wrappers/python/{sovrin => indy}/wallet.py (50%) create mode 100644 wrappers/python/setup.py delete mode 100644 wrappers/python/sovrin/__init__.py delete mode 100644 wrappers/python/sovrin/error.py create mode 100644 wrappers/python/tests/__init__.py create mode 100644 wrappers/python/tests/libindy.py delete mode 100644 wrappers/python/tests/test_wallet.py create mode 100644 wrappers/python/tests/utils/__init__.py create mode 100644 wrappers/python/tests/utils/storage.py create mode 100644 wrappers/python/tests/utils/test_storage.py create mode 100644 wrappers/python/tests/wallet/__init__.py create mode 100644 wrappers/python/tests/wallet/test_create_wallet.py diff --git a/.gitignore b/.gitignore index 66b179d245..2a51587df7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ cargo-registry target +build Cargo.lock .idea +.venv +.cache .DS_Store Podfile.lock diff --git a/wrappers/python/indy/__init__.py b/wrappers/python/indy/__init__.py new file mode 100644 index 0000000000..1c5564eee4 --- /dev/null +++ b/wrappers/python/indy/__init__.py @@ -0,0 +1,7 @@ +from indy.error import IndyError + +from indy.anoncreds import Anoncreds +from indy.ledger import Ledger +from indy.pool import Pool +from indy.signus import Signus +from indy.wallet import Wallet diff --git a/wrappers/python/sovrin/anoncreds.py b/wrappers/python/indy/anoncreds.py similarity index 99% rename from wrappers/python/sovrin/anoncreds.py rename to wrappers/python/indy/anoncreds.py index bbcdcb51bd..f158261d89 100644 --- a/wrappers/python/sovrin/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -1,5 +1,5 @@ from typing import Callable -from . import SovrinError +from . import IndyError class Anoncreds(object): diff --git a/wrappers/python/indy/error.py b/wrappers/python/indy/error.py new file mode 100644 index 0000000000..bc0f0ef97f --- /dev/null +++ b/wrappers/python/indy/error.py @@ -0,0 +1,12 @@ +from enum import Enum + +class ErrorCode(Enum): + Success = 0 + CommonInvalidParam1 = 100 + + +class IndyError(Exception): + error_code: ErrorCode + + def __init__(self, error_code: ErrorCode): + self.error_code = error_code diff --git a/wrappers/python/sovrin/ledger.py b/wrappers/python/indy/ledger.py similarity index 99% rename from wrappers/python/sovrin/ledger.py rename to wrappers/python/indy/ledger.py index 25692b5590..6825a74c24 100644 --- a/wrappers/python/sovrin/ledger.py +++ b/wrappers/python/indy/ledger.py @@ -1,5 +1,5 @@ from typing import Callable -from . import SovrinError +from . import IndyError class Ledger(object): diff --git a/wrappers/python/indy/libindy.py b/wrappers/python/indy/libindy.py new file mode 100644 index 0000000000..a7503695fe --- /dev/null +++ b/wrappers/python/indy/libindy.py @@ -0,0 +1,31 @@ +import ctypes +import logging +import sys + + +def load_cdll(): + libindy_prefix_mapping = {'darwin': 'lib', 'linux': 'lib', 'linux2': 'lib', 'win32': ''} + libindy_suffix_mapping = {'darwin': '.dylib', 'linux': '.so', 'linux2': '.so', 'win32': '.dll'} + + os_name = sys.platform + logging.debug("Detected OS name is: %s", os_name) + + try: + libindy_prefix = libindy_prefix_mapping[os_name] + libindy_suffix = libindy_suffix_mapping[os_name] + except KeyError: + logging.error("OS isn't supported: %s", os_name) + raise OSError("OS isn't supported: %s", os_name) + + libindy_name = libindy_prefix + 'indy' + libindy_suffix + logging.debug("Resolved libindy name is: %s", libindy_name) + + try: + return ctypes.CDLL(libindy_name) + except OSError as e: + logging.error("Can't load libindy: %s", e) + raise e + + +# load indy sdk C library +cdll = load_cdll() diff --git a/wrappers/python/sovrin/pool.py b/wrappers/python/indy/pool.py similarity index 97% rename from wrappers/python/sovrin/pool.py rename to wrappers/python/indy/pool.py index e35f41e593..5c6426bdaa 100644 --- a/wrappers/python/sovrin/pool.py +++ b/wrappers/python/indy/pool.py @@ -1,5 +1,5 @@ from typing import Callable -from . import SovrinError +from . import IndyError class Pool(object): diff --git a/wrappers/python/sovrin/signus.py b/wrappers/python/indy/signus.py similarity index 98% rename from wrappers/python/sovrin/signus.py rename to wrappers/python/indy/signus.py index aa55156eb4..5110d7a331 100644 --- a/wrappers/python/sovrin/signus.py +++ b/wrappers/python/indy/signus.py @@ -1,5 +1,5 @@ from typing import Callable -from . import SovrinError +from . import IndyError class Signus(object): diff --git a/wrappers/python/sovrin/wallet.py b/wrappers/python/indy/wallet.py similarity index 50% rename from wrappers/python/sovrin/wallet.py rename to wrappers/python/indy/wallet.py index b7786b198b..c319518cc8 100644 --- a/wrappers/python/sovrin/wallet.py +++ b/wrappers/python/indy/wallet.py @@ -1,10 +1,21 @@ from typing import Callable -from . import SovrinError +from . import IndyError + +from . import libindy class Wallet(object): """TODO: document it""" + # extern indy_error_t indy_create_wallet(indy_handle_t command_handle, + # const char* pool_name, + # const char* name, + # const char* xtype, + # const char* config, + # const char* credentials, + # void (*fn)(indy_handle_t xcommand_handle, indy_error_t err) + # ); + async def create_wallet(pool_name: str, name: str, xtype: str, diff --git a/wrappers/python/setup.py b/wrappers/python/setup.py new file mode 100644 index 0000000000..218ccbfd1e --- /dev/null +++ b/wrappers/python/setup.py @@ -0,0 +1,14 @@ +from distutils.core import setup + +setup( + name='indy-sdk', + version='0.0.1', + packages=['indy'], + url='https://github.com/hyperledger/indy-sdk', + license='MIT/Apache-2.0', + author='Vyacheslav Gudkov', + author_email='vyacheslav.gudkov@dsr-company.com', + description='This is the official SDK for Hyperledger Indy (https://www.hyperledger.org/projects), which provides a distributed-ledger-based foundation for self-sovereign identity (https://sovrin.org). The major artifact of the SDK is a c-callable library.', + install_requires=[], + tests_require=['pytest', 'pytest-asyncio'] +) diff --git a/wrappers/python/sovrin/__init__.py b/wrappers/python/sovrin/__init__.py deleted file mode 100644 index a4c3e3c060..0000000000 --- a/wrappers/python/sovrin/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -from sovrin.error import SovrinError - -from sovrin.anoncreds import Anoncreds -from sovrin.ledger import Ledger -from sovrin.pool import Pool -from sovrin.signus import Signus -from sovrin.wallet import Wallet diff --git a/wrappers/python/sovrin/error.py b/wrappers/python/sovrin/error.py deleted file mode 100644 index 548b43bd11..0000000000 --- a/wrappers/python/sovrin/error.py +++ /dev/null @@ -1,12 +0,0 @@ -from enum import Enum - -class SovrinErrorCode(Enum): - Success = 0 - CommonInvalidParam1 = 100 - - -class SovrinError(Exception): - error_code: SovrinErrorCode - - def __init__(self, error_code: SovrinErrorCode): - self.error_code = error_code diff --git a/wrappers/python/tests/__init__.py b/wrappers/python/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/wrappers/python/tests/libindy.py b/wrappers/python/tests/libindy.py new file mode 100644 index 0000000000..a8332ba5b7 --- /dev/null +++ b/wrappers/python/tests/libindy.py @@ -0,0 +1,7 @@ +import logging + +logging.basicConfig(level=logging.DEBUG) + +def test_libindy_loading_works(): + import indy.libindy as libindy + assert libindy.cdll != None \ No newline at end of file diff --git a/wrappers/python/tests/test_wallet.py b/wrappers/python/tests/test_wallet.py deleted file mode 100644 index 365b78142d..0000000000 --- a/wrappers/python/tests/test_wallet.py +++ /dev/null @@ -1,11 +0,0 @@ -import asyncio - -from sovrin import * - -async def main(): - await Wallet.create_wallet(None, "wallet", "wallet-type", "config", "creds") - - -loop = asyncio.get_event_loop() -loop.run_until_complete(main()) -loop.close() diff --git a/wrappers/python/tests/utils/__init__.py b/wrappers/python/tests/utils/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/wrappers/python/tests/utils/storage.py b/wrappers/python/tests/utils/storage.py new file mode 100644 index 0000000000..4c55e7b1ec --- /dev/null +++ b/wrappers/python/tests/utils/storage.py @@ -0,0 +1,28 @@ +import logging +from pathlib import Path +from shutil import rmtree +from tempfile import gettempdir + + +class StorageUtils(object): + @staticmethod + def cleanup(): + tmp_path = StorageUtils.indy_temp_path() + logging.debug("Cleaning tmp path: %s", tmp_path) + + if tmp_path.exists(): + rmtree(str(tmp_path)) + + home_path = StorageUtils.indy_home_path() + logging.debug("Cleaning home path: %s", home_path) + + if home_path.exists(): + rmtree(str(home_path)) + + @staticmethod + def indy_home_path() -> Path: + return Path.home().joinpath(".indy") + + @staticmethod + def indy_temp_path() -> Path: + return Path(gettempdir()).joinpath("indy") diff --git a/wrappers/python/tests/utils/test_storage.py b/wrappers/python/tests/utils/test_storage.py new file mode 100644 index 0000000000..7d7533d63e --- /dev/null +++ b/wrappers/python/tests/utils/test_storage.py @@ -0,0 +1,19 @@ +from .storage import StorageUtils + +import logging + +logging.basicConfig(level=logging.DEBUG) + + +def test_storage_utils_indy_home_path_works(): + home_path = StorageUtils.indy_home_path() + assert '.indy' in str(home_path) + + +def test_storage_utils_indy_temp_path_works(): + tmp_path = StorageUtils.indy_temp_path() + assert 'indy' in str(tmp_path) + + +def test_storage_utils_cleanup_works(): + StorageUtils.cleanup() diff --git a/wrappers/python/tests/wallet/__init__.py b/wrappers/python/tests/wallet/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/wrappers/python/tests/wallet/test_create_wallet.py b/wrappers/python/tests/wallet/test_create_wallet.py new file mode 100644 index 0000000000..736cc9e4cc --- /dev/null +++ b/wrappers/python/tests/wallet/test_create_wallet.py @@ -0,0 +1,23 @@ +import indy + +from ..utils.storage import StorageUtils + +import logging +import pytest + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.mark.asyncio +async def test_indy_create_wallet_works(): + logging.error("test!") + + StorageUtils.cleanup() + + pool_name = 'indy_create_wallet_works' + wallet_name = 'indy_create_wallet_works' + xtype = 'default' + + await indy.Wallet.create_wallet(pool_name, wallet_name, xtype, None, None) + + StorageUtils.cleanup() From e5e68243f20b65c8ef4a784f7f1008e7b780116c Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 12 Jul 2017 18:23:25 +0300 Subject: [PATCH 089/349] changed path --- tests/anoncreds.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index cb214a5230..7cca2ad024 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -1348,7 +1348,7 @@ mod demos { let claim_offer_json = serde_json::to_string(&claim_offers[0]).unwrap(); let mut command = Command::new("python3") - .arg("../anoncreds-fork/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_issuer.py") + .arg("../anoncreds/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_issuer.py") .spawn().expect("failed to execute process"); thread::sleep(time::Duration::from_millis(3000)); @@ -1470,7 +1470,7 @@ mod demos { let claim_def_json = AnoncredsUtils::issuer_create_claim_definition(issuer_wallet_handle, &ISSUER_DID, &schema, None, false).unwrap(); let mut command = Command::new("python3") - .arg("../anoncreds-fork/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_verifier.py") + .arg("../anoncreds/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_verifier.py") .spawn().expect("failed to execute process"); thread::sleep(time::Duration::from_millis(3000)); @@ -1568,7 +1568,7 @@ mod demos { let schema = AnoncredsUtils::get_gvt_schema_json(schema_seq_no); let mut command = Command::new("python3") - .arg("../anoncreds-fork/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_prover.py") + .arg("../anoncreds/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_prover.py") .spawn().expect("failed to execute process"); thread::sleep(time::Duration::from_millis(3000)); From 8316935a63e13d94ffa87ea53bc5ddcc33d7c649 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Wed, 12 Jul 2017 18:34:21 +0300 Subject: [PATCH 090/349] * Usage of pre-configured logger --- wrappers/python/indy/wallet.py | 26 +++++++++---------- wrappers/python/tests/libindy.py | 6 ++--- wrappers/python/tests/utils/logging.py | 4 +++ wrappers/python/tests/utils/storage.py | 8 +++--- wrappers/python/tests/utils/test_storage.py | 4 --- .../python/tests/wallet/test_create_wallet.py | 13 ++++------ 6 files changed, 28 insertions(+), 33 deletions(-) create mode 100644 wrappers/python/tests/utils/logging.py diff --git a/wrappers/python/indy/wallet.py b/wrappers/python/indy/wallet.py index c319518cc8..b212f24d0c 100644 --- a/wrappers/python/indy/wallet.py +++ b/wrappers/python/indy/wallet.py @@ -23,16 +23,16 @@ async def create_wallet(pool_name: str, credentials: str) -> None: pass - async def open_wallet(pool_handle: int, - name: str, - config: str) -> int: - return -1 - - async def close_wallet(wallet_handle: int) -> None: - pass - - async def delete_wallet(name:str) -> None: - pass - - async def set_seq_no_for_value(wallet_key: str, seq_num: str) -> None: - pass + # async def open_wallet(pool_handle: int, + # name: str, + # config: str) -> int: + # return -1 + # + # async def close_wallet(wallet_handle: int) -> None: + # pass + # + # async def delete_wallet(name:str) -> None: + # pass + # + # async def set_seq_no_for_value(wallet_key: str, seq_num: str) -> None: + # pass diff --git a/wrappers/python/tests/libindy.py b/wrappers/python/tests/libindy.py index a8332ba5b7..8c4474a5b6 100644 --- a/wrappers/python/tests/libindy.py +++ b/wrappers/python/tests/libindy.py @@ -1,7 +1,5 @@ -import logging +from indy import libindy -logging.basicConfig(level=logging.DEBUG) def test_libindy_loading_works(): - import indy.libindy as libindy - assert libindy.cdll != None \ No newline at end of file + assert libindy.cdll is not None diff --git a/wrappers/python/tests/utils/logging.py b/wrappers/python/tests/utils/logging.py new file mode 100644 index 0000000000..c9da66dc0f --- /dev/null +++ b/wrappers/python/tests/utils/logging.py @@ -0,0 +1,4 @@ +import logging + +logger = logging.getLogger("indy_test") +logger.setLevel(level=logging.DEBUG) \ No newline at end of file diff --git a/wrappers/python/tests/utils/storage.py b/wrappers/python/tests/utils/storage.py index 4c55e7b1ec..85097531d9 100644 --- a/wrappers/python/tests/utils/storage.py +++ b/wrappers/python/tests/utils/storage.py @@ -1,20 +1,20 @@ -import logging +from ..utils.logging import logger + from pathlib import Path from shutil import rmtree from tempfile import gettempdir - class StorageUtils(object): @staticmethod def cleanup(): tmp_path = StorageUtils.indy_temp_path() - logging.debug("Cleaning tmp path: %s", tmp_path) + logger.debug("Cleaning tmp path: %s", tmp_path) if tmp_path.exists(): rmtree(str(tmp_path)) home_path = StorageUtils.indy_home_path() - logging.debug("Cleaning home path: %s", home_path) + logger.debug("Cleaning home path: %s", home_path) if home_path.exists(): rmtree(str(home_path)) diff --git a/wrappers/python/tests/utils/test_storage.py b/wrappers/python/tests/utils/test_storage.py index 7d7533d63e..2f3e584828 100644 --- a/wrappers/python/tests/utils/test_storage.py +++ b/wrappers/python/tests/utils/test_storage.py @@ -1,9 +1,5 @@ from .storage import StorageUtils -import logging - -logging.basicConfig(level=logging.DEBUG) - def test_storage_utils_indy_home_path_works(): home_path = StorageUtils.indy_home_path() diff --git a/wrappers/python/tests/wallet/test_create_wallet.py b/wrappers/python/tests/wallet/test_create_wallet.py index 736cc9e4cc..b2299fb34c 100644 --- a/wrappers/python/tests/wallet/test_create_wallet.py +++ b/wrappers/python/tests/wallet/test_create_wallet.py @@ -1,23 +1,20 @@ -import indy +from indy import Wallet from ..utils.storage import StorageUtils +from ..utils.logging import logger -import logging import pytest -logging.basicConfig(level=logging.DEBUG) - @pytest.mark.asyncio async def test_indy_create_wallet_works(): - logging.error("test!") - + logger.debug("asasd") StorageUtils.cleanup() pool_name = 'indy_create_wallet_works' wallet_name = 'indy_create_wallet_works' xtype = 'default' - await indy.Wallet.create_wallet(pool_name, wallet_name, xtype, None, None) + await Wallet.create_wallet(pool_name, wallet_name, xtype, None, None) - StorageUtils.cleanup() + StorageUtils.cleanup() \ No newline at end of file From 79555d55922c4e109213c05abf8aac97c9d76adc Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Wed, 12 Jul 2017 21:28:56 +0200 Subject: [PATCH 091/349] new connection is created in this callback --- .../main/java/org/hyperledger/indy/sdk/agent/Agent.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java index 2294c6028e..0f7510bb60 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java @@ -36,6 +36,7 @@ public void callback(int xcommand_handle, int err, int connection_handle) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); if (! checkCallback(future, err)) return; + assert(! connections.containsKey(Integer.valueOf(connection_handle))); Agent.Connection connection = new Agent.Connection(connection_handle); connections.put(Integer.valueOf(connection_handle), connection); @@ -52,6 +53,7 @@ public void callback(int xcommand_handle, int err, int listener_handle) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); if (! checkCallback(future, err)) return; + assert(! listeners.containsKey(Integer.valueOf(listener_handle))); Agent.Listener listener = new Agent.Listener(listener_handle); listeners.put(Integer.valueOf(listener_handle), listener); @@ -187,8 +189,9 @@ public void callback(int xlistener_handle, int err, int connection_handle, Strin Agent.Listener listener = listeners.get(Integer.valueOf(xlistener_handle)); if (listener == null) return; - Agent.Connection connection = connections.get(Integer.valueOf(connection_handle)); - if (connection == null) return; + assert(! connections.containsKey(Integer.valueOf(connection_handle))); + Agent.Connection connection = new Agent.Connection(connection_handle); + connections.put(Integer.valueOf(connection_handle), connection); agentListenObserver.onConnection(listener, connection, sender_did, receiver_did); } From 96c1496294d8788c273d8852a382ff912f68572b Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Wed, 12 Jul 2017 21:30:13 +0200 Subject: [PATCH 092/349] additional assert() --- .../java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java index d46be6e345..b8f8d0e93a 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java @@ -34,6 +34,7 @@ public static class API { protected static int addFuture(CompletableFuture future) { int commandHandle = Integer.valueOf(atomicInteger.incrementAndGet()); + assert(! futures.containsKey(Integer.valueOf(commandHandle))); futures.put(Integer.valueOf(commandHandle), future); return commandHandle; @@ -42,7 +43,7 @@ protected static int addFuture(CompletableFuture future) { protected static CompletableFuture removeFuture(int xcommand_handle) { CompletableFuture future = futures.remove(Integer.valueOf(xcommand_handle)); - assert (future != null); + assert(future != null); return future; } From 96b378849d6ba41c0e806e719db73c329f4eeaec Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Wed, 12 Jul 2017 21:45:29 +0200 Subject: [PATCH 093/349] Java 1.5 instead of 1.8 --- wrappers/java/pom.xml | 4 ++-- .../org/hyperledger/indy/sdk/ErrorCode.java | 2 +- .../org/hyperledger/indy/sdk/IndyJava.java | 2 +- .../org/hyperledger/indy/sdk/agent/Agent.java | 22 ++++++++--------- .../indy/sdk/anoncreds/Anoncreds.java | 12 +++++----- .../hyperledger/indy/sdk/ledger/Ledger.java | 24 +++++++++---------- .../org/hyperledger/indy/sdk/pool/Pool.java | 10 ++++---- .../hyperledger/indy/sdk/signus/Signus.java | 14 +++++------ .../hyperledger/indy/sdk/wallet/Wallet.java | 10 ++++---- 9 files changed, 50 insertions(+), 50 deletions(-) diff --git a/wrappers/java/pom.xml b/wrappers/java/pom.xml index b1ea3fa129..fc74d27a2e 100644 --- a/wrappers/java/pom.xml +++ b/wrappers/java/pom.xml @@ -32,8 +32,8 @@ maven-compiler-plugin 3.3 - 1.8 - 1.8 + 1.5 + 1.5 diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java index 226f428fd9..fbca690480 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java @@ -103,7 +103,7 @@ public enum ErrorCode { SignusUnknownCryptoError(500); private int value; - private static Map map = new HashMap<> (); + private static Map map = new HashMap (); private ErrorCode(int value) { diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java index b8f8d0e93a..815bc56fda 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java @@ -29,7 +29,7 @@ public static class API { */ private static AtomicInteger atomicInteger = new AtomicInteger(); - private static Map> futures = new ConcurrentHashMap<> (); + private static Map> futures = new ConcurrentHashMap> (); protected static int addFuture(CompletableFuture future) { diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java index 0f7510bb60..b67e7fac0c 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java @@ -17,8 +17,8 @@ */ public class Agent extends IndyJava.API { - private static Map connections = new ConcurrentHashMap<> (); - private static Map listeners = new ConcurrentHashMap<> (); + private static Map connections = new ConcurrentHashMap (); + private static Map listeners = new ConcurrentHashMap (); private Agent() { @@ -136,9 +136,9 @@ public static CompletableFuture agentConnect( Wallet wallet, String senderDid, String receiverDid, - AgentObservers.AgentConnectObserver agentConnectObserver) throws IndyException { + final AgentObservers.AgentConnectObserver agentConnectObserver) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); Callback messageCb = new Callback() { @@ -174,9 +174,9 @@ public void callback(int xconnection_handle, int err, String message) throws Ind public static CompletableFuture agentListen( String endpoint, - AgentObservers.AgentListenObserver agentListenObserver) throws IndyException { + final AgentObservers.AgentListenObserver agentListenObserver) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); Callback connectionCb = new Callback() { @@ -229,7 +229,7 @@ public static CompletableFuture agentAddIdentity( Wallet wallet, String did) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int listenerHandle = listener.getListenerHandle(); @@ -254,7 +254,7 @@ public static CompletableFuture agentRemoveIdentity( Wallet wallet, String did) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int listenerHandle = listener.getListenerHandle(); @@ -276,7 +276,7 @@ public static CompletableFuture agentSend( Agent.Connection connection, String message) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int connectionHandle = connection.getConnectionHandle(); @@ -295,7 +295,7 @@ public static CompletableFuture agentSend( public static CompletableFuture agentCloseConnection( Agent.Connection connection) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int connectionHandle = connection.getConnectionHandle(); @@ -315,7 +315,7 @@ public static CompletableFuture agentCloseConnection( public static CompletableFuture agentCloseListener( Agent.Listener listener) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int listenerHandle = listener.getListenerHandle(); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java index d4eb36f039..448ae38649 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java @@ -113,7 +113,7 @@ public static CompletableFuture issuerCreateAndStoreClaimDef( String signatureType, boolean createNonRevoc) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -138,7 +138,7 @@ public static CompletableFuture issuerCreate int schemaSeqNo, int maxClaimNum) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -163,7 +163,7 @@ public static CompletableFuture issuerCreateClaim( int revocRegSeqNo, int userRevocIndex) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -187,7 +187,7 @@ public static CompletableFuture issuerRevokeClaim( int revocRegSeqNo, int userRevocIndex) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -208,7 +208,7 @@ public static CompletableFuture proverStoreClaimOffer( Wallet wallet, String claimOfferJson) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -228,7 +228,7 @@ public static CompletableFuture proverGetClaimOffers( Wallet wallet, String filterJson) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java index 8510ab6971..9e35b6a991 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java @@ -189,7 +189,7 @@ public static CompletableFuture signAndSubmitRequest( String submitterDid, String requestJson) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int poolHandle = pool.getPoolHandle(); @@ -212,7 +212,7 @@ public static CompletableFuture submitRequest( Pool pool, String requestJson) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int poolHandle = pool.getPoolHandle(); @@ -233,7 +233,7 @@ public static CompletableFuture buildGetDdoRequest( String targetDid, String requestJson) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_get_ddo_request( @@ -254,7 +254,7 @@ public static CompletableFuture buildNymRequest( String alias, String role) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_nym_request( @@ -278,7 +278,7 @@ public static CompletableFuture buildAttribRequest( String raw, String enc) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_attrib_request( @@ -300,7 +300,7 @@ public static CompletableFuture buildGetAttribRequest( String targetDid, String data) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_get_attrib_request( @@ -319,7 +319,7 @@ public static CompletableFuture buildGetNymRequest( String submitterDid, String targetDid) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_get_nym_request( @@ -337,7 +337,7 @@ public static CompletableFuture buildSchemaRequest( String submitterDid, String data) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_schema_request( @@ -355,7 +355,7 @@ public static CompletableFuture buildGetSchemaRequest( String submitterDid, String data) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_get_schema_request( @@ -374,7 +374,7 @@ public static CompletableFuture buildClaimDefTxn( String xref, String data) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_claim_def_txn( @@ -393,7 +393,7 @@ public static CompletableFuture buildGetClaimDefTxn( String submitterDid, String xref) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_get_claim_def_txn( @@ -412,7 +412,7 @@ public static CompletableFuture buildNodeRequest( String targetDid, String data) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_node_request( diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java index 28cfa0b856..90f4b85bd8 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java @@ -106,7 +106,7 @@ public static CompletableFuture createPoolLedgerConfig( String configName, CreatePoolLedgerConfigJSONParameter config) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int result = LibIndy.api.indy_create_pool_ledger_config( @@ -124,7 +124,7 @@ public static CompletableFuture openPoolLedger( String configName, OpenPoolLedgerJSONParameter config) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int result = LibIndy.api.indy_open_pool_ledger( @@ -141,7 +141,7 @@ public static CompletableFuture openPoolLedger( private static CompletableFuture refreshPoolLedger( Pool pool) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int handle = pool.getPoolHandle(); @@ -159,7 +159,7 @@ private static CompletableFuture refreshPoolLedger( private static CompletableFuture closePoolLedger( Pool pool) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int handle = pool.getPoolHandle(); @@ -177,7 +177,7 @@ private static CompletableFuture closePoolLedger( public static CompletableFuture deletePoolLedgerConfig( String configName) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int result = LibIndy.api.indy_delete_pool_ledger_config( diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java index 721306d79a..0b5eed9cdf 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java @@ -125,7 +125,7 @@ public static CompletableFuture createAndStoreMyDid( Wallet wallet, CreateAndStoreMyDidJSONParameter didJson) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -146,7 +146,7 @@ public static CompletableFuture replaceKeys( String did, String identityJson) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -167,7 +167,7 @@ public static CompletableFuture storeTheirDid( Wallet wallet, String identityJson) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -188,7 +188,7 @@ public static CompletableFuture sign( String did, String msg) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -211,7 +211,7 @@ public static CompletableFuture verifySignature( String did, String signedMsg) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -235,7 +235,7 @@ public static CompletableFuture encrypt( String did, String msg) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -257,7 +257,7 @@ public static CompletableFuture decrypt( String did, String encryptedMsg) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java index 11473ce02b..1f9d3273ca 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java @@ -111,7 +111,7 @@ public static CompletableFuture createWallet( String config, String credentials) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int result = LibIndy.api.indy_create_wallet( @@ -133,7 +133,7 @@ public static CompletableFuture openWallet( String runtimeConfig, String credentials) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int result = LibIndy.api.indy_open_wallet( @@ -151,7 +151,7 @@ public static CompletableFuture openWallet( private static CompletableFuture closeWallet( Wallet wallet) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int handle = wallet.getWalletHandle(); @@ -170,7 +170,7 @@ public static CompletableFuture deleteWallet( String name, String credentials) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int result = LibIndy.api.indy_delete_wallet( @@ -189,7 +189,7 @@ private static CompletableFuture walletSetSeqNoForValue( String walletKey, String configName) throws IndyException { - CompletableFuture future = new CompletableFuture<> (); + CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); From 4772415881c485db76f7df4096c28fb2f449e1e0 Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Thu, 13 Jul 2017 08:24:20 +0200 Subject: [PATCH 094/349] wrap indy_build_get_txn_request() --- .../org/hyperledger/indy/sdk/LibIndy.java | 1 + .../hyperledger/indy/sdk/ledger/Ledger.java | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java index 9a7afd907a..3d71fbdfd6 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java @@ -46,6 +46,7 @@ public interface API extends Library { public int indy_build_claim_def_txn(int command_handle, String submitter_did, String xref, String data, Callback cb); public int indy_build_get_claim_def_txn(int command_handle, String submitter_did, String xref, Callback cb); public int indy_build_node_request(int command_handle, String submitter_did, String target_did, String data, Callback cb); + public int indy_build_get_txn_request(int command_handle, String submitter_did, int data, Callback cb); // signus.rs diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java index 9e35b6a991..f065b33f79 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java @@ -179,6 +179,19 @@ public void callback(int xcommand_handle, int err, String request_json) { } }; + public static Callback buildGetTxnRequestCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err, String request_json) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = request_json; + future.complete(result); + } + }; + /* * STATIC METHODS */ @@ -426,4 +439,22 @@ public static CompletableFuture buildNodeRequest( return future; } + + public static CompletableFuture buildGetTxnRequest( + String submitterDid, + int data) throws IndyException { + + CompletableFuture future = new CompletableFuture (); + int commandHandle = addFuture(future); + + int result = LibIndy.api.indy_build_get_txn_request( + commandHandle, + submitterDid, + data, + buildGetTxnRequestCb); + + checkResult(result); + + return future; + } } From 6a72b9083c2dde15993d98b58c7ef5ed34b0c497 Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Thu, 13 Jul 2017 08:33:17 +0200 Subject: [PATCH 095/349] use JsonParameter as optional request builder, but don't depend on it in wrapper methods --- .../main/java/org/hyperledger/indy/sdk/pool/Pool.java | 10 ++++------ .../java/org/hyperledger/indy/sdk/signus/Signus.java | 5 ++--- .../test/java/org/hyperledger/indy/sdk/LedgerTest.java | 2 +- .../test/java/org/hyperledger/indy/sdk/PoolTest.java | 4 ++-- .../test/java/org/hyperledger/indy/sdk/SignusTest.java | 2 +- .../test/java/org/hyperledger/indy/sdk/WalletTest.java | 2 +- 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java index 90f4b85bd8..b67e03b619 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java @@ -5,8 +5,6 @@ import org.hyperledger.indy.sdk.IndyException; import org.hyperledger.indy.sdk.IndyJava; import org.hyperledger.indy.sdk.LibIndy; -import org.hyperledger.indy.sdk.pool.PoolJSONParameters.CreatePoolLedgerConfigJSONParameter; -import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; import com.sun.jna.Callback; @@ -104,7 +102,7 @@ public void callback(int xcommand_handle, int err) { public static CompletableFuture createPoolLedgerConfig( String configName, - CreatePoolLedgerConfigJSONParameter config) throws IndyException { + String config) throws IndyException { CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); @@ -112,7 +110,7 @@ public static CompletableFuture createPoolLedgerConfig( int result = LibIndy.api.indy_create_pool_ledger_config( commandHandle, configName, - config == null ? null : config.toJson(), + config, createPoolLedgerConfigCb); checkResult(result); @@ -122,7 +120,7 @@ public static CompletableFuture createPoolLedgerConfig( public static CompletableFuture openPoolLedger( String configName, - OpenPoolLedgerJSONParameter config) throws IndyException { + String config) throws IndyException { CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); @@ -130,7 +128,7 @@ public static CompletableFuture openPoolLedger( int result = LibIndy.api.indy_open_pool_ledger( commandHandle, configName, - config == null ? null : config.toJson(), + config, openPoolLedgerCb); checkResult(result); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java index 0b5eed9cdf..62122e2934 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java @@ -6,7 +6,6 @@ import org.hyperledger.indy.sdk.IndyJava; import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.pool.Pool; -import org.hyperledger.indy.sdk.signus.SignusJSONParameters.CreateAndStoreMyDidJSONParameter; import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; import org.hyperledger.indy.sdk.signus.SignusResults.ReplaceKeysResult; import org.hyperledger.indy.sdk.wallet.Wallet; @@ -123,7 +122,7 @@ public void callback(int xcommand_handle, int err, String decryptedMsg) { public static CompletableFuture createAndStoreMyDid( Wallet wallet, - CreateAndStoreMyDidJSONParameter didJson) throws IndyException { + String didJson) throws IndyException { CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); @@ -133,7 +132,7 @@ public static CompletableFuture createAndStoreMyDid( int result = LibIndy.api.indy_create_and_store_my_did( commandHandle, walletHandle, - didJson == null ? null : didJson.toJson(), + didJson, createAndStoreMyDidCb); checkResult(result); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/LedgerTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/LedgerTest.java index 262dc5ec65..477ca7f2ce 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/LedgerTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/LedgerTest.java @@ -19,7 +19,7 @@ protected void setUp() throws Exception { if (! LibIndy.isInitialized()) LibIndy.init(new File("./lib/libindy.so")); OpenPoolLedgerJSONParameter openPoolLedgerOptions = new OpenPoolLedgerJSONParameter(null, null, null); - this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions).get(); + this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions.toJson()).get(); } @Override diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java index 172e3d9f96..3905564371 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java @@ -25,12 +25,12 @@ protected void tearDown() throws Exception { public void testPool() throws Exception { /* CreatePoolLedgerConfigOptions config1 = new CreatePoolLedgerConfigOptions(null); - Future future1 = Pool.createPoolLedgerConfig("myconfig", config1); + Future future1 = Pool.createPoolLedgerConfig("myconfig", config1.toJson()); CreatePoolLedgerConfigResult result1 = future1.get(); Assert.assertNotNull(result1);*/ OpenPoolLedgerJSONParameter config2 = new OpenPoolLedgerJSONParameter(null, null, null); - Future future2 = Pool.openPoolLedger("myconfig", config2); + Future future2 = Pool.openPoolLedger("myconfig", config2.toJson()); Pool result2 = future2.get(); Assert.assertNotNull(result2); } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/SignusTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/SignusTest.java index c0be961755..3248221e88 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/SignusTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/SignusTest.java @@ -24,7 +24,7 @@ protected void setUp() throws Exception { if (! LibIndy.isInitialized()) LibIndy.init(new File("./lib/libindy.so")); OpenPoolLedgerJSONParameter openPoolLedgerOptions = new OpenPoolLedgerJSONParameter(null, null, null); - this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions).get(); + this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions.toJson()).get(); this.wallet = Wallet.openWallet("mywallet", null, null).get(); } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java index e79493fcf5..e0db12f255 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/WalletTest.java @@ -19,7 +19,7 @@ protected void setUp() throws Exception { if (! LibIndy.isInitialized()) LibIndy.init(new File("./lib/libindy.so")); OpenPoolLedgerJSONParameter openPoolLedgerOptions = new OpenPoolLedgerJSONParameter(null, null, null); - this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions).get(); + this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions.toJson()).get(); } @Override From 90211866545fc28bccd009dc0a66129cccb96bee Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 10:50:06 +0300 Subject: [PATCH 096/349] small changes --- tests/anoncreds.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index 7d76d57990..7c6215fc74 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -28,8 +28,7 @@ use utils::types::{ ClaimRequestJson, ClaimInfo, ClaimJson, - ProofJson, - ProofRequestJson + ProofJson }; use indy::api::ErrorCode; @@ -1347,7 +1346,7 @@ mod demos { assert!(claim_offers.len() == 1); let claim_offer_json = serde_json::to_string(&claim_offers[0]).unwrap(); - let mut command = Command::new("python3") + Command::new("python3") .arg("../anoncreds/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_issuer.py") .spawn().expect("failed to execute process"); thread::sleep(time::Duration::from_millis(3000)); @@ -1469,7 +1468,7 @@ mod demos { let claim_def_json = AnoncredsUtils::issuer_create_claim_definition(issuer_wallet_handle, &ISSUER_DID, &schema, None, false).unwrap(); - let mut command = Command::new("python3") + Command::new("python3") .arg("../anoncreds/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_verifier.py") .spawn().expect("failed to execute process"); thread::sleep(time::Duration::from_millis(3000)); @@ -1567,7 +1566,7 @@ mod demos { let schema_seq_no = 1; let schema = AnoncredsUtils::get_gvt_schema_json(schema_seq_no); - let mut command = Command::new("python3") + Command::new("python3") .arg("../anoncreds/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_prover.py") .spawn().expect("failed to execute process"); thread::sleep(time::Duration::from_millis(3000)); From ea7f850eab75a12c737f196c454d725ccabec77f Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 11:03:22 +0300 Subject: [PATCH 097/349] added anoncreds repository for jenkins --- ci/ubuntu.dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index 3bf0b84000..806e3e6411 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -32,4 +32,6 @@ USER indy RUN cargo install --git https://github.com/DSRCorporation/cargo-test-xunit -WORKDIR /home/sovrin \ No newline at end of file +WORKDIR /home/sovrin + +RUN git clone https://github.com/hyperledger/indy-anoncreds.git \ No newline at end of file From 0935a9130ee82379029d006ae229f72cfffc6db5 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 11:05:06 +0300 Subject: [PATCH 098/349] added git --- ci/ubuntu.dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index 806e3e6411..91311084d3 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -11,7 +11,8 @@ RUN apt-get update && \ build-essential \ libsqlite3-dev \ libsodium-dev \ - cmake + cmake \ + git ENV RUST_ARCHIVE=rust-1.16.0-x86_64-unknown-linux-gnu.tar.gz ENV RUST_DOWNLOAD_URL=https://static.rust-lang.org/dist/$RUST_ARCHIVE From 6b0e40a3f50aa4017366f0009fccefec72e61eff Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Thu, 13 Jul 2017 10:39:28 +0200 Subject: [PATCH 099/349] more work on observer pattern for agentConnect() and agentListen() --- .../org/hyperledger/indy/sdk/IndyJava.java | 7 +- .../org/hyperledger/indy/sdk/agent/Agent.java | 243 ++++++++++-------- .../indy/sdk/agent/AgentObservers.java | 12 +- .../org/hyperledger/indy/sdk/AgentTest.java | 76 ++++++ 4 files changed, 232 insertions(+), 106 deletions(-) create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java index 815bc56fda..c10e29215a 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java @@ -31,9 +31,14 @@ public static class API { private static AtomicInteger atomicInteger = new AtomicInteger(); private static Map> futures = new ConcurrentHashMap> (); + protected static int newCommandHandle() { + + return Integer.valueOf(atomicInteger.incrementAndGet()); + } + protected static int addFuture(CompletableFuture future) { - int commandHandle = Integer.valueOf(atomicInteger.incrementAndGet()); + int commandHandle = newCommandHandle(); assert(! futures.containsKey(Integer.valueOf(commandHandle))); futures.put(Integer.valueOf(commandHandle), future); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java index b67e7fac0c..4133a72a81 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java @@ -24,41 +24,132 @@ private Agent() { } + /* + * OBSERVERS + */ + + private static Map listenerObservers = new ConcurrentHashMap (); + private static Map connectionObservers = new ConcurrentHashMap (); + + private static int addListenerObserver(AgentObservers.ListenerObserver listenerObserver) { + + int commandHandle = newCommandHandle(); + assert(! listenerObservers.containsKey(Integer.valueOf(commandHandle))); + listenerObservers.put(Integer.valueOf(commandHandle), listenerObserver); + + return commandHandle; + } + + private static AgentObservers.ListenerObserver removeListenerObserver(int xcommand_handle) { + + AgentObservers.ListenerObserver future = listenerObservers.remove(Integer.valueOf(xcommand_handle)); + assert(future != null); + + return future; + } + + private static int addConnectionObserver(AgentObservers.ConnectionObserver connectionObserver) { + + int commandHandle = newCommandHandle(); + assert(! connectionObservers.containsKey(Integer.valueOf(commandHandle))); + connectionObservers.put(Integer.valueOf(commandHandle), connectionObserver); + + return commandHandle; + } + + private static AgentObservers.ConnectionObserver removeConnectionObserver(int xcommand_handle) { + + AgentObservers.ConnectionObserver future = connectionObservers.remove(Integer.valueOf(xcommand_handle)); + assert(future != null); + + return future; + } + /* * STATIC CALLBACKS */ - private static Callback agentConnectCb = new Callback() { + private static Callback agentConnectConnectionCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) - public void callback(int xcommand_handle, int err, int connection_handle) { + @SuppressWarnings("unused") + public void callback(int xcommand_handle, int err, int connection_handle) throws IndyException { - CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + checkCallback(err); assert(! connections.containsKey(Integer.valueOf(connection_handle))); Agent.Connection connection = new Agent.Connection(connection_handle); connections.put(Integer.valueOf(connection_handle), connection); - Agent.Connection result = connection; - future.complete(result); + AgentObservers.ConnectionObserver connectionObserver = removeConnectionObserver(xcommand_handle); + AgentObservers.MessageObserver messageObserver = connectionObserver.onConnection(null, connection, null, null); + connection.messageObserver = messageObserver; } }; - private static Callback agentListenCb = new Callback() { + private static Callback agentConnectMessageCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) - public void callback(int xcommand_handle, int err, int listener_handle) { + @SuppressWarnings("unused") + public void callback(int xconnection_handle, int err, String message) throws IndyException { - CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + checkCallback(err); + + Agent.Connection connection = connections.get(Integer.valueOf(xconnection_handle)); + if (connection == null) return; + + AgentObservers.MessageObserver messageObserver = connection.messageObserver; + messageObserver.onMessage(connection, message); + } + }; + + private static Callback agentListenListenerCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(int xcommand_handle, int err, int listener_handle) throws IndyException { + + checkCallback(err); assert(! listeners.containsKey(Integer.valueOf(listener_handle))); Agent.Listener listener = new Agent.Listener(listener_handle); listeners.put(Integer.valueOf(listener_handle), listener); - Agent.Listener result = listener; - future.complete(result); + AgentObservers.ListenerObserver listenerObserver = removeListenerObserver(xcommand_handle); + AgentObservers.ConnectionObserver connectionObserver = listenerObserver.onListener(listener); + listener.connectionObserver = connectionObserver; + } + }; + + private static Callback agentListenConnectionCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(int xlistener_handle, int err, int connection_handle, String sender_did, String receiver_did) throws IndyException { + + checkCallback(err); + + Agent.Listener listener = listeners.get(Integer.valueOf(xlistener_handle)); + if (listener == null) return; + + assert(! connections.containsKey(Integer.valueOf(connection_handle))); + Agent.Connection connection = new Agent.Connection(connection_handle); + connections.put(Integer.valueOf(connection_handle), connection); + + AgentObservers.ConnectionObserver connectionObserver = listener.connectionObserver; + AgentObservers.MessageObserver messageObserver = connectionObserver.onConnection(listener, connection, sender_did, receiver_did); + connection.messageObserver = messageObserver; + } + }; + + private static Callback agentListenMessageCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(int xconnection_handle, int err, String message) throws IndyException { + + checkCallback(err); + + Agent.Connection connection = connections.get(Integer.valueOf(xconnection_handle)); + if (connection == null) return; + + AgentObservers.MessageObserver messageObserver = connection.messageObserver; + messageObserver.onMessage(connection, message); } }; @@ -131,29 +222,14 @@ public void callback(int xcommand_handle, int err) { * STATIC METHODS */ - public static CompletableFuture agentConnect( + public static void agentConnect( Pool pool, Wallet wallet, String senderDid, String receiverDid, - final AgentObservers.AgentConnectObserver agentConnectObserver) throws IndyException { + AgentObservers.ConnectionObserver connectionObserver) throws IndyException { - CompletableFuture future = new CompletableFuture (); - int commandHandle = addFuture(future); - - Callback messageCb = new Callback() { - - @SuppressWarnings({ "unused", "unchecked" }) - public void callback(int xconnection_handle, int err, String message) throws IndyException { - - checkCallback(err); - - Agent.Connection connection = connections.get(Integer.valueOf(xconnection_handle)); - if (connection == null) return; - - agentConnectObserver.onMessage(connection, message); - } - }; + int commandHandle = addConnectionObserver(connectionObserver); int poolHandle = pool.getPoolHandle(); int walletHandle = wallet.getWalletHandle(); @@ -164,63 +240,26 @@ public void callback(int xconnection_handle, int err, String message) throws Ind walletHandle, senderDid, receiverDid, - agentConnectCb, - messageCb); + agentConnectConnectionCb, + agentConnectMessageCb); checkResult(result); - - return future; } - public static CompletableFuture agentListen( + public static void agentListen( String endpoint, - final AgentObservers.AgentListenObserver agentListenObserver) throws IndyException { + AgentObservers.ListenerObserver listenerObserver) throws IndyException { - CompletableFuture future = new CompletableFuture (); - int commandHandle = addFuture(future); - - Callback connectionCb = new Callback() { - - @SuppressWarnings({ "unused", "unchecked" }) - public void callback(int xlistener_handle, int err, int connection_handle, String sender_did, String receiver_did) throws IndyException { - - checkCallback(err); - - Agent.Listener listener = listeners.get(Integer.valueOf(xlistener_handle)); - if (listener == null) return; - - assert(! connections.containsKey(Integer.valueOf(connection_handle))); - Agent.Connection connection = new Agent.Connection(connection_handle); - connections.put(Integer.valueOf(connection_handle), connection); - - agentListenObserver.onConnection(listener, connection, sender_did, receiver_did); - } - }; - - Callback messageCb = new Callback() { - - @SuppressWarnings({ "unused", "unchecked" }) - public void callback(int xconnection_handle, int err, String message) throws IndyException { - - checkCallback(err); - - Agent.Connection connection = connections.get(Integer.valueOf(xconnection_handle)); - if (connection == null) return; - - agentListenObserver.onMessage(connection, message); - } - }; + int commandHandle = addListenerObserver(listenerObserver); int result = LibIndy.api.indy_agent_listen( commandHandle, endpoint, - agentListenCb, - connectionCb, - messageCb); + agentListenListenerCb, + agentListenConnectionCb, + agentListenMessageCb); checkResult(result); - - return future; } public static CompletableFuture agentAddIdentity( @@ -336,58 +375,60 @@ public static CompletableFuture agentCloseListener( * NESTED CLASSES WITH INSTANCE METHODS */ - public static class Connection { + public static class Listener { - private final int connectionHandle; + private final int listenerHandle; + private AgentObservers.ConnectionObserver connectionObserver; - private Connection(int connectionHandle) { + private Listener(int listenerHandle) { - this.connectionHandle = connectionHandle; + this.listenerHandle = listenerHandle; } - public int getConnectionHandle() { + public int getListenerHandle() { - return this.connectionHandle; + return this.listenerHandle; } - public CompletableFuture agentSend(String message) throws IndyException { + public CompletableFuture agentAddIdentity(Pool pool, Wallet wallet, String did) throws IndyException { - return Agent.agentSend(this, message); + return Agent.agentAddIdentity(this, pool, wallet, did); } - public CompletableFuture agentCloseConnection() throws IndyException { + public CompletableFuture agentRemoveIdentity(Wallet wallet, String did) throws IndyException { - return Agent.agentCloseConnection(this); + return Agent.agentRemoveIdentity(this, wallet, did); } - } - public static class Listener { + public CompletableFuture agentCloseListener() throws IndyException { - private final int listenerHandle; + return Agent.agentCloseListener(this); + } + } - private Listener(int listenerHandle) { + public static class Connection { - this.listenerHandle = listenerHandle; - } + private final int connectionHandle; + private AgentObservers.MessageObserver messageObserver; - public int getListenerHandle() { + private Connection(int connectionHandle) { - return this.listenerHandle; + this.connectionHandle = connectionHandle; } - public CompletableFuture agentAddIdentity(Pool pool, Wallet wallet, String did) throws IndyException { + public int getConnectionHandle() { - return Agent.agentAddIdentity(this, pool, wallet, did); + return this.connectionHandle; } - public CompletableFuture agentRemoveIdentity(Wallet wallet, String did) throws IndyException { + public CompletableFuture agentSend(String message) throws IndyException { - return Agent.agentRemoveIdentity(this, wallet, did); + return Agent.agentSend(this, message); } - public CompletableFuture agentCloseListener() throws IndyException { + public CompletableFuture agentCloseConnection() throws IndyException { - return Agent.agentCloseListener(this); + return Agent.agentCloseConnection(this); } } } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentObservers.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentObservers.java index 9760088516..3cd5c6c39a 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentObservers.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentObservers.java @@ -9,14 +9,18 @@ private AgentObservers() { } - public interface AgentConnectObserver { + public interface ListenerObserver { - public void onMessage(Agent.Connection connection, String message); + public ConnectionObserver onListener(Agent.Listener listener); + } + + public interface ConnectionObserver { + + public MessageObserver onConnection(Agent.Listener listener, Agent.Connection connection, String senderDid, String receiverDid); } - public interface AgentListenObserver extends AgentConnectObserver { + public interface MessageObserver { - public void onConnection(Agent.Listener listener, Agent.Connection connection, String senderDid, String receiverDid); public void onMessage(Agent.Connection connection, String message); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java new file mode 100644 index 0000000000..38e0819191 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java @@ -0,0 +1,76 @@ +package org.hyperledger.indy.sdk; + +import java.io.File; + +import org.hyperledger.indy.sdk.agent.Agent; +import org.hyperledger.indy.sdk.agent.Agent.Connection; +import org.hyperledger.indy.sdk.agent.Agent.Listener; +import org.hyperledger.indy.sdk.agent.AgentObservers.ConnectionObserver; +import org.hyperledger.indy.sdk.agent.AgentObservers.ListenerObserver; +import org.hyperledger.indy.sdk.agent.AgentObservers.MessageObserver; +import org.hyperledger.indy.sdk.pool.Pool; +import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.junit.Assert; + +import junit.framework.TestCase; + +public class AgentTest extends TestCase { + + private Pool pool; + + @Override + protected void setUp() throws Exception { + + if (! LibIndy.isInitialized()) LibIndy.init(new File("./lib/libindy.so")); + + OpenPoolLedgerJSONParameter openPoolLedgerOptions = new OpenPoolLedgerJSONParameter(null, null, null); + this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions.toJson()).get(); + } + + @Override + protected void tearDown() throws Exception { + + this.pool.closePoolLedger(); + } + + public void testAgent() throws Exception { + + Pool pool = Pool.openPoolLedger("myconfig", null).get(); + Wallet wallet = Wallet.openWallet("mywallet", null, null).get(); + Assert.assertNotNull(pool); + Assert.assertNotNull(wallet); + + final MessageObserver messageObserver = new MessageObserver() { + + public void onMessage(Connection connection, String message) { + + System.out.println("Received message '" + message + "' on connection " + connection); + } + }; + + final ConnectionObserver connectionObserver = new ConnectionObserver() { + + public MessageObserver onConnection(Listener listener, Connection connection, String senderDid, String receiverDid) { + + System.out.println("New connection " + connection); + + return messageObserver; + } + }; + + final ListenerObserver listenerObserver = new ListenerObserver() { + + public ConnectionObserver onListener(Listener listener) { + + System.out.println("New listener " + listener); + + return connectionObserver; + } + }; + + Agent.agentConnect(pool, wallet, "did1", "did2", connectionObserver); + + Agent.agentListen("endpoint", listenerObserver); + } +} From 23ce5eed823893570d190e65e7ad568cd164d7f1 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 12:07:25 +0300 Subject: [PATCH 100/349] changes for dockerfile --- ci/ubuntu.dockerfile | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index 91311084d3..249926c2e3 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -27,12 +27,11 @@ RUN curl -fsOSL $RUST_DOWNLOAD_URL \ && ./install.sh ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin" - -RUN useradd -ms /bin/bash -u $uid indy +RUN mkdir /home/indy +WORKDIR /home/indy +RUN git clone https://github.com/hyperledger/indy-anoncreds.git +RUN cargo install --git https://github.com/DSRCorporation/cargo-test-xunit --verbose +RUN useradd -s /bin/bash -u $uid indy USER indy -RUN cargo install --git https://github.com/DSRCorporation/cargo-test-xunit - -WORKDIR /home/sovrin - -RUN git clone https://github.com/hyperledger/indy-anoncreds.git \ No newline at end of file +WORKDIR /home/sovrin \ No newline at end of file From 693278db1f550bee8adb90ed6f9c12983df98d5f Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Thu, 13 Jul 2017 11:10:24 +0200 Subject: [PATCH 101/349] back to Java 1.8 for now because of CompletableFuture class --- wrappers/java/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wrappers/java/pom.xml b/wrappers/java/pom.xml index fc74d27a2e..b1ea3fa129 100644 --- a/wrappers/java/pom.xml +++ b/wrappers/java/pom.xml @@ -32,8 +32,8 @@ maven-compiler-plugin 3.3 - 1.5 - 1.5 + 1.8 + 1.8 From 9e64b7d7a44c1f7fc9e97757c2475d6b80042317 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 12:20:12 +0300 Subject: [PATCH 102/349] changes for dockerfile --- ci/ubuntu.dockerfile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index 249926c2e3..5ea75962be 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -27,11 +27,12 @@ RUN curl -fsOSL $RUST_DOWNLOAD_URL \ && ./install.sh ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin" -RUN mkdir /home/indy -WORKDIR /home/indy -RUN git clone https://github.com/hyperledger/indy-anoncreds.git -RUN cargo install --git https://github.com/DSRCorporation/cargo-test-xunit --verbose -RUN useradd -s /bin/bash -u $uid indy + +RUN useradd -ms /bin/bash -u $uid indy USER indy -WORKDIR /home/sovrin \ No newline at end of file +RUN cargo install --git https://github.com/DSRCorporation/cargo-test-xunit + +WORKDIR /home/indy + +RUN git clone https://github.com/hyperledger/indy-anoncreds.git \ No newline at end of file From 44f93ddde9ffd647c8ba6ef3538b4facb1a0c14c Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 12:37:20 +0300 Subject: [PATCH 103/349] added _ variable for result --- tests/anoncreds.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index 7c6215fc74..8d758787db 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -1353,7 +1353,7 @@ mod demos { let mut stream = TcpStream::connect("127.0.0.1:1234").unwrap(); - stream.write(r#"{"type":"get_claim_def"}"#.as_bytes()); + let _ = stream.write(r#"{"type":"get_claim_def"}"#.as_bytes()); let mut buf = vec![0; 10240]; stream.read(&mut buf).unwrap(); buf.retain(|&element| element != 0); @@ -1377,10 +1377,10 @@ mod demos { &claim_def_json, master_secret_name).unwrap(); - stream.write(format!(r#"{{"type":"issue_claim", "data": {}}}"#, claim_req).as_bytes()); + let _ = stream.write(format!(r#"{{"type":"issue_claim", "data": {}}}"#, claim_req).as_bytes()); let mut buf = vec![0; 10240]; stream.read(&mut buf).unwrap(); - stream.write(r#"{"type":"close"}"#.as_bytes()); + let _ = stream.write(r#"{"type":"close"}"#.as_bytes()); buf.retain(|&element| element != 0); let mut claim_json: ClaimJson = serde_json::from_str(&String::from_utf8(buf).unwrap()).unwrap(); @@ -1475,7 +1475,7 @@ mod demos { let mut stream = TcpStream::connect("127.0.0.1:1234").unwrap(); - stream.write(format!(r#"{{"type":"receive_claim_def", "data": {}}}"#, claim_def_json).as_bytes()); + let _ = stream.write(format!(r#"{{"type":"receive_claim_def", "data": {}}}"#, claim_def_json).as_bytes()); //4. Prover create Master Secret let master_secret_name = "prover_master_secret"; @@ -1513,7 +1513,7 @@ mod demos { // 9. Prover store received Claim AnoncredsUtils::prover_store_claim(prover_wallet_handle, &xclaim_json).unwrap(); - stream.write(r#"{"type":"get_proof_request"}"#.as_bytes()); + let _ = stream.write(r#"{"type":"get_proof_request"}"#.as_bytes()); let mut buf = vec![0; 10240]; stream.read(&mut buf).unwrap(); buf.retain(|&element| element != 0); @@ -1547,10 +1547,10 @@ mod demos { &claim_defs_json, &revoc_regs_jsons).unwrap(); - stream.write(format!(r#"{{"type":"check_proof", "data": {}}}"#, proof_json).as_bytes()); + let _ = stream.write(format!(r#"{{"type":"check_proof", "data": {}}}"#, proof_json).as_bytes()); let mut buf = vec![0; 102400]; stream.read(&mut buf).unwrap(); - stream.write(r#"{"type":"close"}"#.as_bytes()); + let _ = stream.write(r#"{"type":"close"}"#.as_bytes()); buf.retain(|&element| element != 0); let valid = String::from_utf8(buf).unwrap(); @@ -1573,7 +1573,7 @@ mod demos { let mut stream = TcpStream::connect("127.0.0.1:1234").unwrap(); - stream.write(r#"{"type":"get_claim_def"}"#.as_bytes()); + let _ = stream.write(r#"{"type":"get_claim_def"}"#.as_bytes()); let mut buf = vec![0; 10240]; stream.read(&mut buf).unwrap(); buf.retain(|&element| element != 0); @@ -1598,7 +1598,7 @@ mod demos { "requested_predicates":{{"predicate_uuid":{{"attr_name":"age","p_type":"GE","value":18}}}} }}"#, schema_seq_no); - stream.write(format!(r#"{{"type":"get_proof", "data": {}}}"#, proof_req_json).as_bytes()); + let _ = stream.write(format!(r#"{{"type":"get_proof", "data": {}}}"#, proof_req_json).as_bytes()); let mut buf = vec![0; 102400]; stream.read(&mut buf).unwrap(); buf.retain(|&element| element != 0); @@ -1606,7 +1606,7 @@ mod demos { let proof: ProofJson = serde_json::from_str(&String::from_utf8(buf).unwrap()).unwrap(); println!("proof: {:?}", proof); - stream.write(r#"{"type":"close"}"#.as_bytes()); + let _ = stream.write(r#"{"type":"close"}"#.as_bytes()); let schemas_json = format!(r#"{{"{}":{}}}"#, 1, schema); let &(_, ref value, _) = proof.requested_proof.revealed_attrs.get("attr_uuid").unwrap(); From 3f0d28286b7eb7c3afb2c3599fb7411e812d4c2b Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 12:53:49 +0300 Subject: [PATCH 104/349] added feature --- Cargo.toml | 1 + tests/anoncreds.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b51b21a540..c3bca4c5a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ pair_milagro = ["milagro-crypto"] pair_amcl = ["amcl"] hash_openssl = ["openssl"] local_nodes_pool = [] +interoperability_tests = [] [dependencies] amcl = { version = "0.1.0", optional = true } diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index 8d758787db..e2826e6faa 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -22,7 +22,6 @@ use utils::test::TestUtils; use std::collections::HashMap; use utils::types::{ ClaimDefinition, - ClaimDefinitionData, ClaimOffer, ProofClaimsJson, ClaimRequestJson, @@ -1309,11 +1308,18 @@ mod medium_cases { mod demos { use super::*; + #[cfg(feature = "interoperability_tests")] + use utils::types::ClaimDefinitionData; + #[cfg(feature = "interoperability_tests")] use std::process::Command; + #[cfg(feature = "interoperability_tests")] use std::io::prelude::*; + #[cfg(feature = "interoperability_tests")] use std::net::TcpStream; + #[cfg(feature = "interoperability_tests")] use std::{thread, time}; + #[cfg(feature = "interoperability_tests")] #[test] fn interoperability_test_pysovrin_is_issuer() { TestUtils::cleanup_storage(); @@ -1449,6 +1455,7 @@ mod demos { TestUtils::cleanup_storage(); } + #[cfg(feature = "interoperability_tests")] #[test] fn interoperability_test_pysovrin_is_verifier() { TestUtils::cleanup_storage(); @@ -1559,6 +1566,7 @@ mod demos { TestUtils::cleanup_storage(); } + #[cfg(feature = "interoperability_tests")] #[test] fn interoperability_test_pysovrin_is_prover() { TestUtils::cleanup_storage(); From 4981c8fca4b9fffb8fd69b5a240d57d4afc2eb8e Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 13:08:28 +0300 Subject: [PATCH 105/349] added feature for cargo test to jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index d74654c3fa..200c1cbd4f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -75,7 +75,7 @@ def testUbuntu() { sh 'cargo update' try { - sh 'RUST_BACKTRACE=1 RUST_TEST_THREADS=1 cargo test' + sh 'RUST_BACKTRACE=1 RUST_TEST_THREADS=1 cargo test --features "interoperability-tests"' /* TODO FIXME restore after xunit will be fixed sh 'RUST_TEST_THREADS=1 cargo test-xunit' */ From db1e3fdc3bcb25c4bccd7ebe2534b9e4b148e125 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 13:31:43 +0300 Subject: [PATCH 106/349] fixed name of feature --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 200c1cbd4f..b73bb0c745 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -75,7 +75,7 @@ def testUbuntu() { sh 'cargo update' try { - sh 'RUST_BACKTRACE=1 RUST_TEST_THREADS=1 cargo test --features "interoperability-tests"' + sh 'RUST_BACKTRACE=1 RUST_TEST_THREADS=1 cargo test --features "interoperability_tests"' /* TODO FIXME restore after xunit will be fixed sh 'RUST_TEST_THREADS=1 cargo test-xunit' */ From 174183dcd711088a5180804257bbaa031249e955 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 13 Jul 2017 13:33:07 +0300 Subject: [PATCH 107/349] Completed Wallet integration tests --- .../java/org/hyperledger/indy/sdk/wallet/Wallet.java | 4 ++-- .../hyperledger/indy/sdk/wallet/CreateWalletTest.java | 11 ++--------- .../hyperledger/indy/sdk/wallet/DeleteWalletTest.java | 11 ++--------- .../hyperledger/indy/sdk/wallet/OpenWalletTest.java | 11 ++--------- 4 files changed, 8 insertions(+), 29 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java index a81cfc56fd..82c7f4d408e 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java @@ -43,7 +43,7 @@ public int getWalletHandle() { * public Future<...> registerWalletType( ...) throws IndyException;*/ - private static HashSet map = new HashSet<>();//TODO FIX BUG WITH CALLBACK LIVE TIME + private static HashSet map = new HashSet<>();//TODO FIX BUG WITH CALLBACK LIVETIME public static Future createWallet( String poolName, @@ -102,7 +102,7 @@ public void callback(int xcommand_handle, int err, int handle) { future.complete(result); } }; - + int result = LibIndy.api.indy_open_wallet( FIXED_COMMAND_HANDLE, name, diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java index c13064223c..7469233ff9 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java @@ -4,6 +4,7 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.utils.InitHelper; import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; import org.hyperledger.indy.sdk.utils.StorageUtils; @@ -14,15 +15,7 @@ import org.junit.rules.ExpectedException; -public class CreateWalletTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Before - public void setUp() throws Exception { - InitHelper.init(); - } +public class CreateWalletTest extends IndyIntegrationTest { @Test public void testCreateWalletWorks() throws Exception { diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java index 0d89187fbe..f0ae140a67 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java @@ -2,6 +2,7 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.utils.InitHelper; import org.hyperledger.indy.sdk.utils.StorageUtils; import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; @@ -15,15 +16,7 @@ import java.util.concurrent.ExecutionException; -public class DeleteWalletTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Before - public void setUp() throws Exception { - InitHelper.init(); - } +public class DeleteWalletTest extends IndyIntegrationTest { @Test public void testDeleteWalletWorks() throws Exception { diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java index 14e7903f3e..97d562b223 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java @@ -2,6 +2,7 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; import org.hyperledger.indy.sdk.utils.StorageUtils; import org.hyperledger.indy.sdk.utils.InitHelper; @@ -14,15 +15,7 @@ import java.util.concurrent.ExecutionException; -public class OpenWalletTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Before - public void setUp() throws Exception { - InitHelper.init(); - } +public class OpenWalletTest extends IndyIntegrationTest { @Test public void testOpenWalletWorks() throws Exception { From c90f76acb8282bcb8ccf64d0b260906428399acc Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Wed, 12 Jul 2017 18:34:46 +0300 Subject: [PATCH 108/349] [java] Implement basic tests for pool create and open. --- .../indy/sdk/pool/CreatePoolTest.java | 26 ++++++++ .../indy/sdk/pool/OpenPoolTest.java | 59 +++++++++++++++++++ .../hyperledger/indy/sdk/utils/PoolUtils.java | 56 ++++++++++++++++++ .../indy/sdk/utils/StorageUtils.java | 38 ++++++++---- 4 files changed, 168 insertions(+), 11 deletions(-) create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java new file mode 100644 index 0000000000..a1ee1d9546 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java @@ -0,0 +1,26 @@ +package org.hyperledger.indy.sdk.pool; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.hyperledger.indy.sdk.utils.StorageUtils; +import org.junit.Test; + +import java.io.File; + +public class CreatePoolTest extends IndyIntegrationTest { + + @Test + public void testCreatePoolWorks() throws Exception { + StorageUtils.cleanupStorage(); + + File genesisTxnFile = PoolUtils.createGenesisTxnFile("genesis.txn"); + + PoolJSONParameters.CreatePoolLedgerConfigJSONParameter createPoolLedgerConfigJSONParameter + = new PoolJSONParameters.CreatePoolLedgerConfigJSONParameter(genesisTxnFile.getAbsolutePath()); + Pool.createPoolLedgerConfig("testCreatePoolWorks", createPoolLedgerConfigJSONParameter).get(); + + StorageUtils.cleanupStorage(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java new file mode 100644 index 0000000000..c984dfe730 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java @@ -0,0 +1,59 @@ +package org.hyperledger.indy.sdk.pool; + +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; +import org.hyperledger.indy.sdk.pool.PoolResults.OpenPoolLedgerResult; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.hyperledger.indy.sdk.utils.StorageUtils; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +public class OpenPoolTest extends IndyIntegrationTest { + + @Test + public void testOpenPoolWorks() throws Exception { + StorageUtils.cleanupStorage(); + + String poolName = PoolUtils.createPoolLedgerConfig(); + + OpenPoolLedgerJSONParameter config2 = new OpenPoolLedgerJSONParameter(null, null, null); + OpenPoolLedgerResult openResult = Pool.openPoolLedger(poolName, config2).get(); + + assertNotNull(openResult); + + openResult.getPool().closePoolLedger(); + StorageUtils.cleanupStorage(); + } + + @Test + public void testOpenPoolWorksForTwoNodes() throws Exception { + StorageUtils.cleanupStorage(); + + String poolName = PoolUtils.createPoolLedgerConfig(2); + + OpenPoolLedgerJSONParameter config2 = new OpenPoolLedgerJSONParameter(null, null, null); + OpenPoolLedgerResult openResult = Pool.openPoolLedger(poolName, config2).get(); + + assertNotNull(openResult); + + openResult.getPool().closePoolLedger(); + StorageUtils.cleanupStorage(); + } + + @Test + public void testOpenPoolWorksForThreeNodes() throws Exception { + StorageUtils.cleanupStorage(); + + String poolName = PoolUtils.createPoolLedgerConfig(3); + + OpenPoolLedgerJSONParameter config2 = new OpenPoolLedgerJSONParameter(null, null, null); + OpenPoolLedgerResult openResult = Pool.openPoolLedger(poolName, config2).get(); + + assertNotNull(openResult); + + openResult.getPool().closePoolLedger(); + StorageUtils.cleanupStorage(); + } + +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java new file mode 100644 index 0000000000..47d59cf224 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java @@ -0,0 +1,56 @@ +package org.hyperledger.indy.sdk.utils; + +import org.hyperledger.indy.sdk.IndyException; +import org.hyperledger.indy.sdk.pool.Pool; +import org.hyperledger.indy.sdk.pool.PoolJSONParameters; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +public class PoolUtils { + public static File createGenesisTxnFile(String filename) throws IOException { + return createGenesisTxnFile(filename, 4); + } + + public static File createGenesisTxnFile(String filename, int nodesCnt) throws IOException { + String path = StorageUtils.getTmpPath(filename); + String[] defaultTxns = new String[]{ + "{\"data\":{\"alias\":\"Node1\",\"client_ip\":\"10.0.0.2\",\"client_port\":9702,\"node_ip\":\"10.0.0.2\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\",\"identifier\":\"FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4\",\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\",\"type\":\"0\"}", + "{\"data\":{\"alias\":\"Node2\",\"client_ip\":\"10.0.0.2\",\"client_port\":9704,\"node_ip\":\"10.0.0.2\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\",\"identifier\":\"8QhFxKxyaFsJy4CyxeYX34dFH8oWqyBv1P4HLQCsoeLy\",\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\",\"type\":\"0\"}", + "{\"data\":{\"alias\":\"Node3\",\"client_ip\":\"10.0.0.2\",\"client_port\":9706,\"node_ip\":\"10.0.0.2\",\"node_port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\",\"identifier\":\"2yAeV5ftuasWNgQwVYzeHeTuM7LwwNtPR3Zg9N4JiDgF\",\"txnId\":\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\",\"type\":\"0\"}", + "{\"data\":{\"alias\":\"Node4\",\"client_ip\":\"10.0.0.2\",\"client_port\":9708,\"node_ip\":\"10.0.0.2\",\"node_port\":9707,\"services\":[\"VALIDATOR\"]},\"dest\":\"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA\",\"identifier\":\"FTE95CVthRtrBnK2PYCBbC9LghTcGwi9Zfi1Gz2dnyNx\",\"txnId\":\"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008\",\"type\":\"0\"}" + }; + + File file = new File(path); + + FileWriter fw = new FileWriter(file); + for (int i = 0; i < nodesCnt; i++) { + fw.write(defaultTxns[i]); + fw.write("\n"); + } + + fw.close(); + + return file; + } + + public static String createPoolLedgerConfig() throws InterruptedException, ExecutionException, IndyException, IOException { + return createPoolLedgerConfig(4); + } + + public static String createPoolLedgerConfig(int nodesCnt) throws InterruptedException, ExecutionException, IndyException, IOException { + String poolName = "test"; + createPoolLedgerConfig(poolName, nodesCnt); + return poolName; + } + + public static void createPoolLedgerConfig(String poolName, int nodesCnt) throws IOException, InterruptedException, java.util.concurrent.ExecutionException, IndyException { + File genesisTxnFile = createGenesisTxnFile("temp.txn", nodesCnt); + PoolJSONParameters.CreatePoolLedgerConfigJSONParameter createPoolLedgerConfigJSONParameter + = new PoolJSONParameters.CreatePoolLedgerConfigJSONParameter(genesisTxnFile.getAbsolutePath()); + Pool.createPoolLedgerConfig(poolName, createPoolLedgerConfigJSONParameter).get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java index 29c498698b..e0cfc2fe75 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java @@ -7,18 +7,34 @@ public class StorageUtils { - private static void cleanDirectory(File path) throws Exception { - if (path.isDirectory()) { - FileUtils.cleanDirectory(path); - } - } + private static void cleanDirectory(File path) throws Exception { + if (path.isDirectory()) { + FileUtils.cleanDirectory(path); + } + } - public static void cleanupStorage() throws Exception { + public static void cleanupStorage() throws Exception { - File tmpDir = new File(FileUtils.getTempDirectoryPath() + "/indy"); - File homeDir = new File(FileUtils.getUserDirectoryPath() + "/.indy"); + File tmpDir = new File(getTmpPath()); + File homeDir = new File(getIndyHomePath()); - StorageUtils.cleanDirectory(tmpDir); - StorageUtils.cleanDirectory(homeDir); - } + StorageUtils.cleanDirectory(tmpDir); + StorageUtils.cleanDirectory(homeDir); + } + + public static String getIndyHomePath() { + return FileUtils.getUserDirectoryPath() + "/.indy/"; + } + + public static String getIndyHomePath(String filename) { + return getIndyHomePath() + filename; + } + + public static String getTmpPath() { + return FileUtils.getTempDirectoryPath() + "/indy/"; + } + + public static String getTmpPath(String filename) { + return getTmpPath() + filename; + } } From 11912fc70eda96ede11c713aa40708193f45426f Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Wed, 12 Jul 2017 18:40:53 +0300 Subject: [PATCH 109/349] [java] Fix error codes. --- .../src/main/java/org/hyperledger/indy/sdk/ErrorCode.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java index 0896cdd37c..9300d16509 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java @@ -73,11 +73,8 @@ public enum ErrorCode { // Trying to use wallet with pool that has different name WalletIncompatiblePoolError(205), - // Plugged wallet error - WalletPluggedWallerError(206), - - // Trying to use wallet with pool that has different name - WalletAlreadyOpenedError(207), + // Trying to open wallet that was opened already + WalletAlreadyOpenedError(206), // Ledger errors // Trying to open pool ledger that wasn't created before From 20d4e4086a11f419c83abd55f7266c10dc302feb Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Thu, 13 Jul 2017 14:18:55 +0300 Subject: [PATCH 110/349] [java] Update pool tests after merge with master. --- .../indy/sdk/pool/CreatePoolTest.java | 4 +--- .../indy/sdk/pool/OpenPoolTest.java | 19 +++++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java index a1ee1d9546..2d6c82cc11 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java @@ -1,7 +1,5 @@ package org.hyperledger.indy.sdk.pool; -import org.hyperledger.indy.sdk.ErrorCode; -import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.utils.PoolUtils; import org.hyperledger.indy.sdk.utils.StorageUtils; @@ -19,7 +17,7 @@ public void testCreatePoolWorks() throws Exception { PoolJSONParameters.CreatePoolLedgerConfigJSONParameter createPoolLedgerConfigJSONParameter = new PoolJSONParameters.CreatePoolLedgerConfigJSONParameter(genesisTxnFile.getAbsolutePath()); - Pool.createPoolLedgerConfig("testCreatePoolWorks", createPoolLedgerConfigJSONParameter).get(); + Pool.createPoolLedgerConfig("testCreatePoolWorks", createPoolLedgerConfigJSONParameter.toJson()).get(); StorageUtils.cleanupStorage(); } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java index c984dfe730..9d074aaaf7 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java @@ -2,7 +2,6 @@ import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; -import org.hyperledger.indy.sdk.pool.PoolResults.OpenPoolLedgerResult; import org.hyperledger.indy.sdk.utils.PoolUtils; import org.hyperledger.indy.sdk.utils.StorageUtils; import org.junit.Test; @@ -18,11 +17,11 @@ public void testOpenPoolWorks() throws Exception { String poolName = PoolUtils.createPoolLedgerConfig(); OpenPoolLedgerJSONParameter config2 = new OpenPoolLedgerJSONParameter(null, null, null); - OpenPoolLedgerResult openResult = Pool.openPoolLedger(poolName, config2).get(); + Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); - assertNotNull(openResult); + assertNotNull(pool); - openResult.getPool().closePoolLedger(); + pool.closePoolLedger(); StorageUtils.cleanupStorage(); } @@ -33,11 +32,11 @@ public void testOpenPoolWorksForTwoNodes() throws Exception { String poolName = PoolUtils.createPoolLedgerConfig(2); OpenPoolLedgerJSONParameter config2 = new OpenPoolLedgerJSONParameter(null, null, null); - OpenPoolLedgerResult openResult = Pool.openPoolLedger(poolName, config2).get(); + Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); - assertNotNull(openResult); + assertNotNull(pool); - openResult.getPool().closePoolLedger(); + pool.closePoolLedger(); StorageUtils.cleanupStorage(); } @@ -48,11 +47,11 @@ public void testOpenPoolWorksForThreeNodes() throws Exception { String poolName = PoolUtils.createPoolLedgerConfig(3); OpenPoolLedgerJSONParameter config2 = new OpenPoolLedgerJSONParameter(null, null, null); - OpenPoolLedgerResult openResult = Pool.openPoolLedger(poolName, config2).get(); + Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); - assertNotNull(openResult); + assertNotNull(pool); - openResult.getPool().closePoolLedger(); + pool.closePoolLedger(); StorageUtils.cleanupStorage(); } From f0998e35c0d6533d06c129929c100e2714d1c59a Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Thu, 13 Jul 2017 14:30:54 +0300 Subject: [PATCH 111/349] * Basic implementation of Wallet::create_wallet was provided --- wrappers/python/indy/error.py | 4 +- wrappers/python/indy/logging.py | 4 + wrappers/python/indy/wallet.py | 75 ++++++++++++------- .../python/tests/wallet/test_create_wallet.py | 1 - 4 files changed, 53 insertions(+), 31 deletions(-) create mode 100644 wrappers/python/indy/logging.py diff --git a/wrappers/python/indy/error.py b/wrappers/python/indy/error.py index bc0f0ef97f..bea0eeb636 100644 --- a/wrappers/python/indy/error.py +++ b/wrappers/python/indy/error.py @@ -1,6 +1,6 @@ -from enum import Enum +from enum import IntEnum -class ErrorCode(Enum): +class ErrorCode(IntEnum): Success = 0 CommonInvalidParam1 = 100 diff --git a/wrappers/python/indy/logging.py b/wrappers/python/indy/logging.py new file mode 100644 index 0000000000..1fa79b901a --- /dev/null +++ b/wrappers/python/indy/logging.py @@ -0,0 +1,4 @@ +import logging + +logger = logging.getLogger("indy") +logger.setLevel(level=logging.DEBUG) \ No newline at end of file diff --git a/wrappers/python/indy/wallet.py b/wrappers/python/indy/wallet.py index b212f24d0c..284ea3d884 100644 --- a/wrappers/python/indy/wallet.py +++ b/wrappers/python/indy/wallet.py @@ -1,38 +1,57 @@ -from typing import Callable -from . import IndyError - from . import libindy +from .error import ErrorCode, IndyError +from .logging import logger -class Wallet(object): +from ctypes import * +from asyncio import get_event_loop - """TODO: document it""" - # extern indy_error_t indy_create_wallet(indy_handle_t command_handle, - # const char* pool_name, - # const char* name, - # const char* xtype, - # const char* config, - # const char* credentials, - # void (*fn)(indy_handle_t xcommand_handle, indy_error_t err) - # ); +class Wallet(object): + _XCOMMAND_HANDLE = 0 + + _CREATE_WALLET_CB_TYPE = CFUNCTYPE(None, c_int32, c_int32) + @staticmethod async def create_wallet(pool_name: str, name: str, xtype: str, config: str, credentials: str) -> None: - pass - - # async def open_wallet(pool_handle: int, - # name: str, - # config: str) -> int: - # return -1 - # - # async def close_wallet(wallet_handle: int) -> None: - # pass - # - # async def delete_wallet(name:str) -> None: - # pass - # - # async def set_seq_no_for_value(wallet_key: str, seq_num: str) -> None: - # pass + + c_comman_handle = c_int32(Wallet._XCOMMAND_HANDLE) + c_pool_name = c_char_p(pool_name.encode('utf-8')) + c_name = c_char_p(name.encode('utf-8')) + c_xtype = c_char_p(xtype.encode('utf-8')) if xtype is not None else None + c_config = c_char_p(config.encode('utf-8')) if config is not None else None + c_credentials = c_char_p(credentials.encode('utf-8')) if credentials is not None else None + + event_loop = get_event_loop() + future = event_loop.create_future() + + def create_wallet_cb(xcommand_handle: int, err: int): + logger.debug("create_wallet_cb called, xcommand_handle: %i, err: %i", xcommand_handle, err) + event_loop.call_soon_threadsafe(create_wallet_loop_cb, err) + + def create_wallet_loop_cb(err): + logger.debug("create_wallet_loop_cb called, err: %i", err) + future.set_result(err) + + c_cb = Wallet._CREATE_WALLET_CB_TYPE(create_wallet_cb) + + res = libindy.cdll.indy_create_wallet(c_comman_handle, + c_pool_name, + c_name, + c_xtype, + c_config, + c_credentials, + c_cb) + + logger.debug("cdll.indy_create_wallet, res: %i", res) + if res != ErrorCode.Success: + raise IndyError(res) + + res = await future + + logger.debug("cdll.indy_create_wallet future, res: %i", res) + if ErrorCode(res) != ErrorCode.Success: + raise IndyError(res) diff --git a/wrappers/python/tests/wallet/test_create_wallet.py b/wrappers/python/tests/wallet/test_create_wallet.py index b2299fb34c..2423d11c68 100644 --- a/wrappers/python/tests/wallet/test_create_wallet.py +++ b/wrappers/python/tests/wallet/test_create_wallet.py @@ -8,7 +8,6 @@ @pytest.mark.asyncio async def test_indy_create_wallet_works(): - logger.debug("asasd") StorageUtils.cleanup() pool_name = 'indy_create_wallet_works' From 08f87026fefec58197125dd7fb5b57a6eabb7d44 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 13 Jul 2017 14:56:34 +0300 Subject: [PATCH 112/349] Updated wallet tests --- .../org/hyperledger/indy/sdk/ErrorCode.java | 5 +- .../org/hyperledger/indy/sdk/IndyJava.java | 6 +- .../org/hyperledger/indy/sdk/LibIndy.java | 4 +- .../indy/sdk/wallet/CloseWalletTest.java | 28 +++------ .../indy/sdk/wallet/CreateWalletTest.java | 15 ++--- .../indy/sdk/wallet/DeleteWalletTest.java | 60 +++++-------------- .../indy/sdk/wallet/OpenWalletTest.java | 22 +++---- 7 files changed, 43 insertions(+), 97 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java index 0896cdd37c..f943318087 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java @@ -73,11 +73,8 @@ public enum ErrorCode { // Trying to use wallet with pool that has different name WalletIncompatiblePoolError(205), - // Plugged wallet error - WalletPluggedWallerError(206), - // Trying to use wallet with pool that has different name - WalletAlreadyOpenedError(207), + WalletAlreadyOpenedError(206), // Ledger errors // Trying to open pool ledger that wasn't created before diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java index 354ace29d9..e75d02a842 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java @@ -67,14 +67,14 @@ protected static boolean checkCallback(CompletableFuture future, int err) { protected static void checkCallback(int err) throws IndyException { - ErrorCode errorCode = ErrorCode.valueOf(result); + ErrorCode errorCode = ErrorCode.valueOf(err); if (! ErrorCode.Success.equals(errorCode)) throw new IndyException(errorCode); } protected static void checkResult(int err) throws IndyException { ErrorCode errorCode = ErrorCode.valueOf(err); - if (! ErrorCode.Success.equals(errorCode)) throw IndyException.fromErrorCode(errorCode, err); + if (! ErrorCode.Success.equals(errorCode)) throw new IndyException(errorCode); } /* @@ -111,7 +111,7 @@ public abstract static class JsonParameter { /* * JSON CREATION */ - + public final String toJson() { StringBuilder builder = new StringBuilder(); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java index 3d71fbdfd6..5868d184ac 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java @@ -60,8 +60,8 @@ public interface API extends Library { // anoncreds.rs - public int indy_issuer_create_and_store_claim_def(int command_handle, int wallet_handle, String issuerDid, String schema_json, String signature_type, boolean create_non_revoc, Callback cb); - public int indy_issuer_create_and_store_revoc_reg(int command_handle, int wallet_handle, String issuerDid, int schema_seq_no, int max_claim_num, Callback cb); + public int indy_issuer_create_and_store_claim_def(int command_handle, int wallet_handle, String issuer_did, String schema_json, String signature_type, boolean create_non_revoc, Callback cb); + public int indy_issuer_create_and_store_revoc_reg(int command_handle, int wallet_handle, String issuer_did, int claim_def_seq_no, int max_claim_num, Callback cb); public int indy_issuer_create_claim(int command_handle, int wallet_handle, String claim_req_json, String claim_json, int revoc_reg_seq_no, int user_revoc_index, Callback cb); public int indy_issuer_revoke_claim(int command_handle, int wallet_handle, int revoc_reg_seq_no, int user_revoc_index, Callback cb); public int indy_prover_store_claim_offer(int command_handle, int wallet_handle, String claim_offer_json, Callback cb); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java index 895aaae4dc..4bedfa4bc7 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java @@ -4,7 +4,6 @@ import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.utils.StorageUtils; -import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; import static org.junit.Assert.assertNotNull; import org.junit.Test; @@ -18,17 +17,12 @@ public void testCloseWalletWorks() throws Exception { StorageUtils.cleanupStorage(); - Wallet wallet; + Wallet.createWallet("default", "closeWalletWorks", "default", null, null).get(); - CreateWalletResult result1 = Wallet.createWallet("default", "closeWalletWorks", "default", null, null).get(); - assertNotNull(result1); + Wallet wallet = Wallet.openWallet("closeWalletWorks", null, null).get(); + assertNotNull(wallet); - WalletResults.OpenWalletResult result2 = Wallet.openWallet("closeWalletWorks", null, null).get(); - assertNotNull(result2); - wallet = result2.getWallet(); - - WalletResults.CloseWalletResult result3 = wallet.closeWallet().get(); - assertNotNull(result3); + wallet.closeWallet().get(); StorageUtils.cleanupStorage(); } @@ -41,18 +35,12 @@ public void testCloseWalletWorksForTwice() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletInvalidHandle)); - Wallet wallet; - - CreateWalletResult result1 = Wallet.createWallet("default", "closeWalletWorksForTwice", "default", null, null).get(); - assertNotNull(result1); + Wallet.createWallet("default", "closeWalletWorksForTwice", "default", null, null).get(); - WalletResults.OpenWalletResult result2 = Wallet.openWallet("closeWalletWorksForTwice", null, null).get(); - assertNotNull(result2); - wallet = result2.getWallet(); - - WalletResults.CloseWalletResult result3 = wallet.closeWallet().get(); - assertNotNull(result3); + Wallet wallet = Wallet.openWallet("closeWalletWorksForTwice", null, null).get(); + assertNotNull(wallet); + wallet.closeWallet().get(); wallet.closeWallet().get(); StorageUtils.cleanupStorage(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java index 7469233ff9..c4f96542b9 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java @@ -5,8 +5,6 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; -import org.hyperledger.indy.sdk.utils.InitHelper; -import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; import org.hyperledger.indy.sdk.utils.StorageUtils; import static org.junit.Assert.assertNotNull; import org.junit.Before; @@ -22,8 +20,7 @@ public void testCreateWalletWorks() throws Exception { StorageUtils.cleanupStorage(); - CreateWalletResult result1 = Wallet.createWallet("default", "createWalletWorks", "default", null, null).get(); - assertNotNull(result1); + Wallet.createWallet("default", "createWalletWorks", "default", null, null).get(); StorageUtils.cleanupStorage(); } @@ -33,8 +30,7 @@ public void testCreateWalletWorksForEmptyType() throws Exception { StorageUtils.cleanupStorage(); - CreateWalletResult result1 = Wallet.createWallet("default", "createWalletWorks", null, null, null).get(); - assertNotNull(result1); + Wallet.createWallet("default", "createWalletWorks", null, null, null).get(); StorageUtils.cleanupStorage(); } @@ -44,9 +40,7 @@ public void testCreateWalletWorksForConfigJson() throws Exception { StorageUtils.cleanupStorage(); - CreateWalletResult result1 = Wallet.createWallet("default", "createWalletWorks", null, - "{\"freshness_time\":1000}", null).get(); - assertNotNull(result1); + Wallet.createWallet("default", "createWalletWorks", null, "{\"freshness_time\":1000}", null).get(); StorageUtils.cleanupStorage(); } @@ -84,8 +78,7 @@ public void testCreateWalletWorksForDuplicateName() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletAlreadyExistsError)); - CreateWalletResult result1 = Wallet.createWallet("default", "createWalletWorks", "default", null, null).get(); - assertNotNull(result1); + Wallet.createWallet("default", "createWalletWorks", "default", null, null).get(); Wallet.createWallet("default", "createWalletWorks", "default", null, null).get(); StorageUtils.cleanupStorage(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java index f0ae140a67..9970cc9284 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java @@ -5,7 +5,6 @@ import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.utils.InitHelper; import org.hyperledger.indy.sdk.utils.StorageUtils; -import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; import static org.junit.Assert.assertNotNull; import org.junit.Before; import org.junit.Ignore; @@ -23,14 +22,9 @@ public void testDeleteWalletWorks() throws Exception { StorageUtils.cleanupStorage(); - CreateWalletResult result1 = Wallet.createWallet("default", "deleteWalletWorks", "default", null, null).get(); - assertNotNull(result1); - - WalletResults.DeleteWalletResult result4 = Wallet.deleteWallet("deleteWalletWorks", null).get(); - assertNotNull(result4); - - CreateWalletResult result3 = Wallet.createWallet("default", "deleteWalletWorks", "default", null, null).get(); - assertNotNull(result3); + Wallet.createWallet("default", "deleteWalletWorks", "default", null, null).get(); + Wallet.deleteWallet("deleteWalletWorks", null).get(); + Wallet.createWallet("default", "deleteWalletWorks", "default", null, null).get(); StorageUtils.cleanupStorage(); } @@ -40,24 +34,14 @@ public void testDeleteWalletWorksForClosed() throws Exception { StorageUtils.cleanupStorage(); - Wallet wallet; - - CreateWalletResult result1 = Wallet.createWallet("default", "deleteWalletWorksForClosed", - null, null, null).get(); - assertNotNull(result1); - - WalletResults.OpenWalletResult result2 = Wallet.openWallet("deleteWalletWorksForClosed", null, null).get(); - assertNotNull(result2); - wallet = result2.getWallet(); - - WalletResults.CloseWalletResult result3 = wallet.closeWallet().get(); - assertNotNull(result3); + Wallet.createWallet("default", "deleteWalletWorksForClosed", null, null, null).get(); - WalletResults.DeleteWalletResult result4 = Wallet.deleteWallet("deleteWalletWorksForClosed", null).get(); - assertNotNull(result4); + Wallet wallet = Wallet.openWallet("deleteWalletWorksForClosed", null, null).get(); + assertNotNull(wallet); - CreateWalletResult result5 = Wallet.createWallet("default", "deleteWalletWorksForClosed", null, null, null).get(); - assertNotNull(result5); + wallet.closeWallet().get(); + Wallet.deleteWallet("deleteWalletWorksForClosed", null).get(); + Wallet.createWallet("default", "deleteWalletWorksForClosed", null, null, null).get(); StorageUtils.cleanupStorage(); } @@ -71,12 +55,8 @@ public void testDeleteWalletWorksForOpened() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonIOError)); - CreateWalletResult result1 = Wallet.createWallet("default", "deleteWalletWorksForOpened", null, null, null).get(); - assertNotNull(result1); - - WalletResults.OpenWalletResult result2 = Wallet.openWallet("deleteWalletWorksForOpened", null, null).get(); - assertNotNull(result2); - + Wallet.createWallet("default", "deleteWalletWorksForOpened", null, null, null).get(); + Wallet.openWallet("deleteWalletWorksForOpened", null, null).get(); Wallet.deleteWallet("deleteWalletWorksForOpened", null).get(); StorageUtils.cleanupStorage(); @@ -90,22 +70,14 @@ public void testDeleteWalletWorksForTwice() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonIOError)); - Wallet wallet; - - CreateWalletResult result1 = Wallet.createWallet("default", "deleteWalletWorksForTwice", - null, null, null).get(); - assertNotNull(result1); + Wallet.createWallet("default", "deleteWalletWorksForTwice", null, null, null).get(); - WalletResults.OpenWalletResult result2 = Wallet.openWallet("deleteWalletWorksForTwice", null, null).get(); - assertNotNull(result2); - wallet = result2.getWallet(); + Wallet wallet = Wallet.openWallet("deleteWalletWorksForTwice", null, null).get(); + assertNotNull(wallet); - WalletResults.CloseWalletResult result3 = wallet.closeWallet().get(); - assertNotNull(result3); - - WalletResults.DeleteWalletResult result4 = Wallet.deleteWallet("deleteWalletWorksForTwice", null).get(); - assertNotNull(result4); + wallet.closeWallet().get(); + Wallet.deleteWallet("deleteWalletWorksForTwice", null).get(); Wallet.deleteWallet("deleteWalletWorksForTwice", null).get(); StorageUtils.cleanupStorage(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java index 97d562b223..4fa5746480 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java @@ -3,10 +3,11 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; -import org.hyperledger.indy.sdk.wallet.WalletResults.CreateWalletResult; import org.hyperledger.indy.sdk.utils.StorageUtils; import org.hyperledger.indy.sdk.utils.InitHelper; + import static org.junit.Assert.assertNotNull; + import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -22,12 +23,10 @@ public void testOpenWalletWorks() throws Exception { StorageUtils.cleanupStorage(); - CreateWalletResult result1 = Wallet.createWallet("default", "openWalletWorks", "default", null, null).get(); - assertNotNull(result1); + Wallet.createWallet("default", "openWalletWorks", "default", null, null).get(); - WalletResults.OpenWalletResult result2 = Wallet.openWallet("openWalletWorks", null, null).get(); - assertNotNull(result2); - assertNotNull(result2.getWallet()); + Wallet wallet = Wallet.openWallet("openWalletWorks", null, null).get(); + assertNotNull(wallet); StorageUtils.cleanupStorage(); } @@ -37,12 +36,10 @@ public void testOpenWalletWorksForConfig() throws Exception { StorageUtils.cleanupStorage(); - CreateWalletResult result1 = Wallet.createWallet("default", "openWalletWorksForConfig", "default", null, null).get(); - assertNotNull(result1); + Wallet.createWallet("default", "openWalletWorksForConfig", "default", null, null).get(); - WalletResults.OpenWalletResult result2 = Wallet.openWallet("openWalletWorksForConfig", "{\"freshness_time\":1000}", null).get(); - assertNotNull(result2); - assertNotNull(result2.getWallet()); + Wallet wallet = Wallet.openWallet("openWalletWorksForConfig", "{\"freshness_time\":1000}", null).get(); + assertNotNull(wallet); StorageUtils.cleanupStorage(); } @@ -68,8 +65,7 @@ public void testOpenWalletWorksForTwice() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletAlreadyOpenedError)); - CreateWalletResult result1 = Wallet.createWallet("default", "openWalletWorksForTwice", "default", null, null).get(); - assertNotNull(result1); + Wallet.createWallet("default", "openWalletWorksForTwice", "default", null, null).get(); Wallet.openWallet("openWalletWorksForTwice", null, null).get(); Wallet.openWallet("openWalletWorksForTwice", null, null).get(); From a1ac3664fc283e0b3bd4797fd63cc970c039d5b6 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 13 Jul 2017 15:00:55 +0300 Subject: [PATCH 113/349] Deleted unused import --- .../src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java index e6b45314ee..1f9d3273ca 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java @@ -1,11 +1,7 @@ package org.hyperledger.indy.sdk.wallet; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; import java.util.concurrent.CompletableFuture; -import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.IndyException; import org.hyperledger.indy.sdk.IndyJava; import org.hyperledger.indy.sdk.LibIndy; From 3e0f03b4527d57057a6aa268e21d5f15e04869fc Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Thu, 13 Jul 2017 15:09:23 +0300 Subject: [PATCH 114/349] Update CreatePoolTest.java. --- .../indy/sdk/pool/CreatePoolTest.java | 34 ++++++++++++++++++- .../hyperledger/indy/sdk/utils/PoolUtils.java | 2 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java index 2d6c82cc11..a59f4aaaa8 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java @@ -1,5 +1,7 @@ package org.hyperledger.indy.sdk.pool; +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.utils.PoolUtils; import org.hyperledger.indy.sdk.utils.StorageUtils; @@ -7,10 +9,25 @@ import java.io.File; +import static org.junit.Assert.assertTrue; + public class CreatePoolTest extends IndyIntegrationTest { @Test - public void testCreatePoolWorks() throws Exception { + public void testCreatePoolWorksWithoutConfig() throws Exception { + StorageUtils.cleanupStorage(); + + File file = new File("testCreatePoolWorks.txn"); + file.deleteOnExit(); + assertTrue(file.createNewFile()); + + Pool.createPoolLedgerConfig("testCreatePoolWorks", null).get(); + + StorageUtils.cleanupStorage(); + } + + @Test + public void testCreatePoolWorksForConfigJSON() throws Exception { StorageUtils.cleanupStorage(); File genesisTxnFile = PoolUtils.createGenesisTxnFile("genesis.txn"); @@ -21,4 +38,19 @@ public void testCreatePoolWorks() throws Exception { StorageUtils.cleanupStorage(); } + + @Test + public void testCreatePoolWorksForEmptyName() throws Exception { + thrown.expect(new ErrorCodeMatcher(ErrorCode.CommonInvalidParam2)); + + StorageUtils.cleanupStorage(); + + File genesisTxnFile = PoolUtils.createGenesisTxnFile("genesis.txn"); + + PoolJSONParameters.CreatePoolLedgerConfigJSONParameter createPoolLedgerConfigJSONParameter + = new PoolJSONParameters.CreatePoolLedgerConfigJSONParameter(genesisTxnFile.getAbsolutePath()); + Pool.createPoolLedgerConfig("", createPoolLedgerConfigJSONParameter.toJson()).get(); + + StorageUtils.cleanupStorage(); + } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java index 47d59cf224..d471c9cdee 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java @@ -51,6 +51,6 @@ public static void createPoolLedgerConfig(String poolName, int nodesCnt) throws File genesisTxnFile = createGenesisTxnFile("temp.txn", nodesCnt); PoolJSONParameters.CreatePoolLedgerConfigJSONParameter createPoolLedgerConfigJSONParameter = new PoolJSONParameters.CreatePoolLedgerConfigJSONParameter(genesisTxnFile.getAbsolutePath()); - Pool.createPoolLedgerConfig(poolName, createPoolLedgerConfigJSONParameter).get(); + Pool.createPoolLedgerConfig(poolName, createPoolLedgerConfigJSONParameter.toJson()).get(); } } From 8a4fa4ffec95848976a11ef91fa8b88266436e3b Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 13 Jul 2017 15:17:06 +0300 Subject: [PATCH 115/349] Deleted Wallet set_seq_no Api call. Added couple of tests for wallet --- src/api/wallet.rs | 39 ---------------- src/commands/wallet.rs | 19 +------- tests/demo.rs | 17 ------- tests/utils/callback.rs | 20 -------- tests/utils/wallet.rs | 34 -------------- tests/wallet.rs | 100 +++++++++++++--------------------------- 6 files changed, 34 insertions(+), 195 deletions(-) diff --git a/src/api/wallet.rs b/src/api/wallet.rs index 3b6701ac3f..1360df1d37 100644 --- a/src/api/wallet.rs +++ b/src/api/wallet.rs @@ -248,44 +248,5 @@ pub extern fn indy_delete_wallet(command_handle: i32, }) ))); - result_to_err_code!(result) -} - -/// Sets a seq_no (the corresponding Ledger transaction unique sequence number) for the a value -/// in a secure wallet identified by the given string. -/// The string identifying the value in the wallet is returned when the value is stored in the wallet. -/// -/// #Params -/// wallet_handle: wallet handler (created by open_wallet). -/// command_handle: command handle to map callback to user context. -/// wallet_key: unique string identifying the value in the wallet. -/// seq_no: transaction sequence number. -/// -/// #Returns -/// Error code -/// -/// #Errors -/// Common* -/// Wallet* -#[no_mangle] -pub extern fn indy_wallet_set_seq_no_for_value(command_handle: i32, - wallet_handle: i32, - wallet_key: *const c_char, - seq_no: i32, - cb: Option) -> ErrorCode { - check_useful_c_str!(wallet_key, ErrorCode::CommonInvalidParam3); - check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam5); - - let result = CommandExecutor::instance() - .send(Command::Wallet(WalletCommand::SetSeqNoForValue( - wallet_handle, - wallet_key, - seq_no, - Box::new(move |result| { - let err = result_to_err_code!(result); - cb(command_handle, err) - }) - ))); - result_to_err_code!(result) } \ No newline at end of file diff --git a/src/commands/wallet.rs b/src/commands/wallet.rs index 86da8b367c..8f1f316382 100644 --- a/src/commands/wallet.rs +++ b/src/commands/wallet.rs @@ -49,11 +49,7 @@ pub enum WalletCommand { Box) + Send>), Delete(String, // name Option, // wallet credentials - Box) + Send>), - SetSeqNoForValue(i32, // wallet handle - String, // wallet key - i32, // sequence number - Box) + Send>) + Box) + Send>) } pub struct WalletCommandExecutor { @@ -94,10 +90,6 @@ impl WalletCommandExecutor { info!(target: "wallet_command_executor", "Delete command received"); self.delete(&name, credentials.as_ref().map(String::as_str), cb); } - WalletCommand::SetSeqNoForValue(handle, key, seq_no, cb) => { - info!(target: "wallet_command_executor", "SetSeqNoForValue command received"); - self.set_seq_no_for_value(handle, &key, seq_no, cb); - } }; } @@ -173,13 +165,4 @@ impl WalletCommandExecutor { cb(self.wallet_service.delete(handle, credentials) .map_err(|err| IndyError::WalletError(err))); } - - fn set_seq_no_for_value(&self, - handle: i32, - key: &str, - seq_no: i32, - cb: Box) + Send>) { - cb(self.wallet_service.set(handle, &format!("seq_no::{}", seq_no), key) - .map_err(|err| IndyError::WalletError(err))); - } } \ No newline at end of file diff --git a/tests/demo.rs b/tests/demo.rs index 80f59920de..9a2d908062 100644 --- a/tests/demo.rs +++ b/tests/demo.rs @@ -69,7 +69,6 @@ fn anoncreds_demo_works() { let (open_wallet_sender, open_wallet_receiver) = channel(); let (issuer_create_claim_definition_sender, issuer_create_claim_definition_receiver) = channel(); // TODO: uncomment this for revocation part - //let (wallet_set_seq_no_for_value_sender2, wallet_set_seq_no_for_value_receiver2) = channel(); //let (issuer_create_and_store_revoc_reg_sender, issuer_create_and_store_revoc_reg_receiver) = channel(); let (prover_create_master_secret_sender, prover_create_master_secret_receiver) = channel(); let (prover_create_claim_req_sender, prover_create_claim_req_receiver) = channel(); @@ -89,9 +88,6 @@ fn anoncreds_demo_works() { open_wallet_sender.send((err, handle)).unwrap(); }); // TODO: uncomment this for revocation part - // let wallet_set_seq_no_for_value_cb2 = Box::new(move |err| { - // wallet_set_seq_no_for_value_sender2.send(err).unwrap(); - // }); // let issuer_create_and_store_revoc_reg_cb = Box::new(move |err, revoc_reg_json, revoc_reg_uuid| { // issuer_create_and_store_revoc_reg_sender.send((err, revoc_reg_json, revoc_reg_uuid)).unwrap(); // }); @@ -121,7 +117,6 @@ fn anoncreds_demo_works() { let (create_wallet_command_handle, create_wallet_callback) = CallbackUtils::closure_to_create_wallet_cb(create_wallet_cb); let (open_wallet_command_handle, open_wallet_callback) = CallbackUtils::closure_to_open_wallet_cb(open_wallet_cb); // TODO: uncomment this for revocation part - // let (wallet_set_seq_no_for_value_command_handle2, wallet_set_seq_no_for_value_callback2) = CallbackUtils::closure_to_wallet_set_seq_no_for_value_cb(wallet_set_seq_no_for_value_cb2); // let (issuer_create_and_store_revoc_reg_command_handle, issuer_create_and_store_revoc_reg_callback) = CallbackUtils::closure_to_issuer_create_and_store_revoc_reg_cb(issuer_create_and_store_revoc_reg_cb); let (prover_create_master_secret_command_handle, prover_create_master_secret_callback) = CallbackUtils::closure_to_prover_create_master_secret_cb(prover_create_master_secret_cb); let (prover_create_claim_req_command_handle, prover_create_claim_req_callback) = CallbackUtils::closure_to_prover_create_claim_req_cb(prover_create_claim_req_cb); @@ -205,18 +200,6 @@ fn anoncreds_demo_works() { // info!("revocation_reg_json: {:?}", revoc_reg_json); // assert_eq!(ErrorCode::Success, err); // - // // Create relationship between revoc_reg_seq_no and revoc_reg_uuid in wallet - // let revoc_reg_seq_no = 2; - // - // let err = indy_wallet_set_seq_no_for_value(wallet_set_seq_no_for_value_command_handle2, - // wallet_handle, - // CString::new(revoc_reg_uuid).unwrap().as_ptr(), - // revoc_reg_seq_no, - // wallet_set_seq_no_for_value_callback2); - // - // assert_eq!(ErrorCode::Success, err); - // let err = wallet_set_seq_no_for_value_receiver2.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); - // assert_eq!(ErrorCode::Success, err); // 5. Prover create Master Secret let err = diff --git a/tests/utils/callback.rs b/tests/utils/callback.rs index 865e588894..e7a91acbc8 100644 --- a/tests/utils/callback.rs +++ b/tests/utils/callback.rs @@ -229,26 +229,6 @@ impl CallbackUtils { (command_handle, Some(open_wallet_callback)) } - pub fn closure_to_wallet_set_seq_no_for_value_cb(closure: Box) -> (i32, - Option) { - lazy_static! { - static ref WALLET_SET_SEQ_NO_FOR_VALUE_CALLBACKS: Mutex>> = Default::default(); - } - - extern "C" fn closure_to_wallet_set_seq_no_for_value_callback(command_handle: i32, err: ErrorCode) { - let mut callbacks = WALLET_SET_SEQ_NO_FOR_VALUE_CALLBACKS.lock().unwrap(); - let mut cb = callbacks.remove(&command_handle).unwrap(); - cb(err) - } - - let mut callbacks = WALLET_SET_SEQ_NO_FOR_VALUE_CALLBACKS.lock().unwrap(); - let command_handle = (COMMAND_HANDLE_COUNTER.fetch_add(1, Ordering::SeqCst) + 1) as i32; - callbacks.insert(command_handle, closure); - - (command_handle, Some(closure_to_wallet_set_seq_no_for_value_callback)) - } - pub fn closure_to_issuer_create_and_store_revoc_reg_cb(closure: Box) -> (i32, Option Result<(), ErrorCode> { - let (sender, receiver) = channel(); - - - let cb = Box::new(move |err| { - sender.send(err).unwrap(); - }); - - let (command_handle, cb) = CallbackUtils::closure_to_wallet_set_seq_no_for_value_cb(cb); - - let value = CString::new(value).unwrap(); - - let err = - indy_wallet_set_seq_no_for_value(command_handle, - wallet_handle, - value.as_ptr(), - seq_no, - cb); - - if err != ErrorCode::Success { - return Err(err); - } - - let err = receiver.recv_timeout(TimeoutUtils::short_timeout()).unwrap(); - - if err != ErrorCode::Success { - return Err(err); - } - - Ok(()) - } - - pub fn delete_wallet(wallet_name: &str) -> Result<(), ErrorCode> { let (sender, receiver) = channel(); diff --git a/tests/wallet.rs b/tests/wallet.rs index 4b0519f3a4..1de4d26256 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -129,6 +129,38 @@ mod high_cases { TestUtils::cleanup_storage(); } + #[test] + fn indy_delete_wallet_works_for_closed() { + TestUtils::cleanup_storage(); + + let pool_name = "indy_delete_wallet_works_for_closed"; + let wallet_name = "indy_delete_wallet_works_for_closed"; + + WalletUtils::create_wallet(pool_name, wallet_name, None, None).unwrap(); + let wallet_handle = WalletUtils::open_wallet(wallet_name, None).unwrap(); + WalletUtils::close_wallet(wallet_handle).unwrap(); + WalletUtils::delete_wallet(wallet_name).unwrap(); + WalletUtils::create_wallet(pool_name, wallet_name, None, None).unwrap(); + + TestUtils::cleanup_storage(); + } + + #[test] + #[ignore]//TODO FUX BUG. We can delete only closed wallet + fn indy_delete_wallet_works_for_opened() { + TestUtils::cleanup_storage(); + + let pool_name = "indy_delete_wallet_works_for_opened"; + let wallet_name = "indy_delete_wallet_works_for_opened"; + + WalletUtils::create_wallet(pool_name, wallet_name, None, None).unwrap(); + WalletUtils::open_wallet(wallet_name, None).unwrap(); + let res = WalletUtils::delete_wallet(wallet_name); + assert_eq!(res.unwrap_err(), ErrorCode::CommonIOError); + + TestUtils::cleanup_storage(); + } + #[test] fn indy_delete_wallet_works_for_plugged() { TestUtils::cleanup_storage(); @@ -235,41 +267,6 @@ mod high_cases { InmemWallet::cleanup(); } } - - mod set_seqno_wallet { - use super::*; - - #[test] - fn indy_wallet_set_seqno_works() { - TestUtils::cleanup_storage(); - - let wallet_handle = WalletUtils::create_and_open_wallet("indy_wallet_set_seqno_works", None).unwrap(); - - let (did, _, _) = SignusUtils::create_my_did(wallet_handle, "{}").unwrap(); - - WalletUtils::wallet_set_seq_no_for_value(wallet_handle, &did, 1).unwrap(); - - TestUtils::cleanup_storage(); - } - - #[test] - fn indy_wallet_set_seqno_works_for_plugged() { - TestUtils::cleanup_storage(); - InmemWallet::cleanup(); - - let xtype = "inmem"; - - WalletUtils::register_wallet_type(xtype).unwrap(); - let wallet_handle = WalletUtils::create_and_open_wallet("indy_wallet_set_seqno_works_for_plugged", Some(xtype)).unwrap(); - - let (did, _, _) = SignusUtils::create_my_did(wallet_handle, "{}").unwrap(); - - WalletUtils::wallet_set_seq_no_for_value(wallet_handle, &did, 1).unwrap(); - - TestUtils::cleanup_storage(); - InmemWallet::cleanup(); - } - } } mod medium_cases { @@ -349,7 +346,6 @@ mod medium_cases { } #[test] - #[ignore] //TODO Check is not implemented fn indy_open_wallet_works_for_twice() { TestUtils::cleanup_storage(); @@ -360,7 +356,7 @@ mod medium_cases { WalletUtils::open_wallet(wallet_name, None).unwrap(); let res = WalletUtils::open_wallet(wallet_name, None); - assert_eq!(res.unwrap_err(), ErrorCode::CommonIOError); + assert_eq!(res.unwrap_err(), ErrorCode::WalletAlreadyOpenedError); TestUtils::cleanup_storage(); } @@ -423,34 +419,4 @@ mod medium_cases { TestUtils::cleanup_storage(); } } - - mod set_seqno { - use super::*; - - #[test] - fn indy_wallet_set_seqno_works_for_not_exists_key() { - TestUtils::cleanup_storage(); - - let wallet_handle = WalletUtils::create_and_open_wallet("indy_wallet_set_seqno_works_for_not_exists_key", None).unwrap(); - - //TODO may be we must return WalletNotFound in case if key not exists in wallet - WalletUtils::wallet_set_seq_no_for_value(wallet_handle, "key", 1).unwrap(); - - TestUtils::cleanup_storage(); - } - - #[test] - fn indy_wallet_set_seqno_works_for_invalid_wallet() { - TestUtils::cleanup_storage(); - - let wallet_handle = WalletUtils::create_and_open_wallet("indy_wallet_set_seqno_works_for_invalid_wallet", None).unwrap(); - - - let invalid_wallet_handle = wallet_handle + 1; - let res = WalletUtils::wallet_set_seq_no_for_value(invalid_wallet_handle, "key", 1); - assert_eq!(res.unwrap_err(), ErrorCode::WalletInvalidHandle); - - TestUtils::cleanup_storage(); - } - } } From 280f1aa30cfc1e0fa7580e1673da5eb04a6d852c Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 13 Jul 2017 15:22:08 +0300 Subject: [PATCH 116/349] Deleted set_seq_no Api call from java wrapper --- include/indy_wallet.h | 24 ----------- tests/wallet.rs | 1 - .../org/hyperledger/indy/sdk/LibIndy.java | 1 - .../hyperledger/indy/sdk/wallet/Wallet.java | 41 ------------------- 4 files changed, 67 deletions(-) diff --git a/include/indy_wallet.h b/include/indy_wallet.h index 2a8f3f34c5..08847e7875 100644 --- a/include/indy_wallet.h +++ b/include/indy_wallet.h @@ -154,30 +154,6 @@ extern "C" { const char* credentials, void (*fn)(indy_handle_t xcommand_handle, indy_error_t err) ); - - /// Sets a seq_no (the corresponding Ledger transaction unique sequence number) for the a value - /// in a secure wallet identified by the given string. - /// The string identifying the value in the wallet is returned when the value is stored in the wallet. - /// - /// #Params - /// wallet_handle: wallet handler (created by open_wallet). - /// command_handle: command handle to map callback to user context. - /// wallet_key: unique string identifying the value in the wallet. - /// seq_no: transaction sequence number. - /// - /// #Returns - /// Error code - /// - /// #Errors - /// Common* - /// Wallet* - - extern indy_error_t indy_wallet_set_seq_no_for_value(indy_handle_t command_handle, - indy_handle_t wallet_handle, - const char* wallet_key, - indy_i32_t seq_no, - void (*fn)(indy_handle_t xcommand_handle, indy_error_t err) - ); #ifdef __cplusplus } diff --git a/tests/wallet.rs b/tests/wallet.rs index 1de4d26256..47fc6cd1be 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -16,7 +16,6 @@ mod utils; use utils::inmem_wallet::InmemWallet; use utils::wallet::WalletUtils; -use utils::signus::SignusUtils; use utils::test::TestUtils; use indy::api::ErrorCode; diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java index 3d71fbdfd6..c37dc1f693 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java @@ -30,7 +30,6 @@ public interface API extends Library { public int indy_open_wallet(int command_handle, String name, String runtime_config, String credentials, Callback cb); public int indy_close_wallet(int command_handle, int handle, Callback cb); public int indy_delete_wallet(int command_handle, String name, String credentials, Callback cb); - public int indy_wallet_set_seq_no_for_value(int command_handle, int wallet_handle, String wallet_key, Callback cb); // ledger.rs diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java index 1f9d3273ca..718c8986c8 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java @@ -83,19 +83,6 @@ public void callback(int xcommand_handle, int err) { } }; - private static Callback walletSetSeqNoForValueCb = new Callback() { - - @SuppressWarnings({ "unused", "unchecked" }) - public void callback(int xcommand_handle, int err) { - - CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; - - Void result = null; - future.complete(result); - } - }; - /* * STATIC METHODS */ @@ -184,27 +171,6 @@ public static CompletableFuture deleteWallet( return future; } - private static CompletableFuture walletSetSeqNoForValue( - Wallet wallet, - String walletKey, - String configName) throws IndyException { - - CompletableFuture future = new CompletableFuture (); - int commandHandle = addFuture(future); - - int walletHandle = wallet.getWalletHandle(); - - int result = LibIndy.api.indy_wallet_set_seq_no_for_value( - commandHandle, - walletHandle, - walletKey, - walletSetSeqNoForValueCb); - - checkResult(result); - - return future; - } - /* * INSTANCE METHODS */ @@ -214,11 +180,4 @@ public CompletableFuture closeWallet( return closeWallet(this); } - - public CompletableFuture walletSetSeqNoForValue( - String walletKey, - String configName) throws IndyException { - - return walletSetSeqNoForValue(this, walletKey, configName); - } } From 6813744c0b0467044d8372c75593c7a2339dcb4d Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 15:22:54 +0300 Subject: [PATCH 117/349] changed path --- tests/anoncreds.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index e2826e6faa..f508232d3a 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -1353,7 +1353,7 @@ mod demos { let claim_offer_json = serde_json::to_string(&claim_offers[0]).unwrap(); Command::new("python3") - .arg("../anoncreds/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_issuer.py") + .arg("/home/indy/indy-anoncreds/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_issuer.py") .spawn().expect("failed to execute process"); thread::sleep(time::Duration::from_millis(3000)); @@ -1476,7 +1476,7 @@ mod demos { let claim_def_json = AnoncredsUtils::issuer_create_claim_definition(issuer_wallet_handle, &ISSUER_DID, &schema, None, false).unwrap(); Command::new("python3") - .arg("../anoncreds/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_verifier.py") + .arg("/home/indy/indy-anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_verifier.py") .spawn().expect("failed to execute process"); thread::sleep(time::Duration::from_millis(3000)); @@ -1575,7 +1575,7 @@ mod demos { let schema = AnoncredsUtils::get_gvt_schema_json(schema_seq_no); Command::new("python3") - .arg("../anoncreds/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_prover.py") + .arg("/home/indy/indy-anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_prover.py") .spawn().expect("failed to execute process"); thread::sleep(time::Duration::from_millis(3000)); From bc048295c1e63a9d349ddcf84333246b1d78b362 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 13 Jul 2017 15:33:27 +0300 Subject: [PATCH 118/349] Added coiple of tests --- .../indy/sdk/wallet/DeleteWalletTest.java | 13 +++++++++++++ .../hyperledger/indy/sdk/wallet/OpenWalletTest.java | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java index 9970cc9284..6098f1c05b 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java @@ -82,4 +82,17 @@ public void testDeleteWalletWorksForTwice() throws Exception { StorageUtils.cleanupStorage(); } + + @Test + public void testDeleteWalletWorksForNotCreated() throws Exception { + + StorageUtils.cleanupStorage(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonIOError)); + + Wallet.deleteWallet("deleteWalletWorksForTwice", null).get(); + + StorageUtils.cleanupStorage(); + } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java index 4fa5746480..174479cdb1 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java @@ -72,4 +72,17 @@ public void testOpenWalletWorksForTwice() throws Exception { StorageUtils.cleanupStorage(); } + + @Test + public void testOpenWalletWorksForNotCreated() throws Exception { + + StorageUtils.cleanupStorage(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonIOError)); + + Wallet.openWallet("testOpenWalletWorksForNotCreated", null, null).get(); + + StorageUtils.cleanupStorage(); + } } From a4fb49c536ca345bcfff9207a1d50d7173011ea9 Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Thu, 13 Jul 2017 15:34:07 +0300 Subject: [PATCH 119/349] [java] Update OpenPoolTest. --- .../indy/sdk/IndyIntegrationTest.java | 19 +++++- .../indy/sdk/pool/CreatePoolTest.java | 2 +- .../indy/sdk/pool/OpenPoolTest.java | 60 +++++++++++++++---- .../indy/sdk/utils/StorageUtils.java | 5 +- 4 files changed, 70 insertions(+), 16 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java index 556ddf9851..5a3b8591e2 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java @@ -1,11 +1,15 @@ package org.hyperledger.indy.sdk; +import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.utils.InitHelper; +import org.hyperledger.indy.sdk.utils.StorageUtils; import org.junit.Before; import org.junit.Rule; import org.junit.rules.ExpectedException; import org.junit.rules.Timeout; +import java.io.IOException; +import java.util.HashSet; import java.util.concurrent.TimeUnit; public class IndyIntegrationTest { @@ -13,10 +17,23 @@ public class IndyIntegrationTest { public ExpectedException thrown = ExpectedException.none(); @Rule - public Timeout globalTimeout= new Timeout(1, TimeUnit.SECONDS); + public Timeout globalTimeout = new Timeout(1, TimeUnit.SECONDS); @Before public void setUp() throws Exception { InitHelper.init(); } + + protected HashSet openedPools = new HashSet<>(); + + protected void afterEach() throws IOException { + openedPools.forEach(pool -> { + try { + pool.closePoolLedger(); + } catch (IndyException ignore) { + } + }); + openedPools.clear(); + StorageUtils.cleanupStorage(); + } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java index a59f4aaaa8..45531b3094 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java @@ -14,7 +14,7 @@ public class CreatePoolTest extends IndyIntegrationTest { @Test - public void testCreatePoolWorksWithoutConfig() throws Exception { + public void testCreatePoolWorksForNullConfig() throws Exception { StorageUtils.cleanupStorage(); File file = new File("testCreatePoolWorks.txn"); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java index 9d074aaaf7..05aa18b63d 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java @@ -1,28 +1,66 @@ package org.hyperledger.indy.sdk.pool; +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.IndyException; import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; import org.hyperledger.indy.sdk.utils.PoolUtils; import org.hyperledger.indy.sdk.utils.StorageUtils; import org.junit.Test; +import java.util.HashSet; + import static org.junit.Assert.assertNotNull; public class OpenPoolTest extends IndyIntegrationTest { @Test - public void testOpenPoolWorks() throws Exception { + public void testOpenPoolWorksForNullConfig() throws Exception { + StorageUtils.cleanupStorage(); + + String poolName = PoolUtils.createPoolLedgerConfig(); + + Pool pool = Pool.openPoolLedger(poolName, null).get(); + + assertNotNull(pool); + openedPools.add(pool); + + afterEach(); + } + + @Test + public void testOpenPoolWorksForConfig() throws Exception { StorageUtils.cleanupStorage(); String poolName = PoolUtils.createPoolLedgerConfig(); - OpenPoolLedgerJSONParameter config2 = new OpenPoolLedgerJSONParameter(null, null, null); - Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); + OpenPoolLedgerJSONParameter config = new OpenPoolLedgerJSONParameter(true, null, null); + Pool pool = Pool.openPoolLedger(poolName, config.toJson()).get(); assertNotNull(pool); + openedPools.add(pool); + + afterEach(); + } + + @Test + public void testOpenPoolWorksForTwice() throws Exception { + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.PoolLedgerInvalidPoolHandle)); - pool.closePoolLedger(); StorageUtils.cleanupStorage(); + + try { + String poolName = PoolUtils.createPoolLedgerConfig(); + + Pool pool1 = Pool.openPoolLedger(poolName, null).get(); + assertNotNull(pool1); + openedPools.add(pool1); + + Pool.openPoolLedger(poolName, null).get(); + } finally { + afterEach(); + } } @Test @@ -31,13 +69,12 @@ public void testOpenPoolWorksForTwoNodes() throws Exception { String poolName = PoolUtils.createPoolLedgerConfig(2); - OpenPoolLedgerJSONParameter config2 = new OpenPoolLedgerJSONParameter(null, null, null); - Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); + Pool pool = Pool.openPoolLedger(poolName, null).get(); assertNotNull(pool); + openedPools.add(pool); - pool.closePoolLedger(); - StorageUtils.cleanupStorage(); + afterEach(); } @Test @@ -46,13 +83,12 @@ public void testOpenPoolWorksForThreeNodes() throws Exception { String poolName = PoolUtils.createPoolLedgerConfig(3); - OpenPoolLedgerJSONParameter config2 = new OpenPoolLedgerJSONParameter(null, null, null); - Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); + Pool pool = Pool.openPoolLedger(poolName, null).get(); assertNotNull(pool); + openedPools.add(pool); - pool.closePoolLedger(); - StorageUtils.cleanupStorage(); + afterEach(); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java index e0cfc2fe75..9826e8b80f 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java @@ -3,17 +3,18 @@ import org.apache.commons.io.FileUtils; import java.io.File; +import java.io.IOException; public class StorageUtils { - private static void cleanDirectory(File path) throws Exception { + private static void cleanDirectory(File path) throws IOException { if (path.isDirectory()) { FileUtils.cleanDirectory(path); } } - public static void cleanupStorage() throws Exception { + public static void cleanupStorage() throws IOException { File tmpDir = new File(getTmpPath()); File homeDir = new File(getIndyHomePath()); From e9abd01e536b87a91a6daa13d5b134271811def1 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 13 Jul 2017 16:06:57 +0300 Subject: [PATCH 120/349] Added Before and After hook for tests --- .../indy/sdk/IndyIntegrationTest.java | 10 ++++++- .../indy/sdk/wallet/CloseWalletTest.java | 9 ------ .../indy/sdk/wallet/CreateWalletTest.java | 29 ------------------- .../indy/sdk/wallet/DeleteWalletTest.java | 25 ---------------- .../indy/sdk/wallet/OpenWalletTest.java | 26 ----------------- 5 files changed, 9 insertions(+), 90 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java index 556ddf9851..8c93dfe517 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java @@ -1,6 +1,8 @@ package org.hyperledger.indy.sdk; import org.hyperledger.indy.sdk.utils.InitHelper; +import org.hyperledger.indy.sdk.utils.StorageUtils; +import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.rules.ExpectedException; @@ -13,10 +15,16 @@ public class IndyIntegrationTest { public ExpectedException thrown = ExpectedException.none(); @Rule - public Timeout globalTimeout= new Timeout(1, TimeUnit.SECONDS); + public Timeout globalTimeout = new Timeout(1, TimeUnit.SECONDS); @Before public void setUp() throws Exception { InitHelper.init(); + StorageUtils.cleanupStorage(); + } + + @After + public void tearDown() throws Exception { + StorageUtils.cleanupStorage(); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java index 4bedfa4bc7..3767bb93e5 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java @@ -3,7 +3,6 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; -import org.hyperledger.indy.sdk.utils.StorageUtils; import static org.junit.Assert.assertNotNull; import org.junit.Test; @@ -15,23 +14,17 @@ public class CloseWalletTest extends IndyIntegrationTest { @Test public void testCloseWalletWorks() throws Exception { - StorageUtils.cleanupStorage(); - Wallet.createWallet("default", "closeWalletWorks", "default", null, null).get(); Wallet wallet = Wallet.openWallet("closeWalletWorks", null, null).get(); assertNotNull(wallet); wallet.closeWallet().get(); - - StorageUtils.cleanupStorage(); } @Test public void testCloseWalletWorksForTwice() throws Exception { - StorageUtils.cleanupStorage(); - thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletInvalidHandle)); @@ -42,7 +35,5 @@ public void testCloseWalletWorksForTwice() throws Exception { wallet.closeWallet().get(); wallet.closeWallet().get(); - - StorageUtils.cleanupStorage(); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java index c4f96542b9..afe55cf586 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java @@ -5,12 +5,7 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; -import org.hyperledger.indy.sdk.utils.StorageUtils; -import static org.junit.Assert.assertNotNull; -import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class CreateWalletTest extends IndyIntegrationTest { @@ -18,69 +13,45 @@ public class CreateWalletTest extends IndyIntegrationTest { @Test public void testCreateWalletWorks() throws Exception { - StorageUtils.cleanupStorage(); - Wallet.createWallet("default", "createWalletWorks", "default", null, null).get(); - - StorageUtils.cleanupStorage(); } @Test public void testCreateWalletWorksForEmptyType() throws Exception { - StorageUtils.cleanupStorage(); - Wallet.createWallet("default", "createWalletWorks", null, null, null).get(); - - StorageUtils.cleanupStorage(); } @Test public void testCreateWalletWorksForConfigJson() throws Exception { - StorageUtils.cleanupStorage(); - Wallet.createWallet("default", "createWalletWorks", null, "{\"freshness_time\":1000}", null).get(); - - StorageUtils.cleanupStorage(); } @Test public void testCreateWalletWorksForUnknowType() throws Exception { - StorageUtils.cleanupStorage(); - thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletUnknownTypeError)); Wallet.createWallet("default", "createWalletWorks", "unknow_type", null, null).get(); - - StorageUtils.cleanupStorage(); } @Test public void testCreateWalletWorksForEmptyName() throws Exception { - StorageUtils.cleanupStorage(); - thrown.expect(new ErrorCodeMatcher(ErrorCode.CommonInvalidParam2)); Wallet.createWallet("", "createWalletWorks", "default", null, null).get(); - - StorageUtils.cleanupStorage(); } @Test public void testCreateWalletWorksForDuplicateName() throws Exception { - StorageUtils.cleanupStorage(); - thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletAlreadyExistsError)); Wallet.createWallet("default", "createWalletWorks", "default", null, null).get(); Wallet.createWallet("default", "createWalletWorks", "default", null, null).get(); - - StorageUtils.cleanupStorage(); } } \ No newline at end of file diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java index 6098f1c05b..2f63eebbc4 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java @@ -3,14 +3,9 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; -import org.hyperledger.indy.sdk.utils.InitHelper; -import org.hyperledger.indy.sdk.utils.StorageUtils; import static org.junit.Assert.assertNotNull; -import org.junit.Before; import org.junit.Ignore; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import java.util.concurrent.ExecutionException; @@ -20,20 +15,14 @@ public class DeleteWalletTest extends IndyIntegrationTest { @Test public void testDeleteWalletWorks() throws Exception { - StorageUtils.cleanupStorage(); - Wallet.createWallet("default", "deleteWalletWorks", "default", null, null).get(); Wallet.deleteWallet("deleteWalletWorks", null).get(); Wallet.createWallet("default", "deleteWalletWorks", "default", null, null).get(); - - StorageUtils.cleanupStorage(); } @Test public void testDeleteWalletWorksForClosed() throws Exception { - StorageUtils.cleanupStorage(); - Wallet.createWallet("default", "deleteWalletWorksForClosed", null, null, null).get(); Wallet wallet = Wallet.openWallet("deleteWalletWorksForClosed", null, null).get(); @@ -42,31 +31,23 @@ public void testDeleteWalletWorksForClosed() throws Exception { wallet.closeWallet().get(); Wallet.deleteWallet("deleteWalletWorksForClosed", null).get(); Wallet.createWallet("default", "deleteWalletWorksForClosed", null, null, null).get(); - - StorageUtils.cleanupStorage(); } @Test @Ignore//TODO THERE IS BUG IN INDY public void testDeleteWalletWorksForOpened() throws Exception { - StorageUtils.cleanupStorage(); - thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonIOError)); Wallet.createWallet("default", "deleteWalletWorksForOpened", null, null, null).get(); Wallet.openWallet("deleteWalletWorksForOpened", null, null).get(); Wallet.deleteWallet("deleteWalletWorksForOpened", null).get(); - - StorageUtils.cleanupStorage(); } @Test public void testDeleteWalletWorksForTwice() throws Exception { - StorageUtils.cleanupStorage(); - thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonIOError)); @@ -79,20 +60,14 @@ public void testDeleteWalletWorksForTwice() throws Exception { Wallet.deleteWallet("deleteWalletWorksForTwice", null).get(); Wallet.deleteWallet("deleteWalletWorksForTwice", null).get(); - - StorageUtils.cleanupStorage(); } @Test public void testDeleteWalletWorksForNotCreated() throws Exception { - StorageUtils.cleanupStorage(); - thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonIOError)); Wallet.deleteWallet("deleteWalletWorksForTwice", null).get(); - - StorageUtils.cleanupStorage(); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java index 174479cdb1..e016959b69 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java @@ -3,15 +3,8 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; -import org.hyperledger.indy.sdk.utils.StorageUtils; -import org.hyperledger.indy.sdk.utils.InitHelper; - import static org.junit.Assert.assertNotNull; - -import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import java.util.concurrent.ExecutionException; @@ -21,47 +14,34 @@ public class OpenWalletTest extends IndyIntegrationTest { @Test public void testOpenWalletWorks() throws Exception { - StorageUtils.cleanupStorage(); - Wallet.createWallet("default", "openWalletWorks", "default", null, null).get(); Wallet wallet = Wallet.openWallet("openWalletWorks", null, null).get(); assertNotNull(wallet); - StorageUtils.cleanupStorage(); } @Test public void testOpenWalletWorksForConfig() throws Exception { - StorageUtils.cleanupStorage(); - Wallet.createWallet("default", "openWalletWorksForConfig", "default", null, null).get(); Wallet wallet = Wallet.openWallet("openWalletWorksForConfig", "{\"freshness_time\":1000}", null).get(); assertNotNull(wallet); - - StorageUtils.cleanupStorage(); } @Test public void testOpenWalletWorksForNotCreatedWallet() throws Exception { - StorageUtils.cleanupStorage(); - thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonIOError)); Wallet.openWallet("openWalletWorksForNotCreatedWallet", null, null).get(); - - StorageUtils.cleanupStorage(); } @Test public void testOpenWalletWorksForTwice() throws Exception { - StorageUtils.cleanupStorage(); - thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletAlreadyOpenedError)); @@ -69,20 +49,14 @@ public void testOpenWalletWorksForTwice() throws Exception { Wallet.openWallet("openWalletWorksForTwice", null, null).get(); Wallet.openWallet("openWalletWorksForTwice", null, null).get(); - - StorageUtils.cleanupStorage(); } @Test public void testOpenWalletWorksForNotCreated() throws Exception { - StorageUtils.cleanupStorage(); - thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonIOError)); Wallet.openWallet("testOpenWalletWorksForNotCreated", null, null).get(); - - StorageUtils.cleanupStorage(); } } From 6f47661185e6c28704d72c1e36d1216561170751 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 16:10:41 +0300 Subject: [PATCH 121/349] changed path --- tests/anoncreds.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index f508232d3a..54c3bb524e 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -1476,7 +1476,7 @@ mod demos { let claim_def_json = AnoncredsUtils::issuer_create_claim_definition(issuer_wallet_handle, &ISSUER_DID, &schema, None, false).unwrap(); Command::new("python3") - .arg("/home/indy/indy-anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_verifier.py") + .arg("/home/indy/indy-anoncreds/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_verifier.py") .spawn().expect("failed to execute process"); thread::sleep(time::Duration::from_millis(3000)); @@ -1575,7 +1575,7 @@ mod demos { let schema = AnoncredsUtils::get_gvt_schema_json(schema_seq_no); Command::new("python3") - .arg("/home/indy/indy-anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_prover.py") + .arg("/home/indy/indy-anoncreds/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_prover.py") .spawn().expect("failed to execute process"); thread::sleep(time::Duration::from_millis(3000)); From a5d5bbee9484e3291969185783cb53387497104d Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Thu, 13 Jul 2017 16:19:22 +0300 Subject: [PATCH 122/349] * Use lazy initialization instead of static --- wrappers/python/indy/libindy.py | 50 +++++++++++-------- wrappers/python/indy/logging.py | 4 -- wrappers/python/indy/wallet.py | 8 +-- wrappers/python/tests/libindy.py | 5 -- wrappers/python/tests/test_libindy.py | 9 ++++ wrappers/python/tests/utils/logging.py | 4 -- wrappers/python/tests/utils/storage.py | 6 ++- wrappers/python/tests/utils/test_storage.py | 4 ++ .../python/tests/wallet/test_create_wallet.py | 6 ++- 9 files changed, 55 insertions(+), 41 deletions(-) delete mode 100644 wrappers/python/indy/logging.py delete mode 100644 wrappers/python/tests/libindy.py create mode 100644 wrappers/python/tests/test_libindy.py delete mode 100644 wrappers/python/tests/utils/logging.py diff --git a/wrappers/python/indy/libindy.py b/wrappers/python/indy/libindy.py index a7503695fe..35b1f0ba50 100644 --- a/wrappers/python/indy/libindy.py +++ b/wrappers/python/indy/libindy.py @@ -1,31 +1,39 @@ import ctypes -import logging import sys +import logging + +class LibIndy: + _cdll = None -def load_cdll(): - libindy_prefix_mapping = {'darwin': 'lib', 'linux': 'lib', 'linux2': 'lib', 'win32': ''} - libindy_suffix_mapping = {'darwin': '.dylib', 'linux': '.so', 'linux2': '.so', 'win32': '.dll'} + @staticmethod + def cdll() -> ctypes.CDLL: + if LibIndy._cdll is None: + LibIndy._cdll = LibIndy._load_cdll() + return LibIndy._cdll - os_name = sys.platform - logging.debug("Detected OS name is: %s", os_name) + @staticmethod + def _load_cdll() -> ctypes.CDLL: + logger = logging.getLogger(__name__) - try: - libindy_prefix = libindy_prefix_mapping[os_name] - libindy_suffix = libindy_suffix_mapping[os_name] - except KeyError: - logging.error("OS isn't supported: %s", os_name) - raise OSError("OS isn't supported: %s", os_name) + libindy_prefix_mapping = {'darwin': 'lib', 'linux': 'lib', 'linux2': 'lib', 'win32': ''} + libindy_suffix_mapping = {'darwin': '.dylib', 'linux': '.so', 'linux2': '.so', 'win32': '.dll'} - libindy_name = libindy_prefix + 'indy' + libindy_suffix - logging.debug("Resolved libindy name is: %s", libindy_name) + os_name = sys.platform + logger.debug("Detected OS name is: %s", os_name) - try: - return ctypes.CDLL(libindy_name) - except OSError as e: - logging.error("Can't load libindy: %s", e) - raise e + try: + libindy_prefix = libindy_prefix_mapping[os_name] + libindy_suffix = libindy_suffix_mapping[os_name] + except KeyError: + logger.error("OS isn't supported: %s", os_name) + raise OSError("OS isn't supported: %s", os_name) + libindy_name = libindy_prefix + 'indy' + libindy_suffix + logger.debug("Resolved libindy name is: %s", libindy_name) -# load indy sdk C library -cdll = load_cdll() + try: + return ctypes.CDLL(libindy_name) + except OSError as e: + logger.error("Can't load libindy: %s", e) + raise e diff --git a/wrappers/python/indy/logging.py b/wrappers/python/indy/logging.py deleted file mode 100644 index 1fa79b901a..0000000000 --- a/wrappers/python/indy/logging.py +++ /dev/null @@ -1,4 +0,0 @@ -import logging - -logger = logging.getLogger("indy") -logger.setLevel(level=logging.DEBUG) \ No newline at end of file diff --git a/wrappers/python/indy/wallet.py b/wrappers/python/indy/wallet.py index 284ea3d884..e73dd9d3fb 100644 --- a/wrappers/python/indy/wallet.py +++ b/wrappers/python/indy/wallet.py @@ -1,10 +1,11 @@ -from . import libindy +from .libindy import LibIndy from .error import ErrorCode, IndyError -from .logging import logger from ctypes import * from asyncio import get_event_loop +import logging + class Wallet(object): _XCOMMAND_HANDLE = 0 @@ -17,6 +18,7 @@ async def create_wallet(pool_name: str, xtype: str, config: str, credentials: str) -> None: + logger = logging.getLogger(__name__) c_comman_handle = c_int32(Wallet._XCOMMAND_HANDLE) c_pool_name = c_char_p(pool_name.encode('utf-8')) @@ -38,7 +40,7 @@ def create_wallet_loop_cb(err): c_cb = Wallet._CREATE_WALLET_CB_TYPE(create_wallet_cb) - res = libindy.cdll.indy_create_wallet(c_comman_handle, + res = LibIndy.cdll().indy_create_wallet(c_comman_handle, c_pool_name, c_name, c_xtype, diff --git a/wrappers/python/tests/libindy.py b/wrappers/python/tests/libindy.py deleted file mode 100644 index 8c4474a5b6..0000000000 --- a/wrappers/python/tests/libindy.py +++ /dev/null @@ -1,5 +0,0 @@ -from indy import libindy - - -def test_libindy_loading_works(): - assert libindy.cdll is not None diff --git a/wrappers/python/tests/test_libindy.py b/wrappers/python/tests/test_libindy.py new file mode 100644 index 0000000000..e63fed869b --- /dev/null +++ b/wrappers/python/tests/test_libindy.py @@ -0,0 +1,9 @@ +from indy.libindy import LibIndy + +import logging + +logging.basicConfig(level=logging.DEBUG) + + +def test_libindy_loading_works(): + assert LibIndy.cdll() is not None diff --git a/wrappers/python/tests/utils/logging.py b/wrappers/python/tests/utils/logging.py deleted file mode 100644 index c9da66dc0f..0000000000 --- a/wrappers/python/tests/utils/logging.py +++ /dev/null @@ -1,4 +0,0 @@ -import logging - -logger = logging.getLogger("indy_test") -logger.setLevel(level=logging.DEBUG) \ No newline at end of file diff --git a/wrappers/python/tests/utils/storage.py b/wrappers/python/tests/utils/storage.py index 85097531d9..da6ac83b0b 100644 --- a/wrappers/python/tests/utils/storage.py +++ b/wrappers/python/tests/utils/storage.py @@ -1,12 +1,14 @@ -from ..utils.logging import logger - from pathlib import Path from shutil import rmtree from tempfile import gettempdir +import logging + class StorageUtils(object): @staticmethod def cleanup(): + logger = logging.getLogger(__name__) + tmp_path = StorageUtils.indy_temp_path() logger.debug("Cleaning tmp path: %s", tmp_path) diff --git a/wrappers/python/tests/utils/test_storage.py b/wrappers/python/tests/utils/test_storage.py index 2f3e584828..7d7533d63e 100644 --- a/wrappers/python/tests/utils/test_storage.py +++ b/wrappers/python/tests/utils/test_storage.py @@ -1,5 +1,9 @@ from .storage import StorageUtils +import logging + +logging.basicConfig(level=logging.DEBUG) + def test_storage_utils_indy_home_path_works(): home_path = StorageUtils.indy_home_path() diff --git a/wrappers/python/tests/wallet/test_create_wallet.py b/wrappers/python/tests/wallet/test_create_wallet.py index 2423d11c68..e89190832f 100644 --- a/wrappers/python/tests/wallet/test_create_wallet.py +++ b/wrappers/python/tests/wallet/test_create_wallet.py @@ -1,9 +1,11 @@ from indy import Wallet from ..utils.storage import StorageUtils -from ..utils.logging import logger import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) @pytest.mark.asyncio @@ -16,4 +18,4 @@ async def test_indy_create_wallet_works(): await Wallet.create_wallet(pool_name, wallet_name, xtype, None, None) - StorageUtils.cleanup() \ No newline at end of file + StorageUtils.cleanup() From 54478a166ab80be452a773fa92de0a2979460dda Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Thu, 13 Jul 2017 16:31:19 +0300 Subject: [PATCH 123/349] Update pool dockerfile to sovrin-node v0.4.23. --- ci/indy-pool.dockerfile | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/ci/indy-pool.dockerfile b/ci/indy-pool.dockerfile index 6fb865b0ee..5c201ffee5 100644 --- a/ci/indy-pool.dockerfile +++ b/ci/indy-pool.dockerfile @@ -26,12 +26,7 @@ RUN echo "deb https://repo.sovrin.org/deb xenial master" >> /etc/apt/sources.lis RUN useradd -ms /bin/bash -u $uid sovrin RUN apt-get update -y && apt-get install -y \ - python3-state-trie=0.2.3 \ - python3-stp=0.2.40 \ - python3-ledger=0.3.48 \ - python3-plenum=0.4.19 \ - python3-sovrin-common=0.3.17 \ - sovrin-node=0.4.13 + sovrin-node=0.4.23 RUN echo '[supervisord]\n\ logfile = /tmp/supervisord.log\n\ From 08310dc11446ee361ce6b763c5c23e34fd894939 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 16:42:17 +0300 Subject: [PATCH 124/349] added python3.5 --- ci/ubuntu.dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index 5ea75962be..348e6fe9c6 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -12,7 +12,8 @@ RUN apt-get update && \ libsqlite3-dev \ libsodium-dev \ cmake \ - git + git \ + python3.5 ENV RUST_ARCHIVE=rust-1.16.0-x86_64-unknown-linux-gnu.tar.gz ENV RUST_DOWNLOAD_URL=https://static.rust-lang.org/dist/$RUST_ARCHIVE From 300f4c41639ddff37b5ddea4fdbf5087aefa1372 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 13 Jul 2017 16:46:25 +0300 Subject: [PATCH 125/349] Fixed comments --- wrappers/java/pom.xml | 1 + .../java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java | 3 +-- .../java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wrappers/java/pom.xml b/wrappers/java/pom.xml index 1a5121483c..fe6832a650 100644 --- a/wrappers/java/pom.xml +++ b/wrappers/java/pom.xml @@ -98,6 +98,7 @@ commons-io commons-io 2.5 + test diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java index f943318087..3b313413b3 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java @@ -115,8 +115,7 @@ public enum ErrorCode { SignusUnknownCryptoError(500); private int value; - private static Map map = new HashMap<>(); - + private static Map map = new HashMap (); private ErrorCode(int value) { this.value = value; diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java index 5868d184ac..c611243cdb 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java @@ -61,7 +61,7 @@ public interface API extends Library { // anoncreds.rs public int indy_issuer_create_and_store_claim_def(int command_handle, int wallet_handle, String issuer_did, String schema_json, String signature_type, boolean create_non_revoc, Callback cb); - public int indy_issuer_create_and_store_revoc_reg(int command_handle, int wallet_handle, String issuer_did, int claim_def_seq_no, int max_claim_num, Callback cb); + public int indy_issuer_create_and_store_revoc_reg(int command_handle, int wallet_handle, String issuer_did, int schema_seq_no, int max_claim_num, Callback cb); public int indy_issuer_create_claim(int command_handle, int wallet_handle, String claim_req_json, String claim_json, int revoc_reg_seq_no, int user_revoc_index, Callback cb); public int indy_issuer_revoke_claim(int command_handle, int wallet_handle, int revoc_reg_seq_no, int user_revoc_index, Callback cb); public int indy_prover_store_claim_offer(int command_handle, int wallet_handle, String claim_offer_json, Callback cb); From 5bd0ba9e51370c6d817858642b0343e0bd298e12 Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Thu, 13 Jul 2017 17:30:50 +0300 Subject: [PATCH 126/349] Support splitted verkey. --- src/commands/agent.rs | 11 +++++++---- src/utils/crypto/mod.rs | 4 +++- src/utils/crypto/verkey_builder.rs | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 src/utils/crypto/verkey_builder.rs diff --git a/src/commands/agent.rs b/src/commands/agent.rs index 44d54e4737..dd2a52a566 100644 --- a/src/commands/agent.rs +++ b/src/commands/agent.rs @@ -25,6 +25,7 @@ use services::wallet::WalletService; use utils::crypto::ed25519::ED25519; use utils::json::JsonDecodable; use utils::sequence::SequenceUtils; +use utils::crypto::verkey_builder::build_full_verkey; pub type AgentConnectCB = Box) + Send>; pub type AgentMessageCB = Box) + Send>; @@ -464,11 +465,13 @@ impl AgentCommandExecutor { trace!("parsed get_nym_result_data {:?}", gen_nym_result_data); - let verkey = gen_nym_result_data.verkey.unwrap_or(gen_nym_result_data.dest); + let pk = ED25519::vk_to_curve25519( + build_full_verkey(&gen_nym_result_data.dest, &gen_nym_result_data.verkey) + .unwrap() + .as_slice()) + .unwrap().to_base58(); - let verkey = ED25519::vk_to_curve25519(verkey.from_base58().unwrap().as_slice()).unwrap().to_base58(); - - Ok(verkey) + Ok(pk) }); self.do_check_connect(listener_handle, did.as_str(), pk.as_str(), res.ok().as_ref().map(String::as_str)); } diff --git a/src/utils/crypto/mod.rs b/src/utils/crypto/mod.rs index 60fc8755c1..5fea09c377 100644 --- a/src/utils/crypto/mod.rs +++ b/src/utils/crypto/mod.rs @@ -26,4 +26,6 @@ pub mod xsalsa20; #[path = "hash/openssl.rs"] pub mod hash; -pub mod signature_serializer; \ No newline at end of file +pub mod signature_serializer; + +pub mod verkey_builder; \ No newline at end of file diff --git a/src/utils/crypto/verkey_builder.rs b/src/utils/crypto/verkey_builder.rs new file mode 100644 index 0000000000..82ade12e0a --- /dev/null +++ b/src/utils/crypto/verkey_builder.rs @@ -0,0 +1,18 @@ +extern crate rust_base58; + +use self::rust_base58::base58::{FromBase58, FromBase58Error}; + +pub fn build_full_verkey(dest: &String, verkey: &Option) + -> Result, FromBase58Error> { + if let &Some(ref verkey) = verkey { + if verkey.starts_with("~") { + let mut result = dest.from_base58()?; + let mut end = verkey[1..].from_base58()?; + result.append(&mut end); + return Ok(result); + } else { + return verkey.from_base58(); + } + } + dest.from_base58() +} From 7c0cc21a08463fed35f6721e14fa96bb266a8b69 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 17:48:05 +0300 Subject: [PATCH 127/349] added test command --- tests/anoncreds.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index 54c3bb524e..8c9571f701 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -1475,6 +1475,9 @@ mod demos { let claim_def_json = AnoncredsUtils::issuer_create_claim_definition(issuer_wallet_handle, &ISSUER_DID, &schema, None, false).unwrap(); + Command::new("python3").arg("-V").spawn().expect("failed to execute process"); + info!("---------------------executed--------------------"); + Command::new("python3") .arg("/home/indy/indy-anoncreds/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_verifier.py") .spawn().expect("failed to execute process"); @@ -1529,7 +1532,7 @@ mod demos { let claims_json = AnoncredsUtils::prover_get_claims_for_proof_req(prover_wallet_handle, &proof_req_json).unwrap(); let claims: ProofClaimsJson = serde_json::from_str(&claims_json).unwrap(); - info!("claims_json: {}", &claims_json); + let claims_for_attr = claims.attrs.get("attr_uuid").unwrap(); assert_eq!(1, claims_for_attr.len()); let claim = claims_for_attr[0].clone(); From ce94759cd0bd5ad7055df97d80998368a5dd9181 Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Thu, 13 Jul 2017 17:56:12 +0300 Subject: [PATCH 128/349] Remove CID usage from tests. --- tests/agent.rs | 8 ++--- tests/demo.rs | 2 +- tests/ledger.rs | 80 +++++++++++++++++++++---------------------- tests/pool.rs | 26 +++++++------- tests/signus.rs | 22 ++++++------ tests/utils/pool.rs | 8 ++--- tests/utils/signus.rs | 2 +- 7 files changed, 74 insertions(+), 74 deletions(-) diff --git a/tests/agent.rs b/tests/agent.rs index b8f68d73b8..9969e1f8e9 100644 --- a/tests/agent.rs +++ b/tests/agent.rs @@ -62,7 +62,7 @@ mod high_cases { let listener_wallet = WalletUtils::create_and_open_wallet("indy_agent_connect_works_for_remote_data", None).unwrap(); let trustee_wallet = WalletUtils::create_and_open_wallet("indy_agent_connect_works_for_remote_data", None).unwrap(); let (listener_did, listener_ver_key, listener_pub_key) = SignusUtils::create_and_store_my_did(listener_wallet, None).unwrap(); - let (trustee_did, _, _) = SignusUtils::create_my_did(trustee_wallet, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(trustee_wallet, Some("000000000000000000000000Trustee1")).unwrap(); let sender_did = trustee_did.clone(); let sender_wallet = trustee_wallet; @@ -89,7 +89,7 @@ mod high_cases { let wallet_handle = WalletUtils::create_and_open_wallet("pool1", None).expect("create wallet"); - let seed: Option = Some("sovrin_agent_connect_works_for_a".to_string()); + let seed: Option<&str> = Some("sovrin_agent_connect_works_for_a"); let (did, ver_key, pub_key) = SignusUtils::create_and_store_my_did(wallet_handle, seed).unwrap(); let endpoint = "127.0.0.1:9702"; @@ -129,7 +129,7 @@ mod high_cases { let wallet_handle = WalletUtils::create_and_open_wallet("pool2", None).expect("create wallet"); - let seed: Option = Some("sovrin_agent_listen_works_for_al".to_string()); + let seed: Option<&str> = Some("sovrin_agent_listen_works_for_al"); let (did, ver_key, pub_key) = SignusUtils::create_and_store_my_did(wallet_handle, seed).unwrap(); let endpoint = "127.0.0.1:9703"; SignusUtils::store_their_did_from_parts(wallet_handle, did.as_str(), pub_key.as_str(), ver_key.as_str(), endpoint).unwrap(); @@ -380,7 +380,7 @@ mod medium_cases { let listener_wallet = WalletUtils::create_and_open_wallet("indy_agent_add_identity_works_for_incoming_connection_require_ledger_request_but_pool_handle_is_invalid", None).unwrap(); let trustee_wallet = WalletUtils::create_and_open_wallet("indy_agent_add_identity_works_for_incoming_connection_require_ledger_request_but_pool_handle_is_invalid", None).unwrap(); let (listener_did, listener_ver_key, listener_pub_key) = SignusUtils::create_and_store_my_did(listener_wallet, None).unwrap(); - let (trustee_did, _, _) = SignusUtils::create_my_did(trustee_wallet, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(trustee_wallet, Some("000000000000000000000000Trustee1")).unwrap(); let sender_did = trustee_did.clone(); let sender_wallet = trustee_wallet; diff --git a/tests/demo.rs b/tests/demo.rs index 80f59920de..5644255a77 100644 --- a/tests/demo.rs +++ b/tests/demo.rs @@ -519,7 +519,7 @@ fn ledger_demo_works() { // 10. Prepare NYM transaction let nym_req_id = PoolUtils::get_req_id(); let nym_txn_req = Request { - identifier: their_verkey.clone(), + identifier: their_did.clone(), operation: Operation { dest: my_did.clone(), type_: "1".to_string(), diff --git a/tests/ledger.rs b/tests/ledger.rs index be04b30623..ad7709b1e6 100644 --- a/tests/ledger.rs +++ b/tests/ledger.rs @@ -60,7 +60,7 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let get_nym_request = LedgerUtils::build_get_nym_request(&my_did.clone(), &my_did.clone()).unwrap(); @@ -80,8 +80,8 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (trustee_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"00000000000000000000000000000My1"}"#).unwrap(); + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), None, None, None).unwrap(); @@ -101,8 +101,8 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (trustee_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"00000000000000000000000000000My1"}"#).unwrap(); + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), None, None, None).unwrap(); @@ -121,9 +121,9 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config("pool1").unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet("pool2", None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"00000000000000000000000000000My1"}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); - let (trustee_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), None, None, None).unwrap(); let res = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request); @@ -145,7 +145,7 @@ mod high_cases { "identifier":"Th7MpTaRZVRYnPiabds81Y", "operation":{ "type":"105", - "dest":"FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4" + "dest":"Th7MpTaRZVRYnPiabds81Y" }, "signature":"4o86XfkiJ4e2r3J6Ufoi17UU3W5Zi9sshV6FjBjkVw4sgEQFQov9dxqDEtLbAJAWffCWd5KfAk164QVo7mYwKkiV"}"#; @@ -156,9 +156,9 @@ mod high_cases { result: GetNymReplyResult { _type: "105".to_string(), req_id: 1491566332010860, - data: Some(r#"{"dest":"FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4","identifier":"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL","role":"2","verkey":null}"#.to_string()), + data: Some(r#"{"dest":"Th7MpTaRZVRYnPiabds81Y","identifier":"V4SGRU86Z58d6TV7PBUe6f","role":"2","verkey":"~7TYfekw4GUagBnBVCqPjiC"}"#.to_string()), identifier: "Th7MpTaRZVRYnPiabds81Y".to_string(), - dest: "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4".to_string(), + dest: "Th7MpTaRZVRYnPiabds81Y".to_string(), } }; let act_reply: Reply = serde_json::from_str(resp.unwrap().as_str()).unwrap(); @@ -175,8 +175,8 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"00000000000000000000000000000My1"}"#).unwrap(); - let (trustee_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), None, None, None).unwrap(); LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request).unwrap(); @@ -257,7 +257,7 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"00000000000000000000000000000My1"}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); let nym_request = LedgerUtils::build_nym_request(&my_did.clone(), &my_did.clone(), None, None, None).unwrap(); @@ -277,7 +277,7 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let get_nym_request = LedgerUtils::build_get_nym_request(&my_did.clone(), &my_did.clone()).unwrap(); @@ -297,8 +297,8 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (trustee_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); - let (my_did, my_verkey, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"00000000000000000000000000000My1"}"#).unwrap(); + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); + let (my_did, my_verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), Some(&my_verkey.clone()), None, None).unwrap(); @@ -381,7 +381,7 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let attrib_request = LedgerUtils::build_attrib_request(&my_did.clone(), &my_did.clone(), @@ -405,8 +405,8 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (trustee_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); - let (my_did, my_verkey, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"00000000000000000000000000000My1"}"#).unwrap(); + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); + let (my_did, my_verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), Some(&my_verkey.clone()), None, None).unwrap(); LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request).unwrap(); @@ -470,7 +470,7 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let schema_data = "{\"name\":\"gvt2\",\ \"version\":\"2.0\",\ @@ -494,7 +494,7 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (trustee_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let (my_did, my_verkey, _) = SignusUtils::create_my_did(wallet_handle, "{}").unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), Some(&my_verkey.clone()), None, None).unwrap(); @@ -548,7 +548,7 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Steward1","cid":true}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Steward1")).unwrap(); let node_data = "{\"node_ip\":\"10.0.0.100\",\ \"node_port\":9710, \ @@ -576,8 +576,8 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (trustee_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); - let (my_did, my_verkey, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"00000000000000000000000000000My1","cid":true}"#).unwrap(); + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); + let (my_did, my_verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); let role = "STEWARD"; let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), Some(&my_verkey), None, Some(role)).unwrap(); @@ -638,7 +638,7 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (trustee_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let (my_did, my_verkey, _) = SignusUtils::create_my_did(wallet_handle, "{}").unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), Some(&my_verkey.clone()), None, None).unwrap(); @@ -711,7 +711,7 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let mut keys: HashSet = HashSet::new(); keys.insert("name".to_string()); @@ -755,7 +755,7 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let mut keys: HashSet = HashSet::new(); keys.insert("name".to_string()); @@ -798,7 +798,7 @@ mod medium_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"00000000000000000000000000000My1"}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); let trustee_did = "trusteedid"; let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), None, None, None).unwrap(); @@ -834,7 +834,7 @@ mod medium_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (trustee_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let request = r#"request"#; let res = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &request); @@ -856,8 +856,8 @@ mod medium_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (trustee_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"00000000000000000000000000000My1"}"#).unwrap(); + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), None, None, None).unwrap(); @@ -876,9 +876,9 @@ mod medium_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (trustee_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); - let (my_did, my_verkey, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"00000000000000000000000000000My1"}"#).unwrap(); + let (my_did, my_verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); let role = "STEWARD"; let alias = "some_alias"; @@ -912,7 +912,7 @@ mod medium_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (trustee_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let (my_did, my_verkey, _) = SignusUtils::create_my_did(wallet_handle, "{\"cid\":true}").unwrap(); @@ -939,7 +939,7 @@ mod medium_cases { let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); let (trustee_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee9","cid":true}"#).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"00000000000000000000000000000My1"}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), None, None, None).unwrap(); let res = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request); @@ -1004,7 +1004,7 @@ mod medium_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"00000000000000000000000000000My1"}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); let attrib_request = LedgerUtils::build_attrib_request(&my_did.clone(), &my_did.clone(), @@ -1050,7 +1050,7 @@ mod medium_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let get_attrib_request = LedgerUtils::build_get_attrib_request(&my_did.clone(), &my_did.clone(), "some_attribute").unwrap(); @@ -1150,7 +1150,7 @@ mod medium_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"00000000000000000000000000000My1"}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); let get_schema_data = "{\"name\":\"schema_name\",\"version\":\"2.0\"}"; let get_schema_request = LedgerUtils::build_get_schema_request(&my_did.clone(), &my_did.clone(), get_schema_data).unwrap(); @@ -1198,7 +1198,7 @@ mod medium_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let node_data = "{\"node_ip\":\"10.0.0.100\",\ \"node_port\":9710, \ @@ -1224,7 +1224,7 @@ mod medium_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Steward1","cid":true}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Steward1")).unwrap(); let node_data = "{\"node_ip\":\"10.0.0.100\",\ \"node_port\":9710, \ diff --git a/tests/pool.rs b/tests/pool.rs index fdad008679..07ee6a8ad8 100644 --- a/tests/pool.rs +++ b/tests/pool.rs @@ -131,8 +131,8 @@ mod high_cases { let pool_name = "open_pool_ledger_works_for_two_nodes"; let nodes = format!("{}\n{}\n", - "{\"data\":{\"alias\":\"Node1\",\"client_ip\":\"10.0.0.2\",\"client_port\":9702,\"node_ip\":\"10.0.0.2\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\",\"identifier\":\"FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4\",\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\",\"type\":\"0\"}", - "{\"data\":{\"alias\":\"Node2\",\"client_ip\":\"10.0.0.2\",\"client_port\":9704,\"node_ip\":\"10.0.0.2\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\",\"identifier\":\"8QhFxKxyaFsJy4CyxeYX34dFH8oWqyBv1P4HLQCsoeLy\",\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\",\"type\":\"0\"}"); + "{\"data\":{\"alias\":\"Node1\",\"client_ip\":\"10.0.0.2\",\"client_port\":9702,\"node_ip\":\"10.0.0.2\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\",\"identifier\":\"Th7MpTaRZVRYnPiabds81Y\",\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\",\"type\":\"0\"}", + "{\"data\":{\"alias\":\"Node2\",\"client_ip\":\"10.0.0.2\",\"client_port\":9704,\"node_ip\":\"10.0.0.2\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\",\"identifier\":\"EbP4aYNeTHL6q385GuVpRV\",\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\",\"type\":\"0\"}"); PoolUtils::create_pool_ledger_config(pool_name, Some(nodes), None, None).unwrap(); @@ -149,9 +149,9 @@ mod high_cases { let pool_name = "open_pool_ledger_works_for_three_nodes"; let nodes = format!("{}\n{}\n{}\n", - "{\"data\":{\"alias\":\"Node1\",\"client_ip\":\"10.0.0.2\",\"client_port\":9702,\"node_ip\":\"10.0.0.2\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\",\"identifier\":\"FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4\",\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\",\"type\":\"0\"}", - "{\"data\":{\"alias\":\"Node2\",\"client_ip\":\"10.0.0.2\",\"client_port\":9704,\"node_ip\":\"10.0.0.2\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\",\"identifier\":\"8QhFxKxyaFsJy4CyxeYX34dFH8oWqyBv1P4HLQCsoeLy\",\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\",\"type\":\"0\"}", - "{\"data\":{\"alias\":\"Node3\",\"client_ip\":\"10.0.0.2\",\"client_port\":9706,\"node_ip\":\"10.0.0.2\",\"node_port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\",\"identifier\":\"2yAeV5ftuasWNgQwVYzeHeTuM7LwwNtPR3Zg9N4JiDgF\",\"txnId\":\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\",\"type\":\"0\"}"); + "{\"data\":{\"alias\":\"Node1\",\"client_ip\":\"10.0.0.2\",\"client_port\":9702,\"node_ip\":\"10.0.0.2\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\",\"identifier\":\"Th7MpTaRZVRYnPiabds81Y\",\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\",\"type\":\"0\"}", + "{\"data\":{\"alias\":\"Node2\",\"client_ip\":\"10.0.0.2\",\"client_port\":9704,\"node_ip\":\"10.0.0.2\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\",\"identifier\":\"EbP4aYNeTHL6q385GuVpRV\",\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\",\"type\":\"0\"}", + "{\"data\":{\"alias\":\"Node3\",\"client_ip\":\"10.0.0.2\",\"client_port\":9706,\"node_ip\":\"10.0.0.2\",\"node_port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\",\"identifier\":\"4cU41vWW82ArfxJxHkzXPG\",\"txnId\":\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\",\"type\":\"0\"}"); PoolUtils::create_pool_ledger_config(pool_name, Some(nodes), None, None).unwrap(); @@ -319,10 +319,10 @@ mod medium_cases { let pool_name = "open_pool_ledger_works_for_invalid_nodes_file"; let nodes = format!("{}\n{}\n{}\n{}\n", - "{\"data\":{\"client_port\":9702,\"client_ip\":\"10.0.0.2\",\"node_ip\":\"10.0.0.2\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\",\"identifier\":\"FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4\",\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\",\"type\":\"0\"}", - "{\"data\":{\"client_port\":9704,\"client_ip\":\"10.0.0.2\",\"node_ip\":\"10.0.0.2\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\",\"identifier\":\"8QhFxKxyaFsJy4CyxeYX34dFH8oWqyBv1P4HLQCsoeLy\",\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\",\"type\":\"0\"}", - "{\"data\":{\"client_port\":9706,\"client_ip\":\"10.0.0.2\",\"node_ip\":\"10.0.0.2\",\"node_port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\",\"identifier\":\"2yAeV5ftuasWNgQwVYzeHeTuM7LwwNtPR3Zg9N4JiDgF\",\"txnId\":\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\",\"type\":\"0\"}", - "{\"data\":{\"client_port\":9708,\"client_ip\":\"10.0.0.2\",\"node_ip\":\"10.0.0.2\",\"node_port\":9707,\"services\":[\"VALIDATOR\"]},\"dest\":\"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA\",\"identifier\":\"FTE95CVthRtrBnK2PYCBbC9LghTcGwi9Zfi1Gz2dnyNx\",\"txnId\":\"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008\",\"type\":\"0\"}"); + "{\"data\":{\"client_ip\":\"10.0.0.2\",\"client_port\":9702,\"node_ip\":\"10.0.0.2\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\",\"identifier\":\"Th7MpTaRZVRYnPiabds81Y\",\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\",\"type\":\"0\"}", + "{\"data\":{\"client_ip\":\"10.0.0.2\",\"client_port\":9704,\"node_ip\":\"10.0.0.2\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\",\"identifier\":\"EbP4aYNeTHL6q385GuVpRV\",\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\",\"type\":\"0\"}", + "{\"data\":{\"client_ip\":\"10.0.0.2\",\"client_port\":9706,\"node_ip\":\"10.0.0.2\",\"node_port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\",\"identifier\":\"4cU41vWW82ArfxJxHkzXPG\",\"txnId\":\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\",\"type\":\"0\"}", + "{\"data\":{\"client_ip\":\"10.0.0.2\",\"client_port\":9708,\"node_ip\":\"10.0.0.2\",\"node_port\":9707,\"services\":[\"VALIDATOR\"]},\"dest\":\"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA\",\"identifier\":\"TWwCRQRZ2ZHMJFn9TzLp7W\",\"txnId\":\"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008\",\"type\":\"0\"}"); PoolUtils::create_pool_ledger_config(pool_name, Some(nodes), None, None).unwrap(); @@ -339,10 +339,10 @@ mod medium_cases { let pool_name = "open_pool_ledger_works_for_wrong_alias"; let nodes = format!("{}\n{}\n{}\n{}\n", - "{\"data\":{\"alias\":\"Node1\",\"client_ip\":\"10.0.0.2\",\"client_port\":9702,\"node_ip\":\"10.0.0.2\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\",\"identifier\":\"FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4\",\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\",\"type\":\"0\"}", - "{\"data\":{\"alias\":\"Node2\",\"client_ip\":\"10.0.0.2\",\"client_port\":9704,\"node_ip\":\"10.0.0.2\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\",\"identifier\":\"8QhFxKxyaFsJy4CyxeYX34dFH8oWqyBv1P4HLQCsoeLy\",\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\",\"type\":\"0\"}", - "{\"data\":{\"alias\":\"Node3\",\"client_ip\":\"10.0.0.2\",\"client_port\":9706,\"node_ip\":\"10.0.0.2\",\"node_port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\",\"identifier\":\"2yAeV5ftuasWNgQwVYzeHeTuM7LwwNtPR3Zg9N4JiDgF\",\"txnId\":\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\",\"type\":\"0\"}", - "{\"data\":{\"alias\":\"ALIAS_NODE\",\"client_ip\":\"10.0.0.2\",\"client_port\":9708,\"node_ip\":\"10.0.0.2\",\"node_port\":9707,\"services\":[\"VALIDATOR\"]},\"dest\":\"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA\",\"identifier\":\"FTE95CVthRtrBnK2PYCBbC9LghTcGwi9Zfi1Gz2dnyNx\",\"txnId\":\"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008\",\"type\":\"0\"}"); + "{\"data\":{\"alias\":\"Node1\",\"client_ip\":\"10.0.0.2\",\"client_port\":9702,\"node_ip\":\"10.0.0.2\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\",\"identifier\":\"Th7MpTaRZVRYnPiabds81Y\",\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\",\"type\":\"0\"}", + "{\"data\":{\"alias\":\"Node2\",\"client_ip\":\"10.0.0.2\",\"client_port\":9704,\"node_ip\":\"10.0.0.2\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\",\"identifier\":\"EbP4aYNeTHL6q385GuVpRV\",\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\",\"type\":\"0\"}", + "{\"data\":{\"alias\":\"Node3\",\"client_ip\":\"10.0.0.2\",\"client_port\":9706,\"node_ip\":\"10.0.0.2\",\"node_port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\",\"identifier\":\"4cU41vWW82ArfxJxHkzXPG\",\"txnId\":\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\",\"type\":\"0\"}", + "{\"data\":{\"alias\":\"ALIAS_NODE\",\"client_ip\":\"10.0.0.2\",\"client_port\":9708,\"node_ip\":\"10.0.0.2\",\"node_port\":9707,\"services\":[\"VALIDATOR\"]},\"dest\":\"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA\",\"identifier\":\"TWwCRQRZ2ZHMJFn9TzLp7W\",\"txnId\":\"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008\",\"type\":\"0\"}"); PoolUtils::create_pool_ledger_config(pool_name, Some(nodes), None, None).unwrap(); diff --git a/tests/signus.rs b/tests/signus.rs index 6868929fec..7bb8775770 100644 --- a/tests/signus.rs +++ b/tests/signus.rs @@ -212,7 +212,7 @@ mod high_cases { let wallet_handle = WalletUtils::create_and_open_wallet("pool1", None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1"}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let message = r#"{ "reqId":1496822211362017764, @@ -275,7 +275,7 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (did, verkey, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1"}"#).unwrap(); + let (did, verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let identity_json = format!(r#"{{"did":"{}", "verkey":"{}"}}"#, did, verkey); SignusUtils::store_their_did(wallet_handle, &identity_json).unwrap(); @@ -306,8 +306,8 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (trustee_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); - let (my_did, my_verkey, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"00000000000000000000000000000My1"}"#).unwrap(); + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); + let (my_did, my_verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), Some(&my_verkey), None, None).unwrap(); LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request).unwrap(); @@ -334,8 +334,8 @@ mod high_cases { WalletUtils::create_wallet(pool_name, "wallet1", None, None).unwrap(); let wallet_handle = WalletUtils::open_wallet("wallet1", Some(r#"{"freshness_time":1}"#)).unwrap(); - let (trustee_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); - let (my_did, my_verkey, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"00000000000000000000000000000My1"}"#).unwrap(); + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); + let (my_did, my_verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), Some(&my_verkey), None, None).unwrap(); LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request).unwrap(); @@ -544,7 +544,7 @@ mod medium_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (did, verkey, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1"}"#).unwrap(); + let (did, verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let identity_json = format!(r#"{{"did":"{}", "verkey":"{}"}}"#, did, verkey); SignusUtils::store_their_did(wallet_handle, &identity_json).unwrap(); @@ -565,7 +565,7 @@ mod medium_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (did, verkey, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1"}"#).unwrap(); + let (did, verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let identity_json = format!(r#"{{"did":"{}", "verkey":"{}"}}"#, did, verkey); SignusUtils::store_their_did(wallet_handle, &identity_json).unwrap(); @@ -590,7 +590,7 @@ mod medium_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet("other_pool_name", None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"00000000000000000000000000000My1"}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); let message = r#"{"reqId":1496822211362017764, "signature":"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai"}"#; @@ -636,8 +636,8 @@ mod medium_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (trustee_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1","cid":true}"#).unwrap(); - let (my_did, my_verkey, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"00000000000000000000000000000My1"}"#).unwrap(); + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); + let (my_did, my_verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), Some(&my_verkey), None, None).unwrap(); LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request).unwrap(); diff --git a/tests/utils/pool.rs b/tests/utils/pool.rs index caaf190f99..cb06e4233d 100644 --- a/tests/utils/pool.rs +++ b/tests/utils/pool.rs @@ -178,10 +178,10 @@ impl PoolUtils { let mut f = fs::File::create(path.clone()).unwrap(); let data = format!("{}\n{}\n{}\n{}\n", - "{\"data\":{\"alias\":\"Node1\",\"client_ip\":\"10.0.0.2\",\"client_port\":9702,\"node_ip\":\"10.0.0.2\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\",\"identifier\":\"FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4\",\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\",\"type\":\"0\"}", - "{\"data\":{\"alias\":\"Node2\",\"client_ip\":\"10.0.0.2\",\"client_port\":9704,\"node_ip\":\"10.0.0.2\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\",\"identifier\":\"8QhFxKxyaFsJy4CyxeYX34dFH8oWqyBv1P4HLQCsoeLy\",\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\",\"type\":\"0\"}", - "{\"data\":{\"alias\":\"Node3\",\"client_ip\":\"10.0.0.2\",\"client_port\":9706,\"node_ip\":\"10.0.0.2\",\"node_port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\",\"identifier\":\"2yAeV5ftuasWNgQwVYzeHeTuM7LwwNtPR3Zg9N4JiDgF\",\"txnId\":\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\",\"type\":\"0\"}", - "{\"data\":{\"alias\":\"Node4\",\"client_ip\":\"10.0.0.2\",\"client_port\":9708,\"node_ip\":\"10.0.0.2\",\"node_port\":9707,\"services\":[\"VALIDATOR\"]},\"dest\":\"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA\",\"identifier\":\"FTE95CVthRtrBnK2PYCBbC9LghTcGwi9Zfi1Gz2dnyNx\",\"txnId\":\"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008\",\"type\":\"0\"}"); + "{\"data\":{\"alias\":\"Node1\",\"client_ip\":\"10.0.0.2\",\"client_port\":9702,\"node_ip\":\"10.0.0.2\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\",\"identifier\":\"Th7MpTaRZVRYnPiabds81Y\",\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\",\"type\":\"0\"}", + "{\"data\":{\"alias\":\"Node2\",\"client_ip\":\"10.0.0.2\",\"client_port\":9704,\"node_ip\":\"10.0.0.2\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\",\"identifier\":\"EbP4aYNeTHL6q385GuVpRV\",\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\",\"type\":\"0\"}", + "{\"data\":{\"alias\":\"Node3\",\"client_ip\":\"10.0.0.2\",\"client_port\":9706,\"node_ip\":\"10.0.0.2\",\"node_port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\",\"identifier\":\"4cU41vWW82ArfxJxHkzXPG\",\"txnId\":\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\",\"type\":\"0\"}", + "{\"data\":{\"alias\":\"Node4\",\"client_ip\":\"10.0.0.2\",\"client_port\":9708,\"node_ip\":\"10.0.0.2\",\"node_port\":9707,\"services\":[\"VALIDATOR\"]},\"dest\":\"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA\",\"identifier\":\"TWwCRQRZ2ZHMJFn9TzLp7W\",\"txnId\":\"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008\",\"type\":\"0\"}"); let data = predefined_data.unwrap_or(data); diff --git a/tests/utils/signus.rs b/tests/utils/signus.rs index f184ee90e7..71eaf2ae91 100644 --- a/tests/utils/signus.rs +++ b/tests/utils/signus.rs @@ -48,7 +48,7 @@ impl SignusUtils { Ok(signature) } - pub fn create_and_store_my_did(wallet_handle: i32, seed: Option) -> Result<(String, String, String), ErrorCode> { + pub fn create_and_store_my_did(wallet_handle: i32, seed: Option<&str>) -> Result<(String, String, String), ErrorCode> { let (create_and_store_my_did_sender, create_and_store_my_did_receiver) = channel(); let create_and_store_my_did_cb = Box::new(move |err, did, verkey, public_key| { create_and_store_my_did_sender.send((err, did, verkey, public_key)).unwrap(); From 9e89fa0629c2d81dbcb5b44f4f8e3defef233ca1 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 18:06:36 +0300 Subject: [PATCH 129/349] added virtual env --- ci/ubuntu.dockerfile | 15 +++++++++++++-- tests/anoncreds.rs | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index 348e6fe9c6..db56d6cf23 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -13,7 +13,13 @@ RUN apt-get update && \ libsodium-dev \ cmake \ git \ - python3.5 + python3.5 \ + python3-pip + +RUN pip3 install -U \ + pip \ + setuptools \ + virtualenv ENV RUST_ARCHIVE=rust-1.16.0-x86_64-unknown-linux-gnu.tar.gz ENV RUST_DOWNLOAD_URL=https://static.rust-lang.org/dist/$RUST_ARCHIVE @@ -36,4 +42,9 @@ RUN cargo install --git https://github.com/DSRCorporation/cargo-test-xunit WORKDIR /home/indy -RUN git clone https://github.com/hyperledger/indy-anoncreds.git \ No newline at end of file +RUN git clone https://github.com/hyperledger/indy-anoncreds.git +RUN virtualenv -p python3.5 /home/indy/ +USER root +RUN ln -sf /home/indy/bin/python /usr/local/bin/python +RUN ln -sf /home/indy/bin/pip /usr/local/bin/pip +USER indy \ No newline at end of file diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index 8c9571f701..7e07d15497 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -1474,7 +1474,7 @@ mod demos { let schema = AnoncredsUtils::get_gvt_schema_json(schema_seq_no); let claim_def_json = AnoncredsUtils::issuer_create_claim_definition(issuer_wallet_handle, &ISSUER_DID, &schema, None, false).unwrap(); - + info!("---------------------before_command--------------------"); Command::new("python3").arg("-V").spawn().expect("failed to execute process"); info!("---------------------executed--------------------"); From b2dd5c3aca92ff4d324487db5c4764874f6cb297 Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Thu, 13 Jul 2017 18:07:45 +0300 Subject: [PATCH 130/349] Switch to sovrin package (was sovrin-node). --- ci/indy-pool.dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/indy-pool.dockerfile b/ci/indy-pool.dockerfile index 5c201ffee5..60fdfed760 100644 --- a/ci/indy-pool.dockerfile +++ b/ci/indy-pool.dockerfile @@ -26,7 +26,7 @@ RUN echo "deb https://repo.sovrin.org/deb xenial master" >> /etc/apt/sources.lis RUN useradd -ms /bin/bash -u $uid sovrin RUN apt-get update -y && apt-get install -y \ - sovrin-node=0.4.23 + sovrin=0.2.8 RUN echo '[supervisord]\n\ logfile = /tmp/supervisord.log\n\ From a5b8d669618e32276b5c16ff46c4d79f8d4a1dd1 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 13 Jul 2017 18:16:35 +0300 Subject: [PATCH 131/349] Implemented integration tests for Signus APi --- wrappers/java/pom.xml | 17 +- .../org/hyperledger/indy/sdk/SignusTest.java | 6 +- .../indy/sdk/signus/CreateMyDidTest.java | 131 +++++++++++++ .../indy/sdk/signus/ReplaceKeysTest.java | 76 ++++++++ .../hyperledger/indy/sdk/signus/SignTest.java | 81 ++++++++ .../indy/sdk/signus/StoreTheirDidTest.java | 73 ++++++++ .../indy/sdk/signus/VerifyTest.java | 176 ++++++++++++++++++ .../hyperledger/indy/sdk/utils/PoolUtils.java | 3 + .../indy/sdk/utils/StorageUtils.java | 2 +- 9 files changed, 557 insertions(+), 8 deletions(-) create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/ReplaceKeysTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/StoreTheirDidTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java diff --git a/wrappers/java/pom.xml b/wrappers/java/pom.xml index 1a5121483c..e9d3016c41 100644 --- a/wrappers/java/pom.xml +++ b/wrappers/java/pom.xml @@ -98,10 +98,19 @@ commons-io commons-io 2.5 + test + + + org.bitcoinj + bitcoinj-core + 0.14.4 + test + + + org.json + json + 20160810 + test - - - - diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/SignusTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/SignusTest.java index 3248221e88..cda7271a4c 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/SignusTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/SignusTest.java @@ -17,7 +17,7 @@ public class SignusTest extends TestCase { private Pool pool; private Wallet wallet; - + @Override protected void setUp() throws Exception { @@ -38,7 +38,7 @@ protected void tearDown() throws Exception { public void testSignus() throws Exception { - Future future1 = Signus.createAndStoreMyDid(this.wallet, null); + Future future1 = Signus.createAndStoreMyDid(this.wallet, "{}"); CreateAndStoreMyDidResult result1 = future1.get(); Assert.assertNotNull(result1); String did1 = result1.getDid(); @@ -60,4 +60,4 @@ public void testSignus() throws Exception { Assert.assertNotNull(pk2); Assert.assertNotEquals(verkey2, verkey1); } -} +} \ No newline at end of file diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java new file mode 100644 index 0000000000..6a500d219c --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java @@ -0,0 +1,131 @@ +package org.hyperledger.indy.sdk.signus; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.junit.*; +import org.bitcoinj.core.Base58; + +import java.util.concurrent.ExecutionException; + +public class CreateMyDidTest extends IndyIntegrationTest { + + private Wallet wallet; + + @Before + public void createWallet() throws Exception { + Wallet.createWallet("default", "signusWallet", "default", null, null).get(); + this.wallet = Wallet.openWallet("signusWallet", null, null).get(); + } + + @After + public void deleteWallet() throws Exception { + this.wallet.closeWallet(); + Wallet.deleteWallet("signusWallet", null); + } + + private String seed = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + private String did = "8wZcEriaNLNKtteJvx7f8i"; + private String expectedVerkey = "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"; + private String existsCryptoType = "ed25519"; + + @Test + public void testCreateMyDidWorksForEmptyJson() throws Exception { + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, null, null); + + CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); + Assert.assertNotNull(result); + + Assert.assertEquals(16, Base58.decode(result.getDid()).length); + Assert.assertEquals(32, Base58.decode(result.getVerkey()).length); + } + + @Test + public void testCreateMyDidWorksForSeed() throws Exception { + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, seed, null, null); + + CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); + Assert.assertNotNull(result); + + Assert.assertEquals("NcYxiDXkpYi6ov5FcYDi1e", result.getDid()); + Assert.assertEquals(expectedVerkey, result.getVerkey()); + } + + @Test + public void testCreateMyDidWorksAsCid() throws Exception { + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, seed, null, true); + + CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); + Assert.assertNotNull(result); + + Assert.assertEquals(expectedVerkey, result.getDid()); + Assert.assertEquals(expectedVerkey, result.getVerkey()); + } + + @Test + public void testCreateMyDidWorksForPassedDid() throws Exception { + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(did, null, null, true); + + CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); + Assert.assertNotNull(result); + + Assert.assertEquals(did, result.getDid()); + } + + @Test + public void testCreateMyDidWorksForCorrectCryptoType() throws Exception { + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, existsCryptoType, null); + + CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); + Assert.assertNotNull(result); + } + + @Test + public void testCreateMyDidWorksForInvalidSeed() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "aaaaaaaaaaa", null, null); + + Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); + } + + @Test + public void testCreateMyDidWorksForInvalidCryptoType() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.SignusUnknownCryptoError)); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, "crypto_type", null); + + Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); + } + + @Test + public void testCreateMyDidWorksForAllParams() throws Exception { + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(did, seed, existsCryptoType, true); + + CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); + Assert.assertNotNull(result); + + Assert.assertEquals(did, result.getDid()); + Assert.assertEquals(expectedVerkey, result.getVerkey()); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/ReplaceKeysTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/ReplaceKeysTest.java new file mode 100644 index 0000000000..112d740b0c --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/ReplaceKeysTest.java @@ -0,0 +1,76 @@ +package org.hyperledger.indy.sdk.signus; + +import org.bitcoinj.core.Base58; +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; +import org.hyperledger.indy.sdk.wallet.Wallet; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.util.concurrent.ExecutionException; + +public class ReplaceKeysTest extends IndyIntegrationTest { + + private Wallet wallet; + private String did; + private String verkey; + + @Before + public void createWalletWithDid() throws Exception { + Wallet.createWallet("default", "signusWallet", "default", null, null).get(); + wallet = Wallet.openWallet("signusWallet", null, null).get(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, null, null); + + CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); + + did = result.getDid(); + verkey = result.getVerkey(); + } + + @After + public void deleteWallet() throws Exception { + wallet.closeWallet(); + Wallet.deleteWallet("signusWallet", null); + } + + @Test + public void testReplaceKeysWorksForEmptyJson() throws Exception { + SignusResults.ReplaceKeysResult result = Signus.replaceKeys(wallet, did, "{}").get(); + assertNotNull(result); + + assertEquals(32, Base58.decode(result.getVerkey()).length); + } + + @Test + public void testReplaceKeysWorksForInvalidDid() throws Exception { + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + Signus.replaceKeys(this.wallet, "invalid_base58_string", "{}").get(); + } + + @Test + public void testReplaceKeysWorksForNotExistsDid() throws Exception { + SignusResults.ReplaceKeysResult result = Signus.replaceKeys(this.wallet, "8wZcEriaNLNKtteJvx7f8i", "{}").get(); + assertNotNull(result); + } + + @Test + public void testReplaceKeysWorksForSeed() throws Exception { + SignusResults.ReplaceKeysResult result = Signus.replaceKeys(this.wallet, this.did, "{\"seed\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}").get(); + assertNotNull(result); + String verkey = result.getVerkey(); + + assertEquals("CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW", verkey); + assertNotEquals(this.verkey, verkey); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java new file mode 100644 index 0000000000..dc38de5d3f --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java @@ -0,0 +1,81 @@ +package org.hyperledger.indy.sdk.signus; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; +import org.hyperledger.indy.sdk.utils.StorageUtils; +import org.hyperledger.indy.sdk.wallet.Wallet; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.util.concurrent.ExecutionException; + +public class SignTest extends IndyIntegrationTest { + + + private Wallet wallet; + private String did; + + @Before + public void createWalletWhitDid() throws Exception { + Wallet.createWallet("default", "signusWallet", "default", null, null).get(); + this.wallet = Wallet.openWallet("signusWallet", null, null).get(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); + did = result.getDid(); + } + + @After + public void deleteWallet() throws Exception { + this.wallet.closeWallet(); + Wallet.deleteWallet("signusWallet", null); + } + + @Test + public void testSignWorks() throws Exception { + + String msg = "{\n" + + " \"reqId\":1496822211362017764,\n" + + " \"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\",\n" + + " \"operation\":{\n" + + " \"type\":\"1\",\n" + + " \"dest\":\"VsKV7grR1BUE29mG2Fm2kX\",\n" + + " \"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\"\n" + + " }\n" + + " }"; + + String expectedSignature = "\"signature\":\"65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW\""; + + String signedMessage = Signus.sign(this.wallet, did, msg).get(); + + assertTrue(signedMessage.contains(expectedSignature)); + } + + @Test + public void testSignWorksForUnknowDid() throws Exception { + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletNotFoundError)); + + String msg = "{\"reqId\":1496822211362017764}"; + + Signus.sign(this.wallet, "8wZcEriaNLNKtteJvx7f8i", msg).get(); + } + + @Test + public void testSignWorksForInvalidMessageFormat() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String msg = "reqId:1495034346617224651"; + Signus.sign(this.wallet, did, msg).get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/StoreTheirDidTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/StoreTheirDidTest.java new file mode 100644 index 0000000000..80edecccc8 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/StoreTheirDidTest.java @@ -0,0 +1,73 @@ +package org.hyperledger.indy.sdk.signus; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.util.concurrent.ExecutionException; + +public class StoreTheirDidTest extends IndyIntegrationTest { + + + private Wallet wallet; + + @Before + public void createWallet() throws Exception { + Wallet.createWallet("default", "signusWallet", "default", null, null).get(); + this.wallet = Wallet.openWallet("signusWallet", null, null).get(); + + } + + @After + public void deleteWallet() throws Exception { + + this.wallet.closeWallet(); + Wallet.deleteWallet("signusWallet", null); + } + + @Test + public void testStoreTheirDidWorks() throws Exception { + Signus.storeTheirDid(this.wallet, "{\"did\":\"8wZcEriaNLNKtteJvx7f8i\"}").get(); + } + + @Test + public void testCreateMyDidWorksForInvalidIdentityJson() throws Exception { + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + Signus.storeTheirDid(this.wallet, "{\"field\":\"value\"}").get(); + } + + @Test + public void testStoreTheirDidWorksWithVerkey() throws Exception { + Signus.storeTheirDid(this.wallet,"{\"did\":\"8wZcEriaNLNKtteJvx7f8i\", " + + "\"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\"}").get(); + } + + @Test + public void testStoreTheirDidWorksWithoutDid() throws Exception { + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + Signus.storeTheirDid(this.wallet, "{\"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\"}").get(); + } + + @Test + public void testStoreTheirDidWorksForCorrectCryptoType() throws Exception { + Signus.storeTheirDid(this.wallet, "{\"did\":\"8wZcEriaNLNKtteJvx7f8i\", " + + "\"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\", \"crypto_type\": \"ed25519\"}").get(); + } + + @Test + public void testStoreTheirDidWorksForInvalidCryptoType() throws Exception { + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.SignusUnknownCryptoError)); + + Signus.storeTheirDid(this.wallet, "{\"did\":\"8wZcEriaNLNKtteJvx7f8i\", " + + "\"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\", \"crypto_type\": \"some_type\"}").get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java new file mode 100644 index 0000000000..98c80754af --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java @@ -0,0 +1,176 @@ +package org.hyperledger.indy.sdk.signus; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.ledger.Ledger; +import org.hyperledger.indy.sdk.pool.Pool; +import org.hyperledger.indy.sdk.pool.PoolJSONParameters; +import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.hyperledger.indy.sdk.utils.StorageUtils; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.junit.*; +import org.junit.rules.Timeout; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +public class VerifyTest extends IndyIntegrationTest { + + @Rule + public Timeout globalTimeout = new Timeout(3, TimeUnit.SECONDS); + + private Pool pool; + private Wallet wallet; + private String trustee_did; + private String trustee_verkey; + private String identityJson; + + @Before + public void createWalletWithDid() throws Exception { + String poolName = PoolUtils.createPoolLedgerConfig(); + + PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); + pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); + + Wallet.createWallet(poolName, "signusWallet", "default", null, null).get(); + wallet = Wallet.openWallet("signusWallet", null, null).get(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, true); + + CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(wallet, didJson.toJson()).get(); + Assert.assertNotNull(result); + + trustee_did = result.getDid(); + trustee_verkey = result.getVerkey(); + } + + @After + public void deleteWallet() throws Exception { + wallet.closeWallet(); + Wallet.deleteWallet("signusWallet", null); + pool.closePoolLedger(); + } + + private String createNewNymWithDidInLedger() throws Exception{ + SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); + + CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(wallet, didJson.toJson()).get(); + String new_did = result.getDid(); + String new_verkey = result.getVerkey(); + + String nymRequest = Ledger.buildNymRequest(trustee_did, new_did, new_verkey, null, null).get(); + Ledger.signAndSubmitRequest(pool, wallet, trustee_did, nymRequest); + return new_did; + } + + @Test + public void testVerifyWorksForVerkeyCachedInWallet() throws Exception { + identityJson = String.format("{\"did\":\"%s\",\"verkey\":\"%s\"}", trustee_did, trustee_verkey); + Signus.storeTheirDid(wallet, identityJson).get(); + + String msg = "{\n" + + " \"reqId\":1496822211362017764,\n" + + " \"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\",\n" + + " \"operation\":{\n" + + " \"type\":\"1\",\n" + + " \"dest\":\"VsKV7grR1BUE29mG2Fm2kX\",\n" + + " \"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\"\n" + + " },\n" + + " \"signature\":\"65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW\"\n" + + " }"; + + Boolean valid = Signus.verifySignature(wallet, pool, trustee_did, msg).get(); + Assert.assertTrue(valid); + } + + @Test + public void testVerifyWorksForGetVerkeyFromLedger() throws Exception { + String new_did = createNewNymWithDidInLedger(); + + identityJson = String.format("{\"did\":\"%s\"}", new_did); + Signus.storeTheirDid(wallet, identityJson).get(); + + String msg = "{\"reqId\":1496822211362017764,\n" + + "\"signature\":\"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai\"}"; + + Boolean valid = Signus.verifySignature(wallet, pool, new_did, msg).get(); + Assert.assertTrue(valid); + } + + @Test + public void testVerifyWorksForGetNymFromLedger() throws Exception { + String new_did = createNewNymWithDidInLedger(); + + String msg = "{\"reqId\":1496822211362017764," + + "\"signature\":\"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai\"}"; + + Boolean valid = Signus.verifySignature(wallet, pool, new_did, msg).get(); + Assert.assertTrue(valid); + } + + @Test + public void testVerifyWorksForInvalidMessageFormat() throws Exception { + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String msg = "\"signature\":\"65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW\""; + + Signus.verifySignature(wallet, pool, trustee_did, msg).get(); + } + + @Test + public void testVerifyWorksForMessageWithoutSignature() throws Exception { + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String msg = "{\n" + + " \"reqId\":1496822211362017764,\n" + + " \"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\",\n" + + " \"operation\":{\n" + + " \"type\":\"1\",\n" + + " \"dest\":\"VsKV7grR1BUE29mG2Fm2kX\",\n" + + " \"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\"\n" + + " },\n" + + " }"; + + Signus.verifySignature(wallet, pool, trustee_did, msg).get(); + } + + @Test + public void testVerifyWorksForOtherSigner() throws Exception { + identityJson = String.format("{\"did\":\"%s\", \"verkey\":\"%s\"}", trustee_did, trustee_verkey); + + Signus.storeTheirDid(wallet, identityJson).get(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Steward1", null, null); + + CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(wallet, didJson.toJson()).get(); + String other_did = result.getDid(); + String other_verkey = result.getVerkey(); + + identityJson = String.format("{\"did\":\"%s\", \"verkey\":\"%s\"}", other_did, other_verkey); + + Signus.storeTheirDid(wallet, identityJson).get(); + + String msg = "{\n" + + " \"reqId\":1496822211362017764,\n" + + " \"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\",\n" + + " \"operation\":{\n" + + " \"type\":\"1\",\n" + + " \"dest\":\"VsKV7grR1BUE29mG2Fm2kX\",\n" + + " \"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\"\n" + + " }\n" + + " }"; + + String signedMessage = Signus.sign(wallet, trustee_did, msg).get(); + + Boolean valid = Signus.verifySignature(wallet, pool, other_did, signedMessage).get(); + + Assert.assertFalse(valid); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java index d471c9cdee..e9129686d9 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java @@ -1,5 +1,6 @@ package org.hyperledger.indy.sdk.utils; +import org.apache.commons.io.FileUtils; import org.hyperledger.indy.sdk.IndyException; import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.pool.PoolJSONParameters; @@ -26,6 +27,8 @@ public static File createGenesisTxnFile(String filename, int nodesCnt) throws IO File file = new File(path); + FileUtils.forceMkdirParent(file); + FileWriter fw = new FileWriter(file); for (int i = 0; i < nodesCnt; i++) { fw.write(defaultTxns[i]); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java index e0cfc2fe75..733331176d 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java @@ -9,7 +9,7 @@ public class StorageUtils { private static void cleanDirectory(File path) throws Exception { if (path.isDirectory()) { - FileUtils.cleanDirectory(path); + FileUtils.deleteQuietly(path); } } From 0d4b7e5e6190b67c074a61e8a1aff3bdbc02c767 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 18:25:19 +0300 Subject: [PATCH 132/349] added anoncreds for python --- ci/ubuntu.dockerfile | 5 ++--- tests/anoncreds.rs | 3 --- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index db56d6cf23..f8cd20888e 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -17,9 +17,8 @@ RUN apt-get update && \ python3-pip RUN pip3 install -U \ - pip \ - setuptools \ - virtualenv + virtualenv \ + git+https://github.com/hyperledger/indy-anoncreds.git ENV RUST_ARCHIVE=rust-1.16.0-x86_64-unknown-linux-gnu.tar.gz ENV RUST_DOWNLOAD_URL=https://static.rust-lang.org/dist/$RUST_ARCHIVE diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index 7e07d15497..4d30e4f870 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -1474,9 +1474,6 @@ mod demos { let schema = AnoncredsUtils::get_gvt_schema_json(schema_seq_no); let claim_def_json = AnoncredsUtils::issuer_create_claim_definition(issuer_wallet_handle, &ISSUER_DID, &schema, None, false).unwrap(); - info!("---------------------before_command--------------------"); - Command::new("python3").arg("-V").spawn().expect("failed to execute process"); - info!("---------------------executed--------------------"); Command::new("python3") .arg("/home/indy/indy-anoncreds/anoncreds/test/test_interoperability_with_libsovrin_pysovrin_is_verifier.py") From a466eb95155bd94e9d74b36a2cdce1fb76fa4b3c Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Thu, 13 Jul 2017 18:32:52 +0300 Subject: [PATCH 133/349] [java] Update pool tests for @before and @after usage. --- .../indy/sdk/IndyIntegrationTest.java | 10 ++---- .../indy/sdk/pool/CreatePoolTest.java | 13 ------- .../indy/sdk/pool/OpenPoolTest.java | 36 +++---------------- .../hyperledger/indy/sdk/utils/PoolUtils.java | 4 ++- 4 files changed, 11 insertions(+), 52 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java index a635fede0f..7ac943ef7a 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java @@ -21,19 +21,15 @@ public class IndyIntegrationTest { public Timeout globalTimeout = new Timeout(1, TimeUnit.SECONDS); @Before - public void setUp() throws Exception { + public void setUp() throws IOException { InitHelper.init(); StorageUtils.cleanupStorage(); } - @After - public void tearDown() throws Exception { - StorageUtils.cleanupStorage(); - } - protected HashSet openedPools = new HashSet<>(); - protected void afterEach() throws IOException { + @After + public void tearDown() throws IOException { openedPools.forEach(pool -> { try { pool.closePoolLedger(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java index 45531b3094..848bf042f5 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/CreatePoolTest.java @@ -4,7 +4,6 @@ import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.utils.PoolUtils; -import org.hyperledger.indy.sdk.utils.StorageUtils; import org.junit.Test; import java.io.File; @@ -15,42 +14,30 @@ public class CreatePoolTest extends IndyIntegrationTest { @Test public void testCreatePoolWorksForNullConfig() throws Exception { - StorageUtils.cleanupStorage(); - File file = new File("testCreatePoolWorks.txn"); file.deleteOnExit(); assertTrue(file.createNewFile()); Pool.createPoolLedgerConfig("testCreatePoolWorks", null).get(); - - StorageUtils.cleanupStorage(); } @Test public void testCreatePoolWorksForConfigJSON() throws Exception { - StorageUtils.cleanupStorage(); - File genesisTxnFile = PoolUtils.createGenesisTxnFile("genesis.txn"); PoolJSONParameters.CreatePoolLedgerConfigJSONParameter createPoolLedgerConfigJSONParameter = new PoolJSONParameters.CreatePoolLedgerConfigJSONParameter(genesisTxnFile.getAbsolutePath()); Pool.createPoolLedgerConfig("testCreatePoolWorks", createPoolLedgerConfigJSONParameter.toJson()).get(); - - StorageUtils.cleanupStorage(); } @Test public void testCreatePoolWorksForEmptyName() throws Exception { thrown.expect(new ErrorCodeMatcher(ErrorCode.CommonInvalidParam2)); - StorageUtils.cleanupStorage(); - File genesisTxnFile = PoolUtils.createGenesisTxnFile("genesis.txn"); PoolJSONParameters.CreatePoolLedgerConfigJSONParameter createPoolLedgerConfigJSONParameter = new PoolJSONParameters.CreatePoolLedgerConfigJSONParameter(genesisTxnFile.getAbsolutePath()); Pool.createPoolLedgerConfig("", createPoolLedgerConfigJSONParameter.toJson()).get(); - - StorageUtils.cleanupStorage(); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java index 05aa18b63d..c4084da718 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java @@ -2,37 +2,27 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; -import org.hyperledger.indy.sdk.IndyException; import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; import org.hyperledger.indy.sdk.utils.PoolUtils; -import org.hyperledger.indy.sdk.utils.StorageUtils; import org.junit.Test; -import java.util.HashSet; - import static org.junit.Assert.assertNotNull; public class OpenPoolTest extends IndyIntegrationTest { @Test public void testOpenPoolWorksForNullConfig() throws Exception { - StorageUtils.cleanupStorage(); - String poolName = PoolUtils.createPoolLedgerConfig(); Pool pool = Pool.openPoolLedger(poolName, null).get(); assertNotNull(pool); openedPools.add(pool); - - afterEach(); } @Test public void testOpenPoolWorksForConfig() throws Exception { - StorageUtils.cleanupStorage(); - String poolName = PoolUtils.createPoolLedgerConfig(); OpenPoolLedgerJSONParameter config = new OpenPoolLedgerJSONParameter(true, null, null); @@ -40,55 +30,39 @@ public void testOpenPoolWorksForConfig() throws Exception { assertNotNull(pool); openedPools.add(pool); - - afterEach(); } @Test public void testOpenPoolWorksForTwice() throws Exception { thrown.expectCause(new ErrorCodeMatcher(ErrorCode.PoolLedgerInvalidPoolHandle)); - StorageUtils.cleanupStorage(); - - try { - String poolName = PoolUtils.createPoolLedgerConfig(); + String poolName = PoolUtils.createPoolLedgerConfig(); - Pool pool1 = Pool.openPoolLedger(poolName, null).get(); - assertNotNull(pool1); - openedPools.add(pool1); + Pool pool1 = Pool.openPoolLedger(poolName, null).get(); + assertNotNull(pool1); + openedPools.add(pool1); - Pool.openPoolLedger(poolName, null).get(); - } finally { - afterEach(); - } + Pool.openPoolLedger(poolName, null).get(); } @Test public void testOpenPoolWorksForTwoNodes() throws Exception { - StorageUtils.cleanupStorage(); - String poolName = PoolUtils.createPoolLedgerConfig(2); Pool pool = Pool.openPoolLedger(poolName, null).get(); assertNotNull(pool); openedPools.add(pool); - - afterEach(); } @Test public void testOpenPoolWorksForThreeNodes() throws Exception { - StorageUtils.cleanupStorage(); - String poolName = PoolUtils.createPoolLedgerConfig(3); Pool pool = Pool.openPoolLedger(poolName, null).get(); assertNotNull(pool); openedPools.add(pool); - - afterEach(); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java index d471c9cdee..a90946b07e 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java @@ -1,10 +1,10 @@ package org.hyperledger.indy.sdk.utils; +import org.apache.commons.io.FileUtils; import org.hyperledger.indy.sdk.IndyException; import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.pool.PoolJSONParameters; -import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -26,6 +26,8 @@ public static File createGenesisTxnFile(String filename, int nodesCnt) throws IO File file = new File(path); + FileUtils.forceMkdirParent(file); + FileWriter fw = new FileWriter(file); for (int i = 0; i < nodesCnt; i++) { fw.write(defaultTxns[i]); From 01cece31ea11756cd37777eea643527eb9e1a339 Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Thu, 13 Jul 2017 18:36:08 +0300 Subject: [PATCH 134/349] [java] Remove old PoolTest. --- .../org/hyperledger/indy/sdk/PoolTest.java | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java deleted file mode 100644 index b24bf8101d..0000000000 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/PoolTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.hyperledger.indy.sdk; - -import java.util.concurrent.Future; - -import org.hyperledger.indy.sdk.utils.InitHelper; -import org.hyperledger.indy.sdk.pool.Pool; -import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; -import org.junit.Assert; - -import junit.framework.TestCase; - -public class PoolTest extends TestCase { - - @Override - protected void setUp() throws Exception { - InitHelper.init(); - } - - @Override - protected void tearDown() throws Exception { - - } - - public void testPool() throws Exception { - -/* CreatePoolLedgerConfigOptions config1 = new CreatePoolLedgerConfigOptions(null); - Future future1 = Pool.createPoolLedgerConfig("myconfig", config1.toJson()); - CreatePoolLedgerConfigResult result1 = future1.get(); - Assert.assertNotNull(result1);*/ - - OpenPoolLedgerJSONParameter config2 = new OpenPoolLedgerJSONParameter(null, null, null); - Future future2 = Pool.openPoolLedger("myconfig", config2.toJson()); - Pool result2 = future2.get(); - Assert.assertNotNull(result2); - } -} From 50531766a22134754fa8abb9d9f6d3e976502c37 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 18:36:45 +0300 Subject: [PATCH 135/349] added setuptools and pip --- Jenkinsfile | 2 +- ci/ubuntu.dockerfile | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index b73bb0c745..2f183b42e6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -71,7 +71,7 @@ def testUbuntu() { testEnv.inside("--ip=\"10.0.0.3\" --network=${network_name}") { echo 'Ubuntu Test: Test' - + sh 'chmod -R 777 /home/indy/' sh 'cargo update' try { diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index f8cd20888e..8fb1640239 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -17,6 +17,8 @@ RUN apt-get update && \ python3-pip RUN pip3 install -U \ + pip \ + setuptools \ virtualenv \ git+https://github.com/hyperledger/indy-anoncreds.git From f175123eef5f94b4bc1dd8e6efc0249f556f31cc Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 18:45:15 +0300 Subject: [PATCH 136/349] added charm-crypto --- ci/ubuntu.dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index 8fb1640239..019f472b93 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -14,7 +14,8 @@ RUN apt-get update && \ cmake \ git \ python3.5 \ - python3-pip + python3-pip \ + python3-charm-crypto RUN pip3 install -U \ pip \ @@ -45,6 +46,8 @@ WORKDIR /home/indy RUN git clone https://github.com/hyperledger/indy-anoncreds.git RUN virtualenv -p python3.5 /home/indy/ +RUN cp -r /usr/local/lib/python3.5/dist-packages/Charm_Crypto-0.0.0.egg-info /home/indy/lib/python3.5/site-packages/Charm_Crypto-0.0.0.egg-info +RUN cp -r /usr/local/lib/python3.5/dist-packages/charm /home/indy/lib/python3.5/site-packages/charm USER root RUN ln -sf /home/indy/bin/python /usr/local/bin/python RUN ln -sf /home/indy/bin/pip /usr/local/bin/pip From e0a9ffec9456391a368940b906f4f7e418815d96 Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Thu, 13 Jul 2017 18:49:13 +0300 Subject: [PATCH 137/349] Switch to indy-node package for pool. --- ci/indy-pool.dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/indy-pool.dockerfile b/ci/indy-pool.dockerfile index 60fdfed760..f3ce4b8d52 100644 --- a/ci/indy-pool.dockerfile +++ b/ci/indy-pool.dockerfile @@ -26,7 +26,7 @@ RUN echo "deb https://repo.sovrin.org/deb xenial master" >> /etc/apt/sources.lis RUN useradd -ms /bin/bash -u $uid sovrin RUN apt-get update -y && apt-get install -y \ - sovrin=0.2.8 + indy-node=0.4.26 RUN echo '[supervisord]\n\ logfile = /tmp/supervisord.log\n\ From bbe54c26ccf3dee2d9b314a2cb09a800e4c4e789 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 18:49:58 +0300 Subject: [PATCH 138/349] added repo --- ci/ubuntu.dockerfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index 019f472b93..ce70138cba 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -14,8 +14,7 @@ RUN apt-get update && \ cmake \ git \ python3.5 \ - python3-pip \ - python3-charm-crypto + python3-pip RUN pip3 install -U \ pip \ @@ -23,6 +22,12 @@ RUN pip3 install -U \ virtualenv \ git+https://github.com/hyperledger/indy-anoncreds.git +RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BD33704C +RUN echo "deb https://repo.evernym.com/deb xenial master" >> /etc/apt/sources.list +RUN apt-get update -y +RUN apt-get install -y \ + python3-charm-crypto + ENV RUST_ARCHIVE=rust-1.16.0-x86_64-unknown-linux-gnu.tar.gz ENV RUST_DOWNLOAD_URL=https://static.rust-lang.org/dist/$RUST_ARCHIVE From 4faf9758e299017454e656d2a0fddaf3875d8ab6 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 18:55:45 +0300 Subject: [PATCH 139/349] small changes --- ci/ubuntu.dockerfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index ce70138cba..cd2fab7433 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -16,18 +16,18 @@ RUN apt-get update && \ python3.5 \ python3-pip -RUN pip3 install -U \ - pip \ - setuptools \ - virtualenv \ - git+https://github.com/hyperledger/indy-anoncreds.git - RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BD33704C RUN echo "deb https://repo.evernym.com/deb xenial master" >> /etc/apt/sources.list RUN apt-get update -y RUN apt-get install -y \ python3-charm-crypto +RUN pip3 install -U \ + pip \ + setuptools \ + virtualenv \ + git+https://github.com/hyperledger/indy-anoncreds.git + ENV RUST_ARCHIVE=rust-1.16.0-x86_64-unknown-linux-gnu.tar.gz ENV RUST_DOWNLOAD_URL=https://static.rust-lang.org/dist/$RUST_ARCHIVE From 59e5caf5c333e89966cc3b497a695c7d0f72b312 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 13 Jul 2017 19:02:23 +0300 Subject: [PATCH 140/349] added https transport --- ci/ubuntu.dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index cd2fab7433..aa5b4bd692 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -14,7 +14,10 @@ RUN apt-get update && \ cmake \ git \ python3.5 \ - python3-pip + python3-pip \ + python-setuptools \ + apt-transport-https \ + ca-certificates RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BD33704C RUN echo "deb https://repo.evernym.com/deb xenial master" >> /etc/apt/sources.list From 2cea160210174ee20916bf14a53c14fc97bb0c65 Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Thu, 13 Jul 2017 19:03:54 +0300 Subject: [PATCH 141/349] [java] Implement test for refresh and base test for close pool. --- .../indy/sdk/pool/ClosePoolTest.java | 24 +++++++++++++++++++ .../indy/sdk/pool/RefreshPoolTest.java | 23 ++++++++++++++++++ .../hyperledger/indy/sdk/utils/PoolUtils.java | 7 ++++++ 3 files changed, 54 insertions(+) create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/ClosePoolTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/RefreshPoolTest.java diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/ClosePoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/ClosePoolTest.java new file mode 100644 index 0000000000..59f1f5ea8c --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/ClosePoolTest.java @@ -0,0 +1,24 @@ +package org.hyperledger.indy.sdk.pool; + +import org.hyperledger.indy.sdk.IndyException; +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.junit.Test; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +import static org.junit.Assert.assertNotNull; + +public class ClosePoolTest extends IndyIntegrationTest { + + @Test + public void testClosePoolWorks() throws IndyException, ExecutionException, InterruptedException, IOException { + Pool pool = PoolUtils.createAndOpenPoolLedger(); + assertNotNull(pool); + openedPools.add(pool); + + pool.closePoolLedger().get(); + openedPools.remove(pool); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/RefreshPoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/RefreshPoolTest.java new file mode 100644 index 0000000000..6cdb837c77 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/RefreshPoolTest.java @@ -0,0 +1,23 @@ +package org.hyperledger.indy.sdk.pool; + +import org.hyperledger.indy.sdk.IndyException; +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.junit.Test; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +import static org.junit.Assert.assertNotNull; + +public class RefreshPoolTest extends IndyIntegrationTest { + + @Test + public void testRefreshPoolWorks() throws IndyException, ExecutionException, InterruptedException, IOException { + Pool pool = PoolUtils.createAndOpenPoolLedger(); + assertNotNull(pool); + openedPools.add(pool); + + pool.refreshPoolLedger().get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java index a90946b07e..cf6b09c4e3 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java @@ -55,4 +55,11 @@ public static void createPoolLedgerConfig(String poolName, int nodesCnt) throws = new PoolJSONParameters.CreatePoolLedgerConfigJSONParameter(genesisTxnFile.getAbsolutePath()); Pool.createPoolLedgerConfig(poolName, createPoolLedgerConfigJSONParameter.toJson()).get(); } + + public static Pool createAndOpenPoolLedger() throws IndyException, InterruptedException, ExecutionException, IOException { + String poolName = PoolUtils.createPoolLedgerConfig(); + + PoolJSONParameters.OpenPoolLedgerJSONParameter config = new PoolJSONParameters.OpenPoolLedgerJSONParameter(true, null, null); + return Pool.openPoolLedger(poolName, config.toJson()).get(); + } } From 40281afc1a5c9295eef58dd80920edaf384a544f Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Thu, 13 Jul 2017 19:20:36 +0300 Subject: [PATCH 142/349] [java] Add more tests for ClosePool. --- .../indy/sdk/pool/ClosePoolTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/ClosePoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/ClosePoolTest.java index 59f1f5ea8c..80a28a241d 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/ClosePoolTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/ClosePoolTest.java @@ -1,5 +1,7 @@ package org.hyperledger.indy.sdk.pool; +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyException; import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.utils.PoolUtils; @@ -21,4 +23,30 @@ public void testClosePoolWorks() throws IndyException, ExecutionException, Inter pool.closePoolLedger().get(); openedPools.remove(pool); } + + @Test + public void testClosePoolWorksForTwice() throws IndyException, ExecutionException, InterruptedException, IOException { + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.PoolLedgerInvalidPoolHandle)); + + Pool pool = PoolUtils.createAndOpenPoolLedger(); + assertNotNull(pool); + openedPools.add(pool); + + pool.closePoolLedger().get(); + openedPools.remove(pool); + pool.closePoolLedger().get(); + } + + @Test + public void testClosePoolWorksForReopenAfterClose() throws IndyException, ExecutionException, InterruptedException, IOException { + String poolName = PoolUtils.createPoolLedgerConfig(); + + Pool pool = Pool.openPoolLedger(poolName, null).get(); + assertNotNull(pool); + openedPools.add(pool); + + pool.closePoolLedger().get(); + + Pool.openPoolLedger(poolName, null).get(); + } } From 0f1dc1ab7935e33972ff9aa3df5d7b53efda7394 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 14 Jul 2017 08:35:40 +0300 Subject: [PATCH 143/349] Finished Signus integration tests for Java --- .../indy/sdk/signus/CreateMyDidTest.java | 4 +- .../indy/sdk/signus/ReplaceKeysTest.java | 4 +- .../hyperledger/indy/sdk/signus/SignTest.java | 4 +- .../indy/sdk/signus/StoreTheirDidTest.java | 4 +- .../indy/sdk/signus/VerifyTest.java | 68 ++++++++----------- .../indy/sdk/utils/StorageUtils.java | 2 +- 6 files changed, 39 insertions(+), 47 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java index 6a500d219c..246c7b48c4 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java @@ -22,8 +22,8 @@ public void createWallet() throws Exception { @After public void deleteWallet() throws Exception { - this.wallet.closeWallet(); - Wallet.deleteWallet("signusWallet", null); + this.wallet.closeWallet().get(); + Wallet.deleteWallet("signusWallet", null).get(); } private String seed = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/ReplaceKeysTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/ReplaceKeysTest.java index 112d740b0c..1a978c6696 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/ReplaceKeysTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/ReplaceKeysTest.java @@ -38,8 +38,8 @@ public void createWalletWithDid() throws Exception { @After public void deleteWallet() throws Exception { - wallet.closeWallet(); - Wallet.deleteWallet("signusWallet", null); + wallet.closeWallet().get(); + Wallet.deleteWallet("signusWallet", null).get(); } @Test diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java index dc38de5d3f..f20bce74f1 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java @@ -35,8 +35,8 @@ public void createWalletWhitDid() throws Exception { @After public void deleteWallet() throws Exception { - this.wallet.closeWallet(); - Wallet.deleteWallet("signusWallet", null); + this.wallet.closeWallet().get(); + Wallet.deleteWallet("signusWallet", null).get(); } @Test diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/StoreTheirDidTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/StoreTheirDidTest.java index 80edecccc8..6158454fc2 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/StoreTheirDidTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/StoreTheirDidTest.java @@ -25,8 +25,8 @@ public void createWallet() throws Exception { @After public void deleteWallet() throws Exception { - this.wallet.closeWallet(); - Wallet.deleteWallet("signusWallet", null); + this.wallet.closeWallet().get(); + Wallet.deleteWallet("signusWallet", null).get(); } @Test diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java index 98c80754af..a8a2a5ce2b 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java @@ -8,24 +8,19 @@ import org.hyperledger.indy.sdk.pool.PoolJSONParameters; import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; import org.hyperledger.indy.sdk.utils.PoolUtils; -import org.hyperledger.indy.sdk.utils.StorageUtils; import org.hyperledger.indy.sdk.wallet.Wallet; import org.junit.*; -import org.junit.rules.Timeout; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; public class VerifyTest extends IndyIntegrationTest { - - @Rule - public Timeout globalTimeout = new Timeout(3, TimeUnit.SECONDS); - + private Pool pool; private Wallet wallet; - private String trustee_did; - private String trustee_verkey; + private String trusteeDid; + private String trusteeVerkey; private String identityJson; + private String newDid; @Before public void createWalletWithDid() throws Exception { @@ -43,33 +38,32 @@ public void createWalletWithDid() throws Exception { CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(wallet, didJson.toJson()).get(); Assert.assertNotNull(result); - trustee_did = result.getDid(); - trustee_verkey = result.getVerkey(); + trusteeDid = result.getDid(); + trusteeVerkey = result.getVerkey(); } @After public void deleteWallet() throws Exception { - wallet.closeWallet(); - Wallet.deleteWallet("signusWallet", null); - pool.closePoolLedger(); + wallet.closeWallet().get(); + Wallet.deleteWallet("signusWallet", null).get(); + pool.closePoolLedger().get(); } - private String createNewNymWithDidInLedger() throws Exception{ + private void createNewNymWithDidInLedger() throws Exception{ SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(wallet, didJson.toJson()).get(); - String new_did = result.getDid(); - String new_verkey = result.getVerkey(); + newDid = result.getDid(); + String newVerkey = result.getVerkey(); - String nymRequest = Ledger.buildNymRequest(trustee_did, new_did, new_verkey, null, null).get(); - Ledger.signAndSubmitRequest(pool, wallet, trustee_did, nymRequest); - return new_did; + String nymRequest = Ledger.buildNymRequest(trusteeDid, newDid, newVerkey, null, null).get(); + Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); } @Test public void testVerifyWorksForVerkeyCachedInWallet() throws Exception { - identityJson = String.format("{\"did\":\"%s\",\"verkey\":\"%s\"}", trustee_did, trustee_verkey); + identityJson = String.format("{\"did\":\"%s\",\"verkey\":\"%s\"}", trusteeDid, trusteeVerkey); Signus.storeTheirDid(wallet, identityJson).get(); String msg = "{\n" + @@ -83,32 +77,30 @@ public void testVerifyWorksForVerkeyCachedInWallet() throws Exception { " \"signature\":\"65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW\"\n" + " }"; - Boolean valid = Signus.verifySignature(wallet, pool, trustee_did, msg).get(); + Boolean valid = Signus.verifySignature(wallet, pool, trusteeDid, msg).get(); Assert.assertTrue(valid); } @Test public void testVerifyWorksForGetVerkeyFromLedger() throws Exception { - String new_did = createNewNymWithDidInLedger(); - - identityJson = String.format("{\"did\":\"%s\"}", new_did); + createNewNymWithDidInLedger(); + identityJson = String.format("{\"did\":\"%s\"}", newDid); Signus.storeTheirDid(wallet, identityJson).get(); String msg = "{\"reqId\":1496822211362017764,\n" + "\"signature\":\"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai\"}"; - Boolean valid = Signus.verifySignature(wallet, pool, new_did, msg).get(); + Boolean valid = Signus.verifySignature(wallet, pool, newDid, msg).get(); Assert.assertTrue(valid); } @Test public void testVerifyWorksForGetNymFromLedger() throws Exception { - String new_did = createNewNymWithDidInLedger(); - - String msg = "{\"reqId\":1496822211362017764," + + createNewNymWithDidInLedger(); + String msg = "{\"reqId\":1496822211362017764,\n" + "\"signature\":\"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai\"}"; - Boolean valid = Signus.verifySignature(wallet, pool, new_did, msg).get(); + Boolean valid = Signus.verifySignature(wallet, pool, newDid, msg).get(); Assert.assertTrue(valid); } @@ -119,7 +111,7 @@ public void testVerifyWorksForInvalidMessageFormat() throws Exception { String msg = "\"signature\":\"65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW\""; - Signus.verifySignature(wallet, pool, trustee_did, msg).get(); + Signus.verifySignature(wallet, pool, trusteeDid, msg).get(); } @Test @@ -137,12 +129,12 @@ public void testVerifyWorksForMessageWithoutSignature() throws Exception { " },\n" + " }"; - Signus.verifySignature(wallet, pool, trustee_did, msg).get(); + Signus.verifySignature(wallet, pool, trusteeDid, msg).get(); } @Test public void testVerifyWorksForOtherSigner() throws Exception { - identityJson = String.format("{\"did\":\"%s\", \"verkey\":\"%s\"}", trustee_did, trustee_verkey); + identityJson = String.format("{\"did\":\"%s\", \"verkey\":\"%s\"}", trusteeDid, trusteeVerkey); Signus.storeTheirDid(wallet, identityJson).get(); @@ -150,10 +142,10 @@ public void testVerifyWorksForOtherSigner() throws Exception { new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Steward1", null, null); CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(wallet, didJson.toJson()).get(); - String other_did = result.getDid(); - String other_verkey = result.getVerkey(); + String stewardDid = result.getDid(); + String stewardVerkey = result.getVerkey(); - identityJson = String.format("{\"did\":\"%s\", \"verkey\":\"%s\"}", other_did, other_verkey); + identityJson = String.format("{\"did\":\"%s\", \"verkey\":\"%s\"}", stewardDid, stewardVerkey); Signus.storeTheirDid(wallet, identityJson).get(); @@ -167,9 +159,9 @@ public void testVerifyWorksForOtherSigner() throws Exception { " }\n" + " }"; - String signedMessage = Signus.sign(wallet, trustee_did, msg).get(); + String signedMessage = Signus.sign(wallet, trusteeDid, msg).get(); - Boolean valid = Signus.verifySignature(wallet, pool, other_did, signedMessage).get(); + Boolean valid = Signus.verifySignature(wallet, pool, stewardDid, signedMessage).get(); Assert.assertFalse(valid); } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java index 733331176d..e0cfc2fe75 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/StorageUtils.java @@ -9,7 +9,7 @@ public class StorageUtils { private static void cleanDirectory(File path) throws Exception { if (path.isDirectory()) { - FileUtils.deleteQuietly(path); + FileUtils.cleanDirectory(path); } } From 35e3cb25befb58dffb4ecda67072579046ab0f78 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 14 Jul 2017 09:04:11 +0300 Subject: [PATCH 144/349] Corrected import --- .../indy/sdk/signus/CreateMyDidTest.java | 38 +++++++++++-------- .../indy/sdk/signus/ReplaceKeysTest.java | 1 + .../hyperledger/indy/sdk/signus/SignTest.java | 3 +- .../indy/sdk/signus/StoreTheirDidTest.java | 2 +- .../indy/sdk/signus/VerifyTest.java | 22 +++++++---- 5 files changed, 39 insertions(+), 27 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java index 246c7b48c4..067bc4ee78 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java @@ -5,8 +5,14 @@ import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; import org.hyperledger.indy.sdk.wallet.Wallet; -import org.junit.*; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import org.bitcoinj.core.Base58; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import java.util.concurrent.ExecutionException; @@ -38,10 +44,10 @@ public void testCreateMyDidWorksForEmptyJson() throws Exception { new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, null, null); CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); - Assert.assertNotNull(result); + assertNotNull(result); - Assert.assertEquals(16, Base58.decode(result.getDid()).length); - Assert.assertEquals(32, Base58.decode(result.getVerkey()).length); + assertEquals(16, Base58.decode(result.getDid()).length); + assertEquals(32, Base58.decode(result.getVerkey()).length); } @Test @@ -51,10 +57,10 @@ public void testCreateMyDidWorksForSeed() throws Exception { new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, seed, null, null); CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); - Assert.assertNotNull(result); + assertNotNull(result); - Assert.assertEquals("NcYxiDXkpYi6ov5FcYDi1e", result.getDid()); - Assert.assertEquals(expectedVerkey, result.getVerkey()); + assertEquals("NcYxiDXkpYi6ov5FcYDi1e", result.getDid()); + assertEquals(expectedVerkey, result.getVerkey()); } @Test @@ -64,10 +70,10 @@ public void testCreateMyDidWorksAsCid() throws Exception { new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, seed, null, true); CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); - Assert.assertNotNull(result); + assertNotNull(result); - Assert.assertEquals(expectedVerkey, result.getDid()); - Assert.assertEquals(expectedVerkey, result.getVerkey()); + assertEquals(expectedVerkey, result.getDid()); + assertEquals(expectedVerkey, result.getVerkey()); } @Test @@ -77,9 +83,9 @@ public void testCreateMyDidWorksForPassedDid() throws Exception { new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(did, null, null, true); CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); - Assert.assertNotNull(result); + assertNotNull(result); - Assert.assertEquals(did, result.getDid()); + assertEquals(did, result.getDid()); } @Test @@ -89,7 +95,7 @@ public void testCreateMyDidWorksForCorrectCryptoType() throws Exception { new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, existsCryptoType, null); CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); - Assert.assertNotNull(result); + assertNotNull(result); } @Test @@ -123,9 +129,9 @@ public void testCreateMyDidWorksForAllParams() throws Exception { new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(did, seed, existsCryptoType, true); CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); - Assert.assertNotNull(result); + assertNotNull(result); - Assert.assertEquals(did, result.getDid()); - Assert.assertEquals(expectedVerkey, result.getVerkey()); + assertEquals(did, result.getDid()); + assertEquals(expectedVerkey, result.getVerkey()); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/ReplaceKeysTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/ReplaceKeysTest.java index 1a978c6696..03d732ad41 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/ReplaceKeysTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/ReplaceKeysTest.java @@ -6,6 +6,7 @@ import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; import org.hyperledger.indy.sdk.wallet.Wallet; + import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java index f20bce74f1..dc3cc7fd0a 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java @@ -4,9 +4,8 @@ import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; -import org.hyperledger.indy.sdk.utils.StorageUtils; import org.hyperledger.indy.sdk.wallet.Wallet; -import static org.junit.Assert.assertNotNull; + import static org.junit.Assert.assertTrue; import org.junit.After; diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/StoreTheirDidTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/StoreTheirDidTest.java index 6158454fc2..78fefd12b7 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/StoreTheirDidTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/StoreTheirDidTest.java @@ -44,7 +44,7 @@ public void testCreateMyDidWorksForInvalidIdentityJson() throws Exception { @Test public void testStoreTheirDidWorksWithVerkey() throws Exception { - Signus.storeTheirDid(this.wallet,"{\"did\":\"8wZcEriaNLNKtteJvx7f8i\", " + + Signus.storeTheirDid(this.wallet, "{\"did\":\"8wZcEriaNLNKtteJvx7f8i\", " + "\"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\"}").get(); } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java index a8a2a5ce2b..8d04f2a493 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java @@ -9,12 +9,18 @@ import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; import org.hyperledger.indy.sdk.utils.PoolUtils; import org.hyperledger.indy.sdk.wallet.Wallet; -import org.junit.*; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static junit.framework.TestCase.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.util.concurrent.ExecutionException; public class VerifyTest extends IndyIntegrationTest { - + private Pool pool; private Wallet wallet; private String trusteeDid; @@ -36,7 +42,7 @@ public void createWalletWithDid() throws Exception { new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, true); CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(wallet, didJson.toJson()).get(); - Assert.assertNotNull(result); + assertNotNull(result); trusteeDid = result.getDid(); trusteeVerkey = result.getVerkey(); @@ -49,7 +55,7 @@ public void deleteWallet() throws Exception { pool.closePoolLedger().get(); } - private void createNewNymWithDidInLedger() throws Exception{ + private void createNewNymWithDidInLedger() throws Exception { SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); @@ -78,7 +84,7 @@ public void testVerifyWorksForVerkeyCachedInWallet() throws Exception { " }"; Boolean valid = Signus.verifySignature(wallet, pool, trusteeDid, msg).get(); - Assert.assertTrue(valid); + assertTrue(valid); } @Test @@ -91,7 +97,7 @@ public void testVerifyWorksForGetVerkeyFromLedger() throws Exception { "\"signature\":\"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai\"}"; Boolean valid = Signus.verifySignature(wallet, pool, newDid, msg).get(); - Assert.assertTrue(valid); + assertTrue(valid); } @Test @@ -101,7 +107,7 @@ public void testVerifyWorksForGetNymFromLedger() throws Exception { "\"signature\":\"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai\"}"; Boolean valid = Signus.verifySignature(wallet, pool, newDid, msg).get(); - Assert.assertTrue(valid); + assertTrue(valid); } @Test @@ -163,6 +169,6 @@ public void testVerifyWorksForOtherSigner() throws Exception { Boolean valid = Signus.verifySignature(wallet, pool, stewardDid, signedMessage).get(); - Assert.assertFalse(valid); + assertFalse(valid); } } From 94b015462eb00eeb33dcd08f631cf2bd760d2d30 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 14 Jul 2017 10:21:11 +0300 Subject: [PATCH 145/349] added gmp --- ci/ubuntu.dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index aa5b4bd692..5548acdf1a 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -7,6 +7,7 @@ RUN apt-get update && \ pkg-config \ libzmq3-dev \ libssl-dev \ + libgmp3-dev \ curl \ build-essential \ libsqlite3-dev \ From 8b188320cffbd7feb5c2555d3ab5d1c875c67539 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 14 Jul 2017 10:33:23 +0300 Subject: [PATCH 146/349] added setup-charm.sh --- ci/ubuntu.dockerfile | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index 5548acdf1a..63573a5309 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -20,11 +20,11 @@ RUN apt-get update && \ apt-transport-https \ ca-certificates -RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BD33704C -RUN echo "deb https://repo.evernym.com/deb xenial master" >> /etc/apt/sources.list -RUN apt-get update -y -RUN apt-get install -y \ - python3-charm-crypto +#RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BD33704C +#RUN echo "deb https://repo.evernym.com/deb xenial master" >> /etc/apt/sources.list +#RUN apt-get update -y +#RUN apt-get install -y \ +# python3-charm-crypto RUN pip3 install -U \ pip \ @@ -55,9 +55,10 @@ WORKDIR /home/indy RUN git clone https://github.com/hyperledger/indy-anoncreds.git RUN virtualenv -p python3.5 /home/indy/ -RUN cp -r /usr/local/lib/python3.5/dist-packages/Charm_Crypto-0.0.0.egg-info /home/indy/lib/python3.5/site-packages/Charm_Crypto-0.0.0.egg-info -RUN cp -r /usr/local/lib/python3.5/dist-packages/charm /home/indy/lib/python3.5/site-packages/charm +#RUN cp -r /usr/local/lib/python3.5/dist-packages/Charm_Crypto-0.0.0.egg-info /home/indy/lib/python3.5/site-packages/Charm_Crypto-0.0.0.egg-info +#RUN cp -r /usr/local/lib/python3.5/dist-packages/charm /home/indy/lib/python3.5/site-packages/charm USER root +RUN /home/indy/indy-anoncreds/setup-charm.sh RUN ln -sf /home/indy/bin/python /usr/local/bin/python RUN ln -sf /home/indy/bin/pip /usr/local/bin/pip USER indy \ No newline at end of file From 1a7fea0c95b12282168e6d2f2f518578534bc557 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 14 Jul 2017 10:51:45 +0300 Subject: [PATCH 147/349] added plenum and anoncreds for indy-pool dockerfile --- ci/indy-pool.dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/indy-pool.dockerfile b/ci/indy-pool.dockerfile index f3ce4b8d52..e22967cb51 100644 --- a/ci/indy-pool.dockerfile +++ b/ci/indy-pool.dockerfile @@ -26,6 +26,8 @@ RUN echo "deb https://repo.sovrin.org/deb xenial master" >> /etc/apt/sources.lis RUN useradd -ms /bin/bash -u $uid sovrin RUN apt-get update -y && apt-get install -y \ + indy-plenum=0.4.43 \ + indy-anoncreds=0.4.12\ indy-node=0.4.26 RUN echo '[supervisord]\n\ From 7d7f3de545f7722b66645f41f268786da1ae7a93 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 14 Jul 2017 11:06:18 +0300 Subject: [PATCH 148/349] minor changes --- ci/ubuntu.dockerfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index 63573a5309..1f4c76b2e4 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -29,8 +29,7 @@ RUN apt-get update && \ RUN pip3 install -U \ pip \ setuptools \ - virtualenv \ - git+https://github.com/hyperledger/indy-anoncreds.git + virtualenv ENV RUST_ARCHIVE=rust-1.16.0-x86_64-unknown-linux-gnu.tar.gz ENV RUST_DOWNLOAD_URL=https://static.rust-lang.org/dist/$RUST_ARCHIVE @@ -59,6 +58,10 @@ RUN virtualenv -p python3.5 /home/indy/ #RUN cp -r /usr/local/lib/python3.5/dist-packages/charm /home/indy/lib/python3.5/site-packages/charm USER root RUN /home/indy/indy-anoncreds/setup-charm.sh + +RUN pip3 install -U \ + git+https://github.com/hyperledger/indy-anoncreds.git + RUN ln -sf /home/indy/bin/python /usr/local/bin/python RUN ln -sf /home/indy/bin/pip /usr/local/bin/pip USER indy \ No newline at end of file From 0b0955186b8a2e2d512af800828eed0e24f2d1d7 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 14 Jul 2017 11:12:18 +0300 Subject: [PATCH 149/349] small changes --- ci/ubuntu.dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index 1f4c76b2e4..599bb0638a 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -57,11 +57,11 @@ RUN virtualenv -p python3.5 /home/indy/ #RUN cp -r /usr/local/lib/python3.5/dist-packages/Charm_Crypto-0.0.0.egg-info /home/indy/lib/python3.5/site-packages/Charm_Crypto-0.0.0.egg-info #RUN cp -r /usr/local/lib/python3.5/dist-packages/charm /home/indy/lib/python3.5/site-packages/charm USER root -RUN /home/indy/indy-anoncreds/setup-charm.sh +RUN ./home/indy/indy-anoncreds/setup-charm.sh RUN pip3 install -U \ git+https://github.com/hyperledger/indy-anoncreds.git - + RUN ln -sf /home/indy/bin/python /usr/local/bin/python RUN ln -sf /home/indy/bin/pip /usr/local/bin/pip USER indy \ No newline at end of file From 513a202f2f3098ef72e645b0a1e49c8333dbe818 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 14 Jul 2017 11:21:19 +0300 Subject: [PATCH 150/349] minor changes --- ci/ubuntu.dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index 599bb0638a..29d799a846 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -57,7 +57,7 @@ RUN virtualenv -p python3.5 /home/indy/ #RUN cp -r /usr/local/lib/python3.5/dist-packages/Charm_Crypto-0.0.0.egg-info /home/indy/lib/python3.5/site-packages/Charm_Crypto-0.0.0.egg-info #RUN cp -r /usr/local/lib/python3.5/dist-packages/charm /home/indy/lib/python3.5/site-packages/charm USER root -RUN ./home/indy/indy-anoncreds/setup-charm.sh +RUN source /home/indy/indy-anoncreds/setup-charm.sh RUN pip3 install -U \ git+https://github.com/hyperledger/indy-anoncreds.git From 5a791f38fa2343a0be3316d0b4e09807a2ba4f63 Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Fri, 14 Jul 2017 11:22:13 +0300 Subject: [PATCH 151/349] Update indy-pool.dockerfile Update to indy-node 0.4.29 --- ci/indy-pool.dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ci/indy-pool.dockerfile b/ci/indy-pool.dockerfile index f3ce4b8d52..2fd7890777 100644 --- a/ci/indy-pool.dockerfile +++ b/ci/indy-pool.dockerfile @@ -26,7 +26,9 @@ RUN echo "deb https://repo.sovrin.org/deb xenial master" >> /etc/apt/sources.lis RUN useradd -ms /bin/bash -u $uid sovrin RUN apt-get update -y && apt-get install -y \ - indy-node=0.4.26 + indy-plenum=0.4.44 \ + indy-anoncreds=0.4.12 \ + indy-node=0.4.29 RUN echo '[supervisord]\n\ logfile = /tmp/supervisord.log\n\ From 39186c93dc3c8d6ea8b6c2103815052585645e1f Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 14 Jul 2017 11:26:17 +0300 Subject: [PATCH 152/349] small changes --- ci/ubuntu.dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index 29d799a846..7a59fa8707 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -57,7 +57,7 @@ RUN virtualenv -p python3.5 /home/indy/ #RUN cp -r /usr/local/lib/python3.5/dist-packages/Charm_Crypto-0.0.0.egg-info /home/indy/lib/python3.5/site-packages/Charm_Crypto-0.0.0.egg-info #RUN cp -r /usr/local/lib/python3.5/dist-packages/charm /home/indy/lib/python3.5/site-packages/charm USER root -RUN source /home/indy/indy-anoncreds/setup-charm.sh +RUN /bin/bash /home/indy/indy-anoncreds/setup-charm.sh RUN pip3 install -U \ git+https://github.com/hyperledger/indy-anoncreds.git From 0a322fdf7838efe7ed544179ed7ddb2da7d55faf Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 14 Jul 2017 11:33:22 +0300 Subject: [PATCH 153/349] small changes --- ci/ubuntu.dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index 7a59fa8707..087b3eac51 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -56,8 +56,8 @@ RUN git clone https://github.com/hyperledger/indy-anoncreds.git RUN virtualenv -p python3.5 /home/indy/ #RUN cp -r /usr/local/lib/python3.5/dist-packages/Charm_Crypto-0.0.0.egg-info /home/indy/lib/python3.5/site-packages/Charm_Crypto-0.0.0.egg-info #RUN cp -r /usr/local/lib/python3.5/dist-packages/charm /home/indy/lib/python3.5/site-packages/charm -USER root RUN /bin/bash /home/indy/indy-anoncreds/setup-charm.sh +USER root RUN pip3 install -U \ git+https://github.com/hyperledger/indy-anoncreds.git From 4d5bd3e626515145a8b1a433b13e96fc53845029 Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Fri, 14 Jul 2017 11:38:36 +0300 Subject: [PATCH 154/349] [java] Update genesis transactions. --- .../java/org/hyperledger/indy/sdk/utils/PoolUtils.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java index cf6b09c4e3..91af2fbd97 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java @@ -18,10 +18,10 @@ public static File createGenesisTxnFile(String filename) throws IOException { public static File createGenesisTxnFile(String filename, int nodesCnt) throws IOException { String path = StorageUtils.getTmpPath(filename); String[] defaultTxns = new String[]{ - "{\"data\":{\"alias\":\"Node1\",\"client_ip\":\"10.0.0.2\",\"client_port\":9702,\"node_ip\":\"10.0.0.2\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\",\"identifier\":\"FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4\",\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\",\"type\":\"0\"}", - "{\"data\":{\"alias\":\"Node2\",\"client_ip\":\"10.0.0.2\",\"client_port\":9704,\"node_ip\":\"10.0.0.2\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\",\"identifier\":\"8QhFxKxyaFsJy4CyxeYX34dFH8oWqyBv1P4HLQCsoeLy\",\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\",\"type\":\"0\"}", - "{\"data\":{\"alias\":\"Node3\",\"client_ip\":\"10.0.0.2\",\"client_port\":9706,\"node_ip\":\"10.0.0.2\",\"node_port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\",\"identifier\":\"2yAeV5ftuasWNgQwVYzeHeTuM7LwwNtPR3Zg9N4JiDgF\",\"txnId\":\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\",\"type\":\"0\"}", - "{\"data\":{\"alias\":\"Node4\",\"client_ip\":\"10.0.0.2\",\"client_port\":9708,\"node_ip\":\"10.0.0.2\",\"node_port\":9707,\"services\":[\"VALIDATOR\"]},\"dest\":\"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA\",\"identifier\":\"FTE95CVthRtrBnK2PYCBbC9LghTcGwi9Zfi1Gz2dnyNx\",\"txnId\":\"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008\",\"type\":\"0\"}" + "{\"data\":{\"alias\":\"Node1\",\"client_ip\":\"10.0.0.2\",\"client_port\":9702,\"node_ip\":\"10.0.0.2\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\",\"identifier\":\"Th7MpTaRZVRYnPiabds81Y\",\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\",\"type\":\"0\"}", + "{\"data\":{\"alias\":\"Node2\",\"client_ip\":\"10.0.0.2\",\"client_port\":9704,\"node_ip\":\"10.0.0.2\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\",\"identifier\":\"EbP4aYNeTHL6q385GuVpRV\",\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\",\"type\":\"0\"}", + "{\"data\":{\"alias\":\"Node3\",\"client_ip\":\"10.0.0.2\",\"client_port\":9706,\"node_ip\":\"10.0.0.2\",\"node_port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\",\"identifier\":\"4cU41vWW82ArfxJxHkzXPG\",\"txnId\":\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\",\"type\":\"0\"}", + "{\"data\":{\"alias\":\"Node4\",\"client_ip\":\"10.0.0.2\",\"client_port\":9708,\"node_ip\":\"10.0.0.2\",\"node_port\":9707,\"services\":[\"VALIDATOR\"]},\"dest\":\"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA\",\"identifier\":\"TWwCRQRZ2ZHMJFn9TzLp7W\",\"txnId\":\"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008\",\"type\":\"0\"}" }; File file = new File(path); From a5a92b3a91a9818bcd902bfc78f0cce07c1bba25 Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Fri, 14 Jul 2017 11:41:59 +0300 Subject: [PATCH 155/349] [java] Update Pool Open and Close tests. --- .../java/org/hyperledger/indy/sdk/pool/ClosePoolTest.java | 4 ++-- .../java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/ClosePoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/ClosePoolTest.java index 80a28a241d..688bb710bd 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/ClosePoolTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/ClosePoolTest.java @@ -43,10 +43,10 @@ public void testClosePoolWorksForReopenAfterClose() throws IndyException, Execut Pool pool = Pool.openPoolLedger(poolName, null).get(); assertNotNull(pool); - openedPools.add(pool); pool.closePoolLedger().get(); - Pool.openPoolLedger(poolName, null).get(); + pool = Pool.openPoolLedger(poolName, null).get(); + openedPools.add(pool); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java index c4084da718..20cae4b4a9 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/OpenPoolTest.java @@ -38,9 +38,9 @@ public void testOpenPoolWorksForTwice() throws Exception { String poolName = PoolUtils.createPoolLedgerConfig(); - Pool pool1 = Pool.openPoolLedger(poolName, null).get(); - assertNotNull(pool1); - openedPools.add(pool1); + Pool pool = Pool.openPoolLedger(poolName, null).get(); + assertNotNull(pool); + openedPools.add(pool); Pool.openPoolLedger(poolName, null).get(); } From f66ca11dc9d7a80b6b8707d72bfc1c3c6aab0934 Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Fri, 14 Jul 2017 11:42:30 +0300 Subject: [PATCH 156/349] [java] Add DeletePoolTest. --- .../indy/sdk/pool/DeletePoolTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/DeletePoolTest.java diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/DeletePoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/DeletePoolTest.java new file mode 100644 index 0000000000..fa7df7151c --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/DeletePoolTest.java @@ -0,0 +1,33 @@ +package org.hyperledger.indy.sdk.pool; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.IndyException; +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.junit.Test; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +import static org.junit.Assert.assertNotNull; + +public class DeletePoolTest extends IndyIntegrationTest { + + @Test + public void testDeletePoolWorks() throws InterruptedException, ExecutionException, IndyException, IOException { + String poolName = PoolUtils.createPoolLedgerConfig(); + Pool.deletePoolLedgerConfig(poolName).get(); + } + + @Test + public void testDeletePoolWorksForOpened() throws InterruptedException, ExecutionException, IndyException, IOException { + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidState)); + + String poolName = PoolUtils.createPoolLedgerConfig(); + Pool pool = Pool.openPoolLedger(poolName, null).get(); + assertNotNull(pool); + openedPools.add(pool); + Pool.deletePoolLedgerConfig(poolName).get(); + } +} From f3503e195df1be181035d86cb8e2145294ee7194 Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Fri, 14 Jul 2017 12:04:35 +0300 Subject: [PATCH 157/349] [java] Change pool tests signature to throws Exception. --- .../org/hyperledger/indy/sdk/pool/ClosePoolTest.java | 10 +++------- .../org/hyperledger/indy/sdk/pool/DeletePoolTest.java | 8 ++------ .../org/hyperledger/indy/sdk/pool/RefreshPoolTest.java | 6 +----- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/ClosePoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/ClosePoolTest.java index 688bb710bd..cceb3a8750 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/ClosePoolTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/ClosePoolTest.java @@ -2,20 +2,16 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; -import org.hyperledger.indy.sdk.IndyException; import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.utils.PoolUtils; import org.junit.Test; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - import static org.junit.Assert.assertNotNull; public class ClosePoolTest extends IndyIntegrationTest { @Test - public void testClosePoolWorks() throws IndyException, ExecutionException, InterruptedException, IOException { + public void testClosePoolWorks() throws Exception { Pool pool = PoolUtils.createAndOpenPoolLedger(); assertNotNull(pool); openedPools.add(pool); @@ -25,7 +21,7 @@ public void testClosePoolWorks() throws IndyException, ExecutionException, Inter } @Test - public void testClosePoolWorksForTwice() throws IndyException, ExecutionException, InterruptedException, IOException { + public void testClosePoolWorksForTwice() throws Exception { thrown.expectCause(new ErrorCodeMatcher(ErrorCode.PoolLedgerInvalidPoolHandle)); Pool pool = PoolUtils.createAndOpenPoolLedger(); @@ -38,7 +34,7 @@ public void testClosePoolWorksForTwice() throws IndyException, ExecutionExceptio } @Test - public void testClosePoolWorksForReopenAfterClose() throws IndyException, ExecutionException, InterruptedException, IOException { + public void testClosePoolWorksForReopenAfterClose() throws Exception { String poolName = PoolUtils.createPoolLedgerConfig(); Pool pool = Pool.openPoolLedger(poolName, null).get(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/DeletePoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/DeletePoolTest.java index fa7df7151c..a2fd14aba3 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/DeletePoolTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/DeletePoolTest.java @@ -2,26 +2,22 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; -import org.hyperledger.indy.sdk.IndyException; import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.utils.PoolUtils; import org.junit.Test; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - import static org.junit.Assert.assertNotNull; public class DeletePoolTest extends IndyIntegrationTest { @Test - public void testDeletePoolWorks() throws InterruptedException, ExecutionException, IndyException, IOException { + public void testDeletePoolWorks() throws Exception { String poolName = PoolUtils.createPoolLedgerConfig(); Pool.deletePoolLedgerConfig(poolName).get(); } @Test - public void testDeletePoolWorksForOpened() throws InterruptedException, ExecutionException, IndyException, IOException { + public void testDeletePoolWorksForOpened() throws Exception { thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidState)); String poolName = PoolUtils.createPoolLedgerConfig(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/RefreshPoolTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/RefreshPoolTest.java index 6cdb837c77..645d7938cf 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/RefreshPoolTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/pool/RefreshPoolTest.java @@ -1,19 +1,15 @@ package org.hyperledger.indy.sdk.pool; -import org.hyperledger.indy.sdk.IndyException; import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.utils.PoolUtils; import org.junit.Test; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - import static org.junit.Assert.assertNotNull; public class RefreshPoolTest extends IndyIntegrationTest { @Test - public void testRefreshPoolWorks() throws IndyException, ExecutionException, InterruptedException, IOException { + public void testRefreshPoolWorks() throws Exception { Pool pool = PoolUtils.createAndOpenPoolLedger(); assertNotNull(pool); openedPools.add(pool); From e844282069563ba2dda9a028fd3c46863c8982f0 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 14 Jul 2017 12:22:22 +0300 Subject: [PATCH 158/349] Implemented Indy Demo tests for Java wrapper --- .../org/hyperledger/indy/sdk/LibIndy.java | 2 +- .../indy/sdk/anoncreds/Anoncreds.java | 224 +++++++++++++++++- .../indy/sdk/demo/AnoncredsDemoTest.java | 162 +++++++++++++ .../indy/sdk/demo/LedgerDemoTest.java | 79 ++++++ .../indy/sdk/demo/SignusDemoTest.java | 87 +++++++ 5 files changed, 551 insertions(+), 3 deletions(-) create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/LedgerDemoTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/SignusDemoTest.java diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java index c611243cdb..162c5dc2ef 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java @@ -72,7 +72,7 @@ public interface API extends Library { public int indy_prover_get_claims(int command_handle, int wallet_handle, String filter_json, Callback cb); public int indy_prover_get_claims_for_proof_req(int command_handle, int wallet_handle, String proof_request_json, Callback cb); public int indy_prover_create_proof(int command_handle, int wallet_handle, String proof_req_json, String requested_claims_json, String schemas_json, String master_secret_name, String claim_defs_json, String revoc_regs_json, Callback cb); - public int indy_verifier_verify_proof(int command_handle, int wallet_handle, String proof_request_json, String proof_json, String schemas_json, String claim_defs_jsons, String revoc_regs_json, Callback cb); + public int indy_verifier_verify_proof(int command_handle, String proof_request_json, String proof_json, String schemas_json, String claim_defs_jsons, String revoc_regs_json, Callback cb); // agent.rs diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java index 448ae38649..5d8930236d 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java @@ -91,16 +91,96 @@ public void callback(int xcommand_handle, int err) { private static Callback proverGetClaimOffersCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String claim_offers_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (!checkCallback(future, err)) return; String result = claim_offers_json; future.complete(result); } }; + + private static Callback proverCreateMasterSecretCb = new Callback() { + + @SuppressWarnings({"unused", "unchecked"}) + public void callback(int xcommand_handle, int err) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (!checkCallback(future, err)) return; + + Void result = null; + future.complete(result); + } + }; + + private static Callback proverCreateClaimReqCb = new Callback() { + + @SuppressWarnings({"unused", "unchecked"}) + public void callback(int xcommand_handle, int err, String claim_req_json) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (!checkCallback(future, err)) return; + + String result = claim_req_json; + future.complete(result); + } + }; + + private static Callback proverStoreClaimCb = new Callback() { + + @SuppressWarnings({"unused", "unchecked"}) + public void callback(int xcommand_handle, int err) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (!checkCallback(future, err)) return; + + Void result = null; + future.complete(result); + } + }; + + private static Callback proverGetClaimsForProofReqCb = new Callback() { + + @SuppressWarnings({"unused", "unchecked"}) + public void callback(int xcommand_handle, int err, String claimsJson) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (!checkCallback(future, err)) return; + + String result = claimsJson; + future.complete(result); + } + }; + + private static Callback proverCreateProofCb = new Callback() { + + @SuppressWarnings({"unused", "unchecked"}) + public void callback(int xcommand_handle, int err, String proofJson) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (!checkCallback(future, err)) return; + + String result = proofJson; + future.complete(result); + } + }; + + private static Callback verifierVerifyProofCb = new Callback() { + + @SuppressWarnings({"unused", "unchecked"}) + public void callback(int xcommand_handle, int err, Boolean valid) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (!checkCallback(future, err)) return; + + Boolean result = valid; + future.complete(result); + } + }; + + /* * STATIC METHODS @@ -243,4 +323,144 @@ public static CompletableFuture proverGetClaimOffers( return future; } + + public static CompletableFuture proverCretaMasterSecret( + Wallet wallet, + String masterSecretName) throws IndyException { + + CompletableFuture future = new CompletableFuture(); + int commandHandle = addFuture(future); + + int walletHandle = wallet.getWalletHandle(); + + int result = LibIndy.api.indy_prover_create_master_secret( + commandHandle, + walletHandle, + masterSecretName, + proverCreateMasterSecretCb); + + checkResult(result); + + return future; + } + + public static CompletableFuture proverCreateClaimReq( + Wallet wallet, + String proverDid, + String claimOfferJson, + String claimDefJson, + String masterSecretName) throws IndyException { + + CompletableFuture future = new CompletableFuture(); + int commandHandle = addFuture(future); + + int walletHandle = wallet.getWalletHandle(); + + int result = LibIndy.api.indy_prover_create_and_store_claim_req( + commandHandle, + walletHandle, + proverDid, + claimOfferJson, + claimDefJson, + masterSecretName, + proverCreateClaimReqCb); + + checkResult(result); + + return future; + } + + public static CompletableFuture proverStoreClaim( + Wallet wallet, + String claim) throws IndyException { + + CompletableFuture future = new CompletableFuture(); + int commandHandle = addFuture(future); + + int walletHandle = wallet.getWalletHandle(); + + int result = LibIndy.api.indy_prover_store_claim( + commandHandle, + walletHandle, + claim, + proverStoreClaimCb); + + checkResult(result); + + return future; + } + + public static CompletableFuture proverGetClaimsForProofReq( + Wallet wallet, + String proofRequest) throws IndyException { + + CompletableFuture future = new CompletableFuture(); + int commandHandle = addFuture(future); + + int walletHandle = wallet.getWalletHandle(); + + int result = LibIndy.api.indy_prover_get_claims_for_proof_req( + commandHandle, + walletHandle, + proofRequest, + proverGetClaimsForProofReqCb); + + checkResult(result); + + return future; + } + + public static CompletableFuture proverCreateProof( + Wallet wallet, + String proofRequest, + String requestedClaims, + String schemas, + String masterSecret, + String claimDefs, + String revocRegs) throws IndyException { + + CompletableFuture future = new CompletableFuture(); + int commandHandle = addFuture(future); + + int walletHandle = wallet.getWalletHandle(); + + int result = LibIndy.api.indy_prover_create_proof( + commandHandle, + walletHandle, + proofRequest, + requestedClaims, + schemas, + masterSecret, + claimDefs, + revocRegs, + proverCreateProofCb); + + checkResult(result); + + return future; + } + + public static CompletableFuture verifierVerifyProof( + String proofRequest, + String proof, + String schemas, + String claimDefs, + String revocRegs) throws IndyException { + + CompletableFuture future = new CompletableFuture(); + int commandHandle = addFuture(future); + + int result = LibIndy.api.indy_verifier_verify_proof( + commandHandle, + proofRequest, + proof, + schemas, + claimDefs, + revocRegs, + verifierVerifyProofCb); + + checkResult(result); + + return future; + } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java new file mode 100644 index 0000000000..f991221eb7 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java @@ -0,0 +1,162 @@ +package org.hyperledger.indy.sdk.demo; + +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.anoncreds.Anoncreds; +import org.hyperledger.indy.sdk.anoncreds.AnoncredsResults; +import org.hyperledger.indy.sdk.pool.Pool; +import org.hyperledger.indy.sdk.pool.PoolJSONParameters; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.Timeout; + +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; + +public class AnoncredsDemoTest extends IndyIntegrationTest { + + @Rule + public Timeout globalTimeout = new Timeout(1, TimeUnit.MINUTES); + + @Test + public void testAnoncredsDemo() throws Exception { + + //1. Create and Open Pool + String poolName = PoolUtils.createPoolLedgerConfig(); + + PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); + Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); + + //2. Issuer Create and Open Wallet + Wallet.createWallet(poolName, "issuerWallet", "default", null, null).get(); + Wallet issuerWallet = Wallet.openWallet("issuerWallet", null, null).get(); + + //3. Prover Create and Open Wallet + Wallet.createWallet(poolName, "proverWallet", "default", null, null).get(); + Wallet proverWallet = Wallet.openWallet("proverWallet", null, null).get(); + + //4. Issuer create ClaimDef + String schemaJson = "{\n" + + " \"seqNo\":1,\n" + + " \"data\": {\n" + + " \"name\":\"gvt\",\n" + + " \"version\":\"1.0\",\n" + + " \"keys\":[\"age\",\"sex\",\"height\",\"name\"]\n" + + " }\n" + + " }"; + String issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; + + String claimDef = Anoncreds.issuerCreateAndStoreClaimDef(issuerWallet, issuerDid, schemaJson, null, false).get(); + assertNotNull(claimDef); + + //5. Prover create Master Secret + String masterSecret = "masterSecretName"; + Anoncreds.proverCretaMasterSecret(proverWallet, masterSecret).get(); + + //6. Prover store Claim Offer + String claimOffer = String.format("{\"issuer_did\":\"%s\", \"schema_seq_no\":%d}", issuerDid, 1); + Anoncreds.proverStoreClaimOffer(proverWallet, claimOffer).get(); + + //7. Prover get Claim Offers + String claimOfferFilter = String.format("{\"issuer_did\":\"%s\"}", issuerDid); + String claimOffersJson = Anoncreds.proverGetClaimOffers(proverWallet, claimOfferFilter).get(); + + JSONArray claimOffersObject = new JSONArray(claimOffersJson); + assertEquals(claimOffersObject.length(), 1); + + JSONObject claimOfferObject = claimOffersObject.getJSONObject(0); + String claimOfferJson = claimOfferObject.toString(); + + //8. Prover create ClaimReq + String proverDid = "BzfFCYk"; + String claimReq = Anoncreds.proverCreateClaimReq(proverWallet, proverDid, claimOfferJson, claimDef, masterSecret).get(); + assertNotNull(claimReq); + + //9. Issuer create Claim + String claimAttributesJson = "{\n" + + " \"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" + + " \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" + + " \"height\":[\"175\",\"175\"],\n" + + " \"age\":[\"28\",\"28\"]\n" + + " }"; + + AnoncredsResults.IssuerCreateClaimResult createClaimResult = Anoncreds.issuerCreateClaim(issuerWallet, claimReq, claimAttributesJson, -1, -1).get(); + assertNotNull(createClaimResult); + String claimJson = createClaimResult.getClaimJson(); + + //10. Prover store Claim + Anoncreds.proverStoreClaim(proverWallet, claimJson).get(); + + //11. Prover gets Claims for Proof Request + String proofRequestJson = "{\n" + + " \"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1,\"name\":\"name\"},\n" + + " \"attr2_uuid\":{\"schema_seq_no\":1,\"name\":\"sex\"}},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}\n" + + " }"; + + String claimsForProofJson = Anoncreds.proverGetClaimsForProofReq(proverWallet, proofRequestJson).get(); + assertNotNull(claimsForProofJson); + + JSONObject claimsForProof = new JSONObject(claimsForProofJson); + JSONArray claimsForAttribute1 = claimsForProof.getJSONObject("attrs").getJSONArray("attr1_uuid"); + JSONArray claimsForAttribute2 = claimsForProof.getJSONObject("attrs").getJSONArray("attr1_uuid"); + JSONArray claimsForPredicate = claimsForProof.getJSONObject("predicates").getJSONArray("predicate1_uuid"); + + assertEquals(claimsForAttribute1.length(), 1); + assertEquals(claimsForAttribute2.length(), 1); + assertEquals(claimsForPredicate.length(), 1); + + String claimUuid = claimsForAttribute1.getJSONObject(0).getString("claim_uuid"); + + //12. Prover create Proof + String selfAttestedValue = "yes"; + String requestedClaimsJson = String.format("{\n" + + " \"self_attested_attributes\":{\"self1\":\"%s\"},\n" + + " \"requested_attrs\":{\"attr1_uuid\":[\"%s\", true],\n" + + " \"attr2_uuid\":[\"%s\", false]},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":\"%s\"}\n" + + " }", selfAttestedValue, claimUuid, claimUuid, claimUuid); + + String schemasJson = String.format("{\"%s\":%s}", claimUuid, schemaJson); + String claimDefsJson = String.format("{\"%s\":%s}", claimUuid, claimDef); + String revocRegsJson = "{}"; + + + String proofJson = Anoncreds.proverCreateProof(proverWallet, proofRequestJson, requestedClaimsJson, schemasJson, + masterSecret, claimDefsJson, revocRegsJson).get(); + assertNotNull(proofJson); + + JSONObject proof = new JSONObject(proofJson); + + //13. Verifier verify Proof + assertEquals("Alex", + proof.getJSONObject("requested_proof").getJSONObject("revealed_attrs").getJSONArray("attr1_uuid").getString(1)); + + assertNotNull(proof.getJSONObject("requested_proof").getJSONObject("unrevealed_attrs").getString("attr2_uuid")); + + assertEquals(selfAttestedValue, proof.getJSONObject("requested_proof").getJSONObject("self_attested_attrs").getString("self1")); + + Boolean valid = Anoncreds.verifierVerifyProof(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson).get(); + assertTrue(valid); + + // 14. Close and delete My Wallet + issuerWallet.closeWallet().get(); + Wallet.deleteWallet("issuerWallet", null).get(); + + // 15. Close and delete Their Wallet + proverWallet.closeWallet().get(); + Wallet.deleteWallet("proverWallet", null).get(); + + //16. Close Pool + pool.closePoolLedger().get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/LedgerDemoTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/LedgerDemoTest.java new file mode 100644 index 0000000000..0c666bf388 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/LedgerDemoTest.java @@ -0,0 +1,79 @@ +package org.hyperledger.indy.sdk.demo; + +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.ledger.Ledger; +import org.hyperledger.indy.sdk.pool.Pool; +import org.hyperledger.indy.sdk.pool.PoolJSONParameters; +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusJSONParameters; +import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.json.JSONObject; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class LedgerDemoTest extends IndyIntegrationTest { + + @Test + public void testLedgerDemo() throws Exception { + + // 1. Create ledger config from genesis txn file + String poolName = PoolUtils.createPoolLedgerConfig(); + PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); + + // 2. Open pool ledger + Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); + + // 3. Create and Open My Wallet + Wallet.createWallet(poolName, "myWallet", "default", null, null).get(); + Wallet myWallet = Wallet.openWallet("myWallet", null, null).get(); + + // 4. Create and Open Trustee Wallet + Wallet.createWallet(poolName, "theirWallet", "default", null, null).get(); + Wallet trusteeWallet = Wallet.openWallet("theirWallet", null, null).get(); + + // 5. Create My Did + SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, null, true); + + CreateAndStoreMyDidResult createMyDidResult = Signus.createAndStoreMyDid(myWallet, myDidJson.toJson()).get(); + assertNotNull(createMyDidResult); + String myDid = createMyDidResult.getDid(); + String myVerkey = createMyDidResult.getDid(); + + // 6. Create Did from Trustee1 seed + SignusJSONParameters.CreateAndStoreMyDidJSONParameter theirDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, true); + + CreateAndStoreMyDidResult createTheirDidResult = Signus.createAndStoreMyDid(trusteeWallet, theirDidJson.toJson()).get(); + assertNotNull(createTheirDidResult); + String trusteeDid = createTheirDidResult.getDid(); + + // 7. Build Nym Request + String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, myVerkey, null, null).get(); + assertNotNull(nymRequest); + + // 8. Trustee Sign Nym Request + String nymResponseJson = Ledger.signAndSubmitRequest(pool, trusteeWallet, trusteeDid, nymRequest).get(); + assertNotNull(nymResponseJson); + + JSONObject nymResponse = new JSONObject(nymResponseJson); + + assertEquals(myDid, nymResponse.getJSONObject("result").getString("dest")); + assertEquals(myVerkey, nymResponse.getJSONObject("result").getString("verkey")); + + // 9. Close and delete My Wallet + myWallet.closeWallet().get(); + Wallet.deleteWallet("myWallet", null).get(); + + // 10. Close and delete Their Wallet + trusteeWallet.closeWallet().get(); + Wallet.deleteWallet("theirWallet", null).get(); + + // 11. Close Pool + pool.closePoolLedger().get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/SignusDemoTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/SignusDemoTest.java new file mode 100644 index 0000000000..e3e34c5876 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/SignusDemoTest.java @@ -0,0 +1,87 @@ +package org.hyperledger.indy.sdk.demo; + +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.pool.Pool; +import org.hyperledger.indy.sdk.pool.PoolJSONParameters; +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusJSONParameters; +import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.hyperledger.indy.sdk.wallet.Wallet; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.Timeout; + +import java.util.concurrent.TimeUnit; + +public class SignusDemoTest extends IndyIntegrationTest { + + @Test + public void testSignusDemo() throws Exception { + + //1. Create and Open Pool + String poolName = PoolUtils.createPoolLedgerConfig(); + + PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); + Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); + + //2. Create and Open My Wallet + Wallet.createWallet(poolName, "myWallet", "default", null, null).get(); + Wallet myWallet = Wallet.openWallet("myWallet", null, null).get(); + + //3. Create and Open Their Wallet + Wallet.createWallet(poolName, "theirWallet", "default", null, null).get(); + Wallet theirWallet = Wallet.openWallet("theirWallet", null, null).get(); + + //4. Create My Did + SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, null, true); + + CreateAndStoreMyDidResult createMyDidResult = Signus.createAndStoreMyDid(myWallet, myDidJson.toJson()).get(); + assertNotNull(createMyDidResult); + + //5. Create Their Did + SignusJSONParameters.CreateAndStoreMyDidJSONParameter theirDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, null, true); + + CreateAndStoreMyDidResult createTheirDidResult = Signus.createAndStoreMyDid(theirWallet, theirDidJson.toJson()).get(); + assertNotNull(createTheirDidResult); + String theirDid = createTheirDidResult.getDid(); + String theirVerkey = createTheirDidResult.getVerkey(); + + // 6. Store Their DID + String identityJson = String.format("{\"did\":\"%s\", \"verkey\":\"%s\"}", theirDid, theirVerkey); + Signus.storeTheirDid(myWallet, identityJson).get(); + + // 7. Their sign message + String msg = "{\n" + + " \"reqId\":1495034346617224651,\n" + + " \"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\",\n" + + " \"operation\":{\n" + + " \"type\":\"1\",\n" + + " \"dest\":\"4efZu2SXufS556yss7W5k6Po37jt4371RM4whbPKBKdB\"\n" + + " }\n" + + " }"; + + String signedMessage = Signus.sign(theirWallet, theirDid, msg).get(); + assertNotNull(signedMessage); + + // 8. I verify message + Boolean valid = Signus.verifySignature(myWallet, pool, theirDid, signedMessage).get(); + assertTrue(valid); + + // 9. Close and delete My Wallet + myWallet.closeWallet().get(); + Wallet.deleteWallet("myWallet", null).get(); + + // 10. Close and delete Their Wallet + theirWallet.closeWallet().get(); + Wallet.deleteWallet("theirWallet", null).get(); + + //11. Close Pool + pool.closePoolLedger().get(); + } +} From 041b6de84979a4d75d09685f2ac3856406730ef3 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 14 Jul 2017 12:38:27 +0300 Subject: [PATCH 159/349] changes for dockerfile --- ci/ubuntu.dockerfile | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index 087b3eac51..39cbe5135a 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -20,11 +20,10 @@ RUN apt-get update && \ apt-transport-https \ ca-certificates -#RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BD33704C -#RUN echo "deb https://repo.evernym.com/deb xenial master" >> /etc/apt/sources.list -#RUN apt-get update -y -#RUN apt-get install -y \ -# python3-charm-crypto +RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BD33704C +RUN echo "deb https://repo.evernym.com/deb xenial master" >> /etc/apt/sources.list +RUN apt-get update -y && apt-get install -y \ + python3-charm-crypto RUN pip3 install -U \ pip \ @@ -53,15 +52,12 @@ RUN cargo install --git https://github.com/DSRCorporation/cargo-test-xunit WORKDIR /home/indy RUN git clone https://github.com/hyperledger/indy-anoncreds.git -RUN virtualenv -p python3.5 /home/indy/ -#RUN cp -r /usr/local/lib/python3.5/dist-packages/Charm_Crypto-0.0.0.egg-info /home/indy/lib/python3.5/site-packages/Charm_Crypto-0.0.0.egg-info -#RUN cp -r /usr/local/lib/python3.5/dist-packages/charm /home/indy/lib/python3.5/site-packages/charm -RUN /bin/bash /home/indy/indy-anoncreds/setup-charm.sh +RUN virtualenv -p python3.5 /home/indy/test +RUN cp -r /usr/local/lib/python3.5/dist-packages/Charm_Crypto-0.0.0.egg-info /home/indy/test/lib/python3.5/site-packages/Charm_Crypto-0.0.0.egg-info +RUN cp -r /usr/local/lib/python3.5/dist-packages/charm /home/indy/test/lib/python3.5/site-packages/charm USER root - -RUN pip3 install -U \ - git+https://github.com/hyperledger/indy-anoncreds.git - -RUN ln -sf /home/indy/bin/python /usr/local/bin/python -RUN ln -sf /home/indy/bin/pip /usr/local/bin/pip -USER indy \ No newline at end of file +RUN ln -sf /home/indy/test/bin/python /usr/local/bin/python3 +RUN ln -sf /home/indy/test/bin/pip /usr/local/bin/pip3 +USER indy +RUN pip3 install \ + /home/indy/indy-anoncreds \ No newline at end of file From 7fc4b2744b8117938c539b9e8dccafede0c04e5b Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 14 Jul 2017 13:26:06 +0300 Subject: [PATCH 160/349] Used cid:false for Nym transaction --- .../org/hyperledger/indy/sdk/signus/CreateMyDidTest.java | 2 +- .../java/org/hyperledger/indy/sdk/signus/VerifyTest.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java index 067bc4ee78..6f47f517cb 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java @@ -80,7 +80,7 @@ public void testCreateMyDidWorksAsCid() throws Exception { public void testCreateMyDidWorksForPassedDid() throws Exception { SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(did, null, null, true); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(did, null, null, false); CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); assertNotNull(result); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java index 8d04f2a493..ebc5f0a34f 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java @@ -11,13 +11,16 @@ import org.hyperledger.indy.sdk.wallet.Wallet; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.Timeout; import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; public class VerifyTest extends IndyIntegrationTest { @@ -39,7 +42,7 @@ public void createWalletWithDid() throws Exception { wallet = Wallet.openWallet("signusWallet", null, null).get(); SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, true); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, false); CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(wallet, didJson.toJson()).get(); assertNotNull(result); From e0a84df05405f9aa6eb0faa9c174b1e233f2af3f Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 14 Jul 2017 13:39:14 +0300 Subject: [PATCH 161/349] Corrected Nym creation --- .../hyperledger/indy/sdk/demo/LedgerDemoTest.java | 9 +++------ .../hyperledger/indy/sdk/demo/SignusDemoTest.java | 15 ++------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/LedgerDemoTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/LedgerDemoTest.java index 0c666bf388..718fb89654 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/LedgerDemoTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/LedgerDemoTest.java @@ -36,17 +36,14 @@ public void testLedgerDemo() throws Exception { Wallet trusteeWallet = Wallet.openWallet("theirWallet", null, null).get(); // 5. Create My Did - SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, null, true); - - CreateAndStoreMyDidResult createMyDidResult = Signus.createAndStoreMyDid(myWallet, myDidJson.toJson()).get(); + CreateAndStoreMyDidResult createMyDidResult = Signus.createAndStoreMyDid(myWallet, "{}").get(); assertNotNull(createMyDidResult); String myDid = createMyDidResult.getDid(); - String myVerkey = createMyDidResult.getDid(); + String myVerkey = createMyDidResult.getVerkey(); // 6. Create Did from Trustee1 seed SignusJSONParameters.CreateAndStoreMyDidJSONParameter theirDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, true); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); CreateAndStoreMyDidResult createTheirDidResult = Signus.createAndStoreMyDid(trusteeWallet, theirDidJson.toJson()).get(); assertNotNull(createTheirDidResult); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/SignusDemoTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/SignusDemoTest.java index e3e34c5876..27fd6f246e 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/SignusDemoTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/SignusDemoTest.java @@ -4,18 +4,13 @@ import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.pool.PoolJSONParameters; import org.hyperledger.indy.sdk.signus.Signus; -import org.hyperledger.indy.sdk.signus.SignusJSONParameters; import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; import org.hyperledger.indy.sdk.utils.PoolUtils; import org.hyperledger.indy.sdk.wallet.Wallet; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.Timeout; - -import java.util.concurrent.TimeUnit; public class SignusDemoTest extends IndyIntegrationTest { @@ -37,17 +32,11 @@ public void testSignusDemo() throws Exception { Wallet theirWallet = Wallet.openWallet("theirWallet", null, null).get(); //4. Create My Did - SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, null, true); - - CreateAndStoreMyDidResult createMyDidResult = Signus.createAndStoreMyDid(myWallet, myDidJson.toJson()).get(); + CreateAndStoreMyDidResult createMyDidResult = Signus.createAndStoreMyDid(myWallet, "{}").get(); assertNotNull(createMyDidResult); //5. Create Their Did - SignusJSONParameters.CreateAndStoreMyDidJSONParameter theirDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, null, true); - - CreateAndStoreMyDidResult createTheirDidResult = Signus.createAndStoreMyDid(theirWallet, theirDidJson.toJson()).get(); + CreateAndStoreMyDidResult createTheirDidResult = Signus.createAndStoreMyDid(theirWallet, "{}").get(); assertNotNull(createTheirDidResult); String theirDid = createTheirDidResult.getDid(); String theirVerkey = createTheirDidResult.getVerkey(); From 0e0bf36346583c31d2c3f530c60b22e954c2b1a9 Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Fri, 14 Jul 2017 13:43:29 +0300 Subject: [PATCH 162/349] [java] Implement draft demo. --- .../org/hyperledger/indy/sdk/AgentTest.java | 70 ++++++++++++------- .../indy/sdk/IndyIntegrationTest.java | 5 +- 2 files changed, 48 insertions(+), 27 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java index 38e0819191..8dabd5d90d 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java @@ -1,45 +1,56 @@ package org.hyperledger.indy.sdk; -import java.io.File; - import org.hyperledger.indy.sdk.agent.Agent; import org.hyperledger.indy.sdk.agent.Agent.Connection; import org.hyperledger.indy.sdk.agent.Agent.Listener; import org.hyperledger.indy.sdk.agent.AgentObservers.ConnectionObserver; import org.hyperledger.indy.sdk.agent.AgentObservers.ListenerObserver; import org.hyperledger.indy.sdk.agent.AgentObservers.MessageObserver; +import org.hyperledger.indy.sdk.ledger.Ledger; import org.hyperledger.indy.sdk.pool.Pool; -import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusJSONParameters; +import org.hyperledger.indy.sdk.signus.SignusResults; +import org.hyperledger.indy.sdk.utils.PoolUtils; import org.hyperledger.indy.sdk.wallet.Wallet; -import org.junit.Assert; +import org.junit.Test; -import junit.framework.TestCase; +import static org.junit.Assert.assertNotNull; -public class AgentTest extends TestCase { +public class AgentTest extends IndyIntegrationTest { - private Pool pool; + @Test + public void testAgentDemo() throws Exception { + String endpoint = "127.0.0.1:9801"; - @Override - protected void setUp() throws Exception { + Pool pool = PoolUtils.createAndOpenPoolLedger(); + assertNotNull(pool); + openedPools.add(pool); - if (! LibIndy.isInitialized()) LibIndy.init(new File("./lib/libindy.so")); + Wallet.createWallet("test" /* FIXME */, "trustee_wallet", null, null, null).get(); + Wallet.createWallet("test" /* FIXME */, "listener_wallet", null, null, null).get(); + Wallet trusteeWallet = Wallet.openWallet("trustee_wallet", null, null).get(); + assertNotNull(trusteeWallet); + Wallet listenerWallet = Wallet.openWallet("listener_wallet", null, null).get(); + assertNotNull(listenerWallet); + Wallet senderWallet = trusteeWallet; - OpenPoolLedgerJSONParameter openPoolLedgerOptions = new OpenPoolLedgerJSONParameter(null, null, null); - this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions.toJson()).get(); - } + SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJSONParameter + = new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, IndyIntegrationTest.TRUSTEE_SEED, null, false); + SignusResults.CreateAndStoreMyDidResult trustee = Signus.createAndStoreMyDid(trusteeWallet, myDidJSONParameter.toJson()).get(); - @Override - protected void tearDown() throws Exception { + SignusResults.CreateAndStoreMyDidResult listener = Signus.createAndStoreMyDid(listenerWallet, "{}").get(); - this.pool.closePoolLedger(); - } + SignusResults.CreateAndStoreMyDidResult sender = trustee; - public void testAgent() throws Exception { + String listenerNymJson = Ledger.buildNymRequest(trustee.getDid(), listener.getDid(), listener.getVerkey(), null, null).get(); - Pool pool = Pool.openPoolLedger("myconfig", null).get(); - Wallet wallet = Wallet.openWallet("mywallet", null, null).get(); - Assert.assertNotNull(pool); - Assert.assertNotNull(wallet); + Ledger.signAndSubmitRequest(pool, trusteeWallet, trustee.getDid(), listenerNymJson).get(); + + String listenerAttribJson = Ledger.buildAttribRequest(listener.getDid(), listener.getDid(), null, + String.format("{\"endpoint\":{\"ha\":\"%s\",\"verkey\":\"%s\"}}", endpoint, listener.getPk()), null).get(); + + Ledger.signAndSubmitRequest(pool, listenerWallet, listener.getDid(), listenerAttribJson).get(); final MessageObserver messageObserver = new MessageObserver() { @@ -61,16 +72,23 @@ public MessageObserver onConnection(Listener listener, Connection connection, St final ListenerObserver listenerObserver = new ListenerObserver() { - public ConnectionObserver onListener(Listener listener) { + public ConnectionObserver onListener(Listener aListener) { - System.out.println("New listener " + listener); + System.out.println("New listener " + aListener); + try { + Agent.agentAddIdentity(aListener, pool, listenerWallet, listener.getDid()); + } catch (IndyException e) { + e.printStackTrace(); + } return connectionObserver; } }; - Agent.agentConnect(pool, wallet, "did1", "did2", connectionObserver); + Agent.agentListen(endpoint, listenerObserver); + + Agent.agentConnect(pool, senderWallet, sender.getDid(), listener.getDid(), connectionObserver); - Agent.agentListen("endpoint", listenerObserver); + Thread.sleep(500); /* FIXME */ } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java index 7ac943ef7a..fd1c7503c4 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java @@ -14,11 +14,14 @@ import java.util.concurrent.TimeUnit; public class IndyIntegrationTest { + + public static final String TRUSTEE_SEED = "000000000000000000000000Trustee1"; + @Rule public ExpectedException thrown = ExpectedException.none(); @Rule - public Timeout globalTimeout = new Timeout(1, TimeUnit.SECONDS); + public Timeout globalTimeout = new Timeout(10, TimeUnit.SECONDS); @Before public void setUp() throws IOException { From 310823074e8d30ca13c70b43954afa999307dd3c Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 14 Jul 2017 13:45:02 +0300 Subject: [PATCH 163/349] added pytest --- ci/ubuntu.dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index 39cbe5135a..caf3f61975 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -17,6 +17,7 @@ RUN apt-get update && \ python3.5 \ python3-pip \ python-setuptools \ + pytest \ apt-transport-https \ ca-certificates From 69d265e4606a4e25d6006aa367d900c88e4d0582 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 14 Jul 2017 13:48:12 +0300 Subject: [PATCH 164/349] added pytest --- ci/ubuntu.dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index caf3f61975..f055fc28b9 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -17,7 +17,6 @@ RUN apt-get update && \ python3.5 \ python3-pip \ python-setuptools \ - pytest \ apt-transport-https \ ca-certificates @@ -28,6 +27,7 @@ RUN apt-get update -y && apt-get install -y \ RUN pip3 install -U \ pip \ + pytest \ setuptools \ virtualenv From 72379b25f5dc4d8dcb6fc69af4327cb5afab5959 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 14 Jul 2017 14:11:03 +0300 Subject: [PATCH 165/349] added pytest --- ci/ubuntu.dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index f055fc28b9..bca34f7ead 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -27,7 +27,6 @@ RUN apt-get update -y && apt-get install -y \ RUN pip3 install -U \ pip \ - pytest \ setuptools \ virtualenv @@ -61,4 +60,5 @@ RUN ln -sf /home/indy/test/bin/python /usr/local/bin/python3 RUN ln -sf /home/indy/test/bin/pip /usr/local/bin/pip3 USER indy RUN pip3 install \ - /home/indy/indy-anoncreds \ No newline at end of file + /home/indy/indy-anoncreds \ + pytest \ No newline at end of file From ff44941fc801e6279ee20b70172b688192486ca1 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 14 Jul 2017 14:26:26 +0300 Subject: [PATCH 166/349] GET_TXN transaction changes --- tests/ledger.rs | 19 +++++++++---------- tests/utils/types.rs | 4 ++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/ledger.rs b/tests/ledger.rs index ad7709b1e6..7d8d973950 100644 --- a/tests/ledger.rs +++ b/tests/ledger.rs @@ -37,8 +37,7 @@ use utils::types::{ Reply, SchemaResult, GetTxnResult, - SchemaData, - Schema + SchemaData }; use std::collections::{HashSet}; // TODO: FIXME: create_my_did doesn't support CID creation, but this trustee has CID as DID. So it is rough workaround for this issue. @@ -702,7 +701,6 @@ mod high_cases { } #[test] - #[ignore]//Delete it after merge https://github.com/hyperledger/indy-plenum/pull/265 #[cfg(feature = "local_nodes_pool")] fn indy_get_txn_request_works() { TestUtils::cleanup_storage(); @@ -733,20 +731,21 @@ mod high_cases { let seq_no = schema_response.result.seq_no; let get_txn_request = LedgerUtils::build_get_txn_request(&my_did, seq_no).unwrap(); - let get_txn_response = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &my_did, &get_txn_request).unwrap(); + let get_txn_response = LedgerUtils::submit_request(pool_handle, &get_txn_request).unwrap(); let get_txn_response: Reply = serde_json::from_str(&get_txn_response).unwrap(); - assert!(get_txn_response.result.data.is_some()); - let get_txn_schema: Schema = serde_json::from_str(&get_txn_response.result.data.unwrap()).unwrap(); + let get_txn_schema_result: SchemaResult = serde_json::from_str(&get_txn_response.result.data).unwrap(); + assert!(get_txn_schema_result.data.is_some()); - assert_eq!(schema_data, get_txn_schema.data); + let get_txn_schema_data: SchemaData = serde_json::from_str(&get_txn_schema_result.data.unwrap()).unwrap(); + + assert_eq!(schema_data, get_txn_schema_data); TestUtils::cleanup_storage(); } #[test] - #[ignore]//Delete it after merge https://github.com/hyperledger/indy-plenum/pull/265 #[cfg(feature = "local_nodes_pool")] fn indy_get_txn_request_works_for_invalid_seq_no() { TestUtils::cleanup_storage(); @@ -774,9 +773,9 @@ mod high_cases { let get_txn_request = LedgerUtils::build_get_txn_request(&my_did, seq_no).unwrap(); - let get_txn_response = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &my_did, &get_txn_request).unwrap(); + let get_txn_response = LedgerUtils::submit_request(pool_handle, &get_txn_request).unwrap(); let get_txn_response: Reply = serde_json::from_str(&get_txn_response).unwrap(); - assert!(get_txn_response.result.data.is_none()); + assert_eq!(get_txn_response.result.data, "{}".to_string()); TestUtils::cleanup_storage(); } diff --git a/tests/utils/types.rs b/tests/utils/types.rs index 3ef21caa80..130217aa4e 100644 --- a/tests/utils/types.rs +++ b/tests/utils/types.rs @@ -120,10 +120,10 @@ pub struct GetTxnResult { #[serde(rename = "reqId")] pub req_id: u64, #[serde(rename = "seqNo")] - pub seq_no: i32, + pub seq_no: Option, #[serde(rename = "type")] pub _type: String, - pub data: Option + pub data: String } #[derive(Debug, Serialize, Deserialize)] From ab68cbc93aacfd4a26d3d2e197effcdbab10a064 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 14 Jul 2017 14:29:29 +0300 Subject: [PATCH 167/349] Small refactoring of LedgerDemo test --- .../indy/sdk/demo/LedgerDemoTest.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/LedgerDemoTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/LedgerDemoTest.java index 718fb89654..3e3b475330 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/LedgerDemoTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/LedgerDemoTest.java @@ -22,26 +22,25 @@ public void testLedgerDemo() throws Exception { // 1. Create ledger config from genesis txn file String poolName = PoolUtils.createPoolLedgerConfig(); + PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); - - // 2. Open pool ledger Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); - // 3. Create and Open My Wallet + // 2. Create and Open My Wallet Wallet.createWallet(poolName, "myWallet", "default", null, null).get(); Wallet myWallet = Wallet.openWallet("myWallet", null, null).get(); - // 4. Create and Open Trustee Wallet + // 3. Create and Open Trustee Wallet Wallet.createWallet(poolName, "theirWallet", "default", null, null).get(); Wallet trusteeWallet = Wallet.openWallet("theirWallet", null, null).get(); - // 5. Create My Did + // 4. Create My Did CreateAndStoreMyDidResult createMyDidResult = Signus.createAndStoreMyDid(myWallet, "{}").get(); assertNotNull(createMyDidResult); String myDid = createMyDidResult.getDid(); String myVerkey = createMyDidResult.getVerkey(); - // 6. Create Did from Trustee1 seed + // 5. Create Did from Trustee1 seed SignusJSONParameters.CreateAndStoreMyDidJSONParameter theirDidJson = new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); @@ -49,11 +48,11 @@ public void testLedgerDemo() throws Exception { assertNotNull(createTheirDidResult); String trusteeDid = createTheirDidResult.getDid(); - // 7. Build Nym Request + // 6. Build Nym Request String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, myVerkey, null, null).get(); assertNotNull(nymRequest); - // 8. Trustee Sign Nym Request + // 7. Trustee Sign Nym Request String nymResponseJson = Ledger.signAndSubmitRequest(pool, trusteeWallet, trusteeDid, nymRequest).get(); assertNotNull(nymResponseJson); @@ -62,15 +61,15 @@ public void testLedgerDemo() throws Exception { assertEquals(myDid, nymResponse.getJSONObject("result").getString("dest")); assertEquals(myVerkey, nymResponse.getJSONObject("result").getString("verkey")); - // 9. Close and delete My Wallet + // 8. Close and delete My Wallet myWallet.closeWallet().get(); Wallet.deleteWallet("myWallet", null).get(); - // 10. Close and delete Their Wallet + // 9. Close and delete Their Wallet trusteeWallet.closeWallet().get(); Wallet.deleteWallet("theirWallet", null).get(); - // 11. Close Pool + // 10. Close Pool pool.closePoolLedger().get(); } } From 4c40e50e4e233d674408e0a34fc0c475f5c15ed2 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 14 Jul 2017 14:45:56 +0300 Subject: [PATCH 168/349] Fixed typo --- .../main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java | 2 +- .../java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java index 5d8930236d..5524fc7e28 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java @@ -324,7 +324,7 @@ public static CompletableFuture proverGetClaimOffers( return future; } - public static CompletableFuture proverCretaMasterSecret( + public static CompletableFuture proverCreateMasterSecret( Wallet wallet, String masterSecretName) throws IndyException { diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java index f991221eb7..4913f26a7f 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java @@ -57,7 +57,7 @@ public void testAnoncredsDemo() throws Exception { //5. Prover create Master Secret String masterSecret = "masterSecretName"; - Anoncreds.proverCretaMasterSecret(proverWallet, masterSecret).get(); + Anoncreds.proverCreateMasterSecret(proverWallet, masterSecret).get(); //6. Prover store Claim Offer String claimOffer = String.format("{\"issuer_did\":\"%s\", \"schema_seq_no\":%d}", issuerDid, 1); From 4eef2751a93d23f01b9353da5c84b76680542c02 Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Fri, 14 Jul 2017 15:06:37 +0300 Subject: [PATCH 169/349] Add FIXME about not founded get txn --- tests/ledger.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ledger.rs b/tests/ledger.rs index 7d8d973950..edb4b60c84 100644 --- a/tests/ledger.rs +++ b/tests/ledger.rs @@ -775,7 +775,7 @@ mod high_cases { let get_txn_response = LedgerUtils::submit_request(pool_handle, &get_txn_request).unwrap(); let get_txn_response: Reply = serde_json::from_str(&get_txn_response).unwrap(); - assert_eq!(get_txn_response.result.data, "{}".to_string()); + assert_eq!(get_txn_response.result.data, "{}".to_string()); /* FIXME: unify with other GET_ transactions (data.is_none()) */ TestUtils::cleanup_storage(); } From 293a1218a1ceefcb1d5f41c0ec13950e46934bdf Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Fri, 14 Jul 2017 15:23:31 +0300 Subject: [PATCH 170/349] [java] Remove listener observer, update agentDemoTest. --- .../org/hyperledger/indy/sdk/agent/Agent.java | 174 +++++++++--------- .../indy/sdk/agent/AgentObservers.java | 7 +- .../org/hyperledger/indy/sdk/AgentTest.java | 36 ++-- .../hyperledger/indy/sdk/utils/PoolUtils.java | 8 +- 4 files changed, 108 insertions(+), 117 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java index 4133a72a81..968b3c063e 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java @@ -17,8 +17,8 @@ */ public class Agent extends IndyJava.API { - private static Map connections = new ConcurrentHashMap (); - private static Map listeners = new ConcurrentHashMap (); + private static Map connections = new ConcurrentHashMap(); + private static Map listeners = new ConcurrentHashMap(); private Agent() { @@ -28,39 +28,35 @@ private Agent() { * OBSERVERS */ - private static Map listenerObservers = new ConcurrentHashMap (); - private static Map connectionObservers = new ConcurrentHashMap (); + private static Map messageObserver = new ConcurrentHashMap(); + private static Map connectionObservers = new ConcurrentHashMap(); - private static int addListenerObserver(AgentObservers.ListenerObserver listenerObserver) { + private static void addMessageObserver(int commandHandle, AgentObservers.MessageObserver messageObserver) { - int commandHandle = newCommandHandle(); - assert(! listenerObservers.containsKey(Integer.valueOf(commandHandle))); - listenerObservers.put(Integer.valueOf(commandHandle), listenerObserver); + assert (!Agent.messageObserver.containsKey(commandHandle)); + Agent.messageObserver.put(commandHandle, messageObserver); - return commandHandle; } - private static AgentObservers.ListenerObserver removeListenerObserver(int xcommand_handle) { + private static AgentObservers.MessageObserver removeMessageObserver(int xcommand_handle) { - AgentObservers.ListenerObserver future = listenerObservers.remove(Integer.valueOf(xcommand_handle)); - assert(future != null); + AgentObservers.MessageObserver future = messageObserver.remove(xcommand_handle); + assert (future != null); return future; } - private static int addConnectionObserver(AgentObservers.ConnectionObserver connectionObserver) { + private static void addIncomingConnectionObserver(int commandHandle, AgentObservers.IncomingConnectionObserver incomingConnectionObserver) { - int commandHandle = newCommandHandle(); - assert(! connectionObservers.containsKey(Integer.valueOf(commandHandle))); - connectionObservers.put(Integer.valueOf(commandHandle), connectionObserver); + assert (!connectionObservers.containsKey(commandHandle)); + connectionObservers.put(commandHandle, incomingConnectionObserver); - return commandHandle; } - private static AgentObservers.ConnectionObserver removeConnectionObserver(int xcommand_handle) { + private static AgentObservers.IncomingConnectionObserver removeIncomingConnectionObserver(int xcommand_handle) { - AgentObservers.ConnectionObserver future = connectionObservers.remove(Integer.valueOf(xcommand_handle)); - assert(future != null); + AgentObservers.IncomingConnectionObserver future = connectionObservers.remove(xcommand_handle); + assert (future != null); return future; } @@ -74,15 +70,16 @@ private static AgentObservers.ConnectionObserver removeConnectionObserver(int xc @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, int connection_handle) throws IndyException { - checkCallback(err); + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (!checkCallback(future, err)) return; - assert(! connections.containsKey(Integer.valueOf(connection_handle))); + assert (!connections.containsKey(connection_handle)); Agent.Connection connection = new Agent.Connection(connection_handle); - connections.put(Integer.valueOf(connection_handle), connection); + connections.put(connection_handle, connection); + + connection.messageObserver = removeMessageObserver(xcommand_handle); - AgentObservers.ConnectionObserver connectionObserver = removeConnectionObserver(xcommand_handle); - AgentObservers.MessageObserver messageObserver = connectionObserver.onConnection(null, connection, null, null); - connection.messageObserver = messageObserver; + future.complete(connection); } }; @@ -93,7 +90,7 @@ public void callback(int xconnection_handle, int err, String message) throws Ind checkCallback(err); - Agent.Connection connection = connections.get(Integer.valueOf(xconnection_handle)); + Agent.Connection connection = connections.get(xconnection_handle); if (connection == null) return; AgentObservers.MessageObserver messageObserver = connection.messageObserver; @@ -106,15 +103,16 @@ public void callback(int xconnection_handle, int err, String message) throws Ind @SuppressWarnings("unused") public void callback(int xcommand_handle, int err, int listener_handle) throws IndyException { - checkCallback(err); + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (!checkCallback(future, err)) return; - assert(! listeners.containsKey(Integer.valueOf(listener_handle))); + assert (!listeners.containsKey(listener_handle)); Agent.Listener listener = new Agent.Listener(listener_handle); - listeners.put(Integer.valueOf(listener_handle), listener); + listeners.put(listener_handle, listener); - AgentObservers.ListenerObserver listenerObserver = removeListenerObserver(xcommand_handle); - AgentObservers.ConnectionObserver connectionObserver = listenerObserver.onListener(listener); - listener.connectionObserver = connectionObserver; + listener.incomingConnectionObserver = removeIncomingConnectionObserver(xcommand_handle); + + future.complete(listener); } }; @@ -125,16 +123,15 @@ public void callback(int xlistener_handle, int err, int connection_handle, Strin checkCallback(err); - Agent.Listener listener = listeners.get(Integer.valueOf(xlistener_handle)); + Agent.Listener listener = listeners.get(xlistener_handle); if (listener == null) return; - assert(! connections.containsKey(Integer.valueOf(connection_handle))); + assert (!connections.containsKey(connection_handle)); Agent.Connection connection = new Agent.Connection(connection_handle); - connections.put(Integer.valueOf(connection_handle), connection); + connections.put(connection_handle, connection); - AgentObservers.ConnectionObserver connectionObserver = listener.connectionObserver; - AgentObservers.MessageObserver messageObserver = connectionObserver.onConnection(listener, connection, sender_did, receiver_did); - connection.messageObserver = messageObserver; + AgentObservers.IncomingConnectionObserver incomingConnectionObserver = listener.incomingConnectionObserver; + connection.messageObserver = incomingConnectionObserver.onConnection(listener, connection, sender_did, receiver_did); } }; @@ -145,7 +142,7 @@ public void callback(int xconnection_handle, int err, String message) throws Ind checkCallback(err); - Agent.Connection connection = connections.get(Integer.valueOf(xconnection_handle)); + Agent.Connection connection = connections.get(xconnection_handle); if (connection == null) return; AgentObservers.MessageObserver messageObserver = connection.messageObserver; @@ -155,66 +152,61 @@ public void callback(int xconnection_handle, int err, String message) throws Ind private static Callback agentAddIdentityCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, int listener_handle) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (!checkCallback(future, err)) return; - Void result = null; - future.complete(result); + future.complete(null); } }; private static Callback agentRemoveIdentityCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, int listener_handle) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (!checkCallback(future, err)) return; - Void result = null; - future.complete(result); + future.complete(null); } }; private static Callback agentSendCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (!checkCallback(future, err)) return; - Void result = null; - future.complete(result); + future.complete(null); } }; private static Callback agentCloseConnectionCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (!checkCallback(future, err)) return; - Void result = null; - future.complete(result); + future.complete(null); } }; private static Callback agentCloseListenerCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (!checkCallback(future, err)) return; - Void result = null; - future.complete(result); + future.complete(null); } }; @@ -222,44 +214,52 @@ public void callback(int xcommand_handle, int err) { * STATIC METHODS */ - public static void agentConnect( + public static CompletableFuture agentConnect( Pool pool, Wallet wallet, String senderDid, String receiverDid, - AgentObservers.ConnectionObserver connectionObserver) throws IndyException { + AgentObservers.MessageObserver messageObserver) throws IndyException { - int commandHandle = addConnectionObserver(connectionObserver); + CompletableFuture future = new CompletableFuture<>(); + int commandHandle = addFuture(future); + addMessageObserver(commandHandle, messageObserver); int poolHandle = pool.getPoolHandle(); int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_agent_connect( - commandHandle, + commandHandle, poolHandle, - walletHandle, + walletHandle, senderDid, receiverDid, agentConnectConnectionCb, agentConnectMessageCb); checkResult(result); + + return future; } - public static void agentListen( + public static CompletableFuture agentListen( String endpoint, - AgentObservers.ListenerObserver listenerObserver) throws IndyException { + AgentObservers.IncomingConnectionObserver incomingConnectionObserver) throws IndyException { - int commandHandle = addListenerObserver(listenerObserver); + CompletableFuture future = new CompletableFuture<>(); + int commandHandle = addFuture(future); + addIncomingConnectionObserver(commandHandle, incomingConnectionObserver); int result = LibIndy.api.indy_agent_listen( - commandHandle, + commandHandle, endpoint, agentListenListenerCb, agentListenConnectionCb, agentListenMessageCb); checkResult(result); + + return future; } public static CompletableFuture agentAddIdentity( @@ -268,7 +268,7 @@ public static CompletableFuture agentAddIdentity( Wallet wallet, String did) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int listenerHandle = listener.getListenerHandle(); @@ -276,10 +276,10 @@ public static CompletableFuture agentAddIdentity( int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_agent_add_identity( - commandHandle, + commandHandle, listenerHandle, poolHandle, - walletHandle, + walletHandle, did, agentAddIdentityCb); @@ -293,16 +293,16 @@ public static CompletableFuture agentRemoveIdentity( Wallet wallet, String did) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int listenerHandle = listener.getListenerHandle(); int walletHandle = wallet.getWalletHandle(); int result = LibIndy.api.indy_agent_remove_identity( - commandHandle, + commandHandle, listenerHandle, - walletHandle, + walletHandle, did, agentRemoveIdentityCb); @@ -315,14 +315,14 @@ public static CompletableFuture agentSend( Agent.Connection connection, String message) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int connectionHandle = connection.getConnectionHandle(); int result = LibIndy.api.indy_agent_send( - commandHandle, - connectionHandle, + commandHandle, + connectionHandle, message, agentSendCb); @@ -334,16 +334,16 @@ public static CompletableFuture agentSend( public static CompletableFuture agentCloseConnection( Agent.Connection connection) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int connectionHandle = connection.getConnectionHandle(); - connections.remove(Integer.valueOf(connectionHandle)); + connections.remove(connectionHandle); int result = LibIndy.api.indy_agent_close_connection( - commandHandle, - connectionHandle, + commandHandle, + connectionHandle, agentCloseConnectionCb); checkResult(result); @@ -354,16 +354,16 @@ public static CompletableFuture agentCloseConnection( public static CompletableFuture agentCloseListener( Agent.Listener listener) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int listenerHandle = listener.getListenerHandle(); - listeners.remove(Integer.valueOf(listenerHandle)); + listeners.remove(listenerHandle); int result = LibIndy.api.indy_agent_close_connection( - commandHandle, - listenerHandle, + commandHandle, + listenerHandle, agentCloseListenerCb); checkResult(result); @@ -378,7 +378,7 @@ public static CompletableFuture agentCloseListener( public static class Listener { private final int listenerHandle; - private AgentObservers.ConnectionObserver connectionObserver; + private AgentObservers.IncomingConnectionObserver incomingConnectionObserver; private Listener(int listenerHandle) { diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentObservers.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentObservers.java index 3cd5c6c39a..a4356919fa 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentObservers.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentObservers.java @@ -9,12 +9,7 @@ private AgentObservers() { } - public interface ListenerObserver { - - public ConnectionObserver onListener(Agent.Listener listener); - } - - public interface ConnectionObserver { + public interface IncomingConnectionObserver { public MessageObserver onConnection(Agent.Listener listener, Agent.Connection connection, String senderDid, String receiverDid); } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java index 8dabd5d90d..6e0b7858d8 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java @@ -3,8 +3,7 @@ import org.hyperledger.indy.sdk.agent.Agent; import org.hyperledger.indy.sdk.agent.Agent.Connection; import org.hyperledger.indy.sdk.agent.Agent.Listener; -import org.hyperledger.indy.sdk.agent.AgentObservers.ConnectionObserver; -import org.hyperledger.indy.sdk.agent.AgentObservers.ListenerObserver; +import org.hyperledger.indy.sdk.agent.AgentObservers.IncomingConnectionObserver; import org.hyperledger.indy.sdk.agent.AgentObservers.MessageObserver; import org.hyperledger.indy.sdk.ledger.Ledger; import org.hyperledger.indy.sdk.pool.Pool; @@ -27,8 +26,8 @@ public void testAgentDemo() throws Exception { assertNotNull(pool); openedPools.add(pool); - Wallet.createWallet("test" /* FIXME */, "trustee_wallet", null, null, null).get(); - Wallet.createWallet("test" /* FIXME */, "listener_wallet", null, null, null).get(); + Wallet.createWallet(PoolUtils.DEFAULT_POOL_NAME, "trustee_wallet", null, null, null).get(); + Wallet.createWallet(PoolUtils.DEFAULT_POOL_NAME, "listener_wallet", null, null, null).get(); Wallet trusteeWallet = Wallet.openWallet("trustee_wallet", null, null).get(); assertNotNull(trusteeWallet); Wallet listenerWallet = Wallet.openWallet("listener_wallet", null, null).get(); @@ -60,35 +59,30 @@ public void onMessage(Connection connection, String message) { } }; - final ConnectionObserver connectionObserver = new ConnectionObserver() { + final MessageObserver messageObserverForIncoming = new MessageObserver() { - public MessageObserver onConnection(Listener listener, Connection connection, String senderDid, String receiverDid) { - - System.out.println("New connection " + connection); + public void onMessage(Connection connection, String message) { - return messageObserver; + System.out.println("Received message '" + message + "' on incoming connection " + connection); } }; - final ListenerObserver listenerObserver = new ListenerObserver() { + final IncomingConnectionObserver incomingConnectionObserver = new IncomingConnectionObserver() { - public ConnectionObserver onListener(Listener aListener) { + public MessageObserver onConnection(Listener listener, Connection connection, String senderDid, String receiverDid) { - System.out.println("New listener " + aListener); - try { - Agent.agentAddIdentity(aListener, pool, listenerWallet, listener.getDid()); - } catch (IndyException e) { - e.printStackTrace(); - } + System.out.println("New connection " + connection); - return connectionObserver; + return messageObserverForIncoming; } }; - Agent.agentListen(endpoint, listenerObserver); + Listener activeListener = Agent.agentListen(endpoint, incomingConnectionObserver).get(); + + activeListener.agentAddIdentity(pool, listenerWallet, listener.getDid()).get(); - Agent.agentConnect(pool, senderWallet, sender.getDid(), listener.getDid(), connectionObserver); + Connection connection = Agent.agentConnect(pool, senderWallet, sender.getDid(), listener.getDid(), messageObserver).get(); - Thread.sleep(500); /* FIXME */ + connection.agentSend("test").get(); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java index 91af2fbd97..80cd869ec9 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java @@ -11,6 +11,9 @@ import java.util.concurrent.ExecutionException; public class PoolUtils { + + public static final String DEFAULT_POOL_NAME = "default_pool"; + public static File createGenesisTxnFile(String filename) throws IOException { return createGenesisTxnFile(filename, 4); } @@ -44,9 +47,8 @@ public static String createPoolLedgerConfig() throws InterruptedException, Execu } public static String createPoolLedgerConfig(int nodesCnt) throws InterruptedException, ExecutionException, IndyException, IOException { - String poolName = "test"; - createPoolLedgerConfig(poolName, nodesCnt); - return poolName; + createPoolLedgerConfig(DEFAULT_POOL_NAME, nodesCnt); + return DEFAULT_POOL_NAME; } public static void createPoolLedgerConfig(String poolName, int nodesCnt) throws IOException, InterruptedException, java.util.concurrent.ExecutionException, IndyException { From 47825c91340aefa82d450fee93283da3383bb1be Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 14 Jul 2017 15:41:32 +0300 Subject: [PATCH 171/349] Code style changes --- .../indy/sdk/anoncreds/Anoncreds.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java index 5524fc7e28..6f92230b95 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java @@ -26,7 +26,7 @@ private Anoncreds() { private static Callback issuerCreateAndStoreClaimDefCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String claim_def_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -39,7 +39,7 @@ public void callback(int xcommand_handle, int err, String claim_def_json) { private static Callback issuerCreateAndStoreRevocRegCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String revoc_reg_json, String revoc_reg_uuid) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -52,7 +52,7 @@ public void callback(int xcommand_handle, int err, String revoc_reg_json, String private static Callback issuerCreateClaimCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String revoc_reg_update_json, String xclaim_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -65,7 +65,7 @@ public void callback(int xcommand_handle, int err, String revoc_reg_update_json, private static Callback issuerRevokeClaimCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String revoc_reg_update_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -78,7 +78,7 @@ public void callback(int xcommand_handle, int err, String revoc_reg_update_json) private static Callback proverStoreClaimOfferCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -95,7 +95,7 @@ public void callback(int xcommand_handle, int err) { public void callback(int xcommand_handle, int err, String claim_offers_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (!checkCallback(future, err)) return; + if (! checkCallback(future, err)) return; String result = claim_offers_json; future.complete(result); @@ -108,7 +108,7 @@ public void callback(int xcommand_handle, int err, String claim_offers_json) { public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (!checkCallback(future, err)) return; + if (! checkCallback(future, err)) return; Void result = null; future.complete(result); @@ -121,7 +121,7 @@ public void callback(int xcommand_handle, int err) { public void callback(int xcommand_handle, int err, String claim_req_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (!checkCallback(future, err)) return; + if (! checkCallback(future, err)) return; String result = claim_req_json; future.complete(result); @@ -134,7 +134,7 @@ public void callback(int xcommand_handle, int err, String claim_req_json) { public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (!checkCallback(future, err)) return; + if (! checkCallback(future, err)) return; Void result = null; future.complete(result); @@ -147,7 +147,7 @@ public void callback(int xcommand_handle, int err) { public void callback(int xcommand_handle, int err, String claimsJson) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (!checkCallback(future, err)) return; + if (! checkCallback(future, err)) return; String result = claimsJson; future.complete(result); @@ -160,7 +160,7 @@ public void callback(int xcommand_handle, int err, String claimsJson) { public void callback(int xcommand_handle, int err, String proofJson) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (!checkCallback(future, err)) return; + if (! checkCallback(future, err)) return; String result = proofJson; future.complete(result); @@ -173,7 +173,7 @@ public void callback(int xcommand_handle, int err, String proofJson) { public void callback(int xcommand_handle, int err, Boolean valid) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (!checkCallback(future, err)) return; + if (! checkCallback(future, err)) return; Boolean result = valid; future.complete(result); From e023ac57666cbcccbe064311e2eb2b907b1a2dc1 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Fri, 14 Jul 2017 16:16:03 +0300 Subject: [PATCH 172/349] * Use plain functions instead of static methods for API * Refactored libindy.py in generic way * Added trace logging --- wrappers/python/indy/__init__.py | 6 - wrappers/python/indy/anoncreds.py | 185 +++++++++--------- wrappers/python/indy/error.py | 110 ++++++++++- wrappers/python/indy/ledger.py | 146 +++++++------- wrappers/python/indy/libindy.py | 123 +++++++++--- wrappers/python/indy/pool.py | 41 ++-- wrappers/python/indy/signus.py | 100 +++++----- wrappers/python/indy/wallet.py | 87 ++++---- wrappers/python/tests/test_libindy.py | 9 - wrappers/python/tests/utils/storage.py | 50 +++-- wrappers/python/tests/utils/test_storage.py | 9 +- .../python/tests/wallet/test_create_wallet.py | 19 +- 12 files changed, 524 insertions(+), 361 deletions(-) delete mode 100644 wrappers/python/tests/test_libindy.py diff --git a/wrappers/python/indy/__init__.py b/wrappers/python/indy/__init__.py index 1c5564eee4..d68cac3eca 100644 --- a/wrappers/python/indy/__init__.py +++ b/wrappers/python/indy/__init__.py @@ -1,7 +1 @@ from indy.error import IndyError - -from indy.anoncreds import Anoncreds -from indy.ledger import Ledger -from indy.pool import Pool -from indy.signus import Signus -from indy.wallet import Wallet diff --git a/wrappers/python/indy/anoncreds.py b/wrappers/python/indy/anoncreds.py index f158261d89..a4067ed1b2 100644 --- a/wrappers/python/indy/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -1,90 +1,95 @@ -from typing import Callable -from . import IndyError - -class Anoncreds(object): - - """TODO: document it""" - - async def issuer_create_and_store_claim_def(wallet_handle: int, - schema_json: str, - signature_type: str, - create_non_revoc: bool, - claim_def_json: str, - claim_def_uuid: str) -> None: - pass - - async def issuer_create_and_store_revoc_reg(wallet_handle: int, - claim_def_seq_no: int, - max_claim_num: int, - revoc_reg_json: str, - revoc_reg_uuid: str) -> None: - pass - - async def issuer_create_claim(wallet_handle: int, - claim_req_json: str, - claim_json: str, - revoc_reg_seq_no: int, - user_revoc_index: int, - revoc_reg_update_json: str, - xclaim_json: str) -> None: - pass - - async def issuer_revoke_claim(wallet_handle: int, - claim_def_seq_no: int, - revoc_reg_seq_no: int, - user_revoc_index: int, - revoc_reg_update_json: str) -> None: - pass - - async def prover_store_claim_offer(wallet_handle: int, - claim_offer_json: str) -> None: - pass - - async def prover_get_claim_offers(wallet_handle: int, - filter_json: str, - claim_offers_json: str) -> None: - pass - - async def prover_create_master_secret(wallet_handle: int, - master_secret_name: str) -> None: - pass - - async def prover_create_and_store_claim_req(wallet_handle: int, - prover_did: str, - claim_offer_json: str, - claim_def_json: str, - master_secret_name: str, - claim_req_json: str) -> None: - pass - - async def prover_store_claim(wallet_handle: int, - claims_json: str) -> None: - pass - - async def prover_get_claims(wallet_handle: int, - filter_json: str, - claims_json: str) -> None: - pass - - async def prover_get_claims_for_proof_req(wallet_handle: int, - proof_request_json: str, - claims_json: str) -> None: - pass - - async def prover_create_proof(wallet_handle: int, - proof_req_json: str, - requested_claims_json: str, - schemas_json: str, - claim_defs_json: str, - revoc_regs_json: str, - proof_json: str) -> None: - pass - - async def verifier_verify_proof(wallet_handle: int, - proof_request_json: str, - proof_json: str, - schemas_json: str, - claim_defs_jsons: str, - revoc_regs_json: str, - valid: bool) -> None: - pass +async def issuer_create_and_store_claim_def(wallet_handle: int, + schema_json: str, + signature_type: str, + create_non_revoc: bool, + claim_def_json: str, + claim_def_uuid: str) -> None: + pass + + +async def issuer_create_and_store_revoc_reg(wallet_handle: int, + claim_def_seq_no: int, + max_claim_num: int, + revoc_reg_json: str, + revoc_reg_uuid: str) -> None: + pass + + +async def issuer_create_claim(wallet_handle: int, + claim_req_json: str, + claim_json: str, + revoc_reg_seq_no: int, + user_revoc_index: int, + revoc_reg_update_json: str, + xclaim_json: str) -> None: + pass + + +async def issuer_revoke_claim(wallet_handle: int, + claim_def_seq_no: int, + revoc_reg_seq_no: int, + user_revoc_index: int, + revoc_reg_update_json: str) -> None: + pass + + +async def prover_store_claim_offer(wallet_handle: int, + claim_offer_json: str) -> None: + pass + + +async def prover_get_claim_offers(wallet_handle: int, + filter_json: str, + claim_offers_json: str) -> None: + pass + + +async def prover_create_master_secret(wallet_handle: int, + master_secret_name: str) -> None: + pass + + +async def prover_create_and_store_claim_req(wallet_handle: int, + prover_did: str, + claim_offer_json: str, + claim_def_json: str, + master_secret_name: str, + claim_req_json: str) -> None: + pass + + +async def prover_store_claim(wallet_handle: int, + claims_json: str) -> None: + pass + + +async def prover_get_claims(wallet_handle: int, + filter_json: str, + claims_json: str) -> None: + pass + + +async def prover_get_claims_for_proof_req(wallet_handle: int, + proof_request_json: str, + claims_json: str) -> None: + pass + + +async def prover_create_proof(wallet_handle: int, + proof_req_json: str, + requested_claims_json: str, + schemas_json: str, + claim_defs_json: str, + revoc_regs_json: str, + proof_json: str) -> None: + pass + + +async def verifier_verify_proof(wallet_handle: int, + proof_request_json: str, + proof_json: str, + schemas_json: str, + claim_defs_jsons: str, + revoc_regs_json: str, + valid: bool) -> None: + pass diff --git a/wrappers/python/indy/error.py b/wrappers/python/indy/error.py index bea0eeb636..a9c17b76ce 100644 --- a/wrappers/python/indy/error.py +++ b/wrappers/python/indy/error.py @@ -1,8 +1,114 @@ from enum import IntEnum + class ErrorCode(IntEnum): - Success = 0 - CommonInvalidParam1 = 100 + Success = 0, + + # Common errors + + # Caller passed invalid value as param 1 (null, invalid json and etc..) + CommonInvalidParam1 = 100, + + # Caller passed invalid value as param 2 (null, invalid json and etc..) + CommonInvalidParam2 = 101, + + # Caller passed invalid value as param 3 (null, invalid json and etc..) + CommonInvalidParam3 = 102, + + # Caller passed invalid value as param 4 (null, invalid json and etc..) + CommonInvalidParam4 = 103, + + # Caller passed invalid value as param 5 (null, invalid json and etc..) + CommonInvalidParam5 = 104, + + # Caller passed invalid value as param 6 (null, invalid json and etc..) + CommonInvalidParam6 = 105, + + # Caller passed invalid value as param 7 (null, invalid json and etc..) + CommonInvalidParam7 = 106, + + # Caller passed invalid value as param 8 (null, invalid json and etc..) + CommonInvalidParam8 = 107, + + # Caller passed invalid value as param 9 (null, invalid json and etc..) + CommonInvalidParam9 = 108, + + # Caller passed invalid value as param 10 (null, invalid json and etc..) + CommonInvalidParam10 = 109, + + # Caller passed invalid value as param 11 (null, invalid json and etc..) + CommonInvalidParam11 = 110, + + # Caller passed invalid value as param 12 (null, invalid json and etc..) + CommonInvalidParam12 = 111, + + # Invalid library state was detected in runtime. It signals library bug + CommonInvalidState = 112, + + # Object (json, config, key, claim and etc...) passed by library caller has invalid structure + CommonInvalidStructure = 113, + + # IO Error + CommonIOError = 114, + + # Wallet errors + # Caller passed invalid wallet handle + WalletInvalidHandle = 200, + + # Unknown type of wallet was passed on create_wallet + WalletUnknownTypeError = 201, + + # Attempt to register already existing wallet type + WalletTypeAlreadyRegisteredError = 202, + + # Attempt to create wallet with name used for another exists wallet + WalletAlreadyExistsError = 203, + + # Requested entity id isn't present in wallet + WalletNotFoundError = 204, + + # Trying to use wallet with pool that has different name + WalletIncompatiblePoolError = 205, + + # Trying to open wallet that was opened already + WalletAlreadyOpenedError = 206, + + # Ledger errors + # Trying to open pool ledger that wasn't created before + PoolLedgerNotCreatedError = 300, + + # Caller passed invalid pool ledger handle + PoolLedgerInvalidPoolHandle = 301, + + # Pool ledger terminated + PoolLedgerTerminated = 302, + + # No concensus during ledger operation + LedgerNoConsensusError = 303, + + # Attempt to send unknown or incomplete transaction message + LedgerInvalidTransaction = 304, + + # Attempt to send transaction without the necessary privileges + LedgerSecurityError = 305, + + # Revocation registry is full and creation of new registry is necessary + AnoncredsRevocationRegistryFullError = 400, + + AnoncredsInvalidUserRevocIndex = 401, + + AnoncredsAccumulatorIsFull = 402, + + AnoncredsNotIssuedError = 403, + + # Attempt to generate master secret with dupplicated name + AnoncredsMasterSecretDuplicateNameError = 404, + + AnoncredsProofRejected = 405, + + # Signus errors + # Unknown format of DID entity keys + SignusUnknownCryptoError = 500 class IndyError(Exception): diff --git a/wrappers/python/indy/ledger.py b/wrappers/python/indy/ledger.py index 6825a74c24..8e22b07744 100644 --- a/wrappers/python/indy/ledger.py +++ b/wrappers/python/indy/ledger.py @@ -1,89 +1,93 @@ -from typing import Callable -from . import IndyError - -class Ledger(object): - - """TODO: document it""" +async def sign_and_submit_request(command_handle: int, + wallet_handle: int, + submitter_did: str, + request_json: str, + request_result_json: str) -> None: + pass - async def sign_and_submit_request(command_handle: int, - wallet_handle: int, - submitter_did: str, - request_json: str, - request_result_json: str) -> None: - pass - async def submit_request(command_handle: int, - pool_handle: int, - request_json: str, - request_result_json: str) -> None: - pass +async def submit_request(command_handle: int, + pool_handle: int, + request_json: str, + request_result_json: str) -> None: + pass - async def build_get_ddo_request(command_handle: int, - submitter_did: str, - target_did: str, - request_json: str) -> None: - pass - async def build_nym_request(command_handle: int, +async def build_get_ddo_request(command_handle: int, submitter_did: str, target_did: str, - verkey: str, - xref: str, - data: str, - role: str, request_json: str) -> None: - pass + pass + + +async def build_nym_request(command_handle: int, + submitter_did: str, + target_did: str, + verkey: str, + xref: str, + data: str, + role: str, + request_json: str) -> None: + pass - async def build_attrib_request(command_handle: int, + +async def build_attrib_request(command_handle: int, + submitter_did: str, + target_did: str, + hash: str, + raw: str, + enc: str, + request_json: str) -> None: + pass + + +async def build_get_attrib_request(command_handle: int, submitter_did: str, target_did: str, - hash: str, - raw: str, - enc: str, + data: str, request_json: str) -> None: - pass - - async def build_get_attrib_request(command_handle: int, - submitter_did: str, - target_did: str, - data: str, - request_json: str) -> None: - pass - - async def build_get_nym_request(command_handle: int, - submitter_did: str, - target_did: str, - request_json: str) -> None: - pass - - async def build_schema_request(command_handle: int, + pass + + +async def build_get_nym_request(command_handle: int, + submitter_did: str, + target_did: str, + request_json: str) -> None: + pass + + +async def build_schema_request(command_handle: int, + submitter_did: str, + data: str, + request_json: str) -> None: + pass + + +async def build_get_schema_request(command_handle: int, submitter_did: str, data: str, request_json: str) -> None: - pass + pass + + +async def build_claim_def_txn(command_handle: int, + submitter_did: str, + xref: str, + data: str, + request_result_json: str) -> None: + pass - async def build_get_schema_request(command_handle: int, - submitter_did: str, - data: str, - request_json: str) -> None: - pass - async def build_claim_def_txn(command_handle: int, +async def build_get_claim_def_txn(command_handle: int, submitter_did: str, xref: str, - data: str, - request_result_json: str) -> None: - pass - - async def build_get_claim_def_txn(command_handle: int, - submitter_did: str, - xref: str, - request_json: str) -> None: - pass - - async def build_node_request(command_handle: int, - submitter_did: str, - target_did: str, - data: str, - request_json: str) -> None: - pass + request_json: str) -> None: + pass + + +async def build_node_request(command_handle: int, + submitter_did: str, + target_did: str, + data: str, + request_json: str) -> None: + pass diff --git a/wrappers/python/indy/libindy.py b/wrappers/python/indy/libindy.py index 35b1f0ba50..65a9d05986 100644 --- a/wrappers/python/indy/libindy.py +++ b/wrappers/python/indy/libindy.py @@ -1,39 +1,106 @@ -import ctypes +from .error import ErrorCode, IndyError + +from ctypes import * + +import asyncio import sys +import itertools import logging +_futures = {} +_futures_counter = itertools.count() + + +def do_call(name: str, cb: CFUNCTYPE, *args): + logger = logging.getLogger(__name__) + logger.debug("do_call: >>> name: %s, args: %s", name, args) + + event_loop = asyncio.get_event_loop() + future = event_loop.create_future() + command_handle = next(_futures_counter) + + _futures[command_handle] = (event_loop, future) + + err = getattr(_cdll(), name)(command_handle, + *args, + cb) + + logger.debug("do_call: Function %s returned err: %i", name, err) + + if err != ErrorCode.Success: + logger.warning("_do_call: Function %s returned error %i", name, err) + future.set_exception(IndyError(err)) + + logger.debug("do_call: <<< %s", future) + return future + + +def create_cb(cb_type: CFUNCTYPE): + logger = logging.getLogger(__name__) + logger.debug("create_cb: >>> cb_type: %s", cb_type) + + res = cb_type(_indy_callback) + + logger.debug("create_cb: <<< res: %s", res) + return res + + +def _indy_callback(command_handle: int, err: int, *args): + logger = logging.getLogger(__name__) + logger.debug("_indy_callback: >>> command_handle: %i, err %i, args: %s", command_handle, err, args) + + (event_loop, future) = _futures[command_handle] + event_loop.call_soon_threadsafe(_indy_loop_callback, command_handle, err, args) + + logger.debug("_indy_callback: <<<") + + +def _indy_loop_callback(command_handle: int, err, *args): + logger = logging.getLogger(__name__) + logger.debug("_indy_loop_callback: >>> command_handle: %i, err %i, args: %s", command_handle, err, args) + + (event_loop, future) = _futures.pop(command_handle) + + if err != ErrorCode.Success: + logger.warning("_indy_loop_callback: Function returned error %i", err) + future.set_exception(IndyError(err)) + else: + future.set_result(args) + + logger.debug("_indy_loop_callback <<<") + + +def _cdll() -> CDLL: + if not hasattr(_cdll, "cdll"): + _cdll.cdll = _load_cdll() -class LibIndy: - _cdll = None + return _cdll.cdll - @staticmethod - def cdll() -> ctypes.CDLL: - if LibIndy._cdll is None: - LibIndy._cdll = LibIndy._load_cdll() - return LibIndy._cdll - @staticmethod - def _load_cdll() -> ctypes.CDLL: - logger = logging.getLogger(__name__) +def _load_cdll() -> CDLL: + logger = logging.getLogger(__name__) + logger.debug("_load_cdll: >>>") - libindy_prefix_mapping = {'darwin': 'lib', 'linux': 'lib', 'linux2': 'lib', 'win32': ''} - libindy_suffix_mapping = {'darwin': '.dylib', 'linux': '.so', 'linux2': '.so', 'win32': '.dll'} + libindy_prefix_mapping = {"darwin": "lib", "linux": "lib", "linux2": "lib", "win32": ""} + libindy_suffix_mapping = {"darwin": ".dylib", "linux": ".so", "linux2": ".so", "win32": ".dll"} - os_name = sys.platform - logger.debug("Detected OS name is: %s", os_name) + os_name = sys.platform + logger.debug("_load_cdll: Detected OS name: %s", os_name) - try: - libindy_prefix = libindy_prefix_mapping[os_name] - libindy_suffix = libindy_suffix_mapping[os_name] - except KeyError: - logger.error("OS isn't supported: %s", os_name) - raise OSError("OS isn't supported: %s", os_name) + try: + libindy_prefix = libindy_prefix_mapping[os_name] + libindy_suffix = libindy_suffix_mapping[os_name] + except KeyError: + logger.error("_load_cdll: OS isn't supported: %s", os_name) + raise OSError("OS isn't supported: %s", os_name) - libindy_name = libindy_prefix + 'indy' + libindy_suffix - logger.debug("Resolved libindy name is: %s", libindy_name) + libindy_name = "{0}indy{1}".format(libindy_prefix, libindy_suffix) + logger.debug("_load_cdll: Resolved libindy name is: %s", libindy_name) - try: - return ctypes.CDLL(libindy_name) - except OSError as e: - logger.error("Can't load libindy: %s", e) - raise e + try: + res = CDLL(libindy_name) + logger.debug("_load_cdll: <<< res: %s", res) + return res + except OSError as e: + logger.error("_load_cdll: Can't load libindy: %s", e) + raise e diff --git a/wrappers/python/indy/pool.py b/wrappers/python/indy/pool.py index 5c6426bdaa..b872b5d451 100644 --- a/wrappers/python/indy/pool.py +++ b/wrappers/python/indy/pool.py @@ -1,29 +1,26 @@ -from typing import Callable -from . import IndyError +async def create_pool_ledger_config(command_handle: int, + config_name: str, + config: str) -> None: + pass -class Pool(object): - """TODO: document it""" +async def open_pool_ledger(command_handle: int, + config_name: str, + config: str, + pool_handle: int) -> None: + pass - async def create_pool_ledger_config(command_handle: int, - config_name: str, - config: str) -> None: - pass - async def open_pool_ledger(command_handle: int, - config_name: str, - config: str, - pool_handle: int) -> None: - pass +async def refresh_pool_ledger(command_handle: int, + handle: int) -> None: + pass - async def refresh_pool_ledger(command_handle: int, - handle: int) -> None: - pass - async def close_pool_ledger(command_handle: int, - handle: int) -> None: - pass +async def close_pool_ledger(command_handle: int, + handle: int) -> None: + pass - async def delete_pool_ledger_config(command_handle: int, - config_name: str) -> None: - pass + +async def delete_pool_ledger_config(command_handle: int, + config_name: str) -> None: + pass diff --git a/wrappers/python/indy/signus.py b/wrappers/python/indy/signus.py index 5110d7a331..b58fc3ec09 100644 --- a/wrappers/python/indy/signus.py +++ b/wrappers/python/indy/signus.py @@ -1,55 +1,55 @@ -from typing import Callable -from . import IndyError +async def create_and_store_my_did(command_handle: int, + wallet_handle: int, + did_json: str, + did: str, + verkey: str, + pk: str) -> None: + pass -class Signus(object): - """TODO: document it""" - async def create_and_store_my_did(command_handle: int, - wallet_handle: int, - did_json: str, - did: str, - verkey: str, - pk: str) -> None: - pass +async def replace_keys(command_handle: int, + wallet_handle: int, + did: str, + identity_json: str, + verkey: str, + pk: str) -> None: + pass - async def replace_keys(command_handle: int, + +async def store_their_did(command_handle: int, + wallet_handle: int, + identity_json: str) -> None: + pass + + +async def sign(command_handle: int, + wallet_handle: int, + did: str, + msg: str, + signature: str) -> None: + pass + + +async def verify_signature(command_handle: int, wallet_handle: int, did: str, - identity_json: str, - verkey: str, - pk: str) -> None: - pass - - async def store_their_did(command_handle: int, - wallet_handle: int, - identity_json: str) -> None: - pass - - async def sign(command_handle: int, - wallet_handle: int, - did: str, - msg: str, - signature: str) -> None: - pass - - async def verify_signature(command_handle: int, - wallet_handle: int, - did: str, - msg: str, - signature: str, - valid: bool) -> None: - pass - - async def encrypt(command_handle: int, - wallet_handle: int, - did: str, - msg: str, - encrypted_msg: str) -> None: - pass - - async def decrypt(command_handle: int, - wallet_handle: int, - did: str, - encrypted_msg: str, - decrypted_msg: str) -> None: - pass + msg: str, + signature: str, + valid: bool) -> None: + pass + + +async def encrypt(command_handle: int, + wallet_handle: int, + did: str, + msg: str, + encrypted_msg: str) -> None: + pass + + +async def decrypt(command_handle: int, + wallet_handle: int, + did: str, + encrypted_msg: str, + decrypted_msg: str) -> None: + pass diff --git a/wrappers/python/indy/wallet.py b/wrappers/python/indy/wallet.py index e73dd9d3fb..f205af8be8 100644 --- a/wrappers/python/indy/wallet.py +++ b/wrappers/python/indy/wallet.py @@ -1,59 +1,40 @@ -from .libindy import LibIndy -from .error import ErrorCode, IndyError +from .libindy import do_call, create_cb +from typing import Optional from ctypes import * -from asyncio import get_event_loop import logging -class Wallet(object): - _XCOMMAND_HANDLE = 0 - - _CREATE_WALLET_CB_TYPE = CFUNCTYPE(None, c_int32, c_int32) - - @staticmethod - async def create_wallet(pool_name: str, - name: str, - xtype: str, - config: str, - credentials: str) -> None: - logger = logging.getLogger(__name__) - - c_comman_handle = c_int32(Wallet._XCOMMAND_HANDLE) - c_pool_name = c_char_p(pool_name.encode('utf-8')) - c_name = c_char_p(name.encode('utf-8')) - c_xtype = c_char_p(xtype.encode('utf-8')) if xtype is not None else None - c_config = c_char_p(config.encode('utf-8')) if config is not None else None - c_credentials = c_char_p(credentials.encode('utf-8')) if credentials is not None else None - - event_loop = get_event_loop() - future = event_loop.create_future() - - def create_wallet_cb(xcommand_handle: int, err: int): - logger.debug("create_wallet_cb called, xcommand_handle: %i, err: %i", xcommand_handle, err) - event_loop.call_soon_threadsafe(create_wallet_loop_cb, err) - - def create_wallet_loop_cb(err): - logger.debug("create_wallet_loop_cb called, err: %i", err) - future.set_result(err) - - c_cb = Wallet._CREATE_WALLET_CB_TYPE(create_wallet_cb) - - res = LibIndy.cdll().indy_create_wallet(c_comman_handle, - c_pool_name, - c_name, - c_xtype, - c_config, - c_credentials, - c_cb) - - logger.debug("cdll.indy_create_wallet, res: %i", res) - if res != ErrorCode.Success: - raise IndyError(res) - - res = await future - - logger.debug("cdll.indy_create_wallet future, res: %i", res) - if ErrorCode(res) != ErrorCode.Success: - raise IndyError(res) +async def create_wallet(pool_name: str, + name: str, + xtype: Optional[str], + config: Optional[str], + credentials: Optional[str]): + logger = logging.getLogger(__name__) + logger.debug("create_wallet: >>> pool_name: %s, name: %s, xtype: %s, config: %s, credentials: %s", + pool_name, + name, + xtype, + config, + credentials) + + if not hasattr(create_wallet, "cb"): + logger.debug("create_wallet: Creating callback") + create_wallet.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) + + c_pool_name = c_char_p(pool_name.encode('utf-8')) + c_name = c_char_p(name.encode('utf-8')) + c_xtype = c_char_p(xtype.encode('utf-8')) if xtype is not None else None + c_config = c_char_p(config.encode('utf-8')) if config is not None else None + c_credentials = c_char_p(credentials.encode('utf-8')) if credentials is not None else None + + await do_call('indy_create_wallet', + create_wallet.cb, + c_pool_name, + c_name, + c_xtype, + c_config, + c_credentials) + + logger.debug("create_wallet: <<<") diff --git a/wrappers/python/tests/test_libindy.py b/wrappers/python/tests/test_libindy.py deleted file mode 100644 index e63fed869b..0000000000 --- a/wrappers/python/tests/test_libindy.py +++ /dev/null @@ -1,9 +0,0 @@ -from indy.libindy import LibIndy - -import logging - -logging.basicConfig(level=logging.DEBUG) - - -def test_libindy_loading_works(): - assert LibIndy.cdll() is not None diff --git a/wrappers/python/tests/utils/storage.py b/wrappers/python/tests/utils/storage.py index da6ac83b0b..0da89fc19b 100644 --- a/wrappers/python/tests/utils/storage.py +++ b/wrappers/python/tests/utils/storage.py @@ -4,27 +4,41 @@ import logging -class StorageUtils(object): - @staticmethod - def cleanup(): - logger = logging.getLogger(__name__) - tmp_path = StorageUtils.indy_temp_path() - logger.debug("Cleaning tmp path: %s", tmp_path) +def indy_temp_path() -> Path: + logger = logging.getLogger(__name__) + logger.debug("indy_temp_path: >>>") - if tmp_path.exists(): - rmtree(str(tmp_path)) + res = Path(gettempdir()).joinpath("indy") - home_path = StorageUtils.indy_home_path() - logger.debug("Cleaning home path: %s", home_path) + logger.debug("indy_temp_path: <<< res: %s", res) + return res - if home_path.exists(): - rmtree(str(home_path)) - @staticmethod - def indy_home_path() -> Path: - return Path.home().joinpath(".indy") +def indy_home_path() -> Path: + logger = logging.getLogger(__name__) + logger.debug("indy_home_path: >>>") - @staticmethod - def indy_temp_path() -> Path: - return Path(gettempdir()).joinpath("indy") + res = Path.home().joinpath(".indy") + + logger.debug("indy_home_path: <<< res: %s", res) + return res + + +def cleanup(): + logger = logging.getLogger(__name__) + logger.debug("cleanup: >>>") + + tmp_path = indy_temp_path() + + if tmp_path.exists(): + logger.debug("cleanup: Cleaning tmp path: %s", tmp_path) + rmtree(str(tmp_path)) + + home_path = indy_home_path() + + if home_path.exists(): + logger.debug("cleanup: Cleaning home path: %s", home_path) + rmtree(str(home_path)) + + logger.debug("cleanup: <<<") diff --git a/wrappers/python/tests/utils/test_storage.py b/wrappers/python/tests/utils/test_storage.py index 7d7533d63e..0fab92ce70 100644 --- a/wrappers/python/tests/utils/test_storage.py +++ b/wrappers/python/tests/utils/test_storage.py @@ -1,4 +1,4 @@ -from .storage import StorageUtils +from .storage import indy_home_path, indy_temp_path, cleanup import logging @@ -6,14 +6,15 @@ def test_storage_utils_indy_home_path_works(): - home_path = StorageUtils.indy_home_path() + home_path = indy_home_path() assert '.indy' in str(home_path) def test_storage_utils_indy_temp_path_works(): - tmp_path = StorageUtils.indy_temp_path() + tmp_path = indy_temp_path() assert 'indy' in str(tmp_path) def test_storage_utils_cleanup_works(): - StorageUtils.cleanup() + cleanup() + assert True diff --git a/wrappers/python/tests/wallet/test_create_wallet.py b/wrappers/python/tests/wallet/test_create_wallet.py index e89190832f..6138e667fc 100644 --- a/wrappers/python/tests/wallet/test_create_wallet.py +++ b/wrappers/python/tests/wallet/test_create_wallet.py @@ -1,6 +1,6 @@ -from indy import Wallet +from indy import wallet -from ..utils.storage import StorageUtils +from ..utils import storage import pytest import logging @@ -8,14 +8,17 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.mark.asyncio -async def test_indy_create_wallet_works(): - StorageUtils.cleanup() +@pytest.yield_fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + +@pytest.mark.asyncio +async def test_create_wallet_works(): pool_name = 'indy_create_wallet_works' wallet_name = 'indy_create_wallet_works' xtype = 'default' - await Wallet.create_wallet(pool_name, wallet_name, xtype, None, None) - - StorageUtils.cleanup() + await wallet.create_wallet(pool_name, wallet_name, xtype, None, None) From 6d728cec3fcd6354edff18c60d6e682843383b2c Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 14 Jul 2017 16:24:13 +0300 Subject: [PATCH 173/349] Updated jenkins file --- Jenkinsfile | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index cc18dd91db..c34ee292d8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -71,7 +71,7 @@ try { } } -def testPipeline(file, env_name) { +def testPipeline(file, env_name, run_interoperability_tests) { def poolInst def network_name = "pool_network" try { @@ -82,7 +82,7 @@ def testPipeline(file, env_name) { sh "docker network create --subnet=10.0.0.0/8 ${network_name}" echo "${env_name} Test: Build docker image for nodes pool" - def poolEnv = dockerHelpers.build('sovrin_pool', 'ci/sovrin-pool.dockerfile ci') + def poolEnv = dockerHelpers.build('indy_pool', 'ci/indy-pool.dockerfile ci') echo "${env_name} Test: Run nodes pool" poolInst = poolEnv.run("--ip=\"10.0.0.2\" --network=${network_name}") @@ -95,7 +95,12 @@ def testPipeline(file, env_name) { sh 'cargo update' try { - sh 'RUST_BACKTRACE=1 RUST_TEST_THREADS=1 cargo test --features "interoperability_tests"' + if (run_interoperability_tests) { + sh 'RUST_BACKTRACE=1 RUST_TEST_THREADS=1 cargo test --features "interoperability_tests"' + } + else { + sh 'RUST_BACKTRACE=1 RUST_TEST_THREADS=1 cargo test' + } /* TODO FIXME restore after xunit will be fixed sh 'RUST_TEST_THREADS=1 cargo test-xunit' */ @@ -132,11 +137,11 @@ def testPipeline(file, env_name) { } def testUbuntu() { - testPipeline("ci/ubuntu.dockerfile ci", "Ubuntu") + testPipeline("ci/ubuntu.dockerfile ci", "Ubuntu", true) } def testRedHat() { - testPipeline("ci/amazon.dockerfile ci", "RedHat") + testPipeline("ci/amazon.dockerfile ci", "RedHat", false) } def publishToCargo() { From 1f293ab1c640463ac7733f6f873b58b185f2a870 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 14 Jul 2017 16:39:50 +0300 Subject: [PATCH 174/349] force install libsodium --- ci/amazon.dockerfile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 2690d3eef8..bbf3f9e637 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -17,6 +17,18 @@ RUN \ libsodium-devel \ spectool + +RUN cd /tmp && \ + curl https://download.libsodium.org/libsodium/releases/libsodium-1.0.12.tar.gz | tar -xz && \ + cd /tmp/libsodium-1.0.12 && \ + ./configure && \ + make && \ + make install && \ + rm -rf /tmp/libsodium-1.0.12 + +ENV PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig +ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib + ENV RUST_ARCHIVE=rust-1.16.0-x86_64-unknown-linux-gnu.tar.gz ENV RUST_DOWNLOAD_URL=https://static.rust-lang.org/dist/$RUST_ARCHIVE From 64fbbbdbb0c6ef7a77e5b55d45c7744b9c5d8c1a Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 14 Jul 2017 16:54:04 +0300 Subject: [PATCH 175/349] added tests --- include/indy_mod.h | 60 ++++++++++----------- src/api/mod.rs | 60 ++++++++++----------- tests/utils/wallet.rs | 4 +- tests/wallet.rs | 118 +++++++++++++++++++++++++++++++++++++++--- 4 files changed, 174 insertions(+), 68 deletions(-) diff --git a/include/indy_mod.h b/include/indy_mod.h index 01905bbb72..44c3a6e395 100644 --- a/include/indy_mod.h +++ b/include/indy_mod.h @@ -11,101 +11,101 @@ typedef enum CommonInvalidParam1 = 100, // Caller passed invalid value as param 2 (null, invalid json and etc..) - CommonInvalidParam2, + CommonInvalidParam2 = 101, // Caller passed invalid value as param 3 (null, invalid json and etc..) - CommonInvalidParam3, + CommonInvalidParam3 = 102, // Caller passed invalid value as param 4 (null, invalid json and etc..) - CommonInvalidParam4, + CommonInvalidParam4 = 103, // Caller passed invalid value as param 5 (null, invalid json and etc..) - CommonInvalidParam5, + CommonInvalidParam5 = 104, // Caller passed invalid value as param 6 (null, invalid json and etc..) - CommonInvalidParam6, + CommonInvalidParam6 = 105, // Caller passed invalid value as param 7 (null, invalid json and etc..) - CommonInvalidParam7, + CommonInvalidParam7 = 106, // Caller passed invalid value as param 8 (null, invalid json and etc..) - CommonInvalidParam8, + CommonInvalidParam8 = 107, // Caller passed invalid value as param 9 (null, invalid json and etc..) - CommonInvalidParam9, + CommonInvalidParam9 = 108, // Caller passed invalid value as param 10 (null, invalid json and etc..) - CommonInvalidParam10, + CommonInvalidParam10 = 109, // Caller passed invalid value as param 11 (null, invalid json and etc..) - CommonInvalidParam11, + CommonInvalidParam11 = 110, // Caller passed invalid value as param 12 (null, invalid json and etc..) - CommonInvalidParam12, + CommonInvalidParam12 = 111, // Invalid library state was detected in runtime. It signals library bug - CommonInvalidState, + CommonInvalidState = 112, // Object (json, config, key, claim and etc...) passed by library caller has invalid structure - CommonInvalidStructure, + CommonInvalidStructure = 113, // IO Error - CommonIOError, + CommonIOError = 114, // Wallet errors // Caller passed invalid wallet handle WalletInvalidHandle = 200, // Unknown type of wallet was passed on create_wallet - WalletUnknownTypeError, + WalletUnknownTypeError = 201, // Attempt to register already existing wallet type - WalletTypeAlreadyRegisteredError, + WalletTypeAlreadyRegisteredError = 202, // Attempt to create wallet with name used for another exists wallet - WalletAlreadyExistsError, + WalletAlreadyExistsError = 203, // Requested entity id isn't present in wallet - WalletNotFoundError, + WalletNotFoundError = 204, // Trying to use wallet with pool that has different name - WalletIncompatiblePoolError, + WalletIncompatiblePoolError = 205, // Trying to open wallet that was opened already - WalletAlreadyOpenedError, + WalletAlreadyOpenedError = 206, // Ledger errors // Trying to open pool ledger that wasn't created before PoolLedgerNotCreatedError = 300, // Caller passed invalid pool ledger handle - PoolLedgerInvalidPoolHandle, + PoolLedgerInvalidPoolHandle = 301, // Pool ledger terminated - PoolLedgerTerminated, + PoolLedgerTerminated = 302, // No concensus during ledger operation - LedgerNoConsensusError, + LedgerNoConsensusError = 303, // Attempt to send unknown or incomplete transaction message - LedgerInvalidTransaction, + LedgerInvalidTransaction = 304, // Attempt to send transaction without the necessary privileges - LedgerSecurityError, + LedgerSecurityError = 305, // Revocation registry is full and creation of new registry is necessary AnoncredsRevocationRegistryFullError = 400, - AnoncredsInvalidUserRevocIndex, + AnoncredsInvalidUserRevocIndex = 401, - AnoncredsAccumulatorIsFull, + AnoncredsAccumulatorIsFull = 402, - AnoncredsNotIssuedError, + AnoncredsNotIssuedError = 403, // Attempt to generate master secret with dupplicated name - AnoncredsMasterSecretDuplicateNameError, + AnoncredsMasterSecretDuplicateNameError = 404, - AnoncredsProofRejected, + AnoncredsProofRejected = 405, // Signus errors // Unknown format of DID entity keys diff --git a/src/api/mod.rs b/src/api/mod.rs index aa802e6798..b3d385eb8e 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -21,101 +21,101 @@ pub enum ErrorCode CommonInvalidParam1 = 100, // Caller passed invalid value as param 2 (null, invalid json and etc..) - CommonInvalidParam2, + CommonInvalidParam2 = 101, // Caller passed invalid value as param 3 (null, invalid json and etc..) - CommonInvalidParam3, + CommonInvalidParam3 = 102, // Caller passed invalid value as param 4 (null, invalid json and etc..) - CommonInvalidParam4, + CommonInvalidParam4 = 103, // Caller passed invalid value as param 5 (null, invalid json and etc..) - CommonInvalidParam5, + CommonInvalidParam5 = 104, // Caller passed invalid value as param 6 (null, invalid json and etc..) - CommonInvalidParam6, + CommonInvalidParam6 = 105, // Caller passed invalid value as param 7 (null, invalid json and etc..) - CommonInvalidParam7, + CommonInvalidParam7 = 106, // Caller passed invalid value as param 8 (null, invalid json and etc..) - CommonInvalidParam8, + CommonInvalidParam8 = 107, // Caller passed invalid value as param 9 (null, invalid json and etc..) - CommonInvalidParam9, + CommonInvalidParam9 = 108, // Caller passed invalid value as param 10 (null, invalid json and etc..) - CommonInvalidParam10, + CommonInvalidParam10 = 109, // Caller passed invalid value as param 11 (null, invalid json and etc..) - CommonInvalidParam11, + CommonInvalidParam11 = 110, // Caller passed invalid value as param 11 (null, invalid json and etc..) - CommonInvalidParam12, + CommonInvalidParam12 = 111, // Invalid library state was detected in runtime. It signals library bug - CommonInvalidState, + CommonInvalidState = 112, // Object (json, config, key, claim and etc...) passed by library caller has invalid structure - CommonInvalidStructure, + CommonInvalidStructure = 113, // IO Error - CommonIOError, + CommonIOError = 114, // Wallet errors // Caller passed invalid wallet handle WalletInvalidHandle = 200, // Unknown type of wallet was passed on create_wallet - WalletUnknownTypeError, + WalletUnknownTypeError = 201, // Attempt to register already existing wallet type - WalletTypeAlreadyRegisteredError, + WalletTypeAlreadyRegisteredError = 202, // Attempt to create wallet with name used for another exists wallet - WalletAlreadyExistsError, + WalletAlreadyExistsError = 203, // Requested entity id isn't present in wallet - WalletNotFoundError, + WalletNotFoundError = 204, // Trying to use wallet with pool that has different name - WalletIncompatiblePoolError, + WalletIncompatiblePoolError = 205, // Trying to open wallet that was opened already - WalletAlreadyOpenedError, + WalletAlreadyOpenedError = 206, // Ledger errors // Trying to open pool ledger that wasn't created before PoolLedgerNotCreatedError = 300, // Caller passed invalid pool ledger handle - PoolLedgerInvalidPoolHandle, + PoolLedgerInvalidPoolHandle = 301, // Pool ledger terminated - PoolLedgerTerminated, + PoolLedgerTerminated = 302, // No concensus during ledger operation - LedgerNoConsensusError, + LedgerNoConsensusError = 303, // Attempt to send unknown or incomplete transaction message - LedgerInvalidTransaction, + LedgerInvalidTransaction = 304, // Attempt to send transaction without the necessary privileges - LedgerSecurityError, + LedgerSecurityError = 305, // Revocation registry is full and creation of new registry is necessary AnoncredsRevocationRegistryFullError = 400, - AnoncredsInvalidUserRevocIndex, + AnoncredsInvalidUserRevocIndex = 401, - AnoncredsAccumulatorIsFull, + AnoncredsAccumulatorIsFull = 402, - AnoncredsNotIssuedError, + AnoncredsNotIssuedError = 403, // Attempt to generate master secret with dupplicated name - AnoncredsMasterSecretDuplicateNameError, + AnoncredsMasterSecretDuplicateNameError = 404, - AnoncredsProofRejected, + AnoncredsProofRejected = 405, // Signus errors // Unknown format of DID entity keys diff --git a/tests/utils/wallet.rs b/tests/utils/wallet.rs index 1ecd2e4202..56d11f3ab9 100644 --- a/tests/utils/wallet.rs +++ b/tests/utils/wallet.rs @@ -23,14 +23,14 @@ pub struct WalletUtils {} impl WalletUtils { - pub fn register_wallet_type(xtype: &str) -> Result<(), ErrorCode> { + pub fn register_wallet_type(xtype: &str, force_create: bool) -> Result<(), ErrorCode> { lazy_static! { static ref REGISERED_WALLETS: Mutex> = Default::default(); } let mut wallets = REGISERED_WALLETS.lock().unwrap(); - if wallets.contains(xtype) { + if wallets.contains(xtype) & !force_create { // as registering of plugged wallet with return Ok(()) } diff --git a/tests/wallet.rs b/tests/wallet.rs index 4b0519f3a4..69cc967e87 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -32,7 +32,7 @@ mod high_cases { TestUtils::cleanup_storage(); InmemWallet::cleanup(); - WalletUtils::register_wallet_type("inmem").unwrap(); + WalletUtils::register_wallet_type("inmem", false).unwrap(); TestUtils::cleanup_storage(); InmemWallet::cleanup(); @@ -64,7 +64,7 @@ mod high_cases { let wallet_name = "indy_create_wallet_works"; let xtype = "inmem"; - WalletUtils::register_wallet_type("inmem").unwrap(); + WalletUtils::register_wallet_type("inmem", false).unwrap(); WalletUtils::create_wallet(pool_name, wallet_name, Some(xtype), None).unwrap(); TestUtils::cleanup_storage(); @@ -138,7 +138,7 @@ mod high_cases { let wallet_name = "indy_delete_wallet_works_for_plugged"; let xtype = "inmem"; - WalletUtils::register_wallet_type(xtype).unwrap(); + WalletUtils::register_wallet_type(xtype, false).unwrap(); WalletUtils::create_wallet(pool_name, wallet_name, Some(xtype), None).unwrap(); WalletUtils::delete_wallet(wallet_name).unwrap(); WalletUtils::create_wallet(pool_name, wallet_name, Some(xtype), None).unwrap(); @@ -173,7 +173,7 @@ mod high_cases { let wallet_name = "indy_open_wallet_works_for_plugged"; let xtype = "inmem"; - WalletUtils::register_wallet_type(xtype).unwrap(); + WalletUtils::register_wallet_type(xtype, false).unwrap(); WalletUtils::create_wallet(pool_name, wallet_name, Some(xtype), None).unwrap(); WalletUtils::open_wallet(wallet_name, None).unwrap(); @@ -224,7 +224,7 @@ mod high_cases { let wallet_name = "indy_close_wallet_works_for_plugged"; let xtype = "inmem"; - WalletUtils::register_wallet_type(xtype).unwrap(); + WalletUtils::register_wallet_type(xtype, false).unwrap(); WalletUtils::create_wallet(pool_name, wallet_name, Some(xtype), None).unwrap(); let wallet_handle = WalletUtils::open_wallet(wallet_name, None).unwrap(); @@ -259,7 +259,7 @@ mod high_cases { let xtype = "inmem"; - WalletUtils::register_wallet_type(xtype).unwrap(); + WalletUtils::register_wallet_type(xtype, false).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet("indy_wallet_set_seqno_works_for_plugged", Some(xtype)).unwrap(); let (did, _, _) = SignusUtils::create_my_did(wallet_handle, "{}").unwrap(); @@ -273,7 +273,113 @@ mod high_cases { } mod medium_cases { + extern crate libc; use super::*; + use std::ffi::CString; + use self::libc::c_char; + + mod register_wallet_type { + use super::*; + use indy::api::wallet::indy_register_wallet_type; + + #[test] + fn indy_register_wallet_type_does_not_work_twice_with_same_name() { + TestUtils::cleanup_storage(); + InmemWallet::cleanup(); + + WalletUtils::register_wallet_type("inmem", false).unwrap(); + let res = WalletUtils::register_wallet_type("inmem", true); + + assert_eq!(res.unwrap_err(), ErrorCode::WalletTypeAlreadyRegisteredError); + TestUtils::cleanup_storage(); + InmemWallet::cleanup(); + } + + #[test] + fn indy_register_wallet_type_does_not_work_with_null_params() { + TestUtils::cleanup_storage(); + InmemWallet::cleanup(); + + let xtype = CString::new("inmem").unwrap(); + let res = indy_register_wallet_type(1, xtype.as_ptr(), None, None, None, None, None, + None, None, None, None, None); + assert_eq!(res, ErrorCode::CommonInvalidParam3); + + extern "C" fn callback(_: *const c_char, _: *const c_char, + _: *const c_char) -> ErrorCode { + ErrorCode::Success + } + + let res = indy_register_wallet_type(1, xtype.as_ptr(), Some(callback), None, None, None, + None, None, None, None, None, None); + assert_eq!(res, ErrorCode::CommonInvalidParam4); + + extern "C" fn callback1(_: *const c_char, _: *const c_char, _: *const c_char, + _: *const c_char, _: *mut i32) -> ErrorCode { + ErrorCode::Success + } + + let res = indy_register_wallet_type(1, xtype.as_ptr(), Some(callback), Some(callback1), + None, None, None, None, None, None, None, None); + assert_eq!(res, ErrorCode::CommonInvalidParam5); + + extern "C" fn callback2(_: i32, _: *const c_char, _: *const c_char) -> ErrorCode { + ErrorCode::Success + } + + let res = indy_register_wallet_type(1, xtype.as_ptr(), Some(callback), Some(callback1), + Some(callback2), None, None, None, None, None, + None, None); + assert_eq!(res, ErrorCode::CommonInvalidParam6); + + extern "C" fn callback3(_: i32, _: *const c_char, _: *mut *const c_char) -> ErrorCode { + ErrorCode::Success + } + + let res = indy_register_wallet_type(1, xtype.as_ptr(), Some(callback), Some(callback1), + Some(callback2), Some(callback3), None, None, None, + None, None, None); + assert_eq!(res, ErrorCode::CommonInvalidParam7); + + let res = indy_register_wallet_type(1, xtype.as_ptr(), Some(callback), Some(callback1), + Some(callback2), Some(callback3), Some(callback3), + None, None, None, None, None); + assert_eq!(res, ErrorCode::CommonInvalidParam8); + + let res = indy_register_wallet_type(1, xtype.as_ptr(), Some(callback), Some(callback1), + Some(callback2), Some(callback3), Some(callback3), + Some(callback3), None, None, None, None); + assert_eq!(res, ErrorCode::CommonInvalidParam9); + + extern "C" fn callback4(_: i32) -> ErrorCode { + ErrorCode::Success + } + + let res = indy_register_wallet_type(1, xtype.as_ptr(), Some(callback), Some(callback1), + Some(callback2), Some(callback3), Some(callback3), + Some(callback3), Some(callback4), None, None, None); + assert_eq!(res, ErrorCode::CommonInvalidParam10); + + let res = indy_register_wallet_type(1, xtype.as_ptr(), Some(callback), Some(callback1), + Some(callback2), Some(callback3), Some(callback3), + Some(callback3), Some(callback4), Some(callback), + None, None); + assert_eq!(res, ErrorCode::CommonInvalidParam11); + + extern "C" fn callback5(_: i32, _: *const c_char) -> ErrorCode { + ErrorCode::Success + } + + let res = indy_register_wallet_type(1, xtype.as_ptr(), Some(callback), Some(callback1), + Some(callback2), Some(callback3), Some(callback3), + Some(callback3), Some(callback4), Some(callback), + Some(callback5), None); + assert_eq!(res, ErrorCode::CommonInvalidParam12); + + TestUtils::cleanup_storage(); + InmemWallet::cleanup(); + } + } mod create_wallet { use super::*; From 7a87d178964476c392a5151bab1e1af5b310987c Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Fri, 14 Jul 2017 17:08:26 +0300 Subject: [PATCH 176/349] * libindy now performs conversion of tupple result to scalar * Bugfixes in libindy * Implemented open_wallet call and simple tests --- wrappers/python/indy/libindy.py | 12 +++++++-- wrappers/python/indy/wallet.py | 27 +++++++++++++++++++ .../python/tests/wallet/test_open_wallet.py | 25 +++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 wrappers/python/tests/wallet/test_open_wallet.py diff --git a/wrappers/python/indy/libindy.py b/wrappers/python/indy/libindy.py index 65a9d05986..394cccef10 100644 --- a/wrappers/python/indy/libindy.py +++ b/wrappers/python/indy/libindy.py @@ -50,7 +50,7 @@ def _indy_callback(command_handle: int, err: int, *args): logger.debug("_indy_callback: >>> command_handle: %i, err %i, args: %s", command_handle, err, args) (event_loop, future) = _futures[command_handle] - event_loop.call_soon_threadsafe(_indy_loop_callback, command_handle, err, args) + event_loop.call_soon_threadsafe(_indy_loop_callback, command_handle, err, *args) logger.debug("_indy_callback: <<<") @@ -65,7 +65,15 @@ def _indy_loop_callback(command_handle: int, err, *args): logger.warning("_indy_loop_callback: Function returned error %i", err) future.set_exception(IndyError(err)) else: - future.set_result(args) + if len(args) == 0: + res = None + elif len(args) == 1: + (res,) = args + else: + res = args + + logger.warning("_indy_loop_callback: Function returned %s", res) + future.set_result(res) logger.debug("_indy_loop_callback <<<") diff --git a/wrappers/python/indy/wallet.py b/wrappers/python/indy/wallet.py index f205af8be8..85e501d007 100644 --- a/wrappers/python/indy/wallet.py +++ b/wrappers/python/indy/wallet.py @@ -38,3 +38,30 @@ async def create_wallet(pool_name: str, c_credentials) logger.debug("create_wallet: <<<") + + +async def open_wallet(name: str, + runtime_config: Optional[str], + credentials: Optional[str]): + logger = logging.getLogger(__name__) + logger.debug("open_wallet: >>> name: %s, runtime_config: %s, credentials: %s", + name, + runtime_config, + credentials) + + if not hasattr(open_wallet, "cb"): + logger.debug("open_wallet: Creating callback") + open_wallet.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_int32)) + + c_name = c_char_p(name.encode('utf-8')) + c_runtime_config = c_char_p(runtime_config.encode('utf-8')) if runtime_config is not None else None + c_credentials = c_char_p(credentials.encode('utf-8')) if credentials is not None else None + + res = await do_call('indy_open_wallet', + open_wallet.cb, + c_name, + c_runtime_config, + c_credentials) + + logger.debug("open_wallet: <<< res: %s", res) + return res diff --git a/wrappers/python/tests/wallet/test_open_wallet.py b/wrappers/python/tests/wallet/test_open_wallet.py new file mode 100644 index 0000000000..9d42ee372d --- /dev/null +++ b/wrappers/python/tests/wallet/test_open_wallet.py @@ -0,0 +1,25 @@ +from indy import wallet + +from ..utils import storage + +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.yield_fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_open_wallet_works(): + pool_name = "indy_open_wallet_works" + wallet_name = "indy_open_wallet_works" + + await wallet.create_wallet(pool_name, wallet_name, None, None, None) + wallet_handle = await wallet.open_wallet(wallet_name, None, None) + assert wallet_handle is not None From 5e7e85e05522cb7ebe17b46a0c4e953006c7fa7c Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Fri, 14 Jul 2017 17:10:43 +0300 Subject: [PATCH 177/349] Fix spaces in demo tests. --- tests/demo.rs | 264 +++++++++++++++++++++++++------------------------- 1 file changed, 132 insertions(+), 132 deletions(-) diff --git a/tests/demo.rs b/tests/demo.rs index 5644255a77..c8424615f5 100644 --- a/tests/demo.rs +++ b/tests/demo.rs @@ -139,12 +139,12 @@ fn anoncreds_demo_works() { //1. Create Wallet let err = indy_create_wallet(create_wallet_command_handle, - CString::new(pool_name).unwrap().as_ptr(), - CString::new(wallet_name).unwrap().as_ptr(), - CString::new(xtype).unwrap().as_ptr(), - null(), - null(), - create_wallet_callback); + CString::new(pool_name).unwrap().as_ptr(), + CString::new(wallet_name).unwrap().as_ptr(), + CString::new(xtype).unwrap().as_ptr(), + null(), + null(), + create_wallet_callback); assert_eq!(ErrorCode::Success, err); let err = create_wallet_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -153,10 +153,10 @@ fn anoncreds_demo_works() { //2. Open Issuer Wallet. Gets Issuer wallet handle let err = indy_open_wallet(open_wallet_command_handle, - CString::new(wallet_name).unwrap().as_ptr(), - null(), - null(), - open_wallet_callback); + CString::new(wallet_name).unwrap().as_ptr(), + null(), + null(), + open_wallet_callback); assert_eq!(ErrorCode::Success, err); let (err, wallet_handle) = open_wallet_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -176,12 +176,12 @@ fn anoncreds_demo_works() { // 3. Issuer create Claim Definition for Schema let err = indy_issuer_create_and_store_claim_def(issuer_create_claim_definition_command_handle, - wallet_handle, - CString::new(issuer_did.clone()).unwrap().as_ptr(), - CString::new(schema.clone()).unwrap().as_ptr(), - null(), - false, - create_claim_definition_callback); + wallet_handle, + CString::new(issuer_did.clone()).unwrap().as_ptr(), + CString::new(schema.clone()).unwrap().as_ptr(), + null(), + false, + create_claim_definition_callback); assert_eq!(ErrorCode::Success, err); let (err, claim_def_json) = issuer_create_claim_definition_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -221,9 +221,9 @@ fn anoncreds_demo_works() { // 5. Prover create Master Secret let err = indy_prover_create_master_secret(prover_create_master_secret_command_handle, - wallet_handle, - CString::new(master_secret_name).unwrap().as_ptr(), - prover_create_master_secret_callback); + wallet_handle, + CString::new(master_secret_name).unwrap().as_ptr(), + prover_create_master_secret_callback); assert_eq!(ErrorCode::Success, err); let err = prover_create_master_secret_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -235,12 +235,12 @@ fn anoncreds_demo_works() { // 6. Prover create Claim Request let err = indy_prover_create_and_store_claim_req(prover_create_claim_req_command_handle, - wallet_handle, - CString::new(prover_did).unwrap().as_ptr(), - CString::new(claim_offer_json).unwrap().as_ptr(), - CString::new(claim_def_json.clone()).unwrap().as_ptr(), - CString::new(master_secret_name).unwrap().as_ptr(), - prover_create_claim_req_callback); + wallet_handle, + CString::new(prover_did).unwrap().as_ptr(), + CString::new(claim_offer_json).unwrap().as_ptr(), + CString::new(claim_def_json.clone()).unwrap().as_ptr(), + CString::new(master_secret_name).unwrap().as_ptr(), + prover_create_claim_req_callback); assert_eq!(ErrorCode::Success, err); let (err, claim_req_json) = prover_create_claim_req_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -257,12 +257,12 @@ fn anoncreds_demo_works() { // 7. Issuer create Claim for Claim Request let err = indy_issuer_create_claim(issuer_create_claim_command_handle, - wallet_handle, - CString::new(claim_req_json).unwrap().as_ptr(), - CString::new(claim_json).unwrap().as_ptr(), - -1, - -1, - issuer_create_claim_callback); + wallet_handle, + CString::new(claim_req_json).unwrap().as_ptr(), + CString::new(claim_json).unwrap().as_ptr(), + -1, + -1, + issuer_create_claim_callback); assert_eq!(ErrorCode::Success, err); let (err, _, xclaim_json) = issuer_create_claim_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -272,9 +272,9 @@ fn anoncreds_demo_works() { // 7. Prover process and store Claim let err = indy_prover_store_claim(prover_store_claim_command_handle, - wallet_handle, - CString::new(xclaim_json).unwrap().as_ptr(), - prover_store_claim_callback); + wallet_handle, + CString::new(xclaim_json).unwrap().as_ptr(), + prover_store_claim_callback); assert_eq!(ErrorCode::Success, err); let err = prover_store_claim_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -291,9 +291,9 @@ fn anoncreds_demo_works() { // 8. Prover gets Claims for Proof Request let err = indy_prover_get_claims_for_proof_req(prover_get_claims_for_proof_req_handle, - wallet_handle, - CString::new(proof_req_json.clone()).unwrap().as_ptr(), - prover_get_claims_for_proof_req_callback); + wallet_handle, + CString::new(proof_req_json.clone()).unwrap().as_ptr(), + prover_get_claims_for_proof_req_callback); assert_eq!(ErrorCode::Success, err); let (err, claims_json) = prover_get_claims_for_proof_req_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -320,14 +320,14 @@ fn anoncreds_demo_works() { // 9. Prover create Proof for Proof Request let err = indy_prover_create_proof(prover_create_proof_handle, - wallet_handle, - CString::new(proof_req_json.clone()).unwrap().as_ptr(), - CString::new(requested_claims_json).unwrap().as_ptr(), - CString::new(schemas_json.clone()).unwrap().as_ptr(), - CString::new(master_secret_name).unwrap().as_ptr(), - CString::new(claim_defs_json.clone()).unwrap().as_ptr(), - CString::new(revoc_regs_jsons.clone()).unwrap().as_ptr(), - prover_create_proof_callback); + wallet_handle, + CString::new(proof_req_json.clone()).unwrap().as_ptr(), + CString::new(requested_claims_json).unwrap().as_ptr(), + CString::new(schemas_json.clone()).unwrap().as_ptr(), + CString::new(master_secret_name).unwrap().as_ptr(), + CString::new(claim_defs_json.clone()).unwrap().as_ptr(), + CString::new(revoc_regs_jsons.clone()).unwrap().as_ptr(), + prover_create_proof_callback); assert_eq!(ErrorCode::Success, err); let (err, proof_json) = prover_create_proof_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -337,12 +337,12 @@ fn anoncreds_demo_works() { // 10. Verifier verify proof let err = indy_verifier_verify_proof(verifier_verify_proof_handle, - CString::new(proof_req_json).unwrap().as_ptr(), - CString::new(proof_json).unwrap().as_ptr(), - CString::new(schemas_json).unwrap().as_ptr(), - CString::new(claim_defs_json).unwrap().as_ptr(), - CString::new(revoc_regs_jsons).unwrap().as_ptr(), - verifier_verify_proof_callback); + CString::new(proof_req_json).unwrap().as_ptr(), + CString::new(proof_json).unwrap().as_ptr(), + CString::new(schemas_json).unwrap().as_ptr(), + CString::new(claim_defs_json).unwrap().as_ptr(), + CString::new(revoc_regs_jsons).unwrap().as_ptr(), + verifier_verify_proof_callback); assert_eq!(ErrorCode::Success, err); let (err, result) = verifier_verify_proof_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -400,18 +400,18 @@ fn ledger_demo_works() { PoolUtils::create_genesis_txn_file(format!("{}.txn", pool_name).as_str(), None); let pool_config = CString::new(PoolUtils::create_default_pool_config(pool_name)).unwrap(); let err = indy_create_pool_ledger_config(create_command_handle, - c_pool_name.as_ptr(), - pool_config.as_ptr(), - create_callback); + c_pool_name.as_ptr(), + pool_config.as_ptr(), + create_callback); assert_eq!(err, ErrorCode::Success); let err = create_receiver.recv_timeout(TimeoutUtils::short_timeout()).unwrap(); assert_eq!(err, ErrorCode::Success); // 2. Open pool ledger let err = indy_open_pool_ledger(open_command_handle, - c_pool_name.as_ptr(), - null(), - open_callback); + c_pool_name.as_ptr(), + null(), + open_callback); assert_eq!(err, ErrorCode::Success); let (err, pool_handle) = open_receiver.recv_timeout(TimeoutUtils::short_timeout()).unwrap(); assert_eq!(err, ErrorCode::Success); @@ -420,12 +420,12 @@ fn ledger_demo_works() { // 3. Create My Wallet let err = indy_create_wallet(create_my_wallet_command_handle, - CString::new(pool_name).unwrap().as_ptr(), - CString::new(my_wallet_name).unwrap().as_ptr(), - CString::new(wallet_type).unwrap().as_ptr(), - null(), - null(), - create_my_wallet_callback); + CString::new(pool_name).unwrap().as_ptr(), + CString::new(my_wallet_name).unwrap().as_ptr(), + CString::new(wallet_type).unwrap().as_ptr(), + null(), + null(), + create_my_wallet_callback); assert_eq!(ErrorCode::Success, err); let err = create_my_wallet_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -434,10 +434,10 @@ fn ledger_demo_works() { // 4. Open My Wallet. Gets My wallet handle let err = indy_open_wallet(open_my_wallet_command_handle, - CString::new(my_wallet_name).unwrap().as_ptr(), - null(), - null(), - open_my_wallet_callback); + CString::new(my_wallet_name).unwrap().as_ptr(), + null(), + null(), + open_my_wallet_callback); assert_eq!(ErrorCode::Success, err); let (err, my_wallet_handle) = open_my_wallet_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -447,12 +447,12 @@ fn ledger_demo_works() { // 5. Create Their Wallet let err = indy_create_wallet(create_their_wallet_command_handle, - CString::new(pool_name).unwrap().as_ptr(), - CString::new(their_wallet_name).unwrap().as_ptr(), - CString::new(wallet_type).unwrap().as_ptr(), - null(), - null(), - create_their_wallet_callback); + CString::new(pool_name).unwrap().as_ptr(), + CString::new(their_wallet_name).unwrap().as_ptr(), + CString::new(wallet_type).unwrap().as_ptr(), + null(), + null(), + create_their_wallet_callback); assert_eq!(ErrorCode::Success, err); let err = create_their_wallet_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -461,10 +461,10 @@ fn ledger_demo_works() { // 6. Open Their Wallet. Gets Their wallet handle let err = indy_open_wallet(open_their_wallet_command_handle, - CString::new(their_wallet_name).unwrap().as_ptr(), - null(), - null(), - open_their_wallet_callback); + CString::new(their_wallet_name).unwrap().as_ptr(), + null(), + null(), + open_their_wallet_callback); assert_eq!(ErrorCode::Success, err); let (err, their_wallet_handle) = open_their_wallet_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -474,9 +474,9 @@ fn ledger_demo_works() { let my_did_json = "{}"; let err = indy_create_and_store_my_did(create_and_store_my_did_command_handle, - my_wallet_handle, - CString::new(my_did_json).unwrap().as_ptr(), - create_and_store_my_did_callback); + my_wallet_handle, + CString::new(my_did_json).unwrap().as_ptr(), + create_and_store_my_did_callback); assert_eq!(ErrorCode::Success, err); let (err, my_did, my_verkey, my_pk) = create_and_store_my_did_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -489,9 +489,9 @@ fn ledger_demo_works() { let their_did_json = r#"{"seed":"000000000000000000000000Trustee1"}"#; let err = indy_create_and_store_my_did(create_and_store_their_did_command_handle, - their_wallet_handle, - CString::new(their_did_json).unwrap().as_ptr(), - create_and_store_their_did_callback); + their_wallet_handle, + CString::new(their_did_json).unwrap().as_ptr(), + create_and_store_their_did_callback); assert_eq!(ErrorCode::Success, err); let (err, their_did, their_verkey, their_pk) = create_and_store_their_did_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -508,9 +508,9 @@ fn ledger_demo_works() { their_did, their_pk, their_verkey); let err = indy_store_their_did(store_their_did_command_handle, - my_wallet_handle, - CString::new(their_identity_json).unwrap().as_ptr(), - store_their_did_callback); + my_wallet_handle, + CString::new(their_identity_json).unwrap().as_ptr(), + store_their_did_callback); assert_eq!(ErrorCode::Success, err); let err = store_their_did_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -533,11 +533,11 @@ fn ledger_demo_works() { let req = CString::new(msg).unwrap(); let did_for_sign = CString::new(their_did).unwrap(); let err = indy_sign_and_submit_request(send_command_handle, - pool_handle, - their_wallet_handle, - did_for_sign.as_ptr(), - req.as_ptr(), - send_callback); + pool_handle, + their_wallet_handle, + did_for_sign.as_ptr(), + req.as_ptr(), + send_callback); assert_eq!(err, ErrorCode::Success); let (err, resp) = submit_receiver.recv_timeout(TimeoutUtils::medium_timeout()).unwrap(); assert_eq!(err, ErrorCode::Success); @@ -560,9 +560,9 @@ fn ledger_demo_works() { let request = serde_json::to_string(&get_nym_txn).unwrap(); let req = CString::new(request).unwrap(); let err = indy_submit_request(get_nym_command_handle, - pool_handle, - req.as_ptr(), - get_nym_callback); + pool_handle, + req.as_ptr(), + get_nym_callback); assert_eq!(err, ErrorCode::Success); let (err, resp) = get_nym_receiver.recv_timeout(TimeoutUtils::medium_timeout()).unwrap(); assert_eq!(err, ErrorCode::Success); @@ -675,12 +675,12 @@ fn signus_demo_works() { //1. Create My Wallet let err = indy_create_wallet(create_my_wallet_command_handle, - CString::new(pool_name).unwrap().as_ptr(), - CString::new(my_wallet_name).unwrap().as_ptr(), - CString::new(xtype).unwrap().as_ptr(), - null(), - null(), - create_my_wallet_callback); + CString::new(pool_name).unwrap().as_ptr(), + CString::new(my_wallet_name).unwrap().as_ptr(), + CString::new(xtype).unwrap().as_ptr(), + null(), + null(), + create_my_wallet_callback); assert_eq!(ErrorCode::Success, err); let err = create_my_wallet_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -689,10 +689,10 @@ fn signus_demo_works() { //2. Open My Wallet. Gets My wallet handle let err = indy_open_wallet(open_my_wallet_command_handle, - CString::new(my_wallet_name).unwrap().as_ptr(), - null(), - null(), - open_my_wallet_callback); + CString::new(my_wallet_name).unwrap().as_ptr(), + null(), + null(), + open_my_wallet_callback); assert_eq!(ErrorCode::Success, err); let (err, my_wallet_handle) = open_my_wallet_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -702,12 +702,12 @@ fn signus_demo_works() { //3. Create Their Wallet let err = indy_create_wallet(create_their_wallet_command_handle, - CString::new(pool_name).unwrap().as_ptr(), - CString::new(their_wallet_name).unwrap().as_ptr(), - CString::new(xtype).unwrap().as_ptr(), - null(), - null(), - create_their_wallet_callback); + CString::new(pool_name).unwrap().as_ptr(), + CString::new(their_wallet_name).unwrap().as_ptr(), + CString::new(xtype).unwrap().as_ptr(), + null(), + null(), + create_their_wallet_callback); assert_eq!(ErrorCode::Success, err); let err = create_their_wallet_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -716,10 +716,10 @@ fn signus_demo_works() { //4. Open Their Wallet. Gets Their wallet handle let err = indy_open_wallet(open_their_wallet_command_handle, - CString::new(their_wallet_name).unwrap().as_ptr(), - null(), - null(), - open_their_wallet_callback); + CString::new(their_wallet_name).unwrap().as_ptr(), + null(), + null(), + open_their_wallet_callback); assert_eq!(ErrorCode::Success, err); let (err, their_wallet_handle) = open_their_wallet_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -729,9 +729,9 @@ fn signus_demo_works() { let my_did_json = "{}"; let err = indy_create_and_store_my_did(create_and_store_my_did_command_handle, - my_wallet_handle, - CString::new(my_did_json).unwrap().as_ptr(), - create_and_store_my_did_callback); + my_wallet_handle, + CString::new(my_did_json).unwrap().as_ptr(), + create_and_store_my_did_callback); assert_eq!(ErrorCode::Success, err); let (err, my_did, my_verkey, my_pk) = create_and_store_my_did_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -744,9 +744,9 @@ fn signus_demo_works() { let their_did_json = "{}"; let err = indy_create_and_store_my_did(create_and_store_their_did_command_handle, - their_wallet_handle, - CString::new(their_did_json).unwrap().as_ptr(), - create_and_store_their_did_callback); + their_wallet_handle, + CString::new(their_did_json).unwrap().as_ptr(), + create_and_store_their_did_callback); assert_eq!(ErrorCode::Success, err); let (err, their_did, their_verkey, their_pk) = create_and_store_their_did_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -763,9 +763,9 @@ fn signus_demo_works() { their_did, their_pk, their_verkey); let err = indy_store_their_did(store_their_did_command_handle, - my_wallet_handle, - CString::new(their_identity_json).unwrap().as_ptr(), - store_their_did_callback); + my_wallet_handle, + CString::new(their_identity_json).unwrap().as_ptr(), + store_their_did_callback); assert_eq!(ErrorCode::Success, err); let err = store_their_did_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -783,10 +783,10 @@ fn signus_demo_works() { }"#; let err = indy_sign(sign_command_handle, - their_wallet_handle, - CString::new(their_did.clone()).unwrap().as_ptr(), - CString::new(message.clone()).unwrap().as_ptr(), - sign_callback); + their_wallet_handle, + CString::new(their_did.clone()).unwrap().as_ptr(), + CString::new(message.clone()).unwrap().as_ptr(), + sign_callback); assert_eq!(ErrorCode::Success, err); let (err, signed_msg) = sign_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); @@ -796,11 +796,11 @@ fn signus_demo_works() { // 9. I Verify message let err = indy_verify_signature(verify_command_handle, - my_wallet_handle, - 1, - CString::new(their_did).unwrap().as_ptr(), - CString::new(signed_msg).unwrap().as_ptr(), - verify_callback); + my_wallet_handle, + 1, + CString::new(their_did).unwrap().as_ptr(), + CString::new(signed_msg).unwrap().as_ptr(), + verify_callback); assert_eq!(ErrorCode::Success, err); let (err, valid) = verify_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); From 9ea50964a850005bdce007f577a20d0eeaeba9ad Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Fri, 14 Jul 2017 17:34:13 +0300 Subject: [PATCH 178/349] * close wallet was implemented --- wrappers/python/indy/wallet.py | 17 +++++++++++ .../python/tests/wallet/test_close_wallet.py | 30 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 wrappers/python/tests/wallet/test_close_wallet.py diff --git a/wrappers/python/indy/wallet.py b/wrappers/python/indy/wallet.py index 85e501d007..bcf19c029f 100644 --- a/wrappers/python/indy/wallet.py +++ b/wrappers/python/indy/wallet.py @@ -65,3 +65,20 @@ async def open_wallet(name: str, logger.debug("open_wallet: <<< res: %s", res) return res + + +async def close_wallet(handle: int): + logger = logging.getLogger(__name__) + logger.debug("close_wallet: >>> handle: %i", handle) + + if not hasattr(close_wallet, "cb"): + logger.debug("close_wallet: Creating callback") + close_wallet.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) + + c_handle = c_int32(handle) + + await do_call('indy_close_wallet', + close_wallet.cb, + c_handle) + + logger.debug("close_wallet: <<<") diff --git a/wrappers/python/tests/wallet/test_close_wallet.py b/wrappers/python/tests/wallet/test_close_wallet.py new file mode 100644 index 0000000000..20623a2627 --- /dev/null +++ b/wrappers/python/tests/wallet/test_close_wallet.py @@ -0,0 +1,30 @@ +from indy import wallet + +from ..utils import storage + +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.yield_fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_close_wallet_works(): + pool_name = "indy_close_wallet_works" + wallet_name = "indy_close_wallet_works" + + await wallet.create_wallet(pool_name, wallet_name, None, None, None) + + wallet_handle = await wallet.open_wallet(wallet_name, None, None) + await wallet.close_wallet(wallet_handle) + wallet_handle = await wallet.open_wallet(wallet_name, None, None) + await wallet.close_wallet(wallet_handle) + + assert True From fdcd1537f3f9404ef0f9e31471215eddc99fc893 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Fri, 14 Jul 2017 17:37:02 +0300 Subject: [PATCH 179/349] * Added return types for methods --- wrappers/python/indy/wallet.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wrappers/python/indy/wallet.py b/wrappers/python/indy/wallet.py index bcf19c029f..e0f4a54070 100644 --- a/wrappers/python/indy/wallet.py +++ b/wrappers/python/indy/wallet.py @@ -10,7 +10,7 @@ async def create_wallet(pool_name: str, name: str, xtype: Optional[str], config: Optional[str], - credentials: Optional[str]): + credentials: Optional[str]) -> None: logger = logging.getLogger(__name__) logger.debug("create_wallet: >>> pool_name: %s, name: %s, xtype: %s, config: %s, credentials: %s", pool_name, @@ -42,7 +42,7 @@ async def create_wallet(pool_name: str, async def open_wallet(name: str, runtime_config: Optional[str], - credentials: Optional[str]): + credentials: Optional[str]) -> int: logger = logging.getLogger(__name__) logger.debug("open_wallet: >>> name: %s, runtime_config: %s, credentials: %s", name, @@ -67,7 +67,7 @@ async def open_wallet(name: str, return res -async def close_wallet(handle: int): +async def close_wallet(handle: int) -> None: logger = logging.getLogger(__name__) logger.debug("close_wallet: >>> handle: %i", handle) From 5d90fd14903a79729c6945a8782b115509cdcbc6 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Fri, 14 Jul 2017 17:56:12 +0300 Subject: [PATCH 180/349] * Implemented delete_wallet call --- wrappers/python/indy/wallet.py | 22 +++++++++++++++ .../python/tests/wallet/test_delete_wallet.py | 27 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 wrappers/python/tests/wallet/test_delete_wallet.py diff --git a/wrappers/python/indy/wallet.py b/wrappers/python/indy/wallet.py index e0f4a54070..d87661cc16 100644 --- a/wrappers/python/indy/wallet.py +++ b/wrappers/python/indy/wallet.py @@ -82,3 +82,25 @@ async def close_wallet(handle: int) -> None: c_handle) logger.debug("close_wallet: <<<") + + +async def delete_wallet(name: str, + credentials: Optional[str]) -> None: + logger = logging.getLogger(__name__) + logger.debug("delete_wallet: >>> name: %s, credentials: %s", + name, + credentials) + + if not hasattr(delete_wallet, "cb"): + logger.debug("delete_wallet: Creating callback") + delete_wallet.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) + + c_name = c_char_p(name.encode('utf-8')) + c_credentials = c_char_p(credentials.encode('utf-8')) if credentials is not None else None + + await do_call('indy_delete_wallet', + delete_wallet.cb, + c_name, + c_credentials) + + logger.debug("delete_wallet: <<<") diff --git a/wrappers/python/tests/wallet/test_delete_wallet.py b/wrappers/python/tests/wallet/test_delete_wallet.py new file mode 100644 index 0000000000..4eb3485917 --- /dev/null +++ b/wrappers/python/tests/wallet/test_delete_wallet.py @@ -0,0 +1,27 @@ +from indy import wallet + +from ..utils import storage + +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.yield_fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_delete_wallet_works(): + pool_name = "indy_delete_wallet_works" + wallet_name = "indy_delete_wallet_works" + + await wallet.create_wallet(pool_name, wallet_name, None, None, None) + await wallet.delete_wallet(wallet_name, None) + await wallet.create_wallet(pool_name, wallet_name, None, None, None) + + assert True From 21f293e655def76840e3d8e74ee2ed00b486b5ca Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 14 Jul 2017 17:56:41 +0300 Subject: [PATCH 181/349] LedgerApi first tests --- .../indy/sdk/ledger/NymRequestsTest.java | 163 ++++++++++++++++++ .../indy/sdk/ledger/RequestsTest.java | 121 +++++++++++++ 2 files changed, 284 insertions(+) create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java new file mode 100644 index 0000000000..f0f8f59656 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java @@ -0,0 +1,163 @@ +package org.hyperledger.indy.sdk.ledger; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.pool.Pool; +import org.hyperledger.indy.sdk.pool.PoolJSONParameters; +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusJSONParameters; +import org.hyperledger.indy.sdk.signus.SignusResults; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.json.JSONObject; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.Timeout; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +public class NymRequestsTest extends IndyIntegrationTest { + + @Rule + public Timeout globalTimeout = new Timeout(5, TimeUnit.SECONDS); + + @Test + public void testBuildNymRequestWorksForOnlyRequiredFields() throws Exception { + + String identifier = "Th7MpTaRZVRYnPiabds81Y"; + String dest = "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4"; + + String expectedResult = String.format("\"identifier\":\"%s\",\"operation\":{\"type\":\"1\",\"dest\":\"%s\"}", identifier, dest); + + String nymRequest = Ledger.buildNymRequest(identifier, dest, null, null, null).get(); + + Assert.assertTrue(nymRequest.contains(expectedResult)); + } + + @Test + public void testBuildNymRequestWorksForOnlyOptionalFields() throws Exception { + + String identifier = "Th7MpTaRZVRYnPiabds81Y"; + String dest = "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4"; + String verkey = "Anfh2rjAcxkE249DcdsaQl"; + String role = "STEWARD"; + String alias = "some_alias"; + + String expectedResult = String.format("\"identifier\":\"%s\"," + + "\"operation\":{" + + "\"type\":\"1\"," + + "\"dest\":\"%s\"," + + "\"verkey\":\"%s\"," + + "\"alias\":\"%s\"," + + "\"role\":\"2\"" + + "}", identifier, dest, verkey, alias, role); + + String nymRequest = Ledger.buildNymRequest(identifier, dest, verkey, alias, role).get(); + + Assert.assertTrue(nymRequest.contains(expectedResult)); + } + + @Test + public void testBuildGetNymRequestWorks() throws Exception { + + String identifier = "Th7MpTaRZVRYnPiabds81Y"; + String dest = "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4"; + + String expectedResult = String.format("\"identifier\":\"%s\",\"operation\":{\"type\":\"105\",\"dest\":\"%s\"}", identifier, dest); + + String nymRequest = Ledger.buildGetNymRequest(identifier, dest).get(); + + Assert.assertTrue(nymRequest.contains(expectedResult)); + } + + @Test + public void testNymRequestWorksWithoutSignature() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.LedgerInvalidTransaction)); + + String poolName = PoolUtils.createPoolLedgerConfig(); + + PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); + Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); + + Wallet.createWallet(poolName, "ledgerWallet", "default", null, null).get(); + Wallet wallet = Wallet.openWallet("ledgerWallet", null, null).get(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); + + SignusResults.CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(wallet, didJson.toJson()).get(); + String did = result.getDid(); + + String nymRequest = Ledger.buildNymRequest(did, did, null, null, null).get(); + Ledger.submitRequest(pool, nymRequest).get(); + } + + @Test + public void testGetNymRequestWorks() throws Exception { + + String poolName = PoolUtils.createPoolLedgerConfig(); + + PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); + Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); + + Wallet.createWallet(poolName, "ledgerWallet", "default", null, null).get(); + Wallet wallet = Wallet.openWallet("ledgerWallet", null, null).get(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(wallet, didJson.toJson()).get(); + String did = result.getDid(); + + String getNymRequest = Ledger.buildGetNymRequest(did, did).get(); + String getNymResponseJson = Ledger.submitRequest(pool, getNymRequest).get(); + + JSONObject getNymResponse = new JSONObject(getNymResponseJson); + + Assert.assertEquals("REPLY", getNymResponse.getString("op")); + Assert.assertEquals("105", getNymResponse.getJSONObject("result").getString("type")); + Assert.assertEquals(did, getNymResponse.getJSONObject("result").getString("dest")); + } + + @Test + public void testNymRequestsWorks() throws Exception { + + String poolName = PoolUtils.createPoolLedgerConfig(); + + PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); + Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); + + Wallet.createWallet(poolName, "ledgerWallet", "default", null, null).get(); + Wallet wallet = Wallet.openWallet("ledgerWallet", null, null).get(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String trusteeDid = trusteeDidResult.getDid(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); + String myDid = myDidResult.getDid(); + String myVerkey = myDidResult.getVerkey(); + + String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, myVerkey, null, null).get(); + Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); + + String getNymRequest = Ledger.buildGetNymRequest(myDid, myDid).get(); + String getNymResponseJson = Ledger.submitRequest(pool, getNymRequest).get(); + + JSONObject getNymResponse = new JSONObject(getNymResponseJson); + + Assert.assertEquals("REPLY", getNymResponse.getString("op")); + Assert.assertEquals("105", getNymResponse.getJSONObject("result").getString("type")); + Assert.assertEquals(myDid, getNymResponse.getJSONObject("result").getString("dest")); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java new file mode 100644 index 0000000000..cb9f1507d9 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java @@ -0,0 +1,121 @@ +package org.hyperledger.indy.sdk.ledger; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.pool.Pool; +import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusJSONParameters; +import org.hyperledger.indy.sdk.signus.SignusResults; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.json.JSONObject; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.Timeout; + +import java.math.BigInteger; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertNotNull; + +public class RequestsTest extends IndyIntegrationTest { + + @Rule + public Timeout globalTimeout = new Timeout(5, TimeUnit.SECONDS); + + @Test + public void testSubmitRequestWorks() throws Exception { + + String poolName = PoolUtils.createPoolLedgerConfig(); + Pool pool = Pool.openPoolLedger(poolName, null).get(); + + Wallet.createWallet("otherPoolName", "ledgerWallet", "default", null, null).get(); + + String request = "{\n" + + " \"reqId\":1491566332010860,\n" + + " \"identifier\":\"Th7MpTaRZVRYnPiabds81Y\",\n" + + " \"operation\":{\n" + + " \"type\":\"105\",\n" + + " \"dest\":\"Th7MpTaRZVRYnPiabds81Y\"\n" + + " },\n" + + " \"signature\":\"4o86XfkiJ4e2r3J6Ufoi17UU3W5Zi9sshV6FjBjkVw4sgEQFQov9dxqDEtLbAJAWffCWd5KfAk164QVo7mYwKkiV\"}"; + + String response = Ledger.submitRequest(pool, request).get(); + + JSONObject responseObject = new JSONObject(response); + + Assert.assertEquals("REPLY", responseObject.getString("op")); + Assert.assertEquals("105", responseObject.getJSONObject("result").getString("type")); + Assert.assertEquals(1491566332010860L, responseObject.getJSONObject("result").getLong("reqId")); + Assert.assertEquals("{\"dest\":\"Th7MpTaRZVRYnPiabds81Y\",\"identifier\":\"V4SGRU86Z58d6TV7PBUe6f\",\"role\":\"2\",\"verkey\":\"~7TYfekw4GUagBnBVCqPjiC\"}", responseObject.getJSONObject("result").getString("data")); + Assert.assertEquals("Th7MpTaRZVRYnPiabds81Y", responseObject.getJSONObject("result").getString("identifier")); + Assert.assertEquals("Th7MpTaRZVRYnPiabds81Y", responseObject.getJSONObject("result").getString("dest")); + + pool.closePoolLedger().get(); + } + + @Test + public void testSignAndSubmitRequestWorks() throws Exception { + + String poolName = PoolUtils.createPoolLedgerConfig(); + Pool pool = Pool.openPoolLedger(poolName, null).get(); + + Wallet.createWallet(poolName, "ledgerWallet", "default", null, null).get(); + Wallet wallet = Wallet.openWallet("ledgerWallet", null, null).get(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); + + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); + String myDid = myDidResult.getDid(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String trusteeDid = trusteeDidResult.getDid(); + + String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, null, null, null).get(); + Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); + + pool.closePoolLedger().get(); + wallet.closeWallet().get(); + Wallet.deleteWallet("ledgerWallet", null).get(); + } + + @Test + public void testSignAndSubmitRequestWorksForIncompatibleWalletAndPool() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletIncompatiblePoolError)); + + String poolName = PoolUtils.createPoolLedgerConfig(); + Pool pool = Pool.openPoolLedger(poolName, null).get(); + + Wallet.createWallet("otherPoolName", "ledgerWallet", "default", null, null).get(); + Wallet wallet = Wallet.openWallet("ledgerWallet", null, null).get(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); + + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); + String myDid = myDidResult.getDid(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String trusteeDid = trusteeDidResult.getDid(); + + String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, null, null, null).get(); + Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); + + pool.closePoolLedger().get(); + wallet.closeWallet().get(); + Wallet.deleteWallet("ledgerWallet", null).get(); + } +} From 0e2a96963a4f487f6e234f173be70bca09ae82b3 Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Fri, 14 Jul 2017 18:07:39 +0300 Subject: [PATCH 182/349] Draft implementation for agent2agent demo. --- tests/demo.rs | 223 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 221 insertions(+), 2 deletions(-) diff --git a/tests/demo.rs b/tests/demo.rs index c8424615f5..033a18f96d 100644 --- a/tests/demo.rs +++ b/tests/demo.rs @@ -5,6 +5,7 @@ use indy::api as api; #[macro_use] extern crate serde_derive; +#[macro_use] extern crate serde_json; #[macro_use] extern crate lazy_static; @@ -14,6 +15,7 @@ extern crate log; #[macro_use] mod utils; +use utils::agent::AgentUtils; #[cfg(feature = "local_nodes_pool")] use utils::pool::PoolUtils; use utils::test::TestUtils; @@ -54,13 +56,230 @@ use indy::api::signus::{ use utils::callback::CallbackUtils; use std::ptr::null; -use std::sync::mpsc::{channel}; -use std::ffi::{CString}; +use std::sync::mpsc::channel; +use std::ffi::CString; use utils::types::ProofClaimsJson; #[cfg(feature = "local_nodes_pool")] use std::thread; +#[test] +fn agent_demo_works() { + TestUtils::cleanup_storage(); + + let endpoint = "127.0.0.1:9801"; + let pool_name = "indy_agent_connect_works_for_remote_data"; + + let listener_wallet_name = "listener_wallet"; + let trustee_wallet_name = "trustee_wallet"; + let wallet_type = "default"; + let c_pool_name = CString::new(pool_name).unwrap(); + + let (submit_sender, submit_receiver) = channel(); + let (create_sender, create_receiver) = channel(); + let (open_sender, open_receiver) = channel(); + let (create_listener_wallet_sender, create_listener_wallet_receiver) = channel(); + let (create_trustee_wallet_sender, create_trustee_wallet_receiver) = channel(); + let (open_listener_wallet_sender, open_listener_wallet_receiver) = channel(); + let (open_trustee_wallet_sender, open_trustee_wallet_receiver) = channel(); + let (create_and_store_listener_did_sender, create_and_store_listener_did_receiver) = channel(); + let (create_and_store_trustee_did_sender, create_and_store_trustee_did_receiver) = channel(); + let (attrib_sender, attrib_receiver) = channel(); + let create_cb = Box::new(move |err| { create_sender.send(err).unwrap(); }); + let open_cb = Box::new(move |err, pool_handle| { open_sender.send((err, pool_handle)).unwrap(); }); + let send_cb = Box::new(move |err, resp| { submit_sender.send((err, resp)).unwrap(); }); + let create_listener_wallet_cb = Box::new(move |err| { create_listener_wallet_sender.send(err).unwrap(); }); + let create_trustee_wallet_cb = Box::new(move |err| { create_trustee_wallet_sender.send(err).unwrap(); }); + let open_listener_wallet_cb = Box::new(move |err, handle| { open_listener_wallet_sender.send((err, handle)).unwrap(); }); + let open_trustee_wallet_cb = Box::new(move |err, handle| { open_trustee_wallet_sender.send((err, handle)).unwrap(); }); + let create_and_store_listener_did_cb = Box::new(move |err, did, verkey, public_key| { create_and_store_listener_did_sender.send((err, did, verkey, public_key)).unwrap(); }); + let create_and_store_trustee_did_cb = Box::new(move |err, did, verkey, public_key| { create_and_store_trustee_did_sender.send((err, did, verkey, public_key)).unwrap(); }); + let (open_command_handle, open_callback) = CallbackUtils::closure_to_open_pool_ledger_cb(open_cb); + let (create_command_handle, create_callback) = CallbackUtils::closure_to_create_pool_ledger_cb(create_cb); + let (send_command_handle, send_callback) = CallbackUtils::closure_to_send_tx_cb(send_cb); + let (create_listener_wallet_command_handle, create_listener_wallet_callback) = CallbackUtils::closure_to_create_wallet_cb(create_listener_wallet_cb); + let (create_trustee_wallet_command_handle, create_trustee_wallet_callback) = CallbackUtils::closure_to_create_wallet_cb(create_trustee_wallet_cb); + let (open_listener_wallet_command_handle, open_listener_wallet_callback) = CallbackUtils::closure_to_open_wallet_cb(open_listener_wallet_cb); + let (open_trustee_wallet_command_handle, open_trustee_wallet_callback) = CallbackUtils::closure_to_open_wallet_cb(open_trustee_wallet_cb); + let (create_and_store_listener_did_command_handle, create_and_store_listener_did_callback) = CallbackUtils::closure_to_create_and_store_my_did_cb(create_and_store_listener_did_cb); + let (create_and_store_trustee_did_command_handle, create_and_store_trustee_did_callback) = CallbackUtils::closure_to_create_and_store_my_did_cb(create_and_store_trustee_did_cb); + let (attrib_command_handle, attrib_callback) = CallbackUtils::closure_to_sign_and_submit_request_cb(Box::new(move |err, request_result_json| { + attrib_sender.send((err, request_result_json)).unwrap(); + })); + + // 1. Create ledger config from genesis txn file + PoolUtils::create_genesis_txn_file(format!("{}.txn", pool_name).as_str(), None); + let pool_config = CString::new(PoolUtils::create_default_pool_config(pool_name)).unwrap(); + let err = indy_create_pool_ledger_config(create_command_handle, + c_pool_name.as_ptr(), + pool_config.as_ptr(), + create_callback); + assert_eq!(err, ErrorCode::Success); + let err = create_receiver.recv_timeout(TimeoutUtils::short_timeout()).unwrap(); + assert_eq!(err, ErrorCode::Success); + + // 2. Open pool ledger + let err = indy_open_pool_ledger(open_command_handle, + c_pool_name.as_ptr(), + null(), + open_callback); + assert_eq!(err, ErrorCode::Success); + let (err, pool_handle) = open_receiver.recv_timeout(TimeoutUtils::short_timeout()).unwrap(); + assert_eq!(err, ErrorCode::Success); + thread::sleep(TimeoutUtils::short_timeout()); + + // 3. Create Listener Wallet + let err = + indy_create_wallet(create_listener_wallet_command_handle, + c_pool_name.as_ptr(), + CString::new(listener_wallet_name).unwrap().as_ptr(), + CString::new(wallet_type).unwrap().as_ptr(), + null(), + null(), + create_listener_wallet_callback); + + assert_eq!(ErrorCode::Success, err); + let err = create_listener_wallet_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); + assert_eq!(ErrorCode::Success, err); + + // 4. Open Listener Wallet. Gets My wallet handle + let err = + indy_open_wallet(open_listener_wallet_command_handle, + CString::new(listener_wallet_name).unwrap().as_ptr(), + null(), + null(), + open_listener_wallet_callback); + + assert_eq!(ErrorCode::Success, err); + let (err, listener_wallet) = open_listener_wallet_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); + assert_eq!(ErrorCode::Success, err); + + + // 5. Create Their Wallet (trustee, sender) + let err = + indy_create_wallet(create_trustee_wallet_command_handle, + CString::new(pool_name).unwrap().as_ptr(), + CString::new(trustee_wallet_name).unwrap().as_ptr(), + CString::new(wallet_type).unwrap().as_ptr(), + null(), + null(), + create_trustee_wallet_callback); + + assert_eq!(ErrorCode::Success, err); + let err = create_trustee_wallet_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); + assert_eq!(ErrorCode::Success, err); + + // 6. Open Their Wallet. Gets Their wallet handle + let err = + indy_open_wallet(open_trustee_wallet_command_handle, + CString::new(trustee_wallet_name).unwrap().as_ptr(), + null(), + null(), + open_trustee_wallet_callback); + + assert_eq!(ErrorCode::Success, err); + let (err, trustee_wallet) = open_trustee_wallet_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); + assert_eq!(ErrorCode::Success, err); + + // 7. Create My DID + let listener_did_json = "{}"; + let err = + indy_create_and_store_my_did(create_and_store_listener_did_command_handle, + listener_wallet, + CString::new(listener_did_json).unwrap().as_ptr(), + create_and_store_listener_did_callback); + + assert_eq!(ErrorCode::Success, err); + let (err, listener_did, listener_vk, listener_pk) = create_and_store_listener_did_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); + info!("listener did {:?}", listener_did); + info!("listener verkey {:?}", listener_vk); + info!("listener pk {:?}", listener_pk); + assert_eq!(ErrorCode::Success, err); + let listener_did_c = CString::new(listener_did.clone()).unwrap(); + + // 8. Create Their DID from Trustee1 seed + let trustee_did_json = r#"{"seed":"000000000000000000000000Trustee1"}"#; + let err = + indy_create_and_store_my_did(create_and_store_trustee_did_command_handle, + trustee_wallet, + CString::new(trustee_did_json).unwrap().as_ptr(), + create_and_store_trustee_did_callback); + + assert_eq!(ErrorCode::Success, err); + let (err, trustee_did, trustee_verkey, trustee_pk) = create_and_store_trustee_did_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); + info!("sender (trustee) did {:?}", trustee_did); + info!("sender (trustee) verkey {:?}", trustee_verkey); + info!("sender (trustee) pk {:?}", trustee_pk); + assert_eq!(ErrorCode::Success, err); + let trustee_did_c = CString::new(trustee_did.clone()).unwrap(); + + // 10. Prepare NYM transaction + let nym_req_id = PoolUtils::get_req_id(); + let nym_txn_req = json!({ + "identifier": trustee_did, + "operation": { + "dest": listener_did, + "verkey": listener_vk, + "type": "1", + }, + "reqId": nym_req_id, + }); + + // 11. Send NYM request with signing + let msg = serde_json::to_string(&nym_txn_req).unwrap(); + let req = CString::new(msg).unwrap(); + let err = indy_sign_and_submit_request(send_command_handle, + pool_handle, + trustee_wallet, + trustee_did_c.as_ptr(), + req.as_ptr(), + send_callback); + assert_eq!(err, ErrorCode::Success); + let (err, _) = submit_receiver.recv_timeout(TimeoutUtils::medium_timeout()).unwrap(); + assert_eq!(err, ErrorCode::Success); + + let sender_did = trustee_did.clone(); + let sender_wallet = trustee_wallet; + + let req_id = PoolUtils::get_req_id(); + let listener_attrib_json = json!({ + "identifier": listener_did, + "operation": { + "dest": listener_did, + "raw": format!("{{\"endpoint\":{{\"ha\":\"{}\", \"verkey\":\"{}\"}}}}", endpoint, listener_pk), + "type": "100", + }, + "reqId": req_id + }); + let listener_attrib_json = serde_json::to_string(&listener_attrib_json).unwrap(); + let listener_attrib_json = CString::new(listener_attrib_json).unwrap(); + + // Send attrib for listener (will be used by sender at start connection) + let err = + indy_sign_and_submit_request(attrib_command_handle, + pool_handle, + listener_wallet, + listener_did_c.as_ptr(), + listener_attrib_json.as_ptr(), + attrib_callback); + + assert_eq!(err, ErrorCode::Success); + + let (err, _) = attrib_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); + + assert_eq!(err, ErrorCode::Success); + + + let agent_listener_handle = AgentUtils::listen(endpoint, None, None).unwrap(); + AgentUtils::add_identity(agent_listener_handle, pool_handle, listener_wallet, listener_did.as_str()).unwrap(); + + let conn_handle_sender_to_listener = AgentUtils::connect(pool_handle, sender_wallet, sender_did.as_str(), listener_did.as_str(), None).unwrap(); + + AgentUtils::send(conn_handle_sender_to_listener, "msg_from_sender_to_listener").unwrap(); + + TestUtils::cleanup_storage(); +} + #[test] fn anoncreds_demo_works() { TestUtils::cleanup_storage(); From 4759b3d2b0195ec4b0502fd8e4dc6a70185f69a1 Mon Sep 17 00:00:00 2001 From: Sergey Minaev Date: Fri, 14 Jul 2017 18:17:41 +0300 Subject: [PATCH 183/349] Update comments. --- tests/demo.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/demo.rs b/tests/demo.rs index 033a18f96d..b3148a6fca 100644 --- a/tests/demo.rs +++ b/tests/demo.rs @@ -213,7 +213,7 @@ fn agent_demo_works() { assert_eq!(ErrorCode::Success, err); let trustee_did_c = CString::new(trustee_did.clone()).unwrap(); - // 10. Prepare NYM transaction + // 9. Prepare NYM transaction let nym_req_id = PoolUtils::get_req_id(); let nym_txn_req = json!({ "identifier": trustee_did, @@ -225,7 +225,7 @@ fn agent_demo_works() { "reqId": nym_req_id, }); - // 11. Send NYM request with signing + // 10. Send NYM request with signing let msg = serde_json::to_string(&nym_txn_req).unwrap(); let req = CString::new(msg).unwrap(); let err = indy_sign_and_submit_request(send_command_handle, @@ -241,6 +241,7 @@ fn agent_demo_works() { let sender_did = trustee_did.clone(); let sender_wallet = trustee_wallet; + // Prepare and send attrib for listener (will be requested from ledger and used by sender at start connection) let req_id = PoolUtils::get_req_id(); let listener_attrib_json = json!({ "identifier": listener_did, @@ -253,8 +254,6 @@ fn agent_demo_works() { }); let listener_attrib_json = serde_json::to_string(&listener_attrib_json).unwrap(); let listener_attrib_json = CString::new(listener_attrib_json).unwrap(); - - // Send attrib for listener (will be used by sender at start connection) let err = indy_sign_and_submit_request(attrib_command_handle, pool_handle, @@ -262,19 +261,21 @@ fn agent_demo_works() { listener_did_c.as_ptr(), listener_attrib_json.as_ptr(), attrib_callback); - assert_eq!(err, ErrorCode::Success); - let (err, _) = attrib_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); - assert_eq!(err, ErrorCode::Success); + // FIXME inline calls bellow, it's demo and should use API calls instead of helpers + // start listener on endpoint let agent_listener_handle = AgentUtils::listen(endpoint, None, None).unwrap(); + // allow listener accept incoming connection for specific DID (listener_did) AgentUtils::add_identity(agent_listener_handle, pool_handle, listener_wallet, listener_did.as_str()).unwrap(); + // inititate connection from sender to listener let conn_handle_sender_to_listener = AgentUtils::connect(pool_handle, sender_wallet, sender_did.as_str(), listener_did.as_str(), None).unwrap(); + // send test message from sender to listener TODO: check message received AgentUtils::send(conn_handle_sender_to_listener, "msg_from_sender_to_listener").unwrap(); TestUtils::cleanup_storage(); From 647a59492ee697ece131511ab8e732c00febb6b0 Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Fri, 14 Jul 2017 17:47:55 +0200 Subject: [PATCH 184/349] [java] Rename IncomingConnectionObserver back to ConnectionObserver --- .../org/hyperledger/indy/sdk/agent/Agent.java | 22 +++++++++---------- .../indy/sdk/agent/AgentObservers.java | 2 +- .../org/hyperledger/indy/sdk/AgentTest.java | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java index 968b3c063e..b5f9d4bc9c 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java @@ -29,7 +29,7 @@ private Agent() { */ private static Map messageObserver = new ConcurrentHashMap(); - private static Map connectionObservers = new ConcurrentHashMap(); + private static Map connectionObservers = new ConcurrentHashMap(); private static void addMessageObserver(int commandHandle, AgentObservers.MessageObserver messageObserver) { @@ -46,16 +46,16 @@ private static AgentObservers.MessageObserver removeMessageObserver(int xcommand return future; } - private static void addIncomingConnectionObserver(int commandHandle, AgentObservers.IncomingConnectionObserver incomingConnectionObserver) { + private static void addConnectionObserver(int commandHandle, AgentObservers.ConnectionObserver connectionObserver) { assert (!connectionObservers.containsKey(commandHandle)); - connectionObservers.put(commandHandle, incomingConnectionObserver); + connectionObservers.put(commandHandle, connectionObserver); } - private static AgentObservers.IncomingConnectionObserver removeIncomingConnectionObserver(int xcommand_handle) { + private static AgentObservers.ConnectionObserver removeConnectionObserver(int xcommand_handle) { - AgentObservers.IncomingConnectionObserver future = connectionObservers.remove(xcommand_handle); + AgentObservers.ConnectionObserver future = connectionObservers.remove(xcommand_handle); assert (future != null); return future; @@ -110,7 +110,7 @@ public void callback(int xcommand_handle, int err, int listener_handle) throws I Agent.Listener listener = new Agent.Listener(listener_handle); listeners.put(listener_handle, listener); - listener.incomingConnectionObserver = removeIncomingConnectionObserver(xcommand_handle); + listener.connectionObserver = removeConnectionObserver(xcommand_handle); future.complete(listener); } @@ -130,8 +130,8 @@ public void callback(int xlistener_handle, int err, int connection_handle, Strin Agent.Connection connection = new Agent.Connection(connection_handle); connections.put(connection_handle, connection); - AgentObservers.IncomingConnectionObserver incomingConnectionObserver = listener.incomingConnectionObserver; - connection.messageObserver = incomingConnectionObserver.onConnection(listener, connection, sender_did, receiver_did); + AgentObservers.ConnectionObserver connectionObserver = listener.connectionObserver; + connection.messageObserver = connectionObserver.onConnection(listener, connection, sender_did, receiver_did); } }; @@ -244,11 +244,11 @@ public static CompletableFuture agentConnect( public static CompletableFuture agentListen( String endpoint, - AgentObservers.IncomingConnectionObserver incomingConnectionObserver) throws IndyException { + AgentObservers.ConnectionObserver connectionObserver) throws IndyException { CompletableFuture future = new CompletableFuture<>(); int commandHandle = addFuture(future); - addIncomingConnectionObserver(commandHandle, incomingConnectionObserver); + addConnectionObserver(commandHandle, connectionObserver); int result = LibIndy.api.indy_agent_listen( commandHandle, @@ -378,7 +378,7 @@ public static CompletableFuture agentCloseListener( public static class Listener { private final int listenerHandle; - private AgentObservers.IncomingConnectionObserver incomingConnectionObserver; + private AgentObservers.ConnectionObserver connectionObserver; private Listener(int listenerHandle) { diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentObservers.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentObservers.java index a4356919fa..c5f148aff2 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentObservers.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/AgentObservers.java @@ -9,7 +9,7 @@ private AgentObservers() { } - public interface IncomingConnectionObserver { + public interface ConnectionObserver { public MessageObserver onConnection(Agent.Listener listener, Agent.Connection connection, String senderDid, String receiverDid); } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java index 6e0b7858d8..d22a5f4c7f 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java @@ -3,7 +3,7 @@ import org.hyperledger.indy.sdk.agent.Agent; import org.hyperledger.indy.sdk.agent.Agent.Connection; import org.hyperledger.indy.sdk.agent.Agent.Listener; -import org.hyperledger.indy.sdk.agent.AgentObservers.IncomingConnectionObserver; +import org.hyperledger.indy.sdk.agent.AgentObservers.ConnectionObserver; import org.hyperledger.indy.sdk.agent.AgentObservers.MessageObserver; import org.hyperledger.indy.sdk.ledger.Ledger; import org.hyperledger.indy.sdk.pool.Pool; @@ -67,7 +67,7 @@ public void onMessage(Connection connection, String message) { } }; - final IncomingConnectionObserver incomingConnectionObserver = new IncomingConnectionObserver() { + final ConnectionObserver incomingConnectionObserver = new ConnectionObserver() { public MessageObserver onConnection(Listener listener, Connection connection, String senderDid, String receiverDid) { From 6080dfdaa66b8fbece4e552303d1da3a5a0cd84c Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Fri, 14 Jul 2017 18:08:08 +0200 Subject: [PATCH 185/349] [java] Whitespace consistency --- .../org/hyperledger/indy/sdk/ErrorCode.java | 2 +- .../org/hyperledger/indy/sdk/IndyJava.java | 4 +- .../org/hyperledger/indy/sdk/agent/Agent.java | 28 +++++----- .../indy/sdk/anoncreds/Anoncreds.java | 24 ++++----- .../hyperledger/indy/sdk/ledger/Ledger.java | 52 +++++++++---------- .../org/hyperledger/indy/sdk/pool/Pool.java | 20 +++---- .../hyperledger/indy/sdk/signus/Signus.java | 28 +++++----- .../hyperledger/indy/sdk/wallet/Wallet.java | 20 +++---- 8 files changed, 89 insertions(+), 89 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java index 30c2af135b..3a465da184 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ErrorCode.java @@ -115,7 +115,7 @@ public enum ErrorCode { SignusUnknownCryptoError(500); private int value; - private static Map map = new HashMap (); + private static Map map = new HashMap(); private ErrorCode(int value) { this.value = value; diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java index e75d02a842..bd5a7a601b 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java @@ -29,7 +29,7 @@ public static class API { */ private static AtomicInteger atomicInteger = new AtomicInteger(); - private static Map> futures = new ConcurrentHashMap> (); + private static Map> futures = new ConcurrentHashMap>(); protected static int newCommandHandle() { @@ -106,7 +106,7 @@ public String toString() { public abstract static class JsonParameter { - protected Map map = new HashMap (); + protected Map map = new HashMap(); /* * JSON CREATION diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java index b5f9d4bc9c..fdf069eb6a 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java @@ -33,7 +33,7 @@ private Agent() { private static void addMessageObserver(int commandHandle, AgentObservers.MessageObserver messageObserver) { - assert (!Agent.messageObserver.containsKey(commandHandle)); + assert(! Agent.messageObserver.containsKey(commandHandle)); Agent.messageObserver.put(commandHandle, messageObserver); } @@ -41,14 +41,14 @@ private static void addMessageObserver(int commandHandle, AgentObservers.Message private static AgentObservers.MessageObserver removeMessageObserver(int xcommand_handle) { AgentObservers.MessageObserver future = messageObserver.remove(xcommand_handle); - assert (future != null); + assert(future != null); return future; } private static void addConnectionObserver(int commandHandle, AgentObservers.ConnectionObserver connectionObserver) { - assert (!connectionObservers.containsKey(commandHandle)); + assert(! connectionObservers.containsKey(commandHandle)); connectionObservers.put(commandHandle, connectionObserver); } @@ -56,7 +56,7 @@ private static void addConnectionObserver(int commandHandle, AgentObservers.Conn private static AgentObservers.ConnectionObserver removeConnectionObserver(int xcommand_handle) { AgentObservers.ConnectionObserver future = connectionObservers.remove(xcommand_handle); - assert (future != null); + assert(future != null); return future; } @@ -71,9 +71,9 @@ private static AgentObservers.ConnectionObserver removeConnectionObserver(int xc public void callback(int xcommand_handle, int err, int connection_handle) throws IndyException { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (!checkCallback(future, err)) return; + if (! checkCallback(future, err)) return; - assert (!connections.containsKey(connection_handle)); + assert(! connections.containsKey(connection_handle)); Agent.Connection connection = new Agent.Connection(connection_handle); connections.put(connection_handle, connection); @@ -104,9 +104,9 @@ public void callback(int xconnection_handle, int err, String message) throws Ind public void callback(int xcommand_handle, int err, int listener_handle) throws IndyException { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (!checkCallback(future, err)) return; + if (! checkCallback(future, err)) return; - assert (!listeners.containsKey(listener_handle)); + assert(! listeners.containsKey(listener_handle)); Agent.Listener listener = new Agent.Listener(listener_handle); listeners.put(listener_handle, listener); @@ -126,7 +126,7 @@ public void callback(int xlistener_handle, int err, int connection_handle, Strin Agent.Listener listener = listeners.get(xlistener_handle); if (listener == null) return; - assert (!connections.containsKey(connection_handle)); + assert(! connections.containsKey(connection_handle)); Agent.Connection connection = new Agent.Connection(connection_handle); connections.put(connection_handle, connection); @@ -156,7 +156,7 @@ public void callback(int xconnection_handle, int err, String message) throws Ind public void callback(int xcommand_handle, int err, int listener_handle) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (!checkCallback(future, err)) return; + if (! checkCallback(future, err)) return; future.complete(null); } @@ -168,7 +168,7 @@ public void callback(int xcommand_handle, int err, int listener_handle) { public void callback(int xcommand_handle, int err, int listener_handle) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (!checkCallback(future, err)) return; + if (! checkCallback(future, err)) return; future.complete(null); } @@ -180,7 +180,7 @@ public void callback(int xcommand_handle, int err, int listener_handle) { public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (!checkCallback(future, err)) return; + if (! checkCallback(future, err)) return; future.complete(null); } @@ -192,7 +192,7 @@ public void callback(int xcommand_handle, int err) { public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (!checkCallback(future, err)) return; + if (! checkCallback(future, err)) return; future.complete(null); } @@ -204,7 +204,7 @@ public void callback(int xcommand_handle, int err) { public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (!checkCallback(future, err)) return; + if (! checkCallback(future, err)) return; future.complete(null); } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java index 448ae38649..d606197a9f 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java @@ -26,7 +26,7 @@ private Anoncreds() { private static Callback issuerCreateAndStoreClaimDefCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String claim_def_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -39,7 +39,7 @@ public void callback(int xcommand_handle, int err, String claim_def_json) { private static Callback issuerCreateAndStoreRevocRegCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String revoc_reg_json, String revoc_reg_uuid) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -52,7 +52,7 @@ public void callback(int xcommand_handle, int err, String revoc_reg_json, String private static Callback issuerCreateClaimCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String revoc_reg_update_json, String xclaim_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -65,7 +65,7 @@ public void callback(int xcommand_handle, int err, String revoc_reg_update_json, private static Callback issuerRevokeClaimCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String revoc_reg_update_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -78,7 +78,7 @@ public void callback(int xcommand_handle, int err, String revoc_reg_update_json) private static Callback proverStoreClaimOfferCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -91,7 +91,7 @@ public void callback(int xcommand_handle, int err) { private static Callback proverGetClaimOffersCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String claim_offers_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -113,7 +113,7 @@ public static CompletableFuture issuerCreateAndStoreClaimDef( String signatureType, boolean createNonRevoc) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -138,7 +138,7 @@ public static CompletableFuture issuerCreate int schemaSeqNo, int maxClaimNum) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -163,7 +163,7 @@ public static CompletableFuture issuerCreateClaim( int revocRegSeqNo, int userRevocIndex) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -187,7 +187,7 @@ public static CompletableFuture issuerRevokeClaim( int revocRegSeqNo, int userRevocIndex) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -208,7 +208,7 @@ public static CompletableFuture proverStoreClaimOffer( Wallet wallet, String claimOfferJson) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -228,7 +228,7 @@ public static CompletableFuture proverGetClaimOffers( Wallet wallet, String filterJson) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java index f065b33f79..1139c23520 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java @@ -25,7 +25,7 @@ private Ledger() { private static Callback signAndSubmitRequestCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String request_result_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -38,7 +38,7 @@ public void callback(int xcommand_handle, int err, String request_result_json) { private static Callback submitRequestCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String request_result_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -51,7 +51,7 @@ public void callback(int xcommand_handle, int err, String request_result_json) { private static Callback buildGetDdoRequestCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String request_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -64,7 +64,7 @@ public void callback(int xcommand_handle, int err, String request_json) { private static Callback buildNymRequestCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String request_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -77,7 +77,7 @@ public void callback(int xcommand_handle, int err, String request_json) { private static Callback buildAttribRequestCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String request_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -90,7 +90,7 @@ public void callback(int xcommand_handle, int err, String request_json) { private static Callback buildGetAttribRequestCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String request_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -103,7 +103,7 @@ public void callback(int xcommand_handle, int err, String request_json) { private static Callback buildGetNymRequestCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String request_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -116,7 +116,7 @@ public void callback(int xcommand_handle, int err, String request_json) { private static Callback buildSchemaRequestCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String request_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -129,7 +129,7 @@ public void callback(int xcommand_handle, int err, String request_json) { private static Callback buildGetSchemaRequestCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String request_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -142,7 +142,7 @@ public void callback(int xcommand_handle, int err, String request_json) { private static Callback buildClaimDefTxnCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String request_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -155,7 +155,7 @@ public void callback(int xcommand_handle, int err, String request_json) { private static Callback buildGetClaimDefTxnCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String request_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -168,7 +168,7 @@ public void callback(int xcommand_handle, int err, String request_json) { private static Callback buildNodeRequestCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String request_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -181,7 +181,7 @@ public void callback(int xcommand_handle, int err, String request_json) { public static Callback buildGetTxnRequestCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String request_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -202,7 +202,7 @@ public static CompletableFuture signAndSubmitRequest( String submitterDid, String requestJson) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int poolHandle = pool.getPoolHandle(); @@ -225,7 +225,7 @@ public static CompletableFuture submitRequest( Pool pool, String requestJson) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int poolHandle = pool.getPoolHandle(); @@ -246,7 +246,7 @@ public static CompletableFuture buildGetDdoRequest( String targetDid, String requestJson) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_get_ddo_request( @@ -267,7 +267,7 @@ public static CompletableFuture buildNymRequest( String alias, String role) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_nym_request( @@ -291,7 +291,7 @@ public static CompletableFuture buildAttribRequest( String raw, String enc) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_attrib_request( @@ -313,7 +313,7 @@ public static CompletableFuture buildGetAttribRequest( String targetDid, String data) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_get_attrib_request( @@ -332,7 +332,7 @@ public static CompletableFuture buildGetNymRequest( String submitterDid, String targetDid) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_get_nym_request( @@ -350,7 +350,7 @@ public static CompletableFuture buildSchemaRequest( String submitterDid, String data) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_schema_request( @@ -368,7 +368,7 @@ public static CompletableFuture buildGetSchemaRequest( String submitterDid, String data) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_get_schema_request( @@ -387,7 +387,7 @@ public static CompletableFuture buildClaimDefTxn( String xref, String data) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_claim_def_txn( @@ -406,7 +406,7 @@ public static CompletableFuture buildGetClaimDefTxn( String submitterDid, String xref) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_get_claim_def_txn( @@ -425,7 +425,7 @@ public static CompletableFuture buildNodeRequest( String targetDid, String data) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_node_request( @@ -444,7 +444,7 @@ public static CompletableFuture buildGetTxnRequest( String submitterDid, int data) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int result = LibIndy.api.indy_build_get_txn_request( diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java index b67e03b619..de1541da5b 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java @@ -31,7 +31,7 @@ public int getPoolHandle() { private static Callback createPoolLedgerConfigCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -44,7 +44,7 @@ public void callback(int xcommand_handle, int err) { private static Callback openPoolLedgerCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, int pool_handle) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -59,7 +59,7 @@ public void callback(int xcommand_handle, int err, int pool_handle) { private static Callback refreshPoolLedgerCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -72,7 +72,7 @@ public void callback(int xcommand_handle, int err) { private static Callback closePoolLedgerCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -85,7 +85,7 @@ public void callback(int xcommand_handle, int err) { private static Callback deletePoolLedgerConfigCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -104,7 +104,7 @@ public static CompletableFuture createPoolLedgerConfig( String configName, String config) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int result = LibIndy.api.indy_create_pool_ledger_config( @@ -122,7 +122,7 @@ public static CompletableFuture openPoolLedger( String configName, String config) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int result = LibIndy.api.indy_open_pool_ledger( @@ -139,7 +139,7 @@ public static CompletableFuture openPoolLedger( private static CompletableFuture refreshPoolLedger( Pool pool) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int handle = pool.getPoolHandle(); @@ -157,7 +157,7 @@ private static CompletableFuture refreshPoolLedger( private static CompletableFuture closePoolLedger( Pool pool) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int handle = pool.getPoolHandle(); @@ -175,7 +175,7 @@ private static CompletableFuture closePoolLedger( public static CompletableFuture deletePoolLedgerConfig( String configName) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int result = LibIndy.api.indy_delete_pool_ledger_config( diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java index 62122e2934..d75bdb6d21 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java @@ -27,7 +27,7 @@ private Signus() { private static Callback createAndStoreMyDidCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String did, String verkey, String pk) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -40,7 +40,7 @@ public void callback(int xcommand_handle, int err, String did, String verkey, St private static Callback replaceKeysCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String verkey, String pk) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -53,7 +53,7 @@ public void callback(int xcommand_handle, int err, String verkey, String pk) { private static Callback storeTheirDidCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -66,7 +66,7 @@ public void callback(int xcommand_handle, int err) { private static Callback signCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String signature) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -79,7 +79,7 @@ public void callback(int xcommand_handle, int err, String signature) { private static Callback verifySignatureCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, boolean valid) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -92,7 +92,7 @@ public void callback(int xcommand_handle, int err, boolean valid) { private static Callback encryptCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String encryptedMsg) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -105,7 +105,7 @@ public void callback(int xcommand_handle, int err, String encryptedMsg) { private static Callback decryptCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, String decryptedMsg) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -124,7 +124,7 @@ public static CompletableFuture createAndStoreMyDid( Wallet wallet, String didJson) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -145,7 +145,7 @@ public static CompletableFuture replaceKeys( String did, String identityJson) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -166,7 +166,7 @@ public static CompletableFuture storeTheirDid( Wallet wallet, String identityJson) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -187,7 +187,7 @@ public static CompletableFuture sign( String did, String msg) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -210,7 +210,7 @@ public static CompletableFuture verifySignature( String did, String signedMsg) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -234,7 +234,7 @@ public static CompletableFuture encrypt( String did, String msg) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -256,7 +256,7 @@ public static CompletableFuture decrypt( String did, String encryptedMsg) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java index 1f9d3273ca..a4a9df5f35 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java @@ -31,7 +31,7 @@ public int getWalletHandle() { private static Callback createWalletCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -44,7 +44,7 @@ public void callback(int xcommand_handle, int err) { private static Callback openWalletCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err, int handle) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -59,7 +59,7 @@ public void callback(int xcommand_handle, int err, int handle) { private static Callback closeWalletCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -72,7 +72,7 @@ public void callback(int xcommand_handle, int err) { private static Callback deleteWalletCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -85,7 +85,7 @@ public void callback(int xcommand_handle, int err) { private static Callback walletSetSeqNoForValueCb = new Callback() { - @SuppressWarnings({ "unused", "unchecked" }) + @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); @@ -111,7 +111,7 @@ public static CompletableFuture createWallet( String config, String credentials) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int result = LibIndy.api.indy_create_wallet( @@ -133,7 +133,7 @@ public static CompletableFuture openWallet( String runtimeConfig, String credentials) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int result = LibIndy.api.indy_open_wallet( @@ -151,7 +151,7 @@ public static CompletableFuture openWallet( private static CompletableFuture closeWallet( Wallet wallet) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int handle = wallet.getWalletHandle(); @@ -170,7 +170,7 @@ public static CompletableFuture deleteWallet( String name, String credentials) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int result = LibIndy.api.indy_delete_wallet( @@ -189,7 +189,7 @@ private static CompletableFuture walletSetSeqNoForValue( String walletKey, String configName) throws IndyException { - CompletableFuture future = new CompletableFuture (); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); From a0e26eff8191455fba12a630d36c67e00673d6d1 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 17 Jul 2017 10:14:34 +0300 Subject: [PATCH 186/349] Finished Agent demo test --- src/api/agent.rs | 8 +++--- tests/demo.rs | 73 +++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 67 insertions(+), 14 deletions(-) diff --git a/src/api/agent.rs b/src/api/agent.rs index c7e4786c70..bae4bb1dcd 100644 --- a/src/api/agent.rs +++ b/src/api/agent.rs @@ -131,10 +131,10 @@ pub extern fn indy_agent_listen(command_handle: i32, message_cb: Option) -> ErrorCode { - check_useful_c_str!(endpoint, ErrorCode::CommonInvalidParam3); - check_useful_c_callback!(listener_cb, ErrorCode::CommonInvalidParam4); - check_useful_c_callback!(connection_cb, ErrorCode::CommonInvalidParam5); - check_useful_c_callback!(message_cb, ErrorCode::CommonInvalidParam6); + check_useful_c_str!(endpoint, ErrorCode::CommonInvalidParam2); + check_useful_c_callback!(listener_cb, ErrorCode::CommonInvalidParam3); + check_useful_c_callback!(connection_cb, ErrorCode::CommonInvalidParam4); + check_useful_c_callback!(message_cb, ErrorCode::CommonInvalidParam5); let cmd = Command::Agent(AgentCommand::Listen( endpoint, diff --git a/tests/demo.rs b/tests/demo.rs index b3148a6fca..92820d76e4 100644 --- a/tests/demo.rs +++ b/tests/demo.rs @@ -15,7 +15,6 @@ extern crate log; #[macro_use] mod utils; -use utils::agent::AgentUtils; #[cfg(feature = "local_nodes_pool")] use utils::pool::PoolUtils; use utils::test::TestUtils; @@ -52,6 +51,12 @@ use indy::api::signus::{ indy_verify_signature, indy_store_their_did }; +use indy::api::agent::{ + indy_agent_listen, + indy_agent_add_identity, + indy_agent_connect, + indy_agent_send +}; use utils::callback::CallbackUtils; @@ -85,6 +90,11 @@ fn agent_demo_works() { let (create_and_store_listener_did_sender, create_and_store_listener_did_receiver) = channel(); let (create_and_store_trustee_did_sender, create_and_store_trustee_did_receiver) = channel(); let (attrib_sender, attrib_receiver) = channel(); + let (listen_sender, listen_receiver) = channel(); + let (add_identity_sender, add_identity_receiver) = channel(); + let (connect_sender, connect_receiver) = channel(); + let (send_sender, send_receiver) = channel(); + let create_cb = Box::new(move |err| { create_sender.send(err).unwrap(); }); let open_cb = Box::new(move |err, pool_handle| { open_sender.send((err, pool_handle)).unwrap(); }); let send_cb = Box::new(move |err, resp| { submit_sender.send((err, resp)).unwrap(); }); @@ -94,6 +104,11 @@ fn agent_demo_works() { let open_trustee_wallet_cb = Box::new(move |err, handle| { open_trustee_wallet_sender.send((err, handle)).unwrap(); }); let create_and_store_listener_did_cb = Box::new(move |err, did, verkey, public_key| { create_and_store_listener_did_sender.send((err, did, verkey, public_key)).unwrap(); }); let create_and_store_trustee_did_cb = Box::new(move |err, did, verkey, public_key| { create_and_store_trustee_did_sender.send((err, did, verkey, public_key)).unwrap(); }); + let listen_cb = Box::new(move |err, listener_handle| listen_sender.send((err, listener_handle)).unwrap()); + let add_identity_cb = Box::new(move |err_code| add_identity_sender.send(err_code).unwrap()); + let connect_cb = Box::new(move |err, connection_handle| { connect_sender.send((err, connection_handle)).unwrap(); }); + let agent_send_cb = Box::new(move |err_code| send_sender.send(err_code).unwrap()); + let (open_command_handle, open_callback) = CallbackUtils::closure_to_open_pool_ledger_cb(open_cb); let (create_command_handle, create_callback) = CallbackUtils::closure_to_create_pool_ledger_cb(create_cb); let (send_command_handle, send_callback) = CallbackUtils::closure_to_send_tx_cb(send_cb); @@ -106,6 +121,10 @@ fn agent_demo_works() { let (attrib_command_handle, attrib_callback) = CallbackUtils::closure_to_sign_and_submit_request_cb(Box::new(move |err, request_result_json| { attrib_sender.send((err, request_result_json)).unwrap(); })); + let (listen_command_handle, listen_callback) = CallbackUtils::closure_to_agent_listen_cb(listen_cb); + let (add_identity_command_handle, add_identity_cb) = CallbackUtils::closure_to_agent_add_identity_cb(add_identity_cb); + let (connect_command_hamdle, connect_callback) = CallbackUtils::closure_to_agent_connect_cb(connect_cb); + let (agent_send_command_handle, agent_send_callback) = CallbackUtils::closure_to_agent_send_cb(agent_send_cb); // 1. Create ledger config from genesis txn file PoolUtils::create_genesis_txn_file(format!("{}.txn", pool_name).as_str(), None); @@ -265,18 +284,52 @@ fn agent_demo_works() { let (err, _) = attrib_receiver.recv_timeout(TimeoutUtils::long_timeout()).unwrap(); assert_eq!(err, ErrorCode::Success); - // FIXME inline calls bellow, it's demo and should use API calls instead of helpers + // 10. start listener on endpoint + let (wait_msg_from_srv_send, wait_msg_from_srv_recv) = channel(); + let on_msg = Box::new(move |_, _, msg| { wait_msg_from_srv_send.send(msg).unwrap(); }); + let (on_msg_cb_id, on_msg_callback) = CallbackUtils::closure_to_agent_message_cb(on_msg); + + let on_connect_cb = Box::new(move |_, _, conn_handle, _, _| { CallbackUtils::closure_map_ids(on_msg_cb_id, conn_handle); }); + let (on_connect_cb_id, on_connect_callback) = CallbackUtils::closure_to_agent_connected_cb(on_connect_cb); + + let endpoint = CString::new(endpoint).unwrap(); + + let err = indy_agent_listen(listen_command_handle, endpoint.as_ptr(), listen_callback, on_connect_callback, on_msg_callback); + assert_eq!(err, ErrorCode::Success); + let (err, agent_listener_handle) = listen_receiver.recv_timeout(TimeoutUtils::short_timeout()).unwrap(); + assert_eq!(err, ErrorCode::Success); + + CallbackUtils::closure_map_ids(on_connect_cb_id, agent_listener_handle); + + // 11. Allow listener accept incoming connection for specific DID (listener_did) + let listener_did = CString::new(listener_did.clone()).unwrap(); + let err = indy_agent_add_identity(add_identity_command_handle, agent_listener_handle, pool_handle, listener_wallet, listener_did.as_ptr(), add_identity_cb); + assert_eq!(err, ErrorCode::Success); + let err = add_identity_receiver.recv_timeout(TimeoutUtils::short_timeout()).unwrap(); + assert_eq!(err, ErrorCode::Success); + + // 12. Initiate connection from sender to listener + let (msg_cb_id, msg_callback) = CallbackUtils::closure_to_agent_message_cb(Box::new(move |_, _, _| {})); + let sender_did = CString::new(sender_did).unwrap(); + + let err = indy_agent_connect(connect_command_hamdle, pool_handle, sender_wallet, sender_did.as_ptr(), listener_did.as_ptr(), connect_callback, msg_callback); + assert_eq!(err, ErrorCode::Success); + let (err, conn_handle_sender_to_listener) = connect_receiver.recv_timeout(TimeoutUtils::medium_timeout()).unwrap(); + assert_eq!(err, ErrorCode::Success); + + CallbackUtils::closure_map_ids(msg_cb_id, conn_handle_sender_to_listener); - // start listener on endpoint - let agent_listener_handle = AgentUtils::listen(endpoint, None, None).unwrap(); - // allow listener accept incoming connection for specific DID (listener_did) - AgentUtils::add_identity(agent_listener_handle, pool_handle, listener_wallet, listener_did.as_str()).unwrap(); + // 13. Send test message from sender to listener + let message = "msg_from_sender_to_listener"; + let msg = CString::new(message).unwrap(); - // inititate connection from sender to listener - let conn_handle_sender_to_listener = AgentUtils::connect(pool_handle, sender_wallet, sender_did.as_str(), listener_did.as_str(), None).unwrap(); + let res = indy_agent_send(agent_send_command_handle, conn_handle_sender_to_listener, msg.as_ptr(), agent_send_callback); + assert_eq!(res, ErrorCode::Success); + let res = send_receiver.recv_timeout(TimeoutUtils::medium_timeout()).unwrap(); + assert_eq!(res, ErrorCode::Success); - // send test message from sender to listener TODO: check message received - AgentUtils::send(conn_handle_sender_to_listener, "msg_from_sender_to_listener").unwrap(); + // 14. Check message received + assert_eq!(wait_msg_from_srv_recv.recv_timeout(TimeoutUtils::short_timeout()).unwrap(), message); TestUtils::cleanup_storage(); } From bf692dbcbe622cbf07e27fc2916f592d21fc5bb0 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 17 Jul 2017 11:23:03 +0300 Subject: [PATCH 187/349] added test for create_and_store_my_did --- wrappers/python/indy/error.py | 2 - wrappers/python/indy/signus.py | 52 ++++++++++++------- wrappers/python/setup.py | 2 +- wrappers/python/tests/signus/__init__.py | 0 .../signus/test_create_and_store_my_did.py | 29 +++++++++++ 5 files changed, 63 insertions(+), 22 deletions(-) create mode 100644 wrappers/python/tests/signus/__init__.py create mode 100644 wrappers/python/tests/signus/test_create_and_store_my_did.py diff --git a/wrappers/python/indy/error.py b/wrappers/python/indy/error.py index a9c17b76ce..ab1172b208 100644 --- a/wrappers/python/indy/error.py +++ b/wrappers/python/indy/error.py @@ -112,7 +112,5 @@ class ErrorCode(IntEnum): class IndyError(Exception): - error_code: ErrorCode - def __init__(self, error_code: ErrorCode): self.error_code = error_code diff --git a/wrappers/python/indy/signus.py b/wrappers/python/indy/signus.py index b58fc3ec09..c8307aaa16 100644 --- a/wrappers/python/indy/signus.py +++ b/wrappers/python/indy/signus.py @@ -1,14 +1,33 @@ -async def create_and_store_my_did(command_handle: int, - wallet_handle: int, - did_json: str, - did: str, - verkey: str, - pk: str) -> None: - pass +from .libindy import do_call, create_cb + +from typing import Optional +from ctypes import * + +import logging + +async def create_and_store_my_did(wallet_handle: int, + did_json: str) -> (str, str, str): + logger = logging.getLogger(__name__) + logger.debug("create_and_store_my_did: >>> wallet_handle: %s, did_json: %s", + wallet_handle, + did_json) + + if not hasattr(create_and_store_my_did, "cb"): + logger.debug("create_wallet: Creating callback") + create_and_store_my_did.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p, c_char_p, c_char_p)) + + c_wallet_handle = c_int32(wallet_handle) + c_did_json = c_char_p(did_json.encode('utf-8')) + + res = await do_call('indy_create_and_store_my_did', + create_and_store_my_did.cb, + c_wallet_handle, + c_did_json) + logger.debug("create_and_store_my_did: <<< res: %s", res) + return res -async def replace_keys(command_handle: int, - wallet_handle: int, +async def replace_keys(wallet_handle: int, did: str, identity_json: str, verkey: str, @@ -16,22 +35,19 @@ async def replace_keys(command_handle: int, pass -async def store_their_did(command_handle: int, - wallet_handle: int, +async def store_their_did(wallet_handle: int, identity_json: str) -> None: pass -async def sign(command_handle: int, - wallet_handle: int, +async def sign(wallet_handle: int, did: str, msg: str, signature: str) -> None: pass -async def verify_signature(command_handle: int, - wallet_handle: int, +async def verify_signature(wallet_handle: int, did: str, msg: str, signature: str, @@ -39,16 +55,14 @@ async def verify_signature(command_handle: int, pass -async def encrypt(command_handle: int, - wallet_handle: int, +async def encrypt(wallet_handle: int, did: str, msg: str, encrypted_msg: str) -> None: pass -async def decrypt(command_handle: int, - wallet_handle: int, +async def decrypt(wallet_handle: int, did: str, encrypted_msg: str, decrypted_msg: str) -> None: diff --git a/wrappers/python/setup.py b/wrappers/python/setup.py index 218ccbfd1e..fa69aaddf4 100644 --- a/wrappers/python/setup.py +++ b/wrappers/python/setup.py @@ -9,6 +9,6 @@ author='Vyacheslav Gudkov', author_email='vyacheslav.gudkov@dsr-company.com', description='This is the official SDK for Hyperledger Indy (https://www.hyperledger.org/projects), which provides a distributed-ledger-based foundation for self-sovereign identity (https://sovrin.org). The major artifact of the SDK is a c-callable library.', - install_requires=[], + install_requires=['base58', ], tests_require=['pytest', 'pytest-asyncio'] ) diff --git a/wrappers/python/tests/signus/__init__.py b/wrappers/python/tests/signus/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/wrappers/python/tests/signus/test_create_and_store_my_did.py b/wrappers/python/tests/signus/test_create_and_store_my_did.py new file mode 100644 index 0000000000..53c4f74c89 --- /dev/null +++ b/wrappers/python/tests/signus/test_create_and_store_my_did.py @@ -0,0 +1,29 @@ +from indy import wallet, signus + +from ..utils import storage + +import base58 +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.yield_fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_create_my_did_works_with_empty_json(): + pool_name = "indy_open_wallet_works" + wallet_name = "indy_open_wallet_works" + + await wallet.create_wallet(pool_name, wallet_name, None, None, None) + wallet_handle = await wallet.open_wallet(wallet_name, None, None) + assert wallet_handle is not None + (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, "{}") + assert len(base58.b58decode(did)) == 16 + assert len(base58.b58decode(ver_key)) == 32 From 4bab304e9a41e32487dbde707a86563a18e3ff98 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 17 Jul 2017 11:35:16 +0300 Subject: [PATCH 188/349] added replace_keys --- wrappers/python/indy/signus.py | 27 +++++++++++++++--- .../python/tests/signus/test_replace_keys.py | 28 +++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 wrappers/python/tests/signus/test_replace_keys.py diff --git a/wrappers/python/indy/signus.py b/wrappers/python/indy/signus.py index c8307aaa16..270591eedd 100644 --- a/wrappers/python/indy/signus.py +++ b/wrappers/python/indy/signus.py @@ -29,10 +29,29 @@ async def create_and_store_my_did(wallet_handle: int, async def replace_keys(wallet_handle: int, did: str, - identity_json: str, - verkey: str, - pk: str) -> None: - pass + identity_json: str) -> (str, str): + logger = logging.getLogger(__name__) + logger.debug("replace_keys: >>> wallet_handle: %s, did: %s, identity_json: %s", + wallet_handle, + did, + identity_json) + + if not hasattr(replace_keys, "cb"): + logger.debug("replace_keys: Creating callback") + replace_keys.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p, c_char_p)) + + c_wallet_handle = c_int32(wallet_handle) + c_did = c_char_p(did) + c_identity_json = c_char_p(identity_json.encode('utf-8')) + + res = await do_call('indy_replace_keys', + replace_keys.cb, + c_wallet_handle, + c_did, + c_identity_json) + + logger.debug("replace_keys: <<< res: %s", res) + return res async def store_their_did(wallet_handle: int, diff --git a/wrappers/python/tests/signus/test_replace_keys.py b/wrappers/python/tests/signus/test_replace_keys.py new file mode 100644 index 0000000000..bd7cb4d991 --- /dev/null +++ b/wrappers/python/tests/signus/test_replace_keys.py @@ -0,0 +1,28 @@ +from indy import wallet, signus + +from ..utils import storage + +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.yield_fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_replace_keys_works(): + pool_name = "indy_open_wallet_works" + wallet_name = "indy_open_wallet_works" + + await wallet.create_wallet(pool_name, wallet_name, None, None, None) + wallet_handle = await wallet.open_wallet(wallet_name, None, None) + assert wallet_handle is not None + (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, "{}") + (new_did, new_ver_key) = await signus.replace_keys(wallet_handle, did, "{}") + assert (new_did != did) and (new_ver_key != ver_key) \ No newline at end of file From 13cda51bfdc3daac8ce519c5a035d914bdc3c7ca Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 17 Jul 2017 11:43:13 +0300 Subject: [PATCH 189/349] added store_their_did --- wrappers/python/indy/signus.py | 20 +++++++++++++- .../tests/signus/test_store_their_did.py | 26 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 wrappers/python/tests/signus/test_store_their_did.py diff --git a/wrappers/python/indy/signus.py b/wrappers/python/indy/signus.py index 270591eedd..6ab4a001b2 100644 --- a/wrappers/python/indy/signus.py +++ b/wrappers/python/indy/signus.py @@ -56,7 +56,25 @@ async def replace_keys(wallet_handle: int, async def store_their_did(wallet_handle: int, identity_json: str) -> None: - pass + logger = logging.getLogger(__name__) + logger.debug("store_their_did: >>> wallet_handle: %s, identity_json: %s", + wallet_handle, + identity_json) + + if not hasattr(store_their_did, "cb"): + logger.debug("store_their_did: Creating callback") + store_their_did.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) + + c_wallet_handle = c_int32(wallet_handle) + c_identity_json = c_char_p(identity_json.encode('utf-8')) + + res = await do_call('indy_store_their_did', + store_their_did.cb, + c_wallet_handle, + c_identity_json) + + logger.debug("store_their_did: <<< res: %s", res) + return res async def sign(wallet_handle: int, diff --git a/wrappers/python/tests/signus/test_store_their_did.py b/wrappers/python/tests/signus/test_store_their_did.py new file mode 100644 index 0000000000..4fddd115d8 --- /dev/null +++ b/wrappers/python/tests/signus/test_store_their_did.py @@ -0,0 +1,26 @@ +from indy import wallet, signus + +from ..utils import storage + +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.yield_fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_store_their_did_works(): + pool_name = "indy_open_wallet_works" + wallet_name = "indy_open_wallet_works" + + await wallet.create_wallet(pool_name, wallet_name, None, None, None) + wallet_handle = await wallet.open_wallet(wallet_name, None, None) + assert wallet_handle is not None + await signus.store_their_did(wallet_handle, '{"did":"8wZcEriaNLNKtteJvx7f8i"}') From 07b55659db2900b8b631fe4ae4e6c5cd45d5d06d Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 17 Jul 2017 12:27:51 +0300 Subject: [PATCH 190/349] added sign --- wrappers/python/indy/signus.py | 26 ++++++++++++-- wrappers/python/tests/signus/test_sign.py | 42 +++++++++++++++++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 wrappers/python/tests/signus/test_sign.py diff --git a/wrappers/python/indy/signus.py b/wrappers/python/indy/signus.py index 6ab4a001b2..8d16722c1b 100644 --- a/wrappers/python/indy/signus.py +++ b/wrappers/python/indy/signus.py @@ -79,9 +79,29 @@ async def store_their_did(wallet_handle: int, async def sign(wallet_handle: int, did: str, - msg: str, - signature: str) -> None: - pass + msg: str) -> str: + logger = logging.getLogger(__name__) + logger.debug("sign: >>> wallet_handle: %s, did: %s, msg: %s", + wallet_handle, + did, + msg) + + if not hasattr(sign, "cb"): + logger.debug("sign: Creating callback") + sign.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_wallet_handle = c_int32(wallet_handle) + c_did = c_char_p(did) + c_msg = c_char_p(msg.encode('utf-8')) + + res = await do_call('indy_sign', + sign.cb, + c_wallet_handle, + c_did, + c_msg) + + logger.debug("sign: <<< res: %s", res) + return res async def verify_signature(wallet_handle: int, diff --git a/wrappers/python/tests/signus/test_sign.py b/wrappers/python/tests/signus/test_sign.py new file mode 100644 index 0000000000..71d3eca1ce --- /dev/null +++ b/wrappers/python/tests/signus/test_sign.py @@ -0,0 +1,42 @@ +from indy import wallet, signus + +from ..utils import storage + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.yield_fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_sign_works(): + pool_name = "indy_open_wallet_works" + wallet_name = "indy_open_wallet_works" + + await wallet.create_wallet(pool_name, wallet_name, None, None, None) + wallet_handle = await wallet.open_wallet(wallet_name, None, None) + assert wallet_handle is not None + (did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') + + message = { + "reqId": 1496822211362017764, + "identifier": "GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL", + "operation": { + "type": "1", + "dest": "VsKV7grR1BUE29mG2Fm2kX", + "verkey": "GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa" + } + } + + expected_signature = "65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW" + + result = json.loads((await signus.sign(wallet_handle, did, json.dumps(message))).decode()) + assert result['signature'] == expected_signature From 120e5b8119a87efecf78b76e23d3373d63f3687d Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 17 Jul 2017 13:26:05 +0300 Subject: [PATCH 191/349] added verify_signature --- wrappers/python/indy/signus.py | 31 ++++++++++-- .../tests/signus/test_verify_signature.py | 48 +++++++++++++++++++ 2 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 wrappers/python/tests/signus/test_verify_signature.py diff --git a/wrappers/python/indy/signus.py b/wrappers/python/indy/signus.py index 8d16722c1b..d823c7e293 100644 --- a/wrappers/python/indy/signus.py +++ b/wrappers/python/indy/signus.py @@ -105,11 +105,34 @@ async def sign(wallet_handle: int, async def verify_signature(wallet_handle: int, + pool_handle: int, did: str, - msg: str, - signature: str, - valid: bool) -> None: - pass + signed_msg: str) -> bool: + logger = logging.getLogger(__name__) + logger.debug("verify_signature: >>> wallet_handle: %s, pool_handle: %s, did: %s, signed_msg: %s", + wallet_handle, + pool_handle, + did, + signed_msg) + + if not hasattr(verify_signature, "cb"): + logger.debug("verify_signature: Creating callback") + verify_signature.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_bool)) + + c_wallet_handle = c_int32(wallet_handle) + c_pool_handle = c_int32(pool_handle) + c_did = c_char_p(did) + c_signed_msg = c_char_p(signed_msg.encode('utf-8')) + + res = await do_call('indy_verify_signature', + verify_signature.cb, + c_wallet_handle, + c_pool_handle, + c_did, + c_signed_msg) + + logger.debug("verify_signature: <<< res: %s", res) + return res async def encrypt(wallet_handle: int, diff --git a/wrappers/python/tests/signus/test_verify_signature.py b/wrappers/python/tests/signus/test_verify_signature.py new file mode 100644 index 0000000000..f75485fc4b --- /dev/null +++ b/wrappers/python/tests/signus/test_verify_signature.py @@ -0,0 +1,48 @@ +from indy import wallet, signus + +from ..utils import storage + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.yield_fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_verify_signature_works(): + pool_name = "indy_open_wallet_works" + pool_handle = 1 + wallet_name = "indy_open_wallet_works" + + await wallet.create_wallet(pool_name, wallet_name, None, None, None) + wallet_handle = await wallet.open_wallet(wallet_name, None, None) + assert wallet_handle is not None + (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') + identity_json = { + "did": did.decode(), + "verkey": ver_key.decode() + } + + await signus.store_their_did(wallet_handle, json.dumps(identity_json)) + + message = { + "reqId": 1496822211362017764, + "identifier": "GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL", + "operation": { + "type": "1", + "dest": "VsKV7grR1BUE29mG2Fm2kX", + "verkey": "GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa" + }, + "signature": "65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW" + } + + valid = await signus.verify_signature(wallet_handle, pool_handle, did, json.dumps(message)) + assert valid From 03ff22d097a457134d4fc9a1d701eb0035866c65 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 17 Jul 2017 13:35:23 +0300 Subject: [PATCH 192/349] added encrypt --- wrappers/python/indy/signus.py | 37 ++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/wrappers/python/indy/signus.py b/wrappers/python/indy/signus.py index d823c7e293..c16a4b8955 100644 --- a/wrappers/python/indy/signus.py +++ b/wrappers/python/indy/signus.py @@ -136,14 +136,43 @@ async def verify_signature(wallet_handle: int, async def encrypt(wallet_handle: int, + pool_handle: int, + my_did: str, did: str, - msg: str, - encrypted_msg: str) -> None: - pass + msg: str) -> (str, str): + logger = logging.getLogger(__name__) + logger.debug("encrypt: >>> wallet_handle: %s, pool_handle: %s, my_did: %s, did: %s, msg: %s", + wallet_handle, + pool_handle, + my_did, + did, + msg) + + if not hasattr(encrypt, "cb"): + logger.debug("encrypt: Creating callback") + encrypt.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p, c_char_p)) + + c_wallet_handle = c_int32(wallet_handle) + c_pool_handle = c_int32(pool_handle) + c_my_did = c_char_p(my_did.encode('utf-8')) + c_did = c_char_p(did.encode('utf-8')) + c_msg = c_char_p(msg.encode('utf-8')) + + res = await do_call('indy_encrypt', + encrypt.cb, + c_wallet_handle, + c_pool_handle, + c_my_did, + c_did, + c_msg) + + logger.debug("encrypt: <<< res: %s", res) + return res async def decrypt(wallet_handle: int, + my_did: str, did: str, encrypted_msg: str, - decrypted_msg: str) -> None: + nonce: str) -> str: pass From d5e0f2f6241d1e7702627c0ab580dd6a4651023d Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 17 Jul 2017 13:38:09 +0300 Subject: [PATCH 193/349] small changes --- wrappers/python/indy/signus.py | 6 +++--- wrappers/python/tests/signus/test_replace_keys.py | 2 +- wrappers/python/tests/signus/test_sign.py | 2 +- wrappers/python/tests/signus/test_verify_signature.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wrappers/python/indy/signus.py b/wrappers/python/indy/signus.py index c16a4b8955..2b42bd1dab 100644 --- a/wrappers/python/indy/signus.py +++ b/wrappers/python/indy/signus.py @@ -41,7 +41,7 @@ async def replace_keys(wallet_handle: int, replace_keys.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p, c_char_p)) c_wallet_handle = c_int32(wallet_handle) - c_did = c_char_p(did) + c_did = c_char_p(did.encode('utf-8')) c_identity_json = c_char_p(identity_json.encode('utf-8')) res = await do_call('indy_replace_keys', @@ -91,7 +91,7 @@ async def sign(wallet_handle: int, sign.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) c_wallet_handle = c_int32(wallet_handle) - c_did = c_char_p(did) + c_did = c_char_p(did.encode('utf-8')) c_msg = c_char_p(msg.encode('utf-8')) res = await do_call('indy_sign', @@ -121,7 +121,7 @@ async def verify_signature(wallet_handle: int, c_wallet_handle = c_int32(wallet_handle) c_pool_handle = c_int32(pool_handle) - c_did = c_char_p(did) + c_did = c_char_p(did.encode('utf-8')) c_signed_msg = c_char_p(signed_msg.encode('utf-8')) res = await do_call('indy_verify_signature', diff --git a/wrappers/python/tests/signus/test_replace_keys.py b/wrappers/python/tests/signus/test_replace_keys.py index bd7cb4d991..8ea0cfee64 100644 --- a/wrappers/python/tests/signus/test_replace_keys.py +++ b/wrappers/python/tests/signus/test_replace_keys.py @@ -24,5 +24,5 @@ async def test_replace_keys_works(): wallet_handle = await wallet.open_wallet(wallet_name, None, None) assert wallet_handle is not None (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, "{}") - (new_did, new_ver_key) = await signus.replace_keys(wallet_handle, did, "{}") + (new_did, new_ver_key) = await signus.replace_keys(wallet_handle, did.decode(), "{}") assert (new_did != did) and (new_ver_key != ver_key) \ No newline at end of file diff --git a/wrappers/python/tests/signus/test_sign.py b/wrappers/python/tests/signus/test_sign.py index 71d3eca1ce..6e29d92392 100644 --- a/wrappers/python/tests/signus/test_sign.py +++ b/wrappers/python/tests/signus/test_sign.py @@ -38,5 +38,5 @@ async def test_sign_works(): expected_signature = "65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW" - result = json.loads((await signus.sign(wallet_handle, did, json.dumps(message))).decode()) + result = json.loads((await signus.sign(wallet_handle, did.decode(), json.dumps(message))).decode()) assert result['signature'] == expected_signature diff --git a/wrappers/python/tests/signus/test_verify_signature.py b/wrappers/python/tests/signus/test_verify_signature.py index f75485fc4b..e313dfc6a6 100644 --- a/wrappers/python/tests/signus/test_verify_signature.py +++ b/wrappers/python/tests/signus/test_verify_signature.py @@ -44,5 +44,5 @@ async def test_verify_signature_works(): "signature": "65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW" } - valid = await signus.verify_signature(wallet_handle, pool_handle, did, json.dumps(message)) + valid = await signus.verify_signature(wallet_handle, pool_handle, did.decode(), json.dumps(message)) assert valid From c5c0cc0bfc9d8e9d8d9b62d3d030489f04dad3f3 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 17 Jul 2017 13:41:20 +0300 Subject: [PATCH 194/349] added decrypt --- wrappers/python/indy/signus.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/wrappers/python/indy/signus.py b/wrappers/python/indy/signus.py index 2b42bd1dab..2a9c1b4307 100644 --- a/wrappers/python/indy/signus.py +++ b/wrappers/python/indy/signus.py @@ -175,4 +175,31 @@ async def decrypt(wallet_handle: int, did: str, encrypted_msg: str, nonce: str) -> str: - pass + logger = logging.getLogger(__name__) + logger.debug("decrypt: >>> wallet_handle: %s, my_did: %s, did: %s, encrypted_msg: %s, nonce: %s", + wallet_handle, + my_did, + did, + encrypted_msg, + nonce) + + if not hasattr(decrypt, "cb"): + logger.debug("decrypt: Creating callback") + decrypt.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_wallet_handle = c_int32(wallet_handle) + c_my_did = c_char_p(my_did.encode('utf-8')) + c_did = c_char_p(did.encode('utf-8')) + c_encrypted_msg = c_char_p(encrypted_msg.encode('utf-8')) + c_nonce = c_char_p(nonce.encode('utf-8')) + + res = await do_call('indy_decrypt', + decrypt.cb, + c_wallet_handle, + c_my_did, + c_did, + c_encrypted_msg, + c_nonce) + + logger.debug("decrypt: <<< res: %s", res) + return res From 15f2a43bc7a688f6dd8a78d7314c20ddd75f0a29 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 17 Jul 2017 14:34:52 +0300 Subject: [PATCH 195/349] removed unnecessary code --- wrappers/python/indy/signus.py | 1 - 1 file changed, 1 deletion(-) diff --git a/wrappers/python/indy/signus.py b/wrappers/python/indy/signus.py index 2a9c1b4307..2e42a8b8f6 100644 --- a/wrappers/python/indy/signus.py +++ b/wrappers/python/indy/signus.py @@ -1,6 +1,5 @@ from .libindy import do_call, create_cb -from typing import Optional from ctypes import * import logging From 59077e99242761fb62556cb7ee23a48e88e47a2a Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 17 Jul 2017 14:39:27 +0300 Subject: [PATCH 196/349] moved base58 to test_require --- wrappers/python/setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wrappers/python/setup.py b/wrappers/python/setup.py index fa69aaddf4..e91cad4532 100644 --- a/wrappers/python/setup.py +++ b/wrappers/python/setup.py @@ -9,6 +9,6 @@ author='Vyacheslav Gudkov', author_email='vyacheslav.gudkov@dsr-company.com', description='This is the official SDK for Hyperledger Indy (https://www.hyperledger.org/projects), which provides a distributed-ledger-based foundation for self-sovereign identity (https://sovrin.org). The major artifact of the SDK is a c-callable library.', - install_requires=['base58', ], - tests_require=['pytest', 'pytest-asyncio'] + install_requires=[], + tests_require=['pytest', 'pytest-asyncio', 'base58'] ) From baaba00732c41a18d7b4fba2248862a92ddf9ed2 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 17 Jul 2017 15:01:30 +0300 Subject: [PATCH 197/349] added wrapper for pool --- wrappers/python/indy/pool.py | 115 +++++++++++++++++++++++++++++------ 1 file changed, 98 insertions(+), 17 deletions(-) diff --git a/wrappers/python/indy/pool.py b/wrappers/python/indy/pool.py index b872b5d451..c68510ba26 100644 --- a/wrappers/python/indy/pool.py +++ b/wrappers/python/indy/pool.py @@ -1,26 +1,107 @@ -async def create_pool_ledger_config(command_handle: int, - config_name: str, +from .libindy import do_call, create_cb + +from ctypes import * + +import logging + +async def create_pool_ledger_config(config_name: str, config: str) -> None: - pass + logger = logging.getLogger(__name__) + logger.debug("create_pool_ledger_config: >>> config_name: %s, config: %s", + config_name, + config) + + if not hasattr(create_pool_ledger_config, "cb"): + logger.debug("create_pool_ledger_config: Creating callback") + create_pool_ledger_config.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) + + c_config_name = c_char_p(config_name.encode('utf-8')) + c_config = c_char_p(config.encode('utf-8')) + + res = await do_call('indy_create_pool_ledger_config', + create_pool_ledger_config.cb, + c_config_name, + c_config) + + logger.debug("create_pool_ledger_config: <<< res: %s", res) + return res + + +async def open_pool_ledger(config_name: str, + config: str) -> int: + logger = logging.getLogger(__name__) + logger.debug("open_pool_ledger: >>> config_name: %s, config: %s", + config_name, + config) + + if not hasattr(open_pool_ledger, "cb"): + logger.debug("open_pool_ledger: Creating callback") + open_pool_ledger.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) + + c_config_name = c_char_p(config_name.encode('utf-8')) + c_config = c_char_p(config.encode('utf-8')) + + res = await do_call('indy_open_pool_ledger', + open_pool_ledger.cb, + c_config_name, + c_config) + + logger.debug("open_pool_ledger: <<< res: %s", res) + return res + + +async def refresh_pool_ledger(handle: int) -> None: + logger = logging.getLogger(__name__) + logger.debug("refresh_pool_ledger: >>> config_name: %s", + handle) + + if not hasattr(refresh_pool_ledger, "cb"): + logger.debug("refresh_pool_ledger: Creating callback") + refresh_pool_ledger.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) + + c_handle = c_int32(handle) + + res = await do_call('indy_refresh_pool_ledger', + refresh_pool_ledger.cb, + c_handle) + + logger.debug("refresh_pool_ledger: <<< res: %s", res) + return res + + +async def close_pool_ledger(handle: int) -> None: + logger = logging.getLogger(__name__) + logger.debug("close_pool_ledger: >>> config_name: %s", + handle) + + if not hasattr(close_pool_ledger, "cb"): + logger.debug("close_pool_ledger: Creating callback") + close_pool_ledger.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) + + c_handle = c_int32(handle) + res = await do_call('indy_close_pool_ledger', + close_pool_ledger.cb, + c_handle) -async def open_pool_ledger(command_handle: int, - config_name: str, - config: str, - pool_handle: int) -> None: - pass + logger.debug("close_pool_ledger: <<< res: %s", res) + return res -async def refresh_pool_ledger(command_handle: int, - handle: int) -> None: - pass +async def delete_pool_ledger_config(config_name: str) -> None: + logger = logging.getLogger(__name__) + logger.debug("delete_pool_ledger_config: >>> config_name: %s", + config_name) + if not hasattr(delete_pool_ledger_config, "cb"): + logger.debug("delete_pool_ledger_config: Creating callback") + delete_pool_ledger_config.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) -async def close_pool_ledger(command_handle: int, - handle: int) -> None: - pass + c_config_name = c_char_p(config_name.encode('utf-8')) + res = await do_call('indy_delete_pool_ledger_config', + delete_pool_ledger_config.cb, + c_config_name) -async def delete_pool_ledger_config(command_handle: int, - config_name: str) -> None: - pass + logger.debug("delete_pool_ledger_config: <<< res: %s", res) + return res From 4f98156aae44e54277399a7834afe4c88b91feee Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 17 Jul 2017 18:14:08 +0300 Subject: [PATCH 198/349] added utils for pool --- wrappers/python/indy/ledger.py | 85 ++++++++----------- wrappers/python/indy/pool.py | 2 +- .../pool/test_create_pool_ledger_config.py | 18 ++++ .../tests/pool/test_open_pool_ledger.py | 21 +++++ wrappers/python/tests/utils/pool.py | 30 +++++++ wrappers/python/tests/utils/storage.py | 5 ++ 6 files changed, 110 insertions(+), 51 deletions(-) create mode 100644 wrappers/python/tests/pool/test_create_pool_ledger_config.py create mode 100644 wrappers/python/tests/pool/test_open_pool_ledger.py create mode 100644 wrappers/python/tests/utils/pool.py diff --git a/wrappers/python/indy/ledger.py b/wrappers/python/indy/ledger.py index 8e22b07744..5625f0c75b 100644 --- a/wrappers/python/indy/ledger.py +++ b/wrappers/python/indy/ledger.py @@ -1,93 +1,78 @@ -async def sign_and_submit_request(command_handle: int, +async def sign_and_submit_request(pool_handle: int, wallet_handle: int, submitter_did: str, - request_json: str, - request_result_json: str) -> None: + request_json: str) -> str: pass -async def submit_request(command_handle: int, - pool_handle: int, - request_json: str, - request_result_json: str) -> None: +async def submit_request(pool_handle: int, + request_json: str) -> str: pass -async def build_get_ddo_request(command_handle: int, - submitter_did: str, - target_did: str, - request_json: str) -> None: +async def build_get_ddo_request(submitter_did: str, + target_did: str) -> str: pass -async def build_nym_request(command_handle: int, - submitter_did: str, +async def build_nym_request(submitter_did: str, target_did: str, verkey: str, - xref: str, - data: str, - role: str, - request_json: str) -> None: + alias: str, + role: str) -> str: pass -async def build_attrib_request(command_handle: int, - submitter_did: str, +async def build_attrib_request(submitter_did: str, target_did: str, hash: str, raw: str, - enc: str, - request_json: str) -> None: + enc: str) -> str: pass -async def build_get_attrib_request(command_handle: int, - submitter_did: str, +async def build_get_attrib_request(submitter_did: str, target_did: str, - data: str, - request_json: str) -> None: + data: str) -> str: pass -async def build_get_nym_request(command_handle: int, - submitter_did: str, - target_did: str, - request_json: str) -> None: +async def build_get_nym_request(submitter_did: str, + target_did: str) -> str: pass -async def build_schema_request(command_handle: int, - submitter_did: str, - data: str, - request_json: str) -> None: +async def build_schema_request(submitter_did: str, + data: str) -> str: pass -async def build_get_schema_request(command_handle: int, - submitter_did: str, - data: str, - request_json: str) -> None: +async def build_get_schema_request(submitter_did: str, + dest: str, + data: str) -> str: pass -async def build_claim_def_txn(command_handle: int, - submitter_did: str, - xref: str, - data: str, - request_result_json: str) -> None: +async def build_claim_def_txn(submitter_did: str, + xref: int, + signature_type: str, + data: str) -> str: pass -async def build_get_claim_def_txn(command_handle: int, - submitter_did: str, - xref: str, - request_json: str) -> None: +async def build_get_claim_def_txn(submitter_did: str, + xref: int, + signature_type: str, + origin: str) -> str: pass -async def build_node_request(command_handle: int, - submitter_did: str, +async def build_node_request(submitter_did: str, target_did: str, - data: str, - request_json: str) -> None: + data: str) -> str: + pass + + +async def build_get_txn_request(submitter_did: str, + data: str) -> str: pass diff --git a/wrappers/python/indy/pool.py b/wrappers/python/indy/pool.py index c68510ba26..975dca81d4 100644 --- a/wrappers/python/indy/pool.py +++ b/wrappers/python/indy/pool.py @@ -36,7 +36,7 @@ async def open_pool_ledger(config_name: str, if not hasattr(open_pool_ledger, "cb"): logger.debug("open_pool_ledger: Creating callback") - open_pool_ledger.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) + open_pool_ledger.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_int32)) c_config_name = c_char_p(config_name.encode('utf-8')) c_config = c_char_p(config.encode('utf-8')) diff --git a/wrappers/python/tests/pool/test_create_pool_ledger_config.py b/wrappers/python/tests/pool/test_create_pool_ledger_config.py new file mode 100644 index 0000000000..8ad4582f10 --- /dev/null +++ b/wrappers/python/tests/pool/test_create_pool_ledger_config.py @@ -0,0 +1,18 @@ +from tests.utils import pool, storage + +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.yield_fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_create_pool_ledger_config_works(): + await pool.create_pool_ledger_config("pool_create") diff --git a/wrappers/python/tests/pool/test_open_pool_ledger.py b/wrappers/python/tests/pool/test_open_pool_ledger.py new file mode 100644 index 0000000000..18230463a3 --- /dev/null +++ b/wrappers/python/tests/pool/test_open_pool_ledger.py @@ -0,0 +1,21 @@ +from tests.utils import pool, storage +from indy.pool import open_pool_ledger +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.yield_fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_open_pool_ledger_works(): + name = "pool_create" + await pool.create_pool_ledger_config(name) + pool_handle = await open_pool_ledger(name, "") + assert pool_handle is not None diff --git a/wrappers/python/tests/utils/pool.py b/wrappers/python/tests/utils/pool.py new file mode 100644 index 0000000000..2f05442544 --- /dev/null +++ b/wrappers/python/tests/utils/pool.py @@ -0,0 +1,30 @@ +from .storage import indy_temp_path, create_temp_dir +from indy import pool + +import json + + +async def create_pool_ledger_config(config_name, nodes=None, pool_config=None, gen_txn_file_name=None): + file_name = gen_txn_file_name or (config_name + '.txn') + path = create_genesis_txn_file(file_name, nodes) + + pool_config = json.dumps(pool_config or {"genesis_txn": str(path)}) + await pool.create_pool_ledger_config(config_name, pool_config) + + +def create_genesis_txn_file(file_name, predefined_data=None): + path = indy_temp_path().joinpath(file_name) + + default_txn = [ + "{\"data\":{\"alias\":\"Node1\",\"client_ip\":\"10.0.0.2\",\"client_port\":9702,\"node_ip\":\"10.0.0.2\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\",\"identifier\":\"Th7MpTaRZVRYnPiabds81Y\",\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\",\"type\":\"0\"}\n", + "{\"data\":{\"alias\":\"Node2\",\"client_ip\":\"10.0.0.2\",\"client_port\":9704,\"node_ip\":\"10.0.0.2\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\",\"identifier\":\"EbP4aYNeTHL6q385GuVpRV\",\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\",\"type\":\"0\"}\n", + "{\"data\":{\"alias\":\"Node3\",\"client_ip\":\"10.0.0.2\",\"client_port\":9706,\"node_ip\":\"10.0.0.2\",\"node_port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\",\"identifier\":\"4cU41vWW82ArfxJxHkzXPG\",\"txnId\":\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\",\"type\":\"0\"}\n", + "{\"data\":{\"alias\":\"Node4\",\"client_ip\":\"10.0.0.2\",\"client_port\":9708,\"node_ip\":\"10.0.0.2\",\"node_port\":9707,\"services\":[\"VALIDATOR\"]},\"dest\":\"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA\",\"identifier\":\"TWwCRQRZ2ZHMJFn9TzLp7W\",\"txnId\":\"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008\",\"type\":\"0\"}\n" + ] + + create_temp_dir() + + with open(str(path), "w+") as f: + f.writelines(predefined_data or default_txn) + + return path diff --git a/wrappers/python/tests/utils/storage.py b/wrappers/python/tests/utils/storage.py index 0da89fc19b..5a3c214383 100644 --- a/wrappers/python/tests/utils/storage.py +++ b/wrappers/python/tests/utils/storage.py @@ -2,6 +2,7 @@ from shutil import rmtree from tempfile import gettempdir +import os import logging @@ -25,6 +26,10 @@ def indy_home_path() -> Path: return res +def create_temp_dir(): + os.makedirs(str(indy_temp_path())) + + def cleanup(): logger = logging.getLogger(__name__) logger.debug("cleanup: >>>") From d75992732a9924d6a88ad87aed93d3bed53f458a Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 18 Jul 2017 10:07:41 +0300 Subject: [PATCH 199/349] Implemented Ledger API integration tests for Java wrapper --- .../org/hyperledger/indy/sdk/LibIndy.java | 6 +- .../hyperledger/indy/sdk/ledger/Ledger.java | 12 +- .../indy/sdk/ledger/AttribRequestsTest.java | 154 +++++++++++++ .../indy/sdk/ledger/ClaimDefRequestsTest.java | 204 ++++++++++++++++++ .../indy/sdk/ledger/GetTxnRequestTest.java | 116 ++++++++++ .../indy/sdk/ledger/NodeRequestsTest.java | 184 ++++++++++++++++ .../indy/sdk/ledger/NymRequestsTest.java | 173 ++++++++++++--- .../indy/sdk/ledger/RequestsTest.java | 81 ++++--- .../indy/sdk/ledger/SchemaRequestsTest.java | 160 ++++++++++++++ 9 files changed, 1007 insertions(+), 83 deletions(-) create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AttribRequestsTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/ClaimDefRequestsTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/GetTxnRequestTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NodeRequestsTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/SchemaRequestsTest.java diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java index 162c5dc2ef..d3c814e417 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java @@ -42,9 +42,9 @@ public interface API extends Library { public int indy_build_get_attrib_request(int command_handle, String submitter_did, String target_did, String data, Callback cb); public int indy_build_get_nym_request(int command_handle, String submitter_did, String target_did, Callback cb); public int indy_build_schema_request(int command_handle, String submitter_did, String data, Callback cb); - public int indy_build_get_schema_request(int command_handle, String submitter_did, String data, Callback cb); - public int indy_build_claim_def_txn(int command_handle, String submitter_did, String xref, String data, Callback cb); - public int indy_build_get_claim_def_txn(int command_handle, String submitter_did, String xref, Callback cb); + public int indy_build_get_schema_request(int command_handle, String submitter_did, String dest, String data, Callback cb); + public int indy_build_claim_def_txn(int command_handle, String submitter_did, int xref, String signature_type, String data, Callback cb); + public int indy_build_get_claim_def_txn(int command_handle, String submitter_did, int xref, String signature_type, String origin, Callback cb); public int indy_build_node_request(int command_handle, String submitter_did, String target_did, String data, Callback cb); public int indy_build_get_txn_request(int command_handle, String submitter_did, int data, Callback cb); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java index f065b33f79..5f5943e2f4 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java @@ -366,6 +366,7 @@ public static CompletableFuture buildSchemaRequest( public static CompletableFuture buildGetSchemaRequest( String submitterDid, + String dest, String data) throws IndyException { CompletableFuture future = new CompletableFuture (); @@ -374,6 +375,7 @@ public static CompletableFuture buildGetSchemaRequest( int result = LibIndy.api.indy_build_get_schema_request( commandHandle, submitterDid, + dest, data, buildGetSchemaRequestCb); @@ -384,7 +386,8 @@ public static CompletableFuture buildGetSchemaRequest( public static CompletableFuture buildClaimDefTxn( String submitterDid, - String xref, + int xref, + String signatureType, String data) throws IndyException { CompletableFuture future = new CompletableFuture (); @@ -394,6 +397,7 @@ public static CompletableFuture buildClaimDefTxn( commandHandle, submitterDid, xref, + signatureType, data, buildClaimDefTxnCb); @@ -404,7 +408,9 @@ public static CompletableFuture buildClaimDefTxn( public static CompletableFuture buildGetClaimDefTxn( String submitterDid, - String xref) throws IndyException { + int xref, + String signatureType, + String origin) throws IndyException { CompletableFuture future = new CompletableFuture (); int commandHandle = addFuture(future); @@ -413,6 +419,8 @@ public static CompletableFuture buildGetClaimDefTxn( commandHandle, submitterDid, xref, + signatureType, + origin, buildGetClaimDefTxnCb); checkResult(result); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AttribRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AttribRequestsTest.java new file mode 100644 index 0000000000..d0a6385712 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AttribRequestsTest.java @@ -0,0 +1,154 @@ +package org.hyperledger.indy.sdk.ledger; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.pool.Pool; +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusJSONParameters; +import org.hyperledger.indy.sdk.signus.SignusResults; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.json.JSONObject; +import org.junit.*; +import org.junit.rules.Timeout; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class AttribRequestsTest extends IndyIntegrationTest { + + private Pool pool; + private Wallet wallet; + private String walletName = "ledgerWallet"; + + @Rule + public Timeout globalTimeout = new Timeout(5, TimeUnit.SECONDS); + + @Before + public void openPool() throws Exception { + String poolName = PoolUtils.createPoolLedgerConfig(); + pool = Pool.openPoolLedger(poolName, null).get(); + + Wallet.createWallet(poolName, walletName, "default", null, null).get(); + wallet = Wallet.openWallet(walletName, null, null).get(); + } + + @After + public void closePool() throws Exception { + pool.closePoolLedger().get(); + wallet.closeWallet().get(); + Wallet.deleteWallet(walletName, null).get(); + } + + @Test + public void testBuildAttribRequestWorksForRawData() throws Exception { + + String identifier = "Th7MpTaRZVRYnPiabds81Y"; + String dest = "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4"; + String raw = "{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}"; + + String expectedResult = String.format("\"identifier\":\"%s\"," + + "\"operation\":{" + + "\"type\":\"100\"," + + "\"dest\":\"%s\"," + + "\"raw\":\"{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}\"" + + "}", identifier, dest); + + String attribRequest = Ledger.buildAttribRequest(identifier, dest, null, raw, null).get(); + + assertTrue(attribRequest.replace("\\","").contains(expectedResult)); + } + + @Test + public void testBuildAttribRequestWorksForMissedAttribute() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + Ledger.buildAttribRequest("Th7MpTaRZVRYnPiabds81Y", + "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4", null, null, null).get(); + } + + @Test + public void testBuildGetAttribRequestWorks() throws Exception { + + String identifier = "Th7MpTaRZVRYnPiabds81Y"; + String dest = "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4"; + String raw = "endpoint"; + + String expectedResult = String.format("\"identifier\":\"%s\"," + + "\"operation\":{" + + "\"type\":\"104\"," + + "\"dest\":\"%s\"," + + "\"raw\":\"%s\"" + + "}", identifier, dest, raw); + + String getAttribRequest = Ledger.buildGetAttribRequest(identifier, dest, raw).get(); + + assertTrue(getAttribRequest.contains(expectedResult)); + } + + @Test + public void testSendAttribRequestWorksWithoutSignature() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.LedgerInvalidTransaction)); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String trusteeDid = trusteeDidResult.getDid(); + + String endpoint = "{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}"; + + String attribRequest = Ledger.buildAttribRequest(trusteeDid, trusteeDid, null, endpoint, null).get(); + Ledger.submitRequest(pool, attribRequest).get(); + } + + @Test + public void testAttribRequestsWorks() throws Exception { + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String trusteeDid = trusteeDidResult.getDid(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); + + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); + String myDid = myDidResult.getDid(); + String myVerkey = myDidResult.getVerkey(); + + String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, myVerkey, null, null).get(); + Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); + + String endpoint = "{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}"; + + String attribRequest = Ledger.buildAttribRequest(myDid, myDid, null, endpoint, null).get(); + Ledger.signAndSubmitRequest(pool, wallet, myDid, attribRequest).get(); + + String getAttribRequest = Ledger.buildGetAttribRequest(myDid, myDid, "endpoint").get(); + String getAttribResponse = Ledger.submitRequest(pool, getAttribRequest).get(); + + JSONObject getAttribResponseObject = new JSONObject(getAttribResponse); + + assertEquals(endpoint, getAttribResponseObject.getJSONObject("result").getString("data")); + } + + @Test + public void testBuildAttribRequestWorksForInvalidIdentifier() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + Ledger.buildAttribRequest("invalid_base58_identifier", + "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4", null, "{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}", null).get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/ClaimDefRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/ClaimDefRequestsTest.java new file mode 100644 index 0000000000..cc4ee91806 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/ClaimDefRequestsTest.java @@ -0,0 +1,204 @@ +package org.hyperledger.indy.sdk.ledger; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.anoncreds.Anoncreds; +import org.hyperledger.indy.sdk.pool.Pool; +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusJSONParameters; +import org.hyperledger.indy.sdk.signus.SignusResults; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.json.JSONObject; +import org.junit.*; +import org.junit.rules.Timeout; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertTrue; + +public class ClaimDefRequestsTest extends IndyIntegrationTest { + + private Pool pool; + private Wallet wallet; + private String walletName = "ledgerWallet"; + + @Rule + public Timeout globalTimeout = new Timeout(1, TimeUnit.MINUTES); + + @Before + public void openPool() throws Exception { + String poolName = PoolUtils.createPoolLedgerConfig(); + pool = Pool.openPoolLedger(poolName, null).get(); + + Wallet.createWallet(poolName, walletName, "default", null, null).get(); + wallet = Wallet.openWallet(walletName, null, null).get(); + } + + @After + public void closePool() throws Exception { + pool.closePoolLedger().get(); + wallet.closeWallet().get(); + Wallet.deleteWallet(walletName, null).get(); + } + + @Test + public void testBuildClaimDefRequestWorks() throws Exception { + + String identifier = "Th7MpTaRZVRYnPiabds81Y"; + String signature_type = "CL"; + int schema_seq_no = 1; + String data = "{\"primary\":{\"n\":\"1\",\"s\":\"2\",\"rms\":\"3\",\"r\":{\"name\":\"1\"},\"rctxt\":\"1\",\"z\":\"1\"}}"; + + String expectedResult = String.format("\"identifier\":\"%s\"," + + "\"operation\":{" + + "\"ref\":%d," + + "\"data\":\"%s\"," + + "\"type\":\"102\"," + + "\"signature_type\":\"%s\"" + + "}", identifier, schema_seq_no, data, signature_type); + + String claimDefRequest = Ledger.buildClaimDefTxn(identifier, schema_seq_no, signature_type, data).get(); + + assertTrue(claimDefRequest.replace("\\", "").contains(expectedResult)); + } + + @Test + public void testBuildGetClaimDefRequestWorks() throws Exception { + + String identifier = "Th7MpTaRZVRYnPiabds81Y"; + String origin = "Th7MpTaRZVRYnPiabds81Y"; + String signature_type = "CL"; + int ref = 1; + + String expectedResult = String.format("\"identifier\":\"%s\"," + + "\"operation\":{" + + "\"type\":\"108\"," + + "\"ref\":%d," + + "\"signature_type\":\"%s\"," + + "\"origin\":\"%s\"" + + "}", identifier, ref, signature_type, origin); + + String getClaimDefRequest = Ledger.buildGetClaimDefTxn(identifier, ref, signature_type, origin).get(); + + assertTrue(getClaimDefRequest.replace("\\", "").contains(expectedResult)); + } + + @Test + public void testBuildClaimDefRequestWorksForInvalidJson() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String identifier = "Th7MpTaRZVRYnPiabds81Y"; + String signature_type = "CL"; + int schema_seq_no = 1; + String data = "{\"primary\":{\"n\":\"1\",\"s\":\"2\",\"rms\":\"3\",\"r\":{\"name\":\"1\"}}}"; + + Ledger.buildClaimDefTxn(identifier, schema_seq_no, signature_type, data).get(); + } + + @Test + public void testClaimDefRequestsWorks() throws Exception { + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String trusteeDid = trusteeDidResult.getDid(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, null, null); + + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); + String myDid = myDidResult.getDid(); + String myVerkey = myDidResult.getVerkey(); + + String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, myVerkey, null, null).get(); + Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); + + String schemaData = "{\"name\":\"gvt2\",\"version\":\"2.0\",\"keys\": [\"name\", \"male\"]}"; + + String schemaRequest = Ledger.buildSchemaRequest(myDid, schemaData).get(); + Ledger.signAndSubmitRequest(pool, wallet, myDid, schemaRequest).get(); + + String getSchemaData = "{\"name\":\"gvt2\",\"version\":\"2.0\"}"; + String getSchemaRequest = Ledger.buildGetSchemaRequest(myDid, myDid, getSchemaData).get(); + String getSchemaResponse = Ledger.submitRequest(pool, getSchemaRequest).get(); + + JSONObject schemaObj = new JSONObject(getSchemaResponse); + + int schemaSeqNo = schemaObj.getJSONObject("result").getInt("seqNo"); + String schemaJson = String.format("{\"seqNo\":%d,\"data\":%s}", schemaSeqNo, schemaData); + + String claimDef = Anoncreds.issuerCreateAndStoreClaimDef(wallet, myDid, schemaJson, null, false).get(); + + JSONObject claimDefObj = new JSONObject(claimDef); + + String claimDefJson = String.format("%s", claimDefObj.getJSONObject("data")); + String signatureType = claimDefObj.getString("signature_type"); + + String claimDefRequest = Ledger.buildClaimDefTxn(myDid, schemaSeqNo, signatureType, claimDefJson).get(); + Ledger.signAndSubmitRequest(pool, wallet, myDid, claimDefRequest).get(); + + String getClaimDefRequest = Ledger.buildGetClaimDefTxn(myDid, schemaSeqNo, signatureType, claimDefObj.getString("origin")).get(); + String getClaimDefResponse = Ledger.submitRequest(pool, getClaimDefRequest).get(); + + JSONObject getClaimDefResponseObj = new JSONObject(getClaimDefResponse); + + JSONObject expectedClaimDef = claimDefObj.getJSONObject("data").getJSONObject("primary"); + JSONObject actualClaimDef = getClaimDefResponseObj.getJSONObject("result").getJSONObject("data").getJSONObject("primary"); + + Assert.assertEquals(expectedClaimDef.getString("n"), actualClaimDef.getString("n")); + Assert.assertEquals(expectedClaimDef.getString("rms"), actualClaimDef.getString("rms")); + Assert.assertEquals(expectedClaimDef.getString("rctxt"), actualClaimDef.getString("rctxt")); + Assert.assertEquals(expectedClaimDef.getString("z"), actualClaimDef.getString("z")); + Assert.assertEquals(expectedClaimDef.getString("n"), actualClaimDef.getString("n")); + Assert.assertEquals(expectedClaimDef.getJSONObject("r").toString(), actualClaimDef.getJSONObject("r").toString()); + + } + + @Test + public void testClaimDefRequestWorksWithoutSignature() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.LedgerInvalidTransaction)); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String trusteeDid = trusteeDidResult.getDid(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, null, null); + + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); + String myDid = myDidResult.getDid(); + String myVerkey = myDidResult.getVerkey(); + + String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, myVerkey, null, null).get(); + Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); + + String schemaData = "{\"name\":\"gvt2\",\"version\":\"2.0\",\"keys\": [\"name\", \"male\"]}"; + + String schemaRequest = Ledger.buildSchemaRequest(myDid, schemaData).get(); + String schemaResponse = Ledger.signAndSubmitRequest(pool, wallet, myDid, schemaRequest).get(); + + JSONObject schemaObj = new JSONObject(schemaResponse); + + int schemaSeqNo = schemaObj.getJSONObject("result").getInt("seqNo"); + String schemaJson = String.format("{\"seqNo\":%d,\"data\":%s}", schemaSeqNo, schemaData); + + String claimDef = Anoncreds.issuerCreateAndStoreClaimDef(wallet, myDid, schemaJson, null, false).get(); + + JSONObject claimDefObj = new JSONObject(claimDef); + + String claimDefJson = String.format("%s", claimDefObj.getJSONObject("data")); + + String claimDefRequest = Ledger.buildClaimDefTxn(myDid, schemaSeqNo, claimDefObj.getString("signature_type"), claimDefJson).get(); + Ledger.submitRequest(pool, claimDefRequest).get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/GetTxnRequestTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/GetTxnRequestTest.java new file mode 100644 index 0000000000..6ddfc2042a --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/GetTxnRequestTest.java @@ -0,0 +1,116 @@ +package org.hyperledger.indy.sdk.ledger; + +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.pool.Pool; +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusJSONParameters; +import org.hyperledger.indy.sdk.signus.SignusResults; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.json.JSONObject; +import org.junit.*; +import org.junit.rules.Timeout; + +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class GetTxnRequestTest extends IndyIntegrationTest { + + private Pool pool; + private Wallet wallet; + private String walletName = "ledgerWallet"; + + @Rule + public Timeout globalTimeout = new Timeout(5, TimeUnit.SECONDS); + + @Before + public void openPool() throws Exception { + String poolName = PoolUtils.createPoolLedgerConfig(); + pool = Pool.openPoolLedger(poolName, null).get(); + + Wallet.createWallet(poolName, walletName, "default", null, null).get(); + wallet = Wallet.openWallet(walletName, null, null).get(); + } + + @After + public void closePool() throws Exception { + pool.closePoolLedger().get(); + wallet.closeWallet().get(); + Wallet.deleteWallet(walletName, null).get(); + } + + @Test + public void testBuildGetTxnRequestWorks() throws Exception { + + String identifier = "Th7MpTaRZVRYnPiabds81Y"; + int data = 1; + + String expectedResult = String.format("\"identifier\":\"%s\"," + + "\"operation\":{" + + "\"type\":\"3\"," + + "\"data\":%s" + + "}", identifier, data); + + String getTxnRequest = Ledger.buildGetTxnRequest(identifier, data).get(); + + assertTrue(getTxnRequest.replace("\\", "").contains(expectedResult)); + } + + @Test + public void testGetTxnRequestWorks() throws Exception { + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult didResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String did = didResult.getDid(); + + String schemaData = "{\"name\":\"gvt2\",\"version\":\"3.0\",\"keys\": [\"name\", \"male\"]}"; + + String schemaRequest = Ledger.buildSchemaRequest(did, schemaData).get(); + String schemaResponse = Ledger.signAndSubmitRequest(pool, wallet, did, schemaRequest).get(); + + JSONObject schemaResponseObj = new JSONObject(schemaResponse); + + int seqNo = schemaResponseObj.getJSONObject("result").getInt("seqNo"); + + String getTxnRequest = Ledger.buildGetTxnRequest(did, seqNo).get(); + String getTxnResponse = Ledger.submitRequest(pool, getTxnRequest).get(); + + JSONObject getTxnResponseObj = new JSONObject(getTxnResponse); + + String schemaTransaction = getTxnResponseObj.getJSONObject("result").getString("data"); + JSONObject schemaTransactionObj = new JSONObject(schemaTransaction); + + assertEquals(schemaData, schemaTransactionObj.getString("data")); + } + + @Test + public void testGetTxnRequestWorksForInvalidSeqNo() throws Exception { + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult didResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String did = didResult.getDid(); + + String schemaData = "{\"name\":\"gvt2\",\"version\":\"3.0\",\"keys\": [\"name\", \"male\"]}"; + + String schemaRequest = Ledger.buildSchemaRequest(did, schemaData).get(); + String schemaResponse = Ledger.signAndSubmitRequest(pool, wallet, did, schemaRequest).get(); + + JSONObject schemaResponseObj = new JSONObject(schemaResponse); + + int seqNo = schemaResponseObj.getJSONObject("result").getInt("seqNo") + 1; + + String getTxnRequest = Ledger.buildGetTxnRequest(did, seqNo).get(); + String getTxnResponse = Ledger.submitRequest(pool, getTxnRequest).get(); + + JSONObject getTxnResponseObj = new JSONObject(getTxnResponse); + + String schemaTransaction = getTxnResponseObj.getJSONObject("result").getString("data"); + assertEquals("{}", schemaTransaction); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NodeRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NodeRequestsTest.java new file mode 100644 index 0000000000..a82979feb7 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NodeRequestsTest.java @@ -0,0 +1,184 @@ +package org.hyperledger.indy.sdk.ledger; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.pool.Pool; +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusJSONParameters; +import org.hyperledger.indy.sdk.signus.SignusResults; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.junit.*; +import org.junit.rules.Timeout; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertTrue; + +public class NodeRequestsTest extends IndyIntegrationTest { + + private Pool pool; + private Wallet wallet; + private String walletName = "ledgerWallet"; + + @Rule + public Timeout globalTimeout = new Timeout(5, TimeUnit.SECONDS); + + @Before + public void openPool() throws Exception { + String poolName = PoolUtils.createPoolLedgerConfig(); + pool = Pool.openPoolLedger(poolName, null).get(); + + Wallet.createWallet(poolName, walletName, "default", null, null).get(); + wallet = Wallet.openWallet(walletName, null, null).get(); + } + + @After + public void closePool() throws Exception { + pool.closePoolLedger().get(); + wallet.closeWallet().get(); + Wallet.deleteWallet(walletName, null).get(); + } + + @Test + public void testBuildNodeRequestWorks() throws Exception { + + String identifier = "Th7MpTaRZVRYnPiabds81Y"; + String dest = "Th7MpTaRZVRYnPiabds81Y"; + String data = "{\"node_ip\":\"10.0.0.100\"," + + "\"node_port\":910," + + "\"client_ip\":\"10.0.0.100\"," + + "\"client_port\":911," + + "\"alias\":\"some\"," + + "\"services\":[\"VALIDATOR\"]}"; + + String expectedResult = String.format("\"identifier\":\"%s\"," + + "\"operation\":{" + + "\"type\":\"0\"," + + "\"dest\":\"%s\"," + + "\"data\":%s" + + "}", identifier, dest, data); + + String nodeRequest = Ledger.buildNodeRequest(identifier, dest, data).get(); + + assertTrue(nodeRequest.replace("\\", "").contains(expectedResult)); + } + + @Test + public void testSendNodeRequestWorksWithoutSignature() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.LedgerInvalidTransaction)); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Steward1", null, null); + + SignusResults.CreateAndStoreMyDidResult didResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String did = didResult.getDid(); + + String data = "{\"node_ip\":\"10.0.0.100\"," + + "\"node_port\":910," + + "\"client_ip\":\"10.0.0.100\"," + + "\"client_port\":910," + + "\"alias\":\"some\"," + + "\"services\":[\"VALIDATOR\"]}"; + + String nodeRequest = Ledger.buildNodeRequest(did, did, data).get(); + Ledger.submitRequest(pool, nodeRequest).get(); + } + + @Test + public void testBuildNodeRequestWorksForWrongServiceType() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String identifier = "Th7MpTaRZVRYnPiabds81Y"; + String dest = "Th7MpTaRZVRYnPiabds81Y"; + String data = "{\"node_ip\":\"10.0.0.100\"," + + "\"node_port\":910," + + "\"client_ip\":\"10.0.0.100\"," + + "\"client_port\":911," + + "\"alias\":\"some\"," + + "\"services\":[\"SERVICE\"]}"; + + Ledger.buildNodeRequest(identifier, dest, data).get(); + } + + @Test + public void testBuildNodeRequestWorksForMissedField() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String identifier = "Th7MpTaRZVRYnPiabds81Y"; + String dest = "Th7MpTaRZVRYnPiabds81Y"; + String data = "{\"node_ip\":\"10.0.0.100\"," + + "\"node_port\":910," + + "\"client_ip\":\"10.0.0.100\"," + + "\"client_port\":910," + + "\"services\":[\"VALIDATOR\"]}"; + + Ledger.buildNodeRequest(identifier, dest, data).get(); + } + + @Test + public void testSendNodeRequestWorksForWrongRole() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.LedgerInvalidTransaction)); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult didResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String did = didResult.getDid(); + + String data = "{\"node_ip\":\"10.0.0.100\"," + + "\"node_port\":910," + + "\"client_ip\":\"10.0.0.100\"," + + "\"client_port\":911," + + "\"alias\":\"some\"," + + "\"services\":[\"VALIDATOR\"]}"; + + String nodeRequest = Ledger.buildNodeRequest(did, did, data).get(); + Ledger.signAndSubmitRequest(pool, wallet, did, nodeRequest).get(); + } + + @Test + @Ignore + public void testSendNodeRequestWorksForNewSteward() throws Exception { + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult didResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String trusteeDid = didResult.getDid(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, null, null); + + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); + String myDid = myDidResult.getDid(); + String myVerkey = myDidResult.getVerkey(); + + String role = "STEWARD"; + + String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, myVerkey, null, role).get(); + Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); + + String data = "{\"node_ip\":\"10.0.0.100\"," + + "\"node_port\":910," + + "\"client_ip\":\"10.0.0.100\"," + + "\"client_port\":911," + + "\"alias\":\"some\"," + + "\"services\":[\"VALIDATOR\"]}"; + + String dest = "A5iWQVT3k8Zo9nXj4otmeqaUziPQPCiDqcydXkAJBk1Y"; + + String nodeRequest = Ledger.buildNodeRequest(myDid, dest, data).get(); + Ledger.signAndSubmitRequest(pool, wallet, myDid, nodeRequest).get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java index f0f8f59656..5f2d632cda 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java @@ -4,26 +4,47 @@ import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.pool.Pool; -import org.hyperledger.indy.sdk.pool.PoolJSONParameters; import org.hyperledger.indy.sdk.signus.Signus; import org.hyperledger.indy.sdk.signus.SignusJSONParameters; import org.hyperledger.indy.sdk.signus.SignusResults; import org.hyperledger.indy.sdk.utils.PoolUtils; import org.hyperledger.indy.sdk.wallet.Wallet; import org.json.JSONObject; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; import org.junit.rules.Timeout; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + public class NymRequestsTest extends IndyIntegrationTest { + private Pool pool; + private Wallet wallet; + private String walletName = "ledgerWallet"; + @Rule public Timeout globalTimeout = new Timeout(5, TimeUnit.SECONDS); + @Before + public void openPool() throws Exception { + String poolName = PoolUtils.createPoolLedgerConfig(); + pool = Pool.openPoolLedger(poolName, null).get(); + + Wallet.createWallet(poolName, walletName, "default", null, null).get(); + wallet = Wallet.openWallet(walletName, null, null).get(); + } + + @After + public void closePool() throws Exception { + pool.closePoolLedger().get(); + wallet.closeWallet().get(); + Wallet.deleteWallet(walletName, null).get(); + } + @Test public void testBuildNymRequestWorksForOnlyRequiredFields() throws Exception { @@ -34,7 +55,7 @@ public void testBuildNymRequestWorksForOnlyRequiredFields() throws Exception { String nymRequest = Ledger.buildNymRequest(identifier, dest, null, null, null).get(); - Assert.assertTrue(nymRequest.contains(expectedResult)); + assertTrue(nymRequest.contains(expectedResult)); } @Test @@ -53,11 +74,11 @@ public void testBuildNymRequestWorksForOnlyOptionalFields() throws Exception { "\"verkey\":\"%s\"," + "\"alias\":\"%s\"," + "\"role\":\"2\"" + - "}", identifier, dest, verkey, alias, role); + "}", identifier, dest, verkey, alias); String nymRequest = Ledger.buildNymRequest(identifier, dest, verkey, alias, role).get(); - Assert.assertTrue(nymRequest.contains(expectedResult)); + assertTrue(nymRequest.contains(expectedResult)); } @Test @@ -70,7 +91,7 @@ public void testBuildGetNymRequestWorks() throws Exception { String nymRequest = Ledger.buildGetNymRequest(identifier, dest).get(); - Assert.assertTrue(nymRequest.contains(expectedResult)); + assertTrue(nymRequest.contains(expectedResult)); } @Test @@ -79,14 +100,6 @@ public void testNymRequestWorksWithoutSignature() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.LedgerInvalidTransaction)); - String poolName = PoolUtils.createPoolLedgerConfig(); - - PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); - Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); - - Wallet.createWallet(poolName, "ledgerWallet", "default", null, null).get(); - Wallet wallet = Wallet.openWallet("ledgerWallet", null, null).get(); - SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); @@ -98,15 +111,52 @@ public void testNymRequestWorksWithoutSignature() throws Exception { } @Test - public void testGetNymRequestWorks() throws Exception { + public void testSendNymRequestsWorksForOnlyRequiredFields() throws Exception { - String poolName = PoolUtils.createPoolLedgerConfig(); + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String trusteeDid = trusteeDidResult.getDid(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); + + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); + String myDid = myDidResult.getDid(); - PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); - Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); + String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, null, null, null).get(); + String nymResponse = Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); - Wallet.createWallet(poolName, "ledgerWallet", "default", null, null).get(); - Wallet wallet = Wallet.openWallet("ledgerWallet", null, null).get(); + assertNotNull(nymResponse); + } + + @Test + public void testSendNymRequestsWorksForOptionalFields() throws Exception { + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String trusteeDid = trusteeDidResult.getDid(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); + + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); + String myDid = myDidResult.getDid(); + String myVerkey = myDidResult.getVerkey(); + String role = "STEWARD"; + String alias = "some_alias"; + + String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, myVerkey, alias, role).get(); + String nymResponse = Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); + + assertNotNull(nymResponse); + } + + @Test + public void testGetNymRequestWorks() throws Exception { SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); @@ -119,21 +169,64 @@ public void testGetNymRequestWorks() throws Exception { JSONObject getNymResponse = new JSONObject(getNymResponseJson); - Assert.assertEquals("REPLY", getNymResponse.getString("op")); - Assert.assertEquals("105", getNymResponse.getJSONObject("result").getString("type")); - Assert.assertEquals(did, getNymResponse.getJSONObject("result").getString("dest")); + assertEquals(did, getNymResponse.getJSONObject("result").getString("dest")); } @Test - public void testNymRequestsWorks() throws Exception { + public void testSendNymRequestsWorksForWrongSignerRole() throws Exception { - String poolName = PoolUtils.createPoolLedgerConfig(); + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.LedgerInvalidTransaction)); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String trusteeDid = trusteeDidResult.getDid(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, null, null); + + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); + String myDid = myDidResult.getDid(); + + String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, null, null, null).get(); + Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson2 = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, null, null); + + SignusResults.CreateAndStoreMyDidResult myDidResult2 = Signus.createAndStoreMyDid(wallet, myDidJson2.toJson()).get(); + String myDid2 = myDidResult2.getDid(); + + String nymRequest2 = Ledger.buildNymRequest(myDid, myDid2, null, null, null).get(); + Ledger.signAndSubmitRequest(pool, wallet, myDid, nymRequest2).get(); + } + + @Test + public void testSendNymRequestsWorksForUnknownSigner() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.LedgerInvalidTransaction)); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee9", null, null); + + SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String trusteeDid = trusteeDidResult.getDid(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, null, null); + + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); + String myDid = myDidResult.getDid(); - PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); - Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); + String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, null, null, null).get(); + Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); + } - Wallet.createWallet(poolName, "ledgerWallet", "default", null, null).get(); - Wallet wallet = Wallet.openWallet("ledgerWallet", null, null).get(); + @Test + public void testNymRequestsWorks() throws Exception { SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); @@ -142,7 +235,7 @@ public void testNymRequestsWorks() throws Exception { String trusteeDid = trusteeDidResult.getDid(); SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); String myDid = myDidResult.getDid(); @@ -156,8 +249,18 @@ public void testNymRequestsWorks() throws Exception { JSONObject getNymResponse = new JSONObject(getNymResponseJson); - Assert.assertEquals("REPLY", getNymResponse.getString("op")); - Assert.assertEquals("105", getNymResponse.getJSONObject("result").getString("type")); - Assert.assertEquals(myDid, getNymResponse.getJSONObject("result").getString("dest")); + assertEquals("REPLY", getNymResponse.getString("op")); + assertEquals("105", getNymResponse.getJSONObject("result").getString("type")); + assertEquals(myDid, getNymResponse.getJSONObject("result").getString("dest")); + } + + @Test + public void testSendNymRequestsWorksForWrongRole() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + Ledger.buildNymRequest("Th7MpTaRZVRYnPiabds81Y", + "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4", null, null, "WRONG_ROLE").get(); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java index cb9f1507d9..caa8e6803d 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java @@ -4,19 +4,15 @@ import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; import org.hyperledger.indy.sdk.pool.Pool; -import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; import org.hyperledger.indy.sdk.signus.Signus; import org.hyperledger.indy.sdk.signus.SignusJSONParameters; import org.hyperledger.indy.sdk.signus.SignusResults; import org.hyperledger.indy.sdk.utils.PoolUtils; import org.hyperledger.indy.sdk.wallet.Wallet; import org.json.JSONObject; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; import org.junit.rules.Timeout; -import java.math.BigInteger; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -24,25 +20,33 @@ public class RequestsTest extends IndyIntegrationTest { + private String poolName; + private Pool pool; + @Rule public Timeout globalTimeout = new Timeout(5, TimeUnit.SECONDS); - @Test - public void testSubmitRequestWorks() throws Exception { + @Before + public void openPool() throws Exception { + poolName = PoolUtils.createPoolLedgerConfig(); + pool = Pool.openPoolLedger(poolName, null).get(); + } - String poolName = PoolUtils.createPoolLedgerConfig(); - Pool pool = Pool.openPoolLedger(poolName, null).get(); + @After + public void closePool() throws Exception { + pool.closePoolLedger().get(); + } - Wallet.createWallet("otherPoolName", "ledgerWallet", "default", null, null).get(); + @Test + public void testSubmitRequestWorks() throws Exception { - String request = "{\n" + - " \"reqId\":1491566332010860,\n" + - " \"identifier\":\"Th7MpTaRZVRYnPiabds81Y\",\n" + - " \"operation\":{\n" + - " \"type\":\"105\",\n" + - " \"dest\":\"Th7MpTaRZVRYnPiabds81Y\"\n" + - " },\n" + - " \"signature\":\"4o86XfkiJ4e2r3J6Ufoi17UU3W5Zi9sshV6FjBjkVw4sgEQFQov9dxqDEtLbAJAWffCWd5KfAk164QVo7mYwKkiV\"}"; + String request = "{\"reqId\":1491566332010860,\n" + + " \"identifier\":\"Th7MpTaRZVRYnPiabds81Y\",\n" + + " \"operation\":{\n" + + " \"type\":\"105\",\n" + + " \"dest\":\"Th7MpTaRZVRYnPiabds81Y\"\n" + + " },\n" + + " \"signature\":\"4o86XfkiJ4e2r3J6Ufoi17UU3W5Zi9sshV6FjBjkVw4sgEQFQov9dxqDEtLbAJAWffCWd5KfAk164QVo7mYwKkiV\"}"; String response = Ledger.submitRequest(pool, request).get(); @@ -54,35 +58,30 @@ public void testSubmitRequestWorks() throws Exception { Assert.assertEquals("{\"dest\":\"Th7MpTaRZVRYnPiabds81Y\",\"identifier\":\"V4SGRU86Z58d6TV7PBUe6f\",\"role\":\"2\",\"verkey\":\"~7TYfekw4GUagBnBVCqPjiC\"}", responseObject.getJSONObject("result").getString("data")); Assert.assertEquals("Th7MpTaRZVRYnPiabds81Y", responseObject.getJSONObject("result").getString("identifier")); Assert.assertEquals("Th7MpTaRZVRYnPiabds81Y", responseObject.getJSONObject("result").getString("dest")); - - pool.closePoolLedger().get(); } @Test public void testSignAndSubmitRequestWorks() throws Exception { - String poolName = PoolUtils.createPoolLedgerConfig(); - Pool pool = Pool.openPoolLedger(poolName, null).get(); - Wallet.createWallet(poolName, "ledgerWallet", "default", null, null).get(); Wallet wallet = Wallet.openWallet("ledgerWallet", null, null).get(); - SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); - - SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); - String myDid = myDidResult.getDid(); - SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); + SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); + + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); + String myDid = myDidResult.getDid(); + String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, null, null, null).get(); - Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); + String nymResponse = Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); + assertNotNull(nymResponse); - pool.closePoolLedger().get(); wallet.closeWallet().get(); Wallet.deleteWallet("ledgerWallet", null).get(); } @@ -93,11 +92,14 @@ public void testSignAndSubmitRequestWorksForIncompatibleWalletAndPool() throws E thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletIncompatiblePoolError)); - String poolName = PoolUtils.createPoolLedgerConfig(); - Pool pool = Pool.openPoolLedger(poolName, null).get(); + Wallet.createWallet("otherPoolName", "wallet", "default", null, null).get(); + Wallet wallet = Wallet.openWallet("wallet", null, null).get(); - Wallet.createWallet("otherPoolName", "ledgerWallet", "default", null, null).get(); - Wallet wallet = Wallet.openWallet("ledgerWallet", null, null).get(); + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String trusteeDid = trusteeDidResult.getDid(); SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); @@ -105,17 +107,10 @@ public void testSignAndSubmitRequestWorksForIncompatibleWalletAndPool() throws E SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); String myDid = myDidResult.getDid(); - SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); - - SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); - String trusteeDid = trusteeDidResult.getDid(); - String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, null, null, null).get(); Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); - pool.closePoolLedger().get(); wallet.closeWallet().get(); - Wallet.deleteWallet("ledgerWallet", null).get(); + Wallet.deleteWallet("wallet", null).get(); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/SchemaRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/SchemaRequestsTest.java new file mode 100644 index 0000000000..e709bff8f7 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/SchemaRequestsTest.java @@ -0,0 +1,160 @@ +package org.hyperledger.indy.sdk.ledger; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.pool.Pool; +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusJSONParameters; +import org.hyperledger.indy.sdk.signus.SignusResults; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.json.JSONObject; +import org.junit.*; +import org.junit.rules.Timeout; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import static junit.framework.TestCase.assertNull; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class SchemaRequestsTest extends IndyIntegrationTest { + + private Pool pool; + private Wallet wallet; + private String walletName = "ledgerWallet"; + + @Rule + public Timeout globalTimeout = new Timeout(5, TimeUnit.SECONDS); + + @Before + public void openPool() throws Exception { + String poolName = PoolUtils.createPoolLedgerConfig(); + pool = Pool.openPoolLedger(poolName, null).get(); + + Wallet.createWallet(poolName, walletName, "default", null, null).get(); + wallet = Wallet.openWallet(walletName, null, null).get(); + } + + @After + public void closePool() throws Exception { + pool.closePoolLedger().get(); + wallet.closeWallet().get(); + Wallet.deleteWallet(walletName, null).get(); + } + + @Test + public void testBuildSchemaRequestWorks() throws Exception { + + String identifier = "Th7MpTaRZVRYnPiabds81Y"; + String data = "{\"name\":\"name\", \"version\":\"1.0\", \"keys\":[\"name\",\"male\"]}"; + + String expectedResult = String.format("\"identifier\":\"%s\"," + + "\"operation\":{" + + "\"type\":\"101\"," + + "\"data\":\"%s\"" + + "}", identifier, data); + + String schemaRequest = Ledger.buildSchemaRequest(identifier, data).get(); + + assertTrue(schemaRequest.replace("\\", "").contains(expectedResult)); + } + + @Test + public void testBuildGetSchemaRequestWorks() throws Exception { + + String identifier = "Th7MpTaRZVRYnPiabds81Y"; + String data = "{\"name\":\"name\",\"version\":\"1.0\"}"; + + String expectedResult = String.format("\"identifier\":\"%s\"," + + "\"operation\":{" + + "\"type\":\"107\"," + + "\"dest\":\"%s\"," + + "\"data\":%s" + + "}", identifier, identifier, data); + + String getSchemaRequest = Ledger.buildGetSchemaRequest(identifier, identifier, data).get(); + + assertTrue(getSchemaRequest.contains(expectedResult)); + } + + @Test + public void testSchemaRequestWorksWithoutSignature() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.LedgerInvalidTransaction)); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult didResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String did = didResult.getDid(); + + String schemaData = "{\"name\":\"gvt2\",\n" + + " \"version\":\"2.0\",\n" + + " \"keys\": [\"name\", \"male\"]}"; + + String schemaRequest = Ledger.buildSchemaRequest(did, schemaData).get(); + String schemaResponse = Ledger.submitRequest(pool, schemaRequest).get(); + + assertNotNull(schemaResponse); + } + + @Test + public void testSchemaRequestsWorks() throws Exception { + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult didResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String did = didResult.getDid(); + + String schemaData = "{\"name\":\"gvt2\",\"version\":\"2.0\",\"keys\": [\"name\", \"male\"]}"; + + String schemaRequest = Ledger.buildSchemaRequest(did, schemaData).get(); + Ledger.signAndSubmitRequest(pool, wallet, did, schemaRequest).get(); + + String getSchemaData = "{\"name\":\"gvt2\",\"version\":\"2.0\"}"; + String getSchemaRequest = Ledger.buildGetSchemaRequest(did, did, getSchemaData).get(); + String getSchemaResponse = Ledger.submitRequest(pool, getSchemaRequest).get(); + + JSONObject getSchemaResponseObject = new JSONObject(getSchemaResponse); + + assertEquals("gvt2", getSchemaResponseObject.getJSONObject("result").getJSONObject("data").getString("name")); + assertEquals("2.0", getSchemaResponseObject.getJSONObject("result").getJSONObject("data").getString("version")); + assertEquals(did, getSchemaResponseObject.getJSONObject("result").getJSONObject("data").getString("origin")); + } + + @Test + public void testGetSchemaRequestsWorksForUnknownSchema() throws Exception { + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult didResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String did = didResult.getDid(); + + String getSchemaData = "{\"name\":\"schema_name\",\"version\":\"2.0\"}"; + String getSchemaRequest = Ledger.buildGetSchemaRequest(did, did, getSchemaData).get(); + String getSchemaResponse = Ledger.submitRequest(pool, getSchemaRequest).get(); + + JSONObject getSchemaResponseObject = new JSONObject(getSchemaResponse); + + assertNull(getSchemaResponseObject.getJSONObject("result").optJSONObject("data")); + } + + @Test + public void testBuildSchemaRequestWorksForMissedFields() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String identifier = "Th7MpTaRZVRYnPiabds81Y"; + String data = "{\"name\":\"name\",\"version\":\"1.0\"}"; + + Ledger.buildSchemaRequest(identifier, data).get(); + } +} From 066b4056dcaf81421455bc070d26004caeaad9cb Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Tue, 18 Jul 2017 10:38:54 +0300 Subject: [PATCH 200/349] * Use natural order of params in do_call method of libindy * Added some initial code for agent_connect --- wrappers/python/indy/agent.py | 46 +++++++++++++++++++++++++++++++++ wrappers/python/indy/libindy.py | 5 ++-- wrappers/python/indy/signus.py | 28 ++++++++++---------- wrappers/python/indy/wallet.py | 20 ++++++++------ 4 files changed, 74 insertions(+), 25 deletions(-) create mode 100644 wrappers/python/indy/agent.py diff --git a/wrappers/python/indy/agent.py b/wrappers/python/indy/agent.py new file mode 100644 index 0000000000..dc86d9a86e --- /dev/null +++ b/wrappers/python/indy/agent.py @@ -0,0 +1,46 @@ +import logging +from ctypes import * + +from .libindy import do_call, create_cb + + +async def agent_connect(pool_handle: int, + wallet_handle: int, + sender_did: str, + receiver_did: str) -> int: + logger = logging.getLogger(__name__) + logger.debug("agent_connect: >>> pool_handle: %i, wallet_handle: %i, sender_did: %s, receiver_did: %s", + pool_handle, + wallet_handle, + sender_did, + receiver_did) + + if not hasattr(agent_connect, "connection_cb"): + logger.debug("agent_connect: Creating callback") + agent_connect.connection_cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) + + def _message_cb(connection_handle, err, message): + logger.debug("agent_connect._message_cb: connection_handle: %i, err: %i, message: %s", + connection_handle, + err, + message) + + if not hasattr(agent_connect, "message_cb"): + logger.debug("agent_connect: Creating connection callback") + agent_connect.message_cb = CFUNCTYPE(None, c_int32, c_int32, c_int32)(_message_cb) + + c_pool_handle = c_int32(pool_handle) + c_wallet_handle = c_int32(wallet_handle) + c_sender_did = c_char_p(sender_did.encode('utf-8')) + c_receiver_did = c_char_p(receiver_did.encode('utf-8')) + + res = await do_call('agent_connect', + c_pool_handle, + c_wallet_handle, + c_sender_did, + c_receiver_did, + agent_connect.connection_cb, + agent_connect.message_cb) + + logger.debug("agent_connect: <<< res: %i", res) + return res diff --git a/wrappers/python/indy/libindy.py b/wrappers/python/indy/libindy.py index 394cccef10..0cf01ec5fc 100644 --- a/wrappers/python/indy/libindy.py +++ b/wrappers/python/indy/libindy.py @@ -11,7 +11,7 @@ _futures_counter = itertools.count() -def do_call(name: str, cb: CFUNCTYPE, *args): +def do_call(name: str, *args): logger = logging.getLogger(__name__) logger.debug("do_call: >>> name: %s, args: %s", name, args) @@ -22,8 +22,7 @@ def do_call(name: str, cb: CFUNCTYPE, *args): _futures[command_handle] = (event_loop, future) err = getattr(_cdll(), name)(command_handle, - *args, - cb) + *args) logger.debug("do_call: Function %s returned err: %i", name, err) diff --git a/wrappers/python/indy/signus.py b/wrappers/python/indy/signus.py index 2e42a8b8f6..63723cedd5 100644 --- a/wrappers/python/indy/signus.py +++ b/wrappers/python/indy/signus.py @@ -19,9 +19,9 @@ async def create_and_store_my_did(wallet_handle: int, c_did_json = c_char_p(did_json.encode('utf-8')) res = await do_call('indy_create_and_store_my_did', - create_and_store_my_did.cb, c_wallet_handle, - c_did_json) + c_did_json, + create_and_store_my_did.cb) logger.debug("create_and_store_my_did: <<< res: %s", res) return res @@ -44,10 +44,10 @@ async def replace_keys(wallet_handle: int, c_identity_json = c_char_p(identity_json.encode('utf-8')) res = await do_call('indy_replace_keys', - replace_keys.cb, c_wallet_handle, c_did, - c_identity_json) + c_identity_json, + replace_keys.cb) logger.debug("replace_keys: <<< res: %s", res) return res @@ -68,9 +68,9 @@ async def store_their_did(wallet_handle: int, c_identity_json = c_char_p(identity_json.encode('utf-8')) res = await do_call('indy_store_their_did', - store_their_did.cb, c_wallet_handle, - c_identity_json) + c_identity_json, + store_their_did.cb) logger.debug("store_their_did: <<< res: %s", res) return res @@ -94,10 +94,10 @@ async def sign(wallet_handle: int, c_msg = c_char_p(msg.encode('utf-8')) res = await do_call('indy_sign', - sign.cb, c_wallet_handle, c_did, - c_msg) + c_msg, + sign.cb) logger.debug("sign: <<< res: %s", res) return res @@ -124,11 +124,11 @@ async def verify_signature(wallet_handle: int, c_signed_msg = c_char_p(signed_msg.encode('utf-8')) res = await do_call('indy_verify_signature', - verify_signature.cb, c_wallet_handle, c_pool_handle, c_did, - c_signed_msg) + c_signed_msg, + verify_signature.cb) logger.debug("verify_signature: <<< res: %s", res) return res @@ -158,12 +158,12 @@ async def encrypt(wallet_handle: int, c_msg = c_char_p(msg.encode('utf-8')) res = await do_call('indy_encrypt', - encrypt.cb, c_wallet_handle, c_pool_handle, c_my_did, c_did, - c_msg) + c_msg, + encrypt.cb) logger.debug("encrypt: <<< res: %s", res) return res @@ -193,12 +193,12 @@ async def decrypt(wallet_handle: int, c_nonce = c_char_p(nonce.encode('utf-8')) res = await do_call('indy_decrypt', - decrypt.cb, c_wallet_handle, c_my_did, c_did, c_encrypted_msg, - c_nonce) + c_nonce, + decrypt.cb) logger.debug("decrypt: <<< res: %s", res) return res diff --git a/wrappers/python/indy/wallet.py b/wrappers/python/indy/wallet.py index d87661cc16..0a88b4b19d 100644 --- a/wrappers/python/indy/wallet.py +++ b/wrappers/python/indy/wallet.py @@ -30,12 +30,12 @@ async def create_wallet(pool_name: str, c_credentials = c_char_p(credentials.encode('utf-8')) if credentials is not None else None await do_call('indy_create_wallet', - create_wallet.cb, c_pool_name, c_name, c_xtype, c_config, - c_credentials) + c_credentials, + create_wallet.cb) logger.debug("create_wallet: <<<") @@ -58,10 +58,10 @@ async def open_wallet(name: str, c_credentials = c_char_p(credentials.encode('utf-8')) if credentials is not None else None res = await do_call('indy_open_wallet', - open_wallet.cb, c_name, c_runtime_config, - c_credentials) + c_credentials, + open_wallet.cb) logger.debug("open_wallet: <<< res: %s", res) return res @@ -78,12 +78,16 @@ async def close_wallet(handle: int) -> None: c_handle = c_int32(handle) await do_call('indy_close_wallet', - close_wallet.cb, - c_handle) + c_handle, + close_wallet.cb) logger.debug("close_wallet: <<<") +# pub extern fn indy_delete_wallet(command_handle: i32, +# name: *const c_char, +# credentials: *const c_char, +# cb: Option) -> ErrorCode { async def delete_wallet(name: str, credentials: Optional[str]) -> None: logger = logging.getLogger(__name__) @@ -99,8 +103,8 @@ async def delete_wallet(name: str, c_credentials = c_char_p(credentials.encode('utf-8')) if credentials is not None else None await do_call('indy_delete_wallet', - delete_wallet.cb, c_name, - c_credentials) + c_credentials, + delete_wallet.cb) logger.debug("delete_wallet: <<<") From 9fd0143c699b67ccaf495038a12385d26b17e6f2 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 18 Jul 2017 10:56:42 +0300 Subject: [PATCH 201/349] added test for refresh --- .../tests/pool/test_refresh_pool_ledger.py | 19 +++++++++++++++++++ wrappers/python/tests/utils/pool.py | 7 +++++++ 2 files changed, 26 insertions(+) create mode 100644 wrappers/python/tests/pool/test_refresh_pool_ledger.py diff --git a/wrappers/python/tests/pool/test_refresh_pool_ledger.py b/wrappers/python/tests/pool/test_refresh_pool_ledger.py new file mode 100644 index 0000000000..5af7fe5a4c --- /dev/null +++ b/wrappers/python/tests/pool/test_refresh_pool_ledger.py @@ -0,0 +1,19 @@ +from tests.utils import pool, storage +from indy.pool import refresh_pool_ledger +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.yield_fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_refresh_pool_ledger_works(): + handle = await pool.create_and_open_pool_ledger("pool_name") + await refresh_pool_ledger(handle) diff --git a/wrappers/python/tests/utils/pool.py b/wrappers/python/tests/utils/pool.py index 2f05442544..b8426f4ee0 100644 --- a/wrappers/python/tests/utils/pool.py +++ b/wrappers/python/tests/utils/pool.py @@ -28,3 +28,10 @@ def create_genesis_txn_file(file_name, predefined_data=None): f.writelines(predefined_data or default_txn) return path + + +async def create_and_open_pool_ledger(name): + await create_pool_ledger_config(name) + pool_handle = await pool.open_pool_ledger(name, "") + assert pool_handle is not None + return pool_handle From 216ae994c1a03bd365a2e78266402193aaaa4e88 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 18 Jul 2017 11:00:04 +0300 Subject: [PATCH 202/349] added close test for close --- .../tests/pool/test_close_pool_ledger.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 wrappers/python/tests/pool/test_close_pool_ledger.py diff --git a/wrappers/python/tests/pool/test_close_pool_ledger.py b/wrappers/python/tests/pool/test_close_pool_ledger.py new file mode 100644 index 0000000000..642b61f71e --- /dev/null +++ b/wrappers/python/tests/pool/test_close_pool_ledger.py @@ -0,0 +1,19 @@ +from tests.utils import pool, storage +from indy.pool import close_pool_ledger +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.yield_fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_close_pool_ledger_works(): + handle = await pool.create_and_open_pool_ledger("pool_name") + await close_pool_ledger(handle) From 3103cbafde7643a88de29958044aa34cbebed38a Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 18 Jul 2017 11:03:32 +0300 Subject: [PATCH 203/349] added test for delete --- .../pool/test_delete_pool_ledger_config.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 wrappers/python/tests/pool/test_delete_pool_ledger_config.py diff --git a/wrappers/python/tests/pool/test_delete_pool_ledger_config.py b/wrappers/python/tests/pool/test_delete_pool_ledger_config.py new file mode 100644 index 0000000000..4fdbb4574d --- /dev/null +++ b/wrappers/python/tests/pool/test_delete_pool_ledger_config.py @@ -0,0 +1,20 @@ +from tests.utils import pool, storage +from indy.pool import delete_pool_ledger_config +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.yield_fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_delete_pool_ledger_config_works(): + name = "pool_name" + await pool.create_pool_ledger_config(name) + await delete_pool_ledger_config(name) From 3b5975edb0c478d09442deed6b54634fd69a9111 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 18 Jul 2017 12:00:22 +0300 Subject: [PATCH 204/349] added fixture for wallet --- .../signus/test_create_and_store_my_did.py | 22 +++++++++++++------ .../python/tests/signus/test_replace_keys.py | 22 +++++++++++++------ wrappers/python/tests/signus/test_sign.py | 22 +++++++++++++------ .../tests/signus/test_store_their_did.py | 22 +++++++++++++------ .../tests/signus/test_verify_signature.py | 22 +++++++++++++------ wrappers/python/tests/utils/wallet.py | 14 ++++++++++++ 6 files changed, 89 insertions(+), 35 deletions(-) create mode 100644 wrappers/python/tests/utils/wallet.py diff --git a/wrappers/python/tests/signus/test_create_and_store_my_did.py b/wrappers/python/tests/signus/test_create_and_store_my_did.py index 53c4f74c89..25716f8891 100644 --- a/wrappers/python/tests/signus/test_create_and_store_my_did.py +++ b/wrappers/python/tests/signus/test_create_and_store_my_did.py @@ -1,7 +1,9 @@ from indy import wallet, signus from ..utils import storage +from ..utils.wallet import create_and_open_wallet +import asyncio import base58 import pytest import logging @@ -16,14 +18,20 @@ def before_after_each(): storage.cleanup() -@pytest.mark.asyncio -async def test_create_my_did_works_with_empty_json(): - pool_name = "indy_open_wallet_works" - wallet_name = "indy_open_wallet_works" +@pytest.yield_fixture() +def wallet_handle(): + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + future = asyncio.Future() + asyncio.ensure_future(create_and_open_wallet(future)) + loop.run_until_complete(future) + yield future.result() + loop.run_until_complete(wallet.close_wallet(future.result())) + loop.close() + - await wallet.create_wallet(pool_name, wallet_name, None, None, None) - wallet_handle = await wallet.open_wallet(wallet_name, None, None) - assert wallet_handle is not None +@pytest.mark.asyncio +async def test_create_my_did_works_with_empty_json(wallet_handle): (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, "{}") assert len(base58.b58decode(did)) == 16 assert len(base58.b58decode(ver_key)) == 32 diff --git a/wrappers/python/tests/signus/test_replace_keys.py b/wrappers/python/tests/signus/test_replace_keys.py index 8ea0cfee64..168d8d4b83 100644 --- a/wrappers/python/tests/signus/test_replace_keys.py +++ b/wrappers/python/tests/signus/test_replace_keys.py @@ -1,7 +1,9 @@ from indy import wallet, signus from ..utils import storage +from ..utils.wallet import create_and_open_wallet +import asyncio import pytest import logging @@ -15,14 +17,20 @@ def before_after_each(): storage.cleanup() -@pytest.mark.asyncio -async def test_replace_keys_works(): - pool_name = "indy_open_wallet_works" - wallet_name = "indy_open_wallet_works" +@pytest.yield_fixture() +def wallet_handle(): + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + future = asyncio.Future() + asyncio.ensure_future(create_and_open_wallet(future)) + loop.run_until_complete(future) + yield future.result() + loop.run_until_complete(wallet.close_wallet(future.result())) + loop.close() + - await wallet.create_wallet(pool_name, wallet_name, None, None, None) - wallet_handle = await wallet.open_wallet(wallet_name, None, None) - assert wallet_handle is not None +@pytest.mark.asyncio +async def test_replace_keys_works(wallet_handle): (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, "{}") (new_did, new_ver_key) = await signus.replace_keys(wallet_handle, did.decode(), "{}") assert (new_did != did) and (new_ver_key != ver_key) \ No newline at end of file diff --git a/wrappers/python/tests/signus/test_sign.py b/wrappers/python/tests/signus/test_sign.py index 6e29d92392..00b9f34d9b 100644 --- a/wrappers/python/tests/signus/test_sign.py +++ b/wrappers/python/tests/signus/test_sign.py @@ -1,7 +1,9 @@ from indy import wallet, signus from ..utils import storage +from ..utils.wallet import create_and_open_wallet +import asyncio import json import pytest import logging @@ -16,14 +18,20 @@ def before_after_each(): storage.cleanup() -@pytest.mark.asyncio -async def test_sign_works(): - pool_name = "indy_open_wallet_works" - wallet_name = "indy_open_wallet_works" +@pytest.yield_fixture() +def wallet_handle(): + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + future = asyncio.Future() + asyncio.ensure_future(create_and_open_wallet(future)) + loop.run_until_complete(future) + yield future.result() + loop.run_until_complete(wallet.close_wallet(future.result())) + loop.close() + - await wallet.create_wallet(pool_name, wallet_name, None, None, None) - wallet_handle = await wallet.open_wallet(wallet_name, None, None) - assert wallet_handle is not None +@pytest.mark.asyncio +async def test_sign_works(wallet_handle): (did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') message = { diff --git a/wrappers/python/tests/signus/test_store_their_did.py b/wrappers/python/tests/signus/test_store_their_did.py index 4fddd115d8..fdeb4df395 100644 --- a/wrappers/python/tests/signus/test_store_their_did.py +++ b/wrappers/python/tests/signus/test_store_their_did.py @@ -1,7 +1,9 @@ from indy import wallet, signus from ..utils import storage +from ..utils.wallet import create_and_open_wallet +import asyncio import pytest import logging @@ -15,12 +17,18 @@ def before_after_each(): storage.cleanup() -@pytest.mark.asyncio -async def test_store_their_did_works(): - pool_name = "indy_open_wallet_works" - wallet_name = "indy_open_wallet_works" +@pytest.yield_fixture() +def wallet_handle(): + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + future = asyncio.Future() + asyncio.ensure_future(create_and_open_wallet(future)) + loop.run_until_complete(future) + yield future.result() + loop.run_until_complete(wallet.close_wallet(future.result())) + loop.close() + - await wallet.create_wallet(pool_name, wallet_name, None, None, None) - wallet_handle = await wallet.open_wallet(wallet_name, None, None) - assert wallet_handle is not None +@pytest.mark.asyncio +async def test_store_their_did_works(wallet_handle): await signus.store_their_did(wallet_handle, '{"did":"8wZcEriaNLNKtteJvx7f8i"}') diff --git a/wrappers/python/tests/signus/test_verify_signature.py b/wrappers/python/tests/signus/test_verify_signature.py index e313dfc6a6..2339be223c 100644 --- a/wrappers/python/tests/signus/test_verify_signature.py +++ b/wrappers/python/tests/signus/test_verify_signature.py @@ -1,7 +1,9 @@ from indy import wallet, signus from ..utils import storage +from ..utils.wallet import create_and_open_wallet +import asyncio import json import pytest import logging @@ -16,15 +18,21 @@ def before_after_each(): storage.cleanup() +@pytest.yield_fixture() +def wallet_handle(): + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + future = asyncio.Future() + asyncio.ensure_future(create_and_open_wallet(future)) + loop.run_until_complete(future) + yield future.result() + loop.run_until_complete(wallet.close_wallet(future.result())) + loop.close() + + @pytest.mark.asyncio -async def test_verify_signature_works(): - pool_name = "indy_open_wallet_works" +async def test_verify_signature_works(wallet_handle): pool_handle = 1 - wallet_name = "indy_open_wallet_works" - - await wallet.create_wallet(pool_name, wallet_name, None, None, None) - wallet_handle = await wallet.open_wallet(wallet_name, None, None) - assert wallet_handle is not None (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') identity_json = { "did": did.decode(), diff --git a/wrappers/python/tests/utils/wallet.py b/wrappers/python/tests/utils/wallet.py new file mode 100644 index 0000000000..1042eff94f --- /dev/null +++ b/wrappers/python/tests/utils/wallet.py @@ -0,0 +1,14 @@ +from indy import wallet + +async def create_and_open_wallet(future): + pool_name = "indy_open_wallet_works" + wallet_name = "indy_open_wallet_works" + + await wallet.create_wallet(pool_name, wallet_name, None, None, None) + wallet_handle = await wallet.open_wallet(wallet_name, None, None) + assert wallet_handle is not None + future.set_result(wallet_handle) + + +async def close_wallet(wallet_handle): + await wallet.close_wallet(wallet_handle) From 2ee5aa861471379bf99c4ac6e2224aa86337a058 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 18 Jul 2017 12:20:43 +0300 Subject: [PATCH 205/349] added optional params for pool --- wrappers/python/indy/pool.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/wrappers/python/indy/pool.py b/wrappers/python/indy/pool.py index 975dca81d4..40e3d33536 100644 --- a/wrappers/python/indy/pool.py +++ b/wrappers/python/indy/pool.py @@ -1,11 +1,12 @@ from .libindy import do_call, create_cb +from typing import Optional from ctypes import * import logging async def create_pool_ledger_config(config_name: str, - config: str) -> None: + config: Optional[str]) -> None: logger = logging.getLogger(__name__) logger.debug("create_pool_ledger_config: >>> config_name: %s, config: %s", config_name, @@ -16,7 +17,7 @@ async def create_pool_ledger_config(config_name: str, create_pool_ledger_config.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) c_config_name = c_char_p(config_name.encode('utf-8')) - c_config = c_char_p(config.encode('utf-8')) + c_config = c_char_p(config.encode('utf-8')) if config is not None else None res = await do_call('indy_create_pool_ledger_config', create_pool_ledger_config.cb, @@ -28,7 +29,7 @@ async def create_pool_ledger_config(config_name: str, async def open_pool_ledger(config_name: str, - config: str) -> int: + config: Optional[str]) -> int: logger = logging.getLogger(__name__) logger.debug("open_pool_ledger: >>> config_name: %s, config: %s", config_name, @@ -39,7 +40,7 @@ async def open_pool_ledger(config_name: str, open_pool_ledger.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_int32)) c_config_name = c_char_p(config_name.encode('utf-8')) - c_config = c_char_p(config.encode('utf-8')) + c_config = c_char_p(config.encode('utf-8')) if config is not None else None res = await do_call('indy_open_pool_ledger', open_pool_ledger.cb, From b4534f6b965f3f36ec7777c3e79b44e76a8f11c3 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 18 Jul 2017 12:42:51 +0300 Subject: [PATCH 206/349] changes for wallet fixture --- .../tests/pool/test_close_pool_ledger.py | 2 +- .../pool/test_create_pool_ledger_config.py | 2 +- .../pool/test_delete_pool_ledger_config.py | 2 +- .../python/tests/pool/test_open_pool_ledger.py | 2 +- .../tests/pool/test_refresh_pool_ledger.py | 2 +- .../signus/test_create_and_store_my_did.py | 18 ++++++------------ .../python/tests/signus/test_replace_keys.py | 18 ++++++------------ wrappers/python/tests/signus/test_sign.py | 18 ++++++------------ .../tests/signus/test_store_their_did.py | 18 ++++++------------ .../tests/signus/test_verify_signature.py | 18 ++++++------------ wrappers/python/tests/utils/wallet.py | 4 ++-- 11 files changed, 37 insertions(+), 67 deletions(-) diff --git a/wrappers/python/tests/pool/test_close_pool_ledger.py b/wrappers/python/tests/pool/test_close_pool_ledger.py index 642b61f71e..10253bed77 100644 --- a/wrappers/python/tests/pool/test_close_pool_ledger.py +++ b/wrappers/python/tests/pool/test_close_pool_ledger.py @@ -6,7 +6,7 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.yield_fixture(autouse=True) +@pytest.fixture(autouse=True) def before_after_each(): storage.cleanup() yield diff --git a/wrappers/python/tests/pool/test_create_pool_ledger_config.py b/wrappers/python/tests/pool/test_create_pool_ledger_config.py index 8ad4582f10..94b0b72391 100644 --- a/wrappers/python/tests/pool/test_create_pool_ledger_config.py +++ b/wrappers/python/tests/pool/test_create_pool_ledger_config.py @@ -6,7 +6,7 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.yield_fixture(autouse=True) +@pytest.fixture(autouse=True) def before_after_each(): storage.cleanup() yield diff --git a/wrappers/python/tests/pool/test_delete_pool_ledger_config.py b/wrappers/python/tests/pool/test_delete_pool_ledger_config.py index 4fdbb4574d..706a9f343b 100644 --- a/wrappers/python/tests/pool/test_delete_pool_ledger_config.py +++ b/wrappers/python/tests/pool/test_delete_pool_ledger_config.py @@ -6,7 +6,7 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.yield_fixture(autouse=True) +@pytest.fixture(autouse=True) def before_after_each(): storage.cleanup() yield diff --git a/wrappers/python/tests/pool/test_open_pool_ledger.py b/wrappers/python/tests/pool/test_open_pool_ledger.py index 18230463a3..78b4e9c19a 100644 --- a/wrappers/python/tests/pool/test_open_pool_ledger.py +++ b/wrappers/python/tests/pool/test_open_pool_ledger.py @@ -6,7 +6,7 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.yield_fixture(autouse=True) +@pytest.fixture(autouse=True) def before_after_each(): storage.cleanup() yield diff --git a/wrappers/python/tests/pool/test_refresh_pool_ledger.py b/wrappers/python/tests/pool/test_refresh_pool_ledger.py index 5af7fe5a4c..d89a2c6315 100644 --- a/wrappers/python/tests/pool/test_refresh_pool_ledger.py +++ b/wrappers/python/tests/pool/test_refresh_pool_ledger.py @@ -6,7 +6,7 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.yield_fixture(autouse=True) +@pytest.fixture(autouse=True) def before_after_each(): storage.cleanup() yield diff --git a/wrappers/python/tests/signus/test_create_and_store_my_did.py b/wrappers/python/tests/signus/test_create_and_store_my_did.py index 25716f8891..93773ff036 100644 --- a/wrappers/python/tests/signus/test_create_and_store_my_did.py +++ b/wrappers/python/tests/signus/test_create_and_store_my_did.py @@ -3,7 +3,6 @@ from ..utils import storage from ..utils.wallet import create_and_open_wallet -import asyncio import base58 import pytest import logging @@ -11,23 +10,18 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.yield_fixture(autouse=True) +@pytest.fixture(autouse=True) def before_after_each(): storage.cleanup() yield storage.cleanup() -@pytest.yield_fixture() -def wallet_handle(): - loop = asyncio.new_event_loop() - asyncio.set_event_loop(loop) - future = asyncio.Future() - asyncio.ensure_future(create_and_open_wallet(future)) - loop.run_until_complete(future) - yield future.result() - loop.run_until_complete(wallet.close_wallet(future.result())) - loop.close() +@pytest.fixture +async def wallet_handle(): + handle = await create_and_open_wallet() + yield handle + await wallet.close_wallet(handle) @pytest.mark.asyncio diff --git a/wrappers/python/tests/signus/test_replace_keys.py b/wrappers/python/tests/signus/test_replace_keys.py index 168d8d4b83..6e212398e4 100644 --- a/wrappers/python/tests/signus/test_replace_keys.py +++ b/wrappers/python/tests/signus/test_replace_keys.py @@ -3,30 +3,24 @@ from ..utils import storage from ..utils.wallet import create_and_open_wallet -import asyncio import pytest import logging logging.basicConfig(level=logging.DEBUG) -@pytest.yield_fixture(autouse=True) +@pytest.fixture(autouse=True) def before_after_each(): storage.cleanup() yield storage.cleanup() -@pytest.yield_fixture() -def wallet_handle(): - loop = asyncio.new_event_loop() - asyncio.set_event_loop(loop) - future = asyncio.Future() - asyncio.ensure_future(create_and_open_wallet(future)) - loop.run_until_complete(future) - yield future.result() - loop.run_until_complete(wallet.close_wallet(future.result())) - loop.close() +@pytest.fixture +async def wallet_handle(): + handle = await create_and_open_wallet() + yield handle + await wallet.close_wallet(handle) @pytest.mark.asyncio diff --git a/wrappers/python/tests/signus/test_sign.py b/wrappers/python/tests/signus/test_sign.py index 00b9f34d9b..99e7843282 100644 --- a/wrappers/python/tests/signus/test_sign.py +++ b/wrappers/python/tests/signus/test_sign.py @@ -3,7 +3,6 @@ from ..utils import storage from ..utils.wallet import create_and_open_wallet -import asyncio import json import pytest import logging @@ -11,23 +10,18 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.yield_fixture(autouse=True) +@pytest.fixture(autouse=True) def before_after_each(): storage.cleanup() yield storage.cleanup() -@pytest.yield_fixture() -def wallet_handle(): - loop = asyncio.new_event_loop() - asyncio.set_event_loop(loop) - future = asyncio.Future() - asyncio.ensure_future(create_and_open_wallet(future)) - loop.run_until_complete(future) - yield future.result() - loop.run_until_complete(wallet.close_wallet(future.result())) - loop.close() +@pytest.fixture +async def wallet_handle(): + handle = await create_and_open_wallet() + yield handle + await wallet.close_wallet(handle) @pytest.mark.asyncio diff --git a/wrappers/python/tests/signus/test_store_their_did.py b/wrappers/python/tests/signus/test_store_their_did.py index fdeb4df395..ad45f881aa 100644 --- a/wrappers/python/tests/signus/test_store_their_did.py +++ b/wrappers/python/tests/signus/test_store_their_did.py @@ -3,30 +3,24 @@ from ..utils import storage from ..utils.wallet import create_and_open_wallet -import asyncio import pytest import logging logging.basicConfig(level=logging.DEBUG) -@pytest.yield_fixture(autouse=True) +@pytest.fixture(autouse=True) def before_after_each(): storage.cleanup() yield storage.cleanup() -@pytest.yield_fixture() -def wallet_handle(): - loop = asyncio.new_event_loop() - asyncio.set_event_loop(loop) - future = asyncio.Future() - asyncio.ensure_future(create_and_open_wallet(future)) - loop.run_until_complete(future) - yield future.result() - loop.run_until_complete(wallet.close_wallet(future.result())) - loop.close() +@pytest.fixture +async def wallet_handle(): + handle = await create_and_open_wallet() + yield handle + await wallet.close_wallet(handle) @pytest.mark.asyncio diff --git a/wrappers/python/tests/signus/test_verify_signature.py b/wrappers/python/tests/signus/test_verify_signature.py index 2339be223c..dcb3b7f53b 100644 --- a/wrappers/python/tests/signus/test_verify_signature.py +++ b/wrappers/python/tests/signus/test_verify_signature.py @@ -3,7 +3,6 @@ from ..utils import storage from ..utils.wallet import create_and_open_wallet -import asyncio import json import pytest import logging @@ -11,23 +10,18 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.yield_fixture(autouse=True) +@pytest.fixture(autouse=True) def before_after_each(): storage.cleanup() yield storage.cleanup() -@pytest.yield_fixture() -def wallet_handle(): - loop = asyncio.new_event_loop() - asyncio.set_event_loop(loop) - future = asyncio.Future() - asyncio.ensure_future(create_and_open_wallet(future)) - loop.run_until_complete(future) - yield future.result() - loop.run_until_complete(wallet.close_wallet(future.result())) - loop.close() +@pytest.fixture +async def wallet_handle(): + handle = await create_and_open_wallet() + yield handle + await wallet.close_wallet(handle) @pytest.mark.asyncio diff --git a/wrappers/python/tests/utils/wallet.py b/wrappers/python/tests/utils/wallet.py index 1042eff94f..0b7832f689 100644 --- a/wrappers/python/tests/utils/wallet.py +++ b/wrappers/python/tests/utils/wallet.py @@ -1,13 +1,13 @@ from indy import wallet -async def create_and_open_wallet(future): +async def create_and_open_wallet(): pool_name = "indy_open_wallet_works" wallet_name = "indy_open_wallet_works" await wallet.create_wallet(pool_name, wallet_name, None, None, None) wallet_handle = await wallet.open_wallet(wallet_name, None, None) assert wallet_handle is not None - future.set_result(wallet_handle) + return wallet_handle async def close_wallet(wallet_handle): From 9351afba845961ac3dd643e039f41ce88e61f7b2 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 18 Jul 2017 15:16:11 +0300 Subject: [PATCH 207/349] added api for ledger --- wrappers/python/indy/ledger.py | 324 +++++++++++++++++++++++++++++++-- 1 file changed, 305 insertions(+), 19 deletions(-) diff --git a/wrappers/python/indy/ledger.py b/wrappers/python/indy/ledger.py index 5625f0c75b..3968896d89 100644 --- a/wrappers/python/indy/ledger.py +++ b/wrappers/python/indy/ledger.py @@ -1,78 +1,364 @@ +from .libindy import do_call, create_cb + +from typing import Optional +from ctypes import * + +import logging + async def sign_and_submit_request(pool_handle: int, wallet_handle: int, submitter_did: str, request_json: str) -> str: - pass + logger = logging.getLogger(__name__) + logger.debug("sign_and_submit_request: >>> pool_handle: %s, wallet_handle: %s, submitter_did: %s, request_json: %s", + pool_handle, + wallet_handle, + submitter_did, + request_json) + + if not hasattr(sign_and_submit_request, "cb"): + logger.debug("sign_and_submit_request: Creating callback") + sign_and_submit_request.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_pool_handle = c_int32(pool_handle) + c_wallet_handle = c_int32(wallet_handle) + c_submitter_did = c_char_p(submitter_did.encode('utf-8')) + c_request_json = c_char_p(request_json.encode('utf-8')) + + res = await do_call('indy_sign_and_submit_request', + sign_and_submit_request.cb, + c_pool_handle, + c_wallet_handle, + c_submitter_did, + c_request_json) + + logger.debug("sign_and_submit_request: <<< res: %s", res) + return res async def submit_request(pool_handle: int, request_json: str) -> str: - pass + logger = logging.getLogger(__name__) + logger.debug("submit_request: >>> pool_handle: %s, request_json: %s", + pool_handle, + request_json) + + if not hasattr(submit_request, "cb"): + logger.debug("submit_request: Creating callback") + submit_request.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_pool_handle = c_int32(pool_handle) + c_request_json = c_char_p(request_json.encode('utf-8')) + + res = await do_call('indy_submit_request', + submit_request.cb, + c_pool_handle, + c_request_json) + + logger.debug("submit_request: <<< res: %s", res) + return res async def build_get_ddo_request(submitter_did: str, target_did: str) -> str: - pass + logger = logging.getLogger(__name__) + logger.debug("build_get_ddo_request: >>> submitter_did: %s, target_did: %s", + submitter_did, + target_did) + + if not hasattr(build_get_ddo_request, "cb"): + logger.debug("build_get_ddo_request: Creating callback") + build_get_ddo_request.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_submitter_did = c_char_p(submitter_did.encode('utf-8')) + c_target_did = c_char_p(target_did.encode('utf-8')) + + res = await do_call('indy_build_get_ddo_request', + build_get_ddo_request.cb, + c_submitter_did, + c_target_did) + + logger.debug("build_get_ddo_request: <<< res: %s", res) + return res async def build_nym_request(submitter_did: str, target_did: str, - verkey: str, - alias: str, - role: str) -> str: - pass + ver_key: Optional[str], + alias: Optional[str], + role: Optional[str]) -> str: + logger = logging.getLogger(__name__) + logger.debug("build_nym_request: >>> submitter_did: %s, target_did: %s, ver_key: %s, alias: %s, role: %s", + submitter_did, + target_did, + ver_key, + alias, + role) + + if not hasattr(build_nym_request, "cb"): + logger.debug("build_nym_request: Creating callback") + build_nym_request.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_submitter_did = c_char_p(submitter_did.encode('utf-8')) + c_target_did = c_char_p(target_did.encode('utf-8')) + c_ver_key = c_char_p(ver_key.encode('utf-8')) if ver_key is not None else None + c_alias = c_char_p(alias.encode('utf-8')) if alias is not None else None + c_role = c_char_p(role.encode('utf-8')) if role is not None else None + + res = await do_call('indy_build_nym_request', + build_nym_request.cb, + c_submitter_did, + c_target_did, + c_ver_key, + c_alias, + c_role) + + logger.debug("build_nym_request: <<< res: %s", res) + return res async def build_attrib_request(submitter_did: str, target_did: str, - hash: str, - raw: str, - enc: str) -> str: - pass + hash: Optional[str], + raw: Optional[str], + enc: Optional[str]) -> str: + logger = logging.getLogger(__name__) + logger.debug("build_attrib_request: >>> submitter_did: %s, target_did: %s, hash: %s, raw: %s, enc: %s", + submitter_did, + target_did, + hash, + raw, + enc) + + if not hasattr(build_attrib_request, "cb"): + logger.debug("build_attrib_request: Creating callback") + build_attrib_request.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_submitter_did = c_char_p(submitter_did.encode('utf-8')) + c_target_did = c_char_p(target_did.encode('utf-8')) + c_hash = c_char_p(hash.encode('utf-8')) if hash is not None else None + c_raw = c_char_p(raw.encode('utf-8')) if raw is not None else None + c_enc = c_char_p(enc.encode('utf-8')) if enc is not None else None + + res = await do_call('indy_build_attrib_request', + build_attrib_request.cb, + c_submitter_did, + c_target_did, + c_hash, + c_raw, + c_enc) + + logger.debug("build_attrib_request: <<< res: %s", res) + return res async def build_get_attrib_request(submitter_did: str, target_did: str, data: str) -> str: - pass + logger = logging.getLogger(__name__) + logger.debug("build_get_attrib_request: >>> submitter_did: %s, target_did: %s, data: %s", + submitter_did, + target_did, + data) + + if not hasattr(build_get_attrib_request, "cb"): + logger.debug("build_get_attrib_request: Creating callback") + build_get_attrib_request.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_submitter_did = c_char_p(submitter_did.encode('utf-8')) + c_target_did = c_char_p(target_did.encode('utf-8')) + c_data = c_char_p(data.encode('utf-8')) + + res = await do_call('indy_build_get_attrib_request', + build_get_attrib_request.cb, + c_submitter_did, + c_target_did, + c_data) + + logger.debug("build_get_attrib_request: <<< res: %s", res) + return res async def build_get_nym_request(submitter_did: str, target_did: str) -> str: - pass + logger = logging.getLogger(__name__) + logger.debug("build_get_nym_request: >>> submitter_did: %s, target_did: %s", + submitter_did, + target_did) + + if not hasattr(build_get_nym_request, "cb"): + logger.debug("build_get_nym_request: Creating callback") + build_get_nym_request.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_submitter_did = c_char_p(submitter_did.encode('utf-8')) + c_target_did = c_char_p(target_did.encode('utf-8')) + + res = await do_call('indy_build_get_nym_request', + build_get_nym_request.cb, + c_submitter_did, + c_target_did) + + logger.debug("build_get_nym_request: <<< res: %s", res) + return res async def build_schema_request(submitter_did: str, data: str) -> str: - pass + logger = logging.getLogger(__name__) + logger.debug("build_schema_request: >>> submitter_did: %s, data: %s", + submitter_did, + data) + + if not hasattr(build_schema_request, "cb"): + logger.debug("build_schema_request: Creating callback") + build_schema_request.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_submitter_did = c_char_p(submitter_did.encode('utf-8')) + c_data = c_char_p(data.encode('utf-8')) + + res = await do_call('indy_build_schema_request', + build_schema_request.cb, + c_submitter_did, + c_data) + + logger.debug("build_schema_request: <<< res: %s", res) + return res async def build_get_schema_request(submitter_did: str, dest: str, data: str) -> str: - pass + logger = logging.getLogger(__name__) + logger.debug("build_get_schema_request: >>> submitter_did: %s, dest: %s, data: %s", + submitter_did, + dest, + data) + + if not hasattr(build_get_schema_request, "cb"): + logger.debug("build_get_schema_request: Creating callback") + build_get_schema_request.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_submitter_did = c_char_p(submitter_did.encode('utf-8')) + c_dest = c_char_p(dest.encode('utf-8')) + c_data = c_char_p(data.encode('utf-8')) + + res = await do_call('indy_build_get_schema_request', + build_get_schema_request.cb, + c_submitter_did, + c_dest, + c_data) + + logger.debug("build_get_schema_request: <<< res: %s", res) + return res async def build_claim_def_txn(submitter_did: str, xref: int, signature_type: str, data: str) -> str: - pass + logger = logging.getLogger(__name__) + logger.debug("build_get_schema_request: >>> submitter_did: %s, xref: %s, signature_type: %s, data: %s", + submitter_did, + xref, + signature_type, + data) + + if not hasattr(build_claim_def_txn, "cb"): + logger.debug("build_claim_def_txn: Creating callback") + build_claim_def_txn.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_submitter_did = c_char_p(submitter_did.encode('utf-8')) + c_xref = c_int32(xref) + c_signature_type = c_char_p(signature_type.encode('utf-8')) + c_data = c_char_p(data.encode('utf-8')) + + res = await do_call('indy_build_claim_def_txn', + build_claim_def_txn.cb, + c_submitter_did, + c_xref, + c_signature_type, + c_data) + + logger.debug("build_claim_def_txn: <<< res: %s", res) + return res async def build_get_claim_def_txn(submitter_did: str, xref: int, signature_type: str, origin: str) -> str: - pass + logger = logging.getLogger(__name__) + logger.debug("build_get_claim_def_txn: >>> submitter_did: %s, xref: %s, signature_type: %s, origin: %s", + submitter_did, + xref, + signature_type, + origin) + + if not hasattr(build_get_claim_def_txn, "cb"): + logger.debug("build_get_claim_def_txn: Creating callback") + build_get_claim_def_txn.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_submitter_did = c_char_p(submitter_did.encode('utf-8')) + c_xref = c_int32(xref) + c_signature_type = c_char_p(signature_type.encode('utf-8')) + c_origin = c_char_p(origin.encode('utf-8')) + + res = await do_call('indy_build_get_claim_def_txn', + build_get_claim_def_txn.cb, + c_submitter_did, + c_xref, + c_signature_type, + c_origin) + + logger.debug("build_get_claim_def_txn: <<< res: %s", res) + return res async def build_node_request(submitter_did: str, target_did: str, data: str) -> str: - pass + logger = logging.getLogger(__name__) + logger.debug("build_node_request: >>> submitter_did: %s, target_did: %s, data: %s", + submitter_did, + target_did, + data) + + if not hasattr(build_node_request, "cb"): + logger.debug("build_node_request: Creating callback") + build_node_request.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_submitter_did = c_char_p(submitter_did.encode('utf-8')) + c_target_did = c_char_p(target_did.encode('utf-8')) + c_data = c_char_p(data.encode('utf-8')) + + res = await do_call('indy_build_node_request', + build_node_request.cb, + c_submitter_did, + c_target_did, + c_data) + + logger.debug("build_node_request: <<< res: %s", res) + return res async def build_get_txn_request(submitter_did: str, data: str) -> str: - pass + logger = logging.getLogger(__name__) + logger.debug("build_get_txn_request: >>> submitter_did: %s, data: %s", + submitter_did, + data) + + if not hasattr(build_get_txn_request, "cb"): + logger.debug("build_get_txn_request: Creating callback") + build_get_txn_request.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_submitter_did = c_char_p(submitter_did.encode('utf-8')) + c_data = c_char_p(data.encode('utf-8')) + + res = await do_call('indy_build_get_txn_request', + build_get_txn_request.cb, + c_submitter_did, + c_data) + + logger.debug("build_get_txn_request: <<< res: %s", res) + return res From fe1a2f2928012b56cc3625641da0fed54aecf4d9 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 18 Jul 2017 15:38:06 +0300 Subject: [PATCH 208/349] added test for sign and submit request --- .../ledger/test_sign_and_submit_request.py | 31 +++++++++++++++++++ wrappers/python/tests/utils/wallet.py | 5 +-- 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 wrappers/python/tests/ledger/test_sign_and_submit_request.py diff --git a/wrappers/python/tests/ledger/test_sign_and_submit_request.py b/wrappers/python/tests/ledger/test_sign_and_submit_request.py new file mode 100644 index 0000000000..c403f49b4e --- /dev/null +++ b/wrappers/python/tests/ledger/test_sign_and_submit_request.py @@ -0,0 +1,31 @@ +from tests.utils import pool, storage +from tests.utils.wallet import create_and_open_wallet +from indy import wallet, signus, ledger + +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.fixture +async def wallet_handle(): + handle = await create_and_open_wallet(pool_name="pool_name") + yield handle + await wallet.close_wallet(handle) + + +@pytest.mark.asyncio +async def test_sign_and_submit_request_works(wallet_handle): + pool_handle = await pool.create_and_open_pool_ledger("pool_name") + (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') + (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') + nym_request = await ledger.build_nym_request(trustee_did.decode(), my_did.decode(), None, None, None) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did.decode(), nym_request.decode()) diff --git a/wrappers/python/tests/utils/wallet.py b/wrappers/python/tests/utils/wallet.py index 0b7832f689..e62cc4a591 100644 --- a/wrappers/python/tests/utils/wallet.py +++ b/wrappers/python/tests/utils/wallet.py @@ -1,9 +1,6 @@ from indy import wallet -async def create_and_open_wallet(): - pool_name = "indy_open_wallet_works" - wallet_name = "indy_open_wallet_works" - +async def create_and_open_wallet(pool_name="indy_open_wallet_works", wallet_name="indy_open_wallet_works"): await wallet.create_wallet(pool_name, wallet_name, None, None, None) wallet_handle = await wallet.open_wallet(wallet_name, None, None) assert wallet_handle is not None From f1fdea850be1e02efb794eba6767f54c13da734b Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 18 Jul 2017 16:22:59 +0300 Subject: [PATCH 209/349] added test_submit_request --- .../ledger/test_sign_and_submit_request.py | 3 +- .../tests/ledger/test_submit_request.py | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 wrappers/python/tests/ledger/test_submit_request.py diff --git a/wrappers/python/tests/ledger/test_sign_and_submit_request.py b/wrappers/python/tests/ledger/test_sign_and_submit_request.py index c403f49b4e..7d92a58ec2 100644 --- a/wrappers/python/tests/ledger/test_sign_and_submit_request.py +++ b/wrappers/python/tests/ledger/test_sign_and_submit_request.py @@ -26,6 +26,7 @@ async def wallet_handle(): async def test_sign_and_submit_request_works(wallet_handle): pool_handle = await pool.create_and_open_pool_ledger("pool_name") (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') - (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') + (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"000000000000000000000000Trustee1"}') nym_request = await ledger.build_nym_request(trustee_did.decode(), my_did.decode(), None, None, None) await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did.decode(), nym_request.decode()) diff --git a/wrappers/python/tests/ledger/test_submit_request.py b/wrappers/python/tests/ledger/test_submit_request.py new file mode 100644 index 0000000000..978f9593dc --- /dev/null +++ b/wrappers/python/tests/ledger/test_submit_request.py @@ -0,0 +1,43 @@ +from tests.utils import pool, storage +from indy import ledger + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_submit_request_works(): + pool_handle = await pool.create_and_open_pool_ledger("pool_name") + request = { + "reqId": 1491566332010860, + "identifier": "Th7MpTaRZVRYnPiabds81Y", + "operation": { + "type": "105", + "dest": "Th7MpTaRZVRYnPiabds81Y" + }, + "signature": "4o86XfkiJ4e2r3J6Ufoi17UU3W5Zi9sshV6FjBjkVw4sgEQFQov9dxqDEtLbAJAWffCWd5KfAk164QVo7mYwKkiV" + } + + expected_response = { + "result": { + "reqId": 1491566332010860, + "identifier": "Th7MpTaRZVRYnPiabds81Y", + "dest": "Th7MpTaRZVRYnPiabds81Y", + "data": "{\"dest\":\"Th7MpTaRZVRYnPiabds81Y\",\"identifier\":\"V4SGRU86Z58d6TV7PBUe6f\",\"role\":\"2\"" + ",\"verkey\":\"~7TYfekw4GUagBnBVCqPjiC\"}", + "type": "105", + }, + "op": "REPLY" + } + response = json.loads((await ledger.submit_request(pool_handle, json.dumps(request))).decode()) + assert response == expected_response From 550421fcec7063035ba6616d3a4340b17065ac83 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 18 Jul 2017 16:45:31 +0300 Subject: [PATCH 210/349] Implemented Anoncreds integration tests for Java wrapper --- .../indy/sdk/anoncreds/Anoncreds.java | 33 +++ .../anoncreds/AnoncredsIntegrationTest.java | 80 ++++++ ...suerCreateAndStoreClaimDefinitionTest.java | 114 ++++++++ .../sdk/anoncreds/IssuerCreateClaimTest.java | 76 ++++++ .../ProverCreateAndStoreClaimReqTest.java | 72 ++++++ .../ProverCreateMasterSecretTest.java | 51 ++++ .../sdk/anoncreds/ProverCreateProofTest.java | 199 ++++++++++++++ .../anoncreds/ProverGetClaimOfferTest.java | 95 +++++++ .../ProverGetClaimsForProofRequestTest.java | 243 ++++++++++++++++++ .../sdk/anoncreds/ProverGetClaimsTest.java | 80 ++++++ .../anoncreds/ProverStoreClaimOfferTest.java | 58 +++++ .../sdk/anoncreds/ProverStoreClaimTest.java | 72 ++++++ .../anoncreds/VerifierVerifyProofTest.java | 80 ++++++ 13 files changed, 1253 insertions(+) create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/AnoncredsIntegrationTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateAndStoreClaimDefinitionTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateClaimTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateAndStoreClaimReqTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateMasterSecretTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateProofTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimOfferTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimsForProofRequestTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimsTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverStoreClaimOfferTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverStoreClaimTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/VerifierVerifyProofTest.java diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java index 648b22130a..85bd4e44f1 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java @@ -141,6 +141,19 @@ public void callback(int xcommand_handle, int err) { } }; + private static Callback proverGetClaimsCb = new Callback() { + + @SuppressWarnings({"unused", "unchecked"}) + public void callback(int xcommand_handle, int err, String claimsJson) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + String result = claimsJson; + future.complete(result); + } + }; + private static Callback proverGetClaimsForProofReqCb = new Callback() { @SuppressWarnings({"unused", "unchecked"}) @@ -390,6 +403,26 @@ public static CompletableFuture proverStoreClaim( return future; } + public static CompletableFuture proverGetClaims( + Wallet wallet, + String filter) throws IndyException { + + CompletableFuture future = new CompletableFuture(); + int commandHandle = addFuture(future); + + int walletHandle = wallet.getWalletHandle(); + + int result = LibIndy.api.indy_prover_get_claims( + commandHandle, + walletHandle, + filter, + proverGetClaimsCb); + + checkResult(result); + + return future; + } + public static CompletableFuture proverGetClaimsForProofReq( Wallet wallet, String proofRequest) throws IndyException { diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/AnoncredsIntegrationTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/AnoncredsIntegrationTest.java new file mode 100644 index 0000000000..4dcce1ddf4 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/AnoncredsIntegrationTest.java @@ -0,0 +1,80 @@ +package org.hyperledger.indy.sdk.anoncreds; + +import org.hyperledger.indy.sdk.utils.InitHelper; +import org.hyperledger.indy.sdk.utils.StorageUtils; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.junit.*; +import org.junit.rules.ExpectedException; +import org.junit.rules.Timeout; + +import java.util.concurrent.TimeUnit; + +public class AnoncredsIntegrationTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Rule + public Timeout globalTimeout = new Timeout(1, TimeUnit.MINUTES); + + static Wallet wallet; + static String claimDef; + + private static Boolean walletOpened = false; + + String masterSecretName = "master_secret_name"; + String issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; + String issuerDid2 = "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"; + String proverDid = "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"; + String claimOfferTemplate = "{\"issuer_did\":\"%s\",\"schema_seq_no\":%d}"; + String schema = "{\"seqNo\":1,\"data\": {\"name\":\"gvt\",\"version\":\"1.0\",\"keys\":[\"age\",\"sex\",\"height\",\"name\"]}}"; + String claimRequestTemplate = "{\"blinded_ms\":" + + "{\"prover_did\":\"CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW\"," + + "\"u\":\"54172737564529332710724213139048941083013176891644677117322321823630308734620627329227591845094100636256829761959157314784293939045176621327154990908459072821826818718739696323299787928173535529024556540323709578850706993294234966440826690899266872682790228513973999212370574548239877108511283629423807338632435431097339875665075453785141722989098387895970395982432709011505864533727415552566715069675346220752584449560407261446567731711814188836703337365986725429656195275616846543535707364215498980750860746440672050640048215761507774996460985293327604627646056062013419674090094698841792968543317468164175921100038\"," + + "\"ur\":null}," + + "\"issuer_did\":\"%s\",\"schema_seq_no\":%d}"; + + @BeforeClass + public static void setUp() throws Exception{ + InitHelper.init(); + } + + void initCommonWallet() throws Exception { + + if (walletOpened) { + return; + } + + StorageUtils.cleanupStorage(); + + String walletName = "anoncredsCommonWallet"; + + Wallet.createWallet("default", walletName, "default", null, null).get(); + wallet = Wallet.openWallet(walletName, null, null).get(); + + claimDef = Anoncreds.issuerCreateAndStoreClaimDef(wallet, issuerDid, schema, null, false).get(); + + Anoncreds.proverStoreClaimOffer(wallet, String.format(claimOfferTemplate, issuerDid, 1)).get(); + Anoncreds.proverStoreClaimOffer(wallet, String.format(claimOfferTemplate, issuerDid, 2)).get(); + Anoncreds.proverStoreClaimOffer(wallet, String.format(claimOfferTemplate, issuerDid2, 2)).get(); + + Anoncreds.proverCreateMasterSecret(wallet, masterSecretName).get(); + + String claimOffer = String.format("{\"issuer_did\":\"%s\",\"schema_seq_no\":%d}", issuerDid, 1); + + String claimRequest = Anoncreds.proverCreateClaimReq(wallet, "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW", claimOffer, claimDef, masterSecretName).get(); + + String claim = "{\"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" + + " \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" + + " \"height\":[\"175\",\"175\"],\n" + + " \"age\":[\"28\",\"28\"]\n" + + " }"; + + AnoncredsResults.IssuerCreateClaimResult createClaimResult = Anoncreds.issuerCreateClaim(wallet, claimRequest, claim, - 1, - 1).get(); + String claimJson = createClaimResult.getClaimJson(); + + Anoncreds.proverStoreClaim(wallet, claimJson).get(); + + walletOpened = true; + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateAndStoreClaimDefinitionTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateAndStoreClaimDefinitionTest.java new file mode 100644 index 0000000000..f4f5b8f419 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateAndStoreClaimDefinitionTest.java @@ -0,0 +1,114 @@ +package org.hyperledger.indy.sdk.anoncreds; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.wallet.Wallet; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.json.*; + +import java.util.concurrent.ExecutionException; + +public class IssuerCreateAndStoreClaimDefinitionTest extends AnoncredsIntegrationTest { + + private Wallet wallet; + private String walletName = "createAndStoreClaimDefWallet"; + + @Before + public void createWallet() throws Exception { + Wallet.createWallet("default", walletName, "default", null, null).get(); + wallet = Wallet.openWallet(walletName, null, null).get(); + } + + @After + public void deleteWallet() throws Exception { + wallet.closeWallet().get(); + Wallet.deleteWallet(walletName, null).get(); + } + + private String issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; + private String gvtSchemaJson = "{\n" + + " \"seqNo\":1,\n" + + " \"data\": {\n" + + " \"name\":\"gvt\",\n" + + " \"version\":\"1.0\",\n" + + " \"keys\":[\"age\",\"sex\",\"height\",\"name\"]\n" + + " }\n" + + " }"; + + @Test + public void testIssuerCreateAndStoreClaimDefWorks() throws Exception { + + String claimDef = Anoncreds.issuerCreateAndStoreClaimDef(wallet, issuerDid, gvtSchemaJson, null, false).get(); + assertNotNull(claimDef); + + JSONObject claimDefObject = new JSONObject(claimDef); + + assertEquals(claimDefObject.getJSONObject("data").getJSONObject("primary").getJSONObject("r").length(), 4); + assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("n").length() > 0); + assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("s").length() > 0); + assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("z").length() > 0); + assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("rms").length() > 0); + assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("rctxt").length() > 0); + } + + @Test + public void testIssuerCreateAndStoreClaimDefWorksForInvalidSchemaJson() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String schema = "{\"seqNo\":1, \"name\":\"name\",\"version\":\"1.0\", \"keys\":[\"name\"]}"; + + Anoncreds.issuerCreateAndStoreClaimDef(wallet, issuerDid, schema, null, false).get(); + } + + @Test + public void testIssuerCreateAndStoreClaimDefWorksForEmptyKeys() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String schema = "{\n" + + " \"seqNo\":1,\n" + + " \"data\": {\n" + + " \"name\":\"gvt\",\n" + + " \"version\":\"1.0\",\n" + + " \"keys\":[]\n" + + " }\n" + + " }"; + + Anoncreds.issuerCreateAndStoreClaimDef(wallet, issuerDid, schema, null, false).get(); + } + + @Test + public void testIssuerCreateAndStoreClaimDefWorksForCorrectCryptoType() throws Exception { + + String claimDef = Anoncreds.issuerCreateAndStoreClaimDef(wallet, issuerDid, gvtSchemaJson, "CL", false).get(); + assertNotNull(claimDef); + + JSONObject claimDefObject = new JSONObject(claimDef); + + assertEquals(claimDefObject.getJSONObject("data").getJSONObject("primary").getJSONObject("r").length(), 4); + assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("n").length() > 0); + assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("s").length() > 0); + assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("z").length() > 0); + assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("rms").length() > 0); + assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("rctxt").length() > 0); + } + + @Test + public void testIssuerCreateAndStoreClaimDefWorksForInvalidCryptoType() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + Anoncreds.issuerCreateAndStoreClaimDef(wallet, issuerDid, gvtSchemaJson, "type", false).get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateClaimTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateClaimTest.java new file mode 100644 index 0000000000..c4c710849e --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateClaimTest.java @@ -0,0 +1,76 @@ +package org.hyperledger.indy.sdk.anoncreds; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.json.JSONObject; +import org.junit.*; + +import java.util.concurrent.ExecutionException; + +import static org.junit.Assert.assertNotNull; + +public class IssuerCreateClaimTest extends AnoncredsIntegrationTest { + + @Test + public void testProverCreateAndStoreClaimReqWorks() throws Exception { + + initCommonWallet(); + + String claimRequest = String.format(claimRequestTemplate, issuerDid, 1); + + String claim = "{\"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" + + " \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" + + " \"height\":[\"175\",\"175\"],\n" + + " \"age\":[\"28\",\"28\"]\n" + + " }"; + + AnoncredsResults.IssuerCreateClaimResult createClaimResult = Anoncreds.issuerCreateClaim(wallet, claimRequest, claim, - 1, - 1).get(); + assertNotNull(createClaimResult); + String claimJson = createClaimResult.getClaimJson(); + + JSONObject claimObj = new JSONObject(claimJson); + + JSONObject primaryClaim = claimObj.getJSONObject("signature").getJSONObject("primary_claim"); + + Assert.assertTrue(primaryClaim.getString("a").length() > 0); + Assert.assertTrue(primaryClaim.getString("m2").length() > 0); + Assert.assertTrue(primaryClaim.getString("e").length() > 0); + Assert.assertTrue(primaryClaim.getString("v").length() > 0); + } + + @Test + public void testProverCreateAndStoreClaimReqWorksForClaimDoesNotCorrespondToClaimRequest() throws Exception { + + initCommonWallet(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String claimRequest = String.format(claimRequestTemplate, issuerDid, 1); + + String claim = "{\"status\":[\"partial\",\"51792877103171595686471452153480627530895\"],\n" + + " \"period\":[\"8\",\"8\"]\n" + + " }"; + + Anoncreds.issuerCreateClaim(wallet, claimRequest, claim, - 1, - 1).get(); + } + + @Test + public void testProverCreateAndStoreClaimReqWorksForInvalidClaim() throws Exception { + + initCommonWallet(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String claimRequest = String.format(claimRequestTemplate, issuerDid, 1); + + String claim = "{\"sex\":\"male\",\n" + + " \"name\":\"Alex\",\n" + + " \"height\":\"175\",\n" + + " \"age\":\"28\"" + + " }"; + + Anoncreds.issuerCreateClaim(wallet, claimRequest, claim, - 1, - 1).get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateAndStoreClaimReqTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateAndStoreClaimReqTest.java new file mode 100644 index 0000000000..6c18116718 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateAndStoreClaimReqTest.java @@ -0,0 +1,72 @@ +package org.hyperledger.indy.sdk.anoncreds; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.junit.Test; + +import java.util.concurrent.ExecutionException; + +public class ProverCreateAndStoreClaimReqTest extends AnoncredsIntegrationTest { + + @Test + public void testProverCreateAndStoreClaimReqWorks() throws Exception { + + initCommonWallet(); + + String claimOffer = String.format(claimOfferTemplate, issuerDid, 1); + + Anoncreds.proverCreateClaimReq(wallet, proverDid, claimOffer, claimDef, masterSecretName).get(); + } + + @Test + public void testProverCreateAndStoreClaimReqWorksForClaimDefDoesNotCorrespondToClaimOfferDifferentIssuer() throws Exception { + + initCommonWallet(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String claimOffer = String.format(claimOfferTemplate, "acWziYqKpYi6ov5FcYDi1e3", 1); + + Anoncreds.proverCreateClaimReq(wallet, proverDid, claimOffer, claimDef, masterSecretName).get(); + } + + @Test + public void testProverCreateAndStoreClaimReqWorksForClaimDefDoesNotCorrespondToClaimOfferDifferentSchema() throws Exception { + + initCommonWallet(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String claimOffer = String.format(claimOfferTemplate, issuerDid, 2); + + Anoncreds.proverCreateClaimReq(wallet, proverDid, claimOffer, claimDef, masterSecretName).get(); + } + + @Test + public void testProverCreateAndStoreClaimReqWorksForInvalidClaimOffer() throws Exception { + + initCommonWallet(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String claimOffer = String.format("{\"issuer_did\":\"%s\"}", issuerDid); + + Anoncreds.proverCreateClaimReq(wallet, proverDid, claimOffer, claimDef, masterSecretName).get(); + } + + @Test + public void testProverCreateAndStoreClaimReqWorksForInvalidMasterSecret() throws Exception { + + initCommonWallet(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletNotFoundError)); + + String claimOffer = String.format(claimOfferTemplate, issuerDid, 1); + + Anoncreds.proverCreateClaimReq(wallet, proverDid, claimOffer, claimDef, "other_master_secret").get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateMasterSecretTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateMasterSecretTest.java new file mode 100644 index 0000000000..56bb828dc2 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateMasterSecretTest.java @@ -0,0 +1,51 @@ +package org.hyperledger.indy.sdk.anoncreds; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.util.concurrent.ExecutionException; + +public class ProverCreateMasterSecretTest extends AnoncredsIntegrationTest { + + private Wallet wallet; + private String walletName = "createMasterSecretWallet"; + + @Before + public void createWallet() throws Exception { + Wallet.createWallet("default", walletName, "default", null, null).get(); + this.wallet = Wallet.openWallet(walletName, null, null).get(); + } + + @After + public void deleteWallet() throws Exception { + this.wallet.closeWallet(); + Wallet.deleteWallet(walletName, null); + } + + @Test + public void testProverCreateMasterSecretWorks() throws Exception { + + Anoncreds.proverCreateMasterSecret(wallet, "master_secret_name").get(); + } + + @Test + public void testProverCreateMasterSecretWorksForDuplicate() throws Exception { + + Anoncreds.proverCreateMasterSecret(wallet, "master_secret_name").get(); + } + + @Test + public void testProverStoreClaimOfferWorksForInvalidIssuerDid() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String claimOffer = "{\"issuer_did\":\"invalid_base58_string\",\"schema_seq_no\":1}"; + + Anoncreds.proverStoreClaimOffer(wallet, claimOffer).get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateProofTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateProofTest.java new file mode 100644 index 0000000000..d498081f40 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateProofTest.java @@ -0,0 +1,199 @@ +package org.hyperledger.indy.sdk.anoncreds; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.utils.InitHelper; +import org.hyperledger.indy.sdk.utils.StorageUtils; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.rules.Timeout; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class ProverCreateProofTest extends AnoncredsIntegrationTest { + + @Test + public void testProverCreateProofWorks() throws Exception { + + initCommonWallet(); + + String proofRequest = "{\"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1, \"name\":\"name\"}},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}\n" + + " }"; + + String claimsJson = Anoncreds.proverGetClaimsForProofReq(wallet, proofRequest).get(); + + JSONObject claims = new JSONObject(claimsJson); + + JSONObject claimForAttribute = claims.getJSONObject("attrs").getJSONArray("attr1_uuid").getJSONObject(0); + + String claimUuid = claimForAttribute.getString("claim_uuid"); + + String requestedClaimsJson = String.format("{\n" + + " \"self_attested_attributes\":{},\n" + + " \"requested_attrs\":{\"attr1_uuid\":[\"%s\", true]},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":\"%s\"}\n" + + " }", claimUuid, claimUuid); + + String schemasJson = String.format("{\"%s\":%s}", claimUuid, schema); + String claimDefsJson = String.format("{\"%s\":%s}", claimUuid, claimDef); + String revocRegsJson = "{}"; + + String proofJson = Anoncreds.proverCreateProof(wallet, proofRequest, requestedClaimsJson, schemasJson, + masterSecretName, claimDefsJson, revocRegsJson).get(); + assertNotNull(proofJson); + } + + @Test + public void testProverCreateProofWorksForUsingNotSatisfyClaim() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + initCommonWallet(); + + String claimsJson = Anoncreds.proverGetClaims(wallet, "{}").get(); + + JSONArray claims = new JSONArray(claimsJson); + + String claimUuid = claims.getJSONObject(0).getString("claim_uuid"); + + String proofRequest = "{\"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1, \"name\":\"some_attr\"}},\n" + + " \"requested_predicates\":{}\n" + + " }"; + + String requestedClaimsJson = String.format("{\"self_attested_attributes\":{},\n" + + " \"requested_attrs\":{\"attr1_uuid\":[\"%s\", true]},\n" + + " \"requested_predicates\":{}\n" + + " }", claimUuid); + + String schemasJson = String.format("{\"%s\":%s}", claimUuid, schema); + String claimDefsJson = String.format("{\"%s\":%s}", claimUuid, claimDef); + String revocRegsJson = "{}"; + + Anoncreds.proverCreateProof(wallet, proofRequest, requestedClaimsJson, schemasJson, + masterSecretName, claimDefsJson, revocRegsJson).get(); + } + + @Test + public void testProverCreateProofWorksForInvalidMasterSecret() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletNotFoundError)); + + initCommonWallet(); + + String proofRequest = "{\"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1, \"name\":\"name\"}},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}\n" + + " }"; + + String claimsJson = Anoncreds.proverGetClaimsForProofReq(wallet, proofRequest).get(); + + JSONObject claims = new JSONObject(claimsJson); + + JSONObject claimForAttribute = claims.getJSONObject("attrs").getJSONArray("attr1_uuid").getJSONObject(0); + + String claimUuid = claimForAttribute.getString("claim_uuid"); + + String requestedClaimsJson = String.format("{\n" + + " \"self_attested_attributes\":{},\n" + + " \"requested_attrs\":{\"attr1_uuid\":[\"%s\", true]},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":\"%s\"}\n" + + " }", claimUuid, claimUuid); + + String schemasJson = String.format("{\"%s\":%s}", claimUuid, schema); + String claimDefsJson = String.format("{\"%s\":%s}", claimUuid, claimDef); + String revocRegsJson = "{}"; + + Anoncreds.proverCreateProof(wallet, proofRequest, requestedClaimsJson, schemasJson, "wrong_master_secret", claimDefsJson, revocRegsJson).get(); + } + + @Test + public void testProverCreateProofWorksForInvalidSchemas() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + initCommonWallet(); + + String proofRequest = "{\"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1, \"name\":\"name\"}},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}\n" + + " }"; + + String claimsJson = Anoncreds.proverGetClaimsForProofReq(wallet, proofRequest).get(); + + JSONObject claims = new JSONObject(claimsJson); + + JSONObject claimForAttribute = claims.getJSONObject("attrs").getJSONArray("attr1_uuid").getJSONObject(0); + + String claimUuid = claimForAttribute.getString("claim_uuid"); + + String requestedClaimsJson = String.format("{\n" + + " \"self_attested_attributes\":{},\n" + + " \"requested_attrs\":{\"attr1_uuid\":[\"%s\", true]},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":\"%s\"}\n" + + " }", claimUuid, claimUuid); + + String schemasJson = "{}"; + String claimDefsJson = String.format("{\"%s\":%s}", claimUuid, claimDef); + String revocRegsJson = "{}"; + + Anoncreds.proverCreateProof(wallet, proofRequest, requestedClaimsJson, schemasJson, masterSecretName, claimDefsJson, revocRegsJson).get(); + } + + @Test + public void testProverCreateProofWorksForInvalidRequestedClaimsJson() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + initCommonWallet(); + + String proofRequest = "{\"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1, \"name\":\"name\"}},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}\n" + + " }"; + + String claimsJson = Anoncreds.proverGetClaimsForProofReq(wallet, proofRequest).get(); + + JSONObject claims = new JSONObject(claimsJson); + + JSONObject claimForAttribute = claims.getJSONObject("attrs").getJSONArray("attr1_uuid").getJSONObject(0); + + String claimUuid = claimForAttribute.getString("claim_uuid"); + + String requestedClaimsJson = "{\"self_attested_attributes\":{},\n" + + " \"requested_predicates\":{}\n" + + " }"; + + String schemasJson = String.format("{\"%s\":%s}", claimUuid, schema); + String claimDefsJson = String.format("{\"%s\":%s}", claimUuid, claimDef); + String revocRegsJson = "{}"; + + Anoncreds.proverCreateProof(wallet, proofRequest, requestedClaimsJson, schemasJson, masterSecretName, claimDefsJson, revocRegsJson).get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimOfferTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimOfferTest.java new file mode 100644 index 0000000000..25265d73e0 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimOfferTest.java @@ -0,0 +1,95 @@ +package org.hyperledger.indy.sdk.anoncreds; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.json.JSONArray; +import org.junit.*; + +import java.util.concurrent.ExecutionException; + +public class ProverGetClaimOfferTest extends AnoncredsIntegrationTest { + + @Test + public void testsProverGetClaimOffersWorksForEmptyFilter() throws Exception { + + initCommonWallet(); + + String claimOffers = Anoncreds.proverGetClaimOffers(wallet, "{}").get(); + JSONArray claimOffersArray = new JSONArray(claimOffers); + + Assert.assertEquals(3, claimOffersArray.length()); + } + + @Test + public void testsProverGetClaimOffersWorksForFilterByIssuer() throws Exception { + + initCommonWallet(); + + String filter = String.format("{\"issuer_did\":\"%s\"}", issuerDid); + + String claimOffers = Anoncreds.proverGetClaimOffers(wallet, filter).get(); + JSONArray claimOffersArray = new JSONArray(claimOffers); + + Assert.assertEquals(2, claimOffersArray.length()); + + Assert.assertTrue(claimOffersArray.toString().contains(String.format(claimOfferTemplate, issuerDid, 1))); + Assert.assertTrue(claimOffersArray.toString().contains(String.format(claimOfferTemplate, issuerDid, 2))); + } + + @Test + public void testsProverGetClaimOffersWorksForFilterBySchema() throws Exception { + + initCommonWallet(); + + String filter = String.format("{\"schema_seq_no\":%d}", 2); + + String claimOffers = Anoncreds.proverGetClaimOffers(wallet, filter).get(); + JSONArray claimOffersArray = new JSONArray(claimOffers); + + Assert.assertEquals(2, claimOffersArray.length()); + + Assert.assertTrue(claimOffersArray.toString().contains(String.format(claimOfferTemplate, issuerDid, 2))); + Assert.assertTrue(claimOffersArray.toString().contains(String.format(claimOfferTemplate, issuerDid2, 2))); + } + + @Test + public void testsProverGetClaimOffersWorksForFilterByIssuerAndSchema() throws Exception { + + initCommonWallet(); + + String filter = String.format("{\"issuer_did\":\"%s\",\"schema_seq_no\":%d}", issuerDid, 1); + + String claimOffers = Anoncreds.proverGetClaimOffers(wallet, filter).get(); + JSONArray claimOffersArray = new JSONArray(claimOffers); + + Assert.assertEquals(1, claimOffersArray.length()); + + Assert.assertTrue(claimOffersArray.toString().contains(String.format(claimOfferTemplate, issuerDid, 1))); + } + + @Test + public void testsProverGetClaimOffersWorksForNoResult() throws Exception { + + initCommonWallet(); + + String filter = String.format("{\"schema_seq_no\":%d}", 3); + + String claimOffers = Anoncreds.proverGetClaimOffers(wallet, filter).get(); + JSONArray claimOffersArray = new JSONArray(claimOffers); + + Assert.assertEquals(0, claimOffersArray.length()); + } + + @Test + public void testsProverGetClaimOffersWorksForInvalidFilterJson() throws Exception { + + initCommonWallet(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String filter = String.format("{\"schema_seq_no\":\"%d\"}", 1); + + Anoncreds.proverGetClaimOffers(wallet, filter).get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimsForProofRequestTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimsForProofRequestTest.java new file mode 100644 index 0000000000..016cc118ab --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimsForProofRequestTest.java @@ -0,0 +1,243 @@ +package org.hyperledger.indy.sdk.anoncreds; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.Test; + +import java.util.concurrent.ExecutionException; + +import static org.junit.Assert.assertEquals; + +public class ProverGetClaimsForProofRequestTest extends AnoncredsIntegrationTest { + + @Test + public void testProverGetClaimsForProofRequestWorksForRevealedAttribute() throws Exception { + + initCommonWallet(); + + String proofRequest = "{\"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1, \"name\":\"name\"}},\n" + + " \"requested_predicates\":{}\n" + + " }"; + + String claimsJson = Anoncreds.proverGetClaimsForProofReq(wallet, proofRequest).get(); + + JSONObject claims = new JSONObject(claimsJson); + + JSONArray claimsForAttribute1 = claims.getJSONObject("attrs").getJSONArray("attr1_uuid"); + assertEquals(claimsForAttribute1.length(), 1); + } + + @Test + public void testProverGetClaimsForProofRequestWorksForNotFoundAttribute() throws Exception { + + initCommonWallet(); + + String proofRequest = "{\"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1, \"name\":\"attribute\"}},\n" + + " \"requested_predicates\":{}\n" + + " }"; + + String claimsJson = Anoncreds.proverGetClaimsForProofReq(wallet, proofRequest).get(); + + JSONObject claims = new JSONObject(claimsJson); + + JSONArray claimsForAttribute1 = claims.getJSONObject("attrs").getJSONArray("attr1_uuid"); + assertEquals(claimsForAttribute1.length(), 0); + } + + @Test + public void testProverGetClaimsForProofRequestWorksForSatisfyPredicate() throws Exception { + + initCommonWallet(); + + String proofRequest = "{\"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}\n" + + " }"; + + String claimsJson = Anoncreds.proverGetClaimsForProofReq(wallet, proofRequest).get(); + + JSONObject claims = new JSONObject(claimsJson); + + JSONArray claimsForPredicate = claims.getJSONObject("predicates").getJSONArray("predicate1_uuid"); + assertEquals(claimsForPredicate.length(), 1); + } + + @Test + public void testProverGetClaimsForProofRequestWorksForNotSatisfyPredicate() throws Exception { + + initCommonWallet(); + + String proofRequest = "{\"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":58}}\n" + + " }"; + + String claimsJson = Anoncreds.proverGetClaimsForProofReq(wallet, proofRequest).get(); + + JSONObject claims = new JSONObject(claimsJson); + + JSONArray claimsForPredicate = claims.getJSONObject("predicates").getJSONArray("predicate1_uuid"); + assertEquals(claimsForPredicate.length(), 0); + } + + @Test + public void testProverGetClaimsForProofRequestWorksForMultiplyAttributesAndPredicates() throws Exception { + + initCommonWallet(); + + String proofRequest = "{\"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\n" + + " \"attr1_uuid\":{\"schema_seq_no\":1, \"name\":\"name\"},\n" + + " \"attr2_uuid\":{\"schema_seq_no\":1, \"name\":\"sex\"}\n" + + " },\n" + + " \"requested_predicates\":{\n" + + " \"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18},\n" + + " \"predicate2_uuid\":{\"attr_name\":\"height\",\"p_type\":\"GE\",\"value\":160}\n" + + " }}"; + + String claimsJson = Anoncreds.proverGetClaimsForProofReq(wallet, proofRequest).get(); + + JSONObject claims = new JSONObject(claimsJson); + + JSONArray claimsForAttribute1 = claims.getJSONObject("attrs").getJSONArray("attr1_uuid"); + assertEquals(claimsForAttribute1.length(), 1); + + JSONArray claimsForAttribute2 = claims.getJSONObject("attrs").getJSONArray("attr2_uuid"); + assertEquals(claimsForAttribute2.length(), 1); + + JSONArray claimsForPredicate1 = claims.getJSONObject("predicates").getJSONArray("predicate1_uuid"); + assertEquals(claimsForPredicate1.length(), 1); + + JSONArray claimsForPredicate2 = claims.getJSONObject("predicates").getJSONArray("predicate2_uuid"); + assertEquals(claimsForPredicate2.length(), 1); + } + + @Test + public void testProverGetClaimsForProofRequestWorksForEmptyRequest() throws Exception { + + initCommonWallet(); + + String proofRequest = "{\"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{},\n" + + " \"requested_predicates\":{}\n" + + " }"; + + String claimsJson = Anoncreds.proverGetClaimsForProofReq(wallet, proofRequest).get(); + + JSONObject claims = new JSONObject(claimsJson); + + assertEquals(claims.getJSONObject("attrs").length(), 0); + assertEquals(claims.getJSONObject("predicates").length(), 0); + } + + @Test + public void testProverGetClaimsForProofRequestWorksForRevealedAttributeWithOtherSchema() throws Exception { + + initCommonWallet(); + + String proofRequest = "{\"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":2, \"name\":\"name\"}},\n" + + " \"requested_predicates\":{}\n" + + " }"; + + String claimsJson = Anoncreds.proverGetClaimsForProofReq(wallet, proofRequest).get(); + + JSONObject claims = new JSONObject(claimsJson); + + JSONArray claimsForAttribute1 = claims.getJSONObject("attrs").getJSONArray("attr1_uuid"); + assertEquals(claimsForAttribute1.length(), 0); + } + + @Test + public void testProverGetClaimsForProofRequestWorksForRevealedAttributeBySpecificIssuer() throws Exception { + + initCommonWallet(); + + String proofRequest = "{\"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"issuer_did\":\"NcYxiDXkpYi6ov5FcYDi1e\",\"name\":\"name\"}},\n" + + " \"requested_predicates\":{}\n" + + " }"; + + String claimsJson = Anoncreds.proverGetClaimsForProofReq(wallet, proofRequest).get(); + + JSONObject claims = new JSONObject(claimsJson); + + JSONArray claimsForAttribute1 = claims.getJSONObject("attrs").getJSONArray("attr1_uuid"); + assertEquals(claimsForAttribute1.length(), 1); + } + + @Test + public void testProverGetClaimsForProofRequestWorksForSatisfyPredicateByIssuerAndSchema() throws Exception { + + initCommonWallet(); + + String proofRequest = "{\"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18,\"schema_seq_no\":1,\"issuer_did\":\"NcYxiDXkpYi6ov5FcYDi1e\"}}\n" + + " }"; + + String claimsJson = Anoncreds.proverGetClaimsForProofReq(wallet, proofRequest).get(); + + JSONObject claims = new JSONObject(claimsJson); + + JSONArray claimsForPredicate = claims.getJSONObject("predicates").getJSONArray("predicate1_uuid"); + assertEquals(claimsForPredicate.length(), 1); + } + + @Test + public void testProverGetClaimsForProofRequestWorksForInvalidProofRequest() throws Exception { + + initCommonWallet(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String proofRequest = "{\"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_predicates\":{}\n" + + " }"; + + Anoncreds.proverGetClaimsForProofReq(wallet, proofRequest).get(); + } + + @Test + public void testProverGetClaimsForProofRequestWorksForInvalidPredicateType() throws Exception { + + initCommonWallet(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String proofRequest = "{\"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"LE\",\"value\":18}}\n" + + " }"; + + Anoncreds.proverGetClaimsForProofReq(wallet, proofRequest).get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimsTest.java new file mode 100644 index 0000000000..7b5047e7c3 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimsTest.java @@ -0,0 +1,80 @@ +package org.hyperledger.indy.sdk.anoncreds; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.json.JSONArray; +import org.junit.Test; + +import java.util.concurrent.ExecutionException; + +import static org.junit.Assert.assertEquals; + +public class ProverGetClaimsTest extends AnoncredsIntegrationTest { + + @Test + public void testProverGetClaimsWorksForEmptyFilter() throws Exception { + + initCommonWallet(); + + String claims = Anoncreds.proverGetClaims(wallet, "{}").get(); + + JSONArray claimsArray = new JSONArray(claims); + + assertEquals(1, claimsArray.length()); + } + + @Test + public void testProverGetClaimsWorksForFilterByIssuer() throws Exception { + + initCommonWallet(); + + String filter = String.format("{\"issuer_did\":\"%s\"}", issuerDid); + + String claims = Anoncreds.proverGetClaims(wallet, filter).get(); + + JSONArray claimsArray = new JSONArray(claims); + + assertEquals(1, claimsArray.length()); + } + + @Test + public void testProverGetClaimsWorksForFilterByIssuerAndSchema() throws Exception { + + initCommonWallet(); + + String filter = String.format("{\"issuer_did\":\"%s\", \"schema_seq_no\":%d}", issuerDid, 1); + + String claims = Anoncreds.proverGetClaims(wallet, filter).get(); + + JSONArray claimsArray = new JSONArray(claims); + + assertEquals(1, claimsArray.length()); + } + + @Test + public void testProverGetClaimsWorksForEmptyResult() throws Exception { + + initCommonWallet(); + + String filter = String.format("{\"schema_seq_no\":%d}", 10); + + String claims = Anoncreds.proverGetClaims(wallet, filter).get(); + + JSONArray claimsArray = new JSONArray(claims); + + assertEquals(0, claimsArray.length()); + } + + @Test + public void testProverGetClaimsWorksForInvalidFilterJson() throws Exception { + + initCommonWallet(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String filter = String.format("{\"schema_seq_no\":\"%d\"}", 1); + + Anoncreds.proverGetClaims(wallet, filter).get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverStoreClaimOfferTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverStoreClaimOfferTest.java new file mode 100644 index 0000000000..69a32bcc06 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverStoreClaimOfferTest.java @@ -0,0 +1,58 @@ +package org.hyperledger.indy.sdk.anoncreds; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.util.concurrent.ExecutionException; + +public class ProverStoreClaimOfferTest extends AnoncredsIntegrationTest { + + private Wallet wallet; + private String walletName = "storeClaimOfferWallet"; + + @Before + public void createWallet() throws Exception { + Wallet.createWallet("default", walletName, "default", null, null).get(); + this.wallet = Wallet.openWallet(walletName, null, null).get(); + } + + @After + public void deleteWallet() throws Exception { + wallet.closeWallet().get(); + Wallet.deleteWallet(walletName, null).get(); + } + + @Test + public void testProverStoreClaimOfferWorks() throws Exception { + + String claimOffer = "{\"issuer_did\":\"NcYxiDXkpYi6ov5FcYDi1e\",\"schema_seq_no\":1 }"; + + Anoncreds.proverStoreClaimOffer(wallet, claimOffer).get(); + } + + @Test + public void testProverStoreClaimOfferWorksForInvalidJson() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String claimOffer = "{\"issuer_did\":\"NcYxiDXkpYi6ov5FcYDi1e\"}"; + + Anoncreds.proverStoreClaimOffer(wallet, claimOffer).get(); + } + + @Test + public void testProverStoreClaimOfferWorksForInvalidIssuerDid() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String claimOffer = "{\"issuer_did\":\"invalid_base58_string\",\"schema_seq_no\":1}"; + + Anoncreds.proverStoreClaimOffer(wallet, claimOffer).get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverStoreClaimTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverStoreClaimTest.java new file mode 100644 index 0000000000..f15a45799e --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverStoreClaimTest.java @@ -0,0 +1,72 @@ +package org.hyperledger.indy.sdk.anoncreds; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.junit.*; + +import java.util.concurrent.ExecutionException; + +import static org.junit.Assert.assertNotNull; + +public class ProverStoreClaimTest extends AnoncredsIntegrationTest { + + @Test + public void testProverCreateAndStoreClaimReqWorks() throws Exception { + + initCommonWallet(); + + String claimOffer = String.format(claimOfferTemplate, issuerDid, 1); + + String claimRequest = Anoncreds.proverCreateClaimReq(wallet, proverDid, claimOffer, claimDef, masterSecretName).get(); + + String claim = "{\"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" + + " \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" + + " \"height\":[\"175\",\"175\"],\n" + + " \"age\":[\"28\",\"28\"]\n" + + " }"; + + AnoncredsResults.IssuerCreateClaimResult createClaimResult = Anoncreds.issuerCreateClaim(wallet, claimRequest, claim, - 1, - 1).get(); + assertNotNull(createClaimResult); + String claimJson = createClaimResult.getClaimJson(); + + Anoncreds.proverStoreClaim(wallet, claimJson).get(); + } + + @Test + public void testProverCreateAndStoreClaimReqWorksWithoutClaimReq() throws Exception { + + initCommonWallet(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletNotFoundError)); + + String claimJson = String.format("{\"claim\":{\"sex\":[\"male\",\"1\"],\"age\":[\"28\",\"28\"],\"name\":[\"Alex\",\"1\"],\"height\":[\"175\",\"175\"]},\n" + + " \"issuer_did\":\"%s\",\n" + + " \"revoc_reg_seq_no\":null,\n" + + " \"schema_seq_no\":2,\n" + + " \"signature\":{\"primary_claim\":{\"m2\":\"1\",\"a\":\"1\",\"e\":\"2\",\"v\":\"3\"}," + + " \"non_revocation_claim\":null}}", issuerDid2); + + Anoncreds.proverStoreClaim(wallet, claimJson).get(); + } + + @Test + public void testProverCreateAndStoreClaimReqWorksForInvalidClaimJson() throws Exception { + + initCommonWallet(); + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String claimOffer = String.format(claimOfferTemplate, issuerDid, 1); + + Anoncreds.proverCreateClaimReq(wallet, proverDid, claimOffer, claimDef, masterSecretName).get(); + + String claimJson = "{\"claim\":{\"sex\":[\"male\",\"1\"],\"age\":[\"28\",\"28\"],\"name\":[\"Alex\",\"1\"],\"height\":[\"175\",\"175\"]},\n" + + " \"issuer_did\":1,\"\n" + + " \"revoc_reg_seq_no\":null,\n" + + " \"schema_seq_no\":1}"; + + Anoncreds.proverStoreClaim(wallet, claimJson).get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/VerifierVerifyProofTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/VerifierVerifyProofTest.java new file mode 100644 index 0000000000..68354c8238 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/VerifierVerifyProofTest.java @@ -0,0 +1,80 @@ +package org.hyperledger.indy.sdk.anoncreds; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.junit.Test; + +import java.util.concurrent.ExecutionException; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class VerifierVerifyProofTest extends AnoncredsIntegrationTest { + + private String claimDef = "{\"ref\":1," + + " \"signature_type\":\"CL\"," + + " \"origin\":\"NcYxiDXkpYi6ov5FcYDi1e\"," + + " \"data\":{\"primary\":{\"n\":\"94759924268422840873493186881483285628376767714620627055233230078254863658476446487556117977593248501523199451418346650764648601684276437772084327637083000213497377603495837360299641742248892290843802071224822481683143989223918276185323177379400413928352871249494885563503003839960930062341074783742062464846448855510814252519824733234277681749977392772900212293652238651538092092030867161752390937372967233462027620699196724949212432236376627703446877808405786247217818975482797381180714523093913559060716447170497587855871901716892114835713057965087473682457896508094049813280368069805661739141591558517233009123957\",\"s\":\"3589207374161609293256840431433442367968556468254553005135697551692970564853243905310862234226531556373974144223993822323573625466428920716249949819187529684239371465431718456502388533731367046146704547241076626874082510133130124364613881638153345624380195335138152993132904167470515345775215584510356780117368593105284564368954871044494967246738070895990267205643985529060025311535539534155086912661927003271053443110788963970349858709526217650537936123121324492871282397691771309596632805099306241616501610166028401599243350835158479028294769235556557248339060399322556412171888114265194198405765574333538019124846\",\"rms\":\"57150374376895616256492932008792437185713712934712117819417607831438470701645904776986426606717466732609284990796923331049549544903261623636958698296956103821068569714644825742048584174696465882627177060166162341112552851798863535031243458188976013190131935905789786836375734914391914349188643340535242562896244661798678234667651641013894284156416773868299435641426810968290584996112925365638881750944407842890875840705650290814965768221299488400872767679122749231050406680432079499973527780212310700022178178822528199576164498116369689770884051691678056831493476045361227274839673581033532995523269047577973637307053\",\"r\":{\"age\":\"94304485801056920773231824603827244147437820123357994068540328541540143488826838939836897544389872126768239056314698953816072289663428273075648246498659039419931054256171488371404693243192741923382499918184822032756852725234903892700640856294525441486319095181804549558538523888770076173572615957495813339649470619615099181648313548341951673407624414494737018574238782648822189142664108450534642272145962844003886059737965854042074083374478426875684184904488545593139633653407062308621502392373426120986761417580127895634822264744063122368296502161439648408926687989964483291459079738447940651025900007635890755686910\",\"sex\":\"29253365609829921413347591854991689007250272038394995372767401325848195298844802462252851926995846503104090589196060683329875231216529049681648909174047403783834364995363938741001507091534282239210301727771803410513303526378812888571225762557471133950393342500638551458868147905023198508660460641434022020257614450354085808398293279060446966692082427506909617283562394303716193372887306176319841941848888379308208426966697446699225783646634631703732019477632822374479322570142967559738439193417309205283438893083349863592921249218168590490390313109776446516881569691499831380592661740653935515397472059631417493981532\",\"name\":\"25134437486609445980011967476486104706321061312022352268621323694861467756181853100693555519614894168921947814126694858839278103549577703105305116890325322098078409416441750313062396467567140699008203113519528887729951138845002409659317083029073793314514377377412805387401717457417895322600145580639449003584446356048213839274172751441145076183734269045919984853749007476629365146654240675320041155618450449041510280560040162429566008590065069477149918088087715269037925211599101597422023202484497946662159070023999719865939258557778022770035320019440597702090334486792710436579355608406897769514395306079855023848170\",\"height\":\"59326960517737425423547279838932030505937927873589489863081026714907925093402287263487670945897247474465655528290016645774365383046524346223348261262488616342337864633104758662753452450299389775751012589698563659277683974188553993694220606310980581680471280640591973543996299789038056921309016983827578247477799948667666717056420270448516049047961099547588510086600581628091290215485826514170097211360599793229701811672966818089371089216189744274422526431130783428589346341196561742409198605034972210917502326180305735092988639850309253190875578501020679137562856724998821945605494355779034135306337094344532980411836\"},\"rctxt\":\"9641986614889199796257508700106896585587271615330980339636468819377346498767697681332046156705231986464570206666984343024200482683981302064613556104594051003956610353281701880542337665385482309134369756144345334575765116656633321636736946947493150642615481313285221467998414924865943067790561494301461899025374692884841352282256044388512875752628313052128404892424405230961678931620525106856624692942373538946467902799339061714326383378018581568876147181355325663707572429090278505823900491548970098691127791086305310899642155499128171811034581730190877600697624903963241473287185133286356124371104261592694271730029\",\"z\":\"77594127026421654059198621152153180600664927707984020918609426112642522289621323453889995053400171879296098965678384769043918218957929606187082395048777546641833348694470081024386996548890150355901703252426977094536933434556202865213941384425538749866521536494046548509344678288447175898173634381514948562261015286492185924659638474376885655055568341574638453213864956407243206035973349529545863886325462867413885904072942842465859476940638839087894582648849969332663627779378998245133055807038199937421971988505911494931665143822588532097754480882750243126847177560978100527491344463525107644125030963904001009159559\"},\"revocation\":null}}"; + + private String proofRequest = "{\"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1, \"name\":\"name\"}},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}\n" + + " }"; + + String schemasJson = String.format("{\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\":%s}", schema); + String claimDefsJson = String.format("{\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\":%s}", claimDef); + String revocRegsJson = "{}"; + + @Test + public void testVerifierVerifyProofWorksForCorrectProof() throws Exception { + + String proofJson = "{\"proofs\":{\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\":{\"proof\":{\"primary_proof\":{\"eq_proof\":{\"revealed_attrs\":{\"name\":\"1139481716457488690172217916278103335\"},\"a_prime\":\"47629821806628155353444789773246165920681315271529392722265555946090524267165563309836167110610840740533588118152308411732923636370660640410661034994521654033599863817144282118006097899736622728860229305231675970853294584911572355833537271010861501353858292189045263114095480601737776505186511389129055847562085611741257601964074827979121349153316235245772819207422031038042586202074331681302501661153569340935741290924699468188826629478130140797677338573924284871118002193526319478550852287453975107498037063076866410320160118555629090040954555043934303307652160345244864713226315470541231435958298648179413077988340\",\"e\":\"13427639393364185909415877973872458621259927563729922146828001652769380799419438410309469022979920689628523901764614163117469683925816443\",\"v\":\"852136445143816932026946294488424887907102968158908948827421962603492187508454543239422067899916472317305416590471170842186669606584356963437132366711335927890209765986844538775191207999204354235774464468525274918097404114453069375363594310105209141774763909570100638835926337238009617444858777301355087706167735590386774813901740600054753028260344014744801229032610106838480523182317262113911183640784111960909501662169298536941919854667754097841344375972975021196106884215734228415868248724905018661498061287694439466570946597514142085096419985189064172035527690786158872698717583830848410994616274586162550376126607414773916066374234063208380831144157533076866210628625236440222547584539349936639548061601416341705483504386186280800509889531835172071717956251546280392606775903107774727736794828168898273891724336881907672405328368540895104468091907771325910937575557566831844131159128453840354307814975621978196047820\",\"m\":{\"age\":\"1117601261519431120446925325460734824239475567013636538481947258329666056692767097795046086413732472111811628751812987521644198549167671875326968410921589186689138994171774838662\",\"height\":\"7064132689652704067914104576495132313294680087958177180391515757079548676035445873279966783996928425154050462229933823707574545166617858646442019030600136959459527533262821184869\",\"sex\":\"16084497853957041205729191269508720470626311156190485518484640641677445098603656354458362520541393995692536218820724164533958162674375198846036330444513484319280148335515891811530\"},\"m1\":\"154906224259819061652290487122980839849626068919893070220438585977323162319993111920906032317552959103520053742608858935542877608981244065301675821390065831113115709272412144796159984624494428122971995557415296140268002332169405587907128359886810433617416529821500995701094400375272097687818064435577784795275\",\"m2\":\"13805395408072590464827983892588030341708765524663545700917462089376137940485022437657208204460048097312372685954050370540389593952001973312378647790917367330461398089529292217752\"},\"ge_proofs\":[{\"u\":{\"1\":\"7698818972783845439601187851976452936638792889455287252542709653271706844173743185409084669157965935169942655008606334521674712818637940377261656468700786810566551698412412949418\",\"0\":\"11703047052430512223413711314521545616119146623040600935686474696241801697819280425232876917607198335376453682738553665221410353412906194951254558355994401995990233992518110582450\",\"3\":\"13210777821918317858818819091924507295018522783042111457450035423463340571245465760486275059291363621513532153389441883097799049597687545496359999443320001567152794884095192951040\",\"2\":\"15219471780524079156861690098171693383497641272226737821992208834301871102152362116211452788300889697214391366996966539871625433480959011635688106136537800706217506402845296449689\"},\"r\":{\"1\":\"46043242109380749151527145850513330956077996622769158245225343392397735706292106535150958053995712629189143692293204979798837951212291825184346767969751978730000071952944305252032332015837054475531407691352179423131405515518588355918925056889302269768343499864256747177988825578647189563088068257214198650437730618330249172716051559993880468542083352885474175039320848153156858562341041960950299312991459780503345784440261679263045723337629951517601461685539857683027034345542399365706329805317943096391758978877658949910614447086409173234155028671453929715706057153381022697673192590033507204548864311227048268516889390503318015295207078022755834130221198717787608473222789491216667698651180077661375273569115943192\",\"0\":\"135472587547410377947826119498467634347118057359097899596599164976338466445104141784869016998150489852448547539824768048351359572626675997498079394825940306636285481821620973655797996638210760710325933304918452142858879806106214845499670718704532018129553348815327362843246706518826311676917538452317818631484884032929252959289913274829848084561421467966320595980172006456003183536232790787521924655750157145207798486087511869939940023266736153366338179116840490184005332351004990854691988404031259910319601383696749511809898297656135548118786342107367065232798999979296280467063561892962526945512167505847049907450058650930480352253243357594344686769208712964458923557777584158831146374282687397585726706489164423632\",\"DELTA\":\"93540839493959971552865423901789226093328763011922445919928571946113703515842729132879472109395228387208764738970926484618949870591214627692618668077375153559192701474693025462226656116549337248146652482501255820930607033869432220667968682424554711616471973627651716863421554516577716366331699848682958681216261888139409101603059124344125075525791543312721162515584942523419876134808829569829529457617639955678189490257208141837196965948342373022812790844435050648360150869293836349223060722858500537182872294143846213258360218898475766641125493477502149553491502593654061863323857297998048614447925371606038801933864960337435890254277043261512846682042139570000962051463878026338583242360548041329046695667868842400\",\"3\":\"1227675452527605924725300993571504188580051470857656204064614533296779844072852823820754766175236321050062349182891221840452517985644028521499240739391613871973822807731772613052644168369405390658793869751915172749739844553410726807277698347769400977274750672880389943392076308065414059539317340070691852044062594715307024113666759844200606183662256825096857658837519571386467051003466014468855293015652584667669998830524947537781865745830650392641812221679438090257444660715937570193098993118585554478799821072396238689063767016402460690760792908977364175126682041704095200572282644311025594681667826054722587271200221036938804846621444065128275082392082327596239358623150786484106872933657139420542280145197712634108\",\"2\":\"596248147592834822582469335300585333722415132713749620075902332764163096347819006925876158892694742461036531935093982309708492066217459300117157420442081698140277277546563570823996272914068575482008392971932777453900260626542725308060927710122631763045025742980634216666560934260634907599194353151523256914796667535940073668465664206971169038864484235442207811974981191879443614478897291543702607764944403808380921189291059195014621592027660463072969363556421687131446107696579365265893962197300447027501604372738056016734644378437907931412654753728514905671605635291285742886484416973884856055084605172305967034292646171874483670469193852404511746786039743401185954843446037600121496137915619789351744485264614840070\"},\"mj\":\"1117601261519431120446925325460734824239475567013636538481947258329666056692767097795046086413732472111811628751812987521644198549167671875326968410921589186689138994171774838662\",\"alpha\":\"76727612740067576380015106087224381023260815407331375101920043509817863645705120013304683427627332447210083684516403565749916480947649443674885388155460323163682547865307733144184097845709556309570345707127872162476432029772452433292049079349274445907295491125915363620615679995457134810061392296263970553630102299601689685622244925494554558218277670233361938142224820526392365740420502452466959099546877778248089664282581792213376636587293479012783947088070052463503335266180110771978445892744225891676396288437005847308189508347446490710626231658457908472341606549292437553353163031111068977301305043175839949352742711874426231072729977019365761072816602400121302646283352164756787266537474728685656685493249314400351742964904006326192403855909148605656818024621453179832395687665671245528217931951331393482249182516107670379946496778373\",\"t\":{\"1\":\"37203689290881948278188715497642400459048942241931994079434400288578680362970117779048886269388440270597283202033458042171954610700745461571112086648991639439510380585728148682202768590972068041537531136529323260832899360551065706810590032715173070285762675403853992183366951113799098912676809373169763887110420539387555392787590966452796271491986622992160642135480293110112269570862265489120557014181468118619500321000966443141863893743211690388599242584469856365803370202569641902205925191670838354052104480074127555862332399641076324738839120815544432811566503174551735326387678621283249883091766325861497740614317\",\"3\":\"58486787977689017034592833190899828017343431922483563651969628402499947729293364026001243898136737211851089198526360764391403150763769829047179796728616126204105160762333590343947446892105646111520243793053992399512412375936746396187319527051818920531870855183738837254656664620975569939859368862778444291640228229744805843388153451336792379036403300211151424879060241580540910888241769468335914016289938374111481091198264912969768783884602931940994543804730631920434719776196148182987249363641941951160704928605829395517074202388967815738516252602903999010405305463910751219873354588685197134114358234107748126140977\",\"0\":\"60771874648036182010335841594233428920565254732600738082343398028553347795361460295011584446745121430144172025428394361648540904134739046923992231536160801306934272250969829886396340824213814702904457884984387666505055153957942221822193548673145705543973635530652570436109428474727638128773540793530691399549837156239786231362112148914687724325416768262058486101761972044802628459748878200584371058300150212485731451700436345975266860685549673168984700174294811561393162860595319582236734968601457003780816977537443267217411297266600994916897237305128142313335280264655603445636393371224354539882875937093696844430903\",\"DELTA\":\"32816484171372208266594641116109072545171919234551585018140151846920408763078147655907777031259225522515086979967895258126318315788662577171150780535509410112003001556402222994276811926864642497249250763185467678044678144507739529818566125668667424447792097244624010084189629269472698722402896445274092470014229247479740671263651727480322483037149584904549203417226525624083290572692241241259382947122018271686649224741832992966652878170311798126004447080305528487720923103595513611363001766063956060990267107048028416069435287244770875463867263571308182619338433913487209319707428378896314619624990311543563016697299\",\"2\":\"36428320569485697540634597755814766104888687488985202673924762266313135133244610404742081973550848160712054769198012193456278135847215508952327879544434490828380496286187725750283788811367824465072001959950807751252194618152990469069074061195618692339915840384087350671392595652921761835083158086795163935060896053332506433434451836095710383871272788002621913967538399141417857031787255744141437237474972197102809365346359345477248611632307159641948507043668113827177494748159094045928919209335044052792843664865311991178972383241855607627188111601119780878072683890170539599447876998109080150992209773901144245398001\"},\"predicate\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}]},\"non_revoc_proof\":null},\"schema_seq_no\":1,\"revoc_reg_seq_no\":null,\"issuer_did\":\"did\"}},\"aggregated_proof\":{\"c_hash\":\"33103550379681684069592829341967479618752165928802550870585275205292715916069\",\"c_list\":[[1,121,77,5,144,154,14,192,190,190,145,180,128,71,22,60,168,20,46,163,139,194,71,165,220,188,121,76,25,146,231,114,65,54,69,68,19,200,250,192,47,123,157,132,74,50,28,69,226,195,243,118,45,63,237,197,216,202,206,101,33,56,225,200,128,3,89,12,182,38,113,221,165,119,228,201,156,201,172,136,59,64,51,72,164,198,49,228,223,117,80,64,166,226,37,8,29,146,186,80,210,119,76,252,4,255,62,218,112,163,164,147,247,190,108,76,140,191,76,217,214,184,152,179,193,149,15,70,197,46,90,60,255,247,197,219,252,73,76,0,125,104,114,22,182,161,110,36,162,103,27,42,88,18,161,237,198,43,177,189,181,86,135,207,71,114,0,26,175,12,199,125,25,124,178,87,36,208,251,15,191,127,202,148,152,43,142,92,191,7,89,153,130,195,223,248,176,109,97,164,126,162,181,124,237,130,155,197,66,59,40,197,72,84,32,100,64,55,227,60,214,143,200,200,89,115,236,172,145,56,100,73,20,242,233,95,130,58,112,153,120,115,119,42,199,30,205,88,223,42,196,184,41,19,100,19,244],[1,225,103,238,42,147,91,191,110,69,154,53,57,156,124,43,174,155,76,202,193,98,128,38,207,126,66,70,161,96,109,127,174,44,203,198,177,238,118,117,89,227,170,155,44,251,35,119,219,29,100,173,26,144,95,50,177,4,40,234,117,174,210,192,172,57,160,198,42,199,212,243,240,114,59,91,207,68,57,38,198,2,73,18,16,209,182,145,206,71,17,69,222,49,36,120,72,117,169,107,238,208,235,216,24,183,201,81,15,83,242,45,136,184,166,26,142,136,228,58,229,235,88,169,238,134,205,96,85,9,122,53,147,100,183,114,92,54,125,178,125,75,127,116,50,88,109,152,22,4,121,252,190,18,190,130,143,138,59,231,38,131,176,54,19,194,218,67,144,122,91,43,86,73,233,48,193,30,183,183,191,238,216,167,101,28,185,43,118,64,242,16,62,239,177,27,109,144,67,221,175,202,4,92,130,74,24,20,151,15,227,225,142,71,145,46,192,248,87,57,183,142,253,52,20,56,153,220,234,25,67,116,225,179,211,116,161,37,64,34,48,155,1,1,159,157,37,31,202,19,229,152,23,138,183,126,55],[1,38,181,193,191,72,2,239,34,83,49,36,179,160,82,112,172,98,255,63,60,22,177,249,67,215,220,198,181,7,49,254,133,243,221,214,47,64,229,82,11,94,175,57,86,152,229,192,184,96,136,116,226,123,128,217,23,244,19,204,36,44,123,208,88,24,217,120,145,139,25,233,227,5,119,90,47,147,1,115,92,39,119,194,167,17,229,39,163,167,237,14,116,234,106,252,216,54,33,233,21,54,183,130,144,161,177,142,177,240,51,73,21,202,188,103,244,153,204,219,123,231,139,135,189,155,143,28,4,180,44,148,0,27,103,26,13,203,31,32,166,67,84,87,23,72,234,236,20,1,84,70,86,76,192,164,235,124,86,128,78,230,119,155,95,121,125,20,244,181,121,250,169,9,67,85,213,177,139,111,187,183,114,165,249,177,161,181,175,46,226,66,86,84,124,86,69,143,217,158,161,30,107,133,44,239,89,209,24,150,1,238,122,144,138,179,121,114,90,13,212,209,60,126,37,62,177,180,131,222,168,2,201,156,169,220,224,53,8,203,220,215,163,104,195,184,73,35,241,182,177,80,41,253,230,90,173],[1,32,145,96,219,241,190,19,195,129,219,50,148,152,107,12,189,225,103,171,149,252,193,243,136,132,195,44,19,20,247,140,160,91,230,78,31,242,85,213,65,185,1,91,12,69,118,80,26,135,102,131,4,108,130,230,83,91,176,249,196,56,128,127,82,72,106,49,211,94,133,40,86,72,42,187,199,216,191,223,208,206,121,118,15,167,255,228,57,206,158,217,64,205,212,178,8,248,129,183,221,98,70,54,37,55,47,81,120,59,186,238,165,0,70,173,137,193,232,180,125,211,237,182,249,191,173,107,129,164,148,231,116,225,66,66,71,156,39,248,164,253,234,140,205,177,140,117,47,21,15,242,31,113,118,91,143,89,213,86,143,135,21,46,35,199,214,107,111,65,65,19,26,171,130,16,19,102,145,210,210,61,51,169,148,169,118,182,106,107,253,100,214,232,52,103,180,96,249,254,71,6,11,119,48,129,213,223,205,93,20,117,26,187,32,151,212,137,203,17,237,208,150,72,23,225,235,122,188,34,105,115,0,160,168,251,191,22,242,238,207,74,142,154,66,94,149,191,215,194,134,6,165,244,167,233,241],[1,207,77,250,146,127,242,229,44,172,182,201,183,242,32,242,182,129,233,10,8,180,23,191,163,21,238,158,5,27,216,146,253,173,127,99,95,168,209,132,242,196,242,34,25,25,249,211,51,236,164,153,175,61,65,150,82,251,174,102,186,47,195,82,44,90,252,184,74,89,251,177,254,108,151,136,230,220,93,224,173,247,244,116,132,59,170,215,194,30,87,84,166,147,57,156,201,207,132,203,222,191,253,15,19,228,173,81,156,4,51,121,227,159,50,18,148,129,205,42,42,227,252,138,62,176,115,227,253,52,125,110,178,167,132,244,14,116,195,194,172,44,45,63,38,121,215,136,68,230,21,108,133,159,197,179,94,78,233,107,236,114,92,165,248,22,124,161,23,142,236,224,175,233,134,25,97,150,131,61,220,203,104,154,199,247,146,47,205,56,209,0,133,132,18,103,136,8,202,37,29,100,105,12,232,74,33,6,255,202,96,170,52,229,244,4,235,2,201,125,86,168,179,224,130,81,54,221,185,184,187,141,0,114,98,38,70,225,228,60,157,53,210,238,60,216,215,154,48,73,3,157,192,245,81,170,49],[1,3,244,229,158,71,18,146,198,202,27,2,231,37,13,145,243,84,112,220,61,174,4,175,104,200,64,146,193,20,174,126,42,157,168,76,165,21,50,216,82,211,180,73,244,54,227,200,19,157,25,228,81,37,64,201,19,138,175,50,246,169,11,45,74,194,131,236,127,177,41,242,130,55,112,182,98,22,99,48,153,83,161,250,65,89,3,97,6,5,171,54,223,87,98,103,23,200,212,177,140,155,151,252,125,45,176,55,92,41,56,2,252,32,149,60,3,168,209,193,23,168,230,182,72,193,230,224,5,15,58,63,93,196,33,93,76,188,30,70,31,136,64,204,223,2,230,210,243,255,135,193,52,132,248,160,22,18,164,71,77,80,112,229,120,116,210,225,2,19,139,35,0,214,5,246,9,106,136,204,0,148,97,21,222,153,57,177,162,11,243,252,7,242,34,239,245,50,104,74,221,92,73,13,142,10,184,250,246,167,240,46,230,86,207,181,12,133,81,119,143,164,88,114,223,243,179,208,175,84,161,27,11,225,36,37,177,112,85,81,184,163,223,159,36,9,247,20,13,230,215,108,117,35,99,117,211]]},\"requested_proof\":{\"revealed_attrs\":{\"attr1_uuid\":[\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\",\"Alex\",\"1139481716457488690172217916278103335\"]},\"unrevealed_attrs\":{},\"self_attested_attrs\":{},\"predicates\":{\"predicate1_uuid\":\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\"}}}"; + + Boolean valid = Anoncreds.verifierVerifyProof(proofRequest, proofJson, schemasJson, claimDefsJson, revocRegsJson).get(); + assertTrue(valid); + } + + @Test + public void testVerifierVerifyProofWorksForProofDoesNotCorrespondToRequested() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String proofRequest = "{\"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1,\"name\":\"sex\"}},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"height\",\"p_type\":\"GE\",\"value\":180}}\n" + + " }"; + + String proofJson = "{\"proofs\":{\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\":{\"proof\":{\"primary_proof\":{\"eq_proof\":{\"revealed_attrs\":{\"name\":\"1139481716457488690172217916278103335\"},\"a_prime\":\"47629821806628155353444789773246165920681315271529392722265555946090524267165563309836167110610840740533588118152308411732923636370660640410661034994521654033599863817144282118006097899736622728860229305231675970853294584911572355833537271010861501353858292189045263114095480601737776505186511389129055847562085611741257601964074827979121349153316235245772819207422031038042586202074331681302501661153569340935741290924699468188826629478130140797677338573924284871118002193526319478550852287453975107498037063076866410320160118555629090040954555043934303307652160345244864713226315470541231435958298648179413077988340\",\"e\":\"13427639393364185909415877973872458621259927563729922146828001652769380799419438410309469022979920689628523901764614163117469683925816443\",\"v\":\"852136445143816932026946294488424887907102968158908948827421962603492187508454543239422067899916472317305416590471170842186669606584356963437132366711335927890209765986844538775191207999204354235774464468525274918097404114453069375363594310105209141774763909570100638835926337238009617444858777301355087706167735590386774813901740600054753028260344014744801229032610106838480523182317262113911183640784111960909501662169298536941919854667754097841344375972975021196106884215734228415868248724905018661498061287694439466570946597514142085096419985189064172035527690786158872698717583830848410994616274586162550376126607414773916066374234063208380831144157533076866210628625236440222547584539349936639548061601416341705483504386186280800509889531835172071717956251546280392606775903107774727736794828168898273891724336881907672405328368540895104468091907771325910937575557566831844131159128453840354307814975621978196047820\",\"m\":{\"age\":\"1117601261519431120446925325460734824239475567013636538481947258329666056692767097795046086413732472111811628751812987521644198549167671875326968410921589186689138994171774838662\",\"height\":\"7064132689652704067914104576495132313294680087958177180391515757079548676035445873279966783996928425154050462229933823707574545166617858646442019030600136959459527533262821184869\",\"sex\":\"16084497853957041205729191269508720470626311156190485518484640641677445098603656354458362520541393995692536218820724164533958162674375198846036330444513484319280148335515891811530\"},\"m1\":\"154906224259819061652290487122980839849626068919893070220438585977323162319993111920906032317552959103520053742608858935542877608981244065301675821390065831113115709272412144796159984624494428122971995557415296140268002332169405587907128359886810433617416529821500995701094400375272097687818064435577784795275\",\"m2\":\"13805395408072590464827983892588030341708765524663545700917462089376137940485022437657208204460048097312372685954050370540389593952001973312378647790917367330461398089529292217752\"},\"ge_proofs\":[{\"u\":{\"1\":\"7698818972783845439601187851976452936638792889455287252542709653271706844173743185409084669157965935169942655008606334521674712818637940377261656468700786810566551698412412949418\",\"0\":\"11703047052430512223413711314521545616119146623040600935686474696241801697819280425232876917607198335376453682738553665221410353412906194951254558355994401995990233992518110582450\",\"3\":\"13210777821918317858818819091924507295018522783042111457450035423463340571245465760486275059291363621513532153389441883097799049597687545496359999443320001567152794884095192951040\",\"2\":\"15219471780524079156861690098171693383497641272226737821992208834301871102152362116211452788300889697214391366996966539871625433480959011635688106136537800706217506402845296449689\"},\"r\":{\"1\":\"46043242109380749151527145850513330956077996622769158245225343392397735706292106535150958053995712629189143692293204979798837951212291825184346767969751978730000071952944305252032332015837054475531407691352179423131405515518588355918925056889302269768343499864256747177988825578647189563088068257214198650437730618330249172716051559993880468542083352885474175039320848153156858562341041960950299312991459780503345784440261679263045723337629951517601461685539857683027034345542399365706329805317943096391758978877658949910614447086409173234155028671453929715706057153381022697673192590033507204548864311227048268516889390503318015295207078022755834130221198717787608473222789491216667698651180077661375273569115943192\",\"0\":\"135472587547410377947826119498467634347118057359097899596599164976338466445104141784869016998150489852448547539824768048351359572626675997498079394825940306636285481821620973655797996638210760710325933304918452142858879806106214845499670718704532018129553348815327362843246706518826311676917538452317818631484884032929252959289913274829848084561421467966320595980172006456003183536232790787521924655750157145207798486087511869939940023266736153366338179116840490184005332351004990854691988404031259910319601383696749511809898297656135548118786342107367065232798999979296280467063561892962526945512167505847049907450058650930480352253243357594344686769208712964458923557777584158831146374282687397585726706489164423632\",\"DELTA\":\"93540839493959971552865423901789226093328763011922445919928571946113703515842729132879472109395228387208764738970926484618949870591214627692618668077375153559192701474693025462226656116549337248146652482501255820930607033869432220667968682424554711616471973627651716863421554516577716366331699848682958681216261888139409101603059124344125075525791543312721162515584942523419876134808829569829529457617639955678189490257208141837196965948342373022812790844435050648360150869293836349223060722858500537182872294143846213258360218898475766641125493477502149553491502593654061863323857297998048614447925371606038801933864960337435890254277043261512846682042139570000962051463878026338583242360548041329046695667868842400\",\"3\":\"1227675452527605924725300993571504188580051470857656204064614533296779844072852823820754766175236321050062349182891221840452517985644028521499240739391613871973822807731772613052644168369405390658793869751915172749739844553410726807277698347769400977274750672880389943392076308065414059539317340070691852044062594715307024113666759844200606183662256825096857658837519571386467051003466014468855293015652584667669998830524947537781865745830650392641812221679438090257444660715937570193098993118585554478799821072396238689063767016402460690760792908977364175126682041704095200572282644311025594681667826054722587271200221036938804846621444065128275082392082327596239358623150786484106872933657139420542280145197712634108\",\"2\":\"596248147592834822582469335300585333722415132713749620075902332764163096347819006925876158892694742461036531935093982309708492066217459300117157420442081698140277277546563570823996272914068575482008392971932777453900260626542725308060927710122631763045025742980634216666560934260634907599194353151523256914796667535940073668465664206971169038864484235442207811974981191879443614478897291543702607764944403808380921189291059195014621592027660463072969363556421687131446107696579365265893962197300447027501604372738056016734644378437907931412654753728514905671605635291285742886484416973884856055084605172305967034292646171874483670469193852404511746786039743401185954843446037600121496137915619789351744485264614840070\"},\"mj\":\"1117601261519431120446925325460734824239475567013636538481947258329666056692767097795046086413732472111811628751812987521644198549167671875326968410921589186689138994171774838662\",\"alpha\":\"76727612740067576380015106087224381023260815407331375101920043509817863645705120013304683427627332447210083684516403565749916480947649443674885388155460323163682547865307733144184097845709556309570345707127872162476432029772452433292049079349274445907295491125915363620615679995457134810061392296263970553630102299601689685622244925494554558218277670233361938142224820526392365740420502452466959099546877778248089664282581792213376636587293479012783947088070052463503335266180110771978445892744225891676396288437005847308189508347446490710626231658457908472341606549292437553353163031111068977301305043175839949352742711874426231072729977019365761072816602400121302646283352164756787266537474728685656685493249314400351742964904006326192403855909148605656818024621453179832395687665671245528217931951331393482249182516107670379946496778373\",\"t\":{\"1\":\"37203689290881948278188715497642400459048942241931994079434400288578680362970117779048886269388440270597283202033458042171954610700745461571112086648991639439510380585728148682202768590972068041537531136529323260832899360551065706810590032715173070285762675403853992183366951113799098912676809373169763887110420539387555392787590966452796271491986622992160642135480293110112269570862265489120557014181468118619500321000966443141863893743211690388599242584469856365803370202569641902205925191670838354052104480074127555862332399641076324738839120815544432811566503174551735326387678621283249883091766325861497740614317\",\"3\":\"58486787977689017034592833190899828017343431922483563651969628402499947729293364026001243898136737211851089198526360764391403150763769829047179796728616126204105160762333590343947446892105646111520243793053992399512412375936746396187319527051818920531870855183738837254656664620975569939859368862778444291640228229744805843388153451336792379036403300211151424879060241580540910888241769468335914016289938374111481091198264912969768783884602931940994543804730631920434719776196148182987249363641941951160704928605829395517074202388967815738516252602903999010405305463910751219873354588685197134114358234107748126140977\",\"0\":\"60771874648036182010335841594233428920565254732600738082343398028553347795361460295011584446745121430144172025428394361648540904134739046923992231536160801306934272250969829886396340824213814702904457884984387666505055153957942221822193548673145705543973635530652570436109428474727638128773540793530691399549837156239786231362112148914687724325416768262058486101761972044802628459748878200584371058300150212485731451700436345975266860685549673168984700174294811561393162860595319582236734968601457003780816977537443267217411297266600994916897237305128142313335280264655603445636393371224354539882875937093696844430903\",\"DELTA\":\"32816484171372208266594641116109072545171919234551585018140151846920408763078147655907777031259225522515086979967895258126318315788662577171150780535509410112003001556402222994276811926864642497249250763185467678044678144507739529818566125668667424447792097244624010084189629269472698722402896445274092470014229247479740671263651727480322483037149584904549203417226525624083290572692241241259382947122018271686649224741832992966652878170311798126004447080305528487720923103595513611363001766063956060990267107048028416069435287244770875463867263571308182619338433913487209319707428378896314619624990311543563016697299\",\"2\":\"36428320569485697540634597755814766104888687488985202673924762266313135133244610404742081973550848160712054769198012193456278135847215508952327879544434490828380496286187725750283788811367824465072001959950807751252194618152990469069074061195618692339915840384087350671392595652921761835083158086795163935060896053332506433434451836095710383871272788002621913967538399141417857031787255744141437237474972197102809365346359345477248611632307159641948507043668113827177494748159094045928919209335044052792843664865311991178972383241855607627188111601119780878072683890170539599447876998109080150992209773901144245398001\"},\"predicate\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}]},\"non_revoc_proof\":null},\"schema_seq_no\":1,\"revoc_reg_seq_no\":null,\"issuer_did\":\"did\"}},\"aggregated_proof\":{\"c_hash\":\"33103550379681684069592829341967479618752165928802550870585275205292715916069\",\"c_list\":[[1,121,77,5,144,154,14,192,190,190,145,180,128,71,22,60,168,20,46,163,139,194,71,165,220,188,121,76,25,146,231,114,65,54,69,68,19,200,250,192,47,123,157,132,74,50,28,69,226,195,243,118,45,63,237,197,216,202,206,101,33,56,225,200,128,3,89,12,182,38,113,221,165,119,228,201,156,201,172,136,59,64,51,72,164,198,49,228,223,117,80,64,166,226,37,8,29,146,186,80,210,119,76,252,4,255,62,218,112,163,164,147,247,190,108,76,140,191,76,217,214,184,152,179,193,149,15,70,197,46,90,60,255,247,197,219,252,73,76,0,125,104,114,22,182,161,110,36,162,103,27,42,88,18,161,237,198,43,177,189,181,86,135,207,71,114,0,26,175,12,199,125,25,124,178,87,36,208,251,15,191,127,202,148,152,43,142,92,191,7,89,153,130,195,223,248,176,109,97,164,126,162,181,124,237,130,155,197,66,59,40,197,72,84,32,100,64,55,227,60,214,143,200,200,89,115,236,172,145,56,100,73,20,242,233,95,130,58,112,153,120,115,119,42,199,30,205,88,223,42,196,184,41,19,100,19,244],[1,225,103,238,42,147,91,191,110,69,154,53,57,156,124,43,174,155,76,202,193,98,128,38,207,126,66,70,161,96,109,127,174,44,203,198,177,238,118,117,89,227,170,155,44,251,35,119,219,29,100,173,26,144,95,50,177,4,40,234,117,174,210,192,172,57,160,198,42,199,212,243,240,114,59,91,207,68,57,38,198,2,73,18,16,209,182,145,206,71,17,69,222,49,36,120,72,117,169,107,238,208,235,216,24,183,201,81,15,83,242,45,136,184,166,26,142,136,228,58,229,235,88,169,238,134,205,96,85,9,122,53,147,100,183,114,92,54,125,178,125,75,127,116,50,88,109,152,22,4,121,252,190,18,190,130,143,138,59,231,38,131,176,54,19,194,218,67,144,122,91,43,86,73,233,48,193,30,183,183,191,238,216,167,101,28,185,43,118,64,242,16,62,239,177,27,109,144,67,221,175,202,4,92,130,74,24,20,151,15,227,225,142,71,145,46,192,248,87,57,183,142,253,52,20,56,153,220,234,25,67,116,225,179,211,116,161,37,64,34,48,155,1,1,159,157,37,31,202,19,229,152,23,138,183,126,55],[1,38,181,193,191,72,2,239,34,83,49,36,179,160,82,112,172,98,255,63,60,22,177,249,67,215,220,198,181,7,49,254,133,243,221,214,47,64,229,82,11,94,175,57,86,152,229,192,184,96,136,116,226,123,128,217,23,244,19,204,36,44,123,208,88,24,217,120,145,139,25,233,227,5,119,90,47,147,1,115,92,39,119,194,167,17,229,39,163,167,237,14,116,234,106,252,216,54,33,233,21,54,183,130,144,161,177,142,177,240,51,73,21,202,188,103,244,153,204,219,123,231,139,135,189,155,143,28,4,180,44,148,0,27,103,26,13,203,31,32,166,67,84,87,23,72,234,236,20,1,84,70,86,76,192,164,235,124,86,128,78,230,119,155,95,121,125,20,244,181,121,250,169,9,67,85,213,177,139,111,187,183,114,165,249,177,161,181,175,46,226,66,86,84,124,86,69,143,217,158,161,30,107,133,44,239,89,209,24,150,1,238,122,144,138,179,121,114,90,13,212,209,60,126,37,62,177,180,131,222,168,2,201,156,169,220,224,53,8,203,220,215,163,104,195,184,73,35,241,182,177,80,41,253,230,90,173],[1,32,145,96,219,241,190,19,195,129,219,50,148,152,107,12,189,225,103,171,149,252,193,243,136,132,195,44,19,20,247,140,160,91,230,78,31,242,85,213,65,185,1,91,12,69,118,80,26,135,102,131,4,108,130,230,83,91,176,249,196,56,128,127,82,72,106,49,211,94,133,40,86,72,42,187,199,216,191,223,208,206,121,118,15,167,255,228,57,206,158,217,64,205,212,178,8,248,129,183,221,98,70,54,37,55,47,81,120,59,186,238,165,0,70,173,137,193,232,180,125,211,237,182,249,191,173,107,129,164,148,231,116,225,66,66,71,156,39,248,164,253,234,140,205,177,140,117,47,21,15,242,31,113,118,91,143,89,213,86,143,135,21,46,35,199,214,107,111,65,65,19,26,171,130,16,19,102,145,210,210,61,51,169,148,169,118,182,106,107,253,100,214,232,52,103,180,96,249,254,71,6,11,119,48,129,213,223,205,93,20,117,26,187,32,151,212,137,203,17,237,208,150,72,23,225,235,122,188,34,105,115,0,160,168,251,191,22,242,238,207,74,142,154,66,94,149,191,215,194,134,6,165,244,167,233,241],[1,207,77,250,146,127,242,229,44,172,182,201,183,242,32,242,182,129,233,10,8,180,23,191,163,21,238,158,5,27,216,146,253,173,127,99,95,168,209,132,242,196,242,34,25,25,249,211,51,236,164,153,175,61,65,150,82,251,174,102,186,47,195,82,44,90,252,184,74,89,251,177,254,108,151,136,230,220,93,224,173,247,244,116,132,59,170,215,194,30,87,84,166,147,57,156,201,207,132,203,222,191,253,15,19,228,173,81,156,4,51,121,227,159,50,18,148,129,205,42,42,227,252,138,62,176,115,227,253,52,125,110,178,167,132,244,14,116,195,194,172,44,45,63,38,121,215,136,68,230,21,108,133,159,197,179,94,78,233,107,236,114,92,165,248,22,124,161,23,142,236,224,175,233,134,25,97,150,131,61,220,203,104,154,199,247,146,47,205,56,209,0,133,132,18,103,136,8,202,37,29,100,105,12,232,74,33,6,255,202,96,170,52,229,244,4,235,2,201,125,86,168,179,224,130,81,54,221,185,184,187,141,0,114,98,38,70,225,228,60,157,53,210,238,60,216,215,154,48,73,3,157,192,245,81,170,49],[1,3,244,229,158,71,18,146,198,202,27,2,231,37,13,145,243,84,112,220,61,174,4,175,104,200,64,146,193,20,174,126,42,157,168,76,165,21,50,216,82,211,180,73,244,54,227,200,19,157,25,228,81,37,64,201,19,138,175,50,246,169,11,45,74,194,131,236,127,177,41,242,130,55,112,182,98,22,99,48,153,83,161,250,65,89,3,97,6,5,171,54,223,87,98,103,23,200,212,177,140,155,151,252,125,45,176,55,92,41,56,2,252,32,149,60,3,168,209,193,23,168,230,182,72,193,230,224,5,15,58,63,93,196,33,93,76,188,30,70,31,136,64,204,223,2,230,210,243,255,135,193,52,132,248,160,22,18,164,71,77,80,112,229,120,116,210,225,2,19,139,35,0,214,5,246,9,106,136,204,0,148,97,21,222,153,57,177,162,11,243,252,7,242,34,239,245,50,104,74,221,92,73,13,142,10,184,250,246,167,240,46,230,86,207,181,12,133,81,119,143,164,88,114,223,243,179,208,175,84,161,27,11,225,36,37,177,112,85,81,184,163,223,159,36,9,247,20,13,230,215,108,117,35,99,117,211]]}," + + "\"requested_proof\":{\"revealed_attrs\":{\"attr1_uuid\":[\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\",\"Alex\",\"1139481716457488690172217916278103335\"]},\"unrevealed_attrs\":{},\"self_attested_attrs\":{},\"predicates\":{\"predicate1_uuid\":\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\"}}}"; + + Anoncreds.verifierVerifyProof(proofRequest, proofJson, schemasJson, claimDefsJson, revocRegsJson).get(); + } + + @Test + public void testVerifierVerifyProofWorksForWrongProof() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String proofJson = "{\"proofs\":{\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\":{\"proof\":{\"primary_proof\":{\"eq_proof\":\"a_prime\":\"47629821806628155353444789773246165920681315271529392722265555946090524267165563309836167110610840740533588118152308411732923636370660640410661034994521654033599863817144282118006097899736622728860229305231675970853294584911572355833537271010861501353858292189045263114095480601737776505186511389129055847562085611741257601964074827979121349153316235245772819207422031038042586202074331681302501661153569340935741290924699468188826629478130140797677338573924284871118002193526319478550852287453975107498037063076866410320160118555629090040954555043934303307652160345244864713226315470541231435958298648179413077988340\",\"e\":\"13427639393364185909415877973872458621259927563729922146828001652769380799419438410309469022979920689628523901764614163117469683925816443\",\"v\":\"852136445143816932026946294488424887907102968158908948827421962603492187508454543239422067899916472317305416590471170842186669606584356963437132366711335927890209765986844538775191207999204354235774464468525274918097404114453069375363594310105209141774763909570100638835926337238009617444858777301355087706167735590386774813901740600054753028260344014744801229032610106838480523182317262113911183640784111960909501662169298536941919854667754097841344375972975021196106884215734228415868248724905018661498061287694439466570946597514142085096419985189064172035527690786158872698717583830848410994616274586162550376126607414773916066374234063208380831144157533076866210628625236440222547584539349936639548061601416341705483504386186280800509889531835172071717956251546280392606775903107774727736794828168898273891724336881907672405328368540895104468091907771325910937575557566831844131159128453840354307814975621978196047820\",\"m\":{\"age\":\"1117601261519431120446925325460734824239475567013636538481947258329666056692767097795046086413732472111811628751812987521644198549167671875326968410921589186689138994171774838662\",\"height\":\"7064132689652704067914104576495132313294680087958177180391515757079548676035445873279966783996928425154050462229933823707574545166617858646442019030600136959459527533262821184869\",\"sex\":\"16084497853957041205729191269508720470626311156190485518484640641677445098603656354458362520541393995692536218820724164533958162674375198846036330444513484319280148335515891811530\"},\"m1\":\"154906224259819061652290487122980839849626068919893070220438585977323162319993111920906032317552959103520053742608858935542877608981244065301675821390065831113115709272412144796159984624494428122971995557415296140268002332169405587907128359886810433617416529821500995701094400375272097687818064435577784795275\",\"m2\":\"13805395408072590464827983892588030341708765524663545700917462089376137940485022437657208204460048097312372685954050370540389593952001973312378647790917367330461398089529292217752\"},\"ge_proofs\":[{\"u\":{\"1\":\"7698818972783845439601187851976452936638792889455287252542709653271706844173743185409084669157965935169942655008606334521674712818637940377261656468700786810566551698412412949418\",\"0\":\"11703047052430512223413711314521545616119146623040600935686474696241801697819280425232876917607198335376453682738553665221410353412906194951254558355994401995990233992518110582450\",\"3\":\"13210777821918317858818819091924507295018522783042111457450035423463340571245465760486275059291363621513532153389441883097799049597687545496359999443320001567152794884095192951040\",\"2\":\"15219471780524079156861690098171693383497641272226737821992208834301871102152362116211452788300889697214391366996966539871625433480959011635688106136537800706217506402845296449689\"},\"r\":{\"1\":\"46043242109380749151527145850513330956077996622769158245225343392397735706292106535150958053995712629189143692293204979798837951212291825184346767969751978730000071952944305252032332015837054475531407691352179423131405515518588355918925056889302269768343499864256747177988825578647189563088068257214198650437730618330249172716051559993880468542083352885474175039320848153156858562341041960950299312991459780503345784440261679263045723337629951517601461685539857683027034345542399365706329805317943096391758978877658949910614447086409173234155028671453929715706057153381022697673192590033507204548864311227048268516889390503318015295207078022755834130221198717787608473222789491216667698651180077661375273569115943192\",\"0\":\"135472587547410377947826119498467634347118057359097899596599164976338466445104141784869016998150489852448547539824768048351359572626675997498079394825940306636285481821620973655797996638210760710325933304918452142858879806106214845499670718704532018129553348815327362843246706518826311676917538452317818631484884032929252959289913274829848084561421467966320595980172006456003183536232790787521924655750157145207798486087511869939940023266736153366338179116840490184005332351004990854691988404031259910319601383696749511809898297656135548118786342107367065232798999979296280467063561892962526945512167505847049907450058650930480352253243357594344686769208712964458923557777584158831146374282687397585726706489164423632\",\"DELTA\":\"93540839493959971552865423901789226093328763011922445919928571946113703515842729132879472109395228387208764738970926484618949870591214627692618668077375153559192701474693025462226656116549337248146652482501255820930607033869432220667968682424554711616471973627651716863421554516577716366331699848682958681216261888139409101603059124344125075525791543312721162515584942523419876134808829569829529457617639955678189490257208141837196965948342373022812790844435050648360150869293836349223060722858500537182872294143846213258360218898475766641125493477502149553491502593654061863323857297998048614447925371606038801933864960337435890254277043261512846682042139570000962051463878026338583242360548041329046695667868842400\",\"3\":\"1227675452527605924725300993571504188580051470857656204064614533296779844072852823820754766175236321050062349182891221840452517985644028521499240739391613871973822807731772613052644168369405390658793869751915172749739844553410726807277698347769400977274750672880389943392076308065414059539317340070691852044062594715307024113666759844200606183662256825096857658837519571386467051003466014468855293015652584667669998830524947537781865745830650392641812221679438090257444660715937570193098993118585554478799821072396238689063767016402460690760792908977364175126682041704095200572282644311025594681667826054722587271200221036938804846621444065128275082392082327596239358623150786484106872933657139420542280145197712634108\",\"2\":\"596248147592834822582469335300585333722415132713749620075902332764163096347819006925876158892694742461036531935093982309708492066217459300117157420442081698140277277546563570823996272914068575482008392971932777453900260626542725308060927710122631763045025742980634216666560934260634907599194353151523256914796667535940073668465664206971169038864484235442207811974981191879443614478897291543702607764944403808380921189291059195014621592027660463072969363556421687131446107696579365265893962197300447027501604372738056016734644378437907931412654753728514905671605635291285742886484416973884856055084605172305967034292646171874483670469193852404511746786039743401185954843446037600121496137915619789351744485264614840070\"},\"mj\":\"1117601261519431120446925325460734824239475567013636538481947258329666056692767097795046086413732472111811628751812987521644198549167671875326968410921589186689138994171774838662\",\"alpha\":\"76727612740067576380015106087224381023260815407331375101920043509817863645705120013304683427627332447210083684516403565749916480947649443674885388155460323163682547865307733144184097845709556309570345707127872162476432029772452433292049079349274445907295491125915363620615679995457134810061392296263970553630102299601689685622244925494554558218277670233361938142224820526392365740420502452466959099546877778248089664282581792213376636587293479012783947088070052463503335266180110771978445892744225891676396288437005847308189508347446490710626231658457908472341606549292437553353163031111068977301305043175839949352742711874426231072729977019365761072816602400121302646283352164756787266537474728685656685493249314400351742964904006326192403855909148605656818024621453179832395687665671245528217931951331393482249182516107670379946496778373\",\"t\":{\"1\":\"37203689290881948278188715497642400459048942241931994079434400288578680362970117779048886269388440270597283202033458042171954610700745461571112086648991639439510380585728148682202768590972068041537531136529323260832899360551065706810590032715173070285762675403853992183366951113799098912676809373169763887110420539387555392787590966452796271491986622992160642135480293110112269570862265489120557014181468118619500321000966443141863893743211690388599242584469856365803370202569641902205925191670838354052104480074127555862332399641076324738839120815544432811566503174551735326387678621283249883091766325861497740614317\",\"3\":\"58486787977689017034592833190899828017343431922483563651969628402499947729293364026001243898136737211851089198526360764391403150763769829047179796728616126204105160762333590343947446892105646111520243793053992399512412375936746396187319527051818920531870855183738837254656664620975569939859368862778444291640228229744805843388153451336792379036403300211151424879060241580540910888241769468335914016289938374111481091198264912969768783884602931940994543804730631920434719776196148182987249363641941951160704928605829395517074202388967815738516252602903999010405305463910751219873354588685197134114358234107748126140977\",\"0\":\"60771874648036182010335841594233428920565254732600738082343398028553347795361460295011584446745121430144172025428394361648540904134739046923992231536160801306934272250969829886396340824213814702904457884984387666505055153957942221822193548673145705543973635530652570436109428474727638128773540793530691399549837156239786231362112148914687724325416768262058486101761972044802628459748878200584371058300150212485731451700436345975266860685549673168984700174294811561393162860595319582236734968601457003780816977537443267217411297266600994916897237305128142313335280264655603445636393371224354539882875937093696844430903\",\"DELTA\":\"32816484171372208266594641116109072545171919234551585018140151846920408763078147655907777031259225522515086979967895258126318315788662577171150780535509410112003001556402222994276811926864642497249250763185467678044678144507739529818566125668667424447792097244624010084189629269472698722402896445274092470014229247479740671263651727480322483037149584904549203417226525624083290572692241241259382947122018271686649224741832992966652878170311798126004447080305528487720923103595513611363001766063956060990267107048028416069435287244770875463867263571308182619338433913487209319707428378896314619624990311543563016697299\",\"2\":\"36428320569485697540634597755814766104888687488985202673924762266313135133244610404742081973550848160712054769198012193456278135847215508952327879544434490828380496286187725750283788811367824465072001959950807751252194618152990469069074061195618692339915840384087350671392595652921761835083158086795163935060896053332506433434451836095710383871272788002621913967538399141417857031787255744141437237474972197102809365346359345477248611632307159641948507043668113827177494748159094045928919209335044052792843664865311991178972383241855607627188111601119780878072683890170539599447876998109080150992209773901144245398001\"},\"predicate\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}]},\"non_revoc_proof\":null},\"issuer_did\":\"NcYxiDXkpYi6ov5FcYDi1e\",\"revoc_reg_seq_no\":null}},\"aggregated_proof\":{\"c_hash\":\"33103550379681684069592829341967479618752165928802550870585275205292715916069\",\"c_list\":[[1,121,77,5,144,154,14,192,190,190,145,180,128,71,22,60,168,20,46,163,139,194,71,165,220,188,121,76,25,146,231,114,65,54,69,68,19,200,250,192,47,123,157,132,74,50,28,69,226,195,243,118,45,63,237,197,216,202,206,101,33,56,225,200,128,3,89,12,182,38,113,221,165,119,228,201,156,201,172,136,59,64,51,72,164,198,49,228,223,117,80,64,166,226,37,8,29,146,186,80,210,119,76,252,4,255,62,218,112,163,164,147,247,190,108,76,140,191,76,217,214,184,152,179,193,149,15,70,197,46,90,60,255,247,197,219,252,73,76,0,125,104,114,22,182,161,110,36,162,103,27,42,88,18,161,237,198,43,177,189,181,86,135,207,71,114,0,26,175,12,199,125,25,124,178,87,36,208,251,15,191,127,202,148,152,43,142,92,191,7,89,153,130,195,223,248,176,109,97,164,126,162,181,124,237,130,155,197,66,59,40,197,72,84,32,100,64,55,227,60,214,143,200,200,89,115,236,172,145,56,100,73,20,242,233,95,130,58,112,153,120,115,119,42,199,30,205,88,223,42,196,184,41,19,100,19,244],[1,225,103,238,42,147,91,191,110,69,154,53,57,156,124,43,174,155,76,202,193,98,128,38,207,126,66,70,161,96,109,127,174,44,203,198,177,238,118,117,89,227,170,155,44,251,35,119,219,29,100,173,26,144,95,50,177,4,40,234,117,174,210,192,172,57,160,198,42,199,212,243,240,114,59,91,207,68,57,38,198,2,73,18,16,209,182,145,206,71,17,69,222,49,36,120,72,117,169,107,238,208,235,216,24,183,201,81,15,83,242,45,136,184,166,26,142,136,228,58,229,235,88,169,238,134,205,96,85,9,122,53,147,100,183,114,92,54,125,178,125,75,127,116,50,88,109,152,22,4,121,252,190,18,190,130,143,138,59,231,38,131,176,54,19,194,218,67,144,122,91,43,86,73,233,48,193,30,183,183,191,238,216,167,101,28,185,43,118,64,242,16,62,239,177,27,109,144,67,221,175,202,4,92,130,74,24,20,151,15,227,225,142,71,145,46,192,248,87,57,183,142,253,52,20,56,153,220,234,25,67,116,225,179,211,116,161,37,64,34,48,155,1,1,159,157,37,31,202,19,229,152,23,138,183,126,55],[1,38,181,193,191,72,2,239,34,83,49,36,179,160,82,112,172,98,255,63,60,22,177,249,67,215,220,198,181,7,49,254,133,243,221,214,47,64,229,82,11,94,175,57,86,152,229,192,184,96,136,116,226,123,128,217,23,244,19,204,36,44,123,208,88,24,217,120,145,139,25,233,227,5,119,90,47,147,1,115,92,39,119,194,167,17,229,39,163,167,237,14,116,234,106,252,216,54,33,233,21,54,183,130,144,161,177,142,177,240,51,73,21,202,188,103,244,153,204,219,123,231,139,135,189,155,143,28,4,180,44,148,0,27,103,26,13,203,31,32,166,67,84,87,23,72,234,236,20,1,84,70,86,76,192,164,235,124,86,128,78,230,119,155,95,121,125,20,244,181,121,250,169,9,67,85,213,177,139,111,187,183,114,165,249,177,161,181,175,46,226,66,86,84,124,86,69,143,217,158,161,30,107,133,44,239,89,209,24,150,1,238,122,144,138,179,121,114,90,13,212,209,60,126,37,62,177,180,131,222,168,2,201,156,169,220,224,53,8,203,220,215,163,104,195,184,73,35,241,182,177,80,41,253,230,90,173],[1,32,145,96,219,241,190,19,195,129,219,50,148,152,107,12,189,225,103,171,149,252,193,243,136,132,195,44,19,20,247,140,160,91,230,78,31,242,85,213,65,185,1,91,12,69,118,80,26,135,102,131,4,108,130,230,83,91,176,249,196,56,128,127,82,72,106,49,211,94,133,40,86,72,42,187,199,216,191,223,208,206,121,118,15,167,255,228,57,206,158,217,64,205,212,178,8,248,129,183,221,98,70,54,37,55,47,81,120,59,186,238,165,0,70,173,137,193,232,180,125,211,237,182,249,191,173,107,129,164,148,231,116,225,66,66,71,156,39,248,164,253,234,140,205,177,140,117,47,21,15,242,31,113,118,91,143,89,213,86,143,135,21,46,35,199,214,107,111,65,65,19,26,171,130,16,19,102,145,210,210,61,51,169,148,169,118,182,106,107,253,100,214,232,52,103,180,96,249,254,71,6,11,119,48,129,213,223,205,93,20,117,26,187,32,151,212,137,203,17,237,208,150,72,23,225,235,122,188,34,105,115,0,160,168,251,191,22,242,238,207,74,142,154,66,94,149,191,215,194,134,6,165,244,167,233,241],[1,207,77,250,146,127,242,229,44,172,182,201,183,242,32,242,182,129,233,10,8,180,23,191,163,21,238,158,5,27,216,146,253,173,127,99,95,168,209,132,242,196,242,34,25,25,249,211,51,236,164,153,175,61,65,150,82,251,174,102,186,47,195,82,44,90,252,184,74,89,251,177,254,108,151,136,230,220,93,224,173,247,244,116,132,59,170,215,194,30,87,84,166,147,57,156,201,207,132,203,222,191,253,15,19,228,173,81,156,4,51,121,227,159,50,18,148,129,205,42,42,227,252,138,62,176,115,227,253,52,125,110,178,167,132,244,14,116,195,194,172,44,45,63,38,121,215,136,68,230,21,108,133,159,197,179,94,78,233,107,236,114,92,165,248,22,124,161,23,142,236,224,175,233,134,25,97,150,131,61,220,203,104,154,199,247,146,47,205,56,209,0,133,132,18,103,136,8,202,37,29,100,105,12,232,74,33,6,255,202,96,170,52,229,244,4,235,2,201,125,86,168,179,224,130,81,54,221,185,184,187,141,0,114,98,38,70,225,228,60,157,53,210,238,60,216,215,154,48,73,3,157,192,245,81,170,49],[1,3,244,229,158,71,18,146,198,202,27,2,231,37,13,145,243,84,112,220,61,174,4,175,104,200,64,146,193,20,174,126,42,157,168,76,165,21,50,216,82,211,180,73,244,54,227,200,19,157,25,228,81,37,64,201,19,138,175,50,246,169,11,45,74,194,131,236,127,177,41,242,130,55,112,182,98,22,99,48,153,83,161,250,65,89,3,97,6,5,171,54,223,87,98,103,23,200,212,177,140,155,151,252,125,45,176,55,92,41,56,2,252,32,149,60,3,168,209,193,23,168,230,182,72,193,230,224,5,15,58,63,93,196,33,93,76,188,30,70,31,136,64,204,223,2,230,210,243,255,135,193,52,132,248,160,22,18,164,71,77,80,112,229,120,116,210,225,2,19,139,35,0,214,5,246,9,106,136,204,0,148,97,21,222,153,57,177,162,11,243,252,7,242,34,239,245,50,104,74,221,92,73,13,142,10,184,250,246,167,240,46,230,86,207,181,12,133,81,119,143,164,88,114,223,243,179,208,175,84,161,27,11,225,36,37,177,112,85,81,184,163,223,159,36,9,247,20,13,230,215,108,117,35,99,117,211]]},\"requested_proof\":{\"revealed_attrs\":{\"attr1_uuid\":[\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\",\"Alex\",\"1139481716457488690172217916278103335\"]},\"unrevealed_attrs\":{},\"self_attested_attrs\":{},\"predicates\":{\"predicate1_uuid\":\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\"}}}"; + + Boolean valid = Anoncreds.verifierVerifyProof(proofRequest, proofJson, schemasJson, claimDefsJson, revocRegsJson).get(); + assertFalse(valid); + } + + @Test + public void testVerifierVerifyProofWorksForInvalidProofJson() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String proofJson = "{\"proofs\":{\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\":{\"proof\":{\"primary_proof\":{\"eq_proof\":\"a_prime\":\"47629821806628155353444789773246165920681315271529392722265555946090524267165563309836167110610840740533588118152308411732923636370660640410661034994521654033599863817144282118006097899736622728860229305231675970853294584911572355833537271010861501353858292189045263114095480601737776505186511389129055847562085611741257601964074827979121349153316235245772819207422031038042586202074331681302501661153569340935741290924699468188826629478130140797677338573924284871118002193526319478550852287453975107498037063076866410320160118555629090040954555043934303307652160345244864713226315470541231435958298648179413077988340\",\"e\":\"13427639393364185909415877973872458621259927563729922146828001652769380799419438410309469022979920689628523901764614163117469683925816443\",\"v\":\"852136445143816932026946294488424887907102968158908948827421962603492187508454543239422067899916472317305416590471170842186669606584356963437132366711335927890209765986844538775191207999204354235774464468525274918097404114453069375363594310105209141774763909570100638835926337238009617444858777301355087706167735590386774813901740600054753028260344014744801229032610106838480523182317262113911183640784111960909501662169298536941919854667754097841344375972975021196106884215734228415868248724905018661498061287694439466570946597514142085096419985189064172035527690786158872698717583830848410994616274586162550376126607414773916066374234063208380831144157533076866210628625236440222547584539349936639548061601416341705483504386186280800509889531835172071717956251546280392606775903107774727736794828168898273891724336881907672405328368540895104468091907771325910937575557566831844131159128453840354307814975621978196047820\",\"m\":{\"age\":\"1117601261519431120446925325460734824239475567013636538481947258329666056692767097795046086413732472111811628751812987521644198549167671875326968410921589186689138994171774838662\",\"height\":\"7064132689652704067914104576495132313294680087958177180391515757079548676035445873279966783996928425154050462229933823707574545166617858646442019030600136959459527533262821184869\",\"sex\":\"16084497853957041205729191269508720470626311156190485518484640641677445098603656354458362520541393995692536218820724164533958162674375198846036330444513484319280148335515891811530\"},\"m1\":\"154906224259819061652290487122980839849626068919893070220438585977323162319993111920906032317552959103520053742608858935542877608981244065301675821390065831113115709272412144796159984624494428122971995557415296140268002332169405587907128359886810433617416529821500995701094400375272097687818064435577784795275\",\"m2\":\"13805395408072590464827983892588030341708765524663545700917462089376137940485022437657208204460048097312372685954050370540389593952001973312378647790917367330461398089529292217752\"},\"ge_proofs\":[{\"u\":{\"1\":\"7698818972783845439601187851976452936638792889455287252542709653271706844173743185409084669157965935169942655008606334521674712818637940377261656468700786810566551698412412949418\",\"0\":\"11703047052430512223413711314521545616119146623040600935686474696241801697819280425232876917607198335376453682738553665221410353412906194951254558355994401995990233992518110582450\",\"3\":\"13210777821918317858818819091924507295018522783042111457450035423463340571245465760486275059291363621513532153389441883097799049597687545496359999443320001567152794884095192951040\",\"2\":\"15219471780524079156861690098171693383497641272226737821992208834301871102152362116211452788300889697214391366996966539871625433480959011635688106136537800706217506402845296449689\"},\"r\":{\"1\":\"46043242109380749151527145850513330956077996622769158245225343392397735706292106535150958053995712629189143692293204979798837951212291825184346767969751978730000071952944305252032332015837054475531407691352179423131405515518588355918925056889302269768343499864256747177988825578647189563088068257214198650437730618330249172716051559993880468542083352885474175039320848153156858562341041960950299312991459780503345784440261679263045723337629951517601461685539857683027034345542399365706329805317943096391758978877658949910614447086409173234155028671453929715706057153381022697673192590033507204548864311227048268516889390503318015295207078022755834130221198717787608473222789491216667698651180077661375273569115943192\",\"0\":\"135472587547410377947826119498467634347118057359097899596599164976338466445104141784869016998150489852448547539824768048351359572626675997498079394825940306636285481821620973655797996638210760710325933304918452142858879806106214845499670718704532018129553348815327362843246706518826311676917538452317818631484884032929252959289913274829848084561421467966320595980172006456003183536232790787521924655750157145207798486087511869939940023266736153366338179116840490184005332351004990854691988404031259910319601383696749511809898297656135548118786342107367065232798999979296280467063561892962526945512167505847049907450058650930480352253243357594344686769208712964458923557777584158831146374282687397585726706489164423632\",\"DELTA\":\"93540839493959971552865423901789226093328763011922445919928571946113703515842729132879472109395228387208764738970926484618949870591214627692618668077375153559192701474693025462226656116549337248146652482501255820930607033869432220667968682424554711616471973627651716863421554516577716366331699848682958681216261888139409101603059124344125075525791543312721162515584942523419876134808829569829529457617639955678189490257208141837196965948342373022812790844435050648360150869293836349223060722858500537182872294143846213258360218898475766641125493477502149553491502593654061863323857297998048614447925371606038801933864960337435890254277043261512846682042139570000962051463878026338583242360548041329046695667868842400\",\"3\":\"1227675452527605924725300993571504188580051470857656204064614533296779844072852823820754766175236321050062349182891221840452517985644028521499240739391613871973822807731772613052644168369405390658793869751915172749739844553410726807277698347769400977274750672880389943392076308065414059539317340070691852044062594715307024113666759844200606183662256825096857658837519571386467051003466014468855293015652584667669998830524947537781865745830650392641812221679438090257444660715937570193098993118585554478799821072396238689063767016402460690760792908977364175126682041704095200572282644311025594681667826054722587271200221036938804846621444065128275082392082327596239358623150786484106872933657139420542280145197712634108\",\"2\":\"596248147592834822582469335300585333722415132713749620075902332764163096347819006925876158892694742461036531935093982309708492066217459300117157420442081698140277277546563570823996272914068575482008392971932777453900260626542725308060927710122631763045025742980634216666560934260634907599194353151523256914796667535940073668465664206971169038864484235442207811974981191879443614478897291543702607764944403808380921189291059195014621592027660463072969363556421687131446107696579365265893962197300447027501604372738056016734644378437907931412654753728514905671605635291285742886484416973884856055084605172305967034292646171874483670469193852404511746786039743401185954843446037600121496137915619789351744485264614840070\"},\"mj\":\"1117601261519431120446925325460734824239475567013636538481947258329666056692767097795046086413732472111811628751812987521644198549167671875326968410921589186689138994171774838662\",\"alpha\":\"76727612740067576380015106087224381023260815407331375101920043509817863645705120013304683427627332447210083684516403565749916480947649443674885388155460323163682547865307733144184097845709556309570345707127872162476432029772452433292049079349274445907295491125915363620615679995457134810061392296263970553630102299601689685622244925494554558218277670233361938142224820526392365740420502452466959099546877778248089664282581792213376636587293479012783947088070052463503335266180110771978445892744225891676396288437005847308189508347446490710626231658457908472341606549292437553353163031111068977301305043175839949352742711874426231072729977019365761072816602400121302646283352164756787266537474728685656685493249314400351742964904006326192403855909148605656818024621453179832395687665671245528217931951331393482249182516107670379946496778373\",\"t\":{\"1\":\"37203689290881948278188715497642400459048942241931994079434400288578680362970117779048886269388440270597283202033458042171954610700745461571112086648991639439510380585728148682202768590972068041537531136529323260832899360551065706810590032715173070285762675403853992183366951113799098912676809373169763887110420539387555392787590966452796271491986622992160642135480293110112269570862265489120557014181468118619500321000966443141863893743211690388599242584469856365803370202569641902205925191670838354052104480074127555862332399641076324738839120815544432811566503174551735326387678621283249883091766325861497740614317\",\"3\":\"58486787977689017034592833190899828017343431922483563651969628402499947729293364026001243898136737211851089198526360764391403150763769829047179796728616126204105160762333590343947446892105646111520243793053992399512412375936746396187319527051818920531870855183738837254656664620975569939859368862778444291640228229744805843388153451336792379036403300211151424879060241580540910888241769468335914016289938374111481091198264912969768783884602931940994543804730631920434719776196148182987249363641941951160704928605829395517074202388967815738516252602903999010405305463910751219873354588685197134114358234107748126140977\",\"0\":\"60771874648036182010335841594233428920565254732600738082343398028553347795361460295011584446745121430144172025428394361648540904134739046923992231536160801306934272250969829886396340824213814702904457884984387666505055153957942221822193548673145705543973635530652570436109428474727638128773540793530691399549837156239786231362112148914687724325416768262058486101761972044802628459748878200584371058300150212485731451700436345975266860685549673168984700174294811561393162860595319582236734968601457003780816977537443267217411297266600994916897237305128142313335280264655603445636393371224354539882875937093696844430903\",\"DELTA\":\"32816484171372208266594641116109072545171919234551585018140151846920408763078147655907777031259225522515086979967895258126318315788662577171150780535509410112003001556402222994276811926864642497249250763185467678044678144507739529818566125668667424447792097244624010084189629269472698722402896445274092470014229247479740671263651727480322483037149584904549203417226525624083290572692241241259382947122018271686649224741832992966652878170311798126004447080305528487720923103595513611363001766063956060990267107048028416069435287244770875463867263571308182619338433913487209319707428378896314619624990311543563016697299\",\"2\":\"36428320569485697540634597755814766104888687488985202673924762266313135133244610404742081973550848160712054769198012193456278135847215508952327879544434490828380496286187725750283788811367824465072001959950807751252194618152990469069074061195618692339915840384087350671392595652921761835083158086795163935060896053332506433434451836095710383871272788002621913967538399141417857031787255744141437237474972197102809365346359345477248611632307159641948507043668113827177494748159094045928919209335044052792843664865311991178972383241855607627188111601119780878072683890170539599447876998109080150992209773901144245398001\"},\"predicate\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}]},\"non_revoc_proof\":null},\"issuer_did\":\"NcYxiDXkpYi6ov5FcYDi1e\",\"revoc_reg_seq_no\":null}},\"aggregated_proof\":{\"c_hash\":\"33103550379681684069592829341967479618752165928802550870585275205292715916069\",\"c_list\":[[1,121,77,5,144,154,14,192,190,190,145,180,128,71,22,60,168,20,46,163,139,194,71,165,220,188,121,76,25,146,231,114,65,54,69,68,19,200,250,192,47,123,157,132,74,50,28,69,226,195,243,118,45,63,237,197,216,202,206,101,33,56,225,200,128,3,89,12,182,38,113,221,165,119,228,201,156,201,172,136,59,64,51,72,164,198,49,228,223,117,80,64,166,226,37,8,29,146,186,80,210,119,76,252,4,255,62,218,112,163,164,147,247,190,108,76,140,191,76,217,214,184,152,179,193,149,15,70,197,46,90,60,255,247,197,219,252,73,76,0,125,104,114,22,182,161,110,36,162,103,27,42,88,18,161,237,198,43,177,189,181,86,135,207,71,114,0,26,175,12,199,125,25,124,178,87,36,208,251,15,191,127,202,148,152,43,142,92,191,7,89,153,130,195,223,248,176,109,97,164,126,162,181,124,237,130,155,197,66,59,40,197,72,84,32,100,64,55,227,60,214,143,200,200,89,115,236,172,145,56,100,73,20,242,233,95,130,58,112,153,120,115,119,42,199,30,205,88,223,42,196,184,41,19,100,19,244],[1,225,103,238,42,147,91,191,110,69,154,53,57,156,124,43,174,155,76,202,193,98,128,38,207,126,66,70,161,96,109,127,174,44,203,198,177,238,118,117,89,227,170,155,44,251,35,119,219,29,100,173,26,144,95,50,177,4,40,234,117,174,210,192,172,57,160,198,42,199,212,243,240,114,59,91,207,68,57,38,198,2,73,18,16,209,182,145,206,71,17,69,222,49,36,120,72,117,169,107,238,208,235,216,24,183,201,81,15,83,242,45,136,184,166,26,142,136,228,58,229,235,88,169,238,134,205,96,85,9,122,53,147,100,183,114,92,54,125,178,125,75,127,116,50,88,109,152,22,4,121,252,190,18,190,130,143,138,59,231,38,131,176,54,19,194,218,67,144,122,91,43,86,73,233,48,193,30,183,183,191,238,216,167,101,28,185,43,118,64,242,16,62,239,177,27,109,144,67,221,175,202,4,92,130,74,24,20,151,15,227,225,142,71,145,46,192,248,87,57,183,142,253,52,20,56,153,220,234,25,67,116,225,179,211,116,161,37,64,34,48,155,1,1,159,157,37,31,202,19,229,152,23,138,183,126,55],[1,38,181,193,191,72,2,239,34,83,49,36,179,160,82,112,172,98,255,63,60,22,177,249,67,215,220,198,181,7,49,254,133,243,221,214,47,64,229,82,11,94,175,57,86,152,229,192,184,96,136,116,226,123,128,217,23,244,19,204,36,44,123,208,88,24,217,120,145,139,25,233,227,5,119,90,47,147,1,115,92,39,119,194,167,17,229,39,163,167,237,14,116,234,106,252,216,54,33,233,21,54,183,130,144,161,177,142,177,240,51,73,21,202,188,103,244,153,204,219,123,231,139,135,189,155,143,28,4,180,44,148,0,27,103,26,13,203,31,32,166,67,84,87,23,72,234,236,20,1,84,70,86,76,192,164,235,124,86,128,78,230,119,155,95,121,125,20,244,181,121,250,169,9,67,85,213,177,139,111,187,183,114,165,249,177,161,181,175,46,226,66,86,84,124,86,69,143,217,158,161,30,107,133,44,239,89,209,24,150,1,238,122,144,138,179,121,114,90,13,212,209,60,126,37,62,177,180,131,222,168,2,201,156,169,220,224,53,8,203,220,215,163,104,195,184,73,35,241,182,177,80,41,253,230,90,173],[1,32,145,96,219,241,190,19,195,129,219,50,148,152,107,12,189,225,103,171,149,252,193,243,136,132,195,44,19,20,247,140,160,91,230,78,31,242,85,213,65,185,1,91,12,69,118,80,26,135,102,131,4,108,130,230,83,91,176,249,196,56,128,127,82,72,106,49,211,94,133,40,86,72,42,187,199,216,191,223,208,206,121,118,15,167,255,228,57,206,158,217,64,205,212,178,8,248,129,183,221,98,70,54,37,55,47,81,120,59,186,238,165,0,70,173,137,193,232,180,125,211,237,182,249,191,173,107,129,164,148,231,116,225,66,66,71,156,39,248,164,253,234,140,205,177,140,117,47,21,15,242,31,113,118,91,143,89,213,86,143,135,21,46,35,199,214,107,111,65,65,19,26,171,130,16,19,102,145,210,210,61,51,169,148,169,118,182,106,107,253,100,214,232,52,103,180,96,249,254,71,6,11,119,48,129,213,223,205,93,20,117,26,187,32,151,212,137,203,17,237,208,150,72,23,225,235,122,188,34,105,115,0,160,168,251,191,22,242,238,207,74,142,154,66,94,149,191,215,194,134,6,165,244,167,233,241],[1,207,77,250,146,127,242,229,44,172,182,201,183,242,32,242,182,129,233,10,8,180,23,191,163,21,238,158,5,27,216,146,253,173,127,99,95,168,209,132,242,196,242,34,25,25,249,211,51,236,164,153,175,61,65,150,82,251,174,102,186,47,195,82,44,90,252,184,74,89,251,177,254,108,151,136,230,220,93,224,173,247,244,116,132,59,170,215,194,30,87,84,166,147,57,156,201,207,132,203,222,191,253,15,19,228,173,81,156,4,51,121,227,159,50,18,148,129,205,42,42,227,252,138,62,176,115,227,253,52,125,110,178,167,132,244,14,116,195,194,172,44,45,63,38,121,215,136,68,230,21,108,133,159,197,179,94,78,233,107,236,114,92,165,248,22,124,161,23,142,236,224,175,233,134,25,97,150,131,61,220,203,104,154,199,247,146,47,205,56,209,0,133,132,18,103,136,8,202,37,29,100,105,12,232,74,33,6,255,202,96,170,52,229,244,4,235,2,201,125,86,168,179,224,130,81,54,221,185,184,187,141,0,114,98,38,70,225,228,60,157,53,210,238,60,216,215,154,48,73,3,157,192,245,81,170,49],[1,3,244,229,158,71,18,146,198,202,27,2,231,37,13,145,243,84,112,220,61,174,4,175,104,200,64,146,193,20,174,126,42,157,168,76,165,21,50,216,82,211,180,73,244,54,227,200,19,157,25,228,81,37,64,201,19,138,175,50,246,169,11,45,74,194,131,236,127,177,41,242,130,55,112,182,98,22,99,48,153,83,161,250,65,89,3,97,6,5,171,54,223,87,98,103,23,200,212,177,140,155,151,252,125,45,176,55,92,41,56,2,252,32,149,60,3,168,209,193,23,168,230,182,72,193,230,224,5,15,58,63,93,196,33,93,76,188,30,70,31,136,64,204,223,2,230,210,243,255,135,193,52,132,248,160,22,18,164,71,77,80,112,229,120,116,210,225,2,19,139,35,0,214,5,246,9,106,136,204,0,148,97,21,222,153,57,177,162,11,243,252,7,242,34,239,245,50,104,74,221,92,73,13,142,10,184,250,246,167,240,46,230,86,207,181,12,133,81,119,143,164,88,114,223,243,179,208,175,84,161,27,11,225,36,37,177,112,85,81,184,163,223,159,36,9,247,20,13,230,215,108,117,35,99,117,211]]},\"requested_proof\":{\"revealed_attrs\":{\"attr1_uuid\":[\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\",\"Alex\",\"1139481716457488690172217916278103335\"]},\"unrevealed_attrs\":{},\"self_attested_attrs\":{},\"predicates\":{\"predicate1_uuid\":\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\"}}}"; + + Anoncreds.verifierVerifyProof(proofRequest, proofJson, schemasJson, claimDefsJson, revocRegsJson).get(); + } +} From a42b0787fb4bc9a0ac6e960ec89655c140d453fa Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 18 Jul 2017 17:21:34 +0300 Subject: [PATCH 211/349] added test for build_nym_request --- wrappers/python/indy/libindy.py | 4 +-- .../tests/ledger/test_build_nym_request.py | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 wrappers/python/tests/ledger/test_build_nym_request.py diff --git a/wrappers/python/indy/libindy.py b/wrappers/python/indy/libindy.py index 394cccef10..78d5e161dc 100644 --- a/wrappers/python/indy/libindy.py +++ b/wrappers/python/indy/libindy.py @@ -29,7 +29,7 @@ def do_call(name: str, cb: CFUNCTYPE, *args): if err != ErrorCode.Success: logger.warning("_do_call: Function %s returned error %i", name, err) - future.set_exception(IndyError(err)) + future.set_exception(IndyError(ErrorCode(err))) logger.debug("do_call: <<< %s", future) return future @@ -63,7 +63,7 @@ def _indy_loop_callback(command_handle: int, err, *args): if err != ErrorCode.Success: logger.warning("_indy_loop_callback: Function returned error %i", err) - future.set_exception(IndyError(err)) + future.set_exception(IndyError(ErrorCode(err))) else: if len(args) == 0: res = None diff --git a/wrappers/python/tests/ledger/test_build_nym_request.py b/wrappers/python/tests/ledger/test_build_nym_request.py new file mode 100644 index 0000000000..2fd9d46064 --- /dev/null +++ b/wrappers/python/tests/ledger/test_build_nym_request.py @@ -0,0 +1,28 @@ +from tests.utils import storage +from indy import ledger +from indy.error import ErrorCode, IndyError + +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_build_nym_request_works_for_invalid_identifier(): + identifier = "invalid_base58_identifier" + dest = "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4" + + try: + await ledger.build_nym_request(identifier, dest, None, None, None) + raise Exception("Failed") + except Exception as e: + assert type(IndyError(ErrorCode.CommonInvalidStructure)) == type(e) and \ + IndyError(ErrorCode.CommonInvalidStructure).args == e.args From 2348afa9d3ea26e29c8a193e5d2969c10a39b84b Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 18 Jul 2017 17:38:00 +0300 Subject: [PATCH 212/349] added test for build_attrib_request --- .../tests/ledger/test_build_attrib_request.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 wrappers/python/tests/ledger/test_build_attrib_request.py diff --git a/wrappers/python/tests/ledger/test_build_attrib_request.py b/wrappers/python/tests/ledger/test_build_attrib_request.py new file mode 100644 index 0000000000..aa3f5e91ef --- /dev/null +++ b/wrappers/python/tests/ledger/test_build_attrib_request.py @@ -0,0 +1,34 @@ +from tests.utils import storage +from indy import ledger + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_build_attrib_request_works_for_raw_data(): + identifier = "Th7MpTaRZVRYnPiabds81Y" + destination = "Th7MpTaRZVRYnPiabds81Y" + raw = '{"endpoint":{"ha":"127.0.0.1:5555"}}' + + expected_response = { + "identifier": identifier, + "operation": { + "type": "100", + "dest": destination, + "raw": raw + } + } + + response = json.loads((await ledger.build_attrib_request(identifier, destination, None, raw, None)).decode()) + assert expected_response.items() <= response.items() From 8f5e96c87e9849cd01f6547d7db24484fed8d901 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 18 Jul 2017 17:41:41 +0300 Subject: [PATCH 213/349] added test for build_get_attrib_request --- .../ledger/test_build_get_attrib_request.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 wrappers/python/tests/ledger/test_build_get_attrib_request.py diff --git a/wrappers/python/tests/ledger/test_build_get_attrib_request.py b/wrappers/python/tests/ledger/test_build_get_attrib_request.py new file mode 100644 index 0000000000..5a474be599 --- /dev/null +++ b/wrappers/python/tests/ledger/test_build_get_attrib_request.py @@ -0,0 +1,34 @@ +from tests.utils import storage +from indy import ledger + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_build_get_attrib_request_works_for_raw_data(): + identifier = "Th7MpTaRZVRYnPiabds81Y" + destination = "Th7MpTaRZVRYnPiabds81Y" + raw = "endpoint" + + expected_response = { + "identifier": identifier, + "operation": { + "type": "104", + "dest": destination, + "raw": raw + } + } + + response = json.loads((await ledger.build_get_attrib_request(identifier, destination, raw)).decode()) + assert expected_response.items() <= response.items() From eb862f3a5e9dbb31014c1c863b06071d14253eae Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 18 Jul 2017 18:05:14 +0300 Subject: [PATCH 214/349] added test for build_get_nym_request --- .../ledger/test_build_get_nym_request.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 wrappers/python/tests/ledger/test_build_get_nym_request.py diff --git a/wrappers/python/tests/ledger/test_build_get_nym_request.py b/wrappers/python/tests/ledger/test_build_get_nym_request.py new file mode 100644 index 0000000000..66e0c57617 --- /dev/null +++ b/wrappers/python/tests/ledger/test_build_get_nym_request.py @@ -0,0 +1,32 @@ +from tests.utils import storage +from indy import ledger + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_build_get_nym_request_works(): + identifier = "Th7MpTaRZVRYnPiabds81Y" + destination = "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4" + + expected_response = { + "identifier": identifier, + "operation": { + "type": "105", + "dest": destination + } + } + + response = json.loads((await ledger.build_get_nym_request(identifier, destination)).decode()) + assert expected_response.items() <= response.items() From 12359ff1835280328bf32bb2696c4ff05fe64225 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 18 Jul 2017 18:13:46 +0300 Subject: [PATCH 215/349] Added Demo integration tests for Anoncreds --- .../org/hyperledger/indy/sdk/LedgerTest.java | 39 -- .../org/hyperledger/indy/sdk/SignusTest.java | 63 ---- .../indy/sdk/demo/AnoncredsDemoTest.java | 355 +++++++++++++++++- 3 files changed, 352 insertions(+), 105 deletions(-) delete mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/LedgerTest.java delete mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/SignusTest.java diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/LedgerTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/LedgerTest.java deleted file mode 100644 index 477ca7f2ce..0000000000 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/LedgerTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.hyperledger.indy.sdk; - -import java.io.File; - -import org.hyperledger.indy.sdk.ledger.Ledger; -import org.hyperledger.indy.sdk.pool.Pool; -import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; -import org.junit.Assert; - -import junit.framework.TestCase; - -public class LedgerTest extends TestCase { - - private Pool pool; - - @Override - protected void setUp() throws Exception { - - if (! LibIndy.isInitialized()) LibIndy.init(new File("./lib/libindy.so")); - - OpenPoolLedgerJSONParameter openPoolLedgerOptions = new OpenPoolLedgerJSONParameter(null, null, null); - this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions.toJson()).get(); - } - - @Override - protected void tearDown() throws Exception { - - this.pool.closePoolLedger(); - } - - public void testLedger() throws Exception { - - String result1 = Ledger.buildGetDdoRequest("did:sov:21tDAKCERh95uGgKbJNHYp", "did:sov:1yvXbmgPoUm4dl66D7KhyD", "{}").get(); - Assert.assertNotNull(result1); - - String result2 = Ledger.buildGetNymRequest("did:sov:21tDAKCERh95uGgKbJNHYp", "did:sov:1yvXbmgPoUm4dl66D7KhyD").get(); - Assert.assertNotNull(result2); - } -} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/SignusTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/SignusTest.java deleted file mode 100644 index cda7271a4c..0000000000 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/SignusTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.hyperledger.indy.sdk; - -import java.io.File; -import java.util.concurrent.Future; - -import org.hyperledger.indy.sdk.pool.Pool; -import org.hyperledger.indy.sdk.pool.PoolJSONParameters.OpenPoolLedgerJSONParameter; -import org.hyperledger.indy.sdk.signus.Signus; -import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; -import org.hyperledger.indy.sdk.signus.SignusResults.ReplaceKeysResult; -import org.hyperledger.indy.sdk.wallet.Wallet; -import org.junit.Assert; - -import junit.framework.TestCase; - -public class SignusTest extends TestCase { - - private Pool pool; - private Wallet wallet; - - @Override - protected void setUp() throws Exception { - - if (! LibIndy.isInitialized()) LibIndy.init(new File("./lib/libindy.so")); - - OpenPoolLedgerJSONParameter openPoolLedgerOptions = new OpenPoolLedgerJSONParameter(null, null, null); - this.pool = Pool.openPoolLedger("myconfig", openPoolLedgerOptions.toJson()).get(); - this.wallet = Wallet.openWallet("mywallet", null, null).get(); - } - - @Override - protected void tearDown() throws Exception { - - this.wallet.closeWallet(); - this.pool.closePoolLedger(); - Wallet.deleteWallet("mywallet", null); - } - - public void testSignus() throws Exception { - - Future future1 = Signus.createAndStoreMyDid(this.wallet, "{}"); - CreateAndStoreMyDidResult result1 = future1.get(); - Assert.assertNotNull(result1); - String did1 = result1.getDid(); - String verkey1 = result1.getVerkey(); - String pk1 = result1.getPk(); - Assert.assertNotNull(did1); - Assert.assertNotNull(verkey1); - Assert.assertNotNull(pk1); - System.out.println(did1); - System.out.println(verkey1); - System.out.println(pk1); - - Future future2 = Signus.replaceKeys(this.wallet, did1, "{}"); - ReplaceKeysResult result2 = future2.get(); - Assert.assertNotNull(result2); - String verkey2 = result2.getVerkey(); - String pk2 = result2.getPk(); - Assert.assertNotNull(verkey2); - Assert.assertNotNull(pk2); - Assert.assertNotEquals(verkey2, verkey1); - } -} \ No newline at end of file diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java index 4913f26a7f..8b99077e83 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java @@ -86,7 +86,7 @@ public void testAnoncredsDemo() throws Exception { " \"age\":[\"28\",\"28\"]\n" + " }"; - AnoncredsResults.IssuerCreateClaimResult createClaimResult = Anoncreds.issuerCreateClaim(issuerWallet, claimReq, claimAttributesJson, -1, -1).get(); + AnoncredsResults.IssuerCreateClaimResult createClaimResult = Anoncreds.issuerCreateClaim(issuerWallet, claimReq, claimAttributesJson, - 1, - 1).get(); assertNotNull(createClaimResult); String claimJson = createClaimResult.getClaimJson(); @@ -148,15 +148,364 @@ public void testAnoncredsDemo() throws Exception { Boolean valid = Anoncreds.verifierVerifyProof(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson).get(); assertTrue(valid); - // 14. Close and delete My Wallet + // 14. Close and delete Issuer Wallet issuerWallet.closeWallet().get(); Wallet.deleteWallet("issuerWallet", null).get(); - // 15. Close and delete Their Wallet + // 15. Close and delete Prover Wallet proverWallet.closeWallet().get(); Wallet.deleteWallet("proverWallet", null).get(); //16. Close Pool pool.closePoolLedger().get(); } + + @Test + public void anoncredsWorksForMultiplyIssuerSingleProver() throws Exception { + + String issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; + String issuerDid2 = "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"; + + //1. Create and Open Pool + String poolName = PoolUtils.createPoolLedgerConfig(); + + PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); + Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); + + //2. Issuer1 Create and Open Wallet + Wallet.createWallet(poolName, "issuer1Wallet", "default", null, null).get(); + Wallet issuerGvtWallet = Wallet.openWallet("issuer1Wallet", null, null).get(); + + //3. Issuer2 Create and Open Wallet + Wallet.createWallet(poolName, "issuer2Wallet", "default", null, null).get(); + Wallet issuerXyzWallet = Wallet.openWallet("issuer2Wallet", null, null).get(); + + //4. Prover Create and Open Wallet + Wallet.createWallet(poolName, "proverWallet", "default", null, null).get(); + Wallet proverWallet = Wallet.openWallet("proverWallet", null, null).get(); + + //5. Issuer create ClaimDef + String gvtSchemaJson = "{\n" + + " \"seqNo\":1,\n" + + " \"data\": {\n" + + " \"name\":\"gvt\",\n" + + " \"version\":\"1.0\",\n" + + " \"keys\":[\"age\",\"sex\",\"height\",\"name\"]\n" + + " }\n" + + " }"; + + String gvtClaimDef = Anoncreds.issuerCreateAndStoreClaimDef(issuerGvtWallet, issuerDid, gvtSchemaJson, null, false).get(); + + //6. Issuer create ClaimDef + String xyzSchemaJson = "{\n" + + " \"seqNo\":2,\n" + + " \"data\": {\n" + + " \"name\":\"xyz\",\n" + + " \"version\":\"1.0\",\n" + + " \"keys\":[\"status\",\"period\"]\n" + + " }\n" + + " }"; + + String xyzClaimDef = Anoncreds.issuerCreateAndStoreClaimDef(issuerXyzWallet, issuerDid2, xyzSchemaJson, null, false).get(); + + //7. Prover create Master Secret + String masterSecret = "masterSecretName"; + Anoncreds.proverCreateMasterSecret(proverWallet, masterSecret).get(); + + //8. Prover store Claim Offer received from Issuer1 + String claimOffer = String.format("{\"issuer_did\":\"%s\", \"schema_seq_no\":%d}", issuerDid, 1); + Anoncreds.proverStoreClaimOffer(proverWallet, claimOffer).get(); + + //9. Prover store Claim Offer received from Issuer2 + String claimOffer2 = String.format("{\"issuer_did\":\"%s\", \"schema_seq_no\":%d}", issuerDid2, 2); + Anoncreds.proverStoreClaimOffer(proverWallet, claimOffer2).get(); + + //10. Prover get Claim Offers + String claimOffersJson = Anoncreds.proverGetClaimOffers(proverWallet, "{}").get(); + + JSONArray claimOffersObject = new JSONArray(claimOffersJson); + assertEquals(2, claimOffersObject.length()); + + JSONObject claimOfferObj1 = claimOffersObject.getJSONObject(0); + JSONObject claimOfferObj2 = claimOffersObject.getJSONObject(1); + + String gvtClaimOffer = claimOfferObj1.getString("issuer_did").equals(issuerDid) ? claimOfferObj1.toString() : claimOfferObj2.toString(); + String xyzClaimOffer = claimOfferObj1.getString("issuer_did").equals(issuerDid2) ? claimOfferObj1.toString() : claimOfferObj2.toString(); + + + //11. Prover create ClaimReq for GVT Claim Offer + String proverDid = "BzfFCYk"; + String gvtClaimReq = Anoncreds.proverCreateClaimReq(proverWallet, proverDid, gvtClaimOffer, gvtClaimDef, masterSecret).get(); + + //12. Issuer create Claim + String gvtClaimAttributesJson = "{\n" + + " \"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" + + " \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" + + " \"height\":[\"175\",\"175\"],\n" + + " \"age\":[\"28\",\"28\"]\n" + + " }"; + + AnoncredsResults.IssuerCreateClaimResult gvtCreateClaimResult = Anoncreds.issuerCreateClaim(issuerGvtWallet, gvtClaimReq, gvtClaimAttributesJson, - 1, - 1).get(); + String gvtClaimJson = gvtCreateClaimResult.getClaimJson(); + + //13. Prover store Claim + Anoncreds.proverStoreClaim(proverWallet, gvtClaimJson).get(); + + //14. Prover create ClaimReq for GVT Claim Offer + String xyzClaimReq = Anoncreds.proverCreateClaimReq(proverWallet, proverDid, xyzClaimOffer, xyzClaimDef, masterSecret).get(); + + //15. Issuer create Claim + String xyzClaimAttributesJson = "{\n" + + " \"status\":[\"partial\",\"51792877103171595686471452153480627530895\"],\n" + + " \"period\":[\"8\",\"8\"]\n" + + " }"; + + AnoncredsResults.IssuerCreateClaimResult xyzCreateClaimResult = Anoncreds.issuerCreateClaim(issuerXyzWallet, xyzClaimReq, xyzClaimAttributesJson, - 1, - 1).get(); + String xyzClaimJson = xyzCreateClaimResult.getClaimJson(); + + //16. Prover store Claim + Anoncreds.proverStoreClaim(proverWallet, xyzClaimJson).get(); + + //17. Prover gets Claims for Proof Request + String proofRequestJson = "{\n" + + " \"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1,\"name\":\"name\"},\n" + + " \"attr2_uuid\":{\"schema_seq_no\":2,\"name\":\"status\"}},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}," + + " \"predicate2_uuid\":{\"attr_name\":\"period\",\"p_type\":\"GE\",\"value\":5}}\n" + + " }"; + + + String claimsForProofJson = Anoncreds.proverGetClaimsForProofReq(proverWallet, proofRequestJson).get(); + assertNotNull(claimsForProofJson); + + JSONObject claimsForProof = new JSONObject(claimsForProofJson); + JSONArray claimsForAttribute1 = claimsForProof.getJSONObject("attrs").getJSONArray("attr1_uuid"); + JSONArray claimsForAttribute2 = claimsForProof.getJSONObject("attrs").getJSONArray("attr2_uuid"); + JSONArray claimsForPredicate1 = claimsForProof.getJSONObject("predicates").getJSONArray("predicate1_uuid"); + JSONArray claimsForPredicate2 = claimsForProof.getJSONObject("predicates").getJSONArray("predicate2_uuid"); + + assertEquals(claimsForAttribute1.length(), 1); + assertEquals(claimsForAttribute2.length(), 1); + assertEquals(claimsForPredicate1.length(), 1); + assertEquals(claimsForPredicate2.length(), 1); + + String claimUuidForAttr1 = claimsForAttribute1.getJSONObject(0).getString("claim_uuid"); + String claimUuidForAttr2 = claimsForAttribute2.getJSONObject(0).getString("claim_uuid"); + String claimUuidForPredicate1 = claimsForPredicate1.getJSONObject(0).getString("claim_uuid"); + String claimUuidForPredicate2 = claimsForPredicate2.getJSONObject(0).getString("claim_uuid"); + + //18. Prover create Proof + String requestedClaimsJson = String.format("{\n" + + " \"self_attested_attributes\":{},\n" + + " \"requested_attrs\":{\"attr1_uuid\":[\"%s\", true],\n" + + " \"attr2_uuid\":[\"%s\", true]},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":\"%s\"," + + " \"predicate2_uuid\":\"%s\"}\n" + + " }", claimUuidForAttr1, claimUuidForAttr2, claimUuidForPredicate1, claimUuidForPredicate2); + + String schemasJson = String.format("{\"%s\":%s, \"%s\":%s}", claimUuidForAttr1, gvtSchemaJson, claimUuidForAttr2, xyzSchemaJson); + String claimDefsJson = String.format("{\"%s\":%s, \"%s\":%s}", claimUuidForAttr1, gvtClaimDef, claimUuidForAttr2, xyzClaimDef); + + String revocRegsJson = "{}"; + + String proofJson = Anoncreds.proverCreateProof(proverWallet, proofRequestJson, requestedClaimsJson, schemasJson, + masterSecret, claimDefsJson, revocRegsJson).get(); + assertNotNull(proofJson); + + JSONObject proof = new JSONObject(proofJson); + + //19. Verifier verify Proof + assertEquals("Alex", + proof.getJSONObject("requested_proof").getJSONObject("revealed_attrs").getJSONArray("attr1_uuid").getString(1)); + + assertEquals("partial", + proof.getJSONObject("requested_proof").getJSONObject("revealed_attrs").getJSONArray("attr2_uuid").getString(1)); + + Boolean valid = Anoncreds.verifierVerifyProof(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson).get(); + assertTrue(valid); + + //20. Close and delete Issuer1 Wallet + issuerGvtWallet.closeWallet().get(); + Wallet.deleteWallet("issuer1Wallet", null).get(); + + //21. Close and delete Issuer2 Wallet + issuerXyzWallet.closeWallet().get(); + Wallet.deleteWallet("issuer2Wallet", null).get(); + + //22. Close and delete Prover Wallet + proverWallet.closeWallet().get(); + Wallet.deleteWallet("proverWallet", null).get(); + + //23. Close Pool + pool.closePoolLedger().get(); + } + + @Test + public void anoncredsWorksForSingleIssuerSingleProver() throws Exception { + + String issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; + + //1. Create and Open Pool + String poolName = PoolUtils.createPoolLedgerConfig(); + + PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); + Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); + + //2. Issuer Create and Open Wallet + Wallet.createWallet(poolName, "issuerWallet", "default", null, null).get(); + Wallet issuerWallet = Wallet.openWallet("issuerWallet", null, null).get(); + + //3. Prover Create and Open Wallet + Wallet.createWallet(poolName, "proverWallet", "default", null, null).get(); + Wallet proverWallet = Wallet.openWallet("proverWallet", null, null).get(); + + //4. Issuer create ClaimDef + String gvtSchemaJson = "{\n" + + " \"seqNo\":1,\n" + + " \"data\": {\n" + + " \"name\":\"gvt\",\n" + + " \"version\":\"1.0\",\n" + + " \"keys\":[\"age\",\"sex\",\"height\",\"name\"]\n" + + " }\n" + + " }"; + + String gvtClaimDef = Anoncreds.issuerCreateAndStoreClaimDef(issuerWallet, issuerDid, gvtSchemaJson, null, false).get(); + + //5. Issuer create ClaimDef + String xyzSchemaJson = "{\n" + + " \"seqNo\":2,\n" + + " \"data\": {\n" + + " \"name\":\"xyz\",\n" + + " \"version\":\"1.0\",\n" + + " \"keys\":[\"status\",\"period\"]\n" + + " }\n" + + " }"; + + String xyzClaimDef = Anoncreds.issuerCreateAndStoreClaimDef(issuerWallet, issuerDid, xyzSchemaJson, null, false).get(); + + //6. Prover create Master Secret + String masterSecret = "masterSecretName"; + Anoncreds.proverCreateMasterSecret(proverWallet, masterSecret).get(); + + //7. Prover store Claim Offer received from Issuer + String claimOffer = String.format("{\"issuer_did\":\"%s\", \"schema_seq_no\":%d}", issuerDid, 1); + Anoncreds.proverStoreClaimOffer(proverWallet, claimOffer).get(); + + //8. Prover store Claim Offer received from Issuer + String claimOffer2 = String.format("{\"issuer_did\":\"%s\", \"schema_seq_no\":%d}", issuerDid, 2); + Anoncreds.proverStoreClaimOffer(proverWallet, claimOffer2).get(); + + //9. Prover get Claim Offers + String claimOffersJson = Anoncreds.proverGetClaimOffers(proverWallet, "{}").get(); + + JSONArray claimOffersObject = new JSONArray(claimOffersJson); + assertEquals(2, claimOffersObject.length()); + + JSONObject claimOfferObj1 = claimOffersObject.getJSONObject(0); + JSONObject claimOfferObj2 = claimOffersObject.getJSONObject(1); + + String gvtClaimOffer = claimOfferObj1.getInt("schema_seq_no") == 1 ? claimOfferObj1.toString() : claimOfferObj2.toString(); + String xyzClaimOffer = claimOfferObj1.getInt("schema_seq_no") == 2 ? claimOfferObj1.toString() : claimOfferObj2.toString(); + + + //10. Prover create ClaimReq for GVT Claim Offer + String proverDid = "BzfFCYk"; + String gvtClaimReq = Anoncreds.proverCreateClaimReq(proverWallet, proverDid, gvtClaimOffer, gvtClaimDef, masterSecret).get(); + + //11. Issuer create Claim + String gvtClaimAttributesJson = "{\n" + + " \"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" + + " \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" + + " \"height\":[\"175\",\"175\"],\n" + + " \"age\":[\"28\",\"28\"]\n" + + " }"; + + AnoncredsResults.IssuerCreateClaimResult gvtCreateClaimResult = Anoncreds.issuerCreateClaim(issuerWallet, gvtClaimReq, gvtClaimAttributesJson, - 1, - 1).get(); + String gvtClaimJson = gvtCreateClaimResult.getClaimJson(); + + //12. Prover store Claim + Anoncreds.proverStoreClaim(proverWallet, gvtClaimJson).get(); + + //13. Prover create ClaimReq for GVT Claim Offer + String xyzClaimReq = Anoncreds.proverCreateClaimReq(proverWallet, proverDid, xyzClaimOffer, xyzClaimDef, masterSecret).get(); + + //14. Issuer create Claim + String xyzClaimAttributesJson = "{\n" + + " \"status\":[\"partial\",\"51792877103171595686471452153480627530895\"],\n" + + " \"period\":[\"8\",\"8\"]\n" + + " }"; + + AnoncredsResults.IssuerCreateClaimResult xyzCreateClaimResult = Anoncreds.issuerCreateClaim(issuerWallet, xyzClaimReq, xyzClaimAttributesJson, - 1, - 1).get(); + String xyzClaimJson = xyzCreateClaimResult.getClaimJson(); + + //15. Prover store Claim + Anoncreds.proverStoreClaim(proverWallet, xyzClaimJson).get(); + + //16. Prover gets Claims for Proof Request + String proofRequestJson = "{\n" + + " \"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1,\"name\":\"name\"}},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}," + + " \"predicate2_uuid\":{\"attr_name\":\"period\",\"p_type\":\"GE\",\"value\":5}}\n" + + " }"; + + + String claimsForProofJson = Anoncreds.proverGetClaimsForProofReq(proverWallet, proofRequestJson).get(); + assertNotNull(claimsForProofJson); + + JSONObject claimsForProof = new JSONObject(claimsForProofJson); + JSONArray claimsForAttribute1 = claimsForProof.getJSONObject("attrs").getJSONArray("attr1_uuid"); + JSONArray claimsForPredicate1 = claimsForProof.getJSONObject("predicates").getJSONArray("predicate1_uuid"); + JSONArray claimsForPredicate2 = claimsForProof.getJSONObject("predicates").getJSONArray("predicate2_uuid"); + + assertEquals(claimsForAttribute1.length(), 1); + assertEquals(claimsForPredicate1.length(), 1); + assertEquals(claimsForPredicate2.length(), 1); + + String claimUuidForAttr1 = claimsForAttribute1.getJSONObject(0).getString("claim_uuid"); + String claimUuidForPredicate1 = claimsForPredicate1.getJSONObject(0).getString("claim_uuid"); + String claimUuidForPredicate2 = claimsForPredicate2.getJSONObject(0).getString("claim_uuid"); + + //17. Prover create Proof + String requestedClaimsJson = String.format("{\n" + + " \"self_attested_attributes\":{},\n" + + " \"requested_attrs\":{\"attr1_uuid\":[\"%s\", true]},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":\"%s\"," + + " \"predicate2_uuid\":\"%s\"}\n" + + " }", claimUuidForAttr1, claimUuidForPredicate1, claimUuidForPredicate2); + + String schemasJson = String.format("{\"%s\":%s, \"%s\":%s}", claimUuidForAttr1, gvtSchemaJson, claimUuidForPredicate2, xyzSchemaJson); + String claimDefsJson = String.format("{\"%s\":%s, \"%s\":%s}", claimUuidForAttr1, gvtClaimDef, claimUuidForPredicate2, xyzClaimDef); + + String revocRegsJson = "{}"; + + String proofJson = Anoncreds.proverCreateProof(proverWallet, proofRequestJson, requestedClaimsJson, schemasJson, + masterSecret, claimDefsJson, revocRegsJson).get(); + assertNotNull(proofJson); + + JSONObject proof = new JSONObject(proofJson); + + //18. Verifier verify Proof + assertEquals("Alex", + proof.getJSONObject("requested_proof").getJSONObject("revealed_attrs").getJSONArray("attr1_uuid").getString(1)); + + Boolean valid = Anoncreds.verifierVerifyProof(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson).get(); + assertTrue(valid); + + //19. Close and delete Issuer Wallet + issuerWallet.closeWallet().get(); + Wallet.deleteWallet("issuerWallet", null).get(); + + //21. Close and delete Their Wallet + proverWallet.closeWallet().get(); + Wallet.deleteWallet("proverWallet", null).get(); + + //22. Close Pool + pool.closePoolLedger().get(); + } } From d15040564a2ab406a4c4a77e3209109fb7997b07 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 18 Jul 2017 18:19:28 +0300 Subject: [PATCH 216/349] added test for build_schema_request --- .../tests/ledger/test_build_schema_request.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 wrappers/python/tests/ledger/test_build_schema_request.py diff --git a/wrappers/python/tests/ledger/test_build_schema_request.py b/wrappers/python/tests/ledger/test_build_schema_request.py new file mode 100644 index 0000000000..4bee422dcf --- /dev/null +++ b/wrappers/python/tests/ledger/test_build_schema_request.py @@ -0,0 +1,31 @@ +from tests.utils import storage +from indy import ledger + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_build_schema_requests_works_for_correct_data_json(): + identifier = "identifier" + data = '{"name":"name", "version":"1.0", "keys":["name","male"]}' + + expected_response = { + "operation": { + "type": "101", + "data": '{"name":"name", "version":"1.0", "keys":["name","male"]}' + } + } + + response = json.loads((await ledger.build_schema_request(identifier, data)).decode()) + assert expected_response.items() <= response.items() From dddedfca9b0d2cee35f231996d87a26c735a2185 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 18 Jul 2017 18:29:13 +0300 Subject: [PATCH 217/349] added fixture for pool_handle --- .../tests/ledger/test_sign_and_submit_request.py | 12 +++++++++--- wrappers/python/tests/ledger/test_submit_request.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/wrappers/python/tests/ledger/test_sign_and_submit_request.py b/wrappers/python/tests/ledger/test_sign_and_submit_request.py index 7d92a58ec2..7324db1f9b 100644 --- a/wrappers/python/tests/ledger/test_sign_and_submit_request.py +++ b/wrappers/python/tests/ledger/test_sign_and_submit_request.py @@ -1,7 +1,7 @@ from tests.utils import pool, storage from tests.utils.wallet import create_and_open_wallet from indy import wallet, signus, ledger - +from indy.pool import close_pool_ledger import pytest import logging @@ -15,6 +15,13 @@ def before_after_each(): storage.cleanup() +@pytest.fixture +async def pool_handle(): + handle = await pool.create_and_open_pool_ledger("pool_name") + yield handle + await close_pool_ledger(handle) + + @pytest.fixture async def wallet_handle(): handle = await create_and_open_wallet(pool_name="pool_name") @@ -23,8 +30,7 @@ async def wallet_handle(): @pytest.mark.asyncio -async def test_sign_and_submit_request_works(wallet_handle): - pool_handle = await pool.create_and_open_pool_ledger("pool_name") +async def test_sign_and_submit_request_works(wallet_handle, pool_handle): (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') diff --git a/wrappers/python/tests/ledger/test_submit_request.py b/wrappers/python/tests/ledger/test_submit_request.py index 978f9593dc..3c10e88d9e 100644 --- a/wrappers/python/tests/ledger/test_submit_request.py +++ b/wrappers/python/tests/ledger/test_submit_request.py @@ -1,5 +1,6 @@ from tests.utils import pool, storage from indy import ledger +from indy.pool import close_pool_ledger import json import pytest @@ -15,9 +16,15 @@ def before_after_each(): storage.cleanup() +@pytest.fixture +async def pool_handle(): + handle = await pool.create_and_open_pool_ledger("pool_name") + yield handle + await close_pool_ledger(handle) + + @pytest.mark.asyncio -async def test_submit_request_works(): - pool_handle = await pool.create_and_open_pool_ledger("pool_name") +async def test_submit_request_works(pool_handle): request = { "reqId": 1491566332010860, "identifier": "Th7MpTaRZVRYnPiabds81Y", From 69ea38b4b13aea03673a304c4facd57bd3ea3cdb Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 19 Jul 2017 09:14:14 +0300 Subject: [PATCH 218/349] Completed AnoncredsApi integration tests --- .../indy/sdk/anoncreds/DemoTest.java | 479 ++++++++++++++++++ .../indy/sdk/demo/AnoncredsDemoTest.java | 349 ------------- 2 files changed, 479 insertions(+), 349 deletions(-) create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/DemoTest.java diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/DemoTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/DemoTest.java new file mode 100644 index 0000000000..366f5c6fcb --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/DemoTest.java @@ -0,0 +1,479 @@ +package org.hyperledger.indy.sdk.anoncreds; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.pool.Pool; +import org.hyperledger.indy.sdk.pool.PoolJSONParameters; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.Timeout; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class DemoTest extends IndyIntegrationTest { + + @Rule + public Timeout globalTimeout = new Timeout(2, TimeUnit.MINUTES); + + private Pool pool; + private Wallet issuerWallet; + private Wallet proverWallet; + private String poolName; + + @Before + public void createWallet() throws Exception { + //1. Create and Open Pool + poolName = PoolUtils.createPoolLedgerConfig(); + + PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); + pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); + + //2. Issuer Create and Open Wallet + Wallet.createWallet(poolName, "issuerWallet", "default", null, null).get(); + issuerWallet = Wallet.openWallet("issuerWallet", null, null).get(); + + //3. Prover Create and Open Wallet + Wallet.createWallet(poolName, "proverWallet", "default", null, null).get(); + proverWallet = Wallet.openWallet("proverWallet", null, null).get(); + } + + @After + public void deleteWallet() throws Exception { + issuerWallet.closeWallet().get(); + Wallet.deleteWallet("issuerWallet", null).get(); + + proverWallet.closeWallet().get(); + Wallet.deleteWallet("proverWallet", null).get(); + + pool.closePoolLedger(); + } + + @Test + public void anoncredsWorksForMultiplyIssuerSingleProver() throws Exception { + + String issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; + String issuerDid2 = "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"; + + Wallet issuerGvtWallet = issuerWallet; + + //1. Issuer2 Create and Open Wallet + Wallet.createWallet(poolName, "issuer2Wallet", "default", null, null).get(); + Wallet issuerXyzWallet = Wallet.openWallet("issuer2Wallet", null, null).get(); + + //2. Issuer create ClaimDef + String gvtSchemaJson = "{\n" + + " \"seqNo\":1,\n" + + " \"data\": {\n" + + " \"name\":\"gvt\",\n" + + " \"version\":\"1.0\",\n" + + " \"keys\":[\"age\",\"sex\",\"height\",\"name\"]\n" + + " }\n" + + " }"; + + String gvtClaimDef = Anoncreds.issuerCreateAndStoreClaimDef(issuerGvtWallet, issuerDid, gvtSchemaJson, null, false).get(); + + //3. Issuer create ClaimDef + String xyzSchemaJson = "{\n" + + " \"seqNo\":2,\n" + + " \"data\": {\n" + + " \"name\":\"xyz\",\n" + + " \"version\":\"1.0\",\n" + + " \"keys\":[\"status\",\"period\"]\n" + + " }\n" + + " }"; + + String xyzClaimDef = Anoncreds.issuerCreateAndStoreClaimDef(issuerXyzWallet, issuerDid2, xyzSchemaJson, null, false).get(); + + //4. Prover create Master Secret + String masterSecret = "masterSecretName"; + Anoncreds.proverCreateMasterSecret(proverWallet, masterSecret).get(); + + //5. Prover store Claim Offer received from Issuer1 + String claimOffer = String.format("{\"issuer_did\":\"%s\", \"schema_seq_no\":%d}", issuerDid, 1); + Anoncreds.proverStoreClaimOffer(proverWallet, claimOffer).get(); + + //6. Prover store Claim Offer received from Issuer2 + String claimOffer2 = String.format("{\"issuer_did\":\"%s\", \"schema_seq_no\":%d}", issuerDid2, 2); + Anoncreds.proverStoreClaimOffer(proverWallet, claimOffer2).get(); + + //7. Prover get Claim Offers + String claimOffersJson = Anoncreds.proverGetClaimOffers(proverWallet, "{}").get(); + + JSONArray claimOffersObject = new JSONArray(claimOffersJson); + assertEquals(2, claimOffersObject.length()); + + JSONObject claimOfferObj1 = claimOffersObject.getJSONObject(0); + JSONObject claimOfferObj2 = claimOffersObject.getJSONObject(1); + + String gvtClaimOffer = claimOfferObj1.getString("issuer_did").equals(issuerDid) ? claimOfferObj1.toString() : claimOfferObj2.toString(); + String xyzClaimOffer = claimOfferObj1.getString("issuer_did").equals(issuerDid2) ? claimOfferObj1.toString() : claimOfferObj2.toString(); + + + //8. Prover create ClaimReq for GVT Claim Offer + String proverDid = "BzfFCYk"; + String gvtClaimReq = Anoncreds.proverCreateClaimReq(proverWallet, proverDid, gvtClaimOffer, gvtClaimDef, masterSecret).get(); + + //9. Issuer create Claim + String gvtClaimAttributesJson = "{\n" + + " \"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" + + " \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" + + " \"height\":[\"175\",\"175\"],\n" + + " \"age\":[\"28\",\"28\"]\n" + + " }"; + + AnoncredsResults.IssuerCreateClaimResult gvtCreateClaimResult = Anoncreds.issuerCreateClaim(issuerGvtWallet, gvtClaimReq, gvtClaimAttributesJson, - 1, - 1).get(); + String gvtClaimJson = gvtCreateClaimResult.getClaimJson(); + + //10. Prover store Claim + Anoncreds.proverStoreClaim(proverWallet, gvtClaimJson).get(); + + //11. Prover create ClaimReq for GVT Claim Offer + String xyzClaimReq = Anoncreds.proverCreateClaimReq(proverWallet, proverDid, xyzClaimOffer, xyzClaimDef, masterSecret).get(); + + //12. Issuer create Claim + String xyzClaimAttributesJson = "{\n" + + " \"status\":[\"partial\",\"51792877103171595686471452153480627530895\"],\n" + + " \"period\":[\"8\",\"8\"]\n" + + " }"; + + AnoncredsResults.IssuerCreateClaimResult xyzCreateClaimResult = Anoncreds.issuerCreateClaim(issuerXyzWallet, xyzClaimReq, xyzClaimAttributesJson, - 1, - 1).get(); + String xyzClaimJson = xyzCreateClaimResult.getClaimJson(); + + //13. Prover store Claim + Anoncreds.proverStoreClaim(proverWallet, xyzClaimJson).get(); + + //14. Prover gets Claims for Proof Request + String proofRequestJson = "{\n" + + " \"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1,\"name\":\"name\"},\n" + + " \"attr2_uuid\":{\"schema_seq_no\":2,\"name\":\"status\"}},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}," + + " \"predicate2_uuid\":{\"attr_name\":\"period\",\"p_type\":\"GE\",\"value\":5}}\n" + + " }"; + + + String claimsForProofJson = Anoncreds.proverGetClaimsForProofReq(proverWallet, proofRequestJson).get(); + assertNotNull(claimsForProofJson); + + JSONObject claimsForProof = new JSONObject(claimsForProofJson); + JSONArray claimsForAttribute1 = claimsForProof.getJSONObject("attrs").getJSONArray("attr1_uuid"); + JSONArray claimsForAttribute2 = claimsForProof.getJSONObject("attrs").getJSONArray("attr2_uuid"); + JSONArray claimsForPredicate1 = claimsForProof.getJSONObject("predicates").getJSONArray("predicate1_uuid"); + JSONArray claimsForPredicate2 = claimsForProof.getJSONObject("predicates").getJSONArray("predicate2_uuid"); + + assertEquals(claimsForAttribute1.length(), 1); + assertEquals(claimsForAttribute2.length(), 1); + assertEquals(claimsForPredicate1.length(), 1); + assertEquals(claimsForPredicate2.length(), 1); + + String claimUuidForAttr1 = claimsForAttribute1.getJSONObject(0).getString("claim_uuid"); + String claimUuidForAttr2 = claimsForAttribute2.getJSONObject(0).getString("claim_uuid"); + String claimUuidForPredicate1 = claimsForPredicate1.getJSONObject(0).getString("claim_uuid"); + String claimUuidForPredicate2 = claimsForPredicate2.getJSONObject(0).getString("claim_uuid"); + + //15. Prover create Proof + String requestedClaimsJson = String.format("{\n" + + " \"self_attested_attributes\":{},\n" + + " \"requested_attrs\":{\"attr1_uuid\":[\"%s\", true],\n" + + " \"attr2_uuid\":[\"%s\", true]},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":\"%s\"," + + " \"predicate2_uuid\":\"%s\"}\n" + + " }", claimUuidForAttr1, claimUuidForAttr2, claimUuidForPredicate1, claimUuidForPredicate2); + + String schemasJson = String.format("{\"%s\":%s, \"%s\":%s}", claimUuidForAttr1, gvtSchemaJson, claimUuidForAttr2, xyzSchemaJson); + String claimDefsJson = String.format("{\"%s\":%s, \"%s\":%s}", claimUuidForAttr1, gvtClaimDef, claimUuidForAttr2, xyzClaimDef); + + String revocRegsJson = "{}"; + + String proofJson = Anoncreds.proverCreateProof(proverWallet, proofRequestJson, requestedClaimsJson, schemasJson, + masterSecret, claimDefsJson, revocRegsJson).get(); + assertNotNull(proofJson); + + JSONObject proof = new JSONObject(proofJson); + + //16. Verifier verify Proof + assertEquals("Alex", + proof.getJSONObject("requested_proof").getJSONObject("revealed_attrs").getJSONArray("attr1_uuid").getString(1)); + + assertEquals("partial", + proof.getJSONObject("requested_proof").getJSONObject("revealed_attrs").getJSONArray("attr2_uuid").getString(1)); + + Boolean valid = Anoncreds.verifierVerifyProof(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson).get(); + assertTrue(valid); + + //18. Close and delete Issuer2 Wallet + issuerXyzWallet.closeWallet().get(); + Wallet.deleteWallet("issuer2Wallet", null).get(); + } + + @Test + public void anoncredsWorksForSingleIssuerSingleProver() throws Exception { + + String issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; + + //1. Issuer create ClaimDef + String gvtSchemaJson = "{\n" + + " \"seqNo\":1,\n" + + " \"data\": {\n" + + " \"name\":\"gvt\",\n" + + " \"version\":\"1.0\",\n" + + " \"keys\":[\"age\",\"sex\",\"height\",\"name\"]\n" + + " }\n" + + " }"; + + String gvtClaimDef = Anoncreds.issuerCreateAndStoreClaimDef(issuerWallet, issuerDid, gvtSchemaJson, null, false).get(); + + //2. Issuer create ClaimDef + String xyzSchemaJson = "{\n" + + " \"seqNo\":2,\n" + + " \"data\": {\n" + + " \"name\":\"xyz\",\n" + + " \"version\":\"1.0\",\n" + + " \"keys\":[\"status\",\"period\"]\n" + + " }\n" + + " }"; + + String xyzClaimDef = Anoncreds.issuerCreateAndStoreClaimDef(issuerWallet, issuerDid, xyzSchemaJson, null, false).get(); + + //3. Prover create Master Secret + String masterSecret = "masterSecretName"; + Anoncreds.proverCreateMasterSecret(proverWallet, masterSecret).get(); + + //4. Prover store Claim Offer received from Issuer + String claimOffer = String.format("{\"issuer_did\":\"%s\", \"schema_seq_no\":%d}", issuerDid, 1); + Anoncreds.proverStoreClaimOffer(proverWallet, claimOffer).get(); + + //5. Prover store Claim Offer received from Issuer + String claimOffer2 = String.format("{\"issuer_did\":\"%s\", \"schema_seq_no\":%d}", issuerDid, 2); + Anoncreds.proverStoreClaimOffer(proverWallet, claimOffer2).get(); + + //6. Prover get Claim Offers + String claimOffersJson = Anoncreds.proverGetClaimOffers(proverWallet, "{}").get(); + + JSONArray claimOffersObject = new JSONArray(claimOffersJson); + assertEquals(2, claimOffersObject.length()); + + JSONObject claimOfferObj1 = claimOffersObject.getJSONObject(0); + JSONObject claimOfferObj2 = claimOffersObject.getJSONObject(1); + + String gvtClaimOffer = claimOfferObj1.getInt("schema_seq_no") == 1 ? claimOfferObj1.toString() : claimOfferObj2.toString(); + String xyzClaimOffer = claimOfferObj1.getInt("schema_seq_no") == 2 ? claimOfferObj1.toString() : claimOfferObj2.toString(); + + + //7. Prover create ClaimReq for GVT Claim Offer + String proverDid = "BzfFCYk"; + String gvtClaimReq = Anoncreds.proverCreateClaimReq(proverWallet, proverDid, gvtClaimOffer, gvtClaimDef, masterSecret).get(); + + //8. Issuer create Claim + String gvtClaimAttributesJson = "{\n" + + " \"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" + + " \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" + + " \"height\":[\"175\",\"175\"],\n" + + " \"age\":[\"28\",\"28\"]\n" + + " }"; + + AnoncredsResults.IssuerCreateClaimResult gvtCreateClaimResult = Anoncreds.issuerCreateClaim(issuerWallet, gvtClaimReq, gvtClaimAttributesJson, - 1, - 1).get(); + String gvtClaimJson = gvtCreateClaimResult.getClaimJson(); + + //9. Prover store Claim + Anoncreds.proverStoreClaim(proverWallet, gvtClaimJson).get(); + + //10. Prover create ClaimReq for GVT Claim Offer + String xyzClaimReq = Anoncreds.proverCreateClaimReq(proverWallet, proverDid, xyzClaimOffer, xyzClaimDef, masterSecret).get(); + + //11. Issuer create Claim + String xyzClaimAttributesJson = "{\n" + + " \"status\":[\"partial\",\"51792877103171595686471452153480627530895\"],\n" + + " \"period\":[\"8\",\"8\"]\n" + + " }"; + + AnoncredsResults.IssuerCreateClaimResult xyzCreateClaimResult = Anoncreds.issuerCreateClaim(issuerWallet, xyzClaimReq, xyzClaimAttributesJson, - 1, - 1).get(); + String xyzClaimJson = xyzCreateClaimResult.getClaimJson(); + + //12. Prover store Claim + Anoncreds.proverStoreClaim(proverWallet, xyzClaimJson).get(); + + //13. Prover gets Claims for Proof Request + String proofRequestJson = "{\n" + + " \"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1,\"name\":\"name\"}},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}," + + " \"predicate2_uuid\":{\"attr_name\":\"period\",\"p_type\":\"GE\",\"value\":5}}\n" + + " }"; + + + String claimsForProofJson = Anoncreds.proverGetClaimsForProofReq(proverWallet, proofRequestJson).get(); + assertNotNull(claimsForProofJson); + + JSONObject claimsForProof = new JSONObject(claimsForProofJson); + JSONArray claimsForAttribute1 = claimsForProof.getJSONObject("attrs").getJSONArray("attr1_uuid"); + JSONArray claimsForPredicate1 = claimsForProof.getJSONObject("predicates").getJSONArray("predicate1_uuid"); + JSONArray claimsForPredicate2 = claimsForProof.getJSONObject("predicates").getJSONArray("predicate2_uuid"); + + assertEquals(claimsForAttribute1.length(), 1); + assertEquals(claimsForPredicate1.length(), 1); + assertEquals(claimsForPredicate2.length(), 1); + + String claimUuidForAttr1 = claimsForAttribute1.getJSONObject(0).getString("claim_uuid"); + String claimUuidForPredicate1 = claimsForPredicate1.getJSONObject(0).getString("claim_uuid"); + String claimUuidForPredicate2 = claimsForPredicate2.getJSONObject(0).getString("claim_uuid"); + + //14. Prover create Proof + String requestedClaimsJson = String.format("{\n" + + " \"self_attested_attributes\":{},\n" + + " \"requested_attrs\":{\"attr1_uuid\":[\"%s\", true]},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":\"%s\"," + + " \"predicate2_uuid\":\"%s\"}\n" + + " }", claimUuidForAttr1, claimUuidForPredicate1, claimUuidForPredicate2); + + String schemasJson = String.format("{\"%s\":%s, \"%s\":%s}", claimUuidForAttr1, gvtSchemaJson, claimUuidForPredicate2, xyzSchemaJson); + String claimDefsJson = String.format("{\"%s\":%s, \"%s\":%s}", claimUuidForAttr1, gvtClaimDef, claimUuidForPredicate2, xyzClaimDef); + + String revocRegsJson = "{}"; + + String proofJson = Anoncreds.proverCreateProof(proverWallet, proofRequestJson, requestedClaimsJson, schemasJson, + masterSecret, claimDefsJson, revocRegsJson).get(); + assertNotNull(proofJson); + + JSONObject proof = new JSONObject(proofJson); + + //15. Verifier verify Proof + assertEquals("Alex", + proof.getJSONObject("requested_proof").getJSONObject("revealed_attrs").getJSONArray("attr1_uuid").getString(1)); + + Boolean valid = Anoncreds.verifierVerifyProof(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson).get(); + assertTrue(valid); + } + + @Test + public void verifyProofWorksForProofDoesNotCorrespondToProofRequest() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + //1. Issuer create ClaimDef + String schemaJson = "{\n" + + " \"seqNo\":1,\n" + + " \"data\": {\n" + + " \"name\":\"gvt\",\n" + + " \"version\":\"1.0\",\n" + + " \"keys\":[\"age\",\"sex\",\"height\",\"name\"]\n" + + " }\n" + + " }"; + String issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; + + String claimDef = Anoncreds.issuerCreateAndStoreClaimDef(issuerWallet, issuerDid, schemaJson, null, false).get(); + assertNotNull(claimDef); + + //2. Prover create Master Secret + String masterSecret = "masterSecretName"; + Anoncreds.proverCreateMasterSecret(proverWallet, masterSecret).get(); + + //3. Prover store Claim Offer + String claimOffer = String.format("{\"issuer_did\":\"%s\", \"schema_seq_no\":%d}", issuerDid, 1); + Anoncreds.proverStoreClaimOffer(proverWallet, claimOffer).get(); + + //4. Prover get Claim Offers + String claimOfferFilter = String.format("{\"issuer_did\":\"%s\"}", issuerDid); + String claimOffersJson = Anoncreds.proverGetClaimOffers(proverWallet, claimOfferFilter).get(); + + JSONArray claimOffersObject = new JSONArray(claimOffersJson); + assertEquals(claimOffersObject.length(), 1); + + JSONObject claimOfferObject = claimOffersObject.getJSONObject(0); + String claimOfferJson = claimOfferObject.toString(); + + //5. Prover create ClaimReq + String proverDid = "BzfFCYk"; + String claimReq = Anoncreds.proverCreateClaimReq(proverWallet, proverDid, claimOfferJson, claimDef, masterSecret).get(); + assertNotNull(claimReq); + + //6. Issuer create Claim + String claimAttributesJson = "{\n" + + " \"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" + + " \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" + + " \"height\":[\"175\",\"175\"],\n" + + " \"age\":[\"28\",\"28\"]\n" + + " }"; + + AnoncredsResults.IssuerCreateClaimResult createClaimResult = Anoncreds.issuerCreateClaim(issuerWallet, claimReq, claimAttributesJson, - 1, - 1).get(); + assertNotNull(createClaimResult); + String claimJson = createClaimResult.getClaimJson(); + + //7. Prover store Claim + Anoncreds.proverStoreClaim(proverWallet, claimJson).get(); + + //8. Prover gets Claims for Proof Request + String proofRequestJson = "{\n" + + " \"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1,\"name\":\"name\"}},\n" + + " \"requested_predicates\":{}\n" + + " }"; + + String claimsForProofJson = Anoncreds.proverGetClaimsForProofReq(proverWallet, proofRequestJson).get(); + assertNotNull(claimsForProofJson); + + JSONObject claimsForProof = new JSONObject(claimsForProofJson); + JSONArray claimsForAttribute1 = claimsForProof.getJSONObject("attrs").getJSONArray("attr1_uuid"); + + assertEquals(claimsForAttribute1.length(), 1); + + String claimUuid = claimsForAttribute1.getJSONObject(0).getString("claim_uuid"); + + //9. Prover create Proof + String selfAttestedValue = "yes"; + String requestedClaimsJson = String.format("{\n" + + " \"self_attested_attributes\":{\"self1\":\"%s\"},\n" + + " \"requested_attrs\":{\"attr1_uuid\":[\"%s\", true],\n" + + " \"attr2_uuid\":[\"%s\", false]},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":\"%s\"}\n" + + " }", selfAttestedValue, claimUuid, claimUuid, claimUuid); + + String schemasJson = String.format("{\"%s\":%s}", claimUuid, schemaJson); + String claimDefsJson = String.format("{\"%s\":%s}", claimUuid, claimDef); + String revocRegsJson = "{}"; + + + String proofJson = Anoncreds.proverCreateProof(proverWallet, proofRequestJson, requestedClaimsJson, schemasJson, + masterSecret, claimDefsJson, revocRegsJson).get(); + assertNotNull(proofJson); + + JSONObject proof = new JSONObject(proofJson); + + //10. Verifier verify Proof + assertEquals("Alex", + proof.getJSONObject("requested_proof").getJSONObject("revealed_attrs").getJSONArray("attr1_uuid").getString(1)); + + assertNotNull(proof.getJSONObject("requested_proof").getJSONObject("unrevealed_attrs").getString("attr2_uuid")); + + assertEquals(selfAttestedValue, proof.getJSONObject("requested_proof").getJSONObject("self_attested_attrs").getString("self1")); + + proofRequestJson = "{\n" + + " \"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1,\"name\":\"name\"}},\n" + + " \"requested_predicates\":{}\n" + + " }"; + + Anoncreds.verifierVerifyProof(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson).get(); + } +} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java index 8b99077e83..c1b3c01fc9 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java @@ -159,353 +159,4 @@ public void testAnoncredsDemo() throws Exception { //16. Close Pool pool.closePoolLedger().get(); } - - @Test - public void anoncredsWorksForMultiplyIssuerSingleProver() throws Exception { - - String issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; - String issuerDid2 = "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"; - - //1. Create and Open Pool - String poolName = PoolUtils.createPoolLedgerConfig(); - - PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); - Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); - - //2. Issuer1 Create and Open Wallet - Wallet.createWallet(poolName, "issuer1Wallet", "default", null, null).get(); - Wallet issuerGvtWallet = Wallet.openWallet("issuer1Wallet", null, null).get(); - - //3. Issuer2 Create and Open Wallet - Wallet.createWallet(poolName, "issuer2Wallet", "default", null, null).get(); - Wallet issuerXyzWallet = Wallet.openWallet("issuer2Wallet", null, null).get(); - - //4. Prover Create and Open Wallet - Wallet.createWallet(poolName, "proverWallet", "default", null, null).get(); - Wallet proverWallet = Wallet.openWallet("proverWallet", null, null).get(); - - //5. Issuer create ClaimDef - String gvtSchemaJson = "{\n" + - " \"seqNo\":1,\n" + - " \"data\": {\n" + - " \"name\":\"gvt\",\n" + - " \"version\":\"1.0\",\n" + - " \"keys\":[\"age\",\"sex\",\"height\",\"name\"]\n" + - " }\n" + - " }"; - - String gvtClaimDef = Anoncreds.issuerCreateAndStoreClaimDef(issuerGvtWallet, issuerDid, gvtSchemaJson, null, false).get(); - - //6. Issuer create ClaimDef - String xyzSchemaJson = "{\n" + - " \"seqNo\":2,\n" + - " \"data\": {\n" + - " \"name\":\"xyz\",\n" + - " \"version\":\"1.0\",\n" + - " \"keys\":[\"status\",\"period\"]\n" + - " }\n" + - " }"; - - String xyzClaimDef = Anoncreds.issuerCreateAndStoreClaimDef(issuerXyzWallet, issuerDid2, xyzSchemaJson, null, false).get(); - - //7. Prover create Master Secret - String masterSecret = "masterSecretName"; - Anoncreds.proverCreateMasterSecret(proverWallet, masterSecret).get(); - - //8. Prover store Claim Offer received from Issuer1 - String claimOffer = String.format("{\"issuer_did\":\"%s\", \"schema_seq_no\":%d}", issuerDid, 1); - Anoncreds.proverStoreClaimOffer(proverWallet, claimOffer).get(); - - //9. Prover store Claim Offer received from Issuer2 - String claimOffer2 = String.format("{\"issuer_did\":\"%s\", \"schema_seq_no\":%d}", issuerDid2, 2); - Anoncreds.proverStoreClaimOffer(proverWallet, claimOffer2).get(); - - //10. Prover get Claim Offers - String claimOffersJson = Anoncreds.proverGetClaimOffers(proverWallet, "{}").get(); - - JSONArray claimOffersObject = new JSONArray(claimOffersJson); - assertEquals(2, claimOffersObject.length()); - - JSONObject claimOfferObj1 = claimOffersObject.getJSONObject(0); - JSONObject claimOfferObj2 = claimOffersObject.getJSONObject(1); - - String gvtClaimOffer = claimOfferObj1.getString("issuer_did").equals(issuerDid) ? claimOfferObj1.toString() : claimOfferObj2.toString(); - String xyzClaimOffer = claimOfferObj1.getString("issuer_did").equals(issuerDid2) ? claimOfferObj1.toString() : claimOfferObj2.toString(); - - - //11. Prover create ClaimReq for GVT Claim Offer - String proverDid = "BzfFCYk"; - String gvtClaimReq = Anoncreds.proverCreateClaimReq(proverWallet, proverDid, gvtClaimOffer, gvtClaimDef, masterSecret).get(); - - //12. Issuer create Claim - String gvtClaimAttributesJson = "{\n" + - " \"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" + - " \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" + - " \"height\":[\"175\",\"175\"],\n" + - " \"age\":[\"28\",\"28\"]\n" + - " }"; - - AnoncredsResults.IssuerCreateClaimResult gvtCreateClaimResult = Anoncreds.issuerCreateClaim(issuerGvtWallet, gvtClaimReq, gvtClaimAttributesJson, - 1, - 1).get(); - String gvtClaimJson = gvtCreateClaimResult.getClaimJson(); - - //13. Prover store Claim - Anoncreds.proverStoreClaim(proverWallet, gvtClaimJson).get(); - - //14. Prover create ClaimReq for GVT Claim Offer - String xyzClaimReq = Anoncreds.proverCreateClaimReq(proverWallet, proverDid, xyzClaimOffer, xyzClaimDef, masterSecret).get(); - - //15. Issuer create Claim - String xyzClaimAttributesJson = "{\n" + - " \"status\":[\"partial\",\"51792877103171595686471452153480627530895\"],\n" + - " \"period\":[\"8\",\"8\"]\n" + - " }"; - - AnoncredsResults.IssuerCreateClaimResult xyzCreateClaimResult = Anoncreds.issuerCreateClaim(issuerXyzWallet, xyzClaimReq, xyzClaimAttributesJson, - 1, - 1).get(); - String xyzClaimJson = xyzCreateClaimResult.getClaimJson(); - - //16. Prover store Claim - Anoncreds.proverStoreClaim(proverWallet, xyzClaimJson).get(); - - //17. Prover gets Claims for Proof Request - String proofRequestJson = "{\n" + - " \"nonce\":\"123432421212\",\n" + - " \"name\":\"proof_req_1\",\n" + - " \"version\":\"0.1\",\n" + - " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1,\"name\":\"name\"},\n" + - " \"attr2_uuid\":{\"schema_seq_no\":2,\"name\":\"status\"}},\n" + - " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}," + - " \"predicate2_uuid\":{\"attr_name\":\"period\",\"p_type\":\"GE\",\"value\":5}}\n" + - " }"; - - - String claimsForProofJson = Anoncreds.proverGetClaimsForProofReq(proverWallet, proofRequestJson).get(); - assertNotNull(claimsForProofJson); - - JSONObject claimsForProof = new JSONObject(claimsForProofJson); - JSONArray claimsForAttribute1 = claimsForProof.getJSONObject("attrs").getJSONArray("attr1_uuid"); - JSONArray claimsForAttribute2 = claimsForProof.getJSONObject("attrs").getJSONArray("attr2_uuid"); - JSONArray claimsForPredicate1 = claimsForProof.getJSONObject("predicates").getJSONArray("predicate1_uuid"); - JSONArray claimsForPredicate2 = claimsForProof.getJSONObject("predicates").getJSONArray("predicate2_uuid"); - - assertEquals(claimsForAttribute1.length(), 1); - assertEquals(claimsForAttribute2.length(), 1); - assertEquals(claimsForPredicate1.length(), 1); - assertEquals(claimsForPredicate2.length(), 1); - - String claimUuidForAttr1 = claimsForAttribute1.getJSONObject(0).getString("claim_uuid"); - String claimUuidForAttr2 = claimsForAttribute2.getJSONObject(0).getString("claim_uuid"); - String claimUuidForPredicate1 = claimsForPredicate1.getJSONObject(0).getString("claim_uuid"); - String claimUuidForPredicate2 = claimsForPredicate2.getJSONObject(0).getString("claim_uuid"); - - //18. Prover create Proof - String requestedClaimsJson = String.format("{\n" + - " \"self_attested_attributes\":{},\n" + - " \"requested_attrs\":{\"attr1_uuid\":[\"%s\", true],\n" + - " \"attr2_uuid\":[\"%s\", true]},\n" + - " \"requested_predicates\":{\"predicate1_uuid\":\"%s\"," + - " \"predicate2_uuid\":\"%s\"}\n" + - " }", claimUuidForAttr1, claimUuidForAttr2, claimUuidForPredicate1, claimUuidForPredicate2); - - String schemasJson = String.format("{\"%s\":%s, \"%s\":%s}", claimUuidForAttr1, gvtSchemaJson, claimUuidForAttr2, xyzSchemaJson); - String claimDefsJson = String.format("{\"%s\":%s, \"%s\":%s}", claimUuidForAttr1, gvtClaimDef, claimUuidForAttr2, xyzClaimDef); - - String revocRegsJson = "{}"; - - String proofJson = Anoncreds.proverCreateProof(proverWallet, proofRequestJson, requestedClaimsJson, schemasJson, - masterSecret, claimDefsJson, revocRegsJson).get(); - assertNotNull(proofJson); - - JSONObject proof = new JSONObject(proofJson); - - //19. Verifier verify Proof - assertEquals("Alex", - proof.getJSONObject("requested_proof").getJSONObject("revealed_attrs").getJSONArray("attr1_uuid").getString(1)); - - assertEquals("partial", - proof.getJSONObject("requested_proof").getJSONObject("revealed_attrs").getJSONArray("attr2_uuid").getString(1)); - - Boolean valid = Anoncreds.verifierVerifyProof(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson).get(); - assertTrue(valid); - - //20. Close and delete Issuer1 Wallet - issuerGvtWallet.closeWallet().get(); - Wallet.deleteWallet("issuer1Wallet", null).get(); - - //21. Close and delete Issuer2 Wallet - issuerXyzWallet.closeWallet().get(); - Wallet.deleteWallet("issuer2Wallet", null).get(); - - //22. Close and delete Prover Wallet - proverWallet.closeWallet().get(); - Wallet.deleteWallet("proverWallet", null).get(); - - //23. Close Pool - pool.closePoolLedger().get(); - } - - @Test - public void anoncredsWorksForSingleIssuerSingleProver() throws Exception { - - String issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; - - //1. Create and Open Pool - String poolName = PoolUtils.createPoolLedgerConfig(); - - PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); - Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); - - //2. Issuer Create and Open Wallet - Wallet.createWallet(poolName, "issuerWallet", "default", null, null).get(); - Wallet issuerWallet = Wallet.openWallet("issuerWallet", null, null).get(); - - //3. Prover Create and Open Wallet - Wallet.createWallet(poolName, "proverWallet", "default", null, null).get(); - Wallet proverWallet = Wallet.openWallet("proverWallet", null, null).get(); - - //4. Issuer create ClaimDef - String gvtSchemaJson = "{\n" + - " \"seqNo\":1,\n" + - " \"data\": {\n" + - " \"name\":\"gvt\",\n" + - " \"version\":\"1.0\",\n" + - " \"keys\":[\"age\",\"sex\",\"height\",\"name\"]\n" + - " }\n" + - " }"; - - String gvtClaimDef = Anoncreds.issuerCreateAndStoreClaimDef(issuerWallet, issuerDid, gvtSchemaJson, null, false).get(); - - //5. Issuer create ClaimDef - String xyzSchemaJson = "{\n" + - " \"seqNo\":2,\n" + - " \"data\": {\n" + - " \"name\":\"xyz\",\n" + - " \"version\":\"1.0\",\n" + - " \"keys\":[\"status\",\"period\"]\n" + - " }\n" + - " }"; - - String xyzClaimDef = Anoncreds.issuerCreateAndStoreClaimDef(issuerWallet, issuerDid, xyzSchemaJson, null, false).get(); - - //6. Prover create Master Secret - String masterSecret = "masterSecretName"; - Anoncreds.proverCreateMasterSecret(proverWallet, masterSecret).get(); - - //7. Prover store Claim Offer received from Issuer - String claimOffer = String.format("{\"issuer_did\":\"%s\", \"schema_seq_no\":%d}", issuerDid, 1); - Anoncreds.proverStoreClaimOffer(proverWallet, claimOffer).get(); - - //8. Prover store Claim Offer received from Issuer - String claimOffer2 = String.format("{\"issuer_did\":\"%s\", \"schema_seq_no\":%d}", issuerDid, 2); - Anoncreds.proverStoreClaimOffer(proverWallet, claimOffer2).get(); - - //9. Prover get Claim Offers - String claimOffersJson = Anoncreds.proverGetClaimOffers(proverWallet, "{}").get(); - - JSONArray claimOffersObject = new JSONArray(claimOffersJson); - assertEquals(2, claimOffersObject.length()); - - JSONObject claimOfferObj1 = claimOffersObject.getJSONObject(0); - JSONObject claimOfferObj2 = claimOffersObject.getJSONObject(1); - - String gvtClaimOffer = claimOfferObj1.getInt("schema_seq_no") == 1 ? claimOfferObj1.toString() : claimOfferObj2.toString(); - String xyzClaimOffer = claimOfferObj1.getInt("schema_seq_no") == 2 ? claimOfferObj1.toString() : claimOfferObj2.toString(); - - - //10. Prover create ClaimReq for GVT Claim Offer - String proverDid = "BzfFCYk"; - String gvtClaimReq = Anoncreds.proverCreateClaimReq(proverWallet, proverDid, gvtClaimOffer, gvtClaimDef, masterSecret).get(); - - //11. Issuer create Claim - String gvtClaimAttributesJson = "{\n" + - " \"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" + - " \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" + - " \"height\":[\"175\",\"175\"],\n" + - " \"age\":[\"28\",\"28\"]\n" + - " }"; - - AnoncredsResults.IssuerCreateClaimResult gvtCreateClaimResult = Anoncreds.issuerCreateClaim(issuerWallet, gvtClaimReq, gvtClaimAttributesJson, - 1, - 1).get(); - String gvtClaimJson = gvtCreateClaimResult.getClaimJson(); - - //12. Prover store Claim - Anoncreds.proverStoreClaim(proverWallet, gvtClaimJson).get(); - - //13. Prover create ClaimReq for GVT Claim Offer - String xyzClaimReq = Anoncreds.proverCreateClaimReq(proverWallet, proverDid, xyzClaimOffer, xyzClaimDef, masterSecret).get(); - - //14. Issuer create Claim - String xyzClaimAttributesJson = "{\n" + - " \"status\":[\"partial\",\"51792877103171595686471452153480627530895\"],\n" + - " \"period\":[\"8\",\"8\"]\n" + - " }"; - - AnoncredsResults.IssuerCreateClaimResult xyzCreateClaimResult = Anoncreds.issuerCreateClaim(issuerWallet, xyzClaimReq, xyzClaimAttributesJson, - 1, - 1).get(); - String xyzClaimJson = xyzCreateClaimResult.getClaimJson(); - - //15. Prover store Claim - Anoncreds.proverStoreClaim(proverWallet, xyzClaimJson).get(); - - //16. Prover gets Claims for Proof Request - String proofRequestJson = "{\n" + - " \"nonce\":\"123432421212\",\n" + - " \"name\":\"proof_req_1\",\n" + - " \"version\":\"0.1\",\n" + - " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1,\"name\":\"name\"}},\n" + - " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}," + - " \"predicate2_uuid\":{\"attr_name\":\"period\",\"p_type\":\"GE\",\"value\":5}}\n" + - " }"; - - - String claimsForProofJson = Anoncreds.proverGetClaimsForProofReq(proverWallet, proofRequestJson).get(); - assertNotNull(claimsForProofJson); - - JSONObject claimsForProof = new JSONObject(claimsForProofJson); - JSONArray claimsForAttribute1 = claimsForProof.getJSONObject("attrs").getJSONArray("attr1_uuid"); - JSONArray claimsForPredicate1 = claimsForProof.getJSONObject("predicates").getJSONArray("predicate1_uuid"); - JSONArray claimsForPredicate2 = claimsForProof.getJSONObject("predicates").getJSONArray("predicate2_uuid"); - - assertEquals(claimsForAttribute1.length(), 1); - assertEquals(claimsForPredicate1.length(), 1); - assertEquals(claimsForPredicate2.length(), 1); - - String claimUuidForAttr1 = claimsForAttribute1.getJSONObject(0).getString("claim_uuid"); - String claimUuidForPredicate1 = claimsForPredicate1.getJSONObject(0).getString("claim_uuid"); - String claimUuidForPredicate2 = claimsForPredicate2.getJSONObject(0).getString("claim_uuid"); - - //17. Prover create Proof - String requestedClaimsJson = String.format("{\n" + - " \"self_attested_attributes\":{},\n" + - " \"requested_attrs\":{\"attr1_uuid\":[\"%s\", true]},\n" + - " \"requested_predicates\":{\"predicate1_uuid\":\"%s\"," + - " \"predicate2_uuid\":\"%s\"}\n" + - " }", claimUuidForAttr1, claimUuidForPredicate1, claimUuidForPredicate2); - - String schemasJson = String.format("{\"%s\":%s, \"%s\":%s}", claimUuidForAttr1, gvtSchemaJson, claimUuidForPredicate2, xyzSchemaJson); - String claimDefsJson = String.format("{\"%s\":%s, \"%s\":%s}", claimUuidForAttr1, gvtClaimDef, claimUuidForPredicate2, xyzClaimDef); - - String revocRegsJson = "{}"; - - String proofJson = Anoncreds.proverCreateProof(proverWallet, proofRequestJson, requestedClaimsJson, schemasJson, - masterSecret, claimDefsJson, revocRegsJson).get(); - assertNotNull(proofJson); - - JSONObject proof = new JSONObject(proofJson); - - //18. Verifier verify Proof - assertEquals("Alex", - proof.getJSONObject("requested_proof").getJSONObject("revealed_attrs").getJSONArray("attr1_uuid").getString(1)); - - Boolean valid = Anoncreds.verifierVerifyProof(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson).get(); - assertTrue(valid); - - //19. Close and delete Issuer Wallet - issuerWallet.closeWallet().get(); - Wallet.deleteWallet("issuerWallet", null).get(); - - //21. Close and delete Their Wallet - proverWallet.closeWallet().get(); - Wallet.deleteWallet("proverWallet", null).get(); - - //22. Close Pool - pool.closePoolLedger().get(); - } } From be9977205ea15bba0bb0920ddafa296b618df5e4 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 19 Jul 2017 09:15:47 +0300 Subject: [PATCH 219/349] Corrected imports --- .../sdk/anoncreds/IssuerCreateClaimTest.java | 9 ++++---- .../anoncreds/ProverGetClaimOfferTest.java | 23 +++++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateClaimTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateClaimTest.java index c4c710849e..d6619d8cac 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateClaimTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateClaimTest.java @@ -8,6 +8,7 @@ import java.util.concurrent.ExecutionException; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class IssuerCreateClaimTest extends AnoncredsIntegrationTest { @@ -32,10 +33,10 @@ public void testProverCreateAndStoreClaimReqWorks() throws Exception { JSONObject primaryClaim = claimObj.getJSONObject("signature").getJSONObject("primary_claim"); - Assert.assertTrue(primaryClaim.getString("a").length() > 0); - Assert.assertTrue(primaryClaim.getString("m2").length() > 0); - Assert.assertTrue(primaryClaim.getString("e").length() > 0); - Assert.assertTrue(primaryClaim.getString("v").length() > 0); + assertTrue(primaryClaim.getString("a").length() > 0); + assertTrue(primaryClaim.getString("m2").length() > 0); + assertTrue(primaryClaim.getString("e").length() > 0); + assertTrue(primaryClaim.getString("v").length() > 0); } @Test diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimOfferTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimOfferTest.java index 25265d73e0..4b49e02b68 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimOfferTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimOfferTest.java @@ -7,6 +7,9 @@ import java.util.concurrent.ExecutionException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + public class ProverGetClaimOfferTest extends AnoncredsIntegrationTest { @Test @@ -17,7 +20,7 @@ public void testsProverGetClaimOffersWorksForEmptyFilter() throws Exception { String claimOffers = Anoncreds.proverGetClaimOffers(wallet, "{}").get(); JSONArray claimOffersArray = new JSONArray(claimOffers); - Assert.assertEquals(3, claimOffersArray.length()); + assertEquals(3, claimOffersArray.length()); } @Test @@ -30,10 +33,10 @@ public void testsProverGetClaimOffersWorksForFilterByIssuer() throws Exception { String claimOffers = Anoncreds.proverGetClaimOffers(wallet, filter).get(); JSONArray claimOffersArray = new JSONArray(claimOffers); - Assert.assertEquals(2, claimOffersArray.length()); + assertEquals(2, claimOffersArray.length()); - Assert.assertTrue(claimOffersArray.toString().contains(String.format(claimOfferTemplate, issuerDid, 1))); - Assert.assertTrue(claimOffersArray.toString().contains(String.format(claimOfferTemplate, issuerDid, 2))); + assertTrue(claimOffersArray.toString().contains(String.format(claimOfferTemplate, issuerDid, 1))); + assertTrue(claimOffersArray.toString().contains(String.format(claimOfferTemplate, issuerDid, 2))); } @Test @@ -46,10 +49,10 @@ public void testsProverGetClaimOffersWorksForFilterBySchema() throws Exception { String claimOffers = Anoncreds.proverGetClaimOffers(wallet, filter).get(); JSONArray claimOffersArray = new JSONArray(claimOffers); - Assert.assertEquals(2, claimOffersArray.length()); + assertEquals(2, claimOffersArray.length()); - Assert.assertTrue(claimOffersArray.toString().contains(String.format(claimOfferTemplate, issuerDid, 2))); - Assert.assertTrue(claimOffersArray.toString().contains(String.format(claimOfferTemplate, issuerDid2, 2))); + assertTrue(claimOffersArray.toString().contains(String.format(claimOfferTemplate, issuerDid, 2))); + assertTrue(claimOffersArray.toString().contains(String.format(claimOfferTemplate, issuerDid2, 2))); } @Test @@ -62,9 +65,9 @@ public void testsProverGetClaimOffersWorksForFilterByIssuerAndSchema() throws Ex String claimOffers = Anoncreds.proverGetClaimOffers(wallet, filter).get(); JSONArray claimOffersArray = new JSONArray(claimOffers); - Assert.assertEquals(1, claimOffersArray.length()); + assertEquals(1, claimOffersArray.length()); - Assert.assertTrue(claimOffersArray.toString().contains(String.format(claimOfferTemplate, issuerDid, 1))); + assertTrue(claimOffersArray.toString().contains(String.format(claimOfferTemplate, issuerDid, 1))); } @Test @@ -77,7 +80,7 @@ public void testsProverGetClaimOffersWorksForNoResult() throws Exception { String claimOffers = Anoncreds.proverGetClaimOffers(wallet, filter).get(); JSONArray claimOffersArray = new JSONArray(claimOffers); - Assert.assertEquals(0, claimOffersArray.length()); + assertEquals(0, claimOffersArray.length()); } @Test From 8ac107635e96ded4801ed4c865cb2d1dd9c86a33 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 19 Jul 2017 10:58:45 +0300 Subject: [PATCH 220/349] added test for build_get_schema_request --- .../ledger/test_build_get_schema_request.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 wrappers/python/tests/ledger/test_build_get_schema_request.py diff --git a/wrappers/python/tests/ledger/test_build_get_schema_request.py b/wrappers/python/tests/ledger/test_build_get_schema_request.py new file mode 100644 index 0000000000..ce1addf24e --- /dev/null +++ b/wrappers/python/tests/ledger/test_build_get_schema_request.py @@ -0,0 +1,36 @@ +from tests.utils import storage +from indy import ledger + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_build_get_schema_requests_works_for_correct_data_json(): + identifier = "identifier" + data = '{"name":"name","version":"1.0"}' + + expected_response = { + "identifier": "identifier", + "operation": { + "type": "107", + "dest": "identifier", + "data": { + "name": "name", + "version": "1.0" + } + } + } + + response = json.loads((await ledger.build_get_schema_request(identifier, identifier, data)).decode()) + assert expected_response.items() <= response.items() From 517df65bc2a1fc3ac33b36e5c618c6d6ed5cb18b Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 19 Jul 2017 11:12:04 +0300 Subject: [PATCH 221/349] added test for build_claim_def --- .../ledger/test_build_claim_def_request.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 wrappers/python/tests/ledger/test_build_claim_def_request.py diff --git a/wrappers/python/tests/ledger/test_build_claim_def_request.py b/wrappers/python/tests/ledger/test_build_claim_def_request.py new file mode 100644 index 0000000000..3c0555caa6 --- /dev/null +++ b/wrappers/python/tests/ledger/test_build_claim_def_request.py @@ -0,0 +1,47 @@ +from tests.utils import storage +from indy import ledger + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_build_claim_def_request_works_for_correct_data_json(): + identifier = "identifier" + signature_type = "CL" + schema_seq_no = 1 + data = { + "primary": { + "n": "1", + "s": "2", + "rms": "3", + "r": { + "name": "1" + }, + "rctxt": "1", + "z": "1" + } + } + + expected_response = { + "identifier": "identifier", + "operation": {"ref": 1, + "data": '{"primary": {"n": "1", "s": "2", "rms": "3",' + ' "r": {"name": "1"}, "rctxt": "1", "z": "1"}}', + "type": "102", + "signature_type": "CL"}} + + response = json.loads((await ledger.build_claim_def_txn( + identifier, schema_seq_no, signature_type, json.dumps(data) + )).decode()) + assert expected_response.items() <= response.items() From cd0d58ec6fa68755423e89d9646ab056395aef0b Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 19 Jul 2017 11:18:27 +0300 Subject: [PATCH 222/349] added test for build_get_claim_def_txn --- ...request.py => test_build_claim_def_txn.py} | 0 .../ledger/test_build_get_claim_def_txn.py | 38 +++++++++++++++++++ 2 files changed, 38 insertions(+) rename wrappers/python/tests/ledger/{test_build_claim_def_request.py => test_build_claim_def_txn.py} (100%) create mode 100644 wrappers/python/tests/ledger/test_build_get_claim_def_txn.py diff --git a/wrappers/python/tests/ledger/test_build_claim_def_request.py b/wrappers/python/tests/ledger/test_build_claim_def_txn.py similarity index 100% rename from wrappers/python/tests/ledger/test_build_claim_def_request.py rename to wrappers/python/tests/ledger/test_build_claim_def_txn.py diff --git a/wrappers/python/tests/ledger/test_build_get_claim_def_txn.py b/wrappers/python/tests/ledger/test_build_get_claim_def_txn.py new file mode 100644 index 0000000000..589e9d40da --- /dev/null +++ b/wrappers/python/tests/ledger/test_build_get_claim_def_txn.py @@ -0,0 +1,38 @@ +from tests.utils import storage +from indy import ledger + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_build_get_claim_def_request_works(): + identifier = "identifier" + _ref = 1 + signature_type = "signature_type" + origin = "origin" + + expected_response = { + "identifier": "identifier", + "operation": { + "type": "108", + "ref": 1, + "signature_type": "signature_type", + "origin": "origin" + } + } + + response = json.loads((await ledger.build_get_claim_def_txn( + identifier, _ref, signature_type, origin + )).decode()) + assert expected_response.items() <= response.items() From a05d61457be90833d47f56eb82c3632ebdd7e94d Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 19 Jul 2017 11:24:11 +0300 Subject: [PATCH 223/349] added test for build_node_request --- .../tests/ledger/test_build_node_request.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 wrappers/python/tests/ledger/test_build_node_request.py diff --git a/wrappers/python/tests/ledger/test_build_node_request.py b/wrappers/python/tests/ledger/test_build_node_request.py new file mode 100644 index 0000000000..613e5d9f12 --- /dev/null +++ b/wrappers/python/tests/ledger/test_build_node_request.py @@ -0,0 +1,35 @@ +from tests.utils import storage +from indy import ledger +from indy.error import ErrorCode, IndyError + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_build_node_request_works_for_missed_field_in_data_json(): + identifier = "identifier" + destination = "destination" + data = { + "node_ip": "ip", + "node_port": 1, + "client_ip": "ip", + "client_port": 1 + } + + try: + await ledger.build_node_request(identifier, destination, json.dumps(data)) + raise Exception("Failed") + except Exception as e: + assert type(IndyError(ErrorCode.CommonInvalidStructure)) == type(e) and \ + IndyError(ErrorCode.CommonInvalidStructure).args == e.args From 18f42d30d59f46c8185648b699c49100030121ca Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 19 Jul 2017 11:30:32 +0300 Subject: [PATCH 224/349] added test for build_get_txn_request --- wrappers/python/indy/ledger.py | 4 +-- .../ledger/test_build_get_txn_request.py | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 wrappers/python/tests/ledger/test_build_get_txn_request.py diff --git a/wrappers/python/indy/ledger.py b/wrappers/python/indy/ledger.py index 3968896d89..2cc7d3b7ec 100644 --- a/wrappers/python/indy/ledger.py +++ b/wrappers/python/indy/ledger.py @@ -342,7 +342,7 @@ async def build_node_request(submitter_did: str, async def build_get_txn_request(submitter_did: str, - data: str) -> str: + data: int) -> str: logger = logging.getLogger(__name__) logger.debug("build_get_txn_request: >>> submitter_did: %s, data: %s", submitter_did, @@ -353,7 +353,7 @@ async def build_get_txn_request(submitter_did: str, build_get_txn_request.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) c_submitter_did = c_char_p(submitter_did.encode('utf-8')) - c_data = c_char_p(data.encode('utf-8')) + c_data = c_int32(data) res = await do_call('indy_build_get_txn_request', build_get_txn_request.cb, diff --git a/wrappers/python/tests/ledger/test_build_get_txn_request.py b/wrappers/python/tests/ledger/test_build_get_txn_request.py new file mode 100644 index 0000000000..1b4f5e73c3 --- /dev/null +++ b/wrappers/python/tests/ledger/test_build_get_txn_request.py @@ -0,0 +1,30 @@ +from tests.utils import storage +from indy import ledger + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_build_get_txn_request_works(): + identifier = "identifier" + data = 1 + expected_response = { + "identifier": "identifier", + "operation": { + "type": "3", "data": 1 + } + } + + response = json.loads((await ledger.build_get_txn_request(identifier, data)).decode()) + assert expected_response.items() <= response.items() From 5244bfd8e7677acf435f95d28ac815c54fcd5eb5 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 19 Jul 2017 11:59:24 +0300 Subject: [PATCH 225/349] changed default values for create_and_open_wallet function --- wrappers/python/tests/utils/wallet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrappers/python/tests/utils/wallet.py b/wrappers/python/tests/utils/wallet.py index e62cc4a591..2d3f5d48b1 100644 --- a/wrappers/python/tests/utils/wallet.py +++ b/wrappers/python/tests/utils/wallet.py @@ -1,6 +1,6 @@ from indy import wallet -async def create_and_open_wallet(pool_name="indy_open_wallet_works", wallet_name="indy_open_wallet_works"): +async def create_and_open_wallet(pool_name="pool_type_1", wallet_name="wallet_type_1"): await wallet.create_wallet(pool_name, wallet_name, None, None, None) wallet_handle = await wallet.open_wallet(wallet_name, None, None) assert wallet_handle is not None From 7e89dc9992387ba53ac2b6c0576e9e72b8e033c0 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 19 Jul 2017 12:12:49 +0300 Subject: [PATCH 226/349] changed default values --- wrappers/python/tests/utils/wallet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrappers/python/tests/utils/wallet.py b/wrappers/python/tests/utils/wallet.py index 2d3f5d48b1..883ba78bc3 100644 --- a/wrappers/python/tests/utils/wallet.py +++ b/wrappers/python/tests/utils/wallet.py @@ -1,6 +1,6 @@ from indy import wallet -async def create_and_open_wallet(pool_name="pool_type_1", wallet_name="wallet_type_1"): +async def create_and_open_wallet(pool_name="pool_1", wallet_name="wallet_1"): await wallet.create_wallet(pool_name, wallet_name, None, None, None) wallet_handle = await wallet.open_wallet(wallet_name, None, None) assert wallet_handle is not None From 6c1dc8d4d9dcf7499e9689b3ca83ecef9131c3af Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 19 Jul 2017 14:04:52 +0300 Subject: [PATCH 227/349] added test for submit submit_request --- .../ledger/test_sign_and_submit_request.py | 4 +-- .../tests/ledger/test_submit_request.py | 28 +++++++++++++++++-- .../tests/pool/test_close_pool_ledger.py | 2 +- .../tests/pool/test_refresh_pool_ledger.py | 2 +- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/wrappers/python/tests/ledger/test_sign_and_submit_request.py b/wrappers/python/tests/ledger/test_sign_and_submit_request.py index 7324db1f9b..28dfb630eb 100644 --- a/wrappers/python/tests/ledger/test_sign_and_submit_request.py +++ b/wrappers/python/tests/ledger/test_sign_and_submit_request.py @@ -17,14 +17,14 @@ def before_after_each(): @pytest.fixture async def pool_handle(): - handle = await pool.create_and_open_pool_ledger("pool_name") + handle = await pool.create_and_open_pool_ledger("pool_1") yield handle await close_pool_ledger(handle) @pytest.fixture async def wallet_handle(): - handle = await create_and_open_wallet(pool_name="pool_name") + handle = await create_and_open_wallet() yield handle await wallet.close_wallet(handle) diff --git a/wrappers/python/tests/ledger/test_submit_request.py b/wrappers/python/tests/ledger/test_submit_request.py index 3c10e88d9e..1ff8834821 100644 --- a/wrappers/python/tests/ledger/test_submit_request.py +++ b/wrappers/python/tests/ledger/test_submit_request.py @@ -1,6 +1,8 @@ from tests.utils import pool, storage -from indy import ledger +from tests.utils.wallet import create_and_open_wallet +from indy import ledger, wallet, signus from indy.pool import close_pool_ledger +from indy.error import ErrorCode, IndyError import json import pytest @@ -16,9 +18,16 @@ def before_after_each(): storage.cleanup() +@pytest.fixture +async def wallet_handle(): + handle = await create_and_open_wallet() + yield handle + await wallet.close_wallet(handle) + + @pytest.fixture async def pool_handle(): - handle = await pool.create_and_open_pool_ledger("pool_name") + handle = await pool.create_and_open_pool_ledger("pool_1") yield handle await close_pool_ledger(handle) @@ -48,3 +57,18 @@ async def test_submit_request_works(pool_handle): } response = json.loads((await ledger.submit_request(pool_handle, json.dumps(request))).decode()) assert response == expected_response + + +@pytest.mark.asyncio +async def test_submit_request_works_for_invalid_pool_handle(pool_handle, wallet_handle): + (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"000000000000000000000000Trustee1"}') + + get_nym_request = await ledger.build_get_nym_request(my_did.decode(), my_did.decode()) + invalid_pool_handle = pool_handle + 1 + try: + await ledger.submit_request(invalid_pool_handle, get_nym_request.decode()) + raise Exception("Failed") + except Exception as e: + assert type(IndyError(ErrorCode.PoolLedgerInvalidPoolHandle)) == type(e) and \ + IndyError(ErrorCode.PoolLedgerInvalidPoolHandle).args == e.args diff --git a/wrappers/python/tests/pool/test_close_pool_ledger.py b/wrappers/python/tests/pool/test_close_pool_ledger.py index 10253bed77..39b2823efc 100644 --- a/wrappers/python/tests/pool/test_close_pool_ledger.py +++ b/wrappers/python/tests/pool/test_close_pool_ledger.py @@ -15,5 +15,5 @@ def before_after_each(): @pytest.mark.asyncio async def test_close_pool_ledger_works(): - handle = await pool.create_and_open_pool_ledger("pool_name") + handle = await pool.create_and_open_pool_ledger("pool_1") await close_pool_ledger(handle) diff --git a/wrappers/python/tests/pool/test_refresh_pool_ledger.py b/wrappers/python/tests/pool/test_refresh_pool_ledger.py index d89a2c6315..6e18f6c03b 100644 --- a/wrappers/python/tests/pool/test_refresh_pool_ledger.py +++ b/wrappers/python/tests/pool/test_refresh_pool_ledger.py @@ -15,5 +15,5 @@ def before_after_each(): @pytest.mark.asyncio async def test_refresh_pool_ledger_works(): - handle = await pool.create_and_open_pool_ledger("pool_name") + handle = await pool.create_and_open_pool_ledger("pool_1") await refresh_pool_ledger(handle) From 1188147f65fb480bdca739ab7d18cd565df46812 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 19 Jul 2017 14:17:54 +0300 Subject: [PATCH 228/349] added tests for sign_and_submit --- .../ledger/test_sign_and_submit_request.py | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/wrappers/python/tests/ledger/test_sign_and_submit_request.py b/wrappers/python/tests/ledger/test_sign_and_submit_request.py index 28dfb630eb..5a083744ad 100644 --- a/wrappers/python/tests/ledger/test_sign_and_submit_request.py +++ b/wrappers/python/tests/ledger/test_sign_and_submit_request.py @@ -2,6 +2,7 @@ from tests.utils.wallet import create_and_open_wallet from indy import wallet, signus, ledger from indy.pool import close_pool_ledger +from indy.error import ErrorCode, IndyError import pytest import logging @@ -36,3 +37,55 @@ async def test_sign_and_submit_request_works(wallet_handle, pool_handle): '{"seed":"000000000000000000000000Trustee1"}') nym_request = await ledger.build_nym_request(trustee_did.decode(), my_did.decode(), None, None, None) await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did.decode(), nym_request.decode()) + + +@pytest.mark.asyncio +async def test_sign_and_submit_request_works_for_invalid_pool_handle(wallet_handle, pool_handle): + (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') + (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"000000000000000000000000Trustee1"}') + nym_request = await ledger.build_nym_request(trustee_did.decode(), my_did.decode(), None, None, None) + invalid_pool_handle = pool_handle + 1 + + try: + await ledger.sign_and_submit_request(invalid_pool_handle, wallet_handle, trustee_did.decode(), + nym_request.decode()) + raise Exception("Failed") + except Exception as e: + assert type(IndyError(ErrorCode.PoolLedgerInvalidPoolHandle)) == type(e) and \ + IndyError(ErrorCode.PoolLedgerInvalidPoolHandle).args == e.args + + +@pytest.mark.asyncio +async def test_sign_and_submit_request_works_for_invalid_wallet_handle(wallet_handle, pool_handle): + (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') + (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"000000000000000000000000Trustee1"}') + nym_request = await ledger.build_nym_request(trustee_did.decode(), my_did.decode(), None, None, None) + invalid_wallet_handle = wallet_handle + 1 + + try: + await ledger.sign_and_submit_request(pool_handle, invalid_wallet_handle, trustee_did.decode(), + nym_request.decode()) + raise Exception("Failed") + except Exception as e: + assert type(IndyError(ErrorCode.WalletInvalidHandle)) == type(e) and \ + IndyError(ErrorCode.WalletInvalidHandle).args == e.args + + +@pytest.mark.asyncio +async def test_sign_and_submit_request_works_for_incompatible_wallet_and_pool(pool_handle): + wallet_handle = await create_and_open_wallet(pool_name="pool_2") + (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') + (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"000000000000000000000000Trustee1"}') + nym_request = await ledger.build_nym_request(trustee_did.decode(), my_did.decode(), None, None, None) + + try: + await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did.decode(), + nym_request.decode()) + raise Exception("Failed") + except Exception as e: + assert type(IndyError(ErrorCode.WalletIncompatiblePoolError)) == type(e) and \ + IndyError(ErrorCode.WalletIncompatiblePoolError).args == e.args + await wallet.close_wallet(wallet_handle) From 228b70b58f752cf6291a37b289bbe0b06a70b4d7 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 19 Jul 2017 14:40:26 +0300 Subject: [PATCH 229/349] added tests for build_nym_request --- .../tests/ledger/test_build_nym_request.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/wrappers/python/tests/ledger/test_build_nym_request.py b/wrappers/python/tests/ledger/test_build_nym_request.py index 2fd9d46064..022a7e959c 100644 --- a/wrappers/python/tests/ledger/test_build_nym_request.py +++ b/wrappers/python/tests/ledger/test_build_nym_request.py @@ -2,6 +2,7 @@ from indy import ledger from indy.error import ErrorCode, IndyError +import json import pytest import logging @@ -26,3 +27,43 @@ async def test_build_nym_request_works_for_invalid_identifier(): except Exception as e: assert type(IndyError(ErrorCode.CommonInvalidStructure)) == type(e) and \ IndyError(ErrorCode.CommonInvalidStructure).args == e.args + + +@pytest.mark.asyncio +async def test_build_nym_request_works_for_only_required_fields(): + identifier = "Th7MpTaRZVRYnPiabds81Y" + destination = "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4" + + expected_response = { + "identifier": identifier, + "operation": { + "type": "1", + "dest": destination + } + } + + response = json.loads((await ledger.build_nym_request(identifier, destination, None, None, None)).decode()) + assert expected_response.items() <= response.items() + + +@pytest.mark.asyncio +async def test_build_nym_request_works_with_option_fields(): + identifier = "Th7MpTaRZVRYnPiabds81Y" + destination = "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4" + ver_key = "Anfh2rjAcxkE249DcdsaQl" + role = "STEWARD" + alias = "some_alias" + + expected_response = { + "identifier": identifier, + "operation": { + "type": "1", + "dest": destination, + "verkey": ver_key, + "alias": alias, + "role": "2" + } + } + + response = json.loads((await ledger.build_nym_request(identifier, destination, ver_key, alias, role)).decode()) + assert expected_response.items() <= response.items() \ No newline at end of file From c30ef389408207a4302f2b6e3333ccb9a5f80faf Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 19 Jul 2017 14:43:09 +0300 Subject: [PATCH 230/349] Implemented AgentApi integration tests for Java wrapper --- .../org/hyperledger/indy/sdk/AgentTest.java | 88 ------------ .../indy/sdk/agent/AgentAddIdentityTest.java | 37 +++++ .../sdk/agent/AgentCloseConnectionTest.java | 98 +++++++++++++ .../sdk/agent/AgentCloseListenerTest.java | 73 ++++++++++ .../indy/sdk/agent/AgentConnectTest.java | 75 ++++++++++ .../indy/sdk/agent/AgentIntegrationTest.java | 89 ++++++++++++ .../indy/sdk/agent/AgentListenTest.java | 26 ++++ .../sdk/agent/AgentRemoveIdentityTest.java | 23 +++ .../indy/sdk/agent/AgentSendTest.java | 78 +++++++++++ .../indy/sdk/anoncreds/DemoTest.java | 6 +- .../indy/sdk/demo/AgentDemoTest.java | 131 ++++++++++++++++++ 11 files changed, 633 insertions(+), 91 deletions(-) delete mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentAddIdentityTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentCloseConnectionTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentCloseListenerTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentConnectTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentIntegrationTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentListenTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentRemoveIdentityTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentSendTest.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AgentDemoTest.java diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java deleted file mode 100644 index d22a5f4c7f..0000000000 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/AgentTest.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.hyperledger.indy.sdk; - -import org.hyperledger.indy.sdk.agent.Agent; -import org.hyperledger.indy.sdk.agent.Agent.Connection; -import org.hyperledger.indy.sdk.agent.Agent.Listener; -import org.hyperledger.indy.sdk.agent.AgentObservers.ConnectionObserver; -import org.hyperledger.indy.sdk.agent.AgentObservers.MessageObserver; -import org.hyperledger.indy.sdk.ledger.Ledger; -import org.hyperledger.indy.sdk.pool.Pool; -import org.hyperledger.indy.sdk.signus.Signus; -import org.hyperledger.indy.sdk.signus.SignusJSONParameters; -import org.hyperledger.indy.sdk.signus.SignusResults; -import org.hyperledger.indy.sdk.utils.PoolUtils; -import org.hyperledger.indy.sdk.wallet.Wallet; -import org.junit.Test; - -import static org.junit.Assert.assertNotNull; - -public class AgentTest extends IndyIntegrationTest { - - @Test - public void testAgentDemo() throws Exception { - String endpoint = "127.0.0.1:9801"; - - Pool pool = PoolUtils.createAndOpenPoolLedger(); - assertNotNull(pool); - openedPools.add(pool); - - Wallet.createWallet(PoolUtils.DEFAULT_POOL_NAME, "trustee_wallet", null, null, null).get(); - Wallet.createWallet(PoolUtils.DEFAULT_POOL_NAME, "listener_wallet", null, null, null).get(); - Wallet trusteeWallet = Wallet.openWallet("trustee_wallet", null, null).get(); - assertNotNull(trusteeWallet); - Wallet listenerWallet = Wallet.openWallet("listener_wallet", null, null).get(); - assertNotNull(listenerWallet); - Wallet senderWallet = trusteeWallet; - - SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJSONParameter - = new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, IndyIntegrationTest.TRUSTEE_SEED, null, false); - SignusResults.CreateAndStoreMyDidResult trustee = Signus.createAndStoreMyDid(trusteeWallet, myDidJSONParameter.toJson()).get(); - - SignusResults.CreateAndStoreMyDidResult listener = Signus.createAndStoreMyDid(listenerWallet, "{}").get(); - - SignusResults.CreateAndStoreMyDidResult sender = trustee; - - String listenerNymJson = Ledger.buildNymRequest(trustee.getDid(), listener.getDid(), listener.getVerkey(), null, null).get(); - - Ledger.signAndSubmitRequest(pool, trusteeWallet, trustee.getDid(), listenerNymJson).get(); - - String listenerAttribJson = Ledger.buildAttribRequest(listener.getDid(), listener.getDid(), null, - String.format("{\"endpoint\":{\"ha\":\"%s\",\"verkey\":\"%s\"}}", endpoint, listener.getPk()), null).get(); - - Ledger.signAndSubmitRequest(pool, listenerWallet, listener.getDid(), listenerAttribJson).get(); - - final MessageObserver messageObserver = new MessageObserver() { - - public void onMessage(Connection connection, String message) { - - System.out.println("Received message '" + message + "' on connection " + connection); - } - }; - - final MessageObserver messageObserverForIncoming = new MessageObserver() { - - public void onMessage(Connection connection, String message) { - - System.out.println("Received message '" + message + "' on incoming connection " + connection); - } - }; - - final ConnectionObserver incomingConnectionObserver = new ConnectionObserver() { - - public MessageObserver onConnection(Listener listener, Connection connection, String senderDid, String receiverDid) { - - System.out.println("New connection " + connection); - - return messageObserverForIncoming; - } - }; - - Listener activeListener = Agent.agentListen(endpoint, incomingConnectionObserver).get(); - - activeListener.agentAddIdentity(pool, listenerWallet, listener.getDid()).get(); - - Connection connection = Agent.agentConnect(pool, senderWallet, sender.getDid(), listener.getDid(), messageObserver).get(); - - connection.agentSend("test").get(); - } -} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentAddIdentityTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentAddIdentityTest.java new file mode 100644 index 0000000000..2697b6831e --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentAddIdentityTest.java @@ -0,0 +1,37 @@ +package org.hyperledger.indy.sdk.agent; + +import org.hyperledger.indy.sdk.agent.Agent.Listener; +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusResults; +import org.junit.Test; + + +public class AgentAddIdentityTest extends AgentIntegrationTest { + + @Test + public void testAgentAddIdentityWorks() throws Exception { + String endpoint = "127.0.0.1:9701"; + + SignusResults.CreateAndStoreMyDidResult myDid = Signus.createAndStoreMyDid(wallet, "{}").get(); + + Listener activeListener = Agent.agentListen(endpoint, incomingConnectionObserver).get(); + + activeListener.agentAddIdentity(pool, wallet, myDid.getDid()).get(); + } + + @Test + public void testAgentAddIdentityWorksForMultiplyKeys() throws Exception { + String endpoint = "127.0.0.1:9702"; + + SignusResults.CreateAndStoreMyDidResult myDid1 = Signus.createAndStoreMyDid(wallet, "{}").get(); + SignusResults.CreateAndStoreMyDidResult myDid2 = Signus.createAndStoreMyDid(wallet, "{}").get(); + + SignusResults.CreateAndStoreMyDidResult[] dids = {myDid1, myDid2}; + + Listener activeListener = Agent.agentListen(endpoint, incomingConnectionObserver).get(); + + for (SignusResults.CreateAndStoreMyDidResult did : dids) { + activeListener.agentAddIdentity(pool, wallet, did.getDid()).get(); + } + } +} \ No newline at end of file diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentCloseConnectionTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentCloseConnectionTest.java new file mode 100644 index 0000000000..125534b97f --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentCloseConnectionTest.java @@ -0,0 +1,98 @@ +package org.hyperledger.indy.sdk.agent; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.agent.Agent.Connection; +import org.hyperledger.indy.sdk.agent.Agent.Listener; +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusResults; +import org.junit.Test; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + + +public class AgentCloseConnectionTest extends AgentIntegrationTest { + + private static CompletableFuture serverToClientConnectionFuture = new CompletableFuture(); + + private static final AgentObservers.MessageObserver messageObserver = new AgentObservers.MessageObserver() { + + public void onMessage(Connection connection, String message) { + + System.out.println("Received message '" + message + "' on connection " + connection); + } + }; + + private static final AgentObservers.MessageObserver messageObserverForIncoming = new AgentObservers.MessageObserver() { + + public void onMessage(Connection connection, String message) { + + System.out.println("Received message '" + message + "' on incoming connection " + connection); + } + }; + + private static final AgentObservers.ConnectionObserver incomingConnectionObserver = new AgentObservers.ConnectionObserver() { + + public AgentObservers.MessageObserver onConnection(Listener listener, Connection connection, String senderDid, String receiverDid) { + + System.out.println("New connection " + connection); + + serverToClientConnectionFuture.complete(connection); + + return messageObserverForIncoming; + } + }; + + @Test + public void testAgentCloseConnectionWorksForOutgoing() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String endpoint = "127.0.0.1:9703"; + + SignusResults.CreateAndStoreMyDidResult myDid = Signus.createAndStoreMyDid(wallet, "{}").get(); + + String identityJson = String.format("{\"did\":\"%s\", \"pk\":\"%s\", \"verkey\":\"%s\", \"endpoint\":\"%s\"}", + myDid.getDid(), myDid.getPk(), myDid.getVerkey(), endpoint); + Signus.storeTheirDid(wallet, identityJson).get(); + + Listener activeListener = Agent.agentListen(endpoint, incomingConnectionObserver).get(); + + activeListener.agentAddIdentity(pool, wallet, myDid.getDid()).get(); + + Connection connection = Agent.agentConnect(pool, wallet, myDid.getDid(), myDid.getDid(), messageObserver).get(); + + connection.agentCloseConnection().get(); + + connection.agentSend("msg").get(); + } + + @Test + public void testAgentCloseConnectionWorksForIncoming() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String endpoint = "127.0.0.1:9713"; + + SignusResults.CreateAndStoreMyDidResult myDid = Signus.createAndStoreMyDid(wallet, "{}").get(); + + String identityJson = String.format("{\"did\":\"%s\", \"pk\":\"%s\", \"verkey\":\"%s\", \"endpoint\":\"%s\"}", + myDid.getDid(), myDid.getPk(), myDid.getVerkey(), endpoint); + Signus.storeTheirDid(wallet, identityJson).get(); + + Listener activeListener = Agent.agentListen(endpoint, incomingConnectionObserver).get(); + + activeListener.agentAddIdentity(pool, wallet, myDid.getDid()).get(); + + Agent.agentConnect(pool, wallet, myDid.getDid(), myDid.getDid(), messageObserver).get(); + + Connection serverToClientConnection = serverToClientConnectionFuture.get(); + + serverToClientConnection.agentCloseConnection().get(); + + serverToClientConnection.agentSend("msg").get(); + } +} \ No newline at end of file diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentCloseListenerTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentCloseListenerTest.java new file mode 100644 index 0000000000..b8971c7471 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentCloseListenerTest.java @@ -0,0 +1,73 @@ +package org.hyperledger.indy.sdk.agent; + +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.agent.Agent.Connection; +import org.hyperledger.indy.sdk.agent.Agent.Listener; +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusResults; +import org.junit.Test; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + + +public class AgentCloseListenerTest extends AgentIntegrationTest { + + private static CompletableFuture serverToClientConnectionFuture = new CompletableFuture(); + + private static final AgentObservers.MessageObserver messageObserver = new AgentObservers.MessageObserver() { + + public void onMessage(Connection connection, String message) { + + System.out.println("Received message '" + message + "' on connection " + connection); + } + }; + + private static final AgentObservers.MessageObserver messageObserverForIncoming = new AgentObservers.MessageObserver() { + + public void onMessage(Connection connection, String message) { + + System.out.println("Received message '" + message + "' on incoming connection " + connection); + } + }; + + private static final AgentObservers.ConnectionObserver incomingConnectionObserver = new AgentObservers.ConnectionObserver() { + + public AgentObservers.MessageObserver onConnection(Listener listener, Connection connection, String senderDid, String receiverDid) { + + System.out.println("New connection " + connection); + + serverToClientConnectionFuture.complete(connection); + + return messageObserverForIncoming; + } + }; + + @Test + public void testAgentCloseConnectionWorksForOutgoing() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + + String endpoint = "127.0.0.1:9704"; + + SignusResults.CreateAndStoreMyDidResult myDid = Signus.createAndStoreMyDid(wallet, "{}").get(); + + String identityJson = String.format("{\"did\":\"%s\", \"pk\":\"%s\", \"verkey\":\"%s\", \"endpoint\":\"%s\"}", + myDid.getDid(), myDid.getPk(), myDid.getVerkey(), endpoint); + Signus.storeTheirDid(wallet, identityJson).get(); + + Listener activeListener = Agent.agentListen(endpoint, incomingConnectionObserver).get(); + + activeListener.agentAddIdentity(pool, wallet, myDid.getDid()).get(); + + Agent.agentConnect(pool, wallet, myDid.getDid(), myDid.getDid(), messageObserver).get(); + + Connection serverToClientConnection = serverToClientConnectionFuture.get(); + + activeListener.agentCloseListener().get(); + + serverToClientConnection.agentSend("msg").get(); + } +} \ No newline at end of file diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentConnectTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentConnectTest.java new file mode 100644 index 0000000000..2ccbdcef34 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentConnectTest.java @@ -0,0 +1,75 @@ +package org.hyperledger.indy.sdk.agent; + +import org.hyperledger.indy.sdk.agent.Agent.Listener; +import org.hyperledger.indy.sdk.ledger.Ledger; +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusJSONParameters; +import org.hyperledger.indy.sdk.signus.SignusResults; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.junit.Test; + + +public class AgentConnectTest extends AgentIntegrationTest { + + @Test + public void testAgentConnectWorksForRemoteData() throws Exception { + String endpoint = "127.0.0.1:9705"; + String listenerWalletName = "listenerWallet"; + String trusteeWalletName = "trusteeWallet"; + + Wallet.createWallet(poolName, listenerWalletName, "default", null, null).get(); + Wallet listenerWallet = Wallet.openWallet(listenerWalletName, null, null).get(); + + Wallet.createWallet(poolName, trusteeWalletName, "default", null, null).get(); + Wallet trusteeWallet = Wallet.openWallet(trusteeWalletName, null, null).get(); + Wallet senderWallet = trusteeWallet; + + SignusResults.CreateAndStoreMyDidResult createMyDidResult = Signus.createAndStoreMyDid(listenerWallet, "{}").get(); + String listenerDid = createMyDidResult.getDid(); + String listenerVerkey = createMyDidResult.getVerkey(); + String listenerPk = createMyDidResult.getPk(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(trusteeWallet, trusteeDidJson.toJson()).get(); + String trusteeDid = trusteeDidResult.getDid(); + String senderDid = trusteeDid; + + String nymRequest = Ledger.buildNymRequest(trusteeDid, listenerDid, listenerVerkey, null, null).get(); + Ledger.signAndSubmitRequest(pool, trusteeWallet, trusteeDid, nymRequest).get(); + + String attribRequest = Ledger.buildAttribRequest(listenerDid, listenerDid, null, + String.format("{\"endpoint\":{\"ha\":\"%s\",\"verkey\":\"%s\"}}", endpoint, listenerPk), null).get(); + Ledger.signAndSubmitRequest(pool, listenerWallet, listenerDid, attribRequest).get(); + + Listener activeListener = Agent.agentListen(endpoint, incomingConnectionObserver).get(); + + activeListener.agentAddIdentity(pool, listenerWallet, listenerDid).get(); + + Agent.agentConnect(pool, senderWallet, senderDid, listenerDid, messageObserver).get(); + + listenerWallet.closeWallet().get(); + Wallet.deleteWallet(listenerWalletName, null).get(); + + trusteeWallet.closeWallet().get(); + Wallet.deleteWallet(trusteeWalletName, null).get(); + } + + @Test + public void testAgentConnectWorksForAllDataInWalletPresent() throws Exception { + String endpoint = "127.0.0.1:9706"; + + SignusResults.CreateAndStoreMyDidResult myDid = Signus.createAndStoreMyDid(wallet, "{}").get(); + + String identityJson = String.format("{\"did\":\"%s\", \"pk\":\"%s\", \"verkey\":\"%s\", \"endpoint\":\"%s\"}", + myDid.getDid(), myDid.getPk(), myDid.getVerkey(), endpoint); + Signus.storeTheirDid(wallet, identityJson).get(); + + Listener activeListener = Agent.agentListen(endpoint, incomingConnectionObserver).get(); + + activeListener.agentAddIdentity(pool, wallet, myDid.getDid()).get(); + + Agent.agentConnect(pool, wallet, myDid.getDid(), myDid.getDid(), messageObserver).get(); + } +} \ No newline at end of file diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentIntegrationTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentIntegrationTest.java new file mode 100644 index 0000000000..d4c2879bed --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentIntegrationTest.java @@ -0,0 +1,89 @@ +package org.hyperledger.indy.sdk.agent; + +import org.hyperledger.indy.sdk.agent.Agent.Connection; +import org.hyperledger.indy.sdk.agent.Agent.Listener; +import org.hyperledger.indy.sdk.agent.AgentObservers.ConnectionObserver; +import org.hyperledger.indy.sdk.agent.AgentObservers.MessageObserver; +import org.hyperledger.indy.sdk.pool.Pool; +import org.hyperledger.indy.sdk.pool.PoolJSONParameters; +import org.hyperledger.indy.sdk.utils.InitHelper; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.hyperledger.indy.sdk.utils.StorageUtils; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.rules.ExpectedException; +import org.junit.rules.Timeout; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; + + +public class AgentIntegrationTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Rule + public Timeout globalTimeout = new Timeout(1, TimeUnit.MINUTES); + + static Wallet wallet; + static Pool pool; + String poolName; + private String walletName = "agentWallet"; + + @BeforeClass + public static void init() throws Exception { + InitHelper.init(); + } + + @Before + public void setUp() throws Exception { + StorageUtils.cleanupStorage(); + + poolName = PoolUtils.createPoolLedgerConfig(); + + PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); + pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); + + Wallet.createWallet(poolName, walletName, "default", null, null).get(); + wallet = Wallet.openWallet(walletName, null, null).get(); + } + + @After + public void tearDown() throws Exception { + wallet.closeWallet().get(); + Wallet.deleteWallet(walletName, null).get(); + + pool.closePoolLedger().get(); + StorageUtils.cleanupStorage(); + } + + static final AgentObservers.MessageObserver messageObserver = new AgentObservers.MessageObserver() { + + public void onMessage(Connection connection, String message) { + + System.out.println("Received message '" + message + "' on connection " + connection); + } + }; + + private static final AgentObservers.MessageObserver messageObserverForIncoming = new AgentObservers.MessageObserver() { + + public void onMessage(Connection connection, String message) { + + System.out.println("Received message '" + message + "' on incoming connection " + connection); + } + }; + + static final AgentObservers.ConnectionObserver incomingConnectionObserver = new AgentObservers.ConnectionObserver() { + + public AgentObservers.MessageObserver onConnection(Listener listener, Connection connection, String senderDid, String receiverDid) { + + System.out.println("New connection " + connection); + + return messageObserverForIncoming; + } + }; +} \ No newline at end of file diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentListenTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentListenTest.java new file mode 100644 index 0000000000..2da18da83b --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentListenTest.java @@ -0,0 +1,26 @@ +package org.hyperledger.indy.sdk.agent; + +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusJSONParameters; +import org.hyperledger.indy.sdk.signus.SignusResults; +import org.junit.Test; + + +public class AgentListenTest extends AgentIntegrationTest { + + @Test + public void testAgentListenWorksForAllDataInWalletPresent() throws Exception { + String endpoint = "127.0.0.1:9707"; + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "sovrin_agent_connect_works_for_a", null, null); + + SignusResults.CreateAndStoreMyDidResult myDid = Signus.createAndStoreMyDid(wallet, didJson.toJson()).get(); + + String identityJson = String.format("{\"did\":\"%s\", \"pk\":\"%s\", \"verkey\":\"%s\", \"endpoint\":\"%s\"}", + myDid.getDid(), myDid.getPk(), myDid.getVerkey(), endpoint); + Signus.storeTheirDid(wallet, identityJson).get(); + + Agent.agentListen(endpoint, incomingConnectionObserver).get(); + } +} \ No newline at end of file diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentRemoveIdentityTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentRemoveIdentityTest.java new file mode 100644 index 0000000000..0231602d5e --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentRemoveIdentityTest.java @@ -0,0 +1,23 @@ +package org.hyperledger.indy.sdk.agent; + +import org.hyperledger.indy.sdk.agent.Agent.Listener; +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusResults; +import org.junit.Test; + + +public class AgentRemoveIdentityTest extends AgentIntegrationTest { + + @Test + public void testAgentRemoveIdentityWorks() throws Exception { + String endpoint = "127.0.0.1:9708"; + + SignusResults.CreateAndStoreMyDidResult myDid = Signus.createAndStoreMyDid(wallet, "{}").get(); + + Listener activeListener = Agent.agentListen(endpoint, incomingConnectionObserver).get(); + + activeListener.agentAddIdentity(pool, wallet, myDid.getDid()).get(); + + activeListener.agentRemoveIdentity(wallet, myDid.getDid()).get(); + } +} \ No newline at end of file diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentSendTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentSendTest.java new file mode 100644 index 0000000000..195b618c6c --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentSendTest.java @@ -0,0 +1,78 @@ +package org.hyperledger.indy.sdk.agent; + +import org.hyperledger.indy.sdk.agent.Agent.Connection; +import org.hyperledger.indy.sdk.agent.Agent.Listener; +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusResults; +import org.junit.Assert; +import org.junit.Test; + +import java.util.concurrent.CompletableFuture; + +public class AgentSendTest extends AgentIntegrationTest { + + private static CompletableFuture serverToClientConnectionFuture = new CompletableFuture(); + private static CompletableFuture serverToClientMsgFuture = new CompletableFuture(); + private static CompletableFuture clientToServerMsgFuture = new CompletableFuture(); + + private static final AgentObservers.MessageObserver messageObserver = new AgentObservers.MessageObserver() { + + public void onMessage(Connection connection, String message) { + + System.out.println("Received message '" + message + "' on connection " + connection); + + serverToClientMsgFuture.complete(message); + } + }; + + private static final AgentObservers.MessageObserver messageObserverForIncoming = new AgentObservers.MessageObserver() { + + public void onMessage(Connection connection, String message) { + + System.out.println("Received message '" + message + "' on incoming connection " + connection); + + clientToServerMsgFuture.complete(message); + } + }; + + private static final AgentObservers.ConnectionObserver incomingConnectionObserver = new AgentObservers.ConnectionObserver() { + + public AgentObservers.MessageObserver onConnection(Listener listener, Connection connection, String senderDid, String receiverDid) { + + System.out.println("New connection " + connection); + + serverToClientConnectionFuture.complete(connection); + + return messageObserverForIncoming; + } + }; + + @Test + public void testAgentSendWorksForAllDataInWalletPresent() throws Exception { + String endpoint = "127.0.0.1:9709"; + + SignusResults.CreateAndStoreMyDidResult myDid = Signus.createAndStoreMyDid(wallet, "{}").get(); + + String identityJson = String.format("{\"did\":\"%s\", \"pk\":\"%s\", \"verkey\":\"%s\", \"endpoint\":\"%s\"}", + myDid.getDid(), myDid.getPk(), myDid.getVerkey(), endpoint); + Signus.storeTheirDid(wallet, identityJson).get(); + + Listener activeListener = Agent.agentListen(endpoint, incomingConnectionObserver).get(); + + activeListener.agentAddIdentity(pool, wallet, myDid.getDid()).get(); + + Connection clientToServerConnection = Agent.agentConnect(pool, wallet, myDid.getDid(), myDid.getDid(), messageObserver).get(); + + String clientToServerMessage = "msg_from_client"; + String serverToClientMessage = "msg_from_server"; + + clientToServerConnection.agentSend(clientToServerMessage).get(); + + Assert.assertEquals(clientToServerMessage, clientToServerMsgFuture.get()); + + Connection serverToClientConnection = serverToClientConnectionFuture.get(); + serverToClientConnection.agentSend(serverToClientMessage).get(); + + Assert.assertEquals(serverToClientMessage, serverToClientMsgFuture.get()); + } +} \ No newline at end of file diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/DemoTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/DemoTest.java index 366f5c6fcb..3d6dc45218 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/DemoTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/DemoTest.java @@ -61,7 +61,7 @@ public void deleteWallet() throws Exception { } @Test - public void anoncredsWorksForMultiplyIssuerSingleProver() throws Exception { + public void testAnoncredsWorksForMultiplyIssuerSingleProver() throws Exception { String issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; String issuerDid2 = "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"; @@ -221,7 +221,7 @@ public void anoncredsWorksForMultiplyIssuerSingleProver() throws Exception { } @Test - public void anoncredsWorksForSingleIssuerSingleProver() throws Exception { + public void testAnoncredsWorksForSingleIssuerSingleProver() throws Exception { String issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; @@ -362,7 +362,7 @@ public void anoncredsWorksForSingleIssuerSingleProver() throws Exception { } @Test - public void verifyProofWorksForProofDoesNotCorrespondToProofRequest() throws Exception { + public void testVerifyProofWorksForProofDoesNotCorrespondToProofRequest() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AgentDemoTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AgentDemoTest.java new file mode 100644 index 0000000000..1ac56ea381 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AgentDemoTest.java @@ -0,0 +1,131 @@ +package org.hyperledger.indy.sdk.demo; + +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.agent.Agent; +import org.hyperledger.indy.sdk.agent.Agent.Connection; +import org.hyperledger.indy.sdk.agent.Agent.Listener; +import org.hyperledger.indy.sdk.agent.AgentObservers.ConnectionObserver; +import org.hyperledger.indy.sdk.agent.AgentObservers.MessageObserver; +import org.hyperledger.indy.sdk.ledger.Ledger; +import org.hyperledger.indy.sdk.pool.Pool; +import org.hyperledger.indy.sdk.pool.PoolJSONParameters; +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusJSONParameters; +import org.hyperledger.indy.sdk.signus.SignusResults; +import org.hyperledger.indy.sdk.utils.PoolUtils; +import org.hyperledger.indy.sdk.wallet.Wallet; +import org.junit.Assert; +import org.junit.Test; + +import java.util.concurrent.CompletableFuture; + + +public class AgentDemoTest extends IndyIntegrationTest { + + @Test + public void testAgentDemo() throws Exception { + String endpoint = "127.0.0.1:9801"; + String listenerWalletName = "listenerWallet"; + String trusteeWalletName = "trusteeWallet"; + String message = "test"; + + //1. Create and Open Pool + String poolName = PoolUtils.createPoolLedgerConfig(); + + PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); + Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); + + //2. Create and Open Listener Wallet + Wallet.createWallet(poolName, listenerWalletName, "default", null, null).get(); + Wallet listenerWallet = Wallet.openWallet(listenerWalletName, null, null).get(); + + //3. Create and Open Trustee Wallet + Wallet.createWallet(poolName, trusteeWalletName, "default", null, null).get(); + Wallet trusteeWallet = Wallet.openWallet(trusteeWalletName, null, null).get(); + Wallet senderWallet = trusteeWallet; + + //4. Create My Did + SignusResults.CreateAndStoreMyDidResult createMyDidResult = Signus.createAndStoreMyDid(listenerWallet, "{}").get(); + String listenerDid = createMyDidResult.getDid(); + String listenerVerkey = createMyDidResult.getVerkey(); + String listenerPk = createMyDidResult.getPk(); + + //5. Create Their Did from Trustee seed + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + + SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(trusteeWallet, trusteeDidJson.toJson()).get(); + String trusteeDid = trusteeDidResult.getDid(); + String senderDid = trusteeDid; + + // 6. Prepare and Send NYM request with signing + String nymRequest = Ledger.buildNymRequest(trusteeDid, listenerDid, listenerVerkey, null, null).get(); + Ledger.signAndSubmitRequest(pool, trusteeWallet, trusteeDid, nymRequest).get(); + + // 7. Prepare and Send Attrib for listener (will be requested from ledger and used by sender at start connection) + String attribRequest = Ledger.buildAttribRequest(listenerDid, listenerDid, null, + String.format("{\"endpoint\":{\"ha\":\"%s\",\"verkey\":\"%s\"}}", endpoint, listenerPk), null).get(); + Ledger.signAndSubmitRequest(pool, listenerWallet, listenerDid, attribRequest).get(); + + CompletableFuture clientToServerMsgFuture = new CompletableFuture(); + + final MessageObserver messageObserver = new MessageObserver() { + + public void onMessage(Connection connection, String message) { + + System.out.println("Received message '" + message + "' on connection " + connection); + } + }; + + final MessageObserver messageObserverForIncoming = new MessageObserver() { + + public void onMessage(Connection connection, String receivedMessage) { + + System.out.println("Received message '" + receivedMessage + "' on incoming connection " + connection); + + clientToServerMsgFuture.complete(receivedMessage); + } + }; + + final ConnectionObserver incomingConnectionObserver = new ConnectionObserver() { + + public MessageObserver onConnection(Listener listener, Connection connection, String senderDid, String receiverDid) { + + System.out.println("New connection " + connection); + + return messageObserverForIncoming; + } + }; + + // 8. start listener on endpoint + Listener activeListener = Agent.agentListen(endpoint, incomingConnectionObserver).get(); + + // 9. Allow listener accept incoming connection for specific DID (listener_did) + activeListener.agentAddIdentity(pool, listenerWallet, listenerDid).get(); + + // 10. Initiate connection from sender to listener + Connection connection = Agent.agentConnect(pool, senderWallet, senderDid, listenerDid, messageObserver).get(); + + // 11. Send test message from sender to listener + connection.agentSend("test").get(); + + Assert.assertEquals(message, clientToServerMsgFuture.get()); + + // 12. Close connection + connection.agentCloseConnection(); + + // 13. Close listener + activeListener.agentCloseListener(); + + // 14. Close and delete Issuer Wallet + listenerWallet.closeWallet().get(); + Wallet.deleteWallet(listenerWalletName, null).get(); + + // 15. Close and delete Prover Wallet + trusteeWallet.closeWallet().get(); + Wallet.deleteWallet(trusteeWalletName, null).get(); + + //16. Close Pool + pool.closePoolLedger().get(); + } +} \ No newline at end of file From 50e572ea876e548de72456e39ef4fb50cecfbfac Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 19 Jul 2017 14:46:28 +0300 Subject: [PATCH 231/349] Corrected import --- .../java/org/hyperledger/indy/sdk/agent/AgentSendTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentSendTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentSendTest.java index 195b618c6c..bdf1defcca 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentSendTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentSendTest.java @@ -4,11 +4,12 @@ import org.hyperledger.indy.sdk.agent.Agent.Listener; import org.hyperledger.indy.sdk.signus.Signus; import org.hyperledger.indy.sdk.signus.SignusResults; -import org.junit.Assert; import org.junit.Test; import java.util.concurrent.CompletableFuture; +import static org.junit.Assert.assertEquals; + public class AgentSendTest extends AgentIntegrationTest { private static CompletableFuture serverToClientConnectionFuture = new CompletableFuture(); @@ -68,11 +69,11 @@ public void testAgentSendWorksForAllDataInWalletPresent() throws Exception { clientToServerConnection.agentSend(clientToServerMessage).get(); - Assert.assertEquals(clientToServerMessage, clientToServerMsgFuture.get()); + assertEquals(clientToServerMessage, clientToServerMsgFuture.get()); Connection serverToClientConnection = serverToClientConnectionFuture.get(); serverToClientConnection.agentSend(serverToClientMessage).get(); - Assert.assertEquals(serverToClientMessage, serverToClientMsgFuture.get()); + assertEquals(serverToClientMessage, serverToClientMsgFuture.get()); } } \ No newline at end of file From 36be9e146beb7fb4e4626d1a6a486883fe224f59 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 19 Jul 2017 15:09:38 +0300 Subject: [PATCH 232/349] added tests for nym_request --- .../tests/ledger/test_build_nym_request.py | 2 +- .../tests/ledger/test_submit_request.py | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/wrappers/python/tests/ledger/test_build_nym_request.py b/wrappers/python/tests/ledger/test_build_nym_request.py index 022a7e959c..bcc7fd3b98 100644 --- a/wrappers/python/tests/ledger/test_build_nym_request.py +++ b/wrappers/python/tests/ledger/test_build_nym_request.py @@ -66,4 +66,4 @@ async def test_build_nym_request_works_with_option_fields(): } response = json.loads((await ledger.build_nym_request(identifier, destination, ver_key, alias, role)).decode()) - assert expected_response.items() <= response.items() \ No newline at end of file + assert expected_response.items() <= response.items() diff --git a/wrappers/python/tests/ledger/test_submit_request.py b/wrappers/python/tests/ledger/test_submit_request.py index 1ff8834821..fcb0912185 100644 --- a/wrappers/python/tests/ledger/test_submit_request.py +++ b/wrappers/python/tests/ledger/test_submit_request.py @@ -72,3 +72,44 @@ async def test_submit_request_works_for_invalid_pool_handle(pool_handle, wallet_ except Exception as e: assert type(IndyError(ErrorCode.PoolLedgerInvalidPoolHandle)) == type(e) and \ IndyError(ErrorCode.PoolLedgerInvalidPoolHandle).args == e.args + + +@pytest.mark.asyncio +async def test_nym_request_works_without_signature(pool_handle, wallet_handle): + (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"00000000000000000000000000000My1"}') + + nym_request = await ledger.build_nym_request(my_did.decode(), my_did.decode(), None, None, None) + try: + await ledger.submit_request(pool_handle, nym_request.decode()) + raise Exception("Failed") + except Exception as e: + assert type(IndyError(ErrorCode.LedgerInvalidTransaction)) == type(e) and \ + IndyError(ErrorCode.LedgerInvalidTransaction).args == e.args + + +@pytest.mark.asyncio +async def test_send_get_nym_request_works(pool_handle, wallet_handle): + (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"000000000000000000000000Trustee1"}') + + get_nym_request = await ledger.build_get_nym_request(my_did.decode(), my_did.decode()) + + response = json.loads((await ledger.submit_request(pool_handle, get_nym_request.decode())).decode()) + assert response['result']['data'] is not None + + +@pytest.mark.asyncio +async def test_nym_requests_works(pool_handle, wallet_handle): + (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"000000000000000000000000Trustee1"}') + (my_did, my_ver_key, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"00000000000000000000000000000My1"}') + + nym_request = await ledger.build_nym_request(trustee_did.decode(), my_did.decode(), my_ver_key.decode(), None, None) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did.decode(), nym_request.decode()) + get_nym_request = await ledger.build_get_nym_request(my_did.decode(), my_did.decode()) + response = json.loads((await ledger.submit_request(pool_handle, get_nym_request.decode())).decode()) + assert response['result']['data'] is not None + + From 194564018c7c9641d78151fb1054609c66f12f8c Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 19 Jul 2017 15:30:12 +0300 Subject: [PATCH 233/349] added tests for attrib_requests --- .../tests/ledger/test_build_attrib_request.py | 14 ++++++++++ .../ledger/test_build_get_attrib_request.py | 2 +- .../tests/ledger/test_submit_request.py | 28 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/wrappers/python/tests/ledger/test_build_attrib_request.py b/wrappers/python/tests/ledger/test_build_attrib_request.py index aa3f5e91ef..4f266e9e24 100644 --- a/wrappers/python/tests/ledger/test_build_attrib_request.py +++ b/wrappers/python/tests/ledger/test_build_attrib_request.py @@ -1,5 +1,6 @@ from tests.utils import storage from indy import ledger +from indy.error import * import json import pytest @@ -32,3 +33,16 @@ async def test_build_attrib_request_works_for_raw_data(): response = json.loads((await ledger.build_attrib_request(identifier, destination, None, raw, None)).decode()) assert expected_response.items() <= response.items() + + +@pytest.mark.asyncio +async def test_build_attrib_request_works_for_missed_attribute(): + identifier = "Th7MpTaRZVRYnPiabds81Y" + destination = "Th7MpTaRZVRYnPiabds81Y" + + try: + await ledger.build_attrib_request(identifier, destination, None, None, None) + except Exception as e: + assert type(IndyError(ErrorCode.CommonInvalidStructure)) == type(e) and \ + IndyError(ErrorCode.CommonInvalidStructure).args == e.args + diff --git a/wrappers/python/tests/ledger/test_build_get_attrib_request.py b/wrappers/python/tests/ledger/test_build_get_attrib_request.py index 5a474be599..2e3d038ed0 100644 --- a/wrappers/python/tests/ledger/test_build_get_attrib_request.py +++ b/wrappers/python/tests/ledger/test_build_get_attrib_request.py @@ -16,7 +16,7 @@ def before_after_each(): @pytest.mark.asyncio -async def test_build_get_attrib_request_works_for_raw_data(): +async def test_build_get_attrib_request_works(): identifier = "Th7MpTaRZVRYnPiabds81Y" destination = "Th7MpTaRZVRYnPiabds81Y" raw = "endpoint" diff --git a/wrappers/python/tests/ledger/test_submit_request.py b/wrappers/python/tests/ledger/test_submit_request.py index fcb0912185..6d21cee6d2 100644 --- a/wrappers/python/tests/ledger/test_submit_request.py +++ b/wrappers/python/tests/ledger/test_submit_request.py @@ -113,3 +113,31 @@ async def test_nym_requests_works(pool_handle, wallet_handle): assert response['result']['data'] is not None +@pytest.mark.asyncio +async def test_attrib_request_works_without_signature(pool_handle, wallet_handle): + (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"00000000000000000000000000000My1"}') + + attrib_request = await ledger.build_attrib_request(my_did.decode(), my_did.decode(), None, + "{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}", None) + try: + await ledger.submit_request(pool_handle, attrib_request.decode()) + raise Exception("Failed") + except Exception as e: + assert type(IndyError(ErrorCode.LedgerInvalidTransaction)) == type(e) and \ + IndyError(ErrorCode.LedgerInvalidTransaction).args == e.args + + +@pytest.mark.asyncio +async def test_attrib_requests_works(pool_handle, wallet_handle): + (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"000000000000000000000000Trustee1"}') + (my_did, my_ver_key, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"00000000000000000000000000000My1"}') + + attrib_request = await ledger.build_attrib_request(my_did.decode(), my_did.decode(), None, + "{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}", None) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, my_did.decode(), attrib_request.decode()) + get_attrib_request = await ledger.build_get_attrib_request(my_did.decode(), my_did.decode(), "endpoint") + response = json.loads((await ledger.submit_request(pool_handle, get_attrib_request.decode())).decode()) + assert response['result']['data'] is not None From e1c5a4d11d03c3bb0d6b62131144b5e2f879baee Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 19 Jul 2017 15:47:40 +0300 Subject: [PATCH 234/349] added tests for schema_request --- .../tests/ledger/test_submit_request.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/wrappers/python/tests/ledger/test_submit_request.py b/wrappers/python/tests/ledger/test_submit_request.py index 6d21cee6d2..79403316e3 100644 --- a/wrappers/python/tests/ledger/test_submit_request.py +++ b/wrappers/python/tests/ledger/test_submit_request.py @@ -141,3 +141,48 @@ async def test_attrib_requests_works(pool_handle, wallet_handle): get_attrib_request = await ledger.build_get_attrib_request(my_did.decode(), my_did.decode(), "endpoint") response = json.loads((await ledger.submit_request(pool_handle, get_attrib_request.decode())).decode()) assert response['result']['data'] is not None + + +@pytest.mark.asyncio +async def test_schema_request_works_without_signature(pool_handle, wallet_handle): + (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"00000000000000000000000000000My1"}') + + schema_data = { + "name": "gvt2", + "version": "2.0", + "keys": ["name", "male"] + } + + schema_request = await ledger.build_schema_request(my_did.decode(), json.dumps(schema_data)) + + try: + await ledger.submit_request(pool_handle, schema_request.decode()) + raise Exception("Failed") + except Exception as e: + assert type(IndyError(ErrorCode.LedgerInvalidTransaction)) == type(e) and \ + IndyError(ErrorCode.LedgerInvalidTransaction).args == e.args + + +@pytest.mark.asyncio +async def test_schema_requests_works(pool_handle, wallet_handle): + (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"000000000000000000000000Trustee1"}') + (my_did, my_ver_key, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"00000000000000000000000000000My1"}') + + schema_data = { + "name": "gvt2", + "version": "2.0", + "keys": ["name", "male"] + } + + schema_request = await ledger.build_schema_request(my_did.decode(), json.dumps(schema_data)) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, my_did.decode(), schema_request.decode()) + get_schema_data = { + "name": "gvt2", + "version": "2.0" + } + get_schema_request = await ledger.build_get_schema_request(my_did.decode(), my_did.decode(), json.dumps(get_schema_data)) + response = json.loads((await ledger.submit_request(pool_handle, get_schema_request.decode())).decode()) + assert response['result']['data'] is not None From ce566b55aa354e6110eafc7c897e77c620645e2d Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 19 Jul 2017 16:04:16 +0300 Subject: [PATCH 235/349] added tests for build_node_request --- .../tests/ledger/test_build_node_request.py | 26 ++++++++++++++++ .../tests/ledger/test_submit_request.py | 30 +++++++++++++++++-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/wrappers/python/tests/ledger/test_build_node_request.py b/wrappers/python/tests/ledger/test_build_node_request.py index 613e5d9f12..6bc059639d 100644 --- a/wrappers/python/tests/ledger/test_build_node_request.py +++ b/wrappers/python/tests/ledger/test_build_node_request.py @@ -33,3 +33,29 @@ async def test_build_node_request_works_for_missed_field_in_data_json(): except Exception as e: assert type(IndyError(ErrorCode.CommonInvalidStructure)) == type(e) and \ IndyError(ErrorCode.CommonInvalidStructure).args == e.args + + +@pytest.mark.asyncio +async def test_build_node_request_works_for_correct_data_json(): + identifier = "identifier" + destination = "destination" + data = { + "node_ip": "ip", + "node_port": 1, + "client_ip": "ip", + "client_port": 1, + "alias": "some", + "services": ["VALIDATOR"] + } + + expected_response = { + "identifier": identifier, + "operation": { + "type": "0", + "dest": destination, + "data": data + } + } + + response = json.loads((await ledger.build_node_request(identifier, destination, json.dumps(data))).decode()) + assert expected_response.items() <= response.items() diff --git a/wrappers/python/tests/ledger/test_submit_request.py b/wrappers/python/tests/ledger/test_submit_request.py index 79403316e3..3a9534de1a 100644 --- a/wrappers/python/tests/ledger/test_submit_request.py +++ b/wrappers/python/tests/ledger/test_submit_request.py @@ -75,7 +75,7 @@ async def test_submit_request_works_for_invalid_pool_handle(pool_handle, wallet_ @pytest.mark.asyncio -async def test_nym_request_works_without_signature(pool_handle, wallet_handle): +async def test_send_nym_request_works_without_signature(pool_handle, wallet_handle): (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') @@ -114,7 +114,7 @@ async def test_nym_requests_works(pool_handle, wallet_handle): @pytest.mark.asyncio -async def test_attrib_request_works_without_signature(pool_handle, wallet_handle): +async def test_send_attrib_request_works_without_signature(pool_handle, wallet_handle): (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') @@ -144,7 +144,7 @@ async def test_attrib_requests_works(pool_handle, wallet_handle): @pytest.mark.asyncio -async def test_schema_request_works_without_signature(pool_handle, wallet_handle): +async def test_send_schema_request_works_without_signature(pool_handle, wallet_handle): (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') @@ -186,3 +186,27 @@ async def test_schema_requests_works(pool_handle, wallet_handle): get_schema_request = await ledger.build_get_schema_request(my_did.decode(), my_did.decode(), json.dumps(get_schema_data)) response = json.loads((await ledger.submit_request(pool_handle, get_schema_request.decode())).decode()) assert response['result']['data'] is not None + + +@pytest.mark.asyncio +async def test_send_node_request_works_without_signature(pool_handle, wallet_handle): + (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"00000000000000000000000000000My1"}') + + node_data = { + "node_ip": "10.0.0.100", + "node_port": 9710, + "client_ip": "10.0.0.100", + "client_port": 9709, + "alias": "Node5", + "services": ["VALIDATOR"] + } + + node_request = await ledger.build_node_request(my_did.decode(), my_did.decode(), json.dumps(node_data)) + + try: + await ledger.submit_request(pool_handle, node_request.decode()) + raise Exception("Failed") + except Exception as e: + assert type(IndyError(ErrorCode.LedgerInvalidTransaction)) == type(e) and \ + IndyError(ErrorCode.LedgerInvalidTransaction).args == e.args From cdeaa3ca0efd50b818315eee63ee0afaf3a376a2 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 19 Jul 2017 16:08:56 +0300 Subject: [PATCH 236/349] Added new integration tests --- tests/anoncreds.rs | 127 +++++++++++++++++++++++++++++++++++++++------ tests/demo.rs | 16 ++++-- tests/ledger.rs | 61 +++++++++++++++++++--- tests/signus.rs | 111 +++++++++++++++++++++++++++++++++++++-- 4 files changed, 284 insertions(+), 31 deletions(-) diff --git a/tests/anoncreds.rs b/tests/anoncreds.rs index 4d30e4f870..553fe10638 100644 --- a/tests/anoncreds.rs +++ b/tests/anoncreds.rs @@ -62,7 +62,7 @@ mod high_cases { let schema = AnoncredsUtils::get_gvt_schema_json(1); - let invalid_wallet_handle = wallet_handle + 1; + let invalid_wallet_handle = wallet_handle + 100; let res = AnoncredsUtils::issuer_create_claim_definition(invalid_wallet_handle, &ISSUER_DID, &schema, None, false); assert_eq!(res.unwrap_err(), ErrorCode::WalletInvalidHandle); } @@ -96,7 +96,7 @@ mod high_cases { let claim_offer_json = AnoncredsUtils::get_claim_offer(&ISSUER_DID, 1); - let invalid_wallet_handle = wallet_handle + 1; + let invalid_wallet_handle = wallet_handle + 100; let res = AnoncredsUtils::prover_store_claim_offer(invalid_wallet_handle, &claim_offer_json); assert_eq!(res.unwrap_err(), ErrorCode::WalletInvalidHandle); } @@ -164,7 +164,7 @@ mod high_cases { fn prover_get_claim_offers_works_for_invalid_wallet_handle() { let (wallet_handle, _) = AnoncredsUtils::init_common_wallet(); - let invalid_wallet_handle = wallet_handle + 1; + let invalid_wallet_handle = wallet_handle + 100; let res = AnoncredsUtils::prover_get_claim_offers(invalid_wallet_handle, r#"{"schema_seq_no":"1"}"#); assert_eq!(res.unwrap_err(), ErrorCode::WalletInvalidHandle); } @@ -184,7 +184,7 @@ mod high_cases { fn prover_create_master_secret_works_invalid_wallet_handle() { let (wallet_handle, _) = AnoncredsUtils::init_common_wallet(); - let invalid_wallet_handle = wallet_handle + 1; + let invalid_wallet_handle = wallet_handle + 100; let res = AnoncredsUtils::prover_create_master_secret(invalid_wallet_handle, "master_secret_name2"); assert_eq!(res.unwrap_err(), ErrorCode::WalletInvalidHandle); } @@ -217,7 +217,7 @@ mod high_cases { let claim_offer_json = AnoncredsUtils::get_claim_offer(ISSUER_DID, 1); - let invalid_wallet_handle = wallet_handle + 1; + let invalid_wallet_handle = wallet_handle + 100; let res = AnoncredsUtils::prover_create_and_store_claim_req(invalid_wallet_handle, "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW", &claim_offer_json, @@ -294,7 +294,7 @@ mod high_cases { let claim_json = AnoncredsUtils::get_gvt_claim_json(); - let invalid_wallet_handle = wallet_handle + 1; + let invalid_wallet_handle = wallet_handle + 100; let res = AnoncredsUtils::issuer_create_claim(invalid_wallet_handle, &claim_req, &claim_json); assert_eq!(res.unwrap_err(), ErrorCode::WalletInvalidHandle); } @@ -306,10 +306,13 @@ mod high_cases { #[test] fn prover_store_claim_works() { let (wallet_handle, claim_def_json) = AnoncredsUtils::init_common_wallet(); + let prover_wallet_handle = WalletUtils::create_and_open_wallet("proverWallet", None).unwrap(); let claim_offer_json = AnoncredsUtils::get_claim_offer(ISSUER_DID, 1); - let claim_req = AnoncredsUtils::prover_create_and_store_claim_req(wallet_handle, + AnoncredsUtils::prover_create_master_secret(prover_wallet_handle, COMMON_MASTER_SECRET).unwrap(); + + let claim_req = AnoncredsUtils::prover_create_and_store_claim_req(prover_wallet_handle, "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW", &claim_offer_json, &claim_def_json, @@ -318,7 +321,7 @@ mod high_cases { let claim_json = AnoncredsUtils::get_gvt_claim_json(); let (_, xclaim_json) = AnoncredsUtils::issuer_create_claim(wallet_handle, &claim_req, &claim_json).unwrap(); - AnoncredsUtils::prover_store_claim(wallet_handle, &xclaim_json).unwrap(); + AnoncredsUtils::prover_store_claim(prover_wallet_handle, &xclaim_json).unwrap(); } #[test] @@ -336,7 +339,7 @@ mod high_cases { let claim_json = AnoncredsUtils::get_gvt_claim_json(); let (_, claim_json) = AnoncredsUtils::issuer_create_claim(wallet_handle, &claim_req, &claim_json).unwrap(); - let invalid_wallet_handle = wallet_handle + 1; + let invalid_wallet_handle = wallet_handle + 100; let res = AnoncredsUtils::prover_store_claim(invalid_wallet_handle, &claim_json); assert_eq!(res.unwrap_err(), ErrorCode::WalletInvalidHandle); } @@ -389,7 +392,7 @@ mod high_cases { fn prover_get_claims_works_for_invalid_wallet_handle() { let (wallet_handle, _) = AnoncredsUtils::init_common_wallet(); - let invalid_wallet_handle = wallet_handle + 1; + let invalid_wallet_handle = wallet_handle + 100; let res = AnoncredsUtils::prover_get_claims(invalid_wallet_handle, r#"{}"#); assert_eq!(res.unwrap_err(), ErrorCode::WalletInvalidHandle); } @@ -533,7 +536,7 @@ mod high_cases { "requested_predicates":{"predicate1_uuid":{"attr_name":"age","p_type":"GE","value":58}} }"#; - let invalid_wallet_handle = wallet_handle + 1; + let invalid_wallet_handle = wallet_handle + 100; let res = AnoncredsUtils::prover_get_claims_for_proof_req(invalid_wallet_handle, &proof_req); assert_eq!(res.unwrap_err(), ErrorCode::WalletInvalidHandle); } @@ -644,7 +647,7 @@ mod high_cases { let claim_defs_json = format!(r#"{{"{}":{}}}"#, claim_for_attr.claim_uuid, claim_def_json); let revoc_regs_jsons = "{}"; - let invalid_wallet_handle = wallet_handle + 1; + let invalid_wallet_handle = wallet_handle + 100; let res = AnoncredsUtils::prover_create_proof(invalid_wallet_handle, &proof_req, &requested_claims_json, @@ -755,12 +758,22 @@ mod medium_cases { fn issuer_create_and_store_claim_def_works_for_invalid_schema() { let (wallet_handle, _) = AnoncredsUtils::init_common_wallet(); - let schema = r#"{"seqNo":1, "name":"name","version":"1.0", "keys":[]}"#; + let schema = r#"{"seqNo":1, "name":"name","version":"1.0", "keys":["name"]}"#; let res = AnoncredsUtils::issuer_create_claim_definition(wallet_handle, ISSUER_DID, &schema, None, false); assert_eq!(res.unwrap_err(), ErrorCode::CommonInvalidStructure); } + #[test] + fn issuer_create_and_store_claim_def_works_for_invalid_did() { + let (wallet_handle, _) = AnoncredsUtils::init_common_wallet(); + + let schema = r#"{"seqNo":1, "data":{"name":"name","version":"1.0","keys":[]}}"#; + + let res = AnoncredsUtils::issuer_create_claim_definition(wallet_handle, "invalid_base58_String", &schema, None, false); + assert_eq!(res.unwrap_err(), ErrorCode::CommonInvalidStructure); + } + #[test] fn issuer_create_and_store_claim_def_works_for_empty_schema_keys() { let (wallet_handle, _) = AnoncredsUtils::init_common_wallet(); @@ -771,6 +784,16 @@ mod medium_cases { assert_eq!(res.unwrap_err(), ErrorCode::CommonInvalidStructure); } + #[test] + fn issuer_create_and_store_claim_def_works_for_correct_signature_type() { + let (wallet_handle, _) = AnoncredsUtils::init_common_wallet(); + + let schema = AnoncredsUtils::get_gvt_schema_json(1); + + let res = AnoncredsUtils::issuer_create_claim_definition(wallet_handle, &schema, ISSUER_DID, Some("CL"), false); + assert_eq!(res.unwrap_err(), ErrorCode::CommonInvalidStructure); + } + #[test] fn issuer_create_and_store_claim_def_works_for_invalid_signature_type() { let (wallet_handle, _) = AnoncredsUtils::init_common_wallet(); @@ -841,6 +864,14 @@ mod medium_cases { let res = AnoncredsUtils::prover_create_master_secret(wallet_handle, "master_secret_name_duplicate"); assert_eq!(res.unwrap_err(), ErrorCode::AnoncredsMasterSecretDuplicateNameError); } + + #[test] + fn prover_create_master_secret_works_for_empty_name() { + let (wallet_handle, _) = AnoncredsUtils::init_common_wallet(); + + let res = AnoncredsUtils::prover_create_master_secret(wallet_handle, ""); + assert_eq!(res.unwrap_err(), ErrorCode::CommonInvalidParam3); + } } mod prover_create_and_store_claim_req { @@ -1038,6 +1069,72 @@ mod medium_cases { assert_eq!(claims_for_attr_1.len(), 0); } + #[test] + fn prover_get_claims_for_proof_req_works_for_revealed_attr_for_specific_issuer() { + let (wallet_handle, _) = AnoncredsUtils::init_common_wallet(); + + let proof_req = r#"{"nonce":"123432421212", + "name":"proof_req_1", + "version":"0.1", + "requested_attrs":{"attr1_uuid":{"issuer_did":"NcYxiDXkpYi6ov5FcYDi1e", "name":"name"}}, + "requested_predicates":{} + }"#; + + let claims_json = AnoncredsUtils::prover_get_claims_for_proof_req(wallet_handle, &proof_req).unwrap(); + + let claims: ProofClaimsJson = serde_json::from_str(&claims_json).unwrap(); + + assert_eq!(claims.attrs.len(), 1); + assert_eq!(claims.predicates.len(), 0); + + let claims_for_attr_1 = claims.attrs.get("attr1_uuid").unwrap(); + assert_eq!(claims_for_attr_1.len(), 1); + } + + #[test] + fn prover_get_claims_for_proof_req_works_for_revealed_attr_with_other_issuer() { + let (wallet_handle, _) = AnoncredsUtils::init_common_wallet(); + + let proof_req = r#"{"nonce":"123432421212", + "name":"proof_req_1", + "version":"0.1", + "requested_attrs":{"attr1_uuid":{"issuer_did":"Ac23dAXkpYi6ov5FcYDi1e", "name":"name"}}, + "requested_predicates":{} + }"#; + + let claims_json = AnoncredsUtils::prover_get_claims_for_proof_req(wallet_handle, &proof_req).unwrap(); + + let claims: ProofClaimsJson = serde_json::from_str(&claims_json).unwrap(); + + assert_eq!(claims.attrs.len(), 1); + assert_eq!(claims.predicates.len(), 0); + + let claims_for_attr_1 = claims.attrs.get("attr1_uuid").unwrap(); + assert_eq!(claims_for_attr_1.len(), 0); + } + + #[test] + fn prover_get_claims_for_proof_req_works_for_satisfy_predicate_by_specific_issuer_and_schema() { + let (wallet_handle, _) = AnoncredsUtils::init_common_wallet(); + + let proof_req = r#"{"nonce":"123432421212", + "name":"proof_req_1", + "version":"0.1", + "requested_attrs":{}, + "requested_predicates":{"predicate1_uuid":{"attr_name":"age","p_type":"GE","value":18,"schema_seq_no":1,"issuer_did":"NcYxiDXkpYi6ov5FcYDi1e"}} + }"#; + + let claims_json = AnoncredsUtils::prover_get_claims_for_proof_req(wallet_handle, &proof_req).unwrap(); + + let claims: ProofClaimsJson = serde_json::from_str(&claims_json).unwrap(); + + assert_eq!(claims.attrs.len(), 0); + assert_eq!(claims.predicates.len(), 1); + + let claims_for_predicate_1 = claims.predicates.get("predicate1_uuid").unwrap(); + assert_eq!(claims_for_predicate_1.len(), 1); + } + #[test] fn prover_get_claims_for_proof_req_works_for_invalid_predicate() { let (wallet_handle, _) = AnoncredsUtils::init_common_wallet(); @@ -1797,7 +1894,7 @@ mod demos { let self_attested_value = "value"; let requested_claims_json = format!(r#"{{ "self_attested_attributes":{{"self1":"{}"}}, - "requested_attrs":{{"attr1_uuid":["{}",true], + "requested_attrs":{{"attr1_uuid":["{}", true], "attr2_uuid":["{}", false]}}, "requested_predicates":{{"predicate1_uuid":"{}"}} }}"#, self_attested_value, claim.claim_uuid, claim.claim_uuid, claim.claim_uuid); @@ -1864,7 +1961,7 @@ mod demos { claim_defs.insert(ISSUER_DID.to_string(), gvt_claim_def_json.clone()); - //5. Issuer1 create claim definition by xyz schema + //5. Issuer2 create claim definition by xyz schema let xyz_schema_seq_no = 2; let xyz_schema = AnoncredsUtils::get_xyz_schema_json(xyz_schema_seq_no); diff --git a/tests/demo.rs b/tests/demo.rs index d0b098fd10..18d203543c 100644 --- a/tests/demo.rs +++ b/tests/demo.rs @@ -260,7 +260,7 @@ fn agent_demo_works() { let sender_did = trustee_did.clone(); let sender_wallet = trustee_wallet; - // Prepare and send attrib for listener (will be requested from ledger and used by sender at start connection) + //10. Prepare and send attrib for listener (will be requested from ledger and used by sender at start connection) let req_id = PoolUtils::get_req_id(); let listener_attrib_json = json!({ "identifier": listener_did, @@ -286,10 +286,16 @@ fn agent_demo_works() { // 10. start listener on endpoint let (wait_msg_from_srv_send, wait_msg_from_srv_recv) = channel(); - let on_msg = Box::new(move |_, _, msg| { wait_msg_from_srv_send.send(msg).unwrap(); }); + let on_msg = Box::new(move |conn_handle, err, msg| { + info!("On connection {} received (with error {:?}) agent message (CLI->SRV): {}", conn_handle, err, msg); + wait_msg_from_srv_send.send(msg).unwrap(); + }); let (on_msg_cb_id, on_msg_callback) = CallbackUtils::closure_to_agent_message_cb(on_msg); - let on_connect_cb = Box::new(move |_, _, conn_handle, _, _| { CallbackUtils::closure_map_ids(on_msg_cb_id, conn_handle); }); + let on_connect_cb = Box::new(move |listener_handle, err, conn_handle, sender_did, receiver_did| { + CallbackUtils::closure_map_ids(on_msg_cb_id, conn_handle); + info!("New connection {} on listener {}, err {:?}, sender DID {}, receiver DID {}", conn_handle, listener_handle, err, sender_did, receiver_did); + }); let (on_connect_cb_id, on_connect_callback) = CallbackUtils::closure_to_agent_connected_cb(on_connect_cb); let endpoint = CString::new(endpoint).unwrap(); @@ -309,7 +315,9 @@ fn agent_demo_works() { assert_eq!(err, ErrorCode::Success); // 12. Initiate connection from sender to listener - let (msg_cb_id, msg_callback) = CallbackUtils::closure_to_agent_message_cb(Box::new(move |_, _, _| {})); + let (msg_cb_id, msg_callback) = CallbackUtils::closure_to_agent_message_cb(Box::new(move |conn_handle, err, msg| { + info!("On connection {} received (with error {:?}) agent message (SRV->CLI): {}", conn_handle, err, msg); + })); let sender_did = CString::new(sender_did).unwrap(); let err = indy_agent_connect(connect_command_hamdle, pool_handle, sender_wallet, sender_did.as_ptr(), listener_did.as_ptr(), connect_callback, msg_callback); diff --git a/tests/ledger.rs b/tests/ledger.rs index edb4b60c84..137a5fb9a6 100644 --- a/tests/ledger.rs +++ b/tests/ledger.rs @@ -529,9 +529,9 @@ mod high_cases { fn indy_build_node_request_works_for_correct_data_json() { let identifier = "identifier"; let dest = "dest"; - let data = r#"{"node_ip":"ip", "node_port": 1, "client_ip": "ip", "client_port": 1, "alias":"some", "services": ["VALIDATOR"]}"#; + let data = r#"{"node_ip":"10.0.0.100", "node_port": 1, "client_ip": "10.0.0.100", "client_port": 1, "alias":"some", "services": ["VALIDATOR"]}"#; - let expected_result = r#""identifier":"identifier","operation":{"type":"0","dest":"dest","data":{"node_ip":"ip","node_port":1,"client_ip":"ip","client_port":1,"alias":"some","services":["VALIDATOR"]}}"#; + let expected_result = r#""identifier":"identifier","operation":{"type":"0","dest":"dest","data":{"node_ip":"10.0.0.100","node_port":1,"client_ip":"10.0.0.100","client_port":1,"alias":"some","services":["VALIDATOR"]}}"#; let node_request = LedgerUtils::build_node_request(identifier, dest, data).unwrap(); assert!(node_request.contains(expected_result)); @@ -628,6 +628,53 @@ mod high_cases { assert!(get_claim_def_request.contains(expected_result)); } + #[test] + #[cfg(feature = "local_nodes_pool")] + fn indy_claim_def_request_works_without_signature() { + TestUtils::cleanup_storage(); + let pool_name = "indy_claim_def_request_works_without_signature"; + + let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); + let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); + + let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); + let (my_did, my_verkey, _) = SignusUtils::create_my_did(wallet_handle, "{}").unwrap(); + + let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), Some(&my_verkey.clone()), None, None).unwrap(); + LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request).unwrap(); + + let schema_data = "{\"name\":\"gvt2\",\ + \"version\":\"2.0\",\ + \"keys\": [\"name\", \"male\"]}"; + let schema_request = LedgerUtils::build_schema_request(&my_did.clone(), schema_data).unwrap(); + LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &my_did, &schema_request).unwrap(); + + let get_schema_data = "{\"name\":\"gvt2\",\"version\":\"2.0\"}"; + let get_schema_request = LedgerUtils::build_get_schema_request(&my_did.clone(), &my_did, get_schema_data).unwrap(); + let get_schema_response = PoolUtils::send_request(pool_handle, &get_schema_request).unwrap(); + + let get_schema_response: Reply = serde_json::from_str(&get_schema_response).unwrap(); + + let claim_def_json = AnoncredsUtils::issuer_create_claim_definition(wallet_handle, &my_did.clone(), + &serde_json::to_string(&get_schema_response.result).unwrap(), None, false).unwrap(); + info!("claim_def_json {:}", claim_def_json); + + let claim_def: ClaimDefinition = serde_json::from_str(&claim_def_json).unwrap(); + let claim_def_data = ClaimDefinitionData { + public_key: claim_def.data.public_key, + public_key_revocation: claim_def.data.public_key_revocation + }; + let claim_def_data_json = serde_json::to_string(&claim_def_data).unwrap(); + + let claim_def_request = LedgerUtils::build_claim_def_txn(&my_did.clone(), get_schema_response.result.seq_no.unwrap(), + &claim_def.signature_type, &claim_def_data_json).unwrap(); + + let res = PoolUtils::send_request(pool_handle, &claim_def_request); + assert_eq!(res.unwrap_err(), ErrorCode::LedgerInvalidTransaction); + + TestUtils::cleanup_storage(); + } + #[test] #[cfg(feature = "local_nodes_pool")] fn indy_claim_def_requests_works() { @@ -655,7 +702,7 @@ mod high_cases { let get_schema_response: Reply = serde_json::from_str(&get_schema_response).unwrap(); - let claim_def_json = AnoncredsUtils::issuer_create_claim_definition(wallet_handle, "NcYxiDXkpYi6ov5FcYDi1e", + let claim_def_json = AnoncredsUtils::issuer_create_claim_definition(wallet_handle, &my_did.clone(), &serde_json::to_string(&get_schema_response.result).unwrap(), None, false).unwrap(); info!("claim_def_json {:}", claim_def_json); @@ -719,7 +766,7 @@ mod high_cases { version: "3.0".to_string(), keys: keys }; - let schema_data_json = serde_json::to_string(&schema_data).unwrap(); + let schema_data_json = serde_json::to_string(&schema_data).unwrap(); let schema_request = LedgerUtils::build_schema_request(&my_did.clone(), &schema_data_json).unwrap(); let schema_response = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &my_did, &schema_request).unwrap(); let schema_response: Reply = serde_json::from_str(&schema_response).unwrap(); @@ -764,7 +811,7 @@ mod high_cases { version: "3.0".to_string(), keys: keys }; - let schema_data_json = serde_json::to_string(&schema_data).unwrap(); + let schema_data_json = serde_json::to_string(&schema_data).unwrap(); let schema_request = LedgerUtils::build_schema_request(&my_did.clone(), &schema_data_json).unwrap(); let schema_response = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &my_did, &schema_request).unwrap(); let schema_response: Reply = serde_json::from_str(&schema_response).unwrap(); @@ -1170,7 +1217,7 @@ mod medium_cases { fn indy_build_node_request_works_for_missed_field_in_data_json() { let identifier = "identifier"; let dest = "dest"; - let data = r#"{"node_ip":"ip", "node_port": 1, "client_ip": "ip", "client_port": 1}"#; + let data = r#"{"node_ip":"10.0.0.100", "node_port": 1, "client_ip": "10.0.0.100", "client_port": 1}"#; let res = LedgerUtils::build_node_request(identifier, dest, data); assert!(res.is_err()); @@ -1181,7 +1228,7 @@ mod medium_cases { fn indy_build_node_request_works_for_wrong_service() { let identifier = "identifier"; let dest = "dest"; - let data = r#"{"node_ip":"ip", "node_port": 1, "client_ip": "ip", "client_port": 1, "alias":"some", "services": ["SERVICE"]}"#; + let data = r#"{"node_ip":"10.0.0.100", "node_port": 1, "client_ip": "10.0.0.100", "client_port": 1, "alias":"some", "services": ["SERVICE"]}"#; let res = LedgerUtils::build_node_request(identifier, dest, data); assert!(res.is_err()); diff --git a/tests/signus.rs b/tests/signus.rs index 7bb8775770..83a5645059 100644 --- a/tests/signus.rs +++ b/tests/signus.rs @@ -90,6 +90,17 @@ mod high_cases { TestUtils::cleanup_storage(); } + #[test] + fn indy_create_my_did_works_for_exists_crypto_type() { + TestUtils::cleanup_storage(); + + let wallet_handle = WalletUtils::create_and_open_wallet("pool1", None).unwrap(); + + SignusUtils::create_my_did(wallet_handle, r#"{"crypto_type":"ed25519"}"#).unwrap(); + + TestUtils::cleanup_storage(); + } + #[test] fn indy_create_my_did_works_for_invalid_wallet_handle() { TestUtils::cleanup_storage(); @@ -146,6 +157,22 @@ mod high_cases { TestUtils::cleanup_storage(); } + + #[test] + fn indy_replace_keys_works_for_seed() { + TestUtils::cleanup_storage(); + + let wallet_handle = WalletUtils::create_and_open_wallet("pool1", None).unwrap(); + + let (my_did, my_verkey, _) = SignusUtils::create_my_did(wallet_handle, "{}").unwrap(); + + let (new_verkey, _) = SignusUtils::replace_keys(wallet_handle, &my_did, r#"{"seed":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}"#).unwrap(); + assert_eq!(new_verkey, "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"); + + assert!(my_verkey != new_verkey); + + TestUtils::cleanup_storage(); + } } mod store_their_did { @@ -201,6 +228,31 @@ mod high_cases { TestUtils::cleanup_storage(); } + + #[test] + fn indy_store_their_did_works_without_did() { + TestUtils::cleanup_storage(); + + let wallet_handle = WalletUtils::create_and_open_wallet("pool1", None).unwrap(); + + let identity_json = r#"{"verkey":"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa"}"#; + let res = SignusUtils::store_their_did(wallet_handle, identity_json); + assert_eq!(res.unwrap_err(), ErrorCode::CommonInvalidStructure); + + TestUtils::cleanup_storage(); + } + + #[test] + fn indy_store_their_did_works_for_correct_crypto_type() { + TestUtils::cleanup_storage(); + + let wallet_handle = WalletUtils::create_and_open_wallet("pool1", None).unwrap(); + + let identity_json = r#"{"did":"8wZcEriaNLNKtteJvx7f8i", "verkey":"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa", "crypto_type": "ed25519"}"#; + SignusUtils::store_their_did(wallet_handle, identity_json).unwrap(); + + TestUtils::cleanup_storage(); + } } mod sign { @@ -240,7 +292,7 @@ mod high_cases { let message = r#"{"reqId":1495034346617224651}"#; - let res = SignusUtils::sign(wallet_handle, "some_did", message); + let res = SignusUtils::sign(wallet_handle, "did", message); assert_eq!(res.unwrap_err(), ErrorCode::WalletNotFoundError); TestUtils::cleanup_storage(); @@ -393,6 +445,41 @@ mod high_cases { TestUtils::cleanup_storage(); } + + #[test] + fn indy_verify_works_for_other_signer() { + TestUtils::cleanup_storage(); + let pool_name = "indy_verify_works_for_other_signer"; + + let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); + let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); + + let (did, verkey, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee1"}"#).unwrap(); + let (other_did, other_verkey, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Steward1"}"#).unwrap(); + + let identity_json = format!(r#"{{"did":"{}", "verkey":"{}"}}"#, did, verkey); + SignusUtils::store_their_did(wallet_handle, &identity_json).unwrap(); + + let identity_json = format!(r#"{{"did":"{}", "verkey":"{}"}}"#, other_did, other_verkey); + SignusUtils::store_their_did(wallet_handle, &identity_json).unwrap(); + + let message = r#"{ + "reqId":1496822211362017764, + "identifier":"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL", + "operation":{ + "type":"1", + "dest":"VsKV7grR1BUE29mG2Fm2kX", + "verkey":"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa" + } + }"#; + + let msg = SignusUtils::sign(wallet_handle, &did, message).unwrap(); + + let valid = SignusUtils::verify(wallet_handle, pool_handle, &other_did, &msg).unwrap(); + assert!(!valid); + + TestUtils::cleanup_storage(); + } } } @@ -465,6 +552,20 @@ mod medium_cases { TestUtils::cleanup_storage(); } + + #[test] + fn indy_replace_keys_works_for_not_invalid_crypto_type() { + TestUtils::cleanup_storage(); + + let wallet_handle = WalletUtils::create_and_open_wallet("pool1", None).unwrap(); + + let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, "{}").unwrap(); + + let res = SignusUtils::replace_keys(wallet_handle, &my_did, r#"{"crypto_type":"type"}"#); + assert_eq!(res.unwrap_err(), ErrorCode::SignusUnknownCryptoError); + + TestUtils::cleanup_storage(); + } } mod store_their_did { @@ -605,10 +706,10 @@ mod medium_cases { } #[test] - fn indy_verify_works_for_get_unknow_nym_from_ledger() { + fn indy_verify_works_for_get_ledger_not_found_nym() { TestUtils::cleanup_storage(); - let pool_name = "indy_verify_works_for_get_unknow_nym_from_ledger"; + let pool_name = "indy_verify_works_for_get_ledger_not_found_nym"; let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); @@ -628,10 +729,10 @@ mod medium_cases { } #[test] - fn indy_verify_works_for_unknown_nym() { + fn indy_verify_works_for_no_nym_in_wallet() { TestUtils::cleanup_storage(); - let pool_name = "indy_verify_works_for_unknown_did"; + let pool_name = "indy_verify_works_for_no_nym_in_wallet"; let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); From 336e7721708cccf5819854a1a7bc2fca8582ddd5 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 19 Jul 2017 17:18:38 +0300 Subject: [PATCH 237/349] Corrected pipeline --- Jenkinsfile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c34ee292d8..23503aa89c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -116,13 +116,12 @@ def testPipeline(file, env_name, run_interoperability_tests) { echo "${env_name} Test: Cleanup" try { sh "docker network inspect ${network_name}" - } catch (ignore) { + } catch (err) { + echo "${env_name} Tests: error while inspect network ${network_name} - ${err}" } try { - if (poolInst) { - echo "${env_name} Test: stop pool" - poolInst.stop() - } + echo "${env_name} Test: stop pool" + poolInst.stop() } catch (err) { echo "${env_name} Tests: error while stop pool ${err}" } From e7cdcb0b8057e453c55c284be1430e350c45aa3e Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 19 Jul 2017 17:26:14 +0300 Subject: [PATCH 238/349] added test for claim_def --- tests/ledger.rs | 4 +- tests/utils/anoncreds.rs | 1 + .../ledger/test_build_get_claim_def_txn.py | 34 +++++++++++ .../tests/ledger/test_submit_request.py | 60 ++++++++++++++++++- 4 files changed, 95 insertions(+), 4 deletions(-) diff --git a/tests/ledger.rs b/tests/ledger.rs index edb4b60c84..07c09a3760 100644 --- a/tests/ledger.rs +++ b/tests/ledger.rs @@ -655,9 +655,7 @@ mod high_cases { let get_schema_response: Reply = serde_json::from_str(&get_schema_response).unwrap(); - let claim_def_json = AnoncredsUtils::issuer_create_claim_definition(wallet_handle, "NcYxiDXkpYi6ov5FcYDi1e", - &serde_json::to_string(&get_schema_response.result).unwrap(), None, false).unwrap(); - info!("claim_def_json {:}", claim_def_json); + let claim_def_json = AnoncredsUtils::get_gvt_claim_def(); let claim_def: ClaimDefinition = serde_json::from_str(&claim_def_json).unwrap(); let claim_def_data = ClaimDefinitionData { diff --git a/tests/utils/anoncreds.rs b/tests/utils/anoncreds.rs index db4d3c05dc..4748227b1f 100644 --- a/tests/utils/anoncreds.rs +++ b/tests/utils/anoncreds.rs @@ -444,6 +444,7 @@ impl AnoncredsUtils { r#"{ "ref":1, "signature_type":"CL", + "origin":"CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW", "data":{ "primary":{ "n":"83469852984476956871633111285697420678256060723156580163068122759469567425381600849138438902552107548539766861666590365174848381535291010418041757276710240953030842046122202402016906205924972182252295487319094577329593677544393592632224714613427822130473474379696616183721440743475053734247824037725487533789856061706740833324717788602268746116297029721621398888459529131593826880823126900285858832457134377949183677639585442886904844793608783831753240185678448312284269486845497720949217396146132958861735347072722092449280372574205841746312833280031873247525372459800132930201998084029506922484661426185450002143461", diff --git a/wrappers/python/tests/ledger/test_build_get_claim_def_txn.py b/wrappers/python/tests/ledger/test_build_get_claim_def_txn.py index 589e9d40da..f6c547b60b 100644 --- a/wrappers/python/tests/ledger/test_build_get_claim_def_txn.py +++ b/wrappers/python/tests/ledger/test_build_get_claim_def_txn.py @@ -36,3 +36,37 @@ async def test_build_get_claim_def_request_works(): identifier, _ref, signature_type, origin )).decode()) assert expected_response.items() <= response.items() + + +@pytest.mark.asyncio +async def test_build_claim_def_request_works_for_correct_data_json(): + identifier = "identifier" + signature_type = "CL" + schema_seq_no = 1 + data = { + "primary": { + "n": "1", + "s": "2", + "rms": "3", + "r": { + "name": "1" + }, + "rctxt": "1", + "z": "1" + } + } + + expected_response = { + "identifier": "identifier", + "operation": { + "ref": schema_seq_no, + "data": json.dumps(data), + "type": "102", + "signature_type": signature_type + } + } + + response = json.loads((await ledger.build_claim_def_txn( + identifier, schema_seq_no, signature_type, json.dumps(data) + )).decode()) + assert expected_response.items() <= response.items() diff --git a/wrappers/python/tests/ledger/test_submit_request.py b/wrappers/python/tests/ledger/test_submit_request.py index 3a9534de1a..96a33b14fe 100644 --- a/wrappers/python/tests/ledger/test_submit_request.py +++ b/wrappers/python/tests/ledger/test_submit_request.py @@ -134,7 +134,8 @@ async def test_attrib_requests_works(pool_handle, wallet_handle): '{"seed":"000000000000000000000000Trustee1"}') (my_did, my_ver_key, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') - + nym_request = await ledger.build_nym_request(trustee_did.decode(), my_did.decode(), my_ver_key.decode(), None, None) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did.decode(), nym_request.decode()) attrib_request = await ledger.build_attrib_request(my_did.decode(), my_did.decode(), None, "{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}", None) await ledger.sign_and_submit_request(pool_handle, wallet_handle, my_did.decode(), attrib_request.decode()) @@ -177,6 +178,8 @@ async def test_schema_requests_works(pool_handle, wallet_handle): "keys": ["name", "male"] } + nym_request = await ledger.build_nym_request(trustee_did.decode(), my_did.decode(), my_ver_key.decode(), None, None) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did.decode(), nym_request.decode()) schema_request = await ledger.build_schema_request(my_did.decode(), json.dumps(schema_data)) await ledger.sign_and_submit_request(pool_handle, wallet_handle, my_did.decode(), schema_request.decode()) get_schema_data = { @@ -210,3 +213,58 @@ async def test_send_node_request_works_without_signature(pool_handle, wallet_han except Exception as e: assert type(IndyError(ErrorCode.LedgerInvalidTransaction)) == type(e) and \ IndyError(ErrorCode.LedgerInvalidTransaction).args == e.args + + +@pytest.mark.asyncio +async def test_claim_def_requests_works(pool_handle, wallet_handle): + (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"000000000000000000000000Trustee1"}') + (my_did, my_ver_key, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"00000000000000000000000000000My1"}') + + schema_data = { + "name": "gvt2", + "version": "2.0", + "keys": ["name", "male"] + } + + nym_request = await ledger.build_nym_request(trustee_did.decode(), my_did.decode(), my_ver_key.decode(), None, None) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did.decode(), nym_request.decode()) + + schema_request = await ledger.build_schema_request(my_did.decode(), json.dumps(schema_data)) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, my_did.decode(), schema_request.decode()) + + get_schema_data = { + "name": "gvt2", + "version": "2.0" + } + + get_schema_request = await ledger.build_get_schema_request(my_did.decode(), my_did.decode(), json.dumps(get_schema_data)) + get_schema_response = json.loads((await ledger.submit_request(pool_handle, get_schema_request.decode())).decode()) + + claim_def = { + "primary": { + "n": "83469852984476956871633111285697420678256060723156580163068122759469567425381600849138438902552107548539766861666590365174848381535291010418041757276710240953030842046122202402016906205924972182252295487319094577329593677544393592632224714613427822130473474379696616183721440743475053734247824037725487533789856061706740833324717788602268746116297029721621398888459529131593826880823126900285858832457134377949183677639585442886904844793608783831753240185678448312284269486845497720949217396146132958861735347072722092449280372574205841746312833280031873247525372459800132930201998084029506922484661426185450002143461", + "s": "36598527821865478336201608644402887021319976830281254144922838415193047189326184120876650311572665920640111967758238425066565864958446810892401358531545590342401290056836149703549220109981509774843525259400920352082531560361277411808530872594109525982462491998670199872903823657869742599086495624835178373073050767142081484206776345277546531080450529061958937980460303537107061046725579009809137197541389237618812289642185603461102513124991949835948586623327143696280240600789928383168220919049794681181861776889681393339729944540218566460627715413465709316412838042632482652979005394086058441511591756153781159121227", + "rms": "23836382972046033209463023456985914927629254782286444334728987813724281765327660893337383450653748691133061782449580026414785334582859397732571499366000805280757877601804441568263743400086744823885203441870748890135445454347495577599234477813361254101857848089907496868136222777024967328411073984887059985103475100012787049491016895625234124538894645853939428009610771524580099452739392988318945585946758355611531582519514003714424216836334706370901576611410508113637778751976890941210538254418937285168453791223070083264852447713991114719905171445881819334587600693321106919667204512182250084258986170095774914769107", + "r": { + "age": "15428480888651268593621235736458685943389726269437020388313417035842991073151072061010468945249435098482625869236498750525662874597991333642865524104221652457788998109101749530884821300954337535472137069380551054204373136155978715752232238326100335828797868667735730830741789880726890058203015780792583471770404478023662994191588489722949795849990796063953164194432710764145637578113087142419634074378464118254848566088943085760634805903735300398689750649630456000759025366784986694635635510206166144055869823907120081668956271923743188342071093889666111639924270726451727101864752767708690529389259470017692442002767", + "name": "74008461204977705404956807338714891429397387365673402608947856456696416827848931951447004905350314563364442667940680669672331872875260077257474781261367591510351742401708951175978700805098470304211391452678992053755170054677498844656517106987419550598382601263743442309896367374279461481792679346472671426558385003925845431219156475505665973289508268634194964491418902859845301351562575713510002838692825728016254605821829245646855474149449192539144107522081712005891593405826343897070114168186645885993480245755494685105636168333649181939830898090651120926156152753918086493335382129839850609934233944397884745134858", + "sex": "40646934914193532541511585946883243600955533193734077080129022860038019728021796610599139377923881754708640252789475144625086755150150612623804964347576907276705600241268266301487516824189453869193926251791711672689649199860304727280764676403810510047397326018392955950249975529169980045664874433828266623495515931483137318724210483205730962036282580749206735450480976847188040030165278917936054139926609849181885654646269083459580415131952938813839182742590617440550773580790446467896469090164142755499827316294406540664375065617280568303837662431668218593808092907551353093044984225946834165309588512359379032847125", + "height": "60077310006190228182950362501472785016827894350517184186566050586806482282196022414888288252599211919680339352529750982779980002923071031258837648242708410943080288964834346858544959217874890558006056551949543916094446891954292824146212277550956558692224016968153138097595802008943263818064605343108607131298420107448075252583276684858815371561492996587478784667827675142382692061950832554910690663724101360454494298013020706080246986445114235542283015624510836206522238238728405826712730615187235709554561445384409566940622412591208469650855059870671771721035756205878334354791247751663679130847366069215369484993653" + }, + "rctxt": "36378575722516953828830668112614685244571602424420162720244033008706985740860180373728219883172046821464173434592331868657297711725743060654773725561634332269874655603697872022630999786617840856366807034806938874090561725454026277048301648000835861491030368037108847175790943895107305383779598585532854170748970999977490244057635358075906501562932970296830906796719844887269636297064678777638050708353254894155336111384638276041851818109156194135995350001255928374102089400812445206030019103440866343736761861049159446083221399575945128480681798837648578166327164995640582517916904912672875184928940552983440410245037", + "z": "65210811645114955910002482704691499297899796787292244564644467629838455625296674951468505972574512639263601600908664306008863647466643899294681985964775001929521624341158696866597713112430928402519124073453804861185882073381514901830347278653016300430179820703804228663001232136885036042101307423527913402600370741689559698469878576457899715687929448757963179899698951620405467976414716277505767979494596626867505828267832223147104774684678295400387894506425769550011471322118172087199519094477785389750318762521728398390891214426117908390767403438354009767291938975195751081032073309083309746656253788033721103313036" + }, + "revocation": None + } + + claim_def_request = await ledger.build_claim_def_txn( + my_did.decode(), get_schema_response['result']['seqNo'], "CL", json.dumps(claim_def)) + + await ledger.sign_and_submit_request(pool_handle, wallet_handle, my_did.decode(), claim_def_request.decode()) + get_claim_def_request = await ledger.build_get_claim_def_txn( + my_did.decode(), get_schema_response['result']['seqNo'], "CL", get_schema_response['result']['data']['origin']) + get_claim_def_response = json.loads( + (await ledger.submit_request(pool_handle, get_claim_def_request.decode())).decode()) + assert claim_def == get_claim_def_response['result']['data'] \ No newline at end of file From e5561cf03491a6eac3d52e41038828553600cdc6 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 19 Jul 2017 18:03:01 +0300 Subject: [PATCH 239/349] added tests for get_txn_request --- .../tests/ledger/test_submit_request.py | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/wrappers/python/tests/ledger/test_submit_request.py b/wrappers/python/tests/ledger/test_submit_request.py index 96a33b14fe..83920a2942 100644 --- a/wrappers/python/tests/ledger/test_submit_request.py +++ b/wrappers/python/tests/ledger/test_submit_request.py @@ -267,4 +267,54 @@ async def test_claim_def_requests_works(pool_handle, wallet_handle): my_did.decode(), get_schema_response['result']['seqNo'], "CL", get_schema_response['result']['data']['origin']) get_claim_def_response = json.loads( (await ledger.submit_request(pool_handle, get_claim_def_request.decode())).decode()) - assert claim_def == get_claim_def_response['result']['data'] \ No newline at end of file + assert claim_def == get_claim_def_response['result']['data'] + + +@pytest.mark.asyncio +async def test_get_txn_request_works(pool_handle, wallet_handle): + (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"000000000000000000000000Trustee1"}') + + schema_data = json.dumps({ + "name": "gvt3", + "version": "3.0", + "keys": ["name"] + }) + + schema_request = await ledger.build_schema_request(my_did.decode(), schema_data) + schema_response = json.loads((await ledger.sign_and_submit_request( + pool_handle, wallet_handle, my_did.decode(), schema_request.decode())).decode()) + + get_schema_data = { + "name": "gvt3", + "version": "3.0" + } + get_schema_request = await ledger.build_get_schema_request( + my_did.decode(), my_did.decode(), json.dumps(get_schema_data)) + await ledger.submit_request(pool_handle, get_schema_request.decode()) + + get_txn_request = await ledger.build_get_txn_request(my_did.decode(), schema_response['result']['seqNo']) + get_txn_response = json.loads((await ledger.submit_request(pool_handle, get_txn_request.decode())).decode()) + assert schema_data == json.loads(get_txn_response['result']['data'])['data'] + + +@pytest.mark.asyncio +async def test_get_txn_request_works_for_invalid_seq_no(pool_handle, wallet_handle): + (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"000000000000000000000000Trustee1"}') + + schema_data = json.dumps({ + "name": "gvt3", + "version": "3.0", + "keys": ["name"] + }) + + schema_request = await ledger.build_schema_request(my_did.decode(), schema_data) + schema_response = json.loads((await ledger.sign_and_submit_request( + pool_handle, wallet_handle, my_did.decode(), schema_request.decode())).decode()) + + seq_no = schema_response['result']['seqNo'] + 1 + + get_txn_request = await ledger.build_get_txn_request(my_did.decode(), seq_no) + get_txn_response = json.loads((await ledger.submit_request(pool_handle, get_txn_request.decode())).decode()) + assert get_txn_response['result']['data'] == "{}" From 1f17435984744359ec1874b7347a5e034b21d567 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Wed, 19 Jul 2017 18:44:18 +0300 Subject: [PATCH 240/349] * agent_connect, agent_listen, agent_add_identity calls were implemented * wallet tests simplification --- wrappers/python/indy/agent.py | 159 +++++++++++++++++- wrappers/python/indy/error.py | 2 + wrappers/python/tests/agent/__init__.py | 0 .../python/tests/agent/test_agent_connect.py | 20 +++ .../python/tests/wallet/test_close_wallet.py | 12 +- .../python/tests/wallet/test_create_wallet.py | 9 +- .../python/tests/wallet/test_delete_wallet.py | 11 +- .../python/tests/wallet/test_open_wallet.py | 10 +- 8 files changed, 193 insertions(+), 30 deletions(-) create mode 100644 wrappers/python/tests/agent/__init__.py create mode 100644 wrappers/python/tests/agent/test_agent_connect.py diff --git a/wrappers/python/indy/agent.py b/wrappers/python/indy/agent.py index dc86d9a86e..2fca964483 100644 --- a/wrappers/python/indy/agent.py +++ b/wrappers/python/indy/agent.py @@ -1,9 +1,79 @@ +import asyncio import logging from ctypes import * +from typing import List, Tuple, Any +from .error import ErrorCode, IndyError from .libindy import do_call, create_cb +class Event: + handle: int + error: IndexError + + def is_success(self): + return self.error is None + + +class ConnectionEvent(Event): + connection_handle: int + sender_did: str + receiver_did: str + + def __init__(self, handle: int, err: int, connection_handle: int, sender_did: str, receiver_did): + self.handle = handle, + + if err != ErrorCode.Success: + self.error = IndyError(ErrorCode(err)) + else: + self.connection_handle = connection_handle + self.sender_did = sender_did + self.receiver_did = receiver_did + + +class MessageEvent(Event): + message: str + + def __init__(self, handle: int, err: int, message: str): + self.handle = handle, + + if err != ErrorCode.Success: + self._error = IndyError(ErrorCode(err)) + else: + self.message = message + + +_events: List[Event] = [] +_event_waiters: List[Tuple[List[int], Any, Any]] = [] + + +def _notify_event_waiters(): + for i, (handles, event_loop, future) in enumerate(_event_waiters): + for j, event in enumerate(_events): + if event.handle in handles: + del _event_waiters[i] + del _events[j] + event_loop.call_soon_threadsafe(lambda f, e: f.set_result(e), + future, + event) + + +async def agent_wait_for_event(handles: List[int]) -> Event: + logger = logging.getLogger(__name__) + logger.debug("agent_wait_for_event: >>> handles: %s", handles) + + event_loop = asyncio.get_event_loop() + future = event_loop.create_future() + + _event_waiters.append((handles, event_loop, future)) + _notify_event_waiters() + + res = await future + + logger.debug("agent_wait_for_event: <<< res: %s", res) + return res + + async def agent_connect(pool_handle: int, wallet_handle: int, sender_did: str, @@ -16,25 +86,27 @@ async def agent_connect(pool_handle: int, receiver_did) if not hasattr(agent_connect, "connection_cb"): - logger.debug("agent_connect: Creating callback") + logger.debug("agent_connect: Creating connection callback") agent_connect.connection_cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) - def _message_cb(connection_handle, err, message): + def _message_cb(connection_handle: int, err: int, message: str): logger.debug("agent_connect._message_cb: connection_handle: %i, err: %i, message: %s", connection_handle, err, message) + _events.append(MessageEvent(connection_handle, err, message)) + _notify_event_waiters() if not hasattr(agent_connect, "message_cb"): - logger.debug("agent_connect: Creating connection callback") - agent_connect.message_cb = CFUNCTYPE(None, c_int32, c_int32, c_int32)(_message_cb) + logger.debug("agent_connect: Creating message callback") + agent_connect.message_cb = CFUNCTYPE(None, c_int32, c_int32, c_char_p)(_message_cb) c_pool_handle = c_int32(pool_handle) c_wallet_handle = c_int32(wallet_handle) c_sender_did = c_char_p(sender_did.encode('utf-8')) c_receiver_did = c_char_p(receiver_did.encode('utf-8')) - res = await do_call('agent_connect', + res = await do_call('indy_agent_connect', c_pool_handle, c_wallet_handle, c_sender_did, @@ -44,3 +116,80 @@ def _message_cb(connection_handle, err, message): logger.debug("agent_connect: <<< res: %i", res) return res + + +async def agent_listen(endpoint: str) -> int: + logger = logging.getLogger(__name__) + logger.debug("agent_listen: >>> endpoint: %s", endpoint) + + if not hasattr(agent_listen, "listener_cb"): + logger.debug("agent_listen: Creating listener callback") + agent_listen.listener_cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) + + def _connection_cb(listener_handle: int, err: int, connection_handle: int, sender_did: str, receiver_did: str): + logger.debug("agent_connect._connection_cb: listener_handle: %i, err: %i, connection_handle: %i, sender_did: " + "%s, receiver_did: %s", + connection_handle, + err, + connection_handle, + sender_did, + receiver_did) + _events.append(ConnectionEvent(listener_handle, err, connection_handle, sender_did, receiver_did)) + _notify_event_waiters() + + if not hasattr(agent_listen, "connection_cb"): + logger.debug("agent_listen: Creating connection callback") + agent_listen.connection_cb = CFUNCTYPE(None, c_int32, c_int32, c_char_p)(_connection_cb) + + def _message_cb(connection_handle: int, err: int, message: str): + logger.debug("agent_connect._message_cb: connection_handle: %i, err: %i, message: %s", + connection_handle, + err, + message) + _events.append(MessageEvent(connection_handle, err, message)) + _notify_event_waiters() + + if not hasattr(agent_listen, "message_cb"): + logger.debug("agent_connect: Creating message callback") + agent_listen.message_cb = CFUNCTYPE(None, c_int32, c_int32, c_char_p)(_message_cb) + + c_endpoint = c_char_p(endpoint.encode('utf-8')) + + res = await do_call('indy_agent_listen', + c_endpoint, + agent_listen.listener_cb, + agent_listen.connection_cb, + agent_listen.message_cb) + + logger.debug("agent_listen: <<< res: %i", res) + return res + + +async def agent_add_identity(listener_handle: int, + pool_handle: int, + wallet_handle: int, + did: str) -> None: + logger = logging.getLogger(__name__) + logger.debug("agent_add_identity: >>> listener_handle: %i, pool_handle: %i, wallet_handle: %i, did: %s", + listener_handle, + pool_handle, + wallet_handle, + did) + + if not hasattr(agent_add_identity, "cb"): + logger.debug("agent_add_identity: Creating callback") + agent_add_identity.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_int32)) + + c_listener_handle = c_int32(listener_handle) + c_pool_handle = c_int32(pool_handle) + c_wallet_handle = c_int32(wallet_handle) + c_did = c_char_p(did.encode('utf-8')) + + await do_call('indy_agent_add_identity', + c_listener_handle, + c_pool_handle, + c_wallet_handle, + c_did, + agent_add_identity.cb) + + logger.debug("agent_add_identity: <<<") diff --git a/wrappers/python/indy/error.py b/wrappers/python/indy/error.py index ab1172b208..a9c17b76ce 100644 --- a/wrappers/python/indy/error.py +++ b/wrappers/python/indy/error.py @@ -112,5 +112,7 @@ class ErrorCode(IntEnum): class IndyError(Exception): + error_code: ErrorCode + def __init__(self, error_code: ErrorCode): self.error_code = error_code diff --git a/wrappers/python/tests/agent/__init__.py b/wrappers/python/tests/agent/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/wrappers/python/tests/agent/test_agent_connect.py b/wrappers/python/tests/agent/test_agent_connect.py new file mode 100644 index 0000000000..a30b8042a4 --- /dev/null +++ b/wrappers/python/tests/agent/test_agent_connect.py @@ -0,0 +1,20 @@ +import logging + +import pytest + +from indy import wallet +from ..utils import storage + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def cleanup_storage(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_agent_connect_works_for_all_data_in_wallet_present(): + pass diff --git a/wrappers/python/tests/wallet/test_close_wallet.py b/wrappers/python/tests/wallet/test_close_wallet.py index 20623a2627..e86fa3e724 100644 --- a/wrappers/python/tests/wallet/test_close_wallet.py +++ b/wrappers/python/tests/wallet/test_close_wallet.py @@ -9,7 +9,7 @@ @pytest.yield_fixture(autouse=True) -def before_after_each(): +def cleanup_storage(): storage.cleanup() yield storage.cleanup() @@ -17,14 +17,12 @@ def before_after_each(): @pytest.mark.asyncio async def test_close_wallet_works(): - pool_name = "indy_close_wallet_works" - wallet_name = "indy_close_wallet_works" + await wallet.create_wallet('pool1', 'wallet1', None, None, None) - await wallet.create_wallet(pool_name, wallet_name, None, None, None) - - wallet_handle = await wallet.open_wallet(wallet_name, None, None) + wallet_handle = await wallet.open_wallet('wallet1', None, None) await wallet.close_wallet(wallet_handle) - wallet_handle = await wallet.open_wallet(wallet_name, None, None) + + wallet_handle = await wallet.open_wallet('wallet1', None, None) await wallet.close_wallet(wallet_handle) assert True diff --git a/wrappers/python/tests/wallet/test_create_wallet.py b/wrappers/python/tests/wallet/test_create_wallet.py index 6138e667fc..0cce020577 100644 --- a/wrappers/python/tests/wallet/test_create_wallet.py +++ b/wrappers/python/tests/wallet/test_create_wallet.py @@ -9,7 +9,7 @@ @pytest.yield_fixture(autouse=True) -def before_after_each(): +def cleanup_storage(): storage.cleanup() yield storage.cleanup() @@ -17,8 +17,5 @@ def before_after_each(): @pytest.mark.asyncio async def test_create_wallet_works(): - pool_name = 'indy_create_wallet_works' - wallet_name = 'indy_create_wallet_works' - xtype = 'default' - - await wallet.create_wallet(pool_name, wallet_name, xtype, None, None) + await wallet.create_wallet('pool1', 'wallet1', 'default', None, None) + assert True diff --git a/wrappers/python/tests/wallet/test_delete_wallet.py b/wrappers/python/tests/wallet/test_delete_wallet.py index 4eb3485917..a4e3fb48fb 100644 --- a/wrappers/python/tests/wallet/test_delete_wallet.py +++ b/wrappers/python/tests/wallet/test_delete_wallet.py @@ -9,7 +9,7 @@ @pytest.yield_fixture(autouse=True) -def before_after_each(): +def cleanup_storage(): storage.cleanup() yield storage.cleanup() @@ -17,11 +17,8 @@ def before_after_each(): @pytest.mark.asyncio async def test_delete_wallet_works(): - pool_name = "indy_delete_wallet_works" - wallet_name = "indy_delete_wallet_works" - - await wallet.create_wallet(pool_name, wallet_name, None, None, None) - await wallet.delete_wallet(wallet_name, None) - await wallet.create_wallet(pool_name, wallet_name, None, None, None) + await wallet.create_wallet('pool1', 'wallet1', None, None, None) + await wallet.delete_wallet('wallet1', None) + await wallet.create_wallet('pool1', 'wallet1', None, None, None) assert True diff --git a/wrappers/python/tests/wallet/test_open_wallet.py b/wrappers/python/tests/wallet/test_open_wallet.py index 9d42ee372d..a5c2af9418 100644 --- a/wrappers/python/tests/wallet/test_open_wallet.py +++ b/wrappers/python/tests/wallet/test_open_wallet.py @@ -17,9 +17,9 @@ def before_after_each(): @pytest.mark.asyncio async def test_open_wallet_works(): - pool_name = "indy_open_wallet_works" - wallet_name = "indy_open_wallet_works" - - await wallet.create_wallet(pool_name, wallet_name, None, None, None) - wallet_handle = await wallet.open_wallet(wallet_name, None, None) + await wallet.create_wallet('pool1', 'wallet1', None, None, None) + wallet_handle = await wallet.open_wallet('wallet1', None, None) assert wallet_handle is not None + + await wallet.close_wallet(wallet_handle) + assert True From f030a28cda8ba2f1598865f5ab772821a55fad64 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Wed, 19 Jul 2017 19:11:19 +0300 Subject: [PATCH 241/349] * agent_remove_identity agent_send calls were implemented --- wrappers/python/indy/agent.py | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/wrappers/python/indy/agent.py b/wrappers/python/indy/agent.py index 2fca964483..8329ed4954 100644 --- a/wrappers/python/indy/agent.py +++ b/wrappers/python/indy/agent.py @@ -193,3 +193,55 @@ async def agent_add_identity(listener_handle: int, agent_add_identity.cb) logger.debug("agent_add_identity: <<<") + + +async def agent_remove_identity(listener_handle: int, + pool_handle: int, + wallet_handle: int, + did: str) -> None: + logger = logging.getLogger(__name__) + logger.debug("agent_remove_identity: >>> listener_handle: %i, pool_handle: %i, wallet_handle: %i, did: %s", + listener_handle, + pool_handle, + wallet_handle, + did) + + if not hasattr(agent_remove_identity, "cb"): + logger.debug("agent_remove_identity: Creating callback") + agent_remove_identity.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_int32)) + + c_listener_handle = c_int32(listener_handle) + c_pool_handle = c_int32(pool_handle) + c_wallet_handle = c_int32(wallet_handle) + c_did = c_char_p(did.encode('utf-8')) + + await do_call('indy_agent_remove_identity', + c_listener_handle, + c_pool_handle, + c_wallet_handle, + c_did, + agent_remove_identity.cb) + + logger.debug("agent_remove_identity: <<<") + + +async def agent_send(connection_handle: int, + message: str) -> None: + logger = logging.getLogger(__name__) + logger.debug("agent_send: >>> connection_handle: %i, message: %s", + connection_handle, + message) + + if not hasattr(agent_send, "cb"): + logger.debug("agent_send: Creating callback") + agent_send.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_int32)) + + c_connection_handle = c_int32(connection_handle) + c_message = c_char_p(message.encode('utf-8')) + + await do_call('indy_agent_send', + c_connection_handle, + c_message, + agent_send.cb) + + logger.debug("agent_send: <<<") From c48df497423e4ab1ee9771adf90b137299aa8a9a Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 20 Jul 2017 08:17:22 +0300 Subject: [PATCH 242/349] try --- ci/upload-rpm.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/ci/upload-rpm.sh b/ci/upload-rpm.sh index 8a5ad95cd1..587c7b73f1 100644 --- a/ci/upload-rpm.sh +++ b/ci/upload-rpm.sh @@ -7,10 +7,5 @@ fi key="$1" cat < Date: Thu, 20 Jul 2017 08:36:25 +0300 Subject: [PATCH 243/349] try --- ci/upload-rpm.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ci/upload-rpm.sh b/ci/upload-rpm.sh index 587c7b73f1..dabf5c1ff9 100644 --- a/ci/upload-rpm.sh +++ b/ci/upload-rpm.sh @@ -7,5 +7,20 @@ fi key="$1" cat < Date: Thu, 20 Jul 2017 08:51:28 +0300 Subject: [PATCH 244/349] try --- ci/rpm-build.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index 8987fdbcb6..e8415b14a7 100755 --- a/ci/rpm-build.sh +++ b/ci/rpm-build.sh @@ -1,10 +1,11 @@ #!/bin/bash if [ "$1" = "--help" ] ; then - echo "Usage: $0 " + echo "Usage: $0 $1 " fi commit="$1" +key="$2" mkdir -p /usr/src/rpm/SOURCES/ @@ -23,4 +24,11 @@ sed \ chown root.root indy-sdk.spec spectool -g -R indy-sdk.spec || exit 3 -rpmbuild -ba indy-sdk.spec || exit 4 \ No newline at end of file +rpmbuild -ba indy-sdk.spec || exit 4 + +cat < Date: Thu, 20 Jul 2017 09:25:43 +0300 Subject: [PATCH 245/349] try --- ci/rpm-build.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/rpm-build.sh b/ci/rpm-build.sh index e8415b14a7..00026a413b 100755 --- a/ci/rpm-build.sh +++ b/ci/rpm-build.sh @@ -27,6 +27,8 @@ spectool -g -R indy-sdk.spec || exit 3 rpmbuild -ba indy-sdk.spec || exit 4 cat < Date: Thu, 20 Jul 2017 09:50:59 +0300 Subject: [PATCH 246/349] Try upload deb files --- Jenkinsfile | 36 ++++++++++++++++++-- ci/deb-build-and-upload.sh | 27 +++++++++++++++ ci/{rpm-build.sh => rpm-build-and-upload.sh} | 5 +-- ci/upload-rpm.sh | 26 -------------- debian/control | 2 +- debian/rules | 2 +- 6 files changed, 65 insertions(+), 33 deletions(-) create mode 100755 ci/deb-build-and-upload.sh rename ci/{rpm-build.sh => rpm-build-and-upload.sh} (89%) delete mode 100644 ci/upload-rpm.sh diff --git a/Jenkinsfile b/Jenkinsfile index 23503aa89c..041fd5fe41 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -53,6 +53,13 @@ try { } } + // 4. PUBLISH DEB TO repo.evernym.com + stage('Publish RPM Files') { + node('ubuntu') { + publishDebFiles() + } + } + } catch (e) { currentBuild.result = "FAILED" node('ubuntu-master') { @@ -188,10 +195,8 @@ def publishRpmFiles() { sh 'chmod -R 777 ci' - sh "./ci/rpm-build.sh $commit" - withCredentials([file(credentialsId: 'EvernymRepoSSHKey', variable: 'evernym_repo_key')]) { - sh "./ci/upload-rpm.sh $evernym_repo_key" + sh "./ci/rpm-build-and-upload.sh $commit $evernym_repo_key" } } } @@ -199,4 +204,29 @@ def publishRpmFiles() { echo 'Publish RPM: Cleanup' step([$class: 'WsCleanup']) } +} + +def publishDebFiles() { + try { + echo 'Publish Deb files: Checkout csm' + checkout scm + + echo 'Publish Deb: Build docker image' + def testEnv = dockerHelpers.build(name) + + testEnv.inside('-u 0:0') { + + commit = sh(returnStdout: true, script: 'git rev-parse HEAD').trim() + + sh 'chmod -R 777 ci' + + withCredentials([file(credentialsId: 'EvernymRepoSSHKey', variable: 'evernym_repo_key')]) { + sh "./ci/deb-build-and-upload.sh $commit $evernym_repo_key" + } + } + } + finally { + echo 'Publish Deb: Cleanup' + step([$class: 'WsCleanup']) + } } \ No newline at end of file diff --git a/ci/deb-build-and-upload.sh b/ci/deb-build-and-upload.sh new file mode 100755 index 0000000000..f844a3bc81 --- /dev/null +++ b/ci/deb-build-and-upload.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +if [ "$1" = "--help" ] ; then + echo "Usage: $0 $1 " +fi + +commit="$1" +key="$2" + +version=$(wget -q https://raw.githubusercontent.com/hyperledger/indy-sdk/$commit/Cargo.toml -O - | grep -E '^version =' | head -n1 | cut -f2 -d= | tr -d '" ') + +[ -z $version ] && exit 1 +[ -z $commit ] && exit 2 +[ -z $key ] && exit 3 + +cd ci + +dpkg-buildpackage + +cat <" -fi - -key="$1" - -cat < -Build-Depends: libssl-dev, libsodium-dev, libsqlite0-dev +Build-Depends: libssl-dev, libsodium-dev, libsqlite3-dev Standards-Version: 0.1.1 Vcs-Git: https://github.com/hyperledger/indy-sdk/ Vcs-Browser: https://github.com/hyperledger/indy-sdk/ diff --git a/debian/rules b/debian/rules index 304d0abf88..d06c47ff6a 100755 --- a/debian/rules +++ b/debian/rules @@ -1,7 +1,7 @@ #!/usr/bin/make -f # -export PATH=/usr/local/bin:/usr/bin:/bin +export PATH=/usr/local/bin:/usr/bin:/bin:/root/.cargo/bin %: dh $@ From 3abf3cacb3a8e51dc61637a06e72aca27a7f8287 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 20 Jul 2017 09:54:45 +0300 Subject: [PATCH 247/349] Updated docker file --- ci/ubuntu.dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index bca34f7ead..312db2e0fe 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -18,7 +18,8 @@ RUN apt-get update && \ python3-pip \ python-setuptools \ apt-transport-https \ - ca-certificates + ca-certificates \ + debhelper RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BD33704C RUN echo "deb https://repo.evernym.com/deb xenial master" >> /etc/apt/sources.list From 813b7311dcbb7c0698934568db45afda23d60b83 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 20 Jul 2017 09:55:55 +0300 Subject: [PATCH 248/349] Updated dockerfile --- ci/ubuntu.dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index 312db2e0fe..47694d8457 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -19,7 +19,8 @@ RUN apt-get update && \ python-setuptools \ apt-transport-https \ ca-certificates \ - debhelper + debhelper \ + wget RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BD33704C RUN echo "deb https://repo.evernym.com/deb xenial master" >> /etc/apt/sources.list From ed5695a81f6f44a900d0d5479792be4177fe260c Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 20 Jul 2017 10:06:54 +0300 Subject: [PATCH 249/349] Corrected build script --- ci/deb-build-and-upload.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/deb-build-and-upload.sh b/ci/deb-build-and-upload.sh index f844a3bc81..c32dc72fb2 100755 --- a/ci/deb-build-and-upload.sh +++ b/ci/deb-build-and-upload.sh @@ -13,10 +13,10 @@ version=$(wget -q https://raw.githubusercontent.com/hyperledger/indy-sdk/$commit [ -z $commit ] && exit 2 [ -z $key ] && exit 3 -cd ci - dpkg-buildpackage +cd ci + cat < Date: Thu, 20 Jul 2017 10:25:09 +0300 Subject: [PATCH 250/349] try --- ci/deb-build-and-upload.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ci/deb-build-and-upload.sh b/ci/deb-build-and-upload.sh index c32dc72fb2..5aa0f6d84a 100755 --- a/ci/deb-build-and-upload.sh +++ b/ci/deb-build-and-upload.sh @@ -17,11 +17,17 @@ dpkg-buildpackage cd ci +ls /home + +echo "other dir" + +ls /home/indy + cat < Date: Thu, 20 Jul 2017 10:47:01 +0300 Subject: [PATCH 251/349] try --- ci/deb-build-and-upload.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ci/deb-build-and-upload.sh b/ci/deb-build-and-upload.sh index 5aa0f6d84a..29a14e48f6 100755 --- a/ci/deb-build-and-upload.sh +++ b/ci/deb-build-and-upload.sh @@ -15,19 +15,19 @@ version=$(wget -q https://raw.githubusercontent.com/hyperledger/indy-sdk/$commit dpkg-buildpackage -cd ci +ls -ls /home +echo +cd .. +ls +pwd -echo "other dir" - -ls /home/indy cat < Date: Thu, 20 Jul 2017 10:57:31 +0300 Subject: [PATCH 252/349] try --- ci/deb-build-and-upload.sh | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/ci/deb-build-and-upload.sh b/ci/deb-build-and-upload.sh index 29a14e48f6..1ab3f98428 100755 --- a/ci/deb-build-and-upload.sh +++ b/ci/deb-build-and-upload.sh @@ -15,19 +15,11 @@ version=$(wget -q https://raw.githubusercontent.com/hyperledger/indy-sdk/$commit dpkg-buildpackage -ls - -echo -cd .. -ls -pwd - - cat < Date: Thu, 20 Jul 2017 11:12:31 +0300 Subject: [PATCH 253/349] try --- ci/deb-build-and-upload.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/deb-build-and-upload.sh b/ci/deb-build-and-upload.sh index 1ab3f98428..a65b0b508f 100755 --- a/ci/deb-build-and-upload.sh +++ b/ci/deb-build-and-upload.sh @@ -19,7 +19,7 @@ cat < Date: Thu, 20 Jul 2017 11:33:27 +0300 Subject: [PATCH 254/349] Fixed typo --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 041fd5fe41..cc35f7be2d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -54,7 +54,7 @@ try { } // 4. PUBLISH DEB TO repo.evernym.com - stage('Publish RPM Files') { + stage('Publish DEB Files') { node('ubuntu') { publishDebFiles() } From 9331a41a21194f4deefe635a27acdda7cbd581d3 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 20 Jul 2017 11:44:19 +0300 Subject: [PATCH 255/349] added documentation to anoncreds wrapper --- src/api/anoncreds.rs | 2 +- wrappers/python/indy/anoncreds.py | 364 +++++++++++++++++++++++++++--- 2 files changed, 339 insertions(+), 27 deletions(-) diff --git a/src/api/anoncreds.rs b/src/api/anoncreds.rs index b3f1b2a01d..8a220d53e4 100644 --- a/src/api/anoncreds.rs +++ b/src/api/anoncreds.rs @@ -201,7 +201,6 @@ pub extern fn indy_issuer_create_claim(command_handle: i32, /// #Params /// wallet_handle: wallet handler (created by open_wallet). /// command_handle: command handle to map callback to user context. -/// issuer_did: a DID of the issuer signing transactions to the Ledger /// revoc_reg_seq_no: seq no of a revocation registry transaction in Ledger /// user_revoc_index: index of the user in the revocation registry /// cb: Callback that takes command result as parameter. @@ -633,6 +632,7 @@ pub extern fn indy_prover_get_claims_for_proof_req(command_handle: i32, /// "claim3_uuid_in_wallet": , /// } /// +/// master_secret_name: the name of the master secret stored in the wallet /// claim_def_jsons: all claim definition jsons participating in the proof request /// { /// "claim1_uuid_in_wallet": , diff --git a/wrappers/python/indy/anoncreds.py b/wrappers/python/indy/anoncreds.py index a4067ed1b2..9780957614 100644 --- a/wrappers/python/indy/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -1,17 +1,46 @@ +from .libindy import do_call, create_cb + +from typing import Optional +from ctypes import * + +import logging + + async def issuer_create_and_store_claim_def(wallet_handle: int, + issuer_did: str, schema_json: str, - signature_type: str, - create_non_revoc: bool, - claim_def_json: str, - claim_def_uuid: str) -> None: + signature_type: Optional[str], + create_non_revoc: bool) -> str: + """ + Create keys (both primary and revocation) for the given schema + and signature type (currently only CL signature type is supported). + Store the keys together with signature type and schema in a secure wallet as a claim definition. + The claim definition in the wallet is identifying by a returned unique key. + :param wallet_handle: wallet handler (created by open_wallet). + :param issuer_did: a DID of the issuer signing claim_def transaction to the Ledger + :param schema_json: schema as a json + :param signature_type: signature type (optional). Currently only 'CL' is supported. + :param create_non_revoc: whether to request non-revocation claim. + :return: claim definition json containing information about signature type, schema and issuer's public key. + Unique number identifying the public key in the wallet + """ pass async def issuer_create_and_store_revoc_reg(wallet_handle: int, - claim_def_seq_no: int, - max_claim_num: int, - revoc_reg_json: str, - revoc_reg_uuid: str) -> None: + issuer_did: str, + schema_seq_no: int, + max_claim_num: int) -> (str, str): + """ + Create a new revocation registry for the given claim definition. + Stores it in a secure wallet identifying by the returned key. + :param wallet_handle: wallet handler (created by open_wallet). + :param issuer_did: a DID of the issuer signing revoc_reg transaction to the Ledger + :param schema_seq_no: seq no of a schema transaction in Ledger + :param max_claim_num: maximum number of claims the new registry can process. + :return: Revoc registry json + Unique number identifying the revocation registry in the wallet + """ pass @@ -19,33 +48,105 @@ async def issuer_create_claim(wallet_handle: int, claim_req_json: str, claim_json: str, revoc_reg_seq_no: int, - user_revoc_index: int, - revoc_reg_update_json: str, - xclaim_json: str) -> None: + user_revoc_index: int) -> (str, str): + """ + Signs a given claim for the given user by a given key (claim ef). + The corresponding claim definition and revocation registry must be already created + an stored into the wallet. + :param wallet_handle: wallet handler (created by open_wallet). + :param claim_req_json: a claim request with a blinded secret + from the user (returned by prover_create_and_store_claim_req). + Also contains schema_seq_no and issuer_did + Example: + { + "blinded_ms" : , + "schema_seq_no" : , + "issuer_did" : + } + :param claim_json: a claim containing attribute values for each of requested attribute names. + Example: + { + "attr1" : ["value1", "value1_as_int"], + "attr2" : ["value2", "value2_as_int"] + } + :param revoc_reg_seq_no: (Optional, pass -1 if revoc_reg_seq_no is absentee) seq no of a revocation + registry transaction in Ledger + :param user_revoc_index: index of a new user in the revocation registry + (optional, pass -1 if user_revoc_index is absentee; default one is used if not provided) + :return: Revocation registry update json with a newly issued claim + Claim json containing issued claim, issuer_did, schema_seq_no, and revoc_reg_seq_no + used for issuance + { + "claim": , + "signature": , + "revoc_reg_seq_no", string, + "issuer_did", string, + "schema_seq_no", string, + } + """ pass async def issuer_revoke_claim(wallet_handle: int, - claim_def_seq_no: int, revoc_reg_seq_no: int, - user_revoc_index: int, - revoc_reg_update_json: str) -> None: + user_revoc_index: int) -> str: + """ + Revokes a user identified by a revoc_id in a given revoc-registry. + The corresponding claim definition and revocation registry must be already + created an stored into the wallet. + :param wallet_handle: wallet handler (created by open_wallet). + :param revoc_reg_seq_no: seq no of a revocation registry transaction in Ledger + :param user_revoc_index: index of the user in the revocation registry + :return: Revocation registry update json with a revoked claim + """ pass async def prover_store_claim_offer(wallet_handle: int, claim_offer_json: str) -> None: + """ + Stores a claim offer from the given issuer in a secure storage. + :param wallet_handle: wallet handler (created by open_wallet). + :param claim_offer_json: claim offer as a json containing information about the issuer and a claim: + { + "issuer_did": string, + "schema_seq_no": string + } + :return: None. + """ pass async def prover_get_claim_offers(wallet_handle: int, - filter_json: str, - claim_offers_json: str) -> None: + filter_json: str) -> str: + """ + Gets all stored claim offers (see prover_store_claim_offer). + A filter can be specified to get claim offers for specific Issuer, claim_def or schema only. + :param wallet_handle: wallet handler (created by open_wallet). + :param filter_json: optional filter to get claim offers for specific Issuer, claim_def or schema only only + Each of the filters is optional and can be combines + { + "issuer_did": string, + "schema_seq_no": string + } + :return: A json with a list of claim offers for the filter. + { + [{"issuer_did": string, + "schema_seq_no": string}] + } + """ pass async def prover_create_master_secret(wallet_handle: int, master_secret_name: str) -> None: + """ + Creates a master secret with a given name and stores it in the wallet. + The name must be unique. + :param wallet_handle: wallet handler (created by open_wallet). + :param master_secret_name: a new master secret name + :return: None. + """ pass @@ -53,25 +154,114 @@ async def prover_create_and_store_claim_req(wallet_handle: int, prover_did: str, claim_offer_json: str, claim_def_json: str, - master_secret_name: str, - claim_req_json: str) -> None: + master_secret_name: str) -> str: + """ + Creates a clam request json for the given claim offer and stores it in a secure wallet. + The claim offer contains the information about Issuer (DID, schema_seq_no), + and the schema (schema_seq_no). + The method gets public key and schema from the ledger, stores them in a wallet, + and creates a blinded master secret for a master secret identified by a provided name. + The master secret identified by the name must be already stored in the secure wallet (see prover_create_master_secret) + The blinded master secret is a part of the claim request. + :param wallet_handle: wallet handler (created by open_wallet). + :param prover_did: a DID of the prover + :param claim_offer_json: claim offer as a json containing information about the issuer and a claim: + { + "issuer_did": string, + "schema_seq_no": string + } + :param claim_def_json: claim definition json associated with issuer_did and schema_seq_no in the claim_offer + :param master_secret_name: the name of the master secret stored in the wallet + :return: Claim request json. + { + "blinded_ms" : , + "schema_seq_no" : , + "issuer_did" : + } + """ pass async def prover_store_claim(wallet_handle: int, claims_json: str) -> None: + """ + Updates the claim by a master secret and stores in a secure wallet. + The claim contains the information about + schema_seq_no, issuer_did, revoc_reg_seq_no (see issuer_create_claim). + Seq_no is a sequence number of the corresponding transaction in the ledger. + The method loads a blinded secret for this key from the wallet, + updates the claim and stores it in a wallet. + :param wallet_handle: wallet handler (created by open_wallet). + :param claims_json: claim json: + { + "claim": {attr1:[value, value_as_int]} + "signature": , + "schema_seq_no": string, + "revoc_reg_seq_no", string + "issuer_did", string + } + :return: None. + """ pass async def prover_get_claims(wallet_handle: int, - filter_json: str, - claims_json: str) -> None: + filter_json: str) -> str: + """ + Gets human readable claims according to the filter. + If filter is NULL, then all claims are returned. + Claims can be filtered by Issuer, claim_def and/or Schema. + :param wallet_handle: wallet handler (created by open_wallet). + :param filter_json: filter for claims + { + "issuer_did": string, + "schema_seq_no": string + } + :return: claims json + [{ + "claim_uuid": , + "attrs": [{"attr_name" : "attr_value"}], + "schema_seq_no": string, + "issuer_did": string, + "revoc_reg_seq_no": string, + }] + """ pass async def prover_get_claims_for_proof_req(wallet_handle: int, - proof_request_json: str, - claims_json: str) -> None: + proof_request_json: str) -> str: + """ + Gets human readable claims matching the given proof request. + :param wallet_handle: wallet handler (created by open_wallet). + :param proof_request_json: proof request json + { + "name": string, + "version": string, + "nonce": string, + "requested_attr1_uuid": , + "requested_attr2_uuid": , + "requested_attr3_uuid": , + "requested_predicate_1_uuid": , + "requested_predicate_2_uuid": , + } + :return: json with claims for the given pool request. + Claim consists of uuid, human-readable attributes (key-value map), schema_seq_no, issuer_did and revoc_reg_seq_no. + { + "requested_attr1_uuid": [claim1, claim2], + "requested_attr2_uuid": [], + "requested_attr3_uuid": [claim3], + "requested_predicate_1_uuid": [claim1, claim3], + "requested_predicate_2_uuid": [claim2], + }, where claim is + { + "claim_uuid": , + "attrs": [{"attr_name" : "attr_value"}], + "schema_seq_no": string, + "issuer_did": string, + "revoc_reg_seq_no": string, + } + """ pass @@ -79,9 +269,78 @@ async def prover_create_proof(wallet_handle: int, proof_req_json: str, requested_claims_json: str, schemas_json: str, + master_secret_name: str, claim_defs_json: str, - revoc_regs_json: str, - proof_json: str) -> None: + revoc_regs_json: str) -> str: + """ + Creates a proof according to the given proof request + Either a corresponding claim with optionally revealed attributes or self-attested attribute must be provided + for each requested attribute (see indy_prover_get_claims_for_pool_req). + A proof request may request multiple claims from different schemas and different issuers. + All required schemas, public keys and revocation registries must be provided. + The proof request also contains nonce. + The proof contains either proof or self-attested attribute value for each requested attribute. + :param wallet_handle: wallet handler (created by open_wallet). + :param proof_req_json: proof request json as come from the verifier + { + "nonce": string, + "requested_attr1_uuid": , + "requested_attr2_uuid": , + "requested_attr3_uuid": , + "requested_predicate_1_uuid": , + "requested_predicate_2_uuid": , + } + :param requested_claims_json: either a claim or self-attested attribute for each requested attribute + { + "requested_attr1_uuid": [claim1_uuid_in_wallet, true ], + "requested_attr2_uuid": [self_attested_attribute], + "requested_attr3_uuid": [claim2_seq_no_in_wallet, false] + "requested_attr4_uuid": [claim2_seq_no_in_wallet, true] + "requested_predicate_1_uuid": [claim2_seq_no_in_wallet], + "requested_predicate_2_uuid": [claim3_seq_no_in_wallet], + } + :param schemas_json: all schema jsons participating in the proof request + { + "claim1_uuid_in_wallet": , + "claim2_uuid_in_wallet": , + "claim3_uuid_in_wallet": , + } + :param master_secret_name: the name of the master secret stored in the wallet + + :param claim_defs_json: all claim definition jsons participating in the proof request + { + "claim1_uuid_in_wallet": , + "claim2_uuid_in_wallet": , + "claim3_uuid_in_wallet": , + } + :param revoc_regs_json: all revocation registry jsons participating in the proof request + { + "claim1_uuid_in_wallet": , + "claim2_uuid_in_wallet": , + "claim3_uuid_in_wallet": , + } + :return: Proof json + For each requested attribute either a proof (with optionally revealed attribute value) or + self-attested attribute value is provided. + Each proof is associated with a claim and corresponding schema_seq_no, issuer_did and revoc_reg_seq_no. + There ais also aggregated proof part common for all claim proofs. + { + "requested": { + "requested_attr1_id": [claim_proof1_uuid, revealed_attr1, revealed_attr1_as_int], + "requested_attr2_id": [self_attested_attribute], + "requested_attr3_id": [claim_proof2_uuid] + "requested_attr4_id": [claim_proof2_uuid, revealed_attr4, revealed_attr4_as_int], + "requested_predicate_1_uuid": [claim_proof2_uuid], + "requested_predicate_2_uuid": [claim_proof3_uuid], + } + "claim_proofs": { + "claim_proof1_uuid": [, issuer_did, schema_seq_no, revoc_reg_seq_no], + "claim_proof2_uuid": [, issuer_did, schema_seq_no, revoc_reg_seq_no], + "claim_proof3_uuid": [, issuer_did, schema_seq_no, revoc_reg_seq_no] + }, + "aggregated_proof": + } + """ pass @@ -90,6 +349,59 @@ async def verifier_verify_proof(wallet_handle: int, proof_json: str, schemas_json: str, claim_defs_jsons: str, - revoc_regs_json: str, - valid: bool) -> None: + revoc_regs_json: str) -> bool: + """ + Verifies a proof (of multiple claim). + All required schemas, public keys and revocation registries must be provided. + :param wallet_handle: wallet handler (created by open_wallet). + :param proof_request_json: initial proof request as sent by the verifier + { + "nonce": string, + "requested_attr1_uuid": , + "requested_attr2_uuid": , + "requested_attr3_uuid": , + "requested_predicate_1_uuid": , + "requested_predicate_2_uuid": , + } + :param proof_json: proof json + For each requested attribute either a proof (with optionally revealed attribute value) or + self-attested attribute value is provided. + Each proof is associated with a claim and corresponding schema_seq_no, issuer_did and revoc_reg_seq_no. + There ais also aggregated proof part common for all claim proofs. + { + "requested": { + "requested_attr1_id": [claim_proof1_uuid, revealed_attr1, revealed_attr1_as_int], + "requested_attr2_id": [self_attested_attribute], + "requested_attr3_id": [claim_proof2_uuid] + "requested_attr4_id": [claim_proof2_uuid, revealed_attr4, revealed_attr4_as_int], + "requested_predicate_1_uuid": [claim_proof2_uuid], + "requested_predicate_2_uuid": [claim_proof3_uuid], + } + "claim_proofs": { + "claim_proof1_uuid": [, issuer_did, schema_seq_no, revoc_reg_seq_no], + "claim_proof2_uuid": [, issuer_did, schema_seq_no, revoc_reg_seq_no], + "claim_proof3_uuid": [, issuer_did, schema_seq_no, revoc_reg_seq_no] + }, + "aggregated_proof": + } + :param schemas_json: all schema jsons participating in the proof + { + "claim_proof1_uuid": , + "claim_proof2_uuid": , + "claim_proof3_uuid": + } + :param claim_defs_jsons: all claim definition jsons participating in the proof + { + "claim_proof1_uuid": , + "claim_proof2_uuid": , + "claim_proof3_uuid": + } + :param revoc_regs_json: all revocation registry jsons participating in the proof + { + "claim_proof1_uuid": , + "claim_proof2_uuid": , + "claim_proof3_uuid": + } + :return: valid: true - if signature is valid, false - otherwise + """ pass From 3a2196d2c4472e05d86d165fd7f09a68766a10ee Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 20 Jul 2017 13:30:53 +0300 Subject: [PATCH 256/349] added documentation for wallet --- wrappers/python/indy/wallet.py | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/wrappers/python/indy/wallet.py b/wrappers/python/indy/wallet.py index d87661cc16..2f04aff080 100644 --- a/wrappers/python/indy/wallet.py +++ b/wrappers/python/indy/wallet.py @@ -11,6 +11,19 @@ async def create_wallet(pool_name: str, xtype: Optional[str], config: Optional[str], credentials: Optional[str]) -> None: + """ + Creates a new secure wallet with the given unique name. + :param pool_name: Name of the pool that corresponds to this wallet. + :param name: Name of the wallet. + :param xtype: (optional) Type of the wallet. Defaults to 'default'. + Custom types can be registered with indy_register_wallet_type call. + :param config: (optional) Wallet configuration json. List of supported keys are defined by wallet type. + if NULL, then default config will be used. + :param credentials: (optional) Wallet credentials json. List of supported keys are defined by wallet type. + if NULL, then default config will be used. + :return: Error code + """ + logger = logging.getLogger(__name__) logger.debug("create_wallet: >>> pool_name: %s, name: %s, xtype: %s, config: %s, credentials: %s", pool_name, @@ -43,6 +56,22 @@ async def create_wallet(pool_name: str, async def open_wallet(name: str, runtime_config: Optional[str], credentials: Optional[str]) -> int: + """ + Opens the wallet with specific name. + Wallet with corresponded name must be previously created with indy_create_wallet method. + It is impossible to open wallet with the same name more than once. + :param name: Name of the wallet. + :param runtime_config: (optional) Runtime wallet configuration json. + if NULL, then default runtime_config will be used. Example: + { + "freshnessTime": string (optional), Amount of minutes to consider wallet value as fresh. Defaults to 24*60. + ... List of additional supported keys are defined by wallet type. + } + :param credentials: (optional) Wallet credentials json. List of supported keys are defined by wallet type. + if NULL, then default credentials will be used. + :return: Handle to opened wallet to use in methods that require wallet access. + """ + logger = logging.getLogger(__name__) logger.debug("open_wallet: >>> name: %s, runtime_config: %s, credentials: %s", name, @@ -68,6 +97,12 @@ async def open_wallet(name: str, async def close_wallet(handle: int) -> None: + """ + Closes opened wallet and frees allocated resources. + :param handle: wallet handle returned by indy_open_wallet. + :return: Error code + """ + logger = logging.getLogger(__name__) logger.debug("close_wallet: >>> handle: %i", handle) @@ -86,6 +121,14 @@ async def close_wallet(handle: int) -> None: async def delete_wallet(name: str, credentials: Optional[str]) -> None: + """ + Deletes created wallet. + :param name: Name of the wallet to delete. + :param credentials: (optional) Wallet credentials json. List of supported keys are defined by wallet type. + if NULL, then default credentials will be used. + :return: + """ + logger = logging.getLogger(__name__) logger.debug("delete_wallet: >>> name: %s, credentials: %s", name, From 3c96f4c8dcdb510ca09fccedbe4ca96ba2229308 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 20 Jul 2017 13:36:07 +0300 Subject: [PATCH 257/349] added documentation for pool --- wrappers/python/indy/pool.py | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/wrappers/python/indy/pool.py b/wrappers/python/indy/pool.py index 40e3d33536..819cf62ed1 100644 --- a/wrappers/python/indy/pool.py +++ b/wrappers/python/indy/pool.py @@ -7,6 +7,17 @@ async def create_pool_ledger_config(config_name: str, config: Optional[str]) -> None: + """ + Creates a new local pool ledger configuration that can be used later to connect pool nodes. + :param config_name: Name of the pool ledger configuration. + :param config: (optional) Pool configuration json. if NULL, then default config will be used. Example: + { + "genesis_txn": string (optional), A path to genesis transaction file. If NULL, then a default one will be used. + If file doesn't exists default one will be created. + } + :return: Error code + """ + logger = logging.getLogger(__name__) logger.debug("create_pool_ledger_config: >>> config_name: %s, config: %s", config_name, @@ -30,6 +41,26 @@ async def create_pool_ledger_config(config_name: str, async def open_pool_ledger(config_name: str, config: Optional[str]) -> int: + """ + Opens pool ledger and performs connecting to pool nodes. + + Pool ledger configuration with corresponded name must be previously created + with indy_create_pool_ledger_config method. + It is impossible to open pool with the same name more than once. + :param config_name: Name of the pool ledger configuration. + :param config: (optional) Runtime pool configuration json. + if NULL, then default config will be used. Example: + { + "refreshOnOpen": bool (optional), Forces pool ledger to be refreshed immediately after opening. + Defaults to true. + "autoRefreshTime": int (optional), After this time in minutes pool ledger will be automatically refreshed. + Use 0 to disable automatic refresh. Defaults to 24*60. + "networkTimeout": int (optional), Network timeout for communication with nodes in milliseconds. + Defaults to 20000. + } + :return: Handle to opened pool to use in methods that require pool connection. + """ + logger = logging.getLogger(__name__) logger.debug("open_pool_ledger: >>> config_name: %s, config: %s", config_name, @@ -52,6 +83,12 @@ async def open_pool_ledger(config_name: str, async def refresh_pool_ledger(handle: int) -> None: + """ + Refreshes a local copy of a pool ledger and updates pool nodes connections. + :param handle: pool handle returned by indy_open_pool_ledger + :return: Error code + """ + logger = logging.getLogger(__name__) logger.debug("refresh_pool_ledger: >>> config_name: %s", handle) @@ -71,6 +108,12 @@ async def refresh_pool_ledger(handle: int) -> None: async def close_pool_ledger(handle: int) -> None: + """ + Closes opened pool ledger, opened nodes connections and frees allocated resources. + :param handle: pool handle returned by indy_open_pool_ledger. + :return: Error code + """ + logger = logging.getLogger(__name__) logger.debug("close_pool_ledger: >>> config_name: %s", handle) @@ -90,6 +133,12 @@ async def close_pool_ledger(handle: int) -> None: async def delete_pool_ledger_config(config_name: str) -> None: + """ + Deletes created pool ledger configuration. + :param config_name: Name of the pool ledger configuration to delete. + :return: Error code + """ + logger = logging.getLogger(__name__) logger.debug("delete_pool_ledger_config: >>> config_name: %s", config_name) From 861acfe81b336aaa145617f0cb57412eaedff124 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 20 Jul 2017 13:47:36 +0300 Subject: [PATCH 258/349] added documentation for signus --- src/api/signus.rs | 4 +- wrappers/python/indy/anoncreds.py | 13 ++++ wrappers/python/indy/pool.py | 5 ++ wrappers/python/indy/signus.py | 106 ++++++++++++++++++++++++++++++ wrappers/python/indy/wallet.py | 4 ++ 5 files changed, 130 insertions(+), 2 deletions(-) diff --git a/src/api/signus.rs b/src/api/signus.rs index 24871adb0d..341b0347d6 100644 --- a/src/api/signus.rs +++ b/src/api/signus.rs @@ -211,8 +211,7 @@ pub extern fn indy_sign(command_handle: i32, /// command_handle: command handle to map callback to user context. /// pool_handle: pool handle. /// did: DID that signed the message -/// msg: message -/// signature: a signature to be verified +/// signed_msg: message /// cb: Callback that takes command result as parameter. /// /// #Returns @@ -260,6 +259,7 @@ pub extern fn indy_verify_signature(command_handle: i32, /// #Params /// wallet_handle: wallet handler (created by open_wallet). /// command_handle: command handle to map callback to user context. +/// pool_handle: pool handle. /// my_did: encrypting DID /// did: encrypting DID /// msg: a message to be signed diff --git a/wrappers/python/indy/anoncreds.py b/wrappers/python/indy/anoncreds.py index 9780957614..3f23eb86f3 100644 --- a/wrappers/python/indy/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -16,6 +16,7 @@ async def issuer_create_and_store_claim_def(wallet_handle: int, and signature type (currently only CL signature type is supported). Store the keys together with signature type and schema in a secure wallet as a claim definition. The claim definition in the wallet is identifying by a returned unique key. + :param wallet_handle: wallet handler (created by open_wallet). :param issuer_did: a DID of the issuer signing claim_def transaction to the Ledger :param schema_json: schema as a json @@ -34,6 +35,7 @@ async def issuer_create_and_store_revoc_reg(wallet_handle: int, """ Create a new revocation registry for the given claim definition. Stores it in a secure wallet identifying by the returned key. + :param wallet_handle: wallet handler (created by open_wallet). :param issuer_did: a DID of the issuer signing revoc_reg transaction to the Ledger :param schema_seq_no: seq no of a schema transaction in Ledger @@ -53,6 +55,7 @@ async def issuer_create_claim(wallet_handle: int, Signs a given claim for the given user by a given key (claim ef). The corresponding claim definition and revocation registry must be already created an stored into the wallet. + :param wallet_handle: wallet handler (created by open_wallet). :param claim_req_json: a claim request with a blinded secret from the user (returned by prover_create_and_store_claim_req). @@ -94,6 +97,7 @@ async def issuer_revoke_claim(wallet_handle: int, Revokes a user identified by a revoc_id in a given revoc-registry. The corresponding claim definition and revocation registry must be already created an stored into the wallet. + :param wallet_handle: wallet handler (created by open_wallet). :param revoc_reg_seq_no: seq no of a revocation registry transaction in Ledger :param user_revoc_index: index of the user in the revocation registry @@ -106,6 +110,7 @@ async def prover_store_claim_offer(wallet_handle: int, claim_offer_json: str) -> None: """ Stores a claim offer from the given issuer in a secure storage. + :param wallet_handle: wallet handler (created by open_wallet). :param claim_offer_json: claim offer as a json containing information about the issuer and a claim: { @@ -122,6 +127,7 @@ async def prover_get_claim_offers(wallet_handle: int, """ Gets all stored claim offers (see prover_store_claim_offer). A filter can be specified to get claim offers for specific Issuer, claim_def or schema only. + :param wallet_handle: wallet handler (created by open_wallet). :param filter_json: optional filter to get claim offers for specific Issuer, claim_def or schema only only Each of the filters is optional and can be combines @@ -143,6 +149,7 @@ async def prover_create_master_secret(wallet_handle: int, """ Creates a master secret with a given name and stores it in the wallet. The name must be unique. + :param wallet_handle: wallet handler (created by open_wallet). :param master_secret_name: a new master secret name :return: None. @@ -163,6 +170,7 @@ async def prover_create_and_store_claim_req(wallet_handle: int, and creates a blinded master secret for a master secret identified by a provided name. The master secret identified by the name must be already stored in the secure wallet (see prover_create_master_secret) The blinded master secret is a part of the claim request. + :param wallet_handle: wallet handler (created by open_wallet). :param prover_did: a DID of the prover :param claim_offer_json: claim offer as a json containing information about the issuer and a claim: @@ -191,6 +199,7 @@ async def prover_store_claim(wallet_handle: int, Seq_no is a sequence number of the corresponding transaction in the ledger. The method loads a blinded secret for this key from the wallet, updates the claim and stores it in a wallet. + :param wallet_handle: wallet handler (created by open_wallet). :param claims_json: claim json: { @@ -211,6 +220,7 @@ async def prover_get_claims(wallet_handle: int, Gets human readable claims according to the filter. If filter is NULL, then all claims are returned. Claims can be filtered by Issuer, claim_def and/or Schema. + :param wallet_handle: wallet handler (created by open_wallet). :param filter_json: filter for claims { @@ -233,6 +243,7 @@ async def prover_get_claims_for_proof_req(wallet_handle: int, proof_request_json: str) -> str: """ Gets human readable claims matching the given proof request. + :param wallet_handle: wallet handler (created by open_wallet). :param proof_request_json: proof request json { @@ -280,6 +291,7 @@ async def prover_create_proof(wallet_handle: int, All required schemas, public keys and revocation registries must be provided. The proof request also contains nonce. The proof contains either proof or self-attested attribute value for each requested attribute. + :param wallet_handle: wallet handler (created by open_wallet). :param proof_req_json: proof request json as come from the verifier { @@ -353,6 +365,7 @@ async def verifier_verify_proof(wallet_handle: int, """ Verifies a proof (of multiple claim). All required schemas, public keys and revocation registries must be provided. + :param wallet_handle: wallet handler (created by open_wallet). :param proof_request_json: initial proof request as sent by the verifier { diff --git a/wrappers/python/indy/pool.py b/wrappers/python/indy/pool.py index 819cf62ed1..af2ce5b544 100644 --- a/wrappers/python/indy/pool.py +++ b/wrappers/python/indy/pool.py @@ -9,6 +9,7 @@ async def create_pool_ledger_config(config_name: str, config: Optional[str]) -> None: """ Creates a new local pool ledger configuration that can be used later to connect pool nodes. + :param config_name: Name of the pool ledger configuration. :param config: (optional) Pool configuration json. if NULL, then default config will be used. Example: { @@ -47,6 +48,7 @@ async def open_pool_ledger(config_name: str, Pool ledger configuration with corresponded name must be previously created with indy_create_pool_ledger_config method. It is impossible to open pool with the same name more than once. + :param config_name: Name of the pool ledger configuration. :param config: (optional) Runtime pool configuration json. if NULL, then default config will be used. Example: @@ -85,6 +87,7 @@ async def open_pool_ledger(config_name: str, async def refresh_pool_ledger(handle: int) -> None: """ Refreshes a local copy of a pool ledger and updates pool nodes connections. + :param handle: pool handle returned by indy_open_pool_ledger :return: Error code """ @@ -110,6 +113,7 @@ async def refresh_pool_ledger(handle: int) -> None: async def close_pool_ledger(handle: int) -> None: """ Closes opened pool ledger, opened nodes connections and frees allocated resources. + :param handle: pool handle returned by indy_open_pool_ledger. :return: Error code """ @@ -135,6 +139,7 @@ async def close_pool_ledger(handle: int) -> None: async def delete_pool_ledger_config(config_name: str) -> None: """ Deletes created pool ledger configuration. + :param config_name: Name of the pool ledger configuration to delete. :return: Error code """ diff --git a/wrappers/python/indy/signus.py b/wrappers/python/indy/signus.py index 2e42a8b8f6..2da472554d 100644 --- a/wrappers/python/indy/signus.py +++ b/wrappers/python/indy/signus.py @@ -6,6 +6,28 @@ async def create_and_store_my_did(wallet_handle: int, did_json: str) -> (str, str, str): + """ + Creates keys (signing and encryption keys) for a new + DID (owned by the caller of the library). + Identity's DID must be either explicitly provided, or taken as the first 16 bit of verkey. + Saves the Identity DID with keys in a secured Wallet, so that it can be used to sign + and encrypt transactions. + + :param wallet_handle: wallet handler (created by open_wallet). + :param did_json: Identity information as json. Example: + { + "did": string, (optional; + if not provided and cid param is false then the first 16 bit of the verkey will be used as a new DID; + if not provided and cid is true then the full verkey will be used as a new DID; + if provided, then keys will be replaced - key rotation use case) + "seed": string, (optional; if not provide then a random one will be created) + "crypto_type": string, (optional; if not set then ed25519 curve is used; + currently only 'ed25519' value is supported for this field) + "cid": bool, (optional; if not set then false is used;) + } + :return: DID, verkey (for verification of signature) and public_key (for decryption) + """ + logger = logging.getLogger(__name__) logger.debug("create_and_store_my_did: >>> wallet_handle: %s, did_json: %s", wallet_handle, @@ -29,6 +51,21 @@ async def create_and_store_my_did(wallet_handle: int, async def replace_keys(wallet_handle: int, did: str, identity_json: str) -> (str, str): + """ + Generated new keys (signing and encryption keys) for an existing + DID (owned by the caller of the library). + + :param wallet_handle: wallet handler (created by open_wallet). + :param did: signing DID + :param identity_json: Identity information as json. Example: + { + "seed": string, (optional; if not provide then a random one will be created) + "crypto_type": string, (optional; if not set then ed25519 curve is used; + currently only 'ed25519' value is supported for this field) + } + :return: verkey (for verification of signature) and public_key (for decryption) + """ + logger = logging.getLogger(__name__) logger.debug("replace_keys: >>> wallet_handle: %s, did: %s, identity_json: %s", wallet_handle, @@ -55,6 +92,21 @@ async def replace_keys(wallet_handle: int, async def store_their_did(wallet_handle: int, identity_json: str) -> None: + """ + Saves their DID for a pairwise connection in a secured Wallet, + so that it can be used to verify transaction. + + :param wallet_handle: wallet handler (created by open_wallet). + :param identity_json: Identity information as json. Example: + { + "did": string, (required) + "verkey": string (optional, if only pk is provided), + "crypto_type": string, (optional; if not set then ed25519 curve is used; + currently only 'ed25519' value is supported for this field) + } + :return: None + """ + logger = logging.getLogger(__name__) logger.debug("store_their_did: >>> wallet_handle: %s, identity_json: %s", wallet_handle, @@ -79,6 +131,16 @@ async def store_their_did(wallet_handle: int, async def sign(wallet_handle: int, did: str, msg: str) -> str: + """ + Signs a message by a signing key associated with my DID. The DID with a signing key + must be already created and stored in a secured wallet (see create_and_store_my_identity) + + :param wallet_handle: wallet handler (created by open_wallet). + :param did: signing DID + :param msg: a message to be signed + :return: a signature string + """ + logger = logging.getLogger(__name__) logger.debug("sign: >>> wallet_handle: %s, did: %s, msg: %s", wallet_handle, @@ -107,6 +169,21 @@ async def verify_signature(wallet_handle: int, pool_handle: int, did: str, signed_msg: str) -> bool: + """ + Verify a signature created by a key associated with a DID. + If a secure wallet doesn't contain a verkey associated with the given DID, + then verkey is read from the Ledger. + Otherwise either an existing verkey from wallet is used (see wallet_store_their_identity), + or it checks the Ledger (according to freshness settings set during initialization) + whether verkey is still the same and updates verkey for the DID if needed. + + :param wallet_handle: wallet handler (created by open_wallet). + :param pool_handle: pool handle. + :param did: DID that signed the message + :param signed_msg: message + :return: valid: true - if signature is valid, false - otherwise + """ + logger = logging.getLogger(__name__) logger.debug("verify_signature: >>> wallet_handle: %s, pool_handle: %s, did: %s, signed_msg: %s", wallet_handle, @@ -139,6 +216,22 @@ async def encrypt(wallet_handle: int, my_did: str, did: str, msg: str) -> (str, str): + """ + Encrypts a message by a public key associated with a DID. + If a secure wallet doesn't contain a public key associated with the given DID, + then the public key is read from the Ledger. + Otherwise either an existing public key from wallet is used (see wallet_store_their_identity), + or it checks the Ledger (according to freshness settings set during initialization) + whether public key is still the same and updates public key for the DID if needed. + + :param wallet_handle: wallet handler (created by open_wallet). + :param pool_handle: pool handle. + :param my_did: encrypting DID + :param did: encrypting DID + :param msg: a message to be signed + :return: an encrypted message and nonce + """ + logger = logging.getLogger(__name__) logger.debug("encrypt: >>> wallet_handle: %s, pool_handle: %s, my_did: %s, did: %s, msg: %s", wallet_handle, @@ -174,6 +267,19 @@ async def decrypt(wallet_handle: int, did: str, encrypted_msg: str, nonce: str) -> str: + """ + Decrypts a message encrypted by a public key associated with my DID. + The DID with a secret key must be already created and + stored in a secured wallet (see wallet_create_and_store_my_identity) + + :param wallet_handle: wallet handler (created by open_wallet). + :param my_did: DID + :param did: DID that signed the message + :param encrypted_msg: encrypted message + :param nonce: nonce that encrypted message + :return: decrypted message + """ + logger = logging.getLogger(__name__) logger.debug("decrypt: >>> wallet_handle: %s, my_did: %s, did: %s, encrypted_msg: %s, nonce: %s", wallet_handle, diff --git a/wrappers/python/indy/wallet.py b/wrappers/python/indy/wallet.py index 2f04aff080..04d22b6270 100644 --- a/wrappers/python/indy/wallet.py +++ b/wrappers/python/indy/wallet.py @@ -13,6 +13,7 @@ async def create_wallet(pool_name: str, credentials: Optional[str]) -> None: """ Creates a new secure wallet with the given unique name. + :param pool_name: Name of the pool that corresponds to this wallet. :param name: Name of the wallet. :param xtype: (optional) Type of the wallet. Defaults to 'default'. @@ -60,6 +61,7 @@ async def open_wallet(name: str, Opens the wallet with specific name. Wallet with corresponded name must be previously created with indy_create_wallet method. It is impossible to open wallet with the same name more than once. + :param name: Name of the wallet. :param runtime_config: (optional) Runtime wallet configuration json. if NULL, then default runtime_config will be used. Example: @@ -99,6 +101,7 @@ async def open_wallet(name: str, async def close_wallet(handle: int) -> None: """ Closes opened wallet and frees allocated resources. + :param handle: wallet handle returned by indy_open_wallet. :return: Error code """ @@ -123,6 +126,7 @@ async def delete_wallet(name: str, credentials: Optional[str]) -> None: """ Deletes created wallet. + :param name: Name of the wallet to delete. :param credentials: (optional) Wallet credentials json. List of supported keys are defined by wallet type. if NULL, then default credentials will be used. From de0f34a4ee28dc4f067e41d0e988393ae5799bc4 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 20 Jul 2017 13:59:16 +0300 Subject: [PATCH 259/349] added documentation for ledger --- src/api/ledger.rs | 2 +- wrappers/python/indy/ledger.py | 124 +++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) diff --git a/src/api/ledger.rs b/src/api/ledger.rs index 0bf2c4f8e6..f509cae1b9 100644 --- a/src/api/ledger.rs +++ b/src/api/ledger.rs @@ -143,7 +143,7 @@ pub extern fn indy_build_get_ddo_request(command_handle: i32, /// submitter_did: Id of Identity stored in secured Wallet. /// target_did: Id of Identity stored in secured Wallet. /// verkey: verification key -/// alias +/// alias: alias /// role: Role of a user NYM record /// cb: Callback that takes command result as parameter. /// diff --git a/wrappers/python/indy/ledger.py b/wrappers/python/indy/ledger.py index 2cc7d3b7ec..f425b51d77 100644 --- a/wrappers/python/indy/ledger.py +++ b/wrappers/python/indy/ledger.py @@ -9,6 +9,20 @@ async def sign_and_submit_request(pool_handle: int, wallet_handle: int, submitter_did: str, request_json: str) -> str: + """ + Signs and submits request message to validator pool. + + Adds submitter information to passed request json, signs it with submitter + sign key (see wallet_sign), and sends signed request message + to validator pool (see write_request). + + :param pool_handle: pool handle (created by open_pool_ledger). + :param wallet_handle: wallet handle (created by open_wallet). + :param submitter_did: Id of Identity stored in secured Wallet. + :param request_json: Request data json. + :return: Request result as json. + """ + logger = logging.getLogger(__name__) logger.debug("sign_and_submit_request: >>> pool_handle: %s, wallet_handle: %s, submitter_did: %s, request_json: %s", pool_handle, @@ -38,6 +52,15 @@ async def sign_and_submit_request(pool_handle: int, async def submit_request(pool_handle: int, request_json: str) -> str: + """ + Publishes request message to validator pool (no signing, unlike sign_and_submit_request). + The request is sent to the validator pool as is. It's assumed that it's already prepared. + + :param pool_handle: pool handle (created by open_pool_ledger). + :param request_json: Request data json. + :return: Request result as json. + """ + logger = logging.getLogger(__name__) logger.debug("submit_request: >>> pool_handle: %s, request_json: %s", pool_handle, @@ -61,6 +84,14 @@ async def submit_request(pool_handle: int, async def build_get_ddo_request(submitter_did: str, target_did: str) -> str: + """ + Builds a request to get a DDO. + + :param submitter_did: Id of Identity stored in secured Wallet. + :param target_did: Id of Identity stored in secured Wallet. + :return: Request result as json. + """ + logger = logging.getLogger(__name__) logger.debug("build_get_ddo_request: >>> submitter_did: %s, target_did: %s", submitter_did, @@ -87,6 +118,17 @@ async def build_nym_request(submitter_did: str, ver_key: Optional[str], alias: Optional[str], role: Optional[str]) -> str: + """ + Builds a NYM request. + + :param submitter_did: Id of Identity stored in secured Wallet. + :param target_did: Id of Identity stored in secured Wallet. + :param ver_key: verification key + :param alias: alias + :param role: Role of a user NYM record + :return: Request result as json. + """ + logger = logging.getLogger(__name__) logger.debug("build_nym_request: >>> submitter_did: %s, target_did: %s, ver_key: %s, alias: %s, role: %s", submitter_did, @@ -122,6 +164,17 @@ async def build_attrib_request(submitter_did: str, hash: Optional[str], raw: Optional[str], enc: Optional[str]) -> str: + """ + Builds an ATTRIB request. + + :param submitter_did: Id of Identity stored in secured Wallet. + :param target_did: Id of Identity stored in secured Wallet. + :param hash: Hash of attribute data + :param raw: represented as json, where key is attribute name and value is it's value + :param enc: Encrypted attribute data + :return: Request result as json. + """ + logger = logging.getLogger(__name__) logger.debug("build_attrib_request: >>> submitter_did: %s, target_did: %s, hash: %s, raw: %s, enc: %s", submitter_did, @@ -155,6 +208,15 @@ async def build_attrib_request(submitter_did: str, async def build_get_attrib_request(submitter_did: str, target_did: str, data: str) -> str: + """ + Builds a GET_ATTRIB request. + + :param submitter_did: Id of Identity stored in secured Wallet. + :param target_did: Id of Identity stored in secured Wallet. + :param data: name (attribute name) + :return: Request result as json. + """ + logger = logging.getLogger(__name__) logger.debug("build_get_attrib_request: >>> submitter_did: %s, target_did: %s, data: %s", submitter_did, @@ -181,6 +243,14 @@ async def build_get_attrib_request(submitter_did: str, async def build_get_nym_request(submitter_did: str, target_did: str) -> str: + """ + Builds a GET_NYM request. + + :param submitter_did: Id of Identity stored in secured Wallet. + :param target_did: Id of Identity stored in secured Wallet. + :return: Request result as json. + """ + logger = logging.getLogger(__name__) logger.debug("build_get_nym_request: >>> submitter_did: %s, target_did: %s", submitter_did, @@ -204,6 +274,14 @@ async def build_get_nym_request(submitter_did: str, async def build_schema_request(submitter_did: str, data: str) -> str: + """ + Builds a SCHEMA request. + + :param submitter_did: Id of Identity stored in secured Wallet. + :param data: name, version, type, attr_names (ip, port, keys) + :return: Request result as json. + """ + logger = logging.getLogger(__name__) logger.debug("build_schema_request: >>> submitter_did: %s, data: %s", submitter_did, @@ -228,6 +306,15 @@ async def build_schema_request(submitter_did: str, async def build_get_schema_request(submitter_did: str, dest: str, data: str) -> str: + """ + Builds a GET_SCHEMA request. + + :param submitter_did: Id of Identity stored in secured Wallet. + :param dest: Id of Identity stored in secured Wallet. + :param data: name, version + :return: Request result as json. + """ + logger = logging.getLogger(__name__) logger.debug("build_get_schema_request: >>> submitter_did: %s, dest: %s, data: %s", submitter_did, @@ -256,6 +343,16 @@ async def build_claim_def_txn(submitter_did: str, xref: int, signature_type: str, data: str) -> str: + """ + Builds an CLAIM_DEF request. + + :param submitter_did: Id of Identity stored in secured Wallet. + :param xref: Seq. number of schema + :param signature_type: signature type (only CL supported now) + :param data: components of a key in json: N, R, S, Z + :return: Request result as json. + """ + logger = logging.getLogger(__name__) logger.debug("build_get_schema_request: >>> submitter_did: %s, xref: %s, signature_type: %s, data: %s", submitter_did, @@ -287,6 +384,16 @@ async def build_get_claim_def_txn(submitter_did: str, xref: int, signature_type: str, origin: str) -> str: + """ + Builds a GET_CLAIM_DEF request. + + :param submitter_did: Id of Identity stored in secured Wallet. + :param xref: Seq. number of schema + :param signature_type: signature type (only CL supported now) + :param origin: issuer did + :return: Request result as json. + """ + logger = logging.getLogger(__name__) logger.debug("build_get_claim_def_txn: >>> submitter_did: %s, xref: %s, signature_type: %s, origin: %s", submitter_did, @@ -317,6 +424,15 @@ async def build_get_claim_def_txn(submitter_did: str, async def build_node_request(submitter_did: str, target_did: str, data: str) -> str: + """ + Builds a NODE request. + + :param submitter_did: Id of Identity stored in secured Wallet. + :param target_did: Id of Identity stored in secured Wallet. + :param data: id of a target NYM record + :return: Request result as json. + """ + logger = logging.getLogger(__name__) logger.debug("build_node_request: >>> submitter_did: %s, target_did: %s, data: %s", submitter_did, @@ -343,6 +459,14 @@ async def build_node_request(submitter_did: str, async def build_get_txn_request(submitter_did: str, data: int) -> str: + """ + Builds a GET_TXN request. + + :param submitter_did: Id of Identity stored in secured Wallet. + :param data: seq_no of transaction in ledger + :return: Request result as json. + """ + logger = logging.getLogger(__name__) logger.debug("build_get_txn_request: >>> submitter_did: %s, data: %s", submitter_did, From 412361ce010ed2f77faf1188850af278a38b3b11 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 20 Jul 2017 14:23:14 +0300 Subject: [PATCH 260/349] Tests refactoring --- tests/ledger.rs | 39 ++++++++--------- .../indy/sdk/ledger/AttribRequestsTest.java | 5 +-- .../indy/sdk/ledger/ClaimDefRequestsTest.java | 31 +++++++++++--- .../indy/sdk/ledger/NymRequestsTest.java | 20 ++------- .../indy/sdk/ledger/RequestsTest.java | 42 +++++++++++++------ 5 files changed, 77 insertions(+), 60 deletions(-) diff --git a/tests/ledger.rs b/tests/ledger.rs index 137a5fb9a6..7ea496744e 100644 --- a/tests/ledger.rs +++ b/tests/ledger.rs @@ -80,7 +80,7 @@ mod high_cases { let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); - let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), None, None, None).unwrap(); @@ -101,7 +101,7 @@ mod high_cases { let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); - let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), None, None, None).unwrap(); @@ -120,7 +120,7 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config("pool1").unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet("pool2", None).unwrap(); - let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), None, None, None).unwrap(); @@ -174,7 +174,7 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), None, None, None).unwrap(); @@ -256,7 +256,7 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); let nym_request = LedgerUtils::build_nym_request(&my_did.clone(), &my_did.clone(), None, None, None).unwrap(); @@ -297,7 +297,7 @@ mod high_cases { let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); - let (my_did, my_verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); + let (my_did, my_verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), Some(&my_verkey.clone()), None, None).unwrap(); @@ -405,7 +405,7 @@ mod high_cases { let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); - let (my_did, my_verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); + let (my_did, my_verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), Some(&my_verkey.clone()), None, None).unwrap(); LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request).unwrap(); @@ -576,7 +576,7 @@ mod high_cases { let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); - let (my_did, my_verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); + let (my_did, my_verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); let role = "STEWARD"; let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), Some(&my_verkey), None, Some(role)).unwrap(); @@ -655,9 +655,7 @@ mod high_cases { let get_schema_response: Reply = serde_json::from_str(&get_schema_response).unwrap(); - let claim_def_json = AnoncredsUtils::issuer_create_claim_definition(wallet_handle, &my_did.clone(), - &serde_json::to_string(&get_schema_response.result).unwrap(), None, false).unwrap(); - info!("claim_def_json {:}", claim_def_json); + let claim_def_json = AnoncredsUtils::get_gvt_claim_def(); let claim_def: ClaimDefinition = serde_json::from_str(&claim_def_json).unwrap(); let claim_def_data = ClaimDefinitionData { @@ -844,12 +842,12 @@ mod medium_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); - let trustee_did = "trusteedid"; - let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), None, None, None).unwrap(); + let signer_did = "Fjc4fCrwGxBq2BkqGs5wEu"; + let nym_request = LedgerUtils::build_nym_request(&signer_did.clone(), &my_did.clone(), None, None, None).unwrap(); - let res = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request); + let res = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &signer_did, &nym_request); assert_eq!(res.unwrap_err(), ErrorCode::WalletNotFoundError); TestUtils::cleanup_storage(); @@ -903,7 +901,7 @@ mod medium_cases { let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); - let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), None, None, None).unwrap(); @@ -924,7 +922,7 @@ mod medium_cases { let (trustee_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); - let (my_did, my_verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); + let (my_did, my_verkey, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); let role = "STEWARD"; let alias = "some_alias"; @@ -985,7 +983,7 @@ mod medium_cases { let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); let (trustee_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"000000000000000000000000Trustee9","cid":true}"#).unwrap(); - let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); let nym_request = LedgerUtils::build_nym_request(&trustee_did.clone(), &my_did.clone(), None, None, None).unwrap(); let res = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request); @@ -1050,7 +1048,7 @@ mod medium_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, None).unwrap(); let attrib_request = LedgerUtils::build_attrib_request(&my_did.clone(), &my_did.clone(), @@ -1196,11 +1194,10 @@ mod medium_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger_config(pool_name).unwrap(); let wallet_handle = WalletUtils::create_and_open_wallet(pool_name, None).unwrap(); - let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("00000000000000000000000000000My1")).unwrap(); + let (my_did, _, _) = SignusUtils::create_and_store_my_did(wallet_handle, Some("000000000000000000000000Trustee1")).unwrap(); let get_schema_data = "{\"name\":\"schema_name\",\"version\":\"2.0\"}"; let get_schema_request = LedgerUtils::build_get_schema_request(&my_did.clone(), &my_did.clone(), get_schema_data).unwrap(); - ; let get_schema_response = PoolUtils::send_request(pool_handle, &get_schema_request).unwrap(); let get_schema_response: Reply = serde_json::from_str(&get_schema_response).unwrap(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AttribRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AttribRequestsTest.java index d0a6385712..ad580900b7 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AttribRequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AttribRequestsTest.java @@ -119,10 +119,7 @@ public void testAttribRequestsWorks() throws Exception { SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); - SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); - - SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, "{}").get(); String myDid = myDidResult.getDid(); String myVerkey = myDidResult.getVerkey(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/ClaimDefRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/ClaimDefRequestsTest.java index cc4ee91806..d69e57fb8c 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/ClaimDefRequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/ClaimDefRequestsTest.java @@ -44,6 +44,28 @@ public void closePool() throws Exception { Wallet.deleteWallet(walletName, null).get(); } + private String claimDefTemplate = "{\n" + + " \"ref\":%d,\n" + + " \"signature_type\":\"CL\",\n" + + " \"origin\":\"%s\",\n" + + " \"data\":{\n" + + " \"primary\":{\n" + + " \"n\":\"83469852984476956871633111285697420678256060723156580163068122759469567425381600849138438902552107548539766861666590365174848381535291010418041757276710240953030842046122202402016906205924972182252295487319094577329593677544393592632224714613427822130473474379696616183721440743475053734247824037725487533789856061706740833324717788602268746116297029721621398888459529131593826880823126900285858832457134377949183677639585442886904844793608783831753240185678448312284269486845497720949217396146132958861735347072722092449280372574205841746312833280031873247525372459800132930201998084029506922484661426185450002143461\",\n" + + " \"s\":\"36598527821865478336201608644402887021319976830281254144922838415193047189326184120876650311572665920640111967758238425066565864958446810892401358531545590342401290056836149703549220109981509774843525259400920352082531560361277411808530872594109525982462491998670199872903823657869742599086495624835178373073050767142081484206776345277546531080450529061958937980460303537107061046725579009809137197541389237618812289642185603461102513124991949835948586623327143696280240600789928383168220919049794681181861776889681393339729944540218566460627715413465709316412838042632482652979005394086058441511591756153781159121227\",\n" + + " \"rms\":\"23836382972046033209463023456985914927629254782286444334728987813724281765327660893337383450653748691133061782449580026414785334582859397732571499366000805280757877601804441568263743400086744823885203441870748890135445454347495577599234477813361254101857848089907496868136222777024967328411073984887059985103475100012787049491016895625234124538894645853939428009610771524580099452739392988318945585946758355611531582519514003714424216836334706370901576611410508113637778751976890941210538254418937285168453791223070083264852447713991114719905171445881819334587600693321106919667204512182250084258986170095774914769107\",\n" + + " \"r\":{\n" + + " \"age\":\"15428480888651268593621235736458685943389726269437020388313417035842991073151072061010468945249435098482625869236498750525662874597991333642865524104221652457788998109101749530884821300954337535472137069380551054204373136155978715752232238326100335828797868667735730830741789880726890058203015780792583471770404478023662994191588489722949795849990796063953164194432710764145637578113087142419634074378464118254848566088943085760634805903735300398689750649630456000759025366784986694635635510206166144055869823907120081668956271923743188342071093889666111639924270726451727101864752767708690529389259470017692442002767\",\n" + + " \"name\":\"74008461204977705404956807338714891429397387365673402608947856456696416827848931951447004905350314563364442667940680669672331872875260077257474781261367591510351742401708951175978700805098470304211391452678992053755170054677498844656517106987419550598382601263743442309896367374279461481792679346472671426558385003925845431219156475505665973289508268634194964491418902859845301351562575713510002838692825728016254605821829245646855474149449192539144107522081712005891593405826343897070114168186645885993480245755494685105636168333649181939830898090651120926156152753918086493335382129839850609934233944397884745134858\",\n" + + " \"sex\":\"40646934914193532541511585946883243600955533193734077080129022860038019728021796610599139377923881754708640252789475144625086755150150612623804964347576907276705600241268266301487516824189453869193926251791711672689649199860304727280764676403810510047397326018392955950249975529169980045664874433828266623495515931483137318724210483205730962036282580749206735450480976847188040030165278917936054139926609849181885654646269083459580415131952938813839182742590617440550773580790446467896469090164142755499827316294406540664375065617280568303837662431668218593808092907551353093044984225946834165309588512359379032847125\",\n" + + " \"height\":\"60077310006190228182950362501472785016827894350517184186566050586806482282196022414888288252599211919680339352529750982779980002923071031258837648242708410943080288964834346858544959217874890558006056551949543916094446891954292824146212277550956558692224016968153138097595802008943263818064605343108607131298420107448075252583276684858815371561492996587478784667827675142382692061950832554910690663724101360454494298013020706080246986445114235542283015624510836206522238238728405826712730615187235709554561445384409566940622412591208469650855059870671771721035756205878334354791247751663679130847366069215369484993653\"\n" + + " },\n" + + " \"rctxt\":\"36378575722516953828830668112614685244571602424420162720244033008706985740860180373728219883172046821464173434592331868657297711725743060654773725561634332269874655603697872022630999786617840856366807034806938874090561725454026277048301648000835861491030368037108847175790943895107305383779598585532854170748970999977490244057635358075906501562932970296830906796719844887269636297064678777638050708353254894155336111384638276041851818109156194135995350001255928374102089400812445206030019103440866343736761861049159446083221399575945128480681798837648578166327164995640582517916904912672875184928940552983440410245037\",\n" + + " \"z\":\"65210811645114955910002482704691499297899796787292244564644467629838455625296674951468505972574512639263601600908664306008863647466643899294681985964775001929521624341158696866597713112430928402519124073453804861185882073381514901830347278653016300430179820703804228663001232136885036042101307423527913402600370741689559698469878576457899715687929448757963179899698951620405467976414716277505767979494596626867505828267832223147104774684678295400387894506425769550011471322118172087199519094477785389750318762521728398390891214426117908390767403438354009767291938975195751081032073309083309746656253788033721103313036\"\n" + + " }\n" + + " }\n" + + " }"; + String signatureType = "CL"; + @Test public void testBuildClaimDefRequestWorks() throws Exception { @@ -131,14 +153,12 @@ public void testClaimDefRequestsWorks() throws Exception { JSONObject schemaObj = new JSONObject(getSchemaResponse); int schemaSeqNo = schemaObj.getJSONObject("result").getInt("seqNo"); - String schemaJson = String.format("{\"seqNo\":%d,\"data\":%s}", schemaSeqNo, schemaData); - String claimDef = Anoncreds.issuerCreateAndStoreClaimDef(wallet, myDid, schemaJson, null, false).get(); + String claimDef = String.format(claimDefTemplate, schemaSeqNo, myDid); JSONObject claimDefObj = new JSONObject(claimDef); String claimDefJson = String.format("%s", claimDefObj.getJSONObject("data")); - String signatureType = claimDefObj.getString("signature_type"); String claimDefRequest = Ledger.buildClaimDefTxn(myDid, schemaSeqNo, signatureType, claimDefJson).get(); Ledger.signAndSubmitRequest(pool, wallet, myDid, claimDefRequest).get(); @@ -190,15 +210,14 @@ public void testClaimDefRequestWorksWithoutSignature() throws Exception { JSONObject schemaObj = new JSONObject(schemaResponse); int schemaSeqNo = schemaObj.getJSONObject("result").getInt("seqNo"); - String schemaJson = String.format("{\"seqNo\":%d,\"data\":%s}", schemaSeqNo, schemaData); - String claimDef = Anoncreds.issuerCreateAndStoreClaimDef(wallet, myDid, schemaJson, null, false).get(); + String claimDef = String.format(claimDefTemplate, schemaSeqNo, myDid); JSONObject claimDefObj = new JSONObject(claimDef); String claimDefJson = String.format("%s", claimDefObj.getJSONObject("data")); - String claimDefRequest = Ledger.buildClaimDefTxn(myDid, schemaSeqNo, claimDefObj.getString("signature_type"), claimDefJson).get(); + String claimDefRequest = Ledger.buildClaimDefTxn(myDid, schemaSeqNo, signatureType, claimDefJson).get(); Ledger.submitRequest(pool, claimDefRequest).get(); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java index 5f2d632cda..e57118796f 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java @@ -100,10 +100,7 @@ public void testNymRequestWorksWithoutSignature() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.LedgerInvalidTransaction)); - SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); - - SignusResults.CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(wallet, didJson.toJson()).get(); + SignusResults.CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(wallet, "{}").get(); String did = result.getDid(); String nymRequest = Ledger.buildNymRequest(did, did, null, null, null).get(); @@ -119,10 +116,7 @@ public void testSendNymRequestsWorksForOnlyRequiredFields() throws Exception { SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); - SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); - - SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, "{}").get(); String myDid = myDidResult.getDid(); String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, null, null, null).get(); @@ -140,10 +134,7 @@ public void testSendNymRequestsWorksForOptionalFields() throws Exception { SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); - SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); - - SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, "{}").get(); String myDid = myDidResult.getDid(); String myVerkey = myDidResult.getVerkey(); String role = "STEWARD"; @@ -234,10 +225,7 @@ public void testNymRequestsWorks() throws Exception { SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); - SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); - - SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, "{}").get(); String myDid = myDidResult.getDid(); String myVerkey = myDidResult.getVerkey(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java index caa8e6803d..2b10968233 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java @@ -22,6 +22,8 @@ public class RequestsTest extends IndyIntegrationTest { private String poolName; private Pool pool; + private Wallet wallet; + private String walletName = "ledgerWallet"; @Rule public Timeout globalTimeout = new Timeout(5, TimeUnit.SECONDS); @@ -30,11 +32,17 @@ public class RequestsTest extends IndyIntegrationTest { public void openPool() throws Exception { poolName = PoolUtils.createPoolLedgerConfig(); pool = Pool.openPoolLedger(poolName, null).get(); + + Wallet.createWallet(poolName, walletName, "default", null, null).get(); + wallet = Wallet.openWallet(walletName, null, null).get(); } @After public void closePool() throws Exception { pool.closePoolLedger().get(); + + wallet.closeWallet().get(); + Wallet.deleteWallet(walletName, null).get(); } @Test @@ -63,27 +71,38 @@ public void testSubmitRequestWorks() throws Exception { @Test public void testSignAndSubmitRequestWorks() throws Exception { - Wallet.createWallet(poolName, "ledgerWallet", "default", null, null).get(); - Wallet wallet = Wallet.openWallet("ledgerWallet", null, null).get(); - SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); - SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); - - SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, "{}").get(); String myDid = myDidResult.getDid(); String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, null, null, null).get(); String nymResponse = Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); assertNotNull(nymResponse); + } - wallet.closeWallet().get(); - Wallet.deleteWallet("ledgerWallet", null).get(); + @Test + public void testSignAndSubmitRequestWorksForNotFoundSigner() throws Exception { + + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.LedgerInvalidTransaction)); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000UnknowSigner", null, null); + + SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); + String signerDid = trusteeDidResult.getDid(); + + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, "{}").get(); + String myDid = myDidResult.getDid(); + + String nymRequest = Ledger.buildNymRequest(signerDid, myDid, null, null, null).get(); + String nymResponse = Ledger.signAndSubmitRequest(pool, wallet, signerDid, nymRequest).get(); + assertNotNull(nymResponse); } @Test @@ -101,10 +120,7 @@ public void testSignAndSubmitRequestWorksForIncompatibleWalletAndPool() throws E SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); - SignusJSONParameters.CreateAndStoreMyDidJSONParameter myDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); - - SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, myDidJson.toJson()).get(); + SignusResults.CreateAndStoreMyDidResult myDidResult = Signus.createAndStoreMyDid(wallet, "{}").get(); String myDid = myDidResult.getDid(); String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, null, null, null).get(); From 2da66701606683b93759909c753286aaf2d48db4 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Thu, 20 Jul 2017 15:32:53 +0300 Subject: [PATCH 261/349] * agent_close_listener, agent_close_connection were implemented * Bugfixes --- wrappers/python/indy/agent.py | 47 +++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/wrappers/python/indy/agent.py b/wrappers/python/indy/agent.py index 8329ed4954..0fb22149ce 100644 --- a/wrappers/python/indy/agent.py +++ b/wrappers/python/indy/agent.py @@ -87,7 +87,7 @@ async def agent_connect(pool_handle: int, if not hasattr(agent_connect, "connection_cb"): logger.debug("agent_connect: Creating connection callback") - agent_connect.connection_cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) + agent_connect.connection_cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_int32)) def _message_cb(connection_handle: int, err: int, message: str): logger.debug("agent_connect._message_cb: connection_handle: %i, err: %i, message: %s", @@ -124,7 +124,7 @@ async def agent_listen(endpoint: str) -> int: if not hasattr(agent_listen, "listener_cb"): logger.debug("agent_listen: Creating listener callback") - agent_listen.listener_cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) + agent_listen.listener_cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_int32)) def _connection_cb(listener_handle: int, err: int, connection_handle: int, sender_did: str, receiver_did: str): logger.debug("agent_connect._connection_cb: listener_handle: %i, err: %i, connection_handle: %i, sender_did: " @@ -178,7 +178,7 @@ async def agent_add_identity(listener_handle: int, if not hasattr(agent_add_identity, "cb"): logger.debug("agent_add_identity: Creating callback") - agent_add_identity.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_int32)) + agent_add_identity.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) c_listener_handle = c_int32(listener_handle) c_pool_handle = c_int32(pool_handle) @@ -208,7 +208,7 @@ async def agent_remove_identity(listener_handle: int, if not hasattr(agent_remove_identity, "cb"): logger.debug("agent_remove_identity: Creating callback") - agent_remove_identity.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_int32)) + agent_remove_identity.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) c_listener_handle = c_int32(listener_handle) c_pool_handle = c_int32(pool_handle) @@ -225,8 +225,7 @@ async def agent_remove_identity(listener_handle: int, logger.debug("agent_remove_identity: <<<") -async def agent_send(connection_handle: int, - message: str) -> None: +async def agent_send(connection_handle: int, message: str) -> None: logger = logging.getLogger(__name__) logger.debug("agent_send: >>> connection_handle: %i, message: %s", connection_handle, @@ -234,7 +233,7 @@ async def agent_send(connection_handle: int, if not hasattr(agent_send, "cb"): logger.debug("agent_send: Creating callback") - agent_send.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_int32)) + agent_send.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) c_connection_handle = c_int32(connection_handle) c_message = c_char_p(message.encode('utf-8')) @@ -245,3 +244,37 @@ async def agent_send(connection_handle: int, agent_send.cb) logger.debug("agent_send: <<<") + + +async def agent_close_connection(connection_handle: int) -> None: + logger = logging.getLogger(__name__) + logger.debug("agent_close_connection: >>> connection_handle: %i", connection_handle) + + if not hasattr(agent_close_connection, "cb"): + logger.debug("agent_close_connection: Creating callback") + agent_close_connection.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) + + c_connection_handle = c_int32(connection_handle) + + await do_call('indy_agent_close_connection', + c_connection_handle, + agent_close_connection.cb) + + logger.debug("agent_close_connection: <<<") + + +async def agent_close_listener(listener_handle: int) -> None: + logger = logging.getLogger(__name__) + logger.debug("agent_close_listener: >>> listener_handle: %i", listener_handle) + + if not hasattr(agent_close_listener, "cb"): + logger.debug("agent_close_listener: Creating callback") + agent_close_listener.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) + + c_listener_handle = c_int32(listener_handle) + + await do_call('indy_agent_close_listener', + c_listener_handle, + agent_close_listener.cb) + + logger.debug("agent_close_listener: <<<") From 343237db455e37029b548b467df7bc8b83d40288 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 20 Jul 2017 16:02:00 +0300 Subject: [PATCH 262/349] Refactoring Java tests --- .../indy/sdk/IndyIntegrationTest.java | 2 +- .../sdk/anoncreds/IssuerCreateClaimTest.java | 6 +- .../sdk/anoncreds/ProverStoreClaimTest.java | 24 ++- .../indy/sdk/demo/AnoncredsDemoTest.java | 162 ------------------ .../indy/sdk/ledger/AttribRequestsTest.java | 3 - .../indy/sdk/ledger/GetTxnRequestTest.java | 3 - .../indy/sdk/ledger/NodeRequestsTest.java | 3 - .../indy/sdk/ledger/NymRequestsTest.java | 3 - .../indy/sdk/ledger/RequestsTest.java | 3 - .../indy/sdk/ledger/SchemaRequestsTest.java | 3 - 10 files changed, 19 insertions(+), 193 deletions(-) delete mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java index fd1c7503c4..9bb4b356ff 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java @@ -21,7 +21,7 @@ public class IndyIntegrationTest { public ExpectedException thrown = ExpectedException.none(); @Rule - public Timeout globalTimeout = new Timeout(10, TimeUnit.SECONDS); + public Timeout globalTimeout = new Timeout(30, TimeUnit.SECONDS); @Before public void setUp() throws IOException { diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateClaimTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateClaimTest.java index d6619d8cac..941813c5e9 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateClaimTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateClaimTest.java @@ -13,7 +13,7 @@ public class IssuerCreateClaimTest extends AnoncredsIntegrationTest { @Test - public void testProverCreateAndStoreClaimReqWorks() throws Exception { + public void testIssuerCreateClaimWorks() throws Exception { initCommonWallet(); @@ -40,7 +40,7 @@ public void testProverCreateAndStoreClaimReqWorks() throws Exception { } @Test - public void testProverCreateAndStoreClaimReqWorksForClaimDoesNotCorrespondToClaimRequest() throws Exception { + public void testIssuerCreateClaimWorksForClaimDoesNotCorrespondToClaimRequest() throws Exception { initCommonWallet(); @@ -57,7 +57,7 @@ public void testProverCreateAndStoreClaimReqWorksForClaimDoesNotCorrespondToClai } @Test - public void testProverCreateAndStoreClaimReqWorksForInvalidClaim() throws Exception { + public void testIssuerCreateClaimWorksForInvalidClaim() throws Exception { initCommonWallet(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverStoreClaimTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverStoreClaimTest.java index f15a45799e..97513c65f2 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverStoreClaimTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverStoreClaimTest.java @@ -2,22 +2,26 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; +import org.hyperledger.indy.sdk.wallet.Wallet; import org.junit.*; import java.util.concurrent.ExecutionException; -import static org.junit.Assert.assertNotNull; - public class ProverStoreClaimTest extends AnoncredsIntegrationTest { @Test - public void testProverCreateAndStoreClaimReqWorks() throws Exception { - + public void testProverStoreClaimWorks() throws Exception { initCommonWallet(); + String proverWalletName = "proverWallet"; + Wallet.createWallet("default", proverWalletName, "default", null, null).get(); + Wallet proverWallet = proverWallet = Wallet.openWallet(proverWalletName, null, null).get(); + + Anoncreds.proverCreateMasterSecret(proverWallet, masterSecretName).get(); + String claimOffer = String.format(claimOfferTemplate, issuerDid, 1); - String claimRequest = Anoncreds.proverCreateClaimReq(wallet, proverDid, claimOffer, claimDef, masterSecretName).get(); + String claimRequest = Anoncreds.proverCreateClaimReq(proverWallet, proverDid, claimOffer, claimDef, masterSecretName).get(); String claim = "{\"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" + " \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" + @@ -26,14 +30,16 @@ public void testProverCreateAndStoreClaimReqWorks() throws Exception { " }"; AnoncredsResults.IssuerCreateClaimResult createClaimResult = Anoncreds.issuerCreateClaim(wallet, claimRequest, claim, - 1, - 1).get(); - assertNotNull(createClaimResult); String claimJson = createClaimResult.getClaimJson(); - Anoncreds.proverStoreClaim(wallet, claimJson).get(); + Anoncreds.proverStoreClaim(proverWallet, claimJson).get(); + + proverWallet.closeWallet().get(); + Wallet.deleteWallet(proverWalletName, null).get(); } @Test - public void testProverCreateAndStoreClaimReqWorksWithoutClaimReq() throws Exception { + public void testProverStoreClaimWorksWithoutClaimReq() throws Exception { initCommonWallet(); @@ -51,7 +57,7 @@ public void testProverCreateAndStoreClaimReqWorksWithoutClaimReq() throws Except } @Test - public void testProverCreateAndStoreClaimReqWorksForInvalidClaimJson() throws Exception { + public void testProverStoreClaimWorksForInvalidClaimJson() throws Exception { initCommonWallet(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java deleted file mode 100644 index c1b3c01fc9..0000000000 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java +++ /dev/null @@ -1,162 +0,0 @@ -package org.hyperledger.indy.sdk.demo; - -import org.hyperledger.indy.sdk.IndyIntegrationTest; -import org.hyperledger.indy.sdk.anoncreds.Anoncreds; -import org.hyperledger.indy.sdk.anoncreds.AnoncredsResults; -import org.hyperledger.indy.sdk.pool.Pool; -import org.hyperledger.indy.sdk.pool.PoolJSONParameters; -import org.hyperledger.indy.sdk.utils.PoolUtils; -import org.hyperledger.indy.sdk.wallet.Wallet; -import org.json.JSONArray; -import org.json.JSONObject; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.Timeout; - -import java.util.concurrent.TimeUnit; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertNotNull; - -public class AnoncredsDemoTest extends IndyIntegrationTest { - - @Rule - public Timeout globalTimeout = new Timeout(1, TimeUnit.MINUTES); - - @Test - public void testAnoncredsDemo() throws Exception { - - //1. Create and Open Pool - String poolName = PoolUtils.createPoolLedgerConfig(); - - PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); - Pool pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); - - //2. Issuer Create and Open Wallet - Wallet.createWallet(poolName, "issuerWallet", "default", null, null).get(); - Wallet issuerWallet = Wallet.openWallet("issuerWallet", null, null).get(); - - //3. Prover Create and Open Wallet - Wallet.createWallet(poolName, "proverWallet", "default", null, null).get(); - Wallet proverWallet = Wallet.openWallet("proverWallet", null, null).get(); - - //4. Issuer create ClaimDef - String schemaJson = "{\n" + - " \"seqNo\":1,\n" + - " \"data\": {\n" + - " \"name\":\"gvt\",\n" + - " \"version\":\"1.0\",\n" + - " \"keys\":[\"age\",\"sex\",\"height\",\"name\"]\n" + - " }\n" + - " }"; - String issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; - - String claimDef = Anoncreds.issuerCreateAndStoreClaimDef(issuerWallet, issuerDid, schemaJson, null, false).get(); - assertNotNull(claimDef); - - //5. Prover create Master Secret - String masterSecret = "masterSecretName"; - Anoncreds.proverCreateMasterSecret(proverWallet, masterSecret).get(); - - //6. Prover store Claim Offer - String claimOffer = String.format("{\"issuer_did\":\"%s\", \"schema_seq_no\":%d}", issuerDid, 1); - Anoncreds.proverStoreClaimOffer(proverWallet, claimOffer).get(); - - //7. Prover get Claim Offers - String claimOfferFilter = String.format("{\"issuer_did\":\"%s\"}", issuerDid); - String claimOffersJson = Anoncreds.proverGetClaimOffers(proverWallet, claimOfferFilter).get(); - - JSONArray claimOffersObject = new JSONArray(claimOffersJson); - assertEquals(claimOffersObject.length(), 1); - - JSONObject claimOfferObject = claimOffersObject.getJSONObject(0); - String claimOfferJson = claimOfferObject.toString(); - - //8. Prover create ClaimReq - String proverDid = "BzfFCYk"; - String claimReq = Anoncreds.proverCreateClaimReq(proverWallet, proverDid, claimOfferJson, claimDef, masterSecret).get(); - assertNotNull(claimReq); - - //9. Issuer create Claim - String claimAttributesJson = "{\n" + - " \"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" + - " \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" + - " \"height\":[\"175\",\"175\"],\n" + - " \"age\":[\"28\",\"28\"]\n" + - " }"; - - AnoncredsResults.IssuerCreateClaimResult createClaimResult = Anoncreds.issuerCreateClaim(issuerWallet, claimReq, claimAttributesJson, - 1, - 1).get(); - assertNotNull(createClaimResult); - String claimJson = createClaimResult.getClaimJson(); - - //10. Prover store Claim - Anoncreds.proverStoreClaim(proverWallet, claimJson).get(); - - //11. Prover gets Claims for Proof Request - String proofRequestJson = "{\n" + - " \"nonce\":\"123432421212\",\n" + - " \"name\":\"proof_req_1\",\n" + - " \"version\":\"0.1\",\n" + - " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1,\"name\":\"name\"},\n" + - " \"attr2_uuid\":{\"schema_seq_no\":1,\"name\":\"sex\"}},\n" + - " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}\n" + - " }"; - - String claimsForProofJson = Anoncreds.proverGetClaimsForProofReq(proverWallet, proofRequestJson).get(); - assertNotNull(claimsForProofJson); - - JSONObject claimsForProof = new JSONObject(claimsForProofJson); - JSONArray claimsForAttribute1 = claimsForProof.getJSONObject("attrs").getJSONArray("attr1_uuid"); - JSONArray claimsForAttribute2 = claimsForProof.getJSONObject("attrs").getJSONArray("attr1_uuid"); - JSONArray claimsForPredicate = claimsForProof.getJSONObject("predicates").getJSONArray("predicate1_uuid"); - - assertEquals(claimsForAttribute1.length(), 1); - assertEquals(claimsForAttribute2.length(), 1); - assertEquals(claimsForPredicate.length(), 1); - - String claimUuid = claimsForAttribute1.getJSONObject(0).getString("claim_uuid"); - - //12. Prover create Proof - String selfAttestedValue = "yes"; - String requestedClaimsJson = String.format("{\n" + - " \"self_attested_attributes\":{\"self1\":\"%s\"},\n" + - " \"requested_attrs\":{\"attr1_uuid\":[\"%s\", true],\n" + - " \"attr2_uuid\":[\"%s\", false]},\n" + - " \"requested_predicates\":{\"predicate1_uuid\":\"%s\"}\n" + - " }", selfAttestedValue, claimUuid, claimUuid, claimUuid); - - String schemasJson = String.format("{\"%s\":%s}", claimUuid, schemaJson); - String claimDefsJson = String.format("{\"%s\":%s}", claimUuid, claimDef); - String revocRegsJson = "{}"; - - - String proofJson = Anoncreds.proverCreateProof(proverWallet, proofRequestJson, requestedClaimsJson, schemasJson, - masterSecret, claimDefsJson, revocRegsJson).get(); - assertNotNull(proofJson); - - JSONObject proof = new JSONObject(proofJson); - - //13. Verifier verify Proof - assertEquals("Alex", - proof.getJSONObject("requested_proof").getJSONObject("revealed_attrs").getJSONArray("attr1_uuid").getString(1)); - - assertNotNull(proof.getJSONObject("requested_proof").getJSONObject("unrevealed_attrs").getString("attr2_uuid")); - - assertEquals(selfAttestedValue, proof.getJSONObject("requested_proof").getJSONObject("self_attested_attrs").getString("self1")); - - Boolean valid = Anoncreds.verifierVerifyProof(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson).get(); - assertTrue(valid); - - // 14. Close and delete Issuer Wallet - issuerWallet.closeWallet().get(); - Wallet.deleteWallet("issuerWallet", null).get(); - - // 15. Close and delete Prover Wallet - proverWallet.closeWallet().get(); - Wallet.deleteWallet("proverWallet", null).get(); - - //16. Close Pool - pool.closePoolLedger().get(); - } -} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AttribRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AttribRequestsTest.java index ad580900b7..d6c8c37032 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AttribRequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AttribRequestsTest.java @@ -25,9 +25,6 @@ public class AttribRequestsTest extends IndyIntegrationTest { private Wallet wallet; private String walletName = "ledgerWallet"; - @Rule - public Timeout globalTimeout = new Timeout(5, TimeUnit.SECONDS); - @Before public void openPool() throws Exception { String poolName = PoolUtils.createPoolLedgerConfig(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/GetTxnRequestTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/GetTxnRequestTest.java index 6ddfc2042a..328ac89739 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/GetTxnRequestTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/GetTxnRequestTest.java @@ -22,9 +22,6 @@ public class GetTxnRequestTest extends IndyIntegrationTest { private Wallet wallet; private String walletName = "ledgerWallet"; - @Rule - public Timeout globalTimeout = new Timeout(5, TimeUnit.SECONDS); - @Before public void openPool() throws Exception { String poolName = PoolUtils.createPoolLedgerConfig(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NodeRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NodeRequestsTest.java index a82979feb7..8f1b3c0573 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NodeRequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NodeRequestsTest.java @@ -23,9 +23,6 @@ public class NodeRequestsTest extends IndyIntegrationTest { private Wallet wallet; private String walletName = "ledgerWallet"; - @Rule - public Timeout globalTimeout = new Timeout(5, TimeUnit.SECONDS); - @Before public void openPool() throws Exception { String poolName = PoolUtils.createPoolLedgerConfig(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java index e57118796f..4208cc837b 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java @@ -26,9 +26,6 @@ public class NymRequestsTest extends IndyIntegrationTest { private Wallet wallet; private String walletName = "ledgerWallet"; - @Rule - public Timeout globalTimeout = new Timeout(5, TimeUnit.SECONDS); - @Before public void openPool() throws Exception { String poolName = PoolUtils.createPoolLedgerConfig(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java index 2b10968233..344a14b290 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java @@ -25,9 +25,6 @@ public class RequestsTest extends IndyIntegrationTest { private Wallet wallet; private String walletName = "ledgerWallet"; - @Rule - public Timeout globalTimeout = new Timeout(5, TimeUnit.SECONDS); - @Before public void openPool() throws Exception { poolName = PoolUtils.createPoolLedgerConfig(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/SchemaRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/SchemaRequestsTest.java index e709bff8f7..36a49cff90 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/SchemaRequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/SchemaRequestsTest.java @@ -27,9 +27,6 @@ public class SchemaRequestsTest extends IndyIntegrationTest { private Wallet wallet; private String walletName = "ledgerWallet"; - @Rule - public Timeout globalTimeout = new Timeout(5, TimeUnit.SECONDS); - @Before public void openPool() throws Exception { String poolName = PoolUtils.createPoolLedgerConfig(); From 248b865898a27dfda56a8cfa227b0ec078a9bca8 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 20 Jul 2017 16:02:16 +0300 Subject: [PATCH 263/349] Refactoring java tests --- .../AnoncredsDemoTest.java} | 123 +++++++++++++++++- 1 file changed, 118 insertions(+), 5 deletions(-) rename wrappers/java/src/test/java/org/hyperledger/indy/sdk/{anoncreds/DemoTest.java => demo/AnoncredsDemoTest.java} (79%) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/DemoTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java similarity index 79% rename from wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/DemoTest.java rename to wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java index 3d6dc45218..52203c5ba6 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/DemoTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AnoncredsDemoTest.java @@ -1,8 +1,10 @@ -package org.hyperledger.indy.sdk.anoncreds; +package org.hyperledger.indy.sdk.demo; import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.anoncreds.Anoncreds; +import org.hyperledger.indy.sdk.anoncreds.AnoncredsResults; import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.pool.PoolJSONParameters; import org.hyperledger.indy.sdk.utils.PoolUtils; @@ -18,14 +20,14 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.*; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertNotNull; -public class DemoTest extends IndyIntegrationTest { +public class AnoncredsDemoTest extends IndyIntegrationTest { @Rule - public Timeout globalTimeout = new Timeout(2, TimeUnit.MINUTES); + public Timeout globalTimeout = new Timeout(1, TimeUnit.MINUTES); private Pool pool; private Wallet issuerWallet; @@ -60,6 +62,117 @@ public void deleteWallet() throws Exception { pool.closePoolLedger(); } + @Test + public void testAnoncredsDemo() throws Exception { + + //4. Issuer create ClaimDef + String schemaJson = "{\n" + + " \"seqNo\":1,\n" + + " \"data\": {\n" + + " \"name\":\"gvt\",\n" + + " \"version\":\"1.0\",\n" + + " \"keys\":[\"age\",\"sex\",\"height\",\"name\"]\n" + + " }\n" + + " }"; + String issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; + + String claimDef = Anoncreds.issuerCreateAndStoreClaimDef(issuerWallet, issuerDid, schemaJson, null, false).get(); + assertNotNull(claimDef); + + //5. Prover create Master Secret + String masterSecret = "masterSecretName"; + Anoncreds.proverCreateMasterSecret(proverWallet, masterSecret).get(); + + //6. Prover store Claim Offer + String claimOffer = String.format("{\"issuer_did\":\"%s\", \"schema_seq_no\":%d}", issuerDid, 1); + Anoncreds.proverStoreClaimOffer(proverWallet, claimOffer).get(); + + //7. Prover get Claim Offers + String claimOfferFilter = String.format("{\"issuer_did\":\"%s\"}", issuerDid); + String claimOffersJson = Anoncreds.proverGetClaimOffers(proverWallet, claimOfferFilter).get(); + + JSONArray claimOffersObject = new JSONArray(claimOffersJson); + assertEquals(claimOffersObject.length(), 1); + + JSONObject claimOfferObject = claimOffersObject.getJSONObject(0); + String claimOfferJson = claimOfferObject.toString(); + + //8. Prover create ClaimReq + String proverDid = "BzfFCYk"; + String claimReq = Anoncreds.proverCreateClaimReq(proverWallet, proverDid, claimOfferJson, claimDef, masterSecret).get(); + assertNotNull(claimReq); + + //9. Issuer create Claim + String claimAttributesJson = "{\n" + + " \"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" + + " \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" + + " \"height\":[\"175\",\"175\"],\n" + + " \"age\":[\"28\",\"28\"]\n" + + " }"; + + AnoncredsResults.IssuerCreateClaimResult createClaimResult = Anoncreds.issuerCreateClaim(issuerWallet, claimReq, claimAttributesJson, - 1, - 1).get(); + assertNotNull(createClaimResult); + String claimJson = createClaimResult.getClaimJson(); + + //10. Prover store Claim + Anoncreds.proverStoreClaim(proverWallet, claimJson).get(); + + //11. Prover gets Claims for Proof Request + String proofRequestJson = "{\n" + + " \"nonce\":\"123432421212\",\n" + + " \"name\":\"proof_req_1\",\n" + + " \"version\":\"0.1\",\n" + + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1,\"name\":\"name\"},\n" + + " \"attr2_uuid\":{\"schema_seq_no\":1,\"name\":\"sex\"}},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}\n" + + " }"; + + String claimsForProofJson = Anoncreds.proverGetClaimsForProofReq(proverWallet, proofRequestJson).get(); + assertNotNull(claimsForProofJson); + + JSONObject claimsForProof = new JSONObject(claimsForProofJson); + JSONArray claimsForAttribute1 = claimsForProof.getJSONObject("attrs").getJSONArray("attr1_uuid"); + JSONArray claimsForAttribute2 = claimsForProof.getJSONObject("attrs").getJSONArray("attr1_uuid"); + JSONArray claimsForPredicate = claimsForProof.getJSONObject("predicates").getJSONArray("predicate1_uuid"); + + assertEquals(claimsForAttribute1.length(), 1); + assertEquals(claimsForAttribute2.length(), 1); + assertEquals(claimsForPredicate.length(), 1); + + String claimUuid = claimsForAttribute1.getJSONObject(0).getString("claim_uuid"); + + //12. Prover create Proof + String selfAttestedValue = "yes"; + String requestedClaimsJson = String.format("{\n" + + " \"self_attested_attributes\":{\"self1\":\"%s\"},\n" + + " \"requested_attrs\":{\"attr1_uuid\":[\"%s\", true],\n" + + " \"attr2_uuid\":[\"%s\", false]},\n" + + " \"requested_predicates\":{\"predicate1_uuid\":\"%s\"}\n" + + " }", selfAttestedValue, claimUuid, claimUuid, claimUuid); + + String schemasJson = String.format("{\"%s\":%s}", claimUuid, schemaJson); + String claimDefsJson = String.format("{\"%s\":%s}", claimUuid, claimDef); + String revocRegsJson = "{}"; + + + String proofJson = Anoncreds.proverCreateProof(proverWallet, proofRequestJson, requestedClaimsJson, schemasJson, + masterSecret, claimDefsJson, revocRegsJson).get(); + assertNotNull(proofJson); + + JSONObject proof = new JSONObject(proofJson); + + //13. Verifier verify Proof + assertEquals("Alex", + proof.getJSONObject("requested_proof").getJSONObject("revealed_attrs").getJSONArray("attr1_uuid").getString(1)); + + assertNotNull(proof.getJSONObject("requested_proof").getJSONObject("unrevealed_attrs").getString("attr2_uuid")); + + assertEquals(selfAttestedValue, proof.getJSONObject("requested_proof").getJSONObject("self_attested_attrs").getString("self1")); + + Boolean valid = Anoncreds.verifierVerifyProof(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson).get(); + assertTrue(valid); + } + @Test public void testAnoncredsWorksForMultiplyIssuerSingleProver() throws Exception { @@ -221,7 +334,7 @@ public void testAnoncredsWorksForMultiplyIssuerSingleProver() throws Exception { } @Test - public void testAnoncredsWorksForSingleIssuerSingleProver() throws Exception { + public void testAnoncredsWorksForSingleIssuerSingleProverMultiplyClaims() throws Exception { String issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; From 1c3bb94331bf798c60ff01edb66276e6d1e03c84 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 20 Jul 2017 16:55:49 +0300 Subject: [PATCH 264/349] Updated debian control file --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index 685576e2b6..1a7fe39a10 100644 --- a/debian/control +++ b/debian/control @@ -10,7 +10,7 @@ Vcs-Browser: https://github.com/hyperledger/indy-sdk/ Package: indy-sdk Architecture: amd64 -Depends: libssl, libsodium, libsqlite0 +Depends: libssl1.0.0, libsodium18, libsqlite0 Suggests: build-essential Description: This is the official SDK for Hyperledger Indy, which provides a distributed-ledger-based foundation for self-sovereign identity. From edc61192185a0c072baad6857e0ff891694da676 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 20 Jul 2017 17:34:00 +0300 Subject: [PATCH 265/349] added issuer_create_and_store_claim_def --- wrappers/python/indy/anoncreds.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/wrappers/python/indy/anoncreds.py b/wrappers/python/indy/anoncreds.py index 3f23eb86f3..fb624830fd 100644 --- a/wrappers/python/indy/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -25,7 +25,36 @@ async def issuer_create_and_store_claim_def(wallet_handle: int, :return: claim definition json containing information about signature type, schema and issuer's public key. Unique number identifying the public key in the wallet """ - pass + + logger = logging.getLogger(__name__) + logger.debug("issuer_create_and_store_claim_def: >>> wallet_handle: %s, issuer_did: %s, schema_json: %s," + " signature_type: %s, create_non_revoc: %s", + wallet_handle, + issuer_did, + schema_json, + signature_type, + create_non_revoc) + + if not hasattr(issuer_create_and_store_claim_def, "cb"): + logger.debug("issuer_create_and_store_claim_def: Creating callback") + issuer_create_and_store_claim_def.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_wallet_handle = c_int32(wallet_handle) + c_issuer_did = c_char_p(issuer_did.encode('utf-8')) + c_schema_json = c_char_p(schema_json.encode('utf-8')) + c_signature_type = c_char_p(signature_type.encode('utf-8')) if signature_type is not None else None + c_create_non_revoc = c_bool(create_non_revoc) + + claim_def_json = await do_call('indy_issuer_create_and_store_claim_def', + issuer_create_and_store_claim_def.cb, + c_wallet_handle, + c_issuer_did, + c_schema_json, + c_signature_type, + c_create_non_revoc) + res = claim_def_json.decode() + logger.debug("issuer_create_and_store_claim_def: <<< res: %s", res) + return res async def issuer_create_and_store_revoc_reg(wallet_handle: int, From 2577583cddbcb9316a72b7444c9f80981d9fd156 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Thu, 20 Jul 2017 17:41:49 +0300 Subject: [PATCH 266/349] added create_and_store_revoc_reg --- wrappers/python/indy/anoncreds.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/wrappers/python/indy/anoncreds.py b/wrappers/python/indy/anoncreds.py index fb624830fd..13f3de8668 100644 --- a/wrappers/python/indy/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -72,7 +72,33 @@ async def issuer_create_and_store_revoc_reg(wallet_handle: int, :return: Revoc registry json Unique number identifying the revocation registry in the wallet """ - pass + + logger = logging.getLogger(__name__) + logger.debug("issuer_create_and_store_revoc_reg: >>> wallet_handle: %s, issuer_did: %s, schema_seq_no: %s," + " max_claim_num: %s", + wallet_handle, + issuer_did, + schema_seq_no, + max_claim_num) + + if not hasattr(issuer_create_and_store_revoc_reg, "cb"): + logger.debug("issuer_create_and_store_revoc_reg: Creating callback") + issuer_create_and_store_revoc_reg.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p, c_char_p)) + + c_wallet_handle = c_int32(wallet_handle) + c_issuer_did = c_char_p(issuer_did.encode('utf-8')) + c_schema_seq_no = c_int32(schema_seq_no) + c_max_claim_num = c_int32(max_claim_num) + + (revoc_reg_json, revoc_reg_uuid) = await do_call('indy_issuer_create_and_store_revoc_reg', + issuer_create_and_store_revoc_reg.cb, + c_wallet_handle, + c_issuer_did, + c_schema_seq_no, + c_max_claim_num) + res = (revoc_reg_json.decode(), revoc_reg_uuid.decode()) + logger.debug("issuer_create_and_store_revoc_reg: <<< res: %s", res) + return res async def issuer_create_claim(wallet_handle: int, From ea34e36466a8fbf0c06fc66257f37c1f19057329 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 21 Jul 2017 09:07:50 +0300 Subject: [PATCH 267/349] try update control file --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index 1a7fe39a10..15670fb972 100644 --- a/debian/control +++ b/debian/control @@ -10,7 +10,7 @@ Vcs-Browser: https://github.com/hyperledger/indy-sdk/ Package: indy-sdk Architecture: amd64 -Depends: libssl1.0.0, libsodium18, libsqlite0 +Depends: libssl (>= 1.0.0), libsodium (>= 1), libsqlite (>= 0) Suggests: build-essential Description: This is the official SDK for Hyperledger Indy, which provides a distributed-ledger-based foundation for self-sovereign identity. From 4d55420d5c159b6c3275257099cab5d257acea96 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 21 Jul 2017 09:18:09 +0300 Subject: [PATCH 268/349] try --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index 15670fb972..b39734358d 100644 --- a/debian/control +++ b/debian/control @@ -10,7 +10,7 @@ Vcs-Browser: https://github.com/hyperledger/indy-sdk/ Package: indy-sdk Architecture: amd64 -Depends: libssl (>= 1.0.0), libsodium (>= 1), libsqlite (>= 0) +Depends: libssl (>= 1.0.0), libsodium18, libsqlite0 Suggests: build-essential Description: This is the official SDK for Hyperledger Indy, which provides a distributed-ledger-based foundation for self-sovereign identity. From 08702cc7c99ddde84c8e421ebd37ce56444bb90d Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 21 Jul 2017 09:28:24 +0300 Subject: [PATCH 269/349] try --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index b39734358d..c668a9fb42 100644 --- a/debian/control +++ b/debian/control @@ -10,7 +10,7 @@ Vcs-Browser: https://github.com/hyperledger/indy-sdk/ Package: indy-sdk Architecture: amd64 -Depends: libssl (>= 1.0.0), libsodium18, libsqlite0 +Depends: libssl [linux-any], libsodium18, libsqlite0 Suggests: build-essential Description: This is the official SDK for Hyperledger Indy, which provides a distributed-ledger-based foundation for self-sovereign identity. From 501a6a9001ef25bc47ff83fedc0c1faaef684d85 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 21 Jul 2017 10:44:11 +0300 Subject: [PATCH 270/349] try --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index c668a9fb42..1a7fe39a10 100644 --- a/debian/control +++ b/debian/control @@ -10,7 +10,7 @@ Vcs-Browser: https://github.com/hyperledger/indy-sdk/ Package: indy-sdk Architecture: amd64 -Depends: libssl [linux-any], libsodium18, libsqlite0 +Depends: libssl1.0.0, libsodium18, libsqlite0 Suggests: build-essential Description: This is the official SDK for Hyperledger Indy, which provides a distributed-ledger-based foundation for self-sovereign identity. From d91d30183328ad130dec3de80dcd9815d2b0fc56 Mon Sep 17 00:00:00 2001 From: Kirill Neznamov Date: Fri, 21 Jul 2017 11:39:18 +0300 Subject: [PATCH 271/349] update build instruction for MAC OS --- doc/mac-build.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/mac-build.md b/doc/mac-build.md index c499b255bd..83182d5a7e 100644 --- a/doc/mac-build.md +++ b/doc/mac-build.md @@ -4,8 +4,9 @@ 2. Install required native libraries and utilities > brew install libsodium - > brew install zeromq > brew install cmake + > brew install automake + > brew install autoconf > brew install openssl 3. Setup environment variables: @@ -17,10 +18,10 @@ 4. Setup OPENSSL_DIR variable: path to installed openssl library - >export OPENSSL_DIR=/usr/local/Cellar/openssl/1.0.2k + > export OPENSSL_DIR=/usr/local/Cellar/openssl/1.0.2k 5. Build the library: - >cargo build + > cargo build From 3f8061b01650860f29b8db6878508c23c727f12b Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 21 Jul 2017 11:56:40 +0300 Subject: [PATCH 272/349] added create_claim --- wrappers/python/indy/anoncreds.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/wrappers/python/indy/anoncreds.py b/wrappers/python/indy/anoncreds.py index 13f3de8668..2cf6fa8919 100644 --- a/wrappers/python/indy/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -142,7 +142,36 @@ async def issuer_create_claim(wallet_handle: int, "schema_seq_no", string, } """ - pass + + logger = logging.getLogger(__name__) + logger.debug("issuer_create_claim: >>> wallet_handle: %s, claim_req_json: %s, claim_json: %s," + " revoc_reg_seq_no: %s, user_revoc_index: %s", + wallet_handle, + claim_req_json, + claim_json, + revoc_reg_seq_no, + user_revoc_index) + + if not hasattr(issuer_create_claim, "cb"): + logger.debug("issuer_create_claim: Creating callback") + issuer_create_claim.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p, c_char_p)) + + c_wallet_handle = c_int32(wallet_handle) + c_claim_req_json = c_char_p(claim_req_json.encode('utf-8')) + c_claim_json = c_char_p(claim_json.encode('utf-8')) + c_revoc_reg_seq_no = c_int32(revoc_reg_seq_no) + c_user_revoc_index = c_int32(user_revoc_index) + + (revoc_reg_update_json, claim_json) = await do_call('indy_issuer_create_claim', + issuer_create_claim.cb, + c_wallet_handle, + c_claim_req_json, + c_claim_json, + c_revoc_reg_seq_no, + c_user_revoc_index) + res = (revoc_reg_update_json.decode(), claim_json.decode()) + logger.debug("issuer_create_claim: <<< res: %s", res) + return res async def issuer_revoke_claim(wallet_handle: int, From 03a262d6d3f5d96aed00a2666646ad353d7623cb Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 21 Jul 2017 13:00:13 +0300 Subject: [PATCH 273/349] added revoke claim --- wrappers/python/indy/anoncreds.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/wrappers/python/indy/anoncreds.py b/wrappers/python/indy/anoncreds.py index 2cf6fa8919..2c8581fcfc 100644 --- a/wrappers/python/indy/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -187,7 +187,29 @@ async def issuer_revoke_claim(wallet_handle: int, :param user_revoc_index: index of the user in the revocation registry :return: Revocation registry update json with a revoked claim """ - pass + + logger = logging.getLogger(__name__) + logger.debug("issuer_revoke_claim: >>> wallet_handle: %s, revoc_reg_seq_no: %s, user_revoc_index: %s", + wallet_handle, + revoc_reg_seq_no, + user_revoc_index) + + if not hasattr(issuer_revoke_claim, "cb"): + logger.debug("issuer_revoke_claim: Creating callback") + issuer_revoke_claim.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_wallet_handle = c_int32(wallet_handle) + c_revoc_reg_seq_no = c_int32(revoc_reg_seq_no) + c_user_revoc_index = c_int32(user_revoc_index) + + revoc_reg_update_json = await do_call('indy_issuer_revoke_claim', + issuer_revoke_claim.cb, + c_wallet_handle, + c_revoc_reg_seq_no, + c_user_revoc_index) + res = revoc_reg_update_json.decode() + logger.debug("issuer_revoke_claim: <<< res: %s", res) + return res async def prover_store_claim_offer(wallet_handle: int, From 5fd4f107c0e158501ca4e4e506b9dadb81dc666a Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 21 Jul 2017 13:04:32 +0300 Subject: [PATCH 274/349] added prover_store_claim_offer --- wrappers/python/indy/anoncreds.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/wrappers/python/indy/anoncreds.py b/wrappers/python/indy/anoncreds.py index 2c8581fcfc..d6491b1a1f 100644 --- a/wrappers/python/indy/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -225,7 +225,26 @@ async def prover_store_claim_offer(wallet_handle: int, } :return: None. """ - pass + + logger = logging.getLogger(__name__) + logger.debug("prover_store_claim_offer: >>> wallet_handle: %s, claim_offer_json: %s", + wallet_handle, + claim_offer_json) + + if not hasattr(prover_store_claim_offer, "cb"): + logger.debug("prover_store_claim_offer: Creating callback") + prover_store_claim_offer.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) + + c_wallet_handle = c_int32(wallet_handle) + c_claim_offer_json = c_char_p(claim_offer_json.encode('utf-8')) + + res = await do_call('indy_prover_store_claim_offer', + prover_store_claim_offer.cb, + c_wallet_handle, + c_claim_offer_json) + + logger.debug("prover_store_claim_offer: <<< res: %s", res) + return res async def prover_get_claim_offers(wallet_handle: int, From 261e190f026bff2730fe09882a378266379ce134 Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Fri, 21 Jul 2017 12:03:00 +0200 Subject: [PATCH 275/349] [java] sync Signus encrypt() and decrypt() method signatures --- .../main/java/org/hyperledger/indy/sdk/LibIndy.java | 4 ++-- .../java/org/hyperledger/indy/sdk/signus/Signus.java | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java index fb5eadca84..60b5f4c3ab 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java @@ -54,8 +54,8 @@ public interface API extends Library { public int indy_store_their_did(int command_handle, int wallet_handle, String identity_json, Callback cb); public int indy_sign(int command_handle, int wallet_handle, String did, String msg, Callback cb); public int indy_verify_signature(int command_handle, int wallet_handle, int pool_handle, String did, String signed_msg, Callback cb); - public int indy_encrypt(int command_handle, int wallet_handle, String did, String msg, Callback cb); - public int indy_decrypt(int command_handle, int wallet_handle, String did, String encrypted_msg, Callback cb); + public int indy_encrypt(int command_handle, int wallet_handle, int pool_handle, String myDid, String did, String msg, Callback cb); + public int indy_decrypt(int command_handle, int wallet_handle, String myDid, String did, String encrypted_msg, String nonce, Callback cb); // anoncreds.rs diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java index d75bdb6d21..731be50240 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java @@ -231,6 +231,8 @@ public static CompletableFuture verifySignature( public static CompletableFuture encrypt( Wallet wallet, + Pool pool, + String myDid, String did, String msg) throws IndyException { @@ -238,10 +240,13 @@ public static CompletableFuture encrypt( int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); + int poolHandle = pool.getPoolHandle(); int result = LibIndy.api.indy_encrypt( commandHandle, walletHandle, + poolHandle, + myDid, did, msg, encryptCb); @@ -253,8 +258,10 @@ public static CompletableFuture encrypt( public static CompletableFuture decrypt( Wallet wallet, + String myDid, String did, - String encryptedMsg) throws IndyException { + String encryptedMsg, + String nonce) throws IndyException { CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); @@ -264,8 +271,10 @@ public static CompletableFuture decrypt( int result = LibIndy.api.indy_decrypt( commandHandle, walletHandle, + myDid, did, encryptedMsg, + nonce, decryptCb); checkResult(result); From 58afa7b20f6955b52af9579209301d4583438ac5 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 21 Jul 2017 13:24:06 +0300 Subject: [PATCH 276/349] Updated version of zmq-pw --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c3bca4c5a7..69d2d9009e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,7 @@ serde_json = "1.0" serde_derive = "1.0" sodiumoxide = {version = "0.0.14", optional = true} time = "0.1.36" -zmq-pw = "0.9.5" +zmq-pw = "0.9.6" lazy_static = "0.2" byteorder = "1.0.0" [dependencies.uuid] From cd937f4e262cf5c1090c22b7a89bcc1529b80d00 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 21 Jul 2017 13:38:43 +0300 Subject: [PATCH 277/349] added get_claim_offers --- wrappers/python/indy/anoncreds.py | 48 ++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/wrappers/python/indy/anoncreds.py b/wrappers/python/indy/anoncreds.py index d6491b1a1f..15f8d49219 100644 --- a/wrappers/python/indy/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -27,8 +27,8 @@ async def issuer_create_and_store_claim_def(wallet_handle: int, """ logger = logging.getLogger(__name__) - logger.debug("issuer_create_and_store_claim_def: >>> wallet_handle: %s, issuer_did: %s, schema_json: %s," - " signature_type: %s, create_non_revoc: %s", + logger.debug("issuer_create_and_store_claim_def: >>> wallet_handle: %r, issuer_did: %r, schema_json: %r," + " signature_type: %r, create_non_revoc: %r", wallet_handle, issuer_did, schema_json, @@ -53,7 +53,7 @@ async def issuer_create_and_store_claim_def(wallet_handle: int, c_signature_type, c_create_non_revoc) res = claim_def_json.decode() - logger.debug("issuer_create_and_store_claim_def: <<< res: %s", res) + logger.debug("issuer_create_and_store_claim_def: <<< res: %r", res) return res @@ -74,8 +74,8 @@ async def issuer_create_and_store_revoc_reg(wallet_handle: int, """ logger = logging.getLogger(__name__) - logger.debug("issuer_create_and_store_revoc_reg: >>> wallet_handle: %s, issuer_did: %s, schema_seq_no: %s," - " max_claim_num: %s", + logger.debug("issuer_create_and_store_revoc_reg: >>> wallet_handle: %r, issuer_did: %r, schema_seq_no: %r," + " max_claim_num: %r", wallet_handle, issuer_did, schema_seq_no, @@ -97,7 +97,7 @@ async def issuer_create_and_store_revoc_reg(wallet_handle: int, c_schema_seq_no, c_max_claim_num) res = (revoc_reg_json.decode(), revoc_reg_uuid.decode()) - logger.debug("issuer_create_and_store_revoc_reg: <<< res: %s", res) + logger.debug("issuer_create_and_store_revoc_reg: <<< res: %r", res) return res @@ -144,8 +144,8 @@ async def issuer_create_claim(wallet_handle: int, """ logger = logging.getLogger(__name__) - logger.debug("issuer_create_claim: >>> wallet_handle: %s, claim_req_json: %s, claim_json: %s," - " revoc_reg_seq_no: %s, user_revoc_index: %s", + logger.debug("issuer_create_claim: >>> wallet_handle: %r, claim_req_json: %r, claim_json: %r," + " revoc_reg_seq_no: %r, user_revoc_index: %r", wallet_handle, claim_req_json, claim_json, @@ -170,7 +170,7 @@ async def issuer_create_claim(wallet_handle: int, c_revoc_reg_seq_no, c_user_revoc_index) res = (revoc_reg_update_json.decode(), claim_json.decode()) - logger.debug("issuer_create_claim: <<< res: %s", res) + logger.debug("issuer_create_claim: <<< res: %r", res) return res @@ -189,7 +189,7 @@ async def issuer_revoke_claim(wallet_handle: int, """ logger = logging.getLogger(__name__) - logger.debug("issuer_revoke_claim: >>> wallet_handle: %s, revoc_reg_seq_no: %s, user_revoc_index: %s", + logger.debug("issuer_revoke_claim: >>> wallet_handle: %r, revoc_reg_seq_no: %r, user_revoc_index: %r", wallet_handle, revoc_reg_seq_no, user_revoc_index) @@ -208,7 +208,7 @@ async def issuer_revoke_claim(wallet_handle: int, c_revoc_reg_seq_no, c_user_revoc_index) res = revoc_reg_update_json.decode() - logger.debug("issuer_revoke_claim: <<< res: %s", res) + logger.debug("issuer_revoke_claim: <<< res: %r", res) return res @@ -227,7 +227,7 @@ async def prover_store_claim_offer(wallet_handle: int, """ logger = logging.getLogger(__name__) - logger.debug("prover_store_claim_offer: >>> wallet_handle: %s, claim_offer_json: %s", + logger.debug("prover_store_claim_offer: >>> wallet_handle: %r, claim_offer_json: %r", wallet_handle, claim_offer_json) @@ -243,7 +243,7 @@ async def prover_store_claim_offer(wallet_handle: int, c_wallet_handle, c_claim_offer_json) - logger.debug("prover_store_claim_offer: <<< res: %s", res) + logger.debug("prover_store_claim_offer: <<< res: %r", res) return res @@ -266,7 +266,27 @@ async def prover_get_claim_offers(wallet_handle: int, "schema_seq_no": string}] } """ - pass + + logger = logging.getLogger(__name__) + logger.debug("prover_store_claim_offer: >>> wallet_handle: %r, filter_json: %r", + wallet_handle, + filter_json) + + if not hasattr(prover_get_claim_offers, "cb"): + logger.debug("prover_get_claim_offers: Creating callback") + prover_get_claim_offers.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_wallet_handle = c_int32(wallet_handle) + c_filter_json = c_char_p(filter_json.encode('utf-8')) + + claim_offers_json = await do_call('indy_prover_get_claim_offers', + prover_get_claim_offers.cb, + c_wallet_handle, + c_filter_json) + + res = claim_offers_json.decode() + logger.debug("prover_get_claim_offers: <<< res: %r", res) + return res async def prover_create_master_secret(wallet_handle: int, From 06896e6ff7bed14fb3b01ebbb5b0041e0e5135c8 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Fri, 21 Jul 2017 13:43:22 +0300 Subject: [PATCH 278/349] * agent_connect/agent_listen bugfixes * test_agent_connect added --- wrappers/python/indy/agent.py | 78 +++++++++++++------ wrappers/python/indy/signus.py | 4 +- .../python/tests/agent/test_agent_connect.py | 38 ++++++++- 3 files changed, 90 insertions(+), 30 deletions(-) diff --git a/wrappers/python/indy/agent.py b/wrappers/python/indy/agent.py index 0fb22149ce..8245bf6dee 100644 --- a/wrappers/python/indy/agent.py +++ b/wrappers/python/indy/agent.py @@ -20,27 +20,46 @@ class ConnectionEvent(Event): sender_did: str receiver_did: str - def __init__(self, handle: int, err: int, connection_handle: int, sender_did: str, receiver_did): - self.handle = handle, + def __init__(self, handle: int, err: int, connection_handle: int, sender_did: bytes, receiver_did: bytes): + logger = logging.getLogger(__name__) + logger.debug("ConnectionEvent:__init__ >>> handle: %r, err: %r, connection_handle: %r, sender_did: %r, " + "receiver_did: %r", + handle, + err, + connection_handle, + sender_did, + receiver_did) + + self.handle = handle if err != ErrorCode.Success: self.error = IndyError(ErrorCode(err)) else: self.connection_handle = connection_handle - self.sender_did = sender_did - self.receiver_did = receiver_did + self.sender_did = sender_did.decode() + self.receiver_did = receiver_did.decode() + + logger.debug("ConnectionEvent:__init__ <<< self: %r", self) class MessageEvent(Event): message: str - def __init__(self, handle: int, err: int, message: str): + def __init__(self, handle: int, err: int, message: bytes): + logger = logging.getLogger(__name__) + logger.debug("MessageEvent:__init__ >>> handle: %r, err: %r, message: %r", + handle, + err, + message) + self.handle = handle, if err != ErrorCode.Success: self._error = IndyError(ErrorCode(err)) else: - self.message = message + self.message = message.decode() + + logger.debug("MessageEvent:__init__ <<< self: %r", self) _events: List[Event] = [] @@ -48,6 +67,11 @@ def __init__(self, handle: int, err: int, message: str): def _notify_event_waiters(): + logger = logging.getLogger(__name__) + logger.debug("_notify_event_waiters: >>> _event_waiters: %r, _events: %r", + _event_waiters, + _events) + for i, (handles, event_loop, future) in enumerate(_event_waiters): for j, event in enumerate(_events): if event.handle in handles: @@ -56,11 +80,15 @@ def _notify_event_waiters(): event_loop.call_soon_threadsafe(lambda f, e: f.set_result(e), future, event) + logger.debug("_notify_event_waiters: <<< handles: %r, event: %r", handles, event) + return + + logger.debug("_notify_event_waiters: <<< no events") async def agent_wait_for_event(handles: List[int]) -> Event: logger = logging.getLogger(__name__) - logger.debug("agent_wait_for_event: >>> handles: %s", handles) + logger.debug("agent_wait_for_event: >>> handles: %r", handles) event_loop = asyncio.get_event_loop() future = event_loop.create_future() @@ -70,7 +98,7 @@ async def agent_wait_for_event(handles: List[int]) -> Event: res = await future - logger.debug("agent_wait_for_event: <<< res: %s", res) + logger.debug("agent_wait_for_event: <<< res: %r", res) return res @@ -79,7 +107,7 @@ async def agent_connect(pool_handle: int, sender_did: str, receiver_did: str) -> int: logger = logging.getLogger(__name__) - logger.debug("agent_connect: >>> pool_handle: %i, wallet_handle: %i, sender_did: %s, receiver_did: %s", + logger.debug("agent_connect: >>> pool_handle: %r, wallet_handle: %r, sender_did: %r, receiver_did: %r", pool_handle, wallet_handle, sender_did, @@ -89,8 +117,8 @@ async def agent_connect(pool_handle: int, logger.debug("agent_connect: Creating connection callback") agent_connect.connection_cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_int32)) - def _message_cb(connection_handle: int, err: int, message: str): - logger.debug("agent_connect._message_cb: connection_handle: %i, err: %i, message: %s", + def _message_cb(connection_handle: int, err: int, message: bytes): + logger.debug("agent_connect._message_cb: connection_handle: %r, err: %r, message: %r", connection_handle, err, message) @@ -114,21 +142,21 @@ def _message_cb(connection_handle: int, err: int, message: str): agent_connect.connection_cb, agent_connect.message_cb) - logger.debug("agent_connect: <<< res: %i", res) + logger.debug("agent_connect: <<< res: %r", res) return res async def agent_listen(endpoint: str) -> int: logger = logging.getLogger(__name__) - logger.debug("agent_listen: >>> endpoint: %s", endpoint) + logger.debug("agent_listen: >>> endpoint: %r", endpoint) if not hasattr(agent_listen, "listener_cb"): logger.debug("agent_listen: Creating listener callback") agent_listen.listener_cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_int32)) - def _connection_cb(listener_handle: int, err: int, connection_handle: int, sender_did: str, receiver_did: str): - logger.debug("agent_connect._connection_cb: listener_handle: %i, err: %i, connection_handle: %i, sender_did: " - "%s, receiver_did: %s", + def _connection_cb(listener_handle: int, err: int, connection_handle: int, sender_did: bytes, receiver_did: bytes): + logger.debug("agent_connect._connection_cb: listener_handle: %r, err: %r, connection_handle: %r, sender_did: " + "%r, receiver_did: %r", connection_handle, err, connection_handle, @@ -139,10 +167,10 @@ def _connection_cb(listener_handle: int, err: int, connection_handle: int, sende if not hasattr(agent_listen, "connection_cb"): logger.debug("agent_listen: Creating connection callback") - agent_listen.connection_cb = CFUNCTYPE(None, c_int32, c_int32, c_char_p)(_connection_cb) + agent_listen.connection_cb = CFUNCTYPE(None, c_int32, c_int32, c_int32, c_char_p, c_char_p)(_connection_cb) - def _message_cb(connection_handle: int, err: int, message: str): - logger.debug("agent_connect._message_cb: connection_handle: %i, err: %i, message: %s", + def _message_cb(connection_handle: int, err: int, message: bytes): + logger.debug("agent_connect._message_cb: connection_handle: %r, err: %r, message: %r", connection_handle, err, message) @@ -161,7 +189,7 @@ def _message_cb(connection_handle: int, err: int, message: str): agent_listen.connection_cb, agent_listen.message_cb) - logger.debug("agent_listen: <<< res: %i", res) + logger.debug("agent_listen: <<< res: %r", res) return res @@ -170,7 +198,7 @@ async def agent_add_identity(listener_handle: int, wallet_handle: int, did: str) -> None: logger = logging.getLogger(__name__) - logger.debug("agent_add_identity: >>> listener_handle: %i, pool_handle: %i, wallet_handle: %i, did: %s", + logger.debug("agent_add_identity: >>> listener_handle: %r, pool_handle: %r, wallet_handle: %r, did: %r", listener_handle, pool_handle, wallet_handle, @@ -200,7 +228,7 @@ async def agent_remove_identity(listener_handle: int, wallet_handle: int, did: str) -> None: logger = logging.getLogger(__name__) - logger.debug("agent_remove_identity: >>> listener_handle: %i, pool_handle: %i, wallet_handle: %i, did: %s", + logger.debug("agent_remove_identity: >>> listener_handle: %r, pool_handle: %r, wallet_handle: %r, did: %r", listener_handle, pool_handle, wallet_handle, @@ -227,7 +255,7 @@ async def agent_remove_identity(listener_handle: int, async def agent_send(connection_handle: int, message: str) -> None: logger = logging.getLogger(__name__) - logger.debug("agent_send: >>> connection_handle: %i, message: %s", + logger.debug("agent_send: >>> connection_handle: %r, message: %r", connection_handle, message) @@ -248,7 +276,7 @@ async def agent_send(connection_handle: int, message: str) -> None: async def agent_close_connection(connection_handle: int) -> None: logger = logging.getLogger(__name__) - logger.debug("agent_close_connection: >>> connection_handle: %i", connection_handle) + logger.debug("agent_close_connection: >>> connection_handle: %r", connection_handle) if not hasattr(agent_close_connection, "cb"): logger.debug("agent_close_connection: Creating callback") @@ -265,7 +293,7 @@ async def agent_close_connection(connection_handle: int) -> None: async def agent_close_listener(listener_handle: int) -> None: logger = logging.getLogger(__name__) - logger.debug("agent_close_listener: >>> listener_handle: %i", listener_handle) + logger.debug("agent_close_listener: >>> listener_handle: %r", listener_handle) if not hasattr(agent_close_listener, "cb"): logger.debug("agent_close_listener: Creating callback") diff --git a/wrappers/python/indy/signus.py b/wrappers/python/indy/signus.py index 63723cedd5..d375dac9d0 100644 --- a/wrappers/python/indy/signus.py +++ b/wrappers/python/indy/signus.py @@ -18,11 +18,13 @@ async def create_and_store_my_did(wallet_handle: int, c_wallet_handle = c_int32(wallet_handle) c_did_json = c_char_p(did_json.encode('utf-8')) - res = await do_call('indy_create_and_store_my_did', + did, verkey, pk = await do_call('indy_create_and_store_my_did', c_wallet_handle, c_did_json, create_and_store_my_did.cb) + res = (did.decode(), verkey.decode(), pk.decode()) + logger.debug("create_and_store_my_did: <<< res: %s", res) return res diff --git a/wrappers/python/tests/agent/test_agent_connect.py b/wrappers/python/tests/agent/test_agent_connect.py index a30b8042a4..ded27c2a96 100644 --- a/wrappers/python/tests/agent/test_agent_connect.py +++ b/wrappers/python/tests/agent/test_agent_connect.py @@ -1,9 +1,10 @@ +import json import logging import pytest -from indy import wallet -from ..utils import storage +from indy import signus, agent +from ..utils import storage, wallet logging.basicConfig(level=logging.DEBUG) @@ -15,6 +16,35 @@ def cleanup_storage(): storage.cleanup() +@pytest.fixture +async def wallet_handle(): + handle = await wallet.create_and_open_wallet() + yield handle + await wallet.close_wallet(handle) + + @pytest.mark.asyncio -async def test_agent_connect_works_for_all_data_in_wallet_present(): - pass +async def test_agent_connect_works(wallet_handle): + endpoint = "127.0.0.1:9701" + did, verkey, pk = await signus.create_and_store_my_did(wallet_handle, "{}") + + await signus.store_their_did(wallet_handle, json.dumps({ + "did": did, + "verkey": verkey, + "pk": pk, + "endpoint": endpoint})) + + listener_handle = await agent.agent_listen(endpoint) + assert listener_handle is not None + + await agent.agent_add_identity(listener_handle, -1, wallet_handle, did) + + connection_handle = await agent.agent_connect(0, wallet_handle, did, did) + assert connection_handle is not None + + event = await agent.agent_wait_for_event([listener_handle, connection_handle]) + + assert type(event) is agent.ConnectionEvent + assert event.handle == listener_handle + assert event.sender_did == did + assert event.receiver_did == did From 6b4e49a0fa6a2c8fc01d2a0e5dda2badf360b37d Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 21 Jul 2017 13:44:39 +0300 Subject: [PATCH 279/349] added prover_create_master_secret --- wrappers/python/indy/anoncreds.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/wrappers/python/indy/anoncreds.py b/wrappers/python/indy/anoncreds.py index 15f8d49219..1cd0226ab5 100644 --- a/wrappers/python/indy/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -299,7 +299,26 @@ async def prover_create_master_secret(wallet_handle: int, :param master_secret_name: a new master secret name :return: None. """ - pass + + logger = logging.getLogger(__name__) + logger.debug("prover_create_master_secret: >>> wallet_handle: %r, master_secret_name: %r", + wallet_handle, + master_secret_name) + + if not hasattr(prover_create_master_secret, "cb"): + logger.debug("prover_create_master_secret: Creating callback") + prover_create_master_secret.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) + + c_wallet_handle = c_int32(wallet_handle) + c_master_secret_name = c_char_p(master_secret_name.encode('utf-8')) + + res = await do_call('indy_prover_create_master_secret', + prover_create_master_secret.cb, + c_wallet_handle, + c_master_secret_name) + + logger.debug("prover_create_master_secret: <<< res: %r", res) + return res async def prover_create_and_store_claim_req(wallet_handle: int, From 78e5931820a3ad9ed48df2716be7175e6920caa9 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 21 Jul 2017 13:55:54 +0300 Subject: [PATCH 280/349] added create_and_store_claim_req --- wrappers/python/indy/anoncreds.py | 32 ++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/wrappers/python/indy/anoncreds.py b/wrappers/python/indy/anoncreds.py index 1cd0226ab5..b7baf12c9e 100644 --- a/wrappers/python/indy/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -351,7 +351,37 @@ async def prover_create_and_store_claim_req(wallet_handle: int, "issuer_did" : } """ - pass + + logger = logging.getLogger(__name__) + logger.debug("prover_create_and_store_claim_req: >>> wallet_handle: %r, prover_did: %r, claim_offer_json: %r," + " claim_def_json: %r, master_secret_name: %r", + wallet_handle, + prover_did, + claim_offer_json, + claim_def_json, + master_secret_name) + + if not hasattr(prover_create_and_store_claim_req, "cb"): + logger.debug("prover_create_and_store_claim_req: Creating callback") + prover_create_and_store_claim_req.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_wallet_handle = c_int32(wallet_handle) + c_prover_did = c_char_p(prover_did.encode('utf-8')) + c_claim_offer_json = c_char_p(claim_offer_json.encode('utf-8')) + c_claim_def_json = c_char_p(claim_def_json.encode('utf-8')) + c_master_secret_name = c_char_p(master_secret_name.encode('utf-8')) + + claim_req_json = await do_call('indy_prover_create_and_store_claim_req', + prover_create_and_store_claim_req.cb, + c_wallet_handle, + c_prover_did, + c_claim_offer_json, + c_claim_def_json, + c_master_secret_name) + + res = claim_req_json.decode() + logger.debug("prover_create_and_store_claim_req: <<< res: %r", res) + return res async def prover_store_claim(wallet_handle: int, From 8f19d978dfe11ed6e156fb2b106475d735968dd7 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 21 Jul 2017 13:58:12 +0300 Subject: [PATCH 281/349] Added java.dockerfile --- ci/java.dockerfile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 ci/java.dockerfile diff --git a/ci/java.dockerfile b/ci/java.dockerfile new file mode 100644 index 0000000000..e0ee906778 --- /dev/null +++ b/ci/java.dockerfile @@ -0,0 +1,19 @@ +FROM ubuntu:16.04 + +RUN apt-get update && apt-get install openjdk-8-jdk -y + +ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64 + +RUN apt-get install -y \ + maven \ + gdebi \ + apt-utils + +ADD https://repo.evernym.com/deb/indy-sdk/0.1.1/indy-sdk_0.1.1_amd64.deb . + +RUN gdebi -n indy-sdk_0.1.1_amd64.deb + +RUN useradd -ms /bin/bash -u $uid indy +USER indy + +WORKDIR /home/indy \ No newline at end of file From 6334b8d1beee7ac62b6aab3bc09b6e1c04ade4ff Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 21 Jul 2017 14:05:30 +0300 Subject: [PATCH 282/349] Corrected dockerfile --- ci/java.dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/java.dockerfile b/ci/java.dockerfile index e0ee906778..ab75104456 100644 --- a/ci/java.dockerfile +++ b/ci/java.dockerfile @@ -1,5 +1,7 @@ FROM ubuntu:16.04 +ARG uid=1000 + RUN apt-get update && apt-get install openjdk-8-jdk -y ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64 From aa74fccf36455b3a342e16dd427bc895552f7e8b Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 21 Jul 2017 14:29:04 +0300 Subject: [PATCH 283/349] corrected dockerfile --- ci/java.dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/java.dockerfile b/ci/java.dockerfile index ab75104456..f3179e6196 100644 --- a/ci/java.dockerfile +++ b/ci/java.dockerfile @@ -18,4 +18,4 @@ RUN gdebi -n indy-sdk_0.1.1_amd64.deb RUN useradd -ms /bin/bash -u $uid indy USER indy -WORKDIR /home/indy \ No newline at end of file +WORKDIR /home/indy/wrappers/java \ No newline at end of file From 9b2c7e647b38802b36d92266ab2f23c6743d8a55 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 21 Jul 2017 14:41:16 +0300 Subject: [PATCH 284/349] Changed version of zmq-pw --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 69d2d9009e..2398bd8059 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,7 @@ serde_json = "1.0" serde_derive = "1.0" sodiumoxide = {version = "0.0.14", optional = true} time = "0.1.36" -zmq-pw = "0.9.6" +zmq-pw = "0.9.7" lazy_static = "0.2" byteorder = "1.0.0" [dependencies.uuid] From eb53544db62f5795814fe9163d10f31e98cbe9db Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Thu, 20 Jul 2017 08:55:28 +0200 Subject: [PATCH 285/349] [java] WIP wrapper for indy_register_wallet_type() --- .../org/hyperledger/indy/sdk/LibIndy.java | 1 + .../hyperledger/indy/sdk/wallet/Wallet.java | 41 +++++- .../indy/sdk/wallet/WalletType.java | 134 ++++++++++++++++++ .../indy/sdk/wallet/WalletTypeMemory.java | 73 ++++++++++ 4 files changed, 246 insertions(+), 3 deletions(-) create mode 100644 wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletType.java create mode 100644 wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeMemory.java diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java index 60b5f4c3ab..f632b3839d 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java @@ -26,6 +26,7 @@ public interface API extends Library { // wallet.rs + public int indy_register_wallet_type(int command_handle, String xtype, Callback create, Callback open, Callback set, Callback get, Callback get_not_expired, Callback list, Callback close, Callback delete, Callback free, Callback cb); public int indy_create_wallet(int command_handle, String pool_name, String name, String xtype, String config, String credentials, Callback cb); public int indy_open_wallet(int command_handle, String name, String runtime_config, String credentials, Callback cb); public int indy_close_wallet(int command_handle, int handle, Callback cb); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java index 2215c4b1b4..f9172334e7 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java @@ -29,6 +29,19 @@ public int getWalletHandle() { * STATIC CALLBACKS */ + private static Callback registerWalletTypeCb = new Callback() { + + @SuppressWarnings({ "unused", "unchecked" }) + public void callback(int xcommand_handle, int err) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkCallback(future, err)) return; + + Void result = null; + future.complete(result); + } + }; + private static Callback createWalletCb = new Callback() { @SuppressWarnings({"unused", "unchecked"}) @@ -87,9 +100,31 @@ public void callback(int xcommand_handle, int err) { * STATIC METHODS */ - /* IMPLEMENT LATER - * public CompletableFuture<...> registerWalletType( - ...) throws IndyException;*/ + public CompletableFuture registerWalletType( + String xtype, + WalletType walletType) throws IndyException { + + CompletableFuture future = new CompletableFuture (); + int commandHandle = addFuture(future); + + int result = LibIndy.api.indy_register_wallet_type( + commandHandle, + xtype, + walletType.getCreateCb(), + walletType.getOpenCb(), + walletType.getSetCb(), + walletType.getGetCb(), + walletType.getGetNotExpiredCb(), + walletType.getListCb(), + walletType.getCloseCb(), + walletType.getDeleteCb(), + walletType.getFreeCb(), + registerWalletTypeCb); + + checkResult(result); + + return future; + } public static CompletableFuture createWallet( String poolName, diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletType.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletType.java new file mode 100644 index 0000000000..7b3b2e021b --- /dev/null +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletType.java @@ -0,0 +1,134 @@ +package org.hyperledger.indy.sdk.wallet; + +import com.sun.jna.Callback; +import com.sun.jna.Pointer; + +public abstract class WalletType { + + private Callback createCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(String name, String config, String credentials) { + + WalletType.this.create(name, config, credentials); + } + }; + + private Callback openCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(String name, String config, String runtime_config, String credentials, Pointer handle) { + + WalletType.this.open(name, config, runtime_config, credentials, handle); + } + }; + + private Callback setCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(int handle, String key, String value) { + + WalletType.this.set(handle, key, value); + } + }; + + private Callback getCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(int handle, String key, Pointer value_ptr) { + + WalletType.this.get(handle, key, value_ptr); + } + }; + + private Callback getNotExpiredCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(int handle, String key, Pointer value_ptr) { + + WalletType.this.getNotExpired(handle, key, value_ptr); + } + }; + + private Callback listCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(int handle, String key_prefix, Pointer values_json_ptr) { + + WalletType.this.list(handle, key_prefix, values_json_ptr); + } + }; + + private Callback closeCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(int handle) { + + WalletType.this.close(handle); + } + }; + + private Callback deleteCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(String name, String config, String credentials) { + + WalletType.this.delete(name, config, credentials); + } + }; + + private Callback freeCb = new Callback() { + + @SuppressWarnings("unused") + public void callback(int wallet_handle, String value) { + + WalletType.this.free(wallet_handle, value); + } + }; + + public abstract void create(String name, String config, String credentials); + public abstract void open(String name, String config, String runtimeConfig, String credentials, Pointer handle); + public abstract void set(int handle, String key, String value); + public abstract void get(int handle, String key, Pointer valuePtr); + public abstract void getNotExpired(int handle, String key, Pointer valuePtr); + public abstract void list(int handle, String keyPrefx, Pointer valuesJsonPtr); + public abstract void close(int handle); + public abstract void delete(String name, String config, String credentials); + public abstract void free(int walletHandle, String value); + + public Callback getCreateCb() { + return createCb; + } + + public Callback getOpenCb() { + return openCb; + } + + public Callback getSetCb() { + return setCb; + } + + public Callback getGetCb() { + return getCb; + } + + public Callback getGetNotExpiredCb() { + return getNotExpiredCb; + } + + public Callback getListCb() { + return listCb; + } + + public Callback getCloseCb() { + return closeCb; + } + + public Callback getDeleteCb() { + return deleteCb; + } + + public Callback getFreeCb() { + return freeCb; + } +} diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeMemory.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeMemory.java new file mode 100644 index 0000000000..82fbb5245c --- /dev/null +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeMemory.java @@ -0,0 +1,73 @@ +package org.hyperledger.indy.sdk.wallet; + +import com.sun.jna.Pointer; + +public class WalletTypeMemory extends WalletType { + + private static WalletTypeMemory instance; + + public static WalletTypeMemory getInstance() { + + if (instance == null) instance = new WalletTypeMemory(); + return instance; + } + + private WalletTypeMemory() { + + } + + @Override + public void create(String name, String config, String credentials) { + // TODO Auto-generated method stub + + } + + @Override + public void open(String name, String config, String runtimeConfig, String credentials, Pointer handle) { + // TODO Auto-generated method stub + + } + + @Override + public void set(int handle, String key, String value) { + // TODO Auto-generated method stub + + } + + @Override + public void get(int handle, String key, Pointer valuePtr) { + // TODO Auto-generated method stub + + } + + @Override + public void getNotExpired(int handle, String key, Pointer valuePtr) { + // TODO Auto-generated method stub + + } + + @Override + public void list(int handle, String keyPrefix, Pointer valuesJsonPtr) { + // TODO Auto-generated method stub + + } + + @Override + public void close(int handle) { + // TODO Auto-generated method stub + + } + + @Override + public void delete(String name, String config, String credentials) { + // TODO Auto-generated method stub + + } + + @Override + public void free(int WalletHandle, String value) { + // TODO Auto-generated method stub + + } + +} From 4bfef37411fc4ea893cb59e90435d5b6ce64a93f Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Fri, 21 Jul 2017 12:30:10 +0200 Subject: [PATCH 286/349] [java] WIP inmem wallet type --- .../hyperledger/indy/sdk/wallet/Wallet.java | 2 +- .../indy/sdk/wallet/WalletType.java | 56 +++--- .../indy/sdk/wallet/WalletTypeInmem.java | 172 ++++++++++++++++++ .../indy/sdk/wallet/WalletTypeMemory.java | 73 -------- .../sdk/wallet/RegisterWalletTypeTest.java | 34 ++++ 5 files changed, 236 insertions(+), 101 deletions(-) create mode 100644 wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeInmem.java delete mode 100644 wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeMemory.java create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/RegisterWalletTypeTest.java diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java index f9172334e7..5cf503e4c6 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java @@ -100,7 +100,7 @@ public void callback(int xcommand_handle, int err) { * STATIC METHODS */ - public CompletableFuture registerWalletType( + public static CompletableFuture registerWalletType( String xtype, WalletType walletType) throws IndyException { diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletType.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletType.java index 7b3b2e021b..3de7e9b7fd 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletType.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletType.java @@ -1,5 +1,7 @@ package org.hyperledger.indy.sdk.wallet; +import org.hyperledger.indy.sdk.ErrorCode; + import com.sun.jna.Callback; import com.sun.jna.Pointer; @@ -8,93 +10,93 @@ public abstract class WalletType { private Callback createCb = new Callback() { @SuppressWarnings("unused") - public void callback(String name, String config, String credentials) { + public int callback(String name, String config, String credentials) { - WalletType.this.create(name, config, credentials); + return WalletType.this.create(name, config, credentials).ordinal(); } }; private Callback openCb = new Callback() { @SuppressWarnings("unused") - public void callback(String name, String config, String runtime_config, String credentials, Pointer handle) { + public int callback(String name, String config, String runtime_config, String credentials, Pointer handle) { - WalletType.this.open(name, config, runtime_config, credentials, handle); + return WalletType.this.open(name, config, runtime_config, credentials, handle).ordinal(); } }; private Callback setCb = new Callback() { @SuppressWarnings("unused") - public void callback(int handle, String key, String value) { + public int callback(int handle, String key, String value) { - WalletType.this.set(handle, key, value); + return WalletType.this.set(handle, key, value).ordinal(); } }; private Callback getCb = new Callback() { @SuppressWarnings("unused") - public void callback(int handle, String key, Pointer value_ptr) { + public int callback(int handle, String key, Pointer value_ptr) { - WalletType.this.get(handle, key, value_ptr); + return WalletType.this.get(handle, key, value_ptr).ordinal(); } }; private Callback getNotExpiredCb = new Callback() { @SuppressWarnings("unused") - public void callback(int handle, String key, Pointer value_ptr) { + public int callback(int handle, String key, Pointer value_ptr) { - WalletType.this.getNotExpired(handle, key, value_ptr); + return WalletType.this.getNotExpired(handle, key, value_ptr).ordinal(); } }; private Callback listCb = new Callback() { @SuppressWarnings("unused") - public void callback(int handle, String key_prefix, Pointer values_json_ptr) { + public int callback(int handle, String key_prefix, Pointer values_json_ptr) { - WalletType.this.list(handle, key_prefix, values_json_ptr); + return WalletType.this.list(handle, key_prefix, values_json_ptr).ordinal(); } }; private Callback closeCb = new Callback() { @SuppressWarnings("unused") - public void callback(int handle) { + public int callback(int handle) { - WalletType.this.close(handle); + return WalletType.this.close(handle).ordinal(); } }; private Callback deleteCb = new Callback() { @SuppressWarnings("unused") - public void callback(String name, String config, String credentials) { + public int callback(String name, String config, String credentials) { - WalletType.this.delete(name, config, credentials); + return WalletType.this.delete(name, config, credentials).ordinal(); } }; private Callback freeCb = new Callback() { @SuppressWarnings("unused") - public void callback(int wallet_handle, String value) { + public int callback(int wallet_handle, String value) { - WalletType.this.free(wallet_handle, value); + return WalletType.this.free(wallet_handle, value).ordinal(); } }; - public abstract void create(String name, String config, String credentials); - public abstract void open(String name, String config, String runtimeConfig, String credentials, Pointer handle); - public abstract void set(int handle, String key, String value); - public abstract void get(int handle, String key, Pointer valuePtr); - public abstract void getNotExpired(int handle, String key, Pointer valuePtr); - public abstract void list(int handle, String keyPrefx, Pointer valuesJsonPtr); - public abstract void close(int handle); - public abstract void delete(String name, String config, String credentials); - public abstract void free(int walletHandle, String value); + public abstract ErrorCode create(String name, String config, String credentials); + public abstract ErrorCode open(String name, String config, String runtimeConfig, String credentials, Pointer handle); + public abstract ErrorCode set(int handle, String key, String value); + public abstract ErrorCode get(int handle, String key, Pointer valuePtr); + public abstract ErrorCode getNotExpired(int handle, String key, Pointer valuePtr); + public abstract ErrorCode list(int handle, String keyPrefx, Pointer valuesJsonPtr); + public abstract ErrorCode close(int handle); + public abstract ErrorCode delete(String name, String config, String credentials); + public abstract ErrorCode free(int walletHandle, String value); public Callback getCreateCb() { return createCb; diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeInmem.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeInmem.java new file mode 100644 index 0000000000..c83870286d --- /dev/null +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeInmem.java @@ -0,0 +1,172 @@ +package org.hyperledger.indy.sdk.wallet; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; + +import org.hyperledger.indy.sdk.ErrorCode; + +import com.sun.jna.Pointer; + +public class WalletTypeInmem extends WalletType { + + private static WalletTypeInmem instance; + + public static WalletTypeInmem getInstance() { + + if (instance == null) instance = new WalletTypeInmem(); + return instance; + } + + private WalletTypeInmem() { + + } + + @Override + public ErrorCode create(String name, String config, String credentials) { + + if (this.walletsByName.containsKey(name)) return ErrorCode.CommonInvalidState; + + WalletInmem wallet = new WalletInmem(); + this.walletsByName.put(name, wallet); + this.walletsByHandle.put(wallet.handle, wallet); + + return ErrorCode.Success; + } + + @Override + public ErrorCode open(String name, String config, String runtimeConfig, String credentials, Pointer handle) { + + WalletInmem wallet = this.walletsByName.get(name); + if (wallet == null) return ErrorCode.CommonInvalidState; + + wallet.open = true; + + handle.setInt(0, wallet.handle); + return ErrorCode.Success; + } + + @Override + public ErrorCode set(int handle, String key, String value) { + + WalletInmem wallet = this.walletsByHandle.get(handle); + if (wallet == null) return ErrorCode.CommonInvalidState; + + wallet.values.put(key, value); + + System.out.println("SET " + key + " --> " + value); + + return ErrorCode.Success; + } + + @Override + public ErrorCode get(int handle, String key, Pointer valuePtr) { + + WalletInmem wallet = this.walletsByHandle.get(handle); + if (wallet == null) return ErrorCode.CommonInvalidState; + + String value = wallet.values.get(key); + + System.out.println("GET " + key + " --> " + value); + + valuePtr.setString(0, value); + return ErrorCode.Success; + } + + @Override + public ErrorCode getNotExpired(int handle, String key, Pointer valuePtr) { + + WalletInmem wallet = this.walletsByHandle.get(handle); + if (wallet == null) return ErrorCode.CommonInvalidState; + + String value = wallet.values.get(key); + + valuePtr.setString(0, value); + return ErrorCode.Success; + } + + @Override + public ErrorCode list(int handle, String keyPrefix, Pointer valuesJsonPtr) { + + WalletInmem wallet = this.walletsByHandle.get(handle); + if (wallet == null) return ErrorCode.CommonInvalidState; + + StringBuilder builder = new StringBuilder(); + builder.append("["); + + for (Iterator> iterator = wallet.values.entrySet().iterator(); iterator.hasNext(); ) { + + Map.Entry entry = iterator.next(); + String key = entry.getKey(); + String value = entry.getValue(); + if (key.startsWith(keyPrefix)) continue; + builder.append("\"" + escapeJson(value.toString()) + "\""); + if (iterator.hasNext()) builder.append(","); + } + + builder.append("]"); + + valuesJsonPtr.setString(0, builder.toString()); + return ErrorCode.Success; + } + + @Override + public ErrorCode close(int handle) { + + WalletInmem wallet = this.walletsByHandle.get(handle); + if (wallet == null) return ErrorCode.CommonInvalidState; + + wallet.open = false; + + return ErrorCode.Success; + } + + @Override + public ErrorCode delete(String name, String config, String credentials) { + + if (! this.walletsByName.containsKey(name)) return ErrorCode.CommonInvalidState; + + WalletInmem wallet = new WalletInmem(); + this.walletsByName.remove(name); + this.walletsByHandle.remove(wallet.handle); + + return ErrorCode.Success; + } + + @Override + public ErrorCode free(int walletHandle, String value) { + // TODO Auto-generated method stub + + return ErrorCode.Success; + } + + private static String escapeJson(String string) { + + return string.replace("\\", "\\\\").replace("\"", "\\\""); + } + + private AtomicInteger atomicInteger = new AtomicInteger(); + private Map walletsByName = new ConcurrentHashMap(); + private Map walletsByHandle = new ConcurrentHashMap(); + + private int newHandle() { + + return Integer.valueOf(atomicInteger.incrementAndGet()); + } + + private class WalletInmem { + + private int handle; + private boolean open; + private Map values; + + private WalletInmem() { + + this.handle = WalletTypeInmem.this.newHandle(); + this.open = false; + this.values = new HashMap<>(); + } + } +} diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeMemory.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeMemory.java deleted file mode 100644 index 82fbb5245c..0000000000 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeMemory.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.hyperledger.indy.sdk.wallet; - -import com.sun.jna.Pointer; - -public class WalletTypeMemory extends WalletType { - - private static WalletTypeMemory instance; - - public static WalletTypeMemory getInstance() { - - if (instance == null) instance = new WalletTypeMemory(); - return instance; - } - - private WalletTypeMemory() { - - } - - @Override - public void create(String name, String config, String credentials) { - // TODO Auto-generated method stub - - } - - @Override - public void open(String name, String config, String runtimeConfig, String credentials, Pointer handle) { - // TODO Auto-generated method stub - - } - - @Override - public void set(int handle, String key, String value) { - // TODO Auto-generated method stub - - } - - @Override - public void get(int handle, String key, Pointer valuePtr) { - // TODO Auto-generated method stub - - } - - @Override - public void getNotExpired(int handle, String key, Pointer valuePtr) { - // TODO Auto-generated method stub - - } - - @Override - public void list(int handle, String keyPrefix, Pointer valuesJsonPtr) { - // TODO Auto-generated method stub - - } - - @Override - public void close(int handle) { - // TODO Auto-generated method stub - - } - - @Override - public void delete(String name, String config, String credentials) { - // TODO Auto-generated method stub - - } - - @Override - public void free(int WalletHandle, String value) { - // TODO Auto-generated method stub - - } - -} diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/RegisterWalletTypeTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/RegisterWalletTypeTest.java new file mode 100644 index 0000000000..191c0b554d --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/RegisterWalletTypeTest.java @@ -0,0 +1,34 @@ +package org.hyperledger.indy.sdk.wallet; + +import static org.junit.Assert.assertNotNull; + +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusJSONParameters.CreateAndStoreMyDidJSONParameter; +import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; +import org.junit.Test; + + +public class RegisterWalletTypeTest extends IndyIntegrationTest { + + @Test + public void testRegisterWalletTypeWorks() throws Exception { + + Wallet.registerWalletType("inmem", WalletTypeInmem.getInstance()); + + Wallet.createWallet("default", "registerWalletTypeWorks", "inmem", null, null).get(); + + Wallet wallet = Wallet.openWallet("registerWalletTypeWorks", null, null).get(); + assertNotNull(wallet); + + CreateAndStoreMyDidJSONParameter createAndStoreMyDidJSONParameter = new CreateAndStoreMyDidJSONParameter(null, null, null, null); + CreateAndStoreMyDidResult createAndStoreMyDidResult = Signus.createAndStoreMyDid(wallet, createAndStoreMyDidJSONParameter.toJson()).get(); + String did = createAndStoreMyDidResult.getDid(); + +/* String nymRequest = Ledger.buildGetNymRequest(did, did).get(); + String signature = Signus.sign(wallet, did, nymRequest).get(); + Signus.verifySignature(wallet, null, did, signature);*/ + + wallet.closeWallet().get(); + } +} From 46a21f8d1d8654402a350b045d2a87084fbe95a0 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Fri, 21 Jul 2017 14:46:42 +0300 Subject: [PATCH 287/349] * Regression fixes * Added test_agent_listen --- wrappers/python/indy/ledger.py | 59 +++++----- wrappers/python/indy/pool.py | 21 ++-- wrappers/python/indy/signus.py | 8 +- .../python/tests/agent/test_agent_connect.py | 33 +++--- .../python/tests/agent/test_agent_listen.py | 59 ++++++++++ .../tests/ledger/test_build_attrib_request.py | 2 +- .../tests/ledger/test_build_claim_def_txn.py | 6 +- .../ledger/test_build_get_attrib_request.py | 2 +- .../ledger/test_build_get_claim_def_txn.py | 6 +- .../ledger/test_build_get_nym_request.py | 2 +- .../ledger/test_build_get_schema_request.py | 2 +- .../ledger/test_build_get_txn_request.py | 2 +- .../tests/ledger/test_build_node_request.py | 2 +- .../tests/ledger/test_build_nym_request.py | 2 +- .../tests/ledger/test_build_schema_request.py | 2 +- .../ledger/test_sign_and_submit_request.py | 10 +- .../tests/ledger/test_submit_request.py | 102 +++++++++--------- .../python/tests/signus/test_replace_keys.py | 2 +- wrappers/python/tests/signus/test_sign.py | 2 +- .../tests/signus/test_verify_signature.py | 9 +- 20 files changed, 203 insertions(+), 130 deletions(-) create mode 100644 wrappers/python/tests/agent/test_agent_listen.py diff --git a/wrappers/python/indy/ledger.py b/wrappers/python/indy/ledger.py index 2cc7d3b7ec..971b267ec3 100644 --- a/wrappers/python/indy/ledger.py +++ b/wrappers/python/indy/ledger.py @@ -5,6 +5,7 @@ import logging + async def sign_and_submit_request(pool_handle: int, wallet_handle: int, submitter_did: str, @@ -26,11 +27,11 @@ async def sign_and_submit_request(pool_handle: int, c_request_json = c_char_p(request_json.encode('utf-8')) res = await do_call('indy_sign_and_submit_request', - sign_and_submit_request.cb, c_pool_handle, c_wallet_handle, c_submitter_did, - c_request_json) + c_request_json, + sign_and_submit_request.cb) logger.debug("sign_and_submit_request: <<< res: %s", res) return res @@ -51,9 +52,9 @@ async def submit_request(pool_handle: int, c_request_json = c_char_p(request_json.encode('utf-8')) res = await do_call('indy_submit_request', - submit_request.cb, c_pool_handle, - c_request_json) + c_request_json, + submit_request.cb) logger.debug("submit_request: <<< res: %s", res) return res @@ -74,9 +75,9 @@ async def build_get_ddo_request(submitter_did: str, c_target_did = c_char_p(target_did.encode('utf-8')) res = await do_call('indy_build_get_ddo_request', - build_get_ddo_request.cb, c_submitter_did, - c_target_did) + c_target_did, + build_get_ddo_request.cb) logger.debug("build_get_ddo_request: <<< res: %s", res) return res @@ -106,12 +107,12 @@ async def build_nym_request(submitter_did: str, c_role = c_char_p(role.encode('utf-8')) if role is not None else None res = await do_call('indy_build_nym_request', - build_nym_request.cb, c_submitter_did, c_target_did, c_ver_key, c_alias, - c_role) + c_role, + build_nym_request.cb) logger.debug("build_nym_request: <<< res: %s", res) return res @@ -119,14 +120,14 @@ async def build_nym_request(submitter_did: str, async def build_attrib_request(submitter_did: str, target_did: str, - hash: Optional[str], + xhash: Optional[str], raw: Optional[str], enc: Optional[str]) -> str: logger = logging.getLogger(__name__) logger.debug("build_attrib_request: >>> submitter_did: %s, target_did: %s, hash: %s, raw: %s, enc: %s", submitter_did, target_did, - hash, + xhash, raw, enc) @@ -136,17 +137,17 @@ async def build_attrib_request(submitter_did: str, c_submitter_did = c_char_p(submitter_did.encode('utf-8')) c_target_did = c_char_p(target_did.encode('utf-8')) - c_hash = c_char_p(hash.encode('utf-8')) if hash is not None else None + c_hash = c_char_p(xhash.encode('utf-8')) if xhash is not None else None c_raw = c_char_p(raw.encode('utf-8')) if raw is not None else None c_enc = c_char_p(enc.encode('utf-8')) if enc is not None else None res = await do_call('indy_build_attrib_request', - build_attrib_request.cb, c_submitter_did, c_target_did, c_hash, c_raw, - c_enc) + c_enc, + build_attrib_request.cb) logger.debug("build_attrib_request: <<< res: %s", res) return res @@ -170,10 +171,10 @@ async def build_get_attrib_request(submitter_did: str, c_data = c_char_p(data.encode('utf-8')) res = await do_call('indy_build_get_attrib_request', - build_get_attrib_request.cb, c_submitter_did, c_target_did, - c_data) + c_data, + build_get_attrib_request.cb) logger.debug("build_get_attrib_request: <<< res: %s", res) return res @@ -194,9 +195,9 @@ async def build_get_nym_request(submitter_did: str, c_target_did = c_char_p(target_did.encode('utf-8')) res = await do_call('indy_build_get_nym_request', - build_get_nym_request.cb, c_submitter_did, - c_target_did) + c_target_did, + build_get_nym_request.cb) logger.debug("build_get_nym_request: <<< res: %s", res) return res @@ -217,9 +218,9 @@ async def build_schema_request(submitter_did: str, c_data = c_char_p(data.encode('utf-8')) res = await do_call('indy_build_schema_request', - build_schema_request.cb, c_submitter_did, - c_data) + c_data, + build_schema_request.cb) logger.debug("build_schema_request: <<< res: %s", res) return res @@ -243,10 +244,10 @@ async def build_get_schema_request(submitter_did: str, c_data = c_char_p(data.encode('utf-8')) res = await do_call('indy_build_get_schema_request', - build_get_schema_request.cb, c_submitter_did, c_dest, - c_data) + c_data, + build_get_schema_request.cb) logger.debug("build_get_schema_request: <<< res: %s", res) return res @@ -273,11 +274,11 @@ async def build_claim_def_txn(submitter_did: str, c_data = c_char_p(data.encode('utf-8')) res = await do_call('indy_build_claim_def_txn', - build_claim_def_txn.cb, c_submitter_did, c_xref, c_signature_type, - c_data) + c_data, + build_claim_def_txn.cb) logger.debug("build_claim_def_txn: <<< res: %s", res) return res @@ -304,11 +305,11 @@ async def build_get_claim_def_txn(submitter_did: str, c_origin = c_char_p(origin.encode('utf-8')) res = await do_call('indy_build_get_claim_def_txn', - build_get_claim_def_txn.cb, c_submitter_did, c_xref, c_signature_type, - c_origin) + c_origin, + build_get_claim_def_txn.cb) logger.debug("build_get_claim_def_txn: <<< res: %s", res) return res @@ -332,10 +333,10 @@ async def build_node_request(submitter_did: str, c_data = c_char_p(data.encode('utf-8')) res = await do_call('indy_build_node_request', - build_node_request.cb, c_submitter_did, c_target_did, - c_data) + c_data, + build_node_request.cb) logger.debug("build_node_request: <<< res: %s", res) return res @@ -356,9 +357,9 @@ async def build_get_txn_request(submitter_did: str, c_data = c_int32(data) res = await do_call('indy_build_get_txn_request', - build_get_txn_request.cb, c_submitter_did, - c_data) + c_data, + build_get_txn_request.cb) logger.debug("build_get_txn_request: <<< res: %s", res) return res diff --git a/wrappers/python/indy/pool.py b/wrappers/python/indy/pool.py index 40e3d33536..12e7dd80a6 100644 --- a/wrappers/python/indy/pool.py +++ b/wrappers/python/indy/pool.py @@ -5,6 +5,7 @@ import logging + async def create_pool_ledger_config(config_name: str, config: Optional[str]) -> None: logger = logging.getLogger(__name__) @@ -20,9 +21,9 @@ async def create_pool_ledger_config(config_name: str, c_config = c_char_p(config.encode('utf-8')) if config is not None else None res = await do_call('indy_create_pool_ledger_config', - create_pool_ledger_config.cb, c_config_name, - c_config) + c_config, + create_pool_ledger_config.cb) logger.debug("create_pool_ledger_config: <<< res: %s", res) return res @@ -43,9 +44,9 @@ async def open_pool_ledger(config_name: str, c_config = c_char_p(config.encode('utf-8')) if config is not None else None res = await do_call('indy_open_pool_ledger', - open_pool_ledger.cb, c_config_name, - c_config) + c_config, + open_pool_ledger.cb) logger.debug("open_pool_ledger: <<< res: %s", res) return res @@ -63,8 +64,8 @@ async def refresh_pool_ledger(handle: int) -> None: c_handle = c_int32(handle) res = await do_call('indy_refresh_pool_ledger', - refresh_pool_ledger.cb, - c_handle) + c_handle, + refresh_pool_ledger.cb) logger.debug("refresh_pool_ledger: <<< res: %s", res) return res @@ -82,8 +83,8 @@ async def close_pool_ledger(handle: int) -> None: c_handle = c_int32(handle) res = await do_call('indy_close_pool_ledger', - close_pool_ledger.cb, - c_handle) + c_handle, + close_pool_ledger.cb) logger.debug("close_pool_ledger: <<< res: %s", res) return res @@ -101,8 +102,8 @@ async def delete_pool_ledger_config(config_name: str) -> None: c_config_name = c_char_p(config_name.encode('utf-8')) res = await do_call('indy_delete_pool_ledger_config', - delete_pool_ledger_config.cb, - c_config_name) + c_config_name, + delete_pool_ledger_config.cb) logger.debug("delete_pool_ledger_config: <<< res: %s", res) return res diff --git a/wrappers/python/indy/signus.py b/wrappers/python/indy/signus.py index d375dac9d0..d897c9585e 100644 --- a/wrappers/python/indy/signus.py +++ b/wrappers/python/indy/signus.py @@ -4,6 +4,7 @@ import logging + async def create_and_store_my_did(wallet_handle: int, did_json: str) -> (str, str, str): logger = logging.getLogger(__name__) @@ -19,15 +20,16 @@ async def create_and_store_my_did(wallet_handle: int, c_did_json = c_char_p(did_json.encode('utf-8')) did, verkey, pk = await do_call('indy_create_and_store_my_did', - c_wallet_handle, - c_did_json, - create_and_store_my_did.cb) + c_wallet_handle, + c_did_json, + create_and_store_my_did.cb) res = (did.decode(), verkey.decode(), pk.decode()) logger.debug("create_and_store_my_did: <<< res: %s", res) return res + async def replace_keys(wallet_handle: int, did: str, identity_json: str) -> (str, str): diff --git a/wrappers/python/tests/agent/test_agent_connect.py b/wrappers/python/tests/agent/test_agent_connect.py index ded27c2a96..d0c61d83f7 100644 --- a/wrappers/python/tests/agent/test_agent_connect.py +++ b/wrappers/python/tests/agent/test_agent_connect.py @@ -8,32 +8,36 @@ logging.basicConfig(level=logging.DEBUG) +endpoint = "127.0.0.1:9701" -@pytest.fixture(autouse=True) + +@pytest.fixture def cleanup_storage(): storage.cleanup() yield storage.cleanup() +# noinspection PyUnusedLocal @pytest.fixture -async def wallet_handle(): - handle = await wallet.create_and_open_wallet() - yield handle - await wallet.close_wallet(handle) - - -@pytest.mark.asyncio -async def test_agent_connect_works(wallet_handle): - endpoint = "127.0.0.1:9701" +async def wallet_with_identities(cleanup_storage): + wallet_handle = await wallet.create_and_open_wallet() did, verkey, pk = await signus.create_and_store_my_did(wallet_handle, "{}") - await signus.store_their_did(wallet_handle, json.dumps({ "did": did, "verkey": verkey, "pk": pk, "endpoint": endpoint})) + yield wallet_handle, did + + await wallet.close_wallet(wallet_handle) + + +@pytest.mark.asyncio +async def test_agent_connect_works(wallet_with_identities): + wallet_handle, did = wallet_with_identities + listener_handle = await agent.agent_listen(endpoint) assert listener_handle is not None @@ -42,9 +46,14 @@ async def test_agent_connect_works(wallet_handle): connection_handle = await agent.agent_connect(0, wallet_handle, did, did) assert connection_handle is not None - event = await agent.agent_wait_for_event([listener_handle, connection_handle]) + event = await agent.agent_wait_for_event([listener_handle, connection_handle]) # type: agent.ConnectionEvent assert type(event) is agent.ConnectionEvent assert event.handle == listener_handle assert event.sender_did == did assert event.receiver_did == did + assert event.connection_handle is not None + + await agent.agent_close_connection(event.connection_handle) + await agent.agent_close_connection(connection_handle) + await agent.agent_close_listener(listener_handle) diff --git a/wrappers/python/tests/agent/test_agent_listen.py b/wrappers/python/tests/agent/test_agent_listen.py new file mode 100644 index 0000000000..157183c57b --- /dev/null +++ b/wrappers/python/tests/agent/test_agent_listen.py @@ -0,0 +1,59 @@ +import json +import logging + +import pytest + +from indy import signus, agent +from ..utils import storage, wallet + +logging.basicConfig(level=logging.DEBUG) + +endpoint = "127.0.0.1:9701" + + +@pytest.fixture(autouse=True) +def cleanup_storage(): + storage.cleanup() + yield + storage.cleanup() + + +# noinspection PyUnusedLocal +@pytest.fixture +async def wallet_with_identities(cleanup_storage): + wallet_handle = await wallet.create_and_open_wallet() + did, verkey, pk = await signus.create_and_store_my_did(wallet_handle, "{}") + await signus.store_their_did(wallet_handle, json.dumps({ + "did": did, + "verkey": verkey, + "pk": pk, + "endpoint": endpoint})) + + yield wallet_handle, did + + await wallet.close_wallet(wallet_handle) + + +@pytest.mark.asyncio +async def test_agent_listen_works(wallet_with_identities): + wallet_handle, did = wallet_with_identities + + listener_handle = await agent.agent_listen(endpoint) + assert listener_handle is not None + + await agent.agent_add_identity(listener_handle, -1, wallet_handle, did) + + connection_handle = await agent.agent_connect(0, wallet_handle, did, did) + assert connection_handle is not None + + event = await agent.agent_wait_for_event([listener_handle, connection_handle]) # type: agent.ConnectionEvent + + assert type(event) is agent.ConnectionEvent + assert event.handle == listener_handle + assert event.sender_did == did + assert event.receiver_did == did + assert event.connection_handle is not None + + await agent.agent_close_connection(event.connection_handle) + await agent.agent_close_connection(connection_handle) + await agent.agent_close_listener(listener_handle) diff --git a/wrappers/python/tests/ledger/test_build_attrib_request.py b/wrappers/python/tests/ledger/test_build_attrib_request.py index 4f266e9e24..a02c24d230 100644 --- a/wrappers/python/tests/ledger/test_build_attrib_request.py +++ b/wrappers/python/tests/ledger/test_build_attrib_request.py @@ -31,7 +31,7 @@ async def test_build_attrib_request_works_for_raw_data(): } } - response = json.loads((await ledger.build_attrib_request(identifier, destination, None, raw, None)).decode()) + response = json.loads(await ledger.build_attrib_request(identifier, destination, None, raw, None)) assert expected_response.items() <= response.items() diff --git a/wrappers/python/tests/ledger/test_build_claim_def_txn.py b/wrappers/python/tests/ledger/test_build_claim_def_txn.py index 3c0555caa6..81d3642267 100644 --- a/wrappers/python/tests/ledger/test_build_claim_def_txn.py +++ b/wrappers/python/tests/ledger/test_build_claim_def_txn.py @@ -41,7 +41,7 @@ async def test_build_claim_def_request_works_for_correct_data_json(): "type": "102", "signature_type": "CL"}} - response = json.loads((await ledger.build_claim_def_txn( - identifier, schema_seq_no, signature_type, json.dumps(data) - )).decode()) + response = json.loads( + await ledger.build_claim_def_txn( + identifier, schema_seq_no, signature_type, json.dumps(data))) assert expected_response.items() <= response.items() diff --git a/wrappers/python/tests/ledger/test_build_get_attrib_request.py b/wrappers/python/tests/ledger/test_build_get_attrib_request.py index 2e3d038ed0..450a5d6105 100644 --- a/wrappers/python/tests/ledger/test_build_get_attrib_request.py +++ b/wrappers/python/tests/ledger/test_build_get_attrib_request.py @@ -30,5 +30,5 @@ async def test_build_get_attrib_request_works(): } } - response = json.loads((await ledger.build_get_attrib_request(identifier, destination, raw)).decode()) + response = json.loads(await ledger.build_get_attrib_request(identifier, destination, raw)) assert expected_response.items() <= response.items() diff --git a/wrappers/python/tests/ledger/test_build_get_claim_def_txn.py b/wrappers/python/tests/ledger/test_build_get_claim_def_txn.py index f6c547b60b..dd6de331af 100644 --- a/wrappers/python/tests/ledger/test_build_get_claim_def_txn.py +++ b/wrappers/python/tests/ledger/test_build_get_claim_def_txn.py @@ -66,7 +66,7 @@ async def test_build_claim_def_request_works_for_correct_data_json(): } } - response = json.loads((await ledger.build_claim_def_txn( - identifier, schema_seq_no, signature_type, json.dumps(data) - )).decode()) + response = json.loads( + await ledger.build_claim_def_txn( + identifier, schema_seq_no, signature_type, json.dumps(data))) assert expected_response.items() <= response.items() diff --git a/wrappers/python/tests/ledger/test_build_get_nym_request.py b/wrappers/python/tests/ledger/test_build_get_nym_request.py index 66e0c57617..bb102bedec 100644 --- a/wrappers/python/tests/ledger/test_build_get_nym_request.py +++ b/wrappers/python/tests/ledger/test_build_get_nym_request.py @@ -28,5 +28,5 @@ async def test_build_get_nym_request_works(): } } - response = json.loads((await ledger.build_get_nym_request(identifier, destination)).decode()) + response = json.loads(await ledger.build_get_nym_request(identifier, destination)) assert expected_response.items() <= response.items() diff --git a/wrappers/python/tests/ledger/test_build_get_schema_request.py b/wrappers/python/tests/ledger/test_build_get_schema_request.py index ce1addf24e..167985a6c6 100644 --- a/wrappers/python/tests/ledger/test_build_get_schema_request.py +++ b/wrappers/python/tests/ledger/test_build_get_schema_request.py @@ -32,5 +32,5 @@ async def test_build_get_schema_requests_works_for_correct_data_json(): } } - response = json.loads((await ledger.build_get_schema_request(identifier, identifier, data)).decode()) + response = json.loads(await ledger.build_get_schema_request(identifier, identifier, data)) assert expected_response.items() <= response.items() diff --git a/wrappers/python/tests/ledger/test_build_get_txn_request.py b/wrappers/python/tests/ledger/test_build_get_txn_request.py index 1b4f5e73c3..0ff71080b2 100644 --- a/wrappers/python/tests/ledger/test_build_get_txn_request.py +++ b/wrappers/python/tests/ledger/test_build_get_txn_request.py @@ -26,5 +26,5 @@ async def test_build_get_txn_request_works(): } } - response = json.loads((await ledger.build_get_txn_request(identifier, data)).decode()) + response = json.loads(await ledger.build_get_txn_request(identifier, data)) assert expected_response.items() <= response.items() diff --git a/wrappers/python/tests/ledger/test_build_node_request.py b/wrappers/python/tests/ledger/test_build_node_request.py index 6bc059639d..d0bb74e34c 100644 --- a/wrappers/python/tests/ledger/test_build_node_request.py +++ b/wrappers/python/tests/ledger/test_build_node_request.py @@ -57,5 +57,5 @@ async def test_build_node_request_works_for_correct_data_json(): } } - response = json.loads((await ledger.build_node_request(identifier, destination, json.dumps(data))).decode()) + response = json.loads(await ledger.build_node_request(identifier, destination, json.dumps(data))) assert expected_response.items() <= response.items() diff --git a/wrappers/python/tests/ledger/test_build_nym_request.py b/wrappers/python/tests/ledger/test_build_nym_request.py index bcc7fd3b98..c858e5e12f 100644 --- a/wrappers/python/tests/ledger/test_build_nym_request.py +++ b/wrappers/python/tests/ledger/test_build_nym_request.py @@ -65,5 +65,5 @@ async def test_build_nym_request_works_with_option_fields(): } } - response = json.loads((await ledger.build_nym_request(identifier, destination, ver_key, alias, role)).decode()) + response = json.loads(await ledger.build_nym_request(identifier, destination, ver_key, alias, role)) assert expected_response.items() <= response.items() diff --git a/wrappers/python/tests/ledger/test_build_schema_request.py b/wrappers/python/tests/ledger/test_build_schema_request.py index 4bee422dcf..f23f8886a2 100644 --- a/wrappers/python/tests/ledger/test_build_schema_request.py +++ b/wrappers/python/tests/ledger/test_build_schema_request.py @@ -27,5 +27,5 @@ async def test_build_schema_requests_works_for_correct_data_json(): } } - response = json.loads((await ledger.build_schema_request(identifier, data)).decode()) + response = json.loads(await ledger.build_schema_request(identifier, data)) assert expected_response.items() <= response.items() diff --git a/wrappers/python/tests/ledger/test_sign_and_submit_request.py b/wrappers/python/tests/ledger/test_sign_and_submit_request.py index 5a083744ad..4f40e3b4ed 100644 --- a/wrappers/python/tests/ledger/test_sign_and_submit_request.py +++ b/wrappers/python/tests/ledger/test_sign_and_submit_request.py @@ -35,8 +35,8 @@ async def test_sign_and_submit_request_works(wallet_handle, pool_handle): (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') - nym_request = await ledger.build_nym_request(trustee_did.decode(), my_did.decode(), None, None, None) - await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did.decode(), nym_request.decode()) + nym_request = await ledger.build_nym_request(trustee_did, my_did, None, None, None) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did.decode(), nym_request) @pytest.mark.asyncio @@ -49,7 +49,7 @@ async def test_sign_and_submit_request_works_for_invalid_pool_handle(wallet_hand try: await ledger.sign_and_submit_request(invalid_pool_handle, wallet_handle, trustee_did.decode(), - nym_request.decode()) + nym_request) raise Exception("Failed") except Exception as e: assert type(IndyError(ErrorCode.PoolLedgerInvalidPoolHandle)) == type(e) and \ @@ -66,7 +66,7 @@ async def test_sign_and_submit_request_works_for_invalid_wallet_handle(wallet_ha try: await ledger.sign_and_submit_request(pool_handle, invalid_wallet_handle, trustee_did.decode(), - nym_request.decode()) + nym_request) raise Exception("Failed") except Exception as e: assert type(IndyError(ErrorCode.WalletInvalidHandle)) == type(e) and \ @@ -83,7 +83,7 @@ async def test_sign_and_submit_request_works_for_incompatible_wallet_and_pool(po try: await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did.decode(), - nym_request.decode()) + nym_request) raise Exception("Failed") except Exception as e: assert type(IndyError(ErrorCode.WalletIncompatiblePoolError)) == type(e) and \ diff --git a/wrappers/python/tests/ledger/test_submit_request.py b/wrappers/python/tests/ledger/test_submit_request.py index 83920a2942..2ed4191847 100644 --- a/wrappers/python/tests/ledger/test_submit_request.py +++ b/wrappers/python/tests/ledger/test_submit_request.py @@ -55,7 +55,7 @@ async def test_submit_request_works(pool_handle): }, "op": "REPLY" } - response = json.loads((await ledger.submit_request(pool_handle, json.dumps(request))).decode()) + response = json.loads(await ledger.submit_request(pool_handle, json.dumps(request))) assert response == expected_response @@ -64,10 +64,10 @@ async def test_submit_request_works_for_invalid_pool_handle(pool_handle, wallet_ (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') - get_nym_request = await ledger.build_get_nym_request(my_did.decode(), my_did.decode()) + get_nym_request = await ledger.build_get_nym_request(my_did, my_did) invalid_pool_handle = pool_handle + 1 try: - await ledger.submit_request(invalid_pool_handle, get_nym_request.decode()) + await ledger.submit_request(invalid_pool_handle, get_nym_request) raise Exception("Failed") except Exception as e: assert type(IndyError(ErrorCode.PoolLedgerInvalidPoolHandle)) == type(e) and \ @@ -79,9 +79,9 @@ async def test_send_nym_request_works_without_signature(pool_handle, wallet_hand (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') - nym_request = await ledger.build_nym_request(my_did.decode(), my_did.decode(), None, None, None) + nym_request = await ledger.build_nym_request(my_did, my_did, None, None, None) try: - await ledger.submit_request(pool_handle, nym_request.decode()) + await ledger.submit_request(pool_handle, nym_request) raise Exception("Failed") except Exception as e: assert type(IndyError(ErrorCode.LedgerInvalidTransaction)) == type(e) and \ @@ -93,9 +93,9 @@ async def test_send_get_nym_request_works(pool_handle, wallet_handle): (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') - get_nym_request = await ledger.build_get_nym_request(my_did.decode(), my_did.decode()) + get_nym_request = await ledger.build_get_nym_request(my_did, my_did) - response = json.loads((await ledger.submit_request(pool_handle, get_nym_request.decode())).decode()) + response = json.loads(await ledger.submit_request(pool_handle, get_nym_request)) assert response['result']['data'] is not None @@ -106,10 +106,10 @@ async def test_nym_requests_works(pool_handle, wallet_handle): (my_did, my_ver_key, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') - nym_request = await ledger.build_nym_request(trustee_did.decode(), my_did.decode(), my_ver_key.decode(), None, None) - await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did.decode(), nym_request.decode()) - get_nym_request = await ledger.build_get_nym_request(my_did.decode(), my_did.decode()) - response = json.loads((await ledger.submit_request(pool_handle, get_nym_request.decode())).decode()) + nym_request = await ledger.build_nym_request(trustee_did, my_did, my_ver_key, None, None) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did, nym_request) + get_nym_request = await ledger.build_get_nym_request(my_did, my_did) + response = json.loads(await ledger.submit_request(pool_handle, get_nym_request)) assert response['result']['data'] is not None @@ -118,10 +118,10 @@ async def test_send_attrib_request_works_without_signature(pool_handle, wallet_h (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') - attrib_request = await ledger.build_attrib_request(my_did.decode(), my_did.decode(), None, + attrib_request = await ledger.build_attrib_request(my_did, my_did, None, "{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}", None) try: - await ledger.submit_request(pool_handle, attrib_request.decode()) + await ledger.submit_request(pool_handle, attrib_request) raise Exception("Failed") except Exception as e: assert type(IndyError(ErrorCode.LedgerInvalidTransaction)) == type(e) and \ @@ -134,13 +134,13 @@ async def test_attrib_requests_works(pool_handle, wallet_handle): '{"seed":"000000000000000000000000Trustee1"}') (my_did, my_ver_key, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') - nym_request = await ledger.build_nym_request(trustee_did.decode(), my_did.decode(), my_ver_key.decode(), None, None) - await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did.decode(), nym_request.decode()) - attrib_request = await ledger.build_attrib_request(my_did.decode(), my_did.decode(), None, + nym_request = await ledger.build_nym_request(trustee_did, my_did, my_ver_key, None, None) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did, nym_request) + attrib_request = await ledger.build_attrib_request(my_did, my_did, None, "{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}", None) - await ledger.sign_and_submit_request(pool_handle, wallet_handle, my_did.decode(), attrib_request.decode()) - get_attrib_request = await ledger.build_get_attrib_request(my_did.decode(), my_did.decode(), "endpoint") - response = json.loads((await ledger.submit_request(pool_handle, get_attrib_request.decode())).decode()) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, my_did, attrib_request) + get_attrib_request = await ledger.build_get_attrib_request(my_did, my_did, "endpoint") + response = json.loads(await ledger.submit_request(pool_handle, get_attrib_request)) assert response['result']['data'] is not None @@ -155,10 +155,10 @@ async def test_send_schema_request_works_without_signature(pool_handle, wallet_h "keys": ["name", "male"] } - schema_request = await ledger.build_schema_request(my_did.decode(), json.dumps(schema_data)) + schema_request = await ledger.build_schema_request(my_did, json.dumps(schema_data)) try: - await ledger.submit_request(pool_handle, schema_request.decode()) + await ledger.submit_request(pool_handle, schema_request) raise Exception("Failed") except Exception as e: assert type(IndyError(ErrorCode.LedgerInvalidTransaction)) == type(e) and \ @@ -178,16 +178,16 @@ async def test_schema_requests_works(pool_handle, wallet_handle): "keys": ["name", "male"] } - nym_request = await ledger.build_nym_request(trustee_did.decode(), my_did.decode(), my_ver_key.decode(), None, None) - await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did.decode(), nym_request.decode()) - schema_request = await ledger.build_schema_request(my_did.decode(), json.dumps(schema_data)) - await ledger.sign_and_submit_request(pool_handle, wallet_handle, my_did.decode(), schema_request.decode()) + nym_request = await ledger.build_nym_request(trustee_did, my_did, my_ver_key, None, None) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did, nym_request) + schema_request = await ledger.build_schema_request(my_did, json.dumps(schema_data)) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, my_did, schema_request) get_schema_data = { "name": "gvt2", "version": "2.0" } - get_schema_request = await ledger.build_get_schema_request(my_did.decode(), my_did.decode(), json.dumps(get_schema_data)) - response = json.loads((await ledger.submit_request(pool_handle, get_schema_request.decode())).decode()) + get_schema_request = await ledger.build_get_schema_request(my_did, my_did, json.dumps(get_schema_data)) + response = json.loads(await ledger.submit_request(pool_handle, get_schema_request)) assert response['result']['data'] is not None @@ -205,10 +205,10 @@ async def test_send_node_request_works_without_signature(pool_handle, wallet_han "services": ["VALIDATOR"] } - node_request = await ledger.build_node_request(my_did.decode(), my_did.decode(), json.dumps(node_data)) + node_request = await ledger.build_node_request(my_did, my_did, json.dumps(node_data)) try: - await ledger.submit_request(pool_handle, node_request.decode()) + await ledger.submit_request(pool_handle, node_request) raise Exception("Failed") except Exception as e: assert type(IndyError(ErrorCode.LedgerInvalidTransaction)) == type(e) and \ @@ -228,19 +228,19 @@ async def test_claim_def_requests_works(pool_handle, wallet_handle): "keys": ["name", "male"] } - nym_request = await ledger.build_nym_request(trustee_did.decode(), my_did.decode(), my_ver_key.decode(), None, None) - await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did.decode(), nym_request.decode()) + nym_request = await ledger.build_nym_request(trustee_did, my_did, my_ver_key, None, None) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did, nym_request) - schema_request = await ledger.build_schema_request(my_did.decode(), json.dumps(schema_data)) - await ledger.sign_and_submit_request(pool_handle, wallet_handle, my_did.decode(), schema_request.decode()) + schema_request = await ledger.build_schema_request(my_did, json.dumps(schema_data)) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, my_did, schema_request) get_schema_data = { "name": "gvt2", "version": "2.0" } - get_schema_request = await ledger.build_get_schema_request(my_did.decode(), my_did.decode(), json.dumps(get_schema_data)) - get_schema_response = json.loads((await ledger.submit_request(pool_handle, get_schema_request.decode())).decode()) + get_schema_request = await ledger.build_get_schema_request(my_did, my_did, json.dumps(get_schema_data)) + get_schema_response = json.loads(await ledger.submit_request(pool_handle, get_schema_request)) claim_def = { "primary": { @@ -260,13 +260,13 @@ async def test_claim_def_requests_works(pool_handle, wallet_handle): } claim_def_request = await ledger.build_claim_def_txn( - my_did.decode(), get_schema_response['result']['seqNo'], "CL", json.dumps(claim_def)) + my_did, get_schema_response['result']['seqNo'], "CL", json.dumps(claim_def)) - await ledger.sign_and_submit_request(pool_handle, wallet_handle, my_did.decode(), claim_def_request.decode()) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, my_did, claim_def_request) get_claim_def_request = await ledger.build_get_claim_def_txn( - my_did.decode(), get_schema_response['result']['seqNo'], "CL", get_schema_response['result']['data']['origin']) + my_did, get_schema_response['result']['seqNo'], "CL", get_schema_response['result']['data']['origin']) get_claim_def_response = json.loads( - (await ledger.submit_request(pool_handle, get_claim_def_request.decode())).decode()) + (await ledger.submit_request(pool_handle, get_claim_def_request))) assert claim_def == get_claim_def_response['result']['data'] @@ -281,20 +281,20 @@ async def test_get_txn_request_works(pool_handle, wallet_handle): "keys": ["name"] }) - schema_request = await ledger.build_schema_request(my_did.decode(), schema_data) - schema_response = json.loads((await ledger.sign_and_submit_request( - pool_handle, wallet_handle, my_did.decode(), schema_request.decode())).decode()) + schema_request = await ledger.build_schema_request(my_did, schema_data) + schema_response = json.loads(await ledger.sign_and_submit_request( + pool_handle, wallet_handle, my_did, schema_request)) get_schema_data = { "name": "gvt3", "version": "3.0" } get_schema_request = await ledger.build_get_schema_request( - my_did.decode(), my_did.decode(), json.dumps(get_schema_data)) - await ledger.submit_request(pool_handle, get_schema_request.decode()) + my_did, my_did, json.dumps(get_schema_data)) + await ledger.submit_request(pool_handle, get_schema_request) - get_txn_request = await ledger.build_get_txn_request(my_did.decode(), schema_response['result']['seqNo']) - get_txn_response = json.loads((await ledger.submit_request(pool_handle, get_txn_request.decode())).decode()) + get_txn_request = await ledger.build_get_txn_request(my_did, schema_response['result']['seqNo']) + get_txn_response = json.loads(await ledger.submit_request(pool_handle, get_txn_request)) assert schema_data == json.loads(get_txn_response['result']['data'])['data'] @@ -309,12 +309,12 @@ async def test_get_txn_request_works_for_invalid_seq_no(pool_handle, wallet_hand "keys": ["name"] }) - schema_request = await ledger.build_schema_request(my_did.decode(), schema_data) - schema_response = json.loads((await ledger.sign_and_submit_request( - pool_handle, wallet_handle, my_did.decode(), schema_request.decode())).decode()) + schema_request = await ledger.build_schema_request(my_did, schema_data) + schema_response = json.loads(await ledger.sign_and_submit_request( + pool_handle, wallet_handle, my_did, schema_request)) seq_no = schema_response['result']['seqNo'] + 1 - get_txn_request = await ledger.build_get_txn_request(my_did.decode(), seq_no) - get_txn_response = json.loads((await ledger.submit_request(pool_handle, get_txn_request.decode())).decode()) + get_txn_request = await ledger.build_get_txn_request(my_did, seq_no) + get_txn_response = json.loads(await ledger.submit_request(pool_handle, get_txn_request)) assert get_txn_response['result']['data'] == "{}" diff --git a/wrappers/python/tests/signus/test_replace_keys.py b/wrappers/python/tests/signus/test_replace_keys.py index 6e212398e4..a868425d73 100644 --- a/wrappers/python/tests/signus/test_replace_keys.py +++ b/wrappers/python/tests/signus/test_replace_keys.py @@ -26,5 +26,5 @@ async def wallet_handle(): @pytest.mark.asyncio async def test_replace_keys_works(wallet_handle): (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, "{}") - (new_did, new_ver_key) = await signus.replace_keys(wallet_handle, did.decode(), "{}") + (new_did, new_ver_key) = await signus.replace_keys(wallet_handle, did, "{}") assert (new_did != did) and (new_ver_key != ver_key) \ No newline at end of file diff --git a/wrappers/python/tests/signus/test_sign.py b/wrappers/python/tests/signus/test_sign.py index 99e7843282..432d2badca 100644 --- a/wrappers/python/tests/signus/test_sign.py +++ b/wrappers/python/tests/signus/test_sign.py @@ -40,5 +40,5 @@ async def test_sign_works(wallet_handle): expected_signature = "65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW" - result = json.loads((await signus.sign(wallet_handle, did.decode(), json.dumps(message))).decode()) + result = json.loads(await signus.sign(wallet_handle, did, json.dumps(message))) assert result['signature'] == expected_signature diff --git a/wrappers/python/tests/signus/test_verify_signature.py b/wrappers/python/tests/signus/test_verify_signature.py index dcb3b7f53b..e2b028caaa 100644 --- a/wrappers/python/tests/signus/test_verify_signature.py +++ b/wrappers/python/tests/signus/test_verify_signature.py @@ -27,10 +27,11 @@ async def wallet_handle(): @pytest.mark.asyncio async def test_verify_signature_works(wallet_handle): pool_handle = 1 - (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') + (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"000000000000000000000000Trustee1"}') identity_json = { - "did": did.decode(), - "verkey": ver_key.decode() + "did": did, + "verkey": ver_key } await signus.store_their_did(wallet_handle, json.dumps(identity_json)) @@ -46,5 +47,5 @@ async def test_verify_signature_works(wallet_handle): "signature": "65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW" } - valid = await signus.verify_signature(wallet_handle, pool_handle, did.decode(), json.dumps(message)) + valid = await signus.verify_signature(wallet_handle, pool_handle, did, json.dumps(message)) assert valid From 0a59a7b4d468d7dd07ed0a4c5939d1f949e02c2b Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 21 Jul 2017 15:13:07 +0300 Subject: [PATCH 288/349] try --- ci/java.dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/java.dockerfile b/ci/java.dockerfile index f3179e6196..ab75104456 100644 --- a/ci/java.dockerfile +++ b/ci/java.dockerfile @@ -18,4 +18,4 @@ RUN gdebi -n indy-sdk_0.1.1_amd64.deb RUN useradd -ms /bin/bash -u $uid indy USER indy -WORKDIR /home/indy/wrappers/java \ No newline at end of file +WORKDIR /home/indy \ No newline at end of file From 67296e7ee7484ae608529401638fe9310a2c822c Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 21 Jul 2017 15:28:44 +0300 Subject: [PATCH 289/349] Try --- ci/run-java-tests.sh | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100755 ci/run-java-tests.sh diff --git a/ci/run-java-tests.sh b/ci/run-java-tests.sh new file mode 100755 index 0000000000..98d556b767 --- /dev/null +++ b/ci/run-java-tests.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Use this script because we can not change directory after docker.inside { } +# https://issues.jenkins-ci.org/browse/JENKINS-35518 + +cd wrappers/java + +maven clean test From 80f369faf36484748f8526f2116032ddecb430a1 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 21 Jul 2017 15:30:41 +0300 Subject: [PATCH 290/349] fix --- ci/run-java-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/run-java-tests.sh b/ci/run-java-tests.sh index 98d556b767..a6abd0c592 100755 --- a/ci/run-java-tests.sh +++ b/ci/run-java-tests.sh @@ -5,4 +5,4 @@ cd wrappers/java -maven clean test +mvn clean test From d90cac67abaad361cfed400b0cb7c868f109dfb6 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 21 Jul 2017 15:39:28 +0300 Subject: [PATCH 291/349] Worked --- JenkinsfileJava | 91 ++++++++++++++++++++++++++++++++++++++++++++ ci/run-java-tests.sh | 8 ---- 2 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 JenkinsfileJava delete mode 100755 ci/run-java-tests.sh diff --git a/JenkinsfileJava b/JenkinsfileJava new file mode 100644 index 0000000000..5c6c73d84e --- /dev/null +++ b/JenkinsfileJava @@ -0,0 +1,91 @@ +#!groovy​ + +@Library('SovrinHelpers') _ + +name = 'indy-sdk' +def err +def publishBranch = (env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'devel') + +try { + +// ALL BRANCHES: master, devel, PRs + + // 1. TEST + stage('Test') { + parallel 'ubuntu-java-test': { + node('ubuntu') { + stage('Ubuntu Java Test') { + javaTestUbuntu() + } + } + } + } + +} catch (e) { + currentBuild.result = "FAILED" + node('ubuntu-master') { + sendNotification.fail([slack: publishBranch]) + } + err = e +} finally { + if (err) { + throw err + } + currentBuild.result = "SUCCESS" + if (publishBranch) { + node('ubuntu-master') { + sendNotification.success(name) + } + } +} + +def javaTestUbuntu() { + def poolInst + def network_name = "pool_network" + try { + echo 'Ubuntu Java Test: Checkout csm' + checkout scm + + echo "Ubuntu Java Test: Create docker network (${network_name}) for nodes pool and test image" + sh "docker network create --subnet=10.0.0.0/8 ${network_name}" + + echo 'Ubuntu Java Test: Build docker image for nodes pool' + def poolEnv = dockerHelpers.build('indy_pool', 'ci/indy-pool.dockerfile ci') + echo 'Ubuntu Java Test: Run nodes pool' + poolInst = poolEnv.run("--ip=\"10.0.0.2\" --network=${network_name}") + + echo 'Ubuntu Java Test: Build docker image' + def testEnv = dockerHelpers.build(name, 'ci/java.dockerfile ci') + + testEnv.inside("--ip=\"10.0.0.3\" --network=${network_name}") { + echo 'Ubuntu Java Test: Test' + + sh ''' + cd wrappers/java + mvn clean test + ''' + } + } + finally { + echo 'Ubuntu Java Test: Cleanup' + try { + sh "docker network inspect ${network_name}" + } catch (ignore) { + } + try { + if (poolInst) { + echo 'Ubuntu Java Test: stop pool' + poolInst.stop() + } + } catch (err) { + echo "Ubuntu Java Tests: error while stop pool ${err}" + } + try { + echo "Ubuntu Java Test: remove pool network ${network_name}" + sh "docker network rm ${network_name}" + } catch (err) { + echo "Ubuntu Java Test: error while delete ${network_name} - ${err}" + } + step([$class: 'WsCleanup']) + } +} \ No newline at end of file diff --git a/ci/run-java-tests.sh b/ci/run-java-tests.sh deleted file mode 100755 index a6abd0c592..0000000000 --- a/ci/run-java-tests.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -# Use this script because we can not change directory after docker.inside { } -# https://issues.jenkins-ci.org/browse/JENKINS-35518 - -cd wrappers/java - -mvn clean test From 34a273639f230d02ec4eb14f82da856deb3e1236 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 21 Jul 2017 15:54:32 +0300 Subject: [PATCH 292/349] Moved Jenkins file --- JenkinsfileJava => wrappers/java/Jenkinsfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename JenkinsfileJava => wrappers/java/Jenkinsfile (100%) diff --git a/JenkinsfileJava b/wrappers/java/Jenkinsfile similarity index 100% rename from JenkinsfileJava rename to wrappers/java/Jenkinsfile From 965522911f6dbc83bd61dc900da654a6b8a7fd89 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 21 Jul 2017 16:12:18 +0300 Subject: [PATCH 293/349] added prover_store_claim --- wrappers/python/indy/anoncreds.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/wrappers/python/indy/anoncreds.py b/wrappers/python/indy/anoncreds.py index b7baf12c9e..0edb18ebed 100644 --- a/wrappers/python/indy/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -405,7 +405,26 @@ async def prover_store_claim(wallet_handle: int, } :return: None. """ - pass + + logger = logging.getLogger(__name__) + logger.debug("prover_store_claim: >>> wallet_handle: %r, claims_json: %r", + wallet_handle, + claims_json) + + if not hasattr(prover_store_claim, "cb"): + logger.debug("prover_store_claim: Creating callback") + prover_store_claim.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) + + c_wallet_handle = c_int32(wallet_handle) + c_claims_json = c_char_p(claims_json.encode('utf-8')) + + res = await do_call('indy_prover_store_claim', + prover_store_claim.cb, + c_wallet_handle, + c_claims_json) + + logger.debug("prover_store_claim: <<< res: %r", res) + return res async def prover_get_claims(wallet_handle: int, From 9309f93c772266971db50eb84eb6dfbe5d503f69 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 21 Jul 2017 16:13:28 +0300 Subject: [PATCH 294/349] Try delete libsodium-devel from installing libraries --- ci/amazon.dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index bbf3f9e637..050457c383 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -6,15 +6,12 @@ RUN \ yum clean all \ && yum upgrade -y \ && yum groupinstall -y "Development Tools" \ - && yum install -y epel-release \ - && yum-config-manager --enable epel \ && yum install -y \ wget \ cmake \ pkgconfig \ openssl-devel \ sqlite-devel \ - libsodium-devel \ spectool From 89f4106b53c6e1467bd1567be46e5f765d38fc3e Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 21 Jul 2017 16:26:53 +0300 Subject: [PATCH 295/349] Try delete libzmq from docker.ubuntu --- ci/ubuntu.dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/ubuntu.dockerfile b/ci/ubuntu.dockerfile index 47694d8457..ac35d9ba22 100644 --- a/ci/ubuntu.dockerfile +++ b/ci/ubuntu.dockerfile @@ -5,7 +5,6 @@ ARG uid=1000 RUN apt-get update && \ apt-get install -y \ pkg-config \ - libzmq3-dev \ libssl-dev \ libgmp3-dev \ curl \ From 17d75a86f582bb99309d1c8fd8326c420d50ff63 Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Fri, 21 Jul 2017 15:26:38 +0200 Subject: [PATCH 296/349] =?UTF-8?q?[java]=C2=A0allocate=20and=20free=20mem?= =?UTF-8?q?ory=20for=20wrapper=20of=20indy=5Fregister=5Fwallet=5Ftype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../indy/sdk/wallet/WalletType.java | 17 +++---- .../indy/sdk/wallet/WalletTypeInmem.java | 44 ++++++++++++------- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletType.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletType.java index 3de7e9b7fd..c619f67a48 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletType.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletType.java @@ -4,6 +4,7 @@ import com.sun.jna.Callback; import com.sun.jna.Pointer; +import com.sun.jna.ptr.PointerByReference; public abstract class WalletType { @@ -37,7 +38,7 @@ public int callback(int handle, String key, String value) { private Callback getCb = new Callback() { @SuppressWarnings("unused") - public int callback(int handle, String key, Pointer value_ptr) { + public int callback(int handle, String key, PointerByReference value_ptr) { return WalletType.this.get(handle, key, value_ptr).ordinal(); } @@ -46,7 +47,7 @@ public int callback(int handle, String key, Pointer value_ptr) { private Callback getNotExpiredCb = new Callback() { @SuppressWarnings("unused") - public int callback(int handle, String key, Pointer value_ptr) { + public int callback(int handle, String key, PointerByReference value_ptr) { return WalletType.this.getNotExpired(handle, key, value_ptr).ordinal(); } @@ -55,7 +56,7 @@ public int callback(int handle, String key, Pointer value_ptr) { private Callback listCb = new Callback() { @SuppressWarnings("unused") - public int callback(int handle, String key_prefix, Pointer values_json_ptr) { + public int callback(int handle, String key_prefix, PointerByReference values_json_ptr) { return WalletType.this.list(handle, key_prefix, values_json_ptr).ordinal(); } @@ -82,7 +83,7 @@ public int callback(String name, String config, String credentials) { private Callback freeCb = new Callback() { @SuppressWarnings("unused") - public int callback(int wallet_handle, String value) { + public int callback(int wallet_handle, Pointer value) { return WalletType.this.free(wallet_handle, value).ordinal(); } @@ -91,12 +92,12 @@ public int callback(int wallet_handle, String value) { public abstract ErrorCode create(String name, String config, String credentials); public abstract ErrorCode open(String name, String config, String runtimeConfig, String credentials, Pointer handle); public abstract ErrorCode set(int handle, String key, String value); - public abstract ErrorCode get(int handle, String key, Pointer valuePtr); - public abstract ErrorCode getNotExpired(int handle, String key, Pointer valuePtr); - public abstract ErrorCode list(int handle, String keyPrefx, Pointer valuesJsonPtr); + public abstract ErrorCode get(int handle, String key, PointerByReference valuePtr); + public abstract ErrorCode getNotExpired(int handle, String key, PointerByReference valuePtr); + public abstract ErrorCode list(int handle, String keyPrefx, PointerByReference valuesJsonPtr); public abstract ErrorCode close(int handle); public abstract ErrorCode delete(String name, String config, String credentials); - public abstract ErrorCode free(int walletHandle, String value); + public abstract ErrorCode free(int walletHandle, Pointer value); public Callback getCreateCb() { return createCb; diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeInmem.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeInmem.java index c83870286d..af03946030 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeInmem.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeInmem.java @@ -8,7 +8,10 @@ import org.hyperledger.indy.sdk.ErrorCode; +import com.sun.jna.Memory; +import com.sun.jna.Native; import com.sun.jna.Pointer; +import com.sun.jna.ptr.PointerByReference; public class WalletTypeInmem extends WalletType { @@ -53,42 +56,46 @@ public ErrorCode set(int handle, String key, String value) { WalletInmem wallet = this.walletsByHandle.get(handle); if (wallet == null) return ErrorCode.CommonInvalidState; - + wallet.values.put(key, value); - - System.out.println("SET " + key + " --> " + value); - + return ErrorCode.Success; } @Override - public ErrorCode get(int handle, String key, Pointer valuePtr) { + public ErrorCode get(int handle, String key, PointerByReference valuePtr) { WalletInmem wallet = this.walletsByHandle.get(handle); if (wallet == null) return ErrorCode.CommonInvalidState; String value = wallet.values.get(key); - System.out.println("GET " + key + " --> " + value); - - valuePtr.setString(0, value); + byte[] bytes = Native.toByteArray(value); + Pointer pointer = new Memory(bytes.length + 1); + pointer.write(0, bytes, 0, bytes.length); + pointer.setByte(bytes.length, (byte)0); + valuePtr.setPointer(pointer); return ErrorCode.Success; } @Override - public ErrorCode getNotExpired(int handle, String key, Pointer valuePtr) { + public ErrorCode getNotExpired(int handle, String key, PointerByReference valuePtr) { WalletInmem wallet = this.walletsByHandle.get(handle); if (wallet == null) return ErrorCode.CommonInvalidState; String value = wallet.values.get(key); - valuePtr.setString(0, value); + byte[] bytes = Native.toByteArray(value); + Pointer pointer = new Memory(bytes.length + 1); + pointer.write(0, bytes, 0, bytes.length); + pointer.setByte(bytes.length, (byte)0); + valuePtr.setPointer(pointer); return ErrorCode.Success; } @Override - public ErrorCode list(int handle, String keyPrefix, Pointer valuesJsonPtr) { + public ErrorCode list(int handle, String keyPrefix, PointerByReference valuesJsonPtr) { WalletInmem wallet = this.walletsByHandle.get(handle); if (wallet == null) return ErrorCode.CommonInvalidState; @@ -97,7 +104,7 @@ public ErrorCode list(int handle, String keyPrefix, Pointer valuesJsonPtr) { builder.append("["); for (Iterator> iterator = wallet.values.entrySet().iterator(); iterator.hasNext(); ) { - + Map.Entry entry = iterator.next(); String key = entry.getKey(); String value = entry.getValue(); @@ -108,7 +115,11 @@ public ErrorCode list(int handle, String keyPrefix, Pointer valuesJsonPtr) { builder.append("]"); - valuesJsonPtr.setString(0, builder.toString()); + byte[] bytes = Native.toByteArray(builder.toString()); + Pointer pointer = new Memory(bytes.length + 1); + pointer.write(0, bytes, 0, bytes.length); + pointer.setByte(bytes.length, (byte)0); + valuesJsonPtr.setPointer(pointer); return ErrorCode.Success; } @@ -119,7 +130,7 @@ public ErrorCode close(int handle) { if (wallet == null) return ErrorCode.CommonInvalidState; wallet.open = false; - + return ErrorCode.Success; } @@ -136,8 +147,9 @@ public ErrorCode delete(String name, String config, String credentials) { } @Override - public ErrorCode free(int walletHandle, String value) { - // TODO Auto-generated method stub + public ErrorCode free(int walletHandle, Pointer value) { + + Native.free(Pointer.nativeValue(value)); return ErrorCode.Success; } From be3f05f8a57e6a6dbfed918b4f5e9bf186f62a83 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Fri, 21 Jul 2017 16:36:22 +0300 Subject: [PATCH 297/349] Deleted zmq from documentation for ubuntu and redhat --- doc/rhel-build.md | 11 ----------- doc/ubuntu-build.md | 1 - 2 files changed, 12 deletions(-) diff --git a/doc/rhel-build.md b/doc/rhel-build.md index efc107c0a5..15191ca7ea 100644 --- a/doc/rhel-build.md +++ b/doc/rhel-build.md @@ -28,18 +28,7 @@ export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib ``` -1. Build and install modern version of libzmq from sources: - ``` - cd /tmp - wget https://github.com/zeromq/libzmq/releases/download/v4.2.2/zeromq-4.2.2.tar.gz - tar xfz zeromq-4.2.2.tar.gz && rm zeromq-4.2.2.tar.gz - cd /tmp/zeromq-4.2.2 - ./configure - make - make install - rm -rf /tmp/zeromq-4.2.2 - ``` 1. Checkout and build the library: ``` diff --git a/doc/ubuntu-build.md b/doc/ubuntu-build.md index 20acad131b..e5562dccdc 100644 --- a/doc/ubuntu-build.md +++ b/doc/ubuntu-build.md @@ -9,7 +9,6 @@ build-essential \ pkg-config \ cmake \ - libzmq3-dev \ libssl-dev \ libsqlite3-dev \ libsodium-dev From d23106124c93c01201ec2cd59280a04eb26553f6 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 21 Jul 2017 16:39:49 +0300 Subject: [PATCH 298/349] added prover get_claims --- wrappers/python/indy/anoncreds.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/wrappers/python/indy/anoncreds.py b/wrappers/python/indy/anoncreds.py index 0edb18ebed..9f679b5c61 100644 --- a/wrappers/python/indy/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -449,7 +449,27 @@ async def prover_get_claims(wallet_handle: int, "revoc_reg_seq_no": string, }] """ - pass + + logger = logging.getLogger(__name__) + logger.debug("prover_get_claims: >>> wallet_handle: %r, filter_json: %r", + wallet_handle, + filter_json) + + if not hasattr(prover_get_claims, "cb"): + logger.debug("prover_get_claims: Creating callback") + prover_get_claims.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_wallet_handle = c_int32(wallet_handle) + c_filter_json = c_char_p(filter_json.encode('utf-8')) + + claims_json = await do_call('indy_prover_get_claims', + prover_get_claims.cb, + c_wallet_handle, + c_filter_json) + + res = claims_json.decode() + logger.debug("prover_get_claims: <<< res: %r", res) + return res async def prover_get_claims_for_proof_req(wallet_handle: int, From 8e748635c543b8535f2b47c900f7d63002eb25d7 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 21 Jul 2017 16:51:24 +0300 Subject: [PATCH 299/349] added get_claims_for_proof_request --- wrappers/python/indy/anoncreds.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/wrappers/python/indy/anoncreds.py b/wrappers/python/indy/anoncreds.py index 9f679b5c61..c4aa07ca4f 100644 --- a/wrappers/python/indy/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -506,7 +506,27 @@ async def prover_get_claims_for_proof_req(wallet_handle: int, "revoc_reg_seq_no": string, } """ - pass + + logger = logging.getLogger(__name__) + logger.debug("prover_get_claims_for_proof_req: >>> wallet_handle: %r, proof_request_json: %r", + wallet_handle, + proof_request_json) + + if not hasattr(prover_get_claims, "cb"): + logger.debug("prover_get_claims_for_proof_req: Creating callback") + prover_get_claims_for_proof_req.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_wallet_handle = c_int32(wallet_handle) + c_proof_request_json = c_char_p(proof_request_json.encode('utf-8')) + + claims_json = await do_call('indy_prover_get_claims_for_proof_req', + prover_get_claims_for_proof_req.cb, + c_wallet_handle, + c_proof_request_json) + + res = claims_json.decode() + logger.debug("prover_get_claims_for_proof_req: <<< res: %r", res) + return res async def prover_create_proof(wallet_handle: int, From 61659d9e1332c7ff6aebb133ad08ac3a47b649ab Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 21 Jul 2017 16:58:30 +0300 Subject: [PATCH 300/349] added create_proof --- wrappers/python/indy/anoncreds.py | 39 ++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/wrappers/python/indy/anoncreds.py b/wrappers/python/indy/anoncreds.py index c4aa07ca4f..8b146a2346 100644 --- a/wrappers/python/indy/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -606,7 +606,44 @@ async def prover_create_proof(wallet_handle: int, "aggregated_proof": } """ - pass + + logger = logging.getLogger(__name__) + logger.debug("prover_create_proof: >>> wallet_handle: %r, proof_req_json: %r," + " requested_claims_json: %r, schemas_json: %r, master_secret_name: %r," + " claim_defs_json: %r, revoc_regs_json: %r", + wallet_handle, + proof_req_json, + requested_claims_json, + schemas_json, + master_secret_name, + claim_defs_json, + revoc_regs_json) + + if not hasattr(prover_create_proof, "cb"): + logger.debug("prover_create_proof: Creating callback") + prover_create_proof.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_wallet_handle = c_int32(wallet_handle) + c_proof_req_json = c_char_p(proof_req_json.encode('utf-8')) + c_requested_claims_json = c_char_p(requested_claims_json.encode('utf-8')) + c_schemas_json = c_char_p(schemas_json.encode('utf-8')) + c_master_secret_name = c_char_p(master_secret_name.encode('utf-8')) + c_claim_defs_json = c_char_p(claim_defs_json.encode('utf-8')) + c_revoc_regs_json = c_char_p(revoc_regs_json.encode('utf-8')) + + proof_json = await do_call('indy_prover_create_proof', + prover_create_proof.cb, + c_wallet_handle, + c_proof_req_json, + c_requested_claims_json, + c_schemas_json, + c_master_secret_name, + c_claim_defs_json, + c_revoc_regs_json) + + res = proof_json.decode() + logger.debug("prover_create_proof: <<< res: %r", res) + return res async def verifier_verify_proof(wallet_handle: int, From a9713eb5e367860e734d1fcc0a58ae0453da2c64 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 21 Jul 2017 17:06:04 +0300 Subject: [PATCH 301/349] added verify --- wrappers/python/indy/anoncreds.py | 34 ++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/wrappers/python/indy/anoncreds.py b/wrappers/python/indy/anoncreds.py index 8b146a2346..a4608c4164 100644 --- a/wrappers/python/indy/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -707,4 +707,36 @@ async def verifier_verify_proof(wallet_handle: int, } :return: valid: true - if signature is valid, false - otherwise """ - pass + + logger = logging.getLogger(__name__) + logger.debug("verifier_verify_proof: >>> wallet_handle: %r, proof_request_json: %r," + " proof_json: %r, schemas_json: %r, claim_defs_jsons: %r, revoc_regs_json: %r", + wallet_handle, + proof_request_json, + proof_json, + schemas_json, + claim_defs_jsons, + revoc_regs_json) + + if not hasattr(verifier_verify_proof, "cb"): + logger.debug("verifier_verify_proof: Creating callback") + verifier_verify_proof.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_wallet_handle = c_int32(wallet_handle) + c_proof_request_json = c_char_p(proof_request_json.encode('utf-8')) + c_proof_json = c_char_p(proof_json.encode('utf-8')) + c_schemas_json = c_char_p(schemas_json.encode('utf-8')) + c_claim_defs_jsons = c_char_p(claim_defs_jsons.encode('utf-8')) + c_revoc_regs_json = c_char_p(revoc_regs_json.encode('utf-8')) + + res = await do_call('indy_verifier_verify_proof', + verifier_verify_proof.cb, + c_wallet_handle, + c_proof_request_json, + c_proof_json, + c_schemas_json, + c_claim_defs_jsons, + c_revoc_regs_json) + + logger.debug("verifier_verify_proof: <<< res: %r", res) + return res From ce4e761f6ab63935be5b81f99bd3c3712b8e1637 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Fri, 21 Jul 2017 17:56:53 +0300 Subject: [PATCH 302/349] added test for create and store claim_def_works --- .../test_issuer_create_and_store_claim_def.py | 38 +++++++++++++++++++ wrappers/python/tests/utils/anoncreds.py | 12 ++++++ 2 files changed, 50 insertions(+) create mode 100644 wrappers/python/tests/anoncreds/test_issuer_create_and_store_claim_def.py create mode 100644 wrappers/python/tests/utils/anoncreds.py diff --git a/wrappers/python/tests/anoncreds/test_issuer_create_and_store_claim_def.py b/wrappers/python/tests/anoncreds/test_issuer_create_and_store_claim_def.py new file mode 100644 index 0000000000..dbcd872309 --- /dev/null +++ b/wrappers/python/tests/anoncreds/test_issuer_create_and_store_claim_def.py @@ -0,0 +1,38 @@ +from indy import wallet +from indy.anoncreds import issuer_create_and_store_claim_def + +from tests.utils import storage, anoncreds +from tests.utils.wallet import create_and_open_wallet + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.fixture +async def wallet_handle(): + handle = await create_and_open_wallet() + yield handle + await wallet.close_wallet(handle) + + +@pytest.mark.asyncio +async def test_issuer_create_and_store_claim_def_works(wallet_handle): + schema = anoncreds.get_gvt_schema_json(1) + claim_def_json = json.loads(await issuer_create_and_store_claim_def(wallet_handle, anoncreds.ISSUER_DID, + json.dumps(schema), "CL", False)) + assert len(claim_def_json['data']['primary']['r']) == 4 + assert len(claim_def_json['data']['primary']['n']) > 0 + assert len(claim_def_json['data']['primary']['s']) > 0 + assert len(claim_def_json['data']['primary']['rms']) > 0 + assert len(claim_def_json['data']['primary']['z']) > 0 + assert len(claim_def_json['data']['primary']['rctxt']) > 0 diff --git a/wrappers/python/tests/utils/anoncreds.py b/wrappers/python/tests/utils/anoncreds.py new file mode 100644 index 0000000000..03c777fc47 --- /dev/null +++ b/wrappers/python/tests/utils/anoncreds.py @@ -0,0 +1,12 @@ +ISSUER_DID = "NcYxiDXkpYi6ov5FcYDi1e" + + +def get_gvt_schema_json(schema_seq_no: int): + return { + "seqNo": schema_seq_no, + "data": { + "name": "gvt", + "version": "1.0", + "keys": ["age", "sex", "height", "name"] + } + } From 3b6b81252d17314a7db19a6bd2251b0fc185de31 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Fri, 21 Jul 2017 19:23:38 +0300 Subject: [PATCH 303/349] * Added comments --- wrappers/python/indy/agent.py | 128 +++++++++++++++++++++++++++++++++- 1 file changed, 127 insertions(+), 1 deletion(-) diff --git a/wrappers/python/indy/agent.py b/wrappers/python/indy/agent.py index 8245bf6dee..2379879716 100644 --- a/wrappers/python/indy/agent.py +++ b/wrappers/python/indy/agent.py @@ -8,14 +8,34 @@ class Event: + """ + Base class for agent 2 agent communication events + + :handle: (int) Event source handle + :error: (IndyError) If event is erroneous contains related IndyError exception + """ + handle: int - error: IndexError + error: IndyError def is_success(self): + """ + Checks is event erroneous or not + + :return: True if there are no errors assigned to this event and False otherwise + """ + return self.error is None class ConnectionEvent(Event): + """ + Agent 2 agent communication listener's connection event + + :connection_handle: Incoming connection handle + :sender_did: Sender DID + :receiver_did: Receiver DID + """ connection_handle: int sender_did: str receiver_did: str @@ -43,6 +63,12 @@ def __init__(self, handle: int, err: int, connection_handle: int, sender_did: by class MessageEvent(Event): + """ + Agent 2 agent communication connection's message event + + :message: Incoming message + """ + message: str def __init__(self, handle: int, err: int, message: bytes): @@ -87,6 +113,13 @@ def _notify_event_waiters(): async def agent_wait_for_event(handles: List[int]) -> Event: + """ + Waits for events for listeners and connections defined by list of corresponded handles + + :param handles: list of listeners or connections handles + :return: first occurred listener or connection event + """ + logger = logging.getLogger(__name__) logger.debug("agent_wait_for_event: >>> handles: %r", handles) @@ -106,6 +139,28 @@ async def agent_connect(pool_handle: int, wallet_handle: int, sender_did: str, receiver_did: str) -> int: + """ + Establishes agent to agent connection. + + Information about sender Identity must be saved in the wallet with indy_create_and_store_my_did + call before establishing of connection. + + Information about receiver Identity can be saved in the wallet with indy_store_their_did + call before establishing of connection. If there is no corresponded wallet record for receiver Identity + than this call will lookup Identity Ledger and cache this information in the wallet. + + Note that messages encryption/decryption will be performed automatically. + + After connection is established returned connection handle can be used to wait for messages with + agent_wait_for_event or sending messages with agent_send. + + :param pool_handle: pool handle (created by open_pool_ledger). + :param wallet_handle: wallet handle (created by open_wallet). + :param sender_did: id of sender Identity stored in secured Wallet. + :param receiver_did: id of receiver Identity. + :return: connection handle to use for messages sending and waiting of incoming messages with agent_wait_for_event + """ + logger = logging.getLogger(__name__) logger.debug("agent_connect: >>> pool_handle: %r, wallet_handle: %r, sender_did: %r, receiver_did: %r", pool_handle, @@ -147,6 +202,23 @@ def _message_cb(connection_handle: int, err: int, message: bytes): async def agent_listen(endpoint: str) -> int: + """ + Starts listening of agent connections. + + Listener will accept only connections to registered DIDs by indy_agent_add_identity call. + + Information about sender Identity for incomming connection validation can be saved in the wallet + with indy_store_their_did call before establishing of connection. If there is no corresponded + wallet record for sender Identity than listener will lookup Identity Ledger and cache this + information in the wallet. + + Note that messages encryption/decryption will be performed automatically. + + :param endpoint: endpoint to use in starting listener. + :return: listener handle to use for waiting of incoming connections with agent_wait_for_event and management of + assigned to this endpoint identities with agent_add_identity or agent_remove_identity. + """ + logger = logging.getLogger(__name__) logger.debug("agent_listen: >>> endpoint: %r", endpoint) @@ -197,6 +269,20 @@ async def agent_add_identity(listener_handle: int, pool_handle: int, wallet_handle: int, did: str) -> None: + """ + Add identity to listener. + + Performs wallet lookup to find corresponded receiver Identity information. + Information about receiver Identity must be saved in the wallet with + indy_create_and_store_my_did call before this call. + + After successfully add_identity listener will start to accept incoming connection to added DID. + + :param listener_handle: listener handle (created by indy_agent_listen). + :param pool_handle: pool handle (created by open_pool_ledger). + :param wallet_handle: wallet handle (created by open_wallet). + :param did: DID of identity. + """ logger = logging.getLogger(__name__) logger.debug("agent_add_identity: >>> listener_handle: %r, pool_handle: %r, wallet_handle: %r, did: %r", listener_handle, @@ -227,6 +313,20 @@ async def agent_remove_identity(listener_handle: int, pool_handle: int, wallet_handle: int, did: str) -> None: + """ + Remove identity from listener. + + Performs wallet lookup to find corresponded receiver Identity information. + Information about receiver Identity must be saved in the wallet with + signus.create_and_store_my_did call before this call. + + After successfully rm_identity listener will stop to accept incoming connection to removed DID. + + :param listener_handle: listener handle (created by indy_agent_listen). + :param pool_handle: pool handle (create by open_pool_ledger) + :param wallet_handle: wallet handle (created by open_wallet). + :param did: DID of identity. + """ logger = logging.getLogger(__name__) logger.debug("agent_remove_identity: >>> listener_handle: %r, pool_handle: %r, wallet_handle: %r, did: %r", listener_handle, @@ -254,6 +354,16 @@ async def agent_remove_identity(listener_handle: int, async def agent_send(connection_handle: int, message: str) -> None: + """" + Sends message to connected agent. + + Note that this call works for both incoming and outgoing connections. + Note that messages encryption/decryption will be performed automatically. + + :param connection_handle: connection handle returned by indy_agent_connect or indy_agent_listen calls. + :param message: message to send. + """ + logger = logging.getLogger(__name__) logger.debug("agent_send: >>> connection_handle: %r, message: %r", connection_handle, @@ -275,6 +385,14 @@ async def agent_send(connection_handle: int, message: str) -> None: async def agent_close_connection(connection_handle: int) -> None: + """ + Closes agent connection. + + Note that this call works for both incoming and outgoing connections. + + :param connection_handle: connection handle returned by indy_agent_connect or indy_agent_listen calls. + """ + logger = logging.getLogger(__name__) logger.debug("agent_close_connection: >>> connection_handle: %r", connection_handle) @@ -292,6 +410,14 @@ async def agent_close_connection(connection_handle: int) -> None: async def agent_close_listener(listener_handle: int) -> None: + """ + Closes listener and stops listening for agent connections. + + Note that all opened incomming connections will be closed automatically. + + :param listener_handle: Listener handle returned by indy_agent_listen call. + """ + logger = logging.getLogger(__name__) logger.debug("agent_close_listener: >>> listener_handle: %r", listener_handle) From e89ef2d193f361b3c5a5fcdee29fcc87d4c9c965 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Sat, 22 Jul 2017 08:23:48 +0300 Subject: [PATCH 304/349] added issuer_create_claim --- .../anoncreds/test_issuer_create_claim.py | 34 ++++++++++++ wrappers/python/tests/utils/anoncreds.py | 52 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 wrappers/python/tests/anoncreds/test_issuer_create_claim.py diff --git a/wrappers/python/tests/anoncreds/test_issuer_create_claim.py b/wrappers/python/tests/anoncreds/test_issuer_create_claim.py new file mode 100644 index 0000000000..3e27b86b38 --- /dev/null +++ b/wrappers/python/tests/anoncreds/test_issuer_create_claim.py @@ -0,0 +1,34 @@ +from indy import wallet +from indy.anoncreds import issuer_create_claim + +from tests.utils import storage, anoncreds +from tests.utils.wallet import create_and_open_wallet + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.fixture +async def wallet_handle(): + handle = await create_and_open_wallet() + await anoncreds.prepare_common_wallet(handle) + yield handle + await wallet.close_wallet(handle) + + +@pytest.mark.asyncio +async def test_issuer_create_claim_works(wallet_handle): + claim_req = anoncreds.get_claim_req() + claim_json = anoncreds.get_gvt_claim_json() + (_, claim_json) = await issuer_create_claim(wallet_handle, json.dumps(claim_req), json.dumps(claim_json), -1, -1) + diff --git a/wrappers/python/tests/utils/anoncreds.py b/wrappers/python/tests/utils/anoncreds.py index 03c777fc47..6dc381db83 100644 --- a/wrappers/python/tests/utils/anoncreds.py +++ b/wrappers/python/tests/utils/anoncreds.py @@ -1,4 +1,34 @@ +from indy import anoncreds + +import json + ISSUER_DID = "NcYxiDXkpYi6ov5FcYDi1e" +COMMON_SCHEMA_SEQ_NO = 1 +COMMON_MASTER_SECRET_NAME = "common_master_secret_name" + + +async def prepare_common_wallet(wallet_handle): + schema = get_gvt_schema_json(1) + claim_def_json = await anoncreds.issuer_create_and_store_claim_def( + wallet_handle, ISSUER_DID, json.dumps(schema), None, False) + + claim_offer_json_1 = get_claim_offer(ISSUER_DID, 1) + claim_offer_json_2 = get_claim_offer(ISSUER_DID, 2) + claim_offer_json_3 = get_claim_offer("CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW", 2) + await anoncreds.prover_store_claim_offer(wallet_handle, json.dumps(claim_offer_json_1)) + await anoncreds.prover_store_claim_offer(wallet_handle, json.dumps(claim_offer_json_2)) + await anoncreds.prover_store_claim_offer(wallet_handle, json.dumps(claim_offer_json_3)) + await anoncreds.prover_create_master_secret(wallet_handle, COMMON_MASTER_SECRET_NAME) + + claim_req = await anoncreds.prover_create_and_store_claim_req( + wallet_handle, "HEJ9gvWX64wW7UD", json.dumps(claim_offer_json_1), claim_def_json, COMMON_MASTER_SECRET_NAME) + (_, claim_json) = await anoncreds.issuer_create_claim( + wallet_handle, claim_req, json.dumps(get_gvt_claim_json()), -1, -1) + await anoncreds.prover_store_claim(wallet_handle, claim_json) + + +def get_claim_offer(issuer_did, schema_seq_no): + return {"issuer_did": issuer_did, "schema_seq_no": schema_seq_no} def get_gvt_schema_json(schema_seq_no: int): @@ -10,3 +40,25 @@ def get_gvt_schema_json(schema_seq_no: int): "keys": ["age", "sex", "height", "name"] } } + + +def get_gvt_claim_json(): + return { + "sex": ["male", "5944657099558967239210949258394887428692050081607692519917050011144233115103"], + "name": ["Alex", "1139481716457488690172217916278103335"], + "height": ["175", "175"], + "age": ["28", "28"] + } + + +def get_claim_req(): + return {"blinded_ms": {"prover_did": "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW", + "u": "541727375645293327107242131390489410830131768916446771173223218236303087346206273292" + "275918450941006362568297619591573147842939390451766213271549909084590728218268187187" + "396963232997879281735355290245565403237095788507069932942349664408266908992668726827" + "902285139739992123705745482398771085112836294238073386324354310973398756650754537851" + "417229890983878959703959824327090115058645337274155525667150696753462207525844495604" + "072614465677317118141888367033373659867254296561952756168465435357073642154989807508" + "60746440672050640048215761507774996460985293327604627646056062013419674090094698841" + "792968543317468164175921100038", + "ur": None}, "issuer_did": ISSUER_DID, "schema_seq_no": 1} From 743d4b909232da7c54c312d9282c78f8f8b82432 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 24 Jul 2017 09:36:00 +0300 Subject: [PATCH 305/349] Implemented register wallet tests. Refactoring tests --- .../org/hyperledger/indy/sdk/agent/Agent.java | 2 +- .../hyperledger/indy/sdk/wallet/Wallet.java | 53 +++++++++++------ .../indy/sdk/wallet/WalletTypeInmem.java | 11 +++- .../indy/sdk/agent/AgentConnectTest.java | 4 +- ...suerCreateAndStoreClaimDefinitionTest.java | 30 +++++----- .../ProverCreateMasterSecretTest.java | 15 +++-- .../sdk/anoncreds/ProverCreateProofTest.java | 10 ---- .../ProverGetClaimsForProofRequestTest.java | 26 ++++----- .../sdk/anoncreds/ProverStoreClaimTest.java | 2 +- .../anoncreds/VerifierVerifyProofTest.java | 6 +- .../indy/sdk/demo/AgentDemoTest.java | 2 +- .../indy/sdk/demo/LedgerDemoTest.java | 2 +- .../indy/sdk/ledger/AttribRequestsTest.java | 33 ++++------- .../indy/sdk/ledger/ClaimDefRequestsTest.java | 20 +++---- .../indy/sdk/ledger/GetTxnRequestTest.java | 7 +-- .../indy/sdk/ledger/NodeRequestsTest.java | 14 ++--- .../indy/sdk/ledger/NymRequestsTest.java | 25 +++----- .../indy/sdk/ledger/RequestsTest.java | 17 +++--- .../indy/sdk/ledger/SchemaRequestsTest.java | 12 ++-- .../indy/sdk/signus/CreateMyDidTest.java | 11 ++-- .../indy/sdk/signus/ReplaceKeysTest.java | 12 ++-- .../hyperledger/indy/sdk/signus/SignTest.java | 9 +-- .../indy/sdk/signus/StoreTheirDidTest.java | 22 +++---- .../indy/sdk/signus/VerifyTest.java | 12 ++-- .../indy/sdk/wallet/CloseWalletTest.java | 31 ++++++++-- .../indy/sdk/wallet/CreateWalletTest.java | 18 +++++- .../indy/sdk/wallet/DeleteWalletTest.java | 57 ++++++++++++++----- .../indy/sdk/wallet/OpenWalletTest.java | 39 ++++++++++--- .../sdk/wallet/RegisterWalletTypeTest.java | 33 +++++------ 29 files changed, 303 insertions(+), 232 deletions(-) diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java index fdf069eb6a..7a89710a54 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/agent/Agent.java @@ -361,7 +361,7 @@ public static CompletableFuture agentCloseListener( listeners.remove(listenerHandle); - int result = LibIndy.api.indy_agent_close_connection( + int result = LibIndy.api.indy_agent_close_listener( commandHandle, listenerHandle, agentCloseListenerCb); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java index 5cf503e4c6..2c529b879b 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java @@ -1,5 +1,8 @@ package org.hyperledger.indy.sdk.wallet; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.concurrent.CompletableFuture; import org.hyperledger.indy.sdk.IndyException; @@ -100,30 +103,44 @@ public void callback(int xcommand_handle, int err) { * STATIC METHODS */ + private static final List REGISERED_WALLETS = Collections.synchronizedList(new ArrayList()); + public static CompletableFuture registerWalletType( String xtype, - WalletType walletType) throws IndyException { + WalletType walletType, + Boolean forceCreate) throws IndyException, InterruptedException { - CompletableFuture future = new CompletableFuture (); - int commandHandle = addFuture(future); + synchronized (REGISERED_WALLETS) { + CompletableFuture future = new CompletableFuture(); + int commandHandle = addFuture(future); - int result = LibIndy.api.indy_register_wallet_type( - commandHandle, - xtype, - walletType.getCreateCb(), - walletType.getOpenCb(), - walletType.getSetCb(), - walletType.getGetCb(), - walletType.getGetNotExpiredCb(), - walletType.getListCb(), - walletType.getCloseCb(), - walletType.getDeleteCb(), - walletType.getFreeCb(), - registerWalletTypeCb); - checkResult(result); + if (REGISERED_WALLETS.contains(xtype) && ! forceCreate) { + future.complete(null); + return future; + } - return future; + + REGISERED_WALLETS.add(xtype); + + int result = LibIndy.api.indy_register_wallet_type( + commandHandle, + xtype, + walletType.getCreateCb(), + walletType.getOpenCb(), + walletType.getSetCb(), + walletType.getGetCb(), + walletType.getGetNotExpiredCb(), + walletType.getListCb(), + walletType.getCloseCb(), + walletType.getDeleteCb(), + walletType.getFreeCb(), + registerWalletTypeCb); + + checkResult(result); + + return future; + } } public static CompletableFuture createWallet( diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeInmem.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeInmem.java index af03946030..2e356b1af3 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeInmem.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/WalletTypeInmem.java @@ -73,7 +73,7 @@ public ErrorCode get(int handle, String key, PointerByReference valuePtr) { byte[] bytes = Native.toByteArray(value); Pointer pointer = new Memory(bytes.length + 1); pointer.write(0, bytes, 0, bytes.length); - pointer.setByte(bytes.length, (byte)0); + pointer.setByte(bytes.length, (byte) 0); valuePtr.setPointer(pointer); return ErrorCode.Success; } @@ -89,7 +89,7 @@ public ErrorCode getNotExpired(int handle, String key, PointerByReference valueP byte[] bytes = Native.toByteArray(value); Pointer pointer = new Memory(bytes.length + 1); pointer.write(0, bytes, 0, bytes.length); - pointer.setByte(bytes.length, (byte)0); + pointer.setByte(bytes.length, (byte) 0); valuePtr.setPointer(pointer); return ErrorCode.Success; } @@ -118,7 +118,7 @@ public ErrorCode list(int handle, String keyPrefix, PointerByReference valuesJso byte[] bytes = Native.toByteArray(builder.toString()); Pointer pointer = new Memory(bytes.length + 1); pointer.write(0, bytes, 0, bytes.length); - pointer.setByte(bytes.length, (byte)0); + pointer.setByte(bytes.length, (byte) 0); valuesJsonPtr.setPointer(pointer); return ErrorCode.Success; } @@ -168,6 +168,11 @@ private int newHandle() { return Integer.valueOf(atomicInteger.incrementAndGet()); } + public void clear() { + this.walletsByName.clear(); + this.walletsByHandle.clear(); + } + private class WalletInmem { private int handle; diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentConnectTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentConnectTest.java index 2ccbdcef34..8e0606938c 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentConnectTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/agent/AgentConnectTest.java @@ -8,6 +8,8 @@ import org.hyperledger.indy.sdk.wallet.Wallet; import org.junit.Test; +import static org.hyperledger.indy.sdk.IndyIntegrationTest.TRUSTEE_SEED; + public class AgentConnectTest extends AgentIntegrationTest { @@ -30,7 +32,7 @@ public void testAgentConnectWorksForRemoteData() throws Exception { String listenerPk = createMyDidResult.getPk(); SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(trusteeWallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateAndStoreClaimDefinitionTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateAndStoreClaimDefinitionTest.java index f4f5b8f419..aabf38ebce 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateAndStoreClaimDefinitionTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/IssuerCreateAndStoreClaimDefinitionTest.java @@ -49,13 +49,14 @@ public void testIssuerCreateAndStoreClaimDefWorks() throws Exception { assertNotNull(claimDef); JSONObject claimDefObject = new JSONObject(claimDef); - - assertEquals(claimDefObject.getJSONObject("data").getJSONObject("primary").getJSONObject("r").length(), 4); - assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("n").length() > 0); - assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("s").length() > 0); - assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("z").length() > 0); - assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("rms").length() > 0); - assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("rctxt").length() > 0); + JSONObject primary = claimDefObject.getJSONObject("data").getJSONObject("primary"); + + assertEquals(4, primary.getJSONObject("r").length()); + assertTrue(primary.getString("n").length() > 0); + assertTrue(primary.getString("s").length() > 0); + assertTrue(primary.getString("z").length() > 0); + assertTrue(primary.getString("rms").length() > 0); + assertTrue(primary.getString("rctxt").length() > 0); } @Test @@ -94,13 +95,14 @@ public void testIssuerCreateAndStoreClaimDefWorksForCorrectCryptoType() throws E assertNotNull(claimDef); JSONObject claimDefObject = new JSONObject(claimDef); - - assertEquals(claimDefObject.getJSONObject("data").getJSONObject("primary").getJSONObject("r").length(), 4); - assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("n").length() > 0); - assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("s").length() > 0); - assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("z").length() > 0); - assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("rms").length() > 0); - assertTrue(claimDefObject.getJSONObject("data").getJSONObject("primary").getString("rctxt").length() > 0); + JSONObject primary = claimDefObject.getJSONObject("data").getJSONObject("primary"); + + assertEquals(4, primary.getJSONObject("r").length()); + assertTrue(primary.getString("n").length() > 0); + assertTrue(primary.getString("s").length() > 0); + assertTrue(primary.getString("z").length() > 0); + assertTrue(primary.getString("rms").length() > 0); + assertTrue(primary.getString("rctxt").length() > 0); } @Test diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateMasterSecretTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateMasterSecretTest.java index 56bb828dc2..eee5db6465 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateMasterSecretTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateMasterSecretTest.java @@ -35,17 +35,20 @@ public void testProverCreateMasterSecretWorks() throws Exception { @Test public void testProverCreateMasterSecretWorksForDuplicate() throws Exception { - Anoncreds.proverCreateMasterSecret(wallet, "master_secret_name").get(); + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.AnoncredsMasterSecretDuplicateNameError)); + + String masterSecretName = "master_secret_name_duplicate"; + Anoncreds.proverCreateMasterSecret(wallet, masterSecretName).get(); + Anoncreds.proverCreateMasterSecret(wallet, masterSecretName).get(); } @Test - public void testProverStoreClaimOfferWorksForInvalidIssuerDid() throws Exception { + public void testProverCreateMasterSecretWorksForEmptyName() throws Exception { - thrown.expect(ExecutionException.class); - thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); + thrown.expect(new ErrorCodeMatcher(ErrorCode.CommonInvalidParam3)); - String claimOffer = "{\"issuer_did\":\"invalid_base58_string\",\"schema_seq_no\":1}"; + Anoncreds.proverCreateMasterSecret(wallet, "").get(); - Anoncreds.proverStoreClaimOffer(wallet, claimOffer).get(); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateProofTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateProofTest.java index d498081f40..1e05c36860 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateProofTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverCreateProofTest.java @@ -2,22 +2,12 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; -import org.hyperledger.indy.sdk.utils.InitHelper; -import org.hyperledger.indy.sdk.utils.StorageUtils; -import org.hyperledger.indy.sdk.wallet.Wallet; import org.json.JSONArray; import org.json.JSONObject; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.Timeout; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; public class ProverCreateProofTest extends AnoncredsIntegrationTest { diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimsForProofRequestTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimsForProofRequestTest.java index 016cc118ab..ba0dd0fc26 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimsForProofRequestTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverGetClaimsForProofRequestTest.java @@ -29,7 +29,7 @@ public void testProverGetClaimsForProofRequestWorksForRevealedAttribute() throws JSONObject claims = new JSONObject(claimsJson); JSONArray claimsForAttribute1 = claims.getJSONObject("attrs").getJSONArray("attr1_uuid"); - assertEquals(claimsForAttribute1.length(), 1); + assertEquals(1, claimsForAttribute1.length()); } @Test @@ -49,7 +49,7 @@ public void testProverGetClaimsForProofRequestWorksForNotFoundAttribute() throws JSONObject claims = new JSONObject(claimsJson); JSONArray claimsForAttribute1 = claims.getJSONObject("attrs").getJSONArray("attr1_uuid"); - assertEquals(claimsForAttribute1.length(), 0); + assertEquals(0, claimsForAttribute1.length()); } @Test @@ -69,7 +69,7 @@ public void testProverGetClaimsForProofRequestWorksForSatisfyPredicate() throws JSONObject claims = new JSONObject(claimsJson); JSONArray claimsForPredicate = claims.getJSONObject("predicates").getJSONArray("predicate1_uuid"); - assertEquals(claimsForPredicate.length(), 1); + assertEquals(1, claimsForPredicate.length()); } @Test @@ -89,7 +89,7 @@ public void testProverGetClaimsForProofRequestWorksForNotSatisfyPredicate() thro JSONObject claims = new JSONObject(claimsJson); JSONArray claimsForPredicate = claims.getJSONObject("predicates").getJSONArray("predicate1_uuid"); - assertEquals(claimsForPredicate.length(), 0); + assertEquals(0, claimsForPredicate.length()); } @Test @@ -114,16 +114,16 @@ public void testProverGetClaimsForProofRequestWorksForMultiplyAttributesAndPredi JSONObject claims = new JSONObject(claimsJson); JSONArray claimsForAttribute1 = claims.getJSONObject("attrs").getJSONArray("attr1_uuid"); - assertEquals(claimsForAttribute1.length(), 1); + assertEquals(1, claimsForAttribute1.length()); JSONArray claimsForAttribute2 = claims.getJSONObject("attrs").getJSONArray("attr2_uuid"); - assertEquals(claimsForAttribute2.length(), 1); + assertEquals(1, claimsForAttribute2.length()); JSONArray claimsForPredicate1 = claims.getJSONObject("predicates").getJSONArray("predicate1_uuid"); - assertEquals(claimsForPredicate1.length(), 1); + assertEquals(1, claimsForPredicate1.length()); JSONArray claimsForPredicate2 = claims.getJSONObject("predicates").getJSONArray("predicate2_uuid"); - assertEquals(claimsForPredicate2.length(), 1); + assertEquals(1, claimsForPredicate2.length()); } @Test @@ -142,8 +142,8 @@ public void testProverGetClaimsForProofRequestWorksForEmptyRequest() throws Exce JSONObject claims = new JSONObject(claimsJson); - assertEquals(claims.getJSONObject("attrs").length(), 0); - assertEquals(claims.getJSONObject("predicates").length(), 0); + assertEquals(0, claims.getJSONObject("attrs").length()); + assertEquals(0, claims.getJSONObject("predicates").length()); } @Test @@ -163,7 +163,7 @@ public void testProverGetClaimsForProofRequestWorksForRevealedAttributeWithOther JSONObject claims = new JSONObject(claimsJson); JSONArray claimsForAttribute1 = claims.getJSONObject("attrs").getJSONArray("attr1_uuid"); - assertEquals(claimsForAttribute1.length(), 0); + assertEquals(0, claimsForAttribute1.length()); } @Test @@ -183,7 +183,7 @@ public void testProverGetClaimsForProofRequestWorksForRevealedAttributeBySpecifi JSONObject claims = new JSONObject(claimsJson); JSONArray claimsForAttribute1 = claims.getJSONObject("attrs").getJSONArray("attr1_uuid"); - assertEquals(claimsForAttribute1.length(), 1); + assertEquals(1, claimsForAttribute1.length()); } @Test @@ -203,7 +203,7 @@ public void testProverGetClaimsForProofRequestWorksForSatisfyPredicateByIssuerAn JSONObject claims = new JSONObject(claimsJson); JSONArray claimsForPredicate = claims.getJSONObject("predicates").getJSONArray("predicate1_uuid"); - assertEquals(claimsForPredicate.length(), 1); + assertEquals(1, claimsForPredicate.length()); } @Test diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverStoreClaimTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverStoreClaimTest.java index 97513c65f2..efee38983d 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverStoreClaimTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/ProverStoreClaimTest.java @@ -15,7 +15,7 @@ public void testProverStoreClaimWorks() throws Exception { String proverWalletName = "proverWallet"; Wallet.createWallet("default", proverWalletName, "default", null, null).get(); - Wallet proverWallet = proverWallet = Wallet.openWallet(proverWalletName, null, null).get(); + Wallet proverWallet = Wallet.openWallet(proverWalletName, null, null).get(); Anoncreds.proverCreateMasterSecret(proverWallet, masterSecretName).get(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/VerifierVerifyProofTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/VerifierVerifyProofTest.java index 68354c8238..773d31f82a 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/VerifierVerifyProofTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/VerifierVerifyProofTest.java @@ -23,9 +23,9 @@ public class VerifierVerifyProofTest extends AnoncredsIntegrationTest { " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}\n" + " }"; - String schemasJson = String.format("{\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\":%s}", schema); - String claimDefsJson = String.format("{\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\":%s}", claimDef); - String revocRegsJson = "{}"; + private String schemasJson = String.format("{\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\":%s}", schema); + private String claimDefsJson = String.format("{\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\":%s}", claimDef); + private String revocRegsJson = "{}"; @Test public void testVerifierVerifyProofWorksForCorrectProof() throws Exception { diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AgentDemoTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AgentDemoTest.java index 1ac56ea381..52dc56aaee 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AgentDemoTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/AgentDemoTest.java @@ -52,7 +52,7 @@ public void testAgentDemo() throws Exception { //5. Create Their Did from Trustee seed SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(trusteeWallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/LedgerDemoTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/LedgerDemoTest.java index 3e3b475330..4a92c09411 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/LedgerDemoTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/LedgerDemoTest.java @@ -42,7 +42,7 @@ public void testLedgerDemo() throws Exception { // 5. Create Did from Trustee1 seed SignusJSONParameters.CreateAndStoreMyDidJSONParameter theirDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); CreateAndStoreMyDidResult createTheirDidResult = Signus.createAndStoreMyDid(trusteeWallet, theirDidJson.toJson()).get(); assertNotNull(createTheirDidResult); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AttribRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AttribRequestsTest.java index d6c8c37032..20424f5ae6 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AttribRequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AttribRequestsTest.java @@ -11,10 +11,8 @@ import org.hyperledger.indy.sdk.wallet.Wallet; import org.json.JSONObject; import org.junit.*; -import org.junit.rules.Timeout; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -24,6 +22,9 @@ public class AttribRequestsTest extends IndyIntegrationTest { private Pool pool; private Wallet wallet; private String walletName = "ledgerWallet"; + private String identifier = "Th7MpTaRZVRYnPiabds81Y"; + private String dest = "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4"; + private String endpoint = "{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}"; @Before public void openPool() throws Exception { @@ -44,20 +45,16 @@ public void closePool() throws Exception { @Test public void testBuildAttribRequestWorksForRawData() throws Exception { - String identifier = "Th7MpTaRZVRYnPiabds81Y"; - String dest = "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4"; - String raw = "{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}"; - String expectedResult = String.format("\"identifier\":\"%s\"," + "\"operation\":{" + "\"type\":\"100\"," + "\"dest\":\"%s\"," + - "\"raw\":\"{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}\"" + - "}", identifier, dest); + "\"raw\":\"%s\"" + + "}", identifier, dest, endpoint); - String attribRequest = Ledger.buildAttribRequest(identifier, dest, null, raw, null).get(); + String attribRequest = Ledger.buildAttribRequest(identifier, dest, null, endpoint, null).get(); - assertTrue(attribRequest.replace("\\","").contains(expectedResult)); + assertTrue(attribRequest.replace("\\", "").contains(expectedResult)); } @Test @@ -66,15 +63,12 @@ public void testBuildAttribRequestWorksForMissedAttribute() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); - Ledger.buildAttribRequest("Th7MpTaRZVRYnPiabds81Y", - "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4", null, null, null).get(); + Ledger.buildAttribRequest(identifier, dest, null, null, null).get(); } @Test public void testBuildGetAttribRequestWorks() throws Exception { - String identifier = "Th7MpTaRZVRYnPiabds81Y"; - String dest = "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4"; String raw = "endpoint"; String expectedResult = String.format("\"identifier\":\"%s\"," + @@ -96,13 +90,11 @@ public void testSendAttribRequestWorksWithoutSignature() throws Exception { thrown.expectCause(new ErrorCodeMatcher(ErrorCode.LedgerInvalidTransaction)); SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); - String endpoint = "{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}"; - String attribRequest = Ledger.buildAttribRequest(trusteeDid, trusteeDid, null, endpoint, null).get(); Ledger.submitRequest(pool, attribRequest).get(); } @@ -111,7 +103,7 @@ public void testSendAttribRequestWorksWithoutSignature() throws Exception { public void testAttribRequestsWorks() throws Exception { SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); @@ -123,8 +115,6 @@ public void testAttribRequestsWorks() throws Exception { String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, myVerkey, null, null).get(); Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); - String endpoint = "{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}"; - String attribRequest = Ledger.buildAttribRequest(myDid, myDid, null, endpoint, null).get(); Ledger.signAndSubmitRequest(pool, wallet, myDid, attribRequest).get(); @@ -142,7 +132,6 @@ public void testBuildAttribRequestWorksForInvalidIdentifier() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); - Ledger.buildAttribRequest("invalid_base58_identifier", - "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4", null, "{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}", null).get(); + Ledger.buildAttribRequest("invalid_base58_identifier", dest, null, endpoint, null).get(); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/ClaimDefRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/ClaimDefRequestsTest.java index d69e57fb8c..73d4c206bc 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/ClaimDefRequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/ClaimDefRequestsTest.java @@ -3,7 +3,6 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; -import org.hyperledger.indy.sdk.anoncreds.Anoncreds; import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.signus.Signus; import org.hyperledger.indy.sdk.signus.SignusJSONParameters; @@ -64,13 +63,13 @@ public void closePool() throws Exception { " }\n" + " }\n" + " }"; - String signatureType = "CL"; + private String signatureType = "CL"; + private String identifier = "Th7MpTaRZVRYnPiabds81Y"; + private String signature_type = "CL"; @Test public void testBuildClaimDefRequestWorks() throws Exception { - String identifier = "Th7MpTaRZVRYnPiabds81Y"; - String signature_type = "CL"; int schema_seq_no = 1; String data = "{\"primary\":{\"n\":\"1\",\"s\":\"2\",\"rms\":\"3\",\"r\":{\"name\":\"1\"},\"rctxt\":\"1\",\"z\":\"1\"}}"; @@ -90,9 +89,6 @@ public void testBuildClaimDefRequestWorks() throws Exception { @Test public void testBuildGetClaimDefRequestWorks() throws Exception { - String identifier = "Th7MpTaRZVRYnPiabds81Y"; - String origin = "Th7MpTaRZVRYnPiabds81Y"; - String signature_type = "CL"; int ref = 1; String expectedResult = String.format("\"identifier\":\"%s\"," + @@ -101,9 +97,9 @@ public void testBuildGetClaimDefRequestWorks() throws Exception { "\"ref\":%d," + "\"signature_type\":\"%s\"," + "\"origin\":\"%s\"" + - "}", identifier, ref, signature_type, origin); + "}", identifier, ref, signature_type, identifier); - String getClaimDefRequest = Ledger.buildGetClaimDefTxn(identifier, ref, signature_type, origin).get(); + String getClaimDefRequest = Ledger.buildGetClaimDefTxn(identifier, ref, signature_type, identifier).get(); assertTrue(getClaimDefRequest.replace("\\", "").contains(expectedResult)); } @@ -114,8 +110,6 @@ public void testBuildClaimDefRequestWorksForInvalidJson() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); - String identifier = "Th7MpTaRZVRYnPiabds81Y"; - String signature_type = "CL"; int schema_seq_no = 1; String data = "{\"primary\":{\"n\":\"1\",\"s\":\"2\",\"rms\":\"3\",\"r\":{\"name\":\"1\"}}}"; @@ -126,7 +120,7 @@ public void testBuildClaimDefRequestWorksForInvalidJson() throws Exception { public void testClaimDefRequestsWorks() throws Exception { SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); @@ -187,7 +181,7 @@ public void testClaimDefRequestWorksWithoutSignature() throws Exception { thrown.expectCause(new ErrorCodeMatcher(ErrorCode.LedgerInvalidTransaction)); SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/GetTxnRequestTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/GetTxnRequestTest.java index 328ac89739..3657add3cd 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/GetTxnRequestTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/GetTxnRequestTest.java @@ -9,9 +9,6 @@ import org.hyperledger.indy.sdk.wallet.Wallet; import org.json.JSONObject; import org.junit.*; -import org.junit.rules.Timeout; - -import java.util.concurrent.TimeUnit; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -59,7 +56,7 @@ public void testBuildGetTxnRequestWorks() throws Exception { public void testGetTxnRequestWorks() throws Exception { SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult didResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String did = didResult.getDid(); @@ -88,7 +85,7 @@ public void testGetTxnRequestWorks() throws Exception { public void testGetTxnRequestWorksForInvalidSeqNo() throws Exception { SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult didResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String did = didResult.getDid(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NodeRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NodeRequestsTest.java index 8f1b3c0573..dbb48edf37 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NodeRequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NodeRequestsTest.java @@ -10,10 +10,8 @@ import org.hyperledger.indy.sdk.utils.PoolUtils; import org.hyperledger.indy.sdk.wallet.Wallet; import org.junit.*; -import org.junit.rules.Timeout; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import static org.junit.Assert.assertTrue; @@ -22,6 +20,8 @@ public class NodeRequestsTest extends IndyIntegrationTest { private Pool pool; private Wallet wallet; private String walletName = "ledgerWallet"; + private String identifier = "Th7MpTaRZVRYnPiabds81Y"; + private String dest = "Th7MpTaRZVRYnPiabds81Y"; @Before public void openPool() throws Exception { @@ -42,8 +42,6 @@ public void closePool() throws Exception { @Test public void testBuildNodeRequestWorks() throws Exception { - String identifier = "Th7MpTaRZVRYnPiabds81Y"; - String dest = "Th7MpTaRZVRYnPiabds81Y"; String data = "{\"node_ip\":\"10.0.0.100\"," + "\"node_port\":910," + "\"client_ip\":\"10.0.0.100\"," + @@ -92,8 +90,6 @@ public void testBuildNodeRequestWorksForWrongServiceType() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); - String identifier = "Th7MpTaRZVRYnPiabds81Y"; - String dest = "Th7MpTaRZVRYnPiabds81Y"; String data = "{\"node_ip\":\"10.0.0.100\"," + "\"node_port\":910," + "\"client_ip\":\"10.0.0.100\"," + @@ -110,8 +106,6 @@ public void testBuildNodeRequestWorksForMissedField() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); - String identifier = "Th7MpTaRZVRYnPiabds81Y"; - String dest = "Th7MpTaRZVRYnPiabds81Y"; String data = "{\"node_ip\":\"10.0.0.100\"," + "\"node_port\":910," + "\"client_ip\":\"10.0.0.100\"," + @@ -128,7 +122,7 @@ public void testSendNodeRequestWorksForWrongRole() throws Exception { thrown.expectCause(new ErrorCodeMatcher(ErrorCode.LedgerInvalidTransaction)); SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult didResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String did = didResult.getDid(); @@ -149,7 +143,7 @@ public void testSendNodeRequestWorksForWrongRole() throws Exception { public void testSendNodeRequestWorksForNewSteward() throws Exception { SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult didResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String trusteeDid = didResult.getDid(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java index 4208cc837b..310a02622c 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NymRequestsTest.java @@ -11,10 +11,8 @@ import org.hyperledger.indy.sdk.wallet.Wallet; import org.json.JSONObject; import org.junit.*; -import org.junit.rules.Timeout; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -25,6 +23,8 @@ public class NymRequestsTest extends IndyIntegrationTest { private Pool pool; private Wallet wallet; private String walletName = "ledgerWallet"; + private String identifier = "Th7MpTaRZVRYnPiabds81Y"; + private String dest = "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4"; @Before public void openPool() throws Exception { @@ -45,9 +45,6 @@ public void closePool() throws Exception { @Test public void testBuildNymRequestWorksForOnlyRequiredFields() throws Exception { - String identifier = "Th7MpTaRZVRYnPiabds81Y"; - String dest = "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4"; - String expectedResult = String.format("\"identifier\":\"%s\",\"operation\":{\"type\":\"1\",\"dest\":\"%s\"}", identifier, dest); String nymRequest = Ledger.buildNymRequest(identifier, dest, null, null, null).get(); @@ -58,8 +55,6 @@ public void testBuildNymRequestWorksForOnlyRequiredFields() throws Exception { @Test public void testBuildNymRequestWorksForOnlyOptionalFields() throws Exception { - String identifier = "Th7MpTaRZVRYnPiabds81Y"; - String dest = "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4"; String verkey = "Anfh2rjAcxkE249DcdsaQl"; String role = "STEWARD"; String alias = "some_alias"; @@ -81,9 +76,6 @@ public void testBuildNymRequestWorksForOnlyOptionalFields() throws Exception { @Test public void testBuildGetNymRequestWorks() throws Exception { - String identifier = "Th7MpTaRZVRYnPiabds81Y"; - String dest = "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4"; - String expectedResult = String.format("\"identifier\":\"%s\",\"operation\":{\"type\":\"105\",\"dest\":\"%s\"}", identifier, dest); String nymRequest = Ledger.buildGetNymRequest(identifier, dest).get(); @@ -108,7 +100,7 @@ public void testNymRequestWorksWithoutSignature() throws Exception { public void testSendNymRequestsWorksForOnlyRequiredFields() throws Exception { SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); @@ -126,7 +118,7 @@ public void testSendNymRequestsWorksForOnlyRequiredFields() throws Exception { public void testSendNymRequestsWorksForOptionalFields() throws Exception { SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); @@ -147,7 +139,7 @@ public void testSendNymRequestsWorksForOptionalFields() throws Exception { public void testGetNymRequestWorks() throws Exception { SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(wallet, didJson.toJson()).get(); String did = result.getDid(); @@ -167,7 +159,7 @@ public void testSendNymRequestsWorksForWrongSignerRole() throws Exception { thrown.expectCause(new ErrorCodeMatcher(ErrorCode.LedgerInvalidTransaction)); SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); @@ -217,7 +209,7 @@ public void testSendNymRequestsWorksForUnknownSigner() throws Exception { public void testNymRequestsWorks() throws Exception { SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); @@ -245,7 +237,6 @@ public void testSendNymRequestsWorksForWrongRole() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); - Ledger.buildNymRequest("Th7MpTaRZVRYnPiabds81Y", - "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4", null, null, "WRONG_ROLE").get(); + Ledger.buildNymRequest(identifier, dest, null, null, "WRONG_ROLE").get(); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java index 344a14b290..16053a8f6f 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/RequestsTest.java @@ -11,23 +11,20 @@ import org.hyperledger.indy.sdk.wallet.Wallet; import org.json.JSONObject; import org.junit.*; -import org.junit.rules.Timeout; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import static org.junit.Assert.assertNotNull; public class RequestsTest extends IndyIntegrationTest { - private String poolName; private Pool pool; private Wallet wallet; private String walletName = "ledgerWallet"; @Before public void openPool() throws Exception { - poolName = PoolUtils.createPoolLedgerConfig(); + String poolName = PoolUtils.createPoolLedgerConfig(); pool = Pool.openPoolLedger(poolName, null).get(); Wallet.createWallet(poolName, walletName, "default", null, null).get(); @@ -69,7 +66,7 @@ public void testSubmitRequestWorks() throws Exception { public void testSignAndSubmitRequestWorks() throws Exception { SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); @@ -108,11 +105,13 @@ public void testSignAndSubmitRequestWorksForIncompatibleWalletAndPool() throws E thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletIncompatiblePoolError)); - Wallet.createWallet("otherPoolName", "wallet", "default", null, null).get(); - Wallet wallet = Wallet.openWallet("wallet", null, null).get(); + String walletName = "incompatibleWallet"; + + Wallet.createWallet("otherPoolName", walletName, "default", null, null).get(); + Wallet wallet = Wallet.openWallet(walletName, null, null).get(); SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult trusteeDidResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String trusteeDid = trusteeDidResult.getDid(); @@ -124,6 +123,6 @@ public void testSignAndSubmitRequestWorksForIncompatibleWalletAndPool() throws E Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); wallet.closeWallet().get(); - Wallet.deleteWallet("wallet", null).get(); + Wallet.deleteWallet(walletName, null).get(); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/SchemaRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/SchemaRequestsTest.java index 36a49cff90..f7d06c7eac 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/SchemaRequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/SchemaRequestsTest.java @@ -11,10 +11,8 @@ import org.hyperledger.indy.sdk.wallet.Wallet; import org.json.JSONObject; import org.junit.*; -import org.junit.rules.Timeout; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import static junit.framework.TestCase.assertNull; import static org.junit.Assert.assertEquals; @@ -26,6 +24,7 @@ public class SchemaRequestsTest extends IndyIntegrationTest { private Pool pool; private Wallet wallet; private String walletName = "ledgerWallet"; + private String identifier = "Th7MpTaRZVRYnPiabds81Y"; @Before public void openPool() throws Exception { @@ -46,7 +45,6 @@ public void closePool() throws Exception { @Test public void testBuildSchemaRequestWorks() throws Exception { - String identifier = "Th7MpTaRZVRYnPiabds81Y"; String data = "{\"name\":\"name\", \"version\":\"1.0\", \"keys\":[\"name\",\"male\"]}"; String expectedResult = String.format("\"identifier\":\"%s\"," + @@ -63,7 +61,6 @@ public void testBuildSchemaRequestWorks() throws Exception { @Test public void testBuildGetSchemaRequestWorks() throws Exception { - String identifier = "Th7MpTaRZVRYnPiabds81Y"; String data = "{\"name\":\"name\",\"version\":\"1.0\"}"; String expectedResult = String.format("\"identifier\":\"%s\"," + @@ -85,7 +82,7 @@ public void testSchemaRequestWorksWithoutSignature() throws Exception { thrown.expectCause(new ErrorCodeMatcher(ErrorCode.LedgerInvalidTransaction)); SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult didResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String did = didResult.getDid(); @@ -104,7 +101,7 @@ public void testSchemaRequestWorksWithoutSignature() throws Exception { public void testSchemaRequestsWorks() throws Exception { SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult didResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String did = didResult.getDid(); @@ -129,7 +126,7 @@ public void testSchemaRequestsWorks() throws Exception { public void testGetSchemaRequestsWorksForUnknownSchema() throws Exception { SignusJSONParameters.CreateAndStoreMyDidJSONParameter trusteeDidJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); SignusResults.CreateAndStoreMyDidResult didResult = Signus.createAndStoreMyDid(wallet, trusteeDidJson.toJson()).get(); String did = didResult.getDid(); @@ -149,7 +146,6 @@ public void testBuildSchemaRequestWorksForMissedFields() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); - String identifier = "Th7MpTaRZVRYnPiabds81Y"; String data = "{\"name\":\"name\",\"version\":\"1.0\"}"; Ledger.buildSchemaRequest(identifier, data).get(); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java index 6f47f517cb..83718c9cae 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java @@ -19,17 +19,19 @@ public class CreateMyDidTest extends IndyIntegrationTest { private Wallet wallet; + private String walletName = "signusWallet"; @Before public void createWallet() throws Exception { - Wallet.createWallet("default", "signusWallet", "default", null, null).get(); - this.wallet = Wallet.openWallet("signusWallet", null, null).get(); + + Wallet.createWallet("default", walletName, "default", null, null).get(); + this.wallet = Wallet.openWallet(walletName, null, null).get(); } @After public void deleteWallet() throws Exception { this.wallet.closeWallet().get(); - Wallet.deleteWallet("signusWallet", null).get(); + Wallet.deleteWallet(walletName, null).get(); } private String seed = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; @@ -59,7 +61,8 @@ public void testCreateMyDidWorksForSeed() throws Exception { CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); assertNotNull(result); - assertEquals("NcYxiDXkpYi6ov5FcYDi1e", result.getDid()); + String expectedDid = "NcYxiDXkpYi6ov5FcYDi1e"; + assertEquals(expectedDid, result.getDid()); assertEquals(expectedVerkey, result.getVerkey()); } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/ReplaceKeysTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/ReplaceKeysTest.java index 03d732ad41..928f74e6bb 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/ReplaceKeysTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/ReplaceKeysTest.java @@ -22,16 +22,14 @@ public class ReplaceKeysTest extends IndyIntegrationTest { private Wallet wallet; private String did; private String verkey; + private String walletName = "signusWallet"; @Before public void createWalletWithDid() throws Exception { - Wallet.createWallet("default", "signusWallet", "default", null, null).get(); - wallet = Wallet.openWallet("signusWallet", null, null).get(); + Wallet.createWallet("default", walletName, "default", null, null).get(); + wallet = Wallet.openWallet(walletName, null, null).get(); - SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, null, null); - - CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); + CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, "{}").get(); did = result.getDid(); verkey = result.getVerkey(); @@ -40,7 +38,7 @@ public void createWalletWithDid() throws Exception { @After public void deleteWallet() throws Exception { wallet.closeWallet().get(); - Wallet.deleteWallet("signusWallet", null).get(); + Wallet.deleteWallet(walletName, null).get(); } @Test diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java index dc3cc7fd0a..842324adef 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java @@ -19,14 +19,15 @@ public class SignTest extends IndyIntegrationTest { private Wallet wallet; private String did; + private String walletName = "signusWallet"; @Before public void createWalletWhitDid() throws Exception { - Wallet.createWallet("default", "signusWallet", "default", null, null).get(); - this.wallet = Wallet.openWallet("signusWallet", null, null).get(); + Wallet.createWallet("default", walletName, "default", null, null).get(); + this.wallet = Wallet.openWallet(walletName, null, null).get(); SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); did = result.getDid(); @@ -35,7 +36,7 @@ public void createWalletWhitDid() throws Exception { @After public void deleteWallet() throws Exception { this.wallet.closeWallet().get(); - Wallet.deleteWallet("signusWallet", null).get(); + Wallet.deleteWallet(walletName, null).get(); } @Test diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/StoreTheirDidTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/StoreTheirDidTest.java index 78fefd12b7..97a5d6fe39 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/StoreTheirDidTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/StoreTheirDidTest.java @@ -14,11 +14,14 @@ public class StoreTheirDidTest extends IndyIntegrationTest { private Wallet wallet; + private String walletName = "signusWallet"; + private String did = "8wZcEriaNLNKtteJvx7f8i"; + private String verkey = "GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa"; @Before public void createWallet() throws Exception { - Wallet.createWallet("default", "signusWallet", "default", null, null).get(); - this.wallet = Wallet.openWallet("signusWallet", null, null).get(); + Wallet.createWallet("default", walletName, "default", null, null).get(); + this.wallet = Wallet.openWallet(walletName, null, null).get(); } @@ -26,12 +29,12 @@ public void createWallet() throws Exception { public void deleteWallet() throws Exception { this.wallet.closeWallet().get(); - Wallet.deleteWallet("signusWallet", null).get(); + Wallet.deleteWallet(walletName, null).get(); } @Test public void testStoreTheirDidWorks() throws Exception { - Signus.storeTheirDid(this.wallet, "{\"did\":\"8wZcEriaNLNKtteJvx7f8i\"}").get(); + Signus.storeTheirDid(this.wallet, String.format("{\"did\":\"%s\"}", did)).get(); } @Test @@ -44,8 +47,7 @@ public void testCreateMyDidWorksForInvalidIdentityJson() throws Exception { @Test public void testStoreTheirDidWorksWithVerkey() throws Exception { - Signus.storeTheirDid(this.wallet, "{\"did\":\"8wZcEriaNLNKtteJvx7f8i\", " + - "\"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\"}").get(); + Signus.storeTheirDid(this.wallet, String.format("{\"did\":\"%s\", \"verkey\":\"%s\"}", did, verkey)).get(); } @Test @@ -53,13 +55,12 @@ public void testStoreTheirDidWorksWithoutDid() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonInvalidStructure)); - Signus.storeTheirDid(this.wallet, "{\"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\"}").get(); + Signus.storeTheirDid(this.wallet, String.format("{\"verkey\":\"%s\"}", verkey)).get(); } @Test public void testStoreTheirDidWorksForCorrectCryptoType() throws Exception { - Signus.storeTheirDid(this.wallet, "{\"did\":\"8wZcEriaNLNKtteJvx7f8i\", " + - "\"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\", \"crypto_type\": \"ed25519\"}").get(); + Signus.storeTheirDid(this.wallet, String.format("{\"did\":\"%s\", \"verkey\":\"%s\", \"crypto_type\": \"ed25519\"}", did, verkey)).get(); } @Test @@ -67,7 +68,6 @@ public void testStoreTheirDidWorksForInvalidCryptoType() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.SignusUnknownCryptoError)); - Signus.storeTheirDid(this.wallet, "{\"did\":\"8wZcEriaNLNKtteJvx7f8i\", " + - "\"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\", \"crypto_type\": \"some_type\"}").get(); + Signus.storeTheirDid(this.wallet, String.format("{\"did\":\"%s\", \"verkey\":\"%s\", \"crypto_type\": \"some_type\"}", did, verkey)).get(); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java index ebc5f0a34f..02fb556c76 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java @@ -30,6 +30,7 @@ public class VerifyTest extends IndyIntegrationTest { private String trusteeVerkey; private String identityJson; private String newDid; + private String walletName = "signusWallet"; @Before public void createWalletWithDid() throws Exception { @@ -38,11 +39,11 @@ public void createWalletWithDid() throws Exception { PoolJSONParameters.OpenPoolLedgerJSONParameter config2 = new PoolJSONParameters.OpenPoolLedgerJSONParameter(null, null, null); pool = Pool.openPoolLedger(poolName, config2.toJson()).get(); - Wallet.createWallet(poolName, "signusWallet", "default", null, null).get(); - wallet = Wallet.openWallet("signusWallet", null, null).get(); + Wallet.createWallet(poolName, walletName, "default", null, null).get(); + wallet = Wallet.openWallet(walletName, null, null).get(); SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Trustee1", null, false); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, false); CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(wallet, didJson.toJson()).get(); assertNotNull(result); @@ -54,7 +55,7 @@ public void createWalletWithDid() throws Exception { @After public void deleteWallet() throws Exception { wallet.closeWallet().get(); - Wallet.deleteWallet("signusWallet", null).get(); + Wallet.deleteWallet(walletName, null).get(); pool.closePoolLedger().get(); } @@ -93,8 +94,7 @@ public void testVerifyWorksForVerkeyCachedInWallet() throws Exception { @Test public void testVerifyWorksForGetVerkeyFromLedger() throws Exception { createNewNymWithDidInLedger(); - identityJson = String.format("{\"did\":\"%s\"}", newDid); - Signus.storeTheirDid(wallet, identityJson).get(); + Signus.storeTheirDid(wallet, String.format("{\"did\":\"%s\"}", newDid)).get(); String msg = "{\"reqId\":1496822211362017764,\n" + "\"signature\":\"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai\"}"; diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java index 3767bb93e5..29bd43510f 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CloseWalletTest.java @@ -3,7 +3,9 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; + import static org.junit.Assert.assertNotNull; + import org.junit.Test; import java.util.concurrent.ExecutionException; @@ -14,9 +16,11 @@ public class CloseWalletTest extends IndyIntegrationTest { @Test public void testCloseWalletWorks() throws Exception { - Wallet.createWallet("default", "closeWalletWorks", "default", null, null).get(); + String walletName = "closeWalletWorks"; + + Wallet.createWallet("default", walletName, "default", null, null).get(); - Wallet wallet = Wallet.openWallet("closeWalletWorks", null, null).get(); + Wallet wallet = Wallet.openWallet(walletName, null, null).get(); assertNotNull(wallet); wallet.closeWallet().get(); @@ -28,12 +32,31 @@ public void testCloseWalletWorksForTwice() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletInvalidHandle)); - Wallet.createWallet("default", "closeWalletWorksForTwice", "default", null, null).get(); + String walletName = "closeWalletWorksForTwice"; - Wallet wallet = Wallet.openWallet("closeWalletWorksForTwice", null, null).get(); + Wallet.createWallet("default", walletName, "default", null, null).get(); + + Wallet wallet = Wallet.openWallet(walletName, null, null).get(); assertNotNull(wallet); wallet.closeWallet().get(); wallet.closeWallet().get(); } + + @Test + public void testCloseWalletWorksForPlugged() throws Exception { + WalletTypeInmem.getInstance().clear(); + + String type = "inmem"; + String walletName = "testCloseWalletWorksForPlugged"; + + Wallet.registerWalletType(type, WalletTypeInmem.getInstance(), false).get(); + Wallet.createWallet("default", walletName, type, null, null).get(); + + Wallet wallet = Wallet.openWallet(walletName, null, null).get(); + wallet.closeWallet().get(); + Wallet.openWallet(walletName, null, null).get(); + + WalletTypeInmem.getInstance().clear(); + } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java index afe55cf586..50d6d5b597 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java @@ -16,6 +16,16 @@ public void testCreateWalletWorks() throws Exception { Wallet.createWallet("default", "createWalletWorks", "default", null, null).get(); } + @Test + public void testCreateWalletWorksForPlugged() throws Exception { + WalletTypeInmem.getInstance().clear(); + + Wallet.registerWalletType("inmem", WalletTypeInmem.getInstance(), false).get(); + Wallet.createWallet("default", "createWalletWorks", "default", null, null).get(); + + WalletTypeInmem.getInstance().clear(); + } + @Test public void testCreateWalletWorksForEmptyType() throws Exception { @@ -51,7 +61,11 @@ public void testCreateWalletWorksForDuplicateName() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletAlreadyExistsError)); - Wallet.createWallet("default", "createWalletWorks", "default", null, null).get(); - Wallet.createWallet("default", "createWalletWorks", "default", null, null).get(); + String poolName = "default"; + String walletName = "deleteWalletWorks"; + String type = "default"; + + Wallet.createWallet(poolName, walletName, type, null, null).get(); + Wallet.createWallet(poolName, walletName, type, null, null).get(); } } \ No newline at end of file diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java index 2f63eebbc4..179b62bb86 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java @@ -3,7 +3,9 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; + import static org.junit.Assert.assertNotNull; + import org.junit.Ignore; import org.junit.Test; @@ -15,22 +17,29 @@ public class DeleteWalletTest extends IndyIntegrationTest { @Test public void testDeleteWalletWorks() throws Exception { - Wallet.createWallet("default", "deleteWalletWorks", "default", null, null).get(); - Wallet.deleteWallet("deleteWalletWorks", null).get(); - Wallet.createWallet("default", "deleteWalletWorks", "default", null, null).get(); + String poolName = "default"; + String walletName = "deleteWalletWorks"; + String type = "default"; + + Wallet.createWallet(poolName, walletName, type, null, null).get(); + Wallet.deleteWallet(walletName, null).get(); + Wallet.createWallet(poolName, walletName, type, null, null).get(); } @Test public void testDeleteWalletWorksForClosed() throws Exception { - Wallet.createWallet("default", "deleteWalletWorksForClosed", null, null, null).get(); + String poolName = "default"; + String walletName = "deleteWalletWorksForOpened"; + + Wallet.createWallet(poolName, walletName, null, null, null).get(); - Wallet wallet = Wallet.openWallet("deleteWalletWorksForClosed", null, null).get(); + Wallet wallet = Wallet.openWallet(walletName, null, null).get(); assertNotNull(wallet); wallet.closeWallet().get(); - Wallet.deleteWallet("deleteWalletWorksForClosed", null).get(); - Wallet.createWallet("default", "deleteWalletWorksForClosed", null, null, null).get(); + Wallet.deleteWallet(walletName, null).get(); + Wallet.createWallet(poolName, walletName, null, null, null).get(); } @Test @@ -40,9 +49,11 @@ public void testDeleteWalletWorksForOpened() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonIOError)); - Wallet.createWallet("default", "deleteWalletWorksForOpened", null, null, null).get(); - Wallet.openWallet("deleteWalletWorksForOpened", null, null).get(); - Wallet.deleteWallet("deleteWalletWorksForOpened", null).get(); + String walletName = "deleteWalletWorksForOpened"; + + Wallet.createWallet("default", walletName, null, null, null).get(); + Wallet.openWallet(walletName, null, null).get(); + Wallet.deleteWallet(walletName, null).get(); } @Test @@ -51,15 +62,33 @@ public void testDeleteWalletWorksForTwice() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonIOError)); - Wallet.createWallet("default", "deleteWalletWorksForTwice", null, null, null).get(); + String walletName = "deleteWalletWorksForTwice"; + + Wallet.createWallet("default", walletName, null, null, null).get(); - Wallet wallet = Wallet.openWallet("deleteWalletWorksForTwice", null, null).get(); + Wallet wallet = Wallet.openWallet(walletName, null, null).get(); assertNotNull(wallet); wallet.closeWallet().get(); - Wallet.deleteWallet("deleteWalletWorksForTwice", null).get(); - Wallet.deleteWallet("deleteWalletWorksForTwice", null).get(); + Wallet.deleteWallet(walletName, null).get(); + Wallet.deleteWallet(walletName, null).get(); + } + + @Test + public void testDeleteWalletWorksForPlugged() throws Exception { + WalletTypeInmem.getInstance().clear(); + + String type = "inmem"; + String poolName = "default"; + String walletName = "wallet"; + + Wallet.registerWalletType(type, WalletTypeInmem.getInstance(), false).get(); + Wallet.createWallet(poolName, walletName, type, null, null).get(); + Wallet.deleteWallet(walletName, null).get(); + Wallet.createWallet(poolName, walletName, type, null, null).get(); + + WalletTypeInmem.getInstance().clear(); } @Test diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java index e016959b69..068833453e 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java @@ -3,7 +3,9 @@ import org.hyperledger.indy.sdk.ErrorCode; import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; + import static org.junit.Assert.assertNotNull; + import org.junit.Test; import java.util.concurrent.ExecutionException; @@ -14,22 +16,41 @@ public class OpenWalletTest extends IndyIntegrationTest { @Test public void testOpenWalletWorks() throws Exception { - Wallet.createWallet("default", "openWalletWorks", "default", null, null).get(); + String walletName = "deleteWalletWorks"; - Wallet wallet = Wallet.openWallet("openWalletWorks", null, null).get(); - assertNotNull(wallet); + Wallet.createWallet("default", walletName, "default", null, null).get(); + Wallet wallet = Wallet.openWallet(walletName, null, null).get(); + assertNotNull(wallet); } @Test public void testOpenWalletWorksForConfig() throws Exception { - Wallet.createWallet("default", "openWalletWorksForConfig", "default", null, null).get(); + String walletName = "openWalletWorksForConfig"; - Wallet wallet = Wallet.openWallet("openWalletWorksForConfig", "{\"freshness_time\":1000}", null).get(); + Wallet.createWallet("default", walletName, "default", null, null).get(); + + Wallet wallet = Wallet.openWallet(walletName, "{\"freshness_time\":1000}", null).get(); assertNotNull(wallet); } + @Test + public void testOpenWalletWorksForPlugged() throws Exception { + WalletTypeInmem.getInstance().clear(); + + String type = "inmem"; + String poolName = "default"; + String walletName = "testOpenWalletWorksForPlugged"; + + Wallet.registerWalletType(type, WalletTypeInmem.getInstance(), false).get(); + Wallet.createWallet(poolName, walletName, type, null, null).get(); + Wallet wallet = Wallet.openWallet(walletName, null, null).get(); + assertNotNull(wallet); + + WalletTypeInmem.getInstance().clear(); + } + @Test public void testOpenWalletWorksForNotCreatedWallet() throws Exception { @@ -45,10 +66,12 @@ public void testOpenWalletWorksForTwice() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletAlreadyOpenedError)); - Wallet.createWallet("default", "openWalletWorksForTwice", "default", null, null).get(); + String walletName = "openWalletWorksForTwice"; + + Wallet.createWallet("default", walletName, "default", null, null).get(); - Wallet.openWallet("openWalletWorksForTwice", null, null).get(); - Wallet.openWallet("openWalletWorksForTwice", null, null).get(); + Wallet.openWallet(walletName, null, null).get(); + Wallet.openWallet(walletName, null, null).get(); } @Test diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/RegisterWalletTypeTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/RegisterWalletTypeTest.java index 191c0b554d..9a130298f3 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/RegisterWalletTypeTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/RegisterWalletTypeTest.java @@ -1,34 +1,35 @@ package org.hyperledger.indy.sdk.wallet; -import static org.junit.Assert.assertNotNull; +import org.hyperledger.indy.sdk.ErrorCode; +import org.hyperledger.indy.sdk.ErrorCodeMatcher; import org.hyperledger.indy.sdk.IndyIntegrationTest; -import org.hyperledger.indy.sdk.signus.Signus; -import org.hyperledger.indy.sdk.signus.SignusJSONParameters.CreateAndStoreMyDidJSONParameter; -import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; + import org.junit.Test; +import java.util.concurrent.ExecutionException; + public class RegisterWalletTypeTest extends IndyIntegrationTest { @Test public void testRegisterWalletTypeWorks() throws Exception { + WalletTypeInmem.getInstance().clear(); - Wallet.registerWalletType("inmem", WalletTypeInmem.getInstance()); - - Wallet.createWallet("default", "registerWalletTypeWorks", "inmem", null, null).get(); + Wallet.registerWalletType("inmem", WalletTypeInmem.getInstance(), false).get(); - Wallet wallet = Wallet.openWallet("registerWalletTypeWorks", null, null).get(); - assertNotNull(wallet); + WalletTypeInmem.getInstance().clear(); + } + + @Test + public void testRegisterWalletTypeDoesNotWorkForTwiceWithSameName() throws Exception { - CreateAndStoreMyDidJSONParameter createAndStoreMyDidJSONParameter = new CreateAndStoreMyDidJSONParameter(null, null, null, null); - CreateAndStoreMyDidResult createAndStoreMyDidResult = Signus.createAndStoreMyDid(wallet, createAndStoreMyDidJSONParameter.toJson()).get(); - String did = createAndStoreMyDidResult.getDid(); + thrown.expect(ExecutionException.class); + thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletTypeAlreadyRegisteredError)); -/* String nymRequest = Ledger.buildGetNymRequest(did, did).get(); - String signature = Signus.sign(wallet, did, nymRequest).get(); - Signus.verifySignature(wallet, null, did, signature);*/ + String type = "inmem"; - wallet.closeWallet().get(); + Wallet.registerWalletType(type, WalletTypeInmem.getInstance(), false).get(); + Wallet.registerWalletType(type, WalletTypeInmem.getInstance(), true).get(); } } From 64866d217fd53f1d035b959c2f079630d4e84516 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 24 Jul 2017 10:17:41 +0300 Subject: [PATCH 306/349] added test for prover_store_claim_offer --- .../test_prover_store_claim_offer.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 wrappers/python/tests/anoncreds/test_prover_store_claim_offer.py diff --git a/wrappers/python/tests/anoncreds/test_prover_store_claim_offer.py b/wrappers/python/tests/anoncreds/test_prover_store_claim_offer.py new file mode 100644 index 0000000000..b65271b513 --- /dev/null +++ b/wrappers/python/tests/anoncreds/test_prover_store_claim_offer.py @@ -0,0 +1,33 @@ +from indy import wallet +from indy.anoncreds import prover_store_claim_offer + +from tests.utils import storage, anoncreds +from tests.utils.wallet import create_and_open_wallet + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.fixture +async def wallet_handle(): + handle = await create_and_open_wallet() + await anoncreds.prepare_common_wallet(handle) + yield handle + await wallet.close_wallet(handle) + + +@pytest.mark.asyncio +async def test_prover_store_claim_offer_works(wallet_handle): + claim_offer = anoncreds.get_claim_offer(anoncreds.ISSUER_DID, 1) + await prover_store_claim_offer(wallet_handle, json.dumps(claim_offer)) + From a644a78c46d0f531f2b4d88179574ca4305f7e4d Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 24 Jul 2017 10:35:31 +0300 Subject: [PATCH 307/349] Changed package name from indy-sdk to indy --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2398bd8059..e95f284856 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "indy-sdk" +name = "indy" version = "0.1.1" authors = [ "Sergej Pupykin ", From 5ce5d9fa7fe98b710f7b8e413d198248d782426e Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 24 Jul 2017 10:46:22 +0300 Subject: [PATCH 308/349] small changes for api calls --- wrappers/python/indy/anoncreds.py | 52 +++++++++++++++---------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/wrappers/python/indy/anoncreds.py b/wrappers/python/indy/anoncreds.py index a4608c4164..423c84d1f3 100644 --- a/wrappers/python/indy/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -46,12 +46,12 @@ async def issuer_create_and_store_claim_def(wallet_handle: int, c_create_non_revoc = c_bool(create_non_revoc) claim_def_json = await do_call('indy_issuer_create_and_store_claim_def', - issuer_create_and_store_claim_def.cb, c_wallet_handle, c_issuer_did, c_schema_json, c_signature_type, - c_create_non_revoc) + c_create_non_revoc, + issuer_create_and_store_claim_def.cb) res = claim_def_json.decode() logger.debug("issuer_create_and_store_claim_def: <<< res: %r", res) return res @@ -91,11 +91,11 @@ async def issuer_create_and_store_revoc_reg(wallet_handle: int, c_max_claim_num = c_int32(max_claim_num) (revoc_reg_json, revoc_reg_uuid) = await do_call('indy_issuer_create_and_store_revoc_reg', - issuer_create_and_store_revoc_reg.cb, c_wallet_handle, c_issuer_did, c_schema_seq_no, - c_max_claim_num) + c_max_claim_num, + issuer_create_and_store_revoc_reg.cb) res = (revoc_reg_json.decode(), revoc_reg_uuid.decode()) logger.debug("issuer_create_and_store_revoc_reg: <<< res: %r", res) return res @@ -163,12 +163,12 @@ async def issuer_create_claim(wallet_handle: int, c_user_revoc_index = c_int32(user_revoc_index) (revoc_reg_update_json, claim_json) = await do_call('indy_issuer_create_claim', - issuer_create_claim.cb, c_wallet_handle, c_claim_req_json, c_claim_json, c_revoc_reg_seq_no, - c_user_revoc_index) + c_user_revoc_index, + issuer_create_claim.cb) res = (revoc_reg_update_json.decode(), claim_json.decode()) logger.debug("issuer_create_claim: <<< res: %r", res) return res @@ -203,10 +203,10 @@ async def issuer_revoke_claim(wallet_handle: int, c_user_revoc_index = c_int32(user_revoc_index) revoc_reg_update_json = await do_call('indy_issuer_revoke_claim', - issuer_revoke_claim.cb, c_wallet_handle, c_revoc_reg_seq_no, - c_user_revoc_index) + c_user_revoc_index, + issuer_revoke_claim.cb) res = revoc_reg_update_json.decode() logger.debug("issuer_revoke_claim: <<< res: %r", res) return res @@ -239,9 +239,9 @@ async def prover_store_claim_offer(wallet_handle: int, c_claim_offer_json = c_char_p(claim_offer_json.encode('utf-8')) res = await do_call('indy_prover_store_claim_offer', - prover_store_claim_offer.cb, c_wallet_handle, - c_claim_offer_json) + c_claim_offer_json, + prover_store_claim_offer.cb) logger.debug("prover_store_claim_offer: <<< res: %r", res) return res @@ -280,9 +280,9 @@ async def prover_get_claim_offers(wallet_handle: int, c_filter_json = c_char_p(filter_json.encode('utf-8')) claim_offers_json = await do_call('indy_prover_get_claim_offers', - prover_get_claim_offers.cb, c_wallet_handle, - c_filter_json) + c_filter_json, + prover_get_claim_offers.cb) res = claim_offers_json.decode() logger.debug("prover_get_claim_offers: <<< res: %r", res) @@ -313,9 +313,9 @@ async def prover_create_master_secret(wallet_handle: int, c_master_secret_name = c_char_p(master_secret_name.encode('utf-8')) res = await do_call('indy_prover_create_master_secret', - prover_create_master_secret.cb, c_wallet_handle, - c_master_secret_name) + c_master_secret_name, + prover_create_master_secret.cb) logger.debug("prover_create_master_secret: <<< res: %r", res) return res @@ -372,12 +372,12 @@ async def prover_create_and_store_claim_req(wallet_handle: int, c_master_secret_name = c_char_p(master_secret_name.encode('utf-8')) claim_req_json = await do_call('indy_prover_create_and_store_claim_req', - prover_create_and_store_claim_req.cb, c_wallet_handle, c_prover_did, c_claim_offer_json, c_claim_def_json, - c_master_secret_name) + c_master_secret_name, + prover_create_and_store_claim_req.cb) res = claim_req_json.decode() logger.debug("prover_create_and_store_claim_req: <<< res: %r", res) @@ -419,9 +419,9 @@ async def prover_store_claim(wallet_handle: int, c_claims_json = c_char_p(claims_json.encode('utf-8')) res = await do_call('indy_prover_store_claim', - prover_store_claim.cb, c_wallet_handle, - c_claims_json) + c_claims_json, + prover_store_claim.cb) logger.debug("prover_store_claim: <<< res: %r", res) return res @@ -463,9 +463,9 @@ async def prover_get_claims(wallet_handle: int, c_filter_json = c_char_p(filter_json.encode('utf-8')) claims_json = await do_call('indy_prover_get_claims', - prover_get_claims.cb, c_wallet_handle, - c_filter_json) + c_filter_json, + prover_get_claims.cb) res = claims_json.decode() logger.debug("prover_get_claims: <<< res: %r", res) @@ -520,9 +520,9 @@ async def prover_get_claims_for_proof_req(wallet_handle: int, c_proof_request_json = c_char_p(proof_request_json.encode('utf-8')) claims_json = await do_call('indy_prover_get_claims_for_proof_req', - prover_get_claims_for_proof_req.cb, c_wallet_handle, - c_proof_request_json) + c_proof_request_json, + prover_get_claims_for_proof_req.cb) res = claims_json.decode() logger.debug("prover_get_claims_for_proof_req: <<< res: %r", res) @@ -632,14 +632,14 @@ async def prover_create_proof(wallet_handle: int, c_revoc_regs_json = c_char_p(revoc_regs_json.encode('utf-8')) proof_json = await do_call('indy_prover_create_proof', - prover_create_proof.cb, c_wallet_handle, c_proof_req_json, c_requested_claims_json, c_schemas_json, c_master_secret_name, c_claim_defs_json, - c_revoc_regs_json) + c_revoc_regs_json, + prover_create_proof.cb) res = proof_json.decode() logger.debug("prover_create_proof: <<< res: %r", res) @@ -730,13 +730,13 @@ async def verifier_verify_proof(wallet_handle: int, c_revoc_regs_json = c_char_p(revoc_regs_json.encode('utf-8')) res = await do_call('indy_verifier_verify_proof', - verifier_verify_proof.cb, c_wallet_handle, c_proof_request_json, c_proof_json, c_schemas_json, c_claim_defs_jsons, - c_revoc_regs_json) + c_revoc_regs_json, + verifier_verify_proof.cb) logger.debug("verifier_verify_proof: <<< res: %r", res) return res From 0951a7b6ab48c2f827c7a706355e1a3a898b805d Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 24 Jul 2017 10:56:17 +0300 Subject: [PATCH 309/349] added test for prover_get_claim_offers --- .../anoncreds/test_prover_get_claim_offers.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 wrappers/python/tests/anoncreds/test_prover_get_claim_offers.py diff --git a/wrappers/python/tests/anoncreds/test_prover_get_claim_offers.py b/wrappers/python/tests/anoncreds/test_prover_get_claim_offers.py new file mode 100644 index 0000000000..fd549b3cee --- /dev/null +++ b/wrappers/python/tests/anoncreds/test_prover_get_claim_offers.py @@ -0,0 +1,33 @@ +from indy import wallet +from indy.anoncreds import prover_get_claim_offers + +from tests.utils import storage, anoncreds +from tests.utils.wallet import create_and_open_wallet + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.fixture +async def wallet_handle(): + handle = await create_and_open_wallet() + await anoncreds.prepare_common_wallet(handle) + yield handle + await wallet.close_wallet(handle) + + +@pytest.mark.asyncio +async def test_prover_get_claim_offers_works_for_empty_filter(wallet_handle): + claim_offers = json.loads(await prover_get_claim_offers(wallet_handle, "{}")) + assert len(claim_offers) == 3 + From 74370742787559dcaf0fb02ab990761decb67cdc Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 24 Jul 2017 10:59:14 +0300 Subject: [PATCH 310/349] added test for prover_create_master_secret --- .../test_prover_create_master_secret.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 wrappers/python/tests/anoncreds/test_prover_create_master_secret.py diff --git a/wrappers/python/tests/anoncreds/test_prover_create_master_secret.py b/wrappers/python/tests/anoncreds/test_prover_create_master_secret.py new file mode 100644 index 0000000000..016b17b497 --- /dev/null +++ b/wrappers/python/tests/anoncreds/test_prover_create_master_secret.py @@ -0,0 +1,31 @@ +from indy import wallet +from indy.anoncreds import prover_create_master_secret + +from tests.utils import storage, anoncreds +from tests.utils.wallet import create_and_open_wallet + +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.fixture +async def wallet_handle(): + handle = await create_and_open_wallet() + await anoncreds.prepare_common_wallet(handle) + yield handle + await wallet.close_wallet(handle) + + +@pytest.mark.asyncio +async def test_prover_create_master_secret_works(wallet_handle): + await prover_create_master_secret(wallet_handle, "master_secret_name") + From 3b6f94bedb69313e9db47a1cc3693104f198d3ec Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 24 Jul 2017 11:25:35 +0300 Subject: [PATCH 311/349] added test for prover_create_and_store_claim_req --- .../test_prover_create_and_store_claim_req.py | 40 +++++++++++++++++++ wrappers/python/tests/utils/anoncreds.py | 2 + 2 files changed, 42 insertions(+) create mode 100644 wrappers/python/tests/anoncreds/test_prover_create_and_store_claim_req.py diff --git a/wrappers/python/tests/anoncreds/test_prover_create_and_store_claim_req.py b/wrappers/python/tests/anoncreds/test_prover_create_and_store_claim_req.py new file mode 100644 index 0000000000..47df68bb74 --- /dev/null +++ b/wrappers/python/tests/anoncreds/test_prover_create_and_store_claim_req.py @@ -0,0 +1,40 @@ +from indy import wallet +from indy.anoncreds import prover_create_and_store_claim_req + +from tests.utils import storage, anoncreds +from tests.utils.wallet import create_and_open_wallet + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.fixture +async def wallet_handle_and_claim_def(): + handle = await create_and_open_wallet() + claim_def = await anoncreds.prepare_common_wallet(handle) + yield (handle, claim_def) + await wallet.close_wallet(handle) + + +@pytest.mark.asyncio +async def test_prover_create_and_store_claim_req_works(wallet_handle_and_claim_def): + schema_seq_no = 1 + prover_did = "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW" + claim_offer_json = anoncreds.get_claim_offer(anoncreds.ISSUER_DID, schema_seq_no) + claim_req_json = json.loads(await prover_create_and_store_claim_req(wallet_handle_and_claim_def[0], prover_did, + json.dumps(claim_offer_json), + wallet_handle_and_claim_def[1], + anoncreds.COMMON_MASTER_SECRET_NAME)) + assert claim_req_json['schema_seq_no'] == schema_seq_no + assert claim_req_json['issuer_did'] == anoncreds.ISSUER_DID + assert len(claim_req_json['blinded_ms']['u']) > 0 diff --git a/wrappers/python/tests/utils/anoncreds.py b/wrappers/python/tests/utils/anoncreds.py index 6dc381db83..0ea11b1152 100644 --- a/wrappers/python/tests/utils/anoncreds.py +++ b/wrappers/python/tests/utils/anoncreds.py @@ -26,6 +26,8 @@ async def prepare_common_wallet(wallet_handle): wallet_handle, claim_req, json.dumps(get_gvt_claim_json()), -1, -1) await anoncreds.prover_store_claim(wallet_handle, claim_json) + return claim_def_json + def get_claim_offer(issuer_did, schema_seq_no): return {"issuer_did": issuer_did, "schema_seq_no": schema_seq_no} From a0e1cd63d6fd9d099b26dbe86f1b00ec65e231f8 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 24 Jul 2017 11:37:59 +0300 Subject: [PATCH 312/349] added test for prover_store_claim_works --- .../anoncreds/test_prover_store_claim.py | 42 +++++++++++++++++++ wrappers/python/tests/utils/anoncreds.py | 1 + 2 files changed, 43 insertions(+) create mode 100644 wrappers/python/tests/anoncreds/test_prover_store_claim.py diff --git a/wrappers/python/tests/anoncreds/test_prover_store_claim.py b/wrappers/python/tests/anoncreds/test_prover_store_claim.py new file mode 100644 index 0000000000..64fc5d0f6b --- /dev/null +++ b/wrappers/python/tests/anoncreds/test_prover_store_claim.py @@ -0,0 +1,42 @@ +from indy import wallet +from indy.anoncreds import prover_create_and_store_claim_req, prover_store_claim,\ + prover_create_master_secret, issuer_create_claim + +from tests.utils import storage, anoncreds +from tests.utils.wallet import create_and_open_wallet + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.fixture +async def wallet_handle_and_claim_def(): + handle = await create_and_open_wallet() + claim_def = await anoncreds.prepare_common_wallet(handle) + yield (handle, claim_def) + await wallet.close_wallet(handle) + + +@pytest.mark.asyncio +async def test_prover_store_claim_works(wallet_handle_and_claim_def): + prover_did = "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW" + claim_offer_json = anoncreds.get_claim_offer(anoncreds.ISSUER_DID, 1) + await prover_create_master_secret(wallet_handle_and_claim_def[0], anoncreds.COMMON_MASTER_SECRET_NAME_1) + claim_req = await prover_create_and_store_claim_req(wallet_handle_and_claim_def[0], prover_did, + json.dumps(claim_offer_json), wallet_handle_and_claim_def[1], + anoncreds.COMMON_MASTER_SECRET_NAME_1) + + (_, claim_json) = await issuer_create_claim(wallet_handle_and_claim_def[0], claim_req, + json.dumps(anoncreds.get_gvt_claim_json()), -1, -1) + await prover_store_claim(wallet_handle_and_claim_def[0], claim_json) + diff --git a/wrappers/python/tests/utils/anoncreds.py b/wrappers/python/tests/utils/anoncreds.py index 0ea11b1152..f2c1c66723 100644 --- a/wrappers/python/tests/utils/anoncreds.py +++ b/wrappers/python/tests/utils/anoncreds.py @@ -5,6 +5,7 @@ ISSUER_DID = "NcYxiDXkpYi6ov5FcYDi1e" COMMON_SCHEMA_SEQ_NO = 1 COMMON_MASTER_SECRET_NAME = "common_master_secret_name" +COMMON_MASTER_SECRET_NAME_1 = "common_master_secret_name_1" async def prepare_common_wallet(wallet_handle): From c2e4b9967f3c06e886e15cab3805a32667017545 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 24 Jul 2017 11:40:07 +0300 Subject: [PATCH 313/349] added test for prover_get_claims --- .../tests/anoncreds/test_prover_get_claims.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 wrappers/python/tests/anoncreds/test_prover_get_claims.py diff --git a/wrappers/python/tests/anoncreds/test_prover_get_claims.py b/wrappers/python/tests/anoncreds/test_prover_get_claims.py new file mode 100644 index 0000000000..017365ca8a --- /dev/null +++ b/wrappers/python/tests/anoncreds/test_prover_get_claims.py @@ -0,0 +1,33 @@ +from indy import wallet +from indy.anoncreds import prover_get_claims + +from tests.utils import storage, anoncreds +from tests.utils.wallet import create_and_open_wallet + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.fixture +async def wallet_handle(): + handle = await create_and_open_wallet() + await anoncreds.prepare_common_wallet(handle) + yield handle + await wallet.close_wallet(handle) + + +@pytest.mark.asyncio +async def test_prover_get_claims_works_for_empty_filter(wallet_handle): + claims = json.loads(await prover_get_claims(wallet_handle, "{}")) + assert len(claims) == 1 + From c3c4cdab369a3b1f307616b69695d240be8ed132 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 24 Jul 2017 11:45:07 +0300 Subject: [PATCH 314/349] added test for get_claims_for_proof_req --- .../test_prover_get_claims_for_proof_req.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 wrappers/python/tests/anoncreds/test_prover_get_claims_for_proof_req.py diff --git a/wrappers/python/tests/anoncreds/test_prover_get_claims_for_proof_req.py b/wrappers/python/tests/anoncreds/test_prover_get_claims_for_proof_req.py new file mode 100644 index 0000000000..b385d47390 --- /dev/null +++ b/wrappers/python/tests/anoncreds/test_prover_get_claims_for_proof_req.py @@ -0,0 +1,47 @@ +from indy import wallet +from indy.anoncreds import prover_get_claims_for_proof_req + +from tests.utils import storage, anoncreds +from tests.utils.wallet import create_and_open_wallet + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.fixture +async def wallet_handle(): + handle = await create_and_open_wallet() + await anoncreds.prepare_common_wallet(handle) + yield handle + await wallet.close_wallet(handle) + + +@pytest.mark.asyncio +async def test_prover_get_claims_for_proof_req_works_for_revealed_attr(wallet_handle): + proof_req = { + "nonce": "123432421212", + "name": "proof_req_1", + "version": "0.1", + "requested_attrs": { + "attr1_uuid": { + "schema_seq_no": 1, + "name": "name" + } + }, + "requested_predicates": {} + } + + claims = json.loads(await prover_get_claims_for_proof_req(wallet_handle, json.dumps(proof_req))) + assert len(claims['attrs']) == 1 + assert len(claims['predicates']) == 0 + assert len(claims['attrs']['attr1_uuid']) == 1 From 5918ac6c49a32a7fda22ce43d11e67863c6ccd94 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 24 Jul 2017 12:24:02 +0300 Subject: [PATCH 315/349] added test for prover_create_proof --- .../anoncreds/test_prover_create_proof.py | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 wrappers/python/tests/anoncreds/test_prover_create_proof.py diff --git a/wrappers/python/tests/anoncreds/test_prover_create_proof.py b/wrappers/python/tests/anoncreds/test_prover_create_proof.py new file mode 100644 index 0000000000..ccbdc7d7dd --- /dev/null +++ b/wrappers/python/tests/anoncreds/test_prover_create_proof.py @@ -0,0 +1,75 @@ +from indy import wallet +from indy.anoncreds import prover_get_claims_for_proof_req, prover_create_proof + +from tests.utils import storage, anoncreds +from tests.utils.wallet import create_and_open_wallet + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.fixture +async def wallet_handle_and_claim_def(): + handle = await create_and_open_wallet() + claim_def = await anoncreds.prepare_common_wallet(handle) + yield (handle, claim_def) + await wallet.close_wallet(handle) + + +@pytest.mark.asyncio +async def test_prover_create_proof_works(wallet_handle_and_claim_def): + proof_req = { + "nonce": "123432421212", + "name": "proof_req_1", + "version": "0.1", + "requested_attrs": { + "attr1_uuid": { + "schema_seq_no": 1, + "name": "name" + } + }, + "requested_predicates": { + "predicate1_uuid": { + "attr_name": "age", + "p_type": "GE", + "value": 18 + } + } + } + + claims = json.loads(await prover_get_claims_for_proof_req(wallet_handle_and_claim_def[0], json.dumps(proof_req))) + claim_for_attr = claims['attrs']['attr1_uuid'][0]['claim_uuid'] + claim_for_predicate = claims['predicates']['predicate1_uuid'][0]['claim_uuid'] + requested_claims = { + "self_attested_attributes": {}, + "requested_attrs": { + "attr1_uuid": [claim_for_attr, True] + }, + "requested_predicates": { + "predicate1_uuid": claim_for_predicate + } + } + + print("requested_claims = {}".format(json.dumps(requested_claims))) + + schemas = { + claim_for_attr: anoncreds.get_gvt_schema_json(1) + } + + claim_defs = { + claim_for_attr: json.loads(wallet_handle_and_claim_def[1]) + } + + await prover_create_proof(wallet_handle_and_claim_def[0], json.dumps(proof_req), json.dumps(requested_claims), + json.dumps(schemas), anoncreds.COMMON_MASTER_SECRET_NAME, + json.dumps(claim_defs), "{}") From 310f127b12ed5c6238184516209f658fded99ca9 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Mon, 24 Jul 2017 13:04:06 +0300 Subject: [PATCH 316/349] added test for verifier_verify_proof --- wrappers/python/indy/anoncreds.py | 10 +- .../tests/anoncreds/test_verify_proof.py | 169 ++++++++++++++++++ wrappers/python/tests/utils/anoncreds.py | 46 +++++ 3 files changed, 218 insertions(+), 7 deletions(-) create mode 100644 wrappers/python/tests/anoncreds/test_verify_proof.py diff --git a/wrappers/python/indy/anoncreds.py b/wrappers/python/indy/anoncreds.py index 423c84d1f3..fd89e7cd41 100644 --- a/wrappers/python/indy/anoncreds.py +++ b/wrappers/python/indy/anoncreds.py @@ -646,8 +646,7 @@ async def prover_create_proof(wallet_handle: int, return res -async def verifier_verify_proof(wallet_handle: int, - proof_request_json: str, +async def verifier_verify_proof(proof_request_json: str, proof_json: str, schemas_json: str, claim_defs_jsons: str, @@ -709,9 +708,8 @@ async def verifier_verify_proof(wallet_handle: int, """ logger = logging.getLogger(__name__) - logger.debug("verifier_verify_proof: >>> wallet_handle: %r, proof_request_json: %r," + logger.debug("verifier_verify_proof: >>> proof_request_json: %r," " proof_json: %r, schemas_json: %r, claim_defs_jsons: %r, revoc_regs_json: %r", - wallet_handle, proof_request_json, proof_json, schemas_json, @@ -720,9 +718,8 @@ async def verifier_verify_proof(wallet_handle: int, if not hasattr(verifier_verify_proof, "cb"): logger.debug("verifier_verify_proof: Creating callback") - verifier_verify_proof.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + verifier_verify_proof.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_bool)) - c_wallet_handle = c_int32(wallet_handle) c_proof_request_json = c_char_p(proof_request_json.encode('utf-8')) c_proof_json = c_char_p(proof_json.encode('utf-8')) c_schemas_json = c_char_p(schemas_json.encode('utf-8')) @@ -730,7 +727,6 @@ async def verifier_verify_proof(wallet_handle: int, c_revoc_regs_json = c_char_p(revoc_regs_json.encode('utf-8')) res = await do_call('indy_verifier_verify_proof', - c_wallet_handle, c_proof_request_json, c_proof_json, c_schemas_json, diff --git a/wrappers/python/tests/anoncreds/test_verify_proof.py b/wrappers/python/tests/anoncreds/test_verify_proof.py new file mode 100644 index 0000000000..50be4a503e --- /dev/null +++ b/wrappers/python/tests/anoncreds/test_verify_proof.py @@ -0,0 +1,169 @@ +from indy.anoncreds import verifier_verify_proof + +from tests.utils import storage, anoncreds + +import json +import pytest +import logging + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_verifier_verify_proof_works_for_correct_proof(): + proof_req = anoncreds.get_proof_req() + claim_def = anoncreds.get_claim_def() + + schemas = { + "claim::277478db-bf57-42c3-8530-b1b13cfe0bfd": anoncreds.get_gvt_schema_json(1) + } + claim_defs = { + "claim::277478db-bf57-42c3-8530-b1b13cfe0bfd": claim_def + } + proof = { + "proofs": { + "claim::277478db-bf57-42c3-8530-b1b13cfe0bfd": { + "proof": { + "primary_proof": { + "eq_proof": { + "revealed_attrs": { + "name": "1139481716457488690172217916278103335" + }, + "a_prime": "47629821806628155353444789773246165920681315271529392722265555946090524267165563309836167110610840740533588118152308411732923636370660640410661034994521654033599863817144282118006097899736622728860229305231675970853294584911572355833537271010861501353858292189045263114095480601737776505186511389129055847562085611741257601964074827979121349153316235245772819207422031038042586202074331681302501661153569340935741290924699468188826629478130140797677338573924284871118002193526319478550852287453975107498037063076866410320160118555629090040954555043934303307652160345244864713226315470541231435958298648179413077988340", + "e": "13427639393364185909415877973872458621259927563729922146828001652769380799419438410309469022979920689628523901764614163117469683925816443", + "v": "852136445143816932026946294488424887907102968158908948827421962603492187508454543239422067899916472317305416590471170842186669606584356963437132366711335927890209765986844538775191207999204354235774464468525274918097404114453069375363594310105209141774763909570100638835926337238009617444858777301355087706167735590386774813901740600054753028260344014744801229032610106838480523182317262113911183640784111960909501662169298536941919854667754097841344375972975021196106884215734228415868248724905018661498061287694439466570946597514142085096419985189064172035527690786158872698717583830848410994616274586162550376126607414773916066374234063208380831144157533076866210628625236440222547584539349936639548061601416341705483504386186280800509889531835172071717956251546280392606775903107774727736794828168898273891724336881907672405328368540895104468091907771325910937575557566831844131159128453840354307814975621978196047820", + "m": { + "age": "1117601261519431120446925325460734824239475567013636538481947258329666056692767097795046086413732472111811628751812987521644198549167671875326968410921589186689138994171774838662", + "height": "7064132689652704067914104576495132313294680087958177180391515757079548676035445873279966783996928425154050462229933823707574545166617858646442019030600136959459527533262821184869", + "sex": "16084497853957041205729191269508720470626311156190485518484640641677445098603656354458362520541393995692536218820724164533958162674375198846036330444513484319280148335515891811530"}, + "m1": "154906224259819061652290487122980839849626068919893070220438585977323162319993111920906032317552959103520053742608858935542877608981244065301675821390065831113115709272412144796159984624494428122971995557415296140268002332169405587907128359886810433617416529821500995701094400375272097687818064435577784795275", + "m2": "13805395408072590464827983892588030341708765524663545700917462089376137940485022437657208204460048097312372685954050370540389593952001973312378647790917367330461398089529292217752"}, + "ge_proofs": [{"u": { + "1": "7698818972783845439601187851976452936638792889455287252542709653271706844173743185409084669157965935169942655008606334521674712818637940377261656468700786810566551698412412949418", + "0": "11703047052430512223413711314521545616119146623040600935686474696241801697819280425232876917607198335376453682738553665221410353412906194951254558355994401995990233992518110582450", + "3": "13210777821918317858818819091924507295018522783042111457450035423463340571245465760486275059291363621513532153389441883097799049597687545496359999443320001567152794884095192951040", + "2": "15219471780524079156861690098171693383497641272226737821992208834301871102152362116211452788300889697214391366996966539871625433480959011635688106136537800706217506402845296449689"}, + "r": { + "1": "46043242109380749151527145850513330956077996622769158245225343392397735706292106535150958053995712629189143692293204979798837951212291825184346767969751978730000071952944305252032332015837054475531407691352179423131405515518588355918925056889302269768343499864256747177988825578647189563088068257214198650437730618330249172716051559993880468542083352885474175039320848153156858562341041960950299312991459780503345784440261679263045723337629951517601461685539857683027034345542399365706329805317943096391758978877658949910614447086409173234155028671453929715706057153381022697673192590033507204548864311227048268516889390503318015295207078022755834130221198717787608473222789491216667698651180077661375273569115943192", + "0": "135472587547410377947826119498467634347118057359097899596599164976338466445104141784869016998150489852448547539824768048351359572626675997498079394825940306636285481821620973655797996638210760710325933304918452142858879806106214845499670718704532018129553348815327362843246706518826311676917538452317818631484884032929252959289913274829848084561421467966320595980172006456003183536232790787521924655750157145207798486087511869939940023266736153366338179116840490184005332351004990854691988404031259910319601383696749511809898297656135548118786342107367065232798999979296280467063561892962526945512167505847049907450058650930480352253243357594344686769208712964458923557777584158831146374282687397585726706489164423632", + "DELTA": "93540839493959971552865423901789226093328763011922445919928571946113703515842729132879472109395228387208764738970926484618949870591214627692618668077375153559192701474693025462226656116549337248146652482501255820930607033869432220667968682424554711616471973627651716863421554516577716366331699848682958681216261888139409101603059124344125075525791543312721162515584942523419876134808829569829529457617639955678189490257208141837196965948342373022812790844435050648360150869293836349223060722858500537182872294143846213258360218898475766641125493477502149553491502593654061863323857297998048614447925371606038801933864960337435890254277043261512846682042139570000962051463878026338583242360548041329046695667868842400", + "3": "1227675452527605924725300993571504188580051470857656204064614533296779844072852823820754766175236321050062349182891221840452517985644028521499240739391613871973822807731772613052644168369405390658793869751915172749739844553410726807277698347769400977274750672880389943392076308065414059539317340070691852044062594715307024113666759844200606183662256825096857658837519571386467051003466014468855293015652584667669998830524947537781865745830650392641812221679438090257444660715937570193098993118585554478799821072396238689063767016402460690760792908977364175126682041704095200572282644311025594681667826054722587271200221036938804846621444065128275082392082327596239358623150786484106872933657139420542280145197712634108", + "2": "596248147592834822582469335300585333722415132713749620075902332764163096347819006925876158892694742461036531935093982309708492066217459300117157420442081698140277277546563570823996272914068575482008392971932777453900260626542725308060927710122631763045025742980634216666560934260634907599194353151523256914796667535940073668465664206971169038864484235442207811974981191879443614478897291543702607764944403808380921189291059195014621592027660463072969363556421687131446107696579365265893962197300447027501604372738056016734644378437907931412654753728514905671605635291285742886484416973884856055084605172305967034292646171874483670469193852404511746786039743401185954843446037600121496137915619789351744485264614840070"}, + "mj": "1117601261519431120446925325460734824239475567013636538481947258329666056692767097795046086413732472111811628751812987521644198549167671875326968410921589186689138994171774838662", + "alpha": "76727612740067576380015106087224381023260815407331375101920043509817863645705120013304683427627332447210083684516403565749916480947649443674885388155460323163682547865307733144184097845709556309570345707127872162476432029772452433292049079349274445907295491125915363620615679995457134810061392296263970553630102299601689685622244925494554558218277670233361938142224820526392365740420502452466959099546877778248089664282581792213376636587293479012783947088070052463503335266180110771978445892744225891676396288437005847308189508347446490710626231658457908472341606549292437553353163031111068977301305043175839949352742711874426231072729977019365761072816602400121302646283352164756787266537474728685656685493249314400351742964904006326192403855909148605656818024621453179832395687665671245528217931951331393482249182516107670379946496778373", + "t": { + "1": "37203689290881948278188715497642400459048942241931994079434400288578680362970117779048886269388440270597283202033458042171954610700745461571112086648991639439510380585728148682202768590972068041537531136529323260832899360551065706810590032715173070285762675403853992183366951113799098912676809373169763887110420539387555392787590966452796271491986622992160642135480293110112269570862265489120557014181468118619500321000966443141863893743211690388599242584469856365803370202569641902205925191670838354052104480074127555862332399641076324738839120815544432811566503174551735326387678621283249883091766325861497740614317", + "3": "58486787977689017034592833190899828017343431922483563651969628402499947729293364026001243898136737211851089198526360764391403150763769829047179796728616126204105160762333590343947446892105646111520243793053992399512412375936746396187319527051818920531870855183738837254656664620975569939859368862778444291640228229744805843388153451336792379036403300211151424879060241580540910888241769468335914016289938374111481091198264912969768783884602931940994543804730631920434719776196148182987249363641941951160704928605829395517074202388967815738516252602903999010405305463910751219873354588685197134114358234107748126140977", + "0": "60771874648036182010335841594233428920565254732600738082343398028553347795361460295011584446745121430144172025428394361648540904134739046923992231536160801306934272250969829886396340824213814702904457884984387666505055153957942221822193548673145705543973635530652570436109428474727638128773540793530691399549837156239786231362112148914687724325416768262058486101761972044802628459748878200584371058300150212485731451700436345975266860685549673168984700174294811561393162860595319582236734968601457003780816977537443267217411297266600994916897237305128142313335280264655603445636393371224354539882875937093696844430903", + "DELTA": "32816484171372208266594641116109072545171919234551585018140151846920408763078147655907777031259225522515086979967895258126318315788662577171150780535509410112003001556402222994276811926864642497249250763185467678044678144507739529818566125668667424447792097244624010084189629269472698722402896445274092470014229247479740671263651727480322483037149584904549203417226525624083290572692241241259382947122018271686649224741832992966652878170311798126004447080305528487720923103595513611363001766063956060990267107048028416069435287244770875463867263571308182619338433913487209319707428378896314619624990311543563016697299", + "2": "36428320569485697540634597755814766104888687488985202673924762266313135133244610404742081973550848160712054769198012193456278135847215508952327879544434490828380496286187725750283788811367824465072001959950807751252194618152990469069074061195618692339915840384087350671392595652921761835083158086795163935060896053332506433434451836095710383871272788002621913967538399141417857031787255744141437237474972197102809365346359345477248611632307159641948507043668113827177494748159094045928919209335044052792843664865311991178972383241855607627188111601119780878072683890170539599447876998109080150992209773901144245398001"}, + "predicate": {"attr_name": "age", "p_type": "GE", "value": 18}}]}, + "non_revoc_proof": None}, "schema_seq_no": 1, "revoc_reg_seq_no": None, "issuer_did": "did"}}, + "aggregated_proof": {"c_hash": "33103550379681684069592829341967479618752165928802550870585275205292715916069", + "c_list": [ + [1, 121, 77, 5, 144, 154, 14, 192, 190, 190, 145, 180, 128, 71, 22, 60, 168, 20, 46, + 163, 139, 194, 71, 165, 220, 188, 121, 76, 25, 146, 231, 114, 65, 54, 69, 68, 19, 200, + 250, 192, 47, 123, 157, 132, 74, 50, 28, 69, 226, 195, 243, 118, 45, 63, 237, 197, + 216, 202, 206, 101, 33, 56, 225, 200, 128, 3, 89, 12, 182, 38, 113, 221, 165, 119, + 228, 201, 156, 201, 172, 136, 59, 64, 51, 72, 164, 198, 49, 228, 223, 117, 80, 64, + 166, 226, 37, 8, 29, 146, 186, 80, 210, 119, 76, 252, 4, 255, 62, 218, 112, 163, 164, + 147, 247, 190, 108, 76, 140, 191, 76, 217, 214, 184, 152, 179, 193, 149, 15, 70, 197, + 46, 90, 60, 255, 247, 197, 219, 252, 73, 76, 0, 125, 104, 114, 22, 182, 161, 110, 36, + 162, 103, 27, 42, 88, 18, 161, 237, 198, 43, 177, 189, 181, 86, 135, 207, 71, 114, 0, + 26, 175, 12, 199, 125, 25, 124, 178, 87, 36, 208, 251, 15, 191, 127, 202, 148, 152, + 43, 142, 92, 191, 7, 89, 153, 130, 195, 223, 248, 176, 109, 97, 164, 126, 162, 181, + 124, 237, 130, 155, 197, 66, 59, 40, 197, 72, 84, 32, 100, 64, 55, 227, 60, 214, 143, + 200, 200, 89, 115, 236, 172, 145, 56, 100, 73, 20, 242, 233, 95, 130, 58, 112, 153, + 120, 115, 119, 42, 199, 30, 205, 88, 223, 42, 196, 184, 41, 19, 100, 19, 244], + [1, 225, 103, 238, 42, 147, 91, 191, 110, 69, 154, 53, 57, 156, 124, 43, 174, 155, 76, + 202, 193, 98, 128, 38, 207, 126, 66, 70, 161, 96, 109, 127, 174, 44, 203, 198, 177, + 238, 118, 117, 89, 227, 170, 155, 44, 251, 35, 119, 219, 29, 100, 173, 26, 144, 95, + 50, 177, 4, 40, 234, 117, 174, 210, 192, 172, 57, 160, 198, 42, 199, 212, 243, 240, + 114, 59, 91, 207, 68, 57, 38, 198, 2, 73, 18, 16, 209, 182, 145, 206, 71, 17, 69, 222, + 49, 36, 120, 72, 117, 169, 107, 238, 208, 235, 216, 24, 183, 201, 81, 15, 83, 242, 45, + 136, 184, 166, 26, 142, 136, 228, 58, 229, 235, 88, 169, 238, 134, 205, 96, 85, 9, + 122, 53, 147, 100, 183, 114, 92, 54, 125, 178, 125, 75, 127, 116, 50, 88, 109, 152, + 22, 4, 121, 252, 190, 18, 190, 130, 143, 138, 59, 231, 38, 131, 176, 54, 19, 194, 218, + 67, 144, 122, 91, 43, 86, 73, 233, 48, 193, 30, 183, 183, 191, 238, 216, 167, 101, 28, + 185, 43, 118, 64, 242, 16, 62, 239, 177, 27, 109, 144, 67, 221, 175, 202, 4, 92, 130, + 74, 24, 20, 151, 15, 227, 225, 142, 71, 145, 46, 192, 248, 87, 57, 183, 142, 253, 52, + 20, 56, 153, 220, 234, 25, 67, 116, 225, 179, 211, 116, 161, 37, 64, 34, 48, 155, 1, + 1, 159, 157, 37, 31, 202, 19, 229, 152, 23, 138, 183, 126, 55], + [1, 38, 181, 193, 191, 72, 2, 239, 34, 83, 49, 36, 179, 160, 82, 112, 172, 98, 255, 63, + 60, 22, 177, 249, 67, 215, 220, 198, 181, 7, 49, 254, 133, 243, 221, 214, 47, 64, 229, + 82, 11, 94, 175, 57, 86, 152, 229, 192, 184, 96, 136, 116, 226, 123, 128, 217, 23, + 244, 19, 204, 36, 44, 123, 208, 88, 24, 217, 120, 145, 139, 25, 233, 227, 5, 119, 90, + 47, 147, 1, 115, 92, 39, 119, 194, 167, 17, 229, 39, 163, 167, 237, 14, 116, 234, 106, + 252, 216, 54, 33, 233, 21, 54, 183, 130, 144, 161, 177, 142, 177, 240, 51, 73, 21, + 202, 188, 103, 244, 153, 204, 219, 123, 231, 139, 135, 189, 155, 143, 28, 4, 180, 44, + 148, 0, 27, 103, 26, 13, 203, 31, 32, 166, 67, 84, 87, 23, 72, 234, 236, 20, 1, 84, + 70, 86, 76, 192, 164, 235, 124, 86, 128, 78, 230, 119, 155, 95, 121, 125, 20, 244, + 181, 121, 250, 169, 9, 67, 85, 213, 177, 139, 111, 187, 183, 114, 165, 249, 177, 161, + 181, 175, 46, 226, 66, 86, 84, 124, 86, 69, 143, 217, 158, 161, 30, 107, 133, 44, 239, + 89, 209, 24, 150, 1, 238, 122, 144, 138, 179, 121, 114, 90, 13, 212, 209, 60, 126, 37, + 62, 177, 180, 131, 222, 168, 2, 201, 156, 169, 220, 224, 53, 8, 203, 220, 215, 163, + 104, 195, 184, 73, 35, 241, 182, 177, 80, 41, 253, 230, 90, 173], + [1, 32, 145, 96, 219, 241, 190, 19, 195, 129, 219, 50, 148, 152, 107, 12, 189, 225, + 103, 171, 149, 252, 193, 243, 136, 132, 195, 44, 19, 20, 247, 140, 160, 91, 230, 78, + 31, 242, 85, 213, 65, 185, 1, 91, 12, 69, 118, 80, 26, 135, 102, 131, 4, 108, 130, + 230, 83, 91, 176, 249, 196, 56, 128, 127, 82, 72, 106, 49, 211, 94, 133, 40, 86, 72, + 42, 187, 199, 216, 191, 223, 208, 206, 121, 118, 15, 167, 255, 228, 57, 206, 158, 217, + 64, 205, 212, 178, 8, 248, 129, 183, 221, 98, 70, 54, 37, 55, 47, 81, 120, 59, 186, + 238, 165, 0, 70, 173, 137, 193, 232, 180, 125, 211, 237, 182, 249, 191, 173, 107, 129, + 164, 148, 231, 116, 225, 66, 66, 71, 156, 39, 248, 164, 253, 234, 140, 205, 177, 140, + 117, 47, 21, 15, 242, 31, 113, 118, 91, 143, 89, 213, 86, 143, 135, 21, 46, 35, 199, + 214, 107, 111, 65, 65, 19, 26, 171, 130, 16, 19, 102, 145, 210, 210, 61, 51, 169, 148, + 169, 118, 182, 106, 107, 253, 100, 214, 232, 52, 103, 180, 96, 249, 254, 71, 6, 11, + 119, 48, 129, 213, 223, 205, 93, 20, 117, 26, 187, 32, 151, 212, 137, 203, 17, 237, + 208, 150, 72, 23, 225, 235, 122, 188, 34, 105, 115, 0, 160, 168, 251, 191, 22, 242, + 238, 207, 74, 142, 154, 66, 94, 149, 191, 215, 194, 134, 6, 165, 244, 167, 233, 241], + [1, 207, 77, 250, 146, 127, 242, 229, 44, 172, 182, 201, 183, 242, 32, 242, 182, 129, + 233, 10, 8, 180, 23, 191, 163, 21, 238, 158, 5, 27, 216, 146, 253, 173, 127, 99, 95, + 168, 209, 132, 242, 196, 242, 34, 25, 25, 249, 211, 51, 236, 164, 153, 175, 61, 65, + 150, 82, 251, 174, 102, 186, 47, 195, 82, 44, 90, 252, 184, 74, 89, 251, 177, 254, + 108, 151, 136, 230, 220, 93, 224, 173, 247, 244, 116, 132, 59, 170, 215, 194, 30, 87, + 84, 166, 147, 57, 156, 201, 207, 132, 203, 222, 191, 253, 15, 19, 228, 173, 81, 156, + 4, 51, 121, 227, 159, 50, 18, 148, 129, 205, 42, 42, 227, 252, 138, 62, 176, 115, 227, + 253, 52, 125, 110, 178, 167, 132, 244, 14, 116, 195, 194, 172, 44, 45, 63, 38, 121, + 215, 136, 68, 230, 21, 108, 133, 159, 197, 179, 94, 78, 233, 107, 236, 114, 92, 165, + 248, 22, 124, 161, 23, 142, 236, 224, 175, 233, 134, 25, 97, 150, 131, 61, 220, 203, + 104, 154, 199, 247, 146, 47, 205, 56, 209, 0, 133, 132, 18, 103, 136, 8, 202, 37, 29, + 100, 105, 12, 232, 74, 33, 6, 255, 202, 96, 170, 52, 229, 244, 4, 235, 2, 201, 125, + 86, 168, 179, 224, 130, 81, 54, 221, 185, 184, 187, 141, 0, 114, 98, 38, 70, 225, 228, + 60, 157, 53, 210, 238, 60, 216, 215, 154, 48, 73, 3, 157, 192, 245, 81, 170, 49], + [1, 3, 244, 229, 158, 71, 18, 146, 198, 202, 27, 2, 231, 37, 13, 145, 243, 84, 112, + 220, 61, 174, 4, 175, 104, 200, 64, 146, 193, 20, 174, 126, 42, 157, 168, 76, 165, 21, + 50, 216, 82, 211, 180, 73, 244, 54, 227, 200, 19, 157, 25, 228, 81, 37, 64, 201, 19, + 138, 175, 50, 246, 169, 11, 45, 74, 194, 131, 236, 127, 177, 41, 242, 130, 55, 112, + 182, 98, 22, 99, 48, 153, 83, 161, 250, 65, 89, 3, 97, 6, 5, 171, 54, 223, 87, 98, + 103, 23, 200, 212, 177, 140, 155, 151, 252, 125, 45, 176, 55, 92, 41, 56, 2, 252, 32, + 149, 60, 3, 168, 209, 193, 23, 168, 230, 182, 72, 193, 230, 224, 5, 15, 58, 63, 93, + 196, 33, 93, 76, 188, 30, 70, 31, 136, 64, 204, 223, 2, 230, 210, 243, 255, 135, 193, + 52, 132, 248, 160, 22, 18, 164, 71, 77, 80, 112, 229, 120, 116, 210, 225, 2, 19, 139, + 35, 0, 214, 5, 246, 9, 106, 136, 204, 0, 148, 97, 21, 222, 153, 57, 177, 162, 11, 243, + 252, 7, 242, 34, 239, 245, 50, 104, 74, 221, 92, 73, 13, 142, 10, 184, 250, 246, 167, + 240, 46, 230, 86, 207, 181, 12, 133, 81, 119, 143, 164, 88, 114, 223, 243, 179, 208, + 175, 84, 161, 27, 11, 225, 36, 37, 177, 112, 85, 81, 184, 163, 223, 159, 36, 9, 247, + 20, 13, 230, 215, 108, 117, 35, 99, 117, 211]]}, "requested_proof": { + "revealed_attrs": { + "attr1_uuid": ["claim::277478db-bf57-42c3-8530-b1b13cfe0bfd", "Alex", + "1139481716457488690172217916278103335"] + }, "unrevealed_attrs": {}, + "self_attested_attrs": {}, + "predicates": { + "predicate1_uuid": "claim::277478db-bf57-42c3-8530-b1b13cfe0bfd" + } + } + } + + valid = await verifier_verify_proof(json.dumps(proof_req), json.dumps(proof), + json.dumps(schemas), json.dumps(claim_defs), "{}") + + assert valid diff --git a/wrappers/python/tests/utils/anoncreds.py b/wrappers/python/tests/utils/anoncreds.py index f2c1c66723..633dcec24b 100644 --- a/wrappers/python/tests/utils/anoncreds.py +++ b/wrappers/python/tests/utils/anoncreds.py @@ -65,3 +65,49 @@ def get_claim_req(): "60746440672050640048215761507774996460985293327604627646056062013419674090094698841" "792968543317468164175921100038", "ur": None}, "issuer_did": ISSUER_DID, "schema_seq_no": 1} + + +def get_proof_req(): + return { + "nonce": "123432421212", + "name": "proof_req_1", + "version": "0.1", + "requested_attrs": { + "attr1_uuid": + { + "schema_seq_no": 1, + "name": "name" + } + }, + "requested_predicates": { + "predicate1_uuid": { + "attr_name": "age", + "p_type": "GE", + "value": 18 + } + } + } + + +def get_claim_def(): + return { + "ref": 1, + "signature_type": "CL", + "origin": ISSUER_DID, + "data": { + "primary": { + "n": "94759924268422840873493186881483285628376767714620627055233230078254863658476446487556117977593248501523199451418346650764648601684276437772084327637083000213497377603495837360299641742248892290843802071224822481683143989223918276185323177379400413928352871249494885563503003839960930062341074783742062464846448855510814252519824733234277681749977392772900212293652238651538092092030867161752390937372967233462027620699196724949212432236376627703446877808405786247217818975482797381180714523093913559060716447170497587855871901716892114835713057965087473682457896508094049813280368069805661739141591558517233009123957", + "s": "3589207374161609293256840431433442367968556468254553005135697551692970564853243905310862234226531556373974144223993822323573625466428920716249949819187529684239371465431718456502388533731367046146704547241076626874082510133130124364613881638153345624380195335138152993132904167470515345775215584510356780117368593105284564368954871044494967246738070895990267205643985529060025311535539534155086912661927003271053443110788963970349858709526217650537936123121324492871282397691771309596632805099306241616501610166028401599243350835158479028294769235556557248339060399322556412171888114265194198405765574333538019124846", + "rms": "57150374376895616256492932008792437185713712934712117819417607831438470701645904776986426606717466732609284990796923331049549544903261623636958698296956103821068569714644825742048584174696465882627177060166162341112552851798863535031243458188976013190131935905789786836375734914391914349188643340535242562896244661798678234667651641013894284156416773868299435641426810968290584996112925365638881750944407842890875840705650290814965768221299488400872767679122749231050406680432079499973527780212310700022178178822528199576164498116369689770884051691678056831493476045361227274839673581033532995523269047577973637307053", + "r": { + "age": "94304485801056920773231824603827244147437820123357994068540328541540143488826838939836897544389872126768239056314698953816072289663428273075648246498659039419931054256171488371404693243192741923382499918184822032756852725234903892700640856294525441486319095181804549558538523888770076173572615957495813339649470619615099181648313548341951673407624414494737018574238782648822189142664108450534642272145962844003886059737965854042074083374478426875684184904488545593139633653407062308621502392373426120986761417580127895634822264744063122368296502161439648408926687989964483291459079738447940651025900007635890755686910", + "sex": "29253365609829921413347591854991689007250272038394995372767401325848195298844802462252851926995846503104090589196060683329875231216529049681648909174047403783834364995363938741001507091534282239210301727771803410513303526378812888571225762557471133950393342500638551458868147905023198508660460641434022020257614450354085808398293279060446966692082427506909617283562394303716193372887306176319841941848888379308208426966697446699225783646634631703732019477632822374479322570142967559738439193417309205283438893083349863592921249218168590490390313109776446516881569691499831380592661740653935515397472059631417493981532", + "name": "25134437486609445980011967476486104706321061312022352268621323694861467756181853100693555519614894168921947814126694858839278103549577703105305116890325322098078409416441750313062396467567140699008203113519528887729951138845002409659317083029073793314514377377412805387401717457417895322600145580639449003584446356048213839274172751441145076183734269045919984853749007476629365146654240675320041155618450449041510280560040162429566008590065069477149918088087715269037925211599101597422023202484497946662159070023999719865939258557778022770035320019440597702090334486792710436579355608406897769514395306079855023848170", + "height": "59326960517737425423547279838932030505937927873589489863081026714907925093402287263487670945897247474465655528290016645774365383046524346223348261262488616342337864633104758662753452450299389775751012589698563659277683974188553993694220606310980581680471280640591973543996299789038056921309016983827578247477799948667666717056420270448516049047961099547588510086600581628091290215485826514170097211360599793229701811672966818089371089216189744274422526431130783428589346341196561742409198605034972210917502326180305735092988639850309253190875578501020679137562856724998821945605494355779034135306337094344532980411836" + }, + "rctxt": "9641986614889199796257508700106896585587271615330980339636468819377346498767697681332046156705231986464570206666984343024200482683981302064613556104594051003956610353281701880542337665385482309134369756144345334575765116656633321636736946947493150642615481313285221467998414924865943067790561494301461899025374692884841352282256044388512875752628313052128404892424405230961678931620525106856624692942373538946467902799339061714326383378018581568876147181355325663707572429090278505823900491548970098691127791086305310899642155499128171811034581730190877600697624903963241473287185133286356124371104261592694271730029", + "z": "77594127026421654059198621152153180600664927707984020918609426112642522289621323453889995053400171879296098965678384769043918218957929606187082395048777546641833348694470081024386996548890150355901703252426977094536933434556202865213941384425538749866521536494046548509344678288447175898173634381514948562261015286492185924659638474376885655055568341574638453213864956407243206035973349529545863886325462867413885904072942842465859476940638839087894582648849969332663627779378998245133055807038199937421971988505911494931665143822588532097754480882750243126847177560978100527491344463525107644125030963904001009159559" + }, + "revocation": None + } + } From 97792b7d08aa924ff5609f17cb562932b3a38fbe Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 24 Jul 2017 14:23:17 +0300 Subject: [PATCH 317/349] Added ledger, anoncreds, signus demo tests --- wrappers/python/tests/demo/anoncreds.py | 117 ++++++++++++++++++++++++ wrappers/python/tests/demo/ledger.py | 76 +++++++++++++++ wrappers/python/tests/demo/signus.py | 68 ++++++++++++++ 3 files changed, 261 insertions(+) create mode 100644 wrappers/python/tests/demo/anoncreds.py create mode 100644 wrappers/python/tests/demo/ledger.py create mode 100644 wrappers/python/tests/demo/signus.py diff --git a/wrappers/python/tests/demo/anoncreds.py b/wrappers/python/tests/demo/anoncreds.py new file mode 100644 index 0000000000..d13a1ba43d --- /dev/null +++ b/wrappers/python/tests/demo/anoncreds.py @@ -0,0 +1,117 @@ +from indy import anoncreds, wallet + +from tests.utils import storage + +import pytest +import logging +import json + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_anoncreds_demo_works(): + pool_name = "anoncreds_demo_pool" + wallet_name = "anoncreds_demo_wallet" + + # 1. Create My Wallet and Get Wallet Handle + await wallet.create_wallet(pool_name, wallet_name, None, None, None) + wallet_handle = await wallet.open_wallet(wallet_name, None, None) + + # 2. Issuer create Claim Definition for Schema + schema_seq_no = 1 + schema = { + 'seqNo': schema_seq_no, + 'data': { + 'name': 'gvt', + 'version': '1.0', + 'keys': ['age', 'sex', 'height', 'name'] + } + } + schema_json = json.dumps(schema) + issuer_did = 'NcYxiDXkpYi6ov5FcYDi1e' + + claim_def_json = \ + await anoncreds.issuer_create_and_store_claim_def(wallet_handle, issuer_did, schema_json, 'CL', False) + + # 3. Prover create Master Secret + master_secret_name = 'master_secret' + await anoncreds.prover_create_master_secret(wallet_handle, master_secret_name) + + # 4. Prover create Claim Request + prover_did = 'BzfFCYk' + claim_offer = { + 'issuer_did': 'NcYxiDXkpYi6ov5FcYDi1e', + 'schema_seq_no': schema_seq_no + } + + claim_req_json = await anoncreds.prover_create_and_store_claim_req(wallet_handle, prover_did, + json.dumps(claim_offer), + claim_def_json, master_secret_name) + + # 5. Issuer create Claim for Claim Request + claim = { + 'sex': ['male', '5944657099558967239210949258394887428692050081607692519917050011144233115103'], + 'name': ['Alex', '1139481716457488690172217916278103335'], + 'height': ['175', '175'], + 'age': ['28', '28'] + } + + (_, claim_json) = await anoncreds.issuer_create_claim(wallet_handle, claim_req_json, json.dumps(claim), -1, -1) + + # 6. Prover process and store Claim + await anoncreds.prover_store_claim(wallet_handle, claim_json) + + # 7. Prover gets Claims for Proof Request + proof_req = { + 'nonce': '123432421212', + 'name': 'proof_req_1', + 'version': '0.1', + 'requested_attrs': { + 'attr1_uuid': {'schema_seq_no': schema_seq_no, 'name': 'name'} + }, + 'requested_predicates': { + 'predicate1_uuid': {'attr_name': 'age', 'p_type': 'GE', 'value': 18} + } + } + proof_req_json = json.dumps(proof_req) + + claim_for_proof_json = await anoncreds.prover_get_claims_for_proof_req(wallet_handle, proof_req_json) + claim_for_proof_json = json.loads(claim_for_proof_json) + + claim_for_attr1 = claim_for_proof_json['attrs']['attr1_uuid'] + assert 1 == len(claim_for_attr1) + + claim_uuid = claim_for_attr1[0]['claim_uuid'] + + # 8. Prover create Proof for Proof Request + requested_claims = { + 'self_attested_attributes': {}, + 'requested_attrs': {'attr1_uuid': [claim_uuid, True]}, + 'requested_predicates': {'predicate1_uuid': claim_uuid} + } + requested_claims_json = json.dumps(requested_claims) + + schemas_json = json.dumps({claim_uuid: schema}) + claim_defs_json = json.dumps({claim_uuid: json.loads(claim_def_json)}) + revoc_regs_json = json.dumps({}) + + proof_json = await anoncreds.prover_create_proof(wallet_handle, proof_req_json, requested_claims_json, schemas_json, + master_secret_name, claim_defs_json, revoc_regs_json) + proof = json.loads(proof_json) + + assert 'Alex' == proof['requested_proof']['revealed_attrs']['attr1_uuid'][1] + + # 9. Verifier verify proof + assert await anoncreds.verifier_verify_proof(proof_req_json, proof_json, schemas_json, claim_defs_json, + revoc_regs_json) + + # 10. Close wallet + await wallet.close_wallet(wallet_handle) diff --git a/wrappers/python/tests/demo/ledger.py b/wrappers/python/tests/demo/ledger.py new file mode 100644 index 0000000000..07a95c7c06 --- /dev/null +++ b/wrappers/python/tests/demo/ledger.py @@ -0,0 +1,76 @@ +from indy import ledger, signus, wallet, pool +from indy.pool import open_pool_ledger + +from tests.utils import storage + +import pytest +import logging +import json + +from tests.utils.pool import create_genesis_txn_file + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_ledger_demo_works(): + pool_name = "pool" + my_wallet_name = "my_wallet" + their_wallet_name = "their_wallet" + + # 1. Create ledger config from genesis txn file + file_name = pool_name + '.txn' + path = create_genesis_txn_file(file_name, None) + pool_config = json.dumps({"genesis_txn": str(path)}) + await pool.create_pool_ledger_config(pool_name, pool_config) + + # 2. Open pool ledger + pool_handle = await open_pool_ledger(pool_name, "") + + # 3. Create My Wallet and Get Wallet Handle + await wallet.create_wallet(pool_name, my_wallet_name, None, None, None) + my_wallet_handle = await wallet.open_wallet(my_wallet_name, None, None) + + # 4. Create Their Wallet and Get Wallet Handle + await wallet.create_wallet(pool_name, their_wallet_name, None, None, None) + their_wallet_handle = await wallet.open_wallet(their_wallet_name, None, None) + + # 5. Create My DID + (my_did, my_verkey, my_pk) = await signus.create_and_store_my_did(my_wallet_handle, "{}") + + # 6. Create Their DID from Trustee1 seed + (their_did, their_verkey, their_pk) = \ + await signus.create_and_store_my_did(their_wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') + + # 7. Store Their DID + their_identity = { + 'did': their_did, + 'pk': their_pk, + 'verkey': their_verkey + } + + await signus.store_their_did(my_wallet_handle, json.dumps(their_identity)) + + # 8. Prepare and send NYM transaction + nym_txn_req = await ledger.build_nym_request(their_did, my_did, None, None, None) + await ledger.sign_and_submit_request(pool_handle, their_wallet_handle, their_did, nym_txn_req.decode()) + + # 9. Prepare and send GET_NYM request + get_nym_txn_req = await ledger.build_get_nym_request(their_did, my_did) + get_nym_txn_resp = await ledger.submit_request(pool_handle, get_nym_txn_req.decode()) + + get_nym_txn_resp = json.loads(get_nym_txn_resp) + + assert get_nym_txn_resp['result']['dest'] == my_did + + # 10. Close wallets and pool + await wallet.close_wallet(their_wallet_handle) + await wallet.close_wallet(my_wallet_handle) + await pool.close_pool_ledger(pool_handle) diff --git a/wrappers/python/tests/demo/signus.py b/wrappers/python/tests/demo/signus.py new file mode 100644 index 0000000000..f68e3fc929 --- /dev/null +++ b/wrappers/python/tests/demo/signus.py @@ -0,0 +1,68 @@ +from indy import signus, wallet + +from tests.utils import storage + +import pytest +import logging +import json + + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_signus_demo_works(): + pool_name = "create" + my_wallet_name = "my_wallet" + their_wallet_name = "their_wallet" + + # 1. Create My Wallet and Get Wallet Handle + await wallet.create_wallet(pool_name, my_wallet_name, None, None, None) + my_wallet_handle = await wallet.open_wallet(my_wallet_name, None, None) + + # 2. Create Their Wallet and Get Wallet Handle + await wallet.create_wallet(pool_name, their_wallet_name, None, None, None) + their_wallet_handle = await wallet.open_wallet(their_wallet_name, None, None) + + # 3. Create My DID + await signus.create_and_store_my_did(my_wallet_handle, "{}") + + # 4. Create Their DID from Trustee1 seed + (their_did, their_verkey, their_pk) = \ + await signus.create_and_store_my_did(their_wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') + + # 5. Store Their DID + their_identity = { + 'did': their_did, + 'pk': their_pk, + 'verkey': their_verkey + } + + await signus.store_their_did(my_wallet_handle, json.dumps(their_identity)) + + # 6. Their sign message + message = { + "reqId": 1495034346617224651, + "identifier": "GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL", + "operation": { + "type": "1", + "dest": "4efZu2SXufS556yss7W5k6Po37jt4371RM4whbPKBKdB" + } + } + + signed_msg = await signus.sign(their_wallet_handle, their_did, json.dumps(message)) + + # 7. Their sign message + assert await signus.verify_signature(my_wallet_handle, 1, their_did, signed_msg.decode()) + + # 8. Close wallets + await wallet.close_wallet(their_wallet_handle) + await wallet.close_wallet(my_wallet_handle) + From 3a3b55c57383e717c1f304a016f88811cd86dd2b Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Mon, 24 Jul 2017 17:07:38 +0300 Subject: [PATCH 318/349] * New tests for agent 2 agent API * Refactoring of tests with massive fixtures usage --- wrappers/python/tests/agent/conftest.py | 81 +++++++++++++++++++ .../tests/agent/test_agent_add_idenitity.py | 11 +++ .../python/tests/agent/test_agent_connect.py | 51 +----------- .../python/tests/agent/test_agent_listen.py | 55 +------------ wrappers/python/tests/conftest.py | 23 ++++++ 5 files changed, 118 insertions(+), 103 deletions(-) create mode 100644 wrappers/python/tests/agent/conftest.py create mode 100644 wrappers/python/tests/agent/test_agent_add_idenitity.py create mode 100644 wrappers/python/tests/conftest.py diff --git a/wrappers/python/tests/agent/conftest.py b/wrappers/python/tests/agent/conftest.py new file mode 100644 index 0000000000..a6c47ddc6d --- /dev/null +++ b/wrappers/python/tests/agent/conftest.py @@ -0,0 +1,81 @@ +import json + +import pytest + +from indy import signus, agent + +endpoint = "127.0.0.1:9701" + + +@pytest.fixture +async def wallet_with_identity(wallet_handle): + did, verkey, pk = await signus.create_and_store_my_did(wallet_handle, "{}") + await signus.store_their_did(wallet_handle, + json.dumps({ + "did": did, + "verkey": verkey, + "pk": pk, + "endpoint": endpoint + })) + + return wallet_handle, did + + +@pytest.fixture +async def wallet_with_identities(wallet_with_identity): + wallet_handle, did1 = wallet_with_identity + + did2, verkey2, pk2 = await signus.create_and_store_my_did(wallet_handle, "{}") + await signus.store_their_did(wallet_handle, + json.dumps({ + "did": did2, + "verkey": verkey2, + "pk": pk2, + "endpoint": endpoint + })) + + return wallet_handle, did1, did2 + + +@pytest.fixture +async def listener_handle(): + listener_handle = await agent.agent_listen(endpoint) + assert type(listener_handle) is int + yield listener_handle + await agent.agent_close_listener(listener_handle) + + +@pytest.fixture +async def listener_with_identity(listener_handle, wallet_with_identity): + wallet_handle, did = wallet_with_identity + await agent.agent_add_identity(listener_handle, -1, wallet_handle, did) + return listener_handle, wallet_handle, did + + +@pytest.fixture +async def listener_with_identities(listener_handle, wallet_with_identities): + wallet_handle, did1, did2 = wallet_with_identities + await agent.agent_add_identity(listener_handle, -1, wallet_handle, did1) + await agent.agent_add_identity(listener_handle, -1, wallet_handle, did2) + return listener_handle, wallet_handle, did1, did2 + + +@pytest.fixture +async def connection(listener_with_identity): + listener_handle, wallet_handle, did = listener_with_identity + + connection_handle = await agent.agent_connect(0, wallet_handle, did, did) + assert connection_handle is not None + + event = await agent.agent_wait_for_event(listener_handle) # type: agent.ConnectionEvent + + assert type(event) is agent.ConnectionEvent + assert event.handle == listener_handle + assert event.sender_did == did + assert event.receiver_did == did + assert event.connection_handle is not None + + yield listener_handle, event.connection_handle, connection_handle, wallet_handle, did + + await agent.agent_close_connection(event.connection_handle) + await agent.agent_close_connection(connection_handle) diff --git a/wrappers/python/tests/agent/test_agent_add_idenitity.py b/wrappers/python/tests/agent/test_agent_add_idenitity.py new file mode 100644 index 0000000000..eebc3d0e5f --- /dev/null +++ b/wrappers/python/tests/agent/test_agent_add_idenitity.py @@ -0,0 +1,11 @@ +import pytest + + +@pytest.mark.asyncio +async def test_agent_add_identity_works(listener_with_identity): + assert listener_with_identity is not None + + +@pytest.mark.asyncio +async def test_agent_add_identity_works_for_multiply_keys(listener_with_identities): + assert listener_with_identities is not None diff --git a/wrappers/python/tests/agent/test_agent_connect.py b/wrappers/python/tests/agent/test_agent_connect.py index d0c61d83f7..50b786f91b 100644 --- a/wrappers/python/tests/agent/test_agent_connect.py +++ b/wrappers/python/tests/agent/test_agent_connect.py @@ -6,54 +6,7 @@ from indy import signus, agent from ..utils import storage, wallet -logging.basicConfig(level=logging.DEBUG) - -endpoint = "127.0.0.1:9701" - - -@pytest.fixture -def cleanup_storage(): - storage.cleanup() - yield - storage.cleanup() - - -# noinspection PyUnusedLocal -@pytest.fixture -async def wallet_with_identities(cleanup_storage): - wallet_handle = await wallet.create_and_open_wallet() - did, verkey, pk = await signus.create_and_store_my_did(wallet_handle, "{}") - await signus.store_their_did(wallet_handle, json.dumps({ - "did": did, - "verkey": verkey, - "pk": pk, - "endpoint": endpoint})) - - yield wallet_handle, did - - await wallet.close_wallet(wallet_handle) - @pytest.mark.asyncio -async def test_agent_connect_works(wallet_with_identities): - wallet_handle, did = wallet_with_identities - - listener_handle = await agent.agent_listen(endpoint) - assert listener_handle is not None - - await agent.agent_add_identity(listener_handle, -1, wallet_handle, did) - - connection_handle = await agent.agent_connect(0, wallet_handle, did, did) - assert connection_handle is not None - - event = await agent.agent_wait_for_event([listener_handle, connection_handle]) # type: agent.ConnectionEvent - - assert type(event) is agent.ConnectionEvent - assert event.handle == listener_handle - assert event.sender_did == did - assert event.receiver_did == did - assert event.connection_handle is not None - - await agent.agent_close_connection(event.connection_handle) - await agent.agent_close_connection(connection_handle) - await agent.agent_close_listener(listener_handle) +async def test_agent_connect_works(connection): + assert connection is not None diff --git a/wrappers/python/tests/agent/test_agent_listen.py b/wrappers/python/tests/agent/test_agent_listen.py index 157183c57b..6412e45c8b 100644 --- a/wrappers/python/tests/agent/test_agent_listen.py +++ b/wrappers/python/tests/agent/test_agent_listen.py @@ -1,59 +1,6 @@ -import json -import logging - import pytest -from indy import signus, agent -from ..utils import storage, wallet - -logging.basicConfig(level=logging.DEBUG) - -endpoint = "127.0.0.1:9701" - - -@pytest.fixture(autouse=True) -def cleanup_storage(): - storage.cleanup() - yield - storage.cleanup() - - -# noinspection PyUnusedLocal -@pytest.fixture -async def wallet_with_identities(cleanup_storage): - wallet_handle = await wallet.create_and_open_wallet() - did, verkey, pk = await signus.create_and_store_my_did(wallet_handle, "{}") - await signus.store_their_did(wallet_handle, json.dumps({ - "did": did, - "verkey": verkey, - "pk": pk, - "endpoint": endpoint})) - - yield wallet_handle, did - - await wallet.close_wallet(wallet_handle) - @pytest.mark.asyncio -async def test_agent_listen_works(wallet_with_identities): - wallet_handle, did = wallet_with_identities - - listener_handle = await agent.agent_listen(endpoint) +async def test_agent_listen_works(listener_handle): assert listener_handle is not None - - await agent.agent_add_identity(listener_handle, -1, wallet_handle, did) - - connection_handle = await agent.agent_connect(0, wallet_handle, did, did) - assert connection_handle is not None - - event = await agent.agent_wait_for_event([listener_handle, connection_handle]) # type: agent.ConnectionEvent - - assert type(event) is agent.ConnectionEvent - assert event.handle == listener_handle - assert event.sender_did == did - assert event.receiver_did == did - assert event.connection_handle is not None - - await agent.agent_close_connection(event.connection_handle) - await agent.agent_close_connection(connection_handle) - await agent.agent_close_listener(listener_handle) diff --git a/wrappers/python/tests/conftest.py b/wrappers/python/tests/conftest.py new file mode 100644 index 0000000000..f26f5683c9 --- /dev/null +++ b/wrappers/python/tests/conftest.py @@ -0,0 +1,23 @@ +import logging + +import pytest + +from .utils import storage, wallet + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture +def cleanup_storage(): + storage.cleanup() + yield + storage.cleanup() + + +# noinspection PyUnusedLocal +@pytest.fixture +async def wallet_handle(cleanup_storage): + wallet_handle = await wallet.create_and_open_wallet() + assert type(wallet_handle) is int + yield wallet_handle + await wallet.close_wallet(wallet_handle) From 42f28e0e45a8de9a1ad6097e70617e4ee5b91c61 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Mon, 24 Jul 2017 17:31:57 +0300 Subject: [PATCH 319/349] * agent_close_connection tests were added --- wrappers/python/tests/agent/conftest.py | 2 +- .../agent/test_agent_close_connection.py | 45 +++++++++++++++++++ .../python/tests/agent/test_agent_connect.py | 6 --- 3 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 wrappers/python/tests/agent/test_agent_close_connection.py diff --git a/wrappers/python/tests/agent/conftest.py b/wrappers/python/tests/agent/conftest.py index a6c47ddc6d..a83d4ecd20 100644 --- a/wrappers/python/tests/agent/conftest.py +++ b/wrappers/python/tests/agent/conftest.py @@ -67,7 +67,7 @@ async def connection(listener_with_identity): connection_handle = await agent.agent_connect(0, wallet_handle, did, did) assert connection_handle is not None - event = await agent.agent_wait_for_event(listener_handle) # type: agent.ConnectionEvent + event = await agent.agent_wait_for_event([listener_handle]) # type: agent.ConnectionEvent assert type(event) is agent.ConnectionEvent assert event.handle == listener_handle diff --git a/wrappers/python/tests/agent/test_agent_close_connection.py b/wrappers/python/tests/agent/test_agent_close_connection.py new file mode 100644 index 0000000000..405e361c3e --- /dev/null +++ b/wrappers/python/tests/agent/test_agent_close_connection.py @@ -0,0 +1,45 @@ +import pytest + +from indy import agent, IndyError +from indy.error import ErrorCode + + +@pytest.mark.asyncio +async def test_agent_close_connection_works_for_outgoing(listener_with_identity): + listener_handle, wallet_handle, did = listener_with_identity + + connection_handle = await agent.agent_connect(0, wallet_handle, did, did) + assert connection_handle is not None + + await agent.agent_close_connection(connection_handle) + + try: + await agent.agent_send(connection_handle, "msg") + raise Exception("Failed") + except Exception as e: + assert type(IndyError(ErrorCode.CommonInvalidStructure)) == type(e) \ + and IndyError(ErrorCode.CommonInvalidStructure).args == e.args + + +@pytest.mark.asyncio +async def test_agent_close_connection_works_for_incoming(listener_with_identity): + listener_handle, wallet_handle, did = listener_with_identity + + connection_handle = await agent.agent_connect(0, wallet_handle, did, did) + assert connection_handle is not None + + event = await agent.agent_wait_for_event([listener_handle]) # type: agent.ConnectionEvent + + assert type(event) is agent.ConnectionEvent + assert event.connection_handle is not None + + await agent.agent_close_connection(event.connection_handle) + + try: + await agent.agent_send(event.connection_handle, "msg") + raise Exception("Failed") + except Exception as e: + assert type(IndyError(ErrorCode.CommonInvalidStructure)) == type(e) \ + and IndyError(ErrorCode.CommonInvalidStructure).args == e.args + finally: + await agent.agent_close_connection(connection_handle) diff --git a/wrappers/python/tests/agent/test_agent_connect.py b/wrappers/python/tests/agent/test_agent_connect.py index 50b786f91b..a369bdda7e 100644 --- a/wrappers/python/tests/agent/test_agent_connect.py +++ b/wrappers/python/tests/agent/test_agent_connect.py @@ -1,11 +1,5 @@ -import json -import logging - import pytest -from indy import signus, agent -from ..utils import storage, wallet - @pytest.mark.asyncio async def test_agent_connect_works(connection): From 40dca63a8499f6d58d1e619a99a07319ca3955e6 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 25 Jul 2017 09:06:20 +0300 Subject: [PATCH 320/349] Implemented agent demo integration test for python wrapper --- wrappers/python/tests/demo/agent.py | 89 +++++++++++++++++++++++++ wrappers/python/tests/demo/anoncreds.py | 6 +- wrappers/python/tests/demo/ledger.py | 2 +- 3 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 wrappers/python/tests/demo/agent.py diff --git a/wrappers/python/tests/demo/agent.py b/wrappers/python/tests/demo/agent.py new file mode 100644 index 0000000000..9bc4b43719 --- /dev/null +++ b/wrappers/python/tests/demo/agent.py @@ -0,0 +1,89 @@ +from indy import agent +from indy import ledger, signus, wallet, pool +from indy.pool import open_pool_ledger + +from tests.utils import storage + +import pytest +import logging +import json + +from tests.utils.pool import create_genesis_txn_file + +logging.basicConfig(level=logging.DEBUG) + + +@pytest.fixture(autouse=True) +def before_after_each(): + storage.cleanup() + yield + storage.cleanup() + + +@pytest.mark.asyncio +async def test_agent_demo_works(): + pool_name = "pool" + listener_wallet_name = "listener_wallet" + sender_wallet_name = "sender_wallet" + + # 1. Create ledger config from genesis txn file + file_name = pool_name + '.txn' + path = create_genesis_txn_file(file_name, None) + pool_config = json.dumps({"genesis_txn": str(path)}) + await pool.create_pool_ledger_config(pool_name, pool_config) + + # 2. Open pool ledger + pool_handle = await open_pool_ledger(pool_name, None) + + # 3. Create and Open Listener Wallet. Gets wallet handle + await wallet.create_wallet(pool_name, listener_wallet_name, None, None, None) + listener_wallet_handle = await wallet.open_wallet(listener_wallet_name, None, None) + + # 4. Create and Open Sender Wallet. Gets wallet handle + await wallet.create_wallet(pool_name, sender_wallet_name, None, None, None) + sender_wallet_handle = await wallet.open_wallet(sender_wallet_name, None, None) + + # 5. Create Listener DID + (listener_did, listener_verkey, listener_pk) = await signus.create_and_store_my_did(listener_wallet_handle, "{}") + + # 6. Create Sender DID from Trustee1 seed + (sender_did, sender_verkey, sender_pk) = \ + await signus.create_and_store_my_did(sender_wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') + + # 7. Prepare and send NYM transaction + nym_txn_req = await ledger.build_nym_request(sender_did, listener_did, listener_verkey, None, None) + await ledger.sign_and_submit_request(pool_handle, sender_wallet_handle, sender_did, nym_txn_req.decode()) + + # 8. Prepare and send GET_NYM request + endpoint = "127.0.0.1:5555" + raw = { + "endpoint": { + "ha": endpoint, + "verkey": listener_pk + } + } + + # 8. Prepare and send Attrib request + attrib_txn_req = await ledger.build_attrib_request(listener_did, listener_did, None, json.dumps(raw), None) + await ledger.sign_and_submit_request(pool_handle, listener_wallet_handle, listener_did, attrib_txn_req.decode()) + + # 8. Start listener on endpoint + listener_handle = await agent.agent_listen(endpoint) + + # 9. Allow listener accept incoming connection for specific DID (listener_did) + await agent.agent_add_identity(listener_handle, pool_handle, listener_wallet_handle, listener_did) + + # 10. Initiate connection from sender to listener + connection_handle = await agent.agent_connect(pool_handle, sender_wallet_handle, sender_did, listener_did) + + # 11. Send test message from sender to listener + message = 'msg_from_sender_to_listener' + await agent.agent_send(connection_handle, message) + + # 12. Close connection, listener, wallets, pool + await agent.agent_close_listener(listener_handle) + await agent.agent_close_connection(connection_handle) + + await wallet.close_wallet(listener_wallet_handle) + await wallet.close_wallet(sender_wallet_handle) + await pool.close_pool_ledger(pool_handle) diff --git a/wrappers/python/tests/demo/anoncreds.py b/wrappers/python/tests/demo/anoncreds.py index d13a1ba43d..fc39d5bfc1 100644 --- a/wrappers/python/tests/demo/anoncreds.py +++ b/wrappers/python/tests/demo/anoncreds.py @@ -48,7 +48,7 @@ async def test_anoncreds_demo_works(): # 4. Prover create Claim Request prover_did = 'BzfFCYk' claim_offer = { - 'issuer_did': 'NcYxiDXkpYi6ov5FcYDi1e', + 'issuer_did': issuer_did, 'schema_seq_no': schema_seq_no } @@ -84,9 +84,9 @@ async def test_anoncreds_demo_works(): proof_req_json = json.dumps(proof_req) claim_for_proof_json = await anoncreds.prover_get_claims_for_proof_req(wallet_handle, proof_req_json) - claim_for_proof_json = json.loads(claim_for_proof_json) + claims_for_proof = json.loads(claim_for_proof_json) - claim_for_attr1 = claim_for_proof_json['attrs']['attr1_uuid'] + claim_for_attr1 = claims_for_proof['attrs']['attr1_uuid'] assert 1 == len(claim_for_attr1) claim_uuid = claim_for_attr1[0]['claim_uuid'] diff --git a/wrappers/python/tests/demo/ledger.py b/wrappers/python/tests/demo/ledger.py index 07a95c7c06..16727b0e27 100644 --- a/wrappers/python/tests/demo/ledger.py +++ b/wrappers/python/tests/demo/ledger.py @@ -32,7 +32,7 @@ async def test_ledger_demo_works(): await pool.create_pool_ledger_config(pool_name, pool_config) # 2. Open pool ledger - pool_handle = await open_pool_ledger(pool_name, "") + pool_handle = await open_pool_ledger(pool_name, None) # 3. Create My Wallet and Get Wallet Handle await wallet.create_wallet(pool_name, my_wallet_name, None, None, None) From 2fc1b276ebeee840895ce1de4f9cadf79c324425 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 25 Jul 2017 10:47:34 +0300 Subject: [PATCH 321/349] added tests for create_and_store_claim_def --- .../test_issuer_create_and_store_claim_def.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/wrappers/python/tests/anoncreds/test_issuer_create_and_store_claim_def.py b/wrappers/python/tests/anoncreds/test_issuer_create_and_store_claim_def.py index dbcd872309..736e8d981e 100644 --- a/wrappers/python/tests/anoncreds/test_issuer_create_and_store_claim_def.py +++ b/wrappers/python/tests/anoncreds/test_issuer_create_and_store_claim_def.py @@ -1,5 +1,6 @@ from indy import wallet from indy.anoncreds import issuer_create_and_store_claim_def +from indy.error import ErrorCode, IndyError from tests.utils import storage, anoncreds from tests.utils.wallet import create_and_open_wallet @@ -36,3 +37,17 @@ async def test_issuer_create_and_store_claim_def_works(wallet_handle): assert len(claim_def_json['data']['primary']['rms']) > 0 assert len(claim_def_json['data']['primary']['z']) > 0 assert len(claim_def_json['data']['primary']['rctxt']) > 0 + + +@pytest.mark.asyncio +async def test_issuer_create_and_store_claim_def_works_for_invalid_wallet(wallet_handle): + schema = anoncreds.get_gvt_schema_json(1) + invalid_wallet_handle = wallet_handle + 100 + + try: + await issuer_create_and_store_claim_def( + invalid_wallet_handle, anoncreds.ISSUER_DID, json.dumps(schema), None, False) + raise Exception("Failed") + except Exception as e: + assert type(IndyError(ErrorCode.WalletInvalidHandle)) == type(e) and \ + IndyError(ErrorCode.WalletInvalidHandle).args == e.args \ No newline at end of file From aaab8ee87cba787b72ba4f3af60c2e3b6cb9b448 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 25 Jul 2017 10:56:25 +0300 Subject: [PATCH 322/349] added tests for prover_store_claim_offer --- .../test_prover_store_claim_offer.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/wrappers/python/tests/anoncreds/test_prover_store_claim_offer.py b/wrappers/python/tests/anoncreds/test_prover_store_claim_offer.py index b65271b513..d167f7788b 100644 --- a/wrappers/python/tests/anoncreds/test_prover_store_claim_offer.py +++ b/wrappers/python/tests/anoncreds/test_prover_store_claim_offer.py @@ -1,5 +1,6 @@ from indy import wallet from indy.anoncreds import prover_store_claim_offer +from indy.error import ErrorCode, IndyError from tests.utils import storage, anoncreds from tests.utils.wallet import create_and_open_wallet @@ -31,3 +32,27 @@ async def test_prover_store_claim_offer_works(wallet_handle): claim_offer = anoncreds.get_claim_offer(anoncreds.ISSUER_DID, 1) await prover_store_claim_offer(wallet_handle, json.dumps(claim_offer)) + +@pytest.mark.asyncio +async def test_prover_store_claim_offer_works_for_invalid_json(wallet_handle): + claim_offer = {"issuer_did": anoncreds.ISSUER_DID} + + try: + await prover_store_claim_offer(wallet_handle, json.dumps(claim_offer)) + raise Exception("Failed") + except Exception as e: + assert type(IndyError(ErrorCode.CommonInvalidStructure)) == type(e) and \ + IndyError(ErrorCode.CommonInvalidStructure).args == e.args + + +@pytest.mark.asyncio +async def test_prover_store_claim_offer_works_for_invalid_wallet(wallet_handle): + claim_offer = anoncreds.get_claim_offer(anoncreds.ISSUER_DID, 1) + invalid_wallet_handle = wallet_handle + 100 + + try: + await prover_store_claim_offer(invalid_wallet_handle, json.dumps(claim_offer)) + raise Exception("Failed") + except Exception as e: + assert type(IndyError(ErrorCode.WalletInvalidHandle)) == type(e) and \ + IndyError(ErrorCode.WalletInvalidHandle).args == e.args From b9325fca344a7bb7795bf6ac09cf1abe5d7a4ce2 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 25 Jul 2017 11:01:00 +0300 Subject: [PATCH 323/349] Added jenkins pupeline for python wrapper --- .gitignore | 3 +- python.dockerfile | 28 +++++++++++ wrappers/python/.gitignore | 1 + wrappers/python/Jenkinsfile | 92 +++++++++++++++++++++++++++++++++++++ wrappers/python/setup.py | 2 +- 5 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 python.dockerfile create mode 100644 wrappers/python/.gitignore create mode 100644 wrappers/python/Jenkinsfile diff --git a/.gitignore b/.gitignore index 2a51587df7..0642927510 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,4 @@ Cargo.lock .venv .cache .DS_Store -Podfile.lock - +Podfile.lock \ No newline at end of file diff --git a/python.dockerfile b/python.dockerfile new file mode 100644 index 0000000000..0005b6d7ae --- /dev/null +++ b/python.dockerfile @@ -0,0 +1,28 @@ +FROM ubuntu:16.04 + +ARG uid=1000 + +RUN apt-get update && \ + apt-get install -y \ + gdebi \ + apt-utils \ + software-properties-common + +RUN add-apt-repository ppa:jonathonf/python-3.6 + +RUN apt-get update && \ + apt-get install -y \ + python3.6 \ + python3-pip + +ADD https://repo.evernym.com/deb/indy-sdk/0.1.1/indy-sdk_0.1.1_amd64.deb . + +RUN gdebi -n indy-sdk_0.1.1_amd64.deb + +RUN useradd -ms /bin/bash -u $uid indy +USER indy + +WORKDIR /home/indy + + + diff --git a/wrappers/python/.gitignore b/wrappers/python/.gitignore new file mode 100644 index 0000000000..0d20b6487c --- /dev/null +++ b/wrappers/python/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/wrappers/python/Jenkinsfile b/wrappers/python/Jenkinsfile new file mode 100644 index 0000000000..a80cfcc89a --- /dev/null +++ b/wrappers/python/Jenkinsfile @@ -0,0 +1,92 @@ +#!groovy​ + +@Library('SovrinHelpers') _ + +name = 'indy-sdk' +def err +def publishBranch = (env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'devel') + +try { + +// ALL BRANCHES: master, devel, PRs + + // 1. TEST + stage('Test') { + parallel 'ubuntu-python-test': { + node('ubuntu') { + stage('Ubuntu Python Test') { + pythonTestUbuntu() + } + } + } + } + +} catch (e) { + currentBuild.result = "FAILED" + node('ubuntu-master') { + sendNotification.fail([slack: publishBranch]) + } + err = e +} finally { + if (err) { + throw err + } + currentBuild.result = "SUCCESS" + if (publishBranch) { + node('ubuntu-master') { + sendNotification.success(name) + } + } +} + +def pythonTestUbuntu() { + def poolInst + def network_name = "pool_network" + try { + echo 'Ubuntu Python Test: Checkout csm' + checkout scm + + echo "Ubuntu Python Test: Create docker network (${network_name}) for nodes pool and test image" + sh "docker network create --subnet=10.0.0.0/8 ${network_name}" + + echo 'Ubuntu Python Test: Build docker image for nodes pool' + def poolEnv = dockerHelpers.build('indy_pool', 'ci/indy-pool.dockerfile ci') + echo 'Ubuntu Python Test: Run nodes pool' + poolInst = poolEnv.run("--ip=\"10.0.0.2\" --network=${network_name}") + + echo 'Ubuntu Python Test: Build docker image' + def testEnv = dockerHelpers.build(name, 'ci/python.dockerfile ci') + + testEnv.inside("--ip=\"10.0.0.3\" --network=${network_name}") { + echo 'Ubuntu Python Test: Test' + + sh ''' + cd wrappers/python + python3.6 -m pip install -e . + pytest + ''' + } + } + finally { + echo 'Ubuntu Python Test: Cleanup' + try { + sh "docker network inspect ${network_name}" + } catch (ignore) { + } + try { + if (poolInst) { + echo 'Ubuntu Python Test: stop pool' + poolInst.stop() + } + } catch (err) { + echo "Ubuntu Python Tests: error while stop pool ${err}" + } + try { + echo "Ubuntu Python Test: remove pool network ${network_name}" + sh "docker network rm ${network_name}" + } catch (err) { + echo "Ubuntu Python Test: error while delete ${network_name} - ${err}" + } + step([$class: 'WsCleanup']) + } +} \ No newline at end of file diff --git a/wrappers/python/setup.py b/wrappers/python/setup.py index e91cad4532..6cb3df422f 100644 --- a/wrappers/python/setup.py +++ b/wrappers/python/setup.py @@ -9,6 +9,6 @@ author='Vyacheslav Gudkov', author_email='vyacheslav.gudkov@dsr-company.com', description='This is the official SDK for Hyperledger Indy (https://www.hyperledger.org/projects), which provides a distributed-ledger-based foundation for self-sovereign identity (https://sovrin.org). The major artifact of the SDK is a c-callable library.', - install_requires=[], + install_requires=['pytest', 'pytest-asyncio', 'base58'], tests_require=['pytest', 'pytest-asyncio', 'base58'] ) From fa0b4597d60ab9ad8c47ca733e4431796dfd2c8b Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 25 Jul 2017 11:06:22 +0300 Subject: [PATCH 324/349] Returned installation of libsodium-devel --- ci/amazon.dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ci/amazon.dockerfile b/ci/amazon.dockerfile index 050457c383..bbf3f9e637 100644 --- a/ci/amazon.dockerfile +++ b/ci/amazon.dockerfile @@ -6,12 +6,15 @@ RUN \ yum clean all \ && yum upgrade -y \ && yum groupinstall -y "Development Tools" \ + && yum install -y epel-release \ + && yum-config-manager --enable epel \ && yum install -y \ wget \ cmake \ pkgconfig \ openssl-devel \ sqlite-devel \ + libsodium-devel \ spectool From 572dfa3c101cfc04e18c1064691ec4956ade4f9a Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 25 Jul 2017 11:08:51 +0300 Subject: [PATCH 325/349] Moved python dockerfile --- python.dockerfile => ci/python.dockerfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename python.dockerfile => ci/python.dockerfile (100%) diff --git a/python.dockerfile b/ci/python.dockerfile similarity index 100% rename from python.dockerfile rename to ci/python.dockerfile From b15a9879e7f4d55f1eec777bc0387f157d696063 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 25 Jul 2017 11:29:30 +0300 Subject: [PATCH 326/349] Corrected pipeline --- wrappers/python/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrappers/python/Jenkinsfile b/wrappers/python/Jenkinsfile index a80cfcc89a..628beeb634 100644 --- a/wrappers/python/Jenkinsfile +++ b/wrappers/python/Jenkinsfile @@ -63,7 +63,7 @@ def pythonTestUbuntu() { sh ''' cd wrappers/python python3.6 -m pip install -e . - pytest + python3.6 -m pytest ''' } } From fca6c3eb4923a72fa96ebdb00b98cf709c5e0e86 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gudkov Date: Tue, 25 Jul 2017 11:35:32 +0300 Subject: [PATCH 327/349] * Bugfixes in Agent API * Added high cases tests for agent_close_listener, agent_connect, agent_remove_identity, agent_send --- wrappers/python/indy/agent.py | 9 +-- wrappers/python/tests/agent/conftest.py | 11 ++-- .../tests/agent/test_agent_close_listener.py | 32 +++++++++ .../python/tests/agent/test_agent_connect.py | 65 ++++++++++++++++++- .../agent/test_agent_remove_idenitity.py | 9 +++ .../python/tests/agent/test_agent_send.py | 25 +++++++ wrappers/python/tests/conftest.py | 16 ++++- wrappers/python/tests/utils/pool.py | 6 +- 8 files changed, 159 insertions(+), 14 deletions(-) create mode 100644 wrappers/python/tests/agent/test_agent_close_listener.py create mode 100644 wrappers/python/tests/agent/test_agent_remove_idenitity.py create mode 100644 wrappers/python/tests/agent/test_agent_send.py diff --git a/wrappers/python/indy/agent.py b/wrappers/python/indy/agent.py index 2379879716..f18e45b2a6 100644 --- a/wrappers/python/indy/agent.py +++ b/wrappers/python/indy/agent.py @@ -78,7 +78,7 @@ def __init__(self, handle: int, err: int, message: bytes): err, message) - self.handle = handle, + self.handle = handle if err != ErrorCode.Success: self._error = IndyError(ErrorCode(err)) @@ -310,7 +310,6 @@ async def agent_add_identity(listener_handle: int, async def agent_remove_identity(listener_handle: int, - pool_handle: int, wallet_handle: int, did: str) -> None: """ @@ -323,14 +322,12 @@ async def agent_remove_identity(listener_handle: int, After successfully rm_identity listener will stop to accept incoming connection to removed DID. :param listener_handle: listener handle (created by indy_agent_listen). - :param pool_handle: pool handle (create by open_pool_ledger) :param wallet_handle: wallet handle (created by open_wallet). :param did: DID of identity. """ logger = logging.getLogger(__name__) - logger.debug("agent_remove_identity: >>> listener_handle: %r, pool_handle: %r, wallet_handle: %r, did: %r", + logger.debug("agent_remove_identity: >>> listener_handle: %r, wallet_handle: %r, did: %r", listener_handle, - pool_handle, wallet_handle, did) @@ -339,13 +336,11 @@ async def agent_remove_identity(listener_handle: int, agent_remove_identity.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32)) c_listener_handle = c_int32(listener_handle) - c_pool_handle = c_int32(pool_handle) c_wallet_handle = c_int32(wallet_handle) c_did = c_char_p(did.encode('utf-8')) await do_call('indy_agent_remove_identity', c_listener_handle, - c_pool_handle, c_wallet_handle, c_did, agent_remove_identity.cb) diff --git a/wrappers/python/tests/agent/conftest.py b/wrappers/python/tests/agent/conftest.py index a83d4ecd20..8c3fcb88ce 100644 --- a/wrappers/python/tests/agent/conftest.py +++ b/wrappers/python/tests/agent/conftest.py @@ -4,11 +4,14 @@ from indy import signus, agent -endpoint = "127.0.0.1:9701" + +@pytest.fixture +async def endpoint(): + return "127.0.0.1:9701" @pytest.fixture -async def wallet_with_identity(wallet_handle): +async def wallet_with_identity(wallet_handle, endpoint): did, verkey, pk = await signus.create_and_store_my_did(wallet_handle, "{}") await signus.store_their_did(wallet_handle, json.dumps({ @@ -22,7 +25,7 @@ async def wallet_with_identity(wallet_handle): @pytest.fixture -async def wallet_with_identities(wallet_with_identity): +async def wallet_with_identities(wallet_with_identity, endpoint): wallet_handle, did1 = wallet_with_identity did2, verkey2, pk2 = await signus.create_and_store_my_did(wallet_handle, "{}") @@ -38,7 +41,7 @@ async def wallet_with_identities(wallet_with_identity): @pytest.fixture -async def listener_handle(): +async def listener_handle(endpoint): listener_handle = await agent.agent_listen(endpoint) assert type(listener_handle) is int yield listener_handle diff --git a/wrappers/python/tests/agent/test_agent_close_listener.py b/wrappers/python/tests/agent/test_agent_close_listener.py new file mode 100644 index 0000000000..9e37abd957 --- /dev/null +++ b/wrappers/python/tests/agent/test_agent_close_listener.py @@ -0,0 +1,32 @@ +import pytest + +from indy import agent, IndyError +from indy.error import ErrorCode + + +@pytest.mark.asyncio +async def test_agent_close_listener_works_for_outgoing(endpoint, wallet_with_identity): + listener_handle = await agent.agent_listen(endpoint) + assert type(listener_handle) is int + + wallet_handle, did = wallet_with_identity + await agent.agent_add_identity(listener_handle, -1, wallet_handle, did) + + connection_handle = await agent.agent_connect(0, wallet_handle, did, did) + assert connection_handle is not None + + event = await agent.agent_wait_for_event([listener_handle]) # type: agent.ConnectionEvent + + assert type(event) is agent.ConnectionEvent + assert event.connection_handle is not None + + await agent.agent_close_listener(listener_handle) + + try: + await agent.agent_send(event.connection_handle, "msg") + raise Exception("Failed") + except Exception as e: + assert type(IndyError(ErrorCode.CommonInvalidStructure)) == type(e) \ + and IndyError(ErrorCode.CommonInvalidStructure).args == e.args + finally: + await agent.agent_close_connection(connection_handle) diff --git a/wrappers/python/tests/agent/test_agent_connect.py b/wrappers/python/tests/agent/test_agent_connect.py index a369bdda7e..8462a845a5 100644 --- a/wrappers/python/tests/agent/test_agent_connect.py +++ b/wrappers/python/tests/agent/test_agent_connect.py @@ -1,6 +1,69 @@ +import json + import pytest +from indy import signus, ledger, agent +from tests.utils import wallet + + +@pytest.mark.asyncio +async def test_agent_connect_works_for_remote_data(pool_handle, + trustee1_seed): + endpoint = "127.0.0.1:9705" + + listener_wallet_handle = await wallet.create_and_open_wallet(wallet_name="listener_wallet") + trustee_wallet_handle = await wallet.create_and_open_wallet(wallet_name="trustee_wallet") + + listener_did, listener_verkey, listener_pk = await signus.create_and_store_my_did(listener_wallet_handle, "{}") + + trustee_did, trustee_verkey, trustee_pk = await signus.create_and_store_my_did( + trustee_wallet_handle, + json.dumps({ + "seed": trustee1_seed + })) + + nym_request = await ledger.build_nym_request(trustee_did, listener_did, listener_verkey, None, None) + await ledger.sign_and_submit_request(pool_handle, listener_wallet_handle, trustee_did, nym_request) + + attrib_request = await ledger.build_attrib_request( + listener_did, + listener_did, + None, + json.dumps({ + "endpoint": { + "ha": endpoint, + "verkey": listener_pk + } + }), + None) + await ledger.sign_and_submit_request(pool_handle, listener_wallet_handle, listener_did, attrib_request) + + listener_handle = await agent.agent_listen(endpoint) + await agent.agent_add_identity(listener_handle, pool_handle, listener_wallet_handle, listener_did) + + sender_did = trustee_did + sender_wallet_handle = trustee_wallet_handle + connection_handle = await agent.agent_connect(pool_handle, + sender_wallet_handle, + sender_did, + listener_did) + assert connection_handle is not None + + connection_event = await agent.agent_wait_for_event([listener_handle]) # type: agent.ConnectionEvent + + assert type(connection_event) is agent.ConnectionEvent + assert connection_event.handle == listener_handle + assert connection_event.sender_did == sender_did + assert connection_event.receiver_did == listener_did + assert connection_event.connection_handle is not None + + await agent.agent_close_connection(connection_handle) + await agent.agent_close_connection(connection_event.handle) + await agent.agent_close_listener(listener_handle) + await wallet.close_wallet(listener_wallet_handle) + await wallet.close_wallet(trustee_wallet_handle) + @pytest.mark.asyncio -async def test_agent_connect_works(connection): +async def test_agent_connect_works_for_all_data_in_wallet_present(connection): assert connection is not None diff --git a/wrappers/python/tests/agent/test_agent_remove_idenitity.py b/wrappers/python/tests/agent/test_agent_remove_idenitity.py new file mode 100644 index 0000000000..68d2228711 --- /dev/null +++ b/wrappers/python/tests/agent/test_agent_remove_idenitity.py @@ -0,0 +1,9 @@ +import pytest + +from indy import agent + + +@pytest.mark.asyncio +async def test_agent_remove_identity_works(listener_with_identity): + listener_handle, wallet_handle, did = listener_with_identity + await agent.agent_remove_identity(listener_handle, wallet_handle, did) diff --git a/wrappers/python/tests/agent/test_agent_send.py b/wrappers/python/tests/agent/test_agent_send.py new file mode 100644 index 0000000000..284b377891 --- /dev/null +++ b/wrappers/python/tests/agent/test_agent_send.py @@ -0,0 +1,25 @@ +import json + +import pytest + +from indy import signus, ledger, agent +from tests.utils import wallet + + +@pytest.mark.asyncio +async def test_agent_send_works_for_all_data_in_wallet_present(connection): + listener_handle, inc_con_handle, out_con_handle, wallet_handle, did = connection + + await agent.agent_send(out_con_handle, "msg_from_client") + message_event = await agent.agent_wait_for_event([listener_handle, inc_con_handle]) # type: agent.MessageEvent + + assert type(message_event) is agent.MessageEvent + assert message_event.handle == inc_con_handle + assert message_event.message == "msg_from_client" + + await agent.agent_send(inc_con_handle, "msg_from_server") + message_event = await agent.agent_wait_for_event([out_con_handle]) # type: agent.MessageEvent + + assert type(message_event) is agent.MessageEvent + assert message_event.handle == out_con_handle + assert message_event.message == "msg_from_server" diff --git a/wrappers/python/tests/conftest.py b/wrappers/python/tests/conftest.py index f26f5683c9..3bcb4cc4dd 100644 --- a/wrappers/python/tests/conftest.py +++ b/wrappers/python/tests/conftest.py @@ -2,11 +2,16 @@ import pytest -from .utils import storage, wallet +from .utils import pool, storage, wallet logging.basicConfig(level=logging.DEBUG) +@pytest.fixture +def trustee1_seed(): + return "000000000000000000000000Trustee1" + + @pytest.fixture def cleanup_storage(): storage.cleanup() @@ -21,3 +26,12 @@ async def wallet_handle(cleanup_storage): assert type(wallet_handle) is int yield wallet_handle await wallet.close_wallet(wallet_handle) + + +# noinspection PyUnusedLocal +@pytest.fixture +async def pool_handle(cleanup_storage): + pool_handle = await pool.create_and_open_pool_ledger() + assert type(pool_handle) is int + yield pool_handle + await pool.close_pool_ledger(pool_handle) diff --git a/wrappers/python/tests/utils/pool.py b/wrappers/python/tests/utils/pool.py index b8426f4ee0..cdb40f8ade 100644 --- a/wrappers/python/tests/utils/pool.py +++ b/wrappers/python/tests/utils/pool.py @@ -30,8 +30,12 @@ def create_genesis_txn_file(file_name, predefined_data=None): return path -async def create_and_open_pool_ledger(name): +async def create_and_open_pool_ledger(name="pool_1"): await create_pool_ledger_config(name) pool_handle = await pool.open_pool_ledger(name, "") assert pool_handle is not None return pool_handle + + +async def close_pool_ledger(pool_handle): + await pool.close_pool_ledger(pool_handle) From 27584a36a395785b4798c6ebd6c4b65f69275d47 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 25 Jul 2017 11:45:23 +0300 Subject: [PATCH 328/349] Updated python pipeline --- wrappers/python/Jenkinsfile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/wrappers/python/Jenkinsfile b/wrappers/python/Jenkinsfile index 628beeb634..09d86d6579 100644 --- a/wrappers/python/Jenkinsfile +++ b/wrappers/python/Jenkinsfile @@ -68,16 +68,15 @@ def pythonTestUbuntu() { } } finally { - echo 'Ubuntu Python Test: Cleanup' + echo "Ubuntu Python Test: Cleanup" try { sh "docker network inspect ${network_name}" - } catch (ignore) { + } catch (err) { + echo "Ubuntu Python Tests: error while inspect network ${network_name} - ${err}" } try { - if (poolInst) { - echo 'Ubuntu Python Test: stop pool' - poolInst.stop() - } + echo "Ubuntu Python Test: stop pool" + poolInst.stop() } catch (err) { echo "Ubuntu Python Tests: error while stop pool ${err}" } From 17d13e40ac3c9a920c405514ee29291823ec8832 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 25 Jul 2017 11:52:03 +0300 Subject: [PATCH 329/349] added tests for get_claim_offers --- .../anoncreds/test_prover_get_claim_offers.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/wrappers/python/tests/anoncreds/test_prover_get_claim_offers.py b/wrappers/python/tests/anoncreds/test_prover_get_claim_offers.py index fd549b3cee..4abae590f2 100644 --- a/wrappers/python/tests/anoncreds/test_prover_get_claim_offers.py +++ b/wrappers/python/tests/anoncreds/test_prover_get_claim_offers.py @@ -1,5 +1,6 @@ from indy import wallet from indy.anoncreds import prover_get_claim_offers +from indy.error import ErrorCode, IndyError from tests.utils import storage, anoncreds from tests.utils.wallet import create_and_open_wallet @@ -31,3 +32,48 @@ async def test_prover_get_claim_offers_works_for_empty_filter(wallet_handle): claim_offers = json.loads(await prover_get_claim_offers(wallet_handle, "{}")) assert len(claim_offers) == 3 + +@pytest.mark.asyncio +async def test_prover_get_claim_offers_works_for_filter_by_issuer(wallet_handle): + claim_offers = json.loads(await prover_get_claim_offers( + wallet_handle, '{{"issuer_did":"{}"}}'.format(anoncreds.ISSUER_DID))) + assert len(claim_offers) == 2 + assert {'issuer_did': anoncreds.ISSUER_DID, 'schema_seq_no': 1} in claim_offers + assert {'issuer_did': anoncreds.ISSUER_DID, 'schema_seq_no': 2} in claim_offers + + +@pytest.mark.asyncio +async def test_prover_get_claim_offers_works_for_filter_by_schema(wallet_handle): + claim_offers = json.loads(await prover_get_claim_offers( + wallet_handle, '{"schema_seq_no":2}')) + assert len(claim_offers) == 2 + assert {'issuer_did': anoncreds.ISSUER_DID, 'schema_seq_no': 2} in claim_offers + assert {'issuer_did': 'CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW', 'schema_seq_no': 2} in claim_offers + + +@pytest.mark.asyncio +async def test_prover_get_claim_offers_works_for_filter_by_issuer_and_schema(wallet_handle): + claim_offers = json.loads(await prover_get_claim_offers( + wallet_handle, json.dumps(anoncreds.get_claim_offer(anoncreds.ISSUER_DID, 1)))) + assert len(claim_offers) == 1 + assert {'issuer_did': anoncreds.ISSUER_DID, 'schema_seq_no': 1} in claim_offers + + +@pytest.mark.asyncio +async def test_prover_get_claim_offers_works_for_no_results(wallet_handle): + claim_offers = json.loads(await prover_get_claim_offers( + wallet_handle, '{"schema_seq_no":4}')) + assert len(claim_offers) == 0 + + +@pytest.mark.asyncio +async def test_prover_get_claim_offers_works_for_invalid_wallet_handle(wallet_handle): + invalid_wallet_handle = wallet_handle + 100 + + try: + await prover_get_claim_offers(invalid_wallet_handle, '{"schema_seq_no":1}') + raise Exception("Failed") + except Exception as e: + assert type(IndyError(ErrorCode.WalletInvalidHandle)) == type(e) and \ + IndyError(ErrorCode.WalletInvalidHandle).args == e.args + From a37635bb5386a9b5ad20161ffe3df2270a41455a Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 25 Jul 2017 11:58:39 +0300 Subject: [PATCH 330/349] added tests for prover_create_master_secret --- .../anoncreds/test_prover_create_master_secret.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/wrappers/python/tests/anoncreds/test_prover_create_master_secret.py b/wrappers/python/tests/anoncreds/test_prover_create_master_secret.py index 016b17b497..9a047fe22e 100644 --- a/wrappers/python/tests/anoncreds/test_prover_create_master_secret.py +++ b/wrappers/python/tests/anoncreds/test_prover_create_master_secret.py @@ -1,5 +1,6 @@ from indy import wallet from indy.anoncreds import prover_create_master_secret +from indy.error import ErrorCode, IndyError from tests.utils import storage, anoncreds from tests.utils.wallet import create_and_open_wallet @@ -29,3 +30,15 @@ async def wallet_handle(): async def test_prover_create_master_secret_works(wallet_handle): await prover_create_master_secret(wallet_handle, "master_secret_name") + +@pytest.mark.asyncio +async def test_prover_create_master_secret_works_invalid_wallet_handle(wallet_handle): + invalid_wallet_handle = wallet_handle + 100 + + try: + await prover_create_master_secret(invalid_wallet_handle, "master_secret_name") + raise Exception("Failed") + except Exception as e: + assert type(IndyError(ErrorCode.WalletInvalidHandle)) == type(e) and \ + IndyError(ErrorCode.WalletInvalidHandle).args == e.args + From 710aea6211103910f5f4e4f110c0632f985d08c8 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 25 Jul 2017 13:16:37 +0300 Subject: [PATCH 331/349] Completed agent demo test --- wrappers/python/tests/demo/agent.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wrappers/python/tests/demo/agent.py b/wrappers/python/tests/demo/agent.py index 9bc4b43719..e1baf24df4 100644 --- a/wrappers/python/tests/demo/agent.py +++ b/wrappers/python/tests/demo/agent.py @@ -75,11 +75,16 @@ async def test_agent_demo_works(): # 10. Initiate connection from sender to listener connection_handle = await agent.agent_connect(pool_handle, sender_wallet_handle, sender_did, listener_did) + event = await agent.agent_wait_for_event([listener_handle]) + inc_con_handle = event.connection_handle # 11. Send test message from sender to listener message = 'msg_from_sender_to_listener' await agent.agent_send(connection_handle, message) + message_event = await agent.agent_wait_for_event([listener_handle, inc_con_handle]) # type: agent.MessageEvent + assert message_event.message == message + # 12. Close connection, listener, wallets, pool await agent.agent_close_listener(listener_handle) await agent.agent_close_connection(connection_handle) From 7ac7d6e2fd0fa1720686d5acea257f1405385e05 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 25 Jul 2017 13:56:37 +0300 Subject: [PATCH 332/349] added tests for prover_create_and_store_claim_req --- .../test_prover_create_and_store_claim_req.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/wrappers/python/tests/anoncreds/test_prover_create_and_store_claim_req.py b/wrappers/python/tests/anoncreds/test_prover_create_and_store_claim_req.py index 47df68bb74..d615aedece 100644 --- a/wrappers/python/tests/anoncreds/test_prover_create_and_store_claim_req.py +++ b/wrappers/python/tests/anoncreds/test_prover_create_and_store_claim_req.py @@ -1,5 +1,6 @@ from indy import wallet from indy.anoncreds import prover_create_and_store_claim_req +from indy.error import ErrorCode, IndyError from tests.utils import storage, anoncreds from tests.utils.wallet import create_and_open_wallet @@ -38,3 +39,49 @@ async def test_prover_create_and_store_claim_req_works(wallet_handle_and_claim_d assert claim_req_json['schema_seq_no'] == schema_seq_no assert claim_req_json['issuer_did'] == anoncreds.ISSUER_DID assert len(claim_req_json['blinded_ms']['u']) > 0 + + +@pytest.mark.asyncio +async def test_prover_create_and_store_claim_req_works_for_invalid_wallet(wallet_handle_and_claim_def): + schema_seq_no = 1 + prover_did = "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW" + invalid_wallet_handle = wallet_handle_and_claim_def[0] + 100 + claim_offer_json = anoncreds.get_claim_offer(anoncreds.ISSUER_DID, schema_seq_no) + + with pytest.raises(IndyError) as e: + await prover_create_and_store_claim_req(invalid_wallet_handle, prover_did, + json.dumps(claim_offer_json), + wallet_handle_and_claim_def[1], + anoncreds.COMMON_MASTER_SECRET_NAME) + + assert ErrorCode.WalletInvalidHandle == e.value.error_code + + +@pytest.mark.asyncio +async def test_prover_create_and_store_claim_req_works_for_claim_def_does_not_correspond_offer_different_issuer_did(wallet_handle_and_claim_def): + schema_seq_no = 1 + prover_did = "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW" + claim_offer_json = anoncreds.get_claim_offer("NcYxiDXkpYi6ov5FcYDi1e3", schema_seq_no) + + with pytest.raises(IndyError) as e: + await prover_create_and_store_claim_req(wallet_handle_and_claim_def[0], prover_did, + json.dumps(claim_offer_json), + wallet_handle_and_claim_def[1], + anoncreds.COMMON_MASTER_SECRET_NAME) + + assert ErrorCode.CommonInvalidStructure == e.value.error_code + + +@pytest.mark.asyncio +async def test_prover_create_and_store_claim_req_works_for_claim_def_does_not_correspond_offer_different_schema_seq_no(wallet_handle_and_claim_def): + schema_seq_no = 2 + prover_did = "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW" + claim_offer_json = anoncreds.get_claim_offer(anoncreds.ISSUER_DID, schema_seq_no) + + with pytest.raises(IndyError) as e: + await prover_create_and_store_claim_req(wallet_handle_and_claim_def[0], prover_did, + json.dumps(claim_offer_json), + wallet_handle_and_claim_def[1], + anoncreds.COMMON_MASTER_SECRET_NAME) + + assert ErrorCode.CommonInvalidStructure == e.value.error_code From 0b2d00277f6363afefb0bceb72812df1696a6954 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 25 Jul 2017 14:02:18 +0300 Subject: [PATCH 333/349] added tests for issuer_create_claim --- .../anoncreds/test_issuer_create_claim.py | 19 +++++++++++++++++++ wrappers/python/tests/utils/anoncreds.py | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/wrappers/python/tests/anoncreds/test_issuer_create_claim.py b/wrappers/python/tests/anoncreds/test_issuer_create_claim.py index 3e27b86b38..6c0d395c31 100644 --- a/wrappers/python/tests/anoncreds/test_issuer_create_claim.py +++ b/wrappers/python/tests/anoncreds/test_issuer_create_claim.py @@ -1,5 +1,6 @@ from indy import wallet from indy.anoncreds import issuer_create_claim +from indy.error import ErrorCode, IndyError from tests.utils import storage, anoncreds from tests.utils.wallet import create_and_open_wallet @@ -32,3 +33,21 @@ async def test_issuer_create_claim_works(wallet_handle): claim_json = anoncreds.get_gvt_claim_json() (_, claim_json) = await issuer_create_claim(wallet_handle, json.dumps(claim_req), json.dumps(claim_json), -1, -1) + +@pytest.mark.asyncio +async def test_issuer_create_claim_works_for_claim_does_not_correspond_to_claim_req(wallet_handle): + claim_req = anoncreds.get_claim_req() + claim_json = anoncreds.get_xyz_claim_json() + with pytest.raises(IndyError) as e: + await issuer_create_claim(wallet_handle, json.dumps(claim_req), json.dumps(claim_json), -1, -1) + assert ErrorCode.CommonInvalidStructure == e.value.error_code + + +@pytest.mark.asyncio +async def test_issuer_create_claim_works_for_for_invalid_wallet_handle(wallet_handle): + claim_req = anoncreds.get_claim_req() + claim_json = anoncreds.get_gvt_claim_json() + invalid_wallet_handle = wallet_handle + 100 + with pytest.raises(IndyError) as e: + await issuer_create_claim(invalid_wallet_handle, json.dumps(claim_req), json.dumps(claim_json), -1, -1) + assert ErrorCode.WalletInvalidHandle == e.value.error_code diff --git a/wrappers/python/tests/utils/anoncreds.py b/wrappers/python/tests/utils/anoncreds.py index 633dcec24b..65b6218eb4 100644 --- a/wrappers/python/tests/utils/anoncreds.py +++ b/wrappers/python/tests/utils/anoncreds.py @@ -54,6 +54,13 @@ def get_gvt_claim_json(): } +def get_xyz_claim_json(): + return { + "status": ["partial", "51792877103171595686471452153480627530895"], + "period": ["8", "8"] + } + + def get_claim_req(): return {"blinded_ms": {"prover_did": "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW", "u": "541727375645293327107242131390489410830131768916446771173223218236303087346206273292" From 30dd9da0c2941a99387f6eed1d6e2d904b5956d6 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 25 Jul 2017 14:05:15 +0300 Subject: [PATCH 334/349] added tests for prover_store_claim --- .../tests/anoncreds/test_prover_store_claim.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/wrappers/python/tests/anoncreds/test_prover_store_claim.py b/wrappers/python/tests/anoncreds/test_prover_store_claim.py index 64fc5d0f6b..5bb6cacc5a 100644 --- a/wrappers/python/tests/anoncreds/test_prover_store_claim.py +++ b/wrappers/python/tests/anoncreds/test_prover_store_claim.py @@ -1,6 +1,7 @@ from indy import wallet from indy.anoncreds import prover_create_and_store_claim_req, prover_store_claim,\ prover_create_master_secret, issuer_create_claim +from indy.error import ErrorCode, IndyError from tests.utils import storage, anoncreds from tests.utils.wallet import create_and_open_wallet @@ -40,3 +41,20 @@ async def test_prover_store_claim_works(wallet_handle_and_claim_def): json.dumps(anoncreds.get_gvt_claim_json()), -1, -1) await prover_store_claim(wallet_handle_and_claim_def[0], claim_json) + +@pytest.mark.asyncio +async def test_prover_store_claim_works_for_invalid_wallet_handle(wallet_handle_and_claim_def): + prover_did = "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW" + claim_offer_json = anoncreds.get_claim_offer(anoncreds.ISSUER_DID, 1) + invalid_wallet_handle = wallet_handle_and_claim_def[0] + 100 + await prover_create_master_secret(wallet_handle_and_claim_def[0], anoncreds.COMMON_MASTER_SECRET_NAME_1) + claim_req = await prover_create_and_store_claim_req(wallet_handle_and_claim_def[0], prover_did, + json.dumps(claim_offer_json), wallet_handle_and_claim_def[1], + anoncreds.COMMON_MASTER_SECRET_NAME_1) + + (_, claim_json) = await issuer_create_claim(wallet_handle_and_claim_def[0], claim_req, + json.dumps(anoncreds.get_gvt_claim_json()), -1, -1) + + with pytest.raises(IndyError) as e: + await prover_store_claim(invalid_wallet_handle, claim_json) + assert ErrorCode.WalletInvalidHandle == e.value.error_code From 077005af964c4ef763d5af3e09550bdf314682d6 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 25 Jul 2017 14:11:08 +0300 Subject: [PATCH 335/349] added tests for prover_get_claims --- .../tests/anoncreds/test_prover_get_claims.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/wrappers/python/tests/anoncreds/test_prover_get_claims.py b/wrappers/python/tests/anoncreds/test_prover_get_claims.py index 017365ca8a..d340a4f6b5 100644 --- a/wrappers/python/tests/anoncreds/test_prover_get_claims.py +++ b/wrappers/python/tests/anoncreds/test_prover_get_claims.py @@ -1,5 +1,6 @@ from indy import wallet from indy.anoncreds import prover_get_claims +from indy.error import ErrorCode, IndyError from tests.utils import storage, anoncreds from tests.utils.wallet import create_and_open_wallet @@ -31,3 +32,29 @@ async def test_prover_get_claims_works_for_empty_filter(wallet_handle): claims = json.loads(await prover_get_claims(wallet_handle, "{}")) assert len(claims) == 1 + +@pytest.mark.asyncio +async def test_prover_get_claims_works_for_filter_by_issuer_did(wallet_handle): + claims = json.loads(await prover_get_claims(wallet_handle, '{{"issuer_did":"{}"}}'.format(anoncreds.ISSUER_DID))) + assert len(claims) == 1 + + +@pytest.mark.asyncio +async def test_prover_get_claims_works_for_filter_by_issuer_did_and_schema_seq_no(wallet_handle): + claims = json.loads(await prover_get_claims(wallet_handle, json.dumps(anoncreds.get_claim_offer(anoncreds.ISSUER_DID, 1)))) + assert len(claims) == 1 + + +@pytest.mark.asyncio +async def test_prover_get_claims_works_for_empty_result(wallet_handle): + claims = json.loads(await prover_get_claims(wallet_handle, '{"schema_seq_no":10}')) + assert len(claims) == 0 + + +@pytest.mark.asyncio +async def test_prover_get_claims_works_for_invalid_wallet_handle(wallet_handle): + invalid_wallet_handle = wallet_handle + 100 + + with pytest.raises(IndyError) as e: + await prover_get_claims(invalid_wallet_handle, '{}') + assert ErrorCode.WalletInvalidHandle == e.value.error_code From cbff7bd4ea690848f5b341e2c671bb698823a1ce Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 25 Jul 2017 14:18:18 +0300 Subject: [PATCH 336/349] Implemented Create Wallet and Open Wallet integration tests for python wrapper --- .../indy/sdk/wallet/CreateWalletTest.java | 4 +-- .../indy/sdk/wallet/OpenWalletTest.java | 9 ----- .../python/tests/wallet/test_create_wallet.py | 35 ++++++++++++++++++- .../python/tests/wallet/test_open_wallet.py | 28 ++++++++++++++- 4 files changed, 63 insertions(+), 13 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java index 50d6d5b597..a2a7615db8 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/CreateWalletTest.java @@ -50,9 +50,9 @@ public void testCreateWalletWorksForUnknowType() throws Exception { @Test public void testCreateWalletWorksForEmptyName() throws Exception { - thrown.expect(new ErrorCodeMatcher(ErrorCode.CommonInvalidParam2)); + thrown.expect(new ErrorCodeMatcher(ErrorCode.CommonInvalidParam3)); - Wallet.createWallet("", "createWalletWorks", "default", null, null).get(); + Wallet.createWallet("pool", "", "default", null, null).get(); } @Test diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java index 068833453e..a3cc8d27bc 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java @@ -73,13 +73,4 @@ public void testOpenWalletWorksForTwice() throws Exception { Wallet.openWallet(walletName, null, null).get(); Wallet.openWallet(walletName, null, null).get(); } - - @Test - public void testOpenWalletWorksForNotCreated() throws Exception { - - thrown.expect(ExecutionException.class); - thrown.expectCause(new ErrorCodeMatcher(ErrorCode.CommonIOError)); - - Wallet.openWallet("testOpenWalletWorksForNotCreated", null, null).get(); - } } diff --git a/wrappers/python/tests/wallet/test_create_wallet.py b/wrappers/python/tests/wallet/test_create_wallet.py index 0cce020577..dfae1c23fb 100644 --- a/wrappers/python/tests/wallet/test_create_wallet.py +++ b/wrappers/python/tests/wallet/test_create_wallet.py @@ -1,4 +1,6 @@ +from indy import IndyError from indy import wallet +from indy.error import ErrorCode from ..utils import storage @@ -18,4 +20,35 @@ def cleanup_storage(): @pytest.mark.asyncio async def test_create_wallet_works(): await wallet.create_wallet('pool1', 'wallet1', 'default', None, None) - assert True + + +@pytest.mark.asyncio +async def test_create_wallet_works_for_empty_type(): + await wallet.create_wallet('pool1', 'wallet1', None, None, None) + + +@pytest.mark.asyncio +async def test_create_wallet_works_for_config_json(): + await wallet.create_wallet('pool1', 'wallet3', 'default', '{"freshness_time":1000}', None) + + +@pytest.mark.asyncio +async def test_create_wallet_works_for_unknown_type(): + with pytest.raises(IndyError) as e: + await wallet.create_wallet('pool1', 'wallet3', 'unknown_type', None, None) + assert ErrorCode.WalletUnknownTypeError == e.value.error_code + + +@pytest.mark.asyncio +async def test_create_wallet_works_for_empty_name(): + with pytest.raises(IndyError) as e: + await wallet.create_wallet('pool1', '', 'default', None, None) + assert ErrorCode.CommonInvalidParam3 == e.value.error_code + + +@pytest.mark.asyncio +async def test_create_wallet_works_for_duplicate_name(): + with pytest.raises(IndyError) as e: + await wallet.create_wallet('pool1', 'wallet4', 'default', None, None) + await wallet.create_wallet('pool1', 'wallet4', 'default', None, None) + assert ErrorCode.WalletAlreadyExistsError == e.value.error_code diff --git a/wrappers/python/tests/wallet/test_open_wallet.py b/wrappers/python/tests/wallet/test_open_wallet.py index a5c2af9418..25725b8f76 100644 --- a/wrappers/python/tests/wallet/test_open_wallet.py +++ b/wrappers/python/tests/wallet/test_open_wallet.py @@ -1,4 +1,6 @@ +from indy import IndyError from indy import wallet +from indy.error import ErrorCode from ..utils import storage @@ -22,4 +24,28 @@ async def test_open_wallet_works(): assert wallet_handle is not None await wallet.close_wallet(wallet_handle) - assert True + + +@pytest.mark.asyncio +async def test_open_wallet_works_for_config(): + await wallet.create_wallet('pool1', 'wallet2', None, None, None) + wallet_handle = await wallet.open_wallet('wallet2', '{"freshness_time":1000}', None) + assert wallet_handle is not None + + await wallet.close_wallet(wallet_handle) + + +@pytest.mark.asyncio +async def test_open_wallet_works_for_not_created_wallet(): + with pytest.raises(IndyError) as e: + await wallet.open_wallet('wallet3', None, None) + assert ErrorCode.CommonIOError == e.value.error_code + + +@pytest.mark.asyncio +async def test_open_wallet_works_for_not_created_wallet(): + with pytest.raises(IndyError) as e: + await wallet.create_wallet('pool1', 'wallet_twice', None, None, None) + await wallet.open_wallet('wallet_twice', None, None) + await wallet.open_wallet('wallet_twice', None, None) + assert ErrorCode.WalletAlreadyOpenedError == e.value.error_code \ No newline at end of file From def3c87f5abcc71335d63ab3b3cf5fa6fa64f331 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 25 Jul 2017 14:23:03 +0300 Subject: [PATCH 337/349] added tests for prover_get_claims_for_proof_request --- .../test_prover_get_claims_for_proof_req.py | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/wrappers/python/tests/anoncreds/test_prover_get_claims_for_proof_req.py b/wrappers/python/tests/anoncreds/test_prover_get_claims_for_proof_req.py index b385d47390..f989ac4597 100644 --- a/wrappers/python/tests/anoncreds/test_prover_get_claims_for_proof_req.py +++ b/wrappers/python/tests/anoncreds/test_prover_get_claims_for_proof_req.py @@ -1,5 +1,6 @@ from indy import wallet from indy.anoncreds import prover_get_claims_for_proof_req +from indy.error import ErrorCode, IndyError from tests.utils import storage, anoncreds from tests.utils.wallet import create_and_open_wallet @@ -45,3 +46,121 @@ async def test_prover_get_claims_for_proof_req_works_for_revealed_attr(wallet_ha assert len(claims['attrs']) == 1 assert len(claims['predicates']) == 0 assert len(claims['attrs']['attr1_uuid']) == 1 + + +@pytest.mark.asyncio +async def test_prover_get_claims_for_proof_req_works_for_not_found_attribute(wallet_handle): + proof_req = { + "nonce": "123432421212", + "name": "proof_req_1", + "version": "0.1", + "requested_attrs": { + "attr1_uuid": { + "schema_seq_no": 1, + "name": "some_attr" + } + }, + "requested_predicates": {} + } + + claims = json.loads(await prover_get_claims_for_proof_req(wallet_handle, json.dumps(proof_req))) + assert len(claims['attrs']) == 1 + assert len(claims['predicates']) == 0 + assert len(claims['attrs']['attr1_uuid']) == 0 + + +@pytest.mark.asyncio +async def test_prover_get_claims_for_proof_req_works_for_satisfy_predicate(wallet_handle): + proof_req = { + "nonce": "123432421212", + "name": "proof_req_1", + "version": "0.1", + "requested_attrs": {}, + "requested_predicates": { + "predicate1_uuid": + { + "attr_name": "age", + "p_type": "GE", + "value": 18 + } + } + } + + claims = json.loads(await prover_get_claims_for_proof_req(wallet_handle, json.dumps(proof_req))) + assert len(claims['attrs']) == 0 + assert len(claims['predicates']) == 1 + assert len(claims['predicates']['predicate1_uuid']) == 1 + + +@pytest.mark.asyncio +async def test_prover_get_claims_for_proof_req_works_for_not_satisfy_predicate(wallet_handle): + proof_req = { + "nonce": "123432421212", + "name": "proof_req_1", + "version": "0.1", + "requested_attrs": {}, + "requested_predicates": { + "predicate1_uuid": + { + "attr_name": "age", + "p_type": "GE", + "value": 58 + } + } + } + + claims = json.loads(await prover_get_claims_for_proof_req(wallet_handle, json.dumps(proof_req))) + assert len(claims['attrs']) == 0 + assert len(claims['predicates']) == 1 + assert len(claims['predicates']['predicate1_uuid']) == 0 + + +@pytest.mark.asyncio +async def test_prover_get_claims_for_proof_req_works_for_multiply_attribute_and_predicates(wallet_handle): + proof_req = { + "nonce": "123432421212", + "name": "proof_req_1", + "version": "0.1", + "requested_attrs": { + "attr1_uuid": {"schema_seq_no": 1, "name": "name"}, + "attr2_uuid": {"schema_seq_no": 1, "name": "sex"} + }, + "requested_predicates": { + "predicate1_uuid": {"attr_name": "age", "p_type": "GE", "value": 18}, + "predicate2_uuid": {"attr_name": "height", "p_type": "GE", "value": 160} + } + } + + claims = json.loads(await prover_get_claims_for_proof_req(wallet_handle, json.dumps(proof_req))) + assert len(claims['attrs']) == 2 + assert len(claims['predicates']) == 2 + assert len(claims['attrs']['attr1_uuid']) == 1 + assert len(claims['attrs']['attr2_uuid']) == 1 + assert len(claims['predicates']['predicate1_uuid']) == 1 + assert len(claims['predicates']['predicate2_uuid']) == 1 + + +@pytest.mark.asyncio +async def test_prover_get_claims_for_proof_req_works_for_invalid_wallet_handle(wallet_handle): + proof_req = { + "nonce": "123432421212", + "name": "proof_req_1", + "version": "0.1", + "requested_attrs": {}, + "requested_predicates": { + "predicate1_uuid": + { + "attr_name": "age", + "p_type": "GE", + "value": 58 + } + } + } + + invalid_wallet_handle = wallet_handle + 100 + + with pytest.raises(IndyError) as e: + await prover_get_claims_for_proof_req(invalid_wallet_handle, json.dumps(proof_req)) + assert ErrorCode.WalletInvalidHandle == e.value.error_code + + From 4cbe5631f9540efe24201eafac378096580264b8 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Tue, 25 Jul 2017 14:54:56 +0300 Subject: [PATCH 338/349] added tests for create_proof --- .../anoncreds/test_prover_create_proof.py | 98 ++++++++++++++++++- 1 file changed, 95 insertions(+), 3 deletions(-) diff --git a/wrappers/python/tests/anoncreds/test_prover_create_proof.py b/wrappers/python/tests/anoncreds/test_prover_create_proof.py index ccbdc7d7dd..a3f7682e72 100644 --- a/wrappers/python/tests/anoncreds/test_prover_create_proof.py +++ b/wrappers/python/tests/anoncreds/test_prover_create_proof.py @@ -1,5 +1,6 @@ from indy import wallet -from indy.anoncreds import prover_get_claims_for_proof_req, prover_create_proof +from indy.anoncreds import prover_get_claims_for_proof_req, prover_create_proof, prover_get_claims +from indy.error import ErrorCode, IndyError from tests.utils import storage, anoncreds from tests.utils.wallet import create_and_open_wallet @@ -60,8 +61,6 @@ async def test_prover_create_proof_works(wallet_handle_and_claim_def): } } - print("requested_claims = {}".format(json.dumps(requested_claims))) - schemas = { claim_for_attr: anoncreds.get_gvt_schema_json(1) } @@ -73,3 +72,96 @@ async def test_prover_create_proof_works(wallet_handle_and_claim_def): await prover_create_proof(wallet_handle_and_claim_def[0], json.dumps(proof_req), json.dumps(requested_claims), json.dumps(schemas), anoncreds.COMMON_MASTER_SECRET_NAME, json.dumps(claim_defs), "{}") + + +@pytest.mark.asyncio +async def test_prover_create_proof_works_for_using_not_satisfy_claim(wallet_handle_and_claim_def): + claims = json.loads(await prover_get_claims(wallet_handle_and_claim_def[0], "{}")) + claim_uuid = claims[0]['claim_uuid'] + proof_req = { + "nonce": "123432421212", + "name": "proof_req_1", + "version": "0.1", + "requested_attrs": { + "attr1_uuid": { + "schema_seq_no": 1, + "name": "some_attr" + } + }, + "requested_predicates": {} + } + + requested_claims = { + "self_attested_attributes": {}, + "requested_attrs": { + "attr1_uuid": [claim_uuid, True] + }, + "requested_predicates": { + "predicate1_uuid": {} + } + } + + schemas = { + claim_uuid: anoncreds.get_gvt_schema_json(1) + } + + claim_defs = { + claim_uuid: json.loads(wallet_handle_and_claim_def[1]) + } + + with pytest.raises(IndyError) as e: + await prover_create_proof(wallet_handle_and_claim_def[0], json.dumps(proof_req), json.dumps(requested_claims), + json.dumps(schemas), anoncreds.COMMON_MASTER_SECRET_NAME, + json.dumps(claim_defs), "{}") + assert ErrorCode.CommonInvalidStructure == e.value.error_code + + +@pytest.mark.asyncio +async def test_prover_create_proof_works_for_invalid_wallet_handle(wallet_handle_and_claim_def): + proof_req = { + "nonce": "123432421212", + "name": "proof_req_1", + "version": "0.1", + "requested_attrs": { + "attr1_uuid": { + "schema_seq_no": 1, + "name": "name" + } + }, + "requested_predicates": { + "predicate1_uuid": { + "attr_name": "age", + "p_type": "GE", + "value": 18 + } + } + } + + claims = json.loads(await prover_get_claims_for_proof_req(wallet_handle_and_claim_def[0], json.dumps(proof_req))) + claim_for_attr = claims['attrs']['attr1_uuid'][0]['claim_uuid'] + claim_for_predicate = claims['predicates']['predicate1_uuid'][0]['claim_uuid'] + requested_claims = { + "self_attested_attributes": {}, + "requested_attrs": { + "attr1_uuid": [claim_for_attr, True] + }, + "requested_predicates": { + "predicate1_uuid": claim_for_predicate + } + } + + schemas = { + claim_for_attr: anoncreds.get_gvt_schema_json(1) + } + + claim_defs = { + claim_for_attr: json.loads(wallet_handle_and_claim_def[1]) + } + + invalid_wallet_handle = wallet_handle_and_claim_def[0] + 100 + + with pytest.raises(IndyError) as e: + await prover_create_proof(invalid_wallet_handle, json.dumps(proof_req), json.dumps(requested_claims), + json.dumps(schemas), anoncreds.COMMON_MASTER_SECRET_NAME, + json.dumps(claim_defs), "{}") + assert ErrorCode.WalletInvalidHandle == e.value.error_code From 18146d5acc6bffce82a20aa320361ca3f4d36f79 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 26 Jul 2017 09:25:08 +0300 Subject: [PATCH 339/349] Implemented Wallet Close and Delete integration tests for python wrapper --- tests/wallet.rs | 2 +- .../python/tests/wallet/test_close_wallet.py | 22 +++++++-- .../python/tests/wallet/test_delete_wallet.py | 47 +++++++++++++++++-- .../python/tests/wallet/test_open_wallet.py | 4 +- 4 files changed, 64 insertions(+), 11 deletions(-) diff --git a/tests/wallet.rs b/tests/wallet.rs index 23d4cc522c..e36d4ee2c1 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -412,7 +412,7 @@ mod medium_cases { use super::*; #[test] - fn indy_delete_wallet_works_for_invalid_wallet_name() { + fn indy_delete_wallet_works_for_not_created() { TestUtils::cleanup_storage(); let res = WalletUtils::delete_wallet("indy_delete_wallet_works_for_invalid_wallet_name"); diff --git a/wrappers/python/tests/wallet/test_close_wallet.py b/wrappers/python/tests/wallet/test_close_wallet.py index e86fa3e724..148f67a08b 100644 --- a/wrappers/python/tests/wallet/test_close_wallet.py +++ b/wrappers/python/tests/wallet/test_close_wallet.py @@ -1,4 +1,6 @@ +from indy import IndyError from indy import wallet +from indy.error import ErrorCode from ..utils import storage @@ -17,12 +19,24 @@ def cleanup_storage(): @pytest.mark.asyncio async def test_close_wallet_works(): - await wallet.create_wallet('pool1', 'wallet1', None, None, None) + wallet_name = 'wallet1' + await wallet.create_wallet('pool1', wallet_name, None, None, None) - wallet_handle = await wallet.open_wallet('wallet1', None, None) + wallet_handle = await wallet.open_wallet(wallet_name, None, None) await wallet.close_wallet(wallet_handle) - wallet_handle = await wallet.open_wallet('wallet1', None, None) + wallet_handle = await wallet.open_wallet(wallet_name, None, None) await wallet.close_wallet(wallet_handle) - assert True + +@pytest.mark.asyncio +async def test_close_wallet_works_for_twice(): + with pytest.raises(IndyError) as e: + wallet_name = 'wallet_for_twice' + await wallet.create_wallet('pool1', wallet_name, None, None, None) + + wallet_handle = await wallet.open_wallet(wallet_name, None, None) + await wallet.close_wallet(wallet_handle) + await wallet.close_wallet(wallet_handle) + + assert ErrorCode.WalletInvalidHandle == e.value.error_code diff --git a/wrappers/python/tests/wallet/test_delete_wallet.py b/wrappers/python/tests/wallet/test_delete_wallet.py index a4e3fb48fb..26f7a9c6dc 100644 --- a/wrappers/python/tests/wallet/test_delete_wallet.py +++ b/wrappers/python/tests/wallet/test_delete_wallet.py @@ -1,4 +1,6 @@ +from indy import IndyError from indy import wallet +from indy.error import ErrorCode from ..utils import storage @@ -17,8 +19,45 @@ def cleanup_storage(): @pytest.mark.asyncio async def test_delete_wallet_works(): - await wallet.create_wallet('pool1', 'wallet1', None, None, None) - await wallet.delete_wallet('wallet1', None) - await wallet.create_wallet('pool1', 'wallet1', None, None, None) + wallet_name = 'wallet1' + await wallet.create_wallet('pool1', wallet_name, None, None, None) + await wallet.delete_wallet(wallet_name, None) + await wallet.create_wallet('pool1', wallet_name, None, None, None) - assert True + +@pytest.mark.asyncio +async def test_delete_wallet_works_for_closed(): + wallet_name = 'wallet2' + await wallet.create_wallet('pool1', wallet_name, None, None, None) + wallet_handle = await wallet.open_wallet(wallet_name, None, None) + await wallet.close_wallet(wallet_handle) + await wallet.delete_wallet(wallet_name, None) + await wallet.create_wallet('pool1', wallet_name, None, None, None) + + +@pytest.mark.skip(reason="There is BUG in indy-sdk") +async def test_delete_wallet_works_for_opened(): + with pytest.raises(IndyError) as e: + wallet_name = 'wallet_for_opened' + await wallet.create_wallet('pool1', wallet_name, None, None, None) + await wallet.open_wallet(wallet_name, None, None) + await wallet.delete_wallet(wallet_name, None) + assert ErrorCode.CommonIOError == e.value.error_code + + +@pytest.mark.asyncio +async def test_delete_wallet_works_for_twice(): + with pytest.raises(IndyError) as e: + wallet_name = 'wallet_for_twice' + await wallet.create_wallet('pool1', wallet_name, None, None, None) + await wallet.delete_wallet(wallet_name, None) + await wallet.delete_wallet(wallet_name, None) + assert ErrorCode.CommonIOError == e.value.error_code + + +@pytest.mark.asyncio +async def test_delete_wallet_works_for_not_created(): + with pytest.raises(IndyError) as e: + wallet_name = 'wallet_not_created' + await wallet.delete_wallet(wallet_name, None) + assert ErrorCode.CommonIOError == e.value.error_code \ No newline at end of file diff --git a/wrappers/python/tests/wallet/test_open_wallet.py b/wrappers/python/tests/wallet/test_open_wallet.py index 25725b8f76..f415ed527a 100644 --- a/wrappers/python/tests/wallet/test_open_wallet.py +++ b/wrappers/python/tests/wallet/test_open_wallet.py @@ -38,12 +38,12 @@ async def test_open_wallet_works_for_config(): @pytest.mark.asyncio async def test_open_wallet_works_for_not_created_wallet(): with pytest.raises(IndyError) as e: - await wallet.open_wallet('wallet3', None, None) + await wallet.open_wallet('wallet_not_created', None, None) assert ErrorCode.CommonIOError == e.value.error_code @pytest.mark.asyncio -async def test_open_wallet_works_for_not_created_wallet(): +async def test_open_wallet_works_for_twice(): with pytest.raises(IndyError) as e: await wallet.create_wallet('pool1', 'wallet_twice', None, None, None) await wallet.open_wallet('wallet_twice', None, None) From 2ed0ed2a8cc974457a69011f956f290e6608b12c Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 26 Jul 2017 10:28:03 +0300 Subject: [PATCH 340/349] added tests for verify_proof --- .../tests/anoncreds/test_verify_proof.py | 297 ++++++++++++++++++ wrappers/python/tests/utils/anoncreds.py | 4 +- 2 files changed, 299 insertions(+), 2 deletions(-) diff --git a/wrappers/python/tests/anoncreds/test_verify_proof.py b/wrappers/python/tests/anoncreds/test_verify_proof.py index 50be4a503e..7d2aaba94a 100644 --- a/wrappers/python/tests/anoncreds/test_verify_proof.py +++ b/wrappers/python/tests/anoncreds/test_verify_proof.py @@ -1,4 +1,5 @@ from indy.anoncreds import verifier_verify_proof +from indy.error import ErrorCode, IndyError from tests.utils import storage, anoncreds @@ -167,3 +168,299 @@ async def test_verifier_verify_proof_works_for_correct_proof(): json.dumps(schemas), json.dumps(claim_defs), "{}") assert valid + + +@pytest.mark.asyncio +async def test_verifier_verify_proof_works_for_proof_does_not_correspond_to_request(): + proof_req = anoncreds.get_proof_req(180) + claim_def = anoncreds.get_claim_def() + + schemas = { + "claim::277478db-bf57-42c3-8530-b1b13cfe0bfd": anoncreds.get_gvt_schema_json(1) + } + claim_defs = { + "claim::277478db-bf57-42c3-8530-b1b13cfe0bfd": claim_def + } + proof = { + "proofs": + { + "claim::277478db-bf57-42c3-8530-b1b13cfe0bfd": + { + "proof": + { + "primary_proof": { + "eq_proof": {"revealed_attrs": {"name": "1139481716457488690172217916278103335"}, + "a_prime": "47629821806628155353444789773246165920681315271529392722265555946090524267165563309836167110610840740533588118152308411732923636370660640410661034994521654033599863817144282118006097899736622728860229305231675970853294584911572355833537271010861501353858292189045263114095480601737776505186511389129055847562085611741257601964074827979121349153316235245772819207422031038042586202074331681302501661153569340935741290924699468188826629478130140797677338573924284871118002193526319478550852287453975107498037063076866410320160118555629090040954555043934303307652160345244864713226315470541231435958298648179413077988340", + "e": "13427639393364185909415877973872458621259927563729922146828001652769380799419438410309469022979920689628523901764614163117469683925816443", + "v": "852136445143816932026946294488424887907102968158908948827421962603492187508454543239422067899916472317305416590471170842186669606584356963437132366711335927890209765986844538775191207999204354235774464468525274918097404114453069375363594310105209141774763909570100638835926337238009617444858777301355087706167735590386774813901740600054753028260344014744801229032610106838480523182317262113911183640784111960909501662169298536941919854667754097841344375972975021196106884215734228415868248724905018661498061287694439466570946597514142085096419985189064172035527690786158872698717583830848410994616274586162550376126607414773916066374234063208380831144157533076866210628625236440222547584539349936639548061601416341705483504386186280800509889531835172071717956251546280392606775903107774727736794828168898273891724336881907672405328368540895104468091907771325910937575557566831844131159128453840354307814975621978196047820", + "m": { + "age": "1117601261519431120446925325460734824239475567013636538481947258329666056692767097795046086413732472111811628751812987521644198549167671875326968410921589186689138994171774838662", + "height": "7064132689652704067914104576495132313294680087958177180391515757079548676035445873279966783996928425154050462229933823707574545166617858646442019030600136959459527533262821184869", + "sex": "16084497853957041205729191269508720470626311156190485518484640641677445098603656354458362520541393995692536218820724164533958162674375198846036330444513484319280148335515891811530"}, + "m1": "154906224259819061652290487122980839849626068919893070220438585977323162319993111920906032317552959103520053742608858935542877608981244065301675821390065831113115709272412144796159984624494428122971995557415296140268002332169405587907128359886810433617416529821500995701094400375272097687818064435577784795275", + "m2": "13805395408072590464827983892588030341708765524663545700917462089376137940485022437657208204460048097312372685954050370540389593952001973312378647790917367330461398089529292217752"}, + "ge_proofs": [{"u": { + "1": "7698818972783845439601187851976452936638792889455287252542709653271706844173743185409084669157965935169942655008606334521674712818637940377261656468700786810566551698412412949418", + "0": "11703047052430512223413711314521545616119146623040600935686474696241801697819280425232876917607198335376453682738553665221410353412906194951254558355994401995990233992518110582450", + "3": "13210777821918317858818819091924507295018522783042111457450035423463340571245465760486275059291363621513532153389441883097799049597687545496359999443320001567152794884095192951040", + "2": "15219471780524079156861690098171693383497641272226737821992208834301871102152362116211452788300889697214391366996966539871625433480959011635688106136537800706217506402845296449689"}, + "r": { + "1": "46043242109380749151527145850513330956077996622769158245225343392397735706292106535150958053995712629189143692293204979798837951212291825184346767969751978730000071952944305252032332015837054475531407691352179423131405515518588355918925056889302269768343499864256747177988825578647189563088068257214198650437730618330249172716051559993880468542083352885474175039320848153156858562341041960950299312991459780503345784440261679263045723337629951517601461685539857683027034345542399365706329805317943096391758978877658949910614447086409173234155028671453929715706057153381022697673192590033507204548864311227048268516889390503318015295207078022755834130221198717787608473222789491216667698651180077661375273569115943192", + "0": "135472587547410377947826119498467634347118057359097899596599164976338466445104141784869016998150489852448547539824768048351359572626675997498079394825940306636285481821620973655797996638210760710325933304918452142858879806106214845499670718704532018129553348815327362843246706518826311676917538452317818631484884032929252959289913274829848084561421467966320595980172006456003183536232790787521924655750157145207798486087511869939940023266736153366338179116840490184005332351004990854691988404031259910319601383696749511809898297656135548118786342107367065232798999979296280467063561892962526945512167505847049907450058650930480352253243357594344686769208712964458923557777584158831146374282687397585726706489164423632", + "DELTA": "93540839493959971552865423901789226093328763011922445919928571946113703515842729132879472109395228387208764738970926484618949870591214627692618668077375153559192701474693025462226656116549337248146652482501255820930607033869432220667968682424554711616471973627651716863421554516577716366331699848682958681216261888139409101603059124344125075525791543312721162515584942523419876134808829569829529457617639955678189490257208141837196965948342373022812790844435050648360150869293836349223060722858500537182872294143846213258360218898475766641125493477502149553491502593654061863323857297998048614447925371606038801933864960337435890254277043261512846682042139570000962051463878026338583242360548041329046695667868842400", + "3": "1227675452527605924725300993571504188580051470857656204064614533296779844072852823820754766175236321050062349182891221840452517985644028521499240739391613871973822807731772613052644168369405390658793869751915172749739844553410726807277698347769400977274750672880389943392076308065414059539317340070691852044062594715307024113666759844200606183662256825096857658837519571386467051003466014468855293015652584667669998830524947537781865745830650392641812221679438090257444660715937570193098993118585554478799821072396238689063767016402460690760792908977364175126682041704095200572282644311025594681667826054722587271200221036938804846621444065128275082392082327596239358623150786484106872933657139420542280145197712634108", + "2": "596248147592834822582469335300585333722415132713749620075902332764163096347819006925876158892694742461036531935093982309708492066217459300117157420442081698140277277546563570823996272914068575482008392971932777453900260626542725308060927710122631763045025742980634216666560934260634907599194353151523256914796667535940073668465664206971169038864484235442207811974981191879443614478897291543702607764944403808380921189291059195014621592027660463072969363556421687131446107696579365265893962197300447027501604372738056016734644378437907931412654753728514905671605635291285742886484416973884856055084605172305967034292646171874483670469193852404511746786039743401185954843446037600121496137915619789351744485264614840070"}, + "mj": "1117601261519431120446925325460734824239475567013636538481947258329666056692767097795046086413732472111811628751812987521644198549167671875326968410921589186689138994171774838662", + "alpha": "76727612740067576380015106087224381023260815407331375101920043509817863645705120013304683427627332447210083684516403565749916480947649443674885388155460323163682547865307733144184097845709556309570345707127872162476432029772452433292049079349274445907295491125915363620615679995457134810061392296263970553630102299601689685622244925494554558218277670233361938142224820526392365740420502452466959099546877778248089664282581792213376636587293479012783947088070052463503335266180110771978445892744225891676396288437005847308189508347446490710626231658457908472341606549292437553353163031111068977301305043175839949352742711874426231072729977019365761072816602400121302646283352164756787266537474728685656685493249314400351742964904006326192403855909148605656818024621453179832395687665671245528217931951331393482249182516107670379946496778373", + "t": { + "1": "37203689290881948278188715497642400459048942241931994079434400288578680362970117779048886269388440270597283202033458042171954610700745461571112086648991639439510380585728148682202768590972068041537531136529323260832899360551065706810590032715173070285762675403853992183366951113799098912676809373169763887110420539387555392787590966452796271491986622992160642135480293110112269570862265489120557014181468118619500321000966443141863893743211690388599242584469856365803370202569641902205925191670838354052104480074127555862332399641076324738839120815544432811566503174551735326387678621283249883091766325861497740614317", + "3": "58486787977689017034592833190899828017343431922483563651969628402499947729293364026001243898136737211851089198526360764391403150763769829047179796728616126204105160762333590343947446892105646111520243793053992399512412375936746396187319527051818920531870855183738837254656664620975569939859368862778444291640228229744805843388153451336792379036403300211151424879060241580540910888241769468335914016289938374111481091198264912969768783884602931940994543804730631920434719776196148182987249363641941951160704928605829395517074202388967815738516252602903999010405305463910751219873354588685197134114358234107748126140977", + "0": "60771874648036182010335841594233428920565254732600738082343398028553347795361460295011584446745121430144172025428394361648540904134739046923992231536160801306934272250969829886396340824213814702904457884984387666505055153957942221822193548673145705543973635530652570436109428474727638128773540793530691399549837156239786231362112148914687724325416768262058486101761972044802628459748878200584371058300150212485731451700436345975266860685549673168984700174294811561393162860595319582236734968601457003780816977537443267217411297266600994916897237305128142313335280264655603445636393371224354539882875937093696844430903", + "DELTA": "32816484171372208266594641116109072545171919234551585018140151846920408763078147655907777031259225522515086979967895258126318315788662577171150780535509410112003001556402222994276811926864642497249250763185467678044678144507739529818566125668667424447792097244624010084189629269472698722402896445274092470014229247479740671263651727480322483037149584904549203417226525624083290572692241241259382947122018271686649224741832992966652878170311798126004447080305528487720923103595513611363001766063956060990267107048028416069435287244770875463867263571308182619338433913487209319707428378896314619624990311543563016697299", + "2": "36428320569485697540634597755814766104888687488985202673924762266313135133244610404742081973550848160712054769198012193456278135847215508952327879544434490828380496286187725750283788811367824465072001959950807751252194618152990469069074061195618692339915840384087350671392595652921761835083158086795163935060896053332506433434451836095710383871272788002621913967538399141417857031787255744141437237474972197102809365346359345477248611632307159641948507043668113827177494748159094045928919209335044052792843664865311991178972383241855607627188111601119780878072683890170539599447876998109080150992209773901144245398001"}, + "predicate": {"attr_name": "age", "p_type": "GE", "value": 18}}]}, + "non_revoc_proof": None}, "schema_seq_no": 1, "revoc_reg_seq_no": None, + "issuer_did": "did"}}, + "aggregated_proof": {"c_hash": "33103550379681684069592829341967479618752165928802550870585275205292715916069", + "c_list": [ + [1, 121, 77, 5, 144, 154, 14, 192, 190, 190, 145, 180, 128, 71, 22, 60, 168, 20, 46, + 163, 139, 194, 71, 165, 220, 188, 121, 76, 25, 146, 231, 114, 65, 54, 69, 68, 19, 200, + 250, 192, 47, 123, 157, 132, 74, 50, 28, 69, 226, 195, 243, 118, 45, 63, 237, 197, + 216, 202, 206, 101, 33, 56, 225, 200, 128, 3, 89, 12, 182, 38, 113, 221, 165, 119, + 228, 201, 156, 201, 172, 136, 59, 64, 51, 72, 164, 198, 49, 228, 223, 117, 80, 64, + 166, 226, 37, 8, 29, 146, 186, 80, 210, 119, 76, 252, 4, 255, 62, 218, 112, 163, 164, + 147, 247, 190, 108, 76, 140, 191, 76, 217, 214, 184, 152, 179, 193, 149, 15, 70, 197, + 46, 90, 60, 255, 247, 197, 219, 252, 73, 76, 0, 125, 104, 114, 22, 182, 161, 110, 36, + 162, 103, 27, 42, 88, 18, 161, 237, 198, 43, 177, 189, 181, 86, 135, 207, 71, 114, 0, + 26, 175, 12, 199, 125, 25, 124, 178, 87, 36, 208, 251, 15, 191, 127, 202, 148, 152, + 43, 142, 92, 191, 7, 89, 153, 130, 195, 223, 248, 176, 109, 97, 164, 126, 162, 181, + 124, 237, 130, 155, 197, 66, 59, 40, 197, 72, 84, 32, 100, 64, 55, 227, 60, 214, 143, + 200, 200, 89, 115, 236, 172, 145, 56, 100, 73, 20, 242, 233, 95, 130, 58, 112, 153, + 120, 115, 119, 42, 199, 30, 205, 88, 223, 42, 196, 184, 41, 19, 100, 19, 244], + [1, 225, 103, 238, 42, 147, 91, 191, 110, 69, 154, 53, 57, 156, 124, 43, 174, 155, 76, + 202, 193, 98, 128, 38, 207, 126, 66, 70, 161, 96, 109, 127, 174, 44, 203, 198, 177, + 238, 118, 117, 89, 227, 170, 155, 44, 251, 35, 119, 219, 29, 100, 173, 26, 144, 95, + 50, 177, 4, 40, 234, 117, 174, 210, 192, 172, 57, 160, 198, 42, 199, 212, 243, 240, + 114, 59, 91, 207, 68, 57, 38, 198, 2, 73, 18, 16, 209, 182, 145, 206, 71, 17, 69, 222, + 49, 36, 120, 72, 117, 169, 107, 238, 208, 235, 216, 24, 183, 201, 81, 15, 83, 242, 45, + 136, 184, 166, 26, 142, 136, 228, 58, 229, 235, 88, 169, 238, 134, 205, 96, 85, 9, + 122, 53, 147, 100, 183, 114, 92, 54, 125, 178, 125, 75, 127, 116, 50, 88, 109, 152, + 22, 4, 121, 252, 190, 18, 190, 130, 143, 138, 59, 231, 38, 131, 176, 54, 19, 194, 218, + 67, 144, 122, 91, 43, 86, 73, 233, 48, 193, 30, 183, 183, 191, 238, 216, 167, 101, 28, + 185, 43, 118, 64, 242, 16, 62, 239, 177, 27, 109, 144, 67, 221, 175, 202, 4, 92, 130, + 74, 24, 20, 151, 15, 227, 225, 142, 71, 145, 46, 192, 248, 87, 57, 183, 142, 253, 52, + 20, 56, 153, 220, 234, 25, 67, 116, 225, 179, 211, 116, 161, 37, 64, 34, 48, 155, 1, + 1, 159, 157, 37, 31, 202, 19, 229, 152, 23, 138, 183, 126, 55], + [1, 38, 181, 193, 191, 72, 2, 239, 34, 83, 49, 36, 179, 160, 82, 112, 172, 98, 255, 63, + 60, 22, 177, 249, 67, 215, 220, 198, 181, 7, 49, 254, 133, 243, 221, 214, 47, 64, 229, + 82, 11, 94, 175, 57, 86, 152, 229, 192, 184, 96, 136, 116, 226, 123, 128, 217, 23, + 244, 19, 204, 36, 44, 123, 208, 88, 24, 217, 120, 145, 139, 25, 233, 227, 5, 119, 90, + 47, 147, 1, 115, 92, 39, 119, 194, 167, 17, 229, 39, 163, 167, 237, 14, 116, 234, 106, + 252, 216, 54, 33, 233, 21, 54, 183, 130, 144, 161, 177, 142, 177, 240, 51, 73, 21, + 202, 188, 103, 244, 153, 204, 219, 123, 231, 139, 135, 189, 155, 143, 28, 4, 180, 44, + 148, 0, 27, 103, 26, 13, 203, 31, 32, 166, 67, 84, 87, 23, 72, 234, 236, 20, 1, 84, + 70, 86, 76, 192, 164, 235, 124, 86, 128, 78, 230, 119, 155, 95, 121, 125, 20, 244, + 181, 121, 250, 169, 9, 67, 85, 213, 177, 139, 111, 187, 183, 114, 165, 249, 177, 161, + 181, 175, 46, 226, 66, 86, 84, 124, 86, 69, 143, 217, 158, 161, 30, 107, 133, 44, 239, + 89, 209, 24, 150, 1, 238, 122, 144, 138, 179, 121, 114, 90, 13, 212, 209, 60, 126, 37, + 62, 177, 180, 131, 222, 168, 2, 201, 156, 169, 220, 224, 53, 8, 203, 220, 215, 163, + 104, 195, 184, 73, 35, 241, 182, 177, 80, 41, 253, 230, 90, 173], + [1, 32, 145, 96, 219, 241, 190, 19, 195, 129, 219, 50, 148, 152, 107, 12, 189, 225, + 103, 171, 149, 252, 193, 243, 136, 132, 195, 44, 19, 20, 247, 140, 160, 91, 230, 78, + 31, 242, 85, 213, 65, 185, 1, 91, 12, 69, 118, 80, 26, 135, 102, 131, 4, 108, 130, + 230, 83, 91, 176, 249, 196, 56, 128, 127, 82, 72, 106, 49, 211, 94, 133, 40, 86, 72, + 42, 187, 199, 216, 191, 223, 208, 206, 121, 118, 15, 167, 255, 228, 57, 206, 158, 217, + 64, 205, 212, 178, 8, 248, 129, 183, 221, 98, 70, 54, 37, 55, 47, 81, 120, 59, 186, + 238, 165, 0, 70, 173, 137, 193, 232, 180, 125, 211, 237, 182, 249, 191, 173, 107, 129, + 164, 148, 231, 116, 225, 66, 66, 71, 156, 39, 248, 164, 253, 234, 140, 205, 177, 140, + 117, 47, 21, 15, 242, 31, 113, 118, 91, 143, 89, 213, 86, 143, 135, 21, 46, 35, 199, + 214, 107, 111, 65, 65, 19, 26, 171, 130, 16, 19, 102, 145, 210, 210, 61, 51, 169, 148, + 169, 118, 182, 106, 107, 253, 100, 214, 232, 52, 103, 180, 96, 249, 254, 71, 6, 11, + 119, 48, 129, 213, 223, 205, 93, 20, 117, 26, 187, 32, 151, 212, 137, 203, 17, 237, + 208, 150, 72, 23, 225, 235, 122, 188, 34, 105, 115, 0, 160, 168, 251, 191, 22, 242, + 238, 207, 74, 142, 154, 66, 94, 149, 191, 215, 194, 134, 6, 165, 244, 167, 233, 241], + [1, 207, 77, 250, 146, 127, 242, 229, 44, 172, 182, 201, 183, 242, 32, 242, 182, 129, + 233, 10, 8, 180, 23, 191, 163, 21, 238, 158, 5, 27, 216, 146, 253, 173, 127, 99, 95, + 168, 209, 132, 242, 196, 242, 34, 25, 25, 249, 211, 51, 236, 164, 153, 175, 61, 65, + 150, 82, 251, 174, 102, 186, 47, 195, 82, 44, 90, 252, 184, 74, 89, 251, 177, 254, + 108, 151, 136, 230, 220, 93, 224, 173, 247, 244, 116, 132, 59, 170, 215, 194, 30, 87, + 84, 166, 147, 57, 156, 201, 207, 132, 203, 222, 191, 253, 15, 19, 228, 173, 81, 156, + 4, 51, 121, 227, 159, 50, 18, 148, 129, 205, 42, 42, 227, 252, 138, 62, 176, 115, 227, + 253, 52, 125, 110, 178, 167, 132, 244, 14, 116, 195, 194, 172, 44, 45, 63, 38, 121, + 215, 136, 68, 230, 21, 108, 133, 159, 197, 179, 94, 78, 233, 107, 236, 114, 92, 165, + 248, 22, 124, 161, 23, 142, 236, 224, 175, 233, 134, 25, 97, 150, 131, 61, 220, 203, + 104, 154, 199, 247, 146, 47, 205, 56, 209, 0, 133, 132, 18, 103, 136, 8, 202, 37, 29, + 100, 105, 12, 232, 74, 33, 6, 255, 202, 96, 170, 52, 229, 244, 4, 235, 2, 201, 125, + 86, 168, 179, 224, 130, 81, 54, 221, 185, 184, 187, 141, 0, 114, 98, 38, 70, 225, 228, + 60, 157, 53, 210, 238, 60, 216, 215, 154, 48, 73, 3, 157, 192, 245, 81, 170, 49], + [1, 3, 244, 229, 158, 71, 18, 146, 198, 202, 27, 2, 231, 37, 13, 145, 243, 84, 112, + 220, 61, 174, 4, 175, 104, 200, 64, 146, 193, 20, 174, 126, 42, 157, 168, 76, 165, 21, + 50, 216, 82, 211, 180, 73, 244, 54, 227, 200, 19, 157, 25, 228, 81, 37, 64, 201, 19, + 138, 175, 50, 246, 169, 11, 45, 74, 194, 131, 236, 127, 177, 41, 242, 130, 55, 112, + 182, 98, 22, 99, 48, 153, 83, 161, 250, 65, 89, 3, 97, 6, 5, 171, 54, 223, 87, 98, + 103, 23, 200, 212, 177, 140, 155, 151, 252, 125, 45, 176, 55, 92, 41, 56, 2, 252, 32, + 149, 60, 3, 168, 209, 193, 23, 168, 230, 182, 72, 193, 230, 224, 5, 15, 58, 63, 93, + 196, 33, 93, 76, 188, 30, 70, 31, 136, 64, 204, 223, 2, 230, 210, 243, 255, 135, 193, + 52, 132, 248, 160, 22, 18, 164, 71, 77, 80, 112, 229, 120, 116, 210, 225, 2, 19, 139, + 35, 0, 214, 5, 246, 9, 106, 136, 204, 0, 148, 97, 21, 222, 153, 57, 177, 162, 11, 243, + 252, 7, 242, 34, 239, 245, 50, 104, 74, 221, 92, 73, 13, 142, 10, 184, 250, 246, 167, + 240, 46, 230, 86, 207, 181, 12, 133, 81, 119, 143, 164, 88, 114, 223, 243, 179, 208, + 175, 84, 161, 27, 11, 225, 36, 37, 177, 112, 85, 81, 184, 163, 223, 159, 36, 9, 247, + 20, 13, 230, 215, 108, 117, 35, 99, 117, 211]]}, "requested_proof": { + "revealed_attrs": {"attr1_uuid": ["claim::277478db-bf57-42c3-8530-b1b13cfe0bfd", "Alex", + "1139481716457488690172217916278103335"]}, "unrevealed_attrs": {}, + "self_attested_attrs": {}, + "predicates": {"predicate1_uuid": "claim::277478db-bf57-42c3-8530-b1b13cfe0bfd"}}} + + with pytest.raises(IndyError) as e: + await verifier_verify_proof(json.dumps(proof_req), json.dumps(proof), + json.dumps(schemas), json.dumps(claim_defs), "{}") + assert ErrorCode.CommonInvalidStructure == e.value.error_code + + +@pytest.mark.asyncio +async def test_verifier_verify_proof_works_for_wrong_proof(): + proof_req = anoncreds.get_proof_req() + claim_def = anoncreds.get_claim_def() + + schemas = { + "claim::277478db-bf57-42c3-8530-b1b13cfe0bfd": anoncreds.get_gvt_schema_json(1) + } + claim_defs = { + "claim::277478db-bf57-42c3-8530-b1b13cfe0bfd": claim_def + } + proof = { + "proofs": + { + "claim::277478db-bf57-42c3-8530-b1b13cfe0bfd": + { + "proof": + { + "primary_proof": { + "eq_proof": {"revealed_attrs": {"name": "1139481716457488690172217916278103337"}, + "a_prime": "47629821806628155353444789773246165920681315271529392722265555946090524267165563309836167110610840740533588118152308411732923636370660640410661034994521654033599863817144282118006097899736622728860229305231675970853294584911572355833537271010861501353858292189045263114095480601737776505186511389129055847562085611741257601964074827979121349153316235245772819207422031038042586202074331681302501661153569340935741290924699468188826629478130140797677338573924284871118002193526319478550852287453975107498037063076866410320160118555629090040954555043934303307652160345244864713226315470541231435958298648179413077988340", + "e": "13427639393364185909415877973872458621259927563729922146828001652769380799419438410309469022979920689628523901764614163117469683925816443", + "v": "852136445143816932026946294488424887907102968158908948827421962603492187508454543239422067899916472317305416590471170842186669606584356963437132366711335927890209765986844538775191207999204354235774464468525274918097404114453069375363594310105209141774763909570100638835926337238009617444858777301355087706167735590386774813901740600054753028260344014744801229032610106838480523182317262113911183640784111960909501662169298536941919854667754097841344375972975021196106884215734228415868248724905018661498061287694439466570946597514142085096419985189064172035527690786158872698717583830848410994616274586162550376126607414773916066374234063208380831144157533076866210628625236440222547584539349936639548061601416341705483504386186280800509889531835172071717956251546280392606775903107774727736794828168898273891724336881907672405328368540895104468091907771325910937575557566831844131159128453840354307814975621978196047820", + "m": { + "age": "1117601261519431120446925325460734824239475567013636538481947258329666056692767097795046086413732472111811628751812987521644198549167671875326968410921589186689138994171774838662", + "height": "7064132689652704067914104576495132313294680087958177180391515757079548676035445873279966783996928425154050462229933823707574545166617858646442019030600136959459527533262821184869", + "sex": "16084497853957041205729191269508720470626311156190485518484640641677445098603656354458362520541393995692536218820724164533958162674375198846036330444513484319280148335515891811530"}, + "m1": "154906224259819061652290487122980839849626068919893070220438585977323162319993111920906032317552959103520053742608858935542877608981244065301675821390065831113115709272412144796159984624494428122971995557415296140268002332169405587907128359886810433617416529821500995701094400375272097687818064435577784795275", + "m2": "13805395408072590464827983892588030341708765524663545700917462089376137940485022437657208204460048097312372685954050370540389593952001973312378647790917367330461398089529292217752"}, + "ge_proofs": [{"u": { + "1": "7698818972783845439601187851976452936638792889455287252542709653271706844173743185409084669157965935169942655008606334521674712818637940377261656468700786810566551698412412949418", + "0": "11703047052430512223413711314521545616119146623040600935686474696241801697819280425232876917607198335376453682738553665221410353412906194951254558355994401995990233992518110582450", + "3": "13210777821918317858818819091924507295018522783042111457450035423463340571245465760486275059291363621513532153389441883097799049597687545496359999443320001567152794884095192951040", + "2": "15219471780524079156861690098171693383497641272226737821992208834301871102152362116211452788300889697214391366996966539871625433480959011635688106136537800706217506402845296449689"}, + "r": { + "1": "46043242109380749151527145850513330956077996622769158245225343392397735706292106535150958053995712629189143692293204979798837951212291825184346767969751978730000071952944305252032332015837054475531407691352179423131405515518588355918925056889302269768343499864256747177988825578647189563088068257214198650437730618330249172716051559993880468542083352885474175039320848153156858562341041960950299312991459780503345784440261679263045723337629951517601461685539857683027034345542399365706329805317943096391758978877658949910614447086409173234155028671453929715706057153381022697673192590033507204548864311227048268516889390503318015295207078022755834130221198717787608473222789491216667698651180077661375273569115943192", + "0": "135472587547410377947826119498467634347118057359097899596599164976338466445104141784869016998150489852448547539824768048351359572626675997498079394825940306636285481821620973655797996638210760710325933304918452142858879806106214845499670718704532018129553348815327362843246706518826311676917538452317818631484884032929252959289913274829848084561421467966320595980172006456003183536232790787521924655750157145207798486087511869939940023266736153366338179116840490184005332351004990854691988404031259910319601383696749511809898297656135548118786342107367065232798999979296280467063561892962526945512167505847049907450058650930480352253243357594344686769208712964458923557777584158831146374282687397585726706489164423632", + "DELTA": "93540839493959971552865423901789226093328763011922445919928571946113703515842729132879472109395228387208764738970926484618949870591214627692618668077375153559192701474693025462226656116549337248146652482501255820930607033869432220667968682424554711616471973627651716863421554516577716366331699848682958681216261888139409101603059124344125075525791543312721162515584942523419876134808829569829529457617639955678189490257208141837196965948342373022812790844435050648360150869293836349223060722858500537182872294143846213258360218898475766641125493477502149553491502593654061863323857297998048614447925371606038801933864960337435890254277043261512846682042139570000962051463878026338583242360548041329046695667868842400", + "3": "1227675452527605924725300993571504188580051470857656204064614533296779844072852823820754766175236321050062349182891221840452517985644028521499240739391613871973822807731772613052644168369405390658793869751915172749739844553410726807277698347769400977274750672880389943392076308065414059539317340070691852044062594715307024113666759844200606183662256825096857658837519571386467051003466014468855293015652584667669998830524947537781865745830650392641812221679438090257444660715937570193098993118585554478799821072396238689063767016402460690760792908977364175126682041704095200572282644311025594681667826054722587271200221036938804846621444065128275082392082327596239358623150786484106872933657139420542280145197712634108", + "2": "596248147592834822582469335300585333722415132713749620075902332764163096347819006925876158892694742461036531935093982309708492066217459300117157420442081698140277277546563570823996272914068575482008392971932777453900260626542725308060927710122631763045025742980634216666560934260634907599194353151523256914796667535940073668465664206971169038864484235442207811974981191879443614478897291543702607764944403808380921189291059195014621592027660463072969363556421687131446107696579365265893962197300447027501604372738056016734644378437907931412654753728514905671605635291285742886484416973884856055084605172305967034292646171874483670469193852404511746786039743401185954843446037600121496137915619789351744485264614840070"}, + "mj": "1117601261519431120446925325460734824239475567013636538481947258329666056692767097795046086413732472111811628751812987521644198549167671875326968410921589186689138994171774838662", + "alpha": "76727612740067576380015106087224381023260815407331375101920043509817863645705120013304683427627332447210083684516403565749916480947649443674885388155460323163682547865307733144184097845709556309570345707127872162476432029772452433292049079349274445907295491125915363620615679995457134810061392296263970553630102299601689685622244925494554558218277670233361938142224820526392365740420502452466959099546877778248089664282581792213376636587293479012783947088070052463503335266180110771978445892744225891676396288437005847308189508347446490710626231658457908472341606549292437553353163031111068977301305043175839949352742711874426231072729977019365761072816602400121302646283352164756787266537474728685656685493249314400351742964904006326192403855909148605656818024621453179832395687665671245528217931951331393482249182516107670379946496778373", + "t": { + "1": "37203689290881948278188715497642400459048942241931994079434400288578680362970117779048886269388440270597283202033458042171954610700745461571112086648991639439510380585728148682202768590972068041537531136529323260832899360551065706810590032715173070285762675403853992183366951113799098912676809373169763887110420539387555392787590966452796271491986622992160642135480293110112269570862265489120557014181468118619500321000966443141863893743211690388599242584469856365803370202569641902205925191670838354052104480074127555862332399641076324738839120815544432811566503174551735326387678621283249883091766325861497740614317", + "3": "58486787977689017034592833190899828017343431922483563651969628402499947729293364026001243898136737211851089198526360764391403150763769829047179796728616126204105160762333590343947446892105646111520243793053992399512412375936746396187319527051818920531870855183738837254656664620975569939859368862778444291640228229744805843388153451336792379036403300211151424879060241580540910888241769468335914016289938374111481091198264912969768783884602931940994543804730631920434719776196148182987249363641941951160704928605829395517074202388967815738516252602903999010405305463910751219873354588685197134114358234107748126140977", + "0": "60771874648036182010335841594233428920565254732600738082343398028553347795361460295011584446745121430144172025428394361648540904134739046923992231536160801306934272250969829886396340824213814702904457884984387666505055153957942221822193548673145705543973635530652570436109428474727638128773540793530691399549837156239786231362112148914687724325416768262058486101761972044802628459748878200584371058300150212485731451700436345975266860685549673168984700174294811561393162860595319582236734968601457003780816977537443267217411297266600994916897237305128142313335280264655603445636393371224354539882875937093696844430903", + "DELTA": "32816484171372208266594641116109072545171919234551585018140151846920408763078147655907777031259225522515086979967895258126318315788662577171150780535509410112003001556402222994276811926864642497249250763185467678044678144507739529818566125668667424447792097244624010084189629269472698722402896445274092470014229247479740671263651727480322483037149584904549203417226525624083290572692241241259382947122018271686649224741832992966652878170311798126004447080305528487720923103595513611363001766063956060990267107048028416069435287244770875463867263571308182619338433913487209319707428378896314619624990311543563016697299", + "2": "36428320569485697540634597755814766104888687488985202673924762266313135133244610404742081973550848160712054769198012193456278135847215508952327879544434490828380496286187725750283788811367824465072001959950807751252194618152990469069074061195618692339915840384087350671392595652921761835083158086795163935060896053332506433434451836095710383871272788002621913967538399141417857031787255744141437237474972197102809365346359345477248611632307159641948507043668113827177494748159094045928919209335044052792843664865311991178972383241855607627188111601119780878072683890170539599447876998109080150992209773901144245398001"}, + "predicate": {"attr_name": "age", "p_type": "GE", "value": 18}}]}, + "non_revoc_proof": None}, "schema_seq_no": 1, "revoc_reg_seq_no": None, + "issuer_did": "did"}}, + "aggregated_proof": {"c_hash": "33103550379681684069592829341967479618752165928802550870585275205292715916069", + "c_list": [ + [1, 121, 77, 5, 144, 154, 14, 192, 190, 190, 145, 180, 128, 71, 22, 60, 168, 20, 46, + 163, 139, 194, 71, 165, 220, 188, 121, 76, 25, 146, 231, 114, 65, 54, 69, 68, 19, 200, + 250, 192, 47, 123, 157, 132, 74, 50, 28, 69, 226, 195, 243, 118, 45, 63, 237, 197, + 216, 202, 206, 101, 33, 56, 225, 200, 128, 3, 89, 12, 182, 38, 113, 221, 165, 119, + 228, 201, 156, 201, 172, 136, 59, 64, 51, 72, 164, 198, 49, 228, 223, 117, 80, 64, + 166, 226, 37, 8, 29, 146, 186, 80, 210, 119, 76, 252, 4, 255, 62, 218, 112, 163, 164, + 147, 247, 190, 108, 76, 140, 191, 76, 217, 214, 184, 152, 179, 193, 149, 15, 70, 197, + 46, 90, 60, 255, 247, 197, 219, 252, 73, 76, 0, 125, 104, 114, 22, 182, 161, 110, 36, + 162, 103, 27, 42, 88, 18, 161, 237, 198, 43, 177, 189, 181, 86, 135, 207, 71, 114, 0, + 26, 175, 12, 199, 125, 25, 124, 178, 87, 36, 208, 251, 15, 191, 127, 202, 148, 152, + 43, 142, 92, 191, 7, 89, 153, 130, 195, 223, 248, 176, 109, 97, 164, 126, 162, 181, + 124, 237, 130, 155, 197, 66, 59, 40, 197, 72, 84, 32, 100, 64, 55, 227, 60, 214, 143, + 200, 200, 89, 115, 236, 172, 145, 56, 100, 73, 20, 242, 233, 95, 130, 58, 112, 153, + 120, 115, 119, 42, 199, 30, 205, 88, 223, 42, 196, 184, 41, 19, 100, 19, 244], + [1, 225, 103, 238, 42, 147, 91, 191, 110, 69, 154, 53, 57, 156, 124, 43, 174, 155, 76, + 202, 193, 98, 128, 38, 207, 126, 66, 70, 161, 96, 109, 127, 174, 44, 203, 198, 177, + 238, 118, 117, 89, 227, 170, 155, 44, 251, 35, 119, 219, 29, 100, 173, 26, 144, 95, + 50, 177, 4, 40, 234, 117, 174, 210, 192, 172, 57, 160, 198, 42, 199, 212, 243, 240, + 114, 59, 91, 207, 68, 57, 38, 198, 2, 73, 18, 16, 209, 182, 145, 206, 71, 17, 69, 222, + 49, 36, 120, 72, 117, 169, 107, 238, 208, 235, 216, 24, 183, 201, 81, 15, 83, 242, 45, + 136, 184, 166, 26, 142, 136, 228, 58, 229, 235, 88, 169, 238, 134, 205, 96, 85, 9, + 122, 53, 147, 100, 183, 114, 92, 54, 125, 178, 125, 75, 127, 116, 50, 88, 109, 152, + 22, 4, 121, 252, 190, 18, 190, 130, 143, 138, 59, 231, 38, 131, 176, 54, 19, 194, 218, + 67, 144, 122, 91, 43, 86, 73, 233, 48, 193, 30, 183, 183, 191, 238, 216, 167, 101, 28, + 185, 43, 118, 64, 242, 16, 62, 239, 177, 27, 109, 144, 67, 221, 175, 202, 4, 92, 130, + 74, 24, 20, 151, 15, 227, 225, 142, 71, 145, 46, 192, 248, 87, 57, 183, 142, 253, 52, + 20, 56, 153, 220, 234, 25, 67, 116, 225, 179, 211, 116, 161, 37, 64, 34, 48, 155, 1, + 1, 159, 157, 37, 31, 202, 19, 229, 152, 23, 138, 183, 126, 55], + [1, 38, 181, 193, 191, 72, 2, 239, 34, 83, 49, 36, 179, 160, 82, 112, 172, 98, 255, 63, + 60, 22, 177, 249, 67, 215, 220, 198, 181, 7, 49, 254, 133, 243, 221, 214, 47, 64, 229, + 82, 11, 94, 175, 57, 86, 152, 229, 192, 184, 96, 136, 116, 226, 123, 128, 217, 23, + 244, 19, 204, 36, 44, 123, 208, 88, 24, 217, 120, 145, 139, 25, 233, 227, 5, 119, 90, + 47, 147, 1, 115, 92, 39, 119, 194, 167, 17, 229, 39, 163, 167, 237, 14, 116, 234, 106, + 252, 216, 54, 33, 233, 21, 54, 183, 130, 144, 161, 177, 142, 177, 240, 51, 73, 21, + 202, 188, 103, 244, 153, 204, 219, 123, 231, 139, 135, 189, 155, 143, 28, 4, 180, 44, + 148, 0, 27, 103, 26, 13, 203, 31, 32, 166, 67, 84, 87, 23, 72, 234, 236, 20, 1, 84, + 70, 86, 76, 192, 164, 235, 124, 86, 128, 78, 230, 119, 155, 95, 121, 125, 20, 244, + 181, 121, 250, 169, 9, 67, 85, 213, 177, 139, 111, 187, 183, 114, 165, 249, 177, 161, + 181, 175, 46, 226, 66, 86, 84, 124, 86, 69, 143, 217, 158, 161, 30, 107, 133, 44, 239, + 89, 209, 24, 150, 1, 238, 122, 144, 138, 179, 121, 114, 90, 13, 212, 209, 60, 126, 37, + 62, 177, 180, 131, 222, 168, 2, 201, 156, 169, 220, 224, 53, 8, 203, 220, 215, 163, + 104, 195, 184, 73, 35, 241, 182, 177, 80, 41, 253, 230, 90, 173], + [1, 32, 145, 96, 219, 241, 190, 19, 195, 129, 219, 50, 148, 152, 107, 12, 189, 225, + 103, 171, 149, 252, 193, 243, 136, 132, 195, 44, 19, 20, 247, 140, 160, 91, 230, 78, + 31, 242, 85, 213, 65, 185, 1, 91, 12, 69, 118, 80, 26, 135, 102, 131, 4, 108, 130, + 230, 83, 91, 176, 249, 196, 56, 128, 127, 82, 72, 106, 49, 211, 94, 133, 40, 86, 72, + 42, 187, 199, 216, 191, 223, 208, 206, 121, 118, 15, 167, 255, 228, 57, 206, 158, 217, + 64, 205, 212, 178, 8, 248, 129, 183, 221, 98, 70, 54, 37, 55, 47, 81, 120, 59, 186, + 238, 165, 0, 70, 173, 137, 193, 232, 180, 125, 211, 237, 182, 249, 191, 173, 107, 129, + 164, 148, 231, 116, 225, 66, 66, 71, 156, 39, 248, 164, 253, 234, 140, 205, 177, 140, + 117, 47, 21, 15, 242, 31, 113, 118, 91, 143, 89, 213, 86, 143, 135, 21, 46, 35, 199, + 214, 107, 111, 65, 65, 19, 26, 171, 130, 16, 19, 102, 145, 210, 210, 61, 51, 169, 148, + 169, 118, 182, 106, 107, 253, 100, 214, 232, 52, 103, 180, 96, 249, 254, 71, 6, 11, + 119, 48, 129, 213, 223, 205, 93, 20, 117, 26, 187, 32, 151, 212, 137, 203, 17, 237, + 208, 150, 72, 23, 225, 235, 122, 188, 34, 105, 115, 0, 160, 168, 251, 191, 22, 242, + 238, 207, 74, 142, 154, 66, 94, 149, 191, 215, 194, 134, 6, 165, 244, 167, 233, 241], + [1, 207, 77, 250, 146, 127, 242, 229, 44, 172, 182, 201, 183, 242, 32, 242, 182, 129, + 233, 10, 8, 180, 23, 191, 163, 21, 238, 158, 5, 27, 216, 146, 253, 173, 127, 99, 95, + 168, 209, 132, 242, 196, 242, 34, 25, 25, 249, 211, 51, 236, 164, 153, 175, 61, 65, + 150, 82, 251, 174, 102, 186, 47, 195, 82, 44, 90, 252, 184, 74, 89, 251, 177, 254, + 108, 151, 136, 230, 220, 93, 224, 173, 247, 244, 116, 132, 59, 170, 215, 194, 30, 87, + 84, 166, 147, 57, 156, 201, 207, 132, 203, 222, 191, 253, 15, 19, 228, 173, 81, 156, + 4, 51, 121, 227, 159, 50, 18, 148, 129, 205, 42, 42, 227, 252, 138, 62, 176, 115, 227, + 253, 52, 125, 110, 178, 167, 132, 244, 14, 116, 195, 194, 172, 44, 45, 63, 38, 121, + 215, 136, 68, 230, 21, 108, 133, 159, 197, 179, 94, 78, 233, 107, 236, 114, 92, 165, + 248, 22, 124, 161, 23, 142, 236, 224, 175, 233, 134, 25, 97, 150, 131, 61, 220, 203, + 104, 154, 199, 247, 146, 47, 205, 56, 209, 0, 133, 132, 18, 103, 136, 8, 202, 37, 29, + 100, 105, 12, 232, 74, 33, 6, 255, 202, 96, 170, 52, 229, 244, 4, 235, 2, 201, 125, + 86, 168, 179, 224, 130, 81, 54, 221, 185, 184, 187, 141, 0, 114, 98, 38, 70, 225, 228, + 60, 157, 53, 210, 238, 60, 216, 215, 154, 48, 73, 3, 157, 192, 245, 81, 170, 49], + [1, 3, 244, 229, 158, 71, 18, 146, 198, 202, 27, 2, 231, 37, 13, 145, 243, 84, 112, + 220, 61, 174, 4, 175, 104, 200, 64, 146, 193, 20, 174, 126, 42, 157, 168, 76, 165, 21, + 50, 216, 82, 211, 180, 73, 244, 54, 227, 200, 19, 157, 25, 228, 81, 37, 64, 201, 19, + 138, 175, 50, 246, 169, 11, 45, 74, 194, 131, 236, 127, 177, 41, 242, 130, 55, 112, + 182, 98, 22, 99, 48, 153, 83, 161, 250, 65, 89, 3, 97, 6, 5, 171, 54, 223, 87, 98, + 103, 23, 200, 212, 177, 140, 155, 151, 252, 125, 45, 176, 55, 92, 41, 56, 2, 252, 32, + 149, 60, 3, 168, 209, 193, 23, 168, 230, 182, 72, 193, 230, 224, 5, 15, 58, 63, 93, + 196, 33, 93, 76, 188, 30, 70, 31, 136, 64, 204, 223, 2, 230, 210, 243, 255, 135, 193, + 52, 132, 248, 160, 22, 18, 164, 71, 77, 80, 112, 229, 120, 116, 210, 225, 2, 19, 139, + 35, 0, 214, 5, 246, 9, 106, 136, 204, 0, 148, 97, 21, 222, 153, 57, 177, 162, 11, 243, + 252, 7, 242, 34, 239, 245, 50, 104, 74, 221, 92, 73, 13, 142, 10, 184, 250, 246, 167, + 240, 46, 230, 86, 207, 181, 12, 133, 81, 119, 143, 164, 88, 114, 223, 243, 179, 208, + 175, 84, 161, 27, 11, 225, 36, 37, 177, 112, 85, 81, 184, 163, 223, 159, 36, 9, 247, + 20, 13, 230, 215, 108, 117, 35, 99, 117, 211]]}, "requested_proof": { + "revealed_attrs": {"attr1_uuid": ["claim::277478db-bf57-42c3-8530-b1b13cfe0bfd", "Alex", + "1139481716457488690172217916278103335"]}, "unrevealed_attrs": {}, + "self_attested_attrs": {}, + "predicates": {"predicate1_uuid": "claim::277478db-bf57-42c3-8530-b1b13cfe0bfd"}}} + + valid = await verifier_verify_proof(json.dumps(proof_req), json.dumps(proof), + json.dumps(schemas), json.dumps(claim_defs), "{}") + + assert not valid diff --git a/wrappers/python/tests/utils/anoncreds.py b/wrappers/python/tests/utils/anoncreds.py index 65b6218eb4..a02df9f0f6 100644 --- a/wrappers/python/tests/utils/anoncreds.py +++ b/wrappers/python/tests/utils/anoncreds.py @@ -74,7 +74,7 @@ def get_claim_req(): "ur": None}, "issuer_did": ISSUER_DID, "schema_seq_no": 1} -def get_proof_req(): +def get_proof_req(predicate_value=18): return { "nonce": "123432421212", "name": "proof_req_1", @@ -90,7 +90,7 @@ def get_proof_req(): "predicate1_uuid": { "attr_name": "age", "p_type": "GE", - "value": 18 + "value": predicate_value } } } From 32d052eea34dc3c765a4d86b5ddbf27bfe5cad96 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 26 Jul 2017 10:53:41 +0300 Subject: [PATCH 341/349] fixed tests for ledger --- wrappers/python/indy/ledger.py | 149 ++++++++++-------- .../ledger/test_build_get_claim_def_txn.py | 2 +- .../tests/ledger/test_build_nym_request.py | 2 +- .../ledger/test_sign_and_submit_request.py | 14 +- 4 files changed, 90 insertions(+), 77 deletions(-) diff --git a/wrappers/python/indy/ledger.py b/wrappers/python/indy/ledger.py index ec5141b7b3..7989342a86 100644 --- a/wrappers/python/indy/ledger.py +++ b/wrappers/python/indy/ledger.py @@ -40,13 +40,14 @@ async def sign_and_submit_request(pool_handle: int, c_submitter_did = c_char_p(submitter_did.encode('utf-8')) c_request_json = c_char_p(request_json.encode('utf-8')) - res = await do_call('indy_sign_and_submit_request', - c_pool_handle, - c_wallet_handle, - c_submitter_did, - c_request_json, - sign_and_submit_request.cb) - + request_result = await do_call('indy_sign_and_submit_request', + c_pool_handle, + c_wallet_handle, + c_submitter_did, + c_request_json, + sign_and_submit_request.cb) + + res = request_result.decode() logger.debug("sign_and_submit_request: <<< res: %s", res) return res @@ -74,11 +75,12 @@ async def submit_request(pool_handle: int, c_pool_handle = c_int32(pool_handle) c_request_json = c_char_p(request_json.encode('utf-8')) - res = await do_call('indy_submit_request', - c_pool_handle, - c_request_json, - submit_request.cb) + request_result = await do_call('indy_submit_request', + c_pool_handle, + c_request_json, + submit_request.cb) + res = request_result.decode() logger.debug("submit_request: <<< res: %s", res) return res @@ -105,11 +107,12 @@ async def build_get_ddo_request(submitter_did: str, c_submitter_did = c_char_p(submitter_did.encode('utf-8')) c_target_did = c_char_p(target_did.encode('utf-8')) - res = await do_call('indy_build_get_ddo_request', - c_submitter_did, - c_target_did, - build_get_ddo_request.cb) + request_json = await do_call('indy_build_get_ddo_request', + c_submitter_did, + c_target_did, + build_get_ddo_request.cb) + res = request_json.decode() logger.debug("build_get_ddo_request: <<< res: %s", res) return res @@ -148,14 +151,15 @@ async def build_nym_request(submitter_did: str, c_alias = c_char_p(alias.encode('utf-8')) if alias is not None else None c_role = c_char_p(role.encode('utf-8')) if role is not None else None - res = await do_call('indy_build_nym_request', - c_submitter_did, - c_target_did, - c_ver_key, - c_alias, - c_role, - build_nym_request.cb) + request_json = await do_call('indy_build_nym_request', + c_submitter_did, + c_target_did, + c_ver_key, + c_alias, + c_role, + build_nym_request.cb) + res = request_json.decode() logger.debug("build_nym_request: <<< res: %s", res) return res @@ -194,14 +198,15 @@ async def build_attrib_request(submitter_did: str, c_raw = c_char_p(raw.encode('utf-8')) if raw is not None else None c_enc = c_char_p(enc.encode('utf-8')) if enc is not None else None - res = await do_call('indy_build_attrib_request', - c_submitter_did, - c_target_did, - c_hash, - c_raw, - c_enc, - build_attrib_request.cb) + request_json = await do_call('indy_build_attrib_request', + c_submitter_did, + c_target_did, + c_hash, + c_raw, + c_enc, + build_attrib_request.cb) + res = request_json.decode() logger.debug("build_attrib_request: <<< res: %s", res) return res @@ -232,12 +237,13 @@ async def build_get_attrib_request(submitter_did: str, c_target_did = c_char_p(target_did.encode('utf-8')) c_data = c_char_p(data.encode('utf-8')) - res = await do_call('indy_build_get_attrib_request', - c_submitter_did, - c_target_did, - c_data, - build_get_attrib_request.cb) + request_json = await do_call('indy_build_get_attrib_request', + c_submitter_did, + c_target_did, + c_data, + build_get_attrib_request.cb) + res = request_json.decode() logger.debug("build_get_attrib_request: <<< res: %s", res) return res @@ -264,11 +270,12 @@ async def build_get_nym_request(submitter_did: str, c_submitter_did = c_char_p(submitter_did.encode('utf-8')) c_target_did = c_char_p(target_did.encode('utf-8')) - res = await do_call('indy_build_get_nym_request', - c_submitter_did, - c_target_did, - build_get_nym_request.cb) + request_json = await do_call('indy_build_get_nym_request', + c_submitter_did, + c_target_did, + build_get_nym_request.cb) + res = request_json.decode() logger.debug("build_get_nym_request: <<< res: %s", res) return res @@ -295,11 +302,12 @@ async def build_schema_request(submitter_did: str, c_submitter_did = c_char_p(submitter_did.encode('utf-8')) c_data = c_char_p(data.encode('utf-8')) - res = await do_call('indy_build_schema_request', - c_submitter_did, - c_data, - build_schema_request.cb) + request_json = await do_call('indy_build_schema_request', + c_submitter_did, + c_data, + build_schema_request.cb) + res = request_json.decode() logger.debug("build_schema_request: <<< res: %s", res) return res @@ -330,12 +338,13 @@ async def build_get_schema_request(submitter_did: str, c_dest = c_char_p(dest.encode('utf-8')) c_data = c_char_p(data.encode('utf-8')) - res = await do_call('indy_build_get_schema_request', - c_submitter_did, - c_dest, - c_data, - build_get_schema_request.cb) + request_json = await do_call('indy_build_get_schema_request', + c_submitter_did, + c_dest, + c_data, + build_get_schema_request.cb) + res = request_json.decode() logger.debug("build_get_schema_request: <<< res: %s", res) return res @@ -370,13 +379,14 @@ async def build_claim_def_txn(submitter_did: str, c_signature_type = c_char_p(signature_type.encode('utf-8')) c_data = c_char_p(data.encode('utf-8')) - res = await do_call('indy_build_claim_def_txn', - c_submitter_did, - c_xref, - c_signature_type, - c_data, - build_claim_def_txn.cb) + request_result = await do_call('indy_build_claim_def_txn', + c_submitter_did, + c_xref, + c_signature_type, + c_data, + build_claim_def_txn.cb) + res = request_result.decode() logger.debug("build_claim_def_txn: <<< res: %s", res) return res @@ -411,13 +421,14 @@ async def build_get_claim_def_txn(submitter_did: str, c_signature_type = c_char_p(signature_type.encode('utf-8')) c_origin = c_char_p(origin.encode('utf-8')) - res = await do_call('indy_build_get_claim_def_txn', - c_submitter_did, - c_xref, - c_signature_type, - c_origin, - build_get_claim_def_txn.cb) + request_json = await do_call('indy_build_get_claim_def_txn', + c_submitter_did, + c_xref, + c_signature_type, + c_origin, + build_get_claim_def_txn.cb) + res = request_json.decode() logger.debug("build_get_claim_def_txn: <<< res: %s", res) return res @@ -448,12 +459,13 @@ async def build_node_request(submitter_did: str, c_target_did = c_char_p(target_did.encode('utf-8')) c_data = c_char_p(data.encode('utf-8')) - res = await do_call('indy_build_node_request', - c_submitter_did, - c_target_did, - c_data, - build_node_request.cb) + request_json = await do_call('indy_build_node_request', + c_submitter_did, + c_target_did, + c_data, + build_node_request.cb) + res = request_json.decode() logger.debug("build_node_request: <<< res: %s", res) return res @@ -480,10 +492,11 @@ async def build_get_txn_request(submitter_did: str, c_submitter_did = c_char_p(submitter_did.encode('utf-8')) c_data = c_int32(data) - res = await do_call('indy_build_get_txn_request', - c_submitter_did, - c_data, - build_get_txn_request.cb) + request_json = await do_call('indy_build_get_txn_request', + c_submitter_did, + c_data, + build_get_txn_request.cb) + res = request_json.decode() logger.debug("build_get_txn_request: <<< res: %s", res) return res diff --git a/wrappers/python/tests/ledger/test_build_get_claim_def_txn.py b/wrappers/python/tests/ledger/test_build_get_claim_def_txn.py index dd6de331af..8205a6bd15 100644 --- a/wrappers/python/tests/ledger/test_build_get_claim_def_txn.py +++ b/wrappers/python/tests/ledger/test_build_get_claim_def_txn.py @@ -34,7 +34,7 @@ async def test_build_get_claim_def_request_works(): response = json.loads((await ledger.build_get_claim_def_txn( identifier, _ref, signature_type, origin - )).decode()) + ))) assert expected_response.items() <= response.items() diff --git a/wrappers/python/tests/ledger/test_build_nym_request.py b/wrappers/python/tests/ledger/test_build_nym_request.py index c858e5e12f..d5d273e283 100644 --- a/wrappers/python/tests/ledger/test_build_nym_request.py +++ b/wrappers/python/tests/ledger/test_build_nym_request.py @@ -42,7 +42,7 @@ async def test_build_nym_request_works_for_only_required_fields(): } } - response = json.loads((await ledger.build_nym_request(identifier, destination, None, None, None)).decode()) + response = json.loads((await ledger.build_nym_request(identifier, destination, None, None, None))) assert expected_response.items() <= response.items() diff --git a/wrappers/python/tests/ledger/test_sign_and_submit_request.py b/wrappers/python/tests/ledger/test_sign_and_submit_request.py index 4f40e3b4ed..df81747b05 100644 --- a/wrappers/python/tests/ledger/test_sign_and_submit_request.py +++ b/wrappers/python/tests/ledger/test_sign_and_submit_request.py @@ -36,7 +36,7 @@ async def test_sign_and_submit_request_works(wallet_handle, pool_handle): (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') nym_request = await ledger.build_nym_request(trustee_did, my_did, None, None, None) - await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did.decode(), nym_request) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did, nym_request) @pytest.mark.asyncio @@ -44,11 +44,11 @@ async def test_sign_and_submit_request_works_for_invalid_pool_handle(wallet_hand (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') - nym_request = await ledger.build_nym_request(trustee_did.decode(), my_did.decode(), None, None, None) + nym_request = await ledger.build_nym_request(trustee_did, my_did, None, None, None) invalid_pool_handle = pool_handle + 1 try: - await ledger.sign_and_submit_request(invalid_pool_handle, wallet_handle, trustee_did.decode(), + await ledger.sign_and_submit_request(invalid_pool_handle, wallet_handle, trustee_did, nym_request) raise Exception("Failed") except Exception as e: @@ -61,11 +61,11 @@ async def test_sign_and_submit_request_works_for_invalid_wallet_handle(wallet_ha (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') - nym_request = await ledger.build_nym_request(trustee_did.decode(), my_did.decode(), None, None, None) + nym_request = await ledger.build_nym_request(trustee_did, my_did, None, None, None) invalid_wallet_handle = wallet_handle + 1 try: - await ledger.sign_and_submit_request(pool_handle, invalid_wallet_handle, trustee_did.decode(), + await ledger.sign_and_submit_request(pool_handle, invalid_wallet_handle, trustee_did, nym_request) raise Exception("Failed") except Exception as e: @@ -79,10 +79,10 @@ async def test_sign_and_submit_request_works_for_incompatible_wallet_and_pool(po (my_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') - nym_request = await ledger.build_nym_request(trustee_did.decode(), my_did.decode(), None, None, None) + nym_request = await ledger.build_nym_request(trustee_did, my_did, None, None, None) try: - await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did.decode(), + await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did, nym_request) raise Exception("Failed") except Exception as e: From 61e575f4d8d02f3768ff3a57168da4d6151f8fd3 Mon Sep 17 00:00:00 2001 From: Evgeniy Razinkov Date: Wed, 26 Jul 2017 11:02:40 +0300 Subject: [PATCH 342/349] small refactoring for errors --- .../tests/ledger/test_build_attrib_request.py | 7 ++-- .../tests/ledger/test_build_node_request.py | 7 +--- .../tests/ledger/test_build_nym_request.py | 7 +--- .../ledger/test_sign_and_submit_request.py | 22 ++++------- .../tests/ledger/test_submit_request.py | 37 ++++++------------- 5 files changed, 26 insertions(+), 54 deletions(-) diff --git a/wrappers/python/tests/ledger/test_build_attrib_request.py b/wrappers/python/tests/ledger/test_build_attrib_request.py index a02c24d230..4d76086543 100644 --- a/wrappers/python/tests/ledger/test_build_attrib_request.py +++ b/wrappers/python/tests/ledger/test_build_attrib_request.py @@ -40,9 +40,8 @@ async def test_build_attrib_request_works_for_missed_attribute(): identifier = "Th7MpTaRZVRYnPiabds81Y" destination = "Th7MpTaRZVRYnPiabds81Y" - try: + with pytest.raises(IndyError) as e: await ledger.build_attrib_request(identifier, destination, None, None, None) - except Exception as e: - assert type(IndyError(ErrorCode.CommonInvalidStructure)) == type(e) and \ - IndyError(ErrorCode.CommonInvalidStructure).args == e.args + assert ErrorCode.CommonInvalidStructure == e.value.error_code + diff --git a/wrappers/python/tests/ledger/test_build_node_request.py b/wrappers/python/tests/ledger/test_build_node_request.py index d0bb74e34c..192c286337 100644 --- a/wrappers/python/tests/ledger/test_build_node_request.py +++ b/wrappers/python/tests/ledger/test_build_node_request.py @@ -27,12 +27,9 @@ async def test_build_node_request_works_for_missed_field_in_data_json(): "client_port": 1 } - try: + with pytest.raises(IndyError) as e: await ledger.build_node_request(identifier, destination, json.dumps(data)) - raise Exception("Failed") - except Exception as e: - assert type(IndyError(ErrorCode.CommonInvalidStructure)) == type(e) and \ - IndyError(ErrorCode.CommonInvalidStructure).args == e.args + assert ErrorCode.CommonInvalidStructure == e.value.error_code @pytest.mark.asyncio diff --git a/wrappers/python/tests/ledger/test_build_nym_request.py b/wrappers/python/tests/ledger/test_build_nym_request.py index d5d273e283..161d54c447 100644 --- a/wrappers/python/tests/ledger/test_build_nym_request.py +++ b/wrappers/python/tests/ledger/test_build_nym_request.py @@ -21,12 +21,9 @@ async def test_build_nym_request_works_for_invalid_identifier(): identifier = "invalid_base58_identifier" dest = "FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4" - try: + with pytest.raises(IndyError) as e: await ledger.build_nym_request(identifier, dest, None, None, None) - raise Exception("Failed") - except Exception as e: - assert type(IndyError(ErrorCode.CommonInvalidStructure)) == type(e) and \ - IndyError(ErrorCode.CommonInvalidStructure).args == e.args + assert ErrorCode.CommonInvalidStructure == e.value.error_code @pytest.mark.asyncio diff --git a/wrappers/python/tests/ledger/test_sign_and_submit_request.py b/wrappers/python/tests/ledger/test_sign_and_submit_request.py index df81747b05..0d2a59eb89 100644 --- a/wrappers/python/tests/ledger/test_sign_and_submit_request.py +++ b/wrappers/python/tests/ledger/test_sign_and_submit_request.py @@ -47,13 +47,10 @@ async def test_sign_and_submit_request_works_for_invalid_pool_handle(wallet_hand nym_request = await ledger.build_nym_request(trustee_did, my_did, None, None, None) invalid_pool_handle = pool_handle + 1 - try: + with pytest.raises(IndyError) as e: await ledger.sign_and_submit_request(invalid_pool_handle, wallet_handle, trustee_did, nym_request) - raise Exception("Failed") - except Exception as e: - assert type(IndyError(ErrorCode.PoolLedgerInvalidPoolHandle)) == type(e) and \ - IndyError(ErrorCode.PoolLedgerInvalidPoolHandle).args == e.args + assert ErrorCode.PoolLedgerInvalidPoolHandle == e.value.error_code @pytest.mark.asyncio @@ -64,13 +61,10 @@ async def test_sign_and_submit_request_works_for_invalid_wallet_handle(wallet_ha nym_request = await ledger.build_nym_request(trustee_did, my_did, None, None, None) invalid_wallet_handle = wallet_handle + 1 - try: + with pytest.raises(IndyError) as e: await ledger.sign_and_submit_request(pool_handle, invalid_wallet_handle, trustee_did, nym_request) - raise Exception("Failed") - except Exception as e: - assert type(IndyError(ErrorCode.WalletInvalidHandle)) == type(e) and \ - IndyError(ErrorCode.WalletInvalidHandle).args == e.args + assert ErrorCode.WalletInvalidHandle == e.value.error_code @pytest.mark.asyncio @@ -81,11 +75,9 @@ async def test_sign_and_submit_request_works_for_incompatible_wallet_and_pool(po '{"seed":"000000000000000000000000Trustee1"}') nym_request = await ledger.build_nym_request(trustee_did, my_did, None, None, None) - try: + with pytest.raises(IndyError) as e: await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did, nym_request) - raise Exception("Failed") - except Exception as e: - assert type(IndyError(ErrorCode.WalletIncompatiblePoolError)) == type(e) and \ - IndyError(ErrorCode.WalletIncompatiblePoolError).args == e.args + assert ErrorCode.WalletIncompatiblePoolError == e.value.error_code + await wallet.close_wallet(wallet_handle) diff --git a/wrappers/python/tests/ledger/test_submit_request.py b/wrappers/python/tests/ledger/test_submit_request.py index 2ed4191847..605fa6e8ea 100644 --- a/wrappers/python/tests/ledger/test_submit_request.py +++ b/wrappers/python/tests/ledger/test_submit_request.py @@ -66,12 +66,10 @@ async def test_submit_request_works_for_invalid_pool_handle(pool_handle, wallet_ get_nym_request = await ledger.build_get_nym_request(my_did, my_did) invalid_pool_handle = pool_handle + 1 - try: + + with pytest.raises(IndyError) as e: await ledger.submit_request(invalid_pool_handle, get_nym_request) - raise Exception("Failed") - except Exception as e: - assert type(IndyError(ErrorCode.PoolLedgerInvalidPoolHandle)) == type(e) and \ - IndyError(ErrorCode.PoolLedgerInvalidPoolHandle).args == e.args + assert ErrorCode.PoolLedgerInvalidPoolHandle == e.value.error_code @pytest.mark.asyncio @@ -80,12 +78,10 @@ async def test_send_nym_request_works_without_signature(pool_handle, wallet_hand '{"seed":"00000000000000000000000000000My1"}') nym_request = await ledger.build_nym_request(my_did, my_did, None, None, None) - try: + + with pytest.raises(IndyError) as e: await ledger.submit_request(pool_handle, nym_request) - raise Exception("Failed") - except Exception as e: - assert type(IndyError(ErrorCode.LedgerInvalidTransaction)) == type(e) and \ - IndyError(ErrorCode.LedgerInvalidTransaction).args == e.args + assert ErrorCode.LedgerInvalidTransaction == e.value.error_code @pytest.mark.asyncio @@ -120,12 +116,9 @@ async def test_send_attrib_request_works_without_signature(pool_handle, wallet_h attrib_request = await ledger.build_attrib_request(my_did, my_did, None, "{\"endpoint\":{\"ha\":\"127.0.0.1:5555\"}}", None) - try: + with pytest.raises(IndyError) as e: await ledger.submit_request(pool_handle, attrib_request) - raise Exception("Failed") - except Exception as e: - assert type(IndyError(ErrorCode.LedgerInvalidTransaction)) == type(e) and \ - IndyError(ErrorCode.LedgerInvalidTransaction).args == e.args + assert ErrorCode.LedgerInvalidTransaction == e.value.error_code @pytest.mark.asyncio @@ -157,12 +150,9 @@ async def test_send_schema_request_works_without_signature(pool_handle, wallet_h schema_request = await ledger.build_schema_request(my_did, json.dumps(schema_data)) - try: + with pytest.raises(IndyError) as e: await ledger.submit_request(pool_handle, schema_request) - raise Exception("Failed") - except Exception as e: - assert type(IndyError(ErrorCode.LedgerInvalidTransaction)) == type(e) and \ - IndyError(ErrorCode.LedgerInvalidTransaction).args == e.args + assert ErrorCode.LedgerInvalidTransaction == e.value.error_code @pytest.mark.asyncio @@ -207,12 +197,9 @@ async def test_send_node_request_works_without_signature(pool_handle, wallet_han node_request = await ledger.build_node_request(my_did, my_did, json.dumps(node_data)) - try: + with pytest.raises(IndyError) as e: await ledger.submit_request(pool_handle, node_request) - raise Exception("Failed") - except Exception as e: - assert type(IndyError(ErrorCode.LedgerInvalidTransaction)) == type(e) and \ - IndyError(ErrorCode.LedgerInvalidTransaction).args == e.args + assert ErrorCode.LedgerInvalidTransaction == e.value.error_code @pytest.mark.asyncio From a0bfff1c17818d77b936873d569026b954394c27 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 26 Jul 2017 11:12:15 +0300 Subject: [PATCH 343/349] Use global fixture --- wrappers/python/tests/demo/agent.py | 9 +-------- wrappers/python/tests/demo/anoncreds.py | 9 +-------- wrappers/python/tests/demo/ledger.py | 9 +-------- wrappers/python/tests/demo/signus.py | 9 +-------- 4 files changed, 4 insertions(+), 32 deletions(-) diff --git a/wrappers/python/tests/demo/agent.py b/wrappers/python/tests/demo/agent.py index e1baf24df4..56f4fd1eed 100644 --- a/wrappers/python/tests/demo/agent.py +++ b/wrappers/python/tests/demo/agent.py @@ -13,15 +13,8 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.fixture(autouse=True) -def before_after_each(): - storage.cleanup() - yield - storage.cleanup() - - @pytest.mark.asyncio -async def test_agent_demo_works(): +async def test_agent_demo_works(cleanup_storage): pool_name = "pool" listener_wallet_name = "listener_wallet" sender_wallet_name = "sender_wallet" diff --git a/wrappers/python/tests/demo/anoncreds.py b/wrappers/python/tests/demo/anoncreds.py index fc39d5bfc1..aa4f5727ac 100644 --- a/wrappers/python/tests/demo/anoncreds.py +++ b/wrappers/python/tests/demo/anoncreds.py @@ -9,15 +9,8 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.fixture(autouse=True) -def before_after_each(): - storage.cleanup() - yield - storage.cleanup() - - @pytest.mark.asyncio -async def test_anoncreds_demo_works(): +async def test_anoncreds_demo_works(cleanup_storage): pool_name = "anoncreds_demo_pool" wallet_name = "anoncreds_demo_wallet" diff --git a/wrappers/python/tests/demo/ledger.py b/wrappers/python/tests/demo/ledger.py index 16727b0e27..25fda95b47 100644 --- a/wrappers/python/tests/demo/ledger.py +++ b/wrappers/python/tests/demo/ledger.py @@ -12,15 +12,8 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.fixture(autouse=True) -def before_after_each(): - storage.cleanup() - yield - storage.cleanup() - - @pytest.mark.asyncio -async def test_ledger_demo_works(): +async def test_ledger_demo_works(cleanup_storage): pool_name = "pool" my_wallet_name = "my_wallet" their_wallet_name = "their_wallet" diff --git a/wrappers/python/tests/demo/signus.py b/wrappers/python/tests/demo/signus.py index f68e3fc929..243fa77ee9 100644 --- a/wrappers/python/tests/demo/signus.py +++ b/wrappers/python/tests/demo/signus.py @@ -10,15 +10,8 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.fixture(autouse=True) -def before_after_each(): - storage.cleanup() - yield - storage.cleanup() - - @pytest.mark.asyncio -async def test_signus_demo_works(): +async def test_signus_demo_works(cleanup_storage): pool_name = "create" my_wallet_name = "my_wallet" their_wallet_name = "their_wallet" From e8c2d54bfcd478d2fe1127eb8f9a99d68d4e2627 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 26 Jul 2017 11:14:42 +0300 Subject: [PATCH 344/349] Used common cleanup --- .../python/tests/wallet/test_close_wallet.py | 11 ++--------- .../python/tests/wallet/test_create_wallet.py | 19 ++++++------------- .../python/tests/wallet/test_delete_wallet.py | 17 +++++------------ .../python/tests/wallet/test_open_wallet.py | 15 ++++----------- 4 files changed, 17 insertions(+), 45 deletions(-) diff --git a/wrappers/python/tests/wallet/test_close_wallet.py b/wrappers/python/tests/wallet/test_close_wallet.py index 148f67a08b..e20d58bb73 100644 --- a/wrappers/python/tests/wallet/test_close_wallet.py +++ b/wrappers/python/tests/wallet/test_close_wallet.py @@ -10,15 +10,8 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.yield_fixture(autouse=True) -def cleanup_storage(): - storage.cleanup() - yield - storage.cleanup() - - @pytest.mark.asyncio -async def test_close_wallet_works(): +async def test_close_wallet_works(cleanup_storage): wallet_name = 'wallet1' await wallet.create_wallet('pool1', wallet_name, None, None, None) @@ -30,7 +23,7 @@ async def test_close_wallet_works(): @pytest.mark.asyncio -async def test_close_wallet_works_for_twice(): +async def test_close_wallet_works_for_twice(cleanup_storage): with pytest.raises(IndyError) as e: wallet_name = 'wallet_for_twice' await wallet.create_wallet('pool1', wallet_name, None, None, None) diff --git a/wrappers/python/tests/wallet/test_create_wallet.py b/wrappers/python/tests/wallet/test_create_wallet.py index dfae1c23fb..5eaa885e05 100644 --- a/wrappers/python/tests/wallet/test_create_wallet.py +++ b/wrappers/python/tests/wallet/test_create_wallet.py @@ -10,44 +10,37 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.yield_fixture(autouse=True) -def cleanup_storage(): - storage.cleanup() - yield - storage.cleanup() - - @pytest.mark.asyncio -async def test_create_wallet_works(): +async def test_create_wallet_works(cleanup_storage): await wallet.create_wallet('pool1', 'wallet1', 'default', None, None) @pytest.mark.asyncio -async def test_create_wallet_works_for_empty_type(): +async def test_create_wallet_works_for_empty_type(cleanup_storage): await wallet.create_wallet('pool1', 'wallet1', None, None, None) @pytest.mark.asyncio -async def test_create_wallet_works_for_config_json(): +async def test_create_wallet_works_for_config_json(cleanup_storage): await wallet.create_wallet('pool1', 'wallet3', 'default', '{"freshness_time":1000}', None) @pytest.mark.asyncio -async def test_create_wallet_works_for_unknown_type(): +async def test_create_wallet_works_for_unknown_type(cleanup_storage): with pytest.raises(IndyError) as e: await wallet.create_wallet('pool1', 'wallet3', 'unknown_type', None, None) assert ErrorCode.WalletUnknownTypeError == e.value.error_code @pytest.mark.asyncio -async def test_create_wallet_works_for_empty_name(): +async def test_create_wallet_works_for_empty_name(cleanup_storage): with pytest.raises(IndyError) as e: await wallet.create_wallet('pool1', '', 'default', None, None) assert ErrorCode.CommonInvalidParam3 == e.value.error_code @pytest.mark.asyncio -async def test_create_wallet_works_for_duplicate_name(): +async def test_create_wallet_works_for_duplicate_name(cleanup_storage): with pytest.raises(IndyError) as e: await wallet.create_wallet('pool1', 'wallet4', 'default', None, None) await wallet.create_wallet('pool1', 'wallet4', 'default', None, None) diff --git a/wrappers/python/tests/wallet/test_delete_wallet.py b/wrappers/python/tests/wallet/test_delete_wallet.py index 26f7a9c6dc..94f558c6e8 100644 --- a/wrappers/python/tests/wallet/test_delete_wallet.py +++ b/wrappers/python/tests/wallet/test_delete_wallet.py @@ -10,15 +10,8 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.yield_fixture(autouse=True) -def cleanup_storage(): - storage.cleanup() - yield - storage.cleanup() - - @pytest.mark.asyncio -async def test_delete_wallet_works(): +async def test_delete_wallet_works(cleanup_storage): wallet_name = 'wallet1' await wallet.create_wallet('pool1', wallet_name, None, None, None) await wallet.delete_wallet(wallet_name, None) @@ -26,7 +19,7 @@ async def test_delete_wallet_works(): @pytest.mark.asyncio -async def test_delete_wallet_works_for_closed(): +async def test_delete_wallet_works_for_closed(cleanup_storage): wallet_name = 'wallet2' await wallet.create_wallet('pool1', wallet_name, None, None, None) wallet_handle = await wallet.open_wallet(wallet_name, None, None) @@ -36,7 +29,7 @@ async def test_delete_wallet_works_for_closed(): @pytest.mark.skip(reason="There is BUG in indy-sdk") -async def test_delete_wallet_works_for_opened(): +async def test_delete_wallet_works_for_opened(cleanup_storage): with pytest.raises(IndyError) as e: wallet_name = 'wallet_for_opened' await wallet.create_wallet('pool1', wallet_name, None, None, None) @@ -46,7 +39,7 @@ async def test_delete_wallet_works_for_opened(): @pytest.mark.asyncio -async def test_delete_wallet_works_for_twice(): +async def test_delete_wallet_works_for_twice(cleanup_storage): with pytest.raises(IndyError) as e: wallet_name = 'wallet_for_twice' await wallet.create_wallet('pool1', wallet_name, None, None, None) @@ -56,7 +49,7 @@ async def test_delete_wallet_works_for_twice(): @pytest.mark.asyncio -async def test_delete_wallet_works_for_not_created(): +async def test_delete_wallet_works_for_not_created(cleanup_storage): with pytest.raises(IndyError) as e: wallet_name = 'wallet_not_created' await wallet.delete_wallet(wallet_name, None) diff --git a/wrappers/python/tests/wallet/test_open_wallet.py b/wrappers/python/tests/wallet/test_open_wallet.py index f415ed527a..5238320e98 100644 --- a/wrappers/python/tests/wallet/test_open_wallet.py +++ b/wrappers/python/tests/wallet/test_open_wallet.py @@ -10,15 +10,8 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.yield_fixture(autouse=True) -def before_after_each(): - storage.cleanup() - yield - storage.cleanup() - - @pytest.mark.asyncio -async def test_open_wallet_works(): +async def test_open_wallet_works(cleanup_storage): await wallet.create_wallet('pool1', 'wallet1', None, None, None) wallet_handle = await wallet.open_wallet('wallet1', None, None) assert wallet_handle is not None @@ -27,7 +20,7 @@ async def test_open_wallet_works(): @pytest.mark.asyncio -async def test_open_wallet_works_for_config(): +async def test_open_wallet_works_for_config(cleanup_storage): await wallet.create_wallet('pool1', 'wallet2', None, None, None) wallet_handle = await wallet.open_wallet('wallet2', '{"freshness_time":1000}', None) assert wallet_handle is not None @@ -36,14 +29,14 @@ async def test_open_wallet_works_for_config(): @pytest.mark.asyncio -async def test_open_wallet_works_for_not_created_wallet(): +async def test_open_wallet_works_for_not_created_wallet(cleanup_storage): with pytest.raises(IndyError) as e: await wallet.open_wallet('wallet_not_created', None, None) assert ErrorCode.CommonIOError == e.value.error_code @pytest.mark.asyncio -async def test_open_wallet_works_for_twice(): +async def test_open_wallet_works_for_twice(cleanup_storage): with pytest.raises(IndyError) as e: await wallet.create_wallet('pool1', 'wallet_twice', None, None, None) await wallet.open_wallet('wallet_twice', None, None) From fcc6054e07ce6367b8f3e9d0991506e2036ff754 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 26 Jul 2017 12:19:10 +0300 Subject: [PATCH 345/349] Implemented Signus Demo tests for python wrapper. --- tests/signus.rs | 28 ++- .../indy/sdk/signus/CreateMyDidTest.java | 8 +- wrappers/python/indy/ledger.py | 4 +- wrappers/python/indy/signus.py | 4 +- .../signus/test_create_and_store_my_did.py | 78 +++++++-- .../python/tests/signus/test_replace_keys.py | 56 ++++-- wrappers/python/tests/signus/test_sign.py | 47 ++++-- .../tests/signus/test_store_their_did.py | 58 +++++-- .../tests/signus/test_verify_signature.py | 159 ++++++++++++++++-- 9 files changed, 353 insertions(+), 89 deletions(-) diff --git a/tests/signus.rs b/tests/signus.rs index 83a5645059..a3903ce332 100644 --- a/tests/signus.rs +++ b/tests/signus.rs @@ -124,9 +124,11 @@ mod high_cases { let wallet_handle = WalletUtils::create_and_open_wallet("pool1", None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, "{}").unwrap(); + let (my_did, my_verkey, _) = SignusUtils::create_my_did(wallet_handle, "{}").unwrap(); + + let (new_verkey, _) = SignusUtils::replace_keys(wallet_handle, &my_did, "{}").unwrap(); - SignusUtils::replace_keys(wallet_handle, &my_did, "{}").unwrap(); + assert!(new_verkey != my_verkey); TestUtils::cleanup_storage(); } @@ -304,7 +306,7 @@ mod high_cases { let wallet_handle = WalletUtils::create_and_open_wallet("pool1", None).unwrap(); - let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{"seed":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}"#).unwrap(); + let (my_did, _, _) = SignusUtils::create_my_did(wallet_handle, r#"{}"#).unwrap(); let message = r#"{"reqId":1495034346617224651,}"#; @@ -554,7 +556,22 @@ mod medium_cases { } #[test] - fn indy_replace_keys_works_for_not_invalid_crypto_type() { + fn indy_replace_keys_works_for_correct_crypto_type() { + TestUtils::cleanup_storage(); + + let wallet_handle = WalletUtils::create_and_open_wallet("pool1", None).unwrap(); + + let (my_did, my_verkey, _) = SignusUtils::create_my_did(wallet_handle, "{}").unwrap(); + + let (new_verkey, _) = SignusUtils::replace_keys(wallet_handle, &my_did, r#"{"crypto_type":"ed25519"}"#).unwrap(); + + assert!(my_verkey != new_verkey); + + TestUtils::cleanup_storage(); + } + + #[test] + fn indy_replace_keys_works_for_invalid_crypto_type() { TestUtils::cleanup_storage(); let wallet_handle = WalletUtils::create_and_open_wallet("pool1", None).unwrap(); @@ -650,7 +667,8 @@ mod medium_cases { SignusUtils::store_their_did(wallet_handle, &identity_json).unwrap(); - let message = r#"1496822211362017764"#; + let message = r#""reqId":1496822211362017764, + "signature":"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai""#; let res = SignusUtils::verify(wallet_handle, pool_handle, &did, message); assert_eq!(res.unwrap_err(), ErrorCode::CommonInvalidStructure); diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java index 83718c9cae..5a54d117be 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/CreateMyDidTest.java @@ -38,6 +38,8 @@ public void deleteWallet() throws Exception { private String did = "8wZcEriaNLNKtteJvx7f8i"; private String expectedVerkey = "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"; private String existsCryptoType = "ed25519"; + private String expectedDid = "NcYxiDXkpYi6ov5FcYDi1e"; + @Test public void testCreateMyDidWorksForEmptyJson() throws Exception { @@ -61,7 +63,6 @@ public void testCreateMyDidWorksForSeed() throws Exception { CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); assertNotNull(result); - String expectedDid = "NcYxiDXkpYi6ov5FcYDi1e"; assertEquals(expectedDid, result.getDid()); assertEquals(expectedVerkey, result.getVerkey()); } @@ -95,10 +96,13 @@ public void testCreateMyDidWorksForPassedDid() throws Exception { public void testCreateMyDidWorksForCorrectCryptoType() throws Exception { SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, null, existsCryptoType, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, seed, existsCryptoType, null); CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); assertNotNull(result); + + assertEquals(expectedDid, result.getDid()); + assertEquals(expectedVerkey, result.getVerkey()); } @Test diff --git a/wrappers/python/indy/ledger.py b/wrappers/python/indy/ledger.py index ec5141b7b3..46780a2e96 100644 --- a/wrappers/python/indy/ledger.py +++ b/wrappers/python/indy/ledger.py @@ -148,7 +148,7 @@ async def build_nym_request(submitter_did: str, c_alias = c_char_p(alias.encode('utf-8')) if alias is not None else None c_role = c_char_p(role.encode('utf-8')) if role is not None else None - res = await do_call('indy_build_nym_request', + nym_req = await do_call('indy_build_nym_request', c_submitter_did, c_target_did, c_ver_key, @@ -156,6 +156,8 @@ async def build_nym_request(submitter_did: str, c_role, build_nym_request.cb) + res = nym_req.decode() + logger.debug("build_nym_request: <<< res: %s", res) return res diff --git a/wrappers/python/indy/signus.py b/wrappers/python/indy/signus.py index adb582d6b6..4ca47b1aec 100644 --- a/wrappers/python/indy/signus.py +++ b/wrappers/python/indy/signus.py @@ -84,12 +84,14 @@ async def replace_keys(wallet_handle: int, c_did = c_char_p(did.encode('utf-8')) c_identity_json = c_char_p(identity_json.encode('utf-8')) - res = await do_call('indy_replace_keys', + verkey, pk = await do_call('indy_replace_keys', c_wallet_handle, c_did, c_identity_json, replace_keys.cb) + res = (verkey.decode(), pk.decode()) + logger.debug("replace_keys: <<< res: %s", res) return res diff --git a/wrappers/python/tests/signus/test_create_and_store_my_did.py b/wrappers/python/tests/signus/test_create_and_store_my_did.py index 93773ff036..1641896137 100644 --- a/wrappers/python/tests/signus/test_create_and_store_my_did.py +++ b/wrappers/python/tests/signus/test_create_and_store_my_did.py @@ -1,7 +1,8 @@ -from indy import wallet, signus +import json -from ..utils import storage -from ..utils.wallet import create_and_open_wallet +from indy import IndyError +from indy import signus +from indy.error import ErrorCode import base58 import pytest @@ -9,19 +10,10 @@ logging.basicConfig(level=logging.DEBUG) - -@pytest.fixture(autouse=True) -def before_after_each(): - storage.cleanup() - yield - storage.cleanup() - - -@pytest.fixture -async def wallet_handle(): - handle = await create_and_open_wallet() - yield handle - await wallet.close_wallet(handle) +seed = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' +expected_verkey = 'CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW' +crypto_type = 'ed25519' +expected_did = 'NcYxiDXkpYi6ov5FcYDi1e' @pytest.mark.asyncio @@ -29,3 +21,57 @@ async def test_create_my_did_works_with_empty_json(wallet_handle): (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, "{}") assert len(base58.b58decode(did)) == 16 assert len(base58.b58decode(ver_key)) == 32 + + +@pytest.mark.asyncio +async def test_create_my_did_works_for_seed(wallet_handle): + did_info = {'seed': seed} + (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, json.dumps(did_info)) + assert expected_did == did + assert expected_verkey == ver_key + + +@pytest.mark.asyncio +async def test_create_my_did_works_as_cid(wallet_handle): + did_info = {'seed': seed, 'cid': True} + (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, json.dumps(did_info)) + assert expected_verkey == did + assert expected_verkey == ver_key + + +@pytest.mark.asyncio +async def test_create_my_did_works_for_passed_did(wallet_handle): + did_info = {'did': expected_did} + (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, json.dumps(did_info)) + assert expected_did == did + + +@pytest.mark.asyncio +async def test_create_my_did_works_for_correct_type(wallet_handle): + did_info = {'seed': seed, 'crypto_type': crypto_type} + (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, json.dumps(did_info)) + assert expected_did == did + assert expected_verkey == ver_key + + +@pytest.mark.asyncio +async def test_create_my_did_works_for_invalid_seed(wallet_handle): + with pytest.raises(IndyError) as e: + did_info = {'seed': 'aaaaaaaaaaa'} + await signus.create_and_store_my_did(wallet_handle, json.dumps(did_info)) + assert ErrorCode.CommonInvalidStructure == e.value.error_code + + +@pytest.mark.asyncio +async def test_create_my_did_works_for_invalid_crypto_type(wallet_handle): + with pytest.raises(IndyError) as e: + did_info = {'crypto_type': 'crypto_type'} + await signus.create_and_store_my_did(wallet_handle, json.dumps(did_info)) + assert ErrorCode.SignusUnknownCryptoError == e.value.error_code + + +@pytest.mark.asyncio +async def test_create_my_did_works_for_invalid_handle(wallet_handle): + with pytest.raises(IndyError) as e: + await signus.create_and_store_my_did(wallet_handle + 1, '{}') + assert ErrorCode.WalletInvalidHandle == e.value.error_code diff --git a/wrappers/python/tests/signus/test_replace_keys.py b/wrappers/python/tests/signus/test_replace_keys.py index a868425d73..7d234718d2 100644 --- a/wrappers/python/tests/signus/test_replace_keys.py +++ b/wrappers/python/tests/signus/test_replace_keys.py @@ -1,7 +1,6 @@ -from indy import wallet, signus - -from ..utils import storage -from ..utils.wallet import create_and_open_wallet +from indy import IndyError +from indy import signus +from indy.error import ErrorCode import pytest import logging @@ -9,22 +8,45 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.fixture(autouse=True) -def before_after_each(): - storage.cleanup() - yield - storage.cleanup() +@pytest.mark.asyncio +async def test_replace_keys_works(wallet_handle): + (did, ver_key, pk) = await signus.create_and_store_my_did(wallet_handle, "{}") + (new_ver_key, new_pk) = await signus.replace_keys(wallet_handle, did, "{}") + assert (new_ver_key != did) and (new_pk != pk) + + +@pytest.mark.asyncio +async def test_replace_keys_works_for_seed(wallet_handle): + (did, ver_key, pk) = await signus.create_and_store_my_did(wallet_handle, "{}") + (new_ver_key, new_pk) = await signus.replace_keys(wallet_handle, did, '{"seed": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}') + assert (new_ver_key != did) and (new_pk != pk) + assert 'CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW' == new_ver_key + +@pytest.mark.asyncio +async def test_replace_keys_works_for_correct_crypto_type(wallet_handle): + (did, ver_key, pk) = await signus.create_and_store_my_did(wallet_handle, "{}") + (new_ver_key, new_pk) = await signus.replace_keys(wallet_handle, did, '{"crypto_type": "ed25519"}') + assert (new_ver_key != did) and (new_pk != pk) -@pytest.fixture -async def wallet_handle(): - handle = await create_and_open_wallet() - yield handle - await wallet.close_wallet(handle) +@pytest.mark.asyncio +async def test_replace_keys_works_for_invalid_did(wallet_handle): + with pytest.raises(IndyError) as e: + await signus.replace_keys(wallet_handle, 'invalid_base58_string', "{}") + assert ErrorCode.CommonInvalidStructure == e.value.error_code @pytest.mark.asyncio async def test_replace_keys_works(wallet_handle): - (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, "{}") - (new_did, new_ver_key) = await signus.replace_keys(wallet_handle, did, "{}") - assert (new_did != did) and (new_ver_key != ver_key) \ No newline at end of file + with pytest.raises(IndyError) as e: + (did, _, _) = await signus.create_and_store_my_did(wallet_handle, "{}") + await signus.replace_keys(wallet_handle + 1, did, "{}") + assert ErrorCode.WalletInvalidHandle == e.value.error_code + + +@pytest.mark.asyncio +async def test_replace_keys_works_for_invalid_crypto_type(wallet_handle): + with pytest.raises(IndyError) as e: + (did, _, _) = await signus.create_and_store_my_did(wallet_handle, "{}") + await signus.replace_keys(wallet_handle, did, '{"crypto_type": "type"}') + assert ErrorCode.SignusUnknownCryptoError == e.value.error_code diff --git a/wrappers/python/tests/signus/test_sign.py b/wrappers/python/tests/signus/test_sign.py index 432d2badca..4c79f25356 100644 --- a/wrappers/python/tests/signus/test_sign.py +++ b/wrappers/python/tests/signus/test_sign.py @@ -1,7 +1,6 @@ -from indy import wallet, signus - -from ..utils import storage -from ..utils.wallet import create_and_open_wallet +from indy import IndyError +from indy import signus +from indy.error import ErrorCode import json import pytest @@ -10,20 +9,6 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.fixture(autouse=True) -def before_after_each(): - storage.cleanup() - yield - storage.cleanup() - - -@pytest.fixture -async def wallet_handle(): - handle = await create_and_open_wallet() - yield handle - await wallet.close_wallet(handle) - - @pytest.mark.asyncio async def test_sign_works(wallet_handle): (did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') @@ -42,3 +27,29 @@ async def test_sign_works(wallet_handle): result = json.loads(await signus.sign(wallet_handle, did, json.dumps(message))) assert result['signature'] == expected_signature + + +@pytest.mark.asyncio +async def test_sign_works_for_unknown_did(wallet_handle): + with pytest.raises(IndyError) as e: + message = {"reqId": 1496822211362017764} + await signus.sign(wallet_handle, '8wZcEriaNLNKtteJvx7f8i', json.dumps(message)) + assert ErrorCode.WalletNotFoundError == e.value.error_code + + +@pytest.mark.asyncio +async def test_sign_works_for_invalid_message_format(wallet_handle): + with pytest.raises(IndyError) as e: + (did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{}') + message = '"reqId":1495034346617224651' + await signus.sign(wallet_handle, did, message) + assert ErrorCode.CommonInvalidStructure == e.value.error_code + + +@pytest.mark.asyncio +async def test_sign_works_for_invalid_handle(wallet_handle): + with pytest.raises(IndyError) as e: + (did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{}') + message = {"reqId": 1496822211362017764} + await signus.sign(wallet_handle + 1, did, json.dumps(message)) + assert ErrorCode.WalletInvalidHandle == e.value.error_code diff --git a/wrappers/python/tests/signus/test_store_their_did.py b/wrappers/python/tests/signus/test_store_their_did.py index ad45f881aa..e6364b8c39 100644 --- a/wrappers/python/tests/signus/test_store_their_did.py +++ b/wrappers/python/tests/signus/test_store_their_did.py @@ -1,28 +1,54 @@ -from indy import wallet, signus - -from ..utils import storage -from ..utils.wallet import create_and_open_wallet +from indy import IndyError +from indy import signus import pytest import logging +from indy.error import ErrorCode + logging.basicConfig(level=logging.DEBUG) -@pytest.fixture(autouse=True) -def before_after_each(): - storage.cleanup() - yield - storage.cleanup() +@pytest.mark.asyncio +async def test_store_their_did_works(wallet_handle): + await signus.store_their_did(wallet_handle, '{"did":"8wZcEriaNLNKtteJvx7f8i"}') -@pytest.fixture -async def wallet_handle(): - handle = await create_and_open_wallet() - yield handle - await wallet.close_wallet(handle) +@pytest.mark.asyncio +async def test_store_their_did_works_for_invalid_json(wallet_handle): + with pytest.raises(IndyError) as e: + await signus.store_their_did(wallet_handle, '{"field":"value"}') + assert ErrorCode.CommonInvalidStructure == e.value.error_code @pytest.mark.asyncio -async def test_store_their_did_works(wallet_handle): - await signus.store_their_did(wallet_handle, '{"did":"8wZcEriaNLNKtteJvx7f8i"}') +async def test_store_their_did_works_for_invalid_handle(wallet_handle): + with pytest.raises(IndyError) as e: + await signus.store_their_did(wallet_handle + 1, '{"did":"8wZcEriaNLNKtteJvx7f8i"}') + assert ErrorCode.WalletInvalidHandle == e.value.error_code + + +@pytest.mark.asyncio +async def test_store_their_did_works_with_verkey(wallet_handle): + await signus.store_their_did(wallet_handle, '{"did":"8wZcEriaNLNKtteJvx7f8i",' + ' "verkey": "GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa"}') + + +@pytest.mark.asyncio +async def test_store_their_did_works_without_did(wallet_handle): + with pytest.raises(IndyError) as e: + await signus.store_their_did(wallet_handle, '{"verkey": "GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa"}') + assert ErrorCode.CommonInvalidStructure == e.value.error_code + + +@pytest.mark.asyncio +async def test_store_their_did_works_for_correct_crypto_type(wallet_handle): + await signus.store_their_did(wallet_handle, '{"did":"8wZcEriaNLNKtteJvx7f8i", "crypto_type": "ed25519"}') + + +@pytest.mark.asyncio +async def test_store_their_did_works_for_invalid_did(wallet_handle): + with pytest.raises(IndyError) as e: + await signus.store_their_did(wallet_handle, '{"did": "invalid_base58_string"}') + assert ErrorCode.CommonInvalidStructure == e.value.error_code + diff --git a/wrappers/python/tests/signus/test_verify_signature.py b/wrappers/python/tests/signus/test_verify_signature.py index e2b028caaa..0080e474f9 100644 --- a/wrappers/python/tests/signus/test_verify_signature.py +++ b/wrappers/python/tests/signus/test_verify_signature.py @@ -1,7 +1,12 @@ +import asyncio + +from indy import IndyError +from indy import ledger from indy import wallet, signus +from indy.error import ErrorCode -from ..utils import storage from ..utils.wallet import create_and_open_wallet +from ..utils.pool import create_and_open_pool_ledger import json import pytest @@ -10,23 +15,21 @@ logging.basicConfig(level=logging.DEBUG) -@pytest.fixture(autouse=True) -def before_after_each(): - storage.cleanup() - yield - storage.cleanup() +@pytest.fixture +async def new_did(wallet_handle, pool_handle): + (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"000000000000000000000000Trustee1"}') + (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"00000000000000000000000000000My1"}') -@pytest.fixture -async def wallet_handle(): - handle = await create_and_open_wallet() - yield handle - await wallet.close_wallet(handle) + nym_request = await ledger.build_nym_request(trustee_did, did, ver_key, None, None) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did, nym_request) + yield did @pytest.mark.asyncio -async def test_verify_signature_works(wallet_handle): - pool_handle = 1 +async def test_verify_works_for_verkey_cached_in_wallet(pool_handle, wallet_handle): (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') identity_json = { @@ -49,3 +52,133 @@ async def test_verify_signature_works(wallet_handle): valid = await signus.verify_signature(wallet_handle, pool_handle, did, json.dumps(message)) assert valid + + +@pytest.mark.asyncio +async def test_verify_works_for_get_verkey_from_ledger(pool_handle, wallet_handle, new_did): + identity_json = {"did": new_did} + + await signus.store_their_did(wallet_handle, json.dumps(identity_json)) + + message = '{"reqId":1496822211362017764,' \ + '"signature":"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai"}' + + valid = await signus.verify_signature(wallet_handle, pool_handle, new_did, message) + assert valid + + +@pytest.mark.asyncio +async def test_verify_works_for_expired_nym(pool_handle, cleanup_storage): + wallet_name = 'wallet2' + await wallet.create_wallet('pool_1', wallet_name, None, None, None) + wallet_handle = await wallet.open_wallet(wallet_name, '{"freshness_time":1}', None) + + (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"000000000000000000000000Trustee1"}') + + (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"00000000000000000000000000000My1"}') + + nym_request = await ledger.build_nym_request(trustee_did, did, ver_key, None, None) + await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did, nym_request) + + identity_json = { + "did": did, + 'verkey': ver_key + } + + await signus.store_their_did(wallet_handle, json.dumps(identity_json)) + + message = '{"reqId":1496822211362017764,' \ + '"signature":"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai"}' + + await asyncio.sleep(2) + + valid = await signus.verify_signature(wallet_handle, pool_handle, did, message) + assert valid + + wallet.close_wallet(wallet_handle) + + +@pytest.mark.asyncio +async def test_verify_works_for_invalid_wallet(pool_handle, wallet_handle, new_did): + with pytest.raises(IndyError) as e: + message = '{"reqId":1496822211362017764,' \ + '"signature":"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai"}' + + await signus.verify_signature(wallet_handle + 1, pool_handle, new_did, message) + assert ErrorCode.WalletInvalidHandle == e.value.error_code + + +@pytest.mark.asyncio +async def test_verify_works_for_invalid_pool(pool_handle, wallet_handle, new_did): + with pytest.raises(IndyError) as e: + message = '{"reqId":1496822211362017764,' \ + '"signature":"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai"}' + + await signus.verify_signature(wallet_handle, pool_handle + 1, new_did, message) + assert ErrorCode.PoolLedgerInvalidPoolHandle == e.value.error_code + + +@pytest.mark.asyncio +async def test_verify_works_for_other_signer(pool_handle, wallet_handle, new_did): + (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"000000000000000000000000Steward1"}') + identity_json = { + "did": did, + "verkey": ver_key + } + + await signus.store_their_did(wallet_handle, json.dumps(identity_json)) + + message = { + "reqId": 1496822211362017764, + "identifier": "GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL", + "operation": { + "type": "1", + "dest": "VsKV7grR1BUE29mG2Fm2kX", + "verkey": "GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa" + }, + "signature": "65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW" + } + + valid = await signus.verify_signature(wallet_handle, pool_handle, did, json.dumps(message)) + assert not valid + + +@pytest.mark.asyncio +async def test_verify_works_for_invalid_message_format(pool_handle, wallet_handle, new_did): + with pytest.raises(IndyError) as e: + message = '"reqId":1496822211362017764,' \ + '"signature":"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai"' + await signus.verify_signature(wallet_handle, pool_handle, new_did, message) + assert ErrorCode.CommonInvalidStructure == e.value.error_code + + +@pytest.mark.asyncio +async def test_verify_works_for_message_without_signature(pool_handle, wallet_handle, new_did): + with pytest.raises(IndyError) as e: + message = '{"reqId":1496822211362017764}' + await signus.verify_signature(wallet_handle, pool_handle, new_did, message) + assert ErrorCode.CommonInvalidStructure == e.value.error_code + + +@pytest.mark.asyncio +async def test_verify_works_for_get_nym_from_ledger_with_incompatible_wallet(cleanup_storage): + with pytest.raises(IndyError) as e: + pool_handle = await create_and_open_pool_ledger("pool_name") + wallet_handle = await create_and_open_wallet("other_pool_name") + + (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, + '{"seed":"00000000000000000000000000000My1"}') + + identity_json = {"did": did} + + await signus.store_their_did(wallet_handle, json.dumps(identity_json)) + + message = '{"reqId":1496822211362017764,' \ + '"signature":"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai"}' + + await signus.verify_signature(wallet_handle, pool_handle, did, message) + + assert ErrorCode.WalletIncompatiblePoolError == e.value.error_code \ No newline at end of file From 82b2f71afb4af47123d116fe47fdf07eed356666 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 26 Jul 2017 13:03:03 +0300 Subject: [PATCH 346/349] Updated demo tests --- wrappers/python/indy/signus.py | 2 ++ wrappers/python/tests/demo/agent.py | 4 ++-- wrappers/python/tests/demo/ledger.py | 4 ++-- wrappers/python/tests/demo/signus.py | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/wrappers/python/indy/signus.py b/wrappers/python/indy/signus.py index adb582d6b6..2df480cde6 100644 --- a/wrappers/python/indy/signus.py +++ b/wrappers/python/indy/signus.py @@ -165,6 +165,8 @@ async def sign(wallet_handle: int, c_msg, sign.cb) + res = res.decode() + logger.debug("sign: <<< res: %s", res) return res diff --git a/wrappers/python/tests/demo/agent.py b/wrappers/python/tests/demo/agent.py index 56f4fd1eed..69fb940db4 100644 --- a/wrappers/python/tests/demo/agent.py +++ b/wrappers/python/tests/demo/agent.py @@ -45,7 +45,7 @@ async def test_agent_demo_works(cleanup_storage): # 7. Prepare and send NYM transaction nym_txn_req = await ledger.build_nym_request(sender_did, listener_did, listener_verkey, None, None) - await ledger.sign_and_submit_request(pool_handle, sender_wallet_handle, sender_did, nym_txn_req.decode()) + await ledger.sign_and_submit_request(pool_handle, sender_wallet_handle, sender_did, nym_txn_req) # 8. Prepare and send GET_NYM request endpoint = "127.0.0.1:5555" @@ -58,7 +58,7 @@ async def test_agent_demo_works(cleanup_storage): # 8. Prepare and send Attrib request attrib_txn_req = await ledger.build_attrib_request(listener_did, listener_did, None, json.dumps(raw), None) - await ledger.sign_and_submit_request(pool_handle, listener_wallet_handle, listener_did, attrib_txn_req.decode()) + await ledger.sign_and_submit_request(pool_handle, listener_wallet_handle, listener_did, attrib_txn_req) # 8. Start listener on endpoint listener_handle = await agent.agent_listen(endpoint) diff --git a/wrappers/python/tests/demo/ledger.py b/wrappers/python/tests/demo/ledger.py index 25fda95b47..0ba0ba23f1 100644 --- a/wrappers/python/tests/demo/ledger.py +++ b/wrappers/python/tests/demo/ledger.py @@ -53,11 +53,11 @@ async def test_ledger_demo_works(cleanup_storage): # 8. Prepare and send NYM transaction nym_txn_req = await ledger.build_nym_request(their_did, my_did, None, None, None) - await ledger.sign_and_submit_request(pool_handle, their_wallet_handle, their_did, nym_txn_req.decode()) + await ledger.sign_and_submit_request(pool_handle, their_wallet_handle, their_did, nym_txn_req) # 9. Prepare and send GET_NYM request get_nym_txn_req = await ledger.build_get_nym_request(their_did, my_did) - get_nym_txn_resp = await ledger.submit_request(pool_handle, get_nym_txn_req.decode()) + get_nym_txn_resp = await ledger.submit_request(pool_handle, get_nym_txn_req) get_nym_txn_resp = json.loads(get_nym_txn_resp) diff --git a/wrappers/python/tests/demo/signus.py b/wrappers/python/tests/demo/signus.py index 243fa77ee9..2d23c9a01d 100644 --- a/wrappers/python/tests/demo/signus.py +++ b/wrappers/python/tests/demo/signus.py @@ -53,7 +53,7 @@ async def test_signus_demo_works(cleanup_storage): signed_msg = await signus.sign(their_wallet_handle, their_did, json.dumps(message)) # 7. Their sign message - assert await signus.verify_signature(my_wallet_handle, 1, their_did, signed_msg.decode()) + assert await signus.verify_signature(my_wallet_handle, 1, their_did, signed_msg) # 8. Close wallets await wallet.close_wallet(their_wallet_handle) From 4668cf2d38907dad6b3b9433a1b2d5ccc69c0220 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 26 Jul 2017 13:39:20 +0300 Subject: [PATCH 347/349] Refactored demo tests --- wrappers/python/tests/demo/agent.py | 48 ++++++++------------ wrappers/python/tests/demo/anoncreds.py | 58 +++++++++---------------- wrappers/python/tests/demo/ledger.py | 30 +++++-------- wrappers/python/tests/demo/signus.py | 33 +++++--------- 4 files changed, 60 insertions(+), 109 deletions(-) diff --git a/wrappers/python/tests/demo/agent.py b/wrappers/python/tests/demo/agent.py index 69fb940db4..363d12d4a8 100644 --- a/wrappers/python/tests/demo/agent.py +++ b/wrappers/python/tests/demo/agent.py @@ -2,39 +2,29 @@ from indy import ledger, signus, wallet, pool from indy.pool import open_pool_ledger -from tests.utils import storage - import pytest -import logging import json from tests.utils.pool import create_genesis_txn_file -logging.basicConfig(level=logging.DEBUG) - @pytest.mark.asyncio async def test_agent_demo_works(cleanup_storage): - pool_name = "pool" - listener_wallet_name = "listener_wallet" - sender_wallet_name = "sender_wallet" - # 1. Create ledger config from genesis txn file - file_name = pool_name + '.txn' - path = create_genesis_txn_file(file_name, None) + path = create_genesis_txn_file('pool_1.txn', None) pool_config = json.dumps({"genesis_txn": str(path)}) - await pool.create_pool_ledger_config(pool_name, pool_config) + await pool.create_pool_ledger_config('pool_1', pool_config) # 2. Open pool ledger - pool_handle = await open_pool_ledger(pool_name, None) + pool_handle = await open_pool_ledger('pool_1', None) # 3. Create and Open Listener Wallet. Gets wallet handle - await wallet.create_wallet(pool_name, listener_wallet_name, None, None, None) - listener_wallet_handle = await wallet.open_wallet(listener_wallet_name, None, None) + await wallet.create_wallet('pool_1', 'listener_wallet', None, None, None) + listener_wallet_handle = await wallet.open_wallet('listener_wallet', None, None) # 4. Create and Open Sender Wallet. Gets wallet handle - await wallet.create_wallet(pool_name, sender_wallet_name, None, None, None) - sender_wallet_handle = await wallet.open_wallet(sender_wallet_name, None, None) + await wallet.create_wallet('pool_1', 'sender_wallet', None, None, None) + sender_wallet_handle = await wallet.open_wallet('sender_wallet', None, None) # 5. Create Listener DID (listener_did, listener_verkey, listener_pk) = await signus.create_and_store_my_did(listener_wallet_handle, "{}") @@ -47,38 +37,36 @@ async def test_agent_demo_works(cleanup_storage): nym_txn_req = await ledger.build_nym_request(sender_did, listener_did, listener_verkey, None, None) await ledger.sign_and_submit_request(pool_handle, sender_wallet_handle, sender_did, nym_txn_req) - # 8. Prepare and send GET_NYM request - endpoint = "127.0.0.1:5555" - raw = { + # 8. Prepare and send Attrib request + raw = json.dumps({ "endpoint": { - "ha": endpoint, + "ha": "127.0.0.1:5555", "verkey": listener_pk } - } + }) - # 8. Prepare and send Attrib request - attrib_txn_req = await ledger.build_attrib_request(listener_did, listener_did, None, json.dumps(raw), None) + attrib_txn_req = await ledger.build_attrib_request(listener_did, listener_did, None, raw, None) await ledger.sign_and_submit_request(pool_handle, listener_wallet_handle, listener_did, attrib_txn_req) - # 8. Start listener on endpoint - listener_handle = await agent.agent_listen(endpoint) + # 9. Start listener on endpoint + listener_handle = await agent.agent_listen("127.0.0.1:5555") - # 9. Allow listener accept incoming connection for specific DID (listener_did) + # 10. Allow listener accept incoming connection for specific DID (listener_did) await agent.agent_add_identity(listener_handle, pool_handle, listener_wallet_handle, listener_did) - # 10. Initiate connection from sender to listener + # 11. Initiate connection from sender to listener connection_handle = await agent.agent_connect(pool_handle, sender_wallet_handle, sender_did, listener_did) event = await agent.agent_wait_for_event([listener_handle]) inc_con_handle = event.connection_handle - # 11. Send test message from sender to listener + # 12. Send test message from sender to listener message = 'msg_from_sender_to_listener' await agent.agent_send(connection_handle, message) message_event = await agent.agent_wait_for_event([listener_handle, inc_con_handle]) # type: agent.MessageEvent assert message_event.message == message - # 12. Close connection, listener, wallets, pool + # 13. Close connection, listener, wallets, pool await agent.agent_close_listener(listener_handle) await agent.agent_close_connection(connection_handle) diff --git a/wrappers/python/tests/demo/anoncreds.py b/wrappers/python/tests/demo/anoncreds.py index aa4f5727ac..8630ca9881 100644 --- a/wrappers/python/tests/demo/anoncreds.py +++ b/wrappers/python/tests/demo/anoncreds.py @@ -1,27 +1,18 @@ from indy import anoncreds, wallet -from tests.utils import storage - import pytest -import logging import json -logging.basicConfig(level=logging.DEBUG) - @pytest.mark.asyncio async def test_anoncreds_demo_works(cleanup_storage): - pool_name = "anoncreds_demo_pool" - wallet_name = "anoncreds_demo_wallet" - # 1. Create My Wallet and Get Wallet Handle - await wallet.create_wallet(pool_name, wallet_name, None, None, None) - wallet_handle = await wallet.open_wallet(wallet_name, None, None) + await wallet.create_wallet('pool_1', 'wallet_1', None, None, None) + wallet_handle = await wallet.open_wallet('wallet_1', None, None) # 2. Issuer create Claim Definition for Schema - schema_seq_no = 1 schema = { - 'seqNo': schema_seq_no, + 'seqNo': 1, 'data': { 'name': 'gvt', 'version': '1.0', @@ -29,75 +20,68 @@ async def test_anoncreds_demo_works(cleanup_storage): } } schema_json = json.dumps(schema) - issuer_did = 'NcYxiDXkpYi6ov5FcYDi1e' claim_def_json = \ - await anoncreds.issuer_create_and_store_claim_def(wallet_handle, issuer_did, schema_json, 'CL', False) + await anoncreds.issuer_create_and_store_claim_def(wallet_handle, + 'NcYxiDXkpYi6ov5FcYDi1e', schema_json, 'CL', False) # 3. Prover create Master Secret - master_secret_name = 'master_secret' - await anoncreds.prover_create_master_secret(wallet_handle, master_secret_name) + await anoncreds.prover_create_master_secret(wallet_handle, 'master_secret') # 4. Prover create Claim Request - prover_did = 'BzfFCYk' - claim_offer = { - 'issuer_did': issuer_did, - 'schema_seq_no': schema_seq_no - } + claim_offer_json = json.dumps({ + 'issuer_did': 'NcYxiDXkpYi6ov5FcYDi1e', + 'schema_seq_no': 1 + }) - claim_req_json = await anoncreds.prover_create_and_store_claim_req(wallet_handle, prover_did, - json.dumps(claim_offer), - claim_def_json, master_secret_name) + claim_req_json = await anoncreds.prover_create_and_store_claim_req(wallet_handle, 'BzfFCYk', claim_offer_json, + claim_def_json, 'master_secret') # 5. Issuer create Claim for Claim Request - claim = { + claim_json = json.dumps({ 'sex': ['male', '5944657099558967239210949258394887428692050081607692519917050011144233115103'], 'name': ['Alex', '1139481716457488690172217916278103335'], 'height': ['175', '175'], 'age': ['28', '28'] - } + }) - (_, claim_json) = await anoncreds.issuer_create_claim(wallet_handle, claim_req_json, json.dumps(claim), -1, -1) + (_, claim_json) = await anoncreds.issuer_create_claim(wallet_handle, claim_req_json, claim_json, -1, -1) # 6. Prover process and store Claim await anoncreds.prover_store_claim(wallet_handle, claim_json) # 7. Prover gets Claims for Proof Request - proof_req = { + proof_req_json = json.dumps({ 'nonce': '123432421212', 'name': 'proof_req_1', 'version': '0.1', 'requested_attrs': { - 'attr1_uuid': {'schema_seq_no': schema_seq_no, 'name': 'name'} + 'attr1_uuid': {'schema_seq_no': 1, 'name': 'name'} }, 'requested_predicates': { 'predicate1_uuid': {'attr_name': 'age', 'p_type': 'GE', 'value': 18} } - } - proof_req_json = json.dumps(proof_req) + }) claim_for_proof_json = await anoncreds.prover_get_claims_for_proof_req(wallet_handle, proof_req_json) claims_for_proof = json.loads(claim_for_proof_json) claim_for_attr1 = claims_for_proof['attrs']['attr1_uuid'] - assert 1 == len(claim_for_attr1) - claim_uuid = claim_for_attr1[0]['claim_uuid'] # 8. Prover create Proof for Proof Request - requested_claims = { + requested_claims_json = json.dumps({ 'self_attested_attributes': {}, 'requested_attrs': {'attr1_uuid': [claim_uuid, True]}, 'requested_predicates': {'predicate1_uuid': claim_uuid} - } - requested_claims_json = json.dumps(requested_claims) + }) schemas_json = json.dumps({claim_uuid: schema}) claim_defs_json = json.dumps({claim_uuid: json.loads(claim_def_json)}) revoc_regs_json = json.dumps({}) proof_json = await anoncreds.prover_create_proof(wallet_handle, proof_req_json, requested_claims_json, schemas_json, - master_secret_name, claim_defs_json, revoc_regs_json) + 'master_secret', claim_defs_json, revoc_regs_json) proof = json.loads(proof_json) assert 'Alex' == proof['requested_proof']['revealed_attrs']['attr1_uuid'][1] diff --git a/wrappers/python/tests/demo/ledger.py b/wrappers/python/tests/demo/ledger.py index 0ba0ba23f1..0bde12efb3 100644 --- a/wrappers/python/tests/demo/ledger.py +++ b/wrappers/python/tests/demo/ledger.py @@ -1,39 +1,29 @@ from indy import ledger, signus, wallet, pool from indy.pool import open_pool_ledger -from tests.utils import storage - import pytest -import logging import json from tests.utils.pool import create_genesis_txn_file -logging.basicConfig(level=logging.DEBUG) - @pytest.mark.asyncio async def test_ledger_demo_works(cleanup_storage): - pool_name = "pool" - my_wallet_name = "my_wallet" - their_wallet_name = "their_wallet" - # 1. Create ledger config from genesis txn file - file_name = pool_name + '.txn' - path = create_genesis_txn_file(file_name, None) + path = create_genesis_txn_file('pool_1.txn', None) pool_config = json.dumps({"genesis_txn": str(path)}) - await pool.create_pool_ledger_config(pool_name, pool_config) + await pool.create_pool_ledger_config('pool_1', pool_config) # 2. Open pool ledger - pool_handle = await open_pool_ledger(pool_name, None) + pool_handle = await open_pool_ledger('pool_1', None) # 3. Create My Wallet and Get Wallet Handle - await wallet.create_wallet(pool_name, my_wallet_name, None, None, None) - my_wallet_handle = await wallet.open_wallet(my_wallet_name, None, None) + await wallet.create_wallet('pool_1', 'my_wallet', None, None, None) + my_wallet_handle = await wallet.open_wallet('my_wallet', None, None) # 4. Create Their Wallet and Get Wallet Handle - await wallet.create_wallet(pool_name, their_wallet_name, None, None, None) - their_wallet_handle = await wallet.open_wallet(their_wallet_name, None, None) + await wallet.create_wallet('pool_1', 'their_wallet', None, None, None) + their_wallet_handle = await wallet.open_wallet('their_wallet', None, None) # 5. Create My DID (my_did, my_verkey, my_pk) = await signus.create_and_store_my_did(my_wallet_handle, "{}") @@ -43,13 +33,13 @@ async def test_ledger_demo_works(cleanup_storage): await signus.create_and_store_my_did(their_wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') # 7. Store Their DID - their_identity = { + their_identity_json = json.dumps({ 'did': their_did, 'pk': their_pk, 'verkey': their_verkey - } + }) - await signus.store_their_did(my_wallet_handle, json.dumps(their_identity)) + await signus.store_their_did(my_wallet_handle, their_identity_json) # 8. Prepare and send NYM transaction nym_txn_req = await ledger.build_nym_request(their_did, my_did, None, None, None) diff --git a/wrappers/python/tests/demo/signus.py b/wrappers/python/tests/demo/signus.py index 2d23c9a01d..0a34aedffd 100644 --- a/wrappers/python/tests/demo/signus.py +++ b/wrappers/python/tests/demo/signus.py @@ -1,28 +1,18 @@ from indy import signus, wallet -from tests.utils import storage - import pytest -import logging import json -logging.basicConfig(level=logging.DEBUG) - - @pytest.mark.asyncio async def test_signus_demo_works(cleanup_storage): - pool_name = "create" - my_wallet_name = "my_wallet" - their_wallet_name = "their_wallet" - # 1. Create My Wallet and Get Wallet Handle - await wallet.create_wallet(pool_name, my_wallet_name, None, None, None) - my_wallet_handle = await wallet.open_wallet(my_wallet_name, None, None) + await wallet.create_wallet('pool_1', 'my_wallet', None, None, None) + my_wallet_handle = await wallet.open_wallet('my_wallet', None, None) # 2. Create Their Wallet and Get Wallet Handle - await wallet.create_wallet(pool_name, their_wallet_name, None, None, None) - their_wallet_handle = await wallet.open_wallet(their_wallet_name, None, None) + await wallet.create_wallet('pool_1', 'their_wallet', None, None, None) + their_wallet_handle = await wallet.open_wallet('their_wallet', None, None) # 3. Create My DID await signus.create_and_store_my_did(my_wallet_handle, "{}") @@ -32,30 +22,29 @@ async def test_signus_demo_works(cleanup_storage): await signus.create_and_store_my_did(their_wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') # 5. Store Their DID - their_identity = { + their_identity_json = json.dumps({ 'did': their_did, 'pk': their_pk, 'verkey': their_verkey - } + }) - await signus.store_their_did(my_wallet_handle, json.dumps(their_identity)) + await signus.store_their_did(my_wallet_handle, their_identity_json) # 6. Their sign message - message = { + message = json.dumps({ "reqId": 1495034346617224651, "identifier": "GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL", "operation": { "type": "1", "dest": "4efZu2SXufS556yss7W5k6Po37jt4371RM4whbPKBKdB" } - } + }) - signed_msg = await signus.sign(their_wallet_handle, their_did, json.dumps(message)) + signed_msg = await signus.sign(their_wallet_handle, their_did, message) # 7. Their sign message assert await signus.verify_signature(my_wallet_handle, 1, their_did, signed_msg) # 8. Close wallets await wallet.close_wallet(their_wallet_handle) - await wallet.close_wallet(my_wallet_handle) - + await wallet.close_wallet(my_wallet_handle) \ No newline at end of file From 17c7664592de0397363b9c3801f19c59a744436e Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 26 Jul 2017 13:49:33 +0300 Subject: [PATCH 348/349] Refactored wallet tests --- .../python/tests/wallet/test_close_wallet.py | 17 +++------ .../python/tests/wallet/test_create_wallet.py | 5 --- .../python/tests/wallet/test_delete_wallet.py | 38 +++++++------------ .../python/tests/wallet/test_open_wallet.py | 9 +---- 4 files changed, 21 insertions(+), 48 deletions(-) diff --git a/wrappers/python/tests/wallet/test_close_wallet.py b/wrappers/python/tests/wallet/test_close_wallet.py index e20d58bb73..77df5e591e 100644 --- a/wrappers/python/tests/wallet/test_close_wallet.py +++ b/wrappers/python/tests/wallet/test_close_wallet.py @@ -2,33 +2,26 @@ from indy import wallet from indy.error import ErrorCode -from ..utils import storage - import pytest -import logging - -logging.basicConfig(level=logging.DEBUG) @pytest.mark.asyncio async def test_close_wallet_works(cleanup_storage): - wallet_name = 'wallet1' - await wallet.create_wallet('pool1', wallet_name, None, None, None) + await wallet.create_wallet('pool1', 'wallet_1', None, None, None) - wallet_handle = await wallet.open_wallet(wallet_name, None, None) + wallet_handle = await wallet.open_wallet('wallet_1', None, None) await wallet.close_wallet(wallet_handle) - wallet_handle = await wallet.open_wallet(wallet_name, None, None) + wallet_handle = await wallet.open_wallet('wallet_1', None, None) await wallet.close_wallet(wallet_handle) @pytest.mark.asyncio async def test_close_wallet_works_for_twice(cleanup_storage): with pytest.raises(IndyError) as e: - wallet_name = 'wallet_for_twice' - await wallet.create_wallet('pool1', wallet_name, None, None, None) + await wallet.create_wallet('pool1', 'wallet_for_twice', None, None, None) - wallet_handle = await wallet.open_wallet(wallet_name, None, None) + wallet_handle = await wallet.open_wallet('wallet_for_twice', None, None) await wallet.close_wallet(wallet_handle) await wallet.close_wallet(wallet_handle) diff --git a/wrappers/python/tests/wallet/test_create_wallet.py b/wrappers/python/tests/wallet/test_create_wallet.py index 5eaa885e05..924fa3cca1 100644 --- a/wrappers/python/tests/wallet/test_create_wallet.py +++ b/wrappers/python/tests/wallet/test_create_wallet.py @@ -2,12 +2,7 @@ from indy import wallet from indy.error import ErrorCode -from ..utils import storage - import pytest -import logging - -logging.basicConfig(level=logging.DEBUG) @pytest.mark.asyncio diff --git a/wrappers/python/tests/wallet/test_delete_wallet.py b/wrappers/python/tests/wallet/test_delete_wallet.py index 94f558c6e8..ff0c5bdbe1 100644 --- a/wrappers/python/tests/wallet/test_delete_wallet.py +++ b/wrappers/python/tests/wallet/test_delete_wallet.py @@ -2,55 +2,45 @@ from indy import wallet from indy.error import ErrorCode -from ..utils import storage - import pytest -import logging - -logging.basicConfig(level=logging.DEBUG) @pytest.mark.asyncio async def test_delete_wallet_works(cleanup_storage): - wallet_name = 'wallet1' - await wallet.create_wallet('pool1', wallet_name, None, None, None) - await wallet.delete_wallet(wallet_name, None) - await wallet.create_wallet('pool1', wallet_name, None, None, None) + await wallet.create_wallet('pool1', 'wallet_1', None, None, None) + await wallet.delete_wallet('wallet_1', None) + await wallet.create_wallet('pool1', 'wallet_1', None, None, None) @pytest.mark.asyncio async def test_delete_wallet_works_for_closed(cleanup_storage): - wallet_name = 'wallet2' - await wallet.create_wallet('pool1', wallet_name, None, None, None) - wallet_handle = await wallet.open_wallet(wallet_name, None, None) + await wallet.create_wallet('pool1', 'wallet_1', None, None, None) + wallet_handle = await wallet.open_wallet('wallet_1', None, None) await wallet.close_wallet(wallet_handle) - await wallet.delete_wallet(wallet_name, None) - await wallet.create_wallet('pool1', wallet_name, None, None, None) + await wallet.delete_wallet('wallet_1', None) + await wallet.create_wallet('pool1', 'wallet_1', None, None, None) @pytest.mark.skip(reason="There is BUG in indy-sdk") async def test_delete_wallet_works_for_opened(cleanup_storage): with pytest.raises(IndyError) as e: - wallet_name = 'wallet_for_opened' - await wallet.create_wallet('pool1', wallet_name, None, None, None) - await wallet.open_wallet(wallet_name, None, None) - await wallet.delete_wallet(wallet_name, None) + await wallet.create_wallet('pool1', 'wallet_for_opened', None, None, None) + await wallet.open_wallet('wallet_for_opened', None, None) + await wallet.delete_wallet('wallet_for_opened', None) assert ErrorCode.CommonIOError == e.value.error_code @pytest.mark.asyncio async def test_delete_wallet_works_for_twice(cleanup_storage): with pytest.raises(IndyError) as e: - wallet_name = 'wallet_for_twice' - await wallet.create_wallet('pool1', wallet_name, None, None, None) - await wallet.delete_wallet(wallet_name, None) - await wallet.delete_wallet(wallet_name, None) + await wallet.create_wallet('pool1', 'wallet_for_twice', None, None, None) + await wallet.delete_wallet('wallet_for_twice', None) + await wallet.delete_wallet('wallet_for_twice', None) assert ErrorCode.CommonIOError == e.value.error_code @pytest.mark.asyncio async def test_delete_wallet_works_for_not_created(cleanup_storage): with pytest.raises(IndyError) as e: - wallet_name = 'wallet_not_created' - await wallet.delete_wallet(wallet_name, None) + await wallet.delete_wallet('wallet_not_created', None) assert ErrorCode.CommonIOError == e.value.error_code \ No newline at end of file diff --git a/wrappers/python/tests/wallet/test_open_wallet.py b/wrappers/python/tests/wallet/test_open_wallet.py index 5238320e98..72e72738a7 100644 --- a/wrappers/python/tests/wallet/test_open_wallet.py +++ b/wrappers/python/tests/wallet/test_open_wallet.py @@ -2,12 +2,7 @@ from indy import wallet from indy.error import ErrorCode -from ..utils import storage - import pytest -import logging - -logging.basicConfig(level=logging.DEBUG) @pytest.mark.asyncio @@ -21,8 +16,8 @@ async def test_open_wallet_works(cleanup_storage): @pytest.mark.asyncio async def test_open_wallet_works_for_config(cleanup_storage): - await wallet.create_wallet('pool1', 'wallet2', None, None, None) - wallet_handle = await wallet.open_wallet('wallet2', '{"freshness_time":1000}', None) + await wallet.create_wallet('pool1', 'wallet1', None, None, None) + wallet_handle = await wallet.open_wallet('wallet1', '{"freshness_time":1000}', None) assert wallet_handle is not None await wallet.close_wallet(wallet_handle) From 638d188c128f9c3f4327617e08dcff06983058c5 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 26 Jul 2017 13:55:18 +0300 Subject: [PATCH 349/349] Refactored signus tests --- .../signus/test_create_and_store_my_did.py | 22 +++---- .../python/tests/signus/test_replace_keys.py | 3 - wrappers/python/tests/signus/test_sign.py | 20 +++---- .../tests/signus/test_store_their_did.py | 3 - .../tests/signus/test_verify_signature.py | 60 ++++++------------- 5 files changed, 32 insertions(+), 76 deletions(-) diff --git a/wrappers/python/tests/signus/test_create_and_store_my_did.py b/wrappers/python/tests/signus/test_create_and_store_my_did.py index 1641896137..af0214cb2a 100644 --- a/wrappers/python/tests/signus/test_create_and_store_my_did.py +++ b/wrappers/python/tests/signus/test_create_and_store_my_did.py @@ -6,9 +6,6 @@ import base58 import pytest -import logging - -logging.basicConfig(level=logging.DEBUG) seed = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' expected_verkey = 'CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW' @@ -25,31 +22,28 @@ async def test_create_my_did_works_with_empty_json(wallet_handle): @pytest.mark.asyncio async def test_create_my_did_works_for_seed(wallet_handle): - did_info = {'seed': seed} - (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, json.dumps(did_info)) + (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, json.dumps({'seed': seed})) assert expected_did == did assert expected_verkey == ver_key @pytest.mark.asyncio async def test_create_my_did_works_as_cid(wallet_handle): - did_info = {'seed': seed, 'cid': True} - (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, json.dumps(did_info)) + (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, json.dumps({'seed': seed, 'cid': True})) assert expected_verkey == did assert expected_verkey == ver_key @pytest.mark.asyncio async def test_create_my_did_works_for_passed_did(wallet_handle): - did_info = {'did': expected_did} - (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, json.dumps(did_info)) + (did, _, _) = await signus.create_and_store_my_did(wallet_handle, json.dumps({'did': expected_did})) assert expected_did == did @pytest.mark.asyncio async def test_create_my_did_works_for_correct_type(wallet_handle): - did_info = {'seed': seed, 'crypto_type': crypto_type} - (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, json.dumps(did_info)) + (did, ver_key, _) = \ + await signus.create_and_store_my_did(wallet_handle, json.dumps({'seed': seed, 'crypto_type': crypto_type})) assert expected_did == did assert expected_verkey == ver_key @@ -57,16 +51,14 @@ async def test_create_my_did_works_for_correct_type(wallet_handle): @pytest.mark.asyncio async def test_create_my_did_works_for_invalid_seed(wallet_handle): with pytest.raises(IndyError) as e: - did_info = {'seed': 'aaaaaaaaaaa'} - await signus.create_and_store_my_did(wallet_handle, json.dumps(did_info)) + await signus.create_and_store_my_did(wallet_handle, json.dumps({'seed': 'aaaaaaaaaaa'})) assert ErrorCode.CommonInvalidStructure == e.value.error_code @pytest.mark.asyncio async def test_create_my_did_works_for_invalid_crypto_type(wallet_handle): with pytest.raises(IndyError) as e: - did_info = {'crypto_type': 'crypto_type'} - await signus.create_and_store_my_did(wallet_handle, json.dumps(did_info)) + await signus.create_and_store_my_did(wallet_handle, json.dumps({'crypto_type': 'crypto_type'})) assert ErrorCode.SignusUnknownCryptoError == e.value.error_code diff --git a/wrappers/python/tests/signus/test_replace_keys.py b/wrappers/python/tests/signus/test_replace_keys.py index 7d234718d2..5a52fad89c 100644 --- a/wrappers/python/tests/signus/test_replace_keys.py +++ b/wrappers/python/tests/signus/test_replace_keys.py @@ -3,9 +3,6 @@ from indy.error import ErrorCode import pytest -import logging - -logging.basicConfig(level=logging.DEBUG) @pytest.mark.asyncio diff --git a/wrappers/python/tests/signus/test_sign.py b/wrappers/python/tests/signus/test_sign.py index 4c79f25356..c6270964b9 100644 --- a/wrappers/python/tests/signus/test_sign.py +++ b/wrappers/python/tests/signus/test_sign.py @@ -4,16 +4,13 @@ import json import pytest -import logging - -logging.basicConfig(level=logging.DEBUG) @pytest.mark.asyncio async def test_sign_works(wallet_handle): (did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') - message = { + message = json.dumps({ "reqId": 1496822211362017764, "identifier": "GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL", "operation": { @@ -21,19 +18,18 @@ async def test_sign_works(wallet_handle): "dest": "VsKV7grR1BUE29mG2Fm2kX", "verkey": "GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa" } - } + }) expected_signature = "65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW" - result = json.loads(await signus.sign(wallet_handle, did, json.dumps(message))) - assert result['signature'] == expected_signature + signed_msg = json.loads(await signus.sign(wallet_handle, did, message)) + assert signed_msg['signature'] == expected_signature @pytest.mark.asyncio async def test_sign_works_for_unknown_did(wallet_handle): with pytest.raises(IndyError) as e: - message = {"reqId": 1496822211362017764} - await signus.sign(wallet_handle, '8wZcEriaNLNKtteJvx7f8i', json.dumps(message)) + await signus.sign(wallet_handle, '8wZcEriaNLNKtteJvx7f8i', json.dumps({"reqId": 1496822211362017764})) assert ErrorCode.WalletNotFoundError == e.value.error_code @@ -41,8 +37,7 @@ async def test_sign_works_for_unknown_did(wallet_handle): async def test_sign_works_for_invalid_message_format(wallet_handle): with pytest.raises(IndyError) as e: (did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{}') - message = '"reqId":1495034346617224651' - await signus.sign(wallet_handle, did, message) + await signus.sign(wallet_handle, did, '"reqId":1495034346617224651') assert ErrorCode.CommonInvalidStructure == e.value.error_code @@ -50,6 +45,5 @@ async def test_sign_works_for_invalid_message_format(wallet_handle): async def test_sign_works_for_invalid_handle(wallet_handle): with pytest.raises(IndyError) as e: (did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{}') - message = {"reqId": 1496822211362017764} - await signus.sign(wallet_handle + 1, did, json.dumps(message)) + await signus.sign(wallet_handle + 1, did, json.dumps({"reqId": 1496822211362017764})) assert ErrorCode.WalletInvalidHandle == e.value.error_code diff --git a/wrappers/python/tests/signus/test_store_their_did.py b/wrappers/python/tests/signus/test_store_their_did.py index e6364b8c39..2505e44474 100644 --- a/wrappers/python/tests/signus/test_store_their_did.py +++ b/wrappers/python/tests/signus/test_store_their_did.py @@ -2,12 +2,9 @@ from indy import signus import pytest -import logging from indy.error import ErrorCode -logging.basicConfig(level=logging.DEBUG) - @pytest.mark.asyncio async def test_store_their_did_works(wallet_handle): diff --git a/wrappers/python/tests/signus/test_verify_signature.py b/wrappers/python/tests/signus/test_verify_signature.py index 0080e474f9..62a199bcba 100644 --- a/wrappers/python/tests/signus/test_verify_signature.py +++ b/wrappers/python/tests/signus/test_verify_signature.py @@ -10,9 +10,6 @@ import json import pytest -import logging - -logging.basicConfig(level=logging.DEBUG) @pytest.fixture @@ -32,14 +29,10 @@ async def new_did(wallet_handle, pool_handle): async def test_verify_works_for_verkey_cached_in_wallet(pool_handle, wallet_handle): (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') - identity_json = { - "did": did, - "verkey": ver_key - } - await signus.store_their_did(wallet_handle, json.dumps(identity_json)) + await signus.store_their_did(wallet_handle, json.dumps({"did": did, "verkey": ver_key})) - message = { + message = json.dumps({ "reqId": 1496822211362017764, "identifier": "GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL", "operation": { @@ -48,17 +41,15 @@ async def test_verify_works_for_verkey_cached_in_wallet(pool_handle, wallet_hand "verkey": "GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa" }, "signature": "65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW" - } + }) - valid = await signus.verify_signature(wallet_handle, pool_handle, did, json.dumps(message)) + valid = await signus.verify_signature(wallet_handle, pool_handle, did, message) assert valid @pytest.mark.asyncio async def test_verify_works_for_get_verkey_from_ledger(pool_handle, wallet_handle, new_did): - identity_json = {"did": new_did} - - await signus.store_their_did(wallet_handle, json.dumps(identity_json)) + await signus.store_their_did(wallet_handle, json.dumps({"did": new_did})) message = '{"reqId":1496822211362017764,' \ '"signature":"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai"}' @@ -69,9 +60,8 @@ async def test_verify_works_for_get_verkey_from_ledger(pool_handle, wallet_handl @pytest.mark.asyncio async def test_verify_works_for_expired_nym(pool_handle, cleanup_storage): - wallet_name = 'wallet2' - await wallet.create_wallet('pool_1', wallet_name, None, None, None) - wallet_handle = await wallet.open_wallet(wallet_name, '{"freshness_time":1}', None) + await wallet.create_wallet('pool_1', 'wallet2', None, None, None) + wallet_handle = await wallet.open_wallet('wallet2', '{"freshness_time":1}', None) (trustee_did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Trustee1"}') @@ -82,12 +72,7 @@ async def test_verify_works_for_expired_nym(pool_handle, cleanup_storage): nym_request = await ledger.build_nym_request(trustee_did, did, ver_key, None, None) await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did, nym_request) - identity_json = { - "did": did, - 'verkey': ver_key - } - - await signus.store_their_did(wallet_handle, json.dumps(identity_json)) + await signus.store_their_did(wallet_handle, json.dumps({"did": did, 'verkey': ver_key})) message = '{"reqId":1496822211362017764,' \ '"signature":"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai"}' @@ -104,8 +89,7 @@ async def test_verify_works_for_expired_nym(pool_handle, cleanup_storage): async def test_verify_works_for_invalid_wallet(pool_handle, wallet_handle, new_did): with pytest.raises(IndyError) as e: message = '{"reqId":1496822211362017764,' \ - '"signature":"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai"}' - + '"signature":"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai"}' await signus.verify_signature(wallet_handle + 1, pool_handle, new_did, message) assert ErrorCode.WalletInvalidHandle == e.value.error_code @@ -114,8 +98,7 @@ async def test_verify_works_for_invalid_wallet(pool_handle, wallet_handle, new_d async def test_verify_works_for_invalid_pool(pool_handle, wallet_handle, new_did): with pytest.raises(IndyError) as e: message = '{"reqId":1496822211362017764,' \ - '"signature":"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai"}' - + '"signature":"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai"}' await signus.verify_signature(wallet_handle, pool_handle + 1, new_did, message) assert ErrorCode.PoolLedgerInvalidPoolHandle == e.value.error_code @@ -124,14 +107,10 @@ async def test_verify_works_for_invalid_pool(pool_handle, wallet_handle, new_did async def test_verify_works_for_other_signer(pool_handle, wallet_handle, new_did): (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"000000000000000000000000Steward1"}') - identity_json = { - "did": did, - "verkey": ver_key - } - await signus.store_their_did(wallet_handle, json.dumps(identity_json)) + await signus.store_their_did(wallet_handle, json.dumps({"did": did, "verkey": ver_key})) - message = { + message = json.dumps({ "reqId": 1496822211362017764, "identifier": "GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL", "operation": { @@ -140,9 +119,9 @@ async def test_verify_works_for_other_signer(pool_handle, wallet_handle, new_did "verkey": "GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa" }, "signature": "65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW" - } + }) - valid = await signus.verify_signature(wallet_handle, pool_handle, did, json.dumps(message)) + valid = await signus.verify_signature(wallet_handle, pool_handle, did, message) assert not valid @@ -158,8 +137,7 @@ async def test_verify_works_for_invalid_message_format(pool_handle, wallet_handl @pytest.mark.asyncio async def test_verify_works_for_message_without_signature(pool_handle, wallet_handle, new_did): with pytest.raises(IndyError) as e: - message = '{"reqId":1496822211362017764}' - await signus.verify_signature(wallet_handle, pool_handle, new_did, message) + await signus.verify_signature(wallet_handle, pool_handle, new_did, '{"reqId":1496822211362017764}') assert ErrorCode.CommonInvalidStructure == e.value.error_code @@ -172,13 +150,11 @@ async def test_verify_works_for_get_nym_from_ledger_with_incompatible_wallet(cle (did, ver_key, _) = await signus.create_and_store_my_did(wallet_handle, '{"seed":"00000000000000000000000000000My1"}') - identity_json = {"did": did} - - await signus.store_their_did(wallet_handle, json.dumps(identity_json)) + await signus.store_their_did(wallet_handle, json.dumps({"did": did})) message = '{"reqId":1496822211362017764,' \ - '"signature":"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai"}' + '"signature":"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai"}' await signus.verify_signature(wallet_handle, pool_handle, did, message) - assert ErrorCode.WalletIncompatiblePoolError == e.value.error_code \ No newline at end of file + assert ErrorCode.WalletIncompatiblePoolError == e.value.error_code