Skip to content

Commit 1dca0d4

Browse files
committed
test: fix tests, add gas measure example
1 parent 72ac30e commit 1dca0d4

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

tests/integration/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def rpc_url():
2121

2222
@pytest.fixture(autouse=True)
2323
def forked_env(rpc_url):
24-
block_to_fork = 20969484
24+
block_to_fork = 21020069
2525
with boa.swap_env(boa.Env()):
2626
if BOA_CACHE:
2727
boa.fork(url=rpc_url, block_identifier=block_to_fork)

tests/integration/test_dynamic_weight.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ def raw_weight() -> uint256:
3333
def test_fee_splitter_cap(
3434
fee_splitter, crvusd, vault, rewards_handler, active_controllers, new_depositor, stablecoin_lens
3535
):
36+
fee_collector_before = crvusd.balanceOf(ab.crvusd_fee_collector)
37+
rewards_handler_before = crvusd.balanceOf(rewards_handler.address)
38+
3639
# test were we ask for so much that we hit the cap
3740
fee_splitter_cap = fee_splitter.receivers(0)[1]
3841

@@ -63,8 +66,10 @@ def test_fee_splitter_cap(
6366
fee_collector_after = crvusd.balanceOf(ab.crvusd_fee_collector)
6467
rewards_handler_after = crvusd.balanceOf(rewards_handler.address)
6568

69+
fee_collector_diff = fee_collector_after - fee_collector_before
70+
rewards_handler_diff = rewards_handler_after - rewards_handler_before
6671
# amount received by the rewards_handler was capped at the source
67-
assert fee_collector_after / rewards_handler_after == 9_000 / 1_000
72+
assert fee_collector_diff / rewards_handler_diff == 9_000 / 1_000
6873

6974

7075
def test_minimum_weight(rewards_handler, minimum_weight, vault, crvusd, new_depositor):
@@ -118,10 +123,16 @@ def test_dynamic_weight_depositors(
118123
# ================= WEIGHTS CHECKS ==================
119124

120125
with boa.env.anchor():
126+
fee_collector_before = crvusd.balanceOf(ab.crvusd_fee_collector)
127+
rewards_handler_before = crvusd.balanceOf(rewards_handler.address)
128+
121129
fee_splitter.dispatch_fees(active_controllers)
122130
fee_collector_after = crvusd.balanceOf(ab.crvusd_fee_collector)
123131
rewards_handler_after = crvusd.balanceOf(rewards_handler.address)
124132

133+
fee_collector_diff = fee_collector_after - fee_collector_before
134+
rewards_handler_diff = rewards_handler_after - rewards_handler_before
135+
125136
if raw_weight < rewards_handler.minimum_weight():
126137
assert rewards_handler.weight() >= raw_weight
127138
assert rewards_handler.weight() == rewards_handler.minimum_weight() == minimum_weight
@@ -132,15 +143,15 @@ def test_dynamic_weight_depositors(
132143
# if the weight is actually dynamic we want to make sure
133144
# that the distribution is done according to the weight
134145

135-
balance_ratio = fee_collector_after * 10_000 // rewards_handler_after
146+
balance_ratio = fee_collector_diff * 10_000 // rewards_handler_diff
136147
excess = 1_000 - raw_weight
137148
weight_ratio = (9_000 + excess) * 10_000 // raw_weight
138149

139150
assert balance_ratio == weight_ratio
140151

141152
elif raw_weight > fee_splitter_cap:
142153
# amount received by the rewards_handler was capped at the source
143-
assert fee_collector_after / rewards_handler_after == 9_000 / 1_000
154+
assert fee_collector_diff / rewards_handler_diff == 9_000 / 1_000
144155

145156
else:
146157
raise AssertionError("This should not happen")

tests/integration/test_fee_splitter.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import boa
22

3-
import address_book as ab
4-
53

64
def test_fee_splitter(fee_splitter, rewards_handler, crvusd, vault, active_controllers):
7-
assert crvusd.balanceOf(ab.crvusd_fee_collector) == 0
85
assert crvusd.balanceOf(rewards_handler.address) == 0
96

107
# ============== SOME DEPOSITS JOIN THE VAULT ==============
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
FORK_BLOCK_SUPPLY = 61914061856509260204722729
1+
import pytest
2+
import boa
3+
4+
FORK_BLOCK_SUPPLY = 62247189465433688283786326
25

36

47
def test_circulating_supply(stablecoin_lens):
58
# circ supply for block of fork
69
assert stablecoin_lens.circulating_supply() == FORK_BLOCK_SUPPLY
10+
11+
12+
@pytest.mark.ignore_isolation
13+
def test_gas_cost(stablecoin_lens):
14+
boa.env.reset_gas_used()
15+
_ = stablecoin_lens.circulating_supply()
16+
print(f"Compute TWA gas: {stablecoin_lens.call_trace().gas_used}")

tests/unitary/rewards_handler/test_take_snapshot.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
import boa
33

44

5-
@pytest.mark.gas_profile
6-
def test_take_snapshot_compute(rewards_handler):
5+
@pytest.mark.ignore_isolation
6+
def test_take_snapshot_compute(vault, rewards_handler):
77
n_days = 7
8-
dt = 600
8+
dt = 3600
99
snaps_per_day = 86_400 // dt
1010
for i_day in range(n_days):
1111
for i_snap in range(snaps_per_day):
1212
rewards_handler.take_snapshot()
1313
boa.env.time_travel(seconds=dt)
14+
boa.env.reset_gas_used()
1415
twa = rewards_handler.compute_twa()
16+
print(f"Compute TWA gas: {rewards_handler.call_trace().gas_used}")
17+
# print(rewards_handler._computation.get_gas_used())
1518
assert twa >= 0, f"Computed TWA is negative: {twa}"

0 commit comments

Comments
 (0)