@@ -35,166 +35,6 @@ using namespace boost::algorithm;
35
35
using namespace boost ::unit_test;
36
36
namespace fs = boost::filesystem;
37
37
38
- namespace
39
- {
40
- using FunctionCallTest = SemanticTest::FunctionCallTest;
41
- using FunctionCall = dev::solidity::test::FunctionCall;
42
- using ParamList = dev::solidity::test::ParameterList;
43
-
44
-
45
- string formatBytes (bytes const & _bytes, ParamList const & _params)
46
- {
47
- stringstream resultStream;
48
- if (_bytes.empty ())
49
- return {};
50
- auto it = _bytes.begin ();
51
- for (auto const & param: _params)
52
- {
53
- long offset = static_cast <long >(param.abiType .size );
54
- auto offsetIter = it + offset;
55
- soltestAssert (offsetIter <= _bytes.end (), " Byte range can not be extended past the end of given bytes." );
56
-
57
- bytes byteRange{it, offsetIter};
58
- switch (param.abiType .type )
59
- {
60
- case ABIType::SignedDec:
61
- if (*byteRange.begin () & 0x80 )
62
- resultStream << u2s (fromBigEndian<u256>(byteRange));
63
- else
64
- resultStream << fromBigEndian<u256>(byteRange);
65
- break ;
66
- case ABIType::UnsignedDec:
67
- // Check if the detected type was wrong and if this could
68
- // be signed. If an unsigned was detected in the expectations,
69
- // but the actual result returned a signed, it would be formatted
70
- // incorrectly.
71
- if (*byteRange.begin () & 0x80 )
72
- resultStream << u2s (fromBigEndian<u256>(byteRange));
73
- else
74
- resultStream << fromBigEndian<u256>(byteRange);
75
- break ;
76
- case ABIType::Failure:
77
- break ;
78
- case ABIType::None:
79
- break ;
80
- }
81
- it += offset;
82
- if (it != _bytes.end () && !(param.abiType .type == ABIType::None))
83
- resultStream << " , " ;
84
- }
85
- soltestAssert (it == _bytes.end (), " Parameter encoding too short for the given byte range." );
86
- return resultStream.str ();
87
- }
88
-
89
- string formatRawArguments (ParamList const & _params, string const & _linePrefix = " " )
90
- {
91
- stringstream resultStream;
92
- for (auto const & param: _params)
93
- {
94
- if (param.format .newline )
95
- resultStream << endl << _linePrefix << " //" ;
96
- resultStream << " " << param.rawString ;
97
- if (¶m != &_params.back ())
98
- resultStream << " ," ;
99
- }
100
- return resultStream.str ();
101
- }
102
-
103
- string formatFunctionCallTest (
104
- FunctionCallTest const & _test,
105
- string const & _linePrefix = " " ,
106
- bool const _renderResult = false ,
107
- bool const _highlight = false
108
- )
109
- {
110
- using namespace soltest ;
111
- using Token = soltest::Token;
112
-
113
- stringstream _stream;
114
- FunctionCall call = _test.call ;
115
- bool highlight = !_test.matchesExpectation () && _highlight;
116
-
117
- auto formatOutput = [&](bool const _singleLine)
118
- {
119
- string ws = " " ;
120
- string arrow = formatToken (Token::Arrow);
121
- string colon = formatToken (Token::Colon);
122
- string comma = formatToken (Token::Comma);
123
- string comment = formatToken (Token::Comment);
124
- string ether = formatToken (Token::Ether);
125
- string newline = formatToken (Token::Newline);
126
- string failure = formatToken (Token::Failure);
127
-
128
- // / Prints the function signature. This is the same independent from the display-mode.
129
- _stream << _linePrefix << newline << ws << call.signature ;
130
- if (call.value > u256 (0 ))
131
- _stream << comma << ws << call.value << ws << ether;
132
- if (!call.arguments .rawBytes ().empty ())
133
- {
134
- string output = formatRawArguments (call.arguments .parameters , _linePrefix);
135
- _stream << colon << output;
136
- }
137
-
138
- // / Prints comments on the function parameters and the arrow taking
139
- // / the display-mode into account.
140
- if (_singleLine)
141
- {
142
- if (!call.arguments .comment .empty ())
143
- _stream << ws << comment << call.arguments .comment << comment;
144
- _stream << ws << arrow << ws;
145
- }
146
- else
147
- {
148
- _stream << endl << _linePrefix << newline << ws;
149
- if (!call.arguments .comment .empty ())
150
- {
151
- _stream << comment << call.arguments .comment << comment;
152
- _stream << endl << _linePrefix << newline << ws;
153
- }
154
- _stream << arrow << ws;
155
- }
156
-
157
- // / Print either the expected output or the actual result output
158
- string result;
159
- if (!_renderResult)
160
- {
161
- bytes output = call.expectations .rawBytes ();
162
- bool const isFailure = call.expectations .failure ;
163
- result = isFailure ? failure : formatBytes (output, call.expectations .result );
164
- }
165
- else
166
- {
167
- bytes output = _test.rawBytes ;
168
- bool const isFailure = _test.failure ;
169
- result = isFailure ? failure : formatBytes (output, call.expectations .result );
170
- }
171
- AnsiColorized (_stream, highlight, {RED_BACKGROUND}) << result;
172
-
173
- // / Print comments on expectations taking the display-mode into account.
174
- if (_singleLine)
175
- {
176
- if (!call.expectations .comment .empty ())
177
- _stream << ws << comment << call.expectations .comment << comment;
178
- }
179
- else
180
- {
181
- if (!call.expectations .comment .empty ())
182
- {
183
- _stream << endl << _linePrefix << newline << ws;
184
- _stream << comment << call.expectations .comment << comment;
185
- }
186
- }
187
- };
188
-
189
- if (call.displayMode == FunctionCall::DisplayMode::SingleLine)
190
- formatOutput (true );
191
- else
192
- formatOutput (false );
193
- _stream << endl;
194
-
195
- return _stream.str ();
196
- }
197
- }
198
38
199
39
SemanticTest::SemanticTest (string const & _filename, string const & _ipcPath):
200
40
SolidityExecutionFramework(_ipcPath)
@@ -218,27 +58,27 @@ bool SemanticTest::run(ostream& _stream, string const& _linePrefix, bool const _
218
58
for (auto & test: m_tests)
219
59
{
220
60
bytes output = callContractFunctionWithValueNoEncoding (
221
- test.call .signature ,
222
- test.call .value ,
223
- test.call .arguments .rawBytes ()
61
+ test.call () .signature ,
62
+ test.call () .value ,
63
+ test.call () .arguments .rawBytes ()
224
64
);
225
65
226
- if ((m_transactionSuccessful == test.call .expectations .failure ) || (output != test.call .expectations .rawBytes ()))
66
+ if ((m_transactionSuccessful == test.call () .expectations .failure ) || (output != test.call () .expectations .rawBytes ()))
227
67
success = false ;
228
68
229
- test.failure = !m_transactionSuccessful;
230
- test.rawBytes = std::move (output);
69
+ test.setFailure ( !m_transactionSuccessful) ;
70
+ test.setRawBytes ( std::move (output) );
231
71
}
232
72
233
73
if (!success)
234
74
{
235
75
AnsiColorized (_stream, _formatted, {BOLD, CYAN}) << _linePrefix << " Expected result:" << endl;
236
76
for (auto const & test: m_tests)
237
- _stream << formatFunctionCallTest ( test, _linePrefix, false , true & _formatted);
77
+ _stream << test. format ( _linePrefix, false , true & _formatted) << endl ;
238
78
239
79
AnsiColorized (_stream, _formatted, {BOLD, CYAN}) << _linePrefix << " Obtained result:" << endl;
240
80
for (auto const & test: m_tests)
241
- _stream << formatFunctionCallTest ( test, _linePrefix, true , true & _formatted);
81
+ _stream << test. format ( _linePrefix, true , true & _formatted) << endl ;
242
82
243
83
AnsiColorized (_stream, _formatted, {BOLD, RED}) << _linePrefix
244
84
<< " Attention: Updates on the test will apply the detected format displayed." << endl;
@@ -258,14 +98,14 @@ void SemanticTest::printSource(ostream& _stream, string const& _linePrefix, bool
258
98
void SemanticTest::printUpdatedExpectations (ostream& _stream, string const &) const
259
99
{
260
100
for (auto const & test: m_tests)
261
- _stream << formatFunctionCallTest ( test, " " , true , false );
101
+ _stream << test. format ( " " , true , false ) << endl ;
262
102
}
263
103
264
104
void SemanticTest::parseExpectations (istream& _stream)
265
105
{
266
106
TestFileParser parser{_stream};
267
107
for (auto const & call: parser.parseFunctionCalls ())
268
- m_tests.emplace_back (FunctionCallTest {call, bytes{}, string{} });
108
+ m_tests.emplace_back (TestFunctionCall {call});
269
109
}
270
110
271
111
bool SemanticTest::deploy (string const & _contractName, u256 const & _value, bytes const & _arguments)
0 commit comments