Unverified Commit 1c053245 by Leo Arias Committed by GitHub

Rename events to past-tense (#1181)

parent 132994d2
...@@ -18,8 +18,21 @@ Any exception or additions specific to our project are documented below. ...@@ -18,8 +18,21 @@ Any exception or additions specific to our project are documented below.
* Parameters must be prefixed with an underscore. * Parameters must be prefixed with an underscore.
``` ```
function test(uint256 _testParameter1, uint256 _testParameter2) { 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.
```
function _burn(address _who, uint256 _value) internal {
super._burn(_who, _value);
emit TokensBurned(_who, _value);
}
```
Some standards (e.g. ERC20) use present tense, and in those cases the
standard specification prevails.
...@@ -43,7 +43,7 @@ contract Crowdsale { ...@@ -43,7 +43,7 @@ contract Crowdsale {
* @param value weis paid for purchase * @param value weis paid for purchase
* @param amount amount of tokens purchased * @param amount amount of tokens purchased
*/ */
event TokenPurchase( event TokensPurchased(
address indexed purchaser, address indexed purchaser,
address indexed beneficiary, address indexed beneficiary,
uint256 value, uint256 value,
...@@ -92,7 +92,7 @@ contract Crowdsale { ...@@ -92,7 +92,7 @@ contract Crowdsale {
weiRaised = weiRaised.add(weiAmount); weiRaised = weiRaised.add(weiAmount);
_processPurchase(_beneficiary, tokens); _processPurchase(_beneficiary, tokens);
emit TokenPurchase( emit TokensPurchased(
msg.sender, msg.sender,
_beneficiary, _beneficiary,
weiAmount, weiAmount,
...@@ -111,7 +111,7 @@ contract Crowdsale { ...@@ -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. * @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); * super._preValidatePurchase(_beneficiary, _weiAmount);
* require(weiRaised.add(_weiAmount) <= cap); * require(weiRaised.add(_weiAmount) <= cap);
* @param _beneficiary Address performing the token purchase * @param _beneficiary Address performing the token purchase
......
...@@ -15,7 +15,7 @@ contract FinalizableCrowdsale is Ownable, TimedCrowdsale { ...@@ -15,7 +15,7 @@ contract FinalizableCrowdsale is Ownable, TimedCrowdsale {
bool public isFinalized = false; bool public isFinalized = false;
event Finalized(); event CrowdsaleFinalized();
/** /**
* @dev Must be called after crowdsale ends, to do some extra finalization * @dev Must be called after crowdsale ends, to do some extra finalization
...@@ -26,7 +26,7 @@ contract FinalizableCrowdsale is Ownable, TimedCrowdsale { ...@@ -26,7 +26,7 @@ contract FinalizableCrowdsale is Ownable, TimedCrowdsale {
require(hasClosed()); require(hasClosed());
finalization(); finalization();
emit Finalized(); emit CrowdsaleFinalized();
isFinalized = true; isFinalized = true;
} }
......
...@@ -9,8 +9,8 @@ import "../ownership/Ownable.sol"; ...@@ -9,8 +9,8 @@ import "../ownership/Ownable.sol";
* @dev Base contract which allows children to implement an emergency stop mechanism. * @dev Base contract which allows children to implement an emergency stop mechanism.
*/ */
contract Pausable is Ownable { contract Pausable is Ownable {
event Pause(); event Paused();
event Unpause(); event Unpaused();
bool public paused = false; bool public paused = false;
...@@ -36,7 +36,7 @@ contract Pausable is Ownable { ...@@ -36,7 +36,7 @@ contract Pausable is Ownable {
*/ */
function pause() public onlyOwner whenNotPaused { function pause() public onlyOwner whenNotPaused {
paused = true; paused = true;
emit Pause(); emit Paused();
} }
/** /**
...@@ -44,6 +44,6 @@ contract Pausable is Ownable { ...@@ -44,6 +44,6 @@ contract Pausable is Ownable {
*/ */
function unpause() public onlyOwner whenPaused { function unpause() public onlyOwner whenPaused {
paused = false; paused = false;
emit Unpause(); emit Unpaused();
} }
} }
...@@ -9,7 +9,7 @@ import "./StandardToken.sol"; ...@@ -9,7 +9,7 @@ import "./StandardToken.sol";
*/ */
contract BurnableToken is StandardToken { 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. * @dev Burns a specific amount of tokens.
...@@ -34,6 +34,6 @@ contract BurnableToken is StandardToken { ...@@ -34,6 +34,6 @@ contract BurnableToken is StandardToken {
*/ */
function _burn(address _who, uint256 _value) internal { function _burn(address _who, uint256 _value) internal {
super._burn(_who, _value); super._burn(_who, _value);
emit Burn(_who, _value); emit TokensBurned(_who, _value);
} }
} }
...@@ -37,7 +37,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW ...@@ -37,7 +37,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
describe('high-level purchase', function () { describe('high-level purchase', function () {
it('should log purchase', async function () { it('should log purchase', async function () {
const { logs } = await this.crowdsale.sendTransaction({ value: value, from: investor }); 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); should.exist(event);
event.args.purchaser.should.equal(investor); event.args.purchaser.should.equal(investor);
event.args.beneficiary.should.equal(investor); event.args.beneficiary.should.equal(investor);
......
...@@ -82,7 +82,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) { ...@@ -82,7 +82,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
describe('high-level purchase', function () { describe('high-level purchase', function () {
it('should log purchase', async function () { it('should log purchase', async function () {
const { logs } = await this.crowdsale.sendTransaction({ value: value, from: investor }); 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); should.exist(event);
event.args.purchaser.should.equal(investor); event.args.purchaser.should.equal(investor);
event.args.beneficiary.should.equal(investor); event.args.beneficiary.should.equal(investor);
...@@ -106,7 +106,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) { ...@@ -106,7 +106,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
describe('low-level purchase', function () { describe('low-level purchase', function () {
it('should log purchase', async function () { it('should log purchase', async function () {
const { logs } = await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }); 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); should.exist(event);
event.args.purchaser.should.equal(purchaser); event.args.purchaser.should.equal(purchaser);
event.args.beneficiary.should.equal(investor); event.args.beneficiary.should.equal(investor);
......
...@@ -56,7 +56,7 @@ contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) { ...@@ -56,7 +56,7 @@ contract('FinalizableCrowdsale', function ([_, owner, wallet, thirdparty]) {
it('logs finalized', async function () { it('logs finalized', async function () {
await increaseTimeTo(this.afterClosingTime); await increaseTimeTo(this.afterClosingTime);
const { logs } = await this.crowdsale.finalize({ from: owner }); 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); should.exist(event);
}); });
}); });
...@@ -20,7 +20,7 @@ function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate ...@@ -20,7 +20,7 @@ function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate
describe('high-level purchase', function () { describe('high-level purchase', function () {
it('should log purchase', async function () { it('should log purchase', async function () {
const { logs } = await this.crowdsale.sendTransaction({ value: value, from: investor }); 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); should.exist(event);
event.args.purchaser.should.equal(investor); event.args.purchaser.should.equal(investor);
event.args.beneficiary.should.equal(investor); event.args.beneficiary.should.equal(investor);
......
...@@ -57,9 +57,9 @@ contract('Pausable', function () { ...@@ -57,9 +57,9 @@ contract('Pausable', function () {
it('should log Pause and Unpause events appropriately', async function () { it('should log Pause and Unpause events appropriately', async function () {
const setPauseLogs = (await this.Pausable.pause()).logs; const setPauseLogs = (await this.Pausable.pause()).logs;
expectEvent.inLogs(setPauseLogs, 'Pause'); expectEvent.inLogs(setPauseLogs, 'Paused');
const setUnPauseLogs = (await this.Pausable.unpause()).logs; const setUnPauseLogs = (await this.Pausable.unpause()).logs;
expectEvent.inLogs(setUnPauseLogs, 'Unpause'); expectEvent.inLogs(setUnPauseLogs, 'Unpaused');
}); });
}); });
...@@ -29,7 +29,7 @@ function shouldBehaveLikeBurnableToken (owner, initialBalance, [burner]) { ...@@ -29,7 +29,7 @@ function shouldBehaveLikeBurnableToken (owner, initialBalance, [burner]) {
}); });
it('emits a burn event', async function () { 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.burner.should.equal(owner);
event.args.value.should.be.bignumber.equal(amount); event.args.value.should.be.bignumber.equal(amount);
}); });
...@@ -80,7 +80,7 @@ function shouldBehaveLikeBurnableToken (owner, initialBalance, [burner]) { ...@@ -80,7 +80,7 @@ function shouldBehaveLikeBurnableToken (owner, initialBalance, [burner]) {
}); });
it('emits a burn event', async function () { 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.burner.should.equal(owner);
event.args.value.should.be.bignumber.equal(amount); event.args.value.should.be.bignumber.equal(amount);
}); });
......
...@@ -20,7 +20,7 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) { ...@@ -20,7 +20,7 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) {
const { logs } = await this.token.pause({ from }); const { logs } = await this.token.pause({ from });
logs.length.should.equal(1); logs.length.should.equal(1);
logs[0].event.should.equal('Pause'); logs[0].event.should.equal('Paused');
}); });
}); });
...@@ -62,7 +62,7 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) { ...@@ -62,7 +62,7 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) {
const { logs } = await this.token.unpause({ from }); const { logs } = await this.token.unpause({ from });
logs.length.should.equal(1); logs.length.should.equal(1);
logs[0].event.should.equal('Unpause'); logs[0].event.should.equal('Unpaused');
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment