Skip to content

Commit

Permalink
Made NetworkParams serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
Radiokot committed Jan 20, 2020
1 parent 71e54bc commit 515ff33
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/kotlin/org/tokend/wallet/NetworkParams.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,7 +10,7 @@ import java.util.*
/**
* Holds network-specific parameters.
*/
class NetworkParams {
class NetworkParams: Serializable {
/**
* Passphrase of the network
*/
Expand Down Expand Up @@ -82,6 +83,8 @@ class NetworkParams {
}

companion object {
const val serialVersionUID = 5677019745177892600L

/**
* Default amount precision in TokenD.
*/
Expand Down
18 changes: 18 additions & 0 deletions src/test/kotlin/org/tokend/wallet_test/NetworkParams.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand Down Expand Up @@ -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)
}
}

0 comments on commit 515ff33

Please sign in to comment.