Skip to content

Instantly share code, notes, and snippets.

@ismaelbej
Created October 10, 2017 17:08
Show Gist options
  • Save ismaelbej/0b976a87576c4d068fb9552764996a49 to your computer and use it in GitHub Desktop.
Save ismaelbej/0b976a87576c4d068fb9552764996a49 to your computer and use it in GitHub Desktop.
const Storage = artifacts.require("./Storage.sol");
module.exports = function(deployer) {
deployer.deploy(Storage);
};
pragma solidity ^0.4.15;
contract Storage {
mapping (uint => uint) public users;
event SetUserData(uint userId, uint data);
function setUserData(uint userId, uint data) public {
require(users[userId] == 0);
users[userId] = data;
SetUserData(userId, data);
}
function getUserData(uint userId) constant public returns (uint data) {
if (users[userId] != 0) {
return users[userId];
} else {
return data;
}
}
}
const Storage = artifacts.require("./Storage.sol");
contract('Storage', function(accounts) {
let storage;
before(async () => {
storage = await Storage.deployed();
});
it("Set user data", async () => {
await storage.setUserData(1, 1234);
const data = await storage.getUserData.call(1);
assert.equal(data, 1234, 'Return user data');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment