Created
November 30, 2021 16:17
-
-
Save ardasener/73f099dd26cd018ea20dcd906b4652d2 to your computer and use it in GitHub Desktop.
CS403 PA2 Test Client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Pyro4 | |
import subprocess as sp | |
import multiprocessing as mp | |
import threading | |
import time | |
def run_btc(): | |
sp.run(["python", "BTCServer.py"]) | |
def run_eth(): | |
sp.run(["python", "ETHServer.py"]) | |
p1 = mp.Process(target=run_btc) | |
p2 = mp.Process(target=run_eth) | |
p1.start() | |
p2.start() | |
time.sleep(2) | |
print("__BTC TESTS__") | |
BTC = Pyro4.Proxy("PYRONAME:BTC") | |
b1 = BTC.createAccount(100) | |
b2 = BTC.createAccount(70) | |
BTC.transfer(b1, b2, -70) | |
BTC.printChain() | |
print("B1:", BTC.calculateBalance(b1)) | |
print("B2:", BTC.calculateBalance(b2)) | |
BTC.transfer(b1, b2, -30) | |
BTC.printChain() | |
print("B1:", BTC.calculateBalance(b1)) | |
print("B2:", BTC.calculateBalance(b2)) | |
print("") | |
print("___ETH TESTS___") | |
ETH = Pyro4.Proxy("PYRONAME:ETH") | |
e1 = ETH.createAccount(30) | |
e2 = ETH.createAccount(10) | |
ETH.printChain() | |
print("E1:", ETH.calculateBalance(e1)) | |
print("E2:", ETH.calculateBalance(e2)) | |
print("") | |
try: | |
print("__EXCHANGE TESTS___") | |
print("Trying bad exchanges...") | |
ETH.exchange(e2,b2,BTC,20) | |
BTC.exchange(b2,e2,ETH,-20) | |
print("Trying good exchange...") | |
BTC.exchange(b1, e1, ETH, 50) | |
BTC.printChain() | |
ETH.printChain() | |
print("B1:", BTC.calculateBalance(b1)) | |
print("B2:", BTC.calculateBalance(b2)) | |
print("E1:", ETH.calculateBalance(e1)) | |
print("E2:", ETH.calculateBalance(e2)) | |
except: | |
print("Does not work with reference calls") | |
try: | |
print("__EXCHANGE TESTS___") | |
print("Trying bad exchanges...") | |
ETH.exchange(e2,b2,"BTC",20) | |
BTC.exchange(b2,e2,"ETH",-20) | |
print("Trying good exchange...") | |
BTC.exchange(b1, e1, "ETH", 50) | |
BTC.printChain() | |
ETH.printChain() | |
print("B1:", BTC.calculateBalance(b1)) | |
print("B2:", BTC.calculateBalance(b2)) | |
print("E1:", ETH.calculateBalance(e1)) | |
print("E2:", ETH.calculateBalance(e2)) | |
except: | |
print("Does not work with string calls") | |
p1.terminate() | |
p2.terminate() | |
sp.run(["pkill","-f","ETHServer"]) | |
sp.run(["pkill","-f","BTCServer"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment