@@ -31,7 +31,7 @@ TEST_CASE("Multiple versions of NodeInfoNetwork")
3131
3232 ccf::NodeInfoNetwork_v1 v1;
3333 std::tie (v1.nodehost , v1.nodeport ) = ccf::split_net_address (node);
34- std::tie (v1.rpchost , v1.nodeport ) = ccf::split_net_address (rpc_a);
34+ std::tie (v1.rpchost , v1.rpcport ) = ccf::split_net_address (rpc_a);
3535 std::tie (v1.pubhost , v1.pubport ) = ccf::split_net_address (rpc_b);
3636
3737 {
@@ -41,56 +41,58 @@ TEST_CASE("Multiple versions of NodeInfoNetwork")
4141 REQUIRE (current == converted);
4242 }
4343
44+ // to_json(NodeInfoNetwork) NEVER writes v1 fields now
45+ // No current node should be using v1 anymore
4446 {
45- INFO (" Old format survives round-trip through current " );
47+ INFO (" Old format loses old fields when converted to new format " );
4648 nlohmann::json j = v1;
47- const auto intermediate = j.get <ccf::NodeInfoNetwork>();
48- nlohmann::json j2 = intermediate;
49- const auto converted = j2.get <ccf::NodeInfoNetwork_v1>();
50-
51- // Manual equality check - not implementing it now for a deprecated format
52- REQUIRE (v1.nodehost == converted.nodehost );
53- REQUIRE (v1.nodeport == converted.nodeport );
54- REQUIRE (v1.rpchost == converted.rpchost );
55- REQUIRE (v1.rpcport == converted.rpcport );
56- REQUIRE (v1.pubhost == converted.pubhost );
57- REQUIRE (v1.pubport == converted.pubport );
49+ nlohmann::json converted;
50+ to_json (converted, j.get <ccf::NodeInfoNetwork>());
51+ const auto dumped_converted = converted.dump ();
52+ const auto deserialized_converted = nlohmann::json::parse (dumped_converted);
53+
54+ // v1 fields are not present anymore
55+ REQUIRE (!deserialized_converted.contains (" nodehost" ));
56+ REQUIRE (!deserialized_converted.contains (" nodeport" ));
57+ REQUIRE (!deserialized_converted.contains (" rpchost" ));
58+ REQUIRE (!deserialized_converted.contains (" rpcport" ));
59+ REQUIRE (!deserialized_converted.contains (" pubhost" ));
60+ REQUIRE (!deserialized_converted.contains (" pubport" ));
61+
62+ const auto new_converted =
63+ deserialized_converted.get <ccf::NodeInfoNetwork>();
64+
65+ // v2 fields have been constructed correctly
66+ REQUIRE (
67+ new_converted.node_to_node_interface .bind_address ==
68+ ccf::NodeInfoNetwork::NetAddress (v1.nodehost + " :" + v1.nodeport ));
69+ REQUIRE (
70+ new_converted.node_to_node_interface .published_address ==
71+ ccf::NodeInfoNetwork::NetAddress (v1.nodehost + " :" + v1.nodeport ));
72+
73+ REQUIRE (new_converted.rpc_interfaces .size () == 1 );
74+ const auto & primary_rpc_it =
75+ new_converted.rpc_interfaces .find (ccf::PRIMARY_RPC_INTERFACE);
76+ const auto & primary_rpc = primary_rpc_it->second ;
77+ REQUIRE (
78+ primary_rpc.bind_address ==
79+ ccf::NodeInfoNetwork::NetAddress (v1.rpchost + " :" + v1.rpcport ));
80+ REQUIRE (
81+ primary_rpc.published_address ==
82+ ccf::NodeInfoNetwork::NetAddress (v1.pubhost + " :" + v1.pubport ));
5883 }
5984
85+ // Test that slightly malformed v2 JSON does not get misparsed as v1
86+ // and triggers an exception instead, for example when an unknown
87+ // operator feature is present
6088 {
61- INFO (
62- " Current format loses some information when round-tripping through old" );
89+ INFO (" Malformed new format does not get misparsed as old format" );
6390 nlohmann::json j = current;
64- const auto intermediate = j.get <ccf::NodeInfoNetwork_v1>();
65- nlohmann::json j2 = intermediate;
66- const auto converted = j2.get <ccf::NodeInfoNetwork>();
67- REQUIRE (!(current == converted));
68-
69- // The node information has been kept
70- REQUIRE (current.node_to_node_interface == converted.node_to_node_interface );
71-
72- // Only the _first_ RPC interface has kept its addresses, though lost its
73- // sessions caps
74- REQUIRE (converted.rpc_interfaces .size () > 0 );
75-
76- const auto & current_interface = current.rpc_interfaces .begin ()->second ;
77- const auto & converted_interface =
78- converted.rpc_interfaces .at (ccf::PRIMARY_RPC_INTERFACE);
79-
80- REQUIRE (current_interface.bind_address == converted_interface.bind_address );
81- REQUIRE (
82- current_interface.published_address ==
83- converted_interface.published_address );
84- REQUIRE (
85- current_interface.max_open_sessions_hard !=
86- converted_interface.max_open_sessions_hard );
87- REQUIRE (
88- current_interface.max_open_sessions_soft !=
89- converted_interface.max_open_sessions_soft );
91+ // Inject an unknown operator feature to make the JSON invalid for v2
92+ j[" node_to_node_interface" ][" enabled_operator_features" ].push_back (
93+ " UnknownFeature" );
9094
91- // The second RPC interface has been lost
92- REQUIRE (converted.rpc_interfaces .size () == 1 );
93- REQUIRE (converted.rpc_interfaces .size () < current.rpc_interfaces .size ());
95+ REQUIRE_THROWS_AS (j.get <ccf::NodeInfoNetwork>(), ccf::JsonParseError);
9496 }
9597
9698 {
0 commit comments