Fix Vault contractStateType's bootstrapping bug, and add integration test. (#3785)

This commit is contained in:
josecoll 2018-08-15 15:15:11 +01:00 committed by GitHub
parent 7a1b75ef35
commit 2b69789a30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 1 deletions

View File

@ -0,0 +1,48 @@
package net.corda.services.vault
import net.corda.core.CordaRuntimeException
import net.corda.core.contracts.FungibleAsset
import net.corda.core.messaging.startFlow
import net.corda.core.messaging.vaultQueryBy
import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.getOrThrow
import net.corda.finance.DOLLARS
import net.corda.finance.contracts.asset.Cash
import net.corda.finance.flows.CashIssueFlow
import net.corda.testing.core.DUMMY_BANK_A_NAME
import net.corda.testing.driver.DriverParameters
import net.corda.testing.driver.OutOfProcess
import net.corda.testing.driver.driver
import org.assertj.core.api.Assertions
import org.junit.Test
class VaultRestartTest {
@Test
fun `restart and query vault after adding some cash states`() {
driver(DriverParameters(inMemoryDB = false, startNodesInProcess = false,
extraCordappPackagesToScan = listOf("net.corda.finance.contracts", "net.corda.finance.schemas"))) {
val node = startNode(providedName = DUMMY_BANK_A_NAME, customOverrides = mapOf("p2pAddress" to "localhost:30000")).getOrThrow()
val expected = 500.DOLLARS
val ref = OpaqueBytes.of(0x01)
val notary = node.rpc.notaryIdentities().firstOrNull() ?: throw CordaRuntimeException("Missing notary")
val issueTx = node.rpc.startFlow(::CashIssueFlow, expected, ref, notary).returnValue.getOrThrow()
println("Issued transaction: $issueTx")
// Query vault
Assertions.assertThat(node.rpc.vaultQueryBy<Cash.State>().states).hasSize(1)
Assertions.assertThat(node.rpc.vaultQueryBy<FungibleAsset<*>>().states).hasSize(1)
// Restart the node and re-query the vault
println("Shutting down the node ...")
(node as OutOfProcess).process.destroyForcibly()
node.stop()
println("Restarting the node ...")
val restartedNode = startNode(providedName = DUMMY_BANK_A_NAME, customOverrides = mapOf("p2pAddress" to "localhost:30000")).getOrThrow()
Assertions.assertThat(restartedNode.rpc.vaultQueryBy<Cash.State>().states).hasSize(1)
Assertions.assertThat(restartedNode.rpc.vaultQueryBy<FungibleAsset<*>>().states).hasSize(1)
}
}
}

View File

@ -535,7 +535,7 @@ class NodeVaultService(
val contractTypes = deriveContractTypes(it)
contractTypes.map {
val contractStateType = contractStateTypeMappings.getOrPut(it.name) { mutableSetOf() }
contractStateType.add(it.name)
contractStateType.add(concreteType.name)
}
}
}