Pet Shop Test: contract code couldn't be stored
See original GitHub issueIssue
Following the pet shop tutorial, I ran into a gas limit issue running on my private blockchain. I asked on Gitter but could not find an answer about setting the right gas amount for running the tests.
Apparently, there is enough gas to store the contract as I see it deployed on the blockchain (INFO [01-11|16:03:06] Submitted contract creation
) but not enough to run the code.
Truffle.js is supposed to have enough gas.
Steps to Reproduce
My blockchain is running with:
geth --datadir ./pethshop-chaindata --rpc --rpcaddr "localhost" --rpcport 8545 --rpcapi eth,web3,personal,net --rpccorsdomain "*" --nodiscover --unlock 0 --mine 1
A very minimal test file example that fails:
pragma solidity ^0.4.17;
import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/Adoption.sol";
contract TestAdoption {
Adoption adoption = Adoption(DeployedAddresses.Adoption());
function testUserCanAdoptPet() public {
uint returnedId = adoption.adopt(8);
uint expected = 8;
Assert.equal(returnedId, expected, "Adoption of pet ID 8 should be recorded.");
}
}
My two migration files are the following:
migrations/1_initial_migration.js
var Migrations = artifacts.require("./Migrations.sol");
module.exports = function(deployer) {
deployer.deploy(Migrations, {gas: 10000});
};
migrations/2_deploy_contracts.js
var Adoption = artifacts.require("Adoption");
module.exports = function(deployer) {
deployer.deploy(Adoption, {gas: 10000});
};
truffle.js
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 8545,
network_id: "15",
gas: 0x10000000,
from: "0x0cddd..."
}
}
};
My private blockchain has the following gas limit: "gasLimit": "0x80000000"
Expected Behavior
The simple test should pass.
Actual Result
$ truffle test
TestAdoption
1) "before all" hook: prepare suite
0 passing (5s)
1 failing
1) TestAdoption "before all" hook: prepare suite:
Error: The contract code couldn't be stored, please check your gas amount.
Environment
- Operating System: Ubuntu 17.04
- Truffle version: Truffle v4.0.4 (core: 4.0.4)
- Ethereum client: 1.7.3-stable
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
The contract code couldn't be stored, please check your gas ...
Network state unknown. Review successful transactions manually. Error: The contract code couldn't be stored, please check your gas amount. test ...
Read more >Truffle - Pet Shop - Errors on All Tests (.sol) - Stack Overflow
Js) to ensure no typos but they are compiling so I don't think that's it. But here is the TestAdoption.sol code (in the...
Read more >ConsenSys/truffle - Gitter
Hello, how can I overcome Error: The contract code couldn't be stored, ... hello, I'm trying pet-shop tutorial with geth client (private network)....
Read more >Truffle Migrations Explained - SitePoint
Commands: Compile: truffle compile Migrate: truffle migrate Test contracts: truffle test. This command creates a barebones Truffle project ...
Read more >Damages for Breach of Contract - NYU Law
•Uses different test than Hadley, but adheres to the underlying principle of ... resale price and the contract price + incidental damages –...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@MathieuMailhos Finally got this to work 😃 I’ve used
geth
s dev mode instead of the regular mining mode because it’s easier to set up for testing, comes with unlocked accounts, and is quite a bit faster. Without specifying any genesis or chain data you can just run:In a separate terminal window run:
Then set the
gas
field of the Truffle config to slightly less than the gasLimit of the most recent block:Then run
truffle test --network geth
.Let me know if that doesn’t work for you.
@cgewecke Thanks so much, works like a charm!