As I was going through the truffle test for the smart contract below to check if it has the owner address:

pragma solidity >=0.4.21 <0.7.0;

contract Owner {
    address public owner;
    address public nextOwner;
    constructor () public {
        owner = msg.sender;

it fails with the message below: after running the truffle test.

Using network 'development'.

Compiling your contracts...
> Compiling ./contracts/Owner.sol
> Artifacts written to /tmp/test-2020319-8538-1ih1ur3.6ijj
> Compiled successfully using:
   - solc: 0.5.16+commit.9c3226ce.Emscripten.clang

  Contract: Owner
    The attributes
      ✓ has the address
      1) has the owner
    > No events were emitted

  1 passing (406ms)
  1 failing

  1) Contract: Owner
       The attributes
         has the owner:

      has owner address
      + expected - actual


      at Context.it (test/DIce.js:21:20)
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:189:7)

It is clear that the actual and the expected was not equal.

The test script I was using is below:

const Owner = artifacts.require('./Owner.sol');

contract('Owner', accounts => {
    const owner = accounts[0];
    const nextOwner = accounts[1];

      describe('The attributes', () => {
        let ownerInstance;
        beforeEach(async () => {
            ownerInstance = await Owner.new();

        it('has the address', () => {
            const address = ownerInstance.address;
            assert.notEqual(address, '0x0', 'has contract address');

        it('has the owner', async () => {
            const address = await ownerInstance.nextOwner();
            assert.equal(address, owner, 'has owner address');



Could you please advice? I would appreciate discussions over this. Thanks.

  • In addition to the answer that I gave you, I also recommend that you fix assert.notEqual(address, '0x0', 'has contract address');, because the zero address is the string '0x' followed by 40 '0's, and this test will therefore always complete successfully, even when the contract doesn't yet have an address (so this test will not serve its purpose). Apr 19, 2020 at 14:44
  • Thanks for your answer @goodvibration, Theassert.notEqual(address, '0x0', 'has contract address'); return the exact contract address here. and As per your recommendation, I used the below: assert(address != "0x" + "0".repeat(40),'has contract address');, it passed. Thanks
    – Aldo
    Apr 19, 2020 at 14:58

1 Answer 1


Change this:


To this:


The nextOwner variable becomes non-zero only when the contract's ownership is transferred.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.