Ganache
松露不能同時執行兩個文件
我的測試文件夾中有兩個文件,當我執行時,
truffle test
我得到了第一個文件的結果,但是當它到達第二個文件時,ganache 失敗了,我得到了下面的錯誤。我試過一次只放置一個文件並執行,它對它們都執行良好,但不能一起執行。ProviderError: Could not connect to your Ethereum client with the following parameters: - host > 127.0.0.1 - port > 7545 - network_id > 5777 Please check that your Ethereum client: - is running - is accepting RPC connections (i.e., "--rpc" or "--http" option is used in geth) - is accessible over the network - is properly configured in your Truffle configuration file (truffle-config.js) at C:\Users\AH30007\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\provider\wrapper.js:73:1 at C:\Users\AH30007\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\provider\wrapper.js:102:1 at XMLHttpRequest.request.onreadystatechange (C:\Users\AH30007\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\web3\node_modules\web3-providers-http\lib\index.js:98:1) at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\AH30007\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\xhr2-cookies\dist\xml-http-request-event-target.js:34:1) at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._setReadyState (C:\Users\AH30007\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\xhr2-cookies\dist\xml-http-request.js:208:1) at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._onHttpRequestError (C:\Users\AH30007\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\xhr2-cookies\dist\xml-http-request.js:349:1) at ClientRequest.<anonymous> (C:\Users\AH30007\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\xhr2-cookies\dist\xml-http-request.js:252:47) at Socket.socketOnEnd (_http_client.js:493:9) at endReadableNT (internal/streams/readable.js:1327:12) at processTicksAndRejections (internal/process/task_queues.js:80:21)
Ganache 失敗並拋出此錯誤
TypeError: Cannot read property 'transactions' of null at ProjectsWatcher.handleBlock (C:\Users\AH30007\AppData\Local\Programs\Ganache\resources\static\node\truffle-integration\projectsWatcher.js:180:38) at processTicksAndRejections (internal/process/task_queues.js:93:5) at Subscription.<anonymous> (C:\Users\AH30007\AppData\Local\Programs\Ganache\resources\static\node\truffle-integration\projectsWatcher.js:57:9)
像這樣對測試文件進行編號 // 2_Test_First // 3_Test_Second 應該可以解決問題,松露很難辨別首先執行哪個文件,因此通過對其進行編號,您可以告訴它以什麼順序執行。
希望這可以幫助
它可以是對合約函式的呼叫,而無需等待,也可以是對函式的另一個呼叫:
//it's gonna crash web3.eth.sendTransaction({from:accounts[0], to:accounts[1], value: web3.utils.toWei("2", "ether")}); let b = await web3.eth.getBalance(accounts[1]);
正確的方法:
await web3.eth.sendTransaction({from:accounts[0], to:accounts[1], value: web3.utils.toWei("2", "ether")}); let b = await web3.eth.getBalance(accounts[1]);