Skip to content

Commit f041b75

Browse files
committed
fix(dataverse): allow getting governance addr in URI
1 parent 8c2ebef commit f041b75

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

dataverse/governance.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ func (c *queryClient) GetResourceGovAddr(ctx context.Context, resourceDID string
2828
if !ok {
2929
return "", NewDVError(ErrType, fmt.Errorf("expected URI, got %T", codeBinding.ValueType))
3030
}
31-
return string(*code.Value.Full), nil
31+
32+
codeURI := string(*code.Value.Full)
33+
addr := codeURI
34+
if i := strings.LastIndex(string(*code.Value.Full), ":"); i != -1 {
35+
addr = codeURI[i+1:]
36+
}
37+
38+
return addr, nil
3239
}
3340

3441
func (c *queryClient) AskGovPermittedActions(ctx context.Context, addr, did string) ([]string, error) {

dataverse/governance_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,30 @@ func TestClient_GetResourceGovAddr(t *testing.T) {
5050
wantErr: nil,
5151
wantResult: "foo",
5252
},
53+
{
54+
name: "ask for good did response with addr in uri",
55+
resourceDID: "did:key:zQ3shuwMJWYXRi64qiGojsV9bPN6Dtugz5YFM2ESPtkaNxTZ5",
56+
response: &cgschema.SelectResponse{
57+
Head: cgschema.Head{
58+
Vars: []string{"code"},
59+
},
60+
Results: cgschema.Results{
61+
Bindings: []map[string]cgschema.Value{
62+
{
63+
"code": cgschema.Value{
64+
ValueType: cgschema.URI{
65+
Type: "uri",
66+
Value: cgschema.IRI{Full: toAddress(cgschema.IRI_Full("contract:law-stone:foo"))},
67+
},
68+
},
69+
},
70+
},
71+
},
72+
},
73+
responseError: nil,
74+
wantErr: nil,
75+
wantResult: "foo",
76+
},
5377
{
5478
name: "grpc error",
5579
resourceDID: "did:key:zQ3shuwMJWYXRi64qiGojsV9bPN6Dtugz5YFM2ESPtkaNxTZ5",

0 commit comments

Comments
 (0)