2023-02-06 06:41:38 -08:00
|
|
|
package cash.z.ecc.android.sdk.model
|
2022-12-23 02:00:37 -08:00
|
|
|
|
|
|
|
import androidx.test.filters.SmallTest
|
2023-02-06 06:41:38 -08:00
|
|
|
import cash.z.ecc.android.sdk.count
|
|
|
|
import cash.z.ecc.android.sdk.fixture.PersistableWalletFixture
|
|
|
|
import cash.z.ecc.android.sdk.fixture.SeedPhraseFixture
|
2022-12-23 02:00:37 -08:00
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
import org.junit.Assert.assertFalse
|
|
|
|
import org.junit.Assert.assertTrue
|
|
|
|
import org.junit.Test
|
|
|
|
|
|
|
|
class PersistableWalletTest {
|
|
|
|
@Test
|
|
|
|
@SmallTest
|
|
|
|
fun serialize() {
|
|
|
|
val persistableWallet = PersistableWalletFixture.new()
|
|
|
|
|
|
|
|
val jsonObject = persistableWallet.toJson()
|
|
|
|
assertEquals(4, jsonObject.keys().count())
|
|
|
|
assertTrue(jsonObject.has(PersistableWallet.KEY_VERSION))
|
|
|
|
assertTrue(jsonObject.has(PersistableWallet.KEY_NETWORK_ID))
|
|
|
|
assertTrue(jsonObject.has(PersistableWallet.KEY_SEED_PHRASE))
|
|
|
|
assertTrue(jsonObject.has(PersistableWallet.KEY_BIRTHDAY))
|
|
|
|
|
|
|
|
assertEquals(1, jsonObject.getInt(PersistableWallet.KEY_VERSION))
|
|
|
|
assertEquals(ZcashNetwork.Testnet.id, jsonObject.getInt(PersistableWallet.KEY_NETWORK_ID))
|
2023-06-20 02:26:38 -07:00
|
|
|
assertEquals(
|
|
|
|
PersistableWalletFixture.SEED_PHRASE.joinToString(),
|
|
|
|
jsonObject.getString(PersistableWallet.KEY_SEED_PHRASE)
|
|
|
|
)
|
2022-12-23 02:00:37 -08:00
|
|
|
|
|
|
|
// Birthday serialization is tested in a separate file
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@SmallTest
|
|
|
|
fun round_trip() {
|
|
|
|
val persistableWallet = PersistableWalletFixture.new()
|
|
|
|
|
|
|
|
val deserialized = PersistableWallet.from(persistableWallet.toJson())
|
|
|
|
|
|
|
|
assertEquals(persistableWallet, deserialized)
|
|
|
|
assertFalse(persistableWallet === deserialized)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@SmallTest
|
|
|
|
fun toString_security() {
|
|
|
|
val actual = PersistableWalletFixture.new().toString()
|
|
|
|
|
|
|
|
assertFalse(actual.contains(SeedPhraseFixture.SEED_PHRASE))
|
|
|
|
}
|
|
|
|
}
|