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);
});
});