@0x/contracts-exchange-libs: Move in revamped LibFillResults tests from @0x/contracts-exchange.

This commit is contained in:
Lawrence Forman
2019-08-01 15:48:44 -04:00
parent 8c05a92a1e
commit 884b1add8e
3 changed files with 72 additions and 4 deletions

View File

@@ -59,7 +59,11 @@
"pr": "TODO"
},
{
"note": "Bring in revamped `LibMath` tests from the `contracts-exchange` package.",
"note": "Move in revamped `LibMath` tests from the `contracts-exchange` package.",
"pr": "TODO"
},
{
"note": "Move in revamped `LibFillResults` tests from the `contracts-exchange` package.",
"pr": "TODO"
},
{

View File

@@ -0,0 +1,66 @@
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 {
// 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),
);
}
describe.optional('combinatorial tests', () => {
testCombinatoriallyWithReferenceFunc(
'addFillResults',
referenceAddFillResultsAsync,
testAddFillResultsAsync,
[uint256Values, uint256Values],
);
});
});
});

View File

@@ -5,13 +5,11 @@ import {
uint256Values,
} from '@0x/contracts-test-utils';
import { BigNumber } from '@0x/utils';
import * as _ from 'lodash';
import { artifacts, ReferenceFunctions, TestLibsContract } from '../src';
const CHAIN_ID = 1337;
blockchainTests('LibMath', env => {
const CHAIN_ID = 1337;
let libsContract: TestLibsContract;
before(async () => {