[英]Testing Deployed Smart Contract on Truffle
I'm having trouble testing a contract using truffle.我在使用松露测试合同时遇到问题。 I have the latest version of truffle installed as well a TestRPC.
我安装了最新版本的 truffle 以及 TestRPC。
It's to my understanding that the latest version of truffle comes with a client for testing SmartContracts so TestRPC isn't needed any more.据我了解,最新版本的 truffle 附带了一个用于测试 SmartContracts 的客户端,因此不再需要 TestRPC。
I have a simple contract my Migrations looks like so:我有一个简单的合同,我的迁移看起来像这样:
var Migrations = artifacts.require("./Migrations.sol");
var OrdersFacilitator = artifacts.require("./OrdersFacilitator.sol")
module.exports = function(deployer) {
deployer.deploy(Migrations);
deployer.deploy(OrdersFacilitator);
};
When I run truffle develop I see that 10 test accounts are created.当我运行 truffle develop 时,我看到创建了 10 个测试帐户。
Accounts:
帐户:
(0) 0x627306090abab3a6e1400e9345bc60c78a8bef57
(0) 0x627306090abab3a6e1400e9345bc60c78a8bef57
(1) 0xf17f52151ebef6c7334fad080c5704d77216b732 //...
(1) 0xf17f52151ebef6c7334fad080c5704d77216b732 //...
My Truffle js is configured like so:我的 Truffle js 配置如下:
networks: {
development: {
host: "localhost",
port: 9545,
network_id: "*"
}
}
When I run the name of my contracts I can see its deployed with the information:当我运行我的合约名称时,我可以看到它已部署的信息:
//...
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' }
the Network Id and the port seem to match the configuration fine, and I can see the information when I type the contract name, However when I try to gain access to it though网络 ID 和端口似乎与配置匹配得很好,当我输入合同名称时我可以看到信息,但是当我尝试访问它时
var facilitator;
OrdersFacilitator.deployed().then(x => facilitator = x);
I Get an Error:我收到一个错误:
OrdersFacilitator has not been deployed to detected network (network/artifact mismatch)
OrdersFacilitator 尚未部署到检测到的网络(网络/工件不匹配)
I've tried deleting the build folder and migrating all with the --reset flag but that doesn't seem to work.我尝试删除构建文件夹并使用 --reset 标志迁移所有文件夹,但这似乎不起作用。 How can I Tested my deployed contract
我如何测试我部署的合同
I've seen similar issues withe Truffle projects attempting the same thing.我在尝试同样事情的 Truffle 项目中看到了类似的问题。 The solution may be to reset the project to a non-cached state.
解决方案可能是将项目重置为非缓存状态。
You can try running truffle compile (and/or truffle migrate) with the --reset flag.您可以尝试使用 --reset 标志运行 truffle compile(和/或 truffle migrate)。 This will remove the
build
dir and recompile everything.这将删除
build
目录并重新编译所有内容。
To fix the issue I've explicitly set the network options and network id.为了解决这个问题,我已经明确设置了网络选项和网络 ID。
//Start Test RPC with an Explicit Network
testrpc --network-id 1337
Then I've created an explicit network for TestRPC:然后我为 TestRPC 创建了一个显式网络:
networks: {
testrpc:{
host: "localhost",
port: 8545,
network_id: "1337"
}
}
Now when I Migrate Explicitly to my new network:现在,当我显式迁移到我的新网络时:
truffle migrate --network testrpc --reset
truffle console --network testrpc
This seems to map properly to the correct network这似乎正确映射到正确的网络
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.