Browse Source

cover1: Transaction

cl-refactor
Dimitry 10 years ago
parent
commit
fa68d87e6a
  1. 126
      test/libethereum/Transaction.cpp

126
test/libethereum/Transaction.cpp

@ -23,36 +23,9 @@
#include "test/TestHelper.h"
#include <libethcore/Exceptions.h>
#include <libevm/VMFace.h>
#include <libethcore/Common.h>
/*std::ostream& dev::eth::operator<<(std::ostream& _out, ExecutionResult const& _er)
{
_out << "{" << _er.gasUsed << ", " << _er.newAddress << ", " << toHex(_er.output) << "}";
return _out;
}
std::ostream& dev::eth::operator<<(std::ostream& _out, TransactionException const& _er)
{
switch (_er)
{
case TransactionException::None: _out << "None"; break;
case TransactionException::BadRLP: _out << "BadRLP"; break;
case TransactionException::InvalidFormat: _out << "InvalidFormat"; break;
case TransactionException::OutOfGasIntrinsic: _out << "OutOfGasIntrinsic"; break;
case TransactionException::InvalidSignature: _out << "InvalidSignature"; break;
case TransactionException::InvalidNonce: _out << "InvalidNonce"; break;
case TransactionException::NotEnoughCash: _out << "NotEnoughCash"; break;
case TransactionException::OutOfGasBase: _out << "OutOfGasBase"; break;
case TransactionException::BlockGasLimitReached: _out << "BlockGasLimitReached"; break;
case TransactionException::BadInstruction: _out << "BadInstruction"; break;
case TransactionException::BadJumpDestination: _out << "BadJumpDestination"; break;
case TransactionException::OutOfGas: _out << "OutOfGas"; break;
case TransactionException::OutOfStack: _out << "OutOfStack"; break;
case TransactionException::StackUnderflow: _out << "StackUnderflow"; break;
default: _out << "Unknown"; break;
}
return _out;
}
/*
Transaction::Transaction(bytesConstRef _rlpData, CheckTransaction _checkSig):
TransactionBase(_rlpData, _checkSig)
{
@ -73,6 +46,101 @@ using namespace eth;
BOOST_AUTO_TEST_SUITE(libethereum)
BOOST_AUTO_TEST_CASE(TransactionConstructor)
{
try
{
Transaction(fromHex("0xf86d800182521c94095e7baea6a6c7c4c2dfeb977efac326af552d870a8e0358ac39584bc98a7c979f984b031ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804"), CheckTransaction::Everything);
}
case(Exception::)
{
}
}
}
BOOST_AUTO_TEST_CASE(ExecutionResultOutput)
{
std::stringstream buffer;
ExecutionResult exRes;
exRes.gasUsed = u256("12345");
exRes.newAddress = Address("a94f5374fce5edbc8e2a8697c15331677e6ebf0b");
exRes.output = fromHex("001122334455");
buffer << exRes;
BOOST_CHECK_MESSAGE(buffer.str() == "{12345, a94f5374fce5edbc8e2a8697c15331677e6ebf0b, 001122334455}", "Error ExecutionResultOutput");
}
BOOST_AUTO_TEST_CASE(transactionExceptionOutput)
{
std::stringstream buffer;
buffer << TransactionException::BadInstruction;
BOOST_CHECK_MESSAGE(buffer.str() == "BadInstruction", "Error output TransactionException::BadInstruction");
buffer.str(std::string());
buffer << TransactionException::None;
BOOST_CHECK_MESSAGE(buffer.str() == "None", "Error output TransactionException::None");
buffer.str(std::string());
buffer << TransactionException::BadRLP;
BOOST_CHECK_MESSAGE(buffer.str() == "BadRLP", "Error output TransactionException::BadRLP");
buffer.str(std::string());
buffer << TransactionException::InvalidFormat;
BOOST_CHECK_MESSAGE(buffer.str() == "InvalidFormat", "Error output TransactionException::InvalidFormat");
buffer.str(std::string());
buffer << TransactionException::OutOfGasIntrinsic;
BOOST_CHECK_MESSAGE(buffer.str() == "OutOfGasIntrinsic", "Error output TransactionException::OutOfGasIntrinsic");
buffer.str(std::string());
buffer << TransactionException::InvalidSignature;
BOOST_CHECK_MESSAGE(buffer.str() == "InvalidSignature", "Error output TransactionException::InvalidSignature");
buffer.str(std::string());
buffer << TransactionException::InvalidNonce;
BOOST_CHECK_MESSAGE(buffer.str() == "InvalidNonce", "Error output TransactionException::InvalidNonce");
buffer.str(std::string());
buffer << TransactionException::NotEnoughCash;
BOOST_CHECK_MESSAGE(buffer.str() == "NotEnoughCash", "Error output TransactionException::NotEnoughCash");
buffer.str(std::string());
buffer << TransactionException::OutOfGasBase;
BOOST_CHECK_MESSAGE(buffer.str() == "OutOfGasBase", "Error output TransactionException::OutOfGasBase");
buffer.str(std::string());
buffer << TransactionException::BlockGasLimitReached;
BOOST_CHECK_MESSAGE(buffer.str() == "BlockGasLimitReached", "Error output TransactionException::BlockGasLimitReached");
buffer.str(std::string());
buffer << TransactionException::BadInstruction;
BOOST_CHECK_MESSAGE(buffer.str() == "BadInstruction", "Error output TransactionException::BadInstruction");
buffer.str(std::string());
buffer << TransactionException::BadJumpDestination;
BOOST_CHECK_MESSAGE(buffer.str() == "BadJumpDestination", "Error output TransactionException::BadJumpDestination");
buffer.str(std::string());
buffer << TransactionException::OutOfGas;
BOOST_CHECK_MESSAGE(buffer.str() == "OutOfGas", "Error output TransactionException::OutOfGas");
buffer.str(std::string());
buffer << TransactionException::OutOfStack;
BOOST_CHECK_MESSAGE(buffer.str() == "OutOfStack", "Error output TransactionException::OutOfStack");
buffer.str(std::string());
buffer << TransactionException::StackUnderflow;
BOOST_CHECK_MESSAGE(buffer.str() == "StackUnderflow", "Error output TransactionException::StackUnderflow");
buffer.str(std::string());
buffer << TransactionException(-1);
BOOST_CHECK_MESSAGE(buffer.str() == "Unknown", "Error output TransactionException::StackUnderflow");
buffer.str(std::string());
}
BOOST_AUTO_TEST_CASE(toTransactionExceptionConvert)
{
RLPException rlpEx("exception");//toTransactionException(*(dynamic_cast<Exception*>

Loading…
Cancel
Save