Skip to content

Commit

Permalink
refactor(indy-testnet): improve setup and tools of indy-testnet
Browse files Browse the repository at this point in the history
req_discounted_cartrade.py - reuse proof when possible, add new flags to
force new proof generation and to ignore discounted-cartrade request to
simplify tests, put this tool into container. testsock.js - fix
formatting, add missing package, use new validator address (nginx).
Refactor all indy-testnet docerfiles according to docker best practices,
reduce container size and complexity. Use nginx as a proxy to validator
(as documented).

Closes: hyperledger-cacti#1812
Signed-off-by: Michal Bajer <[email protected]>
  • Loading branch information
outSH authored and petermetz committed Feb 9, 2022
1 parent 2ad2ea2 commit 998c2d8
Show file tree
Hide file tree
Showing 13 changed files with 274 additions and 214 deletions.
46 changes: 23 additions & 23 deletions etc/cactus/validator-registry-config.yaml
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
ledgerPluginInfo:
-
-
validatorID: 84jUisrs
validatorType: socketio
validatorURL: https://localhost:5050
validatorKeyPath: ./validatorKey/84jUisrs/key84jUisrs.crt
ledgerInfo:
ledgerAbstract: Go-Ethereum Ledger
apiInfo:
-
-
apiType: getNumericBalance
requestedData:
-
-
dataName: referedAddress
dataType: string
-
-
apiType: transferNumericAsset
requestedData:
-
-
dataName: fromAddress
dataType: string
-
-
dataName: toAddress
dataType: string
-
-
dataName: amount
dataType: number
-
-
apiType: sendRawTransaction
requestedData:
-
-
dataName: serializedTx
dataType: string

-
-
validatorID: r9IS4dDf
validatorType: socketio
validatorURL: https://localhost:5040
validatorKeyPath: ./validatorKey/r9IS4dDf/keyr9IS4dDf.crt
ledgerInfo:
ledgerAbstract: Fabric Ledger
apiInfo:
-
-
apiType: changeCarOwner
requestedData:
-
-
dataName: carId
dataType: string
-
-
dataName: newOwner
dataType: string
-
-
apiType: sendSignedProposal
requestedData:
-
-
dataName: signedCommitProposal
dataType: string
-
-
dataName: commitReq
dataType: string

-
-
validatorID: sUr7d10R
validatorType: socketio
validatorURL: https://localhost:5140
Expand All @@ -68,16 +68,16 @@ ledgerPluginInfo:
ledgerAbstract: Sawtooth Ledger
apiInfo: []

-
-
validatorID: 3PfTJw8g
validatorType: socketio
validatorURL: http://172.16.0.4:8000
validatorURL: http://localhost:10080
validatorKeyPath: ./validatorKey/3PfTJw8g/3PfTJw8g.crt
ledgerInfo:
ledgerAbstract: "Indy Ledger"
apiInfo: []

-
-
validatorID: vIdO32CB
validatorType: openapi
validatorURL: http://localhost:5053/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/
Expand All @@ -86,7 +86,7 @@ ledgerPluginInfo:
ledgerAbstract: "Cactus Besu Ledger via http connection"
apiInfo: []

-
-
validatorID: vIdO32CF
validatorType: openapi
validatorURL: http://localhost:5053/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-fabric/
Expand All @@ -95,7 +95,7 @@ ledgerPluginInfo:
ledgerAbstract: "Cactus Fabric Ledger via http connection"
apiInfo: []

-
-
validatorID: vIdO32CQ
validatorType: openapi
validatorURL: http://localhost:5053/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-quorum/
Expand All @@ -115,7 +115,7 @@ signTxInfo:
fabric:
mspID: Org1MSP
peers:
-
-
name: peer0.org1.example.com
requests: grpc://localhost:7051
orderer:
Expand Down
18 changes: 18 additions & 0 deletions examples/register-indy-data/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Simple tool for setup and sending requests to discounted-cartrade sample app
# Run as part of docker-compose or remember to use host network

FROM clientbase

# Default IP for test indy pool on localhost
ENV TEST_POOL_IP 172.16.0.2

USER root
RUN mkdir -p "/etc/cactus/indy-validator/" && chown -R indy "/etc/cactus/"
VOLUME [ "/etc/cactus/" ]

USER indy
WORKDIR /home/indy
COPY --chown=indy:indy './req_discounted_cartrade.py' './src/'
RUN cp 'from-indy-sdk/utils.py' './src/'

ENTRYPOINT [ "python3", "-m", "src.req_discounted_cartrade" ]
28 changes: 28 additions & 0 deletions examples/register-indy-data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# req_discounted_cartrade

Simple tool for setup and sending requests to discounted-cartrade sample app

# How to use
- Setup discounted-cartrade first
- Build clientbase from `tools/docker/indy-testnet/clientbase`
- Build this container `docker build . -t req_discounted_cartrade`
- `mkdir -p /etc/cactus/indy-validator/`

## Usage

### Generate proof only
- Will replace existing proof file (like called with -f flag)

```
docker run --rm -ti -v/etc/cactus/:/etc/cactus/ --net="host" req_discounted_cartrade --proof_only
```

### Send discounted-cartrade request
```
docker run --rm -ti -v/etc/cactus/:/etc/cactus/ --net="host" req_discounted_cartrade
```

### Recreate the proof and send discounted-cartrade request
```
docker run --rm -ti -v/etc/cactus/:/etc/cactus/ --net="host" req_discounted_cartrade --force
```
24 changes: 14 additions & 10 deletions examples/register-indy-data/req_discounted_cartrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import argparse
import sys
from ctypes import *
from os.path import dirname
from os.path import dirname, isfile

from indy.error import ErrorCode, IndyError

Expand Down Expand Up @@ -39,7 +39,7 @@
"authParams": ["<<company name>>"]
}

file_name = "myproof.json"
proof_file_path = "/etc/cactus/indy-validator/myproof.json"

#parser = argparse.ArgumentParser(description='Run python getting-started scenario (Alice/Faber)')
parser = argparse.ArgumentParser(description='Run python getting-started scenario (Alice/Acme/Thrift)')
Expand All @@ -48,7 +48,8 @@
parser.add_argument('-e', '--entrypoint', help='entry point for dynamic library')
parser.add_argument('-c', '--config', help='entry point for dynamic library')
parser.add_argument('-s', '--creds', help='entry point for dynamic library')
parser.add_argument('-m', '--mode', help='mode of send http request')
parser.add_argument('-p', '--proof_only', help="create only the proof, don't start the cartrade", action='store_true')
parser.add_argument('-f', '--force', help="force recreate the proof (even if already exists)", action='store_true')

args = parser.parse_args()

Expand Down Expand Up @@ -82,7 +83,7 @@
async def run():
logger.info("Getting started -> started")

if not(args.mode == "http"):
if (not isfile(proof_file_path)) or args.force or args.proof_only:
pool_ = {
'name': 'pool1'
}
Expand Down Expand Up @@ -426,14 +427,16 @@ async def apply_loan_basic():
##request_json = { "proof_request": json.dumps(alice['apply_loan_proof_request']), "proof": json.dumps(alice['apply_loan_proof'])}
request_json = { "proof_request": alice['apply_loan_proof_request'], "proof": alice['apply_loan_proof']}
logger.info(json.dumps(request_json))
# create_user_proof_file(file_name, json.dumps(request_str))
create_user_proof_file(file_name, json.dumps(request_json))

# create_user_proof_file(proof_file_path, json.dumps(request_str))
create_user_proof_file(proof_file_path, json.dumps(request_json))

await apply_loan_basic()

request_discounted_cartrade(file_name)
if not args.proof_only:
request_discounted_cartrade(proof_file_path)

print("Done.")

def wallet_config(operation, wallet_config_str):
if not args.storage_type:
Expand Down Expand Up @@ -616,6 +619,7 @@ def create_user_proof_file(json_file, user_proof):
logger.info(f"called create_user_proof_file()")
with open(json_file, 'w') as file:
file.write(user_proof)
logger.info(f"Saved proof to {json_file}")

def request_discounted_cartrade(json_file):
# read json file
Expand All @@ -626,7 +630,7 @@ def request_discounted_cartrade(json_file):

# append data of json file to http req param
http_req_params["tradeParams"].append(json_str)

# logger.info(f"http_params: url: {http_req_params['url']}")
# logger.info(f"http_params: businessLogicID: {http_req_params['businessLogicID']}")
# logger.info(f"http_params: tradeParams: {http_req_params['tradeParams']}")
Expand All @@ -641,7 +645,7 @@ def request_discounted_cartrade(json_file):
'authParams': http_req_params["authParams"]}

logger.info(f"req_body: {req_body}")


# response = requests.post(
# http_req_params["url"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"jsonwebtoken": "^8.5.1",
"socket.io-client": "4.1.3"
}
}
Loading

0 comments on commit 998c2d8

Please sign in to comment.