From 2969e149af0445e87fa89965a6c03f56f122bd98 Mon Sep 17 00:00:00 2001 From: oskin1 Date: Mon, 16 Sep 2019 19:45:51 +0300 Subject: [PATCH 1/2] WalletStorage test added. --- .../wallet/persistence/WalletStorageSpec.scala | 11 +++++++++++ .../utils/generators/WalletGenerators.scala | 9 +++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/test/scala/org/ergoplatform/nodeView/wallet/persistence/WalletStorageSpec.scala b/src/test/scala/org/ergoplatform/nodeView/wallet/persistence/WalletStorageSpec.scala index b3e9eacbc5..f263d6abf9 100644 --- a/src/test/scala/org/ergoplatform/nodeView/wallet/persistence/WalletStorageSpec.scala +++ b/src/test/scala/org/ergoplatform/nodeView/wallet/persistence/WalletStorageSpec.scala @@ -4,6 +4,7 @@ import io.iohk.iodb.{LSMStore, Store} import org.ergoplatform.ErgoAddressEncoder import org.ergoplatform.db.DBSpec import org.ergoplatform.utils.generators.WalletGenerators +import org.scalacheck.Gen import org.scalatest.prop.GeneratorDrivenPropertyChecks import org.scalatest.{FlatSpec, Matchers} import scorex.testkit.utils.FileUtils @@ -44,4 +45,14 @@ class WalletStorageSpec } } + it should "add and read derivation paths" in { + forAll(Gen.nonEmptyListOf(derivationPathGen)) { paths => + withStore { store => + val storage = new WalletStorage(store, settings) + paths.foreach(storage.addPath) + storage.readPaths should contain theSameElementsAs paths + } + } + } + } diff --git a/src/test/scala/org/ergoplatform/utils/generators/WalletGenerators.scala b/src/test/scala/org/ergoplatform/utils/generators/WalletGenerators.scala index e93d8ea09e..af451fefbf 100644 --- a/src/test/scala/org/ergoplatform/utils/generators/WalletGenerators.scala +++ b/src/test/scala/org/ergoplatform/utils/generators/WalletGenerators.scala @@ -7,12 +7,11 @@ import org.ergoplatform.nodeView.wallet.persistence.{PostponedBlock, RegistryInd import org.ergoplatform.nodeView.wallet.requests.{AssetIssueRequest, PaymentRequest} import org.ergoplatform.settings.{Constants, ErgoSettings} import org.ergoplatform.wallet.boxes.{BoxCertainty, TrackedBox} +import org.ergoplatform.wallet.secrets.{DerivationPath, Index} import org.scalacheck.Gen trait WalletGenerators extends ErgoTransactionGenerators { - private val ergoSettings = ErgoSettings.read() - def trackedBoxGen: Gen[TrackedBox] = { Gen.oneOf( unspentOffchainBoxGen, @@ -116,6 +115,12 @@ trait WalletGenerators extends ErgoTransactionGenerators { txs <- Gen.listOf(invalidErgoTransactionGen) } yield PostponedBlock(id, height, txs) + def derivationPathGen: Gen[DerivationPath] = for { + isPublic <- Gen.oneOf(Seq(true, false)) + indices <- Gen.listOf(Gen.oneOf(Seq(true, false)) + .flatMap(x => Gen.posNum[Int].map(i => if (x) Index.hardIndex(i) else i))) + } yield DerivationPath(0 +: indices, isPublic) + private def outIndexGen(tx: ErgoTransaction) = Gen.choose(0: Short, tx.outputCandidates.length.toShort) private def heightGen(min: Int = 0) = Gen.choose(min + 1, Integer.MAX_VALUE / 2 + min) From 1bcbc72293dfae54a77257c789267cc8b2b6bdac Mon Sep 17 00:00:00 2001 From: oskin1 Date: Mon, 16 Sep 2019 22:08:39 +0300 Subject: [PATCH 2/2] Test corrected. --- .../nodeView/wallet/persistence/WalletStorageSpec.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/scala/org/ergoplatform/nodeView/wallet/persistence/WalletStorageSpec.scala b/src/test/scala/org/ergoplatform/nodeView/wallet/persistence/WalletStorageSpec.scala index f263d6abf9..90e94f9257 100644 --- a/src/test/scala/org/ergoplatform/nodeView/wallet/persistence/WalletStorageSpec.scala +++ b/src/test/scala/org/ergoplatform/nodeView/wallet/persistence/WalletStorageSpec.scala @@ -50,7 +50,7 @@ class WalletStorageSpec withStore { store => val storage = new WalletStorage(store, settings) paths.foreach(storage.addPath) - storage.readPaths should contain theSameElementsAs paths + storage.readPaths should contain theSameElementsAs paths.toSet } } }