From cde761f2fbbece87aab82c7cf5ae9ec45973c81c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Peter=20Rouven=20M=C3=BCller?= Date: Wed, 19 Jan 2022 13:10:04 +0100 Subject: [PATCH] Remove unnecessary conversations and also just use unwrap for tagged strings --- ...ServiceIntegrationTestUserManagement.scala | 29 +++++++++---------- .../scala/com/digitalasset/http/domain.scala | 9 +++--- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ledger-service/http-json/src/it/scala/http/HttpServiceIntegrationTestUserManagement.scala b/ledger-service/http-json/src/it/scala/http/HttpServiceIntegrationTestUserManagement.scala index f1edb937230f..8179698581c5 100644 --- a/ledger-service/http-json/src/it/scala/http/HttpServiceIntegrationTestUserManagement.scala +++ b/ledger-service/http-json/src/it/scala/http/HttpServiceIntegrationTestUserManagement.scala @@ -26,6 +26,7 @@ import scalaz.syntax.show._ import spray.json.JsValue import scala.concurrent.Future +import scalaz.syntax.tag._ @SuppressWarnings(Array("org.wartremover.warts.NonUnitStatements")) trait HttpServiceIntegrationTestUserManagementFuns @@ -52,7 +53,7 @@ trait HttpServiceIntegrationTestUserManagementFuns def headersWithUserAuth(userId: String): List[Authorization] = authorizationHeader(jwtForUser(userId)) - def getUniqueUserName(name: String): String = getUniqueParty(name).toString + def getUniqueUserName(name: String): String = getUniqueParty(name).unwrap } @@ -72,8 +73,6 @@ class HttpServiceIntegrationTestUserManagementNoAuth override def wsConfig: Option[WebsocketConfig] = None - import scalaz.syntax.tag._ - "Json format of UserRight should be stable" in Future { import spray.json._ val ham = getUniqueParty("ham") @@ -100,7 +99,7 @@ class HttpServiceIntegrationTestUserManagementNoAuth user <- createUser(ledgerClient)( Ref.UserId.assertFromString(getUniqueUserName("nice.user")), initialRights = List( - CanActAs(Ref.Party.assertFromString(alice.toString)) + CanActAs(Ref.Party.assertFromString(alice.unwrap)) ), ) (status, output) <- postJsonRequest( @@ -128,7 +127,7 @@ class HttpServiceIntegrationTestUserManagementNoAuth user <- createUser(ledgerClient)( Ref.UserId.assertFromString(getUniqueUserName("nice.user")), initialRights = List( - CanActAs(Ref.Party.assertFromString(bob.toString)) + CanActAs(Ref.Party.assertFromString(bob.unwrap)) ), ) (status, output) <- postJsonRequest( @@ -156,8 +155,8 @@ class HttpServiceIntegrationTestUserManagementNoAuth user <- createUser(ledgerClient)( Ref.UserId.assertFromString(getUniqueUserName("nice.user")), initialRights = List( - CanActAs(Ref.Party.assertFromString(alice.toString)), - CanActAs(Ref.Party.assertFromString(bob.toString)), + CanActAs(Ref.Party.assertFromString(alice.unwrap)), + CanActAs(Ref.Party.assertFromString(bob.unwrap)), ), ) (status, output) <- postJsonRequest( @@ -190,7 +189,7 @@ class HttpServiceIntegrationTestUserManagementNoAuth assertStatus(output, StatusCodes.OK) getResult(output).convertTo[UserDetails] shouldEqual UserDetails( user.id, - user.primaryParty.map(_.toString), + user.primaryParty: Option[String], ) } } yield assertion @@ -206,8 +205,8 @@ class HttpServiceIntegrationTestUserManagementNoAuth user <- createUser(ledgerClient)( Ref.UserId.assertFromString(getUniqueUserName("nice.user")), initialRights = List( - CanActAs(Ref.Party.assertFromString(alice.toString)), - CanActAs(Ref.Party.assertFromString(bob.toString)), + CanActAs(Ref.Party.assertFromString(alice.unwrap)), + CanActAs(Ref.Party.assertFromString(bob.unwrap)), ), ) (status, output) <- postRequest( @@ -236,8 +235,8 @@ class HttpServiceIntegrationTestUserManagementNoAuth user <- createUser(ledgerClient)( Ref.UserId.assertFromString(getUniqueUserName("nice.user")), initialRights = List( - CanActAs(Ref.Party.assertFromString(alice.toString)), - CanActAs(Ref.Party.assertFromString(bob.toString)), + CanActAs(Ref.Party.assertFromString(alice.unwrap)), + CanActAs(Ref.Party.assertFromString(bob.unwrap)), ), ) (status, output) <- getRequest( @@ -486,7 +485,7 @@ class HttpServiceIntegrationTestUserManagementNoAuth user <- createUser(ledgerClient)( Ref.UserId.assertFromString(getUniqueUserName("nice.user")), initialRights = List( - CanActAs(Ref.Party.assertFromString(alice)) + CanActAs(Ref.Party.assertFromString(alice.unwrap)) ), ) (status, output) <- postRequest( @@ -543,8 +542,8 @@ class HttpServiceIntegrationTestUserManagementNoAuth user <- createUser(ledgerClient)( Ref.UserId.assertFromString(getUniqueUserName("nice.user")), initialRights = List( - CanActAs(Ref.Party.assertFromString(alice.toString)), - CanActAs(Ref.Party.assertFromString(bob.toString)), + CanActAs(Ref.Party.assertFromString(alice.unwrap)), + CanActAs(Ref.Party.assertFromString(bob.unwrap)), ParticipantAdmin, ), ) diff --git a/ledger-service/http-json/src/main/scala/com/digitalasset/http/domain.scala b/ledger-service/http-json/src/main/scala/com/digitalasset/http/domain.scala index ac051dba3fe8..f107bd017bec 100644 --- a/ledger-service/http-json/src/main/scala/com/digitalasset/http/domain.scala +++ b/ledger-service/http-json/src/main/scala/com/digitalasset/http/domain.scala @@ -142,23 +142,24 @@ object domain extends com.daml.fetchcontracts.domain.Aliases { import com.daml.ledger.api.domain.{UserRight => LedgerUserRight}, com.daml.lf.data.Ref import scalaz.syntax.traverse._ import scalaz.syntax.std.either._ + import scalaz.syntax.tag._ def toLedgerUserRights(input: List[UserRight]): String \/ List[LedgerUserRight] = input.traverse { case ParticipantAdmin => \/.right(LedgerUserRight.ParticipantAdmin) case CanActAs(party) => - Ref.Party.fromString(Party.unwrap(party)).map(LedgerUserRight.CanActAs).disjunction + Ref.Party.fromString(party.unwrap).map(LedgerUserRight.CanActAs).disjunction case CanReadAs(party) => - Ref.Party.fromString(Party.unwrap(party)).map(LedgerUserRight.CanReadAs).disjunction + Ref.Party.fromString(party.unwrap).map(LedgerUserRight.CanReadAs).disjunction } def fromLedgerUserRights(input: Vector[LedgerUserRight]): List[UserRight] = input .map[domain.UserRight] { case LedgerUserRight.ParticipantAdmin => ParticipantAdmin case LedgerUserRight.CanActAs(party) => - CanActAs(Party(party.toString: String)) + CanActAs(Party(party: String)) case LedgerUserRight.CanReadAs(party) => - CanReadAs(Party(party.toString: String)) + CanReadAs(Party(party: String)) } .toList }