我注意到,在迁移过程中,使用HDWalletProvider使用account参数可以在dryRun期间获得随机/意外的帐户。我添加了一条安全线,地址应该和预期的一样,但是由于dryRun,这总是失败的。
我是否可以有一个条件,即迁移中的代码只有在不使用dryRun时才能执行?
这里有一个很小的迁移示例(truffle.js需要配置为使用HDWalletProvider,并期望地址为account0):
const expected = "0xcFbB1f35EF57b96cA51221a331165fF9B2c828FD";
module.exports = function(deployer, network, account) {
console.log("This accounts are not from HDWalletProvider on dryRun and are always different");
console.log(account);
//this fails even if HDWalletProvider is configured correctly in truffle.js
if (account[0].toLowerCase() !== expected.toLowerCase()) {
throw new Error(
`Unexpected account0: account0=${account[0]} instead of ${expected}`
);
}
};发布于 2019-09-07 21:54:21
只需将skipDryRun: true添加到松露-config.js中的网络配置中即可。
请参阅:https://www.trufflesuite.com/docs/truffle/reference/configuration
发布于 2019-09-07 22:07:58
在“真实”和“模拟运行”模式下运行不同的代码是非常不推荐的。这就是为什么我认为,在模拟运行中使用与在实际迁移中使用的帐户相同的原因。
然而,就目前而言,如果您仍然希望在迁移代码中检测到尝试运行,则似乎特弗莱在网络名称中添加了"-fork“作为后缀。也许,这段代码会有帮助:
if (network.split('-')[1] === "fork") {
// dry-run specific code
}`https://ethereum.stackexchange.com/questions/74099
复制相似问题