require txOrigin for RFQ orders, allow origins to register alternate … (#47)

require txOrigin for RFQ orders, allow origins to register alternate addresses that can fill orders
This commit is contained in:
Steve Marx
2020-11-24 16:53:32 -05:00
committed by GitHub
parent e2ee3414ea
commit 841e4ee666
5 changed files with 116 additions and 13 deletions

View File

@@ -77,7 +77,7 @@ blockchainTests.resets('NativeOrdersFeature', env => {
verifyingContract,
takerToken: takerToken.address,
makerToken: makerToken.address,
txOrigin: NULL_ADDRESS,
txOrigin: taker,
...fields,
});
}
@@ -86,10 +86,10 @@ blockchainTests.resets('NativeOrdersFeature', env => {
await makerToken.mint(maker, order.makerAmount).awaitTransactionSuccessAsync();
if ('takerTokenFeeAmount' in order) {
await takerToken
.mint(taker, order.takerAmount.plus(order.takerTokenFeeAmount))
.mint(_taker, order.takerAmount.plus(order.takerTokenFeeAmount))
.awaitTransactionSuccessAsync();
} else {
await takerToken.mint(taker, order.takerAmount).awaitTransactionSuccessAsync();
await takerToken.mint(_taker, order.takerAmount).awaitTransactionSuccessAsync();
}
}
@@ -303,7 +303,7 @@ blockchainTests.resets('NativeOrdersFeature', env => {
it('filled order', async () => {
const order = getTestRfqOrder();
// Fill the order first.
await fillRfqOrderAsync(order);
await fillRfqOrderAsync(order, order.takerAmount, taker);
const info = await zeroEx.getRfqOrderInfo(order).callAsync();
assertOrderInfoEquals(info, {
status: OrderStatus.Filled,
@@ -1110,13 +1110,66 @@ blockchainTests.resets('NativeOrdersFeature', env => {
});
it('cannot fill an order with wrong tx.origin', async () => {
const order = getTestRfqOrder({ txOrigin: taker });
const order = getTestRfqOrder();
const tx = fillRfqOrderAsync(order, order.takerAmount, notTaker);
return expect(tx).to.revertWith(
new RevertErrors.OrderNotFillableByOriginError(order.getHash(), notTaker, taker),
);
});
it('can fill an order from a different tx.origin if registered', async () => {
const order = getTestRfqOrder();
const receipt = await zeroEx
.registerAllowedRfqOrigin(notTaker, true)
.awaitTransactionSuccessAsync({ from: taker });
verifyEventsFromLogs(
receipt.logs,
[
{
origin: taker,
addr: notTaker,
allowed: true,
},
],
IZeroExEvents.RfqOrderOriginAllowed,
);
return fillRfqOrderAsync(order, order.takerAmount, notTaker);
});
it('cannot fill an order with registered then unregistered tx.origin', async () => {
const order = getTestRfqOrder();
await zeroEx.registerAllowedRfqOrigin(notTaker, true).awaitTransactionSuccessAsync({ from: taker });
const receipt = await zeroEx
.registerAllowedRfqOrigin(notTaker, false)
.awaitTransactionSuccessAsync({ from: taker });
verifyEventsFromLogs(
receipt.logs,
[
{
origin: taker,
addr: notTaker,
allowed: false,
},
],
IZeroExEvents.RfqOrderOriginAllowed,
);
const tx = fillRfqOrderAsync(order, order.takerAmount, notTaker);
return expect(tx).to.revertWith(
new RevertErrors.OrderNotFillableByOriginError(order.getHash(), notTaker, taker),
);
});
it('cannot fill an order with a zero tx.origin', async () => {
const order = getTestRfqOrder({ txOrigin: NULL_ADDRESS });
const tx = fillRfqOrderAsync(order, order.takerAmount, notTaker);
return expect(tx).to.revertWith(
new RevertErrors.OrderNotFillableByOriginError(order.getHash(), notTaker, order.txOrigin),
);
});
it('cannot fill an expired order', async () => {
const order = getTestRfqOrder({ expiry: createExpiry(-60) });
const tx = fillRfqOrderAsync(order);
@@ -1166,7 +1219,7 @@ blockchainTests.resets('NativeOrdersFeature', env => {
)
.awaitTransactionSuccessAsync({ from: taker, value: ZERO_AMOUNT });
// The exact revert error depends on whether we are still doing a
// token spender fallthroigh, so we won't get too specific.
// token spender fallthrough, so we won't get too specific.
return expect(tx).to.revertWith(new AnyRevertError());
});
});