1

I'm writing test for MAX_SUPPLY of this function

// contract.sol

function mintStandard() public payable whenNotPaused {
        require(
            _standardCounter.current() <= 2222,
            "Sorry we reach max supply"
        );
        require(
            balanceOf(msg.sender, STANDARD) == 0,
            "You can only own 1 Standard NFT"
        );
        require(msg.value == 0.25 ether, "insufficient balance");
        _mint(msg.sender, STANDARD, 1, "0x00");
        _standardCounter.increment();
    }

// test.js

const { expect, assert } = require('chai');
const { loadFixture } = require("@nomicfoundation/hardhat-network-helpers");
const { ethers } = require('hardhat');
require('dotenv').config()

describe('NFT contract function test', function() {
    async function deployContract() {
        const [ owner, signer ] = await ethers.getSigners();
    
        const NFT = await ethers.getContractFactory('NFT');
        const nft = await NFT.deploy();

        const price = ethers.utils.parseEther("0.25");

        return {nft, owner, signer, price };
    }

    it('Should let mint only 2222 NFT', async function () {
            const {owner, nft, price} = await loadFixture(deployContract);

            const hdNode = await ethers.utils.HDNode.fromMnemonic(process.env.SEED_PHRASE)
        
            for (let i = 0; i < 2222; i++) {
                const signers = await ethers.getSigner(hdNode.derivePath(`m/44'/60'/0'/0/${i}`).address);

                console.log('creating signer: ', signers.address)

                const tx = {
                    to: signers.address,
                    value: ethers.utils.parseEther("1")
                }
                console.log('creating transaction: ', tx)

                const txn = await owner.sendTransaction(tx);
                console.log('Mining transaction...')

                await txn.wait()
                console.log('Transaction mined!')

                await nft.connect(signers).mintStandard({value:price})
                console.log('Minting nft')

                expect(await nft.balanceOf(signer.address, 0)).to.be.equal(1);
            }

        })
    })

keep getting this error

InvalidInputError: unknown account 0x4f099cfbc4043e60c52ef47ebc593ba0bda5c85e
      at HardhatNode.getSignedTransaction (/home/dtnwen/learn/diploma/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:481:11)
      at EthModule._sendTransactionAction (/home/dtnwen/learn/diploma/node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:1046:33)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at runNextTicks (node:internal/process/task_queues:64:3)
      at listOnTimeout (node:internal/timers:538:9)
      at processTimers (node:internal/timers:512:7)
      at HardhatNetworkProvider.request (/home/dtnwen/learn/diploma/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:123:18)
      at EthersProviderWrapper.send (/home/dtnwen/learn/diploma/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)

when I tried to debug, I find out that my signers instance get from const signers = await ethers.getSigner(hdNode.derivePath(`m/44'/60'/0'/0/${i}`).address); doesn't have fields:

_network: { chainId: 31337, name: 'unknown' },
    _internalBlockNumber: Promise { [Object] },
    _fastBlockNumber: 0,
    _fastBlockNumberPromise: Promise { 0 }

Is that the problem? If not then why?

// console

creating signer:  0x4f099cFbC4043e60c52EF47EBC593ba0Bda5C85e
creating transaction:  {
  to: '0x4f099cFbC4043e60c52EF47EBC593ba0Bda5C85e',
  value: BigNumber { value: "1000000000000000000" }
}
Mining transaction...
Transaction mined!
      1) Should let mint only 2222 NFT

error at await nft.connect(signers).mintStandard({value:price})

// signers instance

SignerWithAddress {
  _isSigner: true,
  address: '0x4f099cFbC4043e60c52EF47EBC593ba0Bda5C85e',
  _signer: JsonRpcSigner {
    _isSigner: true,
    provider: EthersProviderWrapper {
      _isProvider: true,
      _events: [],
      _emitted: [Object],
      disableCcipRead: false,
      formatter: [Formatter],
      anyNetwork: false,
      _networkPromise: [Promise],
      _maxInternalBlockNumber: -1024,
      _lastBlockNumber: -2,
      _maxFilterBlockRange: 10,
      _pollingInterval: 4000,
      _fastQueryDate: 0,
      connection: [Object],
      _nextId: 42,
      _hardhatProvider: [BackwardsCompatibilityProviderAdapter],
      _eventLoopCache: [Object]
    },
    _address: '0x4f099cFbC4043e60c52EF47EBC593ba0Bda5C85e',
    _index: null
  },
  provider: EthersProviderWrapper {
    _isProvider: true,
    _events: [],
    _emitted: { block: -2 },
    disableCcipRead: false,
    formatter: Formatter { formats: [Object] },
    anyNetwork: false,
    _networkPromise: Promise { <pending> },
    _maxInternalBlockNumber: -1024,
    _lastBlockNumber: -2,
    _maxFilterBlockRange: 10,
    _pollingInterval: 4000,
    _fastQueryDate: 0,
    connection: { url: 'http://localhost:8545' },
    _nextId: 42,
    _hardhatProvider: BackwardsCompatibilityProviderAdapter {
      _wrapped: [FixedGasProvider],
      _provider: [FixedGasProvider],
      sendAsync: [Function: bound sendAsync],
      send: [Function: bound send],
      _sendJsonRpcRequest: [Function: bound _sendJsonRpcRequest] AsyncFunction
    },
    _eventLoopCache: { detectNetwork: [Promise] }
  }
}

// owner instance

SignerWithAddress {
  _isSigner: true,
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  _signer: JsonRpcSigner {
    _isSigner: true,
    provider: EthersProviderWrapper {
      _isProvider: true,
      _events: [],
      _emitted: [Object],
      disableCcipRead: false,
      formatter: [Formatter],
      anyNetwork: false,
      _networkPromise: [Promise],
      _maxInternalBlockNumber: 0,
      _lastBlockNumber: -2,
      _maxFilterBlockRange: 10,
      _pollingInterval: 4000,
      _fastQueryDate: 1684145659967,
      connection: [Object],
      _nextId: 42,
      _hardhatProvider: [BackwardsCompatibilityProviderAdapter],
      _eventLoopCache: [Object],
      _network: [Object],
      _internalBlockNumber: [Promise],
      _fastBlockNumber: 0,
      _fastBlockNumberPromise: [Promise]
    },
    _address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
    _index: null
  },
  provider: EthersProviderWrapper {
    _isProvider: true,
    _events: [],
    _emitted: {
      block: -2,
      't:0x4d9029bee75a2f2954c2fc9e28c9f5354a7b5132bcf1463bf2a1b2e5a5010b67': 1,
      't:0xcec1b3b6782ff589a95ec5a60f5959c099787ba2416b1b102e0f7cfefcef3444': 2
    },
    disableCcipRead: false,
    formatter: Formatter { formats: [Object] },
    anyNetwork: false,
    _networkPromise: Promise { [Object] },
    _maxInternalBlockNumber: 0,
    _lastBlockNumber: -2,
    _maxFilterBlockRange: 10,
    _pollingInterval: 4000,
    _fastQueryDate: 1684145659967,
    connection: { url: 'http://localhost:8545' },
    _nextId: 42,
    _hardhatProvider: BackwardsCompatibilityProviderAdapter {
      _wrapped: [FixedGasProvider],
      _provider: [FixedGasProvider],
      sendAsync: [Function: bound sendAsync],
      send: [Function: bound send],
      _sendJsonRpcRequest: [Function: bound _sendJsonRpcRequest] AsyncFunction
    },
    _eventLoopCache: { detectNetwork: [Promise] },
    _network: { chainId: 31337, name: 'unknown' },
    _internalBlockNumber: Promise { [Object] },
    _fastBlockNumber: 0,
    _fastBlockNumberPromise: Promise { 0 }
  }
}

0

Your Answer

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

Browse other questions tagged or ask your own question.