Skip to content

Commit 08aa7e4

Browse files
authored
Merge pull request #4305 from ethereum/transactionReceipts
Determine transaction status in RPC sessions.
2 parents da60fda + 334c023 commit 08aa7e4

13 files changed

Lines changed: 57 additions & 1 deletion

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Language Features:
3939

4040
Compiler Features:
4141
* Type Checker: Show named argument in case of error.
42+
* Tests: Determine transaction status during IPC calls.
4243

4344
Bugfixes:
4445
* Tests: Fix chain parameters to make ipc tests work with newer versions of cpp-ethereum.

test/ExecutionFramework.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ void ExecutionFramework::sendMessage(bytes const& _data, bool _isCreation, u256
142142
entry.data = fromHex(log.data, WhenError::Throw);
143143
m_logs.push_back(entry);
144144
}
145+
146+
if (!receipt.status.empty())
147+
m_transactionSuccessful = (receipt.status == "1");
148+
else
149+
m_transactionSuccessful = (m_gas != m_gasUsed);
145150
}
146151

147152
void ExecutionFramework::sendEther(Address const& _to, u256 const& _value)

test/ExecutionFramework.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class ExecutionFramework
7272
)
7373
{
7474
compileAndRunWithoutCheck(_sourceCode, _value, _contractName, _arguments, _libraryAddresses);
75+
BOOST_REQUIRE(m_transactionSuccessful);
7576
BOOST_REQUIRE(!m_output.empty());
7677
return m_output;
7778
}
@@ -234,6 +235,7 @@ class ExecutionFramework
234235
unsigned m_optimizeRuns = 200;
235236
bool m_optimize = false;
236237
bool m_showMessages = false;
238+
bool m_transactionSuccessful = true;
237239
Address m_sender;
238240
Address m_contractAddress;
239241
u256 m_blockNumber;

test/RPCSession.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ RPCSession::TransactionReceipt RPCSession::eth_getTransactionReceipt(string cons
163163
receipt.gasUsed = result["gasUsed"].asString();
164164
receipt.contractAddress = result["contractAddress"].asString();
165165
receipt.blockNumber = result["blockNumber"].asString();
166+
if (m_receiptHasStatusField)
167+
{
168+
BOOST_REQUIRE(!result["status"].isNull());
169+
receipt.status = result["status"].asString();
170+
}
166171
for (auto const& log: result["logs"])
167172
{
168173
LogEntry entry;
@@ -225,7 +230,10 @@ void RPCSession::test_setChainParams(vector<string> const& _accounts)
225230
if (test::Options::get().evmVersion() >= solidity::EVMVersion::spuriousDragon())
226231
forks += "\"EIP158ForkBlock\": \"0x00\",\n";
227232
if (test::Options::get().evmVersion() >= solidity::EVMVersion::byzantium())
233+
{
228234
forks += "\"byzantiumForkBlock\": \"0x00\",\n";
235+
m_receiptHasStatusField = true;
236+
}
229237
if (test::Options::get().evmVersion() >= solidity::EVMVersion::constantinople())
230238
forks += "\"constantinopleForkBlock\": \"0x00\",\n";
231239
static string const c_configString = R"(

test/RPCSession.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class RPCSession: public boost::noncopyable
9999
std::string contractAddress;
100100
std::vector<LogEntry> logEntries;
101101
std::string blockNumber;
102+
/// note: pre-byzantium the status field will be empty
103+
std::string status;
102104
};
103105

104106
static RPCSession& instance(std::string const& _path);
@@ -136,6 +138,7 @@ class RPCSession: public boost::noncopyable
136138
unsigned m_maxMiningTime = 6000000; // 600 seconds
137139
unsigned m_sleepTime = 10; // 10 milliseconds
138140
unsigned m_successfulMineRuns = 0;
141+
bool m_receiptHasStatusField = false;
139142

140143
std::vector<std::string> m_accounts;
141144
};

test/contracts/AuctionRegistrar.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ class AuctionRegistrarTestFramework: public SolidityExecutionFramework
223223
s_compiledRegistrar.reset(new bytes(compileContract(registrarCode, "GlobalRegistrar")));
224224

225225
sendMessage(*s_compiledRegistrar, true);
226+
BOOST_REQUIRE(m_transactionSuccessful);
226227
BOOST_REQUIRE(!m_output.empty());
227228
}
228229

test/contracts/FixedFeeRegistrar.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class RegistrarTestFramework: public SolidityExecutionFramework
135135
s_compiledRegistrar.reset(new bytes(compileContract(registrarCode, "FixedFeeRegistrar")));
136136

137137
sendMessage(*s_compiledRegistrar, true);
138+
BOOST_REQUIRE(m_transactionSuccessful);
138139
BOOST_REQUIRE(!m_output.empty());
139140
}
140141
u256 const m_fee = u256("69000000000000000000");

test/contracts/LLL_ENS.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ class LLLENSTestFramework: public LLLExecutionFramework
349349
BOOST_REQUIRE(errors.empty());
350350
}
351351
sendMessage(*s_compiledEns, true);
352+
BOOST_REQUIRE(m_transactionSuccessful);
352353
BOOST_REQUIRE(!m_output.empty());
353354
}
354355

test/contracts/LLL_ERC20.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ class LLLERC20TestFramework: public LLLExecutionFramework
400400
BOOST_REQUIRE(errors.empty());
401401
}
402402
sendMessage(*s_compiledErc20, true);
403+
BOOST_REQUIRE(m_transactionSuccessful);
403404
BOOST_REQUIRE(!m_output.empty());
404405
}
405406

@@ -629,18 +630,22 @@ BOOST_AUTO_TEST_CASE(bad_data)
629630

630631
// Correct data: transfer(address _to, 1).
631632
sendMessage((bytes)fromHex("a9059cbb") + (bytes)fromHex("000000000000000000000000123456789a123456789a123456789a123456789a") + encodeArgs(1), false, 0);
633+
BOOST_CHECK(m_transactionSuccessful);
632634
BOOST_CHECK(m_output == SUCCESS);
633635

634636
// Too little data (address is truncated by one byte).
635637
sendMessage((bytes)fromHex("a9059cbb") + (bytes)fromHex("000000000000000000000000123456789a123456789a123456789a12345678") + encodeArgs(1), false, 0);
638+
BOOST_CHECK(!m_transactionSuccessful);
636639
BOOST_CHECK(m_output != SUCCESS);
637640

638641
// Too much data (address is extended with a zero byte).
639642
sendMessage((bytes)fromHex("a9059cbb") + (bytes)fromHex("000000000000000000000000123456789a123456789a123456789a123456789a00") + encodeArgs(1), false, 0);
643+
BOOST_CHECK(!m_transactionSuccessful);
640644
BOOST_CHECK(m_output != SUCCESS);
641645

642646
// Invalid address (a bit above the 160th is set).
643647
sendMessage((bytes)fromHex("a9059cbb") + (bytes)fromHex("000000000000000000000100123456789a123456789a123456789a123456789a") + encodeArgs(1), false, 0);
648+
BOOST_CHECK(!m_transactionSuccessful);
644649
BOOST_CHECK(m_output != SUCCESS);
645650
}
646651

test/contracts/Wallet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ class WalletTestFramework: public SolidityExecutionFramework
451451

452452
bytes args = encodeArgs(u256(0x60), _required, _dailyLimit, u256(_owners.size()), _owners);
453453
sendMessage(*s_compiledWallet + args, true, _value);
454+
BOOST_REQUIRE(m_transactionSuccessful);
454455
BOOST_REQUIRE(!m_output.empty());
455456
}
456457
};

0 commit comments

Comments
 (0)