1

New to Ethereum and learning unit testing with Truffle. Here in smart contract function;

function createAgreement(
        bytes32 _id, 
        address _owner,  
        string _fileHash,
        address[] _listOfSigners,
        uint256[] _types
    )   public returns (bool success) {
        //TODO: code here
        return true;
}

Here is the test cases that I wrote so far:

let owner = web3.eth.accounts[1],
    fileHash = "2413FB3709B05939F04CF2E92F7D0897FC2596F9AD0B8A9EA855C7BFEBAAE892",
    listOfSigner = ["0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef",
                    "0x821aEa9a577a9b44299B9c15c88cf3087F3b5544"],
    types = [0,1,2],
    Instance;
    id = "XVXIJLO-9XNQ-ZQWF-OLAF-E14L09FHZALQ";

describe("Unit Test For Create Agreement Method", function() {
    it("Adding agreement into blockchain", function(){
        return Instance.createAgreement.call(id, owner, fileHash, listOfSigner, types)
            .then(function(res){  
                console.log("created!");
            });
    });
});

When I run the test case, it's getting failed with an error of:

Error: Transaction: 0xc5bbcab6c3cc45cf198e5cd75725c881eb280f3b6758b9f080101c7d491985dd exited with an error (status 0) after consuming all gas. Please check that the transaction: - satisfies all conditions set by Solidity assert statements. - has enough gas to execute the full transaction. - does not trigger an invalid opcode by other means (ex: accessing an array out of bounds).

Probably, error due to GAS, how could estimate GAS and pass it?

8
  • As far as I remember, truffle will send gas as specified in truffle.js config (gas - parameter). If this value is not large enough for your transaction, it can fail like you're describing.
    – ivicaa
    Jul 10, 2018 at 13:36
  • Is your Instance deployed (migrated) on the blockchain? Is the function really doing nothing except return true?
    – schemar
    Jul 10, 2018 at 20:18
  • @schemar, The code blocks displaying in the question is just for minimal example..actual code is different? could actual code take more GAS to run the operation?
    – Hina
    Jul 11, 2018 at 8:09
  • @HinaKhuman well it depends on what you are doing 😅 did you make sure the contract is deployed when testing? To the right network?
    – schemar
    Jul 11, 2018 at 8:26
  • @schemar: alright, but I can do either to pass more GAS? let me check again.
    – Hina
    Jul 11, 2018 at 8:27

1 Answer 1

2

Which version of Truffle do you use?

In my case, downgrading Truffle from v5.0.27 to v5.0.5 fixed the issue.

npm i -g [email protected]

1
  • Issue appears to be related to the fact latest version of truffle is using solidity compiler 0.5.8 which causes an issue with the interaction with contracts
    – Gabriel G.
    Aug 12, 2019 at 15:57

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .