From e97e631d8e9656ce514d04065d1182f3e686219e Mon Sep 17 00:00:00 2001 From: Matthew Roll Date: Mon, 19 Mar 2018 09:24:04 -0400 Subject: [PATCH] port ethereum tests to individual files (issue #809) (#820) * Add contract keyword arg to IntegrationTest._simple_cli_run * Remove inline tests from test_eth * Refactor IntegrationTest.test_eth_regressions to support multi-contract files --- tests/binaries/799.sol | 2 ++ tests/binaries/807.sol | 11 +++++++++++ tests/test_binaries.py | 30 +++++++++++++++++++++++++----- tests/test_eth.py | 33 --------------------------------- 4 files changed, 38 insertions(+), 38 deletions(-) create mode 100644 tests/binaries/799.sol create mode 100644 tests/binaries/807.sol diff --git a/tests/binaries/799.sol b/tests/binaries/799.sol new file mode 100644 index 0000000..8d83d38 --- /dev/null +++ b/tests/binaries/799.sol @@ -0,0 +1,2 @@ +contract X { function X(address x) {} } +contract C { function C(address x) { new X(x); } } diff --git a/tests/binaries/807.sol b/tests/binaries/807.sol new file mode 100644 index 0000000..51556a3 --- /dev/null +++ b/tests/binaries/807.sol @@ -0,0 +1,11 @@ +contract X { + mapping(address => uint) private balance; + function f(address z) returns (uint) { return balance[z]; } +} +contract C { + X y; + function C() { + y = new X(); + uint z = y.f(0); + } +} diff --git a/tests/test_binaries.py b/tests/test_binaries.py index 79f525b..83159db 100644 --- a/tests/test_binaries.py +++ b/tests/test_binaries.py @@ -31,7 +31,7 @@ class IntegrationTest(unittest.TestCase): return set(vitems) - def _simple_cli_run(self, filename): + def _simple_cli_run(self, filename, contract=None): """ Simply run the Manticore command line with `filename` :param filename: Name of file inside the `tests/binaries` directory @@ -39,7 +39,14 @@ class IntegrationTest(unittest.TestCase): """ dirname = os.path.dirname(__file__) filename = '{}/binaries/{}'.format(dirname, filename) - subprocess.check_call(['python', '-m', 'manticore', filename], stdout=subprocess.PIPE) + command = ['python', '-m', 'manticore'] + + if contract: + command.append('--contract') + command.append(contract) + command.append(filename) + + subprocess.check_call(command, stdout=subprocess.PIPE) def _runWithTimeout(self, procargs, logfile, timeout=1200): @@ -128,9 +135,22 @@ class IntegrationTest(unittest.TestCase): self.assertTrue(len(actual) > 100 ) def test_eth_regressions(self): - contracts = [676, 678, 701, 714, 735, 760, 780, 795] - for contract in contracts: - self._simple_cli_run('{}.sol'.format(contract)) + issues = [ + {'number': 676, 'contract': None}, + {'number': 678, 'contract': None}, + {'number': 701, 'contract': None}, + {'number': 714, 'contract': None}, + {'number': 735, 'contract': None}, + {'number': 760, 'contract': None}, + {'number': 780, 'contract': None}, + {'number': 795, 'contract': None}, + {'number': 799, 'contract': 'C'}, + {'number': 807, 'contract': 'C'}, + ] + + for issue in issues: + self._simple_cli_run('{}.sol'.format(issue['number']), + contract=issue['contract']) def test_eth_705(self): # This test needs to run inside tests/binaries because the contract imports a file diff --git a/tests/test_eth.py b/tests/test_eth.py index 6950ea6..5fd4225 100644 --- a/tests/test_eth.py +++ b/tests/test_eth.py @@ -117,39 +117,6 @@ class EthTests(unittest.TestCase): with self.assertRaises(NoAliveStates): contract_account.f(m.SValue) # no alive states, but try to run a tx anyway - def test_can_create(self): - mevm = ManticoreEVM() - source_code = """ - contract X { function X(address x) {} } - contract C { function C(address x) { new X(x); } - } - """ - # Make sure that we can can call CREATE without raising an exception - owner = mevm.create_account(balance=1000) - x = mevm.create_account(balance=0) - contract_account = mevm.solidity_create_contract(source_code, - contract_name="C", owner=owner, args=[x]) - - def test_writebuffer_doesnt_raise(self): - mevm = ManticoreEVM() - source_code = """ - contract X { - mapping(address => uint) private balance; - function f(address z) returns (uint) { return balance[z]; } - } - contract C { - X y; - function C() { - y = new X(); - uint z = y.f(0); - } - }""" - # Make sure that write_buffer (used by RETURN) succeeds without errors - owner = mevm.create_account(balance=1000) - x = mevm.create_account(balance=0) - contract_account = mevm.solidity_create_contract(source_code, - contract_name="C", owner=owner, args=[x]) - class EthHelpers(unittest.TestCase): def setUp(self):