@0x/contracts-test-utils: Fix blockchainTests fork config to work with other tests.

This commit is contained in:
Lawrence Forman 2020-02-06 01:55:55 -05:00
parent d94a26f0f4
commit bf9b4b993f
4 changed files with 43 additions and 17 deletions

View File

@ -117,6 +117,15 @@ interface IDydx {
)
external;
// @dev Approves/disapproves any number of operators. An operator is an external address that has the
// same permissions to manipulate an account as the owner of the account. Operators are simply
// addresses and therefore may either be externally-owned Ethereum accounts OR smart contracts.
// Operators are also able to act as AutoTrader contracts on behalf of the account owner if the
// operator is a smart contract and implements the IAutoTrader interface.
// @param args A list of OperatorArgs which have an address and a boolean. The boolean value
// denotes whether to approve (true) or revoke approval (false) for that address.
function setOperators(OperatorArg[] calldata args) external;
/// @dev Return true if a particular address is approved as an operator for an owner's accounts.
/// Approved operators can act on the accounts of the owner as if it were the operator's own.
/// @param owner The owner of the accounts
@ -171,13 +180,4 @@ interface IDydx {
external
view
returns (Value memory supplyValue, Value memory borrowValue);
// @dev Approves/disapproves any number of operators. An operator is an external address that has the
// same permissions to manipulate an account as the owner of the account. Operators are simply
// addresses and therefore may either be externally-owned Ethereum accounts OR smart contracts.
// Operators are also able to act as AutoTrader contracts on behalf of the account owner if the
// operator is a smart contract and implements the IAutoTrader interface.
// @param args A list of OperatorArgs which have an address and a boolean. The boolean value
// denotes whether to approve (true) or revoke approval (false) for that address.
function setOperators(OperatorArg[] calldata args) external;
}

View File

@ -172,6 +172,9 @@ contract TestDydxBridge is
return _testTokenAddress;
}
/// @dev Unused.
function setOperators(OperatorArg[] calldata args) external {}
/// @dev Unused.
function getIsLocalOperator(
address owner,
@ -216,9 +219,6 @@ contract TestDydxBridge is
returns (Value memory supplyValue, Value memory borrowValue)
{}
/// @dev Unused.
function setOperators(OperatorArg[] calldata args) external {}
/// @dev overrides `_getDydxAddress()` from `DeploymentConstants` to return this address.
function _getDydxAddress()
internal

View File

@ -33,11 +33,11 @@ enum DydxAssetReference {
const MAKER_ADDRESS = '0x3a9F7C8cA36C42d7035E87C3304eE5cBd353a532';
blockchainTests.config = {
blockchainTests.configure({
fork: {
unlockedAccounts: [MAKER_ADDRESS],
},
};
});
blockchainTests.fork('DevUtils dydx order validation tests', env => {
const { ZERO_AMOUNT: ZERO } = constants;

View File

@ -30,12 +30,14 @@ export interface BlockchainContextConfig {
}>;
}
let TEST_ENV_CONFIG: Partial<BlockchainContextConfig> = {};
/**
* Interface for `blockchainTests()`.
*/
export interface BlockchainContextDefinition {
(description: string, callback: BlockchainSuiteCallback): ISuite;
config: Partial<BlockchainContextConfig>;
configure: (config?: Partial<BlockchainContextConfig>) => void;
only: BlockchainContextDefinitionCallback<ISuite>;
skip: BlockchainContextDefinitionCallback<void>;
optional: BlockchainContextDefinitionCallback<ISuite | void>;
@ -102,6 +104,11 @@ export class StandardBlockchainTestsEnvironmentSingleton extends BlockchainTests
return StandardBlockchainTestsEnvironmentSingleton._instance;
}
// Reset the singleton.
public static reset(): void {
StandardBlockchainTestsEnvironmentSingleton._instance = undefined;
}
// Get the singleton instance of this class.
public static getInstance(): StandardBlockchainTestsEnvironmentSingleton | undefined {
return StandardBlockchainTestsEnvironmentSingleton._instance;
@ -130,8 +137,13 @@ export class ForkedBlockchainTestsEnvironmentSingleton extends BlockchainTestsEn
return ForkedBlockchainTestsEnvironmentSingleton._instance;
}
// Reset the singleton.
public static reset(): void {
ForkedBlockchainTestsEnvironmentSingleton._instance = undefined;
}
protected static _createWeb3Provider(forkHost: string): Web3ProviderEngine {
const forkConfig = blockchainTests.config.fork || {};
const forkConfig = TEST_ENV_CONFIG.fork || {};
const unlockedAccounts = forkConfig.unlockedAccounts;
return web3Factory.getRpcProvider({
...providerConfigs,
@ -172,6 +184,11 @@ export class LiveBlockchainTestsEnvironmentSingleton extends BlockchainTestsEnvi
return LiveBlockchainTestsEnvironmentSingleton._instance;
}
// Reset the singleton.
public static reset(): void {
LiveBlockchainTestsEnvironmentSingleton._instance = undefined;
}
protected static _createWeb3Provider(rpcHost: string): Web3ProviderEngine {
const providerEngine = new Web3ProviderEngine();
providerEngine.addProvider(new RPCSubprovider(rpcHost));
@ -223,7 +240,16 @@ export const blockchainTests: BlockchainContextDefinition = _.assign(
return defineBlockchainSuite(StandardBlockchainTestsEnvironmentSingleton, description, callback, describe);
},
{
config: {},
configure(config?: Partial<BlockchainContextConfig>): void {
// Update the global config and reset all environment singletons.
TEST_ENV_CONFIG = {
...TEST_ENV_CONFIG,
...config,
};
ForkedBlockchainTestsEnvironmentSingleton.reset();
StandardBlockchainTestsEnvironmentSingleton.reset();
LiveBlockchainTestsEnvironmentSingleton.reset();
},
only(description: string, callback: BlockchainSuiteCallback): ISuite {
return defineBlockchainSuite(
StandardBlockchainTestsEnvironmentSingleton,