Skip to content

Commit

Permalink
Unit and integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lealobanov committed Nov 5, 2024
1 parent e8d7a66 commit 1faecd9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sdk/src/test/kotlin/org/onflow/flow/sdk/FlowAccessApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@ class FlowAccessApiTest {
assertEquals(FlowAccessApi.AccessApiCallResponse.Success(flowCollection), result)
}

@Test
fun `Test getFullCollectionById`() {
val flowAccessApi = mock(FlowAccessApi::class.java)
val flowId = FlowId("01")
val flowTransaction = FlowTransaction.of(TransactionOuterClass.Transaction.getDefaultInstance())
`when`(flowAccessApi.getFullCollectionById(flowId)).thenReturn(FlowAccessApi.AccessApiCallResponse.Success(listOf(flowTransaction)))

val result = flowAccessApi.getFullCollectionById(flowId)

assertEquals(FlowAccessApi.AccessApiCallResponse.Success(listOf(flowTransaction)), result)
}

@Test
fun `Test sendTransaction`() {
val flowAccessApi = mock(FlowAccessApi::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ class AsyncFlowAccessApiImplTest {
.setCollection(mockCollection.builder().build())
.build()

fun fullCollectionResponse(transactions: List<FlowTransaction>) = Access.FullCollectionResponse
.newBuilder()
.addAllTransactions(transactions.map { it.builder().build() })
.build()

fun executionResultResponse(mockExecutionResult: FlowExecutionResult) = Access.ExecutionResultByIDResponse
.newBuilder()
.setExecutionResult(mockExecutionResult.builder().build())
Expand Down Expand Up @@ -413,6 +418,16 @@ class AsyncFlowAccessApiImplTest {
assertSuccess(result, mockCollection)
}

@Test
fun `test getFullCollectionById`() {
val collectionId = FlowId("01")
val mockTransaction = FlowTransaction(FlowScript("script"), emptyList(), FlowId.of("01".toByteArray()), 123L, FlowTransactionProposalKey(FlowAddress("02"), 1, 123L), FlowAddress("02"), emptyList())
`when`(api.getFullCollectionByID(any())).thenReturn(setupFutureMock(MockResponseFactory.fullCollectionResponse(listOf(mockTransaction))))

val result = asyncFlowAccessApi.getFullCollectionById(collectionId).get()
assertSuccess(result, listOf(mockTransaction))
}

@Test
fun `test sendTransaction`() {
val mockTransaction = FlowTransaction(FlowScript("script"), emptyList(), FlowId.of("01".toByteArray()), 123L, FlowTransactionProposalKey(FlowAddress("02"), 1, 123L), FlowAddress("02"), emptyList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,17 @@ class FlowAccessApiImplTest {
assertResultSuccess(result) { assertEquals(mockCollection, it) }
}

@Test
fun `Test getFullCollectionById`() {
val collectionId = FlowId("01")
val mockTransaction = createMockTransaction()

`when`(mockApi.getFullCollectionByID(any())).thenReturn(AsyncFlowAccessApiImplTest.MockResponseFactory.fullCollectionResponse(listOf(mockTransaction)))

val result = flowAccessApiImpl.getFullCollectionById(collectionId)
assertResultSuccess(result) { assertEquals(listOf(mockTransaction), it) }
}

@Test
fun `Test sendTransaction`() {
val mockTransaction = createMockTransaction()
Expand Down

0 comments on commit 1faecd9

Please sign in to comment.