@0x:contracts-integrations Added unit tests for FunctionAssertion
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
pragma solidity ^0.5.9;
|
||||
|
||||
|
||||
contract TestCache {
|
||||
contract TestFramework {
|
||||
|
||||
event SomeEvent(uint256 someNumber);
|
||||
|
||||
uint256 public counter;
|
||||
|
||||
@@ -11,12 +13,16 @@ contract TestCache {
|
||||
counter = newCounter;
|
||||
}
|
||||
|
||||
function numberSideEffect()
|
||||
function revertSideEffect(uint256 returnValue)
|
||||
external
|
||||
view
|
||||
returns (uint256)
|
||||
{
|
||||
return counter;
|
||||
if (counter != 0) {
|
||||
revert("Revert");
|
||||
}
|
||||
|
||||
emit SomeEvent(returnValue);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
function equalsSideEffect(uint256 possiblyZero)
|
||||
@@ -31,6 +37,19 @@ contract TestCache {
|
||||
}
|
||||
}
|
||||
|
||||
function noEffect(uint256)
|
||||
external
|
||||
pure
|
||||
{} // solhint-disable-line no-empty-blocks
|
||||
|
||||
function numberSideEffect()
|
||||
external
|
||||
view
|
||||
returns (uint256)
|
||||
{
|
||||
return counter;
|
||||
}
|
||||
|
||||
function hashSideEffect(uint256 arg1, bytes32 arg2)
|
||||
external
|
||||
view
|
||||
@@ -1,15 +0,0 @@
|
||||
pragma solidity ^0.5.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-staking/contracts/test/TestStaking.sol";
|
||||
|
||||
|
||||
// TODO(jalextowle): This contract can be removed when the added to this package.
|
||||
contract TestStakingPlaceholder is
|
||||
TestStaking
|
||||
{
|
||||
constructor(address wethAddress, address zrxVaultAddress)
|
||||
public
|
||||
TestStaking(wethAddress, zrxVaultAddress)
|
||||
{} // solhint-disable-line no-empty-blocks
|
||||
}
|
||||
@@ -35,7 +35,7 @@
|
||||
"compile:truffle": "truffle compile"
|
||||
},
|
||||
"config": {
|
||||
"abis": "./generated-artifacts/@(TestCache|TestStakingPlaceholder).json",
|
||||
"abis": "./generated-artifacts/@(TestFramework).json",
|
||||
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
|
||||
},
|
||||
"repository": {
|
||||
|
||||
@@ -5,9 +5,5 @@
|
||||
*/
|
||||
import { ContractArtifact } from 'ethereum-types';
|
||||
|
||||
import * as TestCache from '../generated-artifacts/TestCache.json';
|
||||
import * as TestStakingPlaceholder from '../generated-artifacts/TestStakingPlaceholder.json';
|
||||
export const artifacts = {
|
||||
TestCache: TestCache as ContractArtifact,
|
||||
TestStakingPlaceholder: TestStakingPlaceholder as ContractArtifact,
|
||||
};
|
||||
import * as TestFramework from '../generated-artifacts/TestFramework.json';
|
||||
export const artifacts = { TestFramework: TestFramework as ContractArtifact };
|
||||
|
||||
@@ -3,5 +3,4 @@
|
||||
* Warning: This file is auto-generated by contracts-gen. Don't edit manually.
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
export * from '../generated-wrappers/test_cache';
|
||||
export * from '../generated-wrappers/test_staking_placeholder';
|
||||
export * from '../generated-wrappers/test_framework';
|
||||
|
||||
@@ -2,16 +2,18 @@ import { blockchainTests, constants, expect } from '@0x/contracts-test-utils';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { TxData, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
||||
|
||||
import { artifacts, Condition, FunctionAssertion, GetterCache, TestCacheContract } from '../../src';
|
||||
import { artifacts, TestFrameworkContract } from '../../src';
|
||||
import { Condition, FunctionAssertion, Result } from '../utils/function_assertions';
|
||||
import { GetterCache } from '../utils/cache';
|
||||
|
||||
// These tests provide examples for how to use the "FunctionAssertion" class to write
|
||||
// tests for "payable" and "nonpayable" Solidity functions as well as "pure" and "view" functions.
|
||||
blockchainTests('TestCache', env => {
|
||||
let testCache: TestCacheContract;
|
||||
blockchainTests('TestFramework', env => {
|
||||
let exampleContract: TestFrameworkContract;
|
||||
|
||||
before(async () => {
|
||||
testCache = await TestCacheContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TestCache,
|
||||
exampleContract = await TestFrameworkContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TestFramework,
|
||||
env.provider,
|
||||
env.txDefaults,
|
||||
artifacts,
|
||||
@@ -24,12 +26,16 @@ blockchainTests('TestCache', env => {
|
||||
before(async () => {
|
||||
const condition = {
|
||||
before: async () => {},
|
||||
after: async (result: any, receipt: TransactionReceiptWithDecodedLogs | undefined) => {
|
||||
const counter = await testCache.counter.callAsync();
|
||||
expect(result).bignumber.to.be.eq(counter);
|
||||
after: async (beforeInfo: any, result: Result) => {
|
||||
// Ensure that the call was successful.
|
||||
expect(result.success).to.be.true();
|
||||
|
||||
// Ensure that the correct counter was returned.
|
||||
const counter = await exampleContract.counter.callAsync();
|
||||
expect(result.data).bignumber.to.be.eq(counter);
|
||||
},
|
||||
};
|
||||
assertion = new FunctionAssertion(testCache.numberSideEffect, condition);
|
||||
assertion = new FunctionAssertion(exampleContract.numberSideEffect, condition);
|
||||
});
|
||||
|
||||
it('should return the correct counter', async () => {
|
||||
@@ -37,7 +43,7 @@ blockchainTests('TestCache', env => {
|
||||
});
|
||||
|
||||
it('should return the correct counter', async () => {
|
||||
await testCache.setCounter.awaitTransactionSuccessAsync(new BigNumber(2));
|
||||
await exampleContract.setCounter.awaitTransactionSuccessAsync(new BigNumber(2));
|
||||
await assertion.runAsync();
|
||||
});
|
||||
});
|
||||
@@ -48,16 +54,16 @@ blockchainTests('TestCache', env => {
|
||||
before(async () => {
|
||||
const condition = {
|
||||
before: async (expectedCounter: BigNumber) => {},
|
||||
after: async (
|
||||
result: any,
|
||||
receipt: TransactionReceiptWithDecodedLogs | undefined,
|
||||
expectedCounter: BigNumber,
|
||||
) => {
|
||||
const counter = await testCache.counter.callAsync();
|
||||
after: async (beforeInfo: any, result: Result, expectedCounter: BigNumber) => {
|
||||
// Ensure that the call was successful.
|
||||
expect(result.success).to.be.true();
|
||||
|
||||
// Ensure that the counter was updated correctly.
|
||||
const counter = await exampleContract.counter.callAsync();
|
||||
expect(counter).bignumber.to.be.eq(expectedCounter);
|
||||
},
|
||||
};
|
||||
assertion = new FunctionAssertion(testCache.setCounter, condition);
|
||||
assertion = new FunctionAssertion(exampleContract.setCounter, condition);
|
||||
});
|
||||
|
||||
it('should correctly set counter to 1', async () => {
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
import { Authorizable, Ownable } from '@0x/contracts-exchange';
|
||||
import { constants as stakingConstants } from '@0x/contracts-staking';
|
||||
import { blockchainTests, expect } from '@0x/contracts-test-utils';
|
||||
|
||||
<<<<<<< HEAD:contracts/integrations/test/utils/deployment_manager_test.ts
|
||||
import { DeploymentManager } from './deployment_mananger';
|
||||
=======
|
||||
import { DeploymentManager } from '../utils/deployment_manager';
|
||||
>>>>>>> `@0x:contracts-integrations` Added unit tests for FunctionAssertion:contracts/integrations/test/framework-unit-tests/deployment_manager_test.ts
|
||||
|
||||
blockchainTests('Deployment Manager', env => {
|
||||
let owner: string;
|
||||
let deploymentManager: DeploymentManager;
|
||||
|
||||
before(async () => {
|
||||
[owner] = await env.getAccountAddressesAsync();
|
||||
deploymentManager = await DeploymentManager.deployAsync(env);
|
||||
});
|
||||
|
||||
async function batchAssertAuthoritiesAsync(
|
||||
authorities: string[],
|
||||
authorizedContracts: Authorizable[],
|
||||
): Promise<void> {
|
||||
for (const authorized of authorizedContracts) {
|
||||
expect(await authorized.getAuthorizedAddresses.callAsync()).to.be.deep.eq(authorities);
|
||||
}
|
||||
}
|
||||
|
||||
async function batchAssertAuthorizedAsync(
|
||||
authorizedAddress: string,
|
||||
authorizedContracts: Authorizable[],
|
||||
): Promise<void> {
|
||||
for (const authorized of authorizedContracts) {
|
||||
expect(await authorized.authorized.callAsync(authorizedAddress)).to.be.true();
|
||||
}
|
||||
}
|
||||
|
||||
async function batchAssertOwnerAsync(ownerAddress: string, owners: Ownable[]): Promise<void> {
|
||||
for (const ownerContract of owners) {
|
||||
expect(await ownerContract.owner.callAsync()).to.be.eq(ownerAddress);
|
||||
}
|
||||
}
|
||||
|
||||
describe('asset proxy owner', () => {
|
||||
it('should be owned by `owner`', async () => {
|
||||
// Ensure that the owners of the asset proxy only contain the owner.
|
||||
const owners = await deploymentManager.governor.getOwners.callAsync();
|
||||
expect(owners).to.be.deep.eq([owner]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('asset proxies', () => {
|
||||
it('should be owned be the asset proxy owner', async () => {
|
||||
await batchAssertOwnerAsync(deploymentManager.governor.address, [
|
||||
deploymentManager.assetProxies.erc1155Proxy,
|
||||
deploymentManager.assetProxies.erc20Proxy,
|
||||
deploymentManager.assetProxies.erc721Proxy,
|
||||
deploymentManager.assetProxies.multiAssetProxy,
|
||||
]);
|
||||
});
|
||||
|
||||
it('should have authorized the multi-asset proxy', async () => {
|
||||
await batchAssertAuthorizedAsync(deploymentManager.assetProxies.multiAssetProxy.address, [
|
||||
deploymentManager.assetProxies.erc1155Proxy,
|
||||
deploymentManager.assetProxies.erc20Proxy,
|
||||
deploymentManager.assetProxies.erc721Proxy,
|
||||
]);
|
||||
});
|
||||
|
||||
it('should have authorized the exchange', async () => {
|
||||
await batchAssertAuthorizedAsync(deploymentManager.exchange.address, [
|
||||
deploymentManager.assetProxies.erc1155Proxy,
|
||||
deploymentManager.assetProxies.erc20Proxy,
|
||||
deploymentManager.assetProxies.erc721Proxy,
|
||||
deploymentManager.assetProxies.multiAssetProxy,
|
||||
]);
|
||||
});
|
||||
|
||||
it('should have the correct authorities list', async () => {
|
||||
// The multi-asset proxy should only have the exchange in the authorities list.
|
||||
const authorities = await deploymentManager.assetProxies.multiAssetProxy.getAuthorizedAddresses.callAsync();
|
||||
expect(authorities).to.be.deep.eq([deploymentManager.exchange.address]);
|
||||
|
||||
// The other asset proxies should have the exchange and the multi-asset proxy in their
|
||||
// authorities list.
|
||||
await batchAssertAuthoritiesAsync(
|
||||
[deploymentManager.assetProxies.multiAssetProxy.address, deploymentManager.exchange.address],
|
||||
[
|
||||
deploymentManager.assetProxies.erc1155Proxy,
|
||||
deploymentManager.assetProxies.erc20Proxy,
|
||||
deploymentManager.assetProxies.erc721Proxy,
|
||||
],
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('exchange', () => {
|
||||
it('should be owned by the asset proxy owner', async () => {
|
||||
const exchangeOwner = await deploymentManager.exchange.owner.callAsync();
|
||||
expect(exchangeOwner).to.be.eq(deploymentManager.governor.address);
|
||||
});
|
||||
|
||||
/*
|
||||
TODO(jalextowle): This test should be enabled once the Exchange is
|
||||
made an Authorizable contract.
|
||||
it('should have authorized the asset proxy owner', async () => {
|
||||
const isAuthorized = await deploymentManager.exchange.owner.callAsync(
|
||||
deploymentManager.governor.address,
|
||||
);
|
||||
expect(isAuthorized).to.be.true();
|
||||
});
|
||||
*/
|
||||
|
||||
it('should have registered the staking proxy', async () => {
|
||||
const feeCollector = await deploymentManager.exchange.protocolFeeCollector.callAsync();
|
||||
expect(feeCollector).to.be.eq(deploymentManager.staking.stakingProxy.address);
|
||||
});
|
||||
|
||||
it('should have set the protocol fee multiplier', async () => {
|
||||
const feeMultiplier = await deploymentManager.exchange.protocolFeeMultiplier.callAsync();
|
||||
expect(feeMultiplier).bignumber.to.be.eq(DeploymentManager.protocolFeeMultiplier);
|
||||
});
|
||||
});
|
||||
|
||||
describe('staking', () => {
|
||||
it('should be owned by the asset proxy owner', async () => {
|
||||
const stakingOwner = await deploymentManager.staking.stakingProxy.owner.callAsync();
|
||||
expect(stakingOwner).to.be.eq(deploymentManager.governor.address);
|
||||
});
|
||||
|
||||
it('should have authorized the asset proxy owner in the staking proxy', async () => {
|
||||
const isAuthorized = await deploymentManager.staking.stakingProxy.authorized.callAsync(
|
||||
deploymentManager.governor.address,
|
||||
);
|
||||
expect(isAuthorized).to.be.true();
|
||||
});
|
||||
|
||||
it('should have registered the exchange in the staking proxy', async () => {
|
||||
const isValid = await deploymentManager.staking.stakingProxy.validExchanges.callAsync(
|
||||
deploymentManager.exchange.address,
|
||||
);
|
||||
expect(isValid).to.be.true();
|
||||
});
|
||||
|
||||
it('should have registered the read-only proxy in the staking proxy', async () => {
|
||||
const readOnlyProxy = await deploymentManager.staking.stakingProxy.readOnlyProxy.callAsync();
|
||||
expect(readOnlyProxy).to.be.eq(deploymentManager.staking.readOnlyProxy.address);
|
||||
});
|
||||
|
||||
it('should have registered the staking contract in the staking proxy', async () => {
|
||||
const stakingContract = await deploymentManager.staking.stakingProxy.stakingContract.callAsync();
|
||||
expect(stakingContract).to.be.eq(deploymentManager.staking.stakingLogic.address);
|
||||
});
|
||||
|
||||
it('should have registered the weth contract in the staking contract', async () => {
|
||||
const weth = await deploymentManager.staking.stakingWrapper.testWethAddress.callAsync();
|
||||
expect(weth).to.be.eq(deploymentManager.tokens.weth.address);
|
||||
});
|
||||
|
||||
it('should have registered the zrx vault in the staking contract', async () => {
|
||||
const zrxVault = await deploymentManager.staking.stakingWrapper.testZrxVaultAddress.callAsync();
|
||||
expect(zrxVault).to.be.eq(deploymentManager.staking.zrxVault.address);
|
||||
});
|
||||
|
||||
it('should have registered the staking proxy in the zrx vault', async () => {
|
||||
const stakingProxy = await deploymentManager.staking.zrxVault.stakingProxyAddress.callAsync();
|
||||
expect(stakingProxy).to.be.eq(deploymentManager.staking.stakingProxy.address);
|
||||
});
|
||||
|
||||
it('should have correctly set the params', async () => {
|
||||
const params = await deploymentManager.staking.stakingWrapper.getParams.callAsync();
|
||||
expect(params).to.be.deep.eq([
|
||||
stakingConstants.DEFAULT_PARAMS.epochDurationInSeconds,
|
||||
stakingConstants.DEFAULT_PARAMS.rewardDelegatedStakeWeight,
|
||||
stakingConstants.DEFAULT_PARAMS.minimumPoolStake,
|
||||
stakingConstants.DEFAULT_PARAMS.cobbDouglasAlphaNumerator,
|
||||
stakingConstants.DEFAULT_PARAMS.cobbDouglasAlphaDenominator,
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,129 @@
|
||||
import { blockchainTests, constants, expect, filterLogsToArguments, hexRandom } from '@0x/contracts-test-utils';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
||||
|
||||
import { artifacts, TestFrameworkContract, TestFrameworkSomeEventEventArgs, TestFrameworkEvents } from '../../src';
|
||||
import { FunctionAssertion, Result } from '../utils/function_assertions';
|
||||
|
||||
blockchainTests.resets('FunctionAssertion Unit Tests', env => {
|
||||
let exampleContract: TestFrameworkContract;
|
||||
|
||||
function randomBigNumber(): BigNumber {
|
||||
return new BigNumber(hexRandom(constants.WORD_LENGTH));
|
||||
}
|
||||
|
||||
before(async () => {
|
||||
exampleContract = await TestFrameworkContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TestFramework,
|
||||
env.provider,
|
||||
env.txDefaults,
|
||||
artifacts,
|
||||
);
|
||||
});
|
||||
|
||||
describe('runAsync', () => {
|
||||
it('should call the before function with the provided arguments', async () => {
|
||||
let beforeIntrospectionObject = constants.ZERO_AMOUNT;
|
||||
const assertion = new FunctionAssertion(exampleContract.noEffect, {
|
||||
before: async (returnValue: BigNumber) => {
|
||||
beforeIntrospectionObject = returnValue;
|
||||
},
|
||||
after: async (beforeInfo: any, result: Result, returnValue: BigNumber) => {},
|
||||
});
|
||||
|
||||
const randomInput = randomBigNumber();
|
||||
await assertion.runAsync(randomInput);
|
||||
expect(beforeIntrospectionObject).bignumber.to.be.eq(randomInput);
|
||||
});
|
||||
|
||||
it('should call the after function with the provided arguments', async () => {
|
||||
let afterIntrospectionObject = constants.ZERO_AMOUNT;
|
||||
const assertion = new FunctionAssertion(exampleContract.noEffect, {
|
||||
before: async (returnValue: BigNumber) => {},
|
||||
after: async (beforeInfo: any, result: Result, returnValue: BigNumber) => {
|
||||
afterIntrospectionObject = returnValue;
|
||||
},
|
||||
});
|
||||
|
||||
const randomInput = randomBigNumber();
|
||||
await assertion.runAsync(randomInput);
|
||||
expect(afterIntrospectionObject).bignumber.to.be.eq(randomInput);
|
||||
});
|
||||
|
||||
it('should not fail immediately if the wrapped function fails', async () => {
|
||||
await exampleContract.setCounter.awaitTransactionSuccessAsync(new BigNumber(1));
|
||||
const assertion = new FunctionAssertion(exampleContract.revertSideEffect, {
|
||||
before: async (returnValue: BigNumber) => {},
|
||||
after: async (beforeInfo: any, result: Result, returnValue: BigNumber) => {},
|
||||
});
|
||||
const randomInput = randomBigNumber();
|
||||
await assertion.runAsync(randomInput);
|
||||
});
|
||||
|
||||
it('should pass the return value from "before" to "after"', async () => {
|
||||
const randomInput = randomBigNumber();
|
||||
let afterIntrospectionObject = constants.ZERO_AMOUNT;
|
||||
const assertion = new FunctionAssertion(exampleContract.noEffect, {
|
||||
before: async (returnValue: BigNumber) => {
|
||||
return randomInput;
|
||||
},
|
||||
after: async (beforeInfo: any, result: Result, returnValue: BigNumber) => {
|
||||
afterIntrospectionObject = beforeInfo;
|
||||
},
|
||||
});
|
||||
await assertion.runAsync(randomInput);
|
||||
expect(afterIntrospectionObject).bignumber.to.be.eq(randomInput);
|
||||
});
|
||||
|
||||
it('should pass the result from the function call to "after"', async () => {
|
||||
let afterIntrospectionObject = constants.ZERO_AMOUNT;
|
||||
const assertion = new FunctionAssertion(exampleContract.revertSideEffect, {
|
||||
before: async (returnValue: BigNumber) => {},
|
||||
after: async (beforeInfo: any, result: Result, returnValue: BigNumber) => {
|
||||
afterIntrospectionObject = result.data;
|
||||
},
|
||||
});
|
||||
const randomInput = randomBigNumber();
|
||||
await assertion.runAsync(randomInput);
|
||||
expect(afterIntrospectionObject).bignumber.to.be.eq(randomInput);
|
||||
});
|
||||
|
||||
it('should pass the receipt from the function call to "after"', async () => {
|
||||
let afterIntrospectionObject: TransactionReceiptWithDecodedLogs = {} as TransactionReceiptWithDecodedLogs;
|
||||
const assertion = new FunctionAssertion(exampleContract.revertSideEffect, {
|
||||
before: async (returnValue: BigNumber) => {},
|
||||
after: async (beforeInfo: any, result: Result, returnValue: BigNumber) => {
|
||||
if (result.receipt) {
|
||||
afterIntrospectionObject = result.receipt;
|
||||
} else {
|
||||
throw new Error('No receipt received.');
|
||||
}
|
||||
},
|
||||
});
|
||||
const randomInput = randomBigNumber();
|
||||
await assertion.runAsync(randomInput);
|
||||
|
||||
// Ensure that the correct events were emitted.
|
||||
const [event] = filterLogsToArguments<TestFrameworkSomeEventEventArgs>(
|
||||
afterIntrospectionObject.logs,
|
||||
TestFrameworkEvents.SomeEvent,
|
||||
);
|
||||
expect(event).to.be.deep.eq({ someNumber: randomInput });
|
||||
});
|
||||
|
||||
it('should pass the error to "after" if the function call fails', async () => {
|
||||
let afterIntrospectionObject: Error = new Error('');
|
||||
await exampleContract.setCounter.awaitTransactionSuccessAsync(new BigNumber(1));
|
||||
const assertion = new FunctionAssertion(exampleContract.revertSideEffect, {
|
||||
before: async (returnValue: BigNumber) => {},
|
||||
after: async (beforeInfo: any, result: Result, returnValue: BigNumber) => {
|
||||
afterIntrospectionObject = result.data;
|
||||
},
|
||||
});
|
||||
const randomInput = randomBigNumber();
|
||||
await assertion.runAsync(randomInput);
|
||||
const errorMessage = 'VM Exception while processing transaction: revert Revert';
|
||||
expect(afterIntrospectionObject.message).to.be.eq(errorMessage);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -3,14 +3,15 @@ import { BigNumber } from '@0x/utils';
|
||||
import { BlockParam, CallData } from 'ethereum-types';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
|
||||
import { artifacts, GetterCache, TestCacheContract } from '../src';
|
||||
import { artifacts, TestFrameworkContract } from '../../src';
|
||||
import { GetterCache } from '../utils/cache';
|
||||
|
||||
blockchainTests.resets('Cache Tests', env => {
|
||||
let testCacheContract: TestCacheContract;
|
||||
let exampleContract: TestFrameworkContract;
|
||||
|
||||
before(async () => {
|
||||
testCacheContract = await TestCacheContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TestCache,
|
||||
exampleContract = await TestFrameworkContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TestFramework,
|
||||
env.provider,
|
||||
env.txDefaults,
|
||||
artifacts,
|
||||
@@ -22,7 +23,7 @@ blockchainTests.resets('Cache Tests', env => {
|
||||
let cache: GetterCache;
|
||||
|
||||
beforeEach(async () => {
|
||||
cache = new GetterCache(testCacheContract.numberSideEffect);
|
||||
cache = new GetterCache(exampleContract.numberSideEffect);
|
||||
});
|
||||
|
||||
it('should return 0 when "counter" == 0', async () => {
|
||||
@@ -31,7 +32,7 @@ blockchainTests.resets('Cache Tests', env => {
|
||||
|
||||
it('should return 1 when "counter" == 1', async () => {
|
||||
// Update the counter to 1.
|
||||
await testCacheContract.setCounter.awaitTransactionSuccessAsync(new BigNumber(1));
|
||||
await exampleContract.setCounter.awaitTransactionSuccessAsync(new BigNumber(1));
|
||||
|
||||
// Ensure that the returned value is the updated counter.
|
||||
expect(await cache.callAsync()).bignumber.to.be.eq(new BigNumber(1));
|
||||
@@ -42,7 +43,7 @@ blockchainTests.resets('Cache Tests', env => {
|
||||
expect(await cache.callAsync()).bignumber.to.be.eq(constants.ZERO_AMOUNT);
|
||||
|
||||
// Update the counter to 1.
|
||||
await testCacheContract.setCounter.awaitTransactionSuccessAsync(new BigNumber(1));
|
||||
await exampleContract.setCounter.awaitTransactionSuccessAsync(new BigNumber(1));
|
||||
|
||||
// Ensure that the returned value is the cached counter.
|
||||
expect(await cache.callAsync()).bignumber.to.be.eq(constants.ZERO_AMOUNT);
|
||||
@@ -53,7 +54,7 @@ blockchainTests.resets('Cache Tests', env => {
|
||||
let cache: GetterCache;
|
||||
|
||||
beforeEach(async () => {
|
||||
cache = new GetterCache(testCacheContract.equalsSideEffect);
|
||||
cache = new GetterCache(exampleContract.equalsSideEffect);
|
||||
});
|
||||
|
||||
it('should return true when "possiblyZero" == 0 && "counter" == 0', async () => {
|
||||
@@ -62,7 +63,7 @@ blockchainTests.resets('Cache Tests', env => {
|
||||
|
||||
it('should return false when "possiblyZero" == 0 && "counter" != 0', async () => {
|
||||
// Update "counter" to "1", which will cause all calls to return false.
|
||||
await testCacheContract.setCounter.awaitTransactionSuccessAsync(new BigNumber(1));
|
||||
await exampleContract.setCounter.awaitTransactionSuccessAsync(new BigNumber(1));
|
||||
expect(await cache.callAsync(constants.ZERO_AMOUNT)).to.be.false();
|
||||
});
|
||||
|
||||
@@ -71,7 +72,7 @@ blockchainTests.resets('Cache Tests', env => {
|
||||
expect(await cache.callAsync(constants.ZERO_AMOUNT)).to.be.true();
|
||||
|
||||
// Update "counter" to "1", which will cause all calls of "isZeroOrFalse" to return "false".
|
||||
await testCacheContract.setCounter.awaitTransactionSuccessAsync(new BigNumber(1));
|
||||
await exampleContract.setCounter.awaitTransactionSuccessAsync(new BigNumber(1));
|
||||
|
||||
// This should return "true" because a value was cached.
|
||||
expect(await cache.callAsync(constants.ZERO_AMOUNT)).to.be.true();
|
||||
@@ -82,12 +83,12 @@ blockchainTests.resets('Cache Tests', env => {
|
||||
let cache: GetterCache;
|
||||
|
||||
beforeEach(async () => {
|
||||
cache = new GetterCache(testCacheContract.hashSideEffect);
|
||||
cache = new GetterCache(exampleContract.hashSideEffect);
|
||||
});
|
||||
|
||||
it('should return correct hash when counter == 0', async () => {
|
||||
// Get the calldata for the function call, which includes the abi-encoded data to hash.
|
||||
const hashData = testCacheContract.hashSideEffect.getABIEncodedTransactionData(
|
||||
const hashData = exampleContract.hashSideEffect.getABIEncodedTransactionData(
|
||||
new BigNumber(1),
|
||||
ethUtil.bufferToHex(ethUtil.sha3(0)),
|
||||
);
|
||||
@@ -100,7 +101,7 @@ blockchainTests.resets('Cache Tests', env => {
|
||||
|
||||
it('should return the null hash when counter != 0', async () => {
|
||||
// Update "counter" to "1", which will cause all calls to return the null hash.
|
||||
await testCacheContract.setCounter.awaitTransactionSuccessAsync(new BigNumber(1));
|
||||
await exampleContract.setCounter.awaitTransactionSuccessAsync(new BigNumber(1));
|
||||
|
||||
// Ensure that the cache returns the correct value.
|
||||
expect(await cache.callAsync(new BigNumber(1), ethUtil.bufferToHex(ethUtil.sha3(0)))).to.be.eq(
|
||||
@@ -110,7 +111,7 @@ blockchainTests.resets('Cache Tests', env => {
|
||||
|
||||
it('should return the cached hash', async () => {
|
||||
// Get the calldata for the function call, which includes the abi-encoded data to hash.
|
||||
const hashData = testCacheContract.hashSideEffect.getABIEncodedTransactionData(
|
||||
const hashData = exampleContract.hashSideEffect.getABIEncodedTransactionData(
|
||||
new BigNumber(1),
|
||||
ethUtil.bufferToHex(ethUtil.sha3(0)),
|
||||
);
|
||||
@@ -121,7 +122,7 @@ blockchainTests.resets('Cache Tests', env => {
|
||||
);
|
||||
|
||||
// Update "counter" to "1", which will cause all calls to return the null hash.
|
||||
await testCacheContract.setCounter.awaitTransactionSuccessAsync(new BigNumber(1));
|
||||
await exampleContract.setCounter.awaitTransactionSuccessAsync(new BigNumber(1));
|
||||
|
||||
// Ensure that the cache returns the correct value.
|
||||
expect(await cache.callAsync(new BigNumber(1), ethUtil.bufferToHex(ethUtil.sha3(0)))).to.be.eq(
|
||||
@@ -136,7 +137,7 @@ blockchainTests.resets('Cache Tests', env => {
|
||||
let cache: GetterCache;
|
||||
|
||||
beforeEach(async () => {
|
||||
cache = new GetterCache(testCacheContract.equalsSideEffect);
|
||||
cache = new GetterCache(exampleContract.equalsSideEffect);
|
||||
});
|
||||
|
||||
it('should return false when the cache was flushed && "possiblyZero" == 0 && "counter" != 0', async () => {
|
||||
@@ -144,7 +145,7 @@ blockchainTests.resets('Cache Tests', env => {
|
||||
expect(await cache.callAsync(constants.ZERO_AMOUNT)).to.be.true();
|
||||
|
||||
// Update "counter" to "1", which will cause all calls of "isZeroOrFalse" to return "false".
|
||||
await testCacheContract.setCounter.awaitTransactionSuccessAsync(new BigNumber(1));
|
||||
await exampleContract.setCounter.awaitTransactionSuccessAsync(new BigNumber(1));
|
||||
|
||||
// Flush the entire cache.
|
||||
cache.flush();
|
||||
@@ -5,7 +5,8 @@ import { IStakingEventsEvents, IStakingEventsStakingPoolActivatedEventArgs } fro
|
||||
import { assetDataUtils, orderHashUtils } from '@0x/order-utils';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
|
||||
import { DeploymentManager, AddressManager } from '../../src';
|
||||
import { AddressManager } from '../utils/address_manager';
|
||||
import { DeploymentManager } from '../utils/deployment_manager';
|
||||
|
||||
blockchainTests('Exchange & Staking', env => {
|
||||
let accounts: string[];
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ContractGetterFunction } from './';
|
||||
import { ContractGetterFunction } from './function_assertions';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
export interface Cache {
|
||||
@@ -2,7 +2,11 @@ import { Authorizable, Ownable } from '@0x/contracts-exchange';
|
||||
import { constants as stakingConstants } from '@0x/contracts-staking';
|
||||
import { blockchainTests, expect } from '@0x/contracts-test-utils';
|
||||
|
||||
<<<<<<< HEAD:contracts/integrations/test/utils/deployment_manager_test.ts
|
||||
import { DeploymentManager } from './deployment_mananger';
|
||||
=======
|
||||
import { DeploymentManager } from '../utils/deployment_manager';
|
||||
>>>>>>> `@0x:contracts-integrations` Added unit tests for FunctionAssertion:contracts/integrations/test/framework-unit-tests/deployment_manager_test.ts
|
||||
|
||||
blockchainTests('Deployment Manager', env => {
|
||||
let owner: string;
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
"extends": "../../tsconfig",
|
||||
"compilerOptions": { "outDir": "lib", "rootDir": ".", "resolveJsonModule": true },
|
||||
"include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"],
|
||||
"files": ["generated-artifacts/TestCache.json", "generated-artifacts/TestStakingPlaceholder.json"]
|
||||
"files": ["generated-artifacts/TestFramework.json"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user