/ AGENTS-VALIDATION.md
AGENTS-VALIDATION.md
 1  # AGENTS-VALIDATION.md
 2  
 3  How to validate Solidity contracts before deployment.
 4  
 5  ## Environment Setup
 6  ```bash
 7  # Required in .env
 8  RPC_URL=https://eth-sepolia.g.alchemy.com/v2/...
 9  DAO_ADDRESS=0x...
10  PRIVATE_KEY=0x...
11  ```
12  
13  ## Validation Commands
14  
15  ```bash
16  # 1. Build and test
17  forge build
18  forge test
19  
20  # 2. Dry run deployment 
21  forge script script/Deploy.s.sol:Deploy --rpc-url $RPC_URL
22  
23  # 3. Deploy and validate on testnet
24  forge script script/Deploy.s.sol:Deploy --rpc-url $RPC_URL --broadcast
25  ```
26  
27  ## Manual Testing with Anvil
28  
29  ```bash
30  # Start local fork
31  anvil --fork-url $RPC_URL --chain-id 31337
32  
33  # Deploy to local fork
34  forge script script/Deploy.s.sol:Deploy --rpc-url http://localhost:8545 --broadcast
35  
36  # Test contract calls
37  cast send 0x[CONTRACT] "signal(...)" ... --private-key 0x[KEY] --rpc-url http://localhost:8545
38  ```
39  
40  ## Key Test Patterns
41  
42  ### Access Control
43  ```solidity
44  function test_OnlyDAO_Success() public {
45      vm.prank(DAO);
46      signal.restrictedFunction();
47  }
48  
49  function test_OnlyDAO_RevertWhen_NotDAO() public {
50      vm.prank(address(0x123));
51      vm.expectRevert("NOT_DAO");
52      signal.restrictedFunction();
53  }
54  ```
55  
56  ### Events
57  ```solidity
58  vm.expectEmit(true, true, true, true, address(signal));
59  emit CogniAction(dao, chainId, repo, action, target, pr, commit, 
60      abi.encode(uint256(1), uint64(1234567890), string('{"schema":"cogni.action@1"}')), executor);
61  signal.functionThatEmits();
62  ```
63  
64  ### Access Control
65  ```solidity
66  vm.prank(address(0x456));
67  vm.expectRevert("NOT_DAO");
68  signal.signal(repo, action, target, pr, commit, extra);
69  ```
70  
71  That's it. Keep tests simple and focused.