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..90e94f9257 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.toSet + } + } + } + } 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)