Merge pull request #660 from facuspagnuolo/bugfix/659_add_transfer_event_to_simple_token
Emit Transfer event on SimpleToken creation
This commit is contained in:
@ -24,6 +24,7 @@ contract SimpleToken is StandardToken {
|
|||||||
function SimpleToken() public {
|
function SimpleToken() public {
|
||||||
totalSupply = INITIAL_SUPPLY;
|
totalSupply = INITIAL_SUPPLY;
|
||||||
balances[msg.sender] = INITIAL_SUPPLY;
|
balances[msg.sender] = INITIAL_SUPPLY;
|
||||||
|
Transfer(0x0, msg.sender, INITIAL_SUPPLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
41
test/SimpleToken.test.js
Normal file
41
test/SimpleToken.test.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import decodeLogs from './helpers/decodeLogs';
|
||||||
|
const SimpleToken = artifacts.require('examples/SimpleToken.sol');
|
||||||
|
|
||||||
|
contract('SimpleToken', accounts => {
|
||||||
|
let token;
|
||||||
|
const creator = accounts[0];
|
||||||
|
|
||||||
|
beforeEach(async function () {
|
||||||
|
token = await SimpleToken.new({ from: creator });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('has a name', async function () {
|
||||||
|
const name = await token.name();
|
||||||
|
assert.equal(name, 'SimpleToken');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('has a symbol', async function () {
|
||||||
|
const symbol = await token.symbol();
|
||||||
|
assert.equal(symbol, 'SIM');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('has 18 decimals', async function () {
|
||||||
|
const decimals = await token.decimals();
|
||||||
|
assert(decimals.eq(18));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('assigns the initial total supply to the creator', async function () {
|
||||||
|
const totalSupply = await token.totalSupply();
|
||||||
|
const creatorBalance = await token.balanceOf(creator);
|
||||||
|
|
||||||
|
assert(creatorBalance.eq(totalSupply));
|
||||||
|
|
||||||
|
const receipt = web3.eth.getTransactionReceipt(token.transactionHash);
|
||||||
|
const logs = decodeLogs(receipt.logs, SimpleToken, token.address);
|
||||||
|
assert.equal(logs.length, 1);
|
||||||
|
assert.equal(logs[0].event, 'Transfer');
|
||||||
|
assert.equal(logs[0].args.from.valueOf(), 0x0);
|
||||||
|
assert.equal(logs[0].args.to.valueOf(), creator);
|
||||||
|
assert(logs[0].args.value.eq(totalSupply));
|
||||||
|
});
|
||||||
|
});
|
||||||
8
test/helpers/decodeLogs.js
Normal file
8
test/helpers/decodeLogs.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
const SolidityEvent = require('web3/lib/web3/event.js');
|
||||||
|
|
||||||
|
export default function decodeLogs (logs, contract, address) {
|
||||||
|
return logs.map(log => {
|
||||||
|
const event = new SolidityEvent(null, contract.events[log.topics[0]], address);
|
||||||
|
return event.decode(log);
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user