Creé e implementé dos contratos con éxito (con confirmación) usando truffle migrate
así:
module.exports = function(deployer) {
deployer.deploy(ReentrancyPot).then(async () => {
deployer.deploy(ReentrancyAttack, ReentrancyPot.address);
})
}
El segundo contrato tiene una dependencia del primero como tal (extracto de ReentrancyAttack.sol
)
contract ReentrancyAttack {
ReentrancyPot public pot;
function ReentrancyAttack (address _pot) public {
pot = ReentrancyPot(_pot);
}
}
Estoy usando una prueba para el primer contrato y es exitosa, sin embargo, el segundo contrato se muestra como no implementado ( truffle.js
está configurado para apuntar al puerto 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();
})
})
Recibo el siguiente error después de ejecutar truffle test
:
Error: ReentrancyAttack has not been deployed to detected network
(network/artifact mismatch)
Lo que quieres es:
module.exports = function(deployer) {
deployer.then(async () => {
await deployer.deploy(ReentrancyPot);
var reentrancyPotInstance = await ReentrancyPot.deployed();
await deployer.deploy(ReentrancyAttack, reentrancyPotInstance.address)
});
}
Pedro es
truffle migrate
: TypeError: No se puede leer la propiedad 'dirección' de undefined en deployment.deploy.then (/Users/p/Dev/experimental/solidity-nemesis/tests/solidity/migrations/2_contract_migration.js: 8:65) en /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-deployer/src/deferredchain.js:20:1 en <anónimo> en process._tickCallback (internal/process/next_tick .js:118:7)ivicaa
ivicaa
ivicaa
chai-as-promised
y hacer que tus pruebas sean más legibles y compactas si también usas async/await en tus pruebas.Pedro es
Pedro es