rippled
View_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/ledger/Ledger.h>
21 #include <ripple/core/ConfigSections.h>
22 #include <ripple/ledger/ApplyViewImpl.h>
23 #include <ripple/ledger/OpenView.h>
24 #include <ripple/ledger/PaymentSandbox.h>
25 #include <ripple/ledger/Sandbox.h>
26 #include <ripple/protocol/Feature.h>
27 #include <ripple/protocol/Protocol.h>
28 #include <test/jtx.h>
29 #include <type_traits>
30 
31 namespace ripple {
32 namespace test {
33 
34 class View_test : public beast::unit_test::suite
35 {
36  // Convert a small integer to a key
37  static Keylet
39  {
40  return Keylet{ltACCOUNT_ROOT, uint256(id)};
41  }
42 
43  // Create SLE with key and payload
46  {
47  auto const le = std::make_shared<SLE>(k(id));
48  le->setFieldU32(sfSequence, seq);
49  return le;
50  }
51 
52  // Return payload for SLE
53  template <class T>
54  static std::uint32_t
56  {
57  return le->getFieldU32(sfSequence);
58  }
59 
60  // Set payload on SLE
61  static void
63  {
64  le->setFieldU32(sfSequence, seq);
65  }
66 
67  // Erase all state items
68  static void
69  wipe(OpenLedger& openLedger)
70  {
71  openLedger.modify([](OpenView& view, beast::Journal) {
72  // HACK!
74  next.emplace(0);
75  for (;;)
76  {
77  next = view.succ(*next);
78  if (!next)
79  break;
80  view.rawErase(std::make_shared<SLE>(
81  *view.read(keylet::unchecked(*next))));
82  }
83  return true;
84  });
85  }
86 
87  static void
88  wipe(Ledger& ledger)
89  {
90  // HACK!
92  next.emplace(0);
93  for (;;)
94  {
95  next = ledger.succ(*next);
96  if (!next)
97  break;
98  ledger.rawErase(
99  std::make_shared<SLE>(*ledger.read(keylet::unchecked(*next))));
100  }
101  }
102 
103  // Test succ correctness
104  void
106  ReadView const& v,
107  std::uint32_t id,
109  {
110  auto const next = v.succ(k(id).key);
111  if (answer)
112  {
113  if (BEAST_EXPECT(next))
114  BEAST_EXPECT(*next == k(*answer).key);
115  }
116  else
117  {
118  BEAST_EXPECT(!next);
119  }
120  }
121 
122  template <class T>
125  {
126  return std::make_shared<std::remove_const_t<T>>(*sp);
127  }
128 
129  // Exercise Ledger implementation of ApplyView
130  void
132  {
133  using namespace jtx;
134  Env env(*this);
135  Config config;
136  std::shared_ptr<Ledger const> const genesis = std::make_shared<Ledger>(
138  config,
140  env.app().getNodeFamily());
141  auto const ledger = std::make_shared<Ledger>(
142  *genesis, env.app().timeKeeper().closeTime());
143  wipe(*ledger);
144  ReadView& v = *ledger;
145  succ(v, 0, std::nullopt);
146  ledger->rawInsert(sle(1, 1));
147  BEAST_EXPECT(v.exists(k(1)));
148  BEAST_EXPECT(seq(v.read(k(1))) == 1);
149  succ(v, 0, 1);
150  succ(v, 1, std::nullopt);
151  ledger->rawInsert(sle(2, 2));
152  BEAST_EXPECT(seq(v.read(k(2))) == 2);
153  ledger->rawInsert(sle(3, 3));
154  BEAST_EXPECT(seq(v.read(k(3))) == 3);
155  auto s = copy(v.read(k(2)));
156  seq(s, 4);
157  ledger->rawReplace(s);
158  BEAST_EXPECT(seq(v.read(k(2))) == 4);
159  ledger->rawErase(sle(2));
160  BEAST_EXPECT(!v.exists(k(2)));
161  BEAST_EXPECT(v.exists(k(1)));
162  BEAST_EXPECT(v.exists(k(3)));
163  }
164 
165  void
167  {
168  using namespace jtx;
169  Env env(*this);
170  wipe(env.app().openLedger());
171  auto const open = env.current();
172  ApplyViewImpl v(&*open, tapNONE);
173  succ(v, 0, std::nullopt);
174  v.insert(sle(1));
175  BEAST_EXPECT(v.exists(k(1)));
176  BEAST_EXPECT(seq(v.read(k(1))) == 1);
177  BEAST_EXPECT(seq(v.peek(k(1))) == 1);
178  succ(v, 0, 1);
179  succ(v, 1, std::nullopt);
180  v.insert(sle(2, 2));
181  BEAST_EXPECT(seq(v.read(k(2))) == 2);
182  v.insert(sle(3, 3));
183  auto s = v.peek(k(3));
184  BEAST_EXPECT(seq(s) == 3);
185  s = v.peek(k(2));
186  seq(s, 4);
187  v.update(s);
188  BEAST_EXPECT(seq(v.read(k(2))) == 4);
189  v.erase(s);
190  BEAST_EXPECT(!v.exists(k(2)));
191  BEAST_EXPECT(v.exists(k(1)));
192  BEAST_EXPECT(v.exists(k(3)));
193  }
194 
195  // Exercise all succ paths
196  void
198  {
199  using namespace jtx;
200  Env env(*this);
201  wipe(env.app().openLedger());
202  auto const open = env.current();
203  ApplyViewImpl v0(&*open, tapNONE);
204  v0.insert(sle(1));
205  v0.insert(sle(2));
206  v0.insert(sle(4));
207  v0.insert(sle(7));
208  {
209  Sandbox v1(&v0);
210  v1.insert(sle(3));
211  v1.insert(sle(5));
212  v1.insert(sle(6));
213 
214  // v0: 12-4--7
215  // v1: --3-56-
216 
217  succ(v0, 0, 1);
218  succ(v0, 1, 2);
219  succ(v0, 2, 4);
220  succ(v0, 3, 4);
221  succ(v0, 4, 7);
222  succ(v0, 5, 7);
223  succ(v0, 6, 7);
224  succ(v0, 7, std::nullopt);
225 
226  succ(v1, 0, 1);
227  succ(v1, 1, 2);
228  succ(v1, 2, 3);
229  succ(v1, 3, 4);
230  succ(v1, 4, 5);
231  succ(v1, 5, 6);
232  succ(v1, 6, 7);
233  succ(v1, 7, std::nullopt);
234 
235  v1.erase(v1.peek(k(4)));
236  succ(v1, 3, 5);
237 
238  v1.erase(v1.peek(k(6)));
239  succ(v1, 5, 7);
240  succ(v1, 6, 7);
241 
242  // v0: 12----7
243  // v1: --3-5--
244 
245  v1.apply(v0);
246  }
247 
248  // v0: 123-5-7
249 
250  succ(v0, 0, 1);
251  succ(v0, 1, 2);
252  succ(v0, 2, 3);
253  succ(v0, 3, 5);
254  succ(v0, 4, 5);
255  succ(v0, 5, 7);
256  succ(v0, 6, 7);
257  succ(v0, 7, std::nullopt);
258  }
259 
260  void
262  {
263  using namespace jtx;
264  Env env(*this);
265  wipe(env.app().openLedger());
266  auto const open = env.current();
267  ApplyViewImpl v0(&*open, tapNONE);
268  v0.rawInsert(sle(1, 1));
269  v0.rawInsert(sle(2, 2));
270  v0.rawInsert(sle(4, 4));
271 
272  {
273  Sandbox v1(&v0);
274  v1.erase(v1.peek(k(2)));
275  v1.insert(sle(3, 3));
276  auto s = v1.peek(k(4));
277  seq(s, 5);
278  v1.update(s);
279  BEAST_EXPECT(seq(v1.read(k(1))) == 1);
280  BEAST_EXPECT(!v1.exists(k(2)));
281  BEAST_EXPECT(seq(v1.read(k(3))) == 3);
282  BEAST_EXPECT(seq(v1.read(k(4))) == 5);
283  {
284  Sandbox v2(&v1);
285  auto s2 = v2.peek(k(3));
286  seq(s2, 6);
287  v2.update(s2);
288  v2.erase(v2.peek(k(4)));
289  BEAST_EXPECT(seq(v2.read(k(1))) == 1);
290  BEAST_EXPECT(!v2.exists(k(2)));
291  BEAST_EXPECT(seq(v2.read(k(3))) == 6);
292  BEAST_EXPECT(!v2.exists(k(4)));
293  // discard v2
294  }
295  BEAST_EXPECT(seq(v1.read(k(1))) == 1);
296  BEAST_EXPECT(!v1.exists(k(2)));
297  BEAST_EXPECT(seq(v1.read(k(3))) == 3);
298  BEAST_EXPECT(seq(v1.read(k(4))) == 5);
299 
300  {
301  Sandbox v2(&v1);
302  auto s2 = v2.peek(k(3));
303  seq(s2, 6);
304  v2.update(s2);
305  v2.erase(v2.peek(k(4)));
306  BEAST_EXPECT(seq(v2.read(k(1))) == 1);
307  BEAST_EXPECT(!v2.exists(k(2)));
308  BEAST_EXPECT(seq(v2.read(k(3))) == 6);
309  BEAST_EXPECT(!v2.exists(k(4)));
310  v2.apply(v1);
311  }
312  BEAST_EXPECT(seq(v1.read(k(1))) == 1);
313  BEAST_EXPECT(!v1.exists(k(2)));
314  BEAST_EXPECT(seq(v1.read(k(3))) == 6);
315  BEAST_EXPECT(!v1.exists(k(4)));
316  v1.apply(v0);
317  }
318  BEAST_EXPECT(seq(v0.read(k(1))) == 1);
319  BEAST_EXPECT(!v0.exists(k(2)));
320  BEAST_EXPECT(seq(v0.read(k(3))) == 6);
321  BEAST_EXPECT(!v0.exists(k(4)));
322  }
323 
324  // Verify contextual information
325  void
327  {
328  using namespace jtx;
329  using namespace std::chrono;
330  {
331  Env env(*this);
332  wipe(env.app().openLedger());
333  auto const open = env.current();
334  OpenView v0(open.get());
335  BEAST_EXPECT(v0.seq() != 98);
336  BEAST_EXPECT(v0.seq() == open->seq());
337  BEAST_EXPECT(v0.parentCloseTime() != NetClock::time_point{99s});
338  BEAST_EXPECT(v0.parentCloseTime() == open->parentCloseTime());
339  {
340  // shallow copy
341  OpenView v1(v0);
342  BEAST_EXPECT(v1.seq() == v0.seq());
343  BEAST_EXPECT(v1.parentCloseTime() == v1.parentCloseTime());
344 
345  ApplyViewImpl v2(&v1, tapRETRY);
346  BEAST_EXPECT(v2.parentCloseTime() == v1.parentCloseTime());
347  BEAST_EXPECT(v2.seq() == v1.seq());
348  BEAST_EXPECT(v2.flags() == tapRETRY);
349 
350  Sandbox v3(&v2);
351  BEAST_EXPECT(v3.seq() == v2.seq());
352  BEAST_EXPECT(v3.parentCloseTime() == v2.parentCloseTime());
353  BEAST_EXPECT(v3.flags() == tapRETRY);
354  }
355  {
356  ApplyViewImpl v1(&v0, tapRETRY);
357  PaymentSandbox v2(&v1);
358  BEAST_EXPECT(v2.seq() == v0.seq());
359  BEAST_EXPECT(v2.parentCloseTime() == v0.parentCloseTime());
360  BEAST_EXPECT(v2.flags() == tapRETRY);
361  PaymentSandbox v3(&v2);
362  BEAST_EXPECT(v3.seq() == v2.seq());
363  BEAST_EXPECT(v3.parentCloseTime() == v2.parentCloseTime());
364  BEAST_EXPECT(v3.flags() == v2.flags());
365  }
366  }
367  }
368 
369  // Return a list of keys found via sles
370  static std::vector<uint256>
371  sles(ReadView const& ledger)
372  {
374  v.reserve(32);
375  for (auto const& sle : ledger.sles)
376  v.push_back(sle->key());
377  return v;
378  }
379 
380  template <class... Args>
381  static std::vector<uint256>
382  list(Args... args)
383  {
384  return std::vector<uint256>({uint256(args)...});
385  }
386 
387  void
389  {
390  using namespace jtx;
391  Env env(*this);
392  Config config;
393  std::shared_ptr<Ledger const> const genesis = std::make_shared<Ledger>(
395  config,
397  env.app().getNodeFamily());
398  auto const ledger = std::make_shared<Ledger>(
399  *genesis, env.app().timeKeeper().closeTime());
400 
401  auto setup = [&ledger](std::vector<int> const& vec) {
402  wipe(*ledger);
403  for (auto x : vec)
404  {
405  ledger->rawInsert(sle(x));
406  }
407  };
408  {
409  setup({1, 2, 3});
410  BEAST_EXPECT(sles(*ledger) == list(1, 2, 3));
411  auto e = ledger->stateMap().end();
412  auto b1 = ledger->stateMap().begin();
413  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(1)) == e);
414  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(2)) == b1);
415  ++b1;
416  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(3)) == b1);
417  ++b1;
418  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(4)) == b1);
419  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(5)) == b1);
420  b1 = ledger->stateMap().begin();
421  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(0)) == b1);
422  ++b1;
423  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(1)) == b1);
424  ++b1;
425  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(2)) == b1);
426  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(3)) == e);
427  }
428 
429  {
430  setup({2, 4, 6});
431  BEAST_EXPECT(sles(*ledger) == list(2, 4, 6));
432  auto e = ledger->stateMap().end();
433  auto b1 = ledger->stateMap().begin();
434  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(1)) == e);
435  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(2)) == e);
436  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(3)) == b1);
437  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(4)) == b1);
438  ++b1;
439  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(5)) == b1);
440  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(6)) == b1);
441  ++b1;
442  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(7)) == b1);
443  b1 = ledger->stateMap().begin();
444  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(1)) == b1);
445  ++b1;
446  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(2)) == b1);
447  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(3)) == b1);
448  ++b1;
449 
450  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(4)) == b1);
451  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(5)) == b1);
452  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(6)) == e);
453  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(7)) == e);
454  }
455  {
456  setup({2, 3, 5, 6, 10, 15});
457  BEAST_EXPECT(sles(*ledger) == list(2, 3, 5, 6, 10, 15));
458  auto e = ledger->stateMap().end();
459  auto b = ledger->stateMap().begin();
460  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(1)) == e);
461  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(2)) == e);
462  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(3)) == b);
463  ++b;
464  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(4)) == b);
465  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(5)) == b);
466  ++b;
467  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(6)) == b);
468  ++b;
469  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(7)) == b);
470  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(8)) == b);
471  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(9)) == b);
472  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(10)) == b);
473  ++b;
474  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(11)) == b);
475  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(12)) == b);
476  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(13)) == b);
477  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(14)) == b);
478  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(15)) == b);
479  ++b;
480  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(16)) == b);
481  b = ledger->stateMap().begin();
482  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(0)) == b);
483  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(1)) == b);
484  ++b;
485  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(2)) == b);
486  ++b;
487  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(3)) == b);
488  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(4)) == b);
489  ++b;
490  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(5)) == b);
491  ++b;
492  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(6)) == b);
493  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(7)) == b);
494  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(8)) == b);
495  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(9)) == b);
496  ++b;
497  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(10)) == b);
498  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(11)) == b);
499  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(12)) == b);
500  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(13)) == b);
501  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(14)) == b);
502  ++b;
503  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(15)) == e);
504  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(16)) == e);
505  }
506  {
507  // some full trees, some empty trees, etc
508  setup({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
509  13, 14, 15, 16, 20, 25, 30, 32, 33, 34, 35, 36, 37,
510  38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 66, 100});
511  BEAST_EXPECT(
512  sles(*ledger) ==
513  list(
514  0,
515  1,
516  2,
517  3,
518  4,
519  5,
520  6,
521  7,
522  8,
523  9,
524  10,
525  11,
526  12,
527  13,
528  14,
529  15,
530  16,
531  20,
532  25,
533  30,
534  32,
535  33,
536  34,
537  35,
538  36,
539  37,
540  38,
541  39,
542  40,
543  41,
544  42,
545  43,
546  44,
547  45,
548  46,
549  47,
550  48,
551  66,
552  100));
553  auto b = ledger->stateMap().begin();
554  auto e = ledger->stateMap().end();
555  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(0)) == e);
556  BEAST_EXPECT(ledger->stateMap().lower_bound(uint256(1)) == b);
557  BEAST_EXPECT(
558  ledger->stateMap().lower_bound(uint256(5))->key() ==
559  uint256(4));
560  BEAST_EXPECT(
561  ledger->stateMap().lower_bound(uint256(15))->key() ==
562  uint256(14));
563  BEAST_EXPECT(
564  ledger->stateMap().lower_bound(uint256(16))->key() ==
565  uint256(15));
566  BEAST_EXPECT(
567  ledger->stateMap().lower_bound(uint256(19))->key() ==
568  uint256(16));
569  BEAST_EXPECT(
570  ledger->stateMap().lower_bound(uint256(20))->key() ==
571  uint256(16));
572  BEAST_EXPECT(
573  ledger->stateMap().lower_bound(uint256(24))->key() ==
574  uint256(20));
575  BEAST_EXPECT(
576  ledger->stateMap().lower_bound(uint256(31))->key() ==
577  uint256(30));
578  BEAST_EXPECT(
579  ledger->stateMap().lower_bound(uint256(32))->key() ==
580  uint256(30));
581  BEAST_EXPECT(
582  ledger->stateMap().lower_bound(uint256(40))->key() ==
583  uint256(39));
584  BEAST_EXPECT(
585  ledger->stateMap().lower_bound(uint256(47))->key() ==
586  uint256(46));
587  BEAST_EXPECT(
588  ledger->stateMap().lower_bound(uint256(48))->key() ==
589  uint256(47));
590  BEAST_EXPECT(
591  ledger->stateMap().lower_bound(uint256(64))->key() ==
592  uint256(48));
593 
594  BEAST_EXPECT(
595  ledger->stateMap().lower_bound(uint256(90))->key() ==
596  uint256(66));
597  BEAST_EXPECT(
598  ledger->stateMap().lower_bound(uint256(96))->key() ==
599  uint256(66));
600  BEAST_EXPECT(
601  ledger->stateMap().lower_bound(uint256(100))->key() ==
602  uint256(66));
603 
604  BEAST_EXPECT(
605  ledger->stateMap().upper_bound(uint256(0))->key() ==
606  uint256(1));
607  BEAST_EXPECT(
608  ledger->stateMap().upper_bound(uint256(5))->key() ==
609  uint256(6));
610  BEAST_EXPECT(
611  ledger->stateMap().upper_bound(uint256(15))->key() ==
612  uint256(16));
613  BEAST_EXPECT(
614  ledger->stateMap().upper_bound(uint256(16))->key() ==
615  uint256(20));
616  BEAST_EXPECT(
617  ledger->stateMap().upper_bound(uint256(18))->key() ==
618  uint256(20));
619  BEAST_EXPECT(
620  ledger->stateMap().upper_bound(uint256(20))->key() ==
621  uint256(25));
622  BEAST_EXPECT(
623  ledger->stateMap().upper_bound(uint256(31))->key() ==
624  uint256(32));
625  BEAST_EXPECT(
626  ledger->stateMap().upper_bound(uint256(32))->key() ==
627  uint256(33));
628  BEAST_EXPECT(
629  ledger->stateMap().upper_bound(uint256(47))->key() ==
630  uint256(48));
631  BEAST_EXPECT(
632  ledger->stateMap().upper_bound(uint256(48))->key() ==
633  uint256(66));
634  BEAST_EXPECT(
635  ledger->stateMap().upper_bound(uint256(53))->key() ==
636  uint256(66));
637  BEAST_EXPECT(
638  ledger->stateMap().upper_bound(uint256(66))->key() ==
639  uint256(100));
640  BEAST_EXPECT(
641  ledger->stateMap().upper_bound(uint256(70))->key() ==
642  uint256(100));
643  BEAST_EXPECT(
644  ledger->stateMap().upper_bound(uint256(85))->key() ==
645  uint256(100));
646  BEAST_EXPECT(
647  ledger->stateMap().upper_bound(uint256(98))->key() ==
648  uint256(100));
649  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(100)) == e);
650  BEAST_EXPECT(ledger->stateMap().upper_bound(uint256(155)) == e);
651  }
652  }
653 
654  void
656  {
657  using namespace jtx;
658  Env env(*this);
659  Config config;
660  std::shared_ptr<Ledger const> const genesis = std::make_shared<Ledger>(
662  config,
664  env.app().getNodeFamily());
665  auto const ledger = std::make_shared<Ledger>(
666  *genesis, env.app().timeKeeper().closeTime());
667  auto setup123 = [&ledger, this]() {
668  // erase middle element
669  wipe(*ledger);
670  ledger->rawInsert(sle(1));
671  ledger->rawInsert(sle(2));
672  ledger->rawInsert(sle(3));
673  BEAST_EXPECT(sles(*ledger) == list(1, 2, 3));
674  };
675  {
676  setup123();
677  OpenView view(ledger.get());
678  view.rawErase(sle(1));
679  view.rawInsert(sle(4));
680  view.rawInsert(sle(5));
681  BEAST_EXPECT(sles(view) == list(2, 3, 4, 5));
682  auto b = view.sles.begin();
683  BEAST_EXPECT(view.sles.upper_bound(uint256(1)) == b);
684  ++b;
685  BEAST_EXPECT(view.sles.upper_bound(uint256(2)) == b);
686  ++b;
687  BEAST_EXPECT(view.sles.upper_bound(uint256(3)) == b);
688  ++b;
689  BEAST_EXPECT(view.sles.upper_bound(uint256(4)) == b);
690  ++b;
691  BEAST_EXPECT(view.sles.upper_bound(uint256(5)) == b);
692  }
693  {
694  setup123();
695  OpenView view(ledger.get());
696  view.rawErase(sle(1));
697  view.rawErase(sle(2));
698  view.rawInsert(sle(4));
699  view.rawInsert(sle(5));
700  BEAST_EXPECT(sles(view) == list(3, 4, 5));
701  auto b = view.sles.begin();
702  BEAST_EXPECT(view.sles.upper_bound(uint256(1)) == b);
703  BEAST_EXPECT(view.sles.upper_bound(uint256(2)) == b);
704  ++b;
705  BEAST_EXPECT(view.sles.upper_bound(uint256(3)) == b);
706  ++b;
707  BEAST_EXPECT(view.sles.upper_bound(uint256(4)) == b);
708  ++b;
709  BEAST_EXPECT(view.sles.upper_bound(uint256(5)) == b);
710  }
711  {
712  setup123();
713  OpenView view(ledger.get());
714  view.rawErase(sle(1));
715  view.rawErase(sle(2));
716  view.rawErase(sle(3));
717  view.rawInsert(sle(4));
718  view.rawInsert(sle(5));
719  BEAST_EXPECT(sles(view) == list(4, 5));
720  auto b = view.sles.begin();
721  BEAST_EXPECT(view.sles.upper_bound(uint256(1)) == b);
722  BEAST_EXPECT(view.sles.upper_bound(uint256(2)) == b);
723  BEAST_EXPECT(view.sles.upper_bound(uint256(3)) == b);
724  ++b;
725  BEAST_EXPECT(view.sles.upper_bound(uint256(4)) == b);
726  ++b;
727  BEAST_EXPECT(view.sles.upper_bound(uint256(5)) == b);
728  }
729  {
730  setup123();
731  OpenView view(ledger.get());
732  view.rawErase(sle(3));
733  view.rawInsert(sle(4));
734  view.rawInsert(sle(5));
735  BEAST_EXPECT(sles(view) == list(1, 2, 4, 5));
736  auto b = view.sles.begin();
737  ++b;
738  BEAST_EXPECT(view.sles.upper_bound(uint256(1)) == b);
739  ++b;
740  BEAST_EXPECT(view.sles.upper_bound(uint256(2)) == b);
741  BEAST_EXPECT(view.sles.upper_bound(uint256(3)) == b);
742  ++b;
743  BEAST_EXPECT(view.sles.upper_bound(uint256(4)) == b);
744  ++b;
745  BEAST_EXPECT(view.sles.upper_bound(uint256(5)) == b);
746  }
747  {
748  setup123();
749  OpenView view(ledger.get());
750  view.rawReplace(sle(1, 10));
751  view.rawReplace(sle(3, 30));
752  BEAST_EXPECT(sles(view) == list(1, 2, 3));
753  BEAST_EXPECT(seq(view.read(k(1))) == 10);
754  BEAST_EXPECT(seq(view.read(k(2))) == 1);
755  BEAST_EXPECT(seq(view.read(k(3))) == 30);
756 
757  view.rawErase(sle(3));
758  BEAST_EXPECT(sles(view) == list(1, 2));
759  auto b = view.sles.begin();
760  ++b;
761  BEAST_EXPECT(view.sles.upper_bound(uint256(1)) == b);
762  ++b;
763  BEAST_EXPECT(view.sles.upper_bound(uint256(2)) == b);
764  BEAST_EXPECT(view.sles.upper_bound(uint256(3)) == b);
765  BEAST_EXPECT(view.sles.upper_bound(uint256(4)) == b);
766  BEAST_EXPECT(view.sles.upper_bound(uint256(5)) == b);
767 
768  view.rawInsert(sle(5));
769  view.rawInsert(sle(4));
770  view.rawInsert(sle(3));
771  BEAST_EXPECT(sles(view) == list(1, 2, 3, 4, 5));
772  b = view.sles.begin();
773  ++b;
774  BEAST_EXPECT(view.sles.upper_bound(uint256(1)) == b);
775  ++b;
776  BEAST_EXPECT(view.sles.upper_bound(uint256(2)) == b);
777  ++b;
778  BEAST_EXPECT(view.sles.upper_bound(uint256(3)) == b);
779  ++b;
780  BEAST_EXPECT(view.sles.upper_bound(uint256(4)) == b);
781  ++b;
782  BEAST_EXPECT(view.sles.upper_bound(uint256(5)) == b);
783  }
784  }
785 
786  void
788  {
789  using namespace jtx;
790  Env env(*this);
791 
792  auto const alice = Account("alice");
793  auto const bob = Account("bob");
794  auto const carol = Account("carol");
795  auto const gw = Account("gateway");
796  auto const USD = gw["USD"];
797  auto const EUR = gw["EUR"];
798 
799  env.fund(XRP(10000), alice, bob, carol, gw);
800  env.trust(USD(100), alice, bob, carol);
801  {
802  // Global freezing.
803  env(pay(gw, alice, USD(50)));
804  env(offer(alice, XRP(5), USD(5)));
805 
806  // Now freeze gw.
807  env(fset(gw, asfGlobalFreeze));
808  env.close();
809  env(offer(alice, XRP(4), USD(5)), ter(tecFROZEN));
810  env.close();
811 
812  // Alice's USD balance should be zero if frozen.
813  BEAST_EXPECT(
814  USD(0) ==
815  accountHolds(
816  *env.closed(),
817  alice,
818  USD.currency,
819  gw,
821  env.journal));
822 
823  // Thaw gw and try again.
824  env(fclear(gw, asfGlobalFreeze));
825  env.close();
826  env(offer("alice", XRP(4), USD(5)));
827  }
828  {
829  // Local freezing.
830  env(pay(gw, bob, USD(50)));
831  env.close();
832 
833  // Now gw freezes bob's USD trust line.
834  env(trust(gw, USD(100), bob, tfSetFreeze));
835  env.close();
836 
837  // Bob's balance should be zero if frozen.
838  BEAST_EXPECT(
839  USD(0) ==
840  accountHolds(
841  *env.closed(),
842  bob,
843  USD.currency,
844  gw,
846  env.journal));
847 
848  // gw thaws bob's trust line. bob gets his money back.
849  env(trust(gw, USD(100), bob, tfClearFreeze));
850  env.close();
851  BEAST_EXPECT(
852  USD(50) ==
853  accountHolds(
854  *env.closed(),
855  bob,
856  USD.currency,
857  gw,
859  env.journal));
860  }
861  {
862  // accountHolds().
863  env(pay(gw, carol, USD(50)));
864  env.close();
865 
866  // carol has no EUR.
867  BEAST_EXPECT(
868  EUR(0) ==
869  accountHolds(
870  *env.closed(),
871  carol,
872  EUR.currency,
873  gw,
875  env.journal));
876 
877  // But carol does have USD.
878  BEAST_EXPECT(
879  USD(50) ==
880  accountHolds(
881  *env.closed(),
882  carol,
883  USD.currency,
884  gw,
886  env.journal));
887 
888  // carol's XRP balance should be her holdings minus her reserve.
889  auto const carolsXRP = accountHolds(
890  *env.closed(),
891  carol,
892  xrpCurrency(),
893  xrpAccount(),
895  env.journal);
896  // carol's XRP balance: 10000
897  // base reserve: -200
898  // 1 trust line times its reserve: 1 * -50
899  // -------
900  // carol's available balance: 9750
901  BEAST_EXPECT(carolsXRP == XRP(9750));
902 
903  // carol should be able to spend *more* than her XRP balance on
904  // a fee by eating into her reserve.
905  env(noop(carol), fee(carolsXRP + XRP(10)));
906  env.close();
907 
908  // carol's XRP balance should now show as zero.
909  BEAST_EXPECT(
910  XRP(0) ==
911  accountHolds(
912  *env.closed(),
913  carol,
914  xrpCurrency(),
915  gw,
917  env.journal));
918  }
919  {
920  // accountFunds().
921  // Gateways have whatever funds they claim to have.
922  auto const gwUSD = accountFunds(
923  *env.closed(), gw, USD(314159), fhZERO_IF_FROZEN, env.journal);
924  BEAST_EXPECT(gwUSD == USD(314159));
925 
926  // carol has funds from the gateway.
927  auto carolsUSD = accountFunds(
928  *env.closed(), carol, USD(0), fhZERO_IF_FROZEN, env.journal);
929  BEAST_EXPECT(carolsUSD == USD(50));
930 
931  // If carol's funds are frozen she has no funds...
932  env(fset(gw, asfGlobalFreeze));
933  env.close();
934  carolsUSD = accountFunds(
935  *env.closed(), carol, USD(0), fhZERO_IF_FROZEN, env.journal);
936  BEAST_EXPECT(carolsUSD == USD(0));
937 
938  // ... unless the query ignores the FROZEN state.
939  carolsUSD = accountFunds(
940  *env.closed(), carol, USD(0), fhIGNORE_FREEZE, env.journal);
941  BEAST_EXPECT(carolsUSD == USD(50));
942 
943  // Just to be tidy, thaw gw.
944  env(fclear(gw, asfGlobalFreeze));
945  env.close();
946  }
947  }
948 
949  void
951  {
952  using namespace jtx;
953  Env env(*this);
954 
955  auto const gw1 = Account("gw1");
956 
957  env.fund(XRP(10000), gw1);
958  env.close();
959 
960  auto rdView = env.closed();
961  // Test with no rate set on gw1.
962  BEAST_EXPECT(transferRate(*rdView, gw1) == parityRate);
963 
964  env(rate(gw1, 1.02));
965  env.close();
966 
967  rdView = env.closed();
968  BEAST_EXPECT(transferRate(*rdView, gw1) == Rate{1020000000});
969  }
970 
971  void
973  {
974  // This test requires incompatible ledgers. The good news we can
975  // construct and manage two different Env instances at the same
976  // time. So we can use two Env instances to produce mutually
977  // incompatible ledgers.
978  using namespace jtx;
979  auto const alice = Account("alice");
980  auto const bob = Account("bob");
981 
982  // The first Env.
983  Env eA(*this);
984 
985  eA.fund(XRP(10000), alice);
986  eA.close();
987  auto const rdViewA3 = eA.closed();
988 
989  eA.fund(XRP(10000), bob);
990  eA.close();
991  auto const rdViewA4 = eA.closed();
992 
993  // The two Env's can't share the same ports, so modifiy the config
994  // of the second Env to use higher port numbers
995  Env eB{*this, envconfig(port_increment, 3)};
996 
997  // Make ledgers that are incompatible with the first ledgers. Note
998  // that bob is funded before alice.
999  eB.fund(XRP(10000), bob);
1000  eB.close();
1001  auto const rdViewB3 = eB.closed();
1002 
1003  eB.fund(XRP(10000), alice);
1004  eB.close();
1005  auto const rdViewB4 = eB.closed();
1006 
1007  // Check for compatibility.
1008  auto jStream = eA.journal.error();
1009  BEAST_EXPECT(areCompatible(*rdViewA3, *rdViewA4, jStream, ""));
1010  BEAST_EXPECT(areCompatible(*rdViewA4, *rdViewA3, jStream, ""));
1011  BEAST_EXPECT(areCompatible(*rdViewA4, *rdViewA4, jStream, ""));
1012  BEAST_EXPECT(!areCompatible(*rdViewA3, *rdViewB4, jStream, ""));
1013  BEAST_EXPECT(!areCompatible(*rdViewA4, *rdViewB3, jStream, ""));
1014  BEAST_EXPECT(!areCompatible(*rdViewA4, *rdViewB4, jStream, ""));
1015 
1016  // Try the other interface.
1017  // Note that the different interface has different outcomes.
1018  auto const& iA3 = rdViewA3->info();
1019  auto const& iA4 = rdViewA4->info();
1020 
1021  BEAST_EXPECT(areCompatible(iA3.hash, iA3.seq, *rdViewA4, jStream, ""));
1022  BEAST_EXPECT(areCompatible(iA4.hash, iA4.seq, *rdViewA3, jStream, ""));
1023  BEAST_EXPECT(areCompatible(iA4.hash, iA4.seq, *rdViewA4, jStream, ""));
1024  BEAST_EXPECT(!areCompatible(iA3.hash, iA3.seq, *rdViewB4, jStream, ""));
1025  BEAST_EXPECT(areCompatible(iA4.hash, iA4.seq, *rdViewB3, jStream, ""));
1026  BEAST_EXPECT(!areCompatible(iA4.hash, iA4.seq, *rdViewB4, jStream, ""));
1027  }
1028 
1029  void
1031  {
1032  using namespace jtx;
1033 
1034  // Create a ledger with 1 item, put a
1035  // ApplyView on that, then another ApplyView,
1036  // erase the item, apply.
1037  {
1038  Env env(*this);
1039  Config config;
1040  std::shared_ptr<Ledger const> const genesis =
1041  std::make_shared<Ledger>(
1043  config,
1045  env.app().getNodeFamily());
1046  auto const ledger = std::make_shared<Ledger>(
1047  *genesis, env.app().timeKeeper().closeTime());
1048  wipe(*ledger);
1049  ledger->rawInsert(sle(1));
1050  ReadView& v0 = *ledger;
1051  ApplyViewImpl v1(&v0, tapNONE);
1052  {
1053  Sandbox v2(&v1);
1054  v2.erase(v2.peek(k(1)));
1055  v2.apply(v1);
1056  }
1057  BEAST_EXPECT(!v1.exists(k(1)));
1058  }
1059 
1060  // Make sure OpenLedger::empty works
1061  {
1062  Env env(*this);
1063  BEAST_EXPECT(env.app().openLedger().empty());
1064  env.fund(XRP(10000), Account("test"));
1065  BEAST_EXPECT(!env.app().openLedger().empty());
1066  }
1067  }
1068 
1069  void
1070  run() override
1071  {
1072  // This had better work, or else
1073  BEAST_EXPECT(k(0).key < k(1).key);
1074 
1075  testLedger();
1076  testMeta();
1077  testMetaSucc();
1078  testStacked();
1079  testContext();
1080  testSles();
1082  testFlags();
1083  testTransferRate();
1085  testRegressions();
1086  }
1087 };
1088 
1089 class GetAmendments_test : public beast::unit_test::suite
1090 {
1091  void
1093  {
1094  using namespace jtx;
1095  Env env{*this, envconfig(validator, "")};
1096 
1097  // Start out with no amendments.
1098  auto majorities = getMajorityAmendments(*env.closed());
1099  BEAST_EXPECT(majorities.empty());
1100 
1101  // Now close ledgers until the amendments show up.
1102  int i = 0;
1103  for (i = 0; i <= 256; ++i)
1104  {
1105  env.close();
1106  majorities = getMajorityAmendments(*env.closed());
1107  if (!majorities.empty())
1108  break;
1109  }
1110 
1111  // There should be at least 5 amendments. Don't do exact comparison
1112  // to avoid maintenance as more amendments are added in the future.
1113  BEAST_EXPECT(i == 254);
1114  BEAST_EXPECT(majorities.size() >= 5);
1115 
1116  // None of the amendments should be enabled yet.
1117  auto enableds = getEnabledAmendments(*env.closed());
1118  BEAST_EXPECT(enableds.empty());
1119 
1120  // Now wait 2 weeks modulo 256 ledgers for the amendments to be
1121  // enabled. Speed the process by closing ledgers every 80 minutes,
1122  // which should get us to just past 2 weeks after 256 ledgers.
1123  for (i = 0; i <= 256; ++i)
1124  {
1125  using namespace std::chrono_literals;
1126  env.close(80min);
1127  enableds = getEnabledAmendments(*env.closed());
1128  if (!enableds.empty())
1129  break;
1130  }
1131  BEAST_EXPECT(i == 255);
1132  BEAST_EXPECT(enableds.size() >= 5);
1133  }
1134 
1135  void
1136  run() override
1137  {
1138  testGetAmendments();
1139  }
1140 };
1141 
1142 BEAST_DEFINE_TESTSUITE(View, ledger, ripple);
1143 BEAST_DEFINE_TESTSUITE(GetAmendments, ledger, ripple);
1144 
1145 } // namespace test
1146 } // namespace ripple
ripple::test::View_test::testMetaSucc
void testMetaSucc()
Definition: View_test.cpp:197
ripple::transferRate
Rate transferRate(ReadView const &view, AccountID const &issuer)
Definition: View.cpp:471
ripple::test::jtx::noop
Json::Value noop(Account const &account)
The null transaction.
Definition: noop.h:31
ripple::tecFROZEN
@ tecFROZEN
Definition: TER.h:265
ripple::getMajorityAmendments
majorityAmendments_t getMajorityAmendments(ReadView const &view)
Definition: View.cpp:621
ripple::test::jtx::XRP
const XRP_t XRP
Converts to XRP Issue or STAmount.
Definition: amount.cpp:105
ripple::test::View_test::testFlags
void testFlags()
Definition: View_test.cpp:787
ripple::Keylet
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:38
ripple::getEnabledAmendments
std::set< uint256 > getEnabledAmendments(ReadView const &view)
Definition: View.cpp:604
ripple::Ledger::succ
std::optional< uint256 > succ(uint256 const &key, std::optional< uint256 > const &last=std::nullopt) const override
Definition: Ledger.cpp:421
std::shared_ptr
STL class.
ripple::test::View_test::seq
static void seq(std::shared_ptr< SLE > const &le, std::uint32_t seq)
Definition: View_test.cpp:62
ripple::test::GetAmendments_test
Definition: View_test.cpp:1089
ripple::fhZERO_IF_FROZEN
@ fhZERO_IF_FROZEN
Definition: View.h:52
ripple::Rate
Represents a transfer rate.
Definition: Rate.h:37
ripple::test::jtx::ter
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition: ter.h:33
ripple::test::View_test::testTransferRate
void testTransferRate()
Definition: View_test.cpp:950
ripple::PaymentSandbox
A wrapper which makes credits unavailable to balances.
Definition: PaymentSandbox.h:112
ripple::Sandbox::apply
void apply(RawView &to)
Definition: Sandbox.h:55
ripple::test::jtx::Env::closed
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
Definition: Env.cpp:115
std::vector::reserve
T reserve(T... args)
ripple::sfSequence
const SF_UINT32 sfSequence
ripple::OpenView
Writable ledger view that accumulates state and tx changes.
Definition: OpenView.h:55
ripple::asfGlobalFreeze
const std::uint32_t asfGlobalFreeze
Definition: TxFlags.h:71
ripple::OpenView::rawErase
void rawErase(std::shared_ptr< SLE > const &sle) override
Delete an existing state item.
Definition: OpenView.cpp:233
ripple::test::jtx::validator
std::unique_ptr< Config > validator(std::unique_ptr< Config >, std::string const &)
adjust configuration with params needed to be a validator
Definition: envconfig.cpp:107
ripple::detail::ApplyViewBase::exists
bool exists(Keylet const &k) const override
Determine if a state item exists.
Definition: ApplyViewBase.cpp:58
std::vector
STL class.
ripple::test::jtx::trust
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition: trust.cpp:30
ripple::accountHolds
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
Definition: View.cpp:216
ripple::detail::ApplyViewBase::update
void update(std::shared_ptr< SLE > const &sle) override
Indicate changes to a peeked SLE.
Definition: ApplyViewBase.cpp:146
ripple::test::View_test::testSles
void testSles()
Definition: View_test.cpp:655
ripple::test::jtx::port_increment
std::unique_ptr< Config > port_increment(std::unique_ptr< Config >, int)
adjust the default configured server ports by a specified value
Definition: envconfig.cpp:116
ripple::OpenView::succ
std::optional< key_type > succ(key_type const &key, std::optional< key_type > const &last=std::nullopt) const override
Return the key of the next state item.
Definition: OpenView.cpp:164
ripple::test::jtx::Env::journal
const beast::Journal journal
Definition: Env.h:144
ripple::ReadView::sles_type::upper_bound
iterator upper_bound(key_type const &key) const
Definition: ReadView.cpp:143
ripple::test::jtx::Env::app
Application & app()
Definition: Env.h:241
ripple::ApplyViewImpl
Editable, discardable view that can build metadata for one tx.
Definition: ApplyViewImpl.h:36
ripple::Application::timeKeeper
virtual TimeKeeper & timeKeeper()=0
ripple::test::jtx::envconfig
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition: envconfig.h:49
ripple::tfClearFreeze
const std::uint32_t tfClearFreeze
Definition: TxFlags.h:95
ripple::Application::openLedger
virtual OpenLedger & openLedger()=0
ripple::ReadView::parentCloseTime
NetClock::time_point parentCloseTime() const
Returns the close time of the previous ledger.
Definition: ReadView.h:253
ripple::test::View_test::sles
static std::vector< uint256 > sles(ReadView const &ledger)
Definition: View_test.cpp:371
ripple::Ledger::rawErase
void rawErase(std::shared_ptr< SLE > const &sle) override
Delete an existing state item.
Definition: Ledger.cpp:516
ripple::tapNONE
@ tapNONE
Definition: ApplyView.h:30
ripple::parityRate
const Rate parityRate(QUALITY_ONE)
A transfer rate signifying a 1:1 exchange.
Definition: Rate.h:94
ripple::ReadView::sles_type::begin
iterator begin() const
Definition: ReadView.cpp:131
ripple::test::jtx::Env::trust
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
Definition: Env.cpp:256
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:529
ripple::test::View_test::run
void run() override
Definition: View_test.cpp:1070
std::vector::push_back
T push_back(T... args)
ripple::Keylet::key
uint256 key
Definition: Keylet.h:40
ripple::base_uint< 256 >
ripple::test::View_test::testRegressions
void testRegressions()
Definition: View_test.cpp:1030
ripple::Ledger
Holds a ledger.
Definition: Ledger.h:76
ripple::test::View_test::testContext
void testContext()
Definition: View_test.cpp:326
ripple::Config
Definition: Config.h:68
ripple::test::View_test::sle
static std::shared_ptr< SLE > sle(std::uint64_t id, std::uint32_t seq=1)
Definition: View_test.cpp:45
ripple::OpenView::rawReplace
void rawReplace(std::shared_ptr< SLE > const &sle) override
Unconditionally replace a state item.
Definition: OpenView.cpp:245
ripple::Sandbox
Discardable, editable view to a ledger.
Definition: Sandbox.h:34
ripple::test::jtx::fset
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Definition: flags.cpp:28
ripple::test::View_test::wipe
static void wipe(Ledger &ledger)
Definition: View_test.cpp:88
ripple::test::jtx::Env::close
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition: Env.cpp:121
ripple::xrpAccount
AccountID const & xrpAccount()
Compute AccountID from public key.
Definition: AccountID.cpp:90
beast::Journal::error
Stream error() const
Definition: Journal.h:333
std::chrono::time_point
ripple::ReadView::exists
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
ripple::ReadView::sles
sles_type sles
Iterable range of ledger state items.
Definition: ReadView.h:387
ripple::TimeKeeper::closeTime
virtual time_point closeTime() const =0
Returns the close time, in network time.
ripple::test::View_test::wipe
static void wipe(OpenLedger &openLedger)
Definition: View_test.cpp:69
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::test::GetAmendments_test::run
void run() override
Definition: View_test.cpp:1136
std::uint64_t
ripple::ReadView::succ
virtual std::optional< key_type > succ(key_type const &key, std::optional< key_type > const &last=std::nullopt) const =0
Return the key of the next state item.
ripple::tfSetFreeze
const std::uint32_t tfSetFreeze
Definition: TxFlags.h:94
ripple::keylet::unchecked
Keylet unchecked(uint256 const &key) noexcept
Any ledger entry.
Definition: Indexes.cpp:294
ripple::test::jtx::fclear
Json::Value fclear(Account const &account, std::uint32_t off)
Remove account flag.
Definition: flags.h:40
ripple::test::View_test::testMeta
void testMeta()
Definition: View_test.cpp:166
ripple::ReadView::read
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
ripple::areCompatible
bool areCompatible(ReadView const &validLedger, ReadView const &testLedger, beast::Journal::Stream &s, const char *reason)
Return false if the test ledger is provably incompatible with the valid ledger, that is,...
Definition: View.cpp:482
ripple::OpenLedger::empty
bool empty() const
Returns true if there are no transactions.
Definition: OpenLedger.cpp:43
ripple::accountFunds
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
Definition: View.cpp:260
ripple::OpenLedger
Represents the open ledger.
Definition: OpenLedger.h:49
ripple::test::jtx::fee
Set the fee on a JTx.
Definition: fee.h:35
ripple::tapRETRY
@ tapRETRY
Definition: ApplyView.h:38
ripple::OpenView::rawInsert
void rawInsert(std::shared_ptr< SLE > const &sle) override
Unconditionally insert a state item.
Definition: OpenView.cpp:239
ripple::Ledger::read
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
Definition: Ledger.cpp:432
ripple::detail::ApplyViewBase::insert
void insert(std::shared_ptr< SLE > const &sle) override
Insert a new state SLE.
Definition: ApplyViewBase.cpp:140
ripple::detail::ApplyViewBase::erase
void erase(std::shared_ptr< SLE > const &sle) override
Remove a peeked SLE.
Definition: ApplyViewBase.cpp:134
ripple::test::jtx::seq
Set the sequence number on a JTx.
Definition: seq.h:33
ripple::detail::ApplyViewBase::flags
ApplyFlags flags() const override
Returns the tx apply flags.
Definition: ApplyViewBase.cpp:122
ripple::test::View_test::copy
static std::shared_ptr< std::remove_const_t< T > > copy(std::shared_ptr< T > const &sp)
Definition: View_test.cpp:124
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:192
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::test::jtx::pay
Json::Value pay(Account const &account, Account const &to, AnyAmount amount)
Create a payment.
Definition: pay.cpp:29
ripple::test::View_test::testLedger
void testLedger()
Definition: View_test.cpp:131
ripple::ReadView::seq
LedgerIndex seq() const
Returns the sequence number of the base ledger.
Definition: ReadView.h:260
ripple::ltACCOUNT_ROOT
@ ltACCOUNT_ROOT
A ledger object which describes an account.
Definition: LedgerFormats.h:59
ripple::test::jtx::Env::fund
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition: Env.cpp:225
ripple::create_genesis
const create_genesis_t create_genesis
Definition: Ledger.cpp:62
ripple::test::View_test
Definition: View_test.cpp:34
ripple::fhIGNORE_FREEZE
@ fhIGNORE_FREEZE
Definition: View.h:52
ripple::OpenView::read
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
Definition: OpenView.cpp:171
std::optional
ripple::test::View_test::testUpperAndLowerBound
void testUpperAndLowerBound()
Definition: View_test.cpp:388
ripple::detail::ApplyViewBase::read
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
Definition: ApplyViewBase.cpp:71
ripple::test::jtx::Account
Immutable cryptographic account descriptor.
Definition: Account.h:37
ripple::detail::ApplyViewBase::peek
std::shared_ptr< SLE > peek(Keylet const &k) override
Prepare to modify the SLE associated with key.
Definition: ApplyViewBase.cpp:128
ripple::test::GetAmendments_test::testGetAmendments
void testGetAmendments()
Definition: View_test.cpp:1092
ripple::test::View_test::testAreCompatible
void testAreCompatible()
Definition: View_test.cpp:972
ripple::test::View_test::testStacked
void testStacked()
Definition: View_test.cpp:261
ripple::test::View_test::k
static Keylet k(std::uint64_t id)
Definition: View_test.cpp:38
ripple::test::View_test::list
static std::vector< uint256 > list(Args... args)
Definition: View_test.cpp:382
type_traits
ripple::OpenLedger::modify
bool modify(modify_type const &f)
Modify the open ledger.
Definition: OpenLedger.cpp:57
ripple::test::jtx::Env::current
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition: Env.h:300
ripple::xrpCurrency
Currency const & xrpCurrency()
XRP currency.
Definition: UintTypes.cpp:121
ripple::test::jtx::Env
A transaction testing environment.
Definition: Env.h:116
ripple::detail::ApplyViewBase::rawInsert
void rawInsert(std::shared_ptr< SLE > const &sle) override
Unconditionally insert a state item.
Definition: ApplyViewBase.cpp:160
ripple::open
void open(soci::session &s, BasicConfig const &config, std::string const &dbName)
Open a soci session.
Definition: SociDB.cpp:98
ripple::test::View_test::succ
void succ(ReadView const &v, std::uint32_t id, std::optional< std::uint32_t > answer)
Definition: View_test.cpp:105
ripple::test::jtx::rate
Json::Value rate(Account const &account, double multiplier)
Set a transfer rate.
Definition: rate.cpp:30
ripple::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(DeliverMin, app, ripple)
std::chrono
ripple::test::View_test::seq
static std::uint32_t seq(std::shared_ptr< T > const &le)
Definition: View_test.cpp:55