Skip to content
Merged
Show file tree
Hide file tree
Changes from 163 commits
Commits
Show all changes
165 commits
Select commit Hold shift + click to select a range
a746d3d
Merge pull request #53 from gruntsoftware/release/v4.4.1
kcw-grunt Mar 30, 2025
ba8ea45
Revert "Updated the APIManager"
kcw-grunt Mar 31, 2025
638ce3a
Reverted the Kotlin APIManager.
kcw-grunt Mar 31, 2025
5344a96
Add version and code to welcome screen
kcw-grunt Mar 31, 2025
ebc3bb9
reset padding
kcw-grunt Mar 31, 2025
03c68b8
Merge pull request #56 from gruntsoftware/feature/add-version-issue-108
kcw-grunt Apr 1, 2025
c770f01
Revert "Updated the APIManager"
kcw-grunt Mar 31, 2025
f8c1bd5
Reverted the Kotlin APIManager.
kcw-grunt Mar 31, 2025
ff58b57
fix: fix crash when FragmentSignal dismissed
andhikayuana Apr 4, 2025
d64ea93
fix: fix sync after wipe
andhikayuana Apr 7, 2025
277f387
Merge branch 'hotfix/api-manager-fix' of https://github.com/brainwall…
kcw-grunt Apr 7, 2025
9a8a20f
fix: fix wrong lifecycle to trigger callback at FragmentSignal
andhikayuana Apr 7, 2025
832fa36
Update issue templates
kcw-grunt Apr 8, 2025
b294cd6
updated core changes
kcw-grunt Apr 8, 2025
4ed8af3
Merge pull request #57 from gruntsoftware/hotfix/api-manager-fix
kcw-grunt Apr 8, 2025
089995a
Rename .java to .kt
andhikayuana Apr 11, 2025
7e85987
chore: refactor BRApiManager & APIClient
andhikayuana Apr 11, 2025
0aa41e7
chore: remove unused part at APIClient
andhikayuana Apr 14, 2025
0cc29cb
feat: wip new peer discovery
andhikayuana Apr 14, 2025
54d2d9e
feat: implement selected peer ip address from cache (fetched from API)
andhikayuana Apr 14, 2025
c6923b1
feat: implement selected peer ip address from cache (fetched from API)
andhikayuana Apr 14, 2025
ef4e6d2
feat: filter out peers with NODE_NETWORK, NODE_BLOOM
andhikayuana Apr 15, 2025
2336939
fix: race condition when clear shared prefs values after wipeAll
andhikayuana Apr 16, 2025
51a4d9a
Merge pull request #62 from gruntsoftware/hotfix/prefs-race-condition
kcw-grunt Apr 16, 2025
62afb9d
Merge pull request #61 from gruntsoftware/feat/new-peer-discovery
kcw-grunt Apr 16, 2025
391e319
Updating the core library
kcw-grunt Apr 16, 2025
836b6f0
Chore/revert pre peer discovery (Android) (#69)
andhikayuana Apr 25, 2025
3caa1a7
feat: remove unused activity (ImportActivity) at AndroidManifest.xml …
andhikayuana Apr 29, 2025
a324444
fix: fix crash IllegalStateException: cannot make a new request becau…
andhikayuana May 2, 2025
1f9c5d0
code bump
kcw-grunt May 2, 2025
7ca17d3
Feat/move tx fee (#74)
andhikayuana May 5, 2025
e7fb2b7
fix: fix dismiss allow state loss (#76)
andhikayuana May 7, 2025
3d8ef98
fix: fix typo at strings.xml (#75)
andhikayuana May 7, 2025
25be1a8
feat: new UI for receive and topup flow (moonpay integration) (#72)
andhikayuana May 12, 2025
18eda46
version and code bump
kcw-grunt May 12, 2025
dbb6a5f
Added support url (#81)
kcw-grunt May 19, 2025
c82a5e3
version and code bump
kcw-grunt May 19, 2025
2981ec6
Revert from eda0f532 & cherry pick (#86)
andhikayuana May 25, 2025
c161fed
build bump
kcw-grunt May 25, 2025
63d7494
chore: open bread activity first then open moonpay widget (#88)
andhikayuana May 26, 2025
f09eb28
Adjustment for circleci (#89)
andhikayuana May 29, 2025
47c69cd
fix: android: Footer version label is obfuscated (#92)
andhikayuana May 29, 2025
a9c4a63
fix: You saved it right screen reset button covers words (#93)
andhikayuana May 29, 2025
d8f08ad
tiny resizing (#94)
kcw-grunt May 29, 2025
ef93585
code and version bump
kcw-grunt May 29, 2025
174d612
change break (#97)
kcw-grunt May 30, 2025
a4521d7
build code number
andhikayuana May 31, 2025
6fec1e2
fix: [#137] fix: Reset fiat options in Buy / Receive modal (#99)
andhikayuana Jun 2, 2025
c8fdf8d
Chore/update device data (#100)
kcw-grunt Jun 2, 2025
3f646df
Add agent string obfuscation (#103)
kcw-grunt Jun 14, 2025
642f9e6
updated metadata (#105)
kcw-grunt Jun 24, 2025
50f44de
chore: remove screen lock detection (#106)
andhikayuana Jun 24, 2025
ea15423
🧰 Fx/seed words UI polish (#108)
kcw-grunt Jun 25, 2025
5b6dff3
❇️ Feat/add polish punjabi farsi (#109)
kcw-grunt Jun 27, 2025
4ff50b8
fix: fix YourSeedProveItState.isWordUsedCorrectly (#111)
andhikayuana Jun 29, 2025
2fd094f
Upgrade targetSdk 36 (#113)
andhikayuana Aug 5, 2025
4efd95f
feat(#195): adopt koin annotation for dependency injection (#120)
JosephSanjaya Aug 18, 2025
5900ed4
Create PULL_REQUEST_TEMPLATE.md
kcw-grunt Aug 19, 2025
3b1f628
bump for test (#121)
kcw-grunt Aug 19, 2025
f11d5a8
feat(#174): initiate games module (#119)
JosephSanjaya Aug 20, 2025
77ed7df
Force pushed the version and code bump and catch up with Prod.
kcw-grunt Aug 20, 2025
ef353e3
🚀[Release v4.7.2] Merge into Develop (#127)
kcw-grunt Aug 25, 2025
e25e9e1
Fix(#227): Crash when launching MoonPay Widget (#126)
JosephSanjaya Aug 25, 2025
e0aebb5
feat(#138): Improve Unlock Screen UI and add dark mode toggle (#122)
JosephSanjaya Aug 25, 2025
7d8dd14
Redesign welcome screen (#123)
josikie Aug 25, 2025
18df293
fix(#226): android test failure on RecoverWalletScreenGrabsTest (#130)
JosephSanjaya Aug 26, 2025
9b191b7
fix(#223): fix issue on test environment SLF4J + agent warnings in te…
JosephSanjaya Aug 26, 2025
c9b1ef0
feat(#225): Send sync duration in Firebase Analytics as a custom even…
JosephSanjaya Aug 30, 2025
58f0cd8
feat(#234): Implement language-specific Firebase messaging topics (#132)
JosephSanjaya Aug 30, 2025
4bb06cf
bump code
kcw-grunt Aug 30, 2025
9f4908b
chore(#234): normalize Indonesian language code to "id" (#133)
JosephSanjaya Aug 30, 2025
4a27ae0
Feat: Detekt and Test Plugins, (Including Create Detekt Baseline) (#136)
JosephSanjaya Sep 22, 2025
3285d8e
Chore/renamed gp module (#140)
kcw-grunt Sep 29, 2025
94459d0
create private gp submodule
kcw-grunt Sep 23, 2025
13c39a0
Update settings.gradle.kts
kcw-grunt Sep 23, 2025
c0683ad
chore: Migrate build logic to version catalog and update submodules
JosephSanjaya Sep 24, 2025
2fcb1b2
feat(deps): add kotlin-immutable dependency
JosephSanjaya Oct 5, 2025
631b4f6
refactor(app): Relocate core module imports
JosephSanjaya Oct 8, 2025
0b46614
Merge pull request #141 from gruntsoftware/js/feat/iap
JosephSanjaya Oct 9, 2025
279fa23
build bump
kcw-grunt Oct 9, 2025
5ea5fe9
Merge branch 'main' into release/v4.8.0
kcw-grunt Oct 9, 2025
779f47f
removed cruft
kcw-grunt Oct 9, 2025
05813ad
chore(submodules): remove bugged games repository
JosephSanjaya Oct 10, 2025
67000e9
bump code
kcw-grunt Oct 10, 2025
83f1b85
Release/v4.8.0 (#147)
kcw-grunt Oct 13, 2025
798b7c9
Merge branch 'develop' of https://github.com/brainwallet-co/android i…
kcw-grunt Oct 18, 2025
d5b14db
bug(crashlytics): Remove InputWordsActivity from AndroidManifest
JosephSanjaya Oct 18, 2025
a08c6f6
fix(crashlytics): resolve ReEnterPinActivity crashes and deprecation …
JosephSanjaya Oct 22, 2025
56be50f
Remove resizability and orientation restrictions in our app (#146)
josikie Oct 22, 2025
2f06f5c
build: Build secp256k1 as a static library and add ABI splits (#149)
JosephSanjaya Nov 14, 2025
aeb5ab5
version bump (#159)
kcw-grunt Feb 7, 2026
8cabf2a
Revert "build: Build secp256k1 as a static library and add ABI splits…
kcw-grunt Feb 7, 2026
0a46627
Techdebt/adjust build logic (#161)
kcw-grunt Feb 8, 2026
5738254
Added auto translate (#178)
kcw-grunt Apr 9, 2026
25fcc5d
Add auto-translate workflow for strings.xml
kcw-grunt Apr 12, 2026
34e6d65
Create PR summary workflow with GitHub Copilot
kcw-grunt Apr 12, 2026
914bcd3
Changed the AI completions
kcw-grunt Apr 13, 2026
ca4fcd9
Add more information of the README
kcw-grunt Apr 13, 2026
12a3d83
nit fix
kcw-grunt Apr 13, 2026
5d3a6c2
🦖😱 HUGE!! Bento Integration (#192)
kcw-grunt Apr 14, 2026
010be8c
Release/v4.9.0 (#201)
kcw-grunt Apr 16, 2026
ce9d121
Feat/add thai dutch (#197)
kcw-grunt Apr 16, 2026
083027f
update gitignore (#204)
kcw-grunt Apr 17, 2026
9495b47
Add send/receive transaction integration tests (#203)
kcw-grunt Apr 18, 2026
e0b116a
Designdebt/polish main screen (#205)
kcw-grunt Apr 18, 2026
902f8fb
Feat/add gamehub minigame (#206)
kcw-grunt Apr 19, 2026
879ab6f
Moved clipboard test point into event (#207)
kcw-grunt Apr 20, 2026
334ce3b
moved out of the state update (#208)
kcw-grunt Apr 20, 2026
4455c07
Version bump
kcw-grunt Apr 20, 2026
fcc51f9
fix: issue when user tries to send (#210)
kcw-grunt Apr 22, 2026
b220d0f
reformatted the test
kcw-grunt Apr 18, 2026
5d01e5a
Added More comprehensive Send Tests to cover better stability
kcw-grunt Apr 23, 2026
2ad22d0
Add WalletManager; make validateAddress instance
kcw-grunt Apr 23, 2026
f0e16f6
Updated the InstrumentedTest
kcw-grunt Apr 23, 2026
9a88ed3
adjust the config
kcw-grunt Apr 23, 2026
a11b4db
adjust config for running
kcw-grunt Apr 23, 2026
39cb5f4
Further fix
kcw-grunt Apr 23, 2026
b981834
Fixes the bug: BreadActivity.initializeViews
kcw-grunt Apr 23, 2026
7828223
Merge branch 'main' into release/v4.9.1
kcw-grunt Apr 24, 2026
4c0e7d3
updated README
kcw-grunt Apr 24, 2026
0bfe9d7
bump
kcw-grunt Apr 24, 2026
8c3f1b2
chore(i18n): auto-translate missing strings [skip ci] (#213)
kcw-grunt Apr 24, 2026
bc79335
Feat/add tutorial functionality (#214)
kcw-grunt Apr 24, 2026
2af613b
Feat/bitrefill in topsecret (#217)
kcw-grunt Apr 25, 2026
38be6d1
Feat/bitrefill in topsecret (#221)
kcw-grunt Apr 25, 2026
04e8546
added polish
kcw-grunt Apr 25, 2026
7224aff
Merge branch 'main' into develop
kcw-grunt Apr 27, 2026
c792f3e
✨ 🛍️ 🛠️ Fix/sendmodelonevent crash (#224)
kcw-grunt Apr 27, 2026
6efad7a
Fixxed the layout of the LTC fiat picker (#225)
kcw-grunt Apr 27, 2026
2025282
Refactored the analytics (#226)
kcw-grunt Apr 28, 2026
f403751
Merge branch 'main' into develop
kcw-grunt Apr 28, 2026
734b3d7
🧼 Techdebt/sync reduce rate fpf (#228)
kcw-grunt May 1, 2026
a20d678
bump
kcw-grunt May 1, 2026
d046259
Techdebt/sync reduce rate fpf (#229)
kcw-grunt May 3, 2026
9cc425d
Feat/add remote shop (#230)
kcw-grunt May 9, 2026
728f354
version bump
kcw-grunt May 10, 2026
e57563d
add part of test
kcw-grunt May 10, 2026
d0886db
Techdebt/improve shop (#232)
kcw-grunt May 28, 2026
44fcc8f
Added analytics when user shows invoice in shop (#233)
kcw-grunt May 28, 2026
89a8974
Techdebt/modules update (#235)
kcw-grunt Jun 6, 2026
9fbfeae
Fallinmoji closed branch (#241)
kcw-grunt Jul 6, 2026
143bdac
version bump
kcw-grunt Jul 6, 2026
bc615f5
Techdebt/polish interface (#242)
kcw-grunt Jul 16, 2026
28f8f56
Fix/polish clear set emojis (#243)
kcw-grunt Jul 17, 2026
81a8870
Set the clean process
kcw-grunt Jul 17, 2026
afdfcfb
Merge branch 'main' into release/v4.10.4
kcw-grunt Jul 17, 2026
b5ca771
Changed the pat
kcw-grunt Jul 17, 2026
26e5c90
polish yml
kcw-grunt Jul 17, 2026
134926c
Use typical GH TOKEN
kcw-grunt Jul 17, 2026
c45fa05
Refactor yml
kcw-grunt Jul 17, 2026
ec2a406
chore(i18n): auto-translate missing strings [skip ci] (#245)
github-actions[bot] Jul 17, 2026
f43bd4b
Unescaped the ' in the translated strings in non-exist
kcw-grunt Jul 17, 2026
3bf7a25
fix(BreadActivity): remove dead bottom-nav/toolbar cruft causing star…
grunt-claude-bot Jul 22, 2026
5eba52b
fix(submodules): remove stale modules/bw-gdlib gitlink breaking CI (#…
grunt-claude-bot Jul 22, 2026
116df6a
fix(shop-bento): eliminate flaky ShopBentoViewModelTest + version bum…
grunt-claude-bot Jul 22, 2026
cb556da
docs: real SECURITY.md + restructured README for external visitors (#…
grunt-claude-bot Jul 22, 2026
459fe19
Bump bw-gdlib submodule to pick up ghost-launcher fix (#252)
grunt-claude-bot Jul 26, 2026
01c2e60
Merge branch 'main' into develop
grunt-claude-bot Jul 29, 2026
7f6aaec
docs: standardize release headers to bold version + PR + divider form…
grunt-claude-bot Jul 29, 2026
91b91dd
🎮 Fallinmoji v1.6.0: Ready, Set, GO! (#257)
grunt-claude-bot Jul 30, 2026
9d89ff3
Add this skill
grunt-claude-bot Jul 30, 2026
07224b9
test: add unit test coverage for pure utility helpers and gameinterfa…
grunt-claude-bot Jul 30, 2026
faac661
Merge branch 'main' into release/v4.11.0
kcw-grunt Jul 30, 2026
1a71dad
docs: add v4.11.0 release notes to README
grunt-claude-bot Jul 30, 2026
f701d2d
Activate InAppReviewService and wire up review prompts (#260)
grunt-claude-bot Jul 31, 2026
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ service-data.json
canary-file.json

# Claude
.claude/
.claude/
CLAUDE.local.md
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ android {
applicationId = "ltd.grunt.brainwallet"
minSdk = 29
targetSdk = 35
versionCode = 202506345
versionName = "v4.10.6"
versionCode = 202506346
versionName = "v4.11.0"
multiDexEnabled = true
base.archivesName.set("${defaultConfig.versionName}(${defaultConfig.versionCode})")
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import org.koin.compose.viewmodel.koinViewModel
import timber.log.Timber

@Serializable
private data class GameExitData(
internal data class GameExitData(
@SerialName("social_network") val socialNetwork: String = "none",
val timestamp: Long = 0L,
@SerialName("total_score") val totalScore: Int = 0,
Expand Down Expand Up @@ -102,7 +102,7 @@ private fun removeFragment(fm: FragmentManager, tag: String) {
}
}

private fun handleGameExit(
internal fun handleGameExit(
jsonString: String,
bytes: ByteArray?,
gameHubViewModel: GameHubViewModel,
Expand Down
79 changes: 79 additions & 0 deletions app/src/test/java/com/brainwallet/tools/crypto/Base58Test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.brainwallet.tools.crypto

import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Assert.assertThrows
import org.junit.Test

class Base58Test {

@Test
fun `given empty byte array, when encode, then returns empty string`() {
assertEquals("", Base58.encode(ByteArray(0)))
}

@Test
fun `given empty string, when decode, then returns empty byte array`() {
assertArrayEquals(ByteArray(0), Base58.decode(""))
}

@Test
fun `given known byte sequence, when encode, then matches known base58 vector`() {
// "Hello World" in bytes is a well known Base58 test vector.
val input = "Hello World".toByteArray(Charsets.UTF_8)
assertEquals("JxF12TrwUP45BMd", Base58.encode(input))
}

@Test
fun `given known base58 string, when decode, then matches known byte vector`() {
val decoded = Base58.decode("JxF12TrwUP45BMd")
assertArrayEquals("Hello World".toByteArray(Charsets.UTF_8), decoded)
}

@Test
fun `given bytes with leading zeroes, when encode then decode, then round trips exactly`() {
val input = byteArrayOf(0, 0, 0, 1, 2, 3, 4, 5)
val encoded = Base58.encode(input)

// Leading zero bytes are represented as leading '1' characters.
assertEquals('1', encoded[0])
assertEquals('1', encoded[1])
assertEquals('1', encoded[2])

assertArrayEquals(input, Base58.decode(encoded))
}

@Test
fun `given all zero bytes, when encode then decode, then round trips exactly`() {
val input = ByteArray(5)
val encoded = Base58.encode(input)

assertEquals("11111", encoded)
assertArrayEquals(input, Base58.decode(encoded))
}

@Test
fun `given arbitrary byte array, when encode then decode, then round trips exactly`() {
val input = byteArrayOf(
0x00,
0x01.toByte(),
0xFF.toByte(),
0x7F,
0x80.toByte(),
0x10,
0x2A
)
val encoded = Base58.encode(input)
val decoded = Base58.decode(encoded)

assertArrayEquals(input, decoded)
}

@Test
fun `given string with invalid base58 character, when decode, then throws RuntimeException`() {
// '0', 'O', 'I', 'l' are excluded from the Base58 alphabet.
assertThrows(RuntimeException::class.java) {
Base58.decode("0OIl")
}
}
}
58 changes: 58 additions & 0 deletions app/src/test/java/com/brainwallet/tools/util/BRCompressorTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.brainwallet.tools.util

import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test

class BRCompressorTest {

@Test
fun `given data, when gZipCompress then gZipExtract, then round trips exactly`() {
val data = "The quick brown fox jumps over the lazy dog".repeat(20).toByteArray(Charsets.UTF_8)

val compressed = BRCompressor.gZipCompress(data)
val extracted = BRCompressor.gZipExtract(compressed)

assertArrayEquals(data, extracted)
}

@Test
fun `given null data, when gZipCompress, then returns null`() {
assertNull(BRCompressor.gZipCompress(null))
}

@Test
fun `given null or empty compressed data, when gZipExtract, then returns null`() {
assertNull(BRCompressor.gZipExtract(null))
assertNull(BRCompressor.gZipExtract(ByteArray(0)))
}

@Test
fun `given data, when bz2Compress then bz2Extract, then round trips exactly`() {
val data = "The quick brown fox jumps over the lazy dog".repeat(20).toByteArray(Charsets.UTF_8)

val compressed = BRCompressor.bz2Compress(data)
val extracted = BRCompressor.bz2Extract(compressed)

assertArrayEquals(data, extracted)
}

@Test
fun `given null or empty compressed data, when bz2Extract, then returns null`() {
assertNull(BRCompressor.bz2Extract(null))
assertNull(BRCompressor.bz2Extract(ByteArray(0)))
}

@Test
fun `given gzip compressed bytes, when isGZIPStream, then returns true`() {
val compressed = BRCompressor.gZipCompress("payload".toByteArray(Charsets.UTF_8))
assertTrue(BRCompressor.isGZIPStream(compressed!!))
}

@Test
fun `given non gzip bytes, when isGZIPStream, then returns false`() {
assertFalse(BRCompressor.isGZIPStream(byteArrayOf(0x01, 0x02)))
}
}
59 changes: 59 additions & 0 deletions app/src/test/java/com/brainwallet/tools/util/BRDateUtilTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.brainwallet.tools.util

import org.junit.Assert.assertEquals
import org.junit.Test
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

class BRDateUtilTest {

private fun minutesAgo(minutes: Long): Date = Date(System.currentTimeMillis() - minutes * 60 * 1000)

private fun hoursAgo(hours: Long): Date = Date(System.currentTimeMillis() - hours * 60 * 60 * 1000)

private fun daysAgo(days: Long): Date = Date(System.currentTimeMillis() - days * 24 * 60 * 60 * 1000)

@Test
fun `given date under a minute ago, then formats as zero minutes`() {
assertEquals("0 m", BRDateUtil.getCustomSpan(Date()))
}

@Test
fun `given date several minutes ago, then formats in minutes`() {
assertEquals("15 m", BRDateUtil.getCustomSpan(minutesAgo(15)))
}

@Test
fun `given date just under an hour ago, then still formats in minutes`() {
assertEquals("59 m", BRDateUtil.getCustomSpan(minutesAgo(59)))
}

@Test
fun `given date exactly one hour ago, then formats in hours`() {
assertEquals("1 h", BRDateUtil.getCustomSpan(hoursAgo(1)))
}

@Test
fun `given date just under a day ago, then still formats in hours`() {
assertEquals("23 h", BRDateUtil.getCustomSpan(hoursAgo(23)))
}

@Test
fun `given date exactly one day ago, then formats in days`() {
assertEquals("1 d", BRDateUtil.getCustomSpan(daysAgo(1)))
}

@Test
fun `given date just under a week ago, then still formats in days`() {
assertEquals("6 d", BRDateUtil.getCustomSpan(daysAgo(6)))
}

@Test
fun `given date a week or more ago, then formats as month and day`() {
val date = daysAgo(7)
val expected = SimpleDateFormat("MMM dd", Locale.getDefault()).format(date)

assertEquals(expected, BRDateUtil.getCustomSpan(date))
}
}
59 changes: 59 additions & 0 deletions app/src/test/java/com/brainwallet/tools/util/BytesUtilTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.brainwallet.tools.util

import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Test
import java.io.ByteArrayInputStream
import java.io.IOException
import java.io.InputStream

class BytesUtilTest {

@Test
fun `given empty stream, when readBytesFromStream, then returns empty byte array`() {
val result = BytesUtil.readBytesFromStream(ByteArrayInputStream(ByteArray(0)))
assertArrayEquals(ByteArray(0), result)
}

@Test
fun `given small stream, when readBytesFromStream, then returns all bytes`() {
val data = "hello world".toByteArray(Charsets.UTF_8)
val result = BytesUtil.readBytesFromStream(ByteArrayInputStream(data))
assertArrayEquals(data, result)
}

@Test
fun `given stream larger than internal buffer, when readBytesFromStream, then returns all bytes`() {
// Internal buffer is 1024 bytes, so exercise multiple read iterations.
val data = ByteArray(1024 * 3 + 17) { (it % 256).toByte() }
val result = BytesUtil.readBytesFromStream(ByteArrayInputStream(data))
assertArrayEquals(data, result)
}

@Test
fun `given stream that throws IOException, when readBytesFromStream, then returns bytes read so far without throwing`() {
val failingStream =
object : InputStream() {
private var callCount = 0

override fun read(): Int = throw UnsupportedOperationException("not used")

override fun read(
b: ByteArray,
off: Int,
len: Int,
): Int {
callCount++
if (callCount == 1) {
b[off] = 42
return 1
}
throw IOException("boom")
}
}

val result = BytesUtil.readBytesFromStream(failingStream)
assertEquals(1, result.size)
assertEquals(42.toByte(), result[0])
}
}
68 changes: 68 additions & 0 deletions app/src/test/java/com/brainwallet/tools/util/TypesConverterTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.brainwallet.tools.util

import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Test

class TypesConverterTest {

@Test
fun `given positive int, when intToBytes then bytesToInt, then round trips exactly`() {
val value = 123456789
assertEquals(value, TypesConverter.bytesToInt(TypesConverter.intToBytes(value)))
}

@Test
fun `given negative int, when intToBytes then bytesToInt, then round trips exactly`() {
val value = -42
assertEquals(value, TypesConverter.bytesToInt(TypesConverter.intToBytes(value)))
}

@Test
fun `given zero int, when intToBytes, then returns four zero bytes`() {
assertArrayEquals(byteArrayOf(0, 0, 0, 0), TypesConverter.intToBytes(0))
}

@Test
fun `given positive long, when long2byteArray then byteArray2long, then round trips exactly`() {
val value = 9876543210123L
assertEquals(value, TypesConverter.byteArray2long(TypesConverter.long2byteArray(value)))
}

@Test
fun `given negative long, when long2byteArray then byteArray2long, then round trips exactly`() {
val value = -1L
assertEquals(value, TypesConverter.byteArray2long(TypesConverter.long2byteArray(value)))
}

@Test
fun `given char array, when toBytes then toChars, then values match as unsigned bytes`() {
val chars = charArrayOf('a', 'B', 'z', '1')
val bytes = TypesConverter.toBytes(chars)
val roundTripped = TypesConverter.toChars(bytes)

assertArrayEquals(chars, roundTripped)
}

@Test
fun `given mixed case char array, when lowerCaseCharArray, then all chars are lower case`() {
val chars = charArrayOf('A', 'b', 'C', '1', 'D')
assertArrayEquals(charArrayOf('a', 'b', 'c', '1', 'd'), TypesConverter.lowerCaseCharArray(chars))
}

@Test
fun `given char array, when charsToBytes, then matches UTF-8 encoded bytes`() {
val chars = "hello".toCharArray()
assertArrayEquals("hello".toByteArray(Charsets.UTF_8), TypesConverter.charsToBytes(chars))
}

@Test
fun `given seed bytes, when getNullTerminatedPhrase, then appends zero byte and zeroes original`() {
val rawSeed = byteArrayOf(1, 2, 3, 4)
val result = TypesConverter.getNullTerminatedPhrase(rawSeed)

assertArrayEquals(byteArrayOf(1, 2, 3, 4, 0), result)
// The original array must be wiped for security once copied.
assertArrayEquals(byteArrayOf(0, 0, 0, 0), rawSeed)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.brainwallet.gameinterface

import org.junit.Assert.assertNotNull
import org.junit.Assert.assertSame
import org.junit.Assert.assertTrue
import org.junit.Test
import org.koin.dsl.koinApplication

class GameKoinModuleTest {

@Test
fun `gameModule provides a GameSlot instance`() {
val koin = koinApplication { modules(gameModule) }.koin

val gameSlot = koin.get<GameSlot>()

assertNotNull(gameSlot)
assertTrue(gameSlot is GdxGameSlot)
}

@Test
fun `gameModule provides GameSlot as a singleton`() {
val koin = koinApplication { modules(gameModule) }.koin

val first = koin.get<GameSlot>()
val second = koin.get<GameSlot>()

assertSame(first, second)
}
}
Loading