sc-forks / solidity-coverage

Code coverage for Solidity smart-contracts
MIT License
977 stars 263 forks source link

TypeError: input.charCodeAt is not a function #218

Closed NFhbar closed 6 years ago

NFhbar commented 6 years ago

I get the following error:

Generating coverage environment
Running: truffle compile --network coverage 
(this can take a few seconds)...
Compiling ./contracts/InterfacePatientRecords.sol...
Compiling ./contracts/Migrations.sol...
Compiling ./contracts/PatientRecords.sol...
Compiling ./contracts/SpringToken.sol...
Compiling ./contracts/TokenDestructible.sol...
Compiling zeppelin-solidity/contracts/math/SafeMath.sol...
Compiling zeppelin-solidity/contracts/ownership/Ownable.sol...
Compiling zeppelin-solidity/contracts/token/ERC20/BasicToken.sol...
Compiling zeppelin-solidity/contracts/token/ERC20/ERC20.sol...
Compiling zeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol...
Compiling zeppelin-solidity/contracts/token/ERC20/StandardToken.sol...

Compilation warnings encountered:

zeppelin-solidity/contracts/token/ERC20/BasicToken.sol:38:5: Warning: Invoking events without "emit" prefix is deprecated.
    Transfer(msg.sender, _to, _value);
    ^-------------------------------^
,zeppelin-solidity/contracts/token/ERC20/StandardToken.sol:33:5: Warning: Invoking events without "emit" prefix is deprecated.
    Transfer(_from, _to, _value);
    ^--------------------------^
,zeppelin-solidity/contracts/token/ERC20/StandardToken.sol:49:5: Warning: Invoking events without "emit" prefix is deprecated.
    Approval(msg.sender, _spender, _value);
    ^------------------------------------^
,zeppelin-solidity/contracts/token/ERC20/StandardToken.sol:75:5: Warning: Invoking events without "emit" prefix is deprecated.
    Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
    ^-----------------------------------------------------------^
,zeppelin-solidity/contracts/token/ERC20/StandardToken.sol:96:5: Warning: Invoking events without "emit" prefix is deprecated.
    Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
    ^-----------------------------------------------------------^
,zeppelin-solidity/contracts/ownership/Ownable.sol:38:5: Warning: Invoking events without "emit" prefix is deprecated.
    OwnershipTransferred(owner, newOwner);
    ^-----------------------------------^
,/home/nico/Desktop/public_repos/hospital_network/coverageEnv/contracts/SpringToken.sol:26:5: Warning: Invoking events without "emit" prefix is deprecated.
    Transfer(0x0, msg.sender, INITIAL_SUPPLY);
    ^---------------------------------------^

Writing artifacts to ./build/contracts

Instrumenting  ./coverageEnv/contracts/InterfacePatientRecords.sol
Skipping instrumentation of  ./coverageEnv/contracts/Migrations.sol
Instrumenting  ./coverageEnv/contracts/PatientRecords.sol
Cleaning up...
There was a problem instrumenting ./coverageEnv/contracts/PatientRecords.sol: TypeError: input.charCodeAt is not a function
Exiting without generating coverage...

truffle.js:

require('dotenv').config()
require('babel-register')({
  ignore: /node_modules\/(?!zeppelin-solidity\/test\/helpers)/
})
require('babel-polyfill')

const Web3 = require("web3")
const web3 = new Web3()
const WalletProvider = require("truffle-wallet-provider")
const Wallet = require('ethereumjs-wallet')

const rinkebyPrivateKey = new Buffer(process.env["RINKEBY_PRIVATE_KEY"], "hex")
const rinkebyWallet = Wallet.fromPrivateKey(rinkebyPrivateKey)
const rinkebyProvider = new WalletProvider(rinkebyWallet, "https://rinkeby.infura.io/")

module.exports = {
  migrations_directory: "./migrations",
  networks: {
    development: {
      host: "localhost",
      port: 9545,
      network_id: "*" // Match any network id
    },
    coverage: {
      host: "localhost",
      network_id: "*",
      port: 8555,         // <-- If you change this, also set the port option in .solcover.js.
      gas: 0xfffffffffff, // <-- Use this high gas value
      gasPrice: 0x01      // <-- Use this low gas price
    },
    ganache: {
      host: "127.0.0.1",
      port: 7545,
      network_id: 5777
    },
    rinkeby: {
      provider: rinkebyProvider,
      // You can get the current gasLimit by running
      // truffle deploy --network rinkeby
      // truffle(rinkeby)> web3.eth.getBlock("pending", (error, result) =>
      //   console.log(result.gasLimit))
      gas: 6721975,
      gasPrice: web3.toWei("50", "gwei"),
      network_id: "4",
    }
  },
  solc: {
    optimizer: {
      enabled: true,
      runs: 500
    }
  }
}

.solcover.js

module.exports = {
  copyNodeModules: true
}

Any ideas?

cgewecke commented 6 years ago

@NFhbar Is there any way you can show PatientRecords.sol? It's difficult to debug this without a target to error against.

NFhbar commented 6 years ago

Yes of course, my bad:

https://gist.github.com/NFhbar/5394dcb4ee4147abeb25f4fe503549f9#file-patientrecords-sol-L168

cgewecke commented 6 years ago

@NFhbar This appears to be a bug in our recent work to support the emit keyword - slightly mysterious tbh.

It looks like it can be worked around in your case by rewriting this expression at ~L298 with enclosing braces e.g

if (msg.value > 0) {
   emit Deposit(msg.sender, msg.value);
}

Apologies, thanks so much for opening the issue. Please feel free to add to this thread if you discover more.

NFhbar commented 6 years ago

I can confirm that changing

if (msg.value > 0) 
   emit Deposit(msg.sender, msg.value);

to

if (msg.value > 0) {
   emit Deposit(msg.sender, msg.value);
 }

Solves the problem. Thank you!

cgewecke commented 6 years ago

@NFhbar This should be fixed in 0.5.0. Thanks!