-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add a lot of unit tests to improve the overall code coverage
Signed-off-by: Ahmed Moussa <[email protected]>
- Loading branch information
Showing
19 changed files
with
558 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
config.set({ | ||
browserDisconnectTimeout: 5000, | ||
processKillTimeout: 5000, | ||
browserDisconnectTimeout: 10000, | ||
processKillTimeout: 10000, | ||
client: { | ||
mocha: { | ||
timeout: 5000 | ||
timeout: 10000 | ||
} | ||
} | ||
}); |
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
11 changes: 11 additions & 0 deletions
11
apollo/src/androidUnitTest/kotlin/io/iohk/atala/prism/apollo/PlatformTests.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,11 @@ | ||
package io.iohk.atala.prism.apollo | ||
|
||
import org.junit.Test | ||
import kotlin.test.assertTrue | ||
|
||
class PlatformTests { | ||
@Test | ||
fun testOS() { | ||
assertTrue(Platform.OS.contains("Android")) | ||
} | ||
} |
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
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
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
71 changes: 71 additions & 0 deletions
71
apollo/src/commonTest/kotlin/io/iohk/atala/prism/apollo/derivation/BigIntegerWrapperTests.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,71 @@ | ||
package io.iohk.atala.prism.apollo.derivation | ||
|
||
import com.ionspin.kotlin.bignum.integer.toBigInteger | ||
import kotlin.random.Random | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNotEquals | ||
|
||
class BigIntegerWrapperTests { | ||
@Test | ||
fun initFromIntShouldInitializeValueCorrectly() { | ||
val intVal = Random.nextInt() | ||
val bigIntegerWrapper = BigIntegerWrapper(intVal) | ||
assertEquals(intVal.toBigInteger(), bigIntegerWrapper.value) | ||
} | ||
|
||
@Test | ||
fun initFromLongShouldInitializeValueCorrectly() { | ||
val longVal = Random.nextLong() | ||
val bigIntegerWrapper = BigIntegerWrapper(longVal) | ||
assertEquals(longVal.toBigInteger(), bigIntegerWrapper.value) | ||
} | ||
|
||
@Test | ||
fun initFromShortShouldInitializeValueCorrectly() { | ||
val shortVal = Random.nextInt(Short.MIN_VALUE.toInt(), Short.MAX_VALUE.toInt()).toShort() | ||
val bigIntegerWrapper = BigIntegerWrapper(shortVal) | ||
assertEquals(shortVal.toInt().toBigInteger(), bigIntegerWrapper.value) | ||
} | ||
|
||
@Test | ||
fun initFromByteShouldInitializeValueCorrectly() { | ||
val byteVal = Random.nextInt(Byte.MIN_VALUE.toInt(), Byte.MAX_VALUE.toInt()).toByte() | ||
val bigIntegerWrapper = BigIntegerWrapper(byteVal) | ||
assertEquals(byteVal.toInt().toBigInteger(), bigIntegerWrapper.value) | ||
} | ||
|
||
@Test | ||
fun initFromStringShouldInitializeValueCorrectly() { | ||
val strVal = Random.nextLong().toString() | ||
val bigIntegerWrapper = BigIntegerWrapper(strVal) | ||
assertEquals(strVal.toBigInteger(), bigIntegerWrapper.value) | ||
} | ||
|
||
@Test | ||
fun initFromBigIntegerShouldInitializeValueCorrectly() { | ||
val bigIntVal = Random.nextLong().toBigInteger() | ||
val bigIntegerWrapper = BigIntegerWrapper(bigIntVal) | ||
assertEquals(bigIntVal, bigIntegerWrapper.value) | ||
} | ||
|
||
@Test | ||
fun equalsShouldReturnTrueForSameObjectAndFalseForDifferentObject() { | ||
val bigIntegerWrapper1 = BigIntegerWrapper(Random.nextInt()) | ||
val bigIntegerWrapper2 = BigIntegerWrapper(bigIntegerWrapper1.value) | ||
val bigIntegerWrapper3 = BigIntegerWrapper(Random.nextInt()) | ||
|
||
assertEquals(bigIntegerWrapper1, bigIntegerWrapper2) | ||
assertNotEquals(bigIntegerWrapper1, bigIntegerWrapper3) | ||
} | ||
|
||
@Test | ||
fun hashCodeShouldReturnSameValueForSameObjectAndDifferentValueForDifferentObject() { | ||
val bigIntegerWrapper1 = BigIntegerWrapper(Random.nextInt()) | ||
val bigIntegerWrapper2 = BigIntegerWrapper(bigIntegerWrapper1.value) | ||
val bigIntegerWrapper3 = BigIntegerWrapper(Random.nextInt()) | ||
|
||
assertEquals(bigIntegerWrapper1.hashCode(), bigIntegerWrapper2.hashCode()) | ||
assertNotEquals(bigIntegerWrapper1.hashCode(), bigIntegerWrapper3.hashCode()) | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
apollo/src/commonTest/kotlin/io/iohk/atala/prism/apollo/derivation/DerivationAxisTests.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,81 @@ | ||
package io.iohk.atala.prism.apollo.derivation | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFailsWith | ||
import kotlin.test.assertFalse | ||
import kotlin.test.assertNotEquals | ||
import kotlin.test.assertTrue | ||
|
||
class DerivationAxisTests { | ||
@Test | ||
fun hardenedShouldInitializeCorrectly() { | ||
val num = 15 // Just an arbitrary number for testing | ||
|
||
val hardenedDerivationAxis = DerivationAxis.hardened(num) | ||
|
||
assertEquals(num or (1 shl 31), hardenedDerivationAxis.i) | ||
assertTrue(hardenedDerivationAxis.hardened) | ||
assertEquals(num, hardenedDerivationAxis.number) | ||
} | ||
|
||
@Test | ||
fun hardenedShouldFailOnNegativeInput() { | ||
val num = -10 | ||
assertFailsWith(IllegalArgumentException::class) { | ||
DerivationAxis.hardened(num) | ||
} | ||
} | ||
|
||
@Test | ||
fun normalShouldInitializeCorrectly() { | ||
val num = 20 // Just an arbitrary number for testing | ||
|
||
val normalDerivationAxis = DerivationAxis.normal(num) | ||
|
||
assertEquals(num, normalDerivationAxis.i) | ||
assertFalse(normalDerivationAxis.hardened) | ||
assertEquals(num, normalDerivationAxis.number) | ||
} | ||
|
||
@Test | ||
fun normalShouldFailOnNegativeInput() { | ||
val num = -10 | ||
assertFailsWith(IllegalArgumentException::class) { | ||
DerivationAxis.hardened(num) | ||
} | ||
} | ||
|
||
@Test | ||
fun toStringShouldRenderCorrectly() { | ||
val num = 25 | ||
|
||
val hardened = DerivationAxis.hardened(num) | ||
val normal = DerivationAxis.normal(num) | ||
|
||
assertEquals("$num'", hardened.toString()) | ||
assertEquals(num.toString(), normal.toString()) | ||
} | ||
|
||
@Test | ||
fun hashCodeShouldCalculateCorrectly() { | ||
val num = 30 | ||
val derivationAxis = DerivationAxis.normal(num) | ||
|
||
assertEquals(num.hashCode(), derivationAxis.hashCode()) | ||
} | ||
|
||
@Test | ||
fun equalsShouldWorkCorrectly() { | ||
val num1 = 35 | ||
val num2 = 36 | ||
|
||
val axis1 = DerivationAxis.normal(num1) | ||
val axisHardened1 = DerivationAxis.hardened(num2) | ||
val axis2 = DerivationAxis.normal(num2) | ||
|
||
assertEquals(axis1, axis1) | ||
assertNotEquals(axis1, axisHardened1) | ||
assertNotEquals(axis1, axis2) | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
apollo/src/commonTest/kotlin/io/iohk/atala/prism/apollo/derivation/DerivationPathTests.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,59 @@ | ||
package io.iohk.atala.prism.apollo.derivation | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFailsWith | ||
import kotlin.test.assertTrue | ||
|
||
class DerivationPathTests { | ||
|
||
@Test | ||
fun deriveShouldReturnNewDerivationPathWithAddedAxis() { | ||
val path = DerivationPath.empty() | ||
val axis = DerivationAxis.normal(1) | ||
|
||
val derivedPath = path.derive(axis) | ||
|
||
assertEquals(path.axes + axis, derivedPath.axes) | ||
} | ||
|
||
@Test | ||
fun emptyShouldReturnNewDerivationPathWithNoAxes() { | ||
val path = DerivationPath.empty() | ||
|
||
assertTrue(path.axes.isEmpty()) | ||
} | ||
|
||
@Test | ||
fun toStringShouldReturnCorrectStringRepresentation() { | ||
val axes = listOf(DerivationAxis.normal(1), DerivationAxis.hardened(2)) | ||
val path = DerivationPath(axes) | ||
|
||
assertEquals("m/1/2'", path.toString()) | ||
} | ||
|
||
@Test | ||
fun fromPathShouldParseStringAndReturnCorrespondingDerivationPath() { | ||
val pathStr = "m/1/2'" | ||
val path = DerivationPath.fromPath(pathStr) | ||
|
||
assertEquals(listOf(DerivationAxis.normal(1), DerivationAxis.hardened(2)), path.axes) | ||
} | ||
|
||
@Test | ||
fun fromPathShouldThrowExceptionOnIncorrectFormat() { | ||
val pathStr = "m'/1/2" | ||
|
||
assertFailsWith(IllegalArgumentException::class) { | ||
DerivationPath.fromPath(pathStr) | ||
} | ||
} | ||
|
||
@Test | ||
fun fromPathShouldThrowExceptionOnNegativeOrNonIntegerInput() { | ||
val pathStr = "m/-1/1.5" | ||
assertFailsWith(IllegalArgumentException::class) { | ||
DerivationPath.fromPath(pathStr) | ||
} | ||
} | ||
} |
Oops, something went wrong.