The test does not start if the storage has a StorageVec

Hey guys!
The problem is that if I add some types to the storage, then my abigen crashes with an error like parameter 'V' is never used

src/main.sw

contract;
use std::{storage::StorageVec};
abi MyContract {
    fn name() -> StorageVec<u8>;
    fn set_name(name: StorageVec<u8>);
}

storage {
    name: StorageVec<u8> = StorageVec {},
}

impl MyContract for Contract {
    fn name() -> StorageVec<u8> {
        storage.name
    }

    fn set_name(name: StorageVec<u8>) {}
        // storage.name = name; // TODO: implement set_name
}

tests/harness.rs

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

abigen!(MyContract, "out/debug/name_contract-abi.json");

async fn get_contract_instance() -> (MyContract, ContractId) {
    let mut wallets = launch_custom_provider_and_get_wallets(
        WalletsConfig::new(Some(1), Some(1), Some(1_000_000_000)),
        None,
        None,
    )
    .await;
    let wallet = wallets.pop().unwrap();

    let id = Contract::deploy(
        "./out/debug/name_contract.bin",
        &wallet,
        TxParameters::default(),
        StorageConfiguration::with_storage_path(Some(
            "./out/debug/name_contract-storage_slots.json".to_string(),
        )),
    )
    .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;
}

The error

error[E0392]: parameter `V` is never used
 --> tests/harness.rs:3:1
  |
3 | abigen!(MyContract, "out/debug/name_contract-abi.json");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unused parameter
  |
  = help: consider removing `V`, referring to it in a field, or using a marker such as `PhantomData`
  = note: this error originates in the macro `abigen` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0392`.
error: could not compile `name-contract` due to previous error
1 Like

Also when I’m trying to store an enum inside a struct I have an extension error like that

And test launch error

error[E0392]: parameter `K` is never used
 --> tests/harness.rs:4:1
  |
4 | abigen!(LimitOrders, "out/debug/limit-orders-abi.json");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unused parameter
  |
  = help: consider removing `K`, referring to it in a field, or using a marker such as `PhantomData`
  = note: this error originates in the macro `abigen` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0392]: parameter `V` is never used
 --> tests/harness.rs:4:1
  |
4 | abigen!(LimitOrders, "out/debug/limit-orders-abi.json");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unused parameter
  |
  = help: consider removing `V`, referring to it in a field, or using a marker such as `PhantomData`
  = note: this error originates in the macro `abigen` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0392`.
error: could not compile `limit-orders` due to 2 previous errors

The contract

contract;
use std::{
    auth::{msg_sender, AuthError},
    storage::StorageVec,
    call_frames::msg_asset_id,  
    context::msg_amount,
    block::timestamp,
};

enum Status {
    Active: (),
    Canceled: (),
    Completed: (),
}

pub struct Order {
    asset0: ContractId,
    amount0: u64,
    asset1: ContractId,
    amount1: u64,
    status: Status,
    fulfilled0: u64,
    fulfilled1: u64,
    owner: Address,
    id: u64,
    timestamp: u64,
}

abi LimitOrders {
    // #[storage(read)]
    fn orders() -> StorageMap<u64, Order>;
    #[storage(read, write)]
    fn create_order(asset1: ContractId, amount1: u64);
}

storage {
    orders: StorageMap<u64, Order> = StorageMap {},
    orders_amount: u64 = 0,

}

impl LimitOrders for Contract {
    // #[storage(read)]
    fn orders() -> StorageMap<u64, Order> {
        storage.orders
    }
    #[storage(read, write)]
    fn create_order(asset1: ContractId, amount1: u64) {
        let asset0 = msg_asset_id();
        let amount0 = msg_amount();
        assert(amount0 > 0); // TODO: throw
        
        let owner: Result<Identity, AuthError> = msg_sender();
        let owner: Address = match owner.unwrap() {
            Identity::Address(addr) => addr,
            _ => revert(0),
        };
        let id = storage.orders_amount + 1;
        let order =  Order {
            asset0,
            amount0,
            asset1,
            amount1,
            fulfilled0: 0,
            fulfilled1: 0,
            status: Status::Active,
            owner,
            id,
            timestamp: timestamp(),
        };

        storage.orders_amount = order.id;
        storage.orders.insert(order.id, order);
    }
}
}

I managed to build it in a neighboring project, but when I tried to rename something I got the same error.
After a couple of hours of trying to figure out why it was so, I got this error
But on the next attempts my error already appears (parameter ‘V’ is never used)

 message: called `Result::unwrap()` on an `Err` value: ParseTokenStreamError("Custom type struct StorageMap must have at least one component!")

Regarding the first example: StorageMap and StorageVec cannot be returned from contract methods yet. This should be disallowed in the compiler. Let me open an issue.

That being said, there are two workarounds:

  1. [not possible yet] Convert the StorageVec into a Vec and return that instead. This is not fully possible yet but will be after Transform `Vec` return from a contract into a `raw_slice` return from the calling scripts · Issue #746 · FuelLabs/fuels-rs · GitHub which will hopefully be resolved soon.
  2. Using logs instead of returns. For example, you can loop over orders and log each value, and then collect the logs in the SDK. Returns and logs are pretty similar (in the sense they both emit receipts with data), except that logs don’t have control flow implications.
3 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.