Skip to content

test(vault): explicit require_auth assertions for set_admin - #585

Merged
greatest0fallt1me merged 2 commits into
CalloraOrg:mainfrom
Osuolale1:task/set-admin-test
Jun 29, 2026
Merged

test(vault): explicit require_auth assertions for set_admin#585
greatest0fallt1me merged 2 commits into
CalloraOrg:mainfrom
Osuolale1:task/set-admin-test

Conversation

@Osuolale1

Copy link
Copy Markdown
Contributor

CLOSE #534

Summary

CalloraVault::set_admin is gated by both caller.require_auth() and an in-body caller != current_admin identity check. The existing set_admin_unauthorized_fails test runs under env.mock_all_auths(), which silently approves any signer — so it only exercises the identity check. If caller.require_auth() were ever removed (intentionally or via a bad merge), the existing test would still pass, leaving the contract one line away from accepting unauthenticated admin rotations.

This PR adds an integration-test file that asserts the Soroban auth framework itself is the gate.

Changes

contracts/vault/tests/set_admin_auth.rs (new) — three integration tests:

  • set_admin_fails_without_authorizationenv.set_auths(&[]) + try_set_admin must error
  • set_admin_records_caller_auth_entryenv.auths() must contain an entry for the caller after a successful call
  • set_admin_fails_when_only_other_party_authorizes — auth mocked for a different address than the declared caller must still fail

contracts/vault/src/lib.rs — separate commit; reconstructs merge corruption left by PRs #578/#579 "-X theirs" auto-resolutions so the workspace compiles. See commit message for the line-by-line list.

Note on "multisig" wording

The bounty asks for tests that set_admin "requires multisig." This contract uses a single-admin model with a two-step pending/accept transfer (lib.rs:574-619), not multisig. The tests assert the strongest property the current contract supports: that Soroban's require_auth framework gates set_admin.

Acceptance criteria

  • Tests assert require_auth is invoked (not just the identity check)
  • All three tests pass locally: cargo test -p callora-vault --test set_admin_auth
  • NatSpec-style /// rustdoc on every test plus //! module preamble
  • No public ABI change; no behavior change to set_admin

Test plan

  • cargo test -p callora-vault --test set_admin_auth → 3 passed
  • CI green (note: settlement crate currently has its own pre-existing merge breakage; if CI is red for that reason it is not a regression from this PR)

Known pre-existing breakage NOT addressed here

The callora-settlement crate has ~77 errors from the same kind of "-X theirs" merge corruption (missing module declarations, duplicate get_storage_ttl, drifted DeveloperBalance.token field, missing StorageKey::DeveloperBalanceV1/StorageVersion variants). Fixing it requires judgment on whether the per-token storage migration was meant to land — out of scope for this PR.

Recent "-X theirs" auto-resolutions in PRs CalloraOrg#578/CalloraOrg#579 left contracts/vault/src/lib.rs
in a non-compiling state with 107 errors. This commit reconstructs the intended state:

- remove duplicate get_max_deduct (was defined at L376 and L1305; kept the
  documented copy at L376)
- remove panic-version broadcast (kept the Result-returning version that
  matches the surrounding contract style and reuses VaultError::MetadataTooLong)
- replace inline VaultError enum with the canonical one in errors.rs via
  `mod errors; pub use errors::VaultError;` (the inline copy was missing the
  contracterror macro import and was diverging from errors.rs)
- declare `mod validators;` so validators.rs is wired into the crate
- fix two StorageKey::Meta typos (variant is MetaKey)
- add the missing `&ut` (USDC token) argument to two
  SettlementClient::receive_payment calls (the settlement trait takes 5 args,
  the call sites were passing 4)
- change `max_fee_bps: u16` -> `u32` in `deduct` (Soroban contract ABI does
  not support u16; updated the u16::MAX sentinel to u32::MAX accordingly)

Verified with `cargo check -p callora-vault --lib`.
The existing set_admin_unauthorized_fails test runs under env.mock_all_auths(),
so it only exercises the in-body `caller != current_admin` identity check.
Removing caller.require_auth() from set_admin would leave that test green,
leaving the contract one edit away from accepting unauthenticated rotations.

Add three integration tests that assert the Soroban auth framework itself
is the gate:

- set_admin_fails_without_authorization: env.set_auths(&[]) + try_set_admin
  must return Err (proves require_auth, not the identity check, is rejecting)
- set_admin_records_caller_auth_entry: under mock_auths for the caller,
  env.auths() must contain an entry signed by the caller
- set_admin_fails_when_only_other_party_authorizes: auth mocked for a
  different address than the declared caller must still cause the call to
  fail (proves require_auth checks the caller parameter, not any in-scope
  signer)

Note: the bounty wording asks for "multisig" tests but the vault uses a
single-admin model with a two-step pending/accept transfer. The tests assert
the strongest property the current contract supports.
@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@Osuolale1 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Osuolale1

Copy link
Copy Markdown
Contributor Author

CI is failing on a build error in the callora-settlement crate, not on this PR's changes.

The settlement crate currently has ~77 compile errors (duplicate get_storage_ttl, missing mod admin/limits/pagination/timelock/types declarations, drifted DeveloperBalance arity, missing StorageKey::DeveloperBalanceV1 / StorageVersion variants, missing Severity / AdminBroadcast / StorageEntryTtl / PendingDeveloperMigration types). These appear to be left over from the "-X theirs" auto-resolved merges in commits b3d2e5f and 6d87b37 — the same class of damage I had to repair in vault/src/lib.rs (separate commit on this PR) to get the workspace to compile at all.

Locally, with that vault repair in place:

```
$ cargo check -p callora-vault --lib
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.99s

$ cargo test -p callora-vault --test set_admin_auth
running 3 tests
test set_admin_fails_without_authorization ... ok
test set_admin_fails_when_only_other_party_authorizes ... ok
test set_admin_records_caller_auth_entry ... ok
test result: ok. 3 passed; 0 failed
```

(Test was verified by temporarily commenting out the `callora-settlement` dev-dep in `contracts/vault/Cargo.toml`; that change is not in this PR — the dev-dep is restored to its original state.)

The settlement crate has a real product question underneath: it looks like a per-token storage migration (`StorageKey::DeveloperBalance(addr, token)`, `StorageVersion`, the `migrate` module's V1→V2 path) was staged but never finished. Reconciling it requires deciding whether that migration is meant to land or to be rolled back — I don't want to guess on that. Could a maintainer confirm the intended direction and either fix settlement here or flag it as a separate issue?

@greatest0fallt1me
greatest0fallt1me merged commit 5ad4f63 into CalloraOrg:main Jun 29, 2026
1 of 6 checks passed
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.

Add explicit auth assertion test for set_admin

2 participants