I want to send erc20 tokens to contract address which is able to trade the token.
However, I failed the test and error says
Error: VM Exception while processing transaction: revert
My function is this
TokenSale.sol
function startSale(address _tokenSaleContractAddress) public {
require(msg.sender == admin);
require(tokenContract.transfer(_tokenSaleContractAddress, 750000));
}
MyToken.sol
function transfer(address _to, uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value);
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
emit Transfer(msg.sender, _to, _value);
return true;
}
My test is this
it('facilitates start sale', function() {
return MyToken.deployed().then(function(instance) {
tokenInstance = instance;
return TokenSale.deployed()
}).then(function(instance) {
tokenSaleInstance = instance;
return tokenSaleInstance.startSale(tokenSaleInstance.address, {from: admin} )
}).then(function(receipt) {
return tokenInstance.balanceOf(tokenSaleInstance.address)
}).then(function(balance) {
assert.equal(balance.toNumber, 750000);
});
});
Could you give me any advise why I failed the test?
Admin has 1000000 tokens, and I want to send 750000 tokens to
TokenSale
contract.
To do this, the admin needs to call transfer
on the token contract. I.e. your test code should have this in it:
tokenInstance.transfer(tokenSaleInstance.address, 750000, { from: admin });
After that, calling startSale
should succeed, but there's no reason to call it because it's just transferring 750,000 tokens to itself.