Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add RollupAdmin integration tests #190

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/actions/buildSetConfirmPeriodBlocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { rollupABI } from '../contracts/Rollup';
import {
WithAccount,
ActionParameters,
WithUpgradeExecutor,
PrepareTransactionRequestReturnTypeWithChainId,
} from '../types/Actions';
import { Prettify } from '../types/utils';
import { getRollupAddress } from '../getRollupAddress';
import { validateParentChainPublicClient } from '../types/ParentChain';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';

export type BuildSetConfirmPeriodBlocksParameters<Curried extends boolean = false> = Prettify<
WithUpgradeExecutor<
WithAccount<ActionParameters<{ newPeriod: bigint }, 'rollupAdminLogic', Curried>>
>
>;

export type BuildSetConfirmPeriodBlocksReturnType = PrepareTransactionRequestReturnTypeWithChainId;

export async function buildSetConfirmPeriodBlocks<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
{ params, account, upgradeExecutor, ...args }: BuildSetConfirmPeriodBlocksParameters,
): Promise<BuildSetConfirmPeriodBlocksReturnType> {
const validatedPublicClient = validateParentChainPublicClient(client);
const rollupAdminLogicAddress =
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic;

const request = await client.prepareTransactionRequest({
chain: client.chain as Chain | undefined,
account,
...prepareUpgradeExecutorCallParameters({
to: rollupAdminLogicAddress,
upgradeExecutor,
args: [params.newPeriod],
abi: rollupABI,
functionName: 'setConfirmPeriodBlocks',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: validatedPublicClient.chain.id };
}
44 changes: 44 additions & 0 deletions src/actions/buildSetExtraChallengeTimeBlocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { rollupABI } from '../contracts/Rollup';
import {
WithAccount,
ActionParameters,
WithUpgradeExecutor,
PrepareTransactionRequestReturnTypeWithChainId,
} from '../types/Actions';
import { Prettify } from '../types/utils';
import { getRollupAddress } from '../getRollupAddress';
import { validateParentChainPublicClient } from '../types/ParentChain';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';

export type BuildSetExtraChallengeTimeBlocksParameters<Curried extends boolean = false> = Prettify<
WithUpgradeExecutor<
WithAccount<ActionParameters<{ newExtraTimeBlocks: bigint }, 'rollupAdminLogic', Curried>>
>
>;

export type BuildSetExtraChallengeTimeBlocksReturnType =
PrepareTransactionRequestReturnTypeWithChainId;

export async function buildSetExtraChallengeTimeBlocks<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
{ params, account, upgradeExecutor, ...args }: BuildSetExtraChallengeTimeBlocksParameters,
): Promise<BuildSetExtraChallengeTimeBlocksReturnType> {
const validatedPublicClient = validateParentChainPublicClient(client);
const rollupAdminLogicAddress =
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic;

const request = await client.prepareTransactionRequest({
chain: client.chain as Chain | undefined,
account,
...prepareUpgradeExecutorCallParameters({
to: rollupAdminLogicAddress,
upgradeExecutor,
args: [params.newExtraTimeBlocks],
abi: rollupABI,
functionName: 'setExtraChallengeTimeBlocks',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: validatedPublicClient.chain.id };
}
44 changes: 44 additions & 0 deletions src/actions/buildSetMinimumAssertionPeriod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { rollupABI } from '../contracts/Rollup';
import {
WithAccount,
ActionParameters,
PrepareTransactionRequestReturnTypeWithChainId,
WithUpgradeExecutor,
} from '../types/Actions';
import { Prettify } from '../types/utils';
import { getRollupAddress } from '../getRollupAddress';
import { validateParentChainPublicClient } from '../types/ParentChain';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';

export type BuildSetMinimumAssertionPeriodParameters<Curried extends boolean = false> = Prettify<
WithUpgradeExecutor<
WithAccount<ActionParameters<{ newPeriod: bigint }, 'rollupAdminLogic', Curried>>
>
>;

export type BuildSetMinimumAssertionPeriodReturnType =
PrepareTransactionRequestReturnTypeWithChainId;

export async function buildSetMinimumAssertionPeriod<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
{ params, account, upgradeExecutor, ...args }: BuildSetMinimumAssertionPeriodParameters,
): Promise<BuildSetMinimumAssertionPeriodReturnType> {
const validatedPublicClient = validateParentChainPublicClient(client);
const rollupAdminLogicAddress =
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic;

const request = await client.prepareTransactionRequest({
chain: client.chain as Chain | undefined,
account,
...prepareUpgradeExecutorCallParameters({
to: rollupAdminLogicAddress,
upgradeExecutor,
args: [params.newPeriod],
abi: rollupABI,
functionName: 'setMinimumAssertionPeriod',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: validatedPublicClient.chain.id };
}
56 changes: 56 additions & 0 deletions src/actions/buildSetValidator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { rollupABI } from '../contracts/Rollup';
import {
WithAccount,
ActionParameters,
WithUpgradeExecutor,
PrepareTransactionRequestReturnTypeWithChainId,
} from '../types/Actions';
import { Prettify } from '../types/utils';
import { getRollupAddress } from '../getRollupAddress';
import { validateParentChainPublicClient } from '../types/ParentChain';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';

export type BuildSetIsValidatorParameters<Curried extends boolean = false> = Prettify<
WithUpgradeExecutor<
WithAccount<
ActionParameters<
{
add: Address[];
remove: Address[];
},
'rollupAdminLogic',
Curried
>
>
>
>;

export type BuildSetIsValidatorReturnType = PrepareTransactionRequestReturnTypeWithChainId;

export async function buildSetValidators<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
{ account, upgradeExecutor, params, ...args }: BuildSetIsValidatorParameters,
): Promise<BuildSetIsValidatorReturnType> {
const validatedPublicClient = validateParentChainPublicClient(client);
const rollupAdminLogicAddress =
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic;
const { add: addressesToAdd, remove: addressesToRemove } = params;

const addState: boolean[] = new Array(addressesToAdd.length).fill(true);
const removeState: boolean[] = new Array(addressesToRemove.length).fill(false);

const request = await client.prepareTransactionRequest({
chain: client.chain as Chain | undefined,
account,
...prepareUpgradeExecutorCallParameters({
to: rollupAdminLogicAddress,
upgradeExecutor,
args: [addressesToAdd.concat(addressesToRemove), addState.concat(removeState)],
abi: rollupABI,
functionName: 'setValidator',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: validatedPublicClient.chain.id };
}
70 changes: 70 additions & 0 deletions src/actions/buildSetValidatorWhitelistDisabled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { rollupABI } from '../contracts/Rollup';
import {
WithAccount,
ActionParameters,
WithUpgradeExecutor,
PrepareTransactionRequestReturnTypeWithChainId,
} from '../types/Actions';
import { Prettify } from '../types/utils';
import { getRollupAddress } from '../getRollupAddress';
import { validateParentChainPublicClient } from '../types/ParentChain';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';

export type BuildSetValidatorWhitelistDisabledParameters<Curried extends boolean = false> =
Prettify<WithUpgradeExecutor<WithAccount<ActionParameters<{}, 'rollupAdminLogic', Curried>>>>;

export type BuildSetValidatorWhitelistDisabledReturnType =
PrepareTransactionRequestReturnTypeWithChainId;

export async function buildSetValidatorWhitelistDisabled<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
{
account,
upgradeExecutor,
params,
...args
}: BuildSetValidatorWhitelistDisabledParameters & { params: { enable: boolean } },
): Promise<BuildSetValidatorWhitelistDisabledReturnType> {
const validatedPublicClient = validateParentChainPublicClient(client);
const rollupAdminLogicAddress =
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic;

const request = await client.prepareTransactionRequest({
chain: client.chain as Chain | undefined,
account,
...prepareUpgradeExecutorCallParameters({
to: rollupAdminLogicAddress,
upgradeExecutor,
args: [params.enable],
abi: rollupABI,
functionName: 'setValidatorWhitelistDisabled',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: validatedPublicClient.chain.id };
}

export async function buildEnableValidatorWhitelist<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
args: BuildSetValidatorWhitelistDisabledParameters,
): Promise<BuildSetValidatorWhitelistDisabledReturnType> {
return buildSetValidatorWhitelistDisabled(client, {
...args,
params: {
enable: true,
},
});
}

export async function buildDisableValidatorWhitelist<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
args: BuildSetValidatorWhitelistDisabledParameters,
): Promise<BuildSetValidatorWhitelistDisabledReturnType> {
return buildSetValidatorWhitelistDisabled(client, {
...args,
params: {
enable: false,
},
});
}
51 changes: 51 additions & 0 deletions src/actions/buildSetWasmModuleRoot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Chain, Hex, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { rollupABI } from '../contracts/Rollup';
import {
WithAccount,
ActionParameters,
WithUpgradeExecutor,
PrepareTransactionRequestReturnTypeWithChainId,
} from '../types/Actions';
import { Prettify } from '../types/utils';
import { getRollupAddress } from '../getRollupAddress';
import { validateParentChainPublicClient } from '../types/ParentChain';
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters';

export type BuildSetWasmModuleRootParameters<Curried extends boolean = false> = Prettify<
WithUpgradeExecutor<
WithAccount<
ActionParameters<
{
newWasmModuleRoot: Hex;
},
'rollupAdminLogic',
Curried
>
>
>
>;

export type BuildSetWasmModuleRootReturnType = PrepareTransactionRequestReturnTypeWithChainId;

export async function buildSetWasmModuleRoot<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
{ account, upgradeExecutor, params, ...args }: BuildSetWasmModuleRootParameters,
): Promise<BuildSetWasmModuleRootReturnType> {
const validatedPublicClient = validateParentChainPublicClient(client);
const rollupAdminLogicAddress =
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic;

const request = await client.prepareTransactionRequest({
chain: client.chain as Chain | undefined,
account,
...prepareUpgradeExecutorCallParameters({
to: rollupAdminLogicAddress,
upgradeExecutor,
args: [params.newWasmModuleRoot],
abi: rollupABI,
functionName: 'setWasmModuleRoot',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: validatedPublicClient.chain.id };
}
29 changes: 29 additions & 0 deletions src/actions/getConfirmPeriodBlocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem';
import { rollupABI } from '../contracts/Rollup';
import { WithContractAddress } from '../types/Actions';
import { getRollupAddress } from '../getRollupAddress';

export type GetConfirmPeriodBlocksParameters<Curried extends boolean = false> = WithContractAddress<
{},
'rollupAdminLogic',
Curried
>;

export type GetConfirmPeriodBlocksReturnType = ReadContractReturnType<
typeof rollupABI,
'confirmPeriodBlocks'
>;

export async function getConfirmPeriodBlocks<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
args: GetConfirmPeriodBlocksParameters,
): Promise<GetConfirmPeriodBlocksReturnType> {
const rollupAdminLogicAddress =
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic;

return client.readContract({
abi: rollupABI,
functionName: 'confirmPeriodBlocks',
address: rollupAdminLogicAddress,
});
}
25 changes: 25 additions & 0 deletions src/actions/getExtraChallengeTimeBlocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem';
import { rollupABI } from '../contracts/Rollup';
import { WithContractAddress } from '../types/Actions';
import { getRollupAddress } from '../getRollupAddress';

export type GetExtraChallengeTimeBlocksParameters<Curried extends boolean = false> =
WithContractAddress<{}, 'rollupAdminLogic', Curried>;

export type GetExtraChallengeTimeBlocksReturnType = ReadContractReturnType<
typeof rollupABI,
'extraChallengeTimeBlocks'
>;

export async function getExtraChallengeTimeBlocks<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
args: GetExtraChallengeTimeBlocksParameters,
): Promise<GetExtraChallengeTimeBlocksReturnType> {
const rollupAdminLogicAddress =
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic;
return client.readContract({
abi: rollupABI,
functionName: 'extraChallengeTimeBlocks',
address: rollupAdminLogicAddress,
});
}
25 changes: 25 additions & 0 deletions src/actions/getMinimumAssertionPeriod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem';
import { rollupABI } from '../contracts/Rollup';
import { WithContractAddress } from '../types/Actions';
import { getRollupAddress } from '../getRollupAddress';

export type GetMinimumAssertionPeriodParameters<Curried extends boolean = false> =
WithContractAddress<{}, 'rollupAdminLogic', Curried>;

export type GetMinimumAssertionPeriodReturnType = ReadContractReturnType<
typeof rollupABI,
'minimumAssertionPeriod'
>;

export async function getMinimumAssertionPeriod<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
args: GetMinimumAssertionPeriodParameters,
): Promise<GetMinimumAssertionPeriodReturnType> {
const rollupAdminLogicAddress =
'sequencerInbox' in args ? await getRollupAddress(client, args) : args.rollupAdminLogic;
return client.readContract({
abi: rollupABI,
functionName: 'minimumAssertionPeriod',
address: rollupAdminLogicAddress,
});
}
Loading