Skip to content

Commit

Permalink
XChain ERC20, Custom IsEntitled (#648)
Browse files Browse the repository at this point in the history
E2E tests for ERC20, implementation and E2E tests for custom
entitlements. (remaining: eth balance and 1155.)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced entitlement management to allow individual updates for
multiple user addresses.
- New utilities for testing ERC20 token interactions and custom
entitlement checks.
- Mock contracts for `MockCustomEntitlement` and `MockERC20` introduced
to facilitate development and testing.

- **Bug Fixes**
- Improved handling of entitlement checks in the application logic,
ensuring accurate status retrieval.

- **Documentation**
- Updated function signatures to clarify that multiple users can be
processed, enhancing API usability.

- **Tests**
- Expanded test suite with new cases for ERC20 token interactions and
custom entitlement logic.
- Refactored and organized existing tests for enhanced readability and
maintainability.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
clemire authored Aug 8, 2024
1 parent 6237b4d commit a491a45
Show file tree
Hide file tree
Showing 17 changed files with 1,833 additions and 235 deletions.
15 changes: 11 additions & 4 deletions contracts/test/mocks/MockCustomEntitlement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ contract MockCustomEntitlement is ICustomEntitlement {

constructor() {}

function setEntitled(address[] memory user, bool userIsEntitled) external {
entitled[keccak256(abi.encode(user))] = userIsEntitled;
function setEntitled(address[] memory users, bool userIsEntitled) external {
for (uint256 i = 0; i < users.length; i++) {
entitled[keccak256(abi.encode(users[i]))] = userIsEntitled;
}
}

function isEntitled(
address[] memory user
address[] memory users
) external view override returns (bool) {
return entitled[keccak256(abi.encode(user))];
for (uint256 i = 0; i < users.length; i++) {
if (entitled[keccak256(abi.encode(users[i]))] == true) {
return true;
}
}
return false;
}
}
4 changes: 2 additions & 2 deletions packages/generated/dev/abis/MockCustomEntitlement.abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"name": "isEntitled",
"inputs": [
{
"name": "user",
"name": "users",
"type": "address[]",
"internalType": "address[]"
}
Expand All @@ -28,7 +28,7 @@
"name": "setEntitled",
"inputs": [
{
"name": "user",
"name": "users",
"type": "address[]",
"internalType": "address[]"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/generated/dev/abis/MockCustomEntitlement.abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default [
"name": "isEntitled",
"inputs": [
{
"name": "user",
"name": "users",
"type": "address[]",
"internalType": "address[]"
}
Expand All @@ -28,7 +28,7 @@ export default [
"name": "setEntitled",
"inputs": [
{
"name": "user",
"name": "users",
"type": "address[]",
"internalType": "address[]"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/generated/dev/abis/MockCustomEntitlement.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
608060405234801561001057600080fd5b506102c1806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80633f4c4d831461003b578063ddc6e68e14610050575b600080fd5b61004e6100493660046101e0565b610077565b005b61006361005e366004610237565b6100c4565b604051901515815260200160405180910390f35b806000808460405160200161008c9190610274565b60408051808303601f19018152918152815160209283012083529082019290925201600020805460ff19169115159190911790555050565b6000806000836040516020016100da9190610274565b60408051601f198184030181529181528151602092830120835290820192909252016000205460ff1692915050565b634e487b7160e01b600052604160045260246000fd5b80356001600160a01b038116811461013657600080fd5b919050565b600082601f83011261014c57600080fd5b8135602067ffffffffffffffff8083111561016957610169610109565b8260051b604051601f19603f8301168101818110848211171561018e5761018e610109565b60405293845260208187018101949081019250878511156101ae57600080fd5b6020870191505b848210156101d5576101c68261011f565b835291830191908301906101b5565b979650505050505050565b600080604083850312156101f357600080fd5b823567ffffffffffffffff81111561020a57600080fd5b6102168582860161013b565b9250506020830135801515811461022c57600080fd5b809150509250929050565b60006020828403121561024957600080fd5b813567ffffffffffffffff81111561026057600080fd5b61026c8482850161013b565b949350505050565b6020808252825182820181905260009190848201906040850190845b818110156102b55783516001600160a01b031683529284019291840191600101610290565b5090969550505050505056
608060405234801561001057600080fd5b50610317806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80633f4c4d831461003b578063ddc6e68e14610050575b600080fd5b61004e61004936600461026d565b610077565b005b61006361005e3660046102c4565b610101565b604051901515815260200160405180910390f35b60005b82518110156100fc578160008085848151811061009957610099610301565b60200260200101516040516020016100c091906001600160a01b0391909116815260200190565b60408051808303601f19018152918152815160209283012083529082019290925201600020805460ff191691151591909117905560010161007a565b505050565b6000805b825181101561018d5760008084838151811061012357610123610301565b602002602001015160405160200161014a91906001600160a01b0391909116815260200190565b60408051601f198184030181529181528151602092830120835290820192909252016000205460ff1615156001036101855750600192915050565b600101610105565b50600092915050565b634e487b7160e01b600052604160045260246000fd5b80356001600160a01b03811681146101c357600080fd5b919050565b600082601f8301126101d957600080fd5b8135602067ffffffffffffffff808311156101f6576101f6610196565b8260051b604051601f19603f8301168101818110848211171561021b5761021b610196565b604052938452602081870181019490810192508785111561023b57600080fd5b6020870191505b8482101561026257610253826101ac565b83529183019190830190610242565b979650505050505050565b6000806040838503121561028057600080fd5b823567ffffffffffffffff81111561029757600080fd5b6102a3858286016101c8565b925050602083013580151581146102b957600080fd5b809150509250929050565b6000602082840312156102d657600080fd5b813567ffffffffffffffff8111156102ed57600080fd5b6102f9848285016101c8565b949350505050565b634e487b7160e01b600052603260045260246000fd
2 changes: 1 addition & 1 deletion packages/generated/dev/abis/MockCustomEntitlement.json

Large diffs are not rendered by default.

28 changes: 7 additions & 21 deletions packages/generated/dev/abis/MockCustomEntitlement.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"inputs": [
{
"internalType": "address[]",
"name": "user",
"name": "users",
"type": "address[]"
}
],
Expand All @@ -33,7 +33,7 @@
"inputs": [
{
"internalType": "address[]",
"name": "user",
"name": "users",
"type": "address[]"
},
{
Expand All @@ -49,25 +49,12 @@
],
"devdoc": {
"kind": "dev",
"methods": {
"isEntitled(address[])": {
"params": {
"user": "address of the user to check"
},
"returns": {
"_0": "whether the user is entitled to the permission"
}
}
},
"methods": {},
"version": 1
},
"userdoc": {
"kind": "user",
"methods": {
"isEntitled(address[])": {
"notice": "checks whether a user is has a given permission for a channel or a space"
}
},
"methods": {},
"version": 1
}
},
Expand All @@ -77,7 +64,6 @@
"@prb/math/=lib/@prb/math/src/",
"@prb/test/=lib/@prb/test/src/",
"account-abstraction/=lib/account-abstraction/contracts/",
"base64/=lib/base64/",
"ds-test/=lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
"hardhat-deploy/=lib/hardhat-deploy/",
Expand Down Expand Up @@ -107,10 +93,10 @@
"license": "MIT"
},
"contracts/test/mocks/MockCustomEntitlement.sol": {
"keccak256": "0x6afb663aa6c5f6403a9b9f833f79e5cc87f594e8bca8f91e5d69d835242655e2",
"keccak256": "0x99a8c364152ef8f6a33bb93c8b2df6d29541a56cb2129a6d3260aecb1a0d0077",
"urls": [
"bzz-raw://0addd74396a3583bc3e6fd38977d84e06a98093567038ce067f505784cd7e38c",
"dweb:/ipfs/Qma5CE3NqVK9cEczjwhtdGgtUr1P4qgGpa9DMh6druciyx"
"bzz-raw://b6a13501aadf349bb71309de5760dfe7971634e8dcff329e0ae8295b8830aace",
"dweb:/ipfs/QmT8xRoZX8gCWaNo1BPZia9GrEkCtthuxpYFFJ1dwoy46Y"
],
"license": "MIT"
}
Expand Down
Loading

0 comments on commit a491a45

Please sign in to comment.