Solidity

Hardhar 測試錯誤:缺少參數

  • March 9, 2022

我在執行安全帽測試期間遇到缺少參數錯誤。下面是觸發錯誤的腳本。我的函式 MINT 只有 1 個參數可以傳入,並且正在將數字“1”傳遞給 mint 函式。請注意

在此處輸入圖像描述

測試腳本

it("Should mint an ape", async () => {
   await FTPContract.setSaleState();
   const mintPrice = await FTPContract.MINT_PRICE();

   expect(
     await FTPContract.mint(1, {             <———  ************* passing number ‘1’
       value: mintPrice, })
   )
     console.log(`
     price: ${mintPrice}
    `);
 });

這是我的 sol 函式 mint :

function mint(uint numberOfTokens) public payable {     <——— *******Has 1 arguments
       uint256 ts = totalSupply();
       require(saleIsActive, "Sale must be active to mint tokens");
       require(numberOfTokens <= MAX_PUBLIC_MINT, "Exceeded max token purchase");
       require(ts + numberOfTokens <= MAX_SUPPLY, "Purchase would exceed max tokens");
   
       require(MINT_PRICE.mul(numberOfTokens) <= msg.value, "Ether value sent is not correct");

       for (uint i = 0; i < numberOfTokens; i++) {
            uint mintIndex = totalSupply(); /*follow BAYC mintape function*/
           if (totalSupply() < MAX_SUPPLY) {
           _safeMint(msg.sender, mintIndex);
        
          }
       }

setSaleState 函式攜帶布爾值。所以我 chg 到下面。

await FTPContract.setSaleState('true');

完畢 。傳入了錯誤的參數

引用自:https://ethereum.stackexchange.com/questions/123219