-
Notifications
You must be signed in to change notification settings - Fork 189
Add forest api test-stateful subcommand
#5836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e383a9e
6c24d61
92e36d9
1166dbe
8025482
a103025
d2aa97f
7069381
da92434
fefbbc2
155c539
4a316c0
032778d
9c0afbf
e893aeb
722ca1b
1c90178
797ee37
cc1b2ba
4f0c2a4
b65cc97
f5d86d9
db3655e
c3913bb
884de14
e8b6bb6
cdea50f
ab02767
4fb1c99
cc6defe
95c36d9
ee14d70
e172cde
d8b5576
e1c2729
8fed6e0
6171f1e
1e93afe
8713195
20b22a9
c2fbe02
6c17c65
4095010
54659d7
78dc2c7
70ad519
b610bf3
585c279
c6d419e
e8b936b
41afdca
1a40061
61c6dc1
d969a28
ab46e8e
8907015
34283bc
a65918e
06b9c46
9842f14
a127f9d
33f37bd
515cf18
1e819fa
f64456b
9258ee6
66f6a11
2a340ef
ca998b1
258621e
9ebf228
1407333
c07de53
0971f06
c53a2b5
4517417
e840947
706ef61
20a9c8d
e67db40
248fa27
6e41430
cd831aa
b89f0e7
e8ac160
4146221
7b2cdeb
d9b1239
86f4c3f
7492451
c353ad3
07d772f
d068413
9fd72b4
4752dee
907bd29
589a0b9
1446872
5bd721f
d1a2afa
58e86a6
b07fac6
3a8de44
b7dfcfc
8e0702e
98b7dde
21aa151
737edb0
9614295
a47c4eb
7de68a9
cac27de
7f164b6
11dfa3f
b63f1bd
87e33de
5bca9bb
bad13d6
9c72ec8
5beb9d6
79667c9
70fe4fd
30433fb
1e3e088
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # RPC Stateful Tests | ||
|
|
||
| Some methods in the Filecoin Ethereum JSON-RPC API require stateful interactions for meaningful testing. These tests validate both **schema compatibility** and **method semantics**, especially for RPC endpoints that rely on internal node state. | ||
|
|
||
| This includes: | ||
|
|
||
| - All subscription-based methods | ||
| - Filter-related methods (e.g., `eth_newFilter`, `eth_getFilterLogs`) | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| Before running the tests, perform the following setup steps: | ||
|
|
||
| 1. Run a Lotus or Forest node (calibnet recommended). Make sure `FULLNODE_API_INFO` is defined. | ||
| 2. Create an f4 address, fund it, and deploy a test smart contract (the deployed contract must emit an event with a known topic when invoked). | ||
| 3. The f4 address must hold enough FIL to invoke the contract. | ||
|
|
||
| Run the test suite with: | ||
| `forest-tool api test-stateful --to <CONTRACT_ADDR> --from <FROM_ADDR> --payload <INVOKE_PAYLOAD> --topic <TOPIC>` | ||
|
|
||
| where: | ||
|
|
||
| - `CONTRACT_ADDR`: f4 address of the deployed smart contract | ||
| - `FROM_ADDR`: f4 address invoking the contract | ||
| - `INVOKE_PAYLOAD`: Calldata that will trigger the contract's event | ||
| - `TOPIC`: The event topic expected to be emitted during invocation | ||
|
|
||
| ## Example output | ||
|
|
||
| ```console | ||
| export FULLNODE_API_INFO="<TOKEN>:/ip4/127.0.0.1/tcp/1234/http" | ||
| forest-tool api test-stateful \ | ||
| --to t410f2jhqlciub25ad3immo5kug2fluj625xiex6lbyi \ | ||
| --from t410f5uudc3yoiodsva73rxyx5sxeiaadpaplsu6mofy \ | ||
| --payload 40c10f19000000000000000000000000ed28316f0e43872a83fb8df17ecae440003781eb00000000000000000000000000000000000000000000000006f05b59d3b20000 \ | ||
| --topic 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef | ||
| running 7 tests | ||
| test eth_newFilter install/uninstall ... ok | ||
| test eth_newFilter under limit ... ok | ||
| test eth_newFilter just under limit ... ok | ||
| test eth_newFilter over limit ... ok | ||
| test eth_newBlockFilter works ... ok | ||
| test eth_newPendingTransactionFilter works ... ok | ||
| test eth_getFilterLogs works ... ok | ||
| test result: ok. 7 passed; 0 failed; 0 ignored; 0 filtered out | ||
| ``` | ||
|
|
||
| The goal is to ensure that Forest now passes all the existing scenarios. These scenarios are not exhaustive, and additional ones can be added as needed. | ||
|
|
||
| ## Adding a new test | ||
|
|
||
| To extend test coverage for another RPC method or cover more semantics: | ||
|
|
||
| 1. Add the RPC method to Forest if not yet implemented, following the guidance in [RPC compatibility guide](./rpc_api_compatibility.md). | ||
| 2. Create a new test scenario in: | ||
| [`stateful_tests.rs`](../../../src/tool/subcommands/api_cmd/stateful_tests.rs) | ||
| 3. Your internal test function should return `Ok(())` on success. Use `anyhow::Result` for error handling. | ||
|
|
||
| Ensure the test behaves consistently on both Lotus and Forest nodes. | ||
|
|
||
| ## Example test function | ||
| ```rust | ||
| pub async fn test_eth_method(client: Arc<Client>) -> anyhow::Result<()> { | ||
| // Setup call to the method | ||
| // Assert intermediate states | ||
| // State cleanup | ||
| // Return Ok when the sequence completes successfully | ||
| Ok(()) | ||
| } | ||
| ``` | ||
|
|
||
| ## Notes | ||
|
|
||
| The current test framework assumes a running node and a valid wallet. | ||
|
|
||
| Consider implementing `forest-tool evm deploy` and `forest-tool evm invoke` subcommands to simplify contract deployment and test invocation. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #!/usr/bin/env bash | ||
| # This script tests RPC API stateful tests on a live forest node. | ||
| # It requires both `forest`, `forest-wallet` and `forest-tool` to be in the PATH. | ||
|
|
||
| set -euxo pipefail | ||
|
|
||
| source "$(dirname "$0")/harness.sh" | ||
|
|
||
|
|
||
| forest_init "$@" | ||
|
|
||
| # This is the address of a Calibnet pre-deployed simple ERC20 contract. | ||
| # You can find the hex and source code in 'src/tool/subcommands/api_cmd/contracts/erc20'. | ||
| TO_ADDRESS="t410fp6e7drelxau7nf76tcn6gva22t5jafefhevubwi" | ||
|
|
||
| FROM_ADDRESS="t410f2avianksmit2cl2bqk53qant7nm7rdmk63twa5y" | ||
|
|
||
| # This payload corresponds to minting new tokens for the 'FROM_ADDRESS' and will trigger a log event upon success. | ||
| # To compute the calldata, you can use the 'cast calldata' subcommand with the following arguments: | ||
| # cast calldata "mint(address,uint256)" 0x7f89f1c48bb829f697fe989be3541ad4fa901485 1000000000000000000 | ||
| # | ||
| # Note that 0x7f89f1c48bb829f697fe989be3541ad4fa901485 is the Ethereum address corresponding to the contract f4 address. | ||
| PAYLOAD="0x40c10f190000000000000000000000007f89f1c48bb829f697fe989be3541ad4fa9014850000000000000000000000000000000000000000000000000de0b6b3a7640000" | ||
|
|
||
| # This topic is derived using the keccak256 hash of the event signature 'Mint(address,uint256)' | ||
| # To compute the topic, you can use the 'cast keccak256' subcommand with the following argument: | ||
| # cast keccak256 "Mint(address,uint256)" | ||
| TOPIC="0x0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d4121396885" | ||
|
|
||
| $FOREST_TOOL_PATH api test-stateful \ | ||
| --to "$TO_ADDRESS" \ | ||
| --from "$FROM_ADDRESS" \ | ||
| --payload "$PAYLOAD" \ | ||
| --topic "$TOPIC" | ||
|
elmattic marked this conversation as resolved.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to handle the tokens? It's saved and consumed already from a default location, as introduced in #5629
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed it. |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not enable xtrace while handling secrets
set -x will print commands and arguments, leaking the wallet secret. Disable xtrace during secret handling and only re-enable afterward.
📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elmattic, is this actionable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.