Skip to content

Commit

Permalink
files for demonstration
Browse files Browse the repository at this point in the history
  • Loading branch information
vivek-arte committed Jul 27, 2023
1 parent 633f121 commit 555557b
Show file tree
Hide file tree
Showing 2 changed files with 228 additions and 8 deletions.
179 changes: 179 additions & 0 deletions qa/rpc-tests/demo-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#! /bin/sh

echo "================================================================"
echo "ZSA DEMO FOR ZCON4 "
echo "================================================================"

echo "Please ensure you are in the root directory of the"
echo "zcash repo, and that you are already running"
echo "python3 qa/rpc-tests/demo-setup.py on another"
echo "terminal."

echo "To confirm the above and proceed to Asset Issuance:"
while true; do
read -p "Please press y to continue, n to exit: " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer y or n"
esac
done

echo "----------------------------------------------------------------"
echo "Dr. Alice issues Rx to self: "
echo "----------------------------------------------------------------"

echo "We will run the following curl command:\n\n"

echo "curl --user `cat qa/rpc-tests/testfiles/auth_alice.txt` --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\",\"method\": \"issue\", \"params\": [0,\"`cat qa/rpc-tests/testfiles/ua1_alice.txt`\", \"Rx date: 2023-08-01, 10 tabs XYZ\", 0.00000001, true] }' -H 'content-type: text/plain;' http://127.0.0.1:`cat qa/rpc-tests/testfiles/port_alice.txt`/ | jq"
echo "................................................................"

curl --user `cat qa/rpc-tests/testfiles/auth_alice.txt` --data-binary '{"jsonrpc": "1.0", "id":"curltest","method": "issue", "params": [0,"'"`cat qa/rpc-tests/testfiles/ua1_alice.txt`"'", "Rx date: 2023-08-01, 10 tabs XYZ", 0.00000001, true] }' -H 'content-type: text/plain;' http://127.0.0.1:`cat qa/rpc-tests/testfiles/port_alice.txt`/ | jq

while true; do
read -p "Please press y to continue, n to exit: " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer y or n"
esac
done

echo "................................................................"
echo "We now generate some blocks:"
echo "Please visit the python script terminal and generate 10 blocks"
echo "................................................................"

while true; do
read -p "Please press y to continue, n to exit: " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer y or n"
esac
done

curl --user `cat qa/rpc-tests/testfiles/auth_alice.txt` --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "generate", "params":[1]}' -H 'content-type: text/plain;' http://127.0.0.1:`cat qa/rpc-tests/testfiles/port_alice.txt`/ | jq

echo "................................................................"
echo "\n Let us now look at Alice's wallet. We run the following command:\n\n"

echo "curl --user `cat qa/rpc-tests/testfiles/auth_alice.txt` --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", \"method\": \"getwalletinfo\", \"params\": [] }' -H 'content-type: text/plain;' http://127.0.0.1:`cat qa/rpc-tests/testfiles/port_alice.txt`/ | jq"

curl --user `cat qa/rpc-tests/testfiles/auth_alice.txt` --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getwalletinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:`cat qa/rpc-tests/testfiles/port_alice.txt`/ | jq

echo "................................................................"

curl --user `cat qa/rpc-tests/testfiles/auth_alice.txt` --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getwalletinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:`cat qa/rpc-tests/testfiles/port_alice.txt`/ | jq '.result.asset_balances |keys |.[0]' -r > qa/rpc-tests/testfiles/asset_base.txt

echo "Notice the presence of the issued prescription asset in Alice's wallet:"
echo "The asset base is `cat qa/rpc-tests/testfiles/asset_base.txt`"

echo "................................................................"

echo "This successfully demonstrates issuance of the Asset. We will"
echo "now demonstrate shielded asset transfer. To proceed:"
while true; do
read -p "Please press y to continue, n to exit: " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer y or n"
esac
done

echo "----------------------------------------------------------------"
echo "Dr. Alice transfers Rx to Felix: "
echo "----------------------------------------------------------------"

echo "We will run the following curl command:\n\n"

echo "curl --user `cat qa/rpc-tests/testfiles/auth_alice.txt` --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", \"method\": \"z_sendassets\", \"params\": [\"`cat qa/rpc-tests/testfiles/ua1_alice.txt`\", [{\"address\": \"`cat qa/rpc-tests/testfiles/ua0_felix.txt`\", \"amount\": 0.00000001, \"asset\": \"`cat qa/rpc-tests/testfiles/asset_base.txt`\"}], 1] }' -H 'content-type: text/plain;' http://127.0.0.1:`cat qa/rpc-tests/testfiles/port_alice.txt`/ | jq"

curl --user `cat qa/rpc-tests/testfiles/auth_alice.txt` --data-binary '{"jsonrpc": "1.0", "id":"curltest","method": "z_sendassets", "params": ["'"`cat qa/rpc-tests/testfiles/ua1_alice.txt`"'",[{"address":"'"`cat qa/rpc-tests/testfiles/ua0_felix.txt`"'", "amount": 0.00000001, "asset": "'"`cat qa/rpc-tests/testfiles/asset_base.txt`"'"}], 1] }' -H 'content-type: text/plain;' http://127.0.0.1:`cat qa/rpc-tests/testfiles/port_alice.txt`/ | jq

echo "................................................................"
echo "Let us now generate some blocks and look at the wallets of Alice and Felix:\n"
echo "Please visit the python script terminal and generate 10 blocks"
echo "................................................................"

while true; do
read -p "Please press y to continue, n to exit: " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer y or n"
esac
done

curl --user `cat qa/rpc-tests/testfiles/auth_felix.txt` --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "generate", "params":[1]}' -H 'content-type: text/plain;' http://127.0.0.1:`cat qa/rpc-tests/testfiles/port_felix.txt`/ | jq

echo "................................................................"
echo " ALICE'S WALLET "
echo "................................................................"

curl --user `cat qa/rpc-tests/testfiles/auth_alice.txt` --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getwalletinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:`cat qa/rpc-tests/testfiles/port_alice.txt`/ | jq

echo "................................................................"
echo " FELIX'S WALLET "
echo "................................................................"

curl --user `cat qa/rpc-tests/testfiles/auth_felix.txt` --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getwalletinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:`cat qa/rpc-tests/testfiles/port_felix.txt`/ | jq

echo "This successfully demonstrates transfer of the Asset from Dr. Alice to Felix."
echo "We will now demonstrate shielded asset transfer from Felix to the manufacturer."
echo "To proceed:"
while true; do
read -p "Please press y to continue, n to exit: " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer y or n"
esac
done

echo "----------------------------------------------------------------"
echo "Felix transfers Rx to the manufacturer: "
echo "----------------------------------------------------------------"

echo "We will run the following curl command:\n\n"

echo "curl --user `cat qa/rpc-tests/testfiles/auth_felix.txt` --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", \"method\": \"z_sendassets\", \"params\": [\"`cat qa/rpc-tests/testfiles/ua0_felix.txt`\", [{\"address\": \"`cat qa/rpc-tests/testfiles/ua0_mfg.txt`\", \"amount\": 0.00000001, \"asset\": \"`cat qa/rpc-tests/testfiles/asset_base.txt`\"}], 1] }' -H 'content-type: text/plain;' http://127.0.0.1:`cat qa/rpc-tests/testfiles/port_felix.txt`/ | jq"

curl --user `cat qa/rpc-tests/testfiles/auth_felix.txt` --data-binary '{"jsonrpc": "1.0", "id":"curltest","method": "z_sendassets", "params": ["'"`cat qa/rpc-tests/testfiles/ua0_felix.txt`"'",[{"address":"'"`cat qa/rpc-tests/testfiles/ua0_mfg.txt`"'", "amount": 0.00000001, "asset": "'"`cat qa/rpc-tests/testfiles/asset_base.txt`"'"}], 1] }' -H 'content-type: text/plain;' http://127.0.0.1:`cat qa/rpc-tests/testfiles/port_felix.txt`/ | jq

echo "................................................................"
echo "Let us now generate some blocks and look at the wallets of Felix and the manufacturer:\n"
echo "Please visit the python script terminal and generate 10 blocks"
echo "................................................................"

while true; do
read -p "Please press y to continue, n to exit: " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer y or n"
esac
done

curl --user `cat qa/rpc-tests/testfiles/auth_mfg.txt` --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "generate", "params":[1]}' -H 'content-type: text/plain;' http://127.0.0.1:`cat qa/rpc-tests/testfiles/port_mfg.txt`/ | jq

echo "................................................................"
echo " FELIX'S WALLET "
echo "................................................................"

curl --user `cat qa/rpc-tests/testfiles/auth_felix.txt` --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getwalletinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:`cat qa/rpc-tests/testfiles/port_felix.txt`/ | jq

echo "................................................................"
echo " MANUFACTURER'S WALLET "
echo "................................................................"

curl --user `cat qa/rpc-tests/testfiles/auth_mfg.txt` --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getwalletinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:`cat qa/rpc-tests/testfiles/port_mfg.txt`/ | jq

echo "This successfully demonstrates transfer of the Asset from Felix to the manufacturer."

echo "================================================================"
echo "THANK YOU! "
echo "================================================================"

rm -rf qa/rpc-tests/testfiles
57 changes: 49 additions & 8 deletions qa/rpc-tests/demo-setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
rpc_url,
)

import time
import time, json, os, re
from decimal import Decimal

class IssueTest(BitcoinTestFramework):
def __init__(self):
Expand Down Expand Up @@ -47,26 +48,66 @@ def run_test(self):
self.nodes[0].generate(5)
self.sync_all()

# Print details post account setup:
# Save necessary details to files for use in demo shell script (store in ./testfiles directory)

os.makedirs(os.path.join(os.path.dirname(__file__),'testfiles'), exist_ok=True)

with open(os.path.join(os.path.dirname(__file__),'testfiles','ua0_alice.txt'), 'wt') as f:
f.write(ua0_alice)

with open(os.path.join(os.path.dirname(__file__),'testfiles','ua1_alice.txt'), 'wt') as f:
f.write(ua1_alice)

with open(os.path.join(os.path.dirname(__file__),'testfiles','ua0_felix.txt'), 'wt') as f:
f.write(ua0_felix)

with open(os.path.join(os.path.dirname(__file__),'testfiles','ua0_mfg.txt'), 'wt') as f:
f.write(ua0_mfg)

with open(os.path.join(os.path.dirname(__file__),'testfiles','port_alice.txt'), 'wt') as f:
f.write(rpc_url(0).split(":")[3])

with open(os.path.join(os.path.dirname(__file__),'testfiles','port_felix.txt'), 'wt') as f:
f.write(rpc_url(1).split(":")[3])

with open(os.path.join(os.path.dirname(__file__),'testfiles','port_mfg.txt'), 'wt') as f:
f.write(rpc_url(2).split(":")[3])

with open(os.path.join(os.path.dirname(__file__),'testfiles','auth_alice.txt'), 'wt') as f:
f.write(rpc_url(0).split("@")[0].split("//")[1])

with open(os.path.join(os.path.dirname(__file__),'testfiles','auth_felix.txt'), 'wt') as f:
f.write(rpc_url(1).split("@")[0].split("//")[1])

with open(os.path.join(os.path.dirname(__file__),'testfiles','auth_mfg.txt'), 'wt') as f:
f.write(rpc_url(2).split("@")[0].split("//")[1])

# Print details post account setup

#Alice:
print("\n\nAlice's port is:", rpc_url(0))
print("\n\n -------------- ALICE --------------\n")
print("\nAlice's port is:", rpc_url(0))
print("\nAlice's Unified Address on Account 0 is:", ua0_alice)
print("\nAlice's Unified Address on Account 1 is:", ua1_alice)
print("\nAlice's wallet details:\n")
print(self.nodes[0].getwalletinfo())
print(json.dumps(self.nodes[0].getwalletinfo(), default=str, indent=4))
print("\n -------------- --------------\n")

#Felix:
print("\n\nFelix's port is:", rpc_url(1))
print("\n\n -------------- FELIX --------------\n")
print("\nFelix's port is:", rpc_url(1))
print("\nFelix's Unified Address on Account 0 is:", ua0_felix)
print("\nFelix's wallet details:\n")
print(self.nodes[1].getwalletinfo())
print(json.dumps(self.nodes[1].getwalletinfo(), default=str, indent=4))
print("\n -------------- --------------\n")

#Manufacturer:
print("\n\nThe manufacturer's port is:", rpc_url(2))
print("\n\n -------------- MANUFACTURER --------------\n")
print("\nThe manufacturer's port is:", rpc_url(2))
print("\nThe manufacturer's Unified Address on Account 0 is:", ua0_mfg)
print("\nThe manufacturer's wallet details:\n")
print(self.nodes[2].getwalletinfo())
print(json.dumps(self.nodes[2].getwalletinfo(), default=str, indent=4))
print("\n -------------- --------------\n")

counter = 0
while True:
Expand Down

0 comments on commit 555557b

Please sign in to comment.