Additional conformance test to assert verbose flag is taken into account (#14557)

* Additional conformance test to assert verbose flag is taken into account

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
Sergey Kisel 2022-07-28 12:09:08 +02:00 committed by GitHub
parent a5bf4a1282
commit 0f381db269
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,9 +7,14 @@ import com.daml.ledger.api.testtool.infrastructure.Allocation._
import com.daml.ledger.api.testtool.infrastructure.Assertions._
import com.daml.ledger.api.testtool.infrastructure.LedgerTestSuite
import com.daml.ledger.api.testtool.infrastructure.TransactionHelpers._
import com.daml.ledger.api.v1.event.CreatedEvent
import com.daml.ledger.api.v1.transaction.{Transaction, TransactionTree}
import com.daml.ledger.api.v1.value.RecordField
import com.daml.ledger.client.binding.Primitive
import com.daml.ledger.test.model.Test._
import scala.collection.immutable.Seq
class TransactionServiceOutputsIT extends LedgerTestSuite {
test(
"TXUnitAsArgumentToNothing",
@ -56,4 +61,79 @@ class TransactionServiceOutputsIT extends LedgerTestSuite {
assertEquals("AgreementTextDefault", contract.getAgreementText, "")
}
})
test(
"TXVerbosity",
"Expose field names only if the verbose flag is set to true",
allocate(SingleParty),
)(implicit ec => { case Participants(Participant(ledger, party)) =>
for {
_ <- ledger.create(party, Dummy(party))
request = ledger.getTransactionsRequest(Seq(party))
verboseTransactions <- ledger.flatTransactions(request.update(_.verbose := true))
verboseTransactionTrees <- ledger.transactionTrees(request.update(_.verbose := true))
nonVerboseTransactions <- ledger.flatTransactions(request.update(_.verbose := false))
nonVerboseTransactionTrees <- ledger.transactionTrees(request.update(_.verbose := false))
} yield {
assertLabelsAreExposedCorrectly(
party,
verboseTransactions,
verboseTransactionTrees,
labelIsNonEmpty = true,
)
assertLabelsAreExposedCorrectly(
party,
nonVerboseTransactions,
nonVerboseTransactionTrees,
labelIsNonEmpty = false,
)
}
})
private def assertLabelsAreExposedCorrectly(
party: Primitive.Party,
transactions: Seq[Transaction],
transactionTrees: Seq[TransactionTree],
labelIsNonEmpty: Boolean,
): Unit = {
def transactionFields(createdEvent: Seq[CreatedEvent]): Seq[RecordField] = createdEvent
.flatMap(_.getCreateArguments.fields)
val transactionTreeCreatedEvents: Seq[CreatedEvent] = {
for {
transactionTree <- transactionTrees
eventById <- transactionTree.eventsById
(_, tree) = eventById
createdEvent = tree.getCreated
} yield createdEvent
}
val transactionTreeFields: Seq[RecordField] =
transactionFields(transactionTreeCreatedEvents)
val flatTransactionFields: Seq[RecordField] =
transactionFields(
transactions
.flatMap(_.events)
.map(_.getCreated)
)
assert(transactions.nonEmpty, s"$party expected non empty transaction list")
assert(transactionTrees.nonEmpty, s"$party expected non empty transaction tree list")
val text = labelIsNonEmpty match {
case true => "with"
case false => "without"
}
assert(
flatTransactionFields.forall(_.label.nonEmpty == labelIsNonEmpty),
s"$party expected a contract $text labels, but received $transactions.",
)
assert(
transactionTreeFields.forall(_.label.nonEmpty == labelIsNonEmpty),
s"$party expected a contract $text labels, but received $transactionTrees.",
)
}
}