rippled
apply_test.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2020 Dev Null Productions
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 <ripple/app/tx/apply.h>
21 #include <ripple/basics/StringUtilities.h>
22 #include <ripple/protocol/Feature.h>
23 #include <test/jtx/Env.h>
24 
25 namespace ripple {
26 
27 class Apply_test : public beast::unit_test::suite
28 {
29 public:
30  void
31  run() override
32  {
33  testcase("Require Fully Canonicial Signature");
35  }
36 
37  void
39  {
40  // Construct a payments w/out a fully-canonical tx
41  const std::string non_fully_canonical_tx =
42  "12000022000000002400000001201B00497D9C6140000000000F6950684000000"
43  "00000000C732103767C7B2C13AD90050A4263745E4BAB2B975417FA22E87780E1"
44  "506DDAF21139BE74483046022100E95670988A34C4DB0FA73A8BFD6383872AF43"
45  "8C147A62BC8387406298C3EADC1022100A7DC80508ED5A4750705C702A81CBF9D"
46  "2C2DC3AFEDBED37BBCCD97BC8C40E08F8114E25A26437D923EEF4D6D815DF9336"
47  "8B62E6440848314BB85996936E4F595287774684DC2AC6266024BEF";
48 
49  auto ret = strUnHex(non_fully_canonical_tx);
50  SerialIter sitTrans(makeSlice(*ret));
51  STTx const tx = *std::make_shared<STTx const>(std::ref(sitTrans));
52 
53  {
54  test::jtx::Env no_fully_canonical(
55  *this,
58 
59  Validity valid = checkValidity(
60  no_fully_canonical.app().getHashRouter(),
61  tx,
62  no_fully_canonical.current()->rules(),
63  no_fully_canonical.app().config())
64  .first;
65 
66  if (valid != Validity::Valid)
67  fail("Non-Fully canoncial signature was not permitted");
68  }
69 
70  {
71  test::jtx::Env fully_canonical(
73 
74  Validity valid = checkValidity(
75  fully_canonical.app().getHashRouter(),
76  tx,
77  fully_canonical.current()->rules(),
78  fully_canonical.app().config())
79  .first;
80  if (valid == Validity::Valid)
81  fail("Non-Fully canoncial signature was permitted");
82  }
83 
84  pass();
85  }
86 };
87 
88 BEAST_DEFINE_TESTSUITE(Apply, app, ripple);
89 
90 } // namespace ripple
ripple::makeSlice
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
Definition: Slice.h:241
std::string
STL class.
ripple::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, ripple)
ripple::test::jtx::Env::app
Application & app()
Definition: Env.h:241
ripple::Validity
Validity
Describes the pre-processing validity of a transaction.
Definition: apply.h:40
ripple::Apply_test::testFullyCanonicalSigs
void testFullyCanonicalSigs()
Definition: apply_test.cpp:38
ripple::featureRequireFullyCanonicalSig
const uint256 featureRequireFullyCanonicalSig
ripple::checkValidity
std::pair< Validity, std::string > checkValidity(HashRouter &router, STTx const &tx, Rules const &rules, Config const &config)
Checks transaction signature and local checks.
Definition: apply.cpp:37
ripple::Application::config
virtual Config & config()=0
ripple::STTx
Definition: STTx.h:45
ripple::Apply_test::run
void run() override
Definition: apply_test.cpp:31
ripple::SerialIter
Definition: Serializer.h:310
ripple::test::jtx::supported_amendments
FeatureBitset supported_amendments()
Definition: Env.h:70
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Validity::Valid
@ Valid
Signature and local checks are good / passed.
ripple::strUnHex
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
Definition: StringUtilities.h:50
ripple::Apply_test
Definition: apply_test.cpp:27
ripple::Application::getHashRouter
virtual HashRouter & getHashRouter()=0
ripple::test::jtx::Env::current
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition: Env.h:300
ripple::test::jtx::Env
A transaction testing environment.
Definition: Env.h:116
std::ref
T ref(T... args)