2020-06-10 00:08:19 -07:00
|
|
|
package cash.z.ecc.android.sdk.util
|
2019-06-14 16:28:07 -07:00
|
|
|
|
|
|
|
import androidx.test.platform.app.InstrumentationRegistry
|
2022-08-02 06:29:09 -07:00
|
|
|
import cash.z.ecc.android.sdk.model.ZcashNetwork
|
2020-09-21 19:43:50 -07:00
|
|
|
import cash.z.ecc.android.sdk.tool.DerivationTool
|
2019-06-14 16:28:07 -07:00
|
|
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
|
|
import kotlinx.coroutines.flow.flow
|
2020-02-21 15:15:13 -08:00
|
|
|
import kotlinx.coroutines.flow.map
|
2019-06-14 16:28:07 -07:00
|
|
|
import kotlinx.coroutines.runBlocking
|
2022-01-19 10:39:07 -08:00
|
|
|
import okio.buffer
|
|
|
|
import okio.source
|
2019-06-14 16:28:07 -07:00
|
|
|
import org.junit.Assert.assertEquals
|
2020-02-21 15:15:13 -08:00
|
|
|
import org.junit.Assert.assertTrue
|
2019-06-14 16:28:07 -07:00
|
|
|
import org.junit.Test
|
|
|
|
import java.io.IOException
|
|
|
|
|
|
|
|
@ExperimentalCoroutinesApi
|
|
|
|
class AddressGeneratorUtil {
|
|
|
|
|
|
|
|
private val context = InstrumentationRegistry.getInstrumentation().context
|
2020-09-21 19:43:50 -07:00
|
|
|
|
2020-02-21 15:15:13 -08:00
|
|
|
private val mnemonics = SimpleMnemonics()
|
2019-06-14 16:28:07 -07:00
|
|
|
|
2020-02-21 15:15:13 -08:00
|
|
|
@Test
|
|
|
|
fun printMnemonic() {
|
|
|
|
mnemonics.apply {
|
|
|
|
val mnemonicPhrase = String(nextMnemonic())
|
|
|
|
println("example mnemonic: $mnemonicPhrase")
|
|
|
|
assertEquals(24, mnemonicPhrase.split(" ").size)
|
|
|
|
}
|
2019-06-14 16:28:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun generateAddresses() = runBlocking {
|
2020-02-21 15:15:13 -08:00
|
|
|
readLines()
|
|
|
|
.map { seedPhrase ->
|
|
|
|
mnemonics.toSeed(seedPhrase.toCharArray())
|
|
|
|
}.map { seed ->
|
2022-08-04 10:09:19 -07:00
|
|
|
DerivationTool.deriveUnifiedAddress(seed, ZcashNetwork.Mainnet)
|
2020-02-21 15:15:13 -08:00
|
|
|
}.collect { address ->
|
|
|
|
println("xrxrx2\t$address")
|
|
|
|
assertTrue(address.startsWith("zs1"))
|
|
|
|
}
|
2019-06-14 16:28:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Throws(IOException::class)
|
|
|
|
fun readLines() = flow<String> {
|
2020-09-21 19:43:50 -07:00
|
|
|
val seedFile = javaClass.getResourceAsStream("/utils/seeds.txt")!!
|
2022-01-19 10:39:07 -08:00
|
|
|
seedFile.source().buffer().use { source ->
|
2019-06-14 16:28:07 -07:00
|
|
|
var line: String? = source.readUtf8Line()
|
|
|
|
while (line != null) {
|
|
|
|
emit(line)
|
|
|
|
line = source.readUtf8Line()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-09 20:28:21 -07:00
|
|
|
}
|