-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_exploitable_swap.py
75 lines (55 loc) · 1.82 KB
/
test_exploitable_swap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Instructions:
# Implement your tests for exploitable_swap.py here.
# Test both single and double spending of the script UTxOs.
# Use this to test your design of fixed_swap.py
# You can use the method stubs below to guide your design of the tests, or create your own design.
# You should borrow the unit test ideas from test_negative_r_timed.py to complete the tests here.
from functools import cache
from types import ModuleType
from typing import Tuple
import pycardano
from opshin import build
from src.utils.mock import MockChainContext, MockUser
from src.week06 import lecture_dir, homework_dir
from src.week06.homework import fixed_swap
from src.week06.lecture import exploitable_swap
exploitable_swap_script = build(lecture_dir.joinpath("exploitable_swap.py"))
fixed_swap_script = build(homework_dir.joinpath("fixed_swap.py"))
script_dict = {
"exploitable_swap": [exploitable_swap_script, exploitable_swap],
"fixed_swap": [fixed_swap_script, fixed_swap],
}
def create_nft(
context: MockChainContext,
user: MockUser,
token_name: str,
) -> Tuple[MockChainContext, pycardano.MultiAsset]:
pass
def lock_nft(
context: MockChainContext,
script_address: pycardano.Address,
seller: MockUser,
nft: pycardano.MultiAsset,
price: int,
) -> MockChainContext:
pass
def create_buyer(context) -> Tuple[MockChainContext, MockUser]:
pass
def unlock_nft(
context: MockChainContext,
plutus_script: pycardano.PlutusV2Script,
script_address: pycardano.Address,
buyer: MockUser,
seller: MockUser,
price: int,
) -> MockChainContext:
pass
@cache
def setup_context(
plutus_script: pycardano.PlutusV2Script, script_module: ModuleType
) -> Tuple[MockChainContext, MockUser, pycardano.MultiAsset]:
pass
def test_normal_spending():
pass
def test_double_spending():
pass