FuelLabs / sway

🌴 Empowering everyone to build reliable and efficient smart contracts.
https://docs.fuel.network/docs/sway/
Apache License 2.0
62.58k stars 5.37k forks source link

Reference example code running to cargo test with error #5551

Open Bear-V opened 9 months ago

Bear-V commented 9 months ago

i am form China , i dont know if its network issue

this is my code

use fuels::{prelude::*, types::ContractId};

// Load abi from json
abigen!(Contract(
    name = "MyContract",
    abi = "out/debug/counter-contract-abi.json"
));

async fn get_contract_instance() -> (MyContract<WalletUnlocked>, ContractId) {
    // Launch a local network and deploy the contract
    let mut wallets = launch_custom_provider_and_get_wallets(
        WalletsConfig::new(
            Some(1),             /* Single wallet */
            Some(1),             /* Single coin (UTXO) */
            Some(1_000_000_000), /* Amount per coin */
        ),
        None,
        None,
    )
    .await
    .unwrap();
    let wallet = wallets.pop().unwrap();

    let id = Contract::load_from(
        "./out/debug/counter-contract.bin",
        LoadConfiguration::default(),
    )
    .unwrap()
    .deploy(&wallet, TxPolicies::default())
    .await
    .unwrap();

    let instance = MyContract::new(id.clone(), wallet);

    (instance, id.into())
}

#[tokio::test]
async fn can_get_contract_id() {
    let (instance, _id) = get_contract_instance().await;

    // Now you have an instance of your contract you can use to test each function
    instance.methods().count().call().await.unwrap();
}

#[tokio::test]
async fn test_increment() {
    let (instance, _id) = get_contract_instance().await;

    // Increment the counter
    instance.methods().increment().call().await.unwrap();

    // Get the current value of the counter
    let result = instance.methods().count().call().await.unwrap();

    // Check that the current value of the counter is 1.
    // Recall that the initial value of the counter was 0.
    assert_eq!(result.value, 1);
}

this is error

cargo test
    Finished test [unoptimized + debuginfo] target(s) in 1.05s
     Running tests/harness.rs (target/debug/deps/integration_tests-ba92b5ecc759ead1)

running 2 tests
test can_get_contract_id ... FAILED
test test_increment ... FAILED

failures:

---- can_get_contract_id stdout ----
thread 'can_get_contract_id' panicked at tests/harness.rs:21:6:
called `Result::unwrap()` on an `Err` value: IOError(Custom { kind: Other, error: ErrorResponse(502, "") })

---- test_increment stdout ----
thread 'test_increment' panicked at tests/harness.rs:21:6:
called `Result::unwrap()` on an `Err` value: IOError(Custom { kind: Other, error: ErrorResponse(502, "") })
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
    can_get_contract_id
    test_increment

test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.78s

error: test failed, to rerun pass `--test integration_tests`

this is fuelup show

$ fuelup show

Default host: x86_64-apple-darwin
fuelup home: /Users/pirate/.fuelup

installed toolchains
--------------------
beta-4-x86_64-apple-darwin (default)
latest-x86_64-apple-darwin

active toolchain
----------------
beta-4-x86_64-apple-darwin (default)
  forc : 0.46.1
    - forc-client
      - forc-deploy : 0.46.1
      - forc-run : 0.46.1
    - forc-crypto : not found
    - forc-doc : 0.46.1
    - forc-explore : 0.28.1
    - forc-fmt : 0.46.1
    - forc-lsp : 0.46.1
    - forc-tx : 0.46.1
    - forc-wallet : 0.3.0
  fuel-core : 0.20.5
  fuel-core-keygen : Error getting version string

fuels versions
--------------
forc : 0.45
forc-wallet : 0.45
Bear-V commented 9 months ago

This is the example page: https://docs.fuel.network/docs/intro/quickstart-contract/