Skip to content

Commit

Permalink
Add managed capability example without the unit return value
Browse files Browse the repository at this point in the history
  • Loading branch information
lsgunnlsgunn committed Feb 10, 2025
1 parent 8935676 commit 53b7543
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion docs/builtins/Repl/test-capability.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To acquire or install the `capability` specified, use the following syntax:

## Arguments

Use the following argument when using the `env-module-admin` Pact function.
Use the following argument when using the `test-capabilities` Pact function.

| Argument | Type | Description |
|----------|------|------------ |
Expand All @@ -34,3 +34,30 @@ pact> (module m g (defcap g () true))
pact> (test-capability (g))
"Capability acquired"
```

In this example, the capability isn't a managed capability and doesn't require any arguments.
Managed capabilities define a resource that the capability controls access to and a management function that modifies the resource.
For example, you might define a managed capability and management function similar to the following:

```pact
(defcap PAY (sender:string receiver:string amount:decimal)
@managed amount manage-PAY
(compose-capability (USER_GUARD sender)))
(defun manage-PAY (mgd recd)
(let ((bal:decimal (- mgd recd)))
(enforce (>= bal 0.0) "insufficient balance")
bal))
(defun pay (sender:string receiver:string amount:decimal)
(with-capability (PAY sender receiver amount) (transfer sender receiver amount))
)
```

For this example, the `PAY` managed capability requires the `sender`, `receiver`, and `amount` arguments:

```pact
(begin-tx "Set capability")
(test-capability (cap-role.PAY "Alice" "Bob" 3.0))
(commit-tx)
```

0 comments on commit 53b7543

Please sign in to comment.