2019-12-08 22:43:49 +01:00
|
|
|
import time
|
|
|
|
from typing import Optional, Dict, List, Tuple, Any
|
2021-09-07 19:57:18 +02:00
|
|
|
from typing_extensions import Final
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
from bemani.client.common import random_hex_string
|
|
|
|
from bemani.client.protocol import ClientProtocol
|
|
|
|
from bemani.protocol import Node
|
|
|
|
|
|
|
|
|
|
|
|
class BaseClient:
|
|
|
|
"""
|
|
|
|
The base client that all client emulators subclass from. This includes
|
|
|
|
a lot of functionality to create cards, exchange packets, verify responses
|
|
|
|
and verify some basic packets that are always expected to work.
|
|
|
|
"""
|
|
|
|
|
2021-09-07 19:57:18 +02:00
|
|
|
CARD_OK: Final[int] = 0
|
|
|
|
CARD_NEW: Final[int] = 112
|
|
|
|
CARD_BAD_PIN: Final[int] = 116
|
|
|
|
CARD_NOT_ALLOWED: Final[int] = 110
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
CORRECT_PASSWORD: Final[str] = "1234"
|
|
|
|
WRONG_PASSWORD: Final[str] = "4321"
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
def __init__(
|
|
|
|
self, proto: ClientProtocol, pcbid: str, config: Dict[str, Any]
|
|
|
|
) -> None:
|
2019-12-08 22:43:49 +01:00
|
|
|
self.__proto = proto
|
|
|
|
self.pcbid = pcbid
|
|
|
|
self.config = config
|
|
|
|
|
|
|
|
def random_card(self) -> str:
|
|
|
|
return "E004" + random_hex_string(12, caps=True)
|
|
|
|
|
|
|
|
def call_node(self) -> Node:
|
2022-10-15 20:56:30 +02:00
|
|
|
call = Node.void("call")
|
|
|
|
call.set_attribute("model", self.config["model"])
|
|
|
|
call.set_attribute("srcid", self.pcbid)
|
|
|
|
call.set_attribute("tag", random_hex_string(8))
|
2019-12-08 22:43:49 +01:00
|
|
|
return call
|
|
|
|
|
|
|
|
def exchange(self, path: str, tree: Node) -> Node:
|
|
|
|
module = tree.children[0].name
|
2022-10-15 20:56:30 +02:00
|
|
|
method = tree.children[0].attribute("method")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
return self.__proto.exchange(
|
2020-01-07 22:29:07 +01:00
|
|
|
f'{path}?model={self.config["model"]}&module={module}&method={method}',
|
2019-12-08 22:43:49 +01:00
|
|
|
tree,
|
|
|
|
)
|
|
|
|
|
|
|
|
def __assert_path(self, root: Node, path: str) -> bool:
|
2022-10-15 20:56:30 +02:00
|
|
|
parts = path.split("/")
|
2019-12-08 22:43:49 +01:00
|
|
|
children = [root]
|
|
|
|
node: Optional[Node] = None
|
|
|
|
|
|
|
|
for part in parts:
|
2022-10-15 20:56:30 +02:00
|
|
|
if part[0] == "@":
|
2019-12-08 22:43:49 +01:00
|
|
|
# Verify attribute, should be last part in chain so
|
|
|
|
# assume its the first node
|
|
|
|
if node is None:
|
|
|
|
return False
|
|
|
|
if part[1:] not in node.attributes:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
# Verify node name, might be last in chain
|
|
|
|
found = False
|
|
|
|
for child in children:
|
|
|
|
if child.name == part:
|
|
|
|
# This is a valid node, set to children and keep going
|
|
|
|
children = child.children
|
|
|
|
node = child
|
|
|
|
found = True
|
|
|
|
break
|
|
|
|
|
|
|
|
if not found:
|
|
|
|
# Didn't find a noce named this
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Traversed whole chain
|
|
|
|
return True
|
|
|
|
|
|
|
|
def assert_path(self, root: Node, path: str) -> None:
|
|
|
|
"""
|
|
|
|
Given a root node and a path string such as a/b/node or a/b/@attr,
|
|
|
|
validate that the root node has decendents that match the path.
|
|
|
|
As a convenience, you can check an attribute on a node with @attr
|
|
|
|
format, where <attr> is the string name of the attribute.
|
|
|
|
"""
|
|
|
|
|
|
|
|
if not self.__assert_path(root, path):
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(f"Path '{path}' not found in root node:\n{root}")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
def verify_services_get(
|
|
|
|
self, expected_services: List[str] = [], include_net: bool = False
|
|
|
|
) -> None:
|
2019-12-08 22:43:49 +01:00
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
services = Node.void("services")
|
2019-12-08 22:43:49 +01:00
|
|
|
call.add_child(services)
|
2022-10-15 20:56:30 +02:00
|
|
|
services.set_attribute("method", "get")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
if self.config["avs"] is not None:
|
2019-12-08 22:43:49 +01:00
|
|
|
# Some older games don't include this info
|
2022-10-15 20:56:30 +02:00
|
|
|
info = Node.void("info")
|
2019-12-08 22:43:49 +01:00
|
|
|
services.add_child(info)
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
info.add_child(Node.string("AVS2", self.config["avs"]))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-03 04:10:43 +02:00
|
|
|
if include_net:
|
2022-10-15 20:56:30 +02:00
|
|
|
net = Node.void("net")
|
2022-10-03 04:10:43 +02:00
|
|
|
services.add_child(net)
|
2022-10-15 20:56:30 +02:00
|
|
|
iface = Node.void("if")
|
2022-10-03 04:10:43 +02:00
|
|
|
net.add_child(iface)
|
2022-10-15 20:56:30 +02:00
|
|
|
iface.add_child(Node.u8("id", 0))
|
|
|
|
iface.add_child(Node.bool("valid", True))
|
|
|
|
iface.add_child(Node.u8("type", 1))
|
|
|
|
iface.add_child(Node.u8_array("mac", [1, 2, 3, 4, 5, 6]))
|
|
|
|
iface.add_child(Node.ipv4("addr", "10.0.0.100"))
|
|
|
|
iface.add_child(Node.ipv4("bcast", "10.0.0.255"))
|
|
|
|
iface.add_child(Node.ipv4("netmask", "255.255.255.0"))
|
|
|
|
iface.add_child(Node.ipv4("gateway", "10.0.0.1"))
|
|
|
|
iface.add_child(Node.ipv4("dhcp", "10.0.0.1"))
|
2022-10-03 04:10:43 +02:00
|
|
|
|
2019-12-08 22:43:49 +01:00
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
resp = self.exchange("core/services", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Verify that response is correct
|
|
|
|
self.assert_path(resp, "response/services")
|
2022-10-15 20:56:30 +02:00
|
|
|
items = resp.child("services").children
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
returned_services = []
|
|
|
|
for item in items:
|
|
|
|
# Make sure it is an item with a url component
|
2022-10-15 20:56:30 +02:00
|
|
|
self.assert_path(item, "item/@url")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Get list of services provided
|
2022-10-15 20:56:30 +02:00
|
|
|
returned_services.append(item.attribute("name"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
for service in expected_services:
|
|
|
|
if service not in returned_services:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(f"Service '{service}' expected but not returned")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def verify_pcbtracker_alive(self, ecflag: int = 1) -> bool:
|
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
pcbtracker = Node.void("pcbtracker")
|
2019-12-08 22:43:49 +01:00
|
|
|
call.add_child(pcbtracker)
|
2022-10-15 20:56:30 +02:00
|
|
|
pcbtracker.set_attribute("accountid", self.pcbid)
|
|
|
|
pcbtracker.set_attribute("ecflag", str(ecflag))
|
|
|
|
pcbtracker.set_attribute("hardid", "01000027584F6D3A")
|
|
|
|
pcbtracker.set_attribute("method", "alive")
|
|
|
|
pcbtracker.set_attribute("softid", "00010203040506070809")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
resp = self.exchange("core/pcbtracker", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Verify that response is correct
|
|
|
|
self.assert_path(resp, "response/pcbtracker/@ecenable")
|
|
|
|
|
|
|
|
# Print out setting
|
2022-10-15 20:56:30 +02:00
|
|
|
enable = int(resp.child("pcbtracker").attribute("ecenable"))
|
2019-12-08 22:43:49 +01:00
|
|
|
if enable != 0:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def verify_message_get(self) -> None:
|
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
message = Node.void("message")
|
2019-12-08 22:43:49 +01:00
|
|
|
call.add_child(message)
|
2022-10-15 20:56:30 +02:00
|
|
|
message.set_attribute("method", "get")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
resp = self.exchange("core/message", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Verify that response is correct
|
|
|
|
self.assert_path(resp, "response/message/@status")
|
|
|
|
|
|
|
|
def verify_dlstatus_progress(self) -> None:
|
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
dlstatus = Node.void("dlstatus")
|
2019-12-08 22:43:49 +01:00
|
|
|
call.add_child(dlstatus)
|
2022-10-15 20:56:30 +02:00
|
|
|
dlstatus.set_attribute("method", "progress")
|
|
|
|
dlstatus.add_child(Node.s32("progress", 0))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
resp = self.exchange("core/dlstatus", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Verify that response is correct
|
|
|
|
self.assert_path(resp, "response/dlstatus/@status")
|
|
|
|
|
|
|
|
def verify_package_list(self) -> None:
|
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
package = Node.void("package")
|
2019-12-08 22:43:49 +01:00
|
|
|
call.add_child(package)
|
2022-10-15 20:56:30 +02:00
|
|
|
package.set_attribute("method", "list")
|
|
|
|
package.set_attribute("pkgtype", "all")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
resp = self.exchange("core/package", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Verify that response is correct
|
|
|
|
self.assert_path(resp, "response/package")
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
def verify_facility_get(self, encoding: str = "SHIFT_JIS") -> str:
|
2019-12-08 22:43:49 +01:00
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
facility = Node.void("facility")
|
2019-12-08 22:43:49 +01:00
|
|
|
call.add_child(facility)
|
2022-10-15 20:56:30 +02:00
|
|
|
facility.set_attribute("encoding", encoding)
|
|
|
|
facility.set_attribute("method", "get")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
resp = self.exchange("core/facility", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Verify that response is correct
|
|
|
|
self.assert_path(resp, "response/facility/location/id")
|
|
|
|
self.assert_path(resp, "response/facility/line")
|
|
|
|
self.assert_path(resp, "response/facility/portfw")
|
|
|
|
self.assert_path(resp, "response/facility/public")
|
|
|
|
self.assert_path(resp, "response/facility/share")
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
return resp.child_value("facility/location/id")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def verify_pcbevent_put(self) -> None:
|
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
pcbevent = Node.void("pcbevent")
|
2019-12-08 22:43:49 +01:00
|
|
|
call.add_child(pcbevent)
|
2022-10-15 20:56:30 +02:00
|
|
|
pcbevent.set_attribute("method", "put")
|
|
|
|
pcbevent.add_child(Node.time("time", int(time.time())))
|
|
|
|
pcbevent.add_child(Node.u32("seq", 0))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
item = Node.void("item")
|
2019-12-08 22:43:49 +01:00
|
|
|
pcbevent.add_child(item)
|
2022-10-15 20:56:30 +02:00
|
|
|
item.add_child(Node.string("name", "boot"))
|
|
|
|
item.add_child(Node.s32("value", 1))
|
|
|
|
item.add_child(Node.time("time", int(time.time())))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
resp = self.exchange("core/pcbevent", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Verify that response is correct
|
|
|
|
self.assert_path(resp, "response/pcbevent")
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
def verify_cardmng_inquire(
|
|
|
|
self, card_id: str, msg_type: str, paseli_enabled: bool
|
|
|
|
) -> Optional[str]:
|
2019-12-08 22:43:49 +01:00
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
cardmng = Node.void("cardmng")
|
2019-12-08 22:43:49 +01:00
|
|
|
call.add_child(cardmng)
|
2022-10-15 20:56:30 +02:00
|
|
|
cardmng.set_attribute("cardid", card_id)
|
|
|
|
cardmng.set_attribute("cardtype", "1")
|
|
|
|
cardmng.set_attribute("method", "inquire")
|
|
|
|
cardmng.set_attribute("update", "0")
|
|
|
|
if msg_type == "new" and "old_profile_model" in self.config:
|
|
|
|
cardmng.set_attribute("model", self.config["old_profile_model"])
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
resp = self.exchange("core/cardmng", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
if msg_type == "unregistered":
|
2019-12-08 22:43:49 +01:00
|
|
|
# Verify that response is correct
|
|
|
|
self.assert_path(resp, "response/cardmng/@status")
|
|
|
|
|
|
|
|
# Verify that we weren't found
|
2022-10-15 20:56:30 +02:00
|
|
|
status = int(resp.child("cardmng").attribute("status"))
|
2019-12-08 22:43:49 +01:00
|
|
|
if status != self.CARD_NEW:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(f"Card '{card_id}' returned invalid status '{status}'")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Nothing to return
|
|
|
|
return None
|
2022-10-15 20:56:30 +02:00
|
|
|
elif msg_type == "new":
|
2019-12-08 22:43:49 +01:00
|
|
|
# Verify that response is correct
|
|
|
|
self.assert_path(resp, "response/cardmng/@refid")
|
|
|
|
self.assert_path(resp, "response/cardmng/@binded")
|
|
|
|
self.assert_path(resp, "response/cardmng/@newflag")
|
|
|
|
self.assert_path(resp, "response/cardmng/@ecflag")
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
binded = int(resp.child("cardmng").attribute("binded"))
|
|
|
|
newflag = int(resp.child("cardmng").attribute("newflag"))
|
|
|
|
ecflag = int(resp.child("cardmng").attribute("ecflag"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
if binded != 0:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(
|
|
|
|
f"Card '{card_id}' returned invalid binded value '{binded}'"
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
if newflag != 1:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(
|
|
|
|
f"Card '{card_id}' returned invalid newflag value '{newflag}'"
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
if ecflag != (1 if paseli_enabled else 0):
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(
|
|
|
|
f"Card '{card_id}' returned invalid ecflag value '{newflag}'"
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Return the refid
|
2022-10-15 20:56:30 +02:00
|
|
|
return resp.child("cardmng").attribute("refid")
|
|
|
|
elif msg_type == "query":
|
2019-12-08 22:43:49 +01:00
|
|
|
# Verify that response is correct
|
|
|
|
self.assert_path(resp, "response/cardmng/@refid")
|
|
|
|
self.assert_path(resp, "response/cardmng/@binded")
|
|
|
|
self.assert_path(resp, "response/cardmng/@newflag")
|
|
|
|
self.assert_path(resp, "response/cardmng/@ecflag")
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
binded = int(resp.child("cardmng").attribute("binded"))
|
|
|
|
newflag = int(resp.child("cardmng").attribute("newflag"))
|
|
|
|
ecflag = int(resp.child("cardmng").attribute("ecflag"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
if binded != 1:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(
|
|
|
|
f"Card '{card_id}' returned invalid binded value '{binded}'"
|
|
|
|
)
|
2021-09-03 06:34:51 +02:00
|
|
|
if newflag != 0:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(
|
|
|
|
f"Card '{card_id}' returned invalid newflag value '{newflag}'"
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
if ecflag != (1 if paseli_enabled else 0):
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(
|
|
|
|
f"Card '{card_id}' returned invalid ecflag value '{newflag}'"
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Return the refid
|
2022-10-15 20:56:30 +02:00
|
|
|
return resp.child("cardmng").attribute("refid")
|
2019-12-08 22:43:49 +01:00
|
|
|
else:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(f"Unrecognized message type '{msg_type}'")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def verify_cardmng_getrefid(self, card_id: str) -> str:
|
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
cardmng = Node.void("cardmng")
|
2019-12-08 22:43:49 +01:00
|
|
|
call.add_child(cardmng)
|
2022-10-15 20:56:30 +02:00
|
|
|
cardmng.set_attribute("cardid", card_id)
|
|
|
|
cardmng.set_attribute("cardtype", "1")
|
|
|
|
cardmng.set_attribute("method", "getrefid")
|
|
|
|
cardmng.set_attribute("newflag", "0")
|
|
|
|
cardmng.set_attribute("passwd", self.CORRECT_PASSWORD)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
resp = self.exchange("core/cardmng", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Verify that response is correct
|
|
|
|
self.assert_path(resp, "response/cardmng/@refid")
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
return resp.child("cardmng").attribute("refid")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def verify_cardmng_authpass(self, ref_id: str, correct: bool) -> None:
|
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
cardmng = Node.void("cardmng")
|
2019-12-08 22:43:49 +01:00
|
|
|
call.add_child(cardmng)
|
2022-10-15 20:56:30 +02:00
|
|
|
cardmng.set_attribute("method", "authpass")
|
|
|
|
cardmng.set_attribute(
|
|
|
|
"pass", self.CORRECT_PASSWORD if correct else self.CORRECT_PASSWORD[::-1]
|
|
|
|
)
|
|
|
|
cardmng.set_attribute("refid", ref_id)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
resp = self.exchange("core/cardmng", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Verify that response is correct
|
|
|
|
self.assert_path(resp, "response/cardmng/@status")
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
status = int(resp.child("cardmng").attribute("status"))
|
2019-12-08 22:43:49 +01:00
|
|
|
if status != (self.CARD_OK if correct else self.CARD_BAD_PIN):
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(f"Ref ID '{ref_id}' returned invalid status '{status}'")
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def verify_eacoin_checkin(self, card_id: str) -> Tuple[str, int]:
|
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
eacoin = Node.void("eacoin")
|
2019-12-08 22:43:49 +01:00
|
|
|
call.add_child(eacoin)
|
2022-10-15 20:56:30 +02:00
|
|
|
eacoin.set_attribute("method", "checkin")
|
|
|
|
eacoin.add_child(Node.string("cardtype", "1"))
|
|
|
|
eacoin.add_child(Node.string("cardid", card_id))
|
|
|
|
eacoin.add_child(Node.string("passwd", self.CORRECT_PASSWORD))
|
|
|
|
eacoin.add_child(Node.string("ectype", "1"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
resp = self.exchange("core/eacoin", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Verify that response is correct
|
|
|
|
self.assert_path(resp, "response/eacoin/sessid")
|
|
|
|
self.assert_path(resp, "response/eacoin/balance")
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
return (
|
|
|
|
resp.child("eacoin").child_value("sessid"),
|
|
|
|
resp.child("eacoin").child_value("balance"),
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def verify_eacoin_consume(self, sessid: str, balance: int, amount: int) -> None:
|
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
eacoin = Node.void("eacoin")
|
2019-12-08 22:43:49 +01:00
|
|
|
call.add_child(eacoin)
|
2022-10-15 20:56:30 +02:00
|
|
|
eacoin.set_attribute("method", "consume")
|
|
|
|
eacoin.add_child(Node.string("sessid", sessid))
|
|
|
|
eacoin.add_child(Node.s16("sequence", 0))
|
|
|
|
eacoin.add_child(Node.s32("payment", amount))
|
|
|
|
eacoin.add_child(Node.s32("service", 0))
|
|
|
|
eacoin.add_child(Node.string("itemtype", "0"))
|
|
|
|
eacoin.add_child(Node.string("detail", "/eacoin/start_pt1"))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
resp = self.exchange("core/eacoin", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Verify that response is correct
|
|
|
|
self.assert_path(resp, "response/eacoin/balance")
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
newbalance = resp.child("eacoin").child_value("balance")
|
2019-12-08 22:43:49 +01:00
|
|
|
if balance - amount != newbalance:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(
|
|
|
|
f"Expected to get back balance {balance - amount} but got {newbalance}"
|
|
|
|
)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def verify_eacoin_checkout(self, session: str) -> None:
|
|
|
|
call = self.call_node()
|
|
|
|
|
|
|
|
# Construct node
|
2022-10-15 20:56:30 +02:00
|
|
|
eacoin = Node.void("eacoin")
|
2019-12-08 22:43:49 +01:00
|
|
|
call.add_child(eacoin)
|
2022-10-15 20:56:30 +02:00
|
|
|
eacoin.set_attribute("method", "checkout")
|
|
|
|
eacoin.add_child(Node.string("sessid", session))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Swap with server
|
2022-10-15 20:56:30 +02:00
|
|
|
resp = self.exchange("core/eacoin", call)
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
# Verify that response is correct
|
|
|
|
self.assert_path(resp, "response/eacoin/@status")
|
|
|
|
|
|
|
|
def verify(self, cardid: Optional[str]) -> None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception("Override in subclass!")
|