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