https://github.com/chronicleprotocol/infestor
https://github.com/chronicleprotocol/infestor
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/chronicleprotocol/infestor
- Owner: chronicleprotocol
- License: agpl-3.0
- Created: 2021-12-17T09:50:07.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-09-14T11:59:39.000Z (almost 3 years ago)
- Last Synced: 2024-04-14T15:04:06.429Z (about 2 years ago)
- Language: Go
- Size: 140 KB
- Stars: 0
- Watchers: 8
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/chronicleprotocol/infestor/actions/workflows/lint_test.yml)
# Infestor
Library for writing integration tests based for different exchanges.
It offers a simple way to mock exchange API responses and test your code.

## Example:
```go
package example
import (
"os/exec"
"strings"
"testing"
"github.com/chronicleprotocol/infestor/origin"
"github.com/chronicleprotocol/infestor"
"github.com/chronicleprotocol/infestor/smocker"
"github.com/stretchr/testify/require"
)
func callSetzer(params ...string) (string, error) {
out, err := exec.Command("setzer", params...).Output()
if err != nil {
return "", err
}
return strings.TrimSpace(string(out)), nil
}
func TestETHBTC(t *testing.T) {
api := smocker.API{
Host: "http://172.17.0.2",
Port: 8081,
}
err := infestor.NewMocksBuilder().
Reset().
Add(origin.NewExchange("binance").WithSymbol("ETH/BTC").WithPrice(1)).
Add(origin.NewExchange("bitfinex").WithSymbol("ETH/BTC").WithPrice(1)).
Add(origin.NewExchange("coinbase").WithSymbol("ETH/BTC").WithPrice(1)).
Add(origin.NewExchange("huobi").WithSymbol("ETH/BTC").WithPrice(1)).
Add(origin.NewExchange("poloniex").WithSymbol("ETH/BTC").WithPrice(1)).
Add(origin.NewExchange("kraken").WithSymbol("XETH/XXBT").WithPrice(1)).
Deploy(api)
// Build your test further
require.NoError(t, err)
out, err := callSetzer("price", "ethbtc")
require.NoError(t, err)
require.Equal(t, "0.5000000000", out)
}
// Run your tests with base URL `http://localhost:8080` for your exchanges
// Example for binance: `http://localhost:8080/api/v3/ticker/price?symbol=ETHBTC`
// it will reply with:
// {
// "symbol": "ETHBTC",
// "price": "1"
// }
```