diff --git a/contracts/DAppStore.sol b/contracts/DAppStore.sol index 54267d2..efa2d5f 100644 --- a/contracts/DAppStore.sol +++ b/contracts/DAppStore.sol @@ -41,6 +41,7 @@ contract DAppStore is ApproveAndCallFallBack, BancorFormula { Data[] public dapps; mapping(bytes32 => uint) public id2index; + mapping(bytes32 => bool) existingIDs; event DAppCreated(bytes32 indexed id, uint votesMint, uint amount); event Upvote(bytes32 indexed id, uint newEffectiveBalance); @@ -231,6 +232,8 @@ contract DAppStore is ApproveAndCallFallBack, BancorFormula { } function _createDApp(address _from, bytes32 _id, uint _amount) internal { + require(!existingIDs[_id], "You must submit a unique ID"); + require(_amount > 0, "You must spend some SNT to submit a ranking in order to avoid spam"); require (_amount < safeMax, "You cannot stake more SNT than the ceiling dictates"); @@ -260,6 +263,7 @@ contract DAppStore is ApproveAndCallFallBack, BancorFormula { d.effectiveBalance = _amount; id2index[_id] = dappIdx; + existingIDs[_id] = true; require(SNT.allowance(_from, address(this)) >= _amount, "Not enough SNT allowance"); require(SNT.transferFrom(_from, address(this), _amount), "Transfer failed"); diff --git a/test/dappstore_spec.js b/test/dappstore_spec.js index a4dd949..9009bba 100644 --- a/test/dappstore_spec.js +++ b/test/dappstore_spec.js @@ -87,6 +87,21 @@ contract("DAppStore", function () { assert.strictEqual(amount, parseInt(receipt.effectiveBalance, 10)); }) + it("should not create a new DApp with the same ID", async function () { + let id = "0x7465737400000000000000000000000000000000000000000000000000000000"; + let amount = 1000; + + await SNT.methods.generateTokens(accounts[0], amount).send(); + const encodedCall = DAppStore.methods.createDApp(id,amount).encodeABI(); + + try { + await SNT.methods.approveAndCall(DAppStore.options.address, amount, encodedCall).send({from: accounts[0]}); + assert.fail('should have reverted before'); + } catch (error) { + TestUtils.assertJump(error); + } + }) + it("should not create a new DApp when exceeding the ceiling or staking nothing", async function () { let id = "0x7465737400000000000000000000000000000000000000000000000000000000"; let initial = await DAppStore.methods.max().call();