Skip to content

Commit

Permalink
Dump devnet_postmanLoad requests (#606)
Browse files Browse the repository at this point in the history
* Improve L1-L2 and dumping docs
  • Loading branch information
FabijanC authored Sep 19, 2024
1 parent 4d321a3 commit 7650137
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/starknet-devnet-server/src/api/json_rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ impl JsonRpcHandler {
"devnet_autoImpersonate",
"devnet_stopAutoImpersonate",
// "devnet_postmanFlush", - not dumped because it creates new RPC calls which get dumped
"devnet_postmanLoad",
"devnet_postmanSendMessageToL2",
"devnet_postmanConsumeMessageFromL2",
"devnet_createBlock",
Expand Down
30 changes: 30 additions & 0 deletions crates/starknet-devnet/tests/test_messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ mod test_messaging {

use ethers::prelude::*;
use serde_json::{json, Value};
use server::rpc_core::error::RpcError;
use server::test_utils::assert_contains;
use starknet_rs_accounts::{
Account, AccountError, ConnectedAccount, ExecutionEncoding, SingleOwnerAccount,
};
Expand Down Expand Up @@ -630,4 +632,32 @@ mod test_messaging {
let expected_nonces: Vec<_> = (0..init_balance).collect();
assert_eq!(flushed_message_nonces, expected_nonces);
}

#[tokio::test]
/// Here we test if the devnet_postmanLoad method call is indeed dumped and then used in a load.
async fn test_dumpability_of_messaging_contract_loading() {
let dump_file = UniqueAutoDeletableFile::new("dump");
let devnet_args = ["--dump-path", &dump_file.path, "--dump-on", "exit"];
let devnet = BackgroundDevnet::spawn_with_additional_args(&devnet_args).await.unwrap();
let anvil = BackgroundAnvil::spawn().await.unwrap();

devnet
.send_custom_rpc("devnet_postmanLoad", json!({ "network_url": anvil.url }))
.await
.unwrap();

// assert loadability while Anvil is still alive
devnet.send_custom_rpc("devnet_dump", Value::Null).await.unwrap();
devnet.send_custom_rpc("devnet_load", json!({ "path": dump_file.path })).await.unwrap();

// assert loading fails if anvil not alive
send_ctrl_c_signal_and_wait(&anvil.process).await;
match devnet.send_custom_rpc("devnet_load", json!({ "path": dump_file.path })).await {
Err(RpcError { message, .. }) => {
assert_contains(&message, "error sending request for url");
assert_contains(&message, &anvil.url);
}
other => panic!("Unexpected response: {other:?}"),
};
}
}
2 changes: 1 addition & 1 deletion website/docs/dump-load-restart.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ JSON-RPC

### Loading disclaimer

Currently, dumping produces a list of received transactions that is stored on disk. Conversely, loading is implemented as the re-execution of transactions from a dump. This means that timestamps of `StarknetBlock` will be different on each load.
Currently, dumping produces a list of reproducible Devnet actions (state-changing requests and transactions). Conversely, loading is implemented as the re-execution of transactions from a dump. This means that timestamps of `StarknetBlock` will be different on each load. This is due to the nature of Devnet's dependencies, which prevent Devnet's state from being serialized.

Dumping and loading are not guaranteed to work across versions. I.e. if you dumped one version of Devnet, do not expect it to be loadable with a different version.

Expand Down
12 changes: 12 additions & 0 deletions website/docs/postman.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ Loads a `MockStarknetMessaging` contract. The `address` parameter is optional; i
- [**Geth**](https://github.com/ethereum/go-ethereum#docker-quick-start)
- [**Hardhat node**](https://hardhat.org/hardhat-network/#running-stand-alone-in-order-to-support-wallets-and-other-software)

:::info Dumping and Loading

Loading a messaging contract is a dumpable event, meaning that, if you've enabled dumping, a messaging-contract-loading event will be dumped. Keep in mind that, if you rely on Devnet deploying a new contract, i.e. if you don't specify a contract address of an already deployed messaging contract, a new contract will be deployed at a new address on each loading of the dump. Read more about dumping [here](./dump-load-restart#dumping).

:::

## Flush

```
Expand Down Expand Up @@ -79,6 +85,12 @@ JSON-RPC

A running L1 node is required if `dry_run` is not set.

:::info Dumping and Loading

Flushing is not dumpable, meaning that, if you've enabled dumping, a flushing event will not itself be re-executed on loading. This is because it produces L2 messaging events that are themselves dumped. No L1-side actions are dumped, you need to take care of those yourself. Read more about dumping [here](./dump-load-restart#dumping).

:::

## Disclaimer

This method of L1-L2 communication testing differs from how Starknet mainnet and testnets work. Taking [**L1L2Example.sol**](https://github.com/MikeSpa/starknet-test/blob/6a68d033cd7ddb5df937154f860f1c06174e6860/L1L2Example.sol#L46) (originally from Starknet documentation, no longer available there):
Expand Down

0 comments on commit 7650137

Please sign in to comment.