Add bitcoin-s unit test class, all unit tests going forward should extend this (#335)

This commit is contained in:
Chris Stewart 2019-02-15 07:13:33 -06:00 committed by GitHub
parent 614efece23
commit fe4d26858c
3 changed files with 74 additions and 28 deletions

View file

@ -40,7 +40,11 @@ lazy val commonSettings = List(
scalacOptions in Test := testCompilerOpts, scalacOptions in Test := testCompilerOpts,
testOptions in Test += Tests.Argument("-oF"), //show full stack trace of failed tests
testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-oF"),
//show duration of tests
testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-oD"),
assemblyOption in assembly := (assemblyOption in assembly).value assemblyOption in assembly := (assemblyOption in assembly).value
.copy(includeScala = false), .copy(includeScala = false),
@ -127,36 +131,33 @@ lazy val secp256k1jni = project
lazy val core = project lazy val core = project
.in(file("core")) .in(file("core"))
.enablePlugins()
.settings(commonSettings: _*) .settings(commonSettings: _*)
.dependsOn( .dependsOn(
secp256k1jni secp256k1jni
) ).enablePlugins()
lazy val coreTest = project lazy val coreTest = project
.in(file("core-test")) .in(file("core-test"))
.enablePlugins()
.settings(commonSettings: _*) .settings(commonSettings: _*)
.settings(skip in publish := true) .settings(skip in publish := true)
.dependsOn( .dependsOn(
core, core,
) ).enablePlugins()
lazy val zmq = project lazy val zmq = project
.in(file("zmq")) .in(file("zmq"))
.enablePlugins()
.settings(commonSettings: _*) .settings(commonSettings: _*)
.dependsOn( .dependsOn(
core core
) ).enablePlugins()
lazy val rpc = project lazy val rpc = project
.in(file("rpc")) .in(file("rpc"))
.enablePlugins()
.settings(commonSettings: _*) .settings(commonSettings: _*)
.dependsOn( .dependsOn(
core core
) ).enablePlugins()
lazy val bench = project lazy val bench = project
.in(file("bench")) .in(file("bench"))

View file

@ -3,31 +3,18 @@ package org.bitcoins.core.protocol.ln
import org.bitcoins.core.crypto._ import org.bitcoins.core.crypto._
import org.bitcoins.core.gen.ln.LnInvoiceGen import org.bitcoins.core.gen.ln.LnInvoiceGen
import org.bitcoins.core.number.{UInt32, UInt64, UInt8} import org.bitcoins.core.number.{UInt32, UInt64, UInt8}
import org.bitcoins.core.protocol.ln.LnParams.{ import org.bitcoins.core.protocol.ln.LnParams.{LnBitcoinMainNet, LnBitcoinTestNet}
LnBitcoinMainNet, import org.bitcoins.core.protocol.ln.currency.{MicroBitcoins, MilliBitcoins, MilliSatoshis}
LnBitcoinTestNet import org.bitcoins.core.protocol.ln.fee.{FeeBaseMSat, FeeProportionalMillionths}
}
import org.bitcoins.core.protocol.ln.currency.{
MicroBitcoins,
MilliBitcoins,
MilliSatoshis
}
import org.bitcoins.core.protocol.ln.fee.{
FeeBaseMSat,
FeeProportionalMillionths
}
import org.bitcoins.core.protocol.ln.routing.LnRoute import org.bitcoins.core.protocol.ln.routing.LnRoute
import org.bitcoins.core.protocol.{Bech32Address, P2PKHAddress, P2SHAddress} import org.bitcoins.core.protocol.{Bech32Address, P2PKHAddress, P2SHAddress}
import org.bitcoins.core.util.CryptoUtil import org.bitcoins.core.util.{BitcoinSUnitTest, CryptoUtil}
import org.scalatest.prop.PropertyChecks
import org.scalatest.{FlatSpec, MustMatchers}
import org.slf4j.LoggerFactory
import scodec.bits.ByteVector import scodec.bits.ByteVector
class LnInvoiceUnitTest extends FlatSpec with MustMatchers with PropertyChecks { class LnInvoiceUnitTest extends BitcoinSUnitTest {
behavior of "LnInvoice" behavior of "LnInvoice"
private val logger = LoggerFactory.getLogger(getClass) override implicit val generatorDrivenConfig: PropertyCheckConfiguration = generatorDrivenConfigNewCode
val hrpEmpty = LnHumanReadablePart(LnBitcoinMainNet) val hrpEmpty = LnHumanReadablePart(LnBitcoinMainNet)
@ -449,4 +436,5 @@ class LnInvoiceUnitTest extends FlatSpec with MustMatchers with PropertyChecks {
invoice.nodeId.hex must be(expected) invoice.nodeId.hex must be(expected)
} }
} }

View file

@ -0,0 +1,57 @@
package org.bitcoins.core.util
import org.scalatest.prop.PropertyChecks
import org.scalatest.{FlatSpec, MustMatchers}
import org.slf4j.LoggerFactory
/** A wrapper for boiler plate testing procesures in bitcoin-s */
abstract class BitcoinSUnitTest extends FlatSpec with MustMatchers with PropertyChecks {
lazy val logger = LoggerFactory.getLogger(getClass)
/** The configuration for property based tests in our testing suite
* See: http://www.scalatest.org/user_guide/writing_scalacheck_style_properties
*/
override implicit val generatorDrivenConfig: PropertyCheckConfiguration = {
generatorDriveConfigOldCode
}
private def buildConfig(executions: Int): PropertyCheckConfiguration = {
PropertyCheckConfig(
minSuccessful = executions,
minSize = executions,
maxSize = executions
)
}
/** Property based tests that have been around a long time
* have a less of a chance failing, so execute them less
* @return
*/
def generatorDriveConfigOldCode: PropertyCheckConfiguration = {
buildConfig(BitcoinSUnitTest.OLD_CODE_EXECUTIONS)
}
/** Property based tests that are new have a higher chance of failing
* so execute them more
* @return
*/
def generatorDrivenConfigNewCode: PropertyCheckConfiguration = {
buildConfig(BitcoinSUnitTest.NEW_CODE_EXECUTIONS)
}
}
object BitcoinSUnitTest {
/** The number of times new code
* should be executed in a property based test
*/
val NEW_CODE_EXECUTIONS = 100
/** The number of times old code should be executed
* in a property based test
*/
val OLD_CODE_EXECUTIONS = 20
}