I have a contract with the following functions:
contract A
{
struct Data
{
uint x;
uint y;
}
function buyItem(Data memory dat) public payable
{
// code to buy 1 item
}
function buyItems(Data[] memory data) public payable
{
uint nr_els = data.length;
for( uint i = 0; i < nr_els; i++)
{
buyPixel(data[i]);
}
}
}
In the javascript test file I call this function as follows:
var data = [];
data[0] = dat1;
data[1] = dat2;
await instance.buyItems(data, {for: user1, value:10000});
When I run this test, I get the following error:
Error: Returned error: VM Exception while processing transaction: revert
I did some more testing. For example, if I initialize the for loop as for(int i = 1 ... )
, so start from 1 instead of 0, then I don't get this error. Also if I just keep the original for loop ( starting at i = 0 ) and in the test file I also make the array var dat[]
just 1 element long ( instead of 2 ), then I also don't get an error.
I have no idea why I am getting this error message. The error message doesn't give me any usefull information. Anyone else knows what might be happening here ? Or can someone point me out how I can get more usefull error information than this with more detailed data about the error it is complaining about ?