Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andres Gonzalez
committed
Sep 7, 2017
1 parent
668698b
commit 1dc26b9
Showing
3 changed files
with
166 additions
and
320 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,46 @@ | ||
var Gambit = artifacts.require("./Gambit.sol"); | ||
const assertFail = require("./helpers/assertFail"); | ||
const Gambit = artifacts.require("./Gambit.sol"); | ||
|
||
contract("Gambit", function(accounts) { | ||
// CREATION | ||
it("creation: test correct setting of vanity information", function(done) { | ||
var ctr; | ||
Gambit.new({ from: accounts[0] }) | ||
.then(function(result) { | ||
ctr = result; | ||
return ctr.name.call(); | ||
}) | ||
.then(function(result) { | ||
assert.strictEqual(result, "Gambit"); | ||
return ctr.decimals.call(); | ||
}) | ||
.then(function(result) { | ||
assert.strictEqual(result.toNumber(), 8); | ||
return ctr.symbol.call(); | ||
}) | ||
.then(function(result) { | ||
assert.strictEqual(result, "GAM"); | ||
done(); | ||
}) | ||
.catch(done); | ||
it("creation: test correct setting of vanity information", async () => { | ||
let ctr = await Gambit.new({ from: accounts[0] }); | ||
assert.strictEqual(await ctr.name.call(), "Gambit"); | ||
assert.strictEqual((await ctr.decimals.call()).toNumber(), 8); | ||
assert.strictEqual(await ctr.symbol.call(), "GAM"); | ||
}); | ||
|
||
// BURNING | ||
it("burning: owner of the contract is able to burn tokens", function(done) { | ||
var ctr; | ||
Gambit.new({ from: accounts[0] }) | ||
.then(function(result) { | ||
ctr = result; | ||
return ctr.totalBurnt.call(); | ||
}) | ||
.then(function(result) { | ||
assert.strictEqual(result.toNumber(), 0); | ||
return ctr.burn(100, { from: accounts[0] }); | ||
}) | ||
.then(function(result) { | ||
var logs = result.logs; | ||
assert.equal(logs[0].event, "Burn"); | ||
assert.equal(logs[0].args._from, accounts[0]); | ||
assert.strictEqual(logs[0].args._value.toNumber(), 100); | ||
return ctr.balanceOf.call(accounts[0]); | ||
}) | ||
.then(function(result) { | ||
assert.strictEqual(result.toNumber(), 259999999999900); | ||
return ctr.totalSupply.call(); | ||
}) | ||
.then(function(result) { | ||
assert.strictEqual(result.toNumber(), 259999999999900); | ||
return ctr.totalBurnt.call(); | ||
}) | ||
.then(function(result) { | ||
assert.strictEqual(result.toNumber(), 100); | ||
done(); | ||
}) | ||
.catch(done); | ||
it("burning: owner of the contract is able to burn tokens", async () => { | ||
let ctr = await Gambit.new({ from: accounts[0] }); | ||
assert.strictEqual((await ctr.totalBurnt.call()).toNumber(), 0); | ||
let logs = (await ctr.burn(100, { from: accounts[0] })).logs; | ||
assert.equal(logs[0].event, "Burn"); | ||
assert.equal(logs[0].args._from, accounts[0]); | ||
assert.strictEqual(logs[0].args._value.toNumber(), 100); | ||
assert.strictEqual( | ||
(await ctr.balanceOf.call(accounts[0])).toNumber(), | ||
259999999999900 | ||
); | ||
assert.strictEqual( | ||
(await ctr.totalSupply.call()).toNumber(), | ||
259999999999900 | ||
); | ||
assert.strictEqual((await ctr.totalBurnt.call()).toNumber(), 100); | ||
}); | ||
|
||
it("burning: owner can only burn it's own tokens.", function(done) { | ||
var ctr; | ||
Gambit.new({ from: accounts[0] }) | ||
.then(function(result) { | ||
ctr = result; | ||
return ctr.transfer(accounts[1], 250000000000000, { | ||
from: accounts[0] | ||
}); | ||
}) | ||
.then(function(result) { | ||
return ctr.burn.call(50000000000000, { from: accounts[0] }); | ||
}) | ||
.then(function(result) { | ||
assert.isFalse(result); | ||
done(); | ||
}) | ||
.catch(done); | ||
it("burning: owner can only burn it's own tokens.", async () => { | ||
let ctr = await Gambit.new({ from: accounts[0] }); | ||
await ctr.transfer(accounts[1], 250000000000000, { | ||
from: accounts[0] | ||
}); | ||
await assertFail( | ||
async () => await ctr.burn.call(50000000000000, { from: accounts[0] }) | ||
); | ||
}); | ||
|
||
it("burning: owner can only burn it's own tokens.", function(done) { | ||
var ctr; | ||
Gambit.new({ from: accounts[0] }) | ||
.then(function(result) { | ||
ctr = result; | ||
return ctr.burn.call(0, { from: accounts[0] }); | ||
}) | ||
.then(function(result) { | ||
assert.isFalse(result); | ||
done(); | ||
}) | ||
.catch(done); | ||
it("burning: owner can only burn it's own tokens.", async () => { | ||
let ctr = await Gambit.new({ from: accounts[0] }); | ||
await assertFail(async () => await ctr.burn.call(0, { from: accounts[0] })); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = async function assertFail(callback, message) { | ||
let web3ErrorThrown = false; | ||
try { | ||
await callback(); | ||
} catch (error) { | ||
if (error.message.search("invalid opcode")) web3ErrorThrown = true; | ||
} | ||
assert.ok(web3ErrorThrown, message || "Transaction should fail"); | ||
}; |
Oops, something went wrong.