I have a contract with a mapping that maps a number to an address and I'm trying to test the contract. Here is the relevant solidity code:
function _spawnPlayer(uint256 id) external {
require(playerIndexToOwner[id] == address(0));
players.push(Player(id));
playerIndexToOwner[id] = address(this);
}
And here is how I'm testing that the created object is indeed assigned to the contract's address as an owner (the line line in the function).
it("Contract is assigned as the player's owner", () => {
return BaseInstance._spawnPlayer(301).then(function (res) {
BaseInstance.playerIndexToOwner.call(301).then((playerOwner) => {
assert.equal(playerOwner, account, "Contract is not the spawned player's owner.")
})
})
});
My problem is for some reason playerOwner
keeps changing every time I run the test and account
is just accounts[0] so that should never change. So why does playerOwner
keep changing? Is the address that deploys the contract not the same every time?