Invalid number of parameters for Crowdsale test

See this mistake more 2 days cant understand

  0 passing (347ms)
  2 failing

  1) Crowdsale
       requires a non-null token:

      Wrong kind of exception received
      + expected - actual

      -Invalid number of parameters for "undefined". Got 3 expected 6!
      +Crowdsale: token is the zero address
"use strict";

const TokenGRAV = artifacts.require("../TokenGRAV");
const ICO = artifacts.require('../ICO');


module.exports = async function (deployer) {
    const initialSupply = web3.utils.toWei('10000', 'ether'); // 10 m
    const openingTime = 1606660200;
    const closingTime = 1606694400;
    const wallet = '0x72c5AEa64e256df193dCf241bC532339BEbB0235';
    const rate = '1000000000000000000'; //5000000000000000000000000000000000
    const cap = web3.utils.toWei('10', 'ether');
    
    //Token

    await deployer.deploy(
        TokenGRAV,   
        initialSupply
    );
    const token = await TokenGRAV.deployed();
        
    // ICO
    await deployer.deploy(
        ICO,
        openingTime,
        closingTime,
        rate,
        wallet,
        token.address,
        cap
    );
    const ico = await ICO.deployed();
    await token.updateAdmin(ico.address);
};

Please provide more details

pragma solidity >=0.4.22 <0.8.0;

import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
import '@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol';
import '@openzeppelin/contracts/token/ERC20/ERC20Pausable.sol';

contract TokenGRAV is ERC20, ERC20Detailed, ERC20Pausable {

  address public admin;

  constructor(
    uint256 initialSupply
  ) ERC20Detailed("Gravitation", "GRA", 18) public{
    admin = msg.sender;
    _mint(msg.sender, initialSupply);
  }
  
  function updateAdmin(address newAdmin) external {
    require(msg.sender == admin, 'admin');
    admin = newAdmin;
  }
}

Crowdsale

pragma solidity >=0.4.22 <0.8.0;

import '@openzeppelin/contracts/crowdsale/Crowdsale.sol';
import '@openzeppelin/contracts/crowdsale/validation/CappedCrowdsale.sol';
import '@openzeppelin/contracts/crowdsale/validation/TimedCrowdsale.sol';
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '../contracts/TokenGRAV.sol';

contract ICO is Crowdsale, CappedCrowdsale, TimedCrowdsale {

    address public admin;

    constructor( 
        uint256 openingTime,     // opening time in unix epoch seconds
        uint256 closingTime,     // closing time in unix epoch seconds
        uint256 rate,
        address payable wallet,  // wallet to send Ether
        IERC20 token,            // the token
        uint256 cap             // total cap, in wei
                  
    )
        CappedCrowdsale(cap)
        TimedCrowdsale(openingTime, closingTime)
        Crowdsale(rate, wallet, token)
        public
        {
        admin = msg.sender;
        // nice, we just created a crowdsale that's only open
        // for a certain amount of time
        // and stops accepting contributions once it reaches `cap`

    }

    modifier onlyAdmin() {
        require(msg.sender == admin, 'admin');
        _;
    }

}

deploy js

const TokenGRAV = artifacts.require("../TokenGRAV");
const ICO = artifacts.require('../ICO');


module.exports = async function (deployer) {
    const initialSupply = web3.utils.toWei('10000', 'ether'); // 10 m
    const openingTime = 1606660200;
    const closingTime = 1606694400;
    const wallet = '0x72c5AEa64e256df193dCf241bC532339BEbB0235';
    const rate = '1000000000000000000'; //5000000000000000000000000000000000
    const cap = web3.utils.toWei('5000', 'ether');
    
    //Token

    await deployer.deploy(
        TokenGRAV,   
        initialSupply
    );
    const token = await TokenGRAV.deployed();
        
    // ICO
    await deployer.deploy(
        ICO,
        openingTime,
        closingTime,
        rate,
        wallet,
        token.address,
        cap
    );
    const ico = await ICO.deployed();
    await token.updateAdmin(ico.address);
};

test show

  1) Crowdsale
       with token
         "before each" hook for "requires a non-zero rate":
     Error: Invalid number of parameters for "undefined". Got 0 expected 1!
     at PromiEvent (node_modules/@truffle/contract/lib/promievent.js:9:30)
      at /home/asven/projects/icoProgect/node_modules/@truffle/contract/lib/execute.js:223:26
      at Function.new (node_modules/@truffle/contract/lib/contract/constructorMethods.js:57:53)
      at Context.<anonymous> (test/test.js:36:41)
      at processImmediate (internal/timers.js:456:21)

it migrate to ganache but crowdsale not send tokens

sorry forget test

const { accounts, contract } = require('@openzeppelin/test-environment');

const { balance, BN, constants, ether, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;

const { expect } = require('chai');

const Crowdsale = contract.fromArtifact('ICO');
const SimpleToken = contract.fromArtifact('TokenGRAV');

describe('Crowdsale', function () {
  const [ investor, wallet, purchaser ] = accounts;

  const value = ether('10');
  const tokenSupply = web3.utils.toWei('10000', 'ether');
  const openingTime = 1606660200;
  const closingTime = 1606694400;
  const rate = '1000000000000000000';
  const cap = web3.utils.toWei('5000', 'ether');
//   const rate = new BN(1);
//   const value = ether('42');
//   const tokenSupply = new BN('10').pow(new BN('22'));
//   const expectedTokenAmount = rate.mul(value);

  it('requires a non-null token', async function () {
    await expectRevert(
      Crowdsale.new(openingTime, closingTime, rate, wallet, ZERO_ADDRESS, cap),
      'Crowdsale: token is the zero address'
    );
  });

  context('with token', async function () {
    beforeEach(async function () {
      this.token = await SimpleToken.new();
    });

    it('requires a non-zero rate', async function () {
      await expectRevert(
        Crowdsale.new(0, wallet, this.token.address), 'Crowdsale: rate is 0'
      );
    });
1 Like

It seems like you do not pass this parameter as requirement.

1 Like

It is in the test or mistake in deploy crowdsale?

1 Like

Hi @asven-2020,

If looks like your token takes a supply parameter but in your test you don’t provide this:

  context('with token', async function () {
    beforeEach(async function () {
      this.token = await SimpleToken.new();
    });

yes thank you for replay

2 Likes