diff --git a/src/upgradeExecutor.ts b/src/upgradeExecutor.ts index f5083c70..d2b4518d 100644 --- a/src/upgradeExecutor.ts +++ b/src/upgradeExecutor.ts @@ -1,5 +1,12 @@ -import { Address, encodeFunctionData, EncodeFunctionDataParameters, keccak256, PublicClient, toHex } from 'viem'; -import { AbiEvent } from 'abitype' +import { + Address, + encodeFunctionData, + EncodeFunctionDataParameters, + keccak256, + PublicClient, + toHex, +} from 'viem'; +import { AbiEvent } from 'abitype'; import { upgradeExecutor } from './contracts'; import { GetFunctionName, Prettify } from './types/utils'; @@ -91,7 +98,7 @@ const RoleRevokedEventAbi: AbiEvent = { type: 'address', }, ], - name: 'RoleGranted', + name: 'RoleRevoked', type: 'event', }; @@ -142,9 +149,14 @@ export async function upgradeExecutorFetchPrivilegedAccounts({ const account = (roleRevokedEvent.args as RoleRevokedLogArgs).account; const role = (roleRevokedEvent.args as RoleRevokedLogArgs).role; - const roleIndex = upgradeExecutorPrivilegedAccounts[account].findIndex((accRole) => accRole == role); + const roleIndex = upgradeExecutorPrivilegedAccounts[account].findIndex( + (accRole) => accRole == role, + ); if (roleIndex >= 0) { - upgradeExecutorPrivilegedAccounts[account] = upgradeExecutorPrivilegedAccounts[account].splice(roleIndex, 1); + upgradeExecutorPrivilegedAccounts[account].splice(roleIndex, 1); + if (upgradeExecutorPrivilegedAccounts[account].length === 0) { + delete upgradeExecutorPrivilegedAccounts[account]; + } } }); @@ -153,4 +165,3 @@ export async function upgradeExecutorFetchPrivilegedAccounts({ function hex(arg0: string): `0x${string}` | Uint8Array { throw new Error('Function not implemented.'); } - diff --git a/src/upgradeExecutor.unit.test.ts b/src/upgradeExecutor.unit.test.ts index 5e31eeb7..4db228b1 100644 --- a/src/upgradeExecutor.unit.test.ts +++ b/src/upgradeExecutor.unit.test.ts @@ -1,5 +1,10 @@ import { it, expect } from 'vitest'; -import { upgradeExecutorEncodeFunctionData, upgradeExecutorFetchPrivilegedAccounts, UPGRADE_EXECUTOR_ROLE_ADMIN, UPGRADE_EXECUTOR_ROLE_EXECUTOR } from './upgradeExecutor'; +import { + upgradeExecutorEncodeFunctionData, + upgradeExecutorFetchPrivilegedAccounts, + UPGRADE_EXECUTOR_ROLE_ADMIN, + UPGRADE_EXECUTOR_ROLE_EXECUTOR, +} from './upgradeExecutor'; import { createPublicClient, http } from 'viem'; import { arbitrum } from 'viem/chains'; @@ -24,9 +29,9 @@ it('upgradeExecutorEncodeFunctionData', () => { }); // Temporary test with https://arbiscan.io/address/0x0611b78A42903a537BE7a2f9a8783BE39AC63cD9#events -it ('it fetches the right privileged accounts from an UpgradeExecutor', async () => { +it('it fetches the right privileged accounts from an UpgradeExecutor', async () => { const upgradeExecutorAddress = '0x0611b78A42903a537BE7a2f9a8783BE39AC63cD9'; - const chainOwner = '0xD1C955A1544cF449F4a8463E9fE2AC4Ff0798E05'; + const chainOwner = '0x46A78349aBA0369D18292a285DE6d5FC5CC2de5c'; const privilegedAccounts = await upgradeExecutorFetchPrivilegedAccounts({ upgradeExecutorAddress,