From 980a3e43fc72edafc8fce11702e40ab14965ef06 Mon Sep 17 00:00:00 2001 From: banteg Date: Wed, 15 Sep 2021 02:52:09 +0200 Subject: [PATCH] fix/reinit (#8) * test: reinit bug * fix: reinit bug --- contracts/VestingEscrowFactory.vy | 2 +- contracts/VestingEscrowSimple.vy | 8 +++++--- contracts/test/ERC20.vy | 2 +- tests/functional/VestingEscrow/test_init.py | 9 +++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 tests/functional/VestingEscrow/test_init.py diff --git a/contracts/VestingEscrowFactory.vy b/contracts/VestingEscrowFactory.vy index d4a2059..bb15615 100644 --- a/contracts/VestingEscrowFactory.vy +++ b/contracts/VestingEscrowFactory.vy @@ -1,4 +1,4 @@ -# @version 0.2.8 +# @version 0.2.16 """ @title Vesting Escrow Factory @author Curve Finance, Yearn Finance diff --git a/contracts/VestingEscrowSimple.vy b/contracts/VestingEscrowSimple.vy index c7de6b2..78cf4db 100644 --- a/contracts/VestingEscrowSimple.vy +++ b/contracts/VestingEscrowSimple.vy @@ -1,4 +1,4 @@ -# @version 0.2.8 +# @version 0.2.16 """ @title Simple Vesting Escrow @author Curve Finance, Yearn Finance @@ -35,6 +35,7 @@ cliff_length: public(uint256) total_locked: public(uint256) total_claimed: public(uint256) disabled_at: public(uint256) +initialized: public(bool) admin: public(address) future_admin: public(address) @@ -42,7 +43,7 @@ future_admin: public(address) @external def __init__(): # ensure that the original contract cannot be initialized - self.admin = msg.sender + self.initialized = True @external @@ -69,7 +70,8 @@ def initialize( @param end_time Time until everything should be vested @param cliff_length Duration after which the first portion vests """ - assert self.admin == ZERO_ADDRESS # dev: can only initialize once + assert not self.initialized # dev: can only initialize once + self.initialized = True self.token = ERC20(token) self.admin = admin diff --git a/contracts/test/ERC20.vy b/contracts/test/ERC20.vy index 2b2e754..c8b7806 100644 --- a/contracts/test/ERC20.vy +++ b/contracts/test/ERC20.vy @@ -2,7 +2,7 @@ @notice Mock ERC20 for testing """ -# @version 0.2.8 +# @version 0.2.16 event Transfer: _from: indexed(address) diff --git a/tests/functional/VestingEscrow/test_init.py b/tests/functional/VestingEscrow/test_init.py new file mode 100644 index 0000000..8263207 --- /dev/null +++ b/tests/functional/VestingEscrow/test_init.py @@ -0,0 +1,9 @@ +import brownie + + +def test_reinit_impossible(vesting, accounts, token): + vesting.renounce_ownership({"from": accounts[0]}) + with brownie.reverts("dev: can only initialize once"): + vesting.initialize( + accounts[1], token, accounts[1], 0, 0, 0, 0, {"from": accounts[1]} + )