0

Am testing my smart contract using Hardhat, Waffle(beginner) and I can't understand why am getting Invalid ENS name error. 'Should only allow tokencreator to change token creator: AssertionError: Expected transaction to be reverted with Only current creator can change the creator, but other exception was thrown: Error: invalid ENS name (argument="name", value=undefined, code=INVALID_ARGUMENT, version=providers/5.3.1)'

I am referencing the address with alice.address syntax which should be correct no Below are snippets of the relevant part of my code.

const { ethers } = require("hardhat");
const {deployContract, MockProvider, solidity} = require('ethereum-waffle');
use(solidity);

describe("TokenFactory", async function () {
   beforeEach(async () => {
   [alice, bob, james] = await ethers.getSigners();
   });
 

  it('should change token creator successfully', async function () {
    const Token = await ethers.getContractFactory("Token");
    const tokenTemplate = await Token.deploy();
    await tokenTemplate.deployed()
    
    const TokenFactory = await ethers.getContractFactory("TokenFactory");
    const tokenFactory = await TokenFactory.deploy(tokenTemplate.address);
    await tokenFactory.deployed();

    const aliceToken = await tokenFactory.createToken("AliceToken", "AT");
    await tokenFactory.changeCreator(aliceToken.address, bob.address);

    await expect(tokenFactory.changeCreator(aliceToken.address, james.address)).to.be.revertedWith
    ('Only current creator can change the creator');

  })
   it('Should only allow tokencreator to change token creator', async function() {
    const Token = await ethers.getContractFactory("Token");
    const tokenTemplate = await Token.deploy();
    await tokenTemplate.deployed()
    
    const TokenFactory = await ethers.getContractFactory("TokenFactory");
    const tokenFactory = await TokenFactory.deploy(tokenTemplate.address);
    await tokenFactory.deployed();

    const aliceToken = await tokenFactory.createToken('AliceToken', 'AT');
     await expect(tokenFactory.connect(bob.address).changeCreator(aliceToken.address, alice)).to.be.revertedWith
    ('Only current creator can change the creator'); //getting error here
    await tokenFactory.changeCreator(aliceToken.address, bob.address);
    await tokenFactory.changeCreator(aliceToken.address, james.address);
  })

}); 

Here are the functions am testing from the Solidity file:

contract TokenFactory {
...

    struct TokenInfo {
        address token;
        address creator;
        address deployer;
    }

    // mapping for address to token info
    mapping(address => TokenInfo) public tokenInfos;

   function createToken(string calldata tokenName, string calldata tokenSymbol) external override returns (address) {
        return createTokenWithCreator(tokenName, tokenSymbol, msg.sender);
    }

    function createTokenWithCreator(string calldata tokenName, string calldata tokenSymbol, address creator) public override returns (address) {
        IToken token = IToken(Clones.clone(tokenTemplate));
        token.initialize(
            string(abi.encodePacked('Bull: ', tokenName)),
            string(abi.encodePacked('BULL_', tokenSymbol)),
            address(this)
        );

        TokenInfo memory tokenInfo = TokenInfo({
            token: address(token),
            creator: creator,
            deployer: msg.sender
        });

        tokenInfos[address(token)] = tokenInfo;

        emit NewToken(address(token), creator, msg.sender);

        // return token address
        return address(token);
    }


    function changeCreator(address token, address creator) external {
        require(creator != address(0x0), 'New creator must not be empty');

        TokenInfo memory tokenInfo = tokenInfos[token];
        require(tokenInfo.token != address(0x0), 'Token does not exist');
        require(tokenInfo.creator == msg.sender, 'Only current creator can change the creator');

        emit CreatorChanged(token, creator, tokenInfo.creator);
        tokenInfo.creator = creator;
    }
...
}
3
  • Please include your changeCreator function (or at least its signature) in the code Jun 29 '21 at 7:45
  • Added the function, and the struct and mapping which are referenced in the implementation
    – HallonDev
    Jun 29 '21 at 7:51
  • 1
    The stack trace should tell you which line in the test is throwing the error. And the message is saying (although quite cryptically) that you are passing an undefined value, where an address is expected. So you can start looking from there. Jul 2 '21 at 18:13
1

If I remember right, the getSigners() returns a list of objects (signers). Each of those objects also has a field address. So you most likely need to use that address field.

Furthermore, the connect function requires the signer, not the address.

So your line should be: await expect(tokenFactory.connect(bob).changeCreator(aliceToken.address, alice.address)).to.be.revertedWith('Only current creator can change the creator');

3
  • still getting the same error even after changing the syntax. I have added the functions am testing, maybe am doing it in the wrong way?
    – HallonDev
    Jun 29 '21 at 7:35
  • added one more correction to my answer Jun 29 '21 at 8:00
  • Seen it. The syntax is correct so not sure why it isn't working. I have even reframed the test with a new caase 'should change token creator successfully' and still getting same errors. Might it be I need to install some library? or my import statements are off?
    – HallonDev
    Jun 29 '21 at 8:15

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.