Skip to content

Scalus node emulator#249

Open
sae3023 wants to merge 6 commits into
IntersectMBO:scalusfrom
sae3023:scalus
Open

Scalus node emulator#249
sae3023 wants to merge 6 commits into
IntersectMBO:scalusfrom
sae3023:scalus

Conversation

@sae3023
Copy link
Copy Markdown
Contributor

@sae3023 sae3023 commented Apr 15, 2026

This PR introduces the Scalus node emulator as one of the Provider implementations, allowing to write the code against the in-memory Emulator as if it was a real node.

It also migrates some of the tests to the scalus emulator, making it drastically faster (180s vs ±3s)

Note on vendored scalus

This PR depends on Scalus features not yet published to npm (Emulator.withState, getDelegation, getDatum, hasTx). The vendor/scalus/ directory contains a local build of scalus 0.15.0 so reviewers can pnpm install && pnpm test without any local setup. The pnpm override in root package.json points to ./vendor/scalus. This will be removed once scalus publishes the new version.

solidsnakedev and others added 2 commits January 10, 2026 10:28
Implements the Provider interface backed by the Scalus Cardano emulator,
enabling local ledger validation for transaction building and submission.
@sae3023 sae3023 marked this pull request as draft April 15, 2026 15:18
@@ -0,0 +1,69 @@
import "@evolution-sdk/scalus-emulator"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole file is a test util, and I don't insist on it existing in this form

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, agreed. A small helper avoids duplicating the NodeEmulator setup across these tests, but I am fine reshaping or moving it if we want a more general test utility.

}

/** Default protocol parameters matching Cardano mainnet. */
const DEFAULT_PROTOCOL_PARAMETERS: ProtocolParameters = {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there's a util that does this better -- i'd really prefer to use it, maybe you can point it out

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked and do not see an exported utility for this. The closest is the private buildCostModels helper in Evaluation.ts, so I think we should extract shared protocol and cost-model defaults into evolution core instead of duplicating them here.

@sae3023 sae3023 changed the title [draft]: scalus emulator Scalus node emulator Apr 24, 2026
@sae3023 sae3023 marked this pull request as ready for review April 24, 2026 11:36
Copy link
Copy Markdown
Collaborator

@solidsnakedev solidsnakedev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@solidsnakedev solidsnakedev dismissed their stale review May 15, 2026 18:06

Posted without authorization — removed by request.

Copy link
Copy Markdown
Collaborator

@hadelive hadelive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding the Scalus-backed node emulator provider and the related transaction builder coverage. I reviewed the current PR head (caa932274b403bc1b9fee948084991bc174357c9) and I believe this needs changes before it is ready to merge.

The new @evolution-sdk/scalus-emulator package does not currently build. Running pnpm --filter @evolution-sdk/scalus-emulator build fails in packages/scalus-emulator/src/index.ts because NodeEmulatorConfig exposes ReadonlyArray values, while Scalus.EmulatorInitialState expects mutable arrays for stakeRegistrations, poolRegistrations, drepRegistrations, and datums. Please either copy these values into mutable arrays before constructing the Scalus state, or align the public config types with the Scalus API.

The new node-emulator test suite is also not green. Running pnpm --filter @evolution-sdk/devnet test -- NodeEmulator fails in packages/evolution-devnet/test/TxBuilder.Pool.NodeEmulator.test.ts for the retirePool case. The emulator rejects the retirement transaction with Pool certificate validation failed ... not registered, even though the test submits a pool registration first. This should be fixed or the test should be adjusted so the suite reliably validates the intended behavior.

There are also a few packaging and runtime concerns to address before publishing this package:

  • packages/scalus-emulator/package.json exports ./src/index.ts and does not define a publishConfig override to point consumers at dist, unlike the existing packages. This would publish runtime exports that resolve to TypeScript source.
  • The same package declares "sideEffects": [], but packages/scalus-emulator/src/index.ts relies on import-time registration via registerNodeEmulatorProviderFactory. Bundlers may remove import "@evolution-sdk/scalus-emulator", which would leave the provider factory unregistered.
  • packages/evolution/package.json adds an optional peer dependency back to @evolution-sdk/scalus-emulator, while the emulator package peer-depends on @evolution-sdk/evolution. This introduces a workspace dependency cycle warning during install, and core does not appear to need a peer dependency on the emulator package.

Finally, ScalusEmulatorProvider.evaluateTx appears to ignore caller-supplied cost models from protocolParameters and recreates the Scalus slot config with hard-coded zeroSlot = 0 and slotLength = 1000. That can make evaluation disagree with submission for custom protocol parameters or slot configurations.

Verification performed:

  • pnpm --filter @evolution-sdk/evolution type-check passed.
  • pnpm --filter @evolution-sdk/scalus-uplc type-check passed.
  • pnpm --filter @evolution-sdk/devnet type-check passed.
  • pnpm --filter @evolution-sdk/scalus-emulator build failed as described above.
  • pnpm --filter @evolution-sdk/devnet test -- NodeEmulator failed as described above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants