aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/contracts/test/exchange/core.ts61
-rw-r--r--packages/contracts/test/exchange/helpers.ts2
-rw-r--r--packages/contracts/util/exchange_wrapper.ts2
-rw-r--r--packages/contracts/util/order.ts7
-rw-r--r--packages/contracts/util/types.ts1
5 files changed, 41 insertions, 32 deletions
diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts
index 5cedaddc9..7a654b2df 100644
--- a/packages/contracts/test/exchange/core.ts
+++ b/packages/contracts/test/exchange/core.ts
@@ -156,8 +156,9 @@ describe('Exchange', () => {
takerTokenAmount: new BigNumber(3),
});
- const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
- .orderHashHex as string);
+ const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.getOrderHashHex(),
+ );
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount1 = new BigNumber(2);
@@ -165,8 +166,9 @@ describe('Exchange', () => {
fillTakerTokenAmount: fillTakerTokenAmount1,
});
- const filledTakerTokenAmountAfter1 = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
- .orderHashHex as string);
+ const filledTakerTokenAmountAfter1 = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.getOrderHashHex(),
+ );
expect(filledTakerTokenAmountAfter1).to.be.bignumber.equal(fillTakerTokenAmount1);
const fillTakerTokenAmount2 = new BigNumber(1);
@@ -174,8 +176,9 @@ describe('Exchange', () => {
fillTakerTokenAmount: fillTakerTokenAmount2,
});
- const filledTakerTokenAmountAfter2 = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
- .orderHashHex as string);
+ const filledTakerTokenAmountAfter2 = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.getOrderHashHex(),
+ );
expect(filledTakerTokenAmountAfter2).to.be.bignumber.equal(filledTakerTokenAmountAfter1);
});
@@ -185,15 +188,17 @@ describe('Exchange', () => {
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
});
- const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
- .orderHashHex as string);
+ const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.getOrderHashHex(),
+ );
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount });
- const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
- .orderHashHex as string);
+ const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.getOrderHashHex(),
+ );
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(fillTakerTokenAmount);
const newBalances = await dmyBalances.getAsync();
@@ -236,15 +241,17 @@ describe('Exchange', () => {
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
});
- const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
- .orderHashHex as string);
+ const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.getOrderHashHex(),
+ );
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount });
- const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
- .orderHashHex as string);
+ const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.getOrderHashHex(),
+ );
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(fillTakerTokenAmount);
const newBalances = await dmyBalances.getAsync();
@@ -287,15 +294,17 @@ describe('Exchange', () => {
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
});
- const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
- .orderHashHex as string);
+ const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.getOrderHashHex(),
+ );
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount });
- const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
- .orderHashHex as string);
+ const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.getOrderHashHex(),
+ );
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(fillTakerTokenAmount);
const newBalances = await dmyBalances.getAsync();
@@ -339,15 +348,17 @@ describe('Exchange', () => {
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
});
- const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
- .orderHashHex as string);
+ const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.getOrderHashHex(),
+ );
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount });
- const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
- .orderHashHex as string);
+ const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.getOrderHashHex(),
+ );
const expectedFillAmountTAfter = fillTakerTokenAmount.add(filledTakerTokenAmountBefore);
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(expectedFillAmountTAfter);
@@ -446,7 +457,7 @@ describe('Exchange', () => {
expect(expectedFeeMPaid).to.be.bignumber.equal(logArgs.paidMakerFee);
expect(expectedFeeTPaid).to.be.bignumber.equal(logArgs.paidTakerFee);
expect(expectedTokens).to.be.equal(logArgs.tokens);
- expect(order.params.orderHashHex).to.be.equal(logArgs.orderHash);
+ expect(order.getOrderHashHex()).to.be.equal(logArgs.orderHash);
});
it('should log 1 event with the correct arguments when order has no feeRecipient', async () => {
@@ -477,7 +488,7 @@ describe('Exchange', () => {
expect(expectedFeeMPaid).to.be.bignumber.equal(logArgs.paidMakerFee);
expect(expectedFeeTPaid).to.be.bignumber.equal(logArgs.paidTakerFee);
expect(expectedTokens).to.be.equal(logArgs.tokens);
- expect(order.params.orderHashHex).to.be.equal(logArgs.orderHash);
+ expect(order.getOrderHashHex()).to.be.equal(logArgs.orderHash);
});
it('should throw when taker is specified and order is claimed by other', async () => {
@@ -842,7 +853,7 @@ describe('Exchange', () => {
expect(expectedCancelledMakerTokenAmount).to.be.bignumber.equal(logArgs.cancelledMakerTokenAmount);
expect(expectedCancelledTakerTokenAmount).to.be.bignumber.equal(logArgs.cancelledTakerTokenAmount);
expect(expectedTokens).to.be.equal(logArgs.tokens);
- expect(order.params.orderHashHex).to.be.equal(logArgs.orderHash);
+ expect(order.getOrderHashHex()).to.be.equal(logArgs.orderHash);
});
it('should not log events if no value is cancelled', async () => {
diff --git a/packages/contracts/test/exchange/helpers.ts b/packages/contracts/test/exchange/helpers.ts
index 33bf8b803..e2e35ece8 100644
--- a/packages/contracts/test/exchange/helpers.ts
+++ b/packages/contracts/test/exchange/helpers.ts
@@ -71,7 +71,7 @@ describe('Exchange', () => {
describe('getOrderHash', () => {
it('should output the correct orderHash', async () => {
const orderHashHex = await exchangeWrapper.getOrderHashAsync(order);
- expect(order.params.orderHashHex).to.be.equal(orderHashHex);
+ expect(order.getOrderHashHex()).to.be.equal(orderHashHex);
});
});
diff --git a/packages/contracts/util/exchange_wrapper.ts b/packages/contracts/util/exchange_wrapper.ts
index b749cd72e..e44a0eab6 100644
--- a/packages/contracts/util/exchange_wrapper.ts
+++ b/packages/contracts/util/exchange_wrapper.ts
@@ -184,7 +184,7 @@ export class ExchangeWrapper {
public async isValidSignatureAsync(order: Order): Promise<boolean> {
const isValidSignature = await this._exchange.isValidSignature(
order.params.maker,
- order.params.orderHashHex as string,
+ order.getOrderHashHex(),
order.params.v as number,
order.params.r as string,
order.params.s as string,
diff --git a/packages/contracts/util/order.ts b/packages/contracts/util/order.ts
index 57bb2bcbf..12f10fa4e 100644
--- a/packages/contracts/util/order.ts
+++ b/packages/contracts/util/order.ts
@@ -18,7 +18,7 @@ export class Order {
if (_.isUndefined(v) || _.isUndefined(r) || _.isUndefined(s)) {
throw new Error('Cannot call isValidSignature on unsigned order');
}
- const orderHash = this._getOrderHash();
+ const orderHash = this.getOrderHashHex();
const msgHash = ethUtil.hashPersonalMessage(ethUtil.toBuffer(orderHash));
try {
const pubKey = ethUtil.ecrecover(msgHash, v, ethUtil.toBuffer(r), ethUtil.toBuffer(s));
@@ -29,11 +29,10 @@ export class Order {
}
}
public async signAsync() {
- const orderHash = this._getOrderHash();
+ const orderHash = this.getOrderHashHex();
const signature = await this._web3Wrapper.signTransactionAsync(this.params.maker, orderHash);
const { v, r, s } = ethUtil.fromRpcSig(signature);
this.params = _.assign(this.params, {
- orderHashHex: orderHash,
v,
r: ethUtil.bufferToHex(r),
s: ethUtil.bufferToHex(s),
@@ -85,7 +84,7 @@ export class Order {
};
return cancel;
}
- private _getOrderHash(): string {
+ public getOrderHashHex(): string {
const orderHash = crypto.solSHA3([
this.params.exchangeContractAddress,
this.params.maker,
diff --git a/packages/contracts/util/types.ts b/packages/contracts/util/types.ts
index 38fd33161..5d474b596 100644
--- a/packages/contracts/util/types.ts
+++ b/packages/contracts/util/types.ts
@@ -76,7 +76,6 @@ export interface OrderParams {
takerFee: BigNumber;
expirationTimestampInSec: BigNumber;
salt: BigNumber;
- orderHashHex?: string;
v?: number;
r?: string;
s?: string;