# Writing an Ante Test

Writing an Ante Test is easy to do! It's also a fantastic way to level up your Solidity skills as you read and think about the workings of the smart contracts that underlie your favorite DeFi protocols. To guide you through the process, we've listed out the basic steps below.

![Is this the face of a liar? I think not.](https://3623970277-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MaBhLPQtzmPqzNtEpO8%2F-MkKky2jRj19bZOmGaPG%2F-MkL0nzz2ucIiiqZWKHh%2Fanyone-can-write-ante-tests%201.png?alt=media\&token=9e123a98-0643-481e-8cd6-30b2e88653c9)

## 1. Think of the invariant you want to test

Ante Tests are single-failure tests of on-chain protocol **invariants**. Invariants should reflect fundamental guarantees that a protocol should satisfy. Some examples of invariants you could write an Ante Test for include:

* **Plunge protection test** – Contract assets do not drop below some threshold
* **Loan solvency test** – Collateral asset value exceeds issued liabilities by some factor
* **APY guarantee test** – APY over a given time period exceeds the rate advertised

For more ideas, check out a longer list below. The possibilities are endless!

{% content-ref url="writing-an-ante-test/invariant-ideas" %}
[invariant-ideas](https://docs.ante.finance/ante/v05/for-devs/writing-an-ante-test/invariant-ideas)
{% endcontent-ref %}

## 2. Fork the Ante community test repository

Forking the **antefinance/ante-community-tests** repository will allow you to work on your own local copy of the repository that includes all the necessary starter code and other community tests for reference.

On the [repository](https://github.com/antefinance/ante-community-tests) page, click **Fork** to create a copy of the repository under your GitHub profile.

![](https://3623970277-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MaBhLPQtzmPqzNtEpO8%2F-MkKky2jRj19bZOmGaPG%2F-MkL5mVUGqcAva8vIsrB%2FScreen%20Shot%202021-09-23%20at%209.40.30%20PM.png?alt=media\&token=6ed18fd4-0cb6-4bfc-bcff-491cf22cf7b0)

Once you've forked the repository, you can [clone the repository](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository) to your local machine.

## 3. Write your Ante Test

It's time to open up your favorite [IDE](https://ethereum.org/en/developers/docs/ides/)/text editor and start coding!

All Ante Tests need to implement the `IAnteTest.sol` interface to work with Ante. To make it easier to work with, we have implemented the **abstract class** `AnteTest.sol` that **any** Ante Test can inherit.

{% content-ref url="writing-an-ante-test/iantetest.sol-and-antetest.sol" %}
[iantetest.sol-and-antetest.sol](https://docs.ante.finance/ante/v05/for-devs/writing-an-ante-test/iantetest.sol-and-antetest.sol)
{% endcontent-ref %}

You can start by copying another Ante Test in the repository, or you can use the following skeleton code:

```typescript
import "@antefinance/contracts/interfaces/AnteTest.sol";

contract MyAnteTest is AnteTest("String descriptor of test") {
    // create Ante Test variables & insert logic here
    
    // you can omit your constructor if not defining these optional parameters
    constructor () {
        protocolName = "My Protocol";
        testedContracts = [0x000000000000000000000000000000000000dEaD];
    }
    
    function checkTestPasses() public view override returns (bool) {
        // insert logic here to check the My Protocol invariant
    }
}
```

## 4. Create a pull request to the Ante community test repository

If you're comfortable deploying your own smart contracts, you can [do it yourself](https://docs.ante.finance/ante/v05/for-devs/deploying-an-ante-test).

If you don't want to go through the hassle of deploying the test yourself, though, you can [open a pull request](https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork) to the ante community test repository:

1. Click **Pull request** on the repository page.
2. Select the base and head branches you want to merge
3. Add a quick description, and click **Create Pull Request**.

That's it! A member of the Ante team will review your test and add it to the main community repository.


---

# 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://docs.ante.finance/ante/v05/for-devs/writing-an-ante-test.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.
