Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#110/ CollectionGuarantee type differs from protobuf schema #118

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
304 changes: 286 additions & 18 deletions sdk/src/main/kotlin/org/onflow/flow/sdk/models.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,35 @@ class AsyncFlowAccessApiImplTest {
companion object {
val BLOCK_ID_BYTES = byteArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
val PARENT_ID_BYTES = byteArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2)

const val HEIGHT = 123L

val mockBlockHeader = FlowBlockHeader(
id = FlowId.of(BLOCK_ID_BYTES),
parentId = FlowId.of(PARENT_ID_BYTES),
height = 123L,
timestamp = LocalDateTime.of(2024, 10, 15, 18, 33, 12),
payloadHash = ByteArray(32) { 0 },
view = 1L,
parentVoterSigData = ByteArray(32) { 0 },
proposerId = FlowId.of(PARENT_ID_BYTES),
proposerSigData = ByteArray(32) { 0 },
chainId = FlowChainId.MAINNET,
parentVoterIndices = ByteArray(32) { 0 },
lastViewTc = FlowTimeoutCertificate(
view = 1L,
highQcViews = emptyList(),
highestQc = FlowQuorumCertificate(
view = 1L,
blockId = FlowId.of(BLOCK_ID_BYTES),
signerIndices = ByteArray(32) { 0 },
sigData = ByteArray(32) { 0 }
),
signerIndices = ByteArray(32) { 0 },
sigData = ByteArray(32) { 0 }
),
parentView = 1L
)
}

private fun <T> setupFutureMock(response: T): ListenableFuture<T> {
Expand All @@ -48,7 +77,7 @@ class AsyncFlowAccessApiImplTest {

@Test
fun `test getLatestBlockHeader`() {
val mockBlockHeader = FlowBlockHeader(FlowId("01"), FlowId("01"), 123L)
val mockBlockHeader = mockBlockHeader
val blockHeaderResponse = Access.BlockHeaderResponse.newBuilder().setBlock(mockBlockHeader.builder().build()).build()
`when`(api.getLatestBlockHeader(any())).thenReturn(setupFutureMock(blockHeaderResponse))

Expand All @@ -60,8 +89,8 @@ class AsyncFlowAccessApiImplTest {

@Test
fun `test getBlockHeaderById`() {
val blockId = FlowId("01")
val mockBlockHeader = FlowBlockHeader(blockId, FlowId("01"), 123L)
val blockId = FlowId.of(BLOCK_ID_BYTES)
val mockBlockHeader = mockBlockHeader
val blockHeaderResponse = Access.BlockHeaderResponse.newBuilder().setBlock(mockBlockHeader.builder().build()).build()
`when`(api.getBlockHeaderByID(any())).thenReturn(setupFutureMock(blockHeaderResponse))

Expand All @@ -73,8 +102,8 @@ class AsyncFlowAccessApiImplTest {

@Test
fun `test getBlockHeaderByHeight`() {
val height = 123L
val mockBlockHeader = FlowBlockHeader(FlowId("01"), FlowId("01"), height)
val height = HEIGHT
val mockBlockHeader = mockBlockHeader
val blockHeaderResponse = Access.BlockHeaderResponse.newBuilder().setBlock(mockBlockHeader.builder().build()).build()
`when`(api.getBlockHeaderByHeight(any())).thenReturn(setupFutureMock(blockHeaderResponse))

Expand All @@ -86,7 +115,19 @@ class AsyncFlowAccessApiImplTest {

@Test
fun `test getLatestBlock`() {
val mockBlock = FlowBlock(FlowId("01"), FlowId("01"), 123L, LocalDateTime.now(), emptyList(), emptyList(), emptyList())
val mockBlock = FlowBlock(
id = FlowId.of(BLOCK_ID_BYTES),
parentId = FlowId.of(PARENT_ID_BYTES),
height = 123L,
timestamp = LocalDateTime.now(),
collectionGuarantees = emptyList(),
blockSeals = emptyList(),
signatures = emptyList(),
executionReceiptMetaList = emptyList(),
executionResultList = emptyList(),
blockHeader = mockBlockHeader,
protocolStateId = FlowId.of(ByteArray(32))
)
val blockResponse = Access.BlockResponse.newBuilder().setBlock(mockBlock.builder().build()).build()
`when`(api.getLatestBlock(any())).thenReturn(setupFutureMock(blockResponse))

Expand All @@ -98,8 +139,20 @@ class AsyncFlowAccessApiImplTest {

@Test
fun `test getBlockById`() {
val blockId = FlowId("01")
val mockBlock = FlowBlock(blockId, FlowId("01"), 123L, LocalDateTime.now(), emptyList(), emptyList(), emptyList())
val blockId = FlowId.of(BLOCK_ID_BYTES)
val mockBlock = FlowBlock(
id = blockId,
parentId = FlowId.of(PARENT_ID_BYTES),
height = 123L,
timestamp = LocalDateTime.now(),
collectionGuarantees = emptyList(),
blockSeals = emptyList(),
signatures = emptyList(),
executionReceiptMetaList = emptyList(),
executionResultList = emptyList(),
blockHeader = mockBlockHeader,
protocolStateId = FlowId.of(ByteArray(32))
)
val blockResponse = Access.BlockResponse.newBuilder().setBlock(mockBlock.builder().build()).build()
`when`(api.getBlockByID(any())).thenReturn(setupFutureMock(blockResponse))

Expand All @@ -111,8 +164,20 @@ class AsyncFlowAccessApiImplTest {

@Test
fun `test getBlockByHeight`() {
val height = 123L
val mockBlock = FlowBlock(FlowId("01"), FlowId("01"), height, LocalDateTime.now(), emptyList(), emptyList(), emptyList())
val height = HEIGHT
val mockBlock = FlowBlock(
FlowId("01"),
FlowId("01"),
height,
LocalDateTime.now(),
emptyList(),
emptyList(),
emptyList(),
emptyList(),
emptyList(),
mockBlockHeader,
FlowId.of(ByteArray(32))
)
val blockResponse = Access.BlockResponse.newBuilder().setBlock(mockBlock.builder().build()).build()
`when`(api.getBlockByHeight(any())).thenReturn(setupFutureMock(blockResponse))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,30 @@ class FlowAccessApiImplTest {
private lateinit var outputStreamCaptor: ByteArrayOutputStream
private lateinit var originalOut: PrintStream

private val api = mock(AccessAPIGrpc.AccessAPIBlockingStub::class.java)
private val executionDataApi = mock(ExecutionDataAPIGrpc.ExecutionDataAPIBlockingStub::class.java)
private val testDispatcher = TestCoroutineDispatcher()
private val testScope = TestCoroutineScope(testDispatcher)

companion object {
val mockBlockHeader = FlowBlockHeader(
id = FlowId.of(AsyncFlowAccessApiImplTest.BLOCK_ID_BYTES),
parentId = FlowId.of(AsyncFlowAccessApiImplTest.PARENT_ID_BYTES),
height = 123L,
timestamp = LocalDateTime.now(),
payloadHash = ByteArray(32),
view = 1L,
parentVoterSigData = ByteArray(32),
proposerId = FlowId.of(AsyncFlowAccessApiImplTest.PARENT_ID_BYTES),
proposerSigData = ByteArray(32),
chainId = FlowChainId.MAINNET,
parentVoterIndices = ByteArray(32),
lastViewTc = FlowTimeoutCertificate(1L, emptyList(), FlowQuorumCertificate(1L, FlowId.of(AsyncFlowAccessApiImplTest.BLOCK_ID_BYTES), ByteArray(32), ByteArray(32)), ByteArray(32), ByteArray(32)),
parentView = 1L
)

val blockId = FlowId("01")
val mockBlock = FlowBlock(blockId, FlowId("01"), 123L, LocalDateTime.now(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), mockBlockHeader, FlowId("01"))
}

@BeforeEach
fun setUp() {
mockApi = mock(AccessAPIGrpc.AccessAPIBlockingStub::class.java)
Expand All @@ -60,7 +79,7 @@ class FlowAccessApiImplTest {

@Test
fun `Test getLatestBlockHeader`() {
val mockBlockHeader = FlowBlockHeader(FlowId("01"), FlowId("01"), 123L)
val mockBlockHeader = mockBlockHeader
val blockHeaderProto = Access.BlockHeaderResponse.newBuilder().setBlock(mockBlockHeader.builder().build()).build()

`when`(mockApi.getLatestBlockHeader(any())).thenReturn(blockHeaderProto)
Expand All @@ -71,8 +90,8 @@ class FlowAccessApiImplTest {

@Test
fun `Test getBlockHeaderById`() {
val blockId = FlowId("01")
val mockBlockHeader = FlowBlockHeader(blockId, FlowId("01"), 123L)
val blockId = blockId
val mockBlockHeader = mockBlockHeader
val blockHeaderProto = Access.BlockHeaderResponse.newBuilder().setBlock(mockBlockHeader.builder().build()).build()

`when`(mockApi.getBlockHeaderByID(any())).thenReturn(blockHeaderProto)
Expand All @@ -84,7 +103,7 @@ class FlowAccessApiImplTest {
@Test
fun `Test getBlockHeaderByHeight`() {
val height = 123L
val mockBlockHeader = FlowBlockHeader(FlowId("01"), FlowId("01"), height)
val mockBlockHeader = mockBlockHeader
val blockHeaderProto = Access.BlockHeaderResponse.newBuilder().setBlock(mockBlockHeader.builder().build()).build()

`when`(mockApi.getBlockHeaderByHeight(any())).thenReturn(blockHeaderProto)
Expand All @@ -95,7 +114,7 @@ class FlowAccessApiImplTest {

@Test
fun `Test getLatestBlock`() {
val mockBlock = FlowBlock(FlowId("01"), FlowId("01"), 123L, LocalDateTime.now(), emptyList(), emptyList(), emptyList())
val mockBlock = mockBlock
val blockProto = Access.BlockResponse.newBuilder().setBlock(mockBlock.builder().build()).build()

`when`(mockApi.getLatestBlock(any())).thenReturn(blockProto)
Expand All @@ -106,9 +125,9 @@ class FlowAccessApiImplTest {

@Test
fun `Test getBlockById`() {
val blockId = FlowId("01")
val mockBlock = FlowBlock(blockId, FlowId("01"), 123L, LocalDateTime.now(), emptyList(), emptyList(), emptyList())
val blockId = blockId
val blockProto = Access.BlockResponse.newBuilder().setBlock(mockBlock.builder().build()).build()
val mockBlock = mockBlock

`when`(mockApi.getBlockByID(any())).thenReturn(blockProto)

Expand All @@ -119,7 +138,7 @@ class FlowAccessApiImplTest {
@Test
fun `Test getBlockByHeight`() {
val height = 123L
val mockBlock = FlowBlock(FlowId("01"), FlowId("01"), height, LocalDateTime.now(), emptyList(), emptyList(), emptyList())
val mockBlock = mockBlock
val blockProto = Access.BlockResponse.newBuilder().setBlock(mockBlock.builder().build()).build()

`when`(mockApi.getBlockByHeight(any())).thenReturn(blockProto)
Expand Down
Loading
Loading