The origin of the issue is because you're trying to deploy the contract from the file migrations/1_initial_migration.js that is supposed to be used only for the deployment of Migration.sol.
To deploy your contracts, you need to create a file in migrations/2_deploy_contracts.js that contains the deployment part of TestCrowsale.sol
migrations/1_initial_migration.js
var Migrations = artifacts.require("./Migrations.sol");
module.exports = function(deployer) {
deployer.deploy(Migrations);
};
migrations/2_deploy_contracts.js
var TestCrowdsale = artifacts.require("./TestCrowdsale.sol");
module.exports = function(deployer) {
deployTestCrowdsale(deployer);
};
function deployTestCrowdsale(deployer) {
const accounts = web3.eth.accounts;
const startTime = latestTime();
const endTime = startTime + duration.days(45);
const rate = 2500;
const goal = web3.toWei(250, 'ether');
const cap = web3.toWei(4000, 'ether');
const wallet = accounts[0];
return deployer.deploy(TestCrowdsale, startTime, endTime, rate, wallet);
}
function latestTime() {
return web3.eth.getBlock('latest').timestamp;
}
const duration = {
seconds: function (val) { return val; },
minutes: function (val) { return val * this.seconds(60); },
hours: function (val) { return val * this.minutes(60); },
days: function (val) { return val * this.hours(24); },
weeks: function (val) { return val * this.days(7); },
years: function (val) { return val * this.days(365); },
};
I tried on my side and the deployment go through :
Compiling ./contracts/Migrations.sol...
Writing artifacts to ./build/contracts
Using network 'development'.
Running migration: 1_initial_migration.js
Deploying Migrations...
... 0x46dd08a7e00419adc52c3b9b048f89812dd960463b02125a93eb7e43eb4ca64f
Migrations: 0x4a5a1448d37aeaaae79deed7e0d3f81ebc52db87
Saving successful migration to network...
... 0x573964afa1f79deca003871bd793026f7c932d9c46b8be055184e10790a63147
Saving artifacts...
Running migration: 2_deploy_contracts.js
Deploying TestCrowdsale...
... 0xd251d1b3b92facb64e38ce3e04907197e9b7b9e7fefdf083da1b43c08f1b9bb1
TestCrowdsale: 0xd817d9295491556f00a45c8092e42c10df271865
Saving successful migration to network...
... 0x83a2ba140f54003fc0f146ff2d8b8e2f6d9013122d59d94a39a74d4a9c8df92e
Saving artifacts..
I pushed the code here for more details: https://github.com/gjeanmart/stackexchange/tree/master/36690-error-encountered-bailing-network-state-unknown-review-successful-transaction
Best Answer
Solved, the problem that when I named the migrations file as 2_deploy_contracts.js, the name was placed on the file itself. Once I deleted this line, it worked