Skip to content

Commit

Permalink
Factor out helpers
Browse files Browse the repository at this point in the history
changelog_begin
changelog_end
  • Loading branch information
cocreature committed Apr 20, 2021
1 parent 8476a49 commit 60a00a5
Showing 1 changed file with 47 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,43 +375,49 @@ class TransactionSpec extends AnyFreeSpec with Matchers with ScalaCheckDrivenPro
}
}

def create(builder: TransactionBuilder, parties: Seq[String], key: Option[String] = None) = {
val cid: ContractId = builder.newCid
val node = builder.create(
id = cid,
template = "-pkg-:Mod:T",
argument = V.ValueUnit,
signatories = parties,
observers = Seq(),
key = key.map(V.ValueText(_)),
)
(cid, node)
}
def exercise(
builder: TransactionBuilder,
create: Node.NodeCreate[ContractId],
parties: Seq[String],
consuming: Boolean,
) =
builder.exercise(
contract = create,
choice = "C",
actingParties = parties.toSet,
consuming = consuming,
argument = V.ValueUnit,
byKey = false,
)

"consumedContract" - {
"return the IDs of consumed contracts" in {
val builder = TransactionBuilder()
val parties = Seq("Alice")
def create() = {
val cid = builder.newCid
val node = builder.create(
cid,
template = "-pkg-:Mod:T",
argument = V.ValueUnit,
signatories = parties,
observers = Seq(),
key = None,
)
(cid, node)
}
def exercise(create: Node.NodeCreate[ContractId], consuming: Boolean) =
builder.exercise(
contract = create,
choice = "C",
actingParties = parties.toSet,
consuming = consuming,
argument = V.ValueUnit,
byKey = false,
)
val (cid0, create0) = create()
val (_, create1) = create()
val (cid2, create2) = create()
val (_, create3) = create()
builder.add(exercise(create0, true))
val (cid0, create0) = create(builder, parties)
val (_, create1) = create(builder, parties)
val (cid2, create2) = create(builder, parties)
val (_, create3) = create(builder, parties)
builder.add(exercise(builder, create0, parties, true))
builder.add(create1)
builder.add(create2)
val exeNid1 = builder.add(exercise(create1, false))
val exeNid2 = builder.add(exercise(create2, true), exeNid1)
builder.add(exercise(create3, false), exeNid2)
val exeNid1 = builder.add(exercise(builder, create1, parties, false))
val exeNid2 = builder.add(exercise(builder, create2, parties, true), exeNid1)
builder.add(exercise(builder, create3, parties, false), exeNid2)
val rollback = builder.add(builder.rollback(), exeNid2)
builder.add(exercise(create3, true), rollback)
builder.add(exercise(builder, create3, parties, true), rollback)
builder.build().consumedContracts shouldBe Set(cid0, cid2)
}
}
Expand All @@ -420,44 +426,23 @@ class TransactionSpec extends AnyFreeSpec with Matchers with ScalaCheckDrivenPro
"return all the updated contract keys" in {
val builder = TransactionBuilder()
val parties = Seq("Alice")
def create(key: String) = {
val cid = builder.newCid
val node = builder.create(
cid,
template = "-pkg-:Mod:T",
argument = V.ValueUnit,
signatories = parties,
observers = Seq(),
key = Some(V.ValueText(key)),
)
(cid, node)
}
def exercise(create: Node.NodeCreate[ContractId], consuming: Boolean) =
builder.exercise(
contract = create,
choice = "C",
actingParties = parties.toSet,
consuming = consuming,
argument = V.ValueUnit,
byKey = false,
)
val (cid0, create0) = create("key0")
val (_, create1) = create("key1")
val (_, create2) = create("key2")
val (cid3, create3) = create("key2")
val (_, create4) = create("key2")
val (_, create5) = create("key3")
val (cid0, create0) = create(builder, parties, Some("key0"))
val (_, create1) = create(builder, parties, Some("key1"))
val (_, create2) = create(builder, parties, Some("key2"))
val (cid3, create3) = create(builder, parties, Some("key2"))
val (_, create4) = create(builder, parties, Some("key2"))
val (_, create5) = create(builder, parties, Some("key3"))
builder.add(create0)
builder.add(exercise(create0, false))
builder.add(exercise(builder, create0, parties, false))
builder.add(create1)
val ex = builder.add(exercise(create1, true))
val ex = builder.add(exercise(builder, create1, parties, true))
builder.add(create2, ex)
builder.add(exercise(create2, true), ex)
builder.add(exercise(builder, create2, parties, true), ex)
builder.add(create3, ex)
val rollback = builder.add(builder.rollback())
builder.add(exercise(create0, true), rollback)
builder.add(exercise(builder, create0, parties, true), rollback)
builder.add(create5, rollback)
builder.add(exercise(create3, true), rollback)
builder.add(exercise(builder, create3, parties, true), rollback)
builder.add(create4, rollback)
def key(s: String) =
GlobalKey.assertBuild(Ref.Identifier.assertFromString("-pkg-:Mod:T"), V.ValueText(s))
Expand Down

0 comments on commit 60a00a5

Please sign in to comment.