Skip to content

Commit

Permalink
Add checks for ddo chain id and did. (#1868)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariacarmina authored Nov 4, 2024
1 parent dc64981 commit 6e0d0e8
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CodeExamples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions ComputeExamples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
7 changes: 7 additions & 0 deletions src/utils/Assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/integration/CodeExamples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions test/integration/ComputeExamples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 4 additions & 4 deletions test/integration/ComputeFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion test/integration/PublishEditConsume.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion test/integration/PublishFlows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 6e0d0e8

Please sign in to comment.