You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@milagro.apache.org by cm...@apache.org on 2019/10/09 12:49:15 UTC

[incubator-milagro-dta] 05/06: Complete fishhook and update tests

This is an automated email from the ASF dual-hosted git repository.

cmorris pushed a commit to branch tendermint
in repository https://gitbox.apache.org/repos/asf/incubator-milagro-dta.git

commit f9c7a03a365815ed6f0bbb9cf5e801967012d601
Author: Christopher Morris <ch...@morris.net>
AuthorDate: Wed Oct 9 13:44:59 2019 +0100

    Complete fishhook and update tests
---
 cmd/servicetester/e2e_test.sh                      | 209 ++++++++-------------
 cmd/servicetester/{e2e_test.sh => e2e_test.sh.old} |   0
 .../fishhook => cmd/servicetester}/fishhook        | Bin 29288396 -> 29288396 bytes
 cmd/servicetester/main.go                          |   2 +-
 cmd/servicetester/ref                              |   1 +
 pkg/defaultservice/orderTX.go                      |   3 +-
 pkg/tendermint/fishhook/fishhook                   | Bin 29288396 -> 29288396 bytes
 pkg/tendermint/fishhook/main.go                    |  41 ++--
 pkg/tendermint/fishhook/run                        |   2 -
 9 files changed, 109 insertions(+), 149 deletions(-)

diff --git a/cmd/servicetester/e2e_test.sh b/cmd/servicetester/e2e_test.sh
index a0f7f0d..2c3ca87 100755
--- a/cmd/servicetester/e2e_test.sh
+++ b/cmd/servicetester/e2e_test.sh
@@ -22,13 +22,14 @@
 apiVersion="v1"
 defaultURL="http://localhost:5556"
 apiURL="${1:-$defaultURL}"
-
+configdir="/Users/chris/.milagro"
+host="34.246.173.153:26657"
 
 status () {
   #Determine if an extension is running
   statusOutput=$(curl -s -X GET "$apiURL/$apiVersion/status" -H "accept: */*" -H "Content-Type: application/json")
 
-echo "$apiURL/$apiVersion/status"
+  echo "$apiURL/$apiVersion/status"
 
   identity=$(echo $statusOutput | jq .nodeCID)
   extensionVendor=$(echo $statusOutput | jq -r .extensionVendor)
@@ -45,144 +46,93 @@ echo "$apiURL/$apiVersion/status"
 
 execute_bitcoin () {
   # #Run 4 Tests against the Bitcoin Extension
-  echo "Bitcoin Plugin Tests [4 Tests]"
-  output1=$(curl -s -X POST "$apiURL/$apiVersion/order1" -H "accept: */*" -H "Content-Type: application/json" -d "{\"beneficiaryIDDocumentCID\":\"\",\"extension\":{\"coin\":\"0\"}}")
-  #echo $output1
-  op1=$(echo $output1 | jq .orderReference)
-  commitment1=$(echo $output1 | jq .commitment)
-  address1=$(echo $output1 | jq .extension.address)
-  output2=$(curl -s -X POST "$apiURL/$apiVersion/order/secret1" -H "accept: */*" -H "Content-Type: application/json" -d "{\"orderReference\":$op1,\"beneficiaryIDDocumentCID\":$identity}")
-  address2=$(echo $output2 | jq .extension.address)
-  commitment2=$(echo $output2 | jq .commitment)
-
-  echo "Committment1 $commitment1 $address1"
-  echo "Committment2 $commitment2 $address2"
-
+  echo "Bitcoin Plugin Tests [2 Tests]"
+
+
+ ( sleep 1; curl -s -X POST "$apiURL/$apiVersion/order" -H "accept: */*" -H "Content-Type: application/json"  -d "{\"beneficiaryIDDocumentCID\":\"\",\"extension\":{\"coin\":\"0\"}}" > ref ) &
+  output1=$(fishhook $configdir $host "self" 2)
+  ref=$(cat ref)
+  commitment1=$(echo $output1 | jq .OrderPart2.CommitmentPublicKey)
+  address1=$(echo $output1 | jq .OrderPart2.Extension.address)
+  (sleep 1; curl -s -X POST "$apiURL/$apiVersion/order/secret" -H "accept: */*" -H "Content-Type: application/json" -d "{\"orderReference\":$ref,\"beneficiaryIDDocumentCID\":$identity}" > /dev/null ) &
+  output2=$(fishhook $configdir $host "self" 2)
+  address2=$(echo $output2 | jq .OrderPart4.Extension.address)
+  commitment2=$(echo $output2 | jq .OrderPart4.Extension.FinalPublicKey)
+  #echo "Committment1 $commitment1 $address1"
+  #echo "Committment2 $commitment2 $address2"
   if [ -z $commitment2 ]; then
       echo "Failed Commitment is empty"
       exit 1
   fi
-
-  if [ $commitment1 == $commitment2 ]; then
-    echo "Pass - Id, Order & OrderSecret(Beneficiary)"
-  else
+  if [ $commitment1 != $commitment2 ]; then
     echo "Fail"
     exit 1
   fi
-
-  output3=$(curl -s -X POST "$apiURL/$apiVersion/order1" -H "accept: */*" -H "Content-Type: application/json" -d "{\"beneficiaryIDDocumentCID\":$identity,\"extension\":{\"coin\":\"0\"}}")
-
-  op3=$(echo $output3 | jq .orderReference)
-  commitment3=$(echo $output3 | jq .commitment)
-  address3=$(echo $output3 | jq .extension.address)
-  output4=$(curl -s -X POST "$apiURL/$apiVersion/order/secret1" -H "accept: */*" -H "Content-Type: application/json" -d "{\"orderReference\":$op3}")
-  commitment4=$(echo $output4 | jq .commitment)
-  address4=$(echo $output4 | jq .extension.address)
-  orderReference=$(echo $output4 | jq .orderReference)
-  orderIndex=1
-
-  echo "Committment3 $commitment3 $address3"
-  echo "Committment4 $commitment4 $address4"
-
-  if [ -z $commitment4 ]; then
+  if [ $address2 != $address2 ]; then
+    echo "Fail"
+    exit 1
+  fi
+  echo "Pass - Id, Order & OrderSecret(Beneficiary)"
+
+
+  ( sleep 1; curl -s -X POST "$apiURL/$apiVersion/order" -H "accept: */*" -H "Content-Type: application/json"  -d "{\"beneficiaryIDDocumentCID\":$identity,\"extension\":{\"coin\":\"0\"}}" > ref ) &
+  output1=$(fishhook $configdir $host "self" 2)
+  ref=$(cat ref)
+  commitment1=$(echo $output1 | jq .OrderPart2.CommitmentPublicKey)
+  address1=$(echo $output1 | jq .OrderPart2.Extension.address)
+  (sleep 1; curl -s -X POST "$apiURL/$apiVersion/order/secret" -H "accept: */*" -H "Content-Type: application/json" -d "{\"orderReference\":$ref}" > /dev/null ) &
+  output2=$(fishhook $configdir $host "self" 2)
+  address2=$(echo $output2 | jq .OrderPart4.Extension.address)
+  commitment2=$(echo $output2 | jq .OrderPart4.Extension.FinalPublicKey)
+  #echo "Committment1 $commitment1 $address1"
+  #echo "Committment2 $commitment2 $address2"
+  if [ -z $commitment2 ]; then
       echo "Failed Commitment is empty"
       exit 1
   fi
-
-  if [ $commitment3 == $commitment4 ]; then
-    echo "Pass - Id, Order(Beneficiary) & OrderSecret"
-  else
-      echo "Fail"
-      exit 1
+  if [ $commitment1 != $commitment2 ]; then
+    echo "Fail"
+    exit 1
   fi
-
-
-   #make another BeneficiaryID
-  #  output5=$(curl -s -X POST "http://localhost:5556/$apiVersion/identity" -H "accept: */*" -H       "Content-Type: application/json" -d "{\"Name\":\"AA\"}")
-  #  benid=$(echo $output5 | jq -r .idDocumentCID)
-
-  #  #Tests against the Bitcoin Extension - different befificary
-  #  output6=$(curl -s -X POST "http://localhost:5556/$apiVersion/order" -H "accept: */*" -H "Content-Type: application/json" -d "{\"beneficiaryIDDocumentCID\":\"\",\"extension\":{\"coin\":\"0\"}}")
-  #  #echo $output6
-  #  op6=$(echo $output6 | jq .orderReference)
-  #  commitment6=$(echo $output6 | jq .commitment)
-  #  address6=$(echo $output6 | jq .extension.address)
-
-  #  output7=$(curl -s -X POST "http://localhost:5556/$apiVersion/order/secret" -H "accept: */*" -H "Content-Type: application/json" -d "{\"orderReference\":$op6,\"beneficiaryIDDocumentCID\":\"$benid\"}")
-  #  address7=$(echo $output7 | jq .extension.address)
-  #  commitment7=$(echo $output7 | jq .commitment)
-
-  #  echo "Committment5 $commitment6 $address6"
-  #  echo "Committment6 $commitment7 $address7"
-
-  #  if [ -z $commitment7 ]; then
-  #      echo "Failed Commitment is empty"
-  #      exit 1
-  #  fi
-
-  #  if [ $commitment6 == $commitment7 ]; then
-  #    echo "Pass - Id, Order & OrderSecret(Beneficiary)"
-  #  else
-  #    echo "Fail"
-  #    exit 1
-  #  fi
-
-  # output8=$(curl -s -X POST "http://localhost:5556/$apiVersion/order" -H "accept: */*" -H "Content-Type: application/json" -d "{\"beneficiaryIDDocumentCID\":\"$benid\",\"extension\":{\"coin\":\"0\"}}")
-  # op8=$(echo $output8 | jq .orderReference)
-  # commitment8=$(echo $output8 | jq .commitment)
-  # address8=$(echo $output8 | jq .extension.address)
-
-
-  # output9=$(curl -s -X POST "http://localhost:5556/$apiVersion/order/secret" -H "accept: */*" -H "Content-Type: application/json" -d "{\"orderReference\":$op8}")
-  # commitment9=$(echo $output9 | jq .commitment)
-  # address9=$(echo $output9 | jq .extension.address)
-  # orderReference=$(echo $output9 | jq .orderReference)
-  # orderIndex=1
-
-  # echo "Committment7 $commitment8 $address8"
-  # echo "Committment8 $commitment9 $address9"
-
-  # if [ -z $commitment9 ]; then
-  #     echo "Failed Commitment is empty"
-  #     exit 1
-  # fi
-
-  # if [ $commitment8 == $commitment9 ]; then
-  #   echo "Pass - Id, Order(Beneficiary) & OrderSecret"
-  # else
-  #     echo "Fail"
-  #     exit 1
-  # fi
-
+  if [ $address2 != $address2 ]; then
+    echo "Fail"
+    exit 1
+  fi
+ echo "Pass - Id, Order(Beneficiary) & OrderSecret"
 }
 
 
 ###############################################################################################################################
 
 execute_safeguardsecret () {
+
   inputString="This is some random test text 1234567890!"
   echo "Encrypt a String [1 Test]"
-  echo $output1
-  output1=$(curl -s -X POST "$apiURL/$apiVersion/order1" -H "accept: */*" -H "Content-Type: application/json" -d "{\"beneficiaryIDDocumentCID\":$identity,\"extension\":{\"plainText\":\"$inputString\"}}")
-  echo $output1
-  op1=$(echo $output1 | jq .orderReference)
-  cipherText=$(echo $output1 | jq .extension.cypherText)
-  tvalue=$(echo $output1 | jq .extension.t)
-  vvalue=$(echo $output1 | jq .extension.v)
-  commitment1=$(echo $output1 | jq .commitment)
-  output2=$(curl -s -X POST "$apiURL/$apiVersion/order/secret1" -H "accept: */*" -H "Content-Type: application/json" -d "{\"orderReference\":$op1,\"beneficiaryIDDocumentCID\":$identity,\"extension\":{\"cypherText\":$cipherText,\"t\":$tvalue,\"v\":$vvalue}}")
-  result=$(echo $output2 | jq -r .extension.plainText)
-
-  orderReference=$(echo $output2 | jq .orderReference)
-  orderIndex=0
 
 
-  if [ "$inputString" == "$result" ]; then
-    echo "Pass"
+  ( sleep 1; curl -s -X POST "$apiURL/$apiVersion/order" -H "accept: */*" -H "Content-Type: application/json" -d "{\"beneficiaryIDDocumentCID\":$identity,\"extension\":{\"plainText\":\"$inputString\"}}" > ref ) &
+  output1=$(fishhook $configdir $host "self" 2)
+  ref=$(cat ref)
+  cipherText=$(echo $output1 | jq .OrderPart2.Extension.cypherText)
+
+  #echo $cipherText
+  ( sleep 1; curl -s -X POST "$apiURL/$apiVersion/order/secret" -H "accept: */*" -H "Content-Type: application/json" -d "{\"orderReference\":$ref,\"beneficiaryIDDocumentCID\":$identity,\"extension\":{\"cypherText\":$cipherText}}" > /dev/null) &
+  output2=$(fishhook $configdir $host "self" 2)
+  plaintext=$(echo $output2 | jq -r .OrderPart4.Extension.plainText)
+
+
+  if [ -z "$plaintext" ]; then
+      echo "Failed Commitment is empty"
+      exit 1
+  fi
+
+  if [ "$inputString" == "$plaintext" ]; then
+    echo "Order Create/Retrieve Pass"
   else
-    echo "Fail"
+    echo "Order Create/Retrieve Fail"
     exit 1
   fi
+
 }
 
 # #############################################################################
@@ -190,21 +140,18 @@ execute_safeguardsecret () {
 
 execute_milagro () {
   echo "Milagro Tests [1 Test]"
-  output1=$(curl -s -X POST "$apiURL/$apiVersion/order1" -H "accept: */*" -H "Content-Type: application/json" -d "{\"beneficiaryIDDocumentCID\":$identity}")
-  echo $output1
-  op1=$(echo $output1 | jq .orderReference)
-
-
-  commitment1=$(echo $output1 | jq .commitment)
-  output2=$(curl -s -X POST "$apiURL/$apiVersion/order/secret1" -H "accept: */*" -H "Content-Type: application/json" -d "{\"orderReference\":$op1,\"beneficiaryIDDocumentCID\":$identity}")
-  commitment2=$(echo $output2 | jq .commitment)
-
-  orderReference=$(echo $output2 | jq .orderReference)
+  ( sleep 1; curl -s -X POST "$apiURL/$apiVersion/order" -H "accept: */*" -H "Content-Type: application/json" -d "{\"beneficiaryIDDocumentCID\":$identity}" > ref ) &
+  output1=$(fishhook $configdir $host "self" 1)
+  ref=$(cat ref)
+  commitment1=$(echo $output1 | jq .OrderPart2.CommitmentPublicKey)
+  #echo "Committment1 $commitment1"
+
+  ( sleep 1; curl -s -X POST "$apiURL/$apiVersion/order/secret" -H "accept: */*" -H "Content-Type: application/json" -d "{\"orderReference\":$ref,\"beneficiaryIDDocumentCID\":$identity}" > /dev/null) &
+  output2=$(fishhook $configdir $host "self" 3)
+  commitment2=$(echo $output2 | jq .OrderPart4.Extension.FinalPublicKey)
   orderIndex=0
-
-
-  echo "Committment1 $commitment1"
-  echo "Committment2 $commitment2"
+  #echo "Committment1 $commitment1"
+  #echo "Committment2 $commitment2"
 
   if [ -z $commitment2 ]; then
       echo "Failed Commitment is empty"
@@ -263,5 +210,5 @@ fi
 if [ $plugin == "safeguardsecret" ]; then
     execute_safeguardsecret
 fi
-execute_orderlist
+#execute_orderlist
 
diff --git a/cmd/servicetester/e2e_test.sh b/cmd/servicetester/e2e_test.sh.old
similarity index 100%
copy from cmd/servicetester/e2e_test.sh
copy to cmd/servicetester/e2e_test.sh.old
diff --git a/pkg/tendermint/fishhook/fishhook b/cmd/servicetester/fishhook
similarity index 80%
copy from pkg/tendermint/fishhook/fishhook
copy to cmd/servicetester/fishhook
index be3a244..6353907 100755
Binary files a/pkg/tendermint/fishhook/fishhook and b/cmd/servicetester/fishhook differ
diff --git a/cmd/servicetester/main.go b/cmd/servicetester/main.go
index fc55432..700645c 100644
--- a/cmd/servicetester/main.go
+++ b/cmd/servicetester/main.go
@@ -84,7 +84,7 @@ func  Dump(tx *BlockChainTX) error {
 	}
 
 	order := &documents.OrderDoc{}
-	err = documents.DecodeOrderDocument(tx.Payload, txHashString, order, sikeSK, nodeID, localIDDoc.BLSPublicKey)
+	err = documents.FinalPrivateKey(tx.Payload, txHashString, order, sikeSK, nodeID, localIDDoc.BLSPublicKey)
 
 	pp, _ := prettyjson.Marshal(order)
 	fmt.Println(string(pp))
diff --git a/cmd/servicetester/ref b/cmd/servicetester/ref
new file mode 100644
index 0000000..7bb74c7
--- /dev/null
+++ b/cmd/servicetester/ref
@@ -0,0 +1 @@
+"83568372-ea91-11e9-888f-acde48001122"
diff --git a/pkg/defaultservice/orderTX.go b/pkg/defaultservice/orderTX.go
index 02ff5f5..ad07ea6 100644
--- a/pkg/defaultservice/orderTX.go
+++ b/pkg/defaultservice/orderTX.go
@@ -126,7 +126,7 @@ func (s *Service) OrderSecret2(tx *api.BlockChainTX) (string, error) {
 		return "", errors.New("Invalid Processor")
 	}
 
-	finalPrivateKey, _, extension, err := s.Plugin.ProduceFinalSecret(keyseed, sikeSK, order, order, nodeID)
+	finalPrivateKey, finalPublicKey, extension, err := s.Plugin.ProduceFinalSecret(keyseed, sikeSK, order, order, nodeID)
 	if err != nil {
 		return "", err
 	}
@@ -143,6 +143,7 @@ func (s *Service) OrderSecret2(tx *api.BlockChainTX) (string, error) {
 		order.OrderPart4.Extension[key] = value
 	}
 	order.OrderPart4.Extension["FinalPrivateKey"] = finalPrivateKey
+	order.OrderPart4.Extension["FinalPublicKey"] = finalPublicKey
 
 	//Output Only to self for autoviewing
 	recipientList, err := common.BuildRecipientList(s.Tendermint, nodeID)
diff --git a/pkg/tendermint/fishhook/fishhook b/pkg/tendermint/fishhook/fishhook
index be3a244..24ad43f 100755
Binary files a/pkg/tendermint/fishhook/fishhook and b/pkg/tendermint/fishhook/fishhook differ
diff --git a/pkg/tendermint/fishhook/main.go b/pkg/tendermint/fishhook/main.go
index 3f4dd4c..9ad860d 100644
--- a/pkg/tendermint/fishhook/main.go
+++ b/pkg/tendermint/fishhook/main.go
@@ -41,13 +41,23 @@ func main() {
 		},
 	}
 	app.Copyright = "(c) 2019 Chris Morris"
-	app.UsageText = `fishhook configdir nodeurl query skip
-eg. fishhook /Users/john/.milagro 10.10,10,10:26657 "tag.recipient='Au1WipqVeTx9i2PV4UcCxmY6iQvA9RZXy88xJLRzafwc'" 3
-
-configdir - the local directory where the DT-A configuration (eg. config.yaml, keys) are stored
-nodeurl   - the host:port of a member Node of the Tendermint Network
-query     - A query to filter the results by (enclosed query in double quotes and values in single quotes)
-skip      - number of matches to skip before showing match and terminating
+	app.UsageText = `USAGE:
+    fishhook configdir nodeurl query skip
+
+DESCRIPTION:
+    fishhook attaches to the specified Tendermint Node via web sockets, and waits for a
+    query to be matches skip times, oncer complete it uses the local keys stored in configdir
+    to decode the Transaction and dump it to stdout
+
+EXAMPLE:
+    fishhook /Users/john/.milagro 10.10,10,10:26657 "tag.recipient='Au1WipqVeTx9i2PV4UcCxmY6iQvA9RZXy88xJLRzafwc'" 3
+
+PARAMETERS: (all mandatory)
+    configdir - the local directory where the DT-A configuration (eg. config.yaml, keys) are stored
+    nodeurl   - the host:port of a member Node of the Tendermint Network
+    query     - A query to filter the results by (enclosed query in double quotes and values in single quotes)
+              - if query is 'self', query auto generated to match itself as recipient.
+    skip      - number of matches to skip before showing match and terminating
 `
 	app.Usage = `retrieve and parse a transaction in the Qredo DT-A Format from a Tendermint Blockchain
 Note tags are case sensistive
@@ -59,23 +69,27 @@ Note tags are case sensistive
 		query := c.Args().Get(2)
 		skip, err := strconv.Atoi(c.Args().Get(3))
 
-		if err != nil {
-			print("Invalid skip value\n")
-			os.Exit(1)
-		}
-
 		if len(c.Args()) != 4 {
 			print(app.UsageText)
 			os.Exit(1)
 			return nil
 		}
 
+		if err != nil {
+			print("Invalid skip value\n")
+			os.Exit(1)
+		}
+
 		cfg, err := parseConfig(folder)
 		if err != nil {
 			print("Failed to open config")
 			os.Exit(1)
 		}
 
+		if query == "self" {
+			query = "tag.recipient='" + cfg.Node.NodeID + "'"
+		}
+
 		keyStore, err := keystore.NewFileStore(filepath.Join(folder, keysFile))
 		if err != nil {
 			print("Fail to open keystore")
@@ -116,12 +130,11 @@ Note tags are case sensistive
 		for {
 			select {
 			case result := <-out:
-				matchCount++
 				if matchCount != skip {
+					matchCount++
 					continue
 				}
 
-				print("result")
 				tx := result.Data.(tmtypes.EventDataTx).Tx
 				nodeID := cfg.Node.NodeID
 				payload := &api.BlockChainTX{}
diff --git a/pkg/tendermint/fishhook/run b/pkg/tendermint/fishhook/run
deleted file mode 100755
index 1e44661..0000000
--- a/pkg/tendermint/fishhook/run
+++ /dev/null
@@ -1,2 +0,0 @@
-./fishhook /Users/chris/.milagro 34.246.173.153:26657 "tag.recipient='Au1WipqVeTx9i2PV4UcCxmY6iQvA9RZXy88xJLRzafwc'" 1
-