✨ Feature Request: Add ERC20 Approval Test Cases to Smart Sessions Test Suite
- Dominant language
- TypeScript
- Stars
- 14
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
### Feature or Improvement Description
Add test cases to `toSmartSessionValidator.test.ts` that demonstrate and validate ERC20 token approvals using Smart Sessions, including verification of allowances after successful approval operations.
### Benefits & Outcomes
- **Validate Token Integration**: Ensure Smart Sessions work correctly with standard ERC20 token operations.
- **Demonstrate Common Use Case**: Token approvals are a fundamental DeFi operation that needs thorough testing.
- **Enhance Test Coverage**: Add critical test cases for token-related functionality.
- **Provide Example Code**: Offer developers a reference implementation for token approvals using Smart Sessions.
- **Ensure Security**: Verify that allowances are set correctly and permissions work as intended.
### Implementation Ideas
1. **Add New Test Cases**
Add the following test cases to `src/sdk/modules/smartSessionsValidator/toSmartSessionsValidator.test.ts`. The test should:
- Create a session for ERC20 token approval
- Execute an approval transaction using the session
- Verify the allowance before and after the approval
- Include proper error handling and assertions
2. **Add Required Imports and Constants**
Add the USDC token ABI import to the test file and ensure all necessary constants are defined in the testAddresses object, including the USDC token address for the test network.
3. **Update Test Setup**
Update the test setup to include USDC token address and any additional configuration needed for token testing. Use the existing USDC deployment on the test network.
4. **Testing Considerations**
- Verify initial allowance is zero
- Test approval with different amounts
- Verify final allowance matches approved amount
- Include error cases (e.g., insufficient permissions)
- Test allowance updates
- Verify session permissions are correctly scoped
5. **Documentation**
- Add clear comments explaining the test flow
- Document any special considerations for token approvals
- Include examples of expected behaviors
- Update test documentation with new cases
## References
- [ERC20 Standard](https://eips.ethereum.org/EIPS/eip-20)
- [Smart Sessions Test File](src/sdk/modules/smartSessionsValidator/toSmartSessionsValidator.test.ts)
- [Smart Sessions Implementation](src/sdk/modules/smartSessionsValidator/toSmartSessionsValidator.ts)
- [USDC Token Contract](https://etherscan.io/token/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48)
- [Viem Documentation](https://viem.sh/docs/contract/encodeFunctionData.html)
---
- [x] I agree to follow this project's Code of Conduct.
### Any References?
_No response_
### Code of Conduct
- [x] I agree to follow this project's Code of Conduct.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.