-
Notifications
You must be signed in to change notification settings - Fork 4
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
test: add a lot of unit tests to improve the overall code coverage #143
Conversation
23f1df4
to
92881f3
Compare
Code Coverage
|
Signed-off-by: Ahmed Moussa <[email protected]>
92881f3
to
30b6485
Compare
apollo/src/commonTest/kotlin/io/iohk/atala/prism/apollo/base64/Base64Tests.kt
Show resolved
Hide resolved
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) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok now with this tests, HDKeyTests, DerivationPathTests the same applies that ive said before.
Yes its great to add tests but we cannot just test for the sake of coverage ;), we need to add tests that are specifically targeting a test vector on a RFC or in this case a BIP, specially like in this case its something well specified on BIP 32.
BIP 32 specifies quite a few test vectors for Derivation paths and Hardened keys. This in part will make Apollo much more secure and reliable having those tests.
https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice, I will add these tests.
Overview
add a lot of unit tests to improve the overall code coverage
Fixes #
Checklist
My PR contains...
My changes...
Documentation
Tests