xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
app
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
24
namespace
xrpl
{
25
26
class
SetRegularKey_test
:
public
beast::unit_test::Suite
27
{
28
public
:
29
void
30
testDisabledMasterKey
()
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
63
testDisabledRegularKey
()
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
76
testNoAlternativeKey
()
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
97
testPasswordSpent
()
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
125
testUniversalMask
()
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
141
testTicketRegularKey
()
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
189
run
()
override
190
{
191
testDisabledMasterKey
();
192
testDisabledRegularKey
();
193
testNoAlternativeKey
();
194
testPasswordSpent
();
195
testUniversalMask
();
196
testTicketRegularKey
();
197
}
198
};
199
200
BEAST_DEFINE_TESTSUITE
(
SetRegularKey
, app,
xrpl
);
201
202
}
// namespace xrpl
beast::unit_test::Suite
A testsuite class.
Definition
suite.h:52
beast::unit_test::Suite::testcase
TestcaseT testcase
Memberspace for declaring test cases.
Definition
suite.h:155
xrpl::SetRegularKey_test
Definition
SetRegularKey_test.cpp:27
xrpl::SetRegularKey_test::testPasswordSpent
void testPasswordSpent()
Definition
SetRegularKey_test.cpp:97
xrpl::SetRegularKey_test::testTicketRegularKey
void testTicketRegularKey()
Definition
SetRegularKey_test.cpp:141
xrpl::SetRegularKey_test::testNoAlternativeKey
void testNoAlternativeKey()
Definition
SetRegularKey_test.cpp:76
xrpl::SetRegularKey_test::testDisabledRegularKey
void testDisabledRegularKey()
Definition
SetRegularKey_test.cpp:63
xrpl::SetRegularKey_test::run
void run() override
Runs the suite.
Definition
SetRegularKey_test.cpp:189
xrpl::SetRegularKey_test::testUniversalMask
void testUniversalMask()
Definition
SetRegularKey_test.cpp:125
xrpl::SetRegularKey_test::testDisabledMasterKey
void testDisabledMasterKey()
Definition
SetRegularKey_test.cpp:30
xrpl::SetRegularKey
Definition
tx/transactors/account/SetRegularKey.h:15
cstdint
std::uint32_t
xrpl::test::jtx
Definition
Oracle_test.cpp:34
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::telINSUF_FEE_P
@ telINSUF_FEE_P
Definition
TER.h:43
xrpl::KeyType::Secp256k1
@ Secp256k1
Definition
KeyType.h:9
xrpl::KeyType::Ed25519
@ Ed25519
Definition
KeyType.h:10
xrpl::tefMASTER_DISABLED
@ tefMASTER_DISABLED
Definition
TER.h:172
xrpl::tefBAD_AUTH
@ tefBAD_AUTH
Definition
TER.h:164
xrpl::temBAD_REGKEY
@ temBAD_REGKEY
Definition
TER.h:86
xrpl::temINVALID_FLAG
@ temINVALID_FLAG
Definition
TER.h:99
xrpl::tecNO_ALTERNATIVE_KEY
@ tecNO_ALTERNATIVE_KEY
Definition
TER.h:304
xrpl::FeePayerType::Account
@ Account
Definition
Transactor.h:145
xrpl::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, xrpl)
xrpl::tfUniversalMask
constexpr FlagValue tfUniversalMask
Definition
TxFlags.h:46
xrpl::tesSUCCESS
@ tesSUCCESS
Definition
TER.h:250
Generated by
1.17.0