Skip to main content
Tests can assert on the auths that are expected to occur. The following example sets up a test environment, registers an increment contract, and checks after the increment invocation what auths were required.
For the full example the above snippet is extracted from, see the auth example contract.

Authorization in constructors

If a contract’s constructor calls require_auth() (or require_auth_for_args()), both env.register(...) and env.register_at(...) switch the environment to recording-auth mode for the duration of the constructor invocation, inheriting the mode from the current auth manager. Once the constructor returns, the previous auth manager is restored. This means constructor auth checks succeed for contracts registered with either function, without requiring mock_all_auths() to be called first. To have auth in a constructor execute as it will in production the contract must be deployed in the test using the standard deployment functions after being built to Wasm.
This behaviour was not consistent in some versions of the soroban-sdk due to an issue, but is consistent as of v27.0.2.