-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCXTZTest.py
More file actions
92 lines (74 loc) · 3.88 KB
/
CXTZTest.py
File metadata and controls
92 lines (74 loc) · 3.88 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import smartpy as sp
import json
CXTZ = sp.io.import_script_from_url("file:contracts/CXTZ.py")
IRM = sp.io.import_script_from_url("file:contracts/tests/mock/InterestRateModelMock.py")
CMPT = sp.io.import_script_from_url("file:contracts/tests/mock/ComptrollerMock.py")
BlockLevel = sp.io.import_script_from_url("file:contracts/tests/utils/BlockLevel.py")
RV = sp.io.import_script_from_url("file:contracts/tests//utils/ResultViewer.py")
DataRelevance = sp.io.import_script_from_url("file:contracts/tests/utils/DataRelevance.py")
@sp.add_test(name = "CXTZ_Tests")
def test():
bLevel = BlockLevel.BlockLevel()
scenario = sp.test_scenario()
scenario.add_flag("protocol", "lima")
scenario.table_of_contents()
scenario.h1("CXTZ tests")
# Test accounts
alice = sp.test_account("Alice")
admin = sp.test_account("admin")
scenario.h2("Accounts")
scenario.show([alice, admin])
# Contracts
scenario.h2("Contracts")
cmpt = CMPT.ComptrollerMock()
scenario += cmpt
irm = IRM.InterestRateModelMock(borrowRate_=sp.nat(80000000000), supplyRate_=sp.nat(180000000000))
scenario += irm
view_result = RV.ViewerNat()
view_result_pair = RV.ViewerNatPair()
scenario += view_result
scenario += view_result_pair
c1 = CXTZ.CXTZ(comptroller_=cmpt.address,
interestRateModel_=irm.address,
administrator_=admin.address,
metadata_=sp.big_map({
"": sp.utils.bytes_of_string("tezos-storage:data"),
"data": sp.utils.bytes_of_string(json.dumps({
"name": "...",
"description": "...",
"version": "1.0.0",
"authors": ["ewqenqjw"],
"homepage": "https://some-website.com",
"interfaces": ["TZIP-007"],
"license": {"name": "..."}
}))
}),
token_metadata_={
"name": sp.utils.bytes_of_string("Compound XTZ"),
"symbol": sp.utils.bytes_of_string("fXTZ"),
"decimals": sp.utils.bytes_of_string("6"),
})
scenario += c1
scenario.h2("mint + transferIn")
scenario.h3("first mint")
DataRelevance.updateAccrueInterest(scenario, bLevel, alice, c1)
scenario += c1.mint(777).run(sender=alice, level=bLevel.current(), amount=sp.mutez(777))
scenario.verify(c1.data.ledger[alice.address].balance == sp.nat(777))
scenario.h3("second mint")
DataRelevance.updateAccrueInterest(scenario, bLevel, alice, c1)
scenario += c1.mint(20).run(sender=admin, level=bLevel.current(), amount=sp.mutez(20))
scenario.verify(c1.data.ledger[admin.address].balance == sp.nat(20))
scenario.h2("getCash")
scenario += c1.getCash(sp.pair(sp.unit, view_result_pair.typed.targetNatPair)).run(sender=alice, level=bLevel.next())
scenario.verify_equal(sp.fst(view_result_pair.data.last.open_some()), 797)
scenario.h2("getTotalSupply")
scenario += c1.getTotalSupply(sp.pair(sp.unit, view_result.typed.targetNat)).run(sender=alice, level=bLevel.next())
scenario.verify_equal(view_result.data.last, sp.some(797))
scenario.h2("call transferOut inside borrow entry point ")
DataRelevance.updateAllRelevance(scenario, bLevel, alice, c1, cmpt, c1.address, alice.address)
scenario += c1.borrow(sp.nat(777)).run(sender=alice, level=bLevel.current())
scenario.h2("getCash after transferOut call")
scenario += c1.getCash(sp.pair(sp.unit, view_result_pair.typed.targetNatPair)).run(sender=alice, level=bLevel.next())
scenario.verify_equal(sp.fst(view_result_pair.data.last.open_some()), 20)
scenario.h2("Try sweepMutez")
scenario += c1.sweepMutez(sp.bool(False)).run(sender=admin, level=bLevel.next(), valid=False)