Skip to main content
Bounty Ended with 100 reputation awarded by CommunityBot
deleted 478 characters in body
Source Link
Badr Bellaj
  • 18.8k
  • 4
  • 59
  • 75

ToIt took me some time to figure out what's wrong with you code (Thanks for the riddle). Here's how i get your test working i had to:

1- I've change truffle.js to following :

networks: {
    local: {
      host: 'localhost',
      port: 7545,
     // gas: 6000010,
     // gasPrice:10000000000,
      network_id: '*'
    }
  }

but instead out of gas i've got revert exception,

enter image description here

to deal with I've replaced :

TokenFactory(DeployedAddresses.TokenFactory());

by

new TokenFactory();

otherwise you have to add it to the deploymentcreated a migration script

as following (2_initial_migration.js):

    pragma solidityvar ^0.4.24;

importTokenFactory "truffle/Assert.sol";
import= "truffle/DeployedAddressesartifacts.sol";
import require("../contracts/TokenFactory.sol";

contract TestTokenFactory {sol");
 
TokenFactorymodule.exports tk=new= TokenFactory();
function testChildContractDeployed(deployer) public{
tk.createToken("xxx","sym");
address[] memory deployedTokens = tk.getDeployedTokens();
Assertdeployer.equaldeploy(deployedTokens.length, 1, "Contact is not deployed"TokenFactory);
 
}
   
};

then the test passed with success   

enter image description here

To get your test working i had to

1- change truffle.js to following :

networks: {
    local: {
      host: 'localhost',
      port: 7545,
     // gas: 6000010,
     // gasPrice:10000000000,
      network_id: '*'
    }
  }

but instead out of gas i've got revert exception,

enter image description here

to deal with I've replaced :

TokenFactory(DeployedAddresses.TokenFactory());

by

new TokenFactory();

otherwise you have to add it to the deployment script

as following :

    pragma solidity ^0.4.24;

import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/TokenFactory.sol";

contract TestTokenFactory {
 
TokenFactory tk=new TokenFactory();
function testChildContractDeployed() public{
tk.createToken("xxx","sym");
address[] memory deployedTokens = tk.getDeployedTokens();
Assert.equal(deployedTokens.length, 1, "Contact is not deployed");
 
}
   
}

the test passed with success  enter image description here

It took me some time to figure out what's wrong with you code (Thanks for the riddle). Here's how i get your test working :

1- I've change truffle.js to following :

networks: {
    local: {
      host: 'localhost',
      port: 7545,
     // gas: 6000010,
     // gasPrice:10000000000,
      network_id: '*'
    }
  }

but instead out of gas i've got revert exception,

enter image description here

to deal with I've created a migration script (2_initial_migration.js):

var TokenFactory = artifacts.require("./TokenFactory.sol");

module.exports = function(deployer) {
  deployer.deploy(TokenFactory);
};

then the test passed with success 

enter image description here

Source Link
Badr Bellaj
  • 18.8k
  • 4
  • 59
  • 75

To get your test working i had to

1- change truffle.js to following :

networks: {
    local: {
      host: 'localhost',
      port: 7545,
     // gas: 6000010,
     // gasPrice:10000000000,
      network_id: '*'
    }
  }

but instead out of gas i've got revert exception,

enter image description here

to deal with I've replaced :

TokenFactory(DeployedAddresses.TokenFactory());

by

new TokenFactory();

otherwise you have to add it to the deployment script

as following :

    pragma solidity ^0.4.24;

import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/TokenFactory.sol";

contract TestTokenFactory {
 
TokenFactory tk=new TokenFactory();
function testChildContractDeployed() public{
tk.createToken("xxx","sym");
address[] memory deployedTokens = tk.getDeployedTokens();
Assert.equal(deployedTokens.length, 1, "Contact is not deployed");

}
   
}

the test passed with success enter image description here