Error: Returned values aren't valid, did it run Out of Gas? on selfdestruct()

1.9k Views Asked by At

the code works fine, cause i'm following an online crash course. my problem is when i enter selfdestruct() it says something about an error, that i am unsure of what. please have a look, and see what is the problem.

here is the code on where the problem pops out every-time i add this:

address payable admin;

function endSale() public {
    require(msg.sender == admin, "must be admin");
    require(tokenContract.transfer(admin, tokenContract.balanceOf(address(this))));
    selfdestruct(admin);
}

note that the error only shows when i add

selfdestruct(admin)

this is the test driven fashion code:

it('ends the token sale', () => {
    return DappToken.deployed().then((instance) => {
      //grab token instance first
      tokenInstance = instance;
      return DappTokenSale.deployed();
    }).then((instance) => {
      //then grab token sale instance
      tokenSaleInstance = instance;
      //try to end the sale from account other than the admin
      return tokenSaleInstance.endSale({ from: buyer });
    }).then(assert.fail).catch((error) => {
      assert(error.message.indexOf('revert') >= 0, 'must be admin to end sale');
      //end sale as admin
      return tokenSaleInstance.endSale({ from: admin});
    }).then((receipt) => {
      //receipt
      return tokenInstance.balanceOf(admin);
    }).then((balance) => {
      //return unsold dapp tokens to admin
      assert.equal(balance.toNumber(), 999990, 'returns all unsold dapp tokens to admin');
      // check that the token price was reset when the selfDestruct was called
      return tokenSaleInstance.tokenPrice();
    }).then((price) => {
      assert.equal(price.toNumber(), 0, 'token price was reset');
    });
  });

i'm using pragma ^0.5.0

here's my error log:

Error: Returned values aren't valid, did it run Out of Gas?
  at ABICoder.decodeParameters (C:\Users\KimVillanueva\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-eth-abi\src\index.js:226:1)
  at Contract._decodeMethodReturn (C:\Users\KimVillanueva\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-eth-contract\src\index.js:465:1)
  at Method.outputFormatter (C:\Users\KimVillanueva\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-eth-contract\src\index.js:818:1)
  at Method.formatOutput (C:\Users\KimVillanueva\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-eth-contract\~\web3-core-method\src\index.js:163:1)
  at sendTxCallback (C:\Users\KimVillanueva\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-eth-contract\~\web3-core-method\src\index.js:473:1)
  at C:\Users\KimVillanueva\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-core-requestmanager\src\index.js:147:1
  at C:\Users\KimVillanueva\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-provider\wrapper.js:112:1
  at XMLHttpRequest.request.onreadystatechange (C:\Users\KimVillanueva\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-providers-http\src\index.js:96:1)
  at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\KimVillanueva\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request-event-target.js:34:1)
  at XMLHttpRequest._setReadyState (C:\Users\KimVillanueva\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:208:1)
  at XMLHttpRequest._onHttpResponseEnd (C:\Users\KimVillanueva\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:318:1)
  at IncomingMessage.<anonymous> (C:\Users\KimVillanueva\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:289:47)
  at endReadableNT (_stream_readable.js:1094:12)
  at process._tickCallback (internal/process/next_tick.js:63:19)
0

There are 0 best solutions below