Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2019
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.10 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Test Parity RPC - Brad Dameron (serpent6877@hotmail.com)
  4. # Modified by https://github.com/c0deright
  5. #
  6. # parity-test.sh <HOST>:<RPC PORT> <# requests before delay> <Delay time between tests>
  7. # Use CTRL+C to exit program
  8. #
  9. # Example ./parity-test.sh localhost:8545 1000 15 5
  10. # Test localhost on port 8545 with 1000 requests of each type 15 times with a 5 second delay between tests
  11. #
  12. # Requires parallel installed.
  13.  
  14.  
  15. HOST_N_PORT=$1
  16. REQUESTS=$2
  17. TESTS=$3
  18. DELAY=$4
  19. LOGFILE=parity-test.log
  20.  
  21. # Set some defaults if no command line option
  22. if [ -z $HOST_N_PORT ]
  23. then
  24.   HOST_N_PORT="localhost:8545"
  25. fi
  26. if [ -z $DELAY ]
  27. then
  28.   REQUESTS=100
  29. fi
  30. if [ -z $TESTS ]
  31. then
  32.   TESTS=10
  33. fi
  34. if [ -z $DELAY ]
  35. then
  36.   DELAY=5
  37. fi
  38.  
  39. getBalance() {
  40.    HOST_N_PORT=$1
  41.    # Test getBalance
  42.    curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0xc94770007dda54cF92009BFF0dE90c06F603a09f", "latest"],"id":1}' -H "Content-Type: application/json" -X POST $HOST_N_PORT
  43.    # Test getWork
  44. #   curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getWork","params":[],"id":73}' -H "Content-Type: application/json" -X POST $HOST_N_PORT
  45.    # Test current blockNumber
  46.    curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H "Content-Type: application/json" -X POST $HOST_N_PORT
  47.    # Test peerCount
  48.    curl -s -X POST --data '{"jsonrpc":"2.0","method":"net_peerCount","params":[],"id":74}' -H "Content-Type: application/json" -X POST $HOST_N_PORT
  49.    # Test accounts
  50.    curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":1}' -H "Content-Type: application/json" -X POST $HOST_N_PORT
  51. }
  52.  
  53. export -f getBalance
  54.  
  55. exec > >(tee -a $LOGFILE) 2>&1
  56.  
  57. for run in $(seq $TESTS)
  58. do
  59.    START=$(date +%s)
  60.    echo "$START - Starting testing ---------"
  61.    seq $REQUESTS | parallel -j0 -N0 getBalance $HOST_N_PORT >/dev/null
  62.    END=$(date +%s)
  63.    DIFF=$(( $END - $START ))
  64.    echo "$END - Stopping testing ---------"
  65.    echo "It took $DIFF seconds for $REQUESTS requests"
  66.    echo "Delaying for $DELAY seconds."
  67.    sleep $DELAY
  68. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement