I have a Solidity function that manipulates an object. The function only allows this manipulation of the caller msg.sender is owner of that object. Something like this:
function Manipulate(uint i)
{
require(msg.sender == data[i].owner, "Sender is not owner.");
<manipulate object>;
}
In the test that I am writing I am making a test case that checks whether this function behaves as expected. I have 2 user accounts:
user1 = accounts[0];
user2 = accounts[1];
user2 is owner of the object I want to manipulate. I do the following call in my test:
await instance.Manipulate.call(10, {from: user2});
Against what I expect, this triggers the Require statetement of my solidity function. So it claims that msg.sender is different from the owner. I modified the string in the Require statement so it also prints msg.sender and the owner of the object I want to manipulate. What I see is that user2 is indeed the owner of the object. However, msg.sender is not user2 but user1. This is weird because I call the Manipulate() function with {from: user2}. So I don't understand why user1 is the msg.sender.
Anyone knows why user1 is the msg.sender and why the {from: user2} statement didn't make user2 the msg.sender ?