Testing validator
We leverage the ScalaCheck library to test Scalus validators.
ScalaCheck is a library written in Scala and used for automated property-based testing of Scala or Java programs. It is a powerful tool for property-based testing, allowing us to define properties that should hold true for a wide range of inputs.
We implemented ScalaCheck generators and Arbitrary
instances for various Scalus types,
including Data
, Plutus V1/V2/V3 types, like Address
, Value
, Cardano ledger types, and more.
ScalusTest - Scalus Testing Framework
trait ScalusTest {
def random[A: Arbitrary]: A
}
class YourTest extends AnyFunSpec with ScalusTest {
test("checking a property") {
val txid = random[TxId] // Generates a random TxId
assert(txid.hash.toHex.length == 32)
}
test("should pass some property") {
// Generating random TxInInfo and TxOut
forAll { (in: TxInInfo, out: TxOut) =>
// Your test logic here
assert(in.resolved.value > out.value)
}
}
}
Last updated on