Using openzeppelin library and truffle I am trying to make a Contract Factory that creates ERC20 tokens. I prefer to test it with Truffle using solidity and not javascript.
Here is the code from the Contract
pragma solidity ^0.4.24;
import "zos-lib/contracts/migrations/Migratable.sol";
import "openzeppelin-solidity/contracts/token/ERC20/StandardToken.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
contract TokenFactory is Migratable {
address[] public deployedTokens;
function createToken(string name, string symbol) public {
address newToken = new Token(name,symbol,msg.sender);
deployedTokens.push(newToken);
}
function getDeployedTokens() public view returns (address[]) {
return deployedTokens;
}
}
contract Token is StandardToken, Ownable {
string public name = "";
string public symbol = "";
uint public decimals = 2;
uint public INITIAL_SUPPLY = 10000 * (10 ** decimals);
constructor(string _name, string _symbol, address creator) {
owner = creator;
name = _name;
symbol = _symbol;
totalSupply_ = INITIAL_SUPPLY;
}
}
and the Test
pragma solidity ^0.4.24;
import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/TokenFactory.sol";
contract TestTokenFactory {
TokenFactory tk = TokenFactory(DeployedAddresses.TokenFactory());
function testChildContractDeployed() public {
tk.createToken("xxx","sym");
address[] memory deployedTokens = tk.getDeployedTokens();
Assert.equal(deployedTokens.length, 1, "Contact is not deployed");
}
}
my truffle.js
'use strict';
module.exports = {
networks: {
local: {
host: 'localhost',
port: 7545,
gas: 6000000,
gasPrice:1,
network_id: '*'
}
}
};
and the error after running truffle test --network local
1) TestTokenFactory "before all" hook: prepare suite: Error: VM Exception while processing transaction: out of gas