Skip to content

Commit

Permalink
SemanticTests synchronize/wait across participants, specify error cod…
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanobaghino-da authored Sep 16, 2019
1 parent 6368942 commit e37e3ec
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ final class SemanticTests(session: LedgerSession) extends LedgerTestSuite(sessio
owner2 <- beta.allocateParty()
shared <- alpha.create(payer, SharedContract(payer, owner1, owner2))
_ <- alpha.exercise(owner1, shared.exerciseSharedContract_Consume1)
_ <- synchronize(alpha, beta)
failure <- beta.exercise(owner2, shared.exerciseSharedContract_Consume2).failed
} yield {
assertGrpcError(failure, Status.Code.INVALID_ARGUMENT, "couldn't find contract")
Expand All @@ -102,14 +103,14 @@ final class SemanticTests(session: LedgerSession) extends LedgerTestSuite(sessio
*/

private[this] val successfulPaintOffer =
LedgerTest("SemanticPaintOffer", "Conduct the paint offer worflow successfully") { context =>
LedgerTest("SemanticPaintOffer", "Conduct the paint offer workflow successfully") { context =>
for {
Vector(alpha, beta) <- context.participants(2)
Vector(bank, houseOwner) <- alpha.allocateParties(2)
painter <- beta.allocateParty()
iou <- alpha.create(bank, Iou(bank, houseOwner, onePound))
offer <- beta.create(painter, PaintOffer(painter, houseOwner, bank, onePound))
tree <- alpha.exercise(houseOwner, offer.exercisePaintOffer_Accept(_, iou))
tree <- eventually { alpha.exercise(houseOwner, offer.exercisePaintOffer_Accept(_, iou)) }
} yield {
val agreement = assertSingleton(
"SemanticPaintOffer",
Expand Down Expand Up @@ -137,10 +138,12 @@ final class SemanticTests(session: LedgerSession) extends LedgerTestSuite(sessio
painter <- beta.allocateParty()
iou <- alpha.create(bank, Iou(bank, houseOwner, onePound))
offer <- beta.create(painter, PaintOffer(painter, houseOwner, bank, twoPounds))
counter <- alpha.exerciseAndGetContract[PaintCounterOffer](
houseOwner,
offer.exercisePaintOffer_Counter(_, iou))
tree <- beta.exercise(painter, counter.exercisePaintCounterOffer_Accept)
counter <- eventually {
alpha.exerciseAndGetContract[PaintCounterOffer](
houseOwner,
offer.exercisePaintOffer_Counter(_, iou))
}
tree <- eventually { beta.exercise(painter, counter.exercisePaintCounterOffer_Accept) }
} yield {
val agreement = assertSingleton(
"SemanticPaintCounterOffer",
Expand Down Expand Up @@ -207,39 +210,54 @@ final class SemanticTests(session: LedgerSession) extends LedgerTestSuite(sessio
Vector(bank, houseOwner) <- alpha.allocateParties(2)
painter <- beta.allocateParty()
iou <- alpha.create(bank, Iou(bank, houseOwner, onePound))
_ <- synchronize(alpha, beta)

// The IOU should be visible only to the payer and the owner
_ <- fetchIou(alpha, bank, iou)
_ <- fetchIou(alpha, houseOwner, iou)
_ <- fetchIou(beta, painter, iou).failed
iouFetchFailure <- fetchIou(beta, painter, iou).failed

offer <- beta.create(painter, PaintOffer(painter, houseOwner, bank, onePound))
_ <- synchronize(alpha, beta)

// The house owner and the painter can see the offer but the bank can't
_ <- fetchPaintOffer(alpha, houseOwner, offer)
_ <- fetchPaintOffer(beta, painter, offer)
_ <- fetchPaintOffer(alpha, bank, offer).failed
paintOfferFetchFailure <- fetchPaintOffer(alpha, bank, offer).failed

tree <- alpha.exercise(houseOwner, offer.exercisePaintOffer_Accept(_, iou))
(newIouEvent +: _, agreementEvent +: _) = createdEvents(tree).partition(
_.getTemplateId == Tag.unwrap(Iou.id))
newIou = Primitive.ContractId[Iou](newIouEvent.contractId)
agreement = Primitive.ContractId[PaintAgree](agreementEvent.contractId)
_ <- synchronize(alpha, beta)

// The Bank can see the new IOU, but it cannot see the PaintAgree contract
_ <- fetchIou(alpha, bank, newIou)
_ <- fetchPaintAgree(alpha, bank, agreement).failed
paintAgreeFetchFailure <- fetchPaintAgree(alpha, bank, agreement).failed

// The house owner and the painter can see the contract
_ <- fetchPaintAgree(beta, painter, agreement)
_ <- fetchPaintAgree(alpha, houseOwner, agreement)

// The painter sees its new IOU but the house owner cannot see it
_ <- fetchIou(beta, painter, newIou)
_ <- fetchIou(alpha, houseOwner, newIou).failed
secondIouFetchFailure <- fetchIou(alpha, houseOwner, newIou).failed

} yield {
// Nothing to do, all checks have been done in the for-comprehension
assertGrpcError(iouFetchFailure, Status.Code.INVALID_ARGUMENT, "couldn't find contract")
assertGrpcError(
paintOfferFetchFailure,
Status.Code.INVALID_ARGUMENT,
"couldn't find contract")
assertGrpcError(
paintAgreeFetchFailure,
Status.Code.INVALID_ARGUMENT,
"couldn't find contract")
assertGrpcError(
secondIouFetchFailure,
Status.Code.INVALID_ARGUMENT,
"requires one of the stakeholders")
}
}

Expand Down Expand Up @@ -288,13 +306,20 @@ final class SemanticTests(session: LedgerSession) extends LedgerTestSuite(sessio
// The owner tries to divulge with a non-consuming choice, which actually doesn't work
noDivulgeToken <- alpha.create(owner, Delegation(owner, delegate))
_ <- alpha.exercise(owner, noDivulgeToken.exerciseDelegation_Wrong_Divulge_Token(_, token))
_ <- beta.exercise(delegate, delegation.exerciseDelegation_Token_Consume(_, token)).failed
_ <- synchronize(alpha, beta)
failure <- beta
.exercise(delegate, delegation.exerciseDelegation_Token_Consume(_, token))
.failed

// Successful divulgence and delegation
divulgeToken <- alpha.create(owner, Delegation(owner, delegate))
_ <- alpha.exercise(owner, divulgeToken.exerciseDelegation_Divulge_Token(_, token))
_ <- beta.exercise(delegate, delegation.exerciseDelegation_Token_Consume(_, token))
} yield {}
_ <- eventually {
beta.exercise(delegate, delegation.exerciseDelegation_Token_Consume(_, token))
}
} yield {
assertGrpcError(failure, Status.Code.INVALID_ARGUMENT, "couldn't find contract")
}
}

/*
Expand All @@ -313,8 +338,9 @@ final class SemanticTests(session: LedgerSession) extends LedgerTestSuite(sessio
// key (bank, accountNumber._1 <> show (this.accountNumber._2)) : (Party, Text)
accountKey = DamlTuple2(bank, "CH123") //
invitation <- alpha.create(bank, AccountInvitation(accountTemplate))
account <- beta
.exerciseAndGetContract[Account](accountHolder, invitation.exerciseAccept)
account <- eventually {
beta.exerciseAndGetContract[Account](accountHolder, invitation.exerciseAccept)
}
toLookup <- alpha.create(bank, AccountLookupByKey(bank, accountKey))
lookup <- alpha.exercise(bank, toLookup.exerciseAccountLookupByKey_Execute)
toFetch <- alpha.create(bank, AccountFetchByKey(bank, accountKey))
Expand Down
1 change: 1 addition & 0 deletions unreleased.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ HEAD — ongoing
You can find more information in the `DAML Assistant documentation <https://docs.daml.com/tools/assistant.html>`_.
+ [Ledger] Upgraded ledger-api server H2 Database version to 1.4.199 with stability fixes including one to the ``merge`` statement.
+ [DAML Integration Kit] One more test case added. Transaction service tests are not multi-node aware.
+ [DAML Integration Kit] Semantic tests now ensure synchronization across participants when running in a multi-node setup.

0 comments on commit e37e3ec

Please sign in to comment.