From 6e0d0e85a656850b3d2d1899244269be733652ce Mon Sep 17 00:00:00 2001 From: Maria Carmina <50501033+mariacarmina@users.noreply.github.com> Date: Mon, 4 Nov 2024 15:12:29 +0200 Subject: [PATCH] Add checks for ddo chain id and did. (#1868) --- CodeExamples.md | 2 +- ComputeExamples.md | 4 ++-- src/utils/Assets.ts | 7 +++++++ test/integration/CodeExamples.test.ts | 2 +- test/integration/ComputeExamples.test.ts | 4 ++-- test/integration/ComputeFlow.test.ts | 8 ++++---- test/integration/PublishEditConsume.test.ts | 2 +- test/integration/PublishFlows.test.ts | 2 +- 8 files changed, 19 insertions(+), 12 deletions(-) diff --git a/CodeExamples.md b/CodeExamples.md index e79f5711..c9184b6e 100644 --- a/CodeExamples.md +++ b/CodeExamples.md @@ -167,7 +167,7 @@ Next, we define the metadata that will describe our data asset. This is what we '@context': ['https://w3id.org/did/v1'], id: '', version: '4.1.0', - chainId: 4, + chainId: 8996, nftAddress: '0x0', metadata: { created: '2021-12-20T14:35:20Z', diff --git a/ComputeExamples.md b/ComputeExamples.md index 8440582f..41f5c618 100644 --- a/ComputeExamples.md +++ b/ComputeExamples.md @@ -183,7 +183,7 @@ const DATASET_DDO: DDO = { '@context': ['https://w3id.org/did/v1'], id: 'id:op:efba17455c127a885ec7830d687a8f6e64f5ba559f8506f8723c1f10f05c049c', version: '4.1.0', - chainId: 5, + chainId: 8996, nftAddress: '0x0', metadata: { created: '2021-12-20T14:35:20Z', @@ -219,7 +219,7 @@ const ALGORITHM_DDO: DDO = { '@context': ['https://w3id.org/did/v1'], id: 'did:op:efba17455c127a885ec7830d687a8f6e64f5ba559f8506f8723c1f10f05c049c', version: '4.1.0', - chainId: 5, + chainId: 8996, nftAddress: '0x0', metadata: { created: '2021-12-20T14:35:20Z', diff --git a/src/utils/Assets.ts b/src/utils/Assets.ts index 568c6857..bd1aa7b9 100644 --- a/src/utils/Assets.ts +++ b/src/utils/Assets.ts @@ -153,6 +153,13 @@ export async function createAsset( } const chainID = (await owner.provider.getNetwork()).chainId + if (ddo.chainId !== chainID) { + throw new Error('Chain ID from DDO is different than the configured network.') + } + if (ddo.id) { + throw new Error('DID already filled in.') + } + const config = new ConfigHelper().getConfig(parseInt(String(chainID))) let templateIndex = await calculateActiveTemplateIndex( diff --git a/test/integration/CodeExamples.test.ts b/test/integration/CodeExamples.test.ts index 13c266f7..86c62f80 100644 --- a/test/integration/CodeExamples.test.ts +++ b/test/integration/CodeExamples.test.ts @@ -167,7 +167,7 @@ describe('Marketplace flow tests', async () => { '@context': ['https://w3id.org/did/v1'], id: '', version: '4.1.0', - chainId: 4, + chainId: 8996, nftAddress: '0x0', metadata: { created: '2021-12-20T14:35:20Z', diff --git a/test/integration/ComputeExamples.test.ts b/test/integration/ComputeExamples.test.ts index da931e92..cbfb81b3 100644 --- a/test/integration/ComputeExamples.test.ts +++ b/test/integration/ComputeExamples.test.ts @@ -183,7 +183,7 @@ const DATASET_DDO: DDO = { '@context': ['https://w3id.org/did/v1'], id: 'id:op:efba17455c127a885ec7830d687a8f6e64f5ba559f8506f8723c1f10f05c049c', version: '4.1.0', - chainId: 5, + chainId: 8996, nftAddress: '0x0', metadata: { created: '2021-12-20T14:35:20Z', @@ -219,7 +219,7 @@ const ALGORITHM_DDO: DDO = { '@context': ['https://w3id.org/did/v1'], id: 'did:op:efba17455c127a885ec7830d687a8f6e64f5ba559f8506f8723c1f10f05c049c', version: '4.1.0', - chainId: 5, + chainId: 8996, nftAddress: '0x0', metadata: { created: '2021-12-20T14:35:20Z', diff --git a/test/integration/ComputeFlow.test.ts b/test/integration/ComputeFlow.test.ts index 31558c98..1b5664bc 100644 --- a/test/integration/ComputeFlow.test.ts +++ b/test/integration/ComputeFlow.test.ts @@ -56,7 +56,7 @@ const ddoWithNoTimeout = { '@context': ['https://w3id.org/did/v1'], id: 'did:op:efba17455c127a885ec7830d687a8f6e64f5ba559f8506f8723c1f10f05c049c', version: '4.1.0', - chainId: 4, + chainId: 8996, nftAddress: '0x0', metadata: { created: '2021-12-20T14:35:20Z', @@ -93,7 +93,7 @@ const ddoWith5mTimeout = { '@context': ['https://w3id.org/did/v1'], id: 'did:op:efba17455c127a885ec7830d687a8f6e64f5ba559f8506f8723c1f10f05c049c', version: '4.1.0', - chainId: 4, + chainId: 8996, nftAddress: '0x0', metadata: { created: '2021-12-20T14:35:20Z', @@ -140,7 +140,7 @@ const algoDdoWithNoTimeout = { '@context': ['https://w3id.org/did/v1'], id: 'did:op:efba17455c127a885ec7830d687a8f6e64f5ba559f8506f8723c1f10f05c049c', version: '4.1.0', - chainId: 4, + chainId: 8996, nftAddress: '0x0', metadata: { created: '2021-12-20T14:35:20Z', @@ -182,7 +182,7 @@ const algoDdoWith5mTimeout = { '@context': ['https://w3id.org/did/v1'], id: 'did:op:efba17455c127a885ec7830d687a8f6e64f5ba559f8506f8723c1f10f05c049c', version: '4.1.0', - chainId: 4, + chainId: 8996, nftAddress: '0x0', metadata: { created: '2021-12-20T14:35:20Z', diff --git a/test/integration/PublishEditConsume.test.ts b/test/integration/PublishEditConsume.test.ts index 8e6e66c2..25c3fde0 100644 --- a/test/integration/PublishEditConsume.test.ts +++ b/test/integration/PublishEditConsume.test.ts @@ -102,7 +102,7 @@ const assetDdo = { '@context': ['https://w3id.org/did/v1'], id: 'did:op:efba17455c127a885ec7830d687a8f6e64f5ba559f8506f8723c1f10f05c049c', version: '4.1.0', - chainId: 4, + chainId: 8996, nftAddress: '0x0', metadata: { created: '2021-12-20T14:35:20Z', diff --git a/test/integration/PublishFlows.test.ts b/test/integration/PublishFlows.test.ts index acdf15e6..dc2955e0 100644 --- a/test/integration/PublishFlows.test.ts +++ b/test/integration/PublishFlows.test.ts @@ -56,7 +56,7 @@ describe('Publish tests', async () => { '@context': ['https://w3id.org/did/v1'], id: '', version: '4.1.0', - chainId: 4, + chainId: 8996, nftAddress: '0x0', metadata: { created: '2021-12-20T14:35:20Z',