Skip to content

feat(simulate): Aptos chain family for cre workflow simulate#392

Open
Fletch153 wants to merge 11 commits intomainfrom
plex-2751
Open

feat(simulate): Aptos chain family for cre workflow simulate#392
Fletch153 wants to merge 11 commits intomainfrom
plex-2751

Conversation

@Fletch153
Copy link
Copy Markdown
Contributor

@Fletch153 Fletch153 commented Apr 21, 2026

Summary

Adds an Aptos chain type to cre workflow simulate, so workflows targeting aptos:ChainSelector:N@1.0.0 can run locally against a testnet RPC + a user-published mock forwarder. Paired with PLEX-2751 chainlink-aptos PR that ships the FakeAptosChain fake.

What's added

chain/aptos/ plugin — parallels chain/evm/:

  • chaintype.go — registers aptos; implements chain.ChainType (Name / SupportedChains / ResolveClients / ResolveKey / RegisterCapabilities / RunHealthCheck / ParseTriggerChainSelector / …). No trigger surface on Aptos.
  • capabilities.goAptosChainCapabilities wires FakeAptosChain per selector and registers with the capability registry.
  • limited_capabilities.goLimitedAptosChain enforces chain-write size + MaxGasAmount via caperrors.ResourceExhausted.
  • supported_chains.go — mainnet + testnet selectors.
  • health.goRunRPCHealthCheck probing GetChainId per client.

chain/evm/ refactor — extracts EVM-specific pieces out of simulate.go so the command delegates per-chain work through a chain-type registry. Trigger handling, registry, types, utils moved to chain/*; evm/trigger.go carries the manual-log-trigger glue.

Settings + limits

  • CRE_APTOS_PRIVATE_KEY plumbing (Ed25519 hex seed); sentinel seed allowed non-broadcast with ui.Warning; hard-fail under --broadcast for unparseable or sentinel key.
  • ChainWriteAptosMaxGasAmount in SimulationLimits.

Follow-up (not in this PR)

This PR adds Aptos alongside EVM but intentionally does not overhaul the broader plumbing. A dedicated follow-up is needed to make adding new chain families a drop-in rather than a fan-out of edits. Concretely:

  • Chain-name → selector lookup (internal/settings/settings_get.go): currently dispatches on family prefix (aptos-, EVM default) because upstream chain-selectors has no cross-family SelectorFromName. This should collapse once a family-agnostic helper is available or added upstream.
  • Private-key env wiring: AllChainTypes is manually extended per family (CRE_ETH_PRIVATE_KEY, CRE_APTOS_PRIVATE_KEY, …). Needs a registration-driven path so new families don't touch settings.go.
  • Per-family hooks in simulate: registry is in place, but several call sites still branch on chain type explicitly. Worth a cleanup pass once a third family lands.
  • chain-selectors upstream: consider contributing AptosChainIdFromName or, preferably, a unified SelectorFromName(name) that iterates all family *ALL slices — eliminates the local switch entirely.

Deliberately scoped out here to keep the PR reviewable

Wires an Aptos chain type into `cre workflow simulate` so workflows
targeting `aptos:ChainSelector:N@1.0.0` can be exercised locally
against testnet RPCs + a user-published mock forwarder.

chain/aptos plugin:
- chaintype.go — registers `aptos` via chain.Register; implements
  ChainType (Name, SupportedChains, ResolveClients, ResolveKey,
  RegisterCapabilities, RunHealthCheck, ParseTriggerChainSelector,
  etc.). No trigger surface on Aptos.
- capabilities.go — AptosChainCapabilities wires FakeAptosChain per
  selector and registers with the capability registry.
- limited_capabilities.go — LimitedAptosChain enforces chain-write
  size + Aptos MaxGasAmount via caperrors.ResourceExhausted.
- supported_chains.go — mainnet + testnet selectors.
- health.go — RunRPCHealthCheck probes GetChainId per client.

chain/evm refactor: extracts the EVM-specific pieces out of simulate.go
so the simulate command delegates per-chain work through a chain-type
registry (EVM + Aptos siblings). Trigger handling, registry, types,
utils moved to chain/*. evm/trigger.go carries manual-log-trigger glue.

Settings + limits:
- CRE_APTOS_PRIVATE_KEY plumbing (Ed25519 hex seed); sentinel seed
  allowed non-broadcast with ui.Warning; hard-fail under --broadcast
  for unparseable or sentinel key.
- ChainWriteAptosMaxGasAmount in SimulationLimits.

Tests:
- Unit: chaintype / capabilities / limited / supported_chains / health.
- 30-scenario CLI end-to-end suite (simulator_scenarios_test.go).
- test/aptos_cli_scenarios_test.go integration.
- test_project/aptos_smoke/ example workflow for manual smoke.

PLEX-2751
@Fletch153 Fletch153 requested a review from a team as a code owner April 21, 2026 13:01
@github-actions
Copy link
Copy Markdown

👋 Fletch153, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

Fletch153 and others added 10 commits April 21, 2026 14:13
Broadens TestSimulatorScenarios_100 to cover the full behavioural
surface of the Aptos chain plugin + FakeAptosChain:

- 31-45: AptosChainType surface (Name, SupportedChains, HasSelector,
  ParseTriggerChainSelector, ExecuteTrigger/ResolveTriggerData stubs,
  ResolveKey hex/0x/uppercase/whitespace/short-seed rejections).
- 46-52: RegisterCapabilities rejects wrong client, key, and limits
  types; accepts unknown (experimental) selectors; skips selectors
  without forwarders; surfaces bad forwarder hex; interface assert.
- 53-62: View TypeTag coverage — BOOL, U8, U16, U32, U64, U128, U256,
  ADDRESS round-trips; SIGNER and VECTOR rejected.
- 63-72: read-path edges — all-zero/all-ones addresses, empty result,
  multi-return, integer return, SDK timeout, nil pagination, nil-entry
  drop, nil request validation.
- 73-82: WriteReport broadcast paths — SUCCESS, VM failure, nil pending,
  forwarder error, WaitForTransaction error, nil-final fallback,
  multi-sig, empty sigs, 64KiB report, zero gas accepted.
- 83-90: LimitedAptosChain — exact/over/under size and gas limits,
  zero-limit disables check, View/TransactionByHash delegation.
- 91-100: lifecycle + info — ChainSelector, Description, Info ID format,
  Name embedding, Initialise/Register/Unregister/Execute no-ops,
  HealthReport shape, AptosChainCapabilities Start/Close, constructor
  nil guards.

PLEX-2751
Drops the local `replace ../chainlink-aptos` directive (breaks CI
sibling-dir lookup) and pins chainlink-aptos to the PLEX-2751
feature-branch pseudo-version v0.0.0-20260421125752-47d9d126c005
so unit, tidy, gendoc, and e2e jobs can resolve the `fakes` import.

Will be re-pinned to the merged SHA once smartcontractkit/chainlink-aptos#442
lands on develop.

PLEX-2751
Broadens the e2e cre-binary suite (gated by CRE_APTOS_CLI_E2E=1) with
70 additional scenarios covering:

- 31-40: balance fan-out across address shapes (high bit, low bit,
  max_u256, fan-out lanes).
- 41-50: view coin::balance edges (all-zero, all-0x01, all-0xff,
  canonical aligned-byte addresses).
- 51-60: tx-by-hash randomised nonexistent hashes (routing proof).
- 61-70: account-transactions fan-out.
- 71-80: wrong selector / experimental-chain rejection (EVM mainnet,
  Solana, 0, 1, max uint64, Aptos mainnet without wiring, experimental
  99999999 for each read op, baseline testnet selector unchanged).
- 81-90: UI + flag variations (--limits none/default, --help global and
  workflow simulate scoped, missing wasm/config error messages, invalid
  --trigger-index, empty CRE_TARGET env).
- 91-100: broadcast + key edge cases (--broadcast with sentinel /
  unparseable / short-hex keys — all must hard-fail with
  CRE_APTOS_PRIVATE_KEY in the error message, dry-run sentinel warning,
  dry-run with valid key success, follow-up routing regression cases).

Runner rewritten to handle three scenario shapes:
- standard simulator dry-run (config + args),
- help/no-config invocations (skip simulator markers),
- mustFail scenarios (process exit non-zero, expect substring in
  combined output).

Scenario padding widened to %03d to fit 100 cases.

PLEX-2751
- ResolveKey: split hex-decode vs length-mismatch errors; align wording
  with EVM's CRE_*_PRIVATE_KEY message.
- ParseTriggerChainSelector: strict prefix+suffix+ParseUint, rejects
  trailing garbage after @1.0.0.
- --broadcast flag help: chain-agnostic wording (no longer EVM-only).
- LimitsSummary: include Aptos gas limit alongside EVM; test updated.
- aptos_cli_scenarios_test: use t.TempDir() for per-subtest config
  paths instead of /tmp/apcfg_%03d.json.
TempDir() paths exceed ConfigPath validation (max=97) on macOS.
Restore /tmp/apcfg_NNN.json with defer os.Remove; add
APTOS_SMOKE_WASM env override for WASM location.
# Conflicts:
#	cmd/workflow/simulate/capabilities.go
#	cmd/workflow/simulate/chain/evm/chaintype.go
#	cmd/workflow/simulate/chain/evm/chaintype_test.go
#	cmd/workflow/simulate/chain/evm/trigger.go
#	cmd/workflow/simulate/chain/evm/trigger_test.go
#	cmd/workflow/simulate/chain/registry.go
#	cmd/workflow/simulate/chain/registry_test.go
#	cmd/workflow/simulate/simulate.go
#	go.mod
#	go.sum
…xpectations

- Add chain-type discriminator to ExperimentalChain; empty defaults to evm
- Aptos ResolveClients picks up chain-type: aptos entries
- EVM skips non-evm experimental entries
- Use corekeys.Aptos / ct.Name() for chain-type strings
- Update project.yaml.tpl example
- Align View/WriteReport test assertions with pinned FakeAptosChain semantics
…399)

Replace EthPrivateKey / AptosPrivateKey fields on UserSettings with a
single PrivateKeys map keyed by ChainType.Name, and introduce a
ChainType struct that bundles each family's name + signing-key env var.
Names are derived from corekeys.EVM / corekeys.Aptos so the canonical
upstream identifiers are the single source of truth.

Adding a new chain family is now one entry in AllChainTypes instead of
a new field, constant, and loader branch. Remove unused EthUrl and
simplify the project.yaml experimental-chains example comment.
chain-selectors has no AptosChainIdFromName; previous fallback scanned
the Aptos map with a double lookup. Switch on FamilyAptos prefix and
iterate AptosALL directly, reading Name/Selector off the struct.
Remove aptos_cli_scenarios_test.go and test/test_project/aptos_smoke/
from version control and ignore them going forward. Files remain on
disk for local iteration.
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.

1 participant