-
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 tests for edge cases in create rollup tx request
- Loading branch information
Showing
2 changed files
with
161 additions
and
2 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
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,146 @@ | ||
import { it, expect } from 'vitest'; | ||
import { createPublicClient, http, parseGwei, zeroAddress } from 'viem'; | ||
|
||
import { nitroTestnodeL2 } from './chains'; | ||
import { generateChainId } from './utils'; | ||
import { prepareChainConfig } from './prepareChainConfig'; | ||
import { createRollupPrepareConfig } from './createRollupPrepareConfig'; | ||
import { createRollupPrepareTransactionRequest } from './createRollupPrepareTransactionRequest'; | ||
|
||
import { getTestPrivateKeyAccount } from './testHelpers'; | ||
|
||
const deployer = getTestPrivateKeyAccount(); | ||
|
||
const publicClient = createPublicClient({ | ||
chain: nitroTestnodeL2, | ||
transport: http(), | ||
}); | ||
|
||
it(`fails to prepare transaction request if "batchPoster" is set to the zero address`, async () => { | ||
// generate a random chain id | ||
const chainId = generateChainId(); | ||
|
||
// create the chain config | ||
const chainConfig = prepareChainConfig({ | ||
chainId, | ||
arbitrum: { InitialChainOwner: deployer.address }, | ||
}); | ||
|
||
// prepare the transaction for deploying the core contracts | ||
await expect( | ||
async () => | ||
await createRollupPrepareTransactionRequest({ | ||
params: { | ||
config: createRollupPrepareConfig({ | ||
chainId: BigInt(chainId), | ||
owner: deployer.address, | ||
chainConfig, | ||
}), | ||
// set batch poster to the zero address | ||
batchPoster: zeroAddress, | ||
validators: [deployer.address], | ||
}, | ||
account: deployer.address, | ||
publicClient, | ||
}) | ||
).rejects.toThrowError( | ||
`Param "batchPoster" can't be set to the zero address.` | ||
); | ||
}); | ||
|
||
it(`fails to prepare transaction request if "validators" is set to an empty array`, async () => { | ||
// generate a random chain id | ||
const chainId = generateChainId(); | ||
|
||
// create the chain config | ||
const chainConfig = prepareChainConfig({ | ||
chainId, | ||
arbitrum: { InitialChainOwner: deployer.address }, | ||
}); | ||
|
||
// prepare the transaction for deploying the core contracts | ||
await expect( | ||
async () => | ||
await createRollupPrepareTransactionRequest({ | ||
params: { | ||
config: createRollupPrepareConfig({ | ||
chainId: BigInt(chainId), | ||
owner: deployer.address, | ||
chainConfig, | ||
}), | ||
batchPoster: deployer.address, | ||
// set validators to an empty array | ||
validators: [], | ||
}, | ||
account: deployer.address, | ||
publicClient, | ||
}) | ||
).rejects.toThrowError( | ||
`Param "validators" can't be empty or contain the zero address.` | ||
); | ||
}); | ||
|
||
it(`fails to prepare transaction request if "validators" includes the zero address`, async () => { | ||
// generate a random chain id | ||
const chainId = generateChainId(); | ||
|
||
// create the chain config | ||
const chainConfig = prepareChainConfig({ | ||
chainId, | ||
arbitrum: { InitialChainOwner: deployer.address }, | ||
}); | ||
|
||
// prepare the transaction for deploying the core contracts | ||
await expect( | ||
async () => | ||
await createRollupPrepareTransactionRequest({ | ||
params: { | ||
config: createRollupPrepareConfig({ | ||
chainId: BigInt(chainId), | ||
owner: deployer.address, | ||
chainConfig, | ||
}), | ||
batchPoster: deployer.address, | ||
// set validators to zero address | ||
validators: [zeroAddress], | ||
}, | ||
account: deployer.address, | ||
publicClient, | ||
}) | ||
).rejects.toThrowError( | ||
`Param "validators" can't be empty or contain the zero address.` | ||
); | ||
}); | ||
|
||
it(`fails to prepare transaction request if "nativeToken" is custom and chain is not anytrust`, async () => { | ||
// generate a random chain id | ||
const chainId = generateChainId(); | ||
|
||
// create the chain config | ||
const chainConfig = prepareChainConfig({ | ||
chainId, | ||
arbitrum: { InitialChainOwner: deployer.address }, | ||
}); | ||
|
||
// prepare the transaction for deploying the core contracts | ||
await expect( | ||
async () => | ||
await createRollupPrepareTransactionRequest({ | ||
params: { | ||
config: createRollupPrepareConfig({ | ||
chainId: BigInt(chainId), | ||
owner: deployer.address, | ||
chainConfig, | ||
}), | ||
batchPoster: deployer.address, | ||
validators: [deployer.address], | ||
// set native token to anything custom | ||
nativeToken: deployer.address, | ||
}, | ||
account: deployer.address, | ||
publicClient, | ||
}) | ||
).rejects.toThrowError( | ||
`Param "nativeToken" can only be used on AnyTrust chains. Set "arbitrum.DataAvailabilityCommittee" to "true" in the chain config.` | ||
); | ||
}); |