Skip to content

Commit

Permalink
Add ledger API test tool tests for rollback projections (#9778)
Browse files Browse the repository at this point in the history
* Add ledger API test tool tests for rollback projections

This adds 3 tests for projections under rollback nodes.

The first one is relatively clear hopefully and tests divulgence.

The other two are a bit more intricate. For both of those we can also
not test too much via the ledger API since we don’t actually get
access to rollback nodes. However, it still seems useful to at least
exercise those code paths and make sure they don’t do anything
horribbly wrong.

The second test tests the normalization rules from
https://github.com/digital-asset/daml/blob/main/docs/source/concepts/ledger-model/ledger-exceptions.rst#privacy

The last one tests a more complex structure with deeply nested
rollback nodes and different informees.

changelog_begin
changelog_end

* Update ledger/test-common/src/main/daml/semantic/Exceptions.daml

Co-authored-by: Sofia Faro <[email protected]>

Co-authored-by: Sofia Faro <[email protected]>
  • Loading branch information
cocreature and sofiafaro-da authored May 25, 2021
1 parent fb6f72c commit 1b428be
Show file tree
Hide file tree
Showing 2 changed files with 295 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ 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.testtool.infrastructure.Synchronize.synchronize
import com.daml.ledger.test.semantic.Exceptions.{Divulger, ExceptionTester, Fetcher, WithKey}
import com.daml.ledger.test.semantic.Exceptions.{
Divulger,
ExceptionTester,
Fetcher,
WithSimpleKey,
Informer,
WithKey,
WithKeyDelegate,
RollbackNestingHelper,
}
import io.grpc.Status

final class ExceptionsIT extends LedgerTestSuite {
Expand Down Expand Up @@ -114,7 +123,7 @@ final class ExceptionsIT extends LedgerTestSuite {
)(implicit ec => { case Participants(Participant(ledger, party)) =>
for {
t <- ledger.create(party, ExceptionTester(party))
withKey <- ledger.create(party, WithKey(party))
withKey <- ledger.create(party, WithSimpleKey(party))
_ <- ledger.exercise(party, t.exerciseRolledbackArchiveConsuming(_, withKey))
} yield ()
})
Expand All @@ -126,7 +135,7 @@ final class ExceptionsIT extends LedgerTestSuite {
)(implicit ec => { case Participants(Participant(ledger, party)) =>
for {
t <- ledger.create(party, ExceptionTester(party))
withKey <- ledger.create(party, WithKey(party))
withKey <- ledger.create(party, WithSimpleKey(party))
_ <- ledger.exercise(party, t.exerciseRolledbackArchiveNonConsuming(_, withKey))
} yield ()
})
Expand All @@ -150,7 +159,7 @@ final class ExceptionsIT extends LedgerTestSuite {
for {
t <- ledger.create(party, ExceptionTester(party))
_ <- ledger.exercise(party, t.exerciseDuplicateKey(_))
_ <- ledger.create(party, WithKey(party))
_ <- ledger.create(party, WithSimpleKey(party))
failure <- ledger.exercise(party, t.exerciseDuplicateKey(_)).mustFail("duplicate key")
} yield {
assertGrpcError(failure, Status.Code.ABORTED, "DuplicateKey")
Expand All @@ -164,7 +173,7 @@ final class ExceptionsIT extends LedgerTestSuite {
)(implicit ec => { case Participants(Participant(ledger, party)) =>
for {
t <- ledger.create(party, ExceptionTester(party))
withKey <- ledger.create(party, WithKey(party))
withKey <- ledger.create(party, WithSimpleKey(party))
failure <- ledger.exercise(party, t.exerciseDuplicateKey(_)).mustFail("duplicate key")
_ = assertGrpcError(failure, Status.Code.ABORTED, "DuplicateKey")
_ <- ledger.exercise(party, withKey.exerciseArchive(_))
Expand All @@ -179,7 +188,7 @@ final class ExceptionsIT extends LedgerTestSuite {
)(implicit ec => { case Participants(Participant(ledger, party)) =>
for {
t <- ledger.create(party, ExceptionTester(party))
withKey <- ledger.create(party, WithKey(party))
withKey <- ledger.create(party, WithSimpleKey(party))
_ <- ledger.exercise(party, t.exerciseFetchKey(_))
_ <- ledger.exercise(party, withKey.exerciseArchive(_))
failure <- ledger.exercise(party, t.exerciseFetchKey(_)).mustFail("couldn't find key")
Expand All @@ -198,7 +207,7 @@ final class ExceptionsIT extends LedgerTestSuite {
t <- ledger.create(party, ExceptionTester(party))
failure <- ledger.exercise(party, t.exerciseFetchKey(_)).mustFail("contract not found")
_ = assertGrpcError(failure, Status.Code.INVALID_ARGUMENT, "couldn't find key")
_ <- ledger.create(party, WithKey(party))
_ <- ledger.create(party, WithSimpleKey(party))
_ <- ledger.exercise(party, t.exerciseFetchKey(_))
} yield ()
})
Expand Down Expand Up @@ -230,7 +239,7 @@ final class ExceptionsIT extends LedgerTestSuite {
for {
divulger <- aLedger.create(aParty, Divulger(aParty, bParty))
fetcher <- bLedger.create(bParty, Fetcher(bParty, aParty))
t <- bLedger.create(bParty, WithKey(bParty))
t <- bLedger.create(bParty, WithSimpleKey(bParty))
_ <- synchronize(aLedger, bLedger)
fetchFailure <- aLedger
.exercise(aParty, fetcher.exerciseFetch(_, t))
Expand All @@ -242,4 +251,96 @@ final class ExceptionsIT extends LedgerTestSuite {
.exercise(aParty, fetcher.exerciseFetch(_, t))
} yield ()
})

test(
"ExRollbackProjectionDivulgence",
"Fetch and fetchbykey in projection divulge",
allocate(SingleParty, SingleParty),
)(implicit ec => {
case Participants(Participant(aLedger, aParty), Participant(bLedger, bParty)) =>
for {
fetcher <- bLedger.create(aParty, Fetcher(aParty, bParty))
withKey0 <- bLedger.create(aParty, WithKey(aParty, 0, List.empty))
withKey1 <- bLedger.create(aParty, WithKey(aParty, 1, List.empty))
_ <- synchronize(aLedger, bLedger)
fetchFailure <- bLedger
.exercise(bParty, fetcher.exerciseFetch_(_, withKey0))
.mustFail("contract could not be found")
_ = assertGrpcError(fetchFailure, Status.Code.ABORTED, "Contract could not be found")
fetchFailure <- bLedger
.exercise(bParty, fetcher.exerciseFetch_(_, withKey1))
.mustFail("contract could not be found")
_ = assertGrpcError(fetchFailure, Status.Code.ABORTED, "Contract could not be found")
tester <- aLedger.create(aParty, ExceptionTester(aParty))
_ <- aLedger.exercise(aParty, tester.exerciseProjectionDivulgence(_, bParty, withKey0))
_ <- synchronize(aLedger, bLedger)
_ <- bLedger
.exercise(bParty, fetcher.exerciseFetch_(_, withKey0))
_ <- bLedger
.exercise(bParty, fetcher.exerciseFetch_(_, withKey1))
} yield ()
})

test(
"ExRollbackProjectionNormalization",
"Projection normalization is correctly applied",
allocate(SingleParty, SingleParty, SingleParty),
)(implicit ec => {
// We cannot test projection & normalization directly via the ledger API
// since rollback nodes are erased so this test only ensures
// that the code paths for this are exercised and do not
// throw errors.
case Participants(
Participant(aLedger, aParty),
Participant(bLedger, bParty),
Participant(cLedger, cParty),
) =>
for {
abInformer <- aLedger.create(aParty, Informer(aParty, List(bParty)))
acInformer <- aLedger.create(aParty, Informer(aParty, List(cParty)))
abcInformer <- aLedger.create(aParty, Informer(aParty, List(bParty, cParty)))
keyDelegate <- bLedger.create(bParty, WithKeyDelegate(aParty, bParty))
_ <- synchronize(aLedger, bLedger)
_ <- synchronize(aLedger, cLedger)
tester <- aLedger.create(aParty, ExceptionTester(aParty))
_ <- aLedger.exercise(
aParty,
tester.exerciseProjectionNormalization(
_,
bParty,
keyDelegate,
abInformer,
acInformer,
abcInformer,
),
)
} yield ()
})

test(
"ExRollbackProjectionNesting",
"Nested rollback nodes are handled properly",
allocate(SingleParty, SingleParty, SingleParty),
)(implicit ec => {
// We cannot test projection & normalization directly via the ledger API
// since rollback nodes are erased so this test only ensures
// that the code paths for this are exercised and do not
// throw errors.
case Participants(
Participant(aLedger, aParty),
Participant(bLedger, bParty),
Participant(cLedger, cParty),
) =>
for {
keyDelegate <- bLedger.create(bParty, WithKeyDelegate(aParty, bParty))
nestingHelper <- cLedger.create(cParty, RollbackNestingHelper(aParty, bParty, cParty))
_ <- synchronize(aLedger, bLedger)
_ <- synchronize(aLedger, cLedger)
tester <- aLedger.create(aParty, ExceptionTester(aParty))
_ <- aLedger.exercise(
aParty,
tester.exerciseProjectionNesting(_, bParty, keyDelegate, nestingHelper),
)
} yield ()
})
}
Loading

0 comments on commit 1b428be

Please sign in to comment.