From 1c6e32ccc21ef3aeb0d3a6f59c242552c3222f92 Mon Sep 17 00:00:00 2001 From: Mike Ellery Date: Mon, 8 Aug 2016 17:19:58 -0700 Subject: [PATCH] Migrate SetRegularKey unit tests (RIPD-1258): Create SetRegularKey test to replace existing js test. Copy and simplify some existing test logic from Env_test.cpp and MultiSign.test.cpp. Add coverage for tfUniversalMask tx flag error case. --- Builds/VisualStudio2015/RippleD.vcxproj | 4 + .../VisualStudio2015/RippleD.vcxproj.filters | 3 + src/ripple/app/tests/SetRegularKey.test.cpp | 107 ++++++++++++++++++ src/ripple/unity/app_tests.cpp | 1 + 4 files changed, 115 insertions(+) create mode 100644 src/ripple/app/tests/SetRegularKey.test.cpp diff --git a/Builds/VisualStudio2015/RippleD.vcxproj b/Builds/VisualStudio2015/RippleD.vcxproj index 68a039a454..8944f2dc30 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj +++ b/Builds/VisualStudio2015/RippleD.vcxproj @@ -1191,6 +1191,10 @@ True True + + True + True + True True diff --git a/Builds/VisualStudio2015/RippleD.vcxproj.filters b/Builds/VisualStudio2015/RippleD.vcxproj.filters index a51dcbd593..5a2880c876 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2015/RippleD.vcxproj.filters @@ -1656,6 +1656,9 @@ ripple\app\tests + + ripple\app\tests + ripple\app\tests diff --git a/src/ripple/app/tests/SetRegularKey.test.cpp b/src/ripple/app/tests/SetRegularKey.test.cpp new file mode 100644 index 0000000000..691037bb9c --- /dev/null +++ b/src/ripple/app/tests/SetRegularKey.test.cpp @@ -0,0 +1,107 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2016 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#include +#include +#include + +namespace ripple { + +class SetRegularKey_test : public beast::unit_test::suite +{ +public: + + void testDisableMasterKey() + { + using namespace test::jtx; + Env env(*this); + Account const alice("alice"); + Account const bob("bob"); + env.fund(XRP(10000), alice, bob); + + // Master and Regular key + env(regkey(alice, bob)); + auto const ar = env.le(alice); + BEAST_EXPECT(ar->isFieldPresent(sfRegularKey) && (ar->getAccountID(sfRegularKey) == bob.id())); + + env(noop(alice)); + env(noop(alice), sig(bob)); + env(noop(alice), sig(alice)); + + // Regular key only + env(fset(alice, asfDisableMaster), sig(alice)); + env(noop(alice)); + env(noop(alice), sig(bob)); + env(noop(alice), sig(alice), ter(tefMASTER_DISABLED)); + env(fclear(alice, asfDisableMaster), sig(alice), ter(tefMASTER_DISABLED)); + env(fclear(alice, asfDisableMaster), sig(bob)); + env(noop(alice), sig(alice)); + } + + void testPasswordSpent() + { + using namespace test::jtx; + Env env(*this); + Account const alice("alice"); + Account const bob("bob"); + env.fund(XRP(10000), alice, bob); + + auto ar = env.le(alice); + BEAST_EXPECT(ar->isFieldPresent(sfFlags) && ((ar->getFieldU32(sfFlags) & lsfPasswordSpent) == 0)); + + env(regkey(alice, bob), sig(alice), fee(0)); + + ar = env.le(alice); + BEAST_EXPECT(ar->isFieldPresent(sfFlags) && ((ar->getFieldU32(sfFlags) & lsfPasswordSpent) == lsfPasswordSpent)); + + // The second SetRegularKey transaction with Fee=0 should fail. + env(regkey(alice, bob), sig(alice), fee(0), ter(telINSUF_FEE_P)); + + env.trust(bob["USD"](1), alice); + env(pay(bob, alice, bob["USD"](1))); + ar = env.le(alice); + BEAST_EXPECT(ar->isFieldPresent(sfFlags) && ((ar->getFieldU32(sfFlags) & lsfPasswordSpent) == 0)); + } + + void testUniversalMaskError() + { + using namespace test::jtx; + Env env(*this); + Account const alice("alice"); + Account const bob("bob"); + env.fund(XRP(10000), alice, bob); + + auto jv = regkey(alice, bob); + jv[sfFlags.fieldName] = tfUniversalMask; + env(jv, ter(temINVALID_FLAG)); + } + + void run() + { + testDisableMasterKey(); + testPasswordSpent(); + testUniversalMaskError(); + } + +}; + +BEAST_DEFINE_TESTSUITE(SetRegularKey,app,ripple); + +} + diff --git a/src/ripple/unity/app_tests.cpp b/src/ripple/unity/app_tests.cpp index 8bdd2097e4..9e1dd80029 100644 --- a/src/ripple/unity/app_tests.cpp +++ b/src/ripple/unity/app_tests.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include