Skip to content

Commit

Permalink
feat: Add polygon amoy support (#739)
Browse files Browse the repository at this point in the history
* feat: Update mapped chain id to use amoy

* chore: Upgrade decentraland-transactions and @dcl/schemas

* feat: Update CollectionFactoryV3 amoy codeHash

* feat: Update packages

* fix: Remove console.logs

* chore: Upgrade @dcl/schemas package

* fix: Update TP mock data

* fix: Update tests hashes to amoy

* feat: Update decentraland-transactions package
  • Loading branch information
cyaiox authored Apr 18, 2024
1 parent 3387a3e commit 2e9b916
Show file tree
Hide file tree
Showing 13 changed files with 423 additions and 312 deletions.
593 changes: 355 additions & 238 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@dcl/crypto": "^3.0.1",
"@dcl/hashing": "^1.1.0",
"@dcl/platform-crypto-middleware": "^1.0.2",
"@dcl/schemas": "^11.4.0",
"@dcl/schemas": "^11.5.0",
"@ethersproject/solidity": "^5.7.0",
"@types/escape-html": "0.0.20",
"@types/express": "^4.17.11",
Expand All @@ -55,7 +55,7 @@
"dcl-catalyst-client": "^21.5.0",
"decentraland-commons": "^5.2.0",
"decentraland-server": "^3.1.0",
"decentraland-transactions": "^2.4.0",
"decentraland-transactions": "^2.6.1",
"escape-html": "^1.0.3",
"ethers": "^5.7.2",
"express": "^4.18.2",
Expand Down
4 changes: 2 additions & 2 deletions spec/mocks/cheque.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const mockedCheque = {
signature:
'0xda1398329aff61ce133d4204c0ebc656b07e0629c280d6f60121874285ac3bbc56e48b9e7211296be9f209d646e723f44a96c82f0e6bd52ee6edf74cc44ee9d71c', // signatured generated using the wallet from fakePrivateKey
'0x784093055673ce56a4a4093a7ec5e3a9594f101682774d980da777d53913760f189b7f1a8d9b4a5123ac113f3407cfcd418868545a455a51fa431223be8fa1931b', // signatured generated using the wallet from fakePrivateKey
qty: 3,
salt: '0xb899ffa17ccea3e2ae5fd36236df56c3bf908a435ad101ed7fa6ec8a9631e253',
salt: '0xdf421c292bafb6f4f8a50fddbe03a4205ef289e2d9377eda4560cf1f94071d14',
}
4 changes: 2 additions & 2 deletions spec/mocks/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export const dbTPCollectionMock: ThirdPartyCollectionAttributes = {
name: 'TP Mocked Collection',
eth_address: '',
contract_address: null,
urn_suffix: 'collection-id',
urn_suffix: 'test-collection',
third_party_id:
'urn:decentraland:mumbai:collections-thirdparty:third-party-id',
'urn:decentraland:amoy:collections-thirdparty:dcl-tests',
}

export const collectionFragmentMock: CollectionFragment = {
Expand Down
35 changes: 17 additions & 18 deletions src/Collection/Collection.router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ jest.mock('./Collection.model')
jest.mock('./access')

const thirdPartyAPIMock = thirdPartyAPI as jest.Mocked<typeof thirdPartyAPI>
const tpUrnPrefix = 'urn:decentraland:amoy:collections-v2'

describe('Collection router', () => {
let dbCollection: CollectionAttributes
Expand Down Expand Up @@ -761,6 +762,7 @@ describe('Collection router', () => {
})

it('should upsert the collection and respond with a 200 and the upserted collection', () => {
const urnRegex = `${tpUrnPrefix}:0[xX][0-9a-fA-F]{40}`
return server
.put(buildURL(url))
.set(createAuthHeaders('put', url))
Expand All @@ -780,9 +782,7 @@ describe('Collection router', () => {
/0[xX][0-9a-fA-F]{40}/
),
eth_address: wallet.address,
urn: expect.stringMatching(
/urn:decentraland:mumbai:collections-v2:0[xX][0-9a-fA-F]{40}/
),
urn: expect.stringMatching(new RegExp(urnRegex)),
}),
})
})
Expand All @@ -797,6 +797,7 @@ describe('Collection router', () => {
})

it('should upsert the collection and respond with a 200 and the upserted collection', () => {
const urnRegex = `${tpUrnPrefix}:0[xX][0-9a-fA-F]{40}`
return server
.put(buildURL(url))
.set(createAuthHeaders('put', url))
Expand All @@ -815,9 +816,7 @@ describe('Collection router', () => {
contract_address: expect.stringMatching(
/0[xX][0-9a-fA-F]{40}/
),
urn: expect.stringMatching(
/urn:decentraland:mumbai:collections-v2:0[xX][0-9a-fA-F]{40}/
),
urn: expect.stringMatching(new RegExp(urnRegex)),
}),
})
})
Expand Down Expand Up @@ -888,7 +887,7 @@ describe('Collection router', () => {
results: [
{
...resultingCollectionAttributes,
urn: `urn:decentraland:mumbai:collections-v2:${dbCollection.contract_address}`,
urn: `${tpUrnPrefix}:${dbCollection.contract_address}`,
},
],
},
Expand Down Expand Up @@ -952,7 +951,7 @@ describe('Collection router', () => {
results: [
{
...resultingCollectionAttributes,
urn: `urn:decentraland:mumbai:collections-v2:${dbCollection.contract_address}`,
urn: `${tpUrnPrefix}:${dbCollection.contract_address}`,
},
],
},
Expand Down Expand Up @@ -1021,7 +1020,7 @@ describe('Collection router', () => {
results: [
{
...resultingCollectionAttributes,
urn: `urn:decentraland:mumbai:collections-v2:${dbCollection.contract_address}`,
urn: `${tpUrnPrefix}:${dbCollection.contract_address}`,
},
],
},
Expand Down Expand Up @@ -1061,7 +1060,7 @@ describe('Collection router', () => {
data: [
{
...resultingCollectionAttributes,
urn: `urn:decentraland:mumbai:collections-v2:${dbCollection.contract_address}`,
urn: `${tpUrnPrefix}:${dbCollection.contract_address}`,
},
],
ok: true,
Expand Down Expand Up @@ -1108,7 +1107,7 @@ describe('Collection router', () => {
results: [
{
...resultingCollectionAttributes,
urn: `urn:decentraland:mumbai:collections-v2:${dbCollection.contract_address}`,
urn: `${tpUrnPrefix}:${dbCollection.contract_address}`,
},
],
},
Expand Down Expand Up @@ -1172,7 +1171,7 @@ describe('Collection router', () => {
results: [
{
...resultingCollectionAttributes,
urn: `urn:decentraland:mumbai:collections-v2:${dbCollection.contract_address}`,
urn: `${tpUrnPrefix}:${dbCollection.contract_address}`,
},
],
},
Expand Down Expand Up @@ -1241,7 +1240,7 @@ describe('Collection router', () => {
results: [
{
...resultingCollectionAttributes,
urn: `urn:decentraland:mumbai:collections-v2:${dbCollection.contract_address}`,
urn: `${tpUrnPrefix}:${dbCollection.contract_address}`,
},
],
},
Expand Down Expand Up @@ -1281,7 +1280,7 @@ describe('Collection router', () => {
data: [
{
...resultingCollectionAttributes,
urn: `urn:decentraland:mumbai:collections-v2:${dbCollection.contract_address}`,
urn: `${tpUrnPrefix}:${dbCollection.contract_address}`,
},
],
ok: true,
Expand Down Expand Up @@ -1342,7 +1341,7 @@ describe('Collection router', () => {
results: [
{
...resultingCollectionAttributes,
urn: `urn:decentraland:mumbai:collections-v2:${dbCollection.contract_address}`,
urn: `${tpUrnPrefix}:${dbCollection.contract_address}`,
},
],
},
Expand Down Expand Up @@ -1398,7 +1397,7 @@ describe('Collection router', () => {
data: [
{
...resultingCollectionAttributes,
urn: `urn:decentraland:mumbai:collections-v2:${dbCollection.contract_address}`,
urn: `${tpUrnPrefix}:${dbCollection.contract_address}`,
},
{
...toResultCollection(dbTPCollection),
Expand Down Expand Up @@ -1434,7 +1433,7 @@ describe('Collection router', () => {
expect(response.body).toEqual({
data: {
...resultingCollectionAttributes,
urn: `urn:decentraland:mumbai:collections-v2:${dbCollection.contract_address}`,
urn: `${tpUrnPrefix}:${dbCollection.contract_address}`,
},
ok: true,
})
Expand Down Expand Up @@ -2787,7 +2786,7 @@ describe('Collection router', () => {
beforeEach(() => {
thirdPartyAPIMock.fetchReceiptById.mockResolvedValueOnce({
id:
'0x7954b5d263d7d1298c98fa330de6a0d94952bb5f6694cab0dde144239d56dce1',
'0x80a6f1bdeaeccc9caec3f8fcf7bde7cf1219735b0fa8dd058d0a8a8b81b8ea16',
} as ReceiptFragment)
thirdPartyAPIMock.fetchThirdParty.mockResolvedValueOnce({
root: 'aRootValue',
Expand Down
4 changes: 2 additions & 2 deletions src/Collection/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe('when getting the cheque hash', () => {
let thirdPartyId: string

beforeEach(() => {
thirdPartyId = 'urn:decentraland:mumbai:collections-thirdparty:jean-pier'
thirdPartyId = 'urn:decentraland:amoy:collections-thirdparty:jean-pier'
cheque = {
signature:
'0x1dd053b34b48bc1e08be16c1d4f51908b4551040cf0fb390b90d18583dab2c7716ba3c73f00b5143e8ecdcd6227433226195e545a897df2e28849e91d291d9201c',
Expand All @@ -156,7 +156,7 @@ describe('when getting the cheque hash', () => {

it('should return the correct hash', () => {
return expect(getChequeMessageHash(cheque, thirdPartyId)).resolves.toEqual(
'0x808b380dc4bd97f8a0cf17c3548ad5c085964b31a99d5c52311c571b398783bc'
'0x507e4d6eb5ec23efbfdc3c2fdb46176f71657ca7443f76ae5701dc58c7d0c57e'
)
})
})
8 changes: 4 additions & 4 deletions src/Item/Item.router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ describe('Item router', () => {
collection_id: tpCollectionMock.id,
eth_address: wallet.address,
local_content_hash:
'1590ff765dfe1479b6a6bc46baa493659c57b9b4a99244da7d3ed9464e4c535c',
'b3520ef20163848f0fc69fc6aee1f7240c7ef4960944fcd92ce2e67a62828f6f',
}
resultingItem = {
...toResultItem(
Expand Down Expand Up @@ -982,7 +982,7 @@ describe('Item router', () => {
expect(ItemCuration.update).toHaveBeenCalledWith(
{
content_hash:
'1590ff765dfe1479b6a6bc46baa493659c57b9b4a99244da7d3ed9464e4c535c',
'b3520ef20163848f0fc69fc6aee1f7240c7ef4960944fcd92ce2e67a62828f6f',
},
{
item_id: itemToUpsert.id,
Expand Down Expand Up @@ -1015,7 +1015,7 @@ describe('Item router', () => {
collection_id: tpCollectionMock.id,
eth_address: wallet.address,
local_content_hash:
'1590ff765dfe1479b6a6bc46baa493659c57b9b4a99244da7d3ed9464e4c535c',
'b3520ef20163848f0fc69fc6aee1f7240c7ef4960944fcd92ce2e67a62828f6f',
}
resultingItem = {
...toResultItem(
Expand Down Expand Up @@ -1178,7 +1178,7 @@ describe('Item router', () => {
collection_id: tpCollectionMock.id,
eth_address: wallet.address,
local_content_hash:
'1590ff765dfe1479b6a6bc46baa493659c57b9b4a99244da7d3ed9464e4c535c',
'b3520ef20163848f0fc69fc6aee1f7240c7ef4960944fcd92ce2e67a62828f6f',
}
mockThirdPartyURNExists(itemToUpsert.urn!, false)
resultingItem = {
Expand Down
41 changes: 17 additions & 24 deletions src/Item/Item.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,17 @@ export class ItemService {
item: FullItem,
eth_address: string
): Promise<FullItem> {
console.log('here1')
const decodedItemURN =
!item.id && item.urn ? decodeThirdPartyItemURN(item.urn) : null

// Finds the item to be updated by URN if it's a third party item or by ID if it's not
const dbItem = decodedItemURN
? await Item.findByURNSuffix(
decodedItemURN.third_party_id,
decodedItemURN.item_urn_suffix
)
decodedItemURN.third_party_id,
decodedItemURN.item_urn_suffix
)
: await Item.findOne<ItemAttributes>(item.id)
console.log('here2')

if (item.data.tags.length > MAX_TAGS_LENGTH) {
const isAlreadyExceeded =
!!dbItem && dbItem.data.tags.length > MAX_TAGS_LENGTH
Expand All @@ -84,15 +83,12 @@ export class ItemService {
throw new MaximunAmountOfTagsReachedError(item.id)
}
}
console.log('here3')

// Inserting by URN is not allowed
if (!item.id && item.urn && !dbItem) {
throw new ThirdPartyItemInsertByURNError(item.urn)
}

console.log('here4')

const isMovingItemFromACollectionToAnother =
dbItem && this.isMovingItemFromACollectionToAnother(item, dbItem)
const isMovingOrphanItemIntoACollection =
Expand Down Expand Up @@ -130,7 +126,6 @@ export class ItemService {
// Set the item dates
item = { ...item, ...buildModelDates(dbItem?.created_at) }

console.log('here5')
// An item is a third party item if it's current collection or the collection
// that is going to be inserted into is a third party collection.
if (dbItemCollection && isTPCollection(dbItemCollection)) {
Expand Down Expand Up @@ -213,14 +208,14 @@ export class ItemService {
const dbItemsWithCount =
status && isTP
? await Item.findByCollectionIdAndStatus(
collectionId,
{
synced,
status: CurationStatus.PENDING,
},
limit,
offset
)
collectionId,
{
synced,
status: CurationStatus.PENDING,
},
limit,
offset
)
: await Item.findByCollectionIds([collectionId], synced, limit, offset)

const totalItems = Number(dbItemsWithCount[0]?.total_count ?? 0)
Expand Down Expand Up @@ -510,20 +505,18 @@ export class ItemService {
const isMovingItemBetweenCollections =
dbItem && this.isMovingItemFromACollectionToAnother(item, dbItem)

console.log('here6')
const [
isDbItemCollectionPublished,
isItemCollectionPublished,
] = await Promise.all([
dbCollection &&
dbCollection.contract_address &&
this.collectionService.isDCLPublished(dbCollection.contract_address),
dbCollection.contract_address &&
this.collectionService.isDCLPublished(dbCollection.contract_address),
isMovingItemBetweenCollections &&
itemCollection &&
itemCollection.contract_address &&
this.collectionService.isDCLPublished(itemCollection.contract_address),
itemCollection &&
itemCollection.contract_address &&
this.collectionService.isDCLPublished(itemCollection.contract_address),
])
console.log('here7')

const isDbItemCollectionOwner =
dbCollection && this.isCollectionOwner(eth_address, dbCollection)
Expand Down
8 changes: 4 additions & 4 deletions src/Item/hashes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('when calculating the hashes of a standard wearable item', () => {
return expect(
calculateItemContentHash(dbItem, dbCollection)
).resolves.toEqual(
'bafkreihtcjnfcahy3nomnhxiuyjyzj2fxzy3eab7ctmxl237nf2vsoqkmu'
'bafkreigblh3xd4r57xvpvokhyhzydmmb5wt6ri7tyf25hpm7flknjkyqma'
)
})
})
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('when calculating the hashes of a standard emote item', () => {
return expect(
calculateItemContentHash(dbItem, dbCollection)
).resolves.toEqual(
'bafkreih6pqxtcmaqfualgyjfydwmmpllu2n34gyipekdcaud47zkrijsli'
'bafkreie2zynwvkky5jxvnyhc2rhhzyyqwdrpmoetcxfaka4zc533adqsoq'
)
})
})
Expand Down Expand Up @@ -174,7 +174,7 @@ describe('when calculating the hashes of a TP item', () => {
return expect(
calculateItemContentHash(dbItem, dbCollection)
).resolves.toEqual(
'0a00e995e0df3736a9a7aa5b7607861f6426239b4acc23f60da69fa3637ae4b8'
'fa107ac8f8a5444454532548b2d906569a275573a7158a6a170f0592f9368313'
)
})
})
Expand Down Expand Up @@ -270,7 +270,7 @@ describe('when calculating the hashes of a standard smart wearable item', () =>
return expect(
calculateItemContentHash(dbItem, dbCollection)
).resolves.toEqual(
'bafkreicvxgq74rvh74ldh4bj2fsxbgitd5gvv3ykan6eox6tjlisqazk2q'
'bafkreidwpzttiygmitkrzgubk3xaiashgvyuqf2u2p47fb7w666rggutzy'
)
})
})
2 changes: 1 addition & 1 deletion src/common/matchers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('matchers', () => {

it('should append the other matchers', () => {
expect(matchers.urn).toBe(
'urn:decentraland:(mainnet|goerli|sepolia|matic|mumbai):(?:collections-thirdparty:[^:|\\s]+:[^:|\\s]+|collections-v2:0x[a-fA-F0-9]{40})'
'urn:decentraland:(mainnet|goerli|sepolia|matic|mumbai|amoy):(?:collections-thirdparty:[^:|\\s]+:[^:|\\s]+|collections-v2:0x[a-fA-F0-9]{40})'
)
})

Expand Down
2 changes: 1 addition & 1 deletion src/common/matchers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// DCL: urn:decentraland:{network}:collections-v2:{contract-address}
// TP: urn:decentraland:{network}:collections-thirdparty:{third-party-name}:{collection-id}(:{item-id})?

const network = '(mainnet|goerli|sepolia|matic|mumbai)'
const network = '(mainnet|goerli|sepolia|matic|mumbai|amoy)'
const address = '0x[a-fA-F0-9]{40}'
const urnSlot = '[^:|\\s]+'
const baseURN = `urn:decentraland:${network}`
Expand Down
Loading

0 comments on commit 2e9b916

Please sign in to comment.