@@ -35,175 +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
- soltestAssert (param.abiType .align == ABIType::AlignRight, " " );
62
- if (*byteRange.begin () & 0x80 )
63
- resultStream << u2s (fromBigEndian<u256>(byteRange));
64
- else
65
- resultStream << fromBigEndian<u256>(byteRange);
66
- break ;
67
- case ABIType::UnsignedDec:
68
- // Check if the detected type was wrong and if this could
69
- // be signed. If an unsigned was detected in the expectations,
70
- // but the actual result returned a signed, it would be formatted
71
- // incorrectly.
72
- soltestAssert (param.abiType .align == ABIType::AlignRight, " " );
73
- if (*byteRange.begin () & 0x80 )
74
- resultStream << u2s (fromBigEndian<u256>(byteRange));
75
- else
76
- resultStream << fromBigEndian<u256>(byteRange);
77
- break ;
78
- case ABIType::Hex:
79
- soltestAssert (param.abiType .align == ABIType::AlignLeft, " " );
80
- byteRange.erase (
81
- std::remove (byteRange.begin (), byteRange.end (), 0 ), byteRange.end ()
82
- );
83
- resultStream << toHex (byteRange, HexPrefix::Add);
84
- break ;
85
- case ABIType::Failure:
86
- break ;
87
- case ABIType::None:
88
- break ;
89
- }
90
- it += offset;
91
- if (it != _bytes.end () && !(param.abiType .type == ABIType::None))
92
- resultStream << " , " ;
93
- }
94
- soltestAssert (it == _bytes.end (), " Parameter encoding too short for the given byte range." );
95
- return resultStream.str ();
96
- }
97
-
98
- string formatRawArguments (ParamList const & _params, string const & _linePrefix = " " )
99
- {
100
- stringstream resultStream;
101
- for (auto const & param: _params)
102
- {
103
- if (param.format .newline )
104
- resultStream << endl << _linePrefix << " //" ;
105
- resultStream << " " << param.rawString ;
106
- if (¶m != &_params.back ())
107
- resultStream << " ," ;
108
- }
109
- return resultStream.str ();
110
- }
111
-
112
- string formatFunctionCallTest (
113
- FunctionCallTest const & _test,
114
- string const & _linePrefix = " " ,
115
- bool const _renderResult = false ,
116
- bool const _highlight = false
117
- )
118
- {
119
- using namespace soltest ;
120
- using Token = soltest::Token;
121
-
122
- stringstream _stream;
123
- FunctionCall call = _test.call ;
124
- bool highlight = !_test.matchesExpectation () && _highlight;
125
-
126
- auto formatOutput = [&](bool const _singleLine)
127
- {
128
- string ws = " " ;
129
- string arrow = formatToken (Token::Arrow);
130
- string colon = formatToken (Token::Colon);
131
- string comma = formatToken (Token::Comma);
132
- string comment = formatToken (Token::Comment);
133
- string ether = formatToken (Token::Ether);
134
- string newline = formatToken (Token::Newline);
135
- string failure = formatToken (Token::Failure);
136
-
137
- // / Prints the function signature. This is the same independent from the display-mode.
138
- _stream << _linePrefix << newline << ws << call.signature ;
139
- if (call.value > u256 (0 ))
140
- _stream << comma << ws << call.value << ws << ether;
141
- if (!call.arguments .rawBytes ().empty ())
142
- {
143
- string output = formatRawArguments (call.arguments .parameters , _linePrefix);
144
- _stream << colon << output;
145
- }
146
-
147
- // / Prints comments on the function parameters and the arrow taking
148
- // / the display-mode into account.
149
- if (_singleLine)
150
- {
151
- if (!call.arguments .comment .empty ())
152
- _stream << ws << comment << call.arguments .comment << comment;
153
- _stream << ws << arrow << ws;
154
- }
155
- else
156
- {
157
- _stream << endl << _linePrefix << newline << ws;
158
- if (!call.arguments .comment .empty ())
159
- {
160
- _stream << comment << call.arguments .comment << comment;
161
- _stream << endl << _linePrefix << newline << ws;
162
- }
163
- _stream << arrow << ws;
164
- }
165
-
166
- // / Print either the expected output or the actual result output
167
- string result;
168
- if (!_renderResult)
169
- {
170
- bytes output = call.expectations .rawBytes ();
171
- bool const isFailure = call.expectations .failure ;
172
- result = isFailure ? failure : formatBytes (output, call.expectations .result );
173
- }
174
- else
175
- {
176
- bytes output = _test.rawBytes ;
177
- bool const isFailure = _test.failure ;
178
- result = isFailure ? failure : formatBytes (output, call.expectations .result );
179
- }
180
- AnsiColorized (_stream, highlight, {RED_BACKGROUND}) << result;
181
-
182
- // / Print comments on expectations taking the display-mode into account.
183
- if (_singleLine)
184
- {
185
- if (!call.expectations .comment .empty ())
186
- _stream << ws << comment << call.expectations .comment << comment;
187
- }
188
- else
189
- {
190
- if (!call.expectations .comment .empty ())
191
- {
192
- _stream << endl << _linePrefix << newline << ws;
193
- _stream << comment << call.expectations .comment << comment;
194
- }
195
- }
196
- };
197
-
198
- if (call.displayMode == FunctionCall::DisplayMode::SingleLine)
199
- formatOutput (true );
200
- else
201
- formatOutput (false );
202
- _stream << endl;
203
-
204
- return _stream.str ();
205
- }
206
- }
207
38
208
39
SemanticTest::SemanticTest (string const & _filename, string const & _ipcPath):
209
40
SolidityExecutionFramework(_ipcPath)
@@ -227,27 +58,27 @@ bool SemanticTest::run(ostream& _stream, string const& _linePrefix, bool const _
227
58
for (auto & test: m_tests)
228
59
{
229
60
bytes output = callContractFunctionWithValueNoEncoding (
230
- test.call .signature ,
231
- test.call .value ,
232
- test.call .arguments .rawBytes ()
61
+ test.call () .signature ,
62
+ test.call () .value ,
63
+ test.call () .arguments .rawBytes ()
233
64
);
234
65
235
- 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 ()))
236
67
success = false ;
237
68
238
- test.failure = !m_transactionSuccessful;
239
- test.rawBytes = std::move (output);
69
+ test.setFailure ( !m_transactionSuccessful) ;
70
+ test.setRawBytes ( std::move (output) );
240
71
}
241
72
242
73
if (!success)
243
74
{
244
75
AnsiColorized (_stream, _formatted, {BOLD, CYAN}) << _linePrefix << " Expected result:" << endl;
245
76
for (auto const & test: m_tests)
246
- _stream << formatFunctionCallTest ( test, _linePrefix, false , true & _formatted);
77
+ _stream << test. format ( _linePrefix, false , true & _formatted) << endl ;
247
78
248
79
AnsiColorized (_stream, _formatted, {BOLD, CYAN}) << _linePrefix << " Obtained result:" << endl;
249
80
for (auto const & test: m_tests)
250
- _stream << formatFunctionCallTest ( test, _linePrefix, true , true & _formatted);
81
+ _stream << test. format ( _linePrefix, true , true & _formatted) << endl ;
251
82
252
83
AnsiColorized (_stream, _formatted, {BOLD, RED}) << _linePrefix
253
84
<< " Attention: Updates on the test will apply the detected format displayed." << endl;
@@ -267,14 +98,14 @@ void SemanticTest::printSource(ostream& _stream, string const& _linePrefix, bool
267
98
void SemanticTest::printUpdatedExpectations (ostream& _stream, string const &) const
268
99
{
269
100
for (auto const & test: m_tests)
270
- _stream << formatFunctionCallTest ( test, " " , true , false );
101
+ _stream << test. format ( " " , true , false ) << endl ;
271
102
}
272
103
273
104
void SemanticTest::parseExpectations (istream& _stream)
274
105
{
275
106
TestFileParser parser{_stream};
276
107
for (auto const & call: parser.parseFunctionCalls ())
277
- m_tests.emplace_back (FunctionCallTest {call, bytes{}, string{} });
108
+ m_tests.emplace_back (TestFunctionCall {call});
278
109
}
279
110
280
111
bool SemanticTest::deploy (string const & _contractName, u256 const & _value, bytes const & _arguments)
0 commit comments