Skip to content

Commit

Permalink
Fix RoleRevoked events handling and format
Browse files Browse the repository at this point in the history
  • Loading branch information
TucksonDev committed Jan 8, 2024
1 parent b05a446 commit 1db0812
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
23 changes: 17 additions & 6 deletions src/upgradeExecutor.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -91,7 +98,7 @@ const RoleRevokedEventAbi: AbiEvent = {
type: 'address',
},
],
name: 'RoleGranted',
name: 'RoleRevoked',
type: 'event',
};

Expand Down Expand Up @@ -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];
}
}
});

Expand All @@ -153,4 +165,3 @@ export async function upgradeExecutorFetchPrivilegedAccounts({
function hex(arg0: string): `0x${string}` | Uint8Array {
throw new Error('Function not implemented.');
}

11 changes: 8 additions & 3 deletions src/upgradeExecutor.unit.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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,
Expand Down

0 comments on commit 1db0812

Please sign in to comment.