Skip to content

Commit

Permalink
DEV-1074: fix gRPC error, update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Toktar committed Apr 12, 2022
1 parent ce77811 commit 2db1d21
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
5 changes: 3 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
networks:
mainnet: https://rpc.cheqd.net:443
testnet: https://api.testnet.cheqd.network:443
mainnet: rpc.cheqd.net:443
testnet: 127.0.0.1:9090
# testnet: api.testnet.cheqd.network:443
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ func main() {
responseBody, err := requestService.ProcessDIDRequest(did, resolutionOption)
status := http.StatusOK
if err != "" {
// todo: defined a correct status
status = http.StatusBadRequest
}
return c.String(status, responseBody)
return c.JSONBlob(status, []byte(responseBody))
//opt := resolver.ResolutionOption{Accept: accept}
//rr := resolver.ResolveRepresentation(conn, did, opt)
//
Expand Down
6 changes: 1 addition & 5 deletions services/diddoc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ func (ds DIDDocService) prepareJWKPubkey(didDoc cheqd.Did) ([]map[string]interfa
return nil, err
}
if len(value.PublicKeyJwk) > 0 {
keyJson, err := cheqd.PubKeyJWKToJson(value.PublicKeyJwk)
if err != nil {
return nil, err
}
methodJson[publicKeyJwk] = keyJson
methodJson[publicKeyJwk] = cheqd.PubKeyJWKToMap(value.PublicKeyJwk)
}
verMethodList = append(verMethodList, methodJson)

Expand Down
15 changes: 13 additions & 2 deletions services/diddoc_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,24 @@ func TestMarshallDID(t *testing.T) {
Controller: "did:cheqd:mainnet:N22KY2Dyvmuu2PyyqSFKue",
PublicKeyMultibase: "zAKJP3f7BD6W4iWEQ9jwndVTCBq8ua2Utt8EEjJ6Vxsf",
}

verificationMethod2 := cheqd.VerificationMethod{
Id: "did:cheqd:mainnet:N22KY2Dyvmuu2PyyqSFKue#verkey",
Type: "JsonWebKey2020",
Controller: "did:cheqd:mainnet:N22KY2Dyvmuu2PyyqSFKue",
PublicKeyJwk: []*cheqd.KeyValuePair{
{"kty", "OKP"},
{"crv", "Ed25519"},
{"x", "VCpo2LMLhn6iWku8MKvSLg2ZAoC-nlOyPVQaO3FxVeQ"},
},
}
didDoc := cheqd.Did{
Context: []string{"test"},
Id: "did:cheqd:mainnet:N22KY2Dyvmuu2PyyqSFKue",
VerificationMethod: []*cheqd.VerificationMethod{&verificationMethod1},
VerificationMethod: []*cheqd.VerificationMethod{&verificationMethod1, &verificationMethod2},
}

expectedDID := "{\"@context\":[\"test\"],\"id\":\"did:cheqd:mainnet:N22KY2Dyvmuu2PyyqSFKue\",\"verificationMethod\":[{\"controller\":\"did:cheqd:mainnet:N22KY2Dyvmuu2PyyqSFKue\",\"id\":\"did:cheqd:mainnet:N22KY2Dyvmuu2PyyqSFKue#verkey\",\"publicKeyMultibase\":\"zAKJP3f7BD6W4iWEQ9jwndVTCBq8ua2Utt8EEjJ6Vxsf\",\"type\":\"Ed25519VerificationKey2020\"}]}"
expectedDID := "{\"@context\":[\"test\"],\"id\":\"did:cheqd:mainnet:N22KY2Dyvmuu2PyyqSFKue\",\"verificationMethod\":[{\"controller\":\"did:cheqd:mainnet:N22KY2Dyvmuu2PyyqSFKue\",\"id\":\"did:cheqd:mainnet:N22KY2Dyvmuu2PyyqSFKue#verkey\",\"publicKeyMultibase\":\"zAKJP3f7BD6W4iWEQ9jwndVTCBq8ua2Utt8EEjJ6Vxsf\",\"type\":\"Ed25519VerificationKey2020\"},{\"controller\":\"did:cheqd:mainnet:N22KY2Dyvmuu2PyyqSFKue\",\"id\":\"did:cheqd:mainnet:N22KY2Dyvmuu2PyyqSFKue#verkey\",\"publicKeyJwk\":{\"crv\":\"Ed25519\",\"kty\":\"OKP\",\"x\":\"VCpo2LMLhn6iWku8MKvSLg2ZAoC-nlOyPVQaO3FxVeQ\"},\"type\":\"JsonWebKey2020\"}]}"

jsonDID, err := didDocService.MarshallDID(didDoc)

Expand Down
13 changes: 5 additions & 8 deletions services/ledger_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,13 @@ func openGRPCConnection(addr string) (conn *grpc.ClientConn, err error) {
grpc.WithInsecure(),
grpc.WithBlock(),
}

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel = context.WithDeadline(ctx, <-time.After(5*time.Second))
// TODO: move to application setup
// TODO: move timeouts to a config
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
// if cancel != nil {
// cancel()
// println("openGRPCConnection: cancel")
// return nil, errors.New("gRPC connection haven't opened")
// }

conn, err = grpc.DialContext(ctx, addr, opts...)

if err != nil {
println("openGRPCConnection: context failed")
println(err.Error())
Expand Down

0 comments on commit 2db1d21

Please sign in to comment.