I have a solidity contract that allows users to register a name to their address. This is done with the register
function. I also have a function to allow users to check the availability of a name; checkAvailability
.
The problem is that checkAvailability
never returns false. It's as if the users mapping never saves any values. Does anyone have any suggestions?
pragma solidity ^0.4.4;
contract Users {
mapping (bytes32 => address) public users;
function register(bytes32 name) {
if(users[name] == 0 && name != ""){
users[name] = msg.sender;
}
}
function checkAvailability(bytes32 name) returns (bool) {
if(users[name] == 0) {
return true;
}
return false;
}
}
NOTES: Checking against 0x00 doesn't seem to fix the issue. I'm using truffle test file to test this contract:
it.only("should user", function() {
return Users.deployed().then(function(instance) {
return instance.register.call('test')
.then(() => {
return instance.checkAvailability.call('test');
});
})
.then((register) => {
console.log(register);
});
});