Readability & cleanup
This commit is contained in:
parent
7d47f5ce9e
commit
77d5e12861
|
@ -59,11 +59,10 @@ contract("DAppStore", function () {
|
|||
const encodedCall = DAppStore.methods.createDApp(id,amount).encodeABI();
|
||||
await SNT.methods.approveAndCall(DAppStore.options.address, amount, encodedCall).send({from: accounts[0]});
|
||||
|
||||
let receipt = await DAppStore.methods.dapps(0).call();
|
||||
|
||||
let receipt = await DAppStore.methods.dapps(0).call();
|
||||
let developer = accounts[0];
|
||||
assert.strictEqual(receipt.developer, developer);
|
||||
|
||||
assert.strictEqual(receipt.developer, developer);
|
||||
assert.strictEqual(receipt.id, id);
|
||||
|
||||
// Check the DApp Store actually receives the SNT!
|
||||
|
@ -123,11 +122,10 @@ contract("DAppStore", function () {
|
|||
const encodedCall = DAppStore.methods.upvote(id,amount).encodeABI();
|
||||
await SNT.methods.approveAndCall(DAppStore.options.address, amount, encodedCall).send({from: accounts[0]});
|
||||
|
||||
let receipt = await DAppStore.methods.dapps(0).call();
|
||||
|
||||
let receipt = await DAppStore.methods.dapps(0).call();
|
||||
let developer = accounts[0];
|
||||
assert.strictEqual(receipt.developer, developer);
|
||||
|
||||
assert.strictEqual(receipt.developer, developer);
|
||||
assert.strictEqual(receipt.id, id);
|
||||
|
||||
// Check the DApp Store actually receives the SNT!
|
||||
|
@ -151,7 +149,6 @@ contract("DAppStore", function () {
|
|||
assert.strictEqual(parseInt(receipt.votes_minted, 10), votes_minted);
|
||||
|
||||
assert.strictEqual(parseInt(receipt.votes_cast, 10), 0);
|
||||
|
||||
assert.strictEqual(parseInt(receipt.effective_balance, 10), upvotedBalance);
|
||||
})
|
||||
|
||||
|
@ -198,7 +195,6 @@ contract("DAppStore", function () {
|
|||
let receipt = await DAppStore.methods.dapps(0).call();
|
||||
|
||||
assert.strictEqual(receipt.developer, developer);
|
||||
|
||||
assert.strictEqual(receipt.id, id);
|
||||
|
||||
// Check the developer actually receives the SNT!
|
||||
|
@ -208,9 +204,7 @@ contract("DAppStore", function () {
|
|||
|
||||
// Balance, rate, and votes_minted remain unchanged for downvotes
|
||||
assert.strictEqual(receipt.balance, initial.balance);
|
||||
|
||||
assert.strictEqual(receipt.rate, initial.rate);
|
||||
|
||||
assert.strictEqual(receipt.votes_minted, initial.votes_minted);
|
||||
|
||||
let available = parseInt(initial.available, 10) - parseInt(cost.c, 10);
|
||||
|
@ -227,8 +221,8 @@ contract("DAppStore", function () {
|
|||
let id = "0x7465737400000000000000000000000000000000000000000000000000000000";
|
||||
let cost = await DAppStore.methods.downvoteCost(id).call()
|
||||
let amount = parseInt(cost.c, 10);
|
||||
|
||||
let developer = accounts[0];
|
||||
|
||||
let initial = await DAppStore.methods.dapps(0).call();
|
||||
let bal_before = await SNT.methods.balanceOf(developer).call();
|
||||
|
||||
|
@ -239,7 +233,6 @@ contract("DAppStore", function () {
|
|||
let receipt = await DAppStore.methods.dapps(0).call();
|
||||
|
||||
assert.strictEqual(receipt.developer, developer);
|
||||
|
||||
assert.strictEqual(receipt.id, id);
|
||||
|
||||
// Check the developer actually receives the SNT!
|
||||
|
@ -249,9 +242,7 @@ contract("DAppStore", function () {
|
|||
|
||||
// Balance, rate, and votes_minted remain unchanged for downvotes
|
||||
assert.strictEqual(receipt.balance, initial.balance);
|
||||
|
||||
assert.strictEqual(receipt.rate, initial.rate);
|
||||
|
||||
assert.strictEqual(receipt.votes_minted, initial.votes_minted);
|
||||
|
||||
let available = parseInt(initial.available, 10) - parseInt(cost.c, 10);
|
||||
|
@ -288,11 +279,10 @@ contract("DAppStore", function () {
|
|||
const encodedCall = DAppStore.methods.upvote(id,amount).encodeABI();
|
||||
await SNT.methods.approveAndCall(DAppStore.options.address, amount, encodedCall).send({from: accounts[0]});
|
||||
|
||||
let receipt = await DAppStore.methods.dapps(0).call();
|
||||
|
||||
let receipt = await DAppStore.methods.dapps(0).call();
|
||||
let developer = accounts[0];
|
||||
assert.strictEqual(receipt.developer, developer);
|
||||
|
||||
assert.strictEqual(receipt.developer, developer);
|
||||
assert.strictEqual(receipt.id, id);
|
||||
|
||||
// Check the DApp Store actually receives the SNT!
|
||||
|
@ -317,8 +307,8 @@ contract("DAppStore", function () {
|
|||
// Votes have been cast by this stage, so we need to check how many there are
|
||||
// and confirm that `upvote` still calculates the effective_balance correctly
|
||||
let votes_cast = parseInt(receipt.votes_cast, 10);
|
||||
let e_balance = Math.round(upvotedBalance - ((votes_cast*rate/decimals)*(available/decimals/votes_minted)));
|
||||
|
||||
let e_balance = Math.round(upvotedBalance - ((votes_cast*rate/decimals)*(available/decimals/votes_minted)));
|
||||
assert.strictEqual(parseInt(receipt.effective_balance, 10), e_balance);
|
||||
})
|
||||
|
||||
|
@ -327,7 +317,6 @@ contract("DAppStore", function () {
|
|||
let amount = 100;
|
||||
|
||||
let receipt = await DAppStore.methods.dapps(0).call();
|
||||
|
||||
let effect = await DAppStore.methods.upvoteEffect(id,amount).call();
|
||||
|
||||
// Mock receiving the SNT
|
||||
|
@ -335,10 +324,9 @@ contract("DAppStore", function () {
|
|||
|
||||
let max = await DAppStore.methods.max().call();
|
||||
let decimals = await DAppStore.methods.decimals().call();
|
||||
|
||||
let mRate = Math.round(decimals - (mBalance * decimals/max));
|
||||
|
||||
let mAvailable = mBalance * mRate;
|
||||
|
||||
let mVMinted = Math.round((mAvailable/decimals) ** (decimals/mRate));
|
||||
|
||||
// Votes have been cast by this stage, so we need to check how many there are
|
||||
|
@ -355,7 +343,6 @@ contract("DAppStore", function () {
|
|||
let id = "0x7465737400000000000000000000000000000000000000000000000000000000";
|
||||
let initial = await DAppStore.methods.max().call();
|
||||
let amount = parseInt(initial, 10);
|
||||
|
||||
try {
|
||||
await DAppStore.methods.upvoteEffect(id,amount).call();
|
||||
} catch (error) {
|
||||
|
@ -368,42 +355,36 @@ contract("DAppStore", function () {
|
|||
let amount = 100;
|
||||
|
||||
let initial = await DAppStore.methods.dapps(0).call();
|
||||
|
||||
// Check the DApp Store actually sends SNT to the developer
|
||||
let before = await SNT.methods.balanceOf(DAppStore.options.address).call();
|
||||
let before_dev = await SNT.methods.balanceOf(accounts[0]).call();
|
||||
|
||||
let receipt_obj = await DAppStore.methods.withdraw(id,amount).send({from: accounts[0]});
|
||||
let receipt = receipt_obj.events.Withdraw.returnValues;
|
||||
|
||||
assert.strictEqual(receipt.id, id);
|
||||
|
||||
// Check the DApp Store actually sends SNT to the developer
|
||||
let after = await SNT.methods.balanceOf(DAppStore.options.address).call();
|
||||
let after_dev = await SNT.methods.balanceOf(accounts[0]).call();
|
||||
|
||||
let difference = parseInt(before, 10) - parseInt(after, 10);
|
||||
let difference_dev = parseInt(after_dev, 10) - parseInt(before_dev, 10);
|
||||
|
||||
assert.strictEqual(difference, amount)
|
||||
assert.strictEqual(difference_dev, amount)
|
||||
|
||||
let receipt = receipt_obj.events.Withdraw.returnValues;
|
||||
|
||||
assert.strictEqual(receipt.id, id);
|
||||
let goal = parseInt(receipt.newEffectiveBalance, 10);
|
||||
|
||||
// Recalculate e_balance manually and check it matched what is returned
|
||||
let balance = parseInt(initial.balance, 10) - amount
|
||||
|
||||
// Recalculate e_balance manually and check it matches what is returned
|
||||
let max = await DAppStore.methods.max().call();
|
||||
let decimals = await DAppStore.methods.decimals().call();
|
||||
|
||||
let balance = parseInt(initial.balance, 10) - amount
|
||||
let rate = Math.round(decimals - (balance * decimals/max));
|
||||
|
||||
let available = balance * rate;
|
||||
|
||||
let v_minted = Math.round((available/decimals) ** (decimals/rate));
|
||||
|
||||
let v_cast = parseInt(initial.votes_cast, 10);
|
||||
let e_balance = Math.round(balance - ((v_cast*rate/decimals)*(available/decimals/v_minted)));
|
||||
|
||||
assert.strictEqual(e_balance, goal);
|
||||
let effective_balance = parseInt(receipt.newEffectiveBalance, 10);
|
||||
|
||||
assert.strictEqual(e_balance, effective_balance);
|
||||
|
||||
// Having withdrawn the SNT, check that it updates the particular DApp's storage values properly
|
||||
let check = await DAppStore.methods.dapps(0).call();
|
||||
|
@ -419,7 +400,6 @@ contract("DAppStore", function () {
|
|||
it("should not allow withdrawing more than was staked", async function () {
|
||||
let id = "0x7465737400000000000000000000000000000000000000000000000000000000";
|
||||
let amount = 150000;
|
||||
|
||||
try {
|
||||
await DAppStore.methods.withdraw(id,amount).send({from: accounts[0]});
|
||||
} catch (error) {
|
||||
|
@ -430,7 +410,6 @@ contract("DAppStore", function () {
|
|||
it("should not allow anyone other than the developer to withdraw", async function () {
|
||||
let id = "0x7465737400000000000000000000000000000000000000000000000000000000";
|
||||
let amount = 1000;
|
||||
|
||||
try {
|
||||
await DAppStore.methods.withdraw(id,amount).send({from: accounts[1]});
|
||||
} catch (error) {
|
||||
|
|
Loading…
Reference in New Issue