Skip to content

this is used in tests #1380

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

Merged
merged 18 commits into from
Oct 4, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 8 additions & 10 deletions test/examples/SimpleToken.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,32 @@ require('chai')
.should();

contract('SimpleToken', function ([_, creator]) {
let token;

const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

beforeEach(async function () {
token = await SimpleToken.new({ from: creator });
this.token = await SimpleToken.new({ from: creator });
});

it('has a name', async function () {
(await token.name()).should.equal('SimpleToken');
(await this.token.name()).should.equal('SimpleToken');
});

it('has a symbol', async function () {
(await token.symbol()).should.equal('SIM');
(await this.token.symbol()).should.equal('SIM');
});

it('has 18 decimals', async function () {
(await token.decimals()).should.be.bignumber.equal(18);
(await this.token.decimals()).should.be.bignumber.equal(18);
});

it('assigns the initial total supply to the creator', async function () {
const totalSupply = await token.totalSupply();
const creatorBalance = await token.balanceOf(creator);
const totalSupply = await this.token.totalSupply();
const creatorBalance = await this.token.balanceOf(creator);

creatorBalance.should.be.bignumber.equal(totalSupply);

const receipt = await web3.eth.getTransactionReceipt(token.transactionHash);
const logs = decodeLogs(receipt.logs, SimpleToken, token.address);
const receipt = await web3.eth.getTransactionReceipt(this.token.transactionHash);
const logs = decodeLogs(receipt.logs, SimpleToken, this.token.address);
logs.length.should.equal(1);
logs[0].event.should.equal('Transfer');
logs[0].args.from.valueOf().should.equal(ZERO_ADDRESS);
Expand Down
10 changes: 4 additions & 6 deletions test/library/MerkleProof.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ require('chai')
.should();

contract('MerkleProof', function () {
let merkleProof;

beforeEach(async function () {
merkleProof = await MerkleProofWrapper.new();
this.merkleProof = await MerkleProofWrapper.new();
});

describe('verify', function () {
Expand All @@ -24,7 +22,7 @@ contract('MerkleProof', function () {

const leaf = bufferToHex(sha3(elements[0]));

(await merkleProof.verify(proof, root, leaf)).should.equal(true);
(await this.merkleProof.verify(proof, root, leaf)).should.equal(true);
});

it('should return false for an invalid Merkle proof', async function () {
Expand All @@ -40,7 +38,7 @@ contract('MerkleProof', function () {

const badProof = badMerkleTree.getHexProof(badElements[0]);

(await merkleProof.verify(badProof, correctRoot, correctLeaf)).should.equal(false);
(await this.merkleProof.verify(badProof, correctRoot, correctLeaf)).should.equal(false);
});

it('should return false for a Merkle proof of invalid length', async function () {
Expand All @@ -54,7 +52,7 @@ contract('MerkleProof', function () {

const leaf = bufferToHex(sha3(elements[0]));

(await merkleProof.verify(badProof, root, leaf)).should.equal(false);
(await this.merkleProof.verify(badProof, root, leaf)).should.equal(false);
});
});
});
10 changes: 4 additions & 6 deletions test/token/ERC20/ERC20Detailed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,23 @@ require('chai')
const ERC20DetailedMock = artifacts.require('ERC20DetailedMock');

contract('ERC20Detailed', function () {
let detailedERC20 = null;

const _name = 'My Detailed ERC20';
const _symbol = 'MDT';
const _decimals = 18;

beforeEach(async function () {
detailedERC20 = await ERC20DetailedMock.new(_name, _symbol, _decimals);
this.detailedERC20 = await ERC20DetailedMock.new(_name, _symbol, _decimals);
});

it('has a name', async function () {
(await detailedERC20.name()).should.be.equal(_name);
(await this.detailedERC20.name()).should.be.equal(_name);
});

it('has a symbol', async function () {
(await detailedERC20.symbol()).should.be.equal(_symbol);
(await this.detailedERC20.symbol()).should.be.equal(_symbol);
});

it('has an amount of decimals', async function () {
(await detailedERC20.decimals()).should.be.bignumber.equal(_decimals);
(await this.detailedERC20.decimals()).should.be.bignumber.equal(_decimals);
});
});
13 changes: 5 additions & 8 deletions test/utils/ReentrancyGuard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,25 @@ require('chai')
.should();

contract('ReentrancyGuard', function () {
let reentrancyMock;

beforeEach(async function () {
reentrancyMock = await ReentrancyMock.new();
const initialCounter = await reentrancyMock.counter();
initialCounter.should.be.bignumber.equal(0);
this.reentrancyMock = await ReentrancyMock.new();
(await this.reentrancyMock.counter()).should.be.bignumber.equal(0);
});

it('should not allow remote callback', async function () {
const attacker = await ReentrancyAttack.new();
await expectThrow(reentrancyMock.countAndCall(attacker.address));
await expectThrow(this.reentrancyMock.countAndCall(attacker.address));
});

// The following are more side-effects than intended behavior:
// I put them here as documentation, and to monitor any changes
// in the side-effects.

it('should not allow local recursion', async function () {
await expectThrow(reentrancyMock.countLocalRecursive(10));
await expectThrow(this.reentrancyMock.countLocalRecursive(10));
});

it('should not allow indirect local recursion', async function () {
await expectThrow(reentrancyMock.countThisRecursive(10));
await expectThrow(this.reentrancyMock.countThisRecursive(10));
});
});