xrpld
Loading...
Searching...
No Matches
SetRegularKey_test.cpp
1
2#include <test/jtx/Account.h>
3#include <test/jtx/Env.h>
4#include <test/jtx/amount.h>
5#include <test/jtx/fee.h>
6#include <test/jtx/flags.h>
7#include <test/jtx/noop.h>
8#include <test/jtx/pay.h>
9#include <test/jtx/regkey.h>
10#include <test/jtx/sig.h>
11#include <test/jtx/tags.h>
12#include <test/jtx/ter.h>
13#include <test/jtx/ticket.h>
14
15#include <xrpl/beast/unit_test/suite.h>
16#include <xrpl/protocol/KeyType.h>
17#include <xrpl/protocol/LedgerFormats.h>
18#include <xrpl/protocol/SField.h>
19#include <xrpl/protocol/TER.h>
20#include <xrpl/protocol/TxFlags.h>
21
22#include <cstdint>
23
24namespace xrpl {
25
27{
28public:
29 void
31 {
32 using namespace test::jtx;
33
34 testcase("Set regular key");
35 Env env{*this, testableAmendments()};
36 Account const alice("alice");
37 Account const bob("bob");
38 env.fund(XRP(10000), alice, bob);
39
40 env(regkey(alice, bob));
41 env(noop(alice), Sig(bob));
42 env(noop(alice), Sig(alice));
43
44 testcase("Disable master key");
45 env(fset(alice, asfDisableMaster), Sig(alice));
46 env(noop(alice), Sig(bob));
47 env(noop(alice), Sig(alice), Ter(tefMASTER_DISABLED));
48
49 testcase("Re-enable master key");
50 env(fclear(alice, asfDisableMaster), Sig(alice), Ter(tefMASTER_DISABLED));
51
52 env(fclear(alice, asfDisableMaster), Sig(bob));
53 env(noop(alice), Sig(bob));
54 env(noop(alice), Sig(alice));
55
56 testcase("Revoke regular key");
57 env(regkey(alice, kDisabled));
58 env(noop(alice), Sig(bob), Ter(tefBAD_AUTH));
59 env(noop(alice), Sig(alice));
60 }
61
62 void
64 {
65 using namespace test::jtx;
66
67 testcase("Set regular key to master key");
68 Env env{*this, testableAmendments()};
69 Account const alice("alice");
70 env.fund(XRP(10000), alice);
71
72 env(regkey(alice, alice), Ter(temBAD_REGKEY));
73 }
74
75 void
77 {
78 using namespace test::jtx;
79
80 testcase("Cannot remove last signing method");
81 Env env{*this, testableAmendments()};
82 Account const alice("alice");
83 Account const bob("bob");
84 env.fund(XRP(10000), alice);
85
86 env(regkey(alice, bob));
87 env(fset(alice, asfDisableMaster), Sig(alice));
88
89 env(regkey(alice, kDisabled), Sig(bob), Ter(tecNO_ALTERNATIVE_KEY));
90
91 auto const sle = env.le(alice);
92 BEAST_EXPECT(
93 sle && sle->isFlag(lsfDisableMaster) && sle->getAccountID(sfRegularKey) == bob.id());
94 }
95
96 void
98 {
99 using namespace test::jtx;
100
101 testcase("Password spent");
102 Env env(*this);
103 Account const alice("alice");
104 Account const bob("bob");
105 env.fund(XRP(10000), alice, bob);
106
107 auto ar = env.le(alice);
108 BEAST_EXPECT(ar->isFieldPresent(sfFlags) && !ar->isFlag(lsfPasswordSpent));
109
110 env(regkey(alice, bob), Sig(alice), Fee(0));
111
112 ar = env.le(alice);
113 BEAST_EXPECT(ar->isFieldPresent(sfFlags) && ar->isFlag(lsfPasswordSpent));
114
115 // The second SetRegularKey transaction with Fee=0 should fail.
116 env(regkey(alice, bob), Sig(alice), Fee(0), Ter(telINSUF_FEE_P));
117
118 env.trust(bob["USD"](1), alice);
119 env(pay(bob, alice, bob["USD"](1)));
120 ar = env.le(alice);
121 BEAST_EXPECT(ar->isFieldPresent(sfFlags) && !ar->isFlag(lsfPasswordSpent));
122 }
123
124 void
126 {
127 using namespace test::jtx;
128
129 testcase("Universal mask");
130 Env env(*this);
131 Account const alice("alice");
132 Account const bob("bob");
133 env.fund(XRP(10000), alice, bob);
134
135 auto jv = regkey(alice, bob);
136 jv[sfFlags.fieldName] = tfUniversalMask;
137 env(jv, Ter(temINVALID_FLAG));
138 }
139
140 void
142 {
143 using namespace test::jtx;
144
145 testcase("Ticket regular key");
146 Env env{*this};
147 Account const alice{"alice", KeyType::Ed25519};
148 env.fund(XRP(1000), alice);
149 env.close();
150
151 // alice makes herself some tickets.
152 env(ticket::create(alice, 4));
153 env.close();
154 std::uint32_t ticketSeq{env.seq(alice)};
155
156 // Make sure we can give a regular key using a ticket.
157 Account const alie{"alie", KeyType::Secp256k1};
158 env(regkey(alice, alie), ticket::Use(--ticketSeq));
159 env.close();
160
161 // Disable alice's master key using a ticket.
162 env(fset(alice, asfDisableMaster), Sig(alice), ticket::Use(--ticketSeq));
163 env.close();
164
165 // alice should be able to sign using the regular key but not the
166 // master key.
167 std::uint32_t const aliceSeq{env.seq(alice)};
168 env(noop(alice), Sig(alice), Ter(tefMASTER_DISABLED));
169 env(noop(alice), Sig(alie), Ter(tesSUCCESS));
170 env.close();
171 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
172
173 // Re-enable the master key using a ticket.
174 env(fclear(alice, asfDisableMaster), Sig(alie), ticket::Use(--ticketSeq));
175 env.close();
176
177 // Disable the regular key using a ticket.
178 env(regkey(alice, kDisabled), Sig(alie), ticket::Use(--ticketSeq));
179 env.close();
180
181 // alice should be able to sign using the master key but not the
182 // regular key.
183 env(noop(alice), Sig(alice), Ter(tesSUCCESS));
184 env(noop(alice), Sig(alie), Ter(tefBAD_AUTH));
185 env.close();
186 }
187
188 void
198};
199
201
202} // namespace xrpl
A testsuite class.
Definition suite.h:50
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:149
void run() override
Runs the suite.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ telINSUF_FEE_P
Definition TER.h:41
@ tefMASTER_DISABLED
Definition TER.h:167
@ tefBAD_AUTH
Definition TER.h:159
@ temBAD_REGKEY
Definition TER.h:84
@ temINVALID_FLAG
Definition TER.h:97
@ tecNO_ALTERNATIVE_KEY
Definition TER.h:294
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, xrpl)
constexpr FlagValue tfUniversalMask
Definition TxFlags.h:45
@ tesSUCCESS
Definition TER.h:240