0

In the following code, the console.log returns an empty string, but the truffle test works fine!

const certificate = contract(Certificate);
certificate.setProvider(web3.currentProvider);
var certificateInstance = 
certificate.at("0xfcdf59a5e2a43059d3d469f4aa31534d6c0d00b7");
return certificateInstance
    .ownerName() // state variable in the contract
    .then(function(_ownerName) {
      console.log(_ownerName);
      // getParam2 is the function with onlyOwner modifier
      return certificateInstance.getParam2({ from: owner });
    })
    .then(function(_value) {
      console.log(_value);
    });

Below are my truffle test code:

...
return Certificate.at(certAddress);
}).then(function(instance){
    certInstance = instance;
    return certInstance.getParam2({from: owner});
}).then(function(_value){
    assert.equal(_value, "param2value", "modifier function returns correct value"
})
-1

Please check out this documentation

You should call as in that example. E.g:

return certificateInstance
   .ownerName
   .call()
   .then( ...
| improve this answer | |
  • Truffle has a different syntaxis than web3.js v1 more like web3.js v0.20. – Ismael Oct 24 '18 at 16:38
  • @Ismael that's correct, but how it's related to my answer. In question it's being asked why this is not working in browser with web3 & I replied why. – petro.sidlovskyy Oct 24 '18 at 20:12

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.