0

I'm getting undefined for the length of multiSig dynimic array, or votes in testing, no matter how many items are pushed into the array.

FlightSuretyData.sol

   address[] multiSig = new address[](0);
   function getMultiSigLength() public view returns (uint256) {
        return multiSig.length;
    }

FlightSuretyApp.sol

    function testGettingMultiSigLength() public view returns (uint256) {
        return flightSuretyData.getMultiSigLength();
    }

test/flightSurety.js

  it("test getting the length from getMultiSigLength()", async () => {
    // ARRANGE
    let votes;
    // ACT
    try {
      votes = await config.flightSuretyApp.testGettingMultiSigLength();
    } catch (e) {
      console.log("votes error", e);
    }
    console.log(votes);
  });

When I log the e.message I get the following:

hijackedStack: 'Error: Returned error: VM Exception while processing transaction: revert\n'

When I bring the array and the function to be combined within the same

contract FlightSuretyApp.sol

   address[] multiSig = new address[](0);
   function getMultiSigLength() public view returns (uint256) {
        return multiSig.length;
    }
    function testGettingMultiSigLength() public view returns (uint256) {
        return getMultiSigLength();
    }

it works fine which means something about reaching over to another contract that's causing the issue. I've had to import the the contract through import "./FlightSuretyData.sol";

testConfig.js

var FlightSuretyApp = artifacts.require("FlightSuretyApp");
var FlightSuretyData = artifacts.require("FlightSuretyData");
var BigNumber = require("bignumber.js");

var Config = async function (accounts) {
  let owner = accounts[0];
  let firstAirline = accounts[1];

  let flightSuretyData = await FlightSuretyData.new();
  let flightSuretyApp = await FlightSuretyApp.new();

  return {
    owner: owner,
    firstAirline: firstAirline,
    weiMultiple: new BigNumber(10).pow(18),
    testAddresses: testAddresses,
    flightSuretyData: flightSuretyData,
    flightSuretyApp: flightSuretyApp,
  };
};

module.exports = {
  Config: Config,
};

And this is how I authorized FlightSuretyApp to FlightSuretyData

  before("setup contract", async () => {
    config = await Test.Config(accounts);
    await config.flightSuretyData.authorizeCaller(
      config.flightSuretyApp.address
    );
  });
  • 1
    Change catch (e) {} to catch (e) {console.log(e.message);}, and you'll know why. – goodvibration May 23 at 5:14
  • @goodvibration updated the question – Kevvv May 23 at 20:51
  • What's so hard about doing console.log(e.message) instead of console.log(e)??? – goodvibration May 24 at 7:49
  • do you not see the message up there? Error: Returned error: VM Exception while processing transaction: revert – Kevvv May 24 at 15:17
  • Yes, but me (and anyone else here) would have seen it much more clearly if you followed that instruction. And when you dump a huge non-relevant piece of text into your question, most people (me included) will not bother to read through and help you out. – goodvibration May 24 at 15:23
0

In contract FlightSuretyApp, you should set variable flightSuretyData to the address of a FlightSuretyData instance.

Here are a few ways to do it (depending on your use-case):

    constructor(FlightSuretyData _flightSuretyData) public {
        flightSuretyData = _flightSuretyData;
    }

    constructor(arg1, arg2, ...) public {
        flightSuretyData = new FlightSuretyData(arg1, arg2, ...);
    }

    function setFlightSuretyData(FlightSuretyData _flightSuretyData) public {
        flightSuretyData = _flightSuretyData;
    }

    function setFlightSuretyData(arg1, arg2, ...) public {
        flightSuretyData = new FlightSuretyData(arg1, arg2, ...);
    }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.