Skip to content

Commit

Permalink
Merge pull request #907 from ergoplatform/wallet-bugs
Browse files Browse the repository at this point in the history
addPath/readPaths test
  • Loading branch information
kushti authored Oct 4, 2019
2 parents 898aa23 + b9e7887 commit 63567cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 63567cb

Please sign in to comment.