rippled
Loading...
Searching...
No Matches
flags.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 <test/jtx/flags.h>
21#include <xrpl/protocol/jss.h>
22
23namespace ripple {
24namespace test {
25namespace jtx {
26
28fset(Account const& account, std::uint32_t on, std::uint32_t off)
29{
30 Json::Value jv;
31 jv[jss::Account] = account.human();
32 jv[jss::TransactionType] = jss::AccountSet;
33 if (on != 0)
34 jv[jss::SetFlag] = on;
35 if (off != 0)
36 jv[jss::ClearFlag] = off;
37 return jv;
38}
39
40void
42{
43 auto const sle = env.le(account_);
44 if (!sle)
45 env.test.fail();
46 else if (sle->isFieldPresent(sfFlags))
47 env.test.expect((sle->getFieldU32(sfFlags) & mask_) == mask_);
48 else
49 env.test.expect(mask_ == 0);
50}
51
52void
54{
55 auto const sle = env.le(account_);
56 if (!sle)
57 env.test.fail();
58 else if (sle->isFieldPresent(sfFlags))
59 env.test.expect((sle->getFieldU32(sfFlags) & mask_) == 0);
60 else
61 env.test.pass();
62}
63
64} // namespace jtx
65} // namespace test
66} // namespace ripple
Represents a JSON value.
Definition: json_value.h:148
void pass()
Record a successful test condition.
Definition: suite.h:511
bool expect(Condition const &shouldBeTrue)
Evaluate a test condition.
Definition: suite.h:229
void fail(String const &reason, char const *file, int line)
Record a failure.
Definition: suite.h:533
Immutable cryptographic account descriptor.
Definition: Account.h:39
A transaction testing environment.
Definition: Env.h:118
beast::unit_test::suite & test
Definition: Env.h:120
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
Definition: Env.cpp:219
void operator()(Env &env) const
Definition: flags.cpp:41
void operator()(Env &env) const
Definition: flags.cpp:53
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Definition: flags.cpp:28
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26