Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add explicit previousVersionId, nextVersionId on DID resolution metadata #239

Merged
merged 5 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .github/linters/mlc_config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"aliveStatusCodes": [0, 200, 206, 403, 501, 999],
"aliveStatusCodes": [
0,
200,
206,
403,
501,
999
],
"replacementPatterns": [
{
"pattern": "\" %}",
Expand All @@ -12,8 +19,11 @@
],
"ignorePatterns": [
{
"pattern": "^https://resolver.cheqd.net/"
"pattern": "^https://resolver.cheqd.net/"
},
{
"pattern": "^https://twitter.com/"
}
],
"retryOn429": true
}
}
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
with:
go-version-file: ./go.mod
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions tests/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\"," +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
46 changes: 23 additions & 23 deletions tests/unit/diddoc/common/dereferencing_content_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}
})
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/diddoc/common/did_doc_metadata_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var _ = Describe("DidDocMetadataList", func() {
Deactivated: false,
Created: &tcreated,
Updated: nil,
Resources: []types.DereferencedResource{
Resources: []types.DereferencedResource{
{
Created: &t1_2,
},
Expand Down Expand Up @@ -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() {
Expand Down
32 changes: 19 additions & 13 deletions tests/unit/diddoc/common/did_doc_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
},
},
},
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/diddoc/request/common_negative_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand All @@ -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),
},
Expand All @@ -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),
},
Expand All @@ -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),
},
Expand All @@ -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),
},
Expand All @@ -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),
},
Expand Down
Loading
Loading