Skip to content

Commit

Permalink
ci: add additional ci jobs for forks (foundry-rs#1728)
Browse files Browse the repository at this point in the history
* ci: add additional ci jobs for forks

* test: fix flaky anvil test

* ci: setup git config

* ci: setup git config

* ci: setup git config global

* chore: fix flaky snapshot test
  • Loading branch information
mattsse authored May 27, 2022
1 parent b8c0009 commit 76b00d0
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 42 deletions.
94 changes: 81 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ jobs:
unit:
name: unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true

- name: cargo test
run: cargo test --locked --workspace --all-features --lib --bins -- --skip fork

fork-unit:
name: fork unit tests
runs-on: ubuntu-latest
env:
ETH_RPC_URL: https://eth-mainnet.alchemyapi.io/v2/C3JEvfW6VgtqZQa-Qp1E-2srEiIc02sD
steps:
Expand All @@ -29,32 +49,38 @@ jobs:
uses: actions/cache@v3
with:
path: "$HOME/.foundry/cache"
key: rpc-cache-${{ hashFiles('cli/tests/it/integration.rs') }}
key: rpc-cache-${{ hashFiles('cli/tests/rpc-cache-keyfile') }}

- name: cargo test
run: cargo test --locked --workspace --all-features --lib --bins
run: cargo test --locked --workspace --all-features --lib --bins fork

doc:
name: doc tests
integration:
name: integration tests
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- uses: Swatinem/rust-cache@v1
- name: Rust cache
uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true

# required for forge commands that use git
- name: setup git config
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "<>"
- name: cargo test
run: cargo test --locked --workspace --all-features --doc
run: cargo test --locked --workspace -- --skip fork

integration:
name: integration tests
fork-integration:
name: fork integration tests
runs-on: ubuntu-latest
steps:
- name: Checkout sources
Expand All @@ -74,14 +100,37 @@ jobs:
uses: actions/cache@v3
with:
path: "$HOME/.foundry/cache"
key: rpc-cache-${{ hashFiles('cli/tests/it/integration.rs') }}
key: rpc-cache-${{ hashFiles('cli/tests/rpc-cache-keyfile') }}

- name: cargo test
run: cargo test --locked --workspace --test '*'
run: cargo test --locked --workspace -- fork

external-integration:
name: external integration tests
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true

- name: Force use of HTTPS for submodules
run: git config --global url."https://github.com/".insteadOf "[email protected]:"

- name: cargo test
run: cargo test --locked -p foundry-cli --features external-integration-tests -- --skip fork

external-fork-integration:
name: external fork integration tests
runs-on: ubuntu-latest
env:
ETH_RPC_URL: https://eth-mainnet.alchemyapi.io/v2/C3JEvfW6VgtqZQa-Qp1E-2srEiIc02sD
steps:
Expand All @@ -101,13 +150,32 @@ jobs:
uses: actions/cache@v3
with:
path: "$HOME/.foundry/cache"
key: rpc-cache-${{ hashFiles('cli/tests/it/integration.rs') }}
key: rpc-cache-${{ hashFiles('cli/tests/rpc-cache-keyfile') }}

- name: Force use of HTTPS for submodules
run: git config --global url."https://github.com/".insteadOf "[email protected]:"

- name: cargo test
run: cargo test --locked --workspace --features external-integration-tests --test '*'
run: cargo test --locked -p foundry-cli --features external-integration-tests fork_integration

doc:
name: doc tests
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true

- name: cargo test
run: cargo test --locked --workspace --all-features --doc

lint:
runs-on: ubuntu-latest
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ Types of tests include:

- **Unit tests**: Functions which have very specific tasks should be unit tested.
- **Integration tests**: For general purpose, far reaching functionality, integration tests should be added.
The best way to add a new integration test is to look at existing ones and follow the style.
The best way to add a new integration test is to look at existing ones and follow the style.

Tests that use forking must contain "fork" in their name.

#### Commits

Expand Down
11 changes: 9 additions & 2 deletions anvil/tests/it/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,15 @@ async fn call_past_state() {
assert_eq!(value, "initial value");

// make a call with `client`
let _tx_hash =
*contract.method::<_, H256>("setValue", "hi".to_owned()).unwrap().send().await.unwrap();
let _tx_hash = contract
.method::<_, H256>("setValue", "hi".to_owned())
.unwrap()
.send()
.await
.unwrap()
.await
.unwrap()
.unwrap();

// assert new value
let value = contract.method::<_, String>("getValue", ()).unwrap().call().await.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion cli/test-utils/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ pub trait OutputExt {
///
/// This should strip everything that can vary from run to run, like elapsed time, file paths
static IGNORE_IN_FIXTURES: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"(finished in (.*)?s|-->(.*).sol|Location(.*?)\.rs(.*)?Backtrace)").unwrap()
Regex::new(r"(finished in (.*)?s|-->(.*).sol|Location(.*?)\.rs(.*)?Backtrace|installing solc version(.*?)\n|Successfully installed solc(.*?)\n)").unwrap()
});

impl OutputExt for process::Output {
Expand Down
6 changes: 1 addition & 5 deletions cli/tests/fixtures/can_check_snapshot.stdout
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
Compiling 3 files with 0.8.10
Compiling 2 files with 0.8.10
Solc 0.8.10 finished in 424.55ms
Compiler run successful

Running 1 test for src/ATest.t.sol:ATest
[PASS] testExample() (gas: 168)
Test result: ok. 1 passed; 0 failed; finished in 4.42ms

Running 1 test for src/BTest.t.sol:BTest
[PASS] testExample() (gas: 168)
Test result: ok. 1 passed; 0 failed; finished in 4.42ms
15 changes: 0 additions & 15 deletions cli/tests/it/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,21 +534,6 @@ contract ATest is DSTest {
function testExample() public {
assertTrue(true);
}
}
"#,
)
.unwrap();
prj.inner()
.add_source(
"BTest.t.sol",
r#"
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.10;
import "./test.sol";
contract BTest is DSTest {
function testExample() public {
assertTrue(true);
}
}
"#,
)
Expand Down
14 changes: 9 additions & 5 deletions cli/tests/it/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ forgetest_external!(solmate, "Rari-Capital/solmate");
forgetest_external!(geb, "reflexer-labs/geb", &["--chain-id", "99"]);
forgetest_external!(stringutils, "Arachnid/solidity-stringutils");
// forgetest_external!(vaults, "Rari-Capital/vaults");
forgetest_external!(multicall, "makerdao/multicall", &["--block-number", "1"]);
forgetest_external!(lootloose, "gakonst/lootloose");
forgetest_external!(lil_web3, "m1guelpf/lil-web3");
forgetest_external!(maple_loan, "maple-labs/loan");

// Forking tests
forgetest_external!(drai, "mds1/drai", 13633752, &["--chain-id", "99"]);
forgetest_external!(gunilev, "hexonaut/guni-lev", 13633752);
forgetest_external!(convex, "mds1/convex-shutdown-simulation", 14445961);
/// Forking tests
mod fork_integration {
use foundry_cli_test_utils::forgetest_external;

forgetest_external!(multicall, "makerdao/multicall", &["--block-number", "1"]);
forgetest_external!(drai, "mds1/drai", 13633752, &["--chain-id", "99"]);
forgetest_external!(gunilev, "hexonaut/guni-lev", 13633752);
forgetest_external!(convex, "mds1/convex-shutdown-simulation", 14445961);
}
5 changes: 5 additions & 0 deletions cli/tests/rpc-cache-keyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This file serves as the key for the github actions/cache

Any change in this file will invalidate the cache in CI that stores RPC data.

Last updated: 05-26-2022

0 comments on commit 76b00d0

Please sign in to comment.