Skip to content

Commit 7dfc6e4

Browse files
align delegate-auth docs with merged example tests
1 parent 18b3dd2 commit 7dfc6e4

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

docs/build/smart-contracts/example-contracts/delegate-auth.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ make test
6060
Expected output:
6161

6262
```
63-
running 1 test
63+
running 3 tests
64+
test test::test_empty_delegates_is_rejected ... ok
65+
test test::test_unknown_delegate_is_rejected ... ok
6466
test test::test ... ok
67+
68+
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
6569
```
6670

6771
[setup]: ../getting-started/setup.mdx
@@ -252,6 +256,8 @@ After the call, the test asserts two things:
252256
1. `env.auths()` shows only the account authorizing `protected` — delegating to `DelegateAccount` is not recorded as a separate top-level authorization.
253257
2. `DelegateAccount`'s `ApprovedContexts` storage contains the same contract context, confirming the delegation actually reached it.
254258

259+
Two further tests cover the rejection paths: `test_unknown_delegate_is_rejected` attaches a delegate the account never registered, and `test_empty_delegates_is_rejected` attaches none at all. In both, `Protected::protected` fails. The caller only sees a generic `Error(Auth, InvalidAction)`, because the host escalates any failed `__check_auth` to that — the account's own error code does not propagate to the return value. To assert the account rejected the call for its own reason, the tests read the host's diagnostic events with `env.host().get_diagnostic_events()` and match the recorded `Error(Contract, #n)``UnknownDelegate` and `InsufficientDelegates` respectively.
260+
255261
:::note
256262

257263
Testing delegated auth via `env.try_invoke_contract_check_auth` is not supported. Use `env.set_auths` with `SorobanAddressCredentialsWithDelegates` and a wrapper contract call instead, as shown in the test.

0 commit comments

Comments
 (0)