mirror of https://github.com/ConsenSys/mythril
parent
1ac4087802
commit
01aef7783c
@ -0,0 +1,10 @@ |
|||||||
|
from pathlib import Path |
||||||
|
import os |
||||||
|
|
||||||
|
TESTS_DIR = Path(__file__).parent |
||||||
|
PROJECT_DIR = TESTS_DIR.parent |
||||||
|
TESTDATA = TESTS_DIR / "testdata" |
||||||
|
TESTDATA_INPUTS = TESTDATA / "inputs" |
||||||
|
TESTDATA_OUTPUTS = TESTDATA / "outputs" |
||||||
|
|
||||||
|
os.environ['MYTHRIL_DIR'] = str(TESTS_DIR / "mythril_dir") |
@ -1,56 +1,53 @@ |
|||||||
from unittest import TestCase |
from unittest import TestCase |
||||||
from subprocess import check_output |
from subprocess import check_output |
||||||
from pathlib import Path |
from tests import * |
||||||
|
|
||||||
|
MYTH = str(PROJECT_DIR / "myth") |
||||||
|
|
||||||
def output_of(command): |
def output_of(command): |
||||||
return check_output(command, shell=True).decode("UTF-8") |
return check_output(command, shell=True).decode("UTF-8") |
||||||
|
|
||||||
class BaseTestCase(TestCase): |
class CommandLineToolTestCase(TestCase): |
||||||
def setUp(self): |
|
||||||
self.tests_dir = Path(__file__).parent |
|
||||||
self.myth = str(self.tests_dir.parent / "myth") |
|
||||||
|
|
||||||
class CommandLineToolTestCase(BaseTestCase): |
|
||||||
|
|
||||||
def test_disassemble_code_correctly(self): |
def test_disassemble_code_correctly(self): |
||||||
command = "python3 {} self.myth -d -c 0x5050".format(self.myth) |
command = "python3 {} MYTH -d -c 0x5050".format(MYTH) |
||||||
self.assertEqual('0 POP\n1 POP\n', output_of(command)) |
self.assertEqual('0 POP\n1 POP\n', output_of(command)) |
||||||
|
|
||||||
def test_disassemble_solidity_file_correctly(self): |
def test_disassemble_solidity_file_correctly(self): |
||||||
solidity_file = str(self.tests_dir / 'testdata/inputs/metacoin.sol') |
solidity_file = str(TESTDATA_INPUTS / 'metacoin.sol') |
||||||
command = "python3 {} -d {}".format(self.myth, solidity_file) |
command = "python3 {} -d {}".format(MYTH, solidity_file) |
||||||
self.assertIn('0 PUSH1 0x60\n2 PUSH1 0x40', output_of(command)) |
self.assertIn('0 PUSH1 0x60\n2 PUSH1 0x40', output_of(command)) |
||||||
|
|
||||||
def test_hash_a_function_correctly(self): |
def test_hash_a_function_correctly(self): |
||||||
command = "python3 {} --hash 'setOwner(address)'".format(self.myth) |
command = "python3 {} --hash 'setOwner(address)'".format(MYTH) |
||||||
self.assertEqual('0x13af4035\n', output_of(command)) |
self.assertEqual('0x13af4035\n', output_of(command)) |
||||||
|
|
||||||
class TruffleTestCase(BaseTestCase): |
class TruffleTestCase(TestCase): |
||||||
|
|
||||||
def test_analysis_truffle_project(self): |
def test_analysis_truffle_project(self): |
||||||
truffle_project_root = str(self.tests_dir / "truffle_project") |
truffle_project_root = str(TESTS_DIR / "truffle_project") |
||||||
command = "cd {}; truffle compile; python3 {} --truffle".format(truffle_project_root, self.myth) |
command = "cd {}; truffle compile; python3 {} --truffle".format(truffle_project_root, MYTH) |
||||||
self.assertIn("In the function 'withdrawfunds()' a non-zero amount of Ether is sent to msg.sender.", output_of(command)) |
self.assertIn("In the function 'withdrawfunds()' a non-zero amount of Ether is sent to msg.sender.", output_of(command)) |
||||||
|
|
||||||
class InfuraTestCase(BaseTestCase): |
class InfuraTestCase(TestCase): |
||||||
|
|
||||||
def test_infura_mainnet(self): |
def test_infura_mainnet(self): |
||||||
command = "python3 {} --rpc infura-mainnet -d -a 0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208".format(self.myth) |
command = "python3 {} --rpc infura-mainnet -d -a 0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208".format(MYTH) |
||||||
output = output_of(command) |
output = output_of(command) |
||||||
self.assertIn("0 PUSH1 0x60\n2 PUSH1 0x40\n4 MSTORE", output) |
self.assertIn("0 PUSH1 0x60\n2 PUSH1 0x40\n4 MSTORE", output) |
||||||
self.assertIn("7278 POP\n7279 POP\n7280 JUMP\n7281 STOP", output) |
self.assertIn("7278 POP\n7279 POP\n7280 JUMP\n7281 STOP", output) |
||||||
|
|
||||||
def test_infura_rinkeby(self): |
def test_infura_rinkeby(self): |
||||||
command = "python3 {} --rpc infura-rinkeby -d -a 0xB6f2bFED892a662bBF26258ceDD443f50Fa307F5".format(self.myth) |
command = "python3 {} --rpc infura-rinkeby -d -a 0xB6f2bFED892a662bBF26258ceDD443f50Fa307F5".format(MYTH) |
||||||
output = output_of(command) |
output = output_of(command) |
||||||
self.assertIn("34 JUMPDEST\n35 CALLVALUE", output) |
self.assertIn("34 JUMPDEST\n35 CALLVALUE", output) |
||||||
|
|
||||||
def test_infura_kovan(self): |
def test_infura_kovan(self): |
||||||
command = "python3 {} --rpc infura-kovan -d -a 0xE6bBF9B5A3451242F82f8cd458675092617a1235".format(self.myth) |
command = "python3 {} --rpc infura-kovan -d -a 0xE6bBF9B5A3451242F82f8cd458675092617a1235".format(MYTH) |
||||||
output = output_of(command) |
output = output_of(command) |
||||||
self.assertIn("9999 PUSH1 0x00\n10001 NOT\n10002 AND\n10003 PUSH1 0x00", output) |
self.assertIn("9999 PUSH1 0x00\n10001 NOT\n10002 AND\n10003 PUSH1 0x00", output) |
||||||
|
|
||||||
def test_infura_ropsten(self): |
def test_infura_ropsten(self): |
||||||
command = "python3 {} --rpc infura-ropsten -d -a 0x6e0E0e02377Bc1d90E8a7c21f12BA385C2C35f78".format(self.myth) |
command = "python3 {} --rpc infura-ropsten -d -a 0x6e0E0e02377Bc1d90E8a7c21f12BA385C2C35f78".format(MYTH) |
||||||
output = output_of(command) |
output = output_of(command) |
||||||
self.assertIn("1821 PUSH1 0x01\n1823 PUSH2 0x070c", output) |
self.assertIn("1821 PUSH1 0x01\n1823 PUSH2 0x070c", output) |
||||||
|
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@ |
|||||||
|
{"0x07f9f7ba": "StandardBounties(address)", "0x8c590917": "contribute(uint256,uint256)", "0x626a413a": "activateBounty(uint256,uint256)", "0x1e688c14": "fulfillBounty(uint256,string)", "0x41ac5dd0": "updateFulfillment(uint256,uint256,string)", "0xd9583497": "acceptFulfillment(uint256,uint256)", "0x16b57509": "killBounty(uint256)", "0x2d1fdef6": "extendDeadline(uint256,uint256)", "0x5d19606e": "transferIssuer(uint256,address)", "0xd6c0ceab": "changeBountyDeadline(uint256,uint256)", "0xf3d3402a": "changeBountyData(uint256,string)", "0x452ccadb": "changeBountyFulfillmentAmount(uint256,uint256)", "0xcdad6576": "changeBountyArbiter(uint256,address)", "0x992a3e75": "changeBountyPaysTokens(uint256,bool,address)", "0x422d4cd6": "increasePayout(uint256,uint256,uint256)", "0xb94b0a3a": "getFulfillment(uint256,uint256)", "0xee8c4bbf": "getBounty(uint256)", "0x86647bac": "getBountyArbiter(uint256)", "0xa60745aa": "getBountyData(uint256)", "0x19dba3d2": "getBountyToken(uint256)", "0x3278ba2f": "getNumBounties()", "0xfbe334f8": "getNumFulfillments(uint256)", "0xdb3b6263": "transitionToState(uint256,BountyStages)", "0x4e3b52fe": "metaCoin()", "0x412664ae": "sendToken(address,uint256)", "0x56885cd8": "crowdfunding()", "0x6c343ffe": "withdrawfunds()", "0xe8b5e51f": "invest()", "0xaa3288f4": "getBalance())", "0xc11a4b47": "Origin()", "0xf2fde38b": "transferOwnership(address)", "0x00362a95": "donate(address)", "0x70a08231": "balanceOf(address)", "0x2e1a7d4d": "withdraw(uint256)", "0x6241bfd1": "Token(uint256)", "0xa3210e87": "sendeth(address,uint256)", "0xcd38aa87": "chooseWinner()", "0xd6d22fa4": "MetaCoin()", "0x90b98a11": "sendCoin(address,uint256)", "0x7bd703e8": "getBalanceInEth(address)", "0xf8b2cb4f": "getBalance(address)", "0xa360b26f": "Migrations()", "0xfdacd576": "setCompleted(uint256)", "0x0900f010": "upgrade(address)", "0xcae9ca51": "approveAndCall(address,uint256,bytes)", "0xa9059cbb": "transfer(address,uint256)", "0x23b872dd": "transferFrom(address,address,uint256)", "0x095ea7b3": "approve(address,uint256)", "0xdd62ed3e": "allowance(address,address)", "0x525f8a5c": "setSaleStartTime(uint256)", "0xd132391a": "setSaleEndTime(uint256)", "0x0a0cd8c8": "setupDone()", "0xd7bb99ba": "contribute()", "0xf0349d5f": "setupStages()", "0x2a4f6533": "createTokenContract())", "0x42a6b21a": "getContributionLimit(address)", "0x1a787915": "startConditions(bytes32)", "0xf3fde261": "onTransition(bytes32)", "0x27816235": "onSaleEnded()", "0x091cde0b": "DisbursementHandler(address)", "0xf3fef3a3": "withdraw(address,uint256)", "0x4bc9fdc2": "calcMaxWithdraw()", "0xc9e61599": "createTarget())", "0x200094e0": "deployContract())", "0x5a048d78": "claim(Target)", "0x16ae6b67": "checkInvariant())", "0x2aa5ed61": "DayLimit(uint256)", "0xe7dde9a3": "_setDailyLimit(uint256)", "0x4a4c82c6": "_resetSpentToday()", "0x180aadb7": "underLimit(uint256)", "0x9d4468ff": "today())", "0x19045a25": "recover(bytes32,bytes)", "0xe92dfb23": "LimitBalance(uint256)", "0xd73dd623": "increaseApproval(address,uint256)", "0x66188463": "decreaseApproval(address,uint256)", "0xabaf5880": "Crowdsale(uint256,uint256,uint256,address)", "0xec8ac4d8": "buyTokens(address)", "0x9d735286": "forwardFunds()", "0x605120cf": "validPurchase())", "0x6e42787f": "hasEnded())", "0xe5c46944": "MultiSigWallet(address[],uint256)", "0x7065cb48": "addOwner(address)", "0x173825d9": "removeOwner(address)", "0xe20056e6": "replaceOwner(address,address)", "0xba51a6df": "changeRequirement(uint256)", "0xc6427474": "submitTransaction(address,uint256,bytes)", "0xc01a8c84": "confirmTransaction(uint256)", "0x20ea8d86": "revokeConfirmation(uint256)", "0xee22610b": "executeTransaction(uint256)", "0x784547a7": "isConfirmed(uint256)", "0xec096f8d": "addTransaction(address,uint256,bytes)", "0x8b51d13f": "getConfirmationCount(uint256)", "0x54741525": "getTransactionCount(bool,bool)", "0xa0e67e2b": "getOwners()", "0xb5dc40c3": "getConfirmations(uint256)", "0xa8abe69a": "getTransactionIds(uint256,uint256,bool,bool)"} |
Binary file not shown.
Loading…
Reference in new issue