###### tags: `tests` # Junior Solidity Test 2 ### Task 1 - Contract to save signed blockheaders The purpose of this contract is to enable a fixed set of trusted validators to submit blockhashes from another blockchain. 1. the contract will hold a mapping of blockhash -> BlockData 2. a mapping of blockhash -> SignedBlock 3. contract will be initialized with a list of validators addresses ``` BlockHeader { parent_hash: bytes32 timestamp: uint256, number: uint256, author: address, transactions_root: bytes32, uncles_hash: bytes32, extra_data: bytes, state_root: bytes32, receipts_root: bytes32, log_bloom: bytes, gas_used: uint256, gas_limit: uint256, difficulty: uint256, mixHash:bytes32, nonce:uint256 } BlockData { header: BlockHeader, rlpHeader: bytes, blockHash: bytes32, } SignedBlock { signatures:bytes[], hasValidatorSigned: mapping<address> -> bool, //to prevent double signatures } ``` 2. add method `addSignedBlock(blockchainid,blockheader,blockhash,signature) onlyValidator` - onlyValidator modifier check that msg sender is in approved list of validators - if blockhash doesnt exists yet, create the block rlpHeader from blockheader and verify hash(rlpHeader) = blockhash - verify signature is of the blockhash and by the msg.sender - verify msg.sender didnt already submit this block - update blockhash -> SignedBlock - update blockhash -> BlockData 3. write a unit test for the above method using hardhat/waffle ### Task 2 - “thegraph” Integration 1. write a subgraph that process Stake and StakeWithdraw events from these contracts - https://kovan.etherscan.io/address/0x97336539bF2ab85ED83e63f294af113A7A110Cd3#code https://github.com/GoodDollar/GoodProtocol/blob/master/contracts/staking/aave/GoodAaveStaking.sol - https://kovan.etherscan.io/address/0xbc371c5c98d40de18382e3e0eeb58805d76d3d50#code https://github.com/GoodDollar/GoodProtocol/blob/master/contracts/staking/compound/GoodCompoundStaking.sol 2. subgraph should have two entities. User and StakeAction ``` User(id:address) { actions: StakeActions[] } StakeAction(id: txhash) { action: stake|unstake value: number } ```