Skip to content

Commit

Permalink
feat: Update snapshot-tool readme | NPG-000 (#696)
Browse files Browse the repository at this point in the history
# Description

Updating a stale `snapshot-tool` Readme.
Providing a guides how to build and run `snapshot-tool` itself and
referencing to the `cardano-db-sync` docs for spin upping local instance
of the database.
  • Loading branch information
Mr-Leshiy committed May 3, 2024
1 parent b05c57d commit 317d2d4
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions src/voting-tools-rs/README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,29 @@
# Voting Tools (Rust)

This tool generates voting power info from a db-sync instance.
This tool generates voting power info from a `cardano-db-sync` instance.

Example usage:

```
```sh
snapshot-tool --db postgres --db-user postgres --db-host localhost --out-file output.json
```

## Building

Building with nix should be straightforward, simply enter a dev environment with `nix develop`, then run `cargo build` to build.

## Testing

To run tests, run `cargo test`. Note, these tests include database tests, which require a running postgres instance to connect to. If you want to run only non-database tests, run `cargo test --no-default-features`
To get a full list of available arguments run:

### Database tests
```sh
snapshot-tool --help
```

Database tests perform predefined queries against a test database. If the results don't match the snapshots, the test fails. This requires having the correct data in your database. The current test data can be found [here](https://updates-cardano-testnet.s3.amazonaws.com/cardano-db-sync/index.html#13/).
## Building

There are also "reference database tests", which populate a mock database with fake data, run queries against them, and check the results. These do not require the preset test data, as the correct data is created in the test.
Building with nix should be straightforward, simply enter a dev environment with `nix develop`, then run `cargo build -p voting_tools_rs` to build.

Once you have this database set up, create a file at `<project_root>/test_db.json`, which contains credentials to connect to this database, for example:
## Testing

```json
{
"host": "localhost",
"name": "database_name",
"user": "username",
"password": "password"
}
```
To run tests, run `cargo test -p voting_tools_rs`.

(Note, password is optional).
## Spin up cardano-db-sync

From there, running `cargo test` will run database tests as well as regular tests. If tests pass, great!
To sucessufully run the `snapshot-tool` it is needed to have a running [`cardano-db-sync`](https://github.com/IntersectMBO/cardano-db-sync) instance.

If not, you need to review the changes. It's possible that you intended to change the result of a query. Use `cargo insta review` to go through all failed tests and mark them as "intended" or not.
[Here](https://github.com/IntersectMBO/cardano-db-sync/blob/master/doc/building-running.md) you can found a guide how to build and run `cardano-db-sync`.

0 comments on commit 317d2d4

Please sign in to comment.