From 165e09131f6ee489ff8893b995debd42acbffbe0 Mon Sep 17 00:00:00 2001 From: jaczkal Date: Tue, 19 Sep 2023 10:55:04 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20tests=20template?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/__init__.py | 0 tests/test_default.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/test_default.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_default.py b/tests/test_default.py new file mode 100644 index 0000000..e81d487 --- /dev/null +++ b/tests/test_default.py @@ -0,0 +1,38 @@ +import time +from woke.testing import * + +from pytypes.contracts.Dungeon import Dungeon + +''' + Write your exploit here. Always act like in production, + do not alter the chain anyhow. +''' +def exploit(dungeon: Dungeon, hackeer: Account): + pass + + +def subtitles(tx: TransactionAbc): + for event in tx.events: + if isinstance(event, Dungeon.Subtitles): + print(f"--- {event.subtitles} ---") + + +def revert_handler(e: TransactionRevertedError): + if e.tx is not None: + print(e.tx.call_trace) + print(e.tx.console_logs) + + +@default_chain.connect() +@on_revert(revert_handler) +def test_hackee(): + default_chain.set_default_accounts(default_chain.accounts[0]) + default_chain.tx_callback = subtitles + dungeon_master=default_chain.accounts[1] # do not touch + hackeer=default_chain.accounts[2] # this is you + + dungeon = Dungeon.deploy(from_=dungeon_master) + + exploit(dungeon, hackeer) + + print(f"You managed to gain: {dungeon.evaluate(hackeer)} dungeon tokens.") \ No newline at end of file