sandbox: Make sure we can get the details of an empty list of parties. (#5030)

This would fail only on PostgreSQL because `IN ()` is invalid. H2 seems
to be fine with it.

CHANGELOG_BEGIN
- [Ledger API Server] Support a call to `GetParties` with an empty list
  of parties.
CHANGELOG_END
This commit is contained in:
Samir Talwar 2020-03-16 19:39:41 +01:00 committed by GitHub
parent 04196597a7
commit ad3c3b326b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 7 deletions

View File

@ -130,6 +130,7 @@ final class PartyManagement(session: LedgerSession) extends LedgerTestSuite(sess
partyDetails <- ledger.getParties(
Seq(party1, party2, binding.Primitive.Party("non-existent")))
noPartyDetails <- ledger.getParties(Seq(binding.Primitive.Party("non-existent")))
zeroPartyDetails <- ledger.getParties(Seq.empty)
} yield {
assert(
partyDetails.sortBy(_.displayName) == Seq(
@ -149,6 +150,9 @@ final class PartyManagement(session: LedgerSession) extends LedgerTestSuite(sess
assert(
noPartyDetails.isEmpty,
s"Retrieved some parties when the party specified did not exist: $noPartyDetails")
assert(
zeroPartyDetails.isEmpty,
s"Retrieved some parties when no parties were requested: $zeroPartyDetails")
}
}

View File

@ -1469,13 +1469,16 @@ private class JdbcLedgerDao(
)
override def getParties(parties: Seq[Party]): Future[List[PartyDetails]] =
dbDispatcher
.executeSql("load_parties") { implicit conn =>
SQL_SELECT_MULTIPLE_PARTIES
.on("parties" -> parties)
.as(PartyDataParser.*)
}
.map(_.map(constructPartyDetails))(executionContext)
if (parties.isEmpty)
Future.successful(List.empty)
else
dbDispatcher
.executeSql("load_parties") { implicit conn =>
SQL_SELECT_MULTIPLE_PARTIES
.on("parties" -> parties)
.as(PartyDataParser.*)
}
.map(_.map(constructPartyDetails))(executionContext)
override def listKnownParties(): Future[List[PartyDetails]] =
dbDispatcher

View File

@ -455,6 +455,14 @@ class JdbcLedgerDaoSpec
}
}
"retrieve zero parties" in {
for {
noPartyDetails <- ledgerDao.getParties(Seq.empty)
} yield {
noPartyDetails should be(Seq.empty)
}
}
"retrieve a single party, if they exist" in {
val party = Ref.Party.assertFromString(s"Carol-${UUID.randomUUID()}")
val nonExistentParty = UUID.randomUUID().toString