1
    Deployment
      √ Should set the contract's address as owner (44ms)
      √ Should assign the totalSupply of credits to the creditsContract (114ms)
    Transactions
      1) Should fail if sender doesn't have enough tokens
      2) Should fail when user tries to access contract approve without access


  2 passing (5s)
  2 failing

  1) Credits.sol: Uint Tests
       Transactions
         Should fail if sender doesn't have enough tokens:
     AssertionError: Expected transaction to be reverted with Not enough tokens, but other exception was thrown: Error: insufficient funds for intrinsic transaction cost (error="Error: VM Exception while processing transaction: revert insufficient funds, revert", method="sendTransaction", transaction=undefined, code=INSUFFICIENT_FUNDS, version=providers/5.0.17)


  2) Credits.sol: Uint Tests
       Transactions
         Should fail when user tries to access contract approve without access:
     AssertionError: Expected transaction to be reverted with No access, but other exception was thrown: Error: invalid ENS name (argument="name", value="<SignerWithAddress 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266>", code=INVALID_ARGUMENT, version=providers/5.0.17)

The errors appear with the following code, however I don't know how to add eth to the accounts :/ Any suggestions?

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

describe("Credits.sol: Uint Tests", () => {
    let Credits, credits, addr1, addr2, addr3, addr4;

    beforeEach(async () => {
        Credits = await ethers.getContractFactory("Credits");
        credits = await Credits.deploy();
        [addr1, addr2, addr3, addr4, _] = await ethers.getSigners();
    });

    describe("Deployment", () => {
        it("Should set the contract's address as owner", async () => {
            expect(await credits.creditsContract()).to.equal(credits.address);
        });

        it("Should assign the totalSupply of credits to the creditsContract", async () => {
            let creditsContractBal = await credits.balanceOf(credits.address);
            expect(await credits.remainingUnheldCredits()).to.equal(creditsContractBal);
        });
    });

    describe("Transactions", () => {
        // it("Should use transfer() to send tokens from addr1 to addr2", async () => {
        //     credits.contractApprove(credits.address, addr1, 100);
        //     await credits.connect(addr1).transfer(addr2.address, 50);
        //     let addr2Balance = await credits.balanceOf(addr2.address);
        //     expect(addr2Balance).to.equal(50);
        //     expect(credits.balanceOf(addr1.address)).to.equal(0);
        // });

        // it("Should transfer tokens from addr1 to addr2", async () => {
        //     // Transfer from addr1 to addr2
        //     await token.connect(addr1).transfer(addr2.address, 50);
        //     let addr2Balance = await token.balanceOf(addr2.address);
        //     expect(addr2Balance).to.equal(50);
        //     addr1Balance = await token.balanceOf(addr1.address);
        //     expect(addr1Balance).to.equal(0);
        // });

        it("Should fail if sender doesn't have enough tokens", async () => {
            const initalCreditsSupply = await credits.balanceOf(credits.address);

            await expect(credits.connect(addr1).transfer(credits.address, 1)).to.be.revertedWith("Not enough tokens");
            expect(await credits.balanceOf(credits.address)).to.equal(initalCreditsSupply);
        });


        it("Should fail when user tries to access contract approve without access", async () => {
            await expect(credits.connect(addr1).contractApprove(credits.address, addr1, 100)).to.be.revertedWith("No access");
            expect(await credits.users[credits.address].allowance[addr1]).to.equal(0);
        });
        // it("Should update balances after transfers", async () => {
        //     const initialOwnerBalance = await token.balanceOf(owner.address);

        //     await token.transfer(addr1.address, 100);
        //     await token.transfer(addr2.address, 50);

        //     const finalOwnerBalance = await token.balanceOf(owner.address);
        //     expect(finalOwnerBalance).to.equal(initialOwnerBalance - 150);

        //     const addr1Balance = await token.balanceOf(addr1.address);
        //     expect(addr1Balance).to.equal(100);

        //     const addr2Balance = await token.balanceOf(addr2.address);
        //     expect(addr2Balance).to.equal(50);
        // });
    });

    // describe("", () => {
    //     it("Should fail if sender doesn't have enough tokens", async () => {
    //         const initialOwnerBalance = await token.balanceOf(owner.address);

    //         await expect(token.connect(addr1).transfer(owner.address, 1)).to.be.revertedWith("Not enough tokens");
    //         expect(await token.balanceOf(owner.address)).to.equal(initialOwnerBalance);
    //     });
    // });
}); ```
1
  • The accounts returned by ethers.getSigners are initialized with 10000 ETH each, unless you modified the default accounts in your config. Can you paste your hardat.config.js too? Jan 29 '21 at 19:48
0

Should work if you replace the to.be.revertedWith with to.be.reverted

0

This happens to me and I don't know how to solve it. I'm testing a bank using ethers

console.log("  ===== Bank---> admin.getBalance(): " + (await adminSigner.getBalance()));

The output is the following

===== Bank---> admin.getBalance(): 9999979959057829397771

Yet the message error suggests admin does not have any Ethers:

Error: VM Exception while processing transaction: reverted with reason string 'ERC20: transfer amount exceeds balance'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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