Skip to content

Commit

Permalink
test(JSON-RPC): integration test with the starknet GW
Browse files Browse the repository at this point in the history
Move test from starknet_client to papyrus_rpc crate to avoid circular dependencies.
  • Loading branch information
TzahiTaub committed Oct 14, 2023
1 parent 8faccea commit 9c1d50f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/nightly-tests-call.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ on:
os:
required: true
type: string
secrets:
INTEGRATION_TESTNET_NODE_URL:
required: true
type: string
INTEGRATION_TESTNET_SENDER_PRIVATE_KEY:
required: true
type: string

jobs:
GW-integration-test-call:
Expand All @@ -24,7 +31,7 @@ jobs:
sudo apt update; sudo apt -y install libclang-dev;
INTEGRATION_TESTNET_NODE_URL=${{ secrets.INTEGRATION_TESTNET_NODE_URL }}
SENDER_PRIVATE_KEY=${{ secrets.INTEGRATION_TESTNET_SENDER_PRIVATE_KEY }}
cargo test --test gateway_integration_test -p starknet_client test_gw_integration_testnet
cargo test --test gateway_integration_test -p papyrus_rpc test_gw_integration_testnet
-- --ignored || retVal=$?;
if [ $retVal -ne 0 ]; then
echo "Integration test failed with exit code $retVal";
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/nightly-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@ on:
- cron: '30 0 * * *' # Uses ubuntu runner.
- cron: '30 3 * * *' # Uses macos runner.
workflow_dispatch: # Uses ubuntu runner.
push:
branches:
- tzahi/gw_integration_test_basic

jobs:
GW-integration-test-ubuntu:
uses: ./.github/workflows/nightly-tests-call.yml
with:
os: ubuntu-latest
secrets:
INTEGRATION_TESTNET_NODE_URL: ${{ secrets.INTEGRATION_TESTNET_NODE_URL }}
INTEGRATION_TESTNET_SENDER_PRIVATE_KEY: ${{ secrets.INTEGRATION_TESTNET_SENDER_PRIVATE_KEY }}
if: github.event.schedule != '30 3 * * *'

GW-integration-test-macos:
uses: ./.github/workflows/nightly-tests-call.yml
with:
os: macos-latest
secrets:
INTEGRATION_TESTNET_NODE_URL: ${{ secrets.INTEGRATION_TESTNET_NODE_URL }}
INTEGRATION_TESTNET_SENDER_PRIVATE_KEY: ${{ secrets.INTEGRATION_TESTNET_SENDER_PRIVATE_KEY }}
if: github.event.schedule == '30 3 * * *'


4 changes: 1 addition & 3 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/papyrus_rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ reqwest.workspace = true
test_utils = { path = "../test_utils" }
starknet_api = { workspace = true, features = ["testing"] }
starknet_client = { path = "../starknet_client", features = ["testing"] }
starknet-core.workspace = true
strum.workspace = true
strum_macros.workspace = true
indexmap = { workspace = true, features = ["serde"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ use jsonrpsee::core::client::ClientT;
use jsonrpsee::http_client::{HttpClient, HttpClientBuilder};
use jsonrpsee::rpc_params;
use papyrus_common::transaction_hash::get_transaction_hash;
use papyrus_rpc::{
AddInvokeOkResult,
InvokeTransaction as SNRpcInvokeTransaction,
InvokeTransactionV1 as SNRpcInvokeTransactionV1,
};
use papyrus_rpc::{AddInvokeOkResult, InvokeTransaction, InvokeTransactionV1};
use starknet_api::core::{ChainId, ContractAddress, EntryPointSelector, Nonce, PatriciaKey};
use starknet_api::hash::{StarkFelt, StarkHash};
use starknet_api::transaction::{
Expand All @@ -19,7 +15,7 @@ use starknet_api::transaction::{
TransactionVersion,
};
use starknet_api::{calldata, contract_address, patricia_key, stark_felt};
use starknet_client::writer::objects::transaction::InvokeTransaction;
use starknet_client::writer::objects::transaction::InvokeTransaction as SNClientInvokeTransaction;
use starknet_core::crypto::ecdsa_sign;
use starknet_core::types::FieldElement;

Expand Down Expand Up @@ -79,7 +75,7 @@ async fn test_gw_integration_testnet() {
let receiver_address = contract_address!(USER_B_ADDRESS);

// Create an invoke transaction for Eth transfer with a signature placeholder.
let mut invoke_tx = SNRpcInvokeTransactionV1 {
let mut invoke_tx = InvokeTransactionV1 {
max_fee: Fee(MAX_FEE),
signature: TransactionSignature::default(),
nonce,
Expand All @@ -104,7 +100,7 @@ async fn test_gw_integration_testnet() {

// Update the signature.
let hash = get_transaction_hash(
&Transaction::Invoke(SNRpcInvokeTransaction::Version1(invoke_tx.clone()).into()),
&Transaction::Invoke(InvokeTransaction::Version1(invoke_tx.clone()).into()),
&ChainId("SN_GOERLI".to_string()),
)
.unwrap();
Expand All @@ -121,7 +117,7 @@ async fn test_gw_integration_testnet() {
let invoke_res = client
.request::<AddInvokeOkResult, _>(
"starknet_addInvokeTransaction",
rpc_params!(InvokeTransaction::from(invoke_tx)),
rpc_params!(SNClientInvokeTransaction::from(invoke_tx)),
)
.await
.unwrap();
Expand Down
4 changes: 0 additions & 4 deletions crates/starknet_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,10 @@ url.workspace = true
assert.workspace = true
assert_matches.workspace = true
enum-iterator.workspace = true
jsonrpsee = { workspace = true, features = ["full"] }
mockall.workspace = true
mockito.workspace = true
rand.workspace = true
rand_chacha.workspace = true
papyrus_common = { path = "../papyrus_common"}
papyrus_rpc = { path = "../papyrus_rpc"}
pretty_assertions.workspace = true
starknet_api = { workspace = true, features = ["testing"] }
starknet-core.workspace = true
test_utils = { path = "../test_utils" }

0 comments on commit 9c1d50f

Please sign in to comment.