-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add integration test for arbGasInfo
- Loading branch information
1 parent
7804ca2
commit 2caf1c8
Showing
6 changed files
with
149 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,46 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { getNitroTestnodePrivateKeyAccounts } from '../testHelpers'; | ||
import { createPublicClient, http } from 'viem'; | ||
import { nitroTestnodeL3 } from '../chains'; | ||
import { getGasAccountingParams } from './getGasAccountingParams'; | ||
import { getMinimumGasPrice } from './getMinimumGasPrice'; | ||
import { getParentBaseFeeEstimate } from './getParentBaseFeeEstimate'; | ||
import { getParentRewardRate } from './getParentRewardRate'; | ||
import { getParentRewardRecipient } from './getParentRewardRecipient'; | ||
|
||
const client = createPublicClient({ | ||
chain: nitroTestnodeL3, | ||
transport: http(), | ||
}); | ||
|
||
const testnodeAccounts = getNitroTestnodePrivateKeyAccounts(); | ||
const l3RollupOwner = testnodeAccounts.l3RollupOwner; | ||
|
||
describe('ArbGasInfo Getters', () => { | ||
it('getGasAccountingParams successfully fetches gas accounting parameters', async () => { | ||
const result = await getGasAccountingParams(client); | ||
expect(result).toMatchInlineSnapshot(` | ||
{ | ||
"gasPoolMax": 32000000n, | ||
"maxTxGasLimit": 32000000n, | ||
"speedLimitPerSecond": 7000000n, | ||
} | ||
`); | ||
}); | ||
it('getMinimumGasPrice successfully fetches minimum gas price', async () => { | ||
const result = await getMinimumGasPrice(client); | ||
expect(result).toMatchInlineSnapshot(`100000000n`); | ||
}); | ||
it('getParentBaseFeeEstimate successfully fetches parent base fee estimate', async () => { | ||
const result = await getParentBaseFeeEstimate(client); | ||
expect(Number(result)).gte(0); | ||
}); | ||
it('getParentRewardRate successfully fetches parent reward rate', async () => { | ||
const result = await getParentRewardRate(client); | ||
expect(result).toMatchInlineSnapshot(`10n`); | ||
}); | ||
it('getParentRewardRecipient successfully fetches parent reward recipient', async () => { | ||
const result = await getParentRewardRecipient(client); | ||
expect(result).toEqual(l3RollupOwner.address); | ||
}); | ||
}); |
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,27 @@ | ||
import { Chain, PublicClient, Transport } from 'viem'; | ||
import { arbGasInfoABI, arbGasInfoAddress } from '../contracts/ArbGasInfo'; | ||
|
||
export type GetGasAccountingParamsParameters = void; | ||
|
||
export type GetGasAccountingParamsReturnType = { | ||
speedLimitPerSecond: bigint; | ||
gasPoolMax: bigint; | ||
maxTxGasLimit: bigint; | ||
}; | ||
|
||
export async function getGasAccountingParams<TChain extends Chain>( | ||
client: PublicClient<Transport, TChain>, | ||
): Promise<GetGasAccountingParamsReturnType> { | ||
// `gasPoolMax` is always zero, as the exponential pricing model has no such notion. | ||
// see https://github.com/OffchainLabs/nitro-contracts/blob/main/src/precompiles/ArbGasInfo.sol | ||
const [speedLimitPerSecond, gasPoolMax, maxTxGasLimit] = await client.readContract({ | ||
abi: arbGasInfoABI, | ||
functionName: 'getGasAccountingParams', | ||
address: arbGasInfoAddress, | ||
}); | ||
return { | ||
speedLimitPerSecond, | ||
gasPoolMax, | ||
maxTxGasLimit, | ||
}; | ||
} |
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,19 @@ | ||
import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem'; | ||
import { arbGasInfoABI, arbGasInfoAddress } from '../contracts/ArbGasInfo'; | ||
|
||
export type GetMinimumGasPriceParameters = void; | ||
|
||
export type GetMinimumGasPriceReturnType = ReadContractReturnType< | ||
typeof arbGasInfoABI, | ||
'getMinimumGasPrice' | ||
>; | ||
|
||
export async function getMinimumGasPrice<TChain extends Chain>( | ||
client: PublicClient<Transport, TChain>, | ||
): Promise<GetMinimumGasPriceReturnType> { | ||
return client.readContract({ | ||
abi: arbGasInfoABI, | ||
functionName: 'getMinimumGasPrice', | ||
address: arbGasInfoAddress, | ||
}); | ||
} |
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,19 @@ | ||
import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem'; | ||
import { arbGasInfoABI, arbGasInfoAddress } from '../contracts/ArbGasInfo'; | ||
|
||
export type GetParentBaseFeeEstimateParameters = void; | ||
|
||
export type GetParentBaseFeeEstimateReturnType = ReadContractReturnType< | ||
typeof arbGasInfoABI, | ||
'getL1BaseFeeEstimate' | ||
>; | ||
|
||
export async function getParentBaseFeeEstimate<TChain extends Chain>( | ||
client: PublicClient<Transport, TChain>, | ||
): Promise<GetParentBaseFeeEstimateReturnType> { | ||
return client.readContract({ | ||
abi: arbGasInfoABI, | ||
functionName: 'getL1BaseFeeEstimate', | ||
address: arbGasInfoAddress, | ||
}); | ||
} |
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,19 @@ | ||
import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem'; | ||
import { arbGasInfoABI, arbGasInfoAddress } from '../contracts/ArbGasInfo'; | ||
|
||
export type GetParentRewardRateParameters = void; | ||
|
||
export type GetParentRewardRateReturnType = ReadContractReturnType< | ||
typeof arbGasInfoABI, | ||
'getL1RewardRate' | ||
>; | ||
|
||
export async function getParentRewardRate<TChain extends Chain>( | ||
client: PublicClient<Transport, TChain>, | ||
): Promise<GetParentRewardRateReturnType> { | ||
return client.readContract({ | ||
abi: arbGasInfoABI, | ||
functionName: 'getL1RewardRate', | ||
address: arbGasInfoAddress, | ||
}); | ||
} |
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,19 @@ | ||
import { Chain, PublicClient, ReadContractReturnType, Transport } from 'viem'; | ||
import { arbGasInfoABI, arbGasInfoAddress } from '../contracts/ArbGasInfo'; | ||
|
||
export type GetParentRewardRecipientParameters = void; | ||
|
||
export type GetParentRewardRecipientReturnType = ReadContractReturnType< | ||
typeof arbGasInfoABI, | ||
'getL1RewardRecipient' | ||
>; | ||
|
||
export async function getParentRewardRecipient<TChain extends Chain>( | ||
client: PublicClient<Transport, TChain>, | ||
): Promise<GetParentRewardRecipientReturnType> { | ||
return client.readContract({ | ||
abi: arbGasInfoABI, | ||
functionName: 'getL1RewardRecipient', | ||
address: arbGasInfoAddress, | ||
}); | ||
} |