Skip to content

Commit 9b36bed

Browse files
author
Leonardo Alt
committedApr 7, 2021
Use SMT engine
1 parent 9bc2e8a commit 9b36bed

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
contract C {
2+
function f() public pure {
3+
}
4+
}
5+
// ====
6+
// SMTEngine: all
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pragma experimental SMTChecker;
2+
contract C {
3+
function f() public pure {
4+
}
5+
}
6+
// ====
7+
// SMTEngine: all
8+
// SMTEngine: chc

‎test/smtcallback.js

+36-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const assert = require('assert');
12
const tape = require('tape');
23
const fs = require('fs');
34
const path = require('path');
@@ -7,7 +8,6 @@ const smtchecker = require('../smtchecker.js');
78
const smtsolver = require('../smtsolver.js');
89

910
var preamble = 'pragma solidity >=0.0;\n// SPDX-License-Identifier: GPL-3.0\n';
10-
var pragmaSMT = 'pragma experimental SMTChecker;\n';
1111

1212
function collectErrors (solOutput) {
1313
if (solOutput === undefined) {
@@ -72,10 +72,20 @@ tape('SMTCheckerCallback', function (t) {
7272
return { error: 'Fake SMT solver error.' };
7373
};
7474

75+
var pragmaSMT = '';
76+
var settings = {};
77+
// `pragma experimental SMTChecker;` was deprecated in 0.8.4
78+
if (!semver.gt(solc.semver(), '0.8.3')) {
79+
pragmaSMT = 'pragma experimental SMTChecker;\n';
80+
} else {
81+
settings = { modelChecker: { engine: 'all' } };
82+
}
83+
7584
var input = { 'a': { content: preamble + pragmaSMT + 'contract C { function f(uint x) public pure { assert(x > 0); } }' } };
7685
var inputJSON = JSON.stringify({
7786
language: 'Solidity',
78-
sources: input
87+
sources: input,
88+
settings: settings
7989
});
8090

8191
var tests;
@@ -152,9 +162,20 @@ tape('SMTCheckerCallback', function (t) {
152162
st.comment('Collecting ' + sources[i] + '...');
153163
var source = fs.readFileSync(sources[i], 'utf8');
154164

155-
if (source.includes('// SMTEngine')) {
156-
st.skip('Test requires specific SMTChecker engine.');
157-
continue;
165+
var engine;
166+
var option = '// SMTEngine: ';
167+
if (source.includes(option)) {
168+
let idx = source.indexOf(option);
169+
if (source.indexOf(option, idx + 1) !== -1) {
170+
st.skip('SMTEngine option given multiple times.');
171+
st.end();
172+
return;
173+
}
174+
let re = new RegExp(option + '(\\w+)');
175+
let m = source.match(re);
176+
assert(m !== undefined);
177+
assert(m.length >= 2);
178+
engine = m[1];
158179
}
159180

160181
var expected = [];
@@ -169,7 +190,8 @@ tape('SMTCheckerCallback', function (t) {
169190
tests[sources[i]] = {
170191
expectations: expected,
171192
solidity: { test: { content: preamble + source } },
172-
ignoreCex: source.includes('// SMTIgnoreCex: yes')
193+
ignoreCex: source.includes('// SMTIgnoreCex: yes'),
194+
engine: engine
173195
};
174196
}
175197

@@ -185,10 +207,17 @@ tape('SMTCheckerCallback', function (t) {
185207
continue;
186208
}
187209

210+
var settings = {};
211+
// `pragma experimental SMTChecker;` was deprecated in 0.8.4
212+
if (semver.gt(solc.semver(), '0.8.3')) {
213+
let engine = test.engine !== undefined ? test.engine : 'all';
214+
settings = { modelChecker: { engine: engine } };
215+
}
188216
var output = JSON.parse(solc.compile(
189217
JSON.stringify({
190218
language: 'Solidity',
191-
sources: test.solidity
219+
sources: test.solidity,
220+
settings: settings
192221
}),
193222
{ smtSolver: smtchecker.smtCallback(smtsolver.smtSolver) }
194223
));

0 commit comments

Comments
 (0)
Please sign in to comment.