From 02635ccb9329fa9808e13936828d382c3cb4d1ee Mon Sep 17 00:00:00 2001 From: Sam Bauch Date: Wed, 26 Jul 2023 20:38:55 -0400 Subject: [PATCH] bugfixes and tests --- .../__tests__/DelegationTree.test.ts | 22 +++++++++++++++++++ .../__tests__/OwnershipService.test.ts | 1 + .../ownership-oracle/__tests__/api.test.ts | 1 + .../ownership-oracle/src/NetworkProvider.ts | 2 ++ .../ownership-oracle/src/OwnershipService.ts | 2 +- 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/ownership-oracle/__tests__/DelegationTree.test.ts b/packages/ownership-oracle/__tests__/DelegationTree.test.ts index e1a1c8d..aa8b01f 100644 --- a/packages/ownership-oracle/__tests__/DelegationTree.test.ts +++ b/packages/ownership-oracle/__tests__/DelegationTree.test.ts @@ -49,6 +49,28 @@ describe('DelegationTree', () => { expect(authorized).toBe(false); }); + it('returns false when signer is not owner and no authorizer', async () => { + getAllDelegationsMock.mockReturnValueOnce([ + { + vault: owner.address, + tokenId, + contract_: nftContract, + delegate: signer.address, + type_: 1, + }, + ]); + + const tree = new DelegationTree( + provider, + nftContract, + tokenId, + signer.address, + ); + + const authorized = await tree.hasDelegatedOwnership(''); + expect(authorized).toBe(false); + }); + it('returns false when authorizer is not owner', async () => { getAllDelegationsMock.mockReturnValueOnce([ { diff --git a/packages/ownership-oracle/__tests__/OwnershipService.test.ts b/packages/ownership-oracle/__tests__/OwnershipService.test.ts index 172baa7..9c71e5b 100644 --- a/packages/ownership-oracle/__tests__/OwnershipService.test.ts +++ b/packages/ownership-oracle/__tests__/OwnershipService.test.ts @@ -65,6 +65,7 @@ describe('OwnershipService', () => { return owner.address; }); }); + it('should throw an error when not authorized', async () => { hasDelegatedOwnershipMock.mockResolvedValue(false); diff --git a/packages/ownership-oracle/__tests__/api.test.ts b/packages/ownership-oracle/__tests__/api.test.ts index a53a8c2..97eb0b8 100644 --- a/packages/ownership-oracle/__tests__/api.test.ts +++ b/packages/ownership-oracle/__tests__/api.test.ts @@ -56,6 +56,7 @@ describe('durin_call endpoint', () => { expect(response.status).toBe(200); expect(response.body).toHaveProperty('result', 'gud proof'); }); + it('returns an error if signer is neither owner nor authorized', async () => { processCallMock.mockRejectedValue(new Error('bad proof')); diff --git a/packages/ownership-oracle/src/NetworkProvider.ts b/packages/ownership-oracle/src/NetworkProvider.ts index 1e10a96..20dc84e 100644 --- a/packages/ownership-oracle/src/NetworkProvider.ts +++ b/packages/ownership-oracle/src/NetworkProvider.ts @@ -7,6 +7,7 @@ export const PROVIDERS = { 7700: 'https://canto.slingshot.finance/', 740: 'https://eth.plexnode.wtf/', 42170: 'https://nova.arbitrum.io/rpc', + 7777777: 'https://rpc.zora.energy/', }; class NetworkProvider { @@ -22,6 +23,7 @@ class NetworkProvider { case 7700: case 740: case 42170: + case 7777777: provider = new providers.JsonRpcProvider(PROVIDERS[chainId], chainId); break; default: diff --git a/packages/ownership-oracle/src/OwnershipService.ts b/packages/ownership-oracle/src/OwnershipService.ts index 75cd6ed..98e3d80 100644 --- a/packages/ownership-oracle/src/OwnershipService.ts +++ b/packages/ownership-oracle/src/OwnershipService.ts @@ -109,7 +109,7 @@ class OwnershipService { from, ); - const authorized = await delegationTree.hasDelegatedOwnership(authorizer); + const authorized = await delegationTree.hasDelegatedOwnership(owner); if (authorized) { console.warn('AUTHORIZED RECURSIVELY');