Skip to content

Commit

Permalink
Added some events and changed data types
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Jul 9, 2018
1 parent 539a27f commit f1237b2
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 12 deletions.
29 changes: 19 additions & 10 deletions contracts/DAppStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,23 @@ contract DAppStore {

struct Dapp {
address developer;
bytes32 category;
bytes32 name;
bytes category;
bytes name;
bytes32 id;
uint256 SNTBalance;
uint256 _effectiveBalance;
uint256 effectiveBalance;
Vote[] votes;
}

Dapp[] public dapps;
mapping(bytes32 => uint) public id2index;


event DAppCreated(bytes32 id, uint256 amount);
event IncreasedDAppStake(bytes32 id, uint256 amount);

// -- TEST
function createDApp(bytes32 _category, bytes32 _name, bytes32 _id, uint256 _amountToStake) public {
function createDApp(bytes _category, bytes _name, bytes32 _id, uint256 _amountToStake) public {
require(_amountToStake != 0);
require(SNT.allowance(msg.sender, address(this)) >= _amountToStake);
require(SNT.transferFrom(msg.sender, address(this), _amountToStake));
Expand All @@ -50,9 +54,11 @@ contract DAppStore {
d.SNTBalance = _amountToStake;

id2index[_id] = dappIdx;

emit DAppCreated(_id, _amountToStake);
}

// -- CODE MISSING
// -- TEST
function numVotesToMint(Dapp storage d, uint256 _SNTBalance) internal view returns(uint256) {
uint TOTAL_SNT = d.SNTBalance;
uint SNT_PROPORTION = TOTAL_SNT * percentage_num;
Expand All @@ -67,10 +73,7 @@ contract DAppStore {

if (_SNTBalance > SNT_PROPORTION) {
uint current_interval_index = _SNTBalance / SNT_PROPORTION;

return 1;
// TODO:
// return num_votes_to_mint_at_1 + ((current_interval_index * (((_SNTBalance/100) - 1) / d._effectiveBalance)) * num_votes_to_mint_at_1);
return num_votes_to_mint_at_1 + ((current_interval_index * (((_SNTBalance/100) - 1) / d.effectiveBalance)) * num_votes_to_mint_at_1);
}
}

Expand All @@ -94,9 +97,11 @@ contract DAppStore {
require(SNT.transferFrom(msg.sender, address(this), _amountToStake));

d.SNTBalance += _amountToStake;

emit IncreasedDAppStake(_id, _amountToStake);
}

// -- MISSING CODE
// -- TEST
function upvote(bytes32 _id, uint256 _amount) public {
uint dappIdx = id2index[_id];
Dapp storage d = dapps[dappIdx];
Expand Down Expand Up @@ -125,6 +130,10 @@ contract DAppStore {
uint negative_percent = ((negative_votes_now - negative_votes_before) * 100 / negative_votes_now );
d.effectiveBalance -= d.effectiveBalance * negative_percent / 100;

assert(d.effectiveBalance < negative_votes_before);

// TODO: what happens if effectiveValance reaches 0;

require(SNT.allowance(msg.sender, d.developer) >= _amount);
require(SNT.transferFrom(msg.sender, d.developer, _amount));
}
Expand Down
1 change: 0 additions & 1 deletion embark.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@
"ipfs-api": "17.2.4"
},
"plugins": {
"embark-solc": {}
}
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
},
"homepage": "https://github.com/status-im/contracts#readme",
"dependencies": {
"embark-solc": "^0.2.0",
"react": "^16.3.2",
"react-blockies": "^1.3.0",
"react-bootstrap": "^0.32.1",
Expand Down
82 changes: 82 additions & 0 deletions test/dappstore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const utils = require('../utils/testUtils')
const assert = require('assert');
const BN = web3.utils.BN;


config({
contracts: {
"MiniMeTokenFactory": {
"gasLimit": 4000000
},
"MiniMeToken": {
"deploy": false,
},
"SNT":{
"instanceOf": "MiniMeToken",
"args": [
"$MiniMeTokenFactory",
utils.zeroAddress,
0,
"TestMiniMeToken",
18,
"TST",
true
],
"gasLimit": 4000000
},
"DAppStore": {
"args": ["$SNT"],
"gasLimit": 4000000
}
}
});

describe("DAppStore", function () {
this.timeout(0);

let accounts;

before(function(done) {

web3.eth.getAccounts().then((acc) => {
accounts = acc;
return SNT.methods.generateTokens(accounts[0], 1000000000).send()
}).then((receipt) => {
return SNT.methods.generateTokens(accounts[1], 1000000000).send()
}).then((receipt) => {
return SNT.methods.generateTokens(accounts[2], 500000000).send()
}).then((receipt) => {
return SNT.methods.generateTokens(accounts[3], 500000000).send()
}).then((receipt) => {
done();
});
});

it("Create a dapp", async () => {

const _category = web3.utils.toHex("Test");
const _name = web3.utils.toHex("TestDapp")
const _id = web3.utils.soliditySha3("TestID");
const _amountToStake = 1000;

let receipt = await SNT.methods.approve(DAppStore.options.address, _amountToStake)
.send();

receipt = await DAppStore.methods.createDApp(_category,
_name,
_id,
_amountToStake)
.send();



receipt = await SNT.methods.approve(DAppStore.options.address, 100)
.send();

receipt = await DAppStore.methods.stake(_id, 100).send();

// console.dir(receipt);
});


});

0 comments on commit f1237b2

Please sign in to comment.