Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename events to past-tense #1181

Merged
merged 5 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CODE_STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ function test(uint256 _testParameter1, uint256 _testParameter2) {
...
}
```

* Events should be emitted immediately after the state change that they
represent, and consequently they should be named in past tense.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we provide a couple examples? I'd add a note mentioning that some standards (e.g. ERC20) use present tense, and in those cases the spec prevails.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good ideas @nventuro! Please check if you like it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

6 changes: 3 additions & 3 deletions contracts/crowdsale/Crowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ contract Crowdsale {
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokenPurchase(
event TokensPurchased(
address indexed purchaser,
address indexed beneficiary,
uint256 value,
Expand Down Expand Up @@ -92,7 +92,7 @@ contract Crowdsale {
weiRaised = weiRaised.add(weiAmount);

_processPurchase(_beneficiary, tokens);
emit TokenPurchase(
emit TokensPurchased(
msg.sender,
_beneficiary,
weiAmount,
Expand All @@ -111,7 +111,7 @@ contract Crowdsale {

/**
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use `super` in contracts that inherit from Crowdsale to extend their validations.
* Example from CappedCrowdsale.sol's _preValidatePurchase method:
* Example from CappedCrowdsale.sol's _preValidatePurchase method:
* super._preValidatePurchase(_beneficiary, _weiAmount);
* require(weiRaised.add(_weiAmount) <= cap);
* @param _beneficiary Address performing the token purchase
Expand Down
4 changes: 2 additions & 2 deletions contracts/crowdsale/distribution/FinalizableCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract FinalizableCrowdsale is Ownable, TimedCrowdsale {

bool public isFinalized = false;

event Finalized();
event CrowdsaleFinalized();

/**
* @dev Must be called after crowdsale ends, to do some extra finalization
Expand All @@ -26,7 +26,7 @@ contract FinalizableCrowdsale is Ownable, TimedCrowdsale {
require(hasClosed());

finalization();
emit Finalized();
emit CrowdsaleFinalized();

isFinalized = true;
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/lifecycle/Pausable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import "../ownership/Ownable.sol";
* @dev Base contract which allows children to implement an emergency stop mechanism.
*/
contract Pausable is Ownable {
event Pause();
event Unpause();
event Paused();
event Unpaused();

bool public paused = false;

Expand All @@ -36,14 +36,14 @@ contract Pausable is Ownable {
*/
function pause() public onlyOwner whenNotPaused {
paused = true;
emit Pause();
emit Paused();
}

/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() public onlyOwner whenPaused {
paused = false;
emit Unpause();
emit Unpaused();
}
}
4 changes: 2 additions & 2 deletions contracts/token/ERC20/BurnableToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "./StandardToken.sol";
*/
contract BurnableToken is StandardToken {

event Burn(address indexed burner, uint256 value);
event TokensBurned(address indexed burner, uint256 value);

/**
* @dev Burns a specific amount of tokens.
Expand All @@ -34,6 +34,6 @@ contract BurnableToken is StandardToken {
*/
function _burn(address _who, uint256 _value) internal {
super._burn(_who, _value);
emit Burn(_who, _value);
emit TokensBurned(_who, _value);
}
}
2 changes: 1 addition & 1 deletion test/crowdsale/AllowanceCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
describe('high-level purchase', function () {
it('should log purchase', async function () {
const { logs } = await this.crowdsale.sendTransaction({ value: value, from: investor });
const event = logs.find(e => e.event === 'TokenPurchase');
const event = logs.find(e => e.event === 'TokensPurchased');
should.exist(event);
event.args.purchaser.should.equal(investor);
event.args.beneficiary.should.equal(investor);
Expand Down
4 changes: 2 additions & 2 deletions test/crowdsale/Crowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
describe('high-level purchase', function () {
it('should log purchase', async function () {
const { logs } = await this.crowdsale.sendTransaction({ value: value, from: investor });
const event = logs.find(e => e.event === 'TokenPurchase');
const event = logs.find(e => e.event === 'TokensPurchased');
should.exist(event);
event.args.purchaser.should.equal(investor);
event.args.beneficiary.should.equal(investor);
Expand All @@ -106,7 +106,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
describe('low-level purchase', function () {
it('should log purchase', async function () {
const { logs } = await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
const event = logs.find(e => e.event === 'TokenPurchase');
const event = logs.find(e => e.event === 'TokensPurchased');
should.exist(event);
event.args.purchaser.should.equal(purchaser);
event.args.beneficiary.should.equal(investor);
Expand Down
2 changes: 1 addition & 1 deletion test/crowdsale/FinalizableCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) {
it('logs finalized', async function () {
await increaseTimeTo(this.afterClosingTime);
const { logs } = await this.crowdsale.finalize({ from: owner });
const event = logs.find(e => e.event === 'Finalized');
const event = logs.find(e => e.event === 'CrowdsaleFinalized');
should.exist(event);
});
});
2 changes: 1 addition & 1 deletion test/crowdsale/MintedCrowdsale.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate
describe('high-level purchase', function () {
it('should log purchase', async function () {
const { logs } = await this.crowdsale.sendTransaction({ value: value, from: investor });
const event = logs.find(e => e.event === 'TokenPurchase');
const event = logs.find(e => e.event === 'TokensPurchased');
should.exist(event);
event.args.purchaser.should.equal(investor);
event.args.beneficiary.should.equal(investor);
Expand Down
4 changes: 2 additions & 2 deletions test/token/ERC20/BurnableToken.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function shouldBehaveLikeBurnableToken (owner, initialBalance, [burner]) {
});

it('emits a burn event', async function () {
const event = expectEvent.inLogs(this.logs, 'Burn');
const event = expectEvent.inLogs(this.logs, 'TokensBurned');
event.args.burner.should.equal(owner);
event.args.value.should.be.bignumber.equal(amount);
});
Expand Down Expand Up @@ -80,7 +80,7 @@ function shouldBehaveLikeBurnableToken (owner, initialBalance, [burner]) {
});

it('emits a burn event', async function () {
const event = expectEvent.inLogs(this.logs, 'Burn');
const event = expectEvent.inLogs(this.logs, 'TokensBurned');
event.args.burner.should.equal(owner);
event.args.value.should.be.bignumber.equal(amount);
});
Expand Down
4 changes: 2 additions & 2 deletions test/token/ERC20/PausableToken.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) {
const { logs } = await this.token.pause({ from });

logs.length.should.equal(1);
logs[0].event.should.equal('Pause');
logs[0].event.should.equal('Paused');
});
});

Expand Down Expand Up @@ -62,7 +62,7 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) {
const { logs } = await this.token.unpause({ from });

logs.length.should.equal(1);
logs[0].event.should.equal('Unpause');
logs[0].event.should.equal('Unpaused');
});
});

Expand Down