|
|
|
|
@ -20,7 +20,7 @@ from test_websocket import (ClientTProtocol, test_tx_hex_1,
|
|
|
|
|
|
|
|
|
|
testdir = os.path.dirname(os.path.realpath(__file__)) |
|
|
|
|
|
|
|
|
|
testfileloc = "testwrpc.jmdat" |
|
|
|
|
testfilename = "testwrpc" |
|
|
|
|
|
|
|
|
|
jlog = get_log() |
|
|
|
|
|
|
|
|
|
@ -42,10 +42,12 @@ class WalletRPCTestBase(object):
|
|
|
|
|
dport = 28183 |
|
|
|
|
# the port for the ws |
|
|
|
|
wss_port = 28283 |
|
|
|
|
|
|
|
|
|
# how many different wallets we need |
|
|
|
|
num_wallet_files = 2 |
|
|
|
|
|
|
|
|
|
def setUp(self): |
|
|
|
|
load_test_config() |
|
|
|
|
self.clean_out_wallet_file() |
|
|
|
|
self.clean_out_wallet_files() |
|
|
|
|
jm_single().bc_interface.tick_forward_chain_interval = 5 |
|
|
|
|
jm_single().bc_interface.simulate_blocks() |
|
|
|
|
# a client connnection object which is often but not always |
|
|
|
|
@ -59,7 +61,7 @@ class WalletRPCTestBase(object):
|
|
|
|
|
# because we sync and start the wallet service manually here |
|
|
|
|
# (and don't use wallet files yet), we won't have set a wallet name, |
|
|
|
|
# so we set it here: |
|
|
|
|
self.daemon.wallet_name = testfileloc |
|
|
|
|
self.daemon.wallet_name = self.get_wallet_file_name(1) |
|
|
|
|
r, s = self.daemon.startService() |
|
|
|
|
self.listener_rpc = r |
|
|
|
|
self.listener_ws = s |
|
|
|
|
@ -82,12 +84,21 @@ class WalletRPCTestBase(object):
|
|
|
|
|
addr += api_version_string |
|
|
|
|
return addr |
|
|
|
|
|
|
|
|
|
def clean_out_wallet_file(self): |
|
|
|
|
if os.path.exists(os.path.join(".", "wallets", testfileloc)): |
|
|
|
|
os.remove(os.path.join(".", "wallets", testfileloc)) |
|
|
|
|
def clean_out_wallet_files(self): |
|
|
|
|
for i in range(1, self.num_wallet_files + 1): |
|
|
|
|
wfn = self.get_wallet_file_name(i, fullpath=True) |
|
|
|
|
if os.path.exists(wfn): |
|
|
|
|
os.remove(wfn) |
|
|
|
|
|
|
|
|
|
def get_wallet_file_name(self, i, fullpath=False): |
|
|
|
|
tfn = testfilename + str(i) + ".jmdat" |
|
|
|
|
if fullpath: |
|
|
|
|
return os.path.join(".", "wallets", tfn) |
|
|
|
|
else: |
|
|
|
|
return tfn |
|
|
|
|
|
|
|
|
|
def tearDown(self): |
|
|
|
|
self.clean_out_wallet_file() |
|
|
|
|
self.clean_out_wallet_files() |
|
|
|
|
for dc in reactor.getDelayedCalls(): |
|
|
|
|
dc.cancel() |
|
|
|
|
d1 = defer.maybeDeferred(self.listener_ws.stopListening) |
|
|
|
|
@ -155,10 +166,13 @@ class TrialTestWRPC_DisplayWallet(WalletRPCTestBase, unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
1. create a wallet and have it persisted |
|
|
|
|
to disk in ./wallets, and get a token. |
|
|
|
|
2. list wallets and check they contain the new |
|
|
|
|
2. lock that wallet. |
|
|
|
|
3. create a second wallet as above. |
|
|
|
|
4. list wallets and check they contain the new |
|
|
|
|
wallet. |
|
|
|
|
3. lock the existing wallet service, using the token. |
|
|
|
|
4. Unlock the wallet with /unlock, get a token. |
|
|
|
|
5. lock the existing wallet service, using the token. |
|
|
|
|
6. Unlock the original wallet with /unlock, get a token. |
|
|
|
|
7. Unlock the second wallet with /unlock, get a token. |
|
|
|
|
""" |
|
|
|
|
# before starting, we have to shut down the existing |
|
|
|
|
# wallet service (usually this would be `lock`): |
|
|
|
|
@ -166,40 +180,67 @@ class TrialTestWRPC_DisplayWallet(WalletRPCTestBase, unittest.TestCase):
|
|
|
|
|
self.daemon.stopService() |
|
|
|
|
self.daemon.auth_disabled = False |
|
|
|
|
|
|
|
|
|
wfn1 = self.get_wallet_file_name(1) |
|
|
|
|
wfn2 = self.get_wallet_file_name(2) |
|
|
|
|
self.wfnames = [wfn1, wfn2] |
|
|
|
|
agent = get_nontor_agent() |
|
|
|
|
root = self.get_route_root() |
|
|
|
|
|
|
|
|
|
# 1. Create first |
|
|
|
|
addr = root + "/wallet/create" |
|
|
|
|
addr = addr.encode() |
|
|
|
|
body = BytesProducer(json.dumps({"walletname": testfileloc, |
|
|
|
|
body = BytesProducer(json.dumps({"walletname": wfn1, |
|
|
|
|
"password": "hunter2", "wallettype": "sw-fb"}).encode()) |
|
|
|
|
yield self.do_request(agent, b"POST", addr, body, |
|
|
|
|
self.process_create_wallet_response) |
|
|
|
|
|
|
|
|
|
# 2. now *lock* |
|
|
|
|
addr = root + "/wallet/" + wfn1 + "/lock" |
|
|
|
|
addr = addr.encode() |
|
|
|
|
jlog.info("Using address: {}".format(addr)) |
|
|
|
|
yield self.do_request(agent, b"GET", addr, None, |
|
|
|
|
self.process_lock_response, token=self.jwt_token) |
|
|
|
|
|
|
|
|
|
# 3. Create this secondary wallet (so we can test re-unlock) |
|
|
|
|
addr = root + "/wallet/create" |
|
|
|
|
addr = addr.encode() |
|
|
|
|
body = BytesProducer(json.dumps({"walletname": wfn2, |
|
|
|
|
"password": "hunter3", "wallettype": "sw"}).encode()) |
|
|
|
|
yield self.do_request(agent, b"POST", addr, body, |
|
|
|
|
self.process_create_wallet_response) |
|
|
|
|
|
|
|
|
|
# 4. List wallets |
|
|
|
|
addr = root + "/wallet/all" |
|
|
|
|
addr = addr.encode() |
|
|
|
|
# does not require a token, though we just got one. |
|
|
|
|
yield self.do_request(agent, b"GET", addr, None, |
|
|
|
|
self.process_list_wallets_response) |
|
|
|
|
|
|
|
|
|
# now *lock* the existing, which will shut down the wallet |
|
|
|
|
# service associated. |
|
|
|
|
addr = root + "/wallet/" + self.daemon.wallet_name + "/lock" |
|
|
|
|
# 5. now *lock* the active. |
|
|
|
|
addr = root + "/wallet/" + wfn2 + "/lock" |
|
|
|
|
addr = addr.encode() |
|
|
|
|
jlog.info("Using address: {}".format(addr)) |
|
|
|
|
yield self.do_request(agent, b"GET", addr, None, |
|
|
|
|
self.process_lock_response, token=self.jwt_token) |
|
|
|
|
# wallet service should now be stopped. |
|
|
|
|
addr = root + "/wallet/" + self.daemon.wallet_name + "/unlock" |
|
|
|
|
# 6. Unlock the original wallet |
|
|
|
|
addr = root + "/wallet/" + wfn1 + "/unlock" |
|
|
|
|
addr = addr.encode() |
|
|
|
|
body = BytesProducer(json.dumps({"password": "hunter2"}).encode()) |
|
|
|
|
yield self.do_request(agent, b"POST", addr, body, |
|
|
|
|
self.process_unlock_response) |
|
|
|
|
|
|
|
|
|
# 7. Unlock the second wallet again |
|
|
|
|
addr = root + "/wallet/" + wfn2 + "/unlock" |
|
|
|
|
addr = addr.encode() |
|
|
|
|
body = BytesProducer(json.dumps({"password": "hunter3"}).encode()) |
|
|
|
|
yield self.do_request(agent, b"POST", addr, body, |
|
|
|
|
self.process_unlock_response) |
|
|
|
|
|
|
|
|
|
def process_create_wallet_response(self, response, code): |
|
|
|
|
assert code == 201 |
|
|
|
|
json_body = json.loads(response.decode("utf-8")) |
|
|
|
|
assert json_body["walletname"] == testfileloc |
|
|
|
|
assert json_body["walletname"] in self.wfnames |
|
|
|
|
self.jwt_token = json_body["token"] |
|
|
|
|
# we don't use this in test, but it must exist: |
|
|
|
|
assert json_body["seedphrase"] |
|
|
|
|
@ -207,7 +248,7 @@ class TrialTestWRPC_DisplayWallet(WalletRPCTestBase, unittest.TestCase):
|
|
|
|
|
def process_list_wallets_response(self, body, code): |
|
|
|
|
assert code == 200 |
|
|
|
|
json_body = json.loads(body.decode("utf-8")) |
|
|
|
|
assert json_body["wallets"] == [testfileloc] |
|
|
|
|
assert set(json_body["wallets"]) == set(self.wfnames) |
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
def test_direct_send_and_display_wallet(self): |
|
|
|
|
@ -369,13 +410,13 @@ class TrialTestWRPC_DisplayWallet(WalletRPCTestBase, unittest.TestCase):
|
|
|
|
|
def process_unlock_response(self, response, code): |
|
|
|
|
assert code == 200 |
|
|
|
|
json_body = json.loads(response.decode("utf-8")) |
|
|
|
|
assert json_body["walletname"] == testfileloc |
|
|
|
|
assert json_body["walletname"] in self.wfnames |
|
|
|
|
self.jwt_token = json_body["token"] |
|
|
|
|
|
|
|
|
|
def process_lock_response(self, response, code): |
|
|
|
|
assert code == 200 |
|
|
|
|
json_body = json.loads(response.decode("utf-8")) |
|
|
|
|
assert json_body["walletname"] == testfileloc |
|
|
|
|
assert json_body["walletname"] in self.wfnames |
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
def test_do_coinjoin(self): |
|
|
|
|
|