Skip to content

Commit

Permalink
✨ add TokensReleased event
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelStark committed Jul 12, 2022
1 parent f345d3c commit baa0077
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/starkvest/events.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ end
@event
func VestingRevoked(vesting_id : felt):
end
@event
func TokensReleased(vesting_id : felt, amount : Uint256):
end
5 changes: 4 additions & 1 deletion src/starkvest/library.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ from openzeppelin.token.erc20.interfaces.IERC20 import IERC20
# Project dependencies

from starkvest.model import Vesting, MAX_SLICE_PERIOD_SECONDS, MAX_TIMESTAMP
from starkvest.events import VestingCreated, VestingRevoked
from starkvest.events import VestingCreated, VestingRevoked, TokensReleased

# ------
# STORAGE
Expand Down Expand Up @@ -350,6 +350,9 @@ namespace StarkVest:
assert transfer_success = TRUE
end
# Emit event
TokensReleased.emit(vesting_id, amount)
# End reetrancy guard
ReentrancyGuard._end()
return ()
Expand Down
11 changes: 10 additions & 1 deletion tests/integrations/starkvest/test_nominal_case.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func test_e2e{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}
# Release 100 tokens
starkvest_instance.release(vesting_id, Uint256(100, 0))
let (releasable_amount) = starkvest_instance.releasable_amount(vesting_id)
%{ stop_warp() %}
assert releasable_amount = Uint256(400, 0)

# Check balance of vesting contract after release
Expand All @@ -124,6 +123,16 @@ func test_e2e{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}
assert starkvest_balance = Uint256(900, 0)
let (owner_balance) = IERC20.balanceOf(token, ADMIN)
assert owner_balance = Uint256(999000, 0)

# Revoke
# The 400 remaining vested tokens should be released
%{ expect_events({"name": "VestingRevoked", "data": [ids.vesting_id]}) %}
%{ expect_events({"name": "TokensReleased", "data": [ids.vesting_id, 400, 0]}) %}
starkvest_instance.revoke(vesting_id)
%{ stop_warp() %}
# Check balance of user 1 after revoke
let (user_1_balance) = IERC20.balanceOf(token, USER_1)
assert user_1_balance = Uint256(500, 0)
end

return ()
Expand Down

0 comments on commit baa0077

Please sign in to comment.