The contract code couldn’t be stored, please check your gas limit

I am having similar problem (“The contract code couldn’t be stored, please check your gas limit.”). I am running tests on ethereum private test network. 60 out of 100 tests fail due to “The contract code couldn’t be stored, please check your gas limit.”.
What is the learning here which all are talking about? What kind of abstract contracts do create this problem?

1 Like

Hi @prabhat,

I suggest checking your gas limit and gas price configuration as the potential cause.

In Solidity 0.5 you could inherit from an abstract contract, not implement all the functions and it would compile as you had created another abstract contract. In Solidity 0.6 we use the keyword abstract and the compiler will complain if you have a non abstract contract and don’t implement all the functions.

Hi @abcoathup

I am running exact code in loop for testing a 1000 times. It fails 60% of times and succeeds 40%.
Same gas and same gas price. It is part of our system test for deployments.

 Error: The contract code couldn't be stored, please check your gas limit.
    at Object.callback (/Users/pksingh/solydBE/api/contracts/node_modules/web3-core-method/src/index.js:376:37)
    at sendTxCallback (/Users/pksingh/solydBE/api/contracts/node_modules/web3-core-method/src/index.js:551:29)
    at /Users/pksingh/solydBE/api/contracts/node_modules/web3-core-requestmanager/src/index.js:147:9
    at XMLHttpRequest.request.onreadystatechange (/Users/pksingh/solydBE/api/contracts/node_modules/web3-providers-http/src/index.js:102:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/pksingh/solydBE/api/contracts/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
    at XMLHttpRequest._setReadyState (/Users/pksingh/solydBE/api/contracts/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
    at XMLHttpRequest._onHttpResponseEnd (/Users/pksingh/solydBE/api/contracts/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
    at IncomingMessage.<anonymous> (/Users/pksingh/solydBE/api/contracts/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
    at IncomingMessage.emit (events.js:203:15)
    at endReadableNT (_stream_readable.js:1145:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
1 Like

Hi @prabhat,

What are you using for testing? (e.g. Truffle test or OpenZeppelin Test Environment)
If Truffle, what local network are you connecting to?
What operating system, node, npm version are you using?

Are you able to share a cutdown version of the contract and test so I can try to replicate?

I am running Geth with 3 miners.
For OZ Upgradables Smart Contract.
Test function does Deploy & initialize. In loops over 100s of times.
System: MAC OSX 10.15.5
NODE 10 LTS, NPM 6
The contract is in next message.

1 Like
// contracts/PubContract.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.7.0;

import "@openzeppelin/upgrades/contracts/Initializable.sol";


contract PubContract is Initializable {


    //Roles.Role private _entity; //Hub Service Providers
    mapping(address => bytes) internal entitlements;
    mapping(string => bytes) internal identities;
    // code ==> encrypted identity with user's own keys(offline encryption)

    address private selfId; //Self ID of the contract extracted by web3 or salting.
    address private owner; //Blockchain address of the owner
    //bytes32 private pubId; //Public Key
    event IdentityExchanged(address indexed account);
    event ServiceRequested(address indexed account, address _subId);

    fallback() external payable { }

    function initialize(address _selfId, bytes memory _name) external initializer {
        selfId = _selfId;
        owner = msg.sender;
        identities["NAME"] = _name;//_name can be encrypted
    }

    function addi(string memory code, bytes memory identity) external  { // Ensure unique entitlement
        //Add - Unique
        require(owner == msg.sender);
        identities[code] = identity;
    }

    function remi(string memory code) external { // Remove existing identity
        //Remove
        require(owner == msg.sender);
        delete identities[code];
    }

    function tmi(
      bytes memory privateId,
      bytes32  _salt,
      address  mainId,
      address  _subId,
      address recipient
    ) external  { // Transmit Identity
        //Remove
        require(owner == msg.sender);
        new Identityxch{salt: _salt}(mainId, _subId, recipient, privateId);
        emit IdentityExchanged(recipient);
    }

    function alli(string memory code) external  returns ( bytes memory) { //get an identity
        //read all entitlements
        return identities[code];
    }

    /* Entitlements
      add - Add Entitlement (address, entitlement)

      rem - Remove Entitlement  (address, entitlement)

      req - Request Service

      all - View all entitlements

    */
    function adde(address hubid, bytes memory entitlement) external { // Ensure unique entitlement
        //Add - Unique
        require(owner == msg.sender);
        //require(entitlements[hubid] != entitlement);
        require(keccak256(entitlements[hubid]) != keccak256(entitlement) );
        entitlements[hubid] = entitlement;
    }

    function reme(address hubid, bytes memory entitlement) external { // Remove existing entitlement
        //Remove
        require(owner == msg.sender);
        //require(entitlements[hubid] == entitlement);
        require(keccak256(entitlements[hubid]) == keccak256(entitlement) );
        delete entitlements[hubid];
    }

    function reqe(bytes32  _salt, address  _subId, address hubid, bytes memory request) external { // Request entitlement service
        //request service
        require(owner == msg.sender);
        new Servicereqs{salt: _salt}(hubid, _subId, entitlements[hubid], request);
        emit ServiceRequested(hubid, _subId);
    }

    function alle(address account) external returns(bytes memory){//get  entitlements
        //read all entitlements
        return entitlements[account];
    }

}


//Identity Exchange Contract
contract Identityxch {
    address payable owner;
    address private mainId;
    address private selfId;
    address private recipient;
    bytes private pvtIdentity;
    bool private complete;

    constructor(address _mainId, address _selfId, address _recipient, bytes memory _pvtIdentity) public payable {
        owner = msg.sender;
        mainId = _mainId; //Main ID of contract
        selfId = _selfId; //Self ID of contract
        recipient = _recipient;
        pvtIdentity = _pvtIdentity;
        //send();
        //require(success, "Transfer failed.");
    }

    fallback() external payable {  }

    function ack() external { //Acknowledge
        require(owner == msg.sender || recipient == msg.sender);
        complete = true;
    }

    function end() external {
        require(owner == msg.sender || recipient == msg.sender);
        selfdestruct(owner);
    }
}


//Service Request Contract for Entitlements
contract Servicereqs {
    address payable owner;
    address private provider;
    address private selfId;
    bytes private entitlement;
    bytes private request;
    bool private complete;
    uint256 private bidc;//bidcount - How many bids will be provided for this
    uint256 private bidCount;//bidcount - How many bids will be provided for this
    mapping(uint256 => address) internal bids;// Micro-bids for this service

    constructor(address _provider, address _selfId, bytes memory _entitlement, bytes memory _request) public payable {
        owner = msg.sender;
        provider = _provider;
        selfId = _selfId;
        entitlement = _entitlement;
        request = _request;
        //send();
        //require(success, "Transfer failed.");
    }

    fallback() external payable {}

    function ack(uint256 countofbids) external { //Acknowledge
        require(owner == msg.sender || provider == msg.sender);
        bidc = countofbids;
    }

    function serve(uint256 order, address contractreward) external {
        require(owner == msg.sender || provider == msg.sender);
        //if (bidc < bids.length) {
        bids[order] = contractreward;
        //}
        //if (bidc >= bids.length) {
        complete = true;
        //}
    }

    function end() external {
        require(owner == msg.sender || provider == msg.sender);
        //selfdestruct();
        selfdestruct(owner);
    }
}
1 Like

Hi @prabhat,

How are you deploying the upgradeable contract in your test? Are you able to share your test or a cutdown version?