坚固 - 硬汉 - 无法测试合同

发布于 2025-02-10 19:49:58 字数 2414 浏览 2 评论 0原文

这是由于缺乏平衡而失败的测试

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

describe("TestBirds", function () {
    it ("Should return correct name, URI, owner and beneficiary", async function () {

        const [owner, addr1] = await hre.ethers.getSigners()
               
        provider = ethers.provider

        const TestBirdsContract = await hre.ethers.getContractFactory("TestBirds")
        const testBirdsContractDeployed = await TestBirdsContract.deploy(
            "TestBirds",
            "XXXX",
            "https://test.url/",
            owner.address,
            owner.address)

        console.log(await provider.getBalance(owner.address));
        await testBirdsContractDeployed.deployed()
        await testBirdsContractDeployed.mintPublic(owner.address)

        expect(await testBirdsContractDeployed.name()).to.equal("TestBirds")
        expect(await testBirdsContractDeployed.tokenURI(0), "https://test.url/0")
        expect(await testBirdsContractDeployed.ownerOf(0)).to.equal(owner.address)
    })
})

,在控制台日志上余额看起来还不错,但是测试失败了

TestBirds

BigNumber { value: "10000000000000000000000" }
    1) Should return correct name, URI, owner and beneficiary

  0 passing (788ms)
  1 failing

  1) TestBirds
       Should return correct name, URI, owner and beneficiary:
     Error: VM Exception while processing transaction: reverted with reason string 'Seller: Costs 2500000000 GWei'
      at TestBirds.onlyOwner (@openzeppelin/contracts/access/Ownable.sol:43)
      at TestBirds._purchase (@divergencetech/ethier/contracts/sales/Seller.sol:229)
      at TestBirds._purchase (@divergencetech/ethier/contracts/sales/Seller.sol:216)
      at TestBirds.mintPublic (contracts/TestBirds.sol:85)
      at HardhatNode._mineBlockWithPendingTxs (node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:1650:23)
      at HardhatNode.mineBlock (node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:459:16)
      at EthModule._sendTransactionAndReturnHash (node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:1496:18)
      at HardhatNetworkProvider.request (node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:117:18)
      at EthersProviderWrapper.send (node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)

我的余额超过2500000000 gwei,因此我不确定哪个问题是问题所在。

谢谢

This is the test that it is failing due to the lack of balance

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

describe("TestBirds", function () {
    it ("Should return correct name, URI, owner and beneficiary", async function () {

        const [owner, addr1] = await hre.ethers.getSigners()
               
        provider = ethers.provider

        const TestBirdsContract = await hre.ethers.getContractFactory("TestBirds")
        const testBirdsContractDeployed = await TestBirdsContract.deploy(
            "TestBirds",
            "XXXX",
            "https://test.url/",
            owner.address,
            owner.address)

        console.log(await provider.getBalance(owner.address));
        await testBirdsContractDeployed.deployed()
        await testBirdsContractDeployed.mintPublic(owner.address)

        expect(await testBirdsContractDeployed.name()).to.equal("TestBirds")
        expect(await testBirdsContractDeployed.tokenURI(0), "https://test.url/0")
        expect(await testBirdsContractDeployed.ownerOf(0)).to.equal(owner.address)
    })
})

The balance looks ok on the console log, but test fails on minting

TestBirds

BigNumber { value: "10000000000000000000000" }
    1) Should return correct name, URI, owner and beneficiary

  0 passing (788ms)
  1 failing

  1) TestBirds
       Should return correct name, URI, owner and beneficiary:
     Error: VM Exception while processing transaction: reverted with reason string 'Seller: Costs 2500000000 GWei'
      at TestBirds.onlyOwner (@openzeppelin/contracts/access/Ownable.sol:43)
      at TestBirds._purchase (@divergencetech/ethier/contracts/sales/Seller.sol:229)
      at TestBirds._purchase (@divergencetech/ethier/contracts/sales/Seller.sol:216)
      at TestBirds.mintPublic (contracts/TestBirds.sol:85)
      at HardhatNode._mineBlockWithPendingTxs (node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:1650:23)
      at HardhatNode.mineBlock (node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:459:16)
      at EthModule._sendTransactionAndReturnHash (node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:1496:18)
      at HardhatNetworkProvider.request (node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:117:18)
      at EthersProviderWrapper.send (node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)

I have more than 2500000000 GWei on my balance, so I am not sure which is the problem.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁把谁当真 2025-02-17 19:49:58

您目前没有为薄荷付费。
您需要在合同电话交易中积极发送铸造费。

await testBirdsContractDeployed.mintPublic(owner.address, {
      value: ethers.utils.parseEther("2.5"),
});

You are currently not paying for your mint.
You need to actively send the minting fee along the contract call transaction.

await testBirdsContractDeployed.mintPublic(owner.address, {
      value: ethers.utils.parseEther("2.5"),
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文