Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce E2E tests for the faucet bot and server #198

Merged
merged 7 commits into from
Feb 15, 2023
Merged

Introduce E2E tests for the faucet bot and server #198

merged 7 commits into from
Feb 15, 2023

Conversation

rzadp
Copy link
Contributor

@rzadp rzadp commented Feb 14, 2023

First, we spin up:

  • A local Polkadot node in a dev mode
  • A local matrix server
    • Default configuration, except for increased rate limits
    • We create necessary users and gather them in a room
  • The faucet backend
    • It uses //Alice seed so it is funded
  • The faucet bot

Next, we test the behaviour by sending !balance and !drip messages.

@rzadp rzadp requested review from a team and fevo1971 as code owners February 14, 2023 10:32
Copy link
Contributor

@Bullrich Bullrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks to me.

But seriously, good pr. Lots of setups I see.

Should we also add tests about the bot interacting with invalid addresses?

.github/workflows/E2E.yml Outdated Show resolved Hide resolved
@rzadp
Copy link
Contributor Author

rzadp commented Feb 14, 2023

Should we also add tests about the bot interacting with invalid addresses?

Yes, I would be adding some more test cases in a separate PR.

Copy link
Contributor

@mutantcornholio mutantcornholio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit about reusing common code, still going through test setup configuration (upd: test setup configuration LGTM)

src/utils.ts Outdated
await sleep(step);
}
throw new Error(`waitUntil timed out after ${timeout} ms`);
};
Copy link
Contributor

@mutantcornholio mutantcornholio Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are already delay and and until functions in opstooling-js.

until from opstooling-js also has timeoutMessage parameter, which would be helpful in tests, to point at expectation that did not occur.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out - applied.

src/utils.ts Outdated
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type Predicate = () => any | (() => Promise<any>);

export const waitUntil = async (predicate: Predicate, step = 100, timeout = 10000) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the timeout here's the same as the governing timeout for the tests, meaning that this timeout condition will never fire, and instead we'll be getting timeouts from jest, without stacktrace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, timeouts adjusted.

@PierreBesson
Copy link
Contributor

IMO setting up docker containers using docker exec and wait-for in bash scripts can be flaky. I would recommend using a proper docker test framework such as https://github.com/testcontainers/testcontainers-node

@mutantcornholio
Copy link
Contributor

IMO setting up docker containers using docker exec and wait-for in bash scripts can be flaky. I would recommend using a proper docker test framework such as https://github.com/testcontainers/testcontainers-node

Good point actually. This advice could save me quite some time a month ago :)

@rzadp
Copy link
Contributor Author

rzadp commented Feb 14, 2023

IMO setting up docker containers using docker exec and wait-for in bash scripts can be flaky. I would recommend using a proper docker test framework such as https://github.com/testcontainers/testcontainers-node

I had no idea this existed, I will check it out.

@Bullrich
Copy link
Contributor

IMO setting up docker containers using docker exec and wait-for in bash scripts can be flaky. I would recommend using a proper docker test framework such as https://github.com/testcontainers/testcontainers-node

That looks super useful! Will keep it in mind

e2e/bootstrap.sh Outdated
# Start Polkadot and Matrix and wait until they are up.
docker-compose up -d
source wait_until.sh 'curl -s "localhost:8008"'
source wait_until.sh 'curl -s "localhost:9933"'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should technically be 127.0.0.1 instead of localhost

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, updated.

@rzadp rzadp merged commit 45752d3 into main Feb 15, 2023
@rzadp rzadp deleted the rzadp/e2e branch February 15, 2023 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants