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

Fix error where object could be undefined given an approval event #1692

Merged
merged 3 commits into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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