Commit 23fecaeb authored by coolhill's avatar coolhill

test StateCommitmentchain

- within fraud proof window
- not batchheader timestamp equal zero
parent 7a7803d8
...@@ -181,6 +181,19 @@ describe('StateCommitmentChain', () => { ...@@ -181,6 +181,19 @@ describe('StateCommitmentChain', () => {
}) })
}) })
}) })
describe('when the proposer has not previously staked at the BondManager', () => {
before(() => {
Mock__BondManager.smocked.isCollateralized.will.return.with(false)
})
it('should revert', async () => {
await expect(
StateCommitmentChain.appendStateBatch(batch, 0)
).to.be.revertedWith(
'Proposer does not have enough collateral posted'
)
})
})
}) })
}) })
...@@ -194,6 +207,10 @@ describe('StateCommitmentChain', () => { ...@@ -194,6 +207,10 @@ describe('StateCommitmentChain', () => {
extraData: ethers.constants.HashZero, extraData: ethers.constants.HashZero,
} }
before(() => {
Mock__BondManager.smocked.isCollateralized.will.return.with(true)
})
beforeEach(async () => { beforeEach(async () => {
Mock__CanonicalTransactionChain.smocked.getTotalElements.will.return.with( Mock__CanonicalTransactionChain.smocked.getTotalElements.will.return.with(
batch.length batch.length
...@@ -253,6 +270,25 @@ describe('StateCommitmentChain', () => { ...@@ -253,6 +270,25 @@ describe('StateCommitmentChain', () => {
}) })
}) })
describe('when outside fraud proof window', () => {
beforeEach(async () => {
const FRAUD_PROOF_WINDOW =
await StateCommitmentChain.FRAUD_PROOF_WINDOW()
await increaseEthTime(
ethers.provider,
FRAUD_PROOF_WINDOW.toNumber() + 1
)
})
it('should revert', async () => {
await expect(
StateCommitmentChain.deleteStateBatch(batchHeader)
).to.be.revertedWith(
'State batches can only be deleted within the fraud proof window.'
)
})
})
describe('when the provided batch header is valid', () => { describe('when the provided batch header is valid', () => {
it('should remove the batch and all following batches', async () => { it('should remove the batch and all following batches', async () => {
await expect(StateCommitmentChain.deleteStateBatch(batchHeader)).to await expect(StateCommitmentChain.deleteStateBatch(batchHeader)).to
...@@ -263,6 +299,27 @@ describe('StateCommitmentChain', () => { ...@@ -263,6 +299,27 @@ describe('StateCommitmentChain', () => {
}) })
}) })
describe('insideFraudProofWindow', () => {
const batchHeader = {
batchIndex: 0,
batchRoot: NON_NULL_BYTES32,
batchSize: 1,
prevTotalElements: 0,
extraData: ethers.constants.HashZero,
}
it('should revert when timestamp is zero', async () => {
await expect(
StateCommitmentChain.insideFraudProofWindow({
...batchHeader,
extraData: ethers.utils.defaultAbiCoder.encode(
['uint256', 'address'],
[0, await sequencer.getAddress()]
),
})
).to.be.revertedWith('Batch header timestamp cannot be zero')
})
})
describe('getTotalElements', () => { describe('getTotalElements', () => {
describe('when no batch elements have been inserted', () => { describe('when no batch elements have been inserted', () => {
it('should return zero', async () => { it('should return zero', async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment