Improve test descriptions #1157 (#2334)

Co-authored-by: Paolo Dibitonto <p.dibitonto@almaviva.it>
Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
This commit is contained in:
dibi91
2020-08-25 19:58:45 +02:00
committed by GitHub
parent 1f06fd7e66
commit 0b489f4d79
16 changed files with 402 additions and 375 deletions

View File

@ -23,71 +23,72 @@ describe('Create2', function () {
beforeEach(async function () {
this.factory = await Create2Impl.new();
});
describe('computeAddress', function () {
it('computes the correct contract address', async function () {
const onChainComputed = await this.factory
.computeAddress(saltHex, web3.utils.keccak256(constructorByteCode));
const offChainComputed =
computeCreate2Address(saltHex, constructorByteCode, this.factory.address);
expect(onChainComputed).to.equal(offChainComputed);
});
it('should compute the correct contract address', async function () {
const onChainComputed = await this.factory
.computeAddress(saltHex, web3.utils.keccak256(constructorByteCode));
const offChainComputed =
computeCreate2Address(saltHex, constructorByteCode, this.factory.address);
expect(onChainComputed).to.equal(offChainComputed);
it('computes the correct contract address with deployer', async function () {
const onChainComputed = await this.factory
.computeAddressWithDeployer(saltHex, web3.utils.keccak256(constructorByteCode), deployerAccount);
const offChainComputed =
computeCreate2Address(saltHex, constructorByteCode, deployerAccount);
expect(onChainComputed).to.equal(offChainComputed);
});
});
it('should compute the correct contract address with deployer', async function () {
const onChainComputed = await this.factory
.computeAddressWithDeployer(saltHex, web3.utils.keccak256(constructorByteCode), deployerAccount);
const offChainComputed =
computeCreate2Address(saltHex, constructorByteCode, deployerAccount);
expect(onChainComputed).to.equal(offChainComputed);
});
describe('deploy', function () {
it('deploys a ERC1820Implementer from inline assembly code', async function () {
const offChainComputed =
computeCreate2Address(saltHex, ERC1820Implementer.bytecode, this.factory.address);
await this.factory.deployERC1820Implementer(0, saltHex);
expect(ERC1820Implementer.bytecode).to.include((await web3.eth.getCode(offChainComputed)).slice(2));
});
it('should deploy a ERC1820Implementer from inline assembly code', async function () {
const offChainComputed =
computeCreate2Address(saltHex, ERC1820Implementer.bytecode, this.factory.address);
it('deploys a ERC20Mock with correct balances', async function () {
const offChainComputed = computeCreate2Address(saltHex, constructorByteCode, this.factory.address);
await this.factory.deployERC1820Implementer(0, saltHex);
await this.factory.deploy(0, saltHex, constructorByteCode);
expect(ERC1820Implementer.bytecode).to.include((await web3.eth.getCode(offChainComputed)).slice(2));
});
const erc20 = await ERC20Mock.at(offChainComputed);
expect(await erc20.balanceOf(deployerAccount)).to.be.bignumber.equal(new BN(100));
});
it('should deploy a ERC20Mock with correct balances', async function () {
const offChainComputed = computeCreate2Address(saltHex, constructorByteCode, this.factory.address);
it('deploys a contract with funds deposited in the factory', async function () {
const deposit = ether('2');
await send.ether(deployerAccount, this.factory.address, deposit);
expect(await balance.current(this.factory.address)).to.be.bignumber.equal(deposit);
await this.factory.deploy(0, saltHex, constructorByteCode);
const onChainComputed = await this.factory
.computeAddressWithDeployer(saltHex, web3.utils.keccak256(constructorByteCode), this.factory.address);
const erc20 = await ERC20Mock.at(offChainComputed);
expect(await erc20.balanceOf(deployerAccount)).to.be.bignumber.equal(new BN(100));
});
await this.factory.deploy(deposit, saltHex, constructorByteCode);
expect(await balance.current(onChainComputed)).to.be.bignumber.equal(deposit);
});
it('should deploy a contract with funds deposited in the factory', async function () {
const deposit = ether('2');
await send.ether(deployerAccount, this.factory.address, deposit);
expect(await balance.current(this.factory.address)).to.be.bignumber.equal(deposit);
it('fails deploying a contract in an existent address', async function () {
await this.factory.deploy(0, saltHex, constructorByteCode, { from: deployerAccount });
await expectRevert(
this.factory.deploy(0, saltHex, constructorByteCode, { from: deployerAccount }), 'Create2: Failed on deploy'
);
});
const onChainComputed = await this.factory
.computeAddressWithDeployer(saltHex, web3.utils.keccak256(constructorByteCode), this.factory.address);
it('fails deploying a contract if the bytecode length is zero', async function () {
await expectRevert(
this.factory.deploy(0, saltHex, '0x', { from: deployerAccount }), 'Create2: bytecode length is zero'
);
});
await this.factory.deploy(deposit, saltHex, constructorByteCode);
expect(await balance.current(onChainComputed)).to.be.bignumber.equal(deposit);
});
it('should failed deploying a contract in an existent address', async function () {
await this.factory.deploy(0, saltHex, constructorByteCode, { from: deployerAccount });
await expectRevert(
this.factory.deploy(0, saltHex, constructorByteCode, { from: deployerAccount }), 'Create2: Failed on deploy'
);
});
it('should fail deploying a contract if the bytecode length is zero', async function () {
await expectRevert(
this.factory.deploy(0, saltHex, '0x', { from: deployerAccount }), 'Create2: bytecode length is zero'
);
});
it('should fail deploying a contract if factory contract does not have sufficient balance', async function () {
await expectRevert(
this.factory.deploy(1, saltHex, constructorByteCode, { from: deployerAccount }),
'Create2: insufficient balance'
);
it('fails deploying a contract if factory contract does not have sufficient balance', async function () {
await expectRevert(
this.factory.deploy(1, saltHex, constructorByteCode, { from: deployerAccount }),
'Create2: insufficient balance'
);
});
});
});