/scalus:contract-testfrom scalus
Guides testing Scalus smart contracts on Cardano, covering unit, property, budget, and Emulator tests for validators.
Ships in scalus. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Before writing test code from memory, fetch https://scalus.org/llms-api.txt and check the testkit signatures you plan to use.
In the Scalus repo, read scalus-site/content/<path>.mdx; in any other project, fetch https://scalus.org/docs/<path>.md.
Testing fundamentals:
testing/unit-testing - ScalusTest trait, property-based testingsmart-contracts/evaluating-script - Script evaluation patternstesting/debugging - Debugging techniquesIntegration testing:
testing/emulator - in-memory Emulator testingtesting/local-devnet - Yaci DevKit integration testslocal-development skill for the full Emulator + TxBuilder loop.Study existing tests before writing new ones:
https://scalus.org/llms-examples.txt - validators with their tests; HtlcTest.scala is the reference style.scalus-examples/jvm/src/test/scala/scalus/examples/.Emulator test with ScalusTest (the standard pattern; see HtlcTest):
class MyValidatorTest extends AnyFunSuite, ScalusTest {
private given env: CardanoInfo = TestUtil.testEnvironment
private val contract = MyContract.compiled.withErrorTraces
test("valid spend succeeds") {
val provider = Emulator.withAddresses(Seq(Alice.address, Bob.address))
val utxos = provider.findUtxos(address = Alice.address).await().toOption.get
// build a transaction with txBuilder, then:
assert(provider.submit(tx).await().isRight)
}
}
Assertions from scalus.testing.kit:
assertScriptFail(expectedError) { buildTx } - expect a validator failureassertEvalResult(expected)(program) - check an evaluation resultBudget assertions from scalus.testing.dsl.EvalTestDsl:
.assertBudgetWithin(memory, steps) - upper bound.assertBudgetEquals(memory, steps) - exact pin (baseline tests)Pin convention:
budget: test in scalus-core that pins mem, cpu
and the mainnet fee: assertEvalWithBudgetAndFee(code, arg, expected, ExUnits(memory = m, steps = s), Coin(fee))
from scalus.testing.kit.EvalTestKit. Pass the input as arg (it goes in as Data) so constant
folding cannot remove the work being measured.ExUnits of every transaction, and the fee where the test
already does (result.budget.fee == Coin(2398) in HtlcTest). Wrap a pin in
ScalaCompilerVersion.baseline(pre38 = ..., since38 = ...) only when the two compiler generations
differ; otherwise write the bare value.ExUnits(memory = 27127, steps = 11_541882), named parameters, _ at the million boundary.Property-based testing: ScalusTest provides generators (e.g. genByteStringOfN); use ScalaCheck forAll for on-chain function properties.
Negative cases: three idioms; pick one per test, do not mix them:
HtlcTest): keep the default evaluator and wrap the build in
assertScriptFail(expectedError) { buildTx }. The builder runs the script while balancing,
throws, and the helper matches expectedError against the script logs, so pass the
validator's own error constant.EditableNftValidatorTest): build with
TxBuilder(env, PlutusScriptEvaluator.constMaxBudget(env)) so the builder skips script
evaluation, then provider.submit(tx).await() and assert(result.isLeft). Use it when the
transaction must get past the builder (for example, to reach the ledger's own checks).VestingValidatorTest): build a ScriptContext by hand, run
compiled.runScript(ctx) (an extension from ScalusTest: mix it into the test class) and
assert(result.isFailure, "..."). For an on-chain helper evaluated directly, assertEvalFailsWithMessage[OnchainError](msg)(expr) checks the message.assertScriptFail(HtlcValidator.InvalidReceiverPreimage) {
txCreator.reveal(utxos = utxos, lockedUtxo = lockedUtxo, preimage = wrongPreimage, ...)
}
Negative-test convention: every safety operation the validator uses gets one Fail: ... test
where the UNSAFE input fails. The transaction is valid apart from the one change. Minimum set:
validFromOrFail / validToOrFail: an unbounded validity range (Interval.always) fails.hasSameTokensAndAtLeastAda and exact value checks: an output whose value is below the expected
amount fails; native tokens stripped from the continuing output fails.findContinuingOutputOrFail: an output with the script payment credential but a different
staking credential fails; a second output to the script address fails.findUniqueOrFail on inputs: a second own input in the same transaction fails (each script run
must fail, see "double satisfaction" in VestingValidatorTest).mint.hasOnly / onlyBurnsUnder: an extra token name under the policy fails; a burn action that
mints nothing fails.hasNft / hasPaidTagged: quantity 2 of the beacon fails; one tagged output claimed by two
script instances fails.Burn redeemer with a positive quantity fails.Liveness convention: every check on a continuing output also gets one passing test of the
honest transaction at its edge. For a value check: the continuing output adds lovelace (a min-ADA
top-up for a larger datum) and passes. A suite with only Fail: tests cannot tell a correct check
from one that rejects every transaction.
Shape of one case (unit path, VestingValidatorTest "Fail: continuing output redirects the staking credential"):
val hijacked = Address(
ScriptCredential(contractHash),
Option.Some(StakingCredential.StakingHash(Credential.PubKeyCredential(attackerPKH)))
)
val outputs = List(TxOut(hijacked, Value.lovelace(remaining), OutputDatum.OutputDatum(datum.toData)))
val result = compiled.runScript(ScriptContext(txInfo = txInfo(outputs), redeemer = redeemer.toData, scriptInfo = spending))
assert(result.isFailure, "Redirecting the staking credential must fail")
In a user project: sbt test or scala-cli test ..
In the Scalus repo:
sbtn scalusJVM/test # Core tests
sbtn scalusExamplesJVM/test # Example tests
sbtn scalusCardanoLedgerJVM/test # Ledger tests
sbtn scalusCardanoLedgerIt/test # Integration tests (requires Docker)
AnyFunSuite) with ScalaCheck for property-based tests.Test/fork := true).What SKILL.md sets; muted values are Claude Code's defaults
7 skills in this plugin
/contractGuide for developing Scalus smart contracts. Use when writing or modifying Cardano validators in Scala 3 with Scalus./local-developmentUse when developing or testing Scalus smart contracts with the local Emulator and TxBuilder. Covers how to create an Emulator provider, submit transactions, test negative validator cases, and test confirmation delay and rollbacks./optimize-contractOptimize Scalus/Cardano smart contracts for execution budget (CPU steps and memory). Analyzes @Compile annotated validators for performance issues — expensive patterns, unnecessary allocations, redundant traversals, missed short-circuits. Provides concrete Scalus rewrites with budget impact estimates. Use when reviewing on-chain code performance or when /optimize-contract is invoked. Requires explicit path argument.npx claudepluginhub scalus3/scalus --plugin scalusOther plugins' skills for the same job