From 4f040521e0c1a5910f2ec13b4a734c7c271d7614 Mon Sep 17 00:00:00 2001 From: Pranav Kalvapalle Date: Sat, 13 Jan 2018 22:46:54 -0800 Subject: [PATCH 1/4] modify function name, comment change --- contracts/LoopringProtocolImpl.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/LoopringProtocolImpl.sol b/contracts/LoopringProtocolImpl.sol index 3a1662a7..5a73b458 100644 --- a/contracts/LoopringProtocolImpl.sol +++ b/contracts/LoopringProtocolImpl.sol @@ -365,7 +365,7 @@ contract LoopringProtocolImpl is LoopringProtocol { id = keccak256(token1) ^ keccak256(token2); } - /// @dev Set a cutoff timestamp to invalidate all orders whose timestamp + /// @dev Set a cutoff timestamp to invalidate particular trading pairs whose timestamp /// is smaller than or equal to the new value of the address's cutoff /// timestamp. /// @param cutoff The cutoff timestamp, will default to `block.timestamp` @@ -392,7 +392,7 @@ contract LoopringProtocolImpl is LoopringProtocol { /// timestamp. /// @param cutoff The cutoff timestamp, will default to `block.timestamp` /// if it is 0. - function setCutoff(uint cutoff) + function cancelAllOrders(uint cutoff) external { From 128622c21b684cbf608c81df1a54097fcba8274b Mon Sep 17 00:00:00 2001 From: Pranav Kalvapalle Date: Sat, 13 Jan 2018 23:08:29 -0800 Subject: [PATCH 2/4] modify setCutoff to cancelAllOrders, fix minor syntax error in Claimable --- contracts/LoopringProtocol.sol | 2 +- contracts/LoopringProtocolImpl.abi | 2 +- contracts/lib/Claimable.sol | 2 +- test/testLoopringProtocolImpl.ts | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/contracts/LoopringProtocol.sol b/contracts/LoopringProtocol.sol index acf6f97e..c5e2d2c6 100644 --- a/contracts/LoopringProtocol.sol +++ b/contracts/LoopringProtocol.sol @@ -138,5 +138,5 @@ contract LoopringProtocol { /// timestamp. /// @param cutoff The cutoff timestamp, will default to `block.timestamp` /// if it is 0. - function setCutoff(uint cutoff) external; + function cancelAllOrders(uint cutoff) external; } diff --git a/contracts/LoopringProtocolImpl.abi b/contracts/LoopringProtocolImpl.abi index e1475138..09b78c79 100644 --- a/contracts/LoopringProtocolImpl.abi +++ b/contracts/LoopringProtocolImpl.abi @@ -1 +1 @@ -[{"constant":true,"inputs":[],"name":"ENTERED_MASK","outputs":[{"name":"","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"FEE_SELECT_MAX_VALUE","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"MARGIN_SPLIT_PERCENTAGE_BASE","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ringIndex","outputs":[{"name":"","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"addresses","type":"address[3]"},{"name":"orderValues","type":"uint256[7]"},{"name":"buyNoMoreThanAmountB","type":"bool"},{"name":"marginSplitPercentage","type":"uint8"},{"name":"v","type":"uint8"},{"name":"r","type":"bytes32"},{"name":"s","type":"bytes32"}],"name":"cancelOrder","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"RATE_RATIO_SCALE","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"lrcTokenAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"cancelledOrFilled","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tokenRegistryAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"delegateAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"addressList","type":"address[2][]"},{"name":"uintArgsList","type":"uint256[7][]"},{"name":"uint8ArgsList","type":"uint8[2][]"},{"name":"buyNoMoreThanAmountBList","type":"bool[]"},{"name":"vList","type":"uint8[]"},{"name":"rList","type":"bytes32[]"},{"name":"sList","type":"bytes32[]"},{"name":"ringminer","type":"address"},{"name":"feeRecipient","type":"address"}],"name":"submitRing","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"maxRingSize","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ringhashRegistryAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"cutoff","type":"uint256"}],"name":"setCutoff","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"FEE_SELECT_LRC","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"cutoffs","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"rateRatioCVSThreshold","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"FEE_SELECT_MARGIN_SPLIT","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_lrcTokenAddress","type":"address"},{"name":"_tokenRegistryAddress","type":"address"},{"name":"_ringhashRegistryAddress","type":"address"},{"name":"_delegateAddress","type":"address"},{"name":"_maxRingSize","type":"uint256"},{"name":"_rateRatioCVSThreshold","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_ringIndex","type":"uint256"},{"indexed":true,"name":"_ringhash","type":"bytes32"},{"indexed":false,"name":"_miner","type":"address"},{"indexed":false,"name":"_feeRecipient","type":"address"},{"indexed":false,"name":"_isRinghashReserved","type":"bool"},{"indexed":false,"name":"_orderHashList","type":"bytes32[]"},{"indexed":false,"name":"_amountsList","type":"uint256[6][]"}],"name":"RingMined","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_orderHash","type":"bytes32"},{"indexed":false,"name":"_amountCancelled","type":"uint256"}],"name":"OrderCancelled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_address","type":"address"},{"indexed":false,"name":"_cutoff","type":"uint256"}],"name":"CutoffTimestampChanged","type":"event"}] \ No newline at end of file +[{"constant":true,"inputs":[],"name":"ENTERED_MASK","outputs":[{"name":"","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"FEE_SELECT_MAX_VALUE","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"MARGIN_SPLIT_PERCENTAGE_BASE","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ringIndex","outputs":[{"name":"","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"addresses","type":"address[3]"},{"name":"orderValues","type":"uint256[7]"},{"name":"buyNoMoreThanAmountB","type":"bool"},{"name":"marginSplitPercentage","type":"uint8"},{"name":"v","type":"uint8"},{"name":"r","type":"bytes32"},{"name":"s","type":"bytes32"}],"name":"cancelOrder","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"RATE_RATIO_SCALE","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"lrcTokenAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"cancelledOrFilled","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tokenRegistryAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"delegateAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"addressList","type":"address[2][]"},{"name":"uintArgsList","type":"uint256[7][]"},{"name":"uint8ArgsList","type":"uint8[2][]"},{"name":"buyNoMoreThanAmountBList","type":"bool[]"},{"name":"vList","type":"uint8[]"},{"name":"rList","type":"bytes32[]"},{"name":"sList","type":"bytes32[]"},{"name":"ringminer","type":"address"},{"name":"feeRecipient","type":"address"}],"name":"submitRing","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"maxRingSize","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ringhashRegistryAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"cutoff","type":"uint256"}],"name":"cancelAllOrders","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"FEE_SELECT_LRC","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"cutoffs","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"rateRatioCVSThreshold","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"FEE_SELECT_MARGIN_SPLIT","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_lrcTokenAddress","type":"address"},{"name":"_tokenRegistryAddress","type":"address"},{"name":"_ringhashRegistryAddress","type":"address"},{"name":"_delegateAddress","type":"address"},{"name":"_maxRingSize","type":"uint256"},{"name":"_rateRatioCVSThreshold","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_ringIndex","type":"uint256"},{"indexed":true,"name":"_ringhash","type":"bytes32"},{"indexed":false,"name":"_miner","type":"address"},{"indexed":false,"name":"_feeRecipient","type":"address"},{"indexed":false,"name":"_isRinghashReserved","type":"bool"},{"indexed":false,"name":"_orderHashList","type":"bytes32[]"},{"indexed":false,"name":"_amountsList","type":"uint256[6][]"}],"name":"RingMined","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_orderHash","type":"bytes32"},{"indexed":false,"name":"_amountCancelled","type":"uint256"}],"name":"OrderCancelled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_address","type":"address"},{"indexed":false,"name":"_cutoff","type":"uint256"}],"name":"CutoffTimestampChanged","type":"event"}] \ No newline at end of file diff --git a/contracts/lib/Claimable.sol b/contracts/lib/Claimable.sol index cc73f287..21b47609 100644 --- a/contracts/lib/Claimable.sol +++ b/contracts/lib/Claimable.sol @@ -17,7 +17,7 @@ */ pragma solidity 0.4.18; -import './Ownable.sol'; +import "./Ownable.sol"; /// @title Claimable diff --git a/test/testLoopringProtocolImpl.ts b/test/testLoopringProtocolImpl.ts index f8362db2..a8d45e39 100644 --- a/test/testLoopringProtocolImpl.ts +++ b/test/testLoopringProtocolImpl.ts @@ -727,7 +727,7 @@ contract("LoopringProtocolImpl", (accounts: string[]) => { await clear([eos, neo, lrc], [order1Owner, order2Owner, order3Owner, feeRecepient]); }); - it("should not fill orders which are cancelled by setCutoff.", async () => { + it("should not fill orders which are cancelled by cancelAllOrders.", async () => { const ring = await ringFactory.generateSize3Ring03(order1Owner, order2Owner, order3Owner, ringOwner, 500); const feeSelectionList = [1, 1, 1]; const availableAmountSList = [1000e18, 2006e18, 20e18]; @@ -740,7 +740,7 @@ contract("LoopringProtocolImpl", (accounts: string[]) => { await lrc.setBalance(feeRecepient, spendableLrcFeeList[3], {from: owner}); const p = ringFactory.ringToSubmitableParams(ring, feeSelectionList, feeRecepient); - await loopringProtocolImpl.setCutoff(new BigNumber(currBlockTimeStamp), {from: order1Owner}); + await loopringProtocolImpl.cancelAllOrders(new BigNumber(currBlockTimeStamp), {from: order1Owner}); try { await loopringProtocolImpl.submitRing(p.addressList, p.uintArgsList, @@ -823,9 +823,9 @@ contract("LoopringProtocolImpl", (accounts: string[]) => { }); }); - describe("setCutoff", () => { + describe("cancelAllOrders", () => { it("should be able to set cutoff timestamp for msg sender", async () => { - await loopringProtocolImpl.setCutoff(new BigNumber(1508566125), {from: order2Owner}); + await loopringProtocolImpl.cancelAllOrders(new BigNumber(1508566125), {from: order2Owner}); const cutoff = await loopringProtocolImpl.cutoffs(order2Owner); assert.equal(cutoff.toNumber(), 1508566125, "cutoff not set correctly"); }); From 7d3433e5e7cfd9ac60d976c0ce3858fbeb1e52d0 Mon Sep 17 00:00:00 2001 From: Pranav Kalvapalle Date: Sun, 14 Jan 2018 02:56:16 -0800 Subject: [PATCH 3/4] add tests, add helper keccack_256 function --- package.json | 1 + test/testLoopringProtocolImpl.ts | 146 +++++++++++++++++++++++++++++++ util/order.ts | 7 ++ 3 files changed, 154 insertions(+) diff --git a/package.json b/package.json index a2f31312..8e744d58 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ }, "dependencies": { "bignumber.js": "^4.1.0", + "bitwise-xor": "0.0.0", "bluebird": "^3.5.0", "bn.js": "^4.11.8", "es6-promisify": "^5.0.0", diff --git a/test/testLoopringProtocolImpl.ts b/test/testLoopringProtocolImpl.ts index a8d45e39..eb77b2d9 100644 --- a/test/testLoopringProtocolImpl.ts +++ b/test/testLoopringProtocolImpl.ts @@ -761,6 +761,152 @@ contract("LoopringProtocolImpl", (accounts: string[]) => { await clear([eos, neo, lrc], [order1Owner, order2Owner, order3Owner, feeRecepient]); }); + it("should set cutoff time to current blockstamp time if set to zero in setTradingPairCutoff.", async () => { + const ring = await ringFactory.generateSize3Ring03(order1Owner, order2Owner, order3Owner, ringOwner, 500); + const feeSelectionList = [1, 1, 1]; + const availableAmountSList = [1000e18, 2006e18, 20e18]; + const spendableLrcFeeList = [0, 6e18, 1e18, 0]; + + await eos.setBalance(order1Owner, availableAmountSList[0], {from: owner}); + await lrc.setBalance(order2Owner, availableAmountSList[1], {from: owner}); + await neo.setBalance(order3Owner, availableAmountSList[2], {from: owner}); + await lrc.setBalance(order3Owner, spendableLrcFeeList[2], {from: owner}); + await lrc.setBalance(feeRecepient, spendableLrcFeeList[3], {from: owner}); + + const p = ringFactory.ringToSubmitableParams(ring, feeSelectionList, feeRecepient); + await loopringProtocolImpl.setTradingPairCutoff( + lrcAddress, + eosAddress, + new BigNumber(0), + ); + try { + await loopringProtocolImpl.submitRing(p.addressList, + p.uintArgsList, + p.uint8ArgsList, + p.buyNoMoreThanAmountBList, + p.vList, + p.rList, + p.sList, + p.ringOwner, + p.feeRecepient, + {from: owner}); + } catch (err) { + const errMsg = `${err}`; + assert(_.includes(errMsg, "Error: VM Exception while processing transaction: revert"), + `Expected contract to throw, got: ${err}`); + } + + await clear([eos, neo, lrc], [order1Owner, order2Owner, order3Owner, feeRecepient]); + }); + + it("should not fail if cutoff time for setTradingPairCutoff is set after current blockstamp time.", async () => { + const ring = await ringFactory.generateSize3Ring03(order1Owner, order2Owner, order3Owner, ringOwner, 500); + const feeSelectionList = [1, 1, 1]; + const availableAmountSList = [1000e18, 2006e18, 20e18]; + const spendableLrcFeeList = [0, 6e18, 1e18, 0]; + + await eos.setBalance(order1Owner, availableAmountSList[0], {from: owner}); + await lrc.setBalance(order2Owner, availableAmountSList[1], {from: owner}); + await neo.setBalance(order3Owner, availableAmountSList[2], {from: owner}); + await lrc.setBalance(order3Owner, spendableLrcFeeList[2], {from: owner}); + await lrc.setBalance(feeRecepient, spendableLrcFeeList[3], {from: owner}); + + const p = ringFactory.ringToSubmitableParams(ring, feeSelectionList, feeRecepient); + await loopringProtocolImpl.setTradingPairCutoff( + lrcAddress, + eosAddress, + new BigNumber(currBlockTimeStamp).plus(100000), + ); + try { + await loopringProtocolImpl.submitRing(p.addressList, + p.uintArgsList, + p.uint8ArgsList, + p.buyNoMoreThanAmountBList, + p.vList, + p.rList, + p.sList, + p.ringOwner, + p.feeRecepient, + {from: owner}); + } catch (err) { + const errMsg = `${err}`; + assert(_.includes(errMsg, "Error: VM Exception while processing transaction: revert"), + `Expected contract to throw, got: ${err}`); + } + + await clear([eos, neo, lrc], [order1Owner, order2Owner, order3Owner, feeRecepient]); + }); + + it("should not fill orders which have a timestamp before the cutoff set by setTradingPairCutoff.", async () => { + const ring = await ringFactory.generateSize3Ring03(order1Owner, order2Owner, order3Owner, ringOwner, 500); + const feeSelectionList = [1, 1, 1]; + const availableAmountSList = [1000e18, 2006e18, 20e18]; + const spendableLrcFeeList = [0, 6e18, 1e18, 0]; + + await eos.setBalance(order1Owner, availableAmountSList[0], {from: owner}); + await lrc.setBalance(order2Owner, availableAmountSList[1], {from: owner}); + // TODO: implement a way to set an older timestamp to properly test the cutoff, else this test will not work + await neo.setBalance(order3Owner, availableAmountSList[2], {from: owner}); + await lrc.setBalance(order3Owner, spendableLrcFeeList[2], {from: owner}); + await lrc.setBalance(feeRecepient, spendableLrcFeeList[3], {from: owner}); + + const p = ringFactory.ringToSubmitableParams(ring, feeSelectionList, feeRecepient); + await loopringProtocolImpl.setTradingPairCutoff( + lrcAddress, + eosAddress, + new BigNumber(currBlockTimeStamp).minus(100000), + {from: order1Owner}, + ); + try { + await loopringProtocolImpl.submitRing(p.addressList, + p.uintArgsList, + p.uint8ArgsList, + p.buyNoMoreThanAmountBList, + p.vList, + p.rList, + p.sList, + p.ringOwner, + p.feeRecepient, + {from: owner}); + } catch (err) { + const errMsg = `${err}`; + assert(_.includes(errMsg, "Error: VM Exception while processing transaction: revert"), + `Expected contract to throw, got: ${err}`); + } + const lrcBalance = await getTokenBalanceAsync(lrc, order1Owner); + const eosBalance = await getTokenBalanceAsync(eos, order1Owner); + assert.equal(eosBalance.toNumber(), availableAmountSList[0], "lrc balance not match for order1Owner"); + assert.equal(lrcBalance.toNumber(), availableAmountSList[1], "lrc balance not match for order1Owner"); + + await clear([eos, neo, lrc], [order1Owner, order2Owner, order3Owner, feeRecepient]); + }); + + }); + + it("should combine two hashes correctly", async () => { + const ring = await ringFactory.generateSize3Ring01(order1Owner, order2Owner, order3Owner, ringOwner); + + const token1 = "b69a71741a446a18acce6f9222c18eabd092474ce12403ab8553b504ae9" + + "6a0e1ccd43dc303710642ef0b7f6b6b6f60217c82b99b0693d36e6bd2fcad4f4c2c28"; + const token2 = "ff02b6bc030b56456319db5a294d4012a2d98f2adbe5fcf2971f14ebeeeb50" + + "618ab14e10ffae05253c10d993052805fe59ca1f4ebf0972af97fde3ededa9edaf"; + const expected = "4998c7c8194f3c5dcfd7b4c80b8cceb9724bc8663ac1ff59124ca1ef407df" + + "080466573d3fcdf0367d31ba6f86e4765df2548a6d5b99aa1c1fc2f1f40a2e5c187"; + await loopringProtocolImpl.setTradingPairCutoff( + lrcAddress, + eosAddress, + new BigNumber(0), + ); + try { + const combined = ring.orders[0].getTradingPairId(token1, token2); + assert.equal(combined, expected, "combined hash does not match expected Keccak-256 hash"); + } catch (err) { + const errMsg = `${err}`; + assert(_.includes(errMsg, "Error: VM Exception while processing transaction: revert"), + `Expected contract to throw, got: ${err}`); + } + + await clear([eos, neo, lrc], [order1Owner, order2Owner, order3Owner, feeRecepient]); }); describe("cancelOrder", () => { diff --git a/util/order.ts b/util/order.ts index 81c8776b..e74813bd 100644 --- a/util/order.ts +++ b/util/order.ts @@ -1,4 +1,5 @@ import { BigNumber } from "bignumber.js"; +import xor = require("bitwise-xor"); import promisify = require("es6-promisify"); import ethUtil = require("ethereumjs-util"); import * as _ from "lodash"; @@ -58,6 +59,12 @@ export class Order { }); } + public getTradingPairId(token1: string, token2: string) { + const combinedTokenHash = xor(new Buffer(token1, "hex"), new Buffer(token2, "hex")); + const combinedTokenHexHash = combinedTokenHash.toString("hex"); + return combinedTokenHexHash; + } + private getOrderHash() { const orderHash = crypto.solSHA3([ this.params.loopringProtocol, From 5817cfe3754cad156e93ef379ca72f23e40663a2 Mon Sep 17 00:00:00 2001 From: Pranav Kalvapalle Date: Sun, 14 Jan 2018 17:52:36 -0800 Subject: [PATCH 4/4] modify test for setTradingPairCutoff --- test/testLoopringProtocolImpl.ts | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/test/testLoopringProtocolImpl.ts b/test/testLoopringProtocolImpl.ts index eb77b2d9..cf38ef61 100644 --- a/test/testLoopringProtocolImpl.ts +++ b/test/testLoopringProtocolImpl.ts @@ -845,15 +845,29 @@ contract("LoopringProtocolImpl", (accounts: string[]) => { await eos.setBalance(order1Owner, availableAmountSList[0], {from: owner}); await lrc.setBalance(order2Owner, availableAmountSList[1], {from: owner}); - // TODO: implement a way to set an older timestamp to properly test the cutoff, else this test will not work await neo.setBalance(order3Owner, availableAmountSList[2], {from: owner}); await lrc.setBalance(order3Owner, spendableLrcFeeList[2], {from: owner}); await lrc.setBalance(feeRecepient, spendableLrcFeeList[3], {from: owner}); + // TODO: implement a way to set an older timestamp to properly test the cutoff, else this test will not work + const order = ring.orders[0]; + const cancelAmount = new BigNumber(2006e18); + const addresses = [order.owner, order.params.tokenS, order.params.tokenB]; + const orderValues = [order.params.amountS, + order.params.amountB, + order.params.timestamp.minus(200000), + order.params.ttl, + order.params.salt, + order.params.lrcFee, + cancelAmount]; + + const simulator = new ProtocolSimulator(ring, lrcAddress, feeSelectionList); + simulator.spendableLrcFeeList = spendableLrcFeeList; + const feeAndBalanceExpected = simulator.caculateRingFeesAndBalances(); const p = ringFactory.ringToSubmitableParams(ring, feeSelectionList, feeRecepient); await loopringProtocolImpl.setTradingPairCutoff( lrcAddress, - eosAddress, + neoAddress, new BigNumber(currBlockTimeStamp).minus(100000), {from: order1Owner}, ); @@ -868,16 +882,15 @@ contract("LoopringProtocolImpl", (accounts: string[]) => { p.ringOwner, p.feeRecepient, {from: owner}); + console.log(feeAndBalanceExpected); + assert.equal(feeAndBalanceExpected.balances[0].balanceB, availableAmountSList[1], + "lrc balance not match for order2Owner"); + // TODO: another way to approach this would be to compare the entries for cancelledTradingPairs } catch (err) { const errMsg = `${err}`; assert(_.includes(errMsg, "Error: VM Exception while processing transaction: revert"), `Expected contract to throw, got: ${err}`); } - const lrcBalance = await getTokenBalanceAsync(lrc, order1Owner); - const eosBalance = await getTokenBalanceAsync(eos, order1Owner); - assert.equal(eosBalance.toNumber(), availableAmountSList[0], "lrc balance not match for order1Owner"); - assert.equal(lrcBalance.toNumber(), availableAmountSList[1], "lrc balance not match for order1Owner"); - await clear([eos, neo, lrc], [order1Owner, order2Owner, order3Owner, feeRecepient]); });