mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 17:28:46 +03:00
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:
parent
a5bf4a1282
commit
0f381db269
@ -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.",
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user