Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration test fixes #2314

Merged
merged 4 commits into from
Jul 30, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make WitnessesIT a word spec with a "title"
  • Loading branch information
gerolf-da committed Jul 30, 2019
commit ac185bcb4f1cdd7b3c9ea75f6ee97f1e79a4138c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import com.digitalasset.platform.apitesting.TestParties._
import com.digitalasset.platform.apitesting.{MultiLedgerFixture, TestIdsGenerator, TestTemplateIds}
import com.digitalasset.platform.participant.util.ValueConversions._
import org.scalatest.concurrent.{AsyncTimeLimitedTests, ScalaFutures}
import org.scalatest.{AsyncFreeSpec, Matchers}
import org.scalatest.{AsyncWordSpec, Matchers}

import scala.concurrent.Future

@SuppressWarnings(Array("org.wartremover.warts.Any"))
class WitnessesIT
extends AsyncFreeSpec
extends AsyncWordSpec
with AkkaBeforeAndAfterAll
with MultiLedgerFixture
with SuiteResourceManagementAroundEach
Expand All @@ -45,76 +45,80 @@ class WitnessesIT
Charlie -> Filters.defaultInstance,
))

"disclosure rules are respected" in allFixtures { ctx =>
val createArg = Record(
fields = List(
RecordField("p_signatory", Alice.asParty),
RecordField("p_observer", Bob.asParty),
RecordField("p_actor", Charlie.asParty)
))
val exerciseArg = Value(Value.Sum.Record(Record()))
"The Ledger" should {
"respect disclosure rules" in allFixtures { ctx =>
val createArg = Record(
fields = List(
RecordField("p_signatory", Alice.asParty),
RecordField("p_observer", Bob.asParty),
RecordField("p_actor", Charlie.asParty)
))
val exerciseArg = Value(Value.Sum.Record(Record()))

def exercise(cid: String, choice: String): Future[ExercisedEvent] =
ctx.testingHelpers
.submitAndListenForSingleTreeResultOfCommand(
def exercise(cid: String, choice: String): Future[ExercisedEvent] =
ctx.testingHelpers
.submitAndListenForSingleTreeResultOfCommand(
ctx.testingHelpers
.submitRequestWithId(
testIds.testCommandId(s"witnesses-$choice-exercise-${UUID.randomUUID()}"),
Charlie)
.update(
_.commands.commands :=
List(ExerciseCommand(Some(templateIds.witnesses), cid, choice, Some(exerciseArg)).wrap)
),
filter,
false
)
.map { tx =>
tx.eventsById(tx.rootEventIds(0)).kind match {
case TreeEvent.Kind.Exercised(e) => e
case _ => fail("unexpected event")
}
}

for {
// Create Witnesses contract
createTx <- ctx.testingHelpers.submitAndListenForSingleResultOfCommand(
ctx.testingHelpers
.submitRequestWithId(
testIds.testCommandId(s"witnesses-$choice-exercise-${UUID.randomUUID()}"),
Charlie)
.submitRequestWithId(testIds.testCommandId("witnesses-create"), Alice)
.update(
_.commands.commands :=
List(
ExerciseCommand(Some(templateIds.witnesses), cid, choice, Some(exerciseArg)).wrap)
List(CreateCommand(Some(templateIds.witnesses), Some(createArg)).wrap)
),
filter,
false
filter
)
.map { tx =>
tx.eventsById(tx.rootEventIds(0)).kind match {
case TreeEvent.Kind.Exercised(e) => e
case _ => fail("unexpected event")
}
}

for {
// Create Witnesses contract
createTx <- ctx.testingHelpers.submitAndListenForSingleResultOfCommand(
ctx.testingHelpers
.submitRequestWithId(testIds.testCommandId("witnesses-create"), Alice)
.update(
_.commands.commands :=
List(CreateCommand(Some(templateIds.witnesses), Some(createArg)).wrap)
),
filter
)
createdEv = ctx.testingHelpers.getHead(ctx.testingHelpers.createdEventsIn(createTx))
// Divulge Witnesses contract to charlie, who's just an actor and thus cannot
// see it by default.
divulgeCreatedEv <- ctx.testingHelpers.simpleCreate(
testIds.testCommandId("witnesses-create-divulge"),
Charlie,
templateIds.divulgeWitnesses,
Record(
fields = List(RecordField(value = Alice.asParty), RecordField(value = Charlie.asParty)))
)
_ <- ctx.testingHelpers.simpleExercise(
testIds.testCommandId("witnesses-exercise-divulge"),
Alice,
templateIds.divulgeWitnesses,
divulgeCreatedEv.contractId,
"Divulge",
Value(
Value.Sum.Record(
Record(fields = List(RecordField(value = createdEv.contractId.asContractId)))))
)
// Now, first try the non-consuming choice
nonConsumingExerciseEv <- exercise(createdEv.contractId, "WitnessesNonConsumingChoice")
// And then the consuming one
consumingExerciseEv <- exercise(createdEv.contractId, "WitnessesChoice")
} yield {
createdEv.witnessParties should contain theSameElementsAs List(Alice, Bob) // stakeholders = signatories \cup observers
nonConsumingExerciseEv.witnessParties should contain theSameElementsAs List(Alice, Charlie) // signatories \cup actors
consumingExerciseEv.witnessParties should contain theSameElementsAs List(Alice, Bob, Charlie) // stakeholders \cup actors
createdEv = ctx.testingHelpers.getHead(ctx.testingHelpers.createdEventsIn(createTx))
// Divulge Witnesses contract to charlie, who's just an actor and thus cannot
// see it by default.
divulgeCreatedEv <- ctx.testingHelpers.simpleCreate(
testIds.testCommandId("witnesses-create-divulge"),
Charlie,
templateIds.divulgeWitnesses,
Record(
fields = List(RecordField(value = Alice.asParty), RecordField(value = Charlie.asParty)))
)
_ <- ctx.testingHelpers.simpleExercise(
testIds.testCommandId("witnesses-exercise-divulge"),
Alice,
templateIds.divulgeWitnesses,
divulgeCreatedEv.contractId,
"Divulge",
Value(
Value.Sum.Record(
Record(fields = List(RecordField(value = createdEv.contractId.asContractId)))))
)
// Now, first try the non-consuming choice
nonConsumingExerciseEv <- exercise(createdEv.contractId, "WitnessesNonConsumingChoice")
// And then the consuming one
consumingExerciseEv <- exercise(createdEv.contractId, "WitnessesChoice")
} yield {
createdEv.witnessParties should contain theSameElementsAs List(Alice, Bob) // stakeholders = signatories \cup observers
nonConsumingExerciseEv.witnessParties should contain theSameElementsAs List(Alice, Charlie) // signatories \cup actors
consumingExerciseEv.witnessParties should contain theSameElementsAs List(
Alice,
Bob,
Charlie) // stakeholders \cup actors
}
}
}
}