Add revert if the bytecode length is zero (#2117)
* Add revert if the bytecode length is not greater than zero * Add value parameter to create2 deploy function Add tests for contract balance revert and depositing funds * Change parameter name to amount for clarity * Fix test for value sending * Fix linter error * Change revert reason * Improve Create2.deploy documentation * Slight test improvement * Add changelog entry Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com>
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
const { contract, accounts, web3 } = require('@openzeppelin/test-environment');
|
||||
const { BN, expectRevert } = require('@openzeppelin/test-helpers');
|
||||
const { balance, BN, ether, expectRevert, send } = require('@openzeppelin/test-helpers');
|
||||
|
||||
const { expect } = require('chai');
|
||||
|
||||
@ -40,7 +40,7 @@ describe('Create2', function () {
|
||||
const offChainComputed =
|
||||
computeCreate2Address(saltHex, ERC20.bytecode, this.factory.address);
|
||||
await this.factory
|
||||
.deploy(saltHex, ERC20.bytecode, { from: deployerAccount });
|
||||
.deploy(0, saltHex, ERC20.bytecode, { from: deployerAccount });
|
||||
expect(ERC20.bytecode).to.include((await web3.eth.getCode(offChainComputed)).slice(2));
|
||||
});
|
||||
|
||||
@ -48,15 +48,40 @@ describe('Create2', function () {
|
||||
const offChainComputed =
|
||||
computeCreate2Address(saltHex, constructorByteCode, this.factory.address);
|
||||
await this.factory
|
||||
.deploy(saltHex, constructorByteCode, { from: deployerAccount });
|
||||
.deploy(0, saltHex, constructorByteCode, { from: deployerAccount });
|
||||
const erc20 = await ERC20Mock.at(offChainComputed);
|
||||
expect(await erc20.balanceOf(deployerAccount)).to.be.bignumber.equal(new BN(100));
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
const onChainComputed = await this.factory
|
||||
.computeAddressWithDeployer(saltHex, web3.utils.keccak256(constructorByteCode), this.factory.address);
|
||||
|
||||
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(saltHex, constructorByteCode, { from: deployerAccount });
|
||||
await this.factory.deploy(0, saltHex, constructorByteCode, { from: deployerAccount });
|
||||
await expectRevert(
|
||||
this.factory.deploy(saltHex, constructorByteCode, { from: deployerAccount }), 'Create2: Failed on deploy'
|
||||
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'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user