Use Prettier for JS files (#3913)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
@ -7,15 +7,12 @@ const VestingWallet = artifacts.require('VestingWallet');
|
||||
const ERC1820Implementer = artifacts.require('$ERC1820Implementer');
|
||||
|
||||
contract('Create2', function (accounts) {
|
||||
const [ deployerAccount, other ] = accounts;
|
||||
const [deployerAccount, other] = accounts;
|
||||
|
||||
const salt = 'salt message';
|
||||
const saltHex = web3.utils.soliditySha3(salt);
|
||||
|
||||
const encodedParams = web3.eth.abi.encodeParameters(
|
||||
[ 'address', 'uint64', 'uint64' ],
|
||||
[ other, 0, 0 ],
|
||||
).slice(2);
|
||||
const encodedParams = web3.eth.abi.encodeParameters(['address', 'uint64', 'uint64'], [other, 0, 0]).slice(2);
|
||||
|
||||
const constructorByteCode = `${VestingWallet.bytecode}${encodedParams}`;
|
||||
|
||||
@ -24,18 +21,18 @@ contract('Create2', function (accounts) {
|
||||
});
|
||||
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);
|
||||
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.$computeAddress(saltHex, web3.utils.keccak256(constructorByteCode), deployerAccount);
|
||||
const offChainComputed =
|
||||
computeCreate2Address(saltHex, constructorByteCode, deployerAccount);
|
||||
const onChainComputed = await this.factory.$computeAddress(
|
||||
saltHex,
|
||||
web3.utils.keccak256(constructorByteCode),
|
||||
deployerAccount,
|
||||
);
|
||||
const offChainComputed = computeCreate2Address(saltHex, constructorByteCode, deployerAccount);
|
||||
expect(onChainComputed).to.equal(offChainComputed);
|
||||
});
|
||||
});
|
||||
@ -44,11 +41,9 @@ contract('Create2', function (accounts) {
|
||||
it('deploys a ERC1820Implementer from inline assembly code', async function () {
|
||||
const offChainComputed = computeCreate2Address(saltHex, ERC1820Implementer.bytecode, this.factory.address);
|
||||
|
||||
expectEvent(
|
||||
await this.factory.$deploy(0, saltHex, ERC1820Implementer.bytecode),
|
||||
'return$deploy',
|
||||
{ addr: offChainComputed },
|
||||
);
|
||||
expectEvent(await this.factory.$deploy(0, saltHex, ERC1820Implementer.bytecode), 'return$deploy', {
|
||||
addr: offChainComputed,
|
||||
});
|
||||
|
||||
expect(ERC1820Implementer.bytecode).to.include((await web3.eth.getCode(offChainComputed)).slice(2));
|
||||
});
|
||||
@ -56,11 +51,9 @@ contract('Create2', function (accounts) {
|
||||
it('deploys a contract with constructor arguments', async function () {
|
||||
const offChainComputed = computeCreate2Address(saltHex, constructorByteCode, this.factory.address);
|
||||
|
||||
expectEvent(
|
||||
await this.factory.$deploy(0, saltHex, constructorByteCode),
|
||||
'return$deploy',
|
||||
{ addr: offChainComputed },
|
||||
);
|
||||
expectEvent(await this.factory.$deploy(0, saltHex, constructorByteCode), 'return$deploy', {
|
||||
addr: offChainComputed,
|
||||
});
|
||||
|
||||
expect(await VestingWallet.at(offChainComputed).then(instance => instance.beneficiary())).to.be.equal(other);
|
||||
});
|
||||
@ -72,39 +65,25 @@ contract('Create2', function (accounts) {
|
||||
|
||||
const offChainComputed = computeCreate2Address(saltHex, constructorByteCode, this.factory.address);
|
||||
|
||||
expectEvent(
|
||||
await this.factory.$deploy(deposit, saltHex, constructorByteCode),
|
||||
'return$deploy',
|
||||
{ addr: offChainComputed },
|
||||
);
|
||||
expectEvent(await this.factory.$deploy(deposit, saltHex, constructorByteCode), 'return$deploy', {
|
||||
addr: offChainComputed,
|
||||
});
|
||||
|
||||
expect(await balance.current(offChainComputed)).to.be.bignumber.equal(deposit);
|
||||
});
|
||||
|
||||
it('fails deploying a contract in an existent address', async function () {
|
||||
expectEvent(
|
||||
await this.factory.$deploy(0, saltHex, constructorByteCode),
|
||||
'return$deploy',
|
||||
);
|
||||
expectEvent(await this.factory.$deploy(0, saltHex, constructorByteCode), 'return$deploy');
|
||||
|
||||
await expectRevert(
|
||||
this.factory.$deploy(0, saltHex, constructorByteCode),
|
||||
'Create2: Failed on deploy',
|
||||
);
|
||||
await expectRevert(this.factory.$deploy(0, saltHex, constructorByteCode), 'Create2: Failed on deploy');
|
||||
});
|
||||
|
||||
it('fails deploying a contract if the bytecode length is zero', async function () {
|
||||
await expectRevert(
|
||||
this.factory.$deploy(0, saltHex, '0x'),
|
||||
'Create2: bytecode length is zero',
|
||||
);
|
||||
await expectRevert(this.factory.$deploy(0, saltHex, '0x'), 'Create2: bytecode length is zero');
|
||||
});
|
||||
|
||||
it('fails deploying a contract if factory contract does not have sufficient balance', async function () {
|
||||
await expectRevert(
|
||||
this.factory.$deploy(1, saltHex, constructorByteCode),
|
||||
'Create2: insufficient balance',
|
||||
);
|
||||
await expectRevert(this.factory.$deploy(1, saltHex, constructorByteCode), 'Create2: insufficient balance');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user