Skip to content

Commit

Permalink
feat: remove tpw managers env (#366)
Browse files Browse the repository at this point in the history
* feat: remove tpw managers env

* feat: re-add useful test

* chore: I english good

* chore: unnecessary spy

* chore: import

* chore: spec desc
  • Loading branch information
nicosantangelo committed Jan 4, 2022
1 parent c1c12d4 commit d0056d6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 58 deletions.
5 changes: 0 additions & 5 deletions .ci/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ export = async function main() {
name: 'WAREHOUSE_TOKEN',
value: config.requireSecret('WAREHOUSE_TOKEN'),
},
{
name: 'TPW_MANAGER_ADDRESSES',
value:
'0x1D9aa2025b67f0F21d1603ce521bda7869098f8a,0xeDaE96F7739aF8A7fB16E2a888C1E578E1328299,0xeC6E6c0841a2bA474E92Bf42BaF76bFe80e8657C,0x24e5F44999c151f08609F8e27b2238c773C4D020',
},
{
name: 'THIRD_PARTY_GRAPH_URL',
value:
Expand Down
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,3 @@ MATIC_RPC_URL=
WAREHOUSE_URL=
WAREHOUSE_TOKEN=
WAREHOUSE_CONTEXT_PREFIX=

TPW_MANAGER_ADDRESSES: 0xc6d2000a7a1ddca92941f4e2b41360fe4ee2abd9
1 change: 0 additions & 1 deletion .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
ANALYTICS_CONNECTION_STRING: ANALYTICS_CONNECTION_STRING
PEER_URL: https://peer.decentraland.zone
ETHEREUM_NETWORK: ropsten
TPW_MANAGER_ADDRESSES: '0x25349e40543494430ae6d06ca2b31bb844439d09'
THIRD_PARTY_GRAPH_URL: 'http://thid-party-url'
- name: Report Coverage
uses: coverallsapp/github-action@master
Expand Down
54 changes: 16 additions & 38 deletions src/Collection/Collection.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { env } from 'decentraland-commons'
import { collectionAttributesMock } from '../../spec/mocks/collections'
import { wallet } from '../../spec/mocks/wallet'
import { thirdPartyAPI } from '../ethereum/api/thirdParty'
Expand Down Expand Up @@ -57,58 +56,37 @@ describe('Collection service', () => {

describe('when checking if an address is a TPW manager', () => {
const service = new CollectionService()
let urn: string
let manager: string

beforeEach(() => {
urn = 'some:valid:urn'
manager = '0x123123'
})

afterAll(() => {
jest.restoreAllMocks()
})

describe('when an address belongs to the TPW_MANAGER_ADDRESSES env var', () => {
let manager: string
describe('when thegraph has a urn with the address as manager', () => {
beforeEach(() => {
manager = '0x123123'
jest
.spyOn(env, 'get')
.mockReturnValueOnce(`0x555,${manager},0x444,0x333`)
;(thirdPartyAPI.isManager as jest.Mock).mockReturnValueOnce(true)
})

it('should return true', async () => {
expect(await service.isTPWManager('', manager)).toBe(true)
expect(env.get).toHaveBeenCalledWith('TPW_MANAGER_ADDRESSES', '')
expect(await service.isTPWManager(urn, manager)).toBe(true)
expect(thirdPartyAPI.isManager).toHaveBeenCalledWith(urn, manager)
})
})

describe('when an address does not belong to the TPW_MANAGER_ADDRESSES env var', () => {
let urn: string
let manager: string

describe('when thegraph does not have a urn with the address as manager', () => {
beforeEach(() => {
urn = 'some:valid:urn'
manager = '0x123123'
jest.spyOn(env, 'get').mockReturnValueOnce(`0x555,0x444,0x333`)
;(thirdPartyAPI.isManager as jest.Mock).mockReturnValueOnce(false)
})

describe('when thegraph has a urn with the address as manager', () => {
beforeEach(() => {
;(thirdPartyAPI.isManager as jest.Mock).mockReturnValueOnce(true)
})

it('should return true', async () => {
expect(await service.isTPWManager(urn, manager)).toBe(true)
expect(thirdPartyAPI.isManager).toHaveBeenCalledWith(urn, manager)
expect(env.get).toHaveBeenCalledWith('TPW_MANAGER_ADDRESSES', '')
})
})

describe('when thegraph does not has a urn with the address as manager', () => {
beforeEach(() => {
;(thirdPartyAPI.isManager as jest.Mock).mockReturnValueOnce(false)
})

it('should return true', async () => {
expect(await service.isTPWManager(urn, manager)).toBe(false)
expect(thirdPartyAPI.isManager).toHaveBeenCalledWith(urn, manager)
expect(env.get).toHaveBeenCalledWith('TPW_MANAGER_ADDRESSES', '')
})
it('should return false', async () => {
expect(await service.isTPWManager(urn, manager)).toBe(false)
expect(thirdPartyAPI.isManager).toHaveBeenCalledWith(urn, manager)
})
})
})
Expand Down
12 changes: 0 additions & 12 deletions src/Collection/Collection.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { env } from 'decentraland-commons'
import { collectionAPI } from '../ethereum/api/collection'
import { thirdPartyAPI } from '../ethereum/api/thirdParty'
import { isPublished } from '../utils/eth'
Expand Down Expand Up @@ -255,17 +254,6 @@ export class CollectionService {
* @param address - The address to check if it manages the collection.
*/
public async isTPWManager(urn: string, address: string): Promise<boolean> {
const isEnvManager =
!env.isProduction() &&
env
.get('TPW_MANAGER_ADDRESSES', '')
.toLowerCase()
.search(address.toLowerCase()) > -1

if (isEnvManager) {
return true
}

return thirdPartyAPI.isManager(urn, address)
}

Expand Down

0 comments on commit d0056d6

Please sign in to comment.