Move MatchedFillResults constants closer to tests where they are utilized

This commit is contained in:
Amir Bandeali 2019-08-15 16:51:40 -07:00
parent 7ac30c5153
commit cc3be9448a

View File

@ -40,50 +40,11 @@ blockchainTests('LibFillResults', env => {
feeRecipientAddress: constants.NULL_ADDRESS, feeRecipientAddress: constants.NULL_ADDRESS,
expirationTimeSeconds: constants.ZERO_AMOUNT, expirationTimeSeconds: constants.ZERO_AMOUNT,
}; };
const EMPTY_FILL_RESULTS: FillResults = {
makerAssetFilledAmount: constants.ZERO_AMOUNT,
takerAssetFilledAmount: constants.ZERO_AMOUNT,
makerFeePaid: constants.ZERO_AMOUNT,
takerFeePaid: constants.ZERO_AMOUNT,
};
const EMPTY_MATCHED_FILL_RESULTS: MatchedFillResults = {
left: EMPTY_FILL_RESULTS,
right: EMPTY_FILL_RESULTS,
profitInLeftMakerAsset: constants.ZERO_AMOUNT,
profitInRightMakerAsset: constants.ZERO_AMOUNT,
};
const COMMON_MATCHED_FILL_RESULTS = {
left: {
makerAssetFilledAmount: Web3Wrapper.toBaseUnitAmount(5, 18),
takerAssetFilledAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
makerFeePaid: Web3Wrapper.toBaseUnitAmount(100, 16),
takerFeePaid: Web3Wrapper.toBaseUnitAmount(100, 16),
},
right: {
makerAssetFilledAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
takerAssetFilledAmount: Web3Wrapper.toBaseUnitAmount(2, 18),
makerFeePaid: Web3Wrapper.toBaseUnitAmount(100, 16),
takerFeePaid: Web3Wrapper.toBaseUnitAmount(100, 16),
},
profitInLeftMakerAsset: Web3Wrapper.toBaseUnitAmount(3, 18),
profitInRightMakerAsset: constants.ZERO_AMOUNT,
};
const randomAddress = () => hexRandom(constants.ADDRESS_LENGTH); const randomAddress = () => hexRandom(constants.ADDRESS_LENGTH);
const randomAssetData = () => hexRandom(36); const randomAssetData = () => hexRandom(36);
const randomUint256 = () => new BigNumber(hexRandom(constants.WORD_LENGTH)); const randomUint256 = () => new BigNumber(hexRandom(constants.WORD_LENGTH));
function createMatchedFillResults(partialMatchedFillResults: PartialMatchedFillResults): MatchedFillResults {
const matchedFillResults = EMPTY_MATCHED_FILL_RESULTS;
matchedFillResults.left = _.assign({}, EMPTY_FILL_RESULTS, partialMatchedFillResults.left);
matchedFillResults.right = _.assign({}, EMPTY_FILL_RESULTS, partialMatchedFillResults.right);
matchedFillResults.profitInLeftMakerAsset =
partialMatchedFillResults.profitInLeftMakerAsset || constants.ZERO_AMOUNT;
matchedFillResults.profitInRightMakerAsset =
partialMatchedFillResults.profitInRightMakerAsset || constants.ZERO_AMOUNT;
return matchedFillResults;
}
let libsContract: TestLibFillResultsContract; let libsContract: TestLibFillResultsContract;
let makerAddressLeft: string; let makerAddressLeft: string;
let makerAddressRight: string; let makerAddressRight: string;
@ -384,6 +345,48 @@ blockchainTests('LibFillResults', env => {
}); });
}); });
const EMPTY_FILL_RESULTS: FillResults = {
makerAssetFilledAmount: constants.ZERO_AMOUNT,
takerAssetFilledAmount: constants.ZERO_AMOUNT,
makerFeePaid: constants.ZERO_AMOUNT,
takerFeePaid: constants.ZERO_AMOUNT,
};
const EMPTY_MATCHED_FILL_RESULTS: MatchedFillResults = {
left: EMPTY_FILL_RESULTS,
right: EMPTY_FILL_RESULTS,
profitInLeftMakerAsset: constants.ZERO_AMOUNT,
profitInRightMakerAsset: constants.ZERO_AMOUNT,
};
const COMMON_MATCHED_FILL_RESULTS = {
left: {
makerAssetFilledAmount: Web3Wrapper.toBaseUnitAmount(5, 18),
takerAssetFilledAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
makerFeePaid: Web3Wrapper.toBaseUnitAmount(100, 16),
takerFeePaid: Web3Wrapper.toBaseUnitAmount(100, 16),
},
right: {
makerAssetFilledAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
takerAssetFilledAmount: Web3Wrapper.toBaseUnitAmount(2, 18),
makerFeePaid: Web3Wrapper.toBaseUnitAmount(100, 16),
takerFeePaid: Web3Wrapper.toBaseUnitAmount(100, 16),
},
profitInLeftMakerAsset: Web3Wrapper.toBaseUnitAmount(3, 18),
profitInRightMakerAsset: constants.ZERO_AMOUNT,
};
function createMatchedFillResults(partialMatchedFillResults: PartialMatchedFillResults): MatchedFillResults {
const matchedFillResults = EMPTY_MATCHED_FILL_RESULTS;
matchedFillResults.left = _.assign({}, EMPTY_FILL_RESULTS, partialMatchedFillResults.left);
matchedFillResults.right = _.assign({}, EMPTY_FILL_RESULTS, partialMatchedFillResults.right);
matchedFillResults.profitInLeftMakerAsset =
partialMatchedFillResults.profitInLeftMakerAsset || constants.ZERO_AMOUNT;
matchedFillResults.profitInRightMakerAsset =
partialMatchedFillResults.profitInRightMakerAsset || constants.ZERO_AMOUNT;
return matchedFillResults;
}
blockchainTests('calculateMatchedFillResults', async () => { blockchainTests('calculateMatchedFillResults', async () => {
/** /**
* Asserts that the results of calling `calculateMatchedFillResults()` is consistent with the results that are expected. * Asserts that the results of calling `calculateMatchedFillResults()` is consistent with the results that are expected.