Skip to content

Commit

Permalink
Merge pull request #143 from DIMO-Network/feature/si-2665-admin-funct…
Browse files Browse the repository at this point in the history
…ion-to-remove-attributes

Feature/si 2665 admin function to remove attributes
  • Loading branch information
LorranSutter committed May 23, 2024
2 parents fc92ebc + 604cbe8 commit 9ca3754
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Selectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
| 0xb17b974b | adminCacheDimoStreamrEns() |
| 0x56936962 | adminChangeParentNode(uint256,address,uint256[]) |
| 0x3febacab | adminPairAftermarketDevice(uint256,uint256) |
| 0x5f741f4d | adminRemoveVehicleAttribute(string) |
| 0xf73a8f04 | renameManufacturers((uint256,string)[]) |
| 0xff96b761 | transferAftermarketDeviceOwnership(uint256,address) |
| 0x5c129493 | unclaimAftermarketDeviceNode(uint256[]) |
Expand All @@ -53,6 +54,7 @@
| 0xf6391f5c | RoleRevoked(bytes32,address,address) |
| 0x8ad18187 | SyntheticDeviceAttributeSetDevAdmin(uint256,string,string) |
| 0x81741fdd | SyntheticDeviceNodeBurnedDevAdmin(uint256,uint256,address) |
| 0x9b4bf377 | VehicleAttributeRemoved(string) |
| 0x1d91e00c | VehicleAttributeSetDevAdmin(uint256,string,string) |
| 0xb956d027 | VehicleNodeBurnedDevAdmin(uint256,address) |

Expand Down
26 changes: 26 additions & 0 deletions abis/DimoRegistry.json
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,19 @@
"name": "SyntheticDeviceNodeBurnedDevAdmin",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "string",
"name": "attribute",
"type": "string"
}
],
"name": "VehicleAttributeRemoved",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -609,6 +622,19 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "attribute",
"type": "string"
}
],
"name": "adminRemoveVehicleAttribute",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down
16 changes: 16 additions & 0 deletions contracts/dev/DevAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ contract DevAdmin is AccessControlInternal {
uint256 vehicleNode,
address indexed owner
);
event VehicleAttributeRemoved(string attribute);

struct IdManufacturerName {
uint256 tokenId;
Expand Down Expand Up @@ -631,6 +632,21 @@ contract DevAdmin is AccessControlInternal {
streamRegistry.createStreamWithENS(dimoStreamrEns, "/vehicles/", "{}");
}

/**
* @notice Admin function remove a vehicle node attribute
* @dev Caller must have the DEV_REMOVE_ATTR role
*/
function adminRemoveVehicleAttribute(
string calldata attribute
) external onlyRole(DEV_REMOVE_ATTR) {
if (
AttributeSet.remove(
VehicleStorage.getStorage().whitelistedAttributes,
attribute
)
) emit VehicleAttributeRemoved(attribute);
}

/**
* @dev Internal function to reset vehicle node infos
* It iterates over all whitelisted attributes to reset each info
Expand Down
1 change: 1 addition & 0 deletions contracts/shared/Roles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ bytes32 constant DEV_AD_BURN_ROLE = keccak256("DEV_AD_BURN_ROLE");
bytes32 constant DEV_SD_BURN_ROLE = keccak256("DEV_SD_BURN_ROLE");
bytes32 constant DEV_CHANGE_PARENT_NODE = keccak256("DEV_CHANGE_PARENT_NODE");
bytes32 constant DEV_CACHE_ENS = keccak256("DEV_CACHE_ENS");
bytes32 constant DEV_REMOVE_ATTR = keccak256("DEV_REMOVE_ATTR");
3 changes: 2 additions & 1 deletion scripts/data/deployArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export const roles = {
DEV_AD_BURN_ROLE: _hashRole('DEV_AD_BURN_ROLE'),
DEV_SD_BURN_ROLE: _hashRole('DEV_SD_BURN_ROLE'),
DEV_CHANGE_PARENT_NODE: _hashRole('DEV_CHANGE_PARENT_NODE'),
DEV_CACHE_ENS: _hashRole('DEV_CACHE_ENS')
DEV_CACHE_ENS: _hashRole('DEV_CACHE_ENS'),
DEV_REMOVE_ATTR: _hashRole('DEV_REMOVE_ATTR')
},
nfts: {
MINTER_ROLE: _hashRole('MINTER_ROLE'),
Expand Down
35 changes: 35 additions & 0 deletions test/DevAdmin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2701,4 +2701,39 @@ describe('DevAdmin', function () {
});
});
});

describe('adminRemoveVehicleAttribute', () => {
context('Error handling', () => {
it('Should revert if caller does not have DEV_REMOVE_ATTR role', async () => {
await expect(
devAdminInstance
.connect(nonAdmin)
.adminRemoveVehicleAttribute(C.mockVehicleAttribute1),
).to.be.rejectedWith(
`AccessControl: account ${nonAdmin.address.toLowerCase()} is missing role ${C.DEV_REMOVE_ATTR
}`,
);
});
});

context('Events', () => {
it('Should not emit VehicleAttributeRemoved if attribute does not exist', async () => {
await expect(
devAdminInstance
.connect(admin)
.adminRemoveVehicleAttribute('UnexistentAttribute')
)
.to.not.emit(devAdminInstance, 'VehicleAttributeRemoved')
});
it('Should emit VehicleAttributeRemoved event with correct params', async () => {
await expect(
devAdminInstance
.connect(admin)
.adminRemoveVehicleAttribute(C.mockVehicleAttribute1)
)
.to.emit(devAdminInstance, 'VehicleAttributeRemoved')
.withArgs(C.mockVehicleAttribute1);
});
});
});
});
3 changes: 3 additions & 0 deletions utils/constants/AccessControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,6 @@ export const DEV_CHANGE_PARENT_NODE = ethers.keccak256(
export const DEV_CACHE_ENS = ethers.keccak256(
ethers.toUtf8Bytes('DEV_CACHE_ENS')
);
export const DEV_REMOVE_ATTR = ethers.keccak256(
ethers.toUtf8Bytes('DEV_REMOVE_ATTR')
);
3 changes: 2 additions & 1 deletion utils/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export async function grantAdminRoles(
C.DEV_AD_BURN_ROLE,
C.DEV_SD_BURN_ROLE,
C.DEV_CHANGE_PARENT_NODE,
C.DEV_CACHE_ENS
C.DEV_CACHE_ENS,
C.DEV_REMOVE_ATTR
];

for (const role of roles) {
Expand Down

0 comments on commit 9ca3754

Please sign in to comment.