I have a smart contract for exchange USDT to QUE token with rate 1:1
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract Question is ERC20 {
address USDTAddress;
address BoxAddress;
constructor(address _USDTAddress) ERC20("Question", "QUE") {
USDTAddress = _USDTAddress;
BoxAddress = msg.sender;
}
function depositUSDT(uint _tokenAmount) public payable {
ERC20 USDTToken = ERC20(USDTAddress);
USDTToken.transferFrom(msg.sender, BoxAddress, _tokenAmount);
_mint(msg.sender, _tokenAmount);
}
}
And I wrote a test:
const { expect } = require("chai")
const { ethers, waffle } = require('hardhat')
const { deployContract } = waffle
// contracts
const QJson = require('../artifacts/contracts/Question.sol/Question.json')
const MockUSDT = require('../artifacts/contracts/mocks/mockUSDT.sol/MockUSDT.json')
describe('Question.sol', _ => {
it('Deposit USDT with Question.sol', async () => {
const [walletUSDT, walletMatrix] = await ethers.getSigners()
const tokenUSDT = await deployContract(walletUSDT, MockUSDT)
// I guess that walletMatrix is a BoxAddress in Question.sol
// and tokenUSDT.address is a _USDTAddress in a constructor of Question.sol
const tokenMatrix = await deployContract(walletMatrix, QJson, [
tokenUSDT.address,
])
// there I put deposit to walletMatrix.address
await tokenUSDT.connect(walletUSDT).transfer(walletMatrix.address, 11)
let balance = await tokenUSDT.balanceOf(walletMatrix.address)
expect(balance).to.equal(11) // ok
await tokenUSDT.approve(walletMatrix.address, 900)
// after line below I've got the error:
await tokenMatrix.connect(walletMatrix).depositUSDT(900)
// ERC20: transfer amount exceeds balance
// What's wrong?
// let matrixBalance = await tokenMatrix.balanceOf(walletMatrix.address)
// expect(matrixBalance).to.equal(amount2)
}).timeout(20000)
})
What I do wrong? Maybe I don't understand correctly values in my .sol and .js files?