![](/img/trans.png)
[英]Testing Smart contract requires in Truffle: transaction reverted if function isnt void
[英]Testing Deployed Smart Contract on Truffle
我在使用松露测试合同时遇到问题。 我安装了最新版本的 truffle 以及 TestRPC。
据我了解,最新版本的 truffle 附带了一个用于测试 SmartContracts 的客户端,因此不再需要 TestRPC。
我有一个简单的合同,我的迁移看起来像这样:
var Migrations = artifacts.require("./Migrations.sol");
var OrdersFacilitator = artifacts.require("./OrdersFacilitator.sol")
module.exports = function(deployer) {
deployer.deploy(Migrations);
deployer.deploy(OrdersFacilitator);
};
当我运行 truffle develop 时,我看到创建了 10 个测试帐户。
帐户:
(0) 0x627306090abab3a6e1400e9345bc60c78a8bef57
(1) 0xf17f52151ebef6c7334fad080c5704d77216b732 //...
我的 Truffle js 配置如下:
networks: {
development: {
host: "localhost",
port: 9545,
network_id: "*"
}
}
当我运行我的合约名称时,我可以看到它已部署的信息:
//...
class_defaults:
{ from: '0x627306090abab3a6e1400e9345bc60c78a8bef57',
gas: 6721975,
gasPrice: 100000000000 },
currentProvider:
HttpProvider {
host: 'http://127.0.0.1:9545/',
timeout: 0,
user: undefined,
password: undefined,
headers: undefined,
send: [Function],
sendAsync: [Function],
_alreadyWrapped: true },
network_id: '4447' }
网络 ID 和端口似乎与配置匹配得很好,当我输入合同名称时我可以看到信息,但是当我尝试访问它时
var facilitator;
OrdersFacilitator.deployed().then(x => facilitator = x);
我收到一个错误:
OrdersFacilitator 尚未部署到检测到的网络(网络/工件不匹配)
我尝试删除构建文件夹并使用 --reset 标志迁移所有文件夹,但这似乎不起作用。 我如何测试我部署的合同
我在尝试同样事情的 Truffle 项目中看到了类似的问题。 解决方案可能是将项目重置为非缓存状态。
您可以尝试使用 --reset 标志运行 truffle compile(和/或 truffle migrate)。 这将删除build
目录并重新编译所有内容。
为了解决这个问题,我已经明确设置了网络选项和网络 ID。
//Start Test RPC with an Explicit Network
testrpc --network-id 1337
然后我为 TestRPC 创建了一个显式网络:
networks: {
testrpc:{
host: "localhost",
port: 8545,
network_id: "1337"
}
}
现在,当我显式迁移到我的新网络时:
truffle migrate --network testrpc --reset
truffle console --network testrpc
这似乎正确映射到正确的网络
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.