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(
69 ar->isFieldPresent(sfFlags) && ((ar->getFieldU32(sfFlags) & lsfPasswordSpent) == 0));
70
71 env(regkey(alice, bob), sig(alice), fee(0));
72
73 ar = env.le(alice);
74 BEAST_EXPECT(
75 ar->isFieldPresent(sfFlags) &&
76 ((ar->getFieldU32(sfFlags) & lsfPasswordSpent) == lsfPasswordSpent));
77
78 // The second SetRegularKey transaction with Fee=0 should fail.
79 env(regkey(alice, bob), sig(alice), fee(0), ter(telINSUF_FEE_P));
80
81 env.trust(bob["USD"](1), alice);
82 env(pay(bob, alice, bob["USD"](1)));
83 ar = env.le(alice);
84 BEAST_EXPECT(
85 ar->isFieldPresent(sfFlags) && ((ar->getFieldU32(sfFlags) & lsfPasswordSpent) == 0));
86 }
87
88 void
90 {
91 using namespace test::jtx;
92
93 testcase("Universal mask");
94 Env env(*this);
95 Account const alice("alice");
96 Account const bob("bob");
97 env.fund(XRP(10000), alice, bob);
98
99 auto jv = regkey(alice, bob);
100 jv[sfFlags.fieldName] = tfUniversalMask;
101 env(jv, ter(temINVALID_FLAG));
102 }
103
104 void
106 {
107 using namespace test::jtx;
108
109 testcase("Ticket regular key");
110 Env env{*this};
111 Account const alice{"alice", KeyType::ed25519};
112 env.fund(XRP(1000), alice);
113 env.close();
114
115 // alice makes herself some tickets.
116 env(ticket::create(alice, 4));
117 env.close();
118 std::uint32_t ticketSeq{env.seq(alice)};
119
120 // Make sure we can give a regular key using a ticket.
121 Account const alie{"alie", KeyType::secp256k1};
122 env(regkey(alice, alie), ticket::use(--ticketSeq));
123 env.close();
124
125 // Disable alice's master key using a ticket.
126 env(fset(alice, asfDisableMaster), sig(alice), ticket::use(--ticketSeq));
127 env.close();
128
129 // alice should be able to sign using the regular key but not the
130 // master key.
131 std::uint32_t const aliceSeq{env.seq(alice)};
132 env(noop(alice), sig(alice), ter(tefMASTER_DISABLED));
133 env(noop(alice), sig(alie), ter(tesSUCCESS));
134 env.close();
135 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
136
137 // Re-enable the master key using a ticket.
138 env(fclear(alice, asfDisableMaster), sig(alie), ticket::use(--ticketSeq));
139 env.close();
140
141 // Disable the regular key using a ticket.
142 env(regkey(alice, disabled), sig(alie), ticket::use(--ticketSeq));
143 env.close();
144
145 // alice should be able to sign using the master key but not the
146 // regular key.
147 env(noop(alice), sig(alice), ter(tesSUCCESS));
148 env(noop(alice), sig(alie), ter(tefBAD_AUTH));
149 env.close();
150 }
151
152 void
161};
162
163BEAST_DEFINE_TESTSUITE(SetRegularKey, app, xrpl);
164
165} // namespace xrpl
A testsuite class.
Definition suite.h:51
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:150
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:37
@ tefMASTER_DISABLED
Definition TER.h:157
@ tefBAD_AUTH
Definition TER.h:149
@ temBAD_REGKEY
Definition TER.h:78
@ temINVALID_FLAG
Definition TER.h:91
constexpr FlagValue tfUniversalMask
Definition TxFlags.h:43
@ tesSUCCESS
Definition TER.h:225