I was using testrpc before and all my tests were passing. Now after upgrading to 4.0.0 beta these same tests don't pass.
One of the issues is:
Error: Invalid number of arguments to Solidity function
Contract constructor
function Oracle(
bytes _eventName,
bytes32[] _eventResultNames,
uint256 _eventBettingEndBlock,
uint256 _decisionEndBlock,
uint8 _averageBlockTime,
uint256 _arbitrationOptionMinutes)
public
payable
{
...
}
JS test class
const testOracleParams = {
_eventName: "test",
_eventResultNames: ["first", "second", "third"],
_eventBettingEndBlock: 100,
_decisionEndBlock: 120,
_averageBlockTime: 10,
_arbitrationOptionMinutes: 1440
};
beforeEach(async function() {
oracle = await Oracle.new(...Object.values(testOracleParams), { from: oracleCreator, value: baseReward });
});
Use constructor normally and tests pass.
1) Contract: Oracle New Oracle inits the Oracle with the correct values:
Error: Invalid number of arguments to Solidity function
at Object.InvalidNumberOfSolidityArgs (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:43993:16)
at SolidityFunction.validateArgs (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:357969:22)
at SolidityFunction.toPayload (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:357985:10)
at SolidityFunction.call (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:358026:24)
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:326504:16
at Promise (<anonymous>)
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:326495:18
at <anonymous>
Looks like this was an issue with 4.0.0 beta. To restore and rollback, I just reverted everything:
npm uninstall -g truffle
npm install -g truffle
truffle migrate --reset --compile-all
Why is this close?
Reverting to an older version isn't a real fix. I'm still facing this issue using truffle 4.0.0 beta. Any ETA on fix?
@fabdarice Try deleting your build folder and run the tests again.
Wow, that worked, would you mind explaning why?
I've tried before truffle migrate --reset --compile-all but it didn't work.
Not exactly sure why. I'm guessing something to do with the already compiled files.
Ya I'd tried using reset and compile all but didn't work for me either.
Whenever I have weird issues with the tests I usually just delete my build folder.
I am still having this problem, even making rollback to 3.4.11, so far nothing mentioned here worked to me. So gotta keep digging to find the problem, but if anyone else have a clue of what it could be... please!
+1 also having this issue on 4beta2. I am using truffle develop and creating a new instance of a contract, and just testing public state variables to see if they're what I expect. I have several bytes32 and uints, some work and some do not in the console running x.name() for instance. There seem to be no correlation to which ones work and which ones don't. I have also made sure the info being provided to these functions has indeed been set.
EDIT: deleting the build worked (didn't delete correct project build first time). Strange that I have to keep deleting the build in the beta.
I'm having this on Truffle 4.0.1. I can't delete my build folder, because that's where I keep the deployed addresses of my live contracts.
Interestingly, I'm getting this when calling a method inherited from a base contract, on only one of two derived contracts. Calling the same base method on the other contract works fine.
Deleting the offending contract's json (which, luckily, is a contract I haven't deployed live yet) seems to have solved the problem for me.
Guys, Delete your build folder, then run the command.
npm run truffle migrate --reset --compile-all
I find it works best when running truffle locally to the folder rather than globally, due to the beta and different versions getting updated quickly recently.
if you prefer the global approach try
truffle migrate --reset --compile-all
Perhaps there should be reset compile function
truffle compile --reset to delete and rebuild the build folder.
Also met this in CentOS 6.7
truffle migrate --reset --compile-all
does not work.
Hey guys, can we zoom out and think about this. It's a recurring problem. Can we get some unit tests to cover this basic functionality?
Like maybe before we get a bunch of new features. I know it's not that glamorous, but it's really important. Million dollar businesses are depending on this software. I bet we could even get some money from these businesses to fund nailing down everything truffle does.
Hi. Unfortunately, artifact deleting is not suitable for me. I can't delete my build folder, it contains deployed addresses of my mainnet/kovan/rinkeby contracts. So artifacts deleting/reverting is definitely not an option. Can anybody suggest anything else? Thanks a lot in advance!
deleting the build folder did not resolve this for me :(
why is this closed? v 4.0.1
Finally, I fixed the issue by doing the following:
networks section from original artifacts to newly compiled by executing the quite simple script (it might be needed to change file pathes)Try deleting the build folder and run
truffle migrate --reset
I had the same issue, the compiled code is corrupted. It works for the first time only and the subsequent compile corrupts the build. Hope it helps.
Has anyone managed to solve this issue RE: running tests? My compile and migrate work, however after removing the build folder and running 'test' it prints out the error message above. Any ideas?
I cant understand how it could compile with no errors then fail on test.
Weird, deleting the build folder solved it for me too. Using 4.0.0 beta.
Same issue on truffle 4.0.1. Deleted the build folder, --reset, and re-compiled but still no tests working.
I have a teeny bit of insight here:
One of the possible causes I noticed was when I changed a data structure in my solidity files. The compiled .json was reflecting the old data type information in a function signature. Clobbering build/ and recompiling fixed the issue.
I wish I had more detail
I do like the idea of having a build directory to store all the relevant info, but it causes so many problems we've reverted to gdocs for recording this info.
@illuzen storing project metadata in this way has been attempted a billion times, and it always sucks.
Proof? Google "xcode derived data"
I've tried this:
truffle migrate --reset --compile-allI'm on OS X High Sierra. This is still not working. I'm sending in 3 arguments, my abi needs 3 arguments. This is very...very...frustrating.
Reporting the same issue.
Had the same issue, but deleting the build folder fixed it. I assume old compiled contract code was being used instead of being recompiled.
Hello all, a bug that caused this problem has been fixed in v4.0.4.
Please upgrade and let us know if the problem persists for you! Thank you!
(Release notes: https://github.com/trufflesuite/truffle/releases/tag/v4.0.4)
Thank you @gnidan! Will test and keep an eye out.
Still not solved
Still not solved!! Tried everything above (deleting build folder, truffle --reset --compile-all) and no good
Ubuntu LTS 16.04
@AlvaroLuken We think we've finally squashed this bug in 4.1.5. If you're seeing the error after deleting the build folder (which you shouldn't have to do anymore) it's likely there is a problem with the way you are calling a function (e.g. you're not passing the correct arguments). Could you provide any more info about what code is triggering the error?
@cgewecke - the code I am running when I get that problem is a simple (yet, I am pretty sure incorrectly written unit test in Solidity)
pragma solidity ^0.4.21;
import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/QuestionBounty.sol";
contract TestQuestionBounty {
bytes32 _question = "What is 2+2?";
uint timeLimit = 10;
//QuestionBounty b = QuestionBounty(DeployedAddresses.QuestionBounty());
uint numBountiesExpected = 1;
//are we the minter?
function testDeployer() public returns (bool passed) {
QuestionBounty b = new QuestionBounty(_question, timeLimit);
if(b.getOwner(_question) == address(this)) {
return passed = true;
}
}
}
This is the error I get:
Error: QuestionBounty contract constructor expected 2 arguments, received 0
at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-contract/contract.js:390:1
at new Promise (
at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-contract/contract.js:374:1
at
at process._tickCallback (internal/process/next_tick.js:188:7)
@AlvaroLuken Thanks, I will have a look at this first thing tomorrow morning. Is there any chance you could show the QuestionBounty contract definition so I can debug and see what's going wrong here? It doesn't have to be the whole contract - just the top is fine.
[EDIT] Just to double-check, is it possible you have defined a migration for QuestionBounty that is missing the constructor arguments?
It may be a problem with my migrations... please advise :)
@AlvaroLuken In the migrations file you sent, QuestionBounty is deployed like this:
deployer.deploy(QuestionBounty)
truffle test runs your migrations in order to make a deployed version available in the test context. If QuestionBounty requires constructor params and it's referenced in the migrations, it will be necessary to pass them in with the deploy function. The syntax is:
deployer.deploy(<contract>, <param_1>, <param_2>, ...)
There's more on the Deployer API here.
I have tried the following:
'''
deployer.deploy(QuestionBounty, bytes32 _question, uint timeLimit);
deployer.deploy(QuestionBounty, bytes32, uint);
'''
and Error is:
/home/hephaestus/Desktop/projects/QandA/migrations/2_deploy_contracts.js:3
deployer.deploy(QuestionBounty, bytes32 _question, uint timeLimit));
^^^^^^^
SyntaxError: missing ) after argument list
at Object.createScript (vm.js:80:10)
at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-require/require.js:96:1
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)
I don't think I am inputting them right... I have tried multiple variations but it keeps saying param is undefined
/home/hephaestus/Desktop/projects/QandA/migrations/2_deploy_contracts.js:3
deployer.deploy(QuestionBounty, bytes32, uint);
^
ReferenceError: bytes32 is not defined
at module.exports (/home/hephaestus/Desktop/projects/QandA/migrations/2_deploy_contracts.js:3:35)
at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-migrate/index.js:82:1
at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-require/require.js:101:1
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)
UPDATE: hardcoding values into params works!
ie. deployer.deploy(QuestionBounty, "What is 2+2?", 5);
Truffle tests pass successfully.
@AlvaroLuken and everyone else:
if any of your params are undefined you will get this error without any other warning in most web3 implementations. Probably a bug in your code that is surfacing in a rather ugly fashion.
@bwheeler96 I am getting this error.
1525509739 1525509859 BigNumber { s: 1, e: 18, c: [ 80000 ] } '0xa563876a8ef0a0d8fbe57d7b42d480326cd24e95' BigNumber { s: 1, e: 3, c: [ 1000 ] } '0xb8ff5597c7db19f45976aae9abdb21c83fb95ecc'
Deploying StartCoinCrowdsale...
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: StartCoinCrowdsale contract constructor expected 5 arguments, received 6
at /usr/lib/node_modules/truffle/build/webpack:/~/truffle-contract/contract.js:390:1
at new Promise (<anonymous>)
at /usr/lib/node_modules/truffle/build/webpack:/~/truffle-contract/contract.js:374:1
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:182:7)
My contract is this.
function StartCoinCrowdsale
(
uint256 _openingTime,
uint256 _closingTime,
uint256 _rate,
address _wallet,
uint256 _cap,
MintableToken _token
)
public
Crowdsale(_rate, _wallet, _token)
TimedCrowdsale(_openingTime, _closingTime)
CappedCrowdsale(_cap) {
}
This is my deployment code.
module.exports = function (deployer, network, accounts) {
const openingTime = web3.eth.getBlock('latest').timestamp + 2; // two secs in the future
const closingTime = openingTime + 120; // 3 minutes
console.log(openingTime, closingTime);
// const closingTime = openingTime + 86400 * 20; // 20 days
const rate = new web3.BigNumber(1000);
const wallet = accounts[1];
const cap = new web3.BigNumber(8000000000000000000); //8 ether
return deployer
.then(() => {
return deployer.deploy(StartCoin);
})
.then(() => {
console.log(openingTime, closingTime, cap, wallet, rate, StartCoin.address);
return deployer.deploy(
StartCoinCrowdsale,
openingTime,
closingTime,
rate,
wallet,
cap,
StartCoin.address
);
})
.then(() => { // giving the crowdsale ownership over the token
return StartCoinCrowdsale.deployed().then(crowdsale => {
crowdsale.token().then(tokenAddress => {
const startCoinInstance = StartCoin.at(tokenAddress);
startCoinInstance.transferOwnership(crowdsale.address).then(output => {})
})
}).catch(err => {
console.log(err);
})
});
};
As you can see my constructor is expecting 6 values and if you see at the top of the error I am consoling the deployed parameters, it has 6 values. But still I am getting this error. Any help would be great.
@praveen7557
Error encountered, bailing. Network state unknown. Review successful transactions manually
This is why I stopped using truffle. No offense to Truffle, it is a good product overall, but it was too unstable for my use cases. I built my own custom solutions.
if any of your params are undefined you will get this error without any other warning in most web3 implementations. Probably a bug in your code that is surfacing in a rather ugly fashion.
It also seems you get this error if you pass in a BigNum as an argument.
I have a function that takes a uint256 and await C.m(bn.divn(100)) doens't work, but await C.m(bn.divn(100).toNumber()) does work >.< (@gnidan - presume CCing you on this is okay)
(Note: the BNs are generated via Web3 1.0 web3.utils.toBN)
Just FYI in case someone else's problem matches mine, I was getting this during migration when trying to transfer full balance and ownership of a token to its parent DAO. It turned out to be a problem with promises - if I split up the contract function calls each in its own promise resolution, it started working.
Instead of
deployer.then(function () {
return TNSToken.deployed();
}).then(function (tIns) {
tokenInstance = tIns;
return StoryDao.deployed();
}).then(function (sIns) {
storyInstance = sIns;
var balance = tokenInstance.totalSupply();
tokenInstance.transfer(storyInstance.address, balance);
return tokenInstance.transferOwnership(storyInstance.address);
});
}
use:
deployer.then(function () {
return TNSToken.deployed();
}).then(function (tIns) {
tokenInstance = tIns;
return StoryDao.deployed();
}).then(function (sIns) {
storyInstance = sIns;
return balance = tokenInstance.totalSupply();
}).then(function (bal) {
return tokenInstance.transfer(storyInstance.address, bal);
}).then(function (something) {
return tokenInstance.transferOwnership(storyInstance.address);
});
}
@swader - your problem is obfuscated via the (terrible) Promise pattern of .then chaining.
If you write this in async/await syntax the problem is somewhat obvious.
your first code was equiv to
await deployer
const tIns = await TNSToken.deployed()
const sIns = await StoryDao.deployed()
const balance = tIns.totalSupply() // no await used - type Promise<BigNumber>
await tIns.transfer(sIns.address, balance)
await tIns.transferOwnership(sIns.address)
Anyway, the problem is generally the same as above: passing in an unrecognised object instead of a value (like string, number, BigInteger, etc)
In my case, I was taking the result of one contract method and passing it as an argument to another. What I didn't realize was that the result coming back from that first method was a TRANSACTION not the uint that it was supposed to return. I'm now baffled about how to test these contracts from JS if the values they're supposed to return aren't returned to me.
I was having the same problem. But figured out the problem is with HDWalletProvider.
If you are using HDWalletProvider for your network config and using accounts[] other then 0 (zero), then it will cause this problem.
Use only accounts[0] wherever you are putting some wallets into migration scripts. As HDWalletProvider do not have capability to support multiple wallets.
FYI this error is also thrown if one of the arguments that you are calling a contract function with isn't the same type that Solidity is expecting.
i used testprc and also migrated with code truffle migrate --reset --all,but still get the callback like:
Error: Invalid number of arguments to Solidity function
at Object.InvalidNumberOfSolidityArgs (inpage.js:1)
at u.validateArgs (inpage.js:1)
at u.toPayload (inpage.js:1)
at u.call (inpage.js:1)
at u.execute (inpage.js:1)
at truffle-contract.js:136
at new Promise (<anonymous>)
at truffle-contract.js:127
it's time of 2019-5,does this problem have some solution now?
Most helpful comment
@fabdarice Try deleting your
buildfolder and run the tests again.