Skip to content

Commit

Permalink
merge branch 'develop' into refactor_uploads_table
Browse files Browse the repository at this point in the history
Signed-off-by: Roy Scheeren <[email protected]>
  • Loading branch information
royscheeren committed Dec 16, 2024
2 parents 1153a8b + 6d526bb commit b7caf64
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 7 deletions.
43 changes: 39 additions & 4 deletions apps/envited.ascs.digital/common/asset/createTokenMetadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { TOKEN_TAGS } from '../constants/tokenTags'
import domainMetadata from '../fixtures/domainMetadata.json'
import manifest from '../fixtures/manifest.json'
import manifestLicenseRefCustomCommercialAgreement from '../fixtures/manifestLicenseRefCustomCommercialAgreement.json'
import manifestLicenseRefPolicySmartContract from '../fixtures/manifestLicenseRefPolicySmartContract.json'
import manifestRemoteAssetData from '../fixtures/manifestRemoteAssetData.json'
import * as SUT from './createTokenMetadata'

export const TEST_TOKEN_TAGS = {
ASAM_OPENDRIVE_VERSION: 'ASAM OpenDRIVE 1.6',
}

describe('common/asset/createTokenMetadata', () => {
describe('createTokenMetadata', () => {
it('should extract data from manifest and domainMetadata and create a token metadata object', async () => {
Expand All @@ -15,7 +20,15 @@ describe('common/asset/createTokenMetadata', () => {
isBooleanAmount: true,
name: 'TestfeldNiedersachsen_ALKS_ODR_sample',
description: 'simple hdmap example file on Testfeld Niedersachsen for ALKS scenario',
tags: ['GaiaX', 'ASCS', 'ENVITED-X', 'EVES', 'nft', 'ASAM OpenDRIVE 1.6'],
tags: [
TOKEN_TAGS.GAIA_X,
TOKEN_TAGS.ASCS,
TOKEN_TAGS.ENVITED_X,
TOKEN_TAGS.EVES,
TOKEN_TAGS.NFT,
TEST_TOKEN_TAGS.ASAM_OPENDRIVE_VERSION,
TOKEN_TAGS.THIRD_PARTY_HOSTED,
],
minter: 'MINTER',
creators: ['CREATOR'],
publishers: ['Automotive Solution Center for Simulation e.V.', 'ENVITED-X Data Space'],
Expand Down Expand Up @@ -112,7 +125,15 @@ describe('common/asset/createTokenMetadata', () => {
isBooleanAmount: true,
name: 'TestfeldNiedersachsen_ALKS_ODR_sample',
description: 'simple hdmap example file on Testfeld Niedersachsen for ALKS scenario',
tags: ['GaiaX', 'ASCS', 'ENVITED-X', 'EVES', 'nft', 'ASAM OpenDRIVE 1.6'],
tags: [
TOKEN_TAGS.GAIA_X,
TOKEN_TAGS.ASCS,
TOKEN_TAGS.ENVITED_X,
TOKEN_TAGS.EVES,
TOKEN_TAGS.NFT,
TEST_TOKEN_TAGS.ASAM_OPENDRIVE_VERSION,
TOKEN_TAGS.THIRD_PARTY_HOSTED,
],
minter: 'MINTER',
creators: ['CREATOR'],
publishers: ['Automotive Solution Center for Simulation e.V.', 'ENVITED-X Data Space'],
Expand Down Expand Up @@ -209,7 +230,14 @@ describe('common/asset/createTokenMetadata', () => {
isBooleanAmount: true,
name: 'TestfeldNiedersachsen_ALKS_ODR_sample',
description: 'simple hdmap example file on Testfeld Niedersachsen for ALKS scenario',
tags: ['GaiaX', 'ASCS', 'ENVITED-X', 'EVES', 'nft', 'ASAM OpenDRIVE 1.6'],
tags: [
TOKEN_TAGS.GAIA_X,
TOKEN_TAGS.ASCS,
TOKEN_TAGS.ENVITED_X,
TOKEN_TAGS.EVES,
TOKEN_TAGS.NFT,
TEST_TOKEN_TAGS.ASAM_OPENDRIVE_VERSION,
],
minter: 'MINTER',
creators: ['CREATOR'],
publishers: ['Automotive Solution Center for Simulation e.V.', 'ENVITED-X Data Space'],
Expand Down Expand Up @@ -306,7 +334,14 @@ describe('common/asset/createTokenMetadata', () => {
isBooleanAmount: true,
name: 'TestfeldNiedersachsen_ALKS_ODR_sample',
description: 'simple hdmap example file on Testfeld Niedersachsen for ALKS scenario',
tags: ['GaiaX', 'ASCS', 'ENVITED-X', 'EVES', 'nft', 'ASAM OpenDRIVE 1.6'],
tags: [
TOKEN_TAGS.GAIA_X,
TOKEN_TAGS.ASCS,
TOKEN_TAGS.ENVITED_X,
TOKEN_TAGS.EVES,
TOKEN_TAGS.NFT,
TEST_TOKEN_TAGS.ASAM_OPENDRIVE_VERSION,
],
minter: 'MINTER',
creators: ['CREATOR'],
publishers: ['Automotive Solution Center for Simulation e.V.', 'ENVITED-X Data Space'],
Expand Down
16 changes: 13 additions & 3 deletions apps/envited.ascs.digital/common/asset/createTokenMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { equals } from 'ramda'
import { append, equals } from 'ramda'

import { TOKEN_TAGS } from '../constants/tokenTags'
import { extractFilenameFromPath, formatAssetUri, formatIpfsUri } from './createTokenMetadata.utils'
import { Manifest } from './types'
import { formatManifestLinkPath } from './utils'
import { formatManifestLinkPath, hasManifestThirdPartyLinks } from './utils'

export const createTokenMetadata = ({
asset,
Expand Down Expand Up @@ -44,13 +45,22 @@ export const createTokenMetadata = ({
const version = domainMetadata.data['hdmap:format']['hdmap:version']['@value']
const today = new Date()
const date = today.toISOString().split('T')[0]
const tags = [
TOKEN_TAGS.GAIA_X,
TOKEN_TAGS.ASCS,
TOKEN_TAGS.ENVITED_X,
TOKEN_TAGS.EVES,
TOKEN_TAGS.NFT,
`${formatType} ${version}`,
]
const isThirdPartyHosted = hasManifestThirdPartyLinks(manifest.data)

return {
decimals: 0,
isBooleanAmount: true,
name,
description,
tags: ['GaiaX', 'ASCS', 'ENVITED-X', 'EVES', 'nft', `${formatType} ${version}`],
tags: isThirdPartyHosted ? append(TOKEN_TAGS.THIRD_PARTY_HOSTED)(tags) : tags,
minter,
creators: [creator],
publishers: ['Automotive Solution Center for Simulation e.V.', 'ENVITED-X Data Space'],
Expand Down
15 changes: 15 additions & 0 deletions apps/envited.ascs.digital/common/asset/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import manifest from '../fixtures/manifest.json'
import manifestRemoteAssetData from '../fixtures/manifestRemoteAssetData.json'
import * as SUT from './utils'

describe('common/asset/utils', () => {
Expand Down Expand Up @@ -345,4 +346,18 @@ describe('common/asset/utils', () => {
])
})
})

describe('hasManifestThirdPartyLinks', () => {
it('should return true when there is a external link', () => {
const result = SUT.hasManifestThirdPartyLinks(manifest as any)

expect(result).toEqual(true)
})

it('should return false when there are not external links found', () => {
const result = SUT.hasManifestThirdPartyLinks(manifestRemoteAssetData as any)

expect(result).toEqual(true)
})
})
})
14 changes: 14 additions & 0 deletions apps/envited.ascs.digital/common/asset/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import * as raw from 'multiformats/codecs/raw'
import { Hasher } from 'multiformats/dist/src/hashes/hasher'
import { sha256 } from 'multiformats/hashes/sha2'
import {
any,
append,
concat,
equals,
find,
groupBy,
includes,
is,
isNil,
map,
Expand Down Expand Up @@ -91,6 +94,17 @@ export const getAllManifestLinks = (manifest: Manifest) =>
export const formatManifestLinkPath = replace('./', '')

export const isRemoteUrl = startsWith('https://')
export const isSelfHosted = includes('.envited-x.net')

export const hasManifestThirdPartyLinks = (manifest: Manifest) =>
pipe(
getAllManifestLinks,
map(
(link: ManifestLink) =>
isRemoteUrl(link['manifest:path']['@value']) && !isSelfHosted(link['manifest:path']['@value']),
),
(x: boolean[]) => any(equals(true))(x),
)(manifest)

export const getPathsFromManifestLinks = (links: ManifestLink[]) =>
pipe(
Expand Down
8 changes: 8 additions & 0 deletions apps/envited.ascs.digital/common/constants/tokenTags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const TOKEN_TAGS = {
GAIA_X: 'GaiaX',
ASCS: 'ASCS',
ENVITED_X: 'ENVITED-X',
EVES: 'EVES',
NFT: 'nft',
THIRD_PARTY_HOSTED: 'Third Party Hosted',
}

0 comments on commit b7caf64

Please sign in to comment.