Assists with testing Aztec smart contracts using the TestEnvironment. Use when writing unit tests, integration tests, or debugging test failures for Aztec contracts.
/plugin marketplace add critesjosh/aztec-claude-plugin/plugin install critesjosh-aztec@critesjosh/aztec-claude-pluginThis skill is limited to using the following tools:
You are an expert in testing Aztec smart contracts. Help users write comprehensive tests using Aztec's TestEnvironment and debugging test failures.
Aztec provides a Noir-native testing framework using TestEnvironment that allows you to:
use dep::aztec::test::helpers::test_environment::TestEnvironment;
#[test]
fn test_example() {
// Setup
let mut env = TestEnvironment::new();
// Deploy
let deployer = env.deploy("MyContract");
let initializer = MyContract::interface().constructor(args);
let contract_address = deployer.with_public_initializer(owner, initializer);
// Act
let contract = MyContract::at(contract_address);
contract.some_function(args).call(&mut env.private());
// Assert
let result = contract.view_function().call(&mut env.public());
assert(result == expected);
}
// Deploy with public initializer
let address = deployer.with_public_initializer(owner, initializer);
// Deploy with private initializer
let address = deployer.with_private_initializer(owner, initializer);
// Deploy without initializer
let address = deployer.without_initializer();
#[test]
fn test_private_transfer() {
let mut env = TestEnvironment::new();
let alice = AztecAddress::from_field(1);
let bob = AztecAddress::from_field(2);
// Deploy and setup
let contract = deploy_token(&mut env, alice);
// Mint to alice first
contract.mint_private(alice, 100).call(&mut env.private());
// Transfer from alice to bob
env.impersonate(alice);
contract.transfer(bob, 50).call(&mut env.private());
// Verify balances
let alice_balance = contract.balance_of_private(alice).call(&mut env.private());
let bob_balance = contract.balance_of_private(bob).call(&mut env.private());
assert(alice_balance == 50);
assert(bob_balance == 50);
}
#[test]
fn test_public_mint() {
let mut env = TestEnvironment::new();
let admin = AztecAddress::from_field(1);
let user = AztecAddress::from_field(2);
let contract = deploy_token(&mut env, admin);
// Admin mints tokens
env.impersonate(admin);
contract.mint_public(user, 1000).call(&mut env.public());
// Verify balance
let balance = contract.balance_of_public(user).call(&mut env.public());
assert(balance == 1000);
}
#[test(should_fail)]
fn test_unauthorized_mint() {
let mut env = TestEnvironment::new();
let admin = AztecAddress::from_field(1);
let attacker = AztecAddress::from_field(2);
let contract = deploy_token(&mut env, admin);
// Non-admin tries to mint
env.impersonate(attacker);
contract.mint_public(attacker, 1000).call(&mut env.public());
// Should fail with "Unauthorized" or similar
}
#[test]
fn test_public_to_private() {
let mut env = TestEnvironment::new();
let user = AztecAddress::from_field(1);
let contract = deploy_token(&mut env, user);
// Give user some public tokens
contract.mint_public(user, 100).call(&mut env.public());
// Move tokens from public to private
env.impersonate(user);
contract.public_to_private(50).call(&mut env.private());
// Verify balances in both domains
let public_balance = contract.balance_of_public(user).call(&mut env.public());
let private_balance = contract.balance_of_private(user).call(&mut env.private());
assert(public_balance == 50);
assert(private_balance == 50);
}
#[test]
fn test_transfer_succeeds_with_sufficient_balance() { }
#[test(should_fail)]
fn test_transfer_fails_with_insufficient_balance() { }
Create reusable helpers for common setup:
fn deploy_token(env: &mut TestEnvironment, admin: AztecAddress) -> Token {
let deployer = env.deploy("Token");
let initializer = Token::interface().constructor(admin);
let address = deployer.with_public_initializer(admin, initializer);
Token::at(address)
}
"Not authorized" errors
env.impersonate(correct_user)State not updating
.private() vs .public())Note not found
Assertion failures
# Run all tests
nargo test
# Run specific test
nargo test --test-name test_transfer
# Run with verbose output
nargo test --show-output
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.