'Flow Testing for Cash Contract

I am trying to create a simple flow test which involves the CashV1 contract which I have adapted from the original cash contract in the corda example. The test is to simply reject the flow when one of the constraints in the cash contract are broken. for example when there are zero value transactions.

I keep getting this error:

java.lang.AssertionError: Expected an exception of class net.corda.core.contracts.TransactionVerificationException to be thrown, but was net.corda.core.transactions.MissingContractAttachments: Cannot find contract attachments for [com.example.contract.CashV1]

How is it possible to edit the flow or the test to include the attachments?



Solution 1:[1]

In V1, you have to tell the mock nodes which additional packages to scan to find the contracts you are referencing (in the future, this will be handled automatically).

See https://github.com/corda/cordapp-example/blob/release-V1/kotlin-source/src/test/kotlin/com/example/flow/IOUFlowTests.kt for an example:

@Before
fun setup() {
    // Tells the mock nodes to scan the `com.example.contract` package when looking for contract attachments.
    setCordappPackages("com.example.contract")
    ...
}

...

@After
fun tearDown() {
    unsetCordappPackages()
    ...
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Joel