@@ -27,6 +27,7 @@ import net.corda.core.utilities.getOrThrow
27
27
import net.corda.core.utilities.minutes
28
28
import net.corda.core.utilities.seconds
29
29
import net.corda.finance.DOLLARS
30
+ import net.corda.finance.GBP
30
31
import net.corda.finance.POUNDS
31
32
import net.corda.finance.SWISS_FRANCS
32
33
import net.corda.finance.USD
@@ -35,32 +36,35 @@ import net.corda.finance.flows.CashIssueFlow
35
36
import net.corda.finance.flows.CashPaymentFlow
36
37
import net.corda.finance.workflows.getCashBalance
37
38
import net.corda.finance.workflows.getCashBalances
38
- import net.corda.java.rpc.StandaloneCordaRPCJavaClientTest
39
39
import net.corda.nodeapi.internal.config.User
40
40
import net.corda.sleeping.SleepingFlow
41
- import net.corda.smoketesting.NodeConfig
41
+ import net.corda.smoketesting.NodeParams
42
42
import net.corda.smoketesting.NodeProcess
43
43
import org.hamcrest.text.MatchesPattern
44
44
import org.junit.After
45
+ import org.junit.AfterClass
45
46
import org.junit.Before
47
+ import org.junit.BeforeClass
46
48
import org.junit.Ignore
47
49
import org.junit.Rule
48
50
import org.junit.Test
49
51
import org.junit.rules.ExpectedException
50
52
import java.io.FilterInputStream
51
53
import java.io.InputStream
52
54
import java.io.OutputStream.nullOutputStream
53
- import java.util.Currency
55
+ import java.nio.file.Path
54
56
import java.util.concurrent.CountDownLatch
55
57
import java.util.concurrent.atomic.AtomicInteger
56
58
import java.util.regex.Pattern
59
+ import kotlin.io.path.Path
60
+ import kotlin.io.path.listDirectoryEntries
57
61
import kotlin.test.assertEquals
58
62
import kotlin.test.assertFalse
59
63
import kotlin.test.assertNotEquals
60
64
import kotlin.test.assertTrue
61
65
62
66
class StandaloneCordaRPClientTest {
63
- private companion object {
67
+ companion object {
64
68
private val log = contextLogger()
65
69
val superUser = User (" superUser" , " test" , permissions = setOf (" ALL" ))
66
70
val nonUser = User (" nonUser" , " test" , permissions = emptySet())
@@ -69,46 +73,57 @@ class StandaloneCordaRPClientTest {
69
73
val port = AtomicInteger (15200 )
70
74
const val ATTACHMENT_SIZE = 2116
71
75
val timeout = 60 .seconds
76
+
77
+ private val factory = NodeProcess .Factory ()
78
+
79
+ private lateinit var notary: NodeProcess
80
+
81
+ private val notaryConfig = NodeParams (
82
+ legalName = CordaX500Name (organisation = " Notary Service" , locality = " Zurich" , country = " CH" ),
83
+ p2pPort = port.andIncrement,
84
+ rpcPort = port.andIncrement,
85
+ rpcAdminPort = port.andIncrement,
86
+ users = listOf (superUser, nonUser, rpcUser, flowUser),
87
+ cordappJars = gatherCordapps()
88
+ )
89
+
90
+ @BeforeClass
91
+ @JvmStatic
92
+ fun startNotary () {
93
+ notary = factory.createNotaries(notaryConfig)[0 ]
94
+ }
95
+
96
+ @AfterClass
97
+ @JvmStatic
98
+ fun close () {
99
+ factory.close()
100
+ }
101
+
102
+ @JvmStatic
103
+ fun gatherCordapps (): List <Path > {
104
+ return Path (" build" , " resources" , " smokeTest" ).listDirectoryEntries(" cordapp*.jar" )
105
+ }
72
106
}
73
107
74
- private lateinit var factory: NodeProcess .Factory
75
- private lateinit var notary: NodeProcess
76
- private lateinit var rpcProxy: CordaRPCOps
77
108
private lateinit var connection: CordaRPCConnection
78
- private lateinit var notaryNode : NodeInfo
109
+ private lateinit var rpcProxy : CordaRPCOps
79
110
private lateinit var notaryNodeIdentity: Party
80
111
81
- private val notaryConfig = NodeConfig (
82
- legalName = CordaX500Name (organisation = " Notary Service" , locality = " Zurich" , country = " CH" ),
83
- p2pPort = port.andIncrement,
84
- rpcPort = port.andIncrement,
85
- rpcAdminPort = port.andIncrement,
86
- isNotary = true ,
87
- users = listOf (superUser, nonUser, rpcUser, flowUser)
88
- )
89
-
90
112
@get:Rule
91
113
val exception: ExpectedException = ExpectedException .none()
92
114
93
115
@Before
94
116
fun setUp () {
95
- factory = NodeProcess .Factory ()
96
- StandaloneCordaRPCJavaClientTest .copyCordapps(factory, notaryConfig)
97
- notary = factory.create(notaryConfig)
98
117
connection = notary.connect(superUser)
99
118
rpcProxy = connection.proxy
100
- notaryNode = fetchNotaryIdentity()
101
119
notaryNodeIdentity = rpcProxy.nodeInfo().legalIdentitiesAndCerts.first().party
102
120
}
103
121
104
122
@After
105
- fun done () {
106
- connection.use {
107
- notary.close()
108
- }
123
+ fun closeConnection () {
124
+ connection.close()
109
125
}
110
126
111
-
112
127
@Test(timeout= 300_000 )
113
128
fun `test attachments` () {
114
129
val attachment = InputStreamAndHash .createInMemoryTestZip(ATTACHMENT_SIZE , 1 )
@@ -168,8 +183,7 @@ class StandaloneCordaRPClientTest {
168
183
169
184
@Test(timeout= 300_000 )
170
185
fun `test state machines` () {
171
- val (stateMachines, updates) = rpcProxy.stateMachinesFeed()
172
- assertEquals(0 , stateMachines.size)
186
+ val (_, updates) = rpcProxy.stateMachinesFeed()
173
187
174
188
val updateLatch = CountDownLatch (1 )
175
189
val updateCount = AtomicInteger (0 )
@@ -190,8 +204,9 @@ class StandaloneCordaRPClientTest {
190
204
191
205
@Test(timeout= 300_000 )
192
206
fun `test vault track by` () {
193
- val (vault, vaultUpdates) = rpcProxy.vaultTrackBy<Cash .State >(paging = PageSpecification (DEFAULT_PAGE_NUM ))
194
- assertEquals(0 , vault.totalStatesAvailable)
207
+ val initialGbpBalance = rpcProxy.getCashBalance(GBP )
208
+
209
+ val (_, vaultUpdates) = rpcProxy.vaultTrackBy<Cash .State >(paging = PageSpecification (DEFAULT_PAGE_NUM ))
195
210
196
211
val updateLatch = CountDownLatch (1 )
197
212
vaultUpdates.subscribe { update ->
@@ -207,34 +222,35 @@ class StandaloneCordaRPClientTest {
207
222
// Check that this cash exists in the vault
208
223
val cashBalance = rpcProxy.getCashBalances()
209
224
log.info(" Cash Balances: $cashBalance " )
210
- assertEquals(1 , cashBalance.size)
211
- assertEquals(629 .POUNDS , cashBalance[Currency .getInstance(" GBP" )])
225
+ assertEquals(629 .POUNDS , cashBalance[GBP ]!! - initialGbpBalance)
212
226
}
213
227
214
228
@Test(timeout= 300_000 )
215
229
fun `test vault query by` () {
216
- // Now issue some cash
217
- rpcProxy.startFlow(::CashIssueFlow , 629 .POUNDS , OpaqueBytes .of(0 ), notaryNodeIdentity)
218
- .returnValue.getOrThrow(timeout)
219
-
220
230
val criteria = QueryCriteria .VaultQueryCriteria (status = Vault .StateStatus .ALL )
221
231
val paging = PageSpecification (DEFAULT_PAGE_NUM , 10 )
222
232
val sorting = Sort (setOf (Sort .SortColumn (SortAttribute .Standard (Sort .VaultStateAttribute .RECORDED_TIME ), Sort .Direction .DESC )))
223
233
234
+ val initialStateCount = rpcProxy.vaultQueryBy<Cash .State >(criteria, paging, sorting).totalStatesAvailable
235
+ val initialGbpBalance = rpcProxy.getCashBalance(GBP )
236
+
237
+ // Now issue some cash
238
+ rpcProxy.startFlow(::CashIssueFlow , 629 .POUNDS , OpaqueBytes .of(0 ), notaryNodeIdentity)
239
+ .returnValue.getOrThrow(timeout)
240
+
224
241
val queryResults = rpcProxy.vaultQueryBy<Cash .State >(criteria, paging, sorting)
225
- assertEquals(1 , queryResults.totalStatesAvailable)
242
+ assertEquals(1 , queryResults.totalStatesAvailable - initialStateCount )
226
243
assertEquals(queryResults.states.first().state.data.amount.quantity, 629 .POUNDS .quantity)
227
244
228
245
rpcProxy.startFlow(::CashPaymentFlow , 100 .POUNDS , notaryNodeIdentity, true , notaryNodeIdentity).returnValue.getOrThrow()
229
246
230
247
val moreResults = rpcProxy.vaultQueryBy<Cash .State >(criteria, paging, sorting)
231
- assertEquals(3 , moreResults.totalStatesAvailable) // 629 - 100 + 100
248
+ assertEquals(3 , moreResults.totalStatesAvailable - initialStateCount ) // 629 - 100 + 100
232
249
233
250
// Check that this cash exists in the vault
234
251
val cashBalances = rpcProxy.getCashBalances()
235
252
log.info(" Cash Balances: $cashBalances " )
236
- assertEquals(1 , cashBalances.size)
237
- assertEquals(629 .POUNDS , cashBalances[Currency .getInstance(" GBP" )])
253
+ assertEquals(629 .POUNDS , cashBalances[GBP ]!! - initialGbpBalance)
238
254
}
239
255
240
256
@Test(timeout= 300_000 )
0 commit comments