Use hardhat-exposed to reduce the need for mocks (#3666)
Co-authored-by: Francisco <fg@frang.io>
This commit is contained in:
@ -4,14 +4,17 @@ const { expect } = require('chai');
|
||||
|
||||
const shouldBehaveLikeClone = require('./Clones.behaviour');
|
||||
|
||||
const ClonesMock = artifacts.require('ClonesMock');
|
||||
const Clones = artifacts.require('$Clones');
|
||||
|
||||
contract('Clones', function (accounts) {
|
||||
const [ deployer ] = accounts;
|
||||
|
||||
contract('Clones', function () {
|
||||
describe('clone', function () {
|
||||
shouldBehaveLikeClone(async (implementation, initData, opts = {}) => {
|
||||
const factory = await ClonesMock.new();
|
||||
const receipt = await factory.clone(implementation, initData, { value: opts.value });
|
||||
const address = receipt.logs.find(({ event }) => event === 'NewInstance').args.instance;
|
||||
const factory = await Clones.new();
|
||||
const receipt = await factory.$clone(implementation);
|
||||
const address = receipt.logs.find(({ event }) => event === 'return$clone').args.instance;
|
||||
await web3.eth.sendTransaction({ from: deployer, to: address, value: opts.value, data: initData });
|
||||
return { address };
|
||||
});
|
||||
});
|
||||
@ -19,24 +22,25 @@ contract('Clones', function () {
|
||||
describe('cloneDeterministic', function () {
|
||||
shouldBehaveLikeClone(async (implementation, initData, opts = {}) => {
|
||||
const salt = web3.utils.randomHex(32);
|
||||
const factory = await ClonesMock.new();
|
||||
const receipt = await factory.cloneDeterministic(implementation, salt, initData, { value: opts.value });
|
||||
const address = receipt.logs.find(({ event }) => event === 'NewInstance').args.instance;
|
||||
const factory = await Clones.new();
|
||||
const receipt = await factory.$cloneDeterministic(implementation, salt);
|
||||
const address = receipt.logs.find(({ event }) => event === 'return$cloneDeterministic').args.instance;
|
||||
await web3.eth.sendTransaction({ from: deployer, to: address, value: opts.value, data: initData });
|
||||
return { address };
|
||||
});
|
||||
|
||||
it('address already used', async function () {
|
||||
const implementation = web3.utils.randomHex(20);
|
||||
const salt = web3.utils.randomHex(32);
|
||||
const factory = await ClonesMock.new();
|
||||
const factory = await Clones.new();
|
||||
// deploy once
|
||||
expectEvent(
|
||||
await factory.cloneDeterministic(implementation, salt, '0x'),
|
||||
'NewInstance',
|
||||
await factory.$cloneDeterministic(implementation, salt),
|
||||
'return$cloneDeterministic',
|
||||
);
|
||||
// deploy twice
|
||||
await expectRevert(
|
||||
factory.cloneDeterministic(implementation, salt, '0x'),
|
||||
factory.$cloneDeterministic(implementation, salt),
|
||||
'ERC1167: create2 failed',
|
||||
);
|
||||
});
|
||||
@ -44,8 +48,8 @@ contract('Clones', function () {
|
||||
it('address prediction', async function () {
|
||||
const implementation = web3.utils.randomHex(20);
|
||||
const salt = web3.utils.randomHex(32);
|
||||
const factory = await ClonesMock.new();
|
||||
const predicted = await factory.predictDeterministicAddress(implementation, salt);
|
||||
const factory = await Clones.new();
|
||||
const predicted = await factory.$predictDeterministicAddress(implementation, salt);
|
||||
|
||||
const creationCode = [
|
||||
'0x3d602d80600a3d3981f3363d3d373d3d3d363d73',
|
||||
@ -60,8 +64,8 @@ contract('Clones', function () {
|
||||
)).to.be.equal(predicted);
|
||||
|
||||
expectEvent(
|
||||
await factory.cloneDeterministic(implementation, salt, '0x'),
|
||||
'NewInstance',
|
||||
await factory.$cloneDeterministic(implementation, salt),
|
||||
'return$cloneDeterministic',
|
||||
{ instance: predicted },
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user