2022-04-05 07:09:27 +00:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2023-10-19 13:47:21 +00:00
|
|
|
"os"
|
|
|
|
"reflect"
|
|
|
|
|
2022-12-09 04:17:14 +00:00
|
|
|
"github.com/cerc-io/laconicd/x/registry/client/cli"
|
|
|
|
"github.com/cerc-io/laconicd/x/registry/helpers"
|
|
|
|
"github.com/cerc-io/laconicd/x/registry/keeper"
|
|
|
|
registrytypes "github.com/cerc-io/laconicd/x/registry/types"
|
2022-04-05 07:09:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) TestGrpcQueryParams() {
|
|
|
|
grpcClient := suite.queryClient
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
msg string
|
2022-12-09 04:17:14 +00:00
|
|
|
req *registrytypes.QueryParamsRequest
|
2022-04-05 07:09:27 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"Get Params",
|
2022-12-09 04:17:14 +00:00
|
|
|
®istrytypes.QueryParamsRequest{},
|
2022-04-05 07:09:27 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range testCases {
|
|
|
|
suite.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
|
|
|
resp, _ := grpcClient.Params(context.Background(), test.req)
|
2022-12-09 04:17:14 +00:00
|
|
|
defaultParams := registrytypes.DefaultParams()
|
2022-04-05 07:09:27 +00:00
|
|
|
suite.Require().Equal(defaultParams.String(), resp.GetParams().String())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) TestGrpcGetRecordLists() {
|
|
|
|
grpcClient, ctx := suite.queryClient, suite.ctx
|
|
|
|
sr := suite.Require()
|
|
|
|
var recordId string
|
2022-11-15 06:21:14 +00:00
|
|
|
examples := []string{
|
|
|
|
"/../helpers/examples/service_provider_example.yml",
|
|
|
|
"/../helpers/examples/website_registration_example.yml",
|
129: Index multivalued attributes. (#128)
This fixes #129, by indexing each value of a multivalued attribute.
This handles at least the most common use case, so that we can search on a single value of the attribute.
```
❯ laconic -c ~/.laconic/local.yml cns record list --all --type ApplicationDeploymentRequest --tags b
[
{
"id": "bafyreidrp4pylixp44rkxu5il72qhwwc4ir5ctdnssps5rnelstloxivwm",
"names": null,
"owners": [
"FCCE01FCC2472AEDBCF33902907F33262445AC2C"
],
"bondId": "4ef470a9207f00fc07663623d092a14c310794b616eb53b085cfe6976e82f56d",
"createTime": "2023-12-18T22:13:23Z",
"expiryTime": "2024-12-17T22:13:23Z",
"attributes": {
"type": "ApplicationDeploymentRequest",
"version": "1.0.6",
"application": "crn://cerc-io/applications/test-progressive-web-app@0.1.1",
"config": {
"env": {
"CERC_WEBAPP_DEBUG": "57588a9d"
}
},
"tags": [
"a",
"b",
"c"
]
}
}
]
```
Reviewed-on: https://git.vdb.to/cerc-io/laconicd/pulls/128
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-12-19 06:55:11 +00:00
|
|
|
"/../helpers/examples/general_record_example.yml",
|
2022-11-15 06:21:14 +00:00
|
|
|
}
|
2022-04-05 07:09:27 +00:00
|
|
|
testCases := []struct {
|
2022-11-15 06:21:14 +00:00
|
|
|
msg string
|
2022-12-09 04:17:14 +00:00
|
|
|
req *registrytypes.QueryListRecordsRequest
|
2022-11-15 06:21:14 +00:00
|
|
|
createRecords bool
|
|
|
|
expErr bool
|
|
|
|
noOfRecords int
|
2022-04-05 07:09:27 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"Empty Records",
|
2022-12-09 04:17:14 +00:00
|
|
|
®istrytypes.QueryListRecordsRequest{},
|
2022-04-05 07:09:27 +00:00
|
|
|
false,
|
|
|
|
false,
|
|
|
|
0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"List Records",
|
2022-12-09 04:17:14 +00:00
|
|
|
®istrytypes.QueryListRecordsRequest{},
|
2022-04-05 07:09:27 +00:00
|
|
|
true,
|
|
|
|
false,
|
129: Index multivalued attributes. (#128)
This fixes #129, by indexing each value of a multivalued attribute.
This handles at least the most common use case, so that we can search on a single value of the attribute.
```
❯ laconic -c ~/.laconic/local.yml cns record list --all --type ApplicationDeploymentRequest --tags b
[
{
"id": "bafyreidrp4pylixp44rkxu5il72qhwwc4ir5ctdnssps5rnelstloxivwm",
"names": null,
"owners": [
"FCCE01FCC2472AEDBCF33902907F33262445AC2C"
],
"bondId": "4ef470a9207f00fc07663623d092a14c310794b616eb53b085cfe6976e82f56d",
"createTime": "2023-12-18T22:13:23Z",
"expiryTime": "2024-12-17T22:13:23Z",
"attributes": {
"type": "ApplicationDeploymentRequest",
"version": "1.0.6",
"application": "crn://cerc-io/applications/test-progressive-web-app@0.1.1",
"config": {
"env": {
"CERC_WEBAPP_DEBUG": "57588a9d"
}
},
"tags": [
"a",
"b",
"c"
]
}
}
]
```
Reviewed-on: https://git.vdb.to/cerc-io/laconicd/pulls/128
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-12-19 06:55:11 +00:00
|
|
|
3,
|
2022-11-15 06:21:14 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Filter with type",
|
2022-12-09 04:17:14 +00:00
|
|
|
®istrytypes.QueryListRecordsRequest{
|
|
|
|
Attributes: []*registrytypes.QueryListRecordsRequest_KeyValueInput{
|
2022-11-15 06:21:14 +00:00
|
|
|
{
|
|
|
|
Key: "type",
|
2022-12-09 04:17:14 +00:00
|
|
|
Value: ®istrytypes.QueryListRecordsRequest_ValueInput{
|
2023-10-19 00:03:21 +00:00
|
|
|
Value: ®istrytypes.QueryListRecordsRequest_ValueInput_String_{"WebsiteRegistrationRecord"},
|
2022-11-15 06:21:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
All: true,
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
1,
|
|
|
|
},
|
2024-01-11 04:56:49 +00:00
|
|
|
// Skip the following test as querying with recursive values not supported (PR https://git.vdb.to/cerc-io/laconicd/pulls/112)
|
|
|
|
// See function RecordsFromAttributes (QueryValueToJSON call) in the registry keeper implementation (x/registry/keeper/keeper.go)
|
|
|
|
// {
|
|
|
|
// "Filter with tag (extant) (https://git.vdb.to/cerc-io/laconicd/issues/129)",
|
|
|
|
// ®istrytypes.QueryListRecordsRequest{
|
|
|
|
// Attributes: []*registrytypes.QueryListRecordsRequest_KeyValueInput{
|
|
|
|
// {
|
|
|
|
// Key: "tags",
|
|
|
|
// // Value: ®istrytypes.QueryListRecordsRequest_ValueInput{
|
|
|
|
// // Value: ®istrytypes.QueryListRecordsRequest_ValueInput_String_{"tagA"},
|
|
|
|
// // },
|
|
|
|
// Value: ®istrytypes.QueryListRecordsRequest_ValueInput{
|
|
|
|
// Value: ®istrytypes.QueryListRecordsRequest_ValueInput_Array{Array: ®istrytypes.QueryListRecordsRequest_ArrayInput{
|
|
|
|
// Values: []*registrytypes.QueryListRecordsRequest_ValueInput{
|
|
|
|
// {
|
|
|
|
// Value: ®istrytypes.QueryListRecordsRequest_ValueInput_String_{"tagA"},
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// }},
|
|
|
|
// },
|
|
|
|
// // Throws: "Recursive query values are not supported"
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// All: true,
|
|
|
|
// },
|
|
|
|
// true,
|
|
|
|
// false,
|
|
|
|
// 1,
|
|
|
|
// },
|
129: Index multivalued attributes. (#128)
This fixes #129, by indexing each value of a multivalued attribute.
This handles at least the most common use case, so that we can search on a single value of the attribute.
```
❯ laconic -c ~/.laconic/local.yml cns record list --all --type ApplicationDeploymentRequest --tags b
[
{
"id": "bafyreidrp4pylixp44rkxu5il72qhwwc4ir5ctdnssps5rnelstloxivwm",
"names": null,
"owners": [
"FCCE01FCC2472AEDBCF33902907F33262445AC2C"
],
"bondId": "4ef470a9207f00fc07663623d092a14c310794b616eb53b085cfe6976e82f56d",
"createTime": "2023-12-18T22:13:23Z",
"expiryTime": "2024-12-17T22:13:23Z",
"attributes": {
"type": "ApplicationDeploymentRequest",
"version": "1.0.6",
"application": "crn://cerc-io/applications/test-progressive-web-app@0.1.1",
"config": {
"env": {
"CERC_WEBAPP_DEBUG": "57588a9d"
}
},
"tags": [
"a",
"b",
"c"
]
}
}
]
```
Reviewed-on: https://git.vdb.to/cerc-io/laconicd/pulls/128
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-12-19 06:55:11 +00:00
|
|
|
{
|
|
|
|
"Filter with tag (non-existent) (https://git.vdb.to/cerc-io/laconicd/issues/129)",
|
|
|
|
®istrytypes.QueryListRecordsRequest{
|
|
|
|
Attributes: []*registrytypes.QueryListRecordsRequest_KeyValueInput{
|
|
|
|
{
|
|
|
|
Key: "tags",
|
|
|
|
Value: ®istrytypes.QueryListRecordsRequest_ValueInput{
|
2024-01-10 12:27:23 +00:00
|
|
|
Value: ®istrytypes.QueryListRecordsRequest_ValueInput_String_{"NOEXIST"},
|
129: Index multivalued attributes. (#128)
This fixes #129, by indexing each value of a multivalued attribute.
This handles at least the most common use case, so that we can search on a single value of the attribute.
```
❯ laconic -c ~/.laconic/local.yml cns record list --all --type ApplicationDeploymentRequest --tags b
[
{
"id": "bafyreidrp4pylixp44rkxu5il72qhwwc4ir5ctdnssps5rnelstloxivwm",
"names": null,
"owners": [
"FCCE01FCC2472AEDBCF33902907F33262445AC2C"
],
"bondId": "4ef470a9207f00fc07663623d092a14c310794b616eb53b085cfe6976e82f56d",
"createTime": "2023-12-18T22:13:23Z",
"expiryTime": "2024-12-17T22:13:23Z",
"attributes": {
"type": "ApplicationDeploymentRequest",
"version": "1.0.6",
"application": "crn://cerc-io/applications/test-progressive-web-app@0.1.1",
"config": {
"env": {
"CERC_WEBAPP_DEBUG": "57588a9d"
}
},
"tags": [
"a",
"b",
"c"
]
}
}
]
```
Reviewed-on: https://git.vdb.to/cerc-io/laconicd/pulls/128
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-12-19 06:55:11 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
All: true,
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
0,
|
|
|
|
},
|
122: Fix attribute index key collision (#123)
Fix #122, where the structure of the index key allowed unintended collisions (see below).
This also adds a test cases which _fails_ under the old scheme, but passes now:
**Before:**
```
--- FAIL: TestKeeperTestSuite (0.31s)
--- FAIL: TestKeeperTestSuite/TestGrpcGetRecordLists (0.09s)
grpc_query_test.go:143:
Error Trace: /home/telackey/cerc/laconicd/x/registry/keeper/grpc_query_test.go:143
/home/telackey/cerc/laconicd/x/registry/keeper/suite.go:91
Error: Not equal:
expected: 0
actual : 1
Test: TestKeeperTestSuite/TestGrpcGetRecordLists
--- FAIL: TestKeeperTestSuite/TestGrpcGetRecordLists/Case_Filter_with_typ_(https://git.vdb.to/cerc-io/laconicd/issues/122)_ (0.00s)
testing.go:1490: test executed panic(nil) or runtime.Goexit: subtest may have called FailNow on a parent test
FAIL
FAIL github.com/cerc-io/laconicd/x/registry/keeper 0.765s
FAIL
make: *** [Makefile:333: run-tests] Error 1
❯ laconic cns record list --all --typ eWebsiteRegistrationRecord
[
{
"id": "bafyreies5he2mxyrjso2quewwlmh6cisekkjnf7yijpd2742wrzxgzuazi",
"names": null,
"owners": [
"FC9B9FB065D70DBB10C8F511348421C16669B37D"
],
"bondId": "a9c7161fc154cf44ee61efc699a59c8a27c804bb23ce4c8a7ffa0a39fcc540b1",
"createTime": "2023-11-28T19:09:03Z",
"expiryTime": "2024-11-27T19:09:03Z",
"attributes": {
"url": "https://hello-urbit.laconic.com",
"repo_registration_record_cid": "QmTZQ8ZJS6mALjEM2wY71msFno6zzxFftVCiZELj9xREPx",
"build_artifact_cid": "~lostex-rabdur-labtul-moltev/hello-urbit",
"tls_cert_cid": "QmR1acEmQt7Tjmhp9cFtymie2eFcrHURQKt9kGto1TQTW1",
"type": "WebsiteRegistrationRecord",
"version": "0.2.4"
}
}
...
❯ laconic cns record list --all --type WebsiteRegistrationRecord
[
{
"id": "bafyreies5he2mxyrjso2quewwlmh6cisekkjnf7yijpd2742wrzxgzuazi",
"names": null,
"owners": [
"FC9B9FB065D70DBB10C8F511348421C16669B37D"
],
"bondId": "a9c7161fc154cf44ee61efc699a59c8a27c804bb23ce4c8a7ffa0a39fcc540b1",
"createTime": "2023-11-28T19:09:03Z",
"expiryTime": "2024-11-27T19:09:03Z",
"attributes": {
"url": "https://hello-urbit.laconic.com",
"repo_registration_record_cid": "QmTZQ8ZJS6mALjEM2wY71msFno6zzxFftVCiZELj9xREPx",
"build_artifact_cid": "~lostex-rabdur-labtul-moltev/hello-urbit",
"tls_cert_cid": "QmR1acEmQt7Tjmhp9cFtymie2eFcrHURQKt9kGto1TQTW1",
"type": "WebsiteRegistrationRecord",
"version": "0.2.4"
}
}
...
```
**After:**
```
ok github.com/cerc-io/laconicd/x/registry/keeper 1.573s
❯ laconic cns record list --all --typ eWebsiteRegistrationRecord
[]
❯ laconic cns record list --all --type WebsiteRegistrationRecord
[
{
"id": "bafyreies5he2mxyrjso2quewwlmh6cisekkjnf7yijpd2742wrzxgzuazi",
"names": null,
"owners": [
"FC9B9FB065D70DBB10C8F511348421C16669B37D"
],
"bondId": "a9c7161fc154cf44ee61efc699a59c8a27c804bb23ce4c8a7ffa0a39fcc540b1",
"createTime": "2023-11-28T19:09:03Z",
"expiryTime": "2024-11-27T19:09:03Z",
"attributes": {
"url": "https://hello-urbit.laconic.com",
"repo_registration_record_cid": "QmTZQ8ZJS6mALjEM2wY71msFno6zzxFftVCiZELj9xREPx",
"build_artifact_cid": "~lostex-rabdur-labtul-moltev/hello-urbit",
"tls_cert_cid": "QmR1acEmQt7Tjmhp9cFtymie2eFcrHURQKt9kGto1TQTW1",
"type": "WebsiteRegistrationRecord",
"version": "0.2.4"
}
}
...
```
Reviewed-on: https://git.vdb.to/cerc-io/laconicd/pulls/123
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-11-29 00:05:56 +00:00
|
|
|
{
|
|
|
|
"Filter test for key collision (https://git.vdb.to/cerc-io/laconicd/issues/122)",
|
|
|
|
®istrytypes.QueryListRecordsRequest{
|
|
|
|
Attributes: []*registrytypes.QueryListRecordsRequest_KeyValueInput{
|
|
|
|
{
|
|
|
|
Key: "typ",
|
|
|
|
Value: ®istrytypes.QueryListRecordsRequest_ValueInput{
|
2024-01-10 12:27:23 +00:00
|
|
|
Value: ®istrytypes.QueryListRecordsRequest_ValueInput_String_{"eWebsiteRegistrationRecord"},
|
122: Fix attribute index key collision (#123)
Fix #122, where the structure of the index key allowed unintended collisions (see below).
This also adds a test cases which _fails_ under the old scheme, but passes now:
**Before:**
```
--- FAIL: TestKeeperTestSuite (0.31s)
--- FAIL: TestKeeperTestSuite/TestGrpcGetRecordLists (0.09s)
grpc_query_test.go:143:
Error Trace: /home/telackey/cerc/laconicd/x/registry/keeper/grpc_query_test.go:143
/home/telackey/cerc/laconicd/x/registry/keeper/suite.go:91
Error: Not equal:
expected: 0
actual : 1
Test: TestKeeperTestSuite/TestGrpcGetRecordLists
--- FAIL: TestKeeperTestSuite/TestGrpcGetRecordLists/Case_Filter_with_typ_(https://git.vdb.to/cerc-io/laconicd/issues/122)_ (0.00s)
testing.go:1490: test executed panic(nil) or runtime.Goexit: subtest may have called FailNow on a parent test
FAIL
FAIL github.com/cerc-io/laconicd/x/registry/keeper 0.765s
FAIL
make: *** [Makefile:333: run-tests] Error 1
❯ laconic cns record list --all --typ eWebsiteRegistrationRecord
[
{
"id": "bafyreies5he2mxyrjso2quewwlmh6cisekkjnf7yijpd2742wrzxgzuazi",
"names": null,
"owners": [
"FC9B9FB065D70DBB10C8F511348421C16669B37D"
],
"bondId": "a9c7161fc154cf44ee61efc699a59c8a27c804bb23ce4c8a7ffa0a39fcc540b1",
"createTime": "2023-11-28T19:09:03Z",
"expiryTime": "2024-11-27T19:09:03Z",
"attributes": {
"url": "https://hello-urbit.laconic.com",
"repo_registration_record_cid": "QmTZQ8ZJS6mALjEM2wY71msFno6zzxFftVCiZELj9xREPx",
"build_artifact_cid": "~lostex-rabdur-labtul-moltev/hello-urbit",
"tls_cert_cid": "QmR1acEmQt7Tjmhp9cFtymie2eFcrHURQKt9kGto1TQTW1",
"type": "WebsiteRegistrationRecord",
"version": "0.2.4"
}
}
...
❯ laconic cns record list --all --type WebsiteRegistrationRecord
[
{
"id": "bafyreies5he2mxyrjso2quewwlmh6cisekkjnf7yijpd2742wrzxgzuazi",
"names": null,
"owners": [
"FC9B9FB065D70DBB10C8F511348421C16669B37D"
],
"bondId": "a9c7161fc154cf44ee61efc699a59c8a27c804bb23ce4c8a7ffa0a39fcc540b1",
"createTime": "2023-11-28T19:09:03Z",
"expiryTime": "2024-11-27T19:09:03Z",
"attributes": {
"url": "https://hello-urbit.laconic.com",
"repo_registration_record_cid": "QmTZQ8ZJS6mALjEM2wY71msFno6zzxFftVCiZELj9xREPx",
"build_artifact_cid": "~lostex-rabdur-labtul-moltev/hello-urbit",
"tls_cert_cid": "QmR1acEmQt7Tjmhp9cFtymie2eFcrHURQKt9kGto1TQTW1",
"type": "WebsiteRegistrationRecord",
"version": "0.2.4"
}
}
...
```
**After:**
```
ok github.com/cerc-io/laconicd/x/registry/keeper 1.573s
❯ laconic cns record list --all --typ eWebsiteRegistrationRecord
[]
❯ laconic cns record list --all --type WebsiteRegistrationRecord
[
{
"id": "bafyreies5he2mxyrjso2quewwlmh6cisekkjnf7yijpd2742wrzxgzuazi",
"names": null,
"owners": [
"FC9B9FB065D70DBB10C8F511348421C16669B37D"
],
"bondId": "a9c7161fc154cf44ee61efc699a59c8a27c804bb23ce4c8a7ffa0a39fcc540b1",
"createTime": "2023-11-28T19:09:03Z",
"expiryTime": "2024-11-27T19:09:03Z",
"attributes": {
"url": "https://hello-urbit.laconic.com",
"repo_registration_record_cid": "QmTZQ8ZJS6mALjEM2wY71msFno6zzxFftVCiZELj9xREPx",
"build_artifact_cid": "~lostex-rabdur-labtul-moltev/hello-urbit",
"tls_cert_cid": "QmR1acEmQt7Tjmhp9cFtymie2eFcrHURQKt9kGto1TQTW1",
"type": "WebsiteRegistrationRecord",
"version": "0.2.4"
}
}
...
```
Reviewed-on: https://git.vdb.to/cerc-io/laconicd/pulls/123
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-11-29 00:05:56 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
All: true,
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
0,
|
|
|
|
},
|
2022-11-15 06:21:14 +00:00
|
|
|
{
|
|
|
|
"Filter with attributes ServiceProviderRegistration",
|
2022-12-09 04:17:14 +00:00
|
|
|
®istrytypes.QueryListRecordsRequest{
|
|
|
|
Attributes: []*registrytypes.QueryListRecordsRequest_KeyValueInput{
|
2022-11-15 06:21:14 +00:00
|
|
|
{
|
|
|
|
Key: "x500state_name",
|
2022-12-09 04:17:14 +00:00
|
|
|
Value: ®istrytypes.QueryListRecordsRequest_ValueInput{
|
2023-10-19 00:03:21 +00:00
|
|
|
Value: ®istrytypes.QueryListRecordsRequest_ValueInput_String_{"california"},
|
2022-11-15 06:21:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
All: true,
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
false,
|
2022-04-05 07:09:27 +00:00
|
|
|
1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range testCases {
|
|
|
|
suite.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
2022-11-15 06:21:14 +00:00
|
|
|
if test.createRecords {
|
|
|
|
for _, example := range examples {
|
|
|
|
dir, err := os.Getwd()
|
|
|
|
sr.NoError(err)
|
|
|
|
payloadType, err := cli.GetPayloadFromFile(fmt.Sprint(dir, example))
|
|
|
|
sr.NoError(err)
|
2023-09-08 08:34:18 +00:00
|
|
|
payload := payloadType.ToPayload()
|
2022-12-09 04:17:14 +00:00
|
|
|
record, err := suite.app.RegistryKeeper.ProcessSetRecord(ctx, registrytypes.MsgSetRecord{
|
2022-11-15 06:21:14 +00:00
|
|
|
BondId: suite.bond.GetId(),
|
|
|
|
Signer: suite.accounts[0].String(),
|
|
|
|
Payload: payload,
|
|
|
|
})
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.NotNil(record.ID)
|
|
|
|
}
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
resp, err := grpcClient.ListRecords(context.Background(), test.req)
|
|
|
|
if test.expErr {
|
|
|
|
suite.Error(err)
|
|
|
|
} else {
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.Equal(test.noOfRecords, len(resp.GetRecords()))
|
122: Fix attribute index key collision (#123)
Fix #122, where the structure of the index key allowed unintended collisions (see below).
This also adds a test cases which _fails_ under the old scheme, but passes now:
**Before:**
```
--- FAIL: TestKeeperTestSuite (0.31s)
--- FAIL: TestKeeperTestSuite/TestGrpcGetRecordLists (0.09s)
grpc_query_test.go:143:
Error Trace: /home/telackey/cerc/laconicd/x/registry/keeper/grpc_query_test.go:143
/home/telackey/cerc/laconicd/x/registry/keeper/suite.go:91
Error: Not equal:
expected: 0
actual : 1
Test: TestKeeperTestSuite/TestGrpcGetRecordLists
--- FAIL: TestKeeperTestSuite/TestGrpcGetRecordLists/Case_Filter_with_typ_(https://git.vdb.to/cerc-io/laconicd/issues/122)_ (0.00s)
testing.go:1490: test executed panic(nil) or runtime.Goexit: subtest may have called FailNow on a parent test
FAIL
FAIL github.com/cerc-io/laconicd/x/registry/keeper 0.765s
FAIL
make: *** [Makefile:333: run-tests] Error 1
❯ laconic cns record list --all --typ eWebsiteRegistrationRecord
[
{
"id": "bafyreies5he2mxyrjso2quewwlmh6cisekkjnf7yijpd2742wrzxgzuazi",
"names": null,
"owners": [
"FC9B9FB065D70DBB10C8F511348421C16669B37D"
],
"bondId": "a9c7161fc154cf44ee61efc699a59c8a27c804bb23ce4c8a7ffa0a39fcc540b1",
"createTime": "2023-11-28T19:09:03Z",
"expiryTime": "2024-11-27T19:09:03Z",
"attributes": {
"url": "https://hello-urbit.laconic.com",
"repo_registration_record_cid": "QmTZQ8ZJS6mALjEM2wY71msFno6zzxFftVCiZELj9xREPx",
"build_artifact_cid": "~lostex-rabdur-labtul-moltev/hello-urbit",
"tls_cert_cid": "QmR1acEmQt7Tjmhp9cFtymie2eFcrHURQKt9kGto1TQTW1",
"type": "WebsiteRegistrationRecord",
"version": "0.2.4"
}
}
...
❯ laconic cns record list --all --type WebsiteRegistrationRecord
[
{
"id": "bafyreies5he2mxyrjso2quewwlmh6cisekkjnf7yijpd2742wrzxgzuazi",
"names": null,
"owners": [
"FC9B9FB065D70DBB10C8F511348421C16669B37D"
],
"bondId": "a9c7161fc154cf44ee61efc699a59c8a27c804bb23ce4c8a7ffa0a39fcc540b1",
"createTime": "2023-11-28T19:09:03Z",
"expiryTime": "2024-11-27T19:09:03Z",
"attributes": {
"url": "https://hello-urbit.laconic.com",
"repo_registration_record_cid": "QmTZQ8ZJS6mALjEM2wY71msFno6zzxFftVCiZELj9xREPx",
"build_artifact_cid": "~lostex-rabdur-labtul-moltev/hello-urbit",
"tls_cert_cid": "QmR1acEmQt7Tjmhp9cFtymie2eFcrHURQKt9kGto1TQTW1",
"type": "WebsiteRegistrationRecord",
"version": "0.2.4"
}
}
...
```
**After:**
```
ok github.com/cerc-io/laconicd/x/registry/keeper 1.573s
❯ laconic cns record list --all --typ eWebsiteRegistrationRecord
[]
❯ laconic cns record list --all --type WebsiteRegistrationRecord
[
{
"id": "bafyreies5he2mxyrjso2quewwlmh6cisekkjnf7yijpd2742wrzxgzuazi",
"names": null,
"owners": [
"FC9B9FB065D70DBB10C8F511348421C16669B37D"
],
"bondId": "a9c7161fc154cf44ee61efc699a59c8a27c804bb23ce4c8a7ffa0a39fcc540b1",
"createTime": "2023-11-28T19:09:03Z",
"expiryTime": "2024-11-27T19:09:03Z",
"attributes": {
"url": "https://hello-urbit.laconic.com",
"repo_registration_record_cid": "QmTZQ8ZJS6mALjEM2wY71msFno6zzxFftVCiZELj9xREPx",
"build_artifact_cid": "~lostex-rabdur-labtul-moltev/hello-urbit",
"tls_cert_cid": "QmR1acEmQt7Tjmhp9cFtymie2eFcrHURQKt9kGto1TQTW1",
"type": "WebsiteRegistrationRecord",
"version": "0.2.4"
}
}
...
```
Reviewed-on: https://git.vdb.to/cerc-io/laconicd/pulls/123
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-11-29 00:05:56 +00:00
|
|
|
if test.createRecords && test.noOfRecords > 0 {
|
2022-11-15 06:21:14 +00:00
|
|
|
recordId = resp.GetRecords()[0].GetId()
|
2022-04-05 07:09:27 +00:00
|
|
|
sr.NotZero(resp.GetRecords())
|
2022-11-15 06:21:14 +00:00
|
|
|
sr.Equal(resp.GetRecords()[0].GetBondId(), suite.bond.GetId())
|
|
|
|
|
|
|
|
for _, record := range resp.GetRecords() {
|
2023-10-26 13:45:08 +00:00
|
|
|
recAttr := helpers.MustUnmarshalJSON[registrytypes.AttributeMap](record.Attributes)
|
|
|
|
|
2022-11-15 06:21:14 +00:00
|
|
|
for _, attr := range test.req.GetAttributes() {
|
2023-10-26 13:45:08 +00:00
|
|
|
enc, err := keeper.QueryValueToJSON(attr.Value)
|
|
|
|
sr.NoError(err)
|
|
|
|
av := helpers.MustUnmarshalJSON[any](enc)
|
|
|
|
|
129: Index multivalued attributes. (#128)
This fixes #129, by indexing each value of a multivalued attribute.
This handles at least the most common use case, so that we can search on a single value of the attribute.
```
❯ laconic -c ~/.laconic/local.yml cns record list --all --type ApplicationDeploymentRequest --tags b
[
{
"id": "bafyreidrp4pylixp44rkxu5il72qhwwc4ir5ctdnssps5rnelstloxivwm",
"names": null,
"owners": [
"FCCE01FCC2472AEDBCF33902907F33262445AC2C"
],
"bondId": "4ef470a9207f00fc07663623d092a14c310794b616eb53b085cfe6976e82f56d",
"createTime": "2023-12-18T22:13:23Z",
"expiryTime": "2024-12-17T22:13:23Z",
"attributes": {
"type": "ApplicationDeploymentRequest",
"version": "1.0.6",
"application": "crn://cerc-io/applications/test-progressive-web-app@0.1.1",
"config": {
"env": {
"CERC_WEBAPP_DEBUG": "57588a9d"
}
},
"tags": [
"a",
"b",
"c"
]
}
}
]
```
Reviewed-on: https://git.vdb.to/cerc-io/laconicd/pulls/128
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-12-19 06:55:11 +00:00
|
|
|
if nil != av && nil != recAttr[attr.Key] &&
|
|
|
|
reflect.Slice == reflect.TypeOf(recAttr[attr.Key]).Kind() &&
|
|
|
|
reflect.Slice != reflect.TypeOf(av).Kind() {
|
|
|
|
found := false
|
|
|
|
allValues := recAttr[attr.Key].([]interface{})
|
|
|
|
for i := range allValues {
|
|
|
|
if av == allValues[i] {
|
|
|
|
fmt.Printf("Found %s in %s", allValues[i], recAttr[attr.Key])
|
|
|
|
found = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sr.Equal(true, found, fmt.Sprintf("Unable to find %s in %s", av, recAttr[attr.Key]))
|
2022-11-15 06:21:14 +00:00
|
|
|
} else {
|
129: Index multivalued attributes. (#128)
This fixes #129, by indexing each value of a multivalued attribute.
This handles at least the most common use case, so that we can search on a single value of the attribute.
```
❯ laconic -c ~/.laconic/local.yml cns record list --all --type ApplicationDeploymentRequest --tags b
[
{
"id": "bafyreidrp4pylixp44rkxu5il72qhwwc4ir5ctdnssps5rnelstloxivwm",
"names": null,
"owners": [
"FCCE01FCC2472AEDBCF33902907F33262445AC2C"
],
"bondId": "4ef470a9207f00fc07663623d092a14c310794b616eb53b085cfe6976e82f56d",
"createTime": "2023-12-18T22:13:23Z",
"expiryTime": "2024-12-17T22:13:23Z",
"attributes": {
"type": "ApplicationDeploymentRequest",
"version": "1.0.6",
"application": "crn://cerc-io/applications/test-progressive-web-app@0.1.1",
"config": {
"env": {
"CERC_WEBAPP_DEBUG": "57588a9d"
}
},
"tags": [
"a",
"b",
"c"
]
}
}
]
```
Reviewed-on: https://git.vdb.to/cerc-io/laconicd/pulls/128
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-12-19 06:55:11 +00:00
|
|
|
if attr.Key[:4] == "x500" {
|
|
|
|
sr.Equal(av, recAttr["x500"].(map[string]interface{})[attr.Key[4:]])
|
|
|
|
} else {
|
|
|
|
sr.Equal(av, recAttr[attr.Key])
|
|
|
|
}
|
2022-11-15 06:21:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the records by record id
|
|
|
|
testCases1 := []struct {
|
|
|
|
msg string
|
2022-12-09 04:17:14 +00:00
|
|
|
req *registrytypes.QueryRecordByIDRequest
|
2022-04-05 07:09:27 +00:00
|
|
|
createRecord bool
|
|
|
|
expErr bool
|
|
|
|
noOfRecords int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"Invalid Request without record id",
|
2022-12-09 04:17:14 +00:00
|
|
|
®istrytypes.QueryRecordByIDRequest{},
|
2022-04-05 07:09:27 +00:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"With Record ID",
|
2022-12-09 04:17:14 +00:00
|
|
|
®istrytypes.QueryRecordByIDRequest{
|
2022-04-05 07:09:27 +00:00
|
|
|
Id: recordId,
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range testCases1 {
|
|
|
|
suite.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
|
|
|
resp, err := grpcClient.GetRecord(context.Background(), test.req)
|
|
|
|
if test.expErr {
|
|
|
|
suite.Error(err)
|
|
|
|
} else {
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.NotNil(resp.GetRecord())
|
|
|
|
if test.createRecord {
|
2022-11-15 06:21:14 +00:00
|
|
|
sr.Equal(resp.GetRecord().BondId, suite.bond.GetId())
|
2022-04-05 07:09:27 +00:00
|
|
|
sr.Equal(resp.GetRecord().Id, recordId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the records by record id
|
|
|
|
testCasesByBondID := []struct {
|
|
|
|
msg string
|
2022-12-09 04:17:14 +00:00
|
|
|
req *registrytypes.QueryRecordByBondIDRequest
|
2022-04-05 07:09:27 +00:00
|
|
|
createRecord bool
|
|
|
|
expErr bool
|
|
|
|
noOfRecords int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"Invalid Request without bond id",
|
2022-12-09 04:17:14 +00:00
|
|
|
®istrytypes.QueryRecordByBondIDRequest{},
|
2022-04-05 07:09:27 +00:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"With Bond ID",
|
2022-12-09 04:17:14 +00:00
|
|
|
®istrytypes.QueryRecordByBondIDRequest{
|
2022-11-15 06:21:14 +00:00
|
|
|
Id: suite.bond.GetId(),
|
2022-04-05 07:09:27 +00:00
|
|
|
},
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range testCasesByBondID {
|
|
|
|
suite.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
2022-10-17 11:03:31 +00:00
|
|
|
resp, err := grpcClient.GetRecordByBondID(context.Background(), test.req)
|
2022-04-05 07:09:27 +00:00
|
|
|
if test.expErr {
|
|
|
|
sr.Zero(resp.GetRecords())
|
|
|
|
} else {
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.NotNil(resp.GetRecords())
|
|
|
|
if test.createRecord {
|
|
|
|
sr.NotZero(resp.GetRecords())
|
2022-11-15 06:21:14 +00:00
|
|
|
sr.Equal(resp.GetRecords()[0].GetBondId(), suite.bond.GetId())
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 04:17:14 +00:00
|
|
|
func (suite *KeeperTestSuite) TestGrpcQueryRegistryModuleBalance() {
|
2022-04-05 07:09:27 +00:00
|
|
|
grpcClient, ctx := suite.queryClient, suite.ctx
|
|
|
|
sr := suite.Require()
|
2022-11-15 06:21:14 +00:00
|
|
|
examples := []string{
|
|
|
|
"/../helpers/examples/service_provider_example.yml",
|
|
|
|
"/../helpers/examples/website_registration_example.yml",
|
|
|
|
}
|
2022-04-05 07:09:27 +00:00
|
|
|
testCases := []struct {
|
2022-11-15 06:21:14 +00:00
|
|
|
msg string
|
2022-12-09 04:17:14 +00:00
|
|
|
req *registrytypes.GetRegistryModuleBalanceRequest
|
2022-11-15 06:21:14 +00:00
|
|
|
createRecords bool
|
|
|
|
expErr bool
|
|
|
|
noOfRecords int
|
2022-04-05 07:09:27 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"Get Module Balance",
|
2022-12-09 04:17:14 +00:00
|
|
|
®istrytypes.GetRegistryModuleBalanceRequest{},
|
2022-04-05 07:09:27 +00:00
|
|
|
true,
|
|
|
|
false,
|
|
|
|
1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range testCases {
|
|
|
|
suite.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
2022-11-15 06:21:14 +00:00
|
|
|
if test.createRecords {
|
2022-04-05 07:09:27 +00:00
|
|
|
dir, err := os.Getwd()
|
|
|
|
sr.NoError(err)
|
2022-11-15 06:21:14 +00:00
|
|
|
for _, example := range examples {
|
|
|
|
payloadType, err := cli.GetPayloadFromFile(fmt.Sprint(dir, example))
|
|
|
|
sr.NoError(err)
|
2023-09-08 08:34:18 +00:00
|
|
|
payload := payloadType.ToPayload()
|
2022-12-09 04:17:14 +00:00
|
|
|
record, err := suite.app.RegistryKeeper.ProcessSetRecord(ctx, registrytypes.MsgSetRecord{
|
2022-11-15 06:21:14 +00:00
|
|
|
BondId: suite.bond.GetId(),
|
|
|
|
Signer: suite.accounts[0].String(),
|
|
|
|
Payload: payload,
|
|
|
|
})
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.NotNil(record.ID)
|
|
|
|
}
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
2022-12-09 04:17:14 +00:00
|
|
|
resp, err := grpcClient.GetRegistryModuleBalance(context.Background(), test.req)
|
2022-04-05 07:09:27 +00:00
|
|
|
if test.expErr {
|
|
|
|
suite.Error(err)
|
|
|
|
} else {
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.Equal(test.noOfRecords, len(resp.GetBalances()))
|
2022-11-15 06:21:14 +00:00
|
|
|
if test.createRecords {
|
2022-04-05 07:09:27 +00:00
|
|
|
balance := resp.GetBalances()[0]
|
2022-12-09 04:17:14 +00:00
|
|
|
sr.Equal(balance.AccountName, registrytypes.RecordRentModuleAccountName)
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) TestGrpcQueryWhoIS() {
|
|
|
|
grpcClient, ctx := suite.queryClient, suite.ctx
|
|
|
|
sr := suite.Require()
|
2022-10-17 06:47:56 +00:00
|
|
|
authorityName := "TestGrpcQueryWhoIS"
|
2022-04-05 07:09:27 +00:00
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
msg string
|
2022-12-09 04:17:14 +00:00
|
|
|
req *registrytypes.QueryWhoisRequest
|
2022-04-05 07:09:27 +00:00
|
|
|
createName bool
|
|
|
|
expErr bool
|
|
|
|
noOfRecords int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"Invalid Request without name",
|
2022-12-09 04:17:14 +00:00
|
|
|
®istrytypes.QueryWhoisRequest{},
|
2022-04-05 07:09:27 +00:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Success",
|
2022-12-09 04:17:14 +00:00
|
|
|
®istrytypes.QueryWhoisRequest{},
|
2022-04-05 07:09:27 +00:00
|
|
|
true,
|
|
|
|
false,
|
|
|
|
1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range testCases {
|
|
|
|
suite.Run(fmt.Sprintf("Case %s ", test.msg), func() {
|
|
|
|
if test.createName {
|
2022-12-09 04:17:14 +00:00
|
|
|
err := suite.app.RegistryKeeper.ProcessReserveAuthority(ctx, registrytypes.MsgReserveAuthority{
|
2022-04-05 07:09:27 +00:00
|
|
|
Name: authorityName,
|
|
|
|
Signer: suite.accounts[0].String(),
|
|
|
|
Owner: suite.accounts[0].String(),
|
|
|
|
})
|
|
|
|
sr.NoError(err)
|
2022-12-09 04:17:14 +00:00
|
|
|
test.req = ®istrytypes.QueryWhoisRequest{Name: authorityName}
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
resp, err := grpcClient.Whois(context.Background(), test.req)
|
|
|
|
if test.expErr {
|
|
|
|
sr.Zero(len(resp.NameAuthority.AuctionId))
|
|
|
|
} else {
|
|
|
|
sr.NoError(err)
|
|
|
|
if test.createName {
|
|
|
|
nameAuth := resp.NameAuthority
|
|
|
|
sr.NotNil(nameAuth)
|
|
|
|
sr.Equal(nameAuth.OwnerAddress, suite.accounts[0].String())
|
2022-12-09 04:17:14 +00:00
|
|
|
sr.Equal(registrytypes.AuthorityActive, nameAuth.Status)
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|