From 515ff33ba3d7c7e24e8b2f6196c2400b27343810 Mon Sep 17 00:00:00 2001 From: Oleg Koretsky Date: Mon, 20 Jan 2020 16:29:18 +0200 Subject: [PATCH] Made NetworkParams serializable --- .../kotlin/org/tokend/wallet/NetworkParams.kt | 5 ++++- .../org/tokend/wallet_test/NetworkParams.kt | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/tokend/wallet/NetworkParams.kt b/src/main/kotlin/org/tokend/wallet/NetworkParams.kt index 7175d1d..965f7ff 100644 --- a/src/main/kotlin/org/tokend/wallet/NetworkParams.kt +++ b/src/main/kotlin/org/tokend/wallet/NetworkParams.kt @@ -1,6 +1,7 @@ package org.tokend.wallet import org.tokend.wallet.utils.Hashing +import java.io.Serializable import java.math.BigDecimal import java.math.MathContext import java.math.RoundingMode @@ -9,7 +10,7 @@ import java.util.* /** * Holds network-specific parameters. */ -class NetworkParams { +class NetworkParams: Serializable { /** * Passphrase of the network */ @@ -82,6 +83,8 @@ class NetworkParams { } companion object { + const val serialVersionUID = 5677019745177892600L + /** * Default amount precision in TokenD. */ diff --git a/src/test/kotlin/org/tokend/wallet_test/NetworkParams.kt b/src/test/kotlin/org/tokend/wallet_test/NetworkParams.kt index 85666ae..17841c2 100644 --- a/src/test/kotlin/org/tokend/wallet_test/NetworkParams.kt +++ b/src/test/kotlin/org/tokend/wallet_test/NetworkParams.kt @@ -3,6 +3,10 @@ package org.tokend.wallet_test import org.junit.Assert import org.junit.Test import org.tokend.wallet.NetworkParams +import java.io.ByteArrayInputStream +import java.io.ByteArrayOutputStream +import java.io.ObjectInputStream +import java.io.ObjectOutputStream import java.math.BigDecimal import java.util.* @@ -30,4 +34,18 @@ class NetworkParams { Assert.assertTrue((calculated - actual) in (correction - 1..correction + 1)) } + + @Test + fun serialization() { + val networkParams = NetworkParams("Test phrase", 10, 42) + val byteArrayOutputStream = ByteArrayOutputStream() + ObjectOutputStream(byteArrayOutputStream).writeObject(networkParams) + val inputStream = ByteArrayInputStream(byteArrayOutputStream.toByteArray()) + val pn = ObjectInputStream(inputStream).readObject() as NetworkParams + + Assert.assertEquals(networkParams.passphrase, pn.passphrase) + Assert.assertEquals(networkParams.precision, pn.precision) + Assert.assertEquals(networkParams.timeOffsetSeconds, pn.timeOffsetSeconds) + Assert.assertArrayEquals(networkParams.networkId, pn.networkId) + } } \ No newline at end of file