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;
}
...
}
changeCreator
function (or at least its signature) in the code