Skip to content

Refuse an unrecognised WDK_GAS_MODE instead of broadcasting - #131

Open
ColinkaMir wants to merge 1 commit into
portdeveloper:mainfrom
ColinkaMir:fix/refuse-unknown-gas-mode
Open

ColinkaMir wants to merge 1 commit into
portdeveloper:mainfrom
ColinkaMir:fix/refuse-unknown-gas-mode

Conversation

@ColinkaMir

Copy link
Copy Markdown
Contributor

Closes #128

What was wrong

config.mjs compared WDK_GAS_MODE only against dry-run and native. With PIMLICO_API_KEY set, any other non-empty value became sponsored, which broadcasts. dryrun, dry_run, simulate and "dry-run " (trailing space) all turned broadcasting on while the operator was asking for a simulation.

The change

  • src/config.mjs. The value is trimmed and lower-cased and must be one of the three documented in .env.example. Anything else sets config.gasModeError, naming the value and the accepted ones. A refused value also resolves to dry-run, so an entry point that never reads gasModeError still cannot broadcast on it.
  • src/cli.mjs. On gasModeError the CLI prints gas mode: … and exits 1 before the banner, the wallet or the model, the way a missing NAD_POLICY file stops it (Fail startup when an explicit NAD_POLICY path is missing #108).
  • Why a flag rather than a throw. My claim said config.mjs would throw. Six modules import it at load time, so a throw there ends the process with an uncaught stack trace instead of the one-line message Fail startup when an explicit NAD_POLICY path is missing #108 gives, and the CLI cannot catch it. The flag lets main() report it cleanly, and the dry-run fallback keeps the refusal safe in any path that does not check it.
  • .env.example. One line saying any other value stops startup.
  • Unchanged. An empty value keeps the auto-detection, no key still means dry-run, upper case is still accepted, and the confirmation lines and the mainnet acknowledgement are untouched.

Verified

test/gas-mode.test.mjs: config loaded in a child process, as reservoir-network.test.mjs does, and the built CLI run with the @qvac/sdk shim, as nfts-command.test.mjs does.

Test What it checks On main
a typo of a gas mode is refused, never read as sponsored dryrun, dry_run, simulate, dry run, gasless with a key: refused with the value named, and gasMode is dry-run fails
a refused value is refused without a key too the same refusal without a key fails
the documented values resolve as documented dry-run, native, sponsored in any case, with padding fails (padding)
the CLI stops before the banner or the wallet on every refused gas mode dryrun, dry_run, simulate through the built CLI: exit 1, the message, no wallet initialisation, no gasless claim, no model call fails
an empty value keeps the auto-detection with and without a key; sponsored without a key still simulates passes (control)
  • Mutations. Dropping gasModeError from the dry-run fallback fails the first test; skipping the check in cli.mjs fails the CLI test.
  • Full suite. npm run build && npm test: 634/634 on Node 22 (CI's major version) and on Node 20. The new file was rerun twice more with no flakes.

config.mjs compared WDK_GAS_MODE only against dry-run and native, so with a
Pimlico key any other non-empty value became sponsored, which broadcasts:
dryrun, dry_run, simulate and "dry-run " (trailing space) all turned
broadcasting on while the operator was asking for a simulation.

The value is now trimmed and lower-cased and must be one of the three
documented in .env.example. Anything else sets config.gasModeError and the
CLI stops before the banner, the wallet or the model, the way a missing
NAD_POLICY file stops it (portdeveloper#108). A refused value also resolves to dry-run,
so an entry point that never looks at gasModeError still cannot broadcast
on it. An empty value keeps the auto-detection, no key still means dry-run,
and the confirmation lines and the mainnet acknowledgement are unchanged.

Tests in test/gas-mode.test.mjs, config loaded in a child process and the
built CLI run with the @qvac/sdk shim: typos are refused with and without a
key, documented values resolve in any case and padding, and the CLI exits 1
before the wallet or the model; these fail on main. Auto-detection for an
empty value is a control that passes on main. npm run build && npm test:
634/634 on Node 22 and on Node 20.

Closes portdeveloper#128
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.

Refuse an unrecognised WDK_GAS_MODE instead of broadcasting

1 participant