rippled
AmendmentTable_test.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/app/misc/AmendmentTable.h>
21 #include <ripple/basics/BasicConfig.h>
22 #include <ripple/basics/Log.h>
23 #include <ripple/basics/chrono.h>
24 #include <ripple/beast/unit_test.h>
25 #include <ripple/core/ConfigSections.h>
26 #include <ripple/protocol/Feature.h>
27 #include <ripple/protocol/PublicKey.h>
28 #include <ripple/protocol/STValidation.h>
29 #include <ripple/protocol/SecretKey.h>
30 #include <ripple/protocol/TxFlags.h>
31 #include <ripple/protocol/digest.h>
32 #include <test/unit_test/SuiteJournal.h>
33 
34 namespace ripple {
35 
36 class AmendmentTable_test final : public beast::unit_test::suite
37 {
38 private:
39  // 204/256 about 80% (we round down because the implementation rounds up)
40  static int const majorityFraction{204};
41 
42  static uint256
44  {
45  sha256_hasher h;
46  using beast::hash_append;
47  hash_append(h, in);
48  auto const d = static_cast<sha256_hasher::result_type>(h);
49  uint256 result;
50  std::memcpy(result.data(), d.data(), d.size());
51  return result;
52  }
53 
55  createSet(int group, int count)
56  {
57  std::vector<std::string> amendments;
58  for (int i = 0; i < count; i++)
59  amendments.push_back(
60  "Amendment" + std::to_string((1000000 * group) + i));
61  return amendments;
62  }
63 
64  static Section
66  {
67  Section section("Test");
68  for (auto const& a : amendments)
69  section.append(to_string(amendmentId(a)) + " " + a);
70  return section;
71  }
72 
73  static Section
74  makeSection(uint256 const& amendment)
75  {
76  Section section("Test");
77  section.append(to_string(amendment) + " " + to_string(amendment));
78  return section;
79  }
80 
86 
88 
90 
91 public:
93  : m_set1(createSet(1, 12))
94  , m_set2(createSet(2, 12))
95  , m_set3(createSet(3, 12))
96  , m_set4(createSet(4, 12))
97  , m_set5(createSet(5, 12))
98  , journal("AmendmentTable_test", *this)
99  {
100  }
101 
104  int w,
105  Section const supported,
106  Section const enabled,
107  Section const vetoed)
108  {
109  return make_AmendmentTable(
110  weeks(w), majorityFraction, supported, enabled, vetoed, journal);
111  }
112 
114  makeTable(int w)
115  {
116  return makeTable(
118  }
119 
120  void
122  {
123  testcase("Construction");
124 
125  auto table = makeTable(1);
126 
127  for (auto const& a : m_set1)
128  {
129  BEAST_EXPECT(table->isSupported(amendmentId(a)));
130  BEAST_EXPECT(!table->isEnabled(amendmentId(a)));
131  }
132 
133  for (auto const& a : m_set2)
134  {
135  BEAST_EXPECT(table->isSupported(amendmentId(a)));
136  BEAST_EXPECT(table->isEnabled(amendmentId(a)));
137  }
138 
139  for (auto const& a : m_set3)
140  {
141  BEAST_EXPECT(!table->isSupported(amendmentId(a)));
142  BEAST_EXPECT(!table->isEnabled(amendmentId(a)));
143  }
144  }
145 
146  void
148  {
149  testcase("Name to ID mapping");
150 
151  auto table = makeTable(1);
152 
153  for (auto const& a : m_set1)
154  BEAST_EXPECT(table->find(a) == amendmentId(a));
155  for (auto const& a : m_set2)
156  BEAST_EXPECT(table->find(a) == amendmentId(a));
157 
158  for (auto const& a : m_set3)
159  BEAST_EXPECT(!table->find(a));
160  for (auto const& a : m_set4)
161  BEAST_EXPECT(!table->find(a));
162  for (auto const& a : m_set5)
163  BEAST_EXPECT(!table->find(a));
164  }
165 
166  void
168  {
169  auto const section = makeSection(m_set1);
170  auto const id = to_string(amendmentId(m_set2[0]));
171 
172  testcase("Bad Config");
173 
174  { // Two arguments are required - we pass one
175  Section test = section;
176  test.append(id);
177 
178  try
179  {
180  if (makeTable(2, test, emptySection, emptySection))
181  fail("Accepted only amendment ID");
182  }
183  catch (...)
184  {
185  pass();
186  }
187  }
188 
189  { // Two arguments are required - we pass three
190  Section test = section;
191  test.append(id + " Test Name");
192 
193  try
194  {
195  if (makeTable(2, test, emptySection, emptySection))
196  fail("Accepted extra arguments");
197  }
198  catch (...)
199  {
200  pass();
201  }
202  }
203 
204  {
205  auto sid = id;
206  sid.resize(sid.length() - 1);
207 
208  Section test = section;
209  test.append(sid + " Name");
210 
211  try
212  {
213  if (makeTable(2, test, emptySection, emptySection))
214  fail("Accepted short amendment ID");
215  }
216  catch (...)
217  {
218  pass();
219  }
220  }
221 
222  {
223  auto sid = id;
224  sid.resize(sid.length() + 1, '0');
225 
226  Section test = section;
227  test.append(sid + " Name");
228 
229  try
230  {
231  if (makeTable(2, test, emptySection, emptySection))
232  fail("Accepted long amendment ID");
233  }
234  catch (...)
235  {
236  pass();
237  }
238  }
239 
240  {
241  auto sid = id;
242  sid.resize(sid.length() - 1);
243  sid.push_back('Q');
244 
245  Section test = section;
246  test.append(sid + " Name");
247 
248  try
249  {
250  if (makeTable(2, test, emptySection, emptySection))
251  fail("Accepted non-hex amendment ID");
252  }
253  catch (...)
254  {
255  pass();
256  }
257  }
258  }
259 
261  getState(AmendmentTable* table, std::set<uint256> const& exclude)
262  {
264 
265  auto track = [&state, table](std::vector<std::string> const& v) {
266  for (auto const& a : v)
267  {
268  auto const id = amendmentId(a);
269  state[id] = table->isEnabled(id);
270  }
271  };
272 
273  track(m_set1);
274  track(m_set2);
275  track(m_set3);
276  track(m_set4);
277  track(m_set5);
278 
279  for (auto const& a : exclude)
280  state.erase(a);
281 
282  return state;
283  }
284 
285  void
287  {
288  testcase("enable & disable");
289 
290  auto const testAmendment = amendmentId("TestAmendment");
291  auto table = makeTable(2);
292 
293  // Subset of amendments to enable
294  std::set<uint256> enabled;
295  enabled.insert(testAmendment);
296  enabled.insert(amendmentId(m_set1[0]));
297  enabled.insert(amendmentId(m_set2[0]));
298  enabled.insert(amendmentId(m_set3[0]));
299  enabled.insert(amendmentId(m_set4[0]));
300  enabled.insert(amendmentId(m_set5[0]));
301 
302  // Get the state before, excluding the items we'll change:
303  auto const pre_state = getState(table.get(), enabled);
304 
305  // Enable the subset and verify
306  for (auto const& a : enabled)
307  table->enable(a);
308 
309  for (auto const& a : enabled)
310  BEAST_EXPECT(table->isEnabled(a));
311 
312  // Disable the subset and verify
313  for (auto const& a : enabled)
314  table->disable(a);
315 
316  for (auto const& a : enabled)
317  BEAST_EXPECT(!table->isEnabled(a));
318 
319  // Get the state after, excluding the items we changed:
320  auto const post_state = getState(table.get(), enabled);
321 
322  // Ensure the states are identical
323  auto ret = std::mismatch(
324  pre_state.begin(),
325  pre_state.end(),
326  post_state.begin(),
327  post_state.end());
328 
329  BEAST_EXPECT(ret.first == pre_state.end());
330  BEAST_EXPECT(ret.second == post_state.end());
331  }
332 
334  makeValidators(int num)
335  {
337  ret.reserve(num);
338  for (int i = 0; i < num; ++i)
339  {
341  }
342  return ret;
343  }
344 
345  static NetClock::time_point
347  {
348  return NetClock::time_point{w};
349  }
350 
351  // Execute a pretend consensus round for a flag ledger
352  void
354  AmendmentTable& table,
355  weeks week,
356  std::vector<std::pair<PublicKey, SecretKey>> const& validators,
357  std::vector<std::pair<uint256, int>> const& votes,
358  std::vector<uint256>& ourVotes,
359  std::set<uint256>& enabled,
360  majorityAmendments_t& majority)
361  {
362  // Do a round at the specified time
363  // Returns the amendments we voted for
364 
365  // Parameters:
366  // table: Our table of known and vetoed amendments
367  // validators: The addreses of validators we trust
368  // votes: Amendments and the number of validators who vote for them
369  // ourVotes: The amendments we vote for in our validation
370  // enabled: In/out enabled amendments
371  // majority: In/our majority amendments (and when they got a majority)
372 
373  auto const roundTime = weekTime(week);
374 
375  // Build validations
377  validations.reserve(validators.size());
378 
379  int i = 0;
380  for (auto const& val : validators)
381  {
382  ++i;
383  std::vector<uint256> field;
384 
385  for (auto const& amendment : votes)
386  {
387  if ((256 * i) < (validators.size() * amendment.second))
388  {
389  // We vote yes on this amendment
390  field.push_back(amendment.first);
391  }
392  }
393 
394  auto v = std::make_shared<STValidation>(
396  val.first,
397  val.second,
398  calcNodeID(val.first),
399  [&field](STValidation& v) {
400  if (!field.empty())
401  v.setFieldV256(
403  });
404 
405  validations.emplace_back(v);
406  }
407 
408  ourVotes = table.doValidation(enabled);
409 
410  auto actions =
411  table.doVoting(roundTime, enabled, majority, validations);
412  for (auto const& action : actions)
413  {
414  // This code assumes other validators do as we do
415 
416  auto const& hash = action.first;
417  switch (action.second)
418  {
419  case 0:
420  // amendment goes from majority to enabled
421  if (enabled.find(hash) != enabled.end())
422  Throw<std::runtime_error>("enabling already enabled");
423  if (majority.find(hash) == majority.end())
424  Throw<std::runtime_error>("enabling without majority");
425  enabled.insert(hash);
426  majority.erase(hash);
427  break;
428 
429  case tfGotMajority:
430  if (majority.find(hash) != majority.end())
431  Throw<std::runtime_error>(
432  "got majority while having majority");
433  majority[hash] = roundTime;
434  break;
435 
436  case tfLostMajority:
437  if (majority.find(hash) == majority.end())
438  Throw<std::runtime_error>(
439  "lost majority without majority");
440  majority.erase(hash);
441  break;
442 
443  default:
444  Throw<std::runtime_error>("unknown action");
445  }
446  }
447  }
448 
449  // No vote on unknown amendment
450  void
452  {
453  testcase("Vote NO on unknown");
454 
455  auto const testAmendment = amendmentId("TestAmendment");
456  auto const validators = makeValidators(10);
457 
458  auto table = makeTable(2, emptySection, emptySection, emptySection);
459 
461  std::vector<uint256> ourVotes;
462  std::set<uint256> enabled;
463  majorityAmendments_t majority;
464 
465  doRound(
466  *table, weeks{1}, validators, votes, ourVotes, enabled, majority);
467  BEAST_EXPECT(ourVotes.empty());
468  BEAST_EXPECT(enabled.empty());
469  BEAST_EXPECT(majority.empty());
470 
471  votes.emplace_back(testAmendment, 256);
472 
473  doRound(
474  *table, weeks{2}, validators, votes, ourVotes, enabled, majority);
475  BEAST_EXPECT(ourVotes.empty());
476  BEAST_EXPECT(enabled.empty());
477 
478  majority[testAmendment] = weekTime(weeks{1});
479 
480  // Note that the simulation code assumes others behave as we do,
481  // so the amendment won't get enabled
482  doRound(
483  *table, weeks{5}, validators, votes, ourVotes, enabled, majority);
484  BEAST_EXPECT(ourVotes.empty());
485  BEAST_EXPECT(enabled.empty());
486  }
487 
488  // No vote on vetoed amendment
489  void
491  {
492  testcase("Vote NO on vetoed");
493 
494  auto const testAmendment = amendmentId("vetoedAmendment");
495 
496  auto table = makeTable(
497  2, emptySection, emptySection, makeSection(testAmendment));
498 
499  auto const validators = makeValidators(10);
500 
502  std::vector<uint256> ourVotes;
503  std::set<uint256> enabled;
504  majorityAmendments_t majority;
505 
506  doRound(
507  *table, weeks{1}, validators, votes, ourVotes, enabled, majority);
508  BEAST_EXPECT(ourVotes.empty());
509  BEAST_EXPECT(enabled.empty());
510  BEAST_EXPECT(majority.empty());
511 
512  votes.emplace_back(testAmendment, 256);
513 
514  doRound(
515  *table, weeks{2}, validators, votes, ourVotes, enabled, majority);
516  BEAST_EXPECT(ourVotes.empty());
517  BEAST_EXPECT(enabled.empty());
518 
519  majority[testAmendment] = weekTime(weeks{1});
520 
521  doRound(
522  *table, weeks{5}, validators, votes, ourVotes, enabled, majority);
523  BEAST_EXPECT(ourVotes.empty());
524  BEAST_EXPECT(enabled.empty());
525  }
526 
527  // Vote on and enable known, not-enabled amendment
528  void
530  {
531  testcase("voteEnable");
532 
533  auto table =
535 
536  auto const validators = makeValidators(10);
538  std::vector<uint256> ourVotes;
539  std::set<uint256> enabled;
540  majorityAmendments_t majority;
541 
542  // Week 1: We should vote for all known amendments not enabled
543  doRound(
544  *table, weeks{1}, validators, votes, ourVotes, enabled, majority);
545  BEAST_EXPECT(ourVotes.size() == m_set1.size());
546  BEAST_EXPECT(enabled.empty());
547  for (auto const& i : m_set1)
548  BEAST_EXPECT(majority.find(amendmentId(i)) == majority.end());
549 
550  // Now, everyone votes for this feature
551  for (auto const& i : m_set1)
552  votes.emplace_back(amendmentId(i), 256);
553 
554  // Week 2: We should recognize a majority
555  doRound(
556  *table, weeks{2}, validators, votes, ourVotes, enabled, majority);
557  BEAST_EXPECT(ourVotes.size() == m_set1.size());
558  BEAST_EXPECT(enabled.empty());
559 
560  for (auto const& i : m_set1)
561  BEAST_EXPECT(majority[amendmentId(i)] == weekTime(weeks{2}));
562 
563  // Week 5: We should enable the amendment
564  doRound(
565  *table, weeks{5}, validators, votes, ourVotes, enabled, majority);
566  BEAST_EXPECT(enabled.size() == m_set1.size());
567 
568  // Week 6: We should remove it from our votes and from having a majority
569  doRound(
570  *table, weeks{6}, validators, votes, ourVotes, enabled, majority);
571  BEAST_EXPECT(enabled.size() == m_set1.size());
572  BEAST_EXPECT(ourVotes.empty());
573  for (auto const& i : m_set1)
574  BEAST_EXPECT(majority.find(amendmentId(i)) == majority.end());
575  }
576 
577  // Detect majority at 80%, enable later
578  void
580  {
581  testcase("detectMajority");
582 
583  auto const testAmendment = amendmentId("detectMajority");
584  auto table = makeTable(
585  2, makeSection(testAmendment), emptySection, emptySection);
586 
587  auto const validators = makeValidators(16);
588 
589  std::set<uint256> enabled;
590  majorityAmendments_t majority;
591 
592  for (int i = 0; i <= 17; ++i)
593  {
595  std::vector<uint256> ourVotes;
596 
597  if ((i > 0) && (i < 17))
598  votes.emplace_back(testAmendment, i * 16);
599 
600  doRound(
601  *table,
602  weeks{i},
603  validators,
604  votes,
605  ourVotes,
606  enabled,
607  majority);
608 
609  if (i < 13)
610  {
611  // We are voting yes, not enabled, no majority
612  BEAST_EXPECT(!ourVotes.empty());
613  BEAST_EXPECT(enabled.empty());
614  BEAST_EXPECT(majority.empty());
615  }
616  else if (i < 15)
617  {
618  // We have a majority, not enabled, keep voting
619  BEAST_EXPECT(!ourVotes.empty());
620  BEAST_EXPECT(!majority.empty());
621  BEAST_EXPECT(enabled.empty());
622  }
623  else if (i == 15)
624  {
625  // enable, keep voting, remove from majority
626  BEAST_EXPECT(!ourVotes.empty());
627  BEAST_EXPECT(majority.empty());
628  BEAST_EXPECT(!enabled.empty());
629  }
630  else
631  {
632  // Done, we should be enabled and not voting
633  BEAST_EXPECT(ourVotes.empty());
634  BEAST_EXPECT(majority.empty());
635  BEAST_EXPECT(!enabled.empty());
636  }
637  }
638  }
639 
640  // Detect loss of majority
641  void
643  {
644  testcase("lostMajority");
645 
646  auto const testAmendment = amendmentId("lostMajority");
647  auto const validators = makeValidators(16);
648 
649  auto table = makeTable(
650  8, makeSection(testAmendment), emptySection, emptySection);
651 
652  std::set<uint256> enabled;
653  majorityAmendments_t majority;
654 
655  {
656  // establish majority
658  std::vector<uint256> ourVotes;
659 
660  votes.emplace_back(testAmendment, 250);
661 
662  doRound(
663  *table,
664  weeks{1},
665  validators,
666  votes,
667  ourVotes,
668  enabled,
669  majority);
670 
671  BEAST_EXPECT(enabled.empty());
672  BEAST_EXPECT(!majority.empty());
673  }
674 
675  for (int i = 1; i < 16; ++i)
676  {
678  std::vector<uint256> ourVotes;
679 
680  // Gradually reduce support
681  votes.emplace_back(testAmendment, 256 - i * 8);
682 
683  doRound(
684  *table,
685  weeks{i + 1},
686  validators,
687  votes,
688  ourVotes,
689  enabled,
690  majority);
691 
692  if (i < 8)
693  {
694  // We are voting yes, not enabled, majority
695  BEAST_EXPECT(!ourVotes.empty());
696  BEAST_EXPECT(enabled.empty());
697  BEAST_EXPECT(!majority.empty());
698  }
699  else
700  {
701  // No majority, not enabled, keep voting
702  BEAST_EXPECT(!ourVotes.empty());
703  BEAST_EXPECT(majority.empty());
704  BEAST_EXPECT(enabled.empty());
705  }
706  }
707  }
708 
709  void
711  {
712  testcase("hasUnsupportedEnabled");
713 
714  using namespace std::chrono_literals;
715 
716  int constexpr w = 1;
717  auto table = makeTable(w);
718  BEAST_EXPECT(!table->hasUnsupportedEnabled());
719  BEAST_EXPECT(!table->firstUnsupportedExpected());
720 
721  std::set<uint256> enabled;
722  majorityAmendments_t majority;
723  std::for_each(m_set4.begin(), m_set4.end(), [&enabled](auto const& s) {
724  enabled.insert(amendmentId(s));
725  });
726  table->doValidatedLedger(1, enabled, majority);
727  BEAST_EXPECT(table->hasUnsupportedEnabled());
728  BEAST_EXPECT(!table->firstUnsupportedExpected());
729  NetClock::duration t{1000s};
731  m_set5.begin(), m_set5.end(), [&majority, &t](auto const& s) {
732  majority[amendmentId(s)] = NetClock::time_point{--t};
733  });
734  table->doValidatedLedger(1, enabled, majority);
735  BEAST_EXPECT(table->hasUnsupportedEnabled());
736  BEAST_EXPECT(
737  table->firstUnsupportedExpected() &&
738  *table->firstUnsupportedExpected() ==
739  NetClock::time_point{t} + weeks{w});
740  }
741 
742  void
743  run() override
744  {
745  testConstruct();
746  testGet();
747  testBadConfig();
749  testNoOnUnknown();
750  testNoOnVetoed();
751  testVoteEnable();
755  }
756 };
757 
758 BEAST_DEFINE_TESTSUITE(AmendmentTable, app, ripple);
759 
760 } // namespace ripple
ripple::AmendmentTable_test::getState
std::map< uint256, bool > getState(AmendmentTable *table, std::set< uint256 > const &exclude)
Definition: AmendmentTable_test.cpp:261
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:43
std::for_each
T for_each(T... args)
ripple::AmendmentTable_test::journal
test::SuiteJournal journal
Definition: AmendmentTable_test.cpp:89
ripple::openssl_sha256_hasher
SHA-256 digest.
Definition: digest.h:91
ripple::AmendmentTable_test::testNoOnUnknown
void testNoOnUnknown()
Definition: AmendmentTable_test.cpp:451
std::string
STL class.
ripple::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, ripple)
ripple::calcNodeID
NodeID calcNodeID(PublicKey const &pk)
Calculate the 160-bit node ID from a node public key.
Definition: PublicKey.cpp:299
ripple::AmendmentTable_test::makeValidators
std::vector< std::pair< PublicKey, SecretKey > > makeValidators(int num)
Definition: AmendmentTable_test.cpp:334
ripple::AmendmentTable_test::makeSection
static Section makeSection(uint256 const &amendment)
Definition: AmendmentTable_test.cpp:74
ripple::AmendmentTable_test::makeTable
std::unique_ptr< AmendmentTable > makeTable(int w)
Definition: AmendmentTable_test.cpp:114
std::pair
std::vector::reserve
T reserve(T... args)
ripple::AmendmentTable_test::m_set5
const std::vector< std::string > m_set5
Definition: AmendmentTable_test.cpp:85
ripple::AmendmentTable_test::testDetectMajority
void testDetectMajority()
Definition: AmendmentTable_test.cpp:579
ripple::AmendmentTable_test::testConstruct
void testConstruct()
Definition: AmendmentTable_test.cpp:121
std::vector< std::string >
std::set::find
T find(T... args)
ripple::make_AmendmentTable
std::unique_ptr< AmendmentTable > make_AmendmentTable(std::chrono::seconds majorityTime, int majorityFraction, Section const &supported, Section const &enabled, Section const &vetoed, beast::Journal journal)
Definition: AmendmentTable.cpp:654
std::vector::size
T size(T... args)
ripple::AmendmentTable_test::testNoOnVetoed
void testNoOnVetoed()
Definition: AmendmentTable_test.cpp:490
ripple::AmendmentTable_test::createSet
static std::vector< std::string > createSet(int group, int count)
Definition: AmendmentTable_test.cpp:55
std::chrono::duration
ripple::AmendmentTable_test::testLostMajority
void testLostMajority()
Definition: AmendmentTable_test.cpp:642
ripple::QualityDirection::in
@ in
ripple::AmendmentTable_test::testHasUnsupported
void testHasUnsupported()
Definition: AmendmentTable_test.cpp:710
ripple::to_string
std::string to_string(ListDisposition disposition)
Definition: ValidatorList.cpp:41
ripple::AmendmentTable_test::m_set2
const std::vector< std::string > m_set2
Definition: AmendmentTable_test.cpp:82
ripple::tfLostMajority
const std::uint32_t tfLostMajority
Definition: TxFlags.h:102
ripple::tfGotMajority
const std::uint32_t tfGotMajority
Definition: TxFlags.h:101
ripple::base_uint::data
pointer data()
Definition: base_uint.h:103
ripple::AmendmentTable_test::weekTime
static NetClock::time_point weekTime(weeks w)
Definition: AmendmentTable_test.cpp:346
ripple::STValidation
Definition: STValidation.h:43
ripple::Section::append
void append(std::vector< std::string > const &lines)
Append a set of lines to this section.
Definition: BasicConfig.cpp:40
std::mismatch
T mismatch(T... args)
ripple::base_uint< 256 >
ripple::weeks
std::chrono::duration< int, std::ratio_multiply< days::period, std::ratio< 7 > >> weeks
Definition: chrono.h:39
std::to_string
T to_string(T... args)
std::array
STL class.
std::chrono::time_point
std::map::erase
T erase(T... args)
std::map
STL class.
ripple::AmendmentTable::doVoting
virtual std::map< uint256, std::uint32_t > doVoting(NetClock::time_point closeTime, std::set< uint256 > const &enabledAmendments, majorityAmendments_t const &majorityAmendments, std::vector< std::shared_ptr< STValidation >> const &valSet)=0
ripple::AmendmentTable_test::emptySection
const Section emptySection
Definition: AmendmentTable_test.cpp:87
ripple::AmendmentTable_test::testVoteEnable
void testVoteEnable()
Definition: AmendmentTable_test.cpp:529
ripple::test::SuiteJournal
Definition: SuiteJournal.h:88
ripple::KeyType::secp256k1
@ secp256k1
ripple::randomKeyPair
std::pair< PublicKey, SecretKey > randomKeyPair(KeyType type)
Create a key pair using secure random numbers.
Definition: SecretKey.cpp:260
std::vector::emplace_back
T emplace_back(T... args)
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::AmendmentTable_test::majorityFraction
static const int majorityFraction
Definition: AmendmentTable_test.cpp:40
ripple::AmendmentTable_test::testGet
void testGet()
Definition: AmendmentTable_test.cpp:147
std::vector::begin
T begin(T... args)
std::set::insert
T insert(T... args)
beast::hash_append
std::enable_if_t< is_contiguously_hashable< T, Hasher >::value > hash_append(Hasher &h, T const &t) noexcept
Logically concatenate input data to a Hasher.
Definition: hash_append.h:232
ripple::AmendmentTable_test::doRound
void doRound(AmendmentTable &table, weeks week, std::vector< std::pair< PublicKey, SecretKey >> const &validators, std::vector< std::pair< uint256, int >> const &votes, std::vector< uint256 > &ourVotes, std::set< uint256 > &enabled, majorityAmendments_t &majority)
Definition: AmendmentTable_test.cpp:353
ripple::AmendmentTable_test::makeSection
static Section makeSection(std::vector< std::string > const &amendments)
Definition: AmendmentTable_test.cpp:65
ripple::hash_append
void hash_append(Hasher &h, Slice const &v)
Definition: Slice.h:149
ripple::STVector256
Definition: STVector256.h:29
ripple::AmendmentTable_test::m_set4
const std::vector< std::string > m_set4
Definition: AmendmentTable_test.cpp:84
ripple::AmendmentTable_test::m_set1
const std::vector< std::string > m_set1
Definition: AmendmentTable_test.cpp:81
std::map::empty
T empty(T... args)
std::memcpy
T memcpy(T... args)
std::set::end
T end(T... args)
ripple::sfAmendments
const SF_Vec256 sfAmendments(access, STI_VECTOR256, 3, "Amendments")
Definition: SField.h:491
ripple::AmendmentTable_test
Definition: AmendmentTable_test.cpp:36
ripple::AmendmentTable_test::m_set3
const std::vector< std::string > m_set3
Definition: AmendmentTable_test.cpp:83
ripple::AmendmentTable
The amendment table stores the list of enabled and potential amendments.
Definition: AmendmentTable.h:34
std::unique_ptr
STL class.
ripple::AmendmentTable_test::AmendmentTable_test
AmendmentTable_test()
Definition: AmendmentTable_test.cpp:92
ripple::AmendmentTable_test::testBadConfig
void testBadConfig()
Definition: AmendmentTable_test.cpp:167
std::set
STL class.
ripple::AmendmentTable_test::run
void run() override
Definition: AmendmentTable_test.cpp:743
ripple::AmendmentTable_test::amendmentId
static uint256 amendmentId(std::string in)
Definition: AmendmentTable_test.cpp:43
ripple::AmendmentTable::doValidation
virtual std::vector< uint256 > doValidation(std::set< uint256 > const &enabled)=0
ripple::AmendmentTable::isEnabled
virtual bool isEnabled(uint256 const &amendment)=0
ripple::AmendmentTable_test::makeTable
std::unique_ptr< AmendmentTable > makeTable(int w, Section const supported, Section const enabled, Section const vetoed)
Definition: AmendmentTable_test.cpp:103
ripple::AmendmentTable_test::testEnableDisable
void testEnableDisable()
Definition: AmendmentTable_test.cpp:286