1

I am not sure where I am going wrong, but I think it is within my const [owner, _] = ... area. I could be wrong, but I am not sure where, if anywhere I should be putting another argument, or inserting the abi string somewhere.

My test.js file:

const {ethers} = require("hardhat");
const {expect} = require("chai");

describe("BCCasino tests", () => {
    let token20, token721, token1155, casino;
    
    beforeEach(async () => {
        
        const Token20 = await ethers.getContractFactory();
        const Token721 = await ethers.getContractFactory();
        const Token1155 = await ethers.getContractFactory();

        const ContractFactory = await ethers.getContractFactory("BCCasino");

        token20 = await Token20.deploy();
        token721 = await Token721.deploy();
        token1155 = await Token1155.deploy();

        await token20.deployed();
        await token721.deployed();  
        await token1155.deployed();

        casino = await CasinoFactory.deploy(
            token20.address, 
            token721.address,
            token1155.address
        );

        await casino.deployed();
    
    });

    it("..should deploy correctly", async () => {
        //const parsedABI = JSON.parse("BCCasino");
        const [owner, _]= await ethers.getSigners();

        expect(await casino.owner()).to.equal(owner.address);
        expect(await casino.token20()).to.equal(token20.address);
        expect(await casino.token721()).to.equal(token721.address);
        expect(await casino.token1155()).to.equal(token1155.address);

        
    });
});

here is the .sol file:

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/utils/Counters.sol";

import "./BC1155.sol";
import "./BCNFT.sol";
import "./BCToken.sol";
import "./AccessControl.sol";


contract BCCasino is AccessControl {
    using Counters for Counters.Counter;

    BC1155 public token1155;
    BCNFT public token721;
    BCToken public token20;

    Counters.Counter public machineIdCounter;

    mapping(uint256 => uint256) public machineToAmount;
    mapping(address => mapping(uint256 => uint256)) public deposits;  //user --> machine -->  amount

    event Deposit(
        address indexed user,
        uint256 indexed machine,
        uint256 amount
    );

    event Reward(
        address indexed user,
        uint256 indexed rewardType,
        uint256 amount
    );

    constructor(address _token20, address _token721, address _token1155) {
        token20 = BCToken(_token20);
        token721 = BCNFT(_token721);
        token1155 = BC1155(_token1155);
    }
    function addMachine(uint256 amount) external onlyAdmin returns(bool) {
        require(amount > 0, "Invalid amount");
        uint256 machineId = machineIdCounter.current();
        machineToAmount[machineId] = amount;
        machineIdCounter.increment();
        return true;
    }

    function deposit(uint256 machineId) external returns(bool) {
        require(machineId <= machineIdCounter.current(), "Invalid Machine ID");
        address user = msg.sender;
        uint256 amount = machineToAmount[machineId];
        token20.transferFrom(user, address(this), amount);
        deposits[user][machineId] += amount;
        emit Deposit(user, machineId, amount);
        return true;
    }

    function reward(address user, 
                    uint256 amount, 
                    uint256 rewardType, 
                    uint256 machineId
    ) external onlyAdmin returns(bool) {
        require(rewardType < 3, "Invalid reward Type");
        require(
            deposits[user][machineId] >= machineToAmount[machineId],
            "User didn't make a deposit for the game. Invalid request"
        );

        deposits[user][machineId] -= machineToAmount[machineId];

        if(rewardType == 2) {
            token721.mint(user);
            emit Reward(user, 2, 1);
         } else if (rewardType == 1){
            token1155.mint(user, 1);
            emit Reward(user, 1, 1);
         } else {
            token20.mint(user, amount);
            emit Reward(user, 0, amount);
         }

         return true;
        }

    function totalMachine() external view returns(uint256) {
        return machineIdCounter.current();
    }
    }

Below is the error I'm getting:

 BCCasino tests
       "before each" hook for "..should deploy correctly":
     TypeError: abi is not iterable
      at addGasToAbiMethodsIfNecessary (node_modules\@nomiclabs\hardhat-ethers\src\internal\helpers.ts:409:28)
      at getContractFactoryByAbiAndBytecode (node_modules\@nomiclabs\hardhat-ethers\src\internal\helpers.ts:288:27)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at Context.<anonymous> (test\BCCasino.test.js:9:25)

Any help is much appreciated.

I fixed my code and inserted the string ABIs in the deploy statements, as suggested but now I get this error when I try to test.

  1) BCCasino tests
       "before each" hook for "..should deploy correctly":
     Error: missing argument:  in Contract constructor (count=0, expectedCount=1, code=MISSING_ARGUMENT, version=contracts/5.7.0)
      at Logger.makeError (node_modules\@ethersproject\logger\src.ts\index.ts:269:28)
      at Logger.throwError (node_modules\@ethersproject\logger\src.ts\index.ts:281:20)
      at Logger.checkArgumentCount (node_modules\@ethersproject\logger\src.ts\index.ts:340:18)
      at ContractFactory.<anonymous> (node_modules\@ethersproject\contracts\src.ts\index.ts:1237:16)
      at step (node_modules\@ethersproject\contracts\lib\index.js:48:23)
      at Object.next (node_modules\@ethersproject\contracts\lib\index.js:29:53)
      at C:\Users\smart\WEB3-GAME\Contracts\node_modules\@ethersproject\contracts\lib\index.js:23:71
      at new Promise (<anonymous>)
      at __awaiter (node_modules\@ethersproject\contracts\lib\index.js:19:12)
      at ContractFactory.deploy (node_modules\@ethersproject\contracts\lib\index.js:1138:16)

here is updated test.js file.

const {ethers} = require("hardhat");
const {expect} = require("chai");

describe("BCCasino tests", () => {
    let token20, token721, token1155, casino;
    
    beforeEach(async () => {
        
        const Token20 = await ethers.getContractFactory("BCToken");
        const Token721 = await ethers.getContractFactory("BCNFT");
        const Token1155 = await ethers.getContractFactory("BC1155");
        const CasinoFactory = await ethers.getContractFactory("BCCasino");  

        

        token20 = await Token20.deploy();
        token721 = await Token721.deploy();
        token1155 = await Token1155.deploy();

        await token20.deployed();
        await token721.deployed();  
        await token1155.deployed();

        casino = await CasinoFactory.deploy(
            token20.address, 
            token721.address,
            token1155.address
        );

        await casino.deployed();
    
    });

    it("..should deploy correctly", async () => {
        //const parsedABI = JSON.parse("BCCasino");
        const [owner, _]= await ethers.getSigners();

        expect(await casino.owner()).to.equal(owner.address);
        expect(await casino.token20()).to.equal(token20.address);
        expect(await casino.token721()).to.equal(token721.address);
        expect(await casino.token1155()).to.equal(token1155.address);

        
    });
});

3 Answers 3

0

you are not passing the contract name to the getContractFactory thats why you have the error, you just have to provide the name of the contract you want to deploy with that factory.

here is your updated test.js file

const Token20 = await ethers.getContractFactory("BCToken");
const Token721 = await ethers.getContractFactory("BCNFT");
const Token1155 = await ethers.getContractFactory("BC1155");
const CasinoFactory = await ethers.getContractFactory("BCCasino");
1
  • Thank you. I did that and now I am getting the following error message........... "before each" hook for "..should deploy correctly": Error: missing argument: in Contract constructor (count=0, expectedCount=1, code=MISSING_ARGUMENT, version=contracts/5.7.0) Jun 2, 2023 at 14:56
0

for the error, Error: missing argument: in Contract constructor (count=0, expectedCount=1, code=MISSING_ARGUMENT, version=contracts/5.7.0) you need to pass in a constructor in the test cos there is a constructor in you .sol code

0

i had the same problem when traying to call methods from a smart contract, getting this error.

for (const a of abi) {
                        ^

TypeError: abi is not iterable

the solution was simple, when you deploy your contract, the abi is save in the artifacts folder root/artifacts/contractName.sol/contractName.json

the abi should be a list of objets, not at object, so the default abi looks like this.

{
  "_format": "hh-sol-artifact-1",
  "contractName": "coinRoll",
  "sourceName": "contracts/coinroll.sol",
  "abi": [
    {
      "inputs": [],
      "stateMutability": "nonpayable",
      "type": "constructor"
    },
    {
      "inputs": [],
      "name": "amountCantBeZero",
      "type": "error"
    },
     //rest of the abi ///
  ],
  "bytecode": “0x60806///",
  "linkReferences": {},
  "deployedLinkReferences": {}
}

so just stay with the value of the key abi like so.

[
    {
      "inputs": [],
      "stateMutability": "nonpayable",
      "type": "constructor"
    },
    {
      "inputs": [],
      "name": "amountCantBeZero",
      "type": "error"
    },
     //rest of the abi ///
  ]

that should fix the problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.