sarvalabs / js-moi-sdk

JavaScript library to interact with MOI Protocol via RPC API
https://js-moi-sdk.docs.moi.technology/
Apache License 2.0
24 stars 2 forks source link

Bug: Incorrect "Invalid Address" Error Thrown When fuelLimit is Missing in routineOptions During Contract Deployment #89

Closed sarvalabs-pawankalyan closed 1 month ago

sarvalabs-pawankalyan commented 2 months ago

Description: When deploying a contract using the moi.LogicFactory and not passing the fuelLimit in the routineOptions, the function throws an incorrect error:

CustomError: invalid address
{
  code: 'ERROR_SERVER',
  reason: 'invalid address',
  params: {}
}

Expected behavior: The function should either deploy successfully or throw a clear error message indicating that the fuelLimit is missing. However, instead of indicating the missing fuelLimit, the error incorrectly states "invalid address."

When the fuelLimit is provided in routineOptions, the contract deploys successfully without any issues.

Suggested Fix: The error handling should be improved to correctly reflect when fuelLimit is missing from routineOptions, rather than providing a misleading "invalid address" error.

Js-Moi-Sdk code

const walletUtils = require('./wallet');
const manifest = require('./testing.json');
const moi = require('js-moi-sdk');

const fuelData = {
    fuelPrice: 0,
    fuelLimit: 50000000,
}

const deploy = async () => {
    try {

        const wallet = await walletUtils.getWallet();
        console.log(wallet.address)
        const factory = new moi.LogicFactory(manifest, wallet);
        const ix = await factory.deploy('Init', moi.createRoutineOption({
            fuelPrice: 0
        }));
        const result = await ix.result();
        const response = {
            status: "success",
            result: result,
        };
        console.log(response);
    } catch (err) {
        console.log(err);
        throw err;
    }
}

Screenshot 2024-09-27 at 12 47 06 PM