DeployedAddresses + Error: VM Exception while processing transaction: revert - ethereum

I have a contract like following -
File Name: dummycontrat.sol
pragma solidity ^0.4.17;
contract DummyContract {
function fetchRandomNumber() public pure returns(uint) {
uint res = 10;
return res;
}
}
I have the following test file -
FileName: test/TestDummyContract.sol
pragma solidity ^0.4.17;
import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/dummycontract.sol";
contract TestDummyContract {
function testRandomNumberNew() public {
DummyContract dummyContract = new DummyContract();
uint randomNumber = dummyContract.fetchRandomNumber();
Assert.equal(randomNumber, 10, "Number is not 10");
}
function testRandomNumberDeployed() public {
DummyContract dummyContract = DummyContract(DeployedAddresses.DummyContract());
uint randomNumber = dummyContract.fetchRandomNumber();
Assert.equal(randomNumber, 10, "Number is not 10");
}
}
I run the command -
truffle compile && truffle migrate --reset --network dev && truffle test --network dev test/TestDummyContract.sol
The first test passes while the second gives an error. Logs from the truffle test command is following -
TestDummyContract
✓ testRandomNumberNew (53ms)
1) testRandomNumberDeployed
> No events were emitted
1 passing (894ms)
1 failing
1) TestDummyContract testRandomNumberDeployed:
Error: VM Exception while processing transaction: revert
at Object.InvalidResponse (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:38:1)
at /usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:86:1
at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-provider/wrapper.js:134:1
at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/httpprovider.js:128:1)
at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:64:1)
at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:354:1)
at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:509:1)
at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:469:1)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
Can anyone explain what's the problem here? I am running Ganache tool on OSX for the network.

DeployedAddresses.DummyContract() is failing because only contracts that are included in the Truffle deployment configurations are made available to DeployedAddresses. From the Truffle documentation:
The addresses of your deployed contracts (i.e., contracts that were deployed as part of your migrations) are available through the truffle/DeployedAddresses.sol library. This is provided by Truffle and is recompiled and relinked before each suite is run to provide your tests with Truffle's a clean room environment. This library provides functions for all of your deployed contracts, in the form of:
DeployedAddresses.<contract name>();
To fix your issue, you need to create the deployment configuration under /migrations (or add to your existing one, if you have it). For example:
2_deploy_contracts.js:
var DummyContract = artifacts.require("dummycontract");
module.exports = function(deployer) {
deployer.deploy(DummyContract);
};
Add that configuration, rerun truffle migrate --reset then your test will work.

Related

Receiving "invalid or does not take any parameters" when attempting to deploy a contract

here is my 2_deploy_contract.js syntax
const DerbyToken = artifacts.require("./DerbyToken.sol");
module.exports = function(deployer) {
// Deploy the Migrations contract as our only task
deployer.deploy(DerbyToken);
};
after I migrate the file using truffle I receive this error message
Error: Migration /home/cyraidz/token_sale/migrations/2_deploy_contracts.js invalid or does not take any parameters
at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:55:1)
at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.3.5 (core: 5.3.5)
Node v10.19.0
Add a newline at the end of "2_deploy_contract.js"

Truffle Smart Contract Error: Invalid number of parameter

I followed the tutorial of quorum with truffle: https://truffleframework.com/tutorials/building-dapps-for-quorum-private-enterprise-blockchains
Now I want to migrate the SimpleStorage.sol Smart Contract to the blockchain, but I want to make it to add the "PrivateFor" parameter.
This is my Smart Contract:
pragma solidity ^0.4.17;
contract SimpleStorage {
uint public storedData;
constructor(uint initVal) public {
storedData = initVal;
}
function set(uint x) public {
storedData = x;
}
function get() view public returns (uint retVal) {
return storedData;
}
}
This is my: 2_deploy_simplestorage.js
var SimpleStorage = artifacts.require("SimpleStorage");
module.exports = function(deployer) {
deployer.deploy(SimpleStorage, 42, {privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]})
};
But when I do truffle migrate, I get this error:
$ truffle migrate
⚠️ Important ⚠️
If you're using an HDWalletProvider, it must be Web3 1.0 enabled or your migration will hang.
Starting migrations...
======================
> Network name: 'development'
> Network id: 10
> Block gas limit: 3758096384
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
> transaction hash: 0x0a55cd010bb30247c3ae303e54be8dd13177b520af5967728cf77e07ca9efe76
- Blocks: 0 Seconds: 0
> Blocks: 0 Seconds: 0
> contract address: 0x1932c48b2bF8102Ba33B4A6B545C32236e342f34
> account: 0xed9d02e382b34818e88B88a309c7fe71E65f419d
> balance: 1000000000
> gas used: 245462
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH
- Saving migration to chain.
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0 ETH
2_deploy_simplestorage.js
=========================
Deploying 'SimpleStorage'
-------------------------
Error: *** Deployment Failed ***
"SimpleStorage" -- Invalid number of parameters for "undefined". Got 2 expected 1!.
at C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-deployer\src\deployment.js:364:1
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
Truffle v5.0.1 (core: 5.0.1)
Node v8.11.4
When I don't add the "privateFor" parameter, it works:
var SimpleStorage = artifacts.require("SimpleStorage");
module.exports = function(deployer) {
deployer.deploy(SimpleStorage, 42)
};
But I need this privateFor parameter..
Does someone know how to fix this?
Hey #BlockChainProgrammer. Thanks for guiding me on how to use the Quorum proxy. It worked.
For this error, Try to upgrade/downgrade your truffle version to v4.1.
$ npm install -g truffle#4.1.10
and change the version of solidity to 0.4.24 in your truffle-config.js and the SimpleStorage.sol and add back privateFor in your migration file.
In this case of quorum, the
{
privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]})
};
was not defined in the contract, and at such the error, but that particular truffle compiler is compatible with Quorum features.
But For non-Quorum users like myself
The error Usually means, define a variable in your contract and not a compiler problem. Most likely a parameter not set in the constructor.
Open to corrections
Problem solved!
What I had to do is to downgrade truffle to "4.1.10" with:
truffle uninstall -g
and then
npm install -g truffle#4.1.10
Many thanks to #TS28

geth shows "contract creation code storage out of gas" when I deploy contract from remix

I created a private network using geth.
And deploy a contract from remix (browser).
It shows following error.
genesis.json is this.
{
"config": {
"homesteadBlock": 0
},
"nonce": "0x0000000000000042",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x8000000",
"difficulty": "0x4000",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"alloc": {}
}
And I created 2 accounts and run network by this code.
geth --identity "sampleNode" --rpc --rpcport 8545 --rpcapi "web3,eth,net,personal" --rpccorsdomain "*" --rpcaddr "0.0.0.0" --datadir "~/eth-private-net/" --nodiscover --networkid 10 --unlock 0,1 --verbosity 6
And I deployed the contract.
pragma solidity ^0.5.0;
contract SingleNumRegister {
uint storedData;
function set(uint x) public{
storedData = x;
}
function get() public view returns (uint retVal){
return storedData;
}
}
After that, it shows error on geth console log.
DEBUG[01-27|11:05:50.009] VM returned with error err="contract creation code storage out of gas"
I got eth by mining and the account has 315 ether on my private network, but it shows same error.
> eth.getBalance(eth.accounts[0]);
315000000000000000000
What is the problem?
If you deploy using remix there is a field called gas limit. If your gas limit is 3000000 it should be enough, when I deploy your contract on remix it costs much less than that.
Also since you said you deploy on a private blockchain it could have something to do with the gas cost there. Try to deploy in the remix JavascriptVM to see if it works (this works in my case). If it works there try increasing the gas limit when deploying on your private blockchain.

truffle serve throws the below mentioned error?

:\blockchain\truffle\demo\mortgage-blockchain-demo>truffle serve
erving static assets in .\build on port 8080...
ebuilding...
:\Users\Mabel\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:220
48
return (new fsevents(path)).on('fsevent', callback).start();
^
ypeError: fsevents is not a constructor
at createFSEventsInstance (C:\Users\Mabel\AppData\Roaming\npm\node_modules\t
uffle\build\cli.bundled.js:220548:11)
at setFSEventsListener (C:\Users\Mabel\AppData\Roaming\npm\node_modules\truf
le\build\cli.bundled.js:220602:16)
at FSWatcher.FsEventsHandler._watchWithFsEvents (C:\Users\Mabel\AppData\Roam
ng\npm\node_modules\truffle\build\cli.bundled.js:220766:16)
at FSWatcher.<anonymous> (C:\Users\Mabel\AppData\Roaming\npm\node_modules\tr
ffle\build\cli.bundled.js:220900:25)
at LOOP (fs.js:1758:14)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
kindly help me in resolving the issue . I am running on a windows 7 machine .
trying to do ethereum truffle setup.
Just remove/off this below code in //Users/**abc/projectFolder/node_modules/chokidar/lib/fsevents-handler.js
function createFSEventsInstance(path, callback) {
//return (new fsevents(path)).on('fsevent', callback).start();
}
Disable the FsEvents when not used:
C:\Users\UserName\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js
// if (!FsEventsHandler.canUse())
opts.useFsEvents = false;
Steps:
truffle compile && truffle build && truffle migrate && truffle serve
scene:
using create-react-app
/Users/**abc/projectFolder/node_modules/chokidar/lib/fsevents-handler.js
Solution:
Temporarily //return (new fsevents(path)).on('fsevent', callback).start();

I can not put a contract on to ethereum via Remix-Solidity by error - Invalid sender

I tried to run the following contract on to the ethereum blockchain,though,
I got a error of "callback contain no result Error: Invalid sender".
pragma solidity ^0.4.0;
contract SingleNumRegister {
uint storedData;
function set(uint x) {
storedData = x;
}
function get() constant returns (uint retVal) {
return storedData;
}
}
The accounts[0] already has enough Gas and it is unlocked.
I have no idea of why this message occurs. Please give me some advice to solve the issue.
//////Data of environment///////
IDE :
Browser-Only Solidity IDE and Runtime Environment
remix-4a2c813.zip.
Web3 Provider
geth :
geth --datadir "/home/yuichi/ethe-prj/dprvnet" --port 30304 --networkid 1234 --rpc --rpcport "8545" --nodiscover --rpccorsdomain "*" console 2>./console.log
instance: Geth/v1.6.1-stable-021c3c28/linux-amd64/go1.8.1
coinbase: 0x91be0471171c5ddfe94cf5b3b81d1d1d5e9cab26
at block: 9466 (Fri, 02 Jun 2017 05:35:45 JST)
datadir: /home/yuichi/ethe-prj/dprvnet
modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
I found out the cause why this happened. genesis.json was incorrect.
Actually config section was wrong. I corrected like this:
"config": {
"chainID": 10,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
And I started again with "geth init" command again like:
geth --datadir AAA init genesis.json
And I created a node and started mining. The error was fixed!