Skip to content
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

Defined Vec alias in Sway breaks SDK harness #1603

Open
bitzoic opened this issue Feb 21, 2025 · 1 comment
Open

Defined Vec alias in Sway breaks SDK harness #1603

bitzoic opened this issue Feb 21, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@bitzoic
Copy link
Member

bitzoic commented Feb 21, 2025

If an alias is defined in Sway that is a Vec, then the Rust SDK will fail to compile.

Minimal Repro Sway Contract:

contract;

pub type MyAlias = Vec<b256>;

abi MyContract {
    fn test_function() -> MyAlias;
}

impl MyContract for Contract {
    fn test_function() -> MyAlias {
        MyAlias::new()
    }
}

Minimal Repro SDK harness:

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

// Load abi from json
abigen!(Contract(
    name = "MyContract",
    abi = "out/debug/test_sdk_vec_alias-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/test_sdk_vec_alias.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
    let result = instance.methods().test_function().await.unwrap().value;
}
Image
@bitzoic bitzoic added the bug Something isn't working label Feb 21, 2025
@segfault-magnet segfault-magnet self-assigned this Feb 21, 2025
@segfault-magnet
Copy link
Contributor

Raised with the compiler team. Will write updates here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants