rippled
Loading...
Searching...
No Matches
SetRegularKey_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2016 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.h>
21
22#include <xrpl/protocol/Feature.h>
23
24namespace ripple {
25
27{
28public:
29 void
31 {
32 using namespace test::jtx;
33
34 testcase("Set regular key");
35 Env env{*this, testable_amendments()};
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),
51 sig(alice),
53
54 env(fclear(alice, asfDisableMaster), sig(bob));
55 env(noop(alice), sig(bob));
56 env(noop(alice), sig(alice));
57
58 testcase("Revoke regular key");
59 env(regkey(alice, disabled));
60 env(noop(alice), sig(bob), ter(tefBAD_AUTH));
61 env(noop(alice), sig(alice));
62 }
63
64 void
66 {
67 using namespace test::jtx;
68
69 testcase("Set regular key to master key");
70 Env env{*this, testable_amendments()};
71 Account const alice("alice");
72 env.fund(XRP(10000), alice);
73
74 env(regkey(alice, alice), ter(temBAD_REGKEY));
75 }
76
77 void
79 {
80 using namespace test::jtx;
81
82 testcase("Password spent");
83 Env env(*this);
84 Account const alice("alice");
85 Account const bob("bob");
86 env.fund(XRP(10000), alice, bob);
87
88 auto ar = env.le(alice);
89 BEAST_EXPECT(
90 ar->isFieldPresent(sfFlags) &&
91 ((ar->getFieldU32(sfFlags) & lsfPasswordSpent) == 0));
92
93 env(regkey(alice, bob), sig(alice), fee(0));
94
95 ar = env.le(alice);
96 BEAST_EXPECT(
97 ar->isFieldPresent(sfFlags) &&
98 ((ar->getFieldU32(sfFlags) & lsfPasswordSpent) ==
100
101 // The second SetRegularKey transaction with Fee=0 should fail.
102 env(regkey(alice, bob), sig(alice), fee(0), ter(telINSUF_FEE_P));
103
104 env.trust(bob["USD"](1), alice);
105 env(pay(bob, alice, bob["USD"](1)));
106 ar = env.le(alice);
107 BEAST_EXPECT(
108 ar->isFieldPresent(sfFlags) &&
109 ((ar->getFieldU32(sfFlags) & lsfPasswordSpent) == 0));
110 }
111
112 void
114 {
115 using namespace test::jtx;
116
117 testcase("Universal mask");
118 Env env(*this);
119 Account const alice("alice");
120 Account const bob("bob");
121 env.fund(XRP(10000), alice, bob);
122
123 auto jv = regkey(alice, bob);
124 jv[sfFlags.fieldName] = tfUniversalMask;
125 env(jv, ter(temINVALID_FLAG));
126 }
127
128 void
130 {
131 using namespace test::jtx;
132
133 testcase("Ticket regular key");
134 Env env{*this};
135 Account const alice{"alice", KeyType::ed25519};
136 env.fund(XRP(1000), alice);
137 env.close();
138
139 // alice makes herself some tickets.
140 env(ticket::create(alice, 4));
141 env.close();
142 std::uint32_t ticketSeq{env.seq(alice)};
143
144 // Make sure we can give a regular key using a ticket.
145 Account const alie{"alie", KeyType::secp256k1};
146 env(regkey(alice, alie), ticket::use(--ticketSeq));
147 env.close();
148
149 // Disable alice's master key using a ticket.
150 env(fset(alice, asfDisableMaster),
151 sig(alice),
152 ticket::use(--ticketSeq));
153 env.close();
154
155 // alice should be able to sign using the regular key but not the
156 // master key.
157 std::uint32_t const aliceSeq{env.seq(alice)};
158 env(noop(alice), sig(alice), ter(tefMASTER_DISABLED));
159 env(noop(alice), sig(alie), ter(tesSUCCESS));
160 env.close();
161 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
162
163 // Re-enable the master key using a ticket.
164 env(fclear(alice, asfDisableMaster),
165 sig(alie),
166 ticket::use(--ticketSeq));
167 env.close();
168
169 // Disable the regular key using a ticket.
170 env(regkey(alice, disabled), sig(alie), ticket::use(--ticketSeq));
171 env.close();
172
173 // alice should be able to sign using the master key but not the
174 // regular key.
175 env(noop(alice), sig(alice), ter(tesSUCCESS));
176 env(noop(alice), sig(alie), ter(tefBAD_AUTH));
177 env.close();
178 }
179
180 void
189};
190
191BEAST_DEFINE_TESTSUITE(SetRegularKey, app, ripple);
192
193} // namespace ripple
A testsuite class.
Definition suite.h:55
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:155
void run() override
Runs the suite.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
@ telINSUF_FEE_P
Definition TER.h:57
@ lsfPasswordSpent
constexpr std::uint32_t asfDisableMaster
Definition TxFlags.h:80
@ tefBAD_AUTH
Definition TER.h:169
@ tefMASTER_DISABLED
Definition TER.h:177
@ tesSUCCESS
Definition TER.h:245
constexpr std::uint32_t tfUniversalMask
Definition TxFlags.h:63
@ temBAD_REGKEY
Definition TER.h:98
@ temINVALID_FLAG
Definition TER.h:111