`@0x/contracts-utils`: Correct internal variable naming in `src/index.ts`. `@0x/contracts-exchange`: Remove functions from `TestExchangeInternals.sol` that are now in other packages. `@0x/contracts-exchange`: Remove `TestExchangeMath.sol`. Exchange math functions are now tested in `@0x/contracts-exchange-libs`. `@0x/contracts-exchange`: Move `ReferenceFunctions` to default package export. `@0x/contracts-exchange`: Update `match_order.ts` tests to use reference math functions instead of `TestExchangeMath`. `@0x/contracts-exchange`: Remove `_updateFilledState()` combinatorial tests in favor of normal unit testing. Combinatorial testing was overkill. `@0x/contracts-exchange`: Update/refactor `calculateFillResults()` combinatorial tests to use the reference functions and hide them behind `TEST_ALL`.
70 lines
2.2 KiB
TypeScript
70 lines
2.2 KiB
TypeScript
import {
|
|
blockchainTests,
|
|
describe,
|
|
testCombinatoriallyWithReferenceFunc,
|
|
uint256Values,
|
|
} from '@0x/contracts-test-utils';
|
|
import { FillResults } from '@0x/types';
|
|
import { BigNumber } from '@0x/utils';
|
|
|
|
import { artifacts, ReferenceFunctions, TestLibsContract } from '../src';
|
|
|
|
blockchainTests('LibFillResults', env => {
|
|
const CHAIN_ID = 1337;
|
|
let libsContract: TestLibsContract;
|
|
|
|
before(async () => {
|
|
libsContract = await TestLibsContract.deployFrom0xArtifactAsync(
|
|
artifacts.TestLibs,
|
|
env.provider,
|
|
env.txDefaults,
|
|
new BigNumber(CHAIN_ID),
|
|
);
|
|
});
|
|
|
|
describe('addFillResults', () => {
|
|
function makeFillResults(value: BigNumber): FillResults {
|
|
// HACK(dorothy-zbornak): We reuse values across fields,
|
|
// but this is fine because `addFillResults()` never does
|
|
// any math between them.
|
|
return {
|
|
makerAssetFilledAmount: value,
|
|
takerAssetFilledAmount: value,
|
|
makerFeePaid: value,
|
|
takerFeePaid: value,
|
|
};
|
|
}
|
|
|
|
async function referenceAddFillResultsAsync(
|
|
totalValue: BigNumber,
|
|
singleValue: BigNumber,
|
|
): Promise<FillResults> {
|
|
return ReferenceFunctions.addFillResults(
|
|
makeFillResults(totalValue),
|
|
makeFillResults(singleValue),
|
|
);
|
|
}
|
|
|
|
async function testAddFillResultsAsync(
|
|
totalValue: BigNumber,
|
|
singleValue: BigNumber,
|
|
): Promise<FillResults> {
|
|
return libsContract.addFillResults.callAsync(
|
|
makeFillResults(totalValue),
|
|
makeFillResults(singleValue),
|
|
);
|
|
}
|
|
|
|
// TODO(dorothy-zbornak): Do we really need these?
|
|
// Just a couple edge cases would likely suffice.
|
|
describe.optional('combinatorial tests', () => {
|
|
testCombinatoriallyWithReferenceFunc(
|
|
'addFillResults',
|
|
referenceAddFillResultsAsync,
|
|
testAddFillResultsAsync,
|
|
[uint256Values, uint256Values],
|
|
);
|
|
});
|
|
});
|
|
});
|