Fabcoin Core  0.16.2
P2P Digital Currency
Transaction.cpp
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
24 #include <libethcore/Exceptions.h>
25 #include <libethcore/Common.h>
26 #include <libevm/VMFace.h>
27 using namespace dev;
28 using namespace eth;
29 using namespace dev::test;
30 
32 
33 BOOST_AUTO_TEST_CASE(TransactionGasRequired)
34 {
35  Transaction tr(fromHex("0xf86d800182521c94095e7baea6a6c7c4c2dfeb977efac326af552d870a8e0358ac39584bc98a7c979f984b031ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804"), CheckTransaction::None);
36  BOOST_CHECK_EQUAL(tr.baseGasRequired(FrontierSchedule), 21952);
37 }
38 
39 BOOST_AUTO_TEST_CASE(ExecutionResultOutput)
40 {
41  std::stringstream buffer;
42  ExecutionResult exRes;
43 
44  exRes.gasUsed = u256("12345");
45  exRes.newAddress = Address("a94f5374fce5edbc8e2a8697c15331677e6ebf0b");
46  exRes.output = fromHex("001122334455");
47 
48  buffer << exRes;
49  BOOST_CHECK_MESSAGE(buffer.str() == "{12345, a94f5374fce5edbc8e2a8697c15331677e6ebf0b, 001122334455}", "Error ExecutionResultOutput");
50 }
51 
52 BOOST_AUTO_TEST_CASE(transactionExceptionOutput)
53 {
54  std::stringstream buffer;
56  BOOST_CHECK_MESSAGE(buffer.str() == "BadInstruction", "Error output TransactionException::BadInstruction");
57  buffer.str(std::string());
58 
60  BOOST_CHECK_MESSAGE(buffer.str() == "None", "Error output TransactionException::None");
61  buffer.str(std::string());
62 
64  BOOST_CHECK_MESSAGE(buffer.str() == "BadRLP", "Error output TransactionException::BadRLP");
65  buffer.str(std::string());
66 
68  BOOST_CHECK_MESSAGE(buffer.str() == "InvalidFormat", "Error output TransactionException::InvalidFormat");
69  buffer.str(std::string());
70 
72  BOOST_CHECK_MESSAGE(buffer.str() == "OutOfGasIntrinsic", "Error output TransactionException::OutOfGasIntrinsic");
73  buffer.str(std::string());
74 
76  BOOST_CHECK_MESSAGE(buffer.str() == "InvalidSignature", "Error output TransactionException::InvalidSignature");
77  buffer.str(std::string());
78 
80  BOOST_CHECK_MESSAGE(buffer.str() == "InvalidNonce", "Error output TransactionException::InvalidNonce");
81  buffer.str(std::string());
82 
84  BOOST_CHECK_MESSAGE(buffer.str() == "NotEnoughCash", "Error output TransactionException::NotEnoughCash");
85  buffer.str(std::string());
86 
88  BOOST_CHECK_MESSAGE(buffer.str() == "OutOfGasBase", "Error output TransactionException::OutOfGasBase");
89  buffer.str(std::string());
90 
92  BOOST_CHECK_MESSAGE(buffer.str() == "BlockGasLimitReached", "Error output TransactionException::BlockGasLimitReached");
93  buffer.str(std::string());
94 
96  BOOST_CHECK_MESSAGE(buffer.str() == "BadInstruction", "Error output TransactionException::BadInstruction");
97  buffer.str(std::string());
98 
100  BOOST_CHECK_MESSAGE(buffer.str() == "BadJumpDestination", "Error output TransactionException::BadJumpDestination");
101  buffer.str(std::string());
102 
104  BOOST_CHECK_MESSAGE(buffer.str() == "OutOfGas", "Error output TransactionException::OutOfGas");
105  buffer.str(std::string());
106 
108  BOOST_CHECK_MESSAGE(buffer.str() == "OutOfStack", "Error output TransactionException::OutOfStack");
109  buffer.str(std::string());
110 
112  BOOST_CHECK_MESSAGE(buffer.str() == "StackUnderflow", "Error output TransactionException::StackUnderflow");
113  buffer.str(std::string());
114 
115  buffer << TransactionException(-1);
116  BOOST_CHECK_MESSAGE(buffer.str() == "Unknown", "Error output TransactionException::StackUnderflow");
117  buffer.str(std::string());
118 }
119 
120 BOOST_AUTO_TEST_CASE(toTransactionExceptionConvert)
121 {
122  RLPException rlpEx("exception");//toTransactionException(*(dynamic_cast<Exception*>
123  BOOST_CHECK_MESSAGE(toTransactionException(rlpEx) == TransactionException::BadRLP, "RLPException !=> TransactionException");
124  OutOfGasIntrinsic oogEx;
125  BOOST_CHECK_MESSAGE(toTransactionException(oogEx) == TransactionException::OutOfGasIntrinsic, "OutOfGasIntrinsic !=> TransactionException");
126  InvalidSignature sigEx;
127  BOOST_CHECK_MESSAGE(toTransactionException(sigEx) == TransactionException::InvalidSignature, "InvalidSignature !=> TransactionException");
128  OutOfGasBase oogbEx;
129  BOOST_CHECK_MESSAGE(toTransactionException(oogbEx) == TransactionException::OutOfGasBase, "OutOfGasBase !=> TransactionException");
130  InvalidNonce nonceEx;
131  BOOST_CHECK_MESSAGE(toTransactionException(nonceEx) == TransactionException::InvalidNonce, "InvalidNonce !=> TransactionException");
132  NotEnoughCash cashEx;
133  BOOST_CHECK_MESSAGE(toTransactionException(cashEx) == TransactionException::NotEnoughCash, "NotEnoughCash !=> TransactionException");
134  BlockGasLimitReached blGasEx;
135  BOOST_CHECK_MESSAGE(toTransactionException(blGasEx) == TransactionException::BlockGasLimitReached, "BlockGasLimitReached !=> TransactionException");
136  BadInstruction badInsEx;
137  BOOST_CHECK_MESSAGE(toTransactionException(badInsEx) == TransactionException::BadInstruction, "BadInstruction !=> TransactionException");
138  BadJumpDestination badJumpEx;
139  BOOST_CHECK_MESSAGE(toTransactionException(badJumpEx) == TransactionException::BadJumpDestination, "BadJumpDestination !=> TransactionException");
140  OutOfGas oogEx2;
141  BOOST_CHECK_MESSAGE(toTransactionException(oogEx2) == TransactionException::OutOfGas, "OutOfGas !=> TransactionException");
142  OutOfStack oosEx;
143  BOOST_CHECK_MESSAGE(toTransactionException(oosEx) == TransactionException::OutOfStack, "OutOfStack !=> TransactionException");
144  StackUnderflow stackEx;
145  BOOST_CHECK_MESSAGE(toTransactionException(stackEx) == TransactionException::StackUnderflow, "StackUnderflow !=> TransactionException");
146  Exception notEx;
147  BOOST_CHECK_MESSAGE(toTransactionException(notEx) == TransactionException::Unknown, "Unexpected should be TransactionException::Unknown");
148 }
149 
Too little gas to pay for the base transaction cost.
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
h160 Address
An Ethereum address: 20 bytes.
Definition: Common.h:62
int64_t baseGasRequired(EVMSchedule const &_es) const
Definition: Transaction.h:148
Ran out of stack executing code of the transaction.
Description of the result of executing a transaction.
Definition: Transaction.h:69
BOOST_AUTO_TEST_CASE(TransactionGasRequired)
Definition: Transaction.cpp:33
Ran out of gas executing code of the transaction.
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
Definition: CommonData.cpp:99
Base class for all exceptions.
Definition: Exceptions.h:39
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
Definition: Common.h:125
Encodes a transaction, ready to be exported to or freshly imported from RLP.
Definition: Transaction.h:84
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
Base class for all RLP exceptions.
Definition: Exceptions.h:51
#define BOOST_AUTO_TEST_SUITE_END()
Definition: object.cpp:16
Too little gas to pay for the base transaction cost.
TransactionException
Definition: Transaction.h:35
Helper functions to work with json::spirit and test files.
TransactionException toTransactionException(Exception const &_e)
Definition: Transaction.cpp:42