-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add upgradeExecutor integration tests
- Loading branch information
1 parent
3a29ffa
commit 09b6ef9
Showing
1 changed file
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { getInformationFromTestnode, getNitroTestnodePrivateKeyAccounts } from '../testHelpers'; | ||
import { Address, createPublicClient, http } from 'viem'; | ||
import { nitroTestnodeL2 } from '../chains'; | ||
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'; | ||
import { upgradeExecutorFetchPrivilegedAccounts } from '../upgradeExecutorFetchPrivilegedAccounts'; | ||
import { buildAddExecutor } from './buildAddExecutor'; | ||
import { UPGRADE_EXECUTOR_ROLE_EXECUTOR } from '../upgradeExecutorEncodeFunctionData'; | ||
import { buildRemoveExecutor } from './buildRemoveExecutor'; | ||
import { hasRole } from './hasRole'; | ||
|
||
const { l3UpgradeExecutor } = getInformationFromTestnode(); | ||
const { l3RollupOwner } = getNitroTestnodePrivateKeyAccounts(); | ||
|
||
const client = createPublicClient({ | ||
chain: nitroTestnodeL2, | ||
transport: http(), | ||
}); | ||
|
||
describe('Upgrade executor', () => { | ||
it('buildAddExecutor and buildRemoveExecutor update upgradeExecutor', async () => { | ||
async function changeUpgradeExecutor(address: Address, add: boolean) { | ||
const fn = add ? buildAddExecutor : buildRemoveExecutor; | ||
const transactionRequest = await fn(client, { | ||
account: l3RollupOwner.address, | ||
upgradeExecutor: l3UpgradeExecutor, | ||
params: { | ||
address, | ||
}, | ||
}); | ||
const txHash = await client.sendRawTransaction({ | ||
serializedTransaction: await l3RollupOwner.signTransaction(transactionRequest), | ||
}); | ||
await client.waitForTransactionReceipt({ hash: txHash }); | ||
} | ||
const addUpgradeExecutor = (address: Address) => changeUpgradeExecutor(address, true); | ||
const removeUpgradeExecutor = (address: Address) => changeUpgradeExecutor(address, false); | ||
|
||
const randomAddress = privateKeyToAccount(generatePrivateKey()).address; | ||
|
||
const initialState = await upgradeExecutorFetchPrivilegedAccounts({ | ||
upgradeExecutorAddress: l3UpgradeExecutor, | ||
publicClient: client, | ||
}); | ||
|
||
expect( | ||
await hasRole(client, { | ||
params: { | ||
role: UPGRADE_EXECUTOR_ROLE_EXECUTOR, | ||
address: randomAddress, | ||
}, | ||
upgradeExecutor: l3UpgradeExecutor, | ||
}), | ||
).toBeFalsy(); | ||
|
||
await addUpgradeExecutor(randomAddress); | ||
expect( | ||
await upgradeExecutorFetchPrivilegedAccounts({ | ||
upgradeExecutorAddress: l3UpgradeExecutor, | ||
publicClient: client, | ||
}), | ||
).toEqual({ | ||
...initialState, | ||
[randomAddress]: [UPGRADE_EXECUTOR_ROLE_EXECUTOR], | ||
}); | ||
expect( | ||
await hasRole(client, { | ||
params: { | ||
role: UPGRADE_EXECUTOR_ROLE_EXECUTOR, | ||
address: randomAddress, | ||
}, | ||
upgradeExecutor: l3UpgradeExecutor, | ||
}), | ||
).toBeTruthy(); | ||
|
||
await removeUpgradeExecutor(randomAddress); | ||
expect( | ||
await upgradeExecutorFetchPrivilegedAccounts({ | ||
upgradeExecutorAddress: l3UpgradeExecutor, | ||
publicClient: client, | ||
}), | ||
).toEqual(initialState); | ||
expect( | ||
await hasRole(client, { | ||
params: { | ||
role: UPGRADE_EXECUTOR_ROLE_EXECUTOR, | ||
address: randomAddress, | ||
}, | ||
upgradeExecutor: l3UpgradeExecutor, | ||
}), | ||
).toBeFalsy(); | ||
}); | ||
}); |