From be3b7b14bdf2751ef612302836546091d1ddada5 Mon Sep 17 00:00:00 2001 From: Jose Coll Date: Mon, 17 Oct 2016 11:16:53 +0100 Subject: [PATCH] Re-factoring of CashBalances code (moved to VaultService) Re-factoring of OnLedgerAsset generateSpend code (moved to VaultService) Fixed broken tests caused by missing Transaction Context (when moving from InMemory to Db implementation of vault service in MockNetwork) Adapted all Contract tests that perform Cash Spending to use the Vault Service. Note: pending resolution of 2 failing tests (IRSSimulation, CP issue, move & redeem) Fixed items raised by MH in CRD-CR-58 code review. Decommissioned InMemoryVaultService service (all dependent Tests updated to use NodeVaultService) Merge remote-tracking branch 'remotes/origin/master' into colljos-vault-code-clean-up-refactor Fixed conflict. Fixed failing Commercial Paper test. FungibleAsset reverted back to original filename. --- .../com/r3corda/contracts/asset/CashTests.kt | 47 ++++++++++++++++++- .../kotlin/com/r3corda/demos/TraderDemo.kt | 0 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/com/r3corda/demos/TraderDemo.kt diff --git a/contracts/src/test/kotlin/com/r3corda/contracts/asset/CashTests.kt b/contracts/src/test/kotlin/com/r3corda/contracts/asset/CashTests.kt index 22887040e4..3d3c9af3b1 100644 --- a/contracts/src/test/kotlin/com/r3corda/contracts/asset/CashTests.kt +++ b/contracts/src/test/kotlin/com/r3corda/contracts/asset/CashTests.kt @@ -91,6 +91,51 @@ class CashTests { dataSource.close() } + lateinit var services: MockServices + val vault: VaultService get() = services.vaultService + lateinit var dataSource: Closeable + lateinit var database: Database + lateinit var vaultService: Vault + + @Before + fun setUp() { + LogHelper.setLevel(NodeVaultService::class) + val dataSourceAndDatabase = configureDatabase(makeTestDataSourceProperties()) + dataSource = dataSourceAndDatabase.first + database = dataSourceAndDatabase.second + databaseTransaction(database) { + services = object : MockServices() { + override val keyManagementService: MockKeyManagementService = MockKeyManagementService(MINI_CORP_KEY, MEGA_CORP_KEY, OUR_KEY) + override val vaultService: VaultService = NodeVaultService(this) + + override fun recordTransactions(txs: Iterable) { + for (stx in txs) { + storageService.validatedTransactions.addTransaction(stx) + } + // Refactored to use notifyAll() as we have no other unit test for that method with multiple transactions. + vaultService.notifyAll(txs.map { it.tx }) + } + } + + services.fillWithSomeTestCash(howMuch = 100.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1, + issuedBy = MEGA_CORP.ref(1), issuerKey = MEGA_CORP_KEY, ownedBy = OUR_PUBKEY_1) + services.fillWithSomeTestCash(howMuch = 400.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1, + issuedBy = MEGA_CORP.ref(1), issuerKey = MEGA_CORP_KEY, ownedBy = OUR_PUBKEY_1) + services.fillWithSomeTestCash(howMuch = 80.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1, + issuedBy = MINI_CORP.ref(1), issuerKey = MINI_CORP_KEY, ownedBy = OUR_PUBKEY_1) + services.fillWithSomeTestCash(howMuch = 80.SWISS_FRANCS, atLeastThisManyStates = 1, atMostThisManyStates = 1, + issuedBy = MINI_CORP.ref(1), issuerKey = MINI_CORP_KEY, ownedBy = OUR_PUBKEY_1) + + vaultService = services.vaultService.currentVault + } + } + + @After + fun tearDown() { + LogHelper.reset(NodeVaultService::class) + dataSource.close() + } + @Test fun trivial() { transaction { @@ -569,7 +614,7 @@ class CashTests { databaseTransaction(database) { val tx = TransactionType.General.Builder(DUMMY_NOTARY) - vault.generateSpend(tx, 80.DOLLARS, ALICE_PUBKEY, setOf(MINI_CORP.ref(1))) + vault.generateSpend(tx, 80.DOLLARS, ALICE_PUBKEY, setOf(MINI_CORP)) assertEquals(vaultService.states.elementAt(2).ref, tx.inputStates()[0]) } diff --git a/src/main/kotlin/com/r3corda/demos/TraderDemo.kt b/src/main/kotlin/com/r3corda/demos/TraderDemo.kt new file mode 100644 index 0000000000..e69de29bb2