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

feat(ci): per provider integration tests #465

Merged
merged 4 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions .github/workflows/sub-providers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: ❖ Providers

on:
workflow_dispatch:
inputs:
providers:
description: 'Providers list to test (space separated)'
required: false
default: 'coinbase binance'
stage-url:
description: 'RPC URL'
required: false
default: 'https://staging.rpc.walletconnect.org/'
workflow_call:
inputs:
providers_directory:
type: string
required: true
description: 'Directory where providers sources are located'
stage-url:
type: string
required: true
description: 'Stage RPC URL'
default: 'https://staging.rpc.walletconnect.org/'

concurrency: cd

permissions:
contents: write
checks: write
id-token: write

jobs:
providers-list:
name: "Preparing providers list"
runs-on: ubuntu-latest
outputs:
providers: ${{ steps.set-matrix.outputs.providers }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Creating list of changed providers
id: set-matrix
run: |
if [[ -n "${{ github.event.inputs.providers }}" ]]; then
PROVIDERS_LIST="${{ github.event.inputs.providers }}"
else
PROVIDERS_DIR="${{ inputs.providers_directory }}"
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
PROVIDERS_LIST=""

for file in $CHANGED_FILES; do
if [[ $file == $PROVIDERS_DIR* ]]; then
PROVIDER_TEST_NAME=$(echo $file | sed "s|^$PROVIDERS_DIR||" | sed 's|/|::|g' | sed 's|\.rs$||')
PROVIDERS_LIST+="$PROVIDER_TEST_NAME "
fi
done

PROVIDERS_LIST="${PROVIDERS_LIST% }"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing whitespace at the end.

fi

JSON_FMT=$(printf '[%s]' "$(echo $PROVIDERS_LIST | awk '{for(i=1;i<=NF;i++) printf "\"%s\",", $i}' | sed 's/,$//')")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Making JSON array from a space separated list.

Copy link
Member

Choose a reason for hiding this comment

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

Have you considered jq?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's not installed by default, so it's not worth to install it for one line.

echo "providers=$JSON_FMT" >> $GITHUB_OUTPUT
- name: Print list of changed providers
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I leave this step for debugging purposes.

run: |
echo "Providers matrix: ${{ steps.set-matrix.outputs.providers }}"

providers-test:
name: "Run provider tests"
needs: providers-list
runs-on: ubuntu-latest
if: needs.providers-list.outputs.providers != '[]'
strategy:
fail-fast: false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we don't need to fail all providers in case of one for cases like: we are manually validating a list of providers and want to know if there is a global issue or just one provider fails.

matrix:
provider: ${{fromJson(needs.providers-list.outputs.providers)}}
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: "Install Rust ${{ vars.RUST_VERSION }}"
uses: WalletConnect/actions-rs/[email protected]
with:
toolchain: ${{ vars.RUST_VERSION }}
profile: 'default'
override: true

- name: Run Tests for ${{ matrix.provider }}
env:
PROJECT_ID: ${{ secrets.PROJECT_ID }}
RPC_URL: ${{ inputs.stage-url }}
run: |
cargo test ${{ matrix.provider }}_provider -- --ignored
18 changes: 18 additions & 0 deletions tests/functional/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Functional integration tests

The following functional integration tests are presented:

* Database tests
* Providers tests
* Providers functional tests should be `#[ignore]` by default, because they will run by
the CI workflow specifically when the providers code is changed in the `src/provider`
directory.
* Providers test names should be in the format `{provider_name}_provider` and
`{provider_name}_provider_*` aligning with the provider name file in the
`src/providers` directory.
* Example for the `coinbase` provider:
* Implementation source file: `src/provider/coinbase.rs`
Tests for the `coinbase` provider will run only if this file is changed.
* Tests implementation for the `coinbase` provider can be in any files but should be
`#[ignore]` by default and the test names must starts with the
`coinbase_provider`.
3 changes: 2 additions & 1 deletion tests/functional/http/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use {

#[test_context(ServerContext)]
#[tokio::test]
async fn eip155_8453_base(ctx: &mut ServerContext) {
#[ignore]
async fn base_provider_eip155_8453_and_84531(ctx: &mut ServerContext) {
// Base mainnet
check_if_rpc_is_responding_correctly_for_supported_chain(ctx, "eip155:8453", "0x2105").await;

Expand Down
3 changes: 2 additions & 1 deletion tests/functional/http/binance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use {

#[test_context(ServerContext)]
#[tokio::test]
async fn binance_provider(ctx: &mut ServerContext) {
#[ignore]
async fn binance_provider_eip155_56_and_97(ctx: &mut ServerContext) {
// Binance mainnet
check_if_rpc_is_responding_correctly_for_supported_chain(ctx, "eip155:56", "0x38").await;

Expand Down
3 changes: 2 additions & 1 deletion tests/functional/http/pokt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use {

#[test_context(ServerContext)]
#[tokio::test]
async fn pokt_provider(ctx: &mut ServerContext) {
#[ignore]
async fn pokt_provider_eip155_43114_and_56_and_100(ctx: &mut ServerContext) {
// Avax
check_if_rpc_is_responding_correctly_for_supported_chain(ctx, "eip155:43114", "0xa86a").await;

Expand Down
3 changes: 2 additions & 1 deletion tests/functional/http/zksync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use {

#[test_context(ServerContext)]
#[tokio::test]
async fn eip155_324_zksync_mainnet(ctx: &mut ServerContext) {
#[ignore]
async fn zksync_provider_eip155_324_and_280(ctx: &mut ServerContext) {
// ZkSync mainnet
check_if_rpc_is_responding_correctly_for_supported_chain(ctx, "eip155:324", "0x144").await;

Expand Down
3 changes: 2 additions & 1 deletion tests/functional/http/zora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use {

#[test_context(ServerContext)]
#[tokio::test]
async fn eip155_7777777_zora(ctx: &mut ServerContext) {
#[ignore]
async fn zora_provider_eip155_7777777_and_999(ctx: &mut ServerContext) {
// Zora mainnet
check_if_rpc_is_responding_correctly_for_supported_chain(ctx, "eip155:7777777", "0x76adf1")
.await;
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/websocket/infura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use {
#[test_context(ServerContext)]
#[tokio::test]
#[ignore]
async fn infura_websocket_provider(ctx: &mut ServerContext) {
async fn infura_provider_websocket(ctx: &mut ServerContext) {
// Ethereum mainnet
check_if_rpc_is_responding_correctly_for_supported_chain(ctx, "eip155:1", "0x1").await;

Expand Down
3 changes: 2 additions & 1 deletion tests/functional/websocket/zora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use {

#[test_context(ServerContext)]
#[tokio::test]
async fn zora_websocket_provider(ctx: &mut ServerContext) {
#[ignore]
async fn zora_provider_websocket(ctx: &mut ServerContext) {
// Zora mainnet
check_if_rpc_is_responding_correctly_for_supported_chain(ctx, "eip155:7777777", "0x76adf1")
.await;
Expand Down