From ff9f5aa9e348345a828bf5eb5b36dad399cf5a56 Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Mon, 2 Oct 2017 17:00:14 +0700 Subject: [PATCH] Add unit tests --- tests/__init__.py | 0 tests/asm_test.py | 1 + tests/contractstorage_test.py | 26 +++++++++++++++++++++ tests/ethcontract_test.py | 2 ++ tests/evm_test.py | 2 ++ tests/rpc_test.py | 2 ++ tests/teststorage/contractstorage.fs | Bin 0 -> 16295 bytes tests/teststorage/contractstorage.fs.index | Bin 0 -> 31 bytes tests/teststorage/contractstorage.fs.lock | 1 + tests/teststorage/contractstorage.fs.tmp | 0 tests/util_test.py | 2 ++ 11 files changed, 36 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/asm_test.py create mode 100644 tests/contractstorage_test.py create mode 100644 tests/ethcontract_test.py create mode 100644 tests/evm_test.py create mode 100644 tests/rpc_test.py create mode 100644 tests/teststorage/contractstorage.fs create mode 100644 tests/teststorage/contractstorage.fs.index create mode 100644 tests/teststorage/contractstorage.fs.lock create mode 100644 tests/teststorage/contractstorage.fs.tmp create mode 100644 tests/util_test.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/asm_test.py b/tests/asm_test.py new file mode 100644 index 00000000..10e61596 --- /dev/null +++ b/tests/asm_test.py @@ -0,0 +1 @@ +import unittest diff --git a/tests/contractstorage_test.py b/tests/contractstorage_test.py new file mode 100644 index 00000000..61823670 --- /dev/null +++ b/tests/contractstorage_test.py @@ -0,0 +1,26 @@ +import unittest +from mythril.ether.contractstorage import get_persistent_storage +import os + + +class GetAndSearchContractTestCase(unittest.TestCase): + + def mockCallback(self, code_hash, code, addresses, balances): + self.isFound = True + pass + + def runTest(self): + + script_path = os.path.dirname(os.path.realpath(__file__)) + storage_dir = os.path.join(script_path, 'teststorage') + storage = get_persistent_storage(storage_dir) + + contract = storage.get_contract_by_hash(bytes.fromhex("ea061445eacbe86b7ffed2bb9e52075e")) + + self.assertTrue("0x60606040" in contract.code,'error reading contract code from database') + + self.isFound = False + + storage.search("code#PUSH1#", self.mockCallback) + + self.assertTrue(self.isFound,'storage search error') diff --git a/tests/ethcontract_test.py b/tests/ethcontract_test.py new file mode 100644 index 00000000..c5c2eee9 --- /dev/null +++ b/tests/ethcontract_test.py @@ -0,0 +1,2 @@ +import unittest + diff --git a/tests/evm_test.py b/tests/evm_test.py new file mode 100644 index 00000000..c5c2eee9 --- /dev/null +++ b/tests/evm_test.py @@ -0,0 +1,2 @@ +import unittest + diff --git a/tests/rpc_test.py b/tests/rpc_test.py new file mode 100644 index 00000000..c5c2eee9 --- /dev/null +++ b/tests/rpc_test.py @@ -0,0 +1,2 @@ +import unittest + diff --git a/tests/teststorage/contractstorage.fs b/tests/teststorage/contractstorage.fs new file mode 100644 index 0000000000000000000000000000000000000000..a3c113189b8dfe443dd7f0fb554fe26643b88afe GIT binary patch literal 16295 zcmd6uORpr!RmXd#dme5HFcKS9%o4F^WoG0PBnx?D1PEltwoq@3m5)eI%k7@2z8A?x zGWKRH#1{a0!4f2v7_ni;7FK)!#1i=%cw_PVpNPoH%&O{J-8~~uRqJ*>;&I|U{^t=< zfADpe-T#jt{>%5i_FI2*FMNLT9{>O5y?aldJ-L0-KYefNZ~LLY@$Ze#eSiDpqi3<* zytMI6^}RAa{>P=&-@hIqkAIDk#*d!e zKJUlduit+3y#Ka8Jb3@zIQ|=lx5n>&|MtV@Po6&Vw;%fFk5b#4(Dvc`+rAGEZ~yr4 z&IdQk0^iuJAQ66C!B1JiOU@B_`rD7cu%iCv@a97In}_@3m%s7c`_T@BW>O`zscAi4d*g{V)FP?ceyy&;IlOzVpLh{P(~A!`I&Vi^CfW84nI` z?l^-Ck^mn5QKbG)ApYUu{*Mn2K44{^9Nzxq@XjZPcN2{d?xgYWP6TjynhodsX?pH& zZakd-=HdS1-+@=z_oi{|+quuW!H;>7RlYB}vL33rFY9`0io9?`lg;hnLH}54HuO&= zgPX%!-#oniw>+8t>8JnpzrWHiO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/contractstorage.fs.index b/tests/teststorage/contractstorage.fs.index new file mode 100644 index 0000000000000000000000000000000000000000..cb464437599f88b1191c517f24653536af58c484 GIT binary patch literal 31 dcmZo*_Fksf!0gP%00zz+5SqcH4JhiT2LMor1fc)` literal 0 HcmV?d00001 diff --git a/tests/teststorage/contractstorage.fs.lock b/tests/teststorage/contractstorage.fs.lock new file mode 100644 index 00000000..e002abb8 --- /dev/null +++ b/tests/teststorage/contractstorage.fs.lock @@ -0,0 +1 @@ + 69453 diff --git a/tests/teststorage/contractstorage.fs.tmp b/tests/teststorage/contractstorage.fs.tmp new file mode 100644 index 00000000..e69de29b diff --git a/tests/util_test.py b/tests/util_test.py new file mode 100644 index 00000000..c5c2eee9 --- /dev/null +++ b/tests/util_test.py @@ -0,0 +1,2 @@ +import unittest +