Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
tests: run rpc tests on a single node
Browse files Browse the repository at this point in the history
  • Loading branch information
tdelabro committed Oct 5, 2023
1 parent 6207f1c commit 239352b
Show file tree
Hide file tree
Showing 34 changed files with 991 additions and 1,171 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,24 @@ jobs:
uses: ./.github/workflows/linters-cargo.yml
needs: rust_build

tests:
name: Run tests
uses: ./.github/workflows/tests.yml
needs: rust_build

tests:
name: Run rpc tests
uses: ./.github/workflows/starknet-rpc-test.yml
needs: rust_build

# TODO: Unlock when rust tests are working on main
# coverage:
# name: Run coverage
# uses: ./.github/workflows/coverage.yml
# needs: [madara_commands, linters_cargo]

# https://github.com/keep-starknet-strange/madara/issues/1097

# benchmark:
# name: Run benchmarks
# uses: ./.github/workflows/benchmarks.yml
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/starknet-rpc-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: Task - Rpc Tests

on:
workflow_dispatch:
workflow_call:

jobs:
rpc-tests:
runs-on: ubuntu-latest
env:
BINARY_PATH: ../target/release/madara
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key:
${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}-${{
github.run_id }}
fail-on-cache-miss: true
- name: Setup build deps
run: |
sudo apt-get update
sudo apt-get install -y clang llvm libudev-dev protobuf-compiler
- name: Run rpc test
run: |-
./target/release/madara setup
./target/release/madara run --dev --alice --sealing=manual --execution=Native --tmp &
sleep 10
cd starknet-rpc-test
cargo test
28 changes: 28 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Task - Integration Tests

on:
workflow_dispatch:
workflow_call:

jobs:
integration-tests:
runs-on: ubuntu-latest
env:
BINARY_PATH: ../target/release/madara
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key:
${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}-${{
github.run_id }}
fail-on-cache-miss: true
- name: Run crates test
run: cargo test
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- test(starknet-rpx-test): run all tests against a single madara node
- dev: fix rpc test failing
- feat: use actual vm resource costs
- fix: add setup and run for rpc tests
Expand Down
44 changes: 37 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@ members = [
"crates/client/transaction-pool",
"starknet-rpc-test",
]
# All previous except for `starknet-rpc-test`
# We don't want `cargo test` to trigger its tests
default-members = [
"crates/node",
"crates/runtime",
"crates/pallets/starknet",
"crates/primitives/digest-log",
"crates/primitives/transactions",
"crates/primitives/felt",
"crates/primitives/hashers",
"crates/primitives/fee",
"crates/primitives/state",
"crates/primitives/block",
"crates/primitives/sequencer-address",
"crates/primitives/storage",
"crates/primitives/commitments",
"crates/primitives/chain-id",
"crates/client/block-proposer",
"crates/client/db",
"crates/client/rpc-core",
"crates/client/rpc",
"crates/client/mapping-sync",
"crates/client/storage",
"crates/client/transaction-pool",
]

[profile.release]
panic = "unwind"
Expand Down
2 changes: 1 addition & 1 deletion crates/client/rpc-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub trait StarknetRpcApi {

/// Get the details of a transaction by a given block id and index
#[method(name = "getTransactionByBlockIdAndIndex")]
fn get_transaction_by_block_id_and_index(&self, block_id: BlockId, index: usize) -> RpcResult<Transaction>;
fn get_transaction_by_block_id_and_index(&self, block_id: BlockId, index: u64) -> RpcResult<Transaction>;

/// Get the information about the result of executing the requested block
#[method(name = "getStateUpdate")]
Expand Down
6 changes: 3 additions & 3 deletions crates/client/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ where

Ok(to_rpc_contract_class(contract_class).map_err(|e| {
error!("Failed to convert contract class at '{contract_address}' to RPC contract class: {e}");
StarknetRpcApiError::ContractNotFound
StarknetRpcApiError::InvalidContractClass
})?)
}

Expand Down Expand Up @@ -623,15 +623,15 @@ where
}

// Returns the details of a transaction by a given block id and index
fn get_transaction_by_block_id_and_index(&self, block_id: BlockId, index: usize) -> RpcResult<Transaction> {
fn get_transaction_by_block_id_and_index(&self, block_id: BlockId, index: u64) -> RpcResult<Transaction> {
let substrate_block_hash = self.substrate_block_hash_from_starknet_block(block_id).map_err(|e| {
error!("'{e}'");
StarknetRpcApiError::BlockNotFound
})?;

let block = get_block_by_block_hash(self.client.as_ref(), substrate_block_hash).unwrap_or_default();

let transaction = block.transactions().get(index).ok_or(StarknetRpcApiError::InvalidTxnIndex)?;
let transaction = block.transactions().get(index as usize).ok_or(StarknetRpcApiError::InvalidTxnIndex)?;
let chain_id = self.chain_id()?;

Ok(to_starknet_core_tx::<H>(transaction.clone(), Felt252Wrapper(chain_id.0)))
Expand Down
5 changes: 4 additions & 1 deletion crates/pallets/starknet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,10 @@ pub mod pallet {
false,
),
}
.map_err(|_| InvalidTransaction::BadProof)?;
.map_err(|e| {
log::error!("failed to validate tx: {}", e);
InvalidTransaction::BadProof
})?;
}

let nonce_for_priority: u64 =
Expand Down
3 changes: 1 addition & 2 deletions starknet-rpc-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ edition = "2021"

anyhow = "1.0.72"
assert_matches = "1.5.0"
derive_more = "0.99.17"
async-lock = { git = "https://github.com/smol-rs/async-lock", branch = "master" }
flate2 = { workspace = true }
lazy_static = "1.4.0"
reqwest = "0.11.18"
rstest = "0.18.1"
serde = { version = "1.0.179", features = ["derive"] }
Expand Down
Loading

0 comments on commit 239352b

Please sign in to comment.