-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db9e3d1
commit 218b5e2
Showing
3 changed files
with
261 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
sdk/src/test/kotlin/org/onflow/flow/sdk/models/FlowAggregatedSignatureTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.onflow.flow.sdk.models | ||
|
||
import org.onflow.flow.sdk.FlowAggregatedSignature | ||
import org.onflow.flow.sdk.FlowId | ||
import org.onflow.flow.sdk.FlowSignature | ||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.Mockito | ||
import org.onflow.protobuf.entities.BlockSealOuterClass | ||
|
||
class FlowAggregatedSignatureTest { | ||
@Test | ||
fun `test FlowAggregatedSignature equals and hashCode`() { | ||
val signature1 = FlowSignature("signature1".toByteArray()) | ||
val signature2 = FlowSignature("signature2".toByteArray()) | ||
|
||
val signerId1 = FlowId.of("signerId1".toByteArray()) | ||
val signerId2 = FlowId.of("signerId2".toByteArray()) | ||
|
||
val aggregatedSignature1 = FlowAggregatedSignature( | ||
verifierSignatures = listOf(signature1), | ||
signerIds = listOf(signerId1) | ||
) | ||
|
||
val aggregatedSignature2 = FlowAggregatedSignature( | ||
verifierSignatures = listOf(signature1), | ||
signerIds = listOf(signerId1) | ||
) | ||
|
||
val aggregatedSignature3 = FlowAggregatedSignature( | ||
verifierSignatures = listOf(signature2), | ||
signerIds = listOf(signerId2) | ||
) | ||
|
||
// Test equality | ||
assertEquals(aggregatedSignature1, aggregatedSignature2) | ||
assertNotEquals(aggregatedSignature1, aggregatedSignature3) | ||
|
||
// Test hashCode | ||
assertEquals(aggregatedSignature1.hashCode(), aggregatedSignature2.hashCode()) | ||
assertNotEquals(aggregatedSignature1.hashCode(), aggregatedSignature3.hashCode()) | ||
} | ||
|
||
@Test | ||
fun `test FlowAggregatedSignature of function`() { | ||
// Mock BlockSealOuterClass.AggregatedSignature | ||
val aggregatedSignatureProto = Mockito.mock(BlockSealOuterClass.AggregatedSignature::class.java) | ||
|
||
val signatureBytes = "signature".toByteArray() | ||
val signerIdBytes = "signerId".toByteArray() | ||
|
||
Mockito.`when`(aggregatedSignatureProto.verifierSignaturesList).thenReturn( | ||
listOf(com.google.protobuf.ByteString.copyFrom(signatureBytes)) | ||
) | ||
Mockito.`when`(aggregatedSignatureProto.signerIdsList).thenReturn( | ||
listOf(com.google.protobuf.ByteString.copyFrom(signerIdBytes)) | ||
) | ||
|
||
val flowAggregatedSignature = FlowAggregatedSignature.of(aggregatedSignatureProto) | ||
|
||
assertEquals(1, flowAggregatedSignature.verifierSignatures.size) | ||
assertEquals(FlowSignature(signatureBytes), flowAggregatedSignature.verifierSignatures[0]) | ||
|
||
assertEquals(1, flowAggregatedSignature.signerIds.size) | ||
assertEquals(FlowId.of(signerIdBytes), flowAggregatedSignature.signerIds[0]) | ||
} | ||
|
||
@Test | ||
fun `test FlowAggregatedSignature builder function`() { | ||
val signature1 = FlowSignature("signature1".toByteArray()) | ||
val signerId1 = FlowId.of("signerId1".toByteArray()) | ||
|
||
val aggregatedSignature = FlowAggregatedSignature( | ||
verifierSignatures = listOf(signature1), | ||
signerIds = listOf(signerId1) | ||
) | ||
|
||
val builderResult = aggregatedSignature.builder() | ||
|
||
assertEquals(listOf(signature1.byteStringValue), builderResult.verifierSignaturesList) | ||
assertEquals(listOf(signerId1.byteStringValue), builderResult.signerIdsList) | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
sdk/src/test/kotlin/org/onflow/flow/sdk/models/FlowBlockSealTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package org.onflow.flow.sdk.models | ||
|
||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.Mockito | ||
import org.onflow.flow.sdk.FlowAggregatedSignature | ||
import org.onflow.flow.sdk.FlowBlockSeal | ||
import org.onflow.flow.sdk.FlowId | ||
import org.onflow.flow.sdk.FlowSignature | ||
import org.onflow.protobuf.entities.BlockSealOuterClass | ||
|
||
class FlowBlockSealTest { | ||
@Test | ||
fun `test FlowBlockSeal equals and hashCode`() { | ||
val blockId = FlowId.of("blockId".toByteArray()) | ||
val executionReceiptId = FlowId.of("executionReceiptId".toByteArray()) | ||
val resultId = FlowId.of("resultId".toByteArray()) | ||
val finalState = "finalState".toByteArray() | ||
|
||
val signature1 = FlowSignature("signature1".toByteArray()) | ||
val signature2 = FlowSignature("signature2".toByteArray()) | ||
|
||
val aggregatedSignature1 = FlowAggregatedSignature( | ||
verifierSignatures = listOf(signature1), | ||
signerIds = listOf(blockId) | ||
) | ||
|
||
val seal1 = FlowBlockSeal( | ||
blockId = blockId, | ||
executionReceiptId = executionReceiptId, | ||
executionReceiptSignatures = listOf(signature1), | ||
resultApprovalSignatures = listOf(signature2), | ||
finalState = finalState, | ||
resultId = resultId, | ||
aggregatedApprovalSigs = listOf(aggregatedSignature1) | ||
) | ||
|
||
val seal2 = FlowBlockSeal( | ||
blockId = blockId, | ||
executionReceiptId = executionReceiptId, | ||
executionReceiptSignatures = listOf(signature1), | ||
resultApprovalSignatures = listOf(signature2), | ||
finalState = finalState, | ||
resultId = resultId, | ||
aggregatedApprovalSigs = listOf(aggregatedSignature1) | ||
) | ||
|
||
// Testing equals | ||
assertEquals(seal1, seal2) | ||
|
||
// Testing hashCode | ||
assertEquals(seal1.hashCode(), seal2.hashCode()) | ||
} | ||
|
||
@Test | ||
fun `test FlowBlockSeal of function`() { | ||
// Mock BlockSealOuterClass.BlockSeal | ||
val blockSealProto = Mockito.mock(BlockSealOuterClass.BlockSeal::class.java) | ||
|
||
val blockIdBytes = "blockId".toByteArray() | ||
val executionReceiptIdBytes = "executionReceiptId".toByteArray() | ||
val resultIdBytes = "resultId".toByteArray() | ||
val finalStateBytes = "finalState".toByteArray() | ||
|
||
Mockito.`when`(blockSealProto.blockId).thenReturn(com.google.protobuf.ByteString.copyFrom(blockIdBytes)) | ||
Mockito.`when`(blockSealProto.executionReceiptId).thenReturn(com.google.protobuf.ByteString.copyFrom(executionReceiptIdBytes)) | ||
Mockito.`when`(blockSealProto.resultId).thenReturn(com.google.protobuf.ByteString.copyFrom(resultIdBytes)) | ||
Mockito.`when`(blockSealProto.finalState).thenReturn(com.google.protobuf.ByteString.copyFrom(finalStateBytes)) | ||
Mockito.`when`(blockSealProto.executionReceiptSignaturesList).thenReturn(listOf( | ||
com.google.protobuf.ByteString.copyFrom("signature1".toByteArray()) | ||
)) | ||
Mockito.`when`(blockSealProto.resultApprovalSignaturesList).thenReturn(listOf( | ||
com.google.protobuf.ByteString.copyFrom("signature2".toByteArray()) | ||
)) | ||
Mockito.`when`(blockSealProto.aggregatedApprovalSigsList).thenReturn(listOf( | ||
BlockSealOuterClass.AggregatedSignature.newBuilder().build() | ||
)) | ||
|
||
val flowBlockSeal = FlowBlockSeal.of(blockSealProto) | ||
|
||
assertEquals(FlowId.of(blockIdBytes), flowBlockSeal.blockId) | ||
assertEquals(FlowId.of(executionReceiptIdBytes), flowBlockSeal.executionReceiptId) | ||
assertEquals(FlowId.of(resultIdBytes), flowBlockSeal.resultId) | ||
assertArrayEquals(finalStateBytes, flowBlockSeal.finalState) | ||
} | ||
|
||
@Test | ||
fun `test FlowBlockSeal builder function`() { | ||
val blockId = FlowId.of("blockId".toByteArray()) | ||
val executionReceiptId = FlowId.of("executionReceiptId".toByteArray()) | ||
val resultId = FlowId.of("resultId".toByteArray()) | ||
val finalState = "finalState".toByteArray() | ||
|
||
val signature1 = FlowSignature("signature1".toByteArray()) | ||
val signature2 = FlowSignature("signature2".toByteArray()) | ||
val aggregatedSignature1 = FlowAggregatedSignature( | ||
verifierSignatures = listOf(signature1), | ||
signerIds = listOf(blockId) | ||
) | ||
|
||
val seal = FlowBlockSeal( | ||
blockId = blockId, | ||
executionReceiptId = executionReceiptId, | ||
executionReceiptSignatures = listOf(signature1), | ||
resultApprovalSignatures = listOf(signature2), | ||
finalState = finalState, | ||
resultId = resultId, | ||
aggregatedApprovalSigs = listOf(aggregatedSignature1) | ||
) | ||
|
||
val builderResult = seal.builder() | ||
|
||
assertEquals(blockId.byteStringValue, builderResult.blockId) | ||
assertEquals(executionReceiptId.byteStringValue, builderResult.executionReceiptId) | ||
assertEquals(resultId.byteStringValue, builderResult.resultId) | ||
assertEquals(finalState.toList(), builderResult.finalState.toByteArray().toList()) | ||
assertEquals(listOf(signature1.byteStringValue), builderResult.executionReceiptSignaturesList) | ||
assertEquals(listOf(signature2.byteStringValue), builderResult.resultApprovalSignaturesList) | ||
} | ||
} |