Truffle v5.0.5 (core: 5.0.5)
Solidity v0.5.0 (solc-js)
Node v10.15.1

ReferenceError: address is not defined.

const ApprovalContracts = artifacts.require('../../contracts/ApprovalContracts.sol'); // Pulls in my smart contract // the accounts are the 10 dummie ones
// the require pulls in the smart contract // the artifacts pulls in our code

contract ('ApprovalContracts', function (accounts) { // These are the accounts stored locally in the server the address
    //tests in javascript part of the contract //setup a contract and getting back the approver //takes a deposit im going to look and see what the balance is
    it('initiates contract', async function() { 
        const contract = await ApprovalContracts.deployed();
        const approver = await contract.approver.call(); 
        assert.equal(approver, 0xc7780C9521C2C2abED69f0D65BEbF9794C55ae94, "approvers don't match");

    it('takes a deposit', async function() {
        const balance = await web3.eth.getBalance(address.contract);  -----> ReferenceError: address is not defined
        const expected = web3.utils.toBN(1e+18);
        assert.equal(balance.toString(), expected.toString(), "amount did not match");

Any advice I would be much appreciated.

const balance = await web3.eth.getBalance(address.contract);
  • I dont understand. This is just a test code where is your actual code, what does deposit do? You cant show us a failed test case and ask what wrong? – haxerl Mar 15 at 1:25

You have two problems:

  • web3.eth.getBalance() returns an promiEvent object, to obtain the expected value you need to await for it
  • Javascript doesn't support large numbers, so values are wrapped in BN objects, and assert doesn't know how to compare those objects against numbers

One solution is converting BN objects to strings to compare them.

const balance = await web3.eth.getBalance(contract.address);
const expected = web3.utils.toBN(1e+18);
assert.equal(balance.toString(), expected.toString(), "amount did not match");
  • Thank you, I've been trying to fix this for a while.I got the error unfortunately. Error: Provided address "undefined" is invalid, the capitalization checksum test failed, or its an indrect IBAN address which can't be converted. Im having serious issues with out to make the rite corrections on code. Is there a way I can solve these challenges, or some kind of useful website – D6ix Mar 16 at 1:34
  • The only address used is contract.address, check the output of console.log(contract.address);. Unless contract is incorrectly initialized it should be a valid address. You can edit your question to add more details, like the contracts used and any other thing required to reproduce your error. Otherwise my answer is just try to guess. – Ismael Mar 16 at 3:23

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.