Skip to content

Commit

Permalink
Allow owner to change endsAt to implement for manual soft cap.
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed May 15, 2017
1 parent 880ad81 commit 4cc3e17
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
22 changes: 22 additions & 0 deletions contracts/Crowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ contract Crowdsale is Haltable {
// Address early participation whitelist status changed
event Whitelisted(address addr, bool status);

// Crowdsale end time has been changed
event EndsAtChanged(uint endsAt);

function Crowdsale(address _token, PricingStrategy _pricingStrategy, address _multisigWallet, uint _start, uint _end, uint _minimumFundingGoal) {

owner = msg.sender;
Expand Down Expand Up @@ -329,6 +332,25 @@ contract Crowdsale is Haltable {
Whitelisted(addr, status);
}

/**
* Allow crowdsale owner to close early or extend the crowdsale.
*
* This is useful e.g. for a manual soft cap implementation:
* - after X amount is reached determine manual closing
*
* This may put the crowdsale to an invalid state,
* but we trust owners know what they are doing.
*
*/
function setEndsAt(uint time) onlyOwner {

if(now > time) {
throw; // Don't change past
}

endsAt = time;
EndsAtChanged(endsAt);
}

/**
* Allow to (re)set pricing strategy.
Expand Down
54 changes: 52 additions & 2 deletions ico/tests/contracts/test_uncapped_flatprice.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from ico.state import CrowdsaleState



@pytest.fixture
def ico(uncapped_flatprice, uncapped_flatprice_finalizer):
"""Set up a crowdsale for this test module with finalizer in place."""
Expand Down Expand Up @@ -44,7 +43,6 @@ def test_buy_early(chain: TestRPCChain, ico: Contract, customer: str, preico_sta
ico.transact({"from": customer, "value": to_wei(1, "ether")}).buy()



def test_buy_early_whitelisted(chain: TestRPCChain, ico: Contract, customer: str, preico_starts_at, team_multisig, uncapped_token):
"""Whitelisted participants can buy earliy."""

Expand All @@ -55,6 +53,14 @@ def test_buy_early_whitelisted(chain: TestRPCChain, ico: Contract, customer: str
assert uncapped_token.call().balanceOf(customer) > 0


def test_early_whitelist_only_owner(chain: TestRPCChain, ico: Contract, customer: str, preico_starts_at, team_multisig, uncapped_token):
"""Only owner can early whitelist."""

time_travel(chain, preico_starts_at - 1)
assert ico.call().getState() == CrowdsaleState.PreFunding
with pytest.raises(TransactionFailed):
ico.transact({"from": customer}).setEarlyParicipantWhitelist(customer, True)


def test_buy_one_investor(chain: TestRPCChain, web3: Web3, ico: Contract, uncapped_token: Contract, customer: str, preico_token_price, preico_starts_at, team_multisig):
"""Can buy when crowdsale is running."""
Expand Down Expand Up @@ -314,3 +320,47 @@ def test_finalize(chain: TestRPCChain, web3: Web3, ico: Contract, malicious_addr

with pytest.raises(TransactionFailed):
ico.transact({"from": malicious_address}).halt()


def test_close_early(chain: TestRPCChain, ico: Contract, customer: str, preico_starts_at, preico_ends_at, team_multisig):
"""Soft cap triggered, close crowdsale early."""

# Close earlier than anticipated
new_early = preico_starts_at + 1*3600
assert new_early < preico_ends_at

time_travel(chain, preico_starts_at + 1)
assert ico.call().getState() == CrowdsaleState.Funding
ico.transact({"from": customer, "value": to_wei(1, "ether")}).buy()
ico.transact({"from": team_multisig}).setEndsAt(new_early)

time_travel(chain, new_early + 1)
assert ico.call().getState() == CrowdsaleState.Failure
with pytest.raises(TransactionFailed):
ico.transact({"from": customer, "value": to_wei(1, "ether")}).buy()


def test_close_late(chain: TestRPCChain, ico: Contract, customer: str, preico_starts_at, preico_ends_at, team_multisig):
"""Extend crowdsale."""

new_end = preico_ends_at + 1*3600
assert new_end > preico_ends_at

time_travel(chain, preico_starts_at + 1)
assert ico.call().getState() == CrowdsaleState.Funding
ico.transact({"from": customer, "value": to_wei(1, "ether")}).buy()

ico.transact({"from": team_multisig}).setEndsAt(new_end)

time_travel(chain, preico_ends_at + 1)
assert ico.call().getState() == CrowdsaleState.Funding
ico.transact({"from": customer, "value": to_wei(1, "ether")}).buy()


def test_change_end_at_only_owner(chain: TestRPCChain, ico: Contract, customer: str, preico_starts_at, preico_ends_at, team_multisig):
"""Only own can change end date."""

new_early = preico_starts_at + 1*3600

with pytest.raises(TransactionFailed):
ico.transact({"from": customer}).setEndsAt(new_early)

0 comments on commit 4cc3e17

Please sign in to comment.