From ad9be4dbf6185f332f2d71c4b7dafe814470d723 Mon Sep 17 00:00:00 2001 From: Mike Ellery Date: Thu, 18 Aug 2016 13:21:54 -0700 Subject: [PATCH] Add LedgerClosed test (RIPD-1272) Migrate the logic in monitor-test.js to a new jtx test that covers the ledger_closed RPC method. --- Builds/VisualStudio2015/RippleD.vcxproj | 4 ++ .../VisualStudio2015/RippleD.vcxproj.filters | 3 + src/ripple/unity/rpcx.cpp | 2 +- src/test/rpc/LedgerClosed_test.cpp | 64 +++++++++++++++++++ src/unity/rpc_test_unity.cpp | 3 +- 5 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/test/rpc/LedgerClosed_test.cpp diff --git a/Builds/VisualStudio2015/RippleD.vcxproj b/Builds/VisualStudio2015/RippleD.vcxproj index 7c6678c5f8..0a6f1dadd7 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj +++ b/Builds/VisualStudio2015/RippleD.vcxproj @@ -4720,6 +4720,10 @@ True True + + True + True + True True diff --git a/Builds/VisualStudio2015/RippleD.vcxproj.filters b/Builds/VisualStudio2015/RippleD.vcxproj.filters index 77c978491c..7733837e9b 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2015/RippleD.vcxproj.filters @@ -5415,6 +5415,9 @@ test\rpc + + test\rpc + test\rpc diff --git a/src/ripple/unity/rpcx.cpp b/src/ripple/unity/rpcx.cpp index 53213d2c1f..e36e3713a2 100644 --- a/src/ripple/unity/rpcx.cpp +++ b/src/ripple/unity/rpcx.cpp @@ -94,4 +94,4 @@ #include #include #include -#include \ No newline at end of file +#include diff --git a/src/test/rpc/LedgerClosed_test.cpp b/src/test/rpc/LedgerClosed_test.cpp new file mode 100644 index 0000000000..aaad8f32be --- /dev/null +++ b/src/test/rpc/LedgerClosed_test.cpp @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +/* + 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 LedgerClosed_test : public beast::unit_test::suite +{ +public: + + void testMonitorRoot() + { + using namespace test::jtx; + Env env {*this}; + Account const alice {"alice"}; + env.fund(XRP(10000), alice); + + auto lc_result = env.rpc("ledger_closed") [jss::result]; + BEAST_EXPECT(lc_result[jss::ledger_hash] == "8AEDBB96643962F1D40F01E25632ABB3C56C9F04B0231EE4B18248B90173D189"); + BEAST_EXPECT(lc_result[jss::ledger_index] == 2); + + env.close(); + auto const ar_master = env.le(env.master); + BEAST_EXPECT(ar_master->getAccountID(sfAccount) == env.master.id()); + BEAST_EXPECT((*ar_master)[sfBalance] == drops( 99999989999999980 )); + + auto const ar_alice = env.le(alice); + BEAST_EXPECT(ar_alice->getAccountID(sfAccount) == alice.id()); + BEAST_EXPECT((*ar_alice)[sfBalance] == XRP( 10000 )); + + lc_result = env.rpc("ledger_closed") [jss::result]; + BEAST_EXPECT(lc_result[jss::ledger_hash] == "7C3EEDB3124D92E49E75D81A8826A2E65A75FD71FC3FD6F36FEB803C5F1D812D"); + BEAST_EXPECT(lc_result[jss::ledger_index] == 3); + } + + void run() + { + testMonitorRoot(); + } +}; + +BEAST_DEFINE_TESTSUITE(LedgerClosed,app,ripple); + +} + diff --git a/src/unity/rpc_test_unity.cpp b/src/unity/rpc_test_unity.cpp index b80341b34f..2134635f69 100644 --- a/src/unity/rpc_test_unity.cpp +++ b/src/unity/rpc_test_unity.cpp @@ -27,9 +27,10 @@ #include #include #include +#include #include #include #include #include #include -#include \ No newline at end of file +#include