@@ -1451,6 +1451,7 @@ const std::vector<TreeOperationsTestVector::Scenario>
14511451TreeOperationsTestVector::TreeOperationsTestVector (mls::CipherSuite suite,
14521452 Scenario scenario)
14531453 : PseudoRandom(suite, " tree-operations" )
1454+ , cipher_suite(suite)
14541455 , proposal_sender(0 )
14551456{
14561457 auto init_priv = prg.hpke_key (" init_key" );
@@ -1480,6 +1481,7 @@ TreeOperationsTestVector::TreeOperationsTestVector(mls::CipherSuite suite,
14801481 proposal = Proposal{ Add{ key_package } };
14811482
14821483 tree_before = tc.pub ;
1484+ tree_hash_before = tree_before.root_hash ();
14831485
14841486 tree_after = tree_before;
14851487 tree_after.add_leaf (key_package.leaf_node );
@@ -1493,6 +1495,8 @@ TreeOperationsTestVector::TreeOperationsTestVector(mls::CipherSuite suite,
14931495
14941496 tree_before = tc.pub ;
14951497 tree_before.blank_path (LeafIndex{ 4 });
1498+ tree_before.set_hash_all ();
1499+ tree_hash_before = tree_before.root_hash ();
14961500
14971501 tree_after = tree_before;
14981502 tree_after.add_leaf (key_package.leaf_node );
@@ -1506,6 +1510,7 @@ TreeOperationsTestVector::TreeOperationsTestVector(mls::CipherSuite suite,
15061510 proposal = Proposal{ Update{ key_package.leaf_node } };
15071511
15081512 tree_before = tc.pub ;
1513+ tree_hash_before = tree_before.root_hash ();
15091514
15101515 tree_after = tree_before;
15111516 tree_after.update_leaf (proposal_sender, key_package.leaf_node );
@@ -1519,6 +1524,7 @@ TreeOperationsTestVector::TreeOperationsTestVector(mls::CipherSuite suite,
15191524 proposal = Proposal{ Remove{ removed } };
15201525
15211526 tree_before = tc.pub ;
1527+ tree_hash_before = tree_before.root_hash ();
15221528
15231529 tree_after = tree_before;
15241530 tree_after.blank_path (removed);
@@ -1533,19 +1539,28 @@ TreeOperationsTestVector::TreeOperationsTestVector(mls::CipherSuite suite,
15331539 proposal = Proposal{ Remove{ removed } };
15341540
15351541 tree_before = tc.pub ;
1542+ tree_hash_before = tree_before.root_hash ();
15361543
15371544 tree_after = tree_before;
15381545 tree_after.blank_path (removed);
15391546 tree_after.truncate ();
15401547 break ;
15411548 }
15421549 }
1550+
1551+ tree_after.set_hash_all ();
1552+ tree_hash_after = tree_after.root_hash ();
15431553}
15441554
15451555std::optional<std::string>
1546- TreeOperationsTestVector::verify () const
1556+ TreeOperationsTestVector::verify ()
15471557{
1558+ tree_before.suite = cipher_suite;
1559+ tree_before.set_hash_all ();
1560+
15481561 auto tree = tree_before;
1562+ VERIFY_EQUAL (" tree hash before" , tree.root_hash (), tree_hash_before);
1563+
15491564 auto apply = overloaded{
15501565 [&](const Add& add) { tree.add_leaf (add.key_package .leaf_node ); },
15511566
@@ -1566,6 +1581,9 @@ TreeOperationsTestVector::verify() const
15661581 var::visit (apply, proposal.content );
15671582 VERIFY_EQUAL (" tree after" , tree, tree_after);
15681583
1584+ tree.set_hash_all ();
1585+ VERIFY_EQUAL (" tree hash after" , tree.root_hash (), tree_hash_after);
1586+
15691587 return std::nullopt ;
15701588}
15711589
0 commit comments