Fixed failing SmokeTests using Vault Query (#1032)

* Fixed failing SmokeTest caused by incorrect default count filter.

* Fixed incorrect spend value for expected assertion.

* Remove deprecated test (unintentionally merged after rebase from master)
This commit is contained in:
josecoll 2017-07-12 18:11:04 +01:00 committed by GitHub
parent 78ecff7933
commit d6deeb2bd6
3 changed files with 69 additions and 25 deletions

View File

@ -134,33 +134,10 @@ class StandaloneCordaRPClientTest {
assertEquals(1, updateCount)
}
@Test
fun `test vault`() {
val (vault, vaultUpdates) = rpcProxy.vaultAndUpdates()
assertEquals(0, vault.size)
var updateCount = 0
vaultUpdates.subscribe { update ->
log.info("Vault>> FlowId=${update.flowId}")
++updateCount
}
// Now issue some cash
rpcProxy.startFlow(::CashIssueFlow, 629.POUNDS, OpaqueBytes.of(0), notaryNode.legalIdentity, notaryNode.notaryIdentity)
.returnValue.getOrThrow(timeout)
assertNotEquals(0, updateCount)
// Check that this cash exists in the vault
val cashBalance = rpcProxy.getCashBalances()
log.info("Cash Balances: $cashBalance")
assertEquals(1, cashBalance.size)
assertEquals(629.POUNDS, cashBalance[Currency.getInstance("GBP")])
}
@Test
fun `test vault track by`() {
val (vault, vaultUpdates) = rpcProxy.vaultTrackBy<Cash.State>()
assertEquals(0, vault.totalStatesAvailable)
assertEquals(0, vault.states.size)
var updateCount = 0
vaultUpdates.subscribe { update ->

View File

@ -45,7 +45,7 @@ class HibernateVaultQueryImpl(hibernateConfig: HibernateConfiguration,
var totalStates = -1L
if (!paging.isDefault) {
val count = builder { VaultSchemaV1.VaultStates::recordedTime.count() }
val countCriteria = VaultCustomQueryCriteria(count)
val countCriteria = VaultCustomQueryCriteria(count, Vault.StateStatus.ALL)
val results = queryBy(contractType, criteria.and(countCriteria))
totalStates = results.otherResults[0] as Long
}

View File

@ -187,6 +187,30 @@ class VaultQueryTests {
}
}
@Test
fun `unconsumed states with count`() {
database.transaction {
services.fillWithSomeTestCash(25.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L))
services.fillWithSomeTestCash(25.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L))
services.fillWithSomeTestCash(25.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L))
services.fillWithSomeTestCash(25.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L))
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
val paging = PageSpecification(DEFAULT_PAGE_NUM, 10)
val resultsBeforeConsume = vaultQuerySvc.queryBy<ContractState>(criteria, paging)
assertThat(resultsBeforeConsume.states).hasSize(4)
assertThat(resultsBeforeConsume.totalStatesAvailable).isEqualTo(4)
services.consumeCash(75.DOLLARS)
val consumedCriteria = VaultQueryCriteria(status = Vault.StateStatus.UNCONSUMED)
val resultsAfterConsume = vaultQuerySvc.queryBy<ContractState>(consumedCriteria, paging)
assertThat(resultsAfterConsume.states).hasSize(1)
assertThat(resultsAfterConsume.totalStatesAvailable).isEqualTo(1)
}
}
@Test
fun `unconsumed cash states simple`() {
database.transaction {
@ -331,6 +355,30 @@ class VaultQueryTests {
}
}
@Test
fun `consumed states with count`() {
database.transaction {
services.fillWithSomeTestCash(25.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L))
services.fillWithSomeTestCash(25.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L))
services.fillWithSomeTestCash(25.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L))
services.fillWithSomeTestCash(25.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L))
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
val paging = PageSpecification(DEFAULT_PAGE_NUM, 10)
val resultsBeforeConsume = vaultQuerySvc.queryBy<ContractState>(criteria, paging)
assertThat(resultsBeforeConsume.states).hasSize(4)
assertThat(resultsBeforeConsume.totalStatesAvailable).isEqualTo(4)
services.consumeCash(75.DOLLARS)
val consumedCriteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED)
val resultsAfterConsume = vaultQuerySvc.queryBy<ContractState>(consumedCriteria, paging)
assertThat(resultsAfterConsume.states).hasSize(3)
assertThat(resultsAfterConsume.totalStatesAvailable).isEqualTo(3)
}
}
@Test
fun `all states`() {
database.transaction {
@ -349,6 +397,25 @@ class VaultQueryTests {
}
}
@Test
fun `all states with count`() {
database.transaction {
services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L))
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
val paging = PageSpecification(DEFAULT_PAGE_NUM, 10)
val resultsBeforeConsume = vaultQuerySvc.queryBy<ContractState>(criteria, paging)
assertThat(resultsBeforeConsume.states).hasSize(1)
assertThat(resultsBeforeConsume.totalStatesAvailable).isEqualTo(1)
services.consumeCash(50.DOLLARS) // consumed 100 (spent), produced 50 (change)
val resultsAfterConsume = vaultQuerySvc.queryBy<ContractState>(criteria, paging)
assertThat(resultsAfterConsume.states).hasSize(2)
assertThat(resultsAfterConsume.totalStatesAvailable).isEqualTo(2)
}
}
val CASH_NOTARY_KEY: KeyPair by lazy { entropyToKeyPair(BigInteger.valueOf(20)) }
val CASH_NOTARY: Party get() = Party(X500Name("CN=Cash Notary Service,O=R3,OU=corda,L=Zurich,C=CH"), CASH_NOTARY_KEY.public)