rippled
Loading...
Searching...
No Matches
SetRegularKey_test.cpp
1#include <test/jtx.h>
2
3#include <xrpl/protocol/Feature.h>
4
5namespace ripple {
6
8{
9public:
10 void
12 {
13 using namespace test::jtx;
14
15 testcase("Set regular key");
16 Env env{*this, testable_amendments()};
17 Account const alice("alice");
18 Account const bob("bob");
19 env.fund(XRP(10000), alice, bob);
20
21 env(regkey(alice, bob));
22 env(noop(alice), sig(bob));
23 env(noop(alice), sig(alice));
24
25 testcase("Disable master key");
26 env(fset(alice, asfDisableMaster), sig(alice));
27 env(noop(alice), sig(bob));
28 env(noop(alice), sig(alice), ter(tefMASTER_DISABLED));
29
30 testcase("Re-enable master key");
31 env(fclear(alice, asfDisableMaster),
32 sig(alice),
34
35 env(fclear(alice, asfDisableMaster), sig(bob));
36 env(noop(alice), sig(bob));
37 env(noop(alice), sig(alice));
38
39 testcase("Revoke regular key");
40 env(regkey(alice, disabled));
41 env(noop(alice), sig(bob), ter(tefBAD_AUTH));
42 env(noop(alice), sig(alice));
43 }
44
45 void
47 {
48 using namespace test::jtx;
49
50 testcase("Set regular key to master key");
51 Env env{*this, testable_amendments()};
52 Account const alice("alice");
53 env.fund(XRP(10000), alice);
54
55 env(regkey(alice, alice), ter(temBAD_REGKEY));
56 }
57
58 void
60 {
61 using namespace test::jtx;
62
63 testcase("Password spent");
64 Env env(*this);
65 Account const alice("alice");
66 Account const bob("bob");
67 env.fund(XRP(10000), alice, bob);
68
69 auto ar = env.le(alice);
70 BEAST_EXPECT(
71 ar->isFieldPresent(sfFlags) &&
72 ((ar->getFieldU32(sfFlags) & lsfPasswordSpent) == 0));
73
74 env(regkey(alice, bob), sig(alice), fee(0));
75
76 ar = env.le(alice);
77 BEAST_EXPECT(
78 ar->isFieldPresent(sfFlags) &&
79 ((ar->getFieldU32(sfFlags) & lsfPasswordSpent) ==
81
82 // The second SetRegularKey transaction with Fee=0 should fail.
83 env(regkey(alice, bob), sig(alice), fee(0), ter(telINSUF_FEE_P));
84
85 env.trust(bob["USD"](1), alice);
86 env(pay(bob, alice, bob["USD"](1)));
87 ar = env.le(alice);
88 BEAST_EXPECT(
89 ar->isFieldPresent(sfFlags) &&
90 ((ar->getFieldU32(sfFlags) & lsfPasswordSpent) == 0));
91 }
92
93 void
95 {
96 using namespace test::jtx;
97
98 testcase("Universal mask");
99 Env env(*this);
100 Account const alice("alice");
101 Account const bob("bob");
102 env.fund(XRP(10000), alice, bob);
103
104 auto jv = regkey(alice, bob);
105 jv[sfFlags.fieldName] = tfUniversalMask;
106 env(jv, ter(temINVALID_FLAG));
107 }
108
109 void
111 {
112 using namespace test::jtx;
113
114 testcase("Ticket regular key");
115 Env env{*this};
116 Account const alice{"alice", KeyType::ed25519};
117 env.fund(XRP(1000), alice);
118 env.close();
119
120 // alice makes herself some tickets.
121 env(ticket::create(alice, 4));
122 env.close();
123 std::uint32_t ticketSeq{env.seq(alice)};
124
125 // Make sure we can give a regular key using a ticket.
126 Account const alie{"alie", KeyType::secp256k1};
127 env(regkey(alice, alie), ticket::use(--ticketSeq));
128 env.close();
129
130 // Disable alice's master key using a ticket.
131 env(fset(alice, asfDisableMaster),
132 sig(alice),
133 ticket::use(--ticketSeq));
134 env.close();
135
136 // alice should be able to sign using the regular key but not the
137 // master key.
138 std::uint32_t const aliceSeq{env.seq(alice)};
139 env(noop(alice), sig(alice), ter(tefMASTER_DISABLED));
140 env(noop(alice), sig(alie), ter(tesSUCCESS));
141 env.close();
142 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
143
144 // Re-enable the master key using a ticket.
145 env(fclear(alice, asfDisableMaster),
146 sig(alie),
147 ticket::use(--ticketSeq));
148 env.close();
149
150 // Disable the regular key using a ticket.
151 env(regkey(alice, disabled), sig(alie), ticket::use(--ticketSeq));
152 env.close();
153
154 // alice should be able to sign using the master key but not the
155 // regular key.
156 env(noop(alice), sig(alice), ter(tesSUCCESS));
157 env(noop(alice), sig(alie), ter(tefBAD_AUTH));
158 env.close();
159 }
160
161 void
170};
171
172BEAST_DEFINE_TESTSUITE(SetRegularKey, app, ripple);
173
174} // namespace ripple
A testsuite class.
Definition suite.h:52
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:152
void run() override
Runs the suite.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
@ telINSUF_FEE_P
Definition TER.h:38
@ lsfPasswordSpent
constexpr std::uint32_t asfDisableMaster
Definition TxFlags.h:61
@ tefBAD_AUTH
Definition TER.h:150
@ tefMASTER_DISABLED
Definition TER.h:158
@ tesSUCCESS
Definition TER.h:226
constexpr std::uint32_t tfUniversalMask
Definition TxFlags.h:44
@ temBAD_REGKEY
Definition TER.h:79
@ temINVALID_FLAG
Definition TER.h:92