Home

Awesome

substrate-tip-bot

GitHub Issue Sync

A GitHub App built with Probot that can submit tips on behalf of a Substrate based network.

Getting started 🌱

Usage

This bot relies on GitHub pull request that opt in via a body text comment (or text in profile bio) to specify what Substrate network and address to send tips to.

Permission to send out tips is limited for a GitHub team, that's configured with APPROVERS_GH_ORG + APPROVERS_GH_TEAM environment variables. For production, it's @paritytech/tip-bot-approvers

Pull request body

{kusama|polkadot|rococo|westend} address: <SS58 Address>

Followed by a comment on said pull request

Pull request comment

/tip {small | medium | large | <custom value>}

In OpenGov, the tip sizes are translated to specific values as follows:

SizeValue on KusamaValue on Polkadot
small4 KSM20 DOT
medium16 KSM80 DOT
large30 KSM150 DOT

Local development 🔧

To use this bot, you'll need to have an .env file. Most of the options will automatically be generated by the GitHub application creation process, but you will also need to add ACCOUNT_SEED, APPROVERS_GH_ORG and APPROVERS_GH_TEAM.

A reference env file is placed at .env.example to copy over

$ cp .env.example .env

Run network locally

Create GitHub application for testing

Integration tests

There are integration tests that execute the tip functions against a locally running Polkadot and Kusama nodes.

The tests will spin up the local nodes automatically.

To run the tests:

Build the application image:

yarn build:docker

Then run the tests:

yarn test:integration

Github app permissions

Repository permissions:
Organization permissions
Event subscriptions

Start a bot

After registering and configuring the bot environment, we can run it.

$ yarn start

Create a PR and test it

You'll need 2 gh users: contributor and maintainer (since it's not allowed for contributors to send a tip to themselves)

Docker

To run the bot via Docker, we need to build and then run it like so

$ docker build -t substrate-tip-bot .
$ docker run \
    -e APP_ID=<app-id> \
    -e PRIVATE_KEY=<pem-value> \
    substrate-tip-bot

End-to-end tests

For the E2E tests, we need a modified Rococo node in a way that speeds up the referenda and treasury.

Preparing and running Rococo

git clone https://github.com/paritytech/polkadot-sdk.git
cd polkadot-sdk
git checkout polkadot-v1.15.0
git apply ../polkadot.e2e.patch
cargo build --release --locked --features=fast-runtime -p polkadot
./target/release/polkadot --rpc-external --no-prometheus --no-telemetry --chain=rococo-dev --tmp --alice --execution Native --unsafe-force-node-key-generation --rpc-port 9902

You might need to fund the treasury (13UVJyLnbVp9RBZYFwFGyDvVd1y27Tt8tkntv6Q7JVPhFsTB) if it is broke.

Patch

The polkadot-sdk code is patched (see the line doing git apply) - that's why we have to build the code from source, instead of using a released binary or docker image.

The patch involves changing the timelines around OpenGov mechanics, so that we can test the whole flow in a reasonable amount of time.

Running the E2E tests

yarn test:e2e

Go make a cup of tea, the tests take ~3 minutes (waiting for the various on-chain stages to pass).

On CI, the E2E tests are running:

The tests are running in a container specified by E2E_TESTS_CONTAINER repository variable.

The container version should be kept in sync with the container used in polkadot-sdk CI.

Contributing

If you have suggestions for how substrate-tip-bot could be improved, or want to report a bug, open an issue! We'd love all and any contributions.

For more, check out the Contributing Guide.

License

MIT © 2021 Parity Technologies admin@parity.io