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

tests: run rpc tests on a single node #1145

Merged
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
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

rpc-tests:
name: Run rpc tests
uses: ./.github/workflows/starknet-rpc-tests.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
49 changes: 49 additions & 0 deletions .github/workflows/starknet-rpc-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
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: Setup dev chain
run: |
./target/release/madara setup --chain=dev --from-remote
- name: Run rpc native test
run: |-
./target/release/madara --dev --sealing=manual --execution=Native &
NATIVE_RUN_PID=$!
while ! echo exit | nc localhost 9944; do sleep 1; done
cd starknet-rpc-test
cargo test
kill $NATIVE_RUN_PID
- name: Run rpc wasm test
run: |-
./target/release/madara --dev --sealing=manual --execution=Wasm &
WASM_RUN_PID=$!
while ! echo exit | nc localhost 9944; do sleep 1; done
cd starknet-rpc-test
cargo test
kill $WASM_RUN_PID
32 changes: 32 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
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: Setup build deps
run: |
sudo apt-get update
sudo apt-get install -y clang llvm libudev-dev protobuf-compiler
- name: Run crates test
run: cargo test --release
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- refacto(pallet/starknet): `GenesisLoader` refactored as `GenesisData` + a
`base_path` field
- feat(cli): for `run` param `--dev` now imply `--tmp`, as it is in substrate
- test(starknet-rpx-test): run all tests against a single madara node

## v0.4.0

Expand Down
5 changes: 2 additions & 3 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
2 changes: 1 addition & 1 deletion crates/pallets/starknet/src/genesis_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ mod tests {
let serialized_loader = serde_json::to_string(&genesis_loader).unwrap();

// Then
let expected = r#"{"madara_path":null,"contract_classes":[["0x1",{"path":"cairo-contracts/ERC20.json","version":0}]],"contracts":[["0x2","0x1"]],"storage":[[["0x2","0x3"],"0x4"]],"fee_token_address":"0x5","seq_addr_updated":false}"#;
let expected = r#"{"contract_classes":[["0x1",{"path":"cairo-contracts/ERC20.json","version":0}]],"contracts":[["0x2","0x1"]],"storage":[[["0x2","0x3"],"0x4"]],"fee_token_address":"0x5","seq_addr_updated":false}"#;
assert_eq!(expected, serialized_loader);
}
}
5 changes: 4 additions & 1 deletion crates/pallets/starknet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,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
2 changes: 1 addition & 1 deletion crates/primitives/transactions/src/compute_hash_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn test_deploy_account_tx_hash() {
fn test_declare_v0_tx_hash() {
// Computed with `calculate_declare_transaction_hash` from the cairo lang package
let expected_tx_hash =
Felt252Wrapper::from_hex_be("0x07cdcb35e703351a74a0e6e8c045ce861eece44f0bca06dbbc569b4d8c0a2ae2").unwrap();
Felt252Wrapper::from_hex_be("0x052b849ca86ca1a1ce6ac7e069900a221b5741786bffe023804ef714f7bb46da").unwrap();

let chain_id = Felt252Wrapper(FieldElement::from_byte_slice_be(b"SN_GOERLI").unwrap());

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

anyhow = "1.0.72"
assert_matches = "1.5.0"
derive_more = "0.99.17"
async-lock = "2.8.0"
flate2 = { workspace = true }
lazy_static = "1.4.0"
reqwest = "0.11.22"
reqwest = "0.11.18"
rstest = "0.18.1"
serde = { version = "1.0.179", features = ["derive"] }
serde_json = "1.0.107"
Expand Down
Loading