I am having an admin in my contract who can do certain things. Here is the contract
function changeAdmin(address admin_) public {
if (msg.sender != admin) revert();
potentialAdmin = admin_;
}
function becomeAdmin() public {
if(potentialAdmin==msg.sender) admin = msg.sender;
}
address public admin;
constructor() public{
admin = msg.sender;
}
I am trying to test this using truffle framework. For this I need to pass an admin name from the contract creator and then call becomeAdmin from the address passed in first step. I am not able to clear this. Here is my test case
const te = artifacts.require("MyContract");
contract("Contract test cases", function() {
it("should be able to change admin", async function() {
var token = await te.deployed();
var accounts = await web3.eth.getAccounts();
var newAdmin = accounts[1];
await token.changeAdmin.call(newAdmin, {from : accounts[0]});
await token.becomeAdmin.call({from: newAdmin});
var adminChanged = await token.admin.call();
assert.equal(adminChanged, accounts[1], 'Admin set is wrong');
});
});
Is the way of calling contract by passing different from addresses correct ?