diff --git a/.github/linters/mlc_config.json b/.github/linters/mlc_config.json index d6e565a0..0726ddf0 100644 --- a/.github/linters/mlc_config.json +++ b/.github/linters/mlc_config.json @@ -1,5 +1,12 @@ { - "aliveStatusCodes": [0, 200, 206, 403, 501, 999], + "aliveStatusCodes": [ + 0, + 200, + 206, + 403, + 501, + 999 + ], "replacementPatterns": [ { "pattern": "\" %}", @@ -12,8 +19,11 @@ ], "ignorePatterns": [ { - "pattern": "^https://resolver.cheqd.net/" + "pattern": "^https://resolver.cheqd.net/" + }, + { + "pattern": "^https://twitter.com/" } ], "retryOn429": true -} +} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bef744fb..1634b625 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: steps: - uses: actions/checkout@v4 - + - uses: actions/setup-go@v4 with: go-version-file: ./go.mod @@ -22,7 +22,7 @@ jobs: - name: Install ginkgo run: | go install github.com/onsi/ginkgo/v2/ginkgo@latest - + - name: Run Golang unit tests working-directory: ./tests/unit/ run: ginkgo -r --tags unit --race --randomize-all --randomize-suites --keep-going --trace @@ -55,12 +55,12 @@ jobs: - name: Install ginkgo working-directory: ./.. run: go install github.com/onsi/ginkgo/v2/ginkgo@latest - + - name: Run Ginkgo integration tests working-directory: ./tests/integration/rest run: | ginkgo -r --tags integration --race --randomize-suites --keep-going --trace --junit-report ./report-integration.xml - + - name: Show logs if: failure() working-directory: ./docker/localnet diff --git a/tests/constants/constants.go b/tests/constants/constants.go index f98a084c..61375a3c 100644 --- a/tests/constants/constants.go +++ b/tests/constants/constants.go @@ -74,13 +74,15 @@ var ( ) var ( - ValidMethod = "cheqd" - ValidMainnetNamespace = "mainnet" - ValidTestnetNamespace = "testnet" - ValidIdentifier = "fb53dd05-329b-4614-a3f2-c0a8c7554ee3" - ValidVersionId = "32e0613e-bee4-4ea4-952c-bba3e857fa2a" - ValidServiceId = "service-1" - ValidPubKeyJWK = "{" + + ValidMethod = "cheqd" + ValidMainnetNamespace = "mainnet" + ValidTestnetNamespace = "testnet" + ValidIdentifier = "fb53dd05-329b-4614-a3f2-c0a8c7554ee3" + ValidVersionId = "32e0613e-bee4-4ea4-952c-bba3e857fa2a" + ValidNextVersionId = "3f3111af-dfe6-411f-adc9-02af59716ddb" + ValidPreviousVersionId = "139445af-4281-4453-b05a-ec9a8931c1f9" + ValidServiceId = "service-1" + ValidPubKeyJWK = "{" + "\"crv\":\"Ed25519\"," + "\"kid\":\"_Qq0UL2Fq651Q0Fjd6TvnYE-faHiOpRlPVQcY_-tA4A\"," + "\"kty\":\"OKP\"," + diff --git a/tests/integration/rest/testdata/diddoc/diddoc_uuid_testnet_several_versions.json b/tests/integration/rest/testdata/diddoc/diddoc_uuid_testnet_several_versions.json index 7eb2108a..383104b3 100644 --- a/tests/integration/rest/testdata/diddoc/diddoc_uuid_testnet_several_versions.json +++ b/tests/integration/rest/testdata/diddoc/diddoc_uuid_testnet_several_versions.json @@ -41,6 +41,7 @@ "updated": "2023-03-06T09:59:22Z", "deactivated": true, "versionId": "f790c9b9-4817-4b31-be43-b198e6e18071", + "previousVersionId": "ce298b6f-594b-426e-b431-370d6bc5d3ad", "linkedResourceMetadata": [ { "resourceURI": "did:cheqd:testnet:b5d70adf-31ca-4662-aa10-d3a54cd8f06c/resources/5e16a3f9-7c6e-4b6b-8e28-20f56780ee25", diff --git a/tests/integration/rest/testdata/diddoc/diddoc_uuid_testnet_several_versions_between.json b/tests/integration/rest/testdata/diddoc/diddoc_uuid_testnet_several_versions_between.json index c1207b04..7e81d0ec 100644 --- a/tests/integration/rest/testdata/diddoc/diddoc_uuid_testnet_several_versions_between.json +++ b/tests/integration/rest/testdata/diddoc/diddoc_uuid_testnet_several_versions_between.json @@ -41,6 +41,8 @@ "updated": "2023-03-06T09:39:48Z", "deactivated": true, "versionId": "ce298b6f-594b-426e-b431-370d6bc5d3ad", + "nextVersionId": "f790c9b9-4817-4b31-be43-b198e6e18071", + "previousVersionId": "0ce23d04-5b67-4ea6-a315-788588e53f4e", "linkedResourceMetadata": [ { "resourceURI": "did:cheqd:testnet:b5d70adf-31ca-4662-aa10-d3a54cd8f06c/resources/5e16a3f9-7c6e-4b6b-8e28-20f56780ee25", diff --git a/tests/integration/rest/testdata/query/diddoc/diddoc_version_did.json b/tests/integration/rest/testdata/query/diddoc/diddoc_version_did.json index 3430e79f..881c8c8d 100644 --- a/tests/integration/rest/testdata/query/diddoc/diddoc_version_did.json +++ b/tests/integration/rest/testdata/query/diddoc/diddoc_version_did.json @@ -30,6 +30,7 @@ "didDocumentMetadata": { "created": "2023-03-06T09:36:55Z", "deactivated": true, - "versionId": "0ce23d04-5b67-4ea6-a315-788588e53f4e" + "versionId": "0ce23d04-5b67-4ea6-a315-788588e53f4e", + "nextVersionId": "ce298b6f-594b-426e-b431-370d6bc5d3ad" } } diff --git a/tests/integration/rest/testdata/query/diddoc_common/metadata/version_time.json b/tests/integration/rest/testdata/query/diddoc_common/metadata/version_time.json index 34778999..1ce0b653 100644 --- a/tests/integration/rest/testdata/query/diddoc_common/metadata/version_time.json +++ b/tests/integration/rest/testdata/query/diddoc_common/metadata/version_time.json @@ -14,6 +14,8 @@ "updated": "2023-03-06T09:39:48Z", "deactivated": true, "versionId": "ce298b6f-594b-426e-b431-370d6bc5d3ad", + "nextVersionId": "f790c9b9-4817-4b31-be43-b198e6e18071", + "previousVersionId": "0ce23d04-5b67-4ea6-a315-788588e53f4e", "linkedResourceMetadata": [ { "resourceURI": "did:cheqd:testnet:b5d70adf-31ca-4662-aa10-d3a54cd8f06c/resources/5e16a3f9-7c6e-4b6b-8e28-20f56780ee25", diff --git a/tests/integration/rest/testdata/query/diddoc_common/version_id/transform_key.json b/tests/integration/rest/testdata/query/diddoc_common/version_id/transform_key.json index 58d5b79b..9d9dea2e 100644 --- a/tests/integration/rest/testdata/query/diddoc_common/version_id/transform_key.json +++ b/tests/integration/rest/testdata/query/diddoc_common/version_id/transform_key.json @@ -45,6 +45,8 @@ "updated": "2023-03-06T09:39:48Z", "deactivated": true, "versionId": "ce298b6f-594b-426e-b431-370d6bc5d3ad", + "nextVersionId": "f790c9b9-4817-4b31-be43-b198e6e18071", + "previousVersionId": "0ce23d04-5b67-4ea6-a315-788588e53f4e", "linkedResourceMetadata": [ { "resourceURI": "did:cheqd:testnet:b5d70adf-31ca-4662-aa10-d3a54cd8f06c/resources/5e16a3f9-7c6e-4b6b-8e28-20f56780ee25", diff --git a/tests/integration/rest/testdata/query/diddoc_common/version_id/version_time.json b/tests/integration/rest/testdata/query/diddoc_common/version_id/version_time.json index 08438f02..09c62f3e 100644 --- a/tests/integration/rest/testdata/query/diddoc_common/version_id/version_time.json +++ b/tests/integration/rest/testdata/query/diddoc_common/version_id/version_time.json @@ -41,6 +41,8 @@ "updated": "2023-03-06T09:39:48Z", "deactivated": true, "versionId": "ce298b6f-594b-426e-b431-370d6bc5d3ad", + "nextVersionId": "f790c9b9-4817-4b31-be43-b198e6e18071", + "previousVersionId": "0ce23d04-5b67-4ea6-a315-788588e53f4e", "linkedResourceMetadata": [ { "resourceURI": "did:cheqd:testnet:b5d70adf-31ca-4662-aa10-d3a54cd8f06c/resources/5e16a3f9-7c6e-4b6b-8e28-20f56780ee25", diff --git a/tests/integration/rest/testdata/query/diddoc_common/version_id/version_time_&_transform_key.json b/tests/integration/rest/testdata/query/diddoc_common/version_id/version_time_&_transform_key.json index a510aa9e..14bbf9f2 100644 --- a/tests/integration/rest/testdata/query/diddoc_common/version_id/version_time_&_transform_key.json +++ b/tests/integration/rest/testdata/query/diddoc_common/version_id/version_time_&_transform_key.json @@ -41,6 +41,8 @@ "updated": "2023-03-06T09:39:48Z", "deactivated": true, "versionId": "ce298b6f-594b-426e-b431-370d6bc5d3ad", + "nextVersionId": "f790c9b9-4817-4b31-be43-b198e6e18071", + "previousVersionId": "0ce23d04-5b67-4ea6-a315-788588e53f4e", "linkedResourceMetadata": [ { "resourceURI": "did:cheqd:testnet:b5d70adf-31ca-4662-aa10-d3a54cd8f06c/resources/5e16a3f9-7c6e-4b6b-8e28-20f56780ee25", diff --git a/tests/integration/rest/testdata/query/version_time/diddoc_version_time_date_did.json b/tests/integration/rest/testdata/query/version_time/diddoc_version_time_date_did.json index 70c1112d..11d3ae6d 100644 --- a/tests/integration/rest/testdata/query/version_time/diddoc_version_time_date_did.json +++ b/tests/integration/rest/testdata/query/version_time/diddoc_version_time_date_did.json @@ -41,6 +41,7 @@ "updated": "2023-03-06T09:59:22Z", "deactivated": true, "versionId": "f790c9b9-4817-4b31-be43-b198e6e18071", + "previousVersionId": "ce298b6f-594b-426e-b431-370d6bc5d3ad", "linkedResourceMetadata": [ { "resourceURI": "did:cheqd:testnet:b5d70adf-31ca-4662-aa10-d3a54cd8f06c/resources/5e16a3f9-7c6e-4b6b-8e28-20f56780ee25", diff --git a/tests/integration/rest/testdata/query/version_time/diddoc_version_time_did.json b/tests/integration/rest/testdata/query/version_time/diddoc_version_time_did.json index 14888767..763a0f59 100644 --- a/tests/integration/rest/testdata/query/version_time/diddoc_version_time_did.json +++ b/tests/integration/rest/testdata/query/version_time/diddoc_version_time_did.json @@ -41,6 +41,8 @@ "updated": "2023-03-06T09:39:48Z", "deactivated": true, "versionId": "ce298b6f-594b-426e-b431-370d6bc5d3ad", + "nextVersionId": "f790c9b9-4817-4b31-be43-b198e6e18071", + "previousVersionId": "0ce23d04-5b67-4ea6-a315-788588e53f4e", "linkedResourceMetadata": [ { "resourceURI": "did:cheqd:testnet:b5d70adf-31ca-4662-aa10-d3a54cd8f06c/resources/5e16a3f9-7c6e-4b6b-8e28-20f56780ee25", diff --git a/tests/unit/diddoc/common/dereferencing_content_stream_test.go b/tests/unit/diddoc/common/dereferencing_content_stream_test.go index 5834fbf0..b36d127c 100644 --- a/tests/unit/diddoc/common/dereferencing_content_stream_test.go +++ b/tests/unit/diddoc/common/dereferencing_content_stream_test.go @@ -5,52 +5,52 @@ package common import ( "time" + utils "github.com/cheqd/did-resolver/tests/unit" "github.com/cheqd/did-resolver/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - utils "github.com/cheqd/did-resolver/tests/unit" ) var _ = Describe("DereferencingContentStream Find before time", func() { var ( versionList types.DereferencedResourceList - t0 = utils.MustParseDate("2021-08-23T08:59:59Z") - t1 = utils.MustParseDate("2021-08-23T09:00:00Z") - t1_2 = utils.MustParseDate("2021-08-23T09:30:01Z") - t2 = utils.MustParseDate("2021-08-23T09:40:00Z") - t2_3 = utils.MustParseDate("2021-08-23T09:40:01Z") - t3 = utils.MustParseDate("2021-08-23T09:50:00Z") - t3_ = utils.MustParseDate("2021-08-23T09:50:01Z") + t0 = utils.MustParseDate("2021-08-23T08:59:59Z") + t1 = utils.MustParseDate("2021-08-23T09:00:00Z") + t1_2 = utils.MustParseDate("2021-08-23T09:30:01Z") + t2 = utils.MustParseDate("2021-08-23T09:40:00Z") + t2_3 = utils.MustParseDate("2021-08-23T09:40:01Z") + t3 = utils.MustParseDate("2021-08-23T09:50:00Z") + t3_ = utils.MustParseDate("2021-08-23T09:50:01Z") ) BeforeEach(func() { versionList = types.DereferencedResourceList{ { - Created: &t1, - ResourceId: "r1", + Created: &t1, + ResourceId: "r1", CollectionId: "c1", - Name: "name1", + Name: "name1", ResourceType: "type1", - Version: "v1", - Checksum: "checksum1", + Version: "v1", + Checksum: "checksum1", }, { - Created: &t2, - ResourceId: "r2", + Created: &t2, + ResourceId: "r2", CollectionId: "c2", - Name: "name2", + Name: "name2", ResourceType: "type2", - Version: "v2", - Checksum: "checksum2", + Version: "v2", + Checksum: "checksum2", }, { - Created: &t3, - ResourceId: "r3", + Created: &t3, + ResourceId: "r3", CollectionId: "c3", - Name: "name2", + Name: "name2", ResourceType: "type2", - Version: "v2", - Checksum: "checksum3", + Version: "v2", + Checksum: "checksum3", }, } }) diff --git a/tests/unit/diddoc/common/did_doc_metadata_list_test.go b/tests/unit/diddoc/common/did_doc_metadata_list_test.go index a66d91ee..def76aad 100644 --- a/tests/unit/diddoc/common/did_doc_metadata_list_test.go +++ b/tests/unit/diddoc/common/did_doc_metadata_list_test.go @@ -31,7 +31,7 @@ var _ = Describe("DidDocMetadataList", func() { Deactivated: false, Created: &tcreated, Updated: nil, - Resources: []types.DereferencedResource{ + Resources: []types.DereferencedResource{ { Created: &t1_2, }, @@ -113,7 +113,6 @@ var _ = Describe("DidDocMetadataList", func() { Context("GetResourcesBeforeNextVersion", func() { It("should return empty list of resources for the first version", func() { - Expect(versionList.GetResourcesBeforeNextVersion("1")).To(Equal(types.DereferencedResourceList{})) }) It("should return resource created before next version", func() { diff --git a/tests/unit/diddoc/common/did_doc_metadata_test.go b/tests/unit/diddoc/common/did_doc_metadata_test.go index 27d1ef7f..e4a07ebc 100644 --- a/tests/unit/diddoc/common/did_doc_metadata_test.go +++ b/tests/unit/diddoc/common/did_doc_metadata_test.go @@ -24,11 +24,13 @@ var _ = Describe("Test NewResolutionDIDDocMetadata function", func() { } expectedResult := types.ResolutionDidDocMetadata{ - Created: nil, - Updated: nil, - Deactivated: false, - VersionId: testconstants.ValidIdentifier, - Resources: []types.DereferencedResource{testconstants.ValidMetadataResource}, + Created: nil, + Updated: nil, + Deactivated: false, + NextVersionId: "", + PreviousVersionId: "", + VersionId: testconstants.ValidIdentifier, + Resources: []types.DereferencedResource{testconstants.ValidMetadataResource}, } result := types.NewResolutionDidDocMetadata(testconstants.ExistentDid, metadata, resources) @@ -37,17 +39,21 @@ var _ = Describe("Test NewResolutionDIDDocMetadata function", func() { It("can create the structure without resource", func() { metadata := &didTypes.Metadata{ - Created: testconstants.NotEmptyTimestamp, - Updated: testconstants.NotEmptyTimestamp, - VersionId: testconstants.ValidVersionId, - Deactivated: false, + Created: testconstants.NotEmptyTimestamp, + Updated: testconstants.NotEmptyTimestamp, + VersionId: testconstants.ValidVersionId, + NextVersionId: testconstants.ValidNextVersionId, + PreviousVersionId: testconstants.ValidPreviousVersionId, + Deactivated: false, } expectedResult := types.ResolutionDidDocMetadata{ - Created: &testconstants.NotEmptyTime, - Updated: &testconstants.NotEmptyTime, - VersionId: testconstants.ValidVersionId, - Deactivated: false, + Created: &testconstants.NotEmptyTime, + Updated: &testconstants.NotEmptyTime, + VersionId: testconstants.ValidVersionId, + NextVersionId: testconstants.ValidNextVersionId, + PreviousVersionId: testconstants.ValidPreviousVersionId, + Deactivated: false, } result := types.NewResolutionDidDocMetadata(testconstants.ExistentDid, metadata, []*resourceTypes.Metadata{}) diff --git a/tests/unit/diddoc/ledger/query_all_did_doc_versions_ledger_service_test.go b/tests/unit/diddoc/ledger/query_all_did_doc_versions_ledger_service_test.go index 198d3e71..757a8a80 100644 --- a/tests/unit/diddoc/ledger/query_all_did_doc_versions_ledger_service_test.go +++ b/tests/unit/diddoc/ledger/query_all_did_doc_versions_ledger_service_test.go @@ -35,8 +35,10 @@ var _ = DescribeTable("Test QueryAllDidDocVersionsMetadata method", func(testCas expectedDidDocVersions: &types.DereferencedDidVersionsList{ Versions: []types.ResolutionDidDocMetadata{ { - Created: &testconstants.ValidCreated, - VersionId: testconstants.ValidMetadata.VersionId, + Created: &testconstants.ValidCreated, + VersionId: testconstants.ValidMetadata.VersionId, + NextVersionId: "", + PreviousVersionId: "", }, }, }, diff --git a/tests/unit/diddoc/request/common_negative_metadata_test.go b/tests/unit/diddoc/request/common_negative_metadata_test.go index ef346237..11c5f2c4 100644 --- a/tests/unit/diddoc/request/common_negative_metadata_test.go +++ b/tests/unit/diddoc/request/common_negative_metadata_test.go @@ -63,7 +63,7 @@ var _ = DescribeTable("Negative tests for mixed cases", func(testCase ResourceMe }, }, ContentStream: &types.DereferencedResourceListStruct{}, - Metadata: &types.ResolutionDidDocMetadata{}, + Metadata: &types.ResolutionDidDocMetadata{}, }, expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, @@ -87,7 +87,7 @@ var _ = DescribeTable("Negative tests for mixed cases", func(testCase ResourceMe }, }, ContentStream: &types.DereferencedResourceListStruct{}, - Metadata: &types.ResolutionDidDocMetadata{}, + Metadata: &types.ResolutionDidDocMetadata{}, }, expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, @@ -111,7 +111,7 @@ var _ = DescribeTable("Negative tests for mixed cases", func(testCase ResourceMe }, }, ContentStream: &types.DereferencedResourceListStruct{}, - Metadata: &types.ResolutionDidDocMetadata{}, + Metadata: &types.ResolutionDidDocMetadata{}, }, expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, @@ -135,7 +135,7 @@ var _ = DescribeTable("Negative tests for mixed cases", func(testCase ResourceMe }, }, ContentStream: &types.DereferencedResourceListStruct{}, - Metadata: &types.ResolutionDidDocMetadata{}, + Metadata: &types.ResolutionDidDocMetadata{}, }, expectedError: types.NewInvalidDidError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, @@ -159,7 +159,7 @@ var _ = DescribeTable("Negative tests for mixed cases", func(testCase ResourceMe }, }, ContentStream: &types.DereferencedResourceListStruct{}, - Metadata: &types.ResolutionDidDocMetadata{}, + Metadata: &types.ResolutionDidDocMetadata{}, }, expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, @@ -183,7 +183,7 @@ var _ = DescribeTable("Negative tests for mixed cases", func(testCase ResourceMe }, }, ContentStream: &types.DereferencedResourceListStruct{}, - Metadata: &types.ResolutionDidDocMetadata{}, + Metadata: &types.ResolutionDidDocMetadata{}, }, expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, diff --git a/tests/unit/diddoc/request/common_positive_metadata_test.go b/tests/unit/diddoc/request/common_positive_metadata_test.go index ea2bc8a8..70976eae 100644 --- a/tests/unit/diddoc/request/common_positive_metadata_test.go +++ b/tests/unit/diddoc/request/common_positive_metadata_test.go @@ -50,7 +50,7 @@ var _ = DescribeTable("Tests for mixed DidDoc and resource cases", func(testCase didURL: fmt.Sprintf( "/1.0/identifiers/%s?versionId=%s&versionTime=%s&resourceId=%s&resourceMetadata=true", testconstants.ValidDid, - VersionId1, + VersionId1, DidDocUpdated.Format(time.RFC3339Nano), ResourceIdName1, ), @@ -78,7 +78,7 @@ var _ = DescribeTable("Tests for mixed DidDoc and resource cases", func(testCase didURL: fmt.Sprintf( "/1.0/identifiers/%s?versionId=%s&versionTime=%s&resourceId=%s&resourceCollectionId=%s&resourceMetadata=true", testconstants.ValidDid, - VersionId1, + VersionId1, DidDocUpdated.Format(time.RFC3339Nano), ResourceIdName1, ResourceName1.Metadata.CollectionId, @@ -107,7 +107,7 @@ var _ = DescribeTable("Tests for mixed DidDoc and resource cases", func(testCase didURL: fmt.Sprintf( "/1.0/identifiers/%s?versionId=%s&versionTime=%s&resourceCollectionId=%s&resourceMetadata=true", testconstants.ValidDid, - VersionId1, + VersionId1, DidDocUpdated.Format(time.RFC3339Nano), ResourceName1.Metadata.CollectionId, ), @@ -139,7 +139,7 @@ var _ = DescribeTable("Tests for mixed DidDoc and resource cases", func(testCase didURL: fmt.Sprintf( "/1.0/identifiers/%s?versionId=%s&versionTime=%s&resourceId=%s&resourceCollectionId=%s&resourceName=%s&resourceMetadata=true", testconstants.ValidDid, - VersionId1, + VersionId1, DidDocUpdated.Format(time.RFC3339Nano), ResourceIdName1, ResourceName1.Metadata.CollectionId, @@ -169,7 +169,7 @@ var _ = DescribeTable("Tests for mixed DidDoc and resource cases", func(testCase didURL: fmt.Sprintf( "/1.0/identifiers/%s?versionId=%s&versionTime=%s&resourceId=%s&resourceCollectionId=%s&resourceName=%s&resourceType=%s&resourceMetadata=true", testconstants.ValidDid, - VersionId1, + VersionId1, DidDocUpdated.Format(time.RFC3339Nano), ResourceIdName1, ResourceName1.Metadata.CollectionId, @@ -200,7 +200,7 @@ var _ = DescribeTable("Tests for mixed DidDoc and resource cases", func(testCase didURL: fmt.Sprintf( "/1.0/identifiers/%s?versionId=%s&versionTime=%s&resourceId=%s&resourceCollectionId=%s&resourceName=%s&resourceType=%s&resourceVersion=%s&resourceMetadata=true", testconstants.ValidDid, - VersionId1, + VersionId1, DidDocUpdated.Format(time.RFC3339Nano), ResourceIdName1, ResourceName1.Metadata.CollectionId, @@ -232,7 +232,7 @@ var _ = DescribeTable("Tests for mixed DidDoc and resource cases", func(testCase didURL: fmt.Sprintf( "/1.0/identifiers/%s?versionId=%s&versionTime=%s&resourceId=%s&resourceCollectionId=%s&resourceName=%s&resourceType=%s&resourceVersion=%s&resourceVersionTime=%s&resourceMetadata=true", testconstants.ValidDid, - VersionId1, + VersionId1, DidDocUpdated.Format(time.RFC3339Nano), ResourceIdName1, ResourceName1.Metadata.CollectionId, @@ -265,7 +265,7 @@ var _ = DescribeTable("Tests for mixed DidDoc and resource cases", func(testCase didURL: fmt.Sprintf( "/1.0/identifiers/%s?versionId=%s&versionTime=%s&resourceId=%s&resourceCollectionId=%s&resourceName=%s&resourceType=%s&resourceVersion=%s&resourceVersionTime=%s&checksum=%s&resourceMetadata=true", testconstants.ValidDid, - VersionId1, + VersionId1, DidDocUpdated.Format(time.RFC3339Nano), ResourceIdName1, ResourceName1.Metadata.CollectionId, @@ -299,7 +299,7 @@ var _ = DescribeTable("Tests for mixed DidDoc and resource cases", func(testCase didURL: fmt.Sprintf( "/1.0/identifiers/%s?versionId=%s&versionTime=%s&resourceVersionTime=%s&resourceMetadata=true", testconstants.ValidDid, - VersionId1, + VersionId1, DidDocUpdated.Format(time.RFC3339Nano), Resource2Created.Format(time.RFC3339), ), @@ -317,7 +317,8 @@ var _ = DescribeTable("Tests for mixed DidDoc and resource cases", func(testCase []*resourceTypes.Metadata{ ResourceName2.Metadata, ResourceName12.Metadata, - ResourceName1.Metadata}, + ResourceName1.Metadata, + }, ), Metadata: &types.ResolutionDidDocMetadata{}, }, diff --git a/tests/unit/diddoc/request/diddoc_negative_cases_test.go b/tests/unit/diddoc/request/diddoc_negative_cases_test.go index 206ef03f..418083bc 100644 --- a/tests/unit/diddoc/request/diddoc_negative_cases_test.go +++ b/tests/unit/diddoc/request/diddoc_negative_cases_test.go @@ -9,13 +9,13 @@ import ( "net/http/httptest" "time" - "github.com/google/uuid" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" didDocService "github.com/cheqd/did-resolver/services/diddoc" testconstants "github.com/cheqd/did-resolver/tests/constants" utils "github.com/cheqd/did-resolver/tests/unit" "github.com/cheqd/did-resolver/types" + "github.com/google/uuid" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) var _ = DescribeTable("Test Query handlers with versionId and versionTime params", func(testCase QueriesDIDDocTestCase) { diff --git a/tests/unit/diddoc/request/diddoc_positive_cases_test.go b/tests/unit/diddoc/request/diddoc_positive_cases_test.go index 63bc792e..3f996277 100644 --- a/tests/unit/diddoc/request/diddoc_positive_cases_test.go +++ b/tests/unit/diddoc/request/diddoc_positive_cases_test.go @@ -11,7 +11,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - + resourceTypes "github.com/cheqd/cheqd-node/api/v2/cheqd/resource/v2" didDocService "github.com/cheqd/did-resolver/services/diddoc" testconstants "github.com/cheqd/did-resolver/tests/constants" @@ -42,7 +42,6 @@ var _ = DescribeTable("Test Query handlers with versionId and versionTime params Expect(expectedContentType).To(Equal(resolutionResult.ResolutionMetadata.ContentType)) Expect(expectedDIDResolution.ResolutionMetadata.DidProperties).To(Equal(resolutionResult.ResolutionMetadata.DidProperties)) Expect(expectedContentType).To(Equal(types.ContentType(rec.Header().Get("Content-Type")))) - }, // Positive cases @@ -90,7 +89,8 @@ var _ = DescribeTable("Test Query handlers with versionId and versionTime params ResourceType1.Metadata, ResourceName2.Metadata, ResourceName12.Metadata, - ResourceName1.Metadata}, + ResourceName1.Metadata, + }, ), }, expectedError: nil, @@ -140,7 +140,8 @@ var _ = DescribeTable("Test Query handlers with versionId and versionTime params ResourceType1.Metadata, ResourceName2.Metadata, ResourceName12.Metadata, - ResourceName1.Metadata}, + ResourceName1.Metadata, + }, ), }, expectedError: nil, @@ -188,9 +189,10 @@ var _ = DescribeTable("Test Query handlers with versionId and versionTime params ResourceType2.Metadata, ResourceType12.Metadata, ResourceType1.Metadata, - ResourceName2.Metadata, - ResourceName12.Metadata, - ResourceName1.Metadata}, + ResourceName2.Metadata, + ResourceName12.Metadata, + ResourceName1.Metadata, + }, ), }, expectedError: nil, diff --git a/tests/unit/diddoc/request/diddoc_service_params_test.go b/tests/unit/diddoc/request/diddoc_service_params_test.go index 5adc0a48..b4e2701d 100644 --- a/tests/unit/diddoc/request/diddoc_service_params_test.go +++ b/tests/unit/diddoc/request/diddoc_service_params_test.go @@ -8,12 +8,12 @@ import ( "net/http/httptest" "time" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" didDocService "github.com/cheqd/did-resolver/services/diddoc" testconstants "github.com/cheqd/did-resolver/tests/constants" utils "github.com/cheqd/did-resolver/tests/unit" "github.com/cheqd/did-resolver/types" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) var _ = DescribeTable("Test Query handlers with service and relativeRef params", func(testCase QueriesDIDDocTestCase) { diff --git a/tests/unit/diddoc/request/resource_negative_data_test.go b/tests/unit/diddoc/request/resource_negative_data_test.go index 12623a63..839b9cc4 100644 --- a/tests/unit/diddoc/request/resource_negative_data_test.go +++ b/tests/unit/diddoc/request/resource_negative_data_test.go @@ -36,12 +36,12 @@ var _ = DescribeTable("Test resource negative cases. Data returning case", func( ResourceTestCase{ didURL: fmt.Sprintf( "/1.0/identifiers/%s?resourceId=%s", - testconstants.ValidDid, + testconstants.ValidDid, uuid.New().String(), ), - resolutionType: types.DIDJSONLD, + resolutionType: types.DIDJSONLD, expectedResource: nil, - expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), + expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, ), Entry( @@ -49,12 +49,12 @@ var _ = DescribeTable("Test resource negative cases. Data returning case", func( ResourceTestCase{ didURL: fmt.Sprintf( "/1.0/identifiers/%s?resourceId=%s", - testconstants.ValidDid, + testconstants.ValidDid, "SomeNotUUID", ), - resolutionType: types.DIDJSONLD, + resolutionType: types.DIDJSONLD, expectedResource: nil, - expectedError: types.NewInvalidDidUrlError(testconstants.ValidDid, types.DIDJSONLD, nil, true), + expectedError: types.NewInvalidDidUrlError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, ), Entry( @@ -62,12 +62,12 @@ var _ = DescribeTable("Test resource negative cases. Data returning case", func( ResourceTestCase{ didURL: fmt.Sprintf( "/1.0/identifiers/%s?resourceVersionTime=%s", - testconstants.ValidDid, + testconstants.ValidDid, "SomeNotUUID", ), - resolutionType: types.DIDJSONLD, + resolutionType: types.DIDJSONLD, expectedResource: nil, - expectedError: types.NewInvalidDidUrlError(testconstants.ValidDid, types.DIDJSONLD, nil, true), + expectedError: types.NewInvalidDidUrlError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, ), Entry( @@ -78,9 +78,9 @@ var _ = DescribeTable("Test resource negative cases. Data returning case", func( testconstants.ValidDid, uuid.New().String(), ), - resolutionType: types.DIDJSONLD, + resolutionType: types.DIDJSONLD, expectedResource: nil, - expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), + expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, ), Entry( @@ -91,9 +91,9 @@ var _ = DescribeTable("Test resource negative cases. Data returning case", func( testconstants.ValidDid, "NotExistentType", ), - resolutionType: types.DIDJSONLD, + resolutionType: types.DIDJSONLD, expectedResource: nil, - expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), + expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, ), Entry( @@ -104,9 +104,9 @@ var _ = DescribeTable("Test resource negative cases. Data returning case", func( testconstants.ValidDid, "NotExistentName", ), - resolutionType: types.DIDJSONLD, + resolutionType: types.DIDJSONLD, expectedResource: nil, - expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), + expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, ), Entry( @@ -117,9 +117,9 @@ var _ = DescribeTable("Test resource negative cases. Data returning case", func( testconstants.ValidDid, "NotExistentVersion", ), - resolutionType: types.DIDJSONLD, + resolutionType: types.DIDJSONLD, expectedResource: nil, - expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), + expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, ), Entry( @@ -131,9 +131,9 @@ var _ = DescribeTable("Test resource negative cases. Data returning case", func( ResourceIdName1, "wrongChecksum", ), - resolutionType: types.DIDJSONLD, + resolutionType: types.DIDJSONLD, expectedResource: nil, - expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), + expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, ), Entry( @@ -144,9 +144,9 @@ var _ = DescribeTable("Test resource negative cases. Data returning case", func( testconstants.ValidDid, DidDocBeforeCreated.Format(time.RFC3339), ), - resolutionType: types.DIDJSONLD, + resolutionType: types.DIDJSONLD, expectedResource: nil, - expectedError: types.NewRepresentationNotSupportedError(testconstants.ValidDid, types.DIDJSONLD, nil, true), + expectedError: types.NewRepresentationNotSupportedError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, ), Entry( @@ -157,9 +157,9 @@ var _ = DescribeTable("Test resource negative cases. Data returning case", func( testconstants.ValidDid, ResourceType1.Metadata.ResourceType, ), - resolutionType: types.DIDJSONLD, + resolutionType: types.DIDJSONLD, expectedResource: nil, - expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), + expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, ), Entry( @@ -170,9 +170,9 @@ var _ = DescribeTable("Test resource negative cases. Data returning case", func( testconstants.ValidDid, ResourceType2.Metadata.Name, ), - resolutionType: types.DIDJSONLD, + resolutionType: types.DIDJSONLD, expectedResource: nil, - expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), + expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, ), -) \ No newline at end of file +) diff --git a/tests/unit/diddoc/request/resource_negative_metadata_test.go b/tests/unit/diddoc/request/resource_negative_metadata_test.go index c90a653c..d490c1b6 100644 --- a/tests/unit/diddoc/request/resource_negative_metadata_test.go +++ b/tests/unit/diddoc/request/resource_negative_metadata_test.go @@ -49,7 +49,7 @@ var _ = DescribeTable("Test resource negative cases with Metadata field", func(t ResourceMetadataTestCase{ didURL: fmt.Sprintf( "/1.0/identifiers/%s?resourceId=%s&resourceMetadata=true", - testconstants.ValidDid, + testconstants.ValidDid, uuid.New().String(), ), resolutionType: types.DIDJSONLD, @@ -62,7 +62,7 @@ var _ = DescribeTable("Test resource negative cases with Metadata field", func(t }, }, ContentStream: &types.DereferencedResourceListStruct{}, - Metadata: &types.ResolutionDidDocMetadata{}, + Metadata: &types.ResolutionDidDocMetadata{}, }, expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, @@ -72,7 +72,7 @@ var _ = DescribeTable("Test resource negative cases with Metadata field", func(t ResourceMetadataTestCase{ didURL: fmt.Sprintf( "/1.0/identifiers/%s?resourceId=%s&resourceMetadata=true", - testconstants.ValidDid, + testconstants.ValidDid, "SomeNotUUID", ), resolutionType: types.DIDJSONLD, @@ -85,7 +85,7 @@ var _ = DescribeTable("Test resource negative cases with Metadata field", func(t }, }, ContentStream: &types.DereferencedResourceListStruct{}, - Metadata: &types.ResolutionDidDocMetadata{}, + Metadata: &types.ResolutionDidDocMetadata{}, }, expectedError: types.NewInvalidDidUrlError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, @@ -95,7 +95,7 @@ var _ = DescribeTable("Test resource negative cases with Metadata field", func(t ResourceMetadataTestCase{ didURL: fmt.Sprintf( "/1.0/identifiers/%s?resourceVersionTime=%s&resourceMetadata=true", - testconstants.ValidDid, + testconstants.ValidDid, "SomeNotUUID", ), resolutionType: types.DIDJSONLD, @@ -108,7 +108,7 @@ var _ = DescribeTable("Test resource negative cases with Metadata field", func(t }, }, ContentStream: &types.DereferencedResourceListStruct{}, - Metadata: &types.ResolutionDidDocMetadata{}, + Metadata: &types.ResolutionDidDocMetadata{}, }, expectedError: types.NewInvalidDidUrlError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, @@ -131,7 +131,7 @@ var _ = DescribeTable("Test resource negative cases with Metadata field", func(t }, }, ContentStream: &types.DereferencedResourceListStruct{}, - Metadata: &types.ResolutionDidDocMetadata{}, + Metadata: &types.ResolutionDidDocMetadata{}, }, expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, @@ -154,7 +154,7 @@ var _ = DescribeTable("Test resource negative cases with Metadata field", func(t }, }, ContentStream: &types.DereferencedResourceListStruct{}, - Metadata: &types.ResolutionDidDocMetadata{}, + Metadata: &types.ResolutionDidDocMetadata{}, }, expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, @@ -177,7 +177,7 @@ var _ = DescribeTable("Test resource negative cases with Metadata field", func(t }, }, ContentStream: &types.DereferencedResourceListStruct{}, - Metadata: &types.ResolutionDidDocMetadata{}, + Metadata: &types.ResolutionDidDocMetadata{}, }, expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, @@ -200,7 +200,7 @@ var _ = DescribeTable("Test resource negative cases with Metadata field", func(t }, }, ContentStream: &types.DereferencedResourceListStruct{}, - Metadata: &types.ResolutionDidDocMetadata{}, + Metadata: &types.ResolutionDidDocMetadata{}, }, expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, @@ -224,7 +224,7 @@ var _ = DescribeTable("Test resource negative cases with Metadata field", func(t }, }, ContentStream: &types.DereferencedResourceListStruct{}, - Metadata: &types.ResolutionDidDocMetadata{}, + Metadata: &types.ResolutionDidDocMetadata{}, }, expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, @@ -247,9 +247,9 @@ var _ = DescribeTable("Test resource negative cases with Metadata field", func(t }, }, ContentStream: &types.DereferencedResourceListStruct{}, - Metadata: &types.ResolutionDidDocMetadata{}, + Metadata: &types.ResolutionDidDocMetadata{}, }, expectedError: types.NewNotFoundError(testconstants.ValidDid, types.DIDJSONLD, nil, true), }, ), -) \ No newline at end of file +) diff --git a/tests/unit/diddoc/request/resources_positive_cases_metadata_test.go b/tests/unit/diddoc/request/resources_positive_cases_metadata_test.go index d098a31d..2ec9887a 100644 --- a/tests/unit/diddoc/request/resources_positive_cases_metadata_test.go +++ b/tests/unit/diddoc/request/resources_positive_cases_metadata_test.go @@ -62,7 +62,7 @@ var _ = DescribeTable("Test resource positive cases with Metadata field", func(t ResourceMetadataTestCase{ didURL: fmt.Sprintf( "/1.0/identifiers/%s?resourceId=%s&resourceMetadata=true", - testconstants.ValidDid, + testconstants.ValidDid, ResourceIdName1, ), resolutionType: types.DIDJSONLD, @@ -315,7 +315,8 @@ var _ = DescribeTable("Test resource positive cases with Metadata field", func(t []*resourceTypes.Metadata{ ResourceName2.Metadata, ResourceName12.Metadata, - ResourceName1.Metadata}, + ResourceName1.Metadata, + }, ), Metadata: &types.ResolutionDidDocMetadata{}, }, @@ -343,7 +344,8 @@ var _ = DescribeTable("Test resource positive cases with Metadata field", func(t testconstants.ValidDid, []*resourceTypes.Metadata{ ResourceName12.Metadata, - ResourceName1.Metadata}, + ResourceName1.Metadata, + }, ), Metadata: &types.ResolutionDidDocMetadata{}, }, @@ -371,7 +373,8 @@ var _ = DescribeTable("Test resource positive cases with Metadata field", func(t testconstants.ValidDid, []*resourceTypes.Metadata{ ResourceType12.Metadata, - ResourceType1.Metadata,}, + ResourceType1.Metadata, + }, ), Metadata: &types.ResolutionDidDocMetadata{}, }, diff --git a/tests/unit/diddoc/request/resources_positive_cases_test.go b/tests/unit/diddoc/request/resources_positive_cases_test.go index 926002bd..2e01fdba 100644 --- a/tests/unit/diddoc/request/resources_positive_cases_test.go +++ b/tests/unit/diddoc/request/resources_positive_cases_test.go @@ -8,12 +8,12 @@ import ( "net/http/httptest" "time" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" didDocService "github.com/cheqd/did-resolver/services/diddoc" testconstants "github.com/cheqd/did-resolver/tests/constants" utils "github.com/cheqd/did-resolver/tests/unit" "github.com/cheqd/did-resolver/types" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) var _ = DescribeTable("Test Query handlers with resource params. Returns Resource", func(testCase ResourceTestCase) { diff --git a/tests/unit/diddoc/request/types_test.go b/tests/unit/diddoc/request/types_test.go index 0d2788a4..341159f3 100644 --- a/tests/unit/diddoc/request/types_test.go +++ b/tests/unit/diddoc/request/types_test.go @@ -115,4 +115,4 @@ func generateMetadata(versionId string, created, updated *timestamppb.Timestamp) Created: created, Updated: updated, } -} \ No newline at end of file +} diff --git a/tests/unit/test_utils.go b/tests/unit/test_utils.go index 532ed3f1..3236ce37 100644 --- a/tests/unit/test_utils.go +++ b/tests/unit/test_utils.go @@ -79,7 +79,7 @@ func NewMockLedgerService(did *didTypes.DidDoc, metadata []*didTypes.Metadata, r func (ls MockLedgerService) QueryDIDDoc(did string, version string) (*didTypes.DidDocWithMetadata, *types.IdentityError) { if ls.Did.Id == did { if version == "" { - return &didTypes.DidDocWithMetadata{DidDoc: ls.Did, Metadata: ls.Metadata[len(ls.Metadata) -1]}, nil + return &didTypes.DidDocWithMetadata{DidDoc: ls.Did, Metadata: ls.Metadata[len(ls.Metadata)-1]}, nil } for _, metadata := range ls.Metadata { if metadata.VersionId == version { @@ -123,7 +123,7 @@ func (ls MockLedgerService) QueryCollectionResources(did string) ([]*resourceTyp return []*resourceTypes.Metadata{}, types.NewNotFoundError(did, types.JSON, nil, true) } - var metadataList = make([]*resourceTypes.Metadata, len(ls.Resources)) + metadataList := make([]*resourceTypes.Metadata, len(ls.Resources)) for i, resource := range ls.Resources { metadataList[i] = resource.Metadata } diff --git a/types/resolution_diddoc_metadata.go b/types/resolution_diddoc_metadata.go index 5ed1422e..70e4385d 100644 --- a/types/resolution_diddoc_metadata.go +++ b/types/resolution_diddoc_metadata.go @@ -9,11 +9,13 @@ import ( ) type ResolutionDidDocMetadata struct { - Created *time.Time `json:"created,omitempty" example:"2021-09-01T12:00:00Z"` - Updated *time.Time `json:"updated,omitempty" example:"2021-09-10T12:00:00Z"` - Deactivated bool `json:"deactivated,omitempty" example:"false"` - VersionId string `json:"versionId,omitempty" example:"4979BAF49599FEF0BAD5ED0849FDD708156761EBBC8EBE78D0907F8BECC9CB2E"` - Resources DereferencedResourceList `json:"linkedResourceMetadata,omitempty"` + Created *time.Time `json:"created,omitempty" example:"2021-09-01T12:00:00Z"` + Updated *time.Time `json:"updated,omitempty" example:"2021-09-10T12:00:00Z"` + Deactivated bool `json:"deactivated,omitempty" example:"false"` + VersionId string `json:"versionId,omitempty" example:"284f297b-b6e3-4ffa-9172-bc3bb904e286"` + NextVersionId string `json:"nextVersionId,omitempty" example:"3f3111af-dfe6-411f-adc9-02af59716ddb"` + PreviousVersionId string `json:"previousVersionId,omitempty" example:"139445af-4281-4453-b05a-ec9a8931c1f9"` + Resources DereferencedResourceList `json:"linkedResourceMetadata,omitempty"` } func NewResolutionDidDocMetadata(did string, metadata *didTypes.Metadata, resources []*resourceTypes.Metadata) ResolutionDidDocMetadata { @@ -21,10 +23,12 @@ func NewResolutionDidDocMetadata(did string, metadata *didTypes.Metadata, resour updated := toTime(metadata.Updated) newMetadata := ResolutionDidDocMetadata{ - Created: created, - Updated: updated, - Deactivated: metadata.Deactivated, - VersionId: metadata.VersionId, + Created: created, + Updated: updated, + Deactivated: metadata.Deactivated, + VersionId: metadata.VersionId, + NextVersionId: metadata.NextVersionId, + PreviousVersionId: metadata.PreviousVersionId, } if len(resources) == 0 {