-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
test: add option to run against live node #1172
Conversation
c360c16
to
3a73394
Compare
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.
Thanks for the devx improvement!
I have made some comments below on the current implementation. While I was testing it locally, I made a lot small changes so I added it to another branch. In the branch, RunOnLiveNode
can be used without arguments and only one time etc. Branch: hal3e/test-against-live-node
Maybe it is worth to explore another implementation possibility. We could avoid adding a new command and instead rely on env
variables. If the variable is set we can use beta wallets. So instead of checking if the command was used we could just use something like option_env!
https://doc.rust-lang.org/stable/std/macro.option_env.html
Pseudo code:
in code_gen
:
- check if
RUN_ON_LIVE_NODE
env variable isSome("true")
-> use beta wallets - else use random wallets
@hal3e thanks a lot for your suggestion! I really like the idea of environment variables. However, we want to give the option to run only some relevant tests on the live nodes, first of all because it's slower, and potentially expensive. The env variables approach does not allow for this flexibility, as the pseudocode you wrote would apply each time we call Thanks a lot for the branch, it's much better this way! |
That is a good point! |
219c018
to
ecccad2
Compare
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.
Cleanly done!
I have one worry that I'd like to talk about:
setup_program_test
besides being useful to us, is also marketed to users to help them bootstrap their tests quicker.
RunOnLiveNode
isn't very flexible:
- You cannot say where the node is live at, an old beta? Some custom user node/network?
- It complicates the
Wallets
command. Previously it meant: "if a wallet is mentioned here I will setup the node and fund the wallet". Now it has a spin of "but if it is a live node, I will read ENV variables with some predetermined name format and connect to beta 4".
Currently, the following is possible without changes to the code:
User connecting to a node of his choice, with wallets of his choice:
let provider = Provider::connect("my.provider.com").await?;
let wallet = WalletUnlocked::new_from_private_key("private_key".parse().unwrap(), Some(provider))
setup_program_test!(
Abigen(Contract(
name = "TestContract",
project = "packages/fuels/tests/contracts/contract_test"
)),
Deploy(
name = "contract_instance",
contract = "TestContract",
wallet = "wallet"
),
);
Us having a helper controlled by a feature:
async fn maybe_live_wallet() -> Result<WalletUnlocked> {
if cfg!(feature = "live") {
let provider = Provider::connect("my.provider.com").await?;
Ok(WalletUnlocked::new_from_private_key(
"private_key".parse().unwrap(),
Some(provider),
))
} else {
launch_provider_and_get_wallet().await
}
}
#[tokio::test]
async fn some_test() -> Result<()> {
let wallet = maybe_live_wallet().await?;
setup_program_test!(
Abigen(Contract(
name = "TestContract",
project = "packages/fuels/tests/contracts/contract_test"
)),
Deploy(
name = "contract_instance",
contract = "TestContract",
wallet = "wallet"
),
);
This way we can keep complexity out of the macro while still being able to achieve our live tests with one extra line.
packages/fuels-macros/src/setup_program_test/parsing/commands/initialize_wallet.rs
Outdated
Show resolved
Hide resolved
packages/fuels-macros/src/setup_program_test/parsing/commands/run_on_live_node.rs
Outdated
Show resolved
Hide resolved
packages/fuels-macros/src/setup_program_test/parsing/commands/initialize_wallet.rs
Outdated
Show resolved
Hide resolved
I like this approach. As this is for our CI test only, a helper controlled with a flag seems to be the best solution. |
0442b85
to
65e6007
Compare
This reverts commit 81531cf.
65e6007
to
da4f61d
Compare
I have updated this PR to take into account the good suggestion by @segfault-magnet to make it a helper controlled by a feature flag. |
Blocked notably by the fact that |
Closing in favor of upcoming PR. |
This PR adds a
cargo
feature calledtest-against-live-node
, which enables running some test against a testnet node.status not found for transaction
(see https://github.com/FuelLabs/fuels-rs/actions/runs/6881505027/job/18718373777). These errors are being investigated as part of refactor: use the right APIs fromfuel-core
#1188.If you want a test to be able to be run against a live node, remove the
Wallets
command from thesetup_test_program
, and in place use themaybe_live_wallet
helper, as follows:Previously, this would have looked like this: