From 9f15d75925efa9b93bbf15a21672aeef3f50781c Mon Sep 17 00:00:00 2001 From: Noah Zinsmeister Date: Wed, 8 Jan 2020 13:04:01 -0500 Subject: [PATCH] fix tests related to bytecode --- contracts/UniswapV2Factory.sol | 6 +++--- test/UniswapV2Factory.spec.ts | 8 +++----- test/shared/fixtures.ts | 13 +++++-------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/contracts/UniswapV2Factory.sol b/contracts/UniswapV2Factory.sol index 10dd4f5..6b141cc 100644 --- a/contracts/UniswapV2Factory.sol +++ b/contracts/UniswapV2Factory.sol @@ -1,8 +1,8 @@ pragma solidity 0.5.15; -import "./UniswapV2.sol"; import "./interfaces/IUniswapV2Factory.sol"; import "./interfaces/IUniswapV2.sol"; +import "./UniswapV2.sol"; contract UniswapV2Factory is IUniswapV2Factory { address public feeToSetter; @@ -35,10 +35,10 @@ contract UniswapV2Factory is IUniswapV2Factory { require(tokenA != address(0) && tokenB != address(0), "UniswapV2Factory: ZERO_ADDRESS"); (address token0, address token1) = sortTokens(tokenA, tokenB); require(getExchange_[token0][token1] == address(0), "UniswapV2Factory: EXCHANGE_EXISTS"); - bytes memory exchangeBytecodeMemory = type(UniswapV2).creationCode; + bytes memory exchangeBytecode = type(UniswapV2).creationCode; bytes32 salt = keccak256(abi.encodePacked(token0, token1)); assembly { // solium-disable-line security/no-inline-assembly - exchange := create2(0, add(exchangeBytecodeMemory, 32), mload(exchangeBytecodeMemory), salt) + exchange := create2(0, add(exchangeBytecode, 32), mload(exchangeBytecode), salt) } IUniswapV2(exchange).initialize(token0, token1); getExchange_[token0][token1] = exchange; diff --git a/test/UniswapV2Factory.spec.ts b/test/UniswapV2Factory.spec.ts index 4494459..5d4329d 100644 --- a/test/UniswapV2Factory.spec.ts +++ b/test/UniswapV2Factory.spec.ts @@ -23,16 +23,13 @@ describe('UniswapV2Factory', () => { const [wallet, other] = getWallets(provider) const loadFixture = createFixtureLoader(provider, [wallet]) - let bytecode: string let factory: Contract beforeEach(async () => { - const { bytecode: _bytecode, factory: _factory }: FactoryFixture = await loadFixture(factoryFixture as any) - bytecode = _bytecode + const { factory: _factory }: FactoryFixture = await loadFixture(factoryFixture as any) factory = _factory }) - it('exchangeBytecode, feeToSetter, feeTo, exchangesCount', async () => { - expect(await factory.exchangeBytecode()).to.eq(bytecode) + it('feeToSetter, feeTo, exchangesCount', async () => { expect(await factory.feeToSetter()).to.eq(wallet.address) expect(await factory.feeTo()).to.eq(AddressZero) expect(await factory.exchangesCount()).to.eq(0) @@ -50,6 +47,7 @@ describe('UniswapV2Factory', () => { }) async function createExchange(tokens: string[]) { + const bytecode = `0x${UniswapV2.evm.bytecode.object}` const create2Address = getCreate2Address(factory.address, TEST_ADDRESSES.token0, TEST_ADDRESSES.token1, bytecode) await expect(factory.createExchange(...tokens)) .to.emit(factory, 'ExchangeCreated') diff --git a/test/shared/fixtures.ts b/test/shared/fixtures.ts index 6c080e0..5fb45da 100644 --- a/test/shared/fixtures.ts +++ b/test/shared/fixtures.ts @@ -8,16 +8,13 @@ import UniswapV2 from '../../build/UniswapV2.json' import UniswapV2Factory from '../../build/UniswapV2Factory.json' export interface FactoryFixture { - bytecode: string factory: Contract } export async function factoryFixture(provider: providers.Web3Provider, [wallet]: Wallet[]): Promise { - const bytecode = `0x${UniswapV2.evm.bytecode.object}` - const factory = await deployContract(wallet, UniswapV2Factory, [bytecode, wallet.address], { - gasLimit: (provider._web3Provider as any).options.gasLimit - }) - return { bytecode, factory } + const factory = await deployContract(wallet, UniswapV2Factory, [wallet.address]) + + return { factory } } export interface ExchangeFixture extends FactoryFixture { @@ -27,7 +24,7 @@ export interface ExchangeFixture extends FactoryFixture { } export async function exchangeFixture(provider: providers.Web3Provider, [wallet]: Wallet[]): Promise { - const { bytecode, factory } = await factoryFixture(provider, [wallet]) + const { factory } = await factoryFixture(provider, [wallet]) const tokenA = await deployContract(wallet, ERC20, ['Test Token A', 'TESTA', 18, expandTo18Decimals(10000)]) const tokenB = await deployContract(wallet, ERC20, ['Test Token B', 'TESTB', 18, expandTo18Decimals(10000)]) @@ -40,5 +37,5 @@ export async function exchangeFixture(provider: providers.Web3Provider, [wallet] const token0 = tokenA.address === token0Address ? tokenA : tokenB const token1 = tokenA.address === token0Address ? tokenB : tokenA - return { bytecode, factory, token0, token1, exchange } + return { factory, token0, token1, exchange } }