Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
moodlezoup committed Nov 20, 2019
1 parent 7b020c5 commit db8ed91
Show file tree
Hide file tree
Showing 23 changed files with 872 additions and 58 deletions.
51 changes: 51 additions & 0 deletions contracts/integrations/contracts/test/TestEth2Dai.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "@0x/contracts-asset-proxy/contracts/src/interfaces/IEth2Dai.sol";
import "@0x/contracts-erc20/contracts/test/DummyERC20Token.sol";


contract TestEth2Dai is
IEth2Dai
{
function sellAllAmount(
address sellTokenAddress,
uint256 sellTokenAmount,
address buyTokenAddress,
uint256 minimumFillAmount
)
external
returns (uint256 fillAmount)
{
DummyERC20Token(sellTokenAddress).transferFrom(
msg.sender,
address(this),
sellTokenAmount
);
DummyERC20Token buyToken = DummyERC20Token(buyTokenAddress);
buyToken.mint(minimumFillAmount);
buyToken.transfer(
msg.sender,
minimumFillAmount
);
return minimumFillAmount;
}
}
45 changes: 45 additions & 0 deletions contracts/integrations/contracts/test/TestEth2DaiBridge.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "@0x/contracts-asset-proxy/contracts/src/bridges/Eth2DaiBridge.sol";
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IEth2Dai.sol";


contract TestEth2DaiBridge is
Eth2DaiBridge
{
// solhint-disable var-name-mixedcase
address public TEST_ETH2DAI_ADDRESS;

constructor (address testEth2Dai)
public
{
TEST_ETH2DAI_ADDRESS = testEth2Dai;
}

function _getEth2DaiContract()
internal
view
returns (IEth2Dai exchange)
{
return IEth2Dai(TEST_ETH2DAI_ADDRESS);
}
}
59 changes: 59 additions & 0 deletions contracts/integrations/contracts/test/TestUniswapBridge.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "@0x/contracts-asset-proxy/contracts/src/bridges/UniswapBridge.sol";
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IUniswapExchangeFactory.sol";
import "@0x/contracts-erc20/contracts/src/interfaces/IEtherToken.sol";


contract TestUniswapBridge is
UniswapBridge
{
// solhint-disable var-name-mixedcase
address public TEST_WETH_ADDRESS;
address public TEST_UNISWAP_EXCHANGE_FACTORY_ADDRESS;

constructor (
address testWeth,
address testUniswapExchangeFactory
)
public
{
TEST_WETH_ADDRESS = testWeth;
TEST_UNISWAP_EXCHANGE_FACTORY_ADDRESS = testUniswapExchangeFactory;
}

function getWethContract()
public
view
returns (IEtherToken token)
{
return IEtherToken(TEST_WETH_ADDRESS);
}

function getUniswapExchangeFactoryContract()
public
view
returns (IUniswapExchangeFactory factory)
{
return IUniswapExchangeFactory(TEST_UNISWAP_EXCHANGE_FACTORY_ADDRESS);
}
}
102 changes: 102 additions & 0 deletions contracts/integrations/contracts/test/TestUniswapExchange.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "@0x/contracts-asset-proxy/contracts/src/interfaces/IUniswapExchange.sol";
import "@0x/contracts-erc20/contracts/test/DummyERC20Token.sol";


contract TestUniswapExchange is
IUniswapExchange
{
DummyERC20Token public token;

constructor(address _tokenAddress) public {
token = DummyERC20Token(_tokenAddress);
}

// solhint-disable no-empty-blocks
/// @dev Used to receive ETH for testing.
function topUpEth()
external
payable
{}

function ethToTokenTransferInput(
uint256 minTokensBought,
uint256, /* deadline */
address recipient
)
external
payable
returns (uint256 tokensBought)
{
token.mint(minTokensBought);
token.transfer(recipient, minTokensBought);
return minTokensBought;
}

function tokenToEthSwapInput(
uint256 tokensSold,
uint256 minEthBought,
uint256 /* deadline */
)
external
returns (uint256 ethBought)
{
token.transferFrom(
msg.sender,
address(this),
tokensSold
);
msg.sender.transfer(minEthBought);
return minEthBought;
}

function tokenToTokenTransferInput(
uint256 tokensSold,
uint256 minTokensBought,
uint256, /* minEthBought */
uint256, /* deadline */
address recipient,
address toTokenAddress
)
external
returns (uint256 tokensBought)
{
token.transferFrom(
msg.sender,
address(this),
tokensSold
);
DummyERC20Token toToken = DummyERC20Token(toTokenAddress);
toToken.mint(minTokensBought);
toToken.transfer(recipient, minTokensBought);
return minTokensBought;
}

function toTokenAddress()
external
view
returns (address _tokenAddress)
{
return address(token);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "@0x/contracts-asset-proxy/contracts/src/bridges/UniswapBridge.sol";
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IUniswapExchangeFactory.sol";
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IUniswapExchange.sol";


contract TestUniswapExchangeFactory is
IUniswapExchangeFactory
{
// Token address to UniswapExchange address.
mapping (address => address) private _testExchanges;

/// @dev Create a token and exchange (if they don't exist) for a new token
/// and sets the exchange revert and fill behavior.
/// @param tokenAddress The token address.
function addExchange(
address tokenAddress,
address exchangeAddress
)
external
{
_testExchanges[tokenAddress] = exchangeAddress;
}

/// @dev `IUniswapExchangeFactory.getExchange`
function getExchange(address tokenAddress)
external
view
returns (IUniswapExchange)
{
return IUniswapExchange(_testExchanges[tokenAddress]);
}
}
2 changes: 1 addition & 1 deletion contracts/integrations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"config": {
"publicInterfaceContracts": "TestFramework",
"abis": "./test/generated-artifacts/@(TestFramework).json",
"abis": "./test/generated-artifacts/@(TestEth2Dai|TestEth2DaiBridge|TestFramework|TestUniswapBridge|TestUniswapExchange|TestUniswapExchangeFactory).json",
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
},
"repository": {
Expand Down
14 changes: 13 additions & 1 deletion contracts/integrations/test/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,17 @@
*/
import { ContractArtifact } from 'ethereum-types';

import * as TestEth2Dai from '../test/generated-artifacts/TestEth2Dai.json';
import * as TestEth2DaiBridge from '../test/generated-artifacts/TestEth2DaiBridge.json';
import * as TestFramework from '../test/generated-artifacts/TestFramework.json';
export const artifacts = { TestFramework: TestFramework as ContractArtifact };
import * as TestUniswapBridge from '../test/generated-artifacts/TestUniswapBridge.json';
import * as TestUniswapExchange from '../test/generated-artifacts/TestUniswapExchange.json';
import * as TestUniswapExchangeFactory from '../test/generated-artifacts/TestUniswapExchangeFactory.json';
export const artifacts = {
TestEth2Dai: TestEth2Dai as ContractArtifact,
TestEth2DaiBridge: TestEth2DaiBridge as ContractArtifact,
TestFramework: TestFramework as ContractArtifact,
TestUniswapBridge: TestUniswapBridge as ContractArtifact,
TestUniswapExchange: TestUniswapExchange as ContractArtifact,
TestUniswapExchangeFactory: TestUniswapExchangeFactory as ContractArtifact,
};
28 changes: 28 additions & 0 deletions contracts/integrations/test/bridges/deploy_eth2dai_bridge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { artifacts as ERC20Artifacts } from '@0x/contracts-erc20';
import { BlockchainTestsEnvironment } from '@0x/contracts-test-utils';

import { artifacts } from '../artifacts';
import { DeploymentManager } from '../framework/deployment_manager';
import { TestEth2DaiBridgeContract, TestEth2DaiContract } from '../wrappers';

export async function deployEth2DaiBridgeAsync(
deployment: DeploymentManager,
environment: BlockchainTestsEnvironment,
): Promise<[TestEth2DaiBridgeContract, TestEth2DaiContract]> {
const eth2Dai = await TestEth2DaiContract.deployFrom0xArtifactAsync(
artifacts.TestEth2Dai,
environment.provider,
deployment.txDefaults,
artifacts,
);

const eth2DaiBridge = await TestEth2DaiBridgeContract.deployFrom0xArtifactAsync(
artifacts.TestEth2DaiBridge,
environment.provider,
deployment.txDefaults,
{ ...ERC20Artifacts, ...artifacts },
eth2Dai.address,
);

return [eth2DaiBridge, eth2Dai];
}
Loading

0 comments on commit db8ed91

Please sign in to comment.