mirror of openzeppelin-contracts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openzeppelin-contracts/test/ownership/HasNoEther.test.js

62 lines
2.0 KiB

const { expectThrow } = require('../helpers/expectThrow');
const { ethSendTransaction, ethGetBalance } = require('../helpers/web3');
const HasNoEtherTest = artifacts.require('HasNoEtherTest');
const ForceEther = artifacts.require('ForceEther');
8 years ago
const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
contract('HasNoEther', function ([_, owner, anyone]) {
8 years ago
const amount = web3.toWei('1', 'ether');
beforeEach(async function () {
this.hasNoEther = await HasNoEtherTest.new({ from: owner });
8 years ago
});
it('should not accept ether in constructor', async function () {
await expectThrow(HasNoEtherTest.new({ value: amount }));
8 years ago
});
it('should not accept ether', async function () {
8 years ago
await expectThrow(
ethSendTransaction({
from: owner,
to: this.hasNoEther.address,
8 years ago
value: amount,
}),
);
});
it('should allow owner to reclaim ether', async function () {
const startBalance = await ethGetBalance(this.hasNoEther.address);
startBalance.should.be.bignumber.equal(0);
8 years ago
// Force ether into it
const forceEther = await ForceEther.new({ value: amount });
await forceEther.destroyAndSend(this.hasNoEther.address);
(await ethGetBalance(this.hasNoEther.address)).should.be.bignumber.equal(amount);
8 years ago
// Reclaim
const ownerStartBalance = await ethGetBalance(owner);
await this.hasNoEther.reclaimEther({ from: owner });
const ownerFinalBalance = await ethGetBalance(owner);
ownerFinalBalance.should.be.bignumber.gt(ownerStartBalance);
(await ethGetBalance(this.hasNoEther.address)).should.be.bignumber.equal(0);
8 years ago
});
it('should allow only owner to reclaim ether', async function () {
8 years ago
// Force ether into it
const forceEther = await ForceEther.new({ value: amount });
await forceEther.destroyAndSend(this.hasNoEther.address);
(await ethGetBalance(this.hasNoEther.address)).should.be.bignumber.equal(amount);
8 years ago
// Reclaim
await expectThrow(this.hasNoEther.reclaimEther({ from: anyone }));
8 years ago
});
});