简体   繁体   English

使用Web3智能合约时,Mocha测试在完成后会挂起

[英]Mocha tests hang after completion when working with web3 smart contracts

I wrote some integration tests for a node app that works with Ethereum smart contracts (and thus use the contracts' state as a data storage). 我为与以太坊智能合约兼容(因此将合约状态用作数据存储)的节点应用编写了一些集成测试。 I am instantiating some smart contracts interfaces using web3 and in the assertion parts of the tests I am using them to check that valid information has been written to the blockchain. 我正在使用web3实例化一些智能合约接口,并在测试的断言部分中使用它们来检查是否已将有效信息写入到区块链中。

However after the tests pass the mocha process is still running and I have to shut it down manually. 但是,通过测试后,mocha程序仍在运行,我必须手动将其关闭。 I suspect this happens because the smart contract interfaces are basically open connections and they are not closed, I know it happens when you do the same with normal database connections (see here: Mocha hangs after execution when connecting with Mongoose ). 我怀疑发生这种情况是因为智能合约接口基本上是开放的连接,并且它们不是关闭的,我知道当您对普通数据库连接执行相同操作时会发生这种情况(请参阅此处: 与Mongoose连接时Mocha在执行后会挂起 )。

I didn't find any disconnect or similar web3 api methods though, anyone had any similar experience with this? 我没有找到任何disconnect或类似的web3 api方法,有人对此有任何类似的经验吗?

有人指出我有一个--exit标志,您可以将其传递给mocha,它会在所有测试完成运行后--exit进程,这可能是目前足够好的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM