Created
October 10, 2017 17:08
-
-
Save ismaelbej/0b976a87576c4d068fb9552764996a49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Storage = artifacts.require("./Storage.sol"); | |
module.exports = function(deployer) { | |
deployer.deploy(Storage); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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