diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-07-23 12:16:35 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-07-23 23:02:51 +0800 |
commit | e5e68de2d7bf8bfc319200b8dc9f27cf8a081b4a (patch) | |
tree | 2f658bbb54abfa22e1d32fe7ffabeab2b5c577fe | |
parent | dcc0908617b83de8f45af3e9ca6854b897be3d72 (diff) | |
download | dexon-sol-tools-e5e68de2d7bf8bfc319200b8dc9f27cf8a081b4a.tar.gz dexon-sol-tools-e5e68de2d7bf8bfc319200b8dc9f27cf8a081b4a.tar.zst dexon-sol-tools-e5e68de2d7bf8bfc319200b8dc9f27cf8a081b4a.zip |
Use != instead of > in loops, add sanity checks to market fill functions
3 files changed, 19 insertions, 19 deletions
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinExchangeWrapper.sol b/packages/contracts/src/2.0.0/forwarder/MixinExchangeWrapper.sol index e230767b7..e150791da 100644 --- a/packages/contracts/src/2.0.0/forwarder/MixinExchangeWrapper.sol +++ b/packages/contracts/src/2.0.0/forwarder/MixinExchangeWrapper.sol @@ -104,7 +104,7 @@ contract MixinExchangeWrapper is bytes memory wethAssetData = WETH_ASSET_DATA; uint256 ordersLength = orders.length; - for (uint256 i = 0; i < ordersLength; i++) { + for (uint256 i = 0; i != ordersLength; i++) { // We assume that asset being bought by taker is the same for each order. // We assume that asset being sold by taker is WETH for each order. @@ -125,7 +125,7 @@ contract MixinExchangeWrapper is addFillResults(totalFillResults, singleFillResults); // Stop execution if the entire amount of takerAsset has been sold - if (totalFillResults.takerAssetFilledAmount == wethSellAmount) { + if (totalFillResults.takerAssetFilledAmount >= wethSellAmount) { break; } } @@ -151,7 +151,7 @@ contract MixinExchangeWrapper is bytes memory wethAssetData = WETH_ASSET_DATA; uint256 ordersLength = orders.length; - for (uint256 i = 0; i < ordersLength; i++) { + for (uint256 i = 0; i != ordersLength; i++) { // We assume that asset being bought by taker is the same for each order. // We assume that asset being sold by taker is WETH for each order. @@ -180,7 +180,7 @@ contract MixinExchangeWrapper is addFillResults(totalFillResults, singleFillResults); // Stop execution if the entire amount of makerAsset has been bought - if (totalFillResults.makerAssetFilledAmount == makerAssetFillAmount) { + if (totalFillResults.makerAssetFilledAmount >= makerAssetFillAmount) { break; } } @@ -214,7 +214,7 @@ contract MixinExchangeWrapper is uint256 zrxPurchased = 0; uint256 ordersLength = orders.length; - for (uint256 i = 0; i < ordersLength; i++) { + for (uint256 i = 0; i != ordersLength; i++) { // All of these are ZRX/WETH, so we can drop the respective assetData from calldata. orders[i].makerAssetData = zrxAssetData; diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol index a0882b108..86194f461 100644 --- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol +++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol @@ -120,7 +120,7 @@ contract MixinWrapperFunctions is returns (FillResults memory totalFillResults) { uint256 ordersLength = orders.length; - for (uint256 i = 0; i < ordersLength; i++) { + for (uint256 i = 0; i != ordersLength; i++) { FillResults memory singleFillResults = fillOrder( orders[i], takerAssetFillAmounts[i], @@ -146,7 +146,7 @@ contract MixinWrapperFunctions is returns (FillResults memory totalFillResults) { uint256 ordersLength = orders.length; - for (uint256 i = 0; i < ordersLength; i++) { + for (uint256 i = 0; i != ordersLength; i++) { FillResults memory singleFillResults = fillOrKillOrder( orders[i], takerAssetFillAmounts[i], @@ -173,7 +173,7 @@ contract MixinWrapperFunctions is returns (FillResults memory totalFillResults) { uint256 ordersLength = orders.length; - for (uint256 i = 0; i < ordersLength; i++) { + for (uint256 i = 0; i != ordersLength; i++) { FillResults memory singleFillResults = fillOrderNoThrow( orders[i], takerAssetFillAmounts[i], @@ -200,7 +200,7 @@ contract MixinWrapperFunctions is bytes memory takerAssetData = orders[0].takerAssetData; uint256 ordersLength = orders.length; - for (uint256 i = 0; i < ordersLength; i++) { + for (uint256 i = 0; i != ordersLength; i++) { // We assume that asset being sold by taker is the same for each order. // Rather than passing this in as calldata, we use the takerAssetData from the first order in all later orders. @@ -220,7 +220,7 @@ contract MixinWrapperFunctions is addFillResults(totalFillResults, singleFillResults); // Stop execution if the entire amount of takerAsset has been sold - if (totalFillResults.takerAssetFilledAmount == takerAssetFillAmount) { + if (totalFillResults.takerAssetFilledAmount >= takerAssetFillAmount) { break; } } @@ -244,7 +244,7 @@ contract MixinWrapperFunctions is bytes memory takerAssetData = orders[0].takerAssetData; uint256 ordersLength = orders.length; - for (uint256 i = 0; i < ordersLength; i++) { + for (uint256 i = 0; i != ordersLength; i++) { // We assume that asset being sold by taker is the same for each order. // Rather than passing this in as calldata, we use the takerAssetData from the first order in all later orders. @@ -264,7 +264,7 @@ contract MixinWrapperFunctions is addFillResults(totalFillResults, singleFillResults); // Stop execution if the entire amount of takerAsset has been sold - if (totalFillResults.takerAssetFilledAmount == takerAssetFillAmount) { + if (totalFillResults.takerAssetFilledAmount >= takerAssetFillAmount) { break; } } @@ -287,7 +287,7 @@ contract MixinWrapperFunctions is bytes memory makerAssetData = orders[0].makerAssetData; uint256 ordersLength = orders.length; - for (uint256 i = 0; i < ordersLength; i++) { + for (uint256 i = 0; i != ordersLength; i++) { // We assume that asset being bought by taker is the same for each order. // Rather than passing this in as calldata, we copy the makerAssetData from the first order onto all later orders. @@ -315,7 +315,7 @@ contract MixinWrapperFunctions is addFillResults(totalFillResults, singleFillResults); // Stop execution if the entire amount of makerAsset has been bought - if (totalFillResults.makerAssetFilledAmount == makerAssetFillAmount) { + if (totalFillResults.makerAssetFilledAmount >= makerAssetFillAmount) { break; } } @@ -339,7 +339,7 @@ contract MixinWrapperFunctions is bytes memory makerAssetData = orders[0].makerAssetData; uint256 ordersLength = orders.length; - for (uint256 i = 0; i < ordersLength; i++) { + for (uint256 i = 0; i != ordersLength; i++) { // We assume that asset being bought by taker is the same for each order. // Rather than passing this in as calldata, we copy the makerAssetData from the first order onto all later orders. @@ -367,7 +367,7 @@ contract MixinWrapperFunctions is addFillResults(totalFillResults, singleFillResults); // Stop execution if the entire amount of makerAsset has been bought - if (totalFillResults.makerAssetFilledAmount == makerAssetFillAmount) { + if (totalFillResults.makerAssetFilledAmount >= makerAssetFillAmount) { break; } } @@ -380,7 +380,7 @@ contract MixinWrapperFunctions is public { uint256 ordersLength = orders.length; - for (uint256 i = 0; i < ordersLength; i++) { + for (uint256 i = 0; i != ordersLength; i++) { cancelOrder(orders[i]); } } @@ -395,7 +395,7 @@ contract MixinWrapperFunctions is { uint256 ordersLength = orders.length; LibOrder.OrderInfo[] memory ordersInfo = new LibOrder.OrderInfo[](ordersLength); - for (uint256 i = 0; i < ordersLength; i++) { + for (uint256 i = 0; i != ordersLength; i++) { ordersInfo[i] = getOrderInfo(orders[i]); } return ordersInfo; diff --git a/packages/contracts/test/forwarder/forwarder.ts b/packages/contracts/test/forwarder/forwarder.ts index b6d81df58..19639d3aa 100644 --- a/packages/contracts/test/forwarder/forwarder.ts +++ b/packages/contracts/test/forwarder/forwarder.ts @@ -29,7 +29,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); const DECIMALS_DEFAULT = 18; const MAX_WETH_FILL_PERCENTAGE = 95; -describe.only(ContractName.Forwarder, () => { +describe(ContractName.Forwarder, () => { let makerAddress: string; let owner: string; let takerAddress: string; |