Ignore messages during message processing in TipProver (#281)
parent
fae4152221
commit
a9b509e973
@ -0,0 +1,18 @@ |
||||
// SPDX-License-Identifier: MIT OR Apache-2.0 |
||||
pragma solidity >=0.6.11; |
||||
|
||||
import {IMessageRecipient} from "../../../interfaces/IMessageRecipient.sol"; |
||||
|
||||
contract BadRandomRecipient is IMessageRecipient { |
||||
event Handled(bytes32 blockHash); |
||||
|
||||
function handle( |
||||
uint32, |
||||
bytes32, |
||||
bytes memory |
||||
) external override { |
||||
bool isBlockHashEven = uint256(blockhash(block.number - 1)) % 2 == 0; |
||||
require(isBlockHashEven, "block hash is odd"); |
||||
emit Handled(blockhash(block.number - 1)); |
||||
} |
||||
} |
@ -0,0 +1,41 @@ |
||||
import { ethers } from 'hardhat'; |
||||
|
||||
import { BadRandomRecipient__factory } from '../types'; |
||||
import { utils } from '@abacus-network/utils'; |
||||
import { expect } from 'chai'; |
||||
|
||||
describe('BadRecipient', () => { |
||||
describe('RandomBadRecipient', () => { |
||||
it('randomly handles a message', async () => { |
||||
const [signer] = await ethers.getSigners(); |
||||
const signerAddress = await signer.getAddress(); |
||||
const recipientFactory = new BadRandomRecipient__factory(signer); |
||||
const recipient = await recipientFactory.deploy(); |
||||
|
||||
// Didn't know how else to test the randomness
|
||||
let successes = 0; |
||||
let failures = 0; |
||||
for (let i = 0; i < 10; i++) { |
||||
try { |
||||
// "Inject randomness"
|
||||
await signer.sendTransaction({ |
||||
from: signerAddress, |
||||
to: signerAddress, |
||||
value: 1, |
||||
}); |
||||
await recipient.handle( |
||||
0, |
||||
utils.addressToBytes32(recipient.address), |
||||
'0x1234', |
||||
); |
||||
successes += 1; |
||||
} catch (error) { |
||||
failures += 1; |
||||
} |
||||
} |
||||
|
||||
expect(successes).to.be.greaterThan(1); |
||||
expect(failures).to.be.greaterThan(1); |
||||
}); |
||||
}); |
||||
}); |
Loading…
Reference in new issue