sablier-labs / flow

🍃 Smart contracts of the Sablier Flow protocol.
Other
10 stars 2 forks source link

test(invariant): streamed amount equals total debt plus withdrawn amount #248

Closed andreivladbrg closed 2 months ago

andreivladbrg commented 2 months ago

Closes #133

Depends on #247

This PR is an alternative (a better one IMO) to this https://github.com/sablier-labs/flow/pull/246/. Why I say it is better: in the 246, the invariant is run only if the stream created is left "untouched":

https://github.com/sablier-labs/flow/blob/de5d1ce231813dc1fcb23ceb61f12f0e298978fe/test/invariant/Flow.t.sol#L271-L274

So to run it on various suquence calls, this PR introduces the concept of "segments" in the invariant tests.

A segment represents a time period during which the rate per second remains constant. For example, if a stream is created at t0 and the rate per second is adjusted at t1, the first segment will be: start = t0, end = t1, ratePerSecond = rate at creation. The second segment will be: start = t1, end = block.timestamp until next rate per second change, ratePerSecond = adjusted rate


For a better understanding, view the graph below. Each color represents a different segment

andreivladbrg commented 2 months ago

Can you please refactor it to something like 'period'?

i don’t have a specific opinion on this (both work for me) @smol-ninja do you have any suggestions in this regard?

smol-ninja commented 2 months ago

I'd prefer period too since it represents the pieces of the whole streamed period.

andreivladbrg commented 2 months ago

vox populi 865e0311259a9c5757a7048f934377872e0ea410

smol-ninja commented 2 months ago

The commit https://github.com/sablier-labs/flow/pull/248/commits/7ed965eda11c8eacb8a54cc3ecbd4bdfea96d97e increases the invariants' efficiency by a huge margin. Locally I can see ~30% successful runs (15k-20k, warp link) which was ~4% (1000-2000 runs) previously. This means, the new vm.assume for rps discards less runs now.

Even the runs in CI have improved.