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

test: add a lot of unit tests to improve the overall code coverage #143

Closed
wants to merge 2 commits into from

Conversation

hamada147
Copy link
Contributor

Overview

add a lot of unit tests to improve the overall code coverage

Fixes #

Checklist

My PR contains...

  • No code changes (changes to documentation, CI, metadata, etc.)
  • Bug fixes (non-breaking change which fixes an issue)
  • Improvements (misc. changes to existing features)
  • Features (non-breaking change which adds functionality)

My changes...

  • are breaking changes
  • are not breaking changes
  • If yes to above: I have updated the documentation accordingly

Documentation

  • My changes do not require a change to the project documentation
  • My changes require a change to the project documentation
  • If yes to above: I have updated the documentation accordingly

Tests

  • My changes can not or do not need to be tested
  • My changes can and should be tested by unit and/or integration tests
  • If yes to above: I have added tests to cover my changes
  • If yes to above: I have taken care to cover edge cases in my tests

@hamada147 hamada147 added the enhancement New feature or request label Dec 25, 2023
@hamada147 hamada147 self-assigned this Dec 25, 2023
@hamada147 hamada147 force-pushed the add-much-more-unit-tests branch from 23f1df4 to 92881f3 Compare December 25, 2023 03:36
@hamada147 hamada147 force-pushed the add-much-more-unit-tests branch from 92881f3 to 30b6485 Compare December 25, 2023 03:44
Comment on lines +10 to +81
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)
}
}
Copy link
Contributor

@goncalo-frade-iohk goncalo-frade-iohk Dec 27, 2023

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

Copy link
Contributor Author

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.

@hamada147 hamada147 closed this May 31, 2024
@hamada147 hamada147 deleted the add-much-more-unit-tests branch May 31, 2024 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants