# Architecture & Tests

This is a hardhat and foundry project following [this](https://book.getfoundry.sh/config/hardhat) guide exactly. Foundry was needed for ease of use during interactions and testing. Hardhat JS functionality was needed for ease of use for testing the oracle.

The entire oracle is \~100 LOC. A randomness consumer can be as short as \~100 SLOC. The two helper libraries add up to less than 400 LOC.&#x20;

ChainLink VRF infrastructure spans many thousands of lines of code.

* `/oracle/oracle.js`: Contains the oracle that listens to `requestRandomness` events for a user. It RLP-encodes the header of the block from the event, verifies that the hash matches so that we know our packaged header is correct, and then ships the header back on chain through `sendEncodedHeader()` which sends a transaction to the Consumer contract's callback function `fulfillRandomWords()` just like Chainlink VRF.
* `/src/CoinFlip.sol`: The randomness consumer contract built by any protocol that allows users to request secure randomness.
* `/src/RandaoLib.sol`: Used to verify that a block header is correct for a particular block number (The recreated hash from the shipped header matches the actual block hash). And has a function to extract the randomness value (mixHash) from the verified block header.
* `/src/RLPDecoder.sol`: Helps `RandaoLib.sol` to properly decode, verify, and extract the randomness (mixHash/randao) from the shipped RLP-encoded block header.
* `/script/DeployCoinFlip.s.sol`: Deploy CoinFlip randomness consumer contract.
* `/test/RandomnessConsumerTest.t.js`: Incomplete hardhat test used for some sanity checks.
* `/test/RandomnessConsumerTest.t.sol`: Incomplete foundry test used for some sanity checks.
* `.env`: Project requires private key and WebSocket for Sepolia. HTTPS not used. See `.env.example`.

NOTE: If you alter the CoinFlip contract, to get the fresh ABI for the oracle, you may need to do `npx hardhat clean` and then recompile `npx hardhat compile`.

### Testing

* Hardhat: `npx hardhat test`
* foundry: `forge test`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://entropyoracle.gitbook.io/entropyoracle/architecture-and-tests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
