Truffle
松露測試期間未找到契約
我使用如下方式成功創建並部署了兩個合約(經過確認)
truffle migrate
:module.exports = function(deployer) { deployer.deploy(ReentrancyPot).then(async () => { deployer.deploy(ReentrancyAttack, ReentrancyPot.address); }) }
第二份契約依賴於第一份契約(摘自
ReentrancyAttack.sol
)contract ReentrancyAttack { ReentrancyPot public pot; function ReentrancyAttack (address _pot) public { pot = ReentrancyPot(_pot); } }
我正在對第一個契約進行測試並且它是成功的,但是,第二個契約顯示為未部署(
truffle.js
配置為指向埠8545
)var ReentrancyPot = artifacts.require("./ReentrancyPot.sol"); var ReentrancyAttack = artifacts.require("./ReentrancyAttack.sol"); var Web3 = require('web3'); var web3 = new Web3(Web3.givenProvider || 'ws://localhost:8545'); require('chai') .use(require('chai-as-promised')) .should(); contract('ReentrancyPot / ReentrancyAttack', function(accounts) { it("pot should support deposits and withdrawals", async () => { let pot = await ReentrancyPot.deployed(); let attack = await ReentrancyAttack.deployed(); }) })
執行後出現以下錯誤
truffle test
:Error: ReentrancyAttack has not been deployed to detected network (network/artifact mismatch)
你想要的是:
module.exports = function(deployer) { deployer.then(async () => { await deployer.deploy(ReentrancyPot); var reentrancyPotInstance = await ReentrancyPot.deployed(); await deployer.deploy(ReentrancyAttack, reentrancyPotInstance.address) }); }