Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1692 from 0xProject/fix/order-watcher/1550
Browse files Browse the repository at this point in the history
Fix error where object could be undefined given an approval event
  • Loading branch information
dekz authored Mar 14, 2019
2 parents af04c29 + e28c6d6 commit b378a06
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/order-watcher/CHANGELOG.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
{
"note": "Update websocket from ^1.0.25 to ^1.0.26",
"pr": 1685
},
{
"note": "Fix issue where ERC721 Approval events could cause a lookup on undefined object",
"pr": 1692
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export class DependentOrderHashesTracker {
this._zrxTokenAddress = zrxTokenAddress;
}
public getDependentOrderHashesByERC721ByMaker(makerAddress: string, tokenAddress: string): string[] {
if (
_.isUndefined(this._orderHashesByERC721AddressByTokenIdByMakerAddress[makerAddress]) ||
_.isUndefined(this._orderHashesByERC721AddressByTokenIdByMakerAddress[makerAddress][tokenAddress])
) {
return [];
}
const orderHashSets = _.values(
this._orderHashesByERC721AddressByTokenIdByMakerAddress[makerAddress][tokenAddress],
);
Expand Down
13 changes: 13 additions & 0 deletions packages/order-watcher/test/order_watcher_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ describe('OrderWatcher', () => {
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('DependentOrderHashesTracker', async () => {
let makerErc721TokenAddress: string;
[makerErc721TokenAddress] = tokenUtils.getDummyERC721TokenAddresses();
it('should handle lookups on unknown addresses', async () => {
// Regression test
// ApprovalForAll events on a token from an untracked address could cause
// nested lookups on undefined object
// #1550
const dependentOrderHashesTracker = (orderWatcher as any)
._dependentOrderHashesTracker as DependentOrderHashesTracker;
dependentOrderHashesTracker.getDependentOrderHashesByERC721ByMaker(takerAddress, makerErc721TokenAddress);
});
});
describe('#removeOrder', async () => {
it('should successfully remove existing order', async () => {
signedOrder = await fillScenarios.createFillableSignedOrderAsync(
Expand Down

0 comments on commit b378a06

Please sign in to comment.