Skip to content

Fix: three FungibleTokenSwitchboard bugs#186

Merged
joshuahannan merged 4 commits intomasterfrom
fix/fungible-token-switchboard-bugs
Mar 12, 2026
Merged

Fix: three FungibleTokenSwitchboard bugs#186
joshuahannan merged 4 commits intomasterfrom
fix/fungible-token-switchboard-bugs

Conversation

@joshuahannan
Copy link
Member

Summary

  • removeVault wrong error message: The panic message in removeVault referred to addNewVaultWrapper instead of removeVault, producing misleading errors when the capability cannot be borrowed.

  • addNewVaultWrappersByPath missing array length guard: No check that paths and types have equal length before the loop accesses types[i]. If paths is longer than types, the function panics with an index out-of-bounds error. Added a pre condition requiring paths.length == types.length.

  • addNewVaultsByPath redundant force-unwraps: vaultRef!.getType() used the force-unwrap operator on a value already safely unwrapped by the enclosing if let vaultRef = capability.borrow() binding. Removed the unnecessary ! operators.

Test plan

  • Verify removeVault produces an error message containing "removeVault" when the capability is invalid
  • Verify addNewVaultWrappersByPath panics with a clear message when paths.length != types.length
  • Verify addNewVaultWrappersByPath still works correctly when arrays are the same length
  • Verify all existing switchboard tests still pass

🤖 Generated with Claude Code

@joshuahannan joshuahannan changed the title fix: three FungibleTokenSwitchboard bugs Fix: three FungibleTokenSwitchboard bugs Mar 11, 2026
joshuahannan and others added 2 commits March 11, 2026 15:08
1. removeVault: panic message incorrectly named the function as
   "addNewVaultWrapper" instead of "removeVault", making error messages
   misleading when the capability cannot be borrowed.

2. addNewVaultWrappersByPath: no guard on the paths and types arrays
   having equal length. If paths is longer than types, accessing
   types[i] panics with an index out-of-bounds. Added a pre-condition
   requiring paths.length == types.length.

3. addNewVaultsByPath: redundant force-unwrap operators (vaultRef!) on
   a value already safely unwrapped by the surrounding if-let binding.
   Removed the unnecessary unwraps.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- testRemoveVaultPanicsWithCorrectFunctionName: verifies the panic message
  from removeVault names the correct function (not "addNewVaultWrapper")
- testAddNewVaultWrappersByPathPanicsOnMismatchedArrayLengths: verifies the
  pre-condition fires when paths and types arrays have different lengths
- testAddNewVaultsByPathAddsCapabilitiesCorrectly: verifies addNewVaultsByPath
  correctly indexes capabilities by vault type from the given address

Also adds a test helper transaction for the mismatched arrays scenario
and regenerates assets.go to embed the updated FungibleTokenSwitchboard.cdc.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@joshuahannan joshuahannan force-pushed the fix/fungible-token-switchboard-bugs branch from afc2b7b to be27fd2 Compare March 11, 2026 20:09
joshuahannan and others added 2 commits March 11, 2026 15:14
The curl-based install script fails in CI with "can't access tty" because
it requires an interactive terminal to fetch the latest release version.
Replace it with the official onflow/flow-cli-action which handles
installation reliably in non-interactive environments.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@joshuahannan joshuahannan merged commit a1bc3ea into master Mar 12, 2026
2 checks passed
@joshuahannan joshuahannan deleted the fix/fungible-token-switchboard-bugs branch March 12, 2026 16:06
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