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

Commit

Permalink
Merge branch '3.0' into fix/3.0/chainId-is-not-net-version
Browse files Browse the repository at this point in the history
  • Loading branch information
feuGeneA authored Oct 26, 2019
2 parents 17cb702 + 59210f5 commit a04da32
Show file tree
Hide file tree
Showing 64 changed files with 1,838 additions and 709 deletions.
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ jobs:
keys:
- repo-{{ .Environment.CIRCLE_SHA1 }}
- run: yarn wsrun test:circleci @0x/contracts-exchange
test-integrations-ganache-3.0:
resource_class: medium+
docker:
- image: nikolaik/python-nodejs:python3.7-nodejs8
working_directory: ~/repo
steps:
- restore_cache:
keys:
- repo-{{ .Environment.CIRCLE_SHA1 }}
- run: yarn wsrun test:circleci @0x/contracts-integrations
test-contracts-rest-ganache-3.0:
resource_class: medium+
docker:
Expand Down Expand Up @@ -392,6 +402,9 @@ workflows:
- test-exchange-ganache-3.0:
requires:
- build
- test-integrations-ganache-3.0:
requires:
- build
- test-contracts-rest-ganache-3.0:
requires:
- build
Expand Down
2 changes: 1 addition & 1 deletion contracts/asset-proxy/contracts/src/ERC20BridgeProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ contract ERC20BridgeProxy is
uint256 balanceBefore = balanceOf(tokenAddress, to);
// Call the bridge, who should transfer `amount` of `tokenAddress` to
// `to`.
bytes4 success = IERC20Bridge(bridgeAddress).withdrawTo(
bytes4 success = IERC20Bridge(bridgeAddress).bridgeTransferFrom(
tokenAddress,
from,
to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract Eth2DaiBridge is
/// @param amount Minimum amount of `toTokenAddress` tokens to buy.
/// @param bridgeData The abi-encoeded "from" token address.
/// @return success The magic bytes if successful.
function withdrawTo(
function bridgeTransferFrom(
address toTokenAddress,
address /* from */,
address to,
Expand Down
4 changes: 2 additions & 2 deletions contracts/asset-proxy/contracts/src/bridges/UniswapBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ contract UniswapBridge is
address constant private UNISWAP_EXCHANGE_FACTORY_ADDRESS = 0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95;
address constant private WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;

// Struct to hold `withdrawTo()` local variables in memory and to avoid
// Struct to hold `bridgeTransferFrom()` local variables in memory and to avoid
// stack overflows.
struct WithdrawToState {
IUniswapExchange exchange;
Expand All @@ -60,7 +60,7 @@ contract UniswapBridge is
/// @param amount Minimum amount of `toTokenAddress` tokens to buy.
/// @param bridgeData The abi-encoded "from" token address.
/// @return success The magic bytes if successful.
function withdrawTo(
function bridgeTransferFrom(
address toTokenAddress,
address /* from */,
address to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract IERC20Bridge {
/// @param amount Amount of asset to transfer.
/// @param bridgeData Arbitrary asset data needed by the bridge contract.
/// @return success The magic bytes `0x37708e9b` if successful.
function withdrawTo(
function bridgeTransferFrom(
address tokenAddress,
address from,
address to,
Expand Down
2 changes: 1 addition & 1 deletion contracts/asset-proxy/contracts/test/TestERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ contract TestERC20Bridge is
testToken.setBalance(owner, balance);
}

function withdrawTo(
function bridgeTransferFrom(
address tokenAddress,
address from,
address to,
Expand Down
6 changes: 3 additions & 3 deletions contracts/asset-proxy/test/eth2dai_bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ blockchainTests.resets('Eth2DaiBridge unit tests', env => {
});
});

describe('withdrawTo()', () => {
describe('bridgeTransferFrom()', () => {
interface WithdrawToOpts {
toTokenAddress?: string;
fromTokenAddress?: string;
Expand Down Expand Up @@ -103,9 +103,9 @@ blockchainTests.resets('Eth2DaiBridge unit tests', env => {
_opts.toTokentransferRevertReason,
_opts.toTokenTransferReturnData,
);
// Call withdrawTo().
// Call bridgeTransferFrom().
const [result, { logs }] = await txHelper.getResultAndReceiptAsync(
testContract.withdrawTo,
testContract.bridgeTransferFrom,
// "to" token address
_opts.toTokenAddress,
// Random from address.
Expand Down
12 changes: 6 additions & 6 deletions contracts/asset-proxy/test/uniswap_bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ blockchainTests.resets('UniswapBridge unit tests', env => {
});
});

describe('withdrawTo()', () => {
describe('bridgeTransferFrom()', () => {
interface WithdrawToOpts {
fromTokenAddress: string;
toTokenAddress: string;
Expand Down Expand Up @@ -115,9 +115,9 @@ blockchainTests.resets('UniswapBridge unit tests', env => {
await testContract.setTokenBalance.awaitTransactionSuccessAsync(_opts.fromTokenAddress, {
value: new BigNumber(_opts.fromTokenBalance),
});
// Call withdrawTo().
// Call bridgeTransferFrom().
const [result, receipt] = await txHelper.getResultAndReceiptAsync(
testContract.withdrawTo,
testContract.bridgeTransferFrom,
// The "to" token address.
_opts.toTokenAddress,
// The "from" address.
Expand Down Expand Up @@ -203,7 +203,7 @@ blockchainTests.resets('UniswapBridge unit tests', env => {
});

it('fails if "from" token does not exist', async () => {
const tx = testContract.withdrawTo.awaitTransactionSuccessAsync(
const tx = testContract.bridgeTransferFrom.awaitTransactionSuccessAsync(
randomAddress(),
randomAddress(),
randomAddress(),
Expand Down Expand Up @@ -275,7 +275,7 @@ blockchainTests.resets('UniswapBridge unit tests', env => {
});

it('fails if "from" token does not exist', async () => {
const tx = testContract.withdrawTo.awaitTransactionSuccessAsync(
const tx = testContract.bridgeTransferFrom.awaitTransactionSuccessAsync(
randomAddress(),
randomAddress(),
randomAddress(),
Expand Down Expand Up @@ -333,7 +333,7 @@ blockchainTests.resets('UniswapBridge unit tests', env => {
});

it('fails if "to" token does not exist', async () => {
const tx = testContract.withdrawTo.awaitTransactionSuccessAsync(
const tx = testContract.bridgeTransferFrom.awaitTransactionSuccessAsync(
wethTokenAddress,
randomAddress(),
randomAddress(),
Expand Down
4 changes: 2 additions & 2 deletions contracts/erc20/contracts/src/ERC20Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ contract ERC20Token is
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;

emit Transfer(
_from,
_to,
_value
);

return true;
}

Expand Down
17 changes: 15 additions & 2 deletions contracts/exchange/test/balance_stores/local_balance_store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { constants } from '@0x/contracts-test-utils';
import { constants, Numberish } from '@0x/contracts-test-utils';
import { assetDataUtils } from '@0x/order-utils';
import { AssetProxyId } from '@0x/types';
import { BigNumber } from '@0x/utils';
Expand Down Expand Up @@ -34,11 +34,24 @@ export class LocalBalanceStore extends BalanceStore {

/**
* Decreases the ETH balance of an address to simulate gas usage.
* @param senderAddress Address whose ETH balance to decrease.
* @param amount Amount to decrease the balance by.
*/
public burnGas(senderAddress: string, amount: BigNumber | number): void {
public burnGas(senderAddress: string, amount: Numberish): void {
this._balances.eth[senderAddress] = this._balances.eth[senderAddress].minus(amount);
}

/**
* Sends ETH from `fromAddress` to `toAddress`.
* @param fromAddress Sender of ETH.
* @param toAddress Receiver of ETH.
* @param amount Amount of ETH to transfer.
*/
public sendEth(fromAddress: string, toAddress: string, amount: Numberish): void {
this._balances.eth[fromAddress] = this._balances.eth[fromAddress].minus(amount);
this._balances.eth[toAddress] = this._balances.eth[toAddress].plus(amount);
}

/**
* Transfers assets from `fromAddress` to `toAddress`.
* @param fromAddress Sender of asset(s)
Expand Down
6 changes: 3 additions & 3 deletions contracts/exchange/test/balance_stores/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ERC1155MintableContract } from '@0x/contracts-erc1155';
import { DummyERC20TokenContract, DummyNoReturnERC20TokenContract } from '@0x/contracts-erc20';
import { DummyERC20TokenContract, DummyNoReturnERC20TokenContract, WETH9Contract } from '@0x/contracts-erc20';
import { DummyERC721TokenContract } from '@0x/contracts-erc721';
import { BigNumber } from '@0x/utils';

Expand All @@ -15,7 +15,7 @@ interface TokenData<TERC20, TERC721, TERC1155> {
export type TokenAddresses = TokenData<address[], address[], address[]>;

export type TokenContracts = TokenData<
Array<DummyERC20TokenContract | DummyNoReturnERC20TokenContract>,
Array<DummyERC20TokenContract | DummyNoReturnERC20TokenContract | WETH9Contract>,
DummyERC721TokenContract[],
ERC1155MintableContract[]
>;
Expand All @@ -29,7 +29,7 @@ export type TokenOwnersByName = Named<address>;
export type TokenAddressesByName = TokenData<Named<address>, Named<address>, Named<address>>;

export type TokenContractsByName = TokenData<
Named<DummyERC20TokenContract | DummyNoReturnERC20TokenContract>,
Named<DummyERC20TokenContract | DummyNoReturnERC20TokenContract | WETH9Contract>,
Named<DummyERC721TokenContract>,
Named<ERC1155MintableContract>
>;
Expand Down
45 changes: 45 additions & 0 deletions contracts/integrations/contracts/test/TestFramework.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
pragma solidity ^0.5.9;

import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";


// This contract is intended to be used in the unit tests that test the typescript
// test framework found in `test/utils/`
contract TestFramework {

event Event(string input);

// bytes4(keccak256("RichRevertErrorSelector(string)"))
bytes4 internal constant RICH_REVERT_ERROR_SELECTOR = 0x49a7e246;

function emitEvent(string calldata input)
external
{
emit Event(input);
}

function emptyRevert()
external
{
revert();
}

function stringRevert(string calldata message)
external
{
revert(message);
}

function doNothing()
external
pure
{} // solhint-disable-line no-empty-blocks

function returnInteger(uint256 integer)
external
pure
returns (uint256)
{
return integer;
}
}
15 changes: 0 additions & 15 deletions contracts/integrations/contracts/test/TestStakingPlaceholder.sol

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/integrations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"compile:truffle": "truffle compile"
},
"config": {
"abis": "./generated-artifacts/@(TestStakingPlaceholder).json",
"abis": "./generated-artifacts/@(TestFramework).json",
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
},
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions contracts/integrations/src/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
*/
import { ContractArtifact } from 'ethereum-types';

import * as TestStakingPlaceholder from '../generated-artifacts/TestStakingPlaceholder.json';
export const artifacts = { TestStakingPlaceholder: TestStakingPlaceholder as ContractArtifact };
import * as TestFramework from '../generated-artifacts/TestFramework.json';
export const artifacts = { TestFramework: TestFramework as ContractArtifact };
3 changes: 3 additions & 0 deletions contracts/integrations/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export * from './artifacts';
export * from './wrappers';
export * from '../test/utils/function_assertions';
export * from '../test/utils/deployment_manager';
export * from '../test/utils/address_manager';
2 changes: 1 addition & 1 deletion contracts/integrations/src/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* Warning: This file is auto-generated by contracts-gen. Don't edit manually.
* -----------------------------------------------------------------------------
*/
export * from '../generated-wrappers/test_staking_placeholder';
export * from '../generated-wrappers/test_framework';
30 changes: 25 additions & 5 deletions contracts/integrations/test/actors/base.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
import { DummyERC20TokenContract, WETH9Contract } from '@0x/contracts-erc20';
import { constants } from '@0x/contracts-test-utils';
import { constants, TransactionFactory } from '@0x/contracts-test-utils';
import { SignatureType, SignedZeroExTransaction, ZeroExTransaction } from '@0x/types';
import { BigNumber } from '@0x/utils';

import { DeploymentManager } from '../deployment/deployment_mananger';
import { DeploymentManager } from '../utils/deployment_manager';

export type Constructor<T = {}> = new (...args: any[]) => T;

export interface ActorConfig {
address: string;
name?: string;
deployment: DeploymentManager;
[mixinProperty: string]: any;
}

export class Actor {
public static count: number = 0;
public readonly address: string;
public readonly name: string;
public readonly privateKey: Buffer;
public readonly deployment: DeploymentManager;
protected readonly transactionFactory: TransactionFactory;

constructor(config: ActorConfig) {
this.address = config.address;
this.name = config.name || config.address;
Actor.count++;
this.address = config.deployment.accounts[Actor.count];
this.name = config.name || this.address;
this.deployment = config.deployment;
this.privateKey = constants.TESTRPC_PRIVATE_KEYS[config.deployment.accounts.indexOf(this.address)];
this.transactionFactory = new TransactionFactory(
this.privateKey,
config.deployment.exchange.address,
config.deployment.chainId,
);
}

/**
Expand Down Expand Up @@ -51,4 +61,14 @@ export class Actor {
{ from: this.address },
);
}

/**
* Signs a transaction.
*/
public async signTransactionAsync(
customTransactionParams: Partial<ZeroExTransaction>,
signatureType: SignatureType = SignatureType.EthSign,
): Promise<SignedZeroExTransaction> {
return this.transactionFactory.newSignedTransactionAsync(customTransactionParams, signatureType);
}
}
Loading

0 comments on commit a04da32

Please sign in to comment.