From 747c15ec9f161298ef2f9872dbd9aa6b3c05d83a Mon Sep 17 00:00:00 2001 From: Eddy Ashton Date: Mon, 18 Nov 2019 15:27:29 +0000 Subject: [PATCH 1/4] Use msgpack's decoder --- tests/infra/jsonrpc.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/tests/infra/jsonrpc.py b/tests/infra/jsonrpc.py index d94fb5466ee..448fb1983ba 100644 --- a/tests/infra/jsonrpc.py +++ b/tests/infra/jsonrpc.py @@ -108,27 +108,14 @@ def to_dict(self): return d def _from_parsed(self, parsed): - def decode(sl, is_key=False): - if is_key and hasattr(sl, "decode"): - return sl.decode() - if hasattr(sl, "items"): - return {decode(k, is_key=True): decode(v) for k, v in sl.items()} - elif isinstance(sl, list): - return [decode(e) for e in sl] - else: - return sl - - parsed_s = { - decode(attr, is_key=True): decode(value) for attr, value in parsed.items() - } - unexpected = parsed_s.keys() - self._attrs + unexpected = parsed.keys() - self._attrs if unexpected: raise ValueError("Unexpected keys in response: {}".format(unexpected)) - for attr, value in parsed_s.items(): + for attr, value in parsed.items(): setattr(self, attr, value) def from_msgpack(self, data): - parsed = msgpack.unpackb(data) + parsed = msgpack.unpackb(data, raw=False) self._from_parsed(parsed) def from_json(self, data): From c106f52bf2f5f97dab40de6da58f5ec2946bbf63 Mon Sep 17 00:00:00 2001 From: Eddy Ashton Date: Mon, 18 Nov 2019 15:27:47 +0000 Subject: [PATCH 2/4] raw quote is a byte-array, not string --- src/node/nodestate.h | 2 +- src/node/rpc/nodecalltypes.h | 4 ++-- tests/governance.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/node/nodestate.h b/src/node/nodestate.h index 642f11e9a49..7dcdfa69b3e 100644 --- a/src/node/nodestate.h +++ b/src/node/nodestate.h @@ -1073,7 +1073,7 @@ namespace ccf { GetQuotes::Quote quote; quote.node_id = nid; - quote.raw = std::string(ni.quote.begin(), ni.quote.end()); + quote.raw = ni.quote; #ifdef GET_QUOTE oe_report_t parsed_quote = {0}; diff --git a/src/node/rpc/nodecalltypes.h b/src/node/rpc/nodecalltypes.h index a5582678968..b6354dd2a63 100644 --- a/src/node/rpc/nodecalltypes.h +++ b/src/node/rpc/nodecalltypes.h @@ -35,10 +35,10 @@ namespace ccf struct Quote { NodeId node_id = {}; - std::string raw = {}; + std::vector raw = {}; std::string error = {}; - std::string mrenclave = {}; + std::string mrenclave = {}; // < Hex-encoded }; struct Out diff --git a/tests/governance.py b/tests/governance.py index 2545ee2a0bc..31a19488725 100644 --- a/tests/governance.py +++ b/tests/governance.py @@ -36,7 +36,7 @@ def run(args): assert len(quotes) == len(hosts) primary_quote = quotes[0] assert primary_quote["node_id"] == 0 - mrenclave = primary_quote["mrenclave"].decode() + mrenclave = primary_quote["mrenclave"] oed = subprocess.run( [args.oesign, "dump", "-e", f"{args.package}.so.signed"], From 3bfeb84af64f187e795a07b01a9fcc49a5f6d120 Mon Sep 17 00:00:00 2001 From: Eddy Ashton Date: Mon, 18 Nov 2019 15:32:17 +0000 Subject: [PATCH 3/4] Schema changed --- sphinx/source/schemas/getQuotes_result.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sphinx/source/schemas/getQuotes_result.json b/sphinx/source/schemas/getQuotes_result.json index 1a5db621d3f..844653568f0 100644 --- a/sphinx/source/schemas/getQuotes_result.json +++ b/sphinx/source/schemas/getQuotes_result.json @@ -16,7 +16,12 @@ "type": "number" }, "raw": { - "type": "string" + "items": { + "maximum": 255, + "minimum": 0, + "type": "number" + }, + "type": "array" } }, "required": [ From 1170502cfeb517525b1827868c7e0dea110d0fd0 Mon Sep 17 00:00:00 2001 From: Eddy Ashton Date: Mon, 18 Nov 2019 16:47:36 +0000 Subject: [PATCH 4/4] Remove manual re-encode --- .../txregulator/tests/txregulatorclient.py | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/samples/apps/txregulator/tests/txregulatorclient.py b/samples/apps/txregulator/tests/txregulatorclient.py index ef0c3cfe1f0..6f204fa73f7 100644 --- a/samples/apps/txregulator/tests/txregulatorclient.py +++ b/samples/apps/txregulator/tests/txregulatorclient.py @@ -61,7 +61,7 @@ def run(args): ) check( c.rpc("REG_get", {"id": regulator[0]}), - result=[regulator[1].encode(), regulator[2].encode()], + result=[regulator[1], regulator[2]], ) check( @@ -77,7 +77,7 @@ def run(args): check = infra.checker.Checker() check(c.rpc("BK_register", {"country": bank[1]}), result=bank[0]) - check(c.rpc("BK_get", {"id": bank[0]}), result=bank[1].encode()) + check(c.rpc("BK_get", {"id": bank[0]}), result=bank[1]) check( c.rpc("REG_register", {"country": bank[1]}), @@ -109,31 +109,31 @@ def run(args): check( c.rpc("TX_get", {"tx_id": tx_id}), result={ - "amt": amount.encode(), + "amt": amount, "bank_id": bank[0], - "dst": transaction["dst"].encode(), - "dst_country": transaction["dst_country"].encode(), - "src": transaction["src"].encode(), - "src_country": transaction["src_country"].encode(), - "timestamp": transaction["timestamp"].encode(), - "type": transaction["type"].encode(), + "dst": transaction["dst"], + "dst_country": transaction["dst_country"], + "src": transaction["src"], + "src_country": transaction["src_country"], + "timestamp": transaction["timestamp"], + "type": transaction["type"], }, ) if float(amount) > flagged_amt: check( c.rpc("FLAGGED_TX_get", {"tx_id": tx_id}), - result=[reg_id, False, transaction["timestamp"].encode()], + result=[reg_id, False, transaction["timestamp"]], ) flagged_tx = { - "amt": amount.encode(), + "amt": amount, "bank_id": bank[0], - "dst": transaction["dst"].encode(), - "dst_country": transaction["dst_country"].encode(), - "src": transaction["src"].encode(), - "src_country": transaction["src_country"].encode(), - "timestamp": transaction["timestamp"].encode(), + "dst": transaction["dst"], + "dst_country": transaction["dst_country"], + "src": transaction["src"], + "src_country": transaction["src_country"], + "timestamp": transaction["timestamp"], "tx_id": tx_id, - "type": transaction["type"].encode(), + "type": transaction["type"], } flagged_ids.append(tx_id) flagged_txs[tx_id] = flagged_tx