使用 Hardhat 的 expectEvent 需要一个 `never` 类型的参数。

huangapple go评论133阅读模式
英文:

Using expectEvent with hardhat requires an argument of type `never`

问题

I get that this has the type const resp0: Truffle.TransactionResponse<never>. Now when I want to test whether an event was triggered, I use

我了解,这具有类型 const resp0: Truffle.TransactionResponse<never>。现在,当我想要测试事件是否已触发时,我使用

expectEvent(resp0, "AgentRedemptionInCollateral", { _amountUBA: fassets0 });

but it tells me the argument "AgentRedemptionInCollateral" is expected to be of type never. How can I fix this?

但它告诉我参数 "AgentRedemptionInCollateral" 应该是类型 never。我该如何修复这个问题?

The expectEvent is imported as

expectEvent 是作为导入的:

import { expectEvent } from "@openzeppelin/test-helpers";

Is it a problem that a function emitting an event is in another contract that is getting called by collateralPool.

一个发出事件的函数位于 collateralPool 调用的另一个合同中,这是否有问题。

英文:

When I make a contract call with hardhat

const resp0 = await collateralPool.selfCloseExit(tokenShare0, true, TokenExitType.MINIMIZE_FEE_DEBT, &quot;&quot;, { from: accounts[0] });

I get that this has the type const resp0: Truffle.TransactionResponse&lt;never&gt;. Now when I want to test whether an event was triggered, I use

expectEvent(resp0, &quot;AgentRedemptionInCollateral&quot;, { _amountUBA: fassets0 });

but it tells me the argument "AgentRedemptionInCollateral" is expected to be of type never. How can I fix this? The expectEvent is imported as

import { expectEvent } from &quot;@openzeppelin/test-helpers&quot;;

Is it a problem that a function emitting an event is in another contract that is getting called by collateralPool.

答案1

得分: 1

在搜索在线内容时,我发现其他人在TypeScript中使用这个包时也遇到了问题。我认为最简单的解决方法是添加 // @ts-ignore 或者像这样调用函数 (expectEvent as any)(resp0, "AgentRedemptionInCollateral", { _amountUBA: fassets0 });

英文:

When searching online I found that other people are also experiencing problems with this package in typescript I think the easiest way to fix this is by adding // @ts-ignore or by calling the function like (expectEvent as any)(resp0, &quot;AgentRedemptionInCollateral, { _amountUBA: fassets0 });

答案2

得分: 0

问题似乎是事件是通过不同的合同触发的,而最初调用的合同不同。使用expectEvent.inTransaction方法解决了这个问题。

英文:

The problem seemed to be that the event was triggered in a different contract, through the one that was called initially. Using method expectEvent.inTransaction solved the problem.

huangapple
  • 本文由 发表于 2023年3月7日 21:06:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75662377.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定