@tokenfoundry/token-contracts
Advanced tools
Comparing version 0.3.7 to 0.3.8
{ | ||
"name": "@tokenfoundry/token-contracts", | ||
"version": "0.3.7", | ||
"version": "0.3.8", | ||
"description": "Code for token contracts to be used by token foundry projects", | ||
@@ -8,3 +8,3 @@ "repository": "https://github.com/tokenfoundry/smart-contracts.git", | ||
"scripts": { | ||
"lint": "eslint .", | ||
"lint": "eslint test", | ||
"coverage": "solidity-coverage", | ||
@@ -11,0 +11,0 @@ "test": "truffle test" |
export default function ether(n) { | ||
return new web3.BigNumber(web3.toWei(n, 'ether')); | ||
return new web3.BigNumber(web3.toWei(n, "ether")); | ||
} |
@@ -1,1 +0,1 @@ | ||
export default 'revert'; | ||
export default "revert"; |
@@ -1,1 +0,1 @@ | ||
export default 'invalid opcode'; | ||
export default "invalid opcode"; |
@@ -7,3 +7,3 @@ export default async promise => { | ||
// and an actual invalid jump. | ||
const invalidOpcode = error.message.search('invalid opcode') >= 0; | ||
const invalidOpcode = error.message.search("invalid opcode") >= 0; | ||
// TODO: When we contract A calls contract B, and B throws, instead | ||
@@ -13,11 +13,11 @@ // of an 'invalid jump', we get an 'out of gas' error. How do | ||
// testrpc log actually show an 'invalid jump' event.) | ||
const outOfGas = error.message.search('out of gas') >= 0; | ||
const revert = error.message.search('revert') >= 0; | ||
const outOfGas = error.message.search("out of gas") >= 0; | ||
const revert = error.message.search("revert") >= 0; | ||
assert( | ||
invalidOpcode || outOfGas || revert, | ||
'Expected throw, got \'' + error + '\' instead', | ||
`Expected throw, got '${error}' instead` | ||
); | ||
return; | ||
} | ||
assert.fail('Expected throw not received'); | ||
assert.fail("Expected throw not received"); | ||
}; |
@@ -1,2 +0,2 @@ | ||
import latestTime from './latestTime'; | ||
import latestTime from "./latestTime"; | ||
@@ -8,18 +8,22 @@ // Increases testrpc time by the passed duration in seconds | ||
return new Promise((resolve, reject) => { | ||
web3.currentProvider.sendAsync({ | ||
jsonrpc: '2.0', | ||
method: 'evm_increaseTime', | ||
params: [duration], | ||
id: id, | ||
}, err1 => { | ||
if (err1) return reject(err1); | ||
web3.currentProvider.sendAsync( | ||
{ | ||
jsonrpc: "2.0", | ||
method: "evm_increaseTime", | ||
params: [duration], | ||
id, | ||
}, | ||
err1 => { | ||
if (err1) reject(err1); | ||
web3.currentProvider.sendAsync({ | ||
jsonrpc: '2.0', | ||
method: 'evm_mine', | ||
id: id+1, | ||
}, (err2, res) => { | ||
return err2 ? reject(err2) : resolve(res); | ||
}); | ||
}); | ||
web3.currentProvider.sendAsync( | ||
{ | ||
jsonrpc: "2.0", | ||
method: "evm_mine", | ||
id: id + 1, | ||
}, | ||
(err2, res) => (err2 ? reject(err2) : resolve(res)) | ||
); | ||
} | ||
); | ||
}); | ||
@@ -36,5 +40,8 @@ } | ||
export async function increaseTimeTo(target) { | ||
let now = await latestTime(); | ||
if (target < now) throw Error(`Cannot increase current time(${now}) to a moment in the past(${target})`); | ||
let diff = target - now; | ||
const now = await latestTime(); | ||
if (target < now) | ||
throw Error( | ||
`Cannot increase current time(${now}) to a moment in the past(${target})` | ||
); | ||
const diff = target - now; | ||
return increaseTime(diff); | ||
@@ -44,8 +51,20 @@ } | ||
export const duration = { | ||
seconds: function(val) { return val;}, | ||
minutes: function(val) { return val * this.seconds(60); }, | ||
hours: function(val) { return val * this.minutes(60); }, | ||
days: function(val) { return val * this.hours(24); }, | ||
weeks: function(val) { return val * this.days(7); }, | ||
years: function(val) { return val * this.days(365);} | ||
seconds(val) { | ||
return val; | ||
}, | ||
minutes(val) { | ||
return val * this.seconds(60); | ||
}, | ||
hours(val) { | ||
return val * this.minutes(60); | ||
}, | ||
days(val) { | ||
return val * this.hours(24); | ||
}, | ||
weeks(val) { | ||
return val * this.days(7); | ||
}, | ||
years(val) { | ||
return val * this.days(365); | ||
}, | ||
}; |
// Returns the time of the last mined block in seconds | ||
export default function latestTime() { | ||
return new Promise((resolve, reject) => { | ||
web3.eth.getBlock('latest', (error, result) => { | ||
web3.eth.getBlock("latest", (error, result) => { | ||
if (error) reject(error); | ||
@@ -6,0 +6,0 @@ resolve(result.timestamp); |
@@ -1,8 +0,7 @@ | ||
import expectThrow from './helpers/expectThrow'; | ||
import expectThrow from "./helpers/expectThrow"; | ||
const Token = artifacts.require('Token'); | ||
const TokenControllerMock = artifacts.require('TokenControllerMock'); | ||
const Token = artifacts.require("Token"); | ||
const TokenControllerMock = artifacts.require("TokenControllerMock"); | ||
contract('Token', (accounts) => { | ||
contract("Token", accounts => { | ||
let token; | ||
@@ -19,5 +18,5 @@ let controller; | ||
beforeEach(async() => { | ||
beforeEach(async () => { | ||
initialAmount = new web3.BigNumber(1000); | ||
token = await Token.new(initialAmount, 'Token', 'TKN', 18); | ||
token = await Token.new(initialAmount, "Token", "TKN", 18); | ||
controller = await TokenControllerMock.new(); | ||
@@ -30,19 +29,21 @@ await controller.setAllowed(owner); | ||
it('should fail if initial token supply is 0', async () => { | ||
await expectThrow(Token.new(0, 'Token', 'TKN', 18)); | ||
it("should fail if initial token supply is 0", async () => { | ||
await expectThrow(Token.new(0, "Token", "TKN", 18)); | ||
}); | ||
it('should not be possible to call non-allowed functions', async () => { | ||
await expectThrow(token.sendTransaction({ from: owner, value: 10 })); //test fallback function | ||
await expectThrow(token.transferOwnership(randomGuy ,{ from: randomGuy })); | ||
it("should not be possible to call non-allowed functions", async () => { | ||
await expectThrow(token.sendTransaction({ from: owner, value: 10 })); // test fallback function | ||
await expectThrow(token.transferOwnership(randomGuy, { from: randomGuy })); | ||
await expectThrow(token.setController(0)); | ||
await expectThrow(token.setController(controller.address, { from: randomGuy })); | ||
await expectThrow( | ||
token.setController(controller.address, { from: randomGuy }) | ||
); | ||
}); | ||
it('should be owned by owner', async () => { | ||
const tokenOwner = await token.owner.call(); | ||
assert.equal(tokenOwner,owner); | ||
it("should be owned by owner", async () => { | ||
const tokenOwner = await token.owner.call(); | ||
assert.equal(tokenOwner, owner); | ||
}); | ||
it('should start with the correct initial amount', async () => { | ||
it("should start with the correct initial amount", async () => { | ||
const amount = await token.totalSupply.call(); | ||
@@ -55,7 +56,7 @@ const owned = await token.balanceOf.call(owner); | ||
it('should not be possible to transfer for an address that is not allowed', async () => { | ||
it("should not be possible to transfer for an address that is not allowed", async () => { | ||
await expectThrow(token.transfer(randomGirl, 1, { from: notAllowed })); | ||
}); | ||
it('should be possible to transfer for an address that is allowed', async () => { | ||
it("should be possible to transfer for an address that is allowed", async () => { | ||
await token.transfer(allowed, 1, { from: owner }); | ||
@@ -68,8 +69,10 @@ await token.transfer(randomGirl, 1, { from: allowed }); | ||
it('should not be possible to transfer from an address that is not allowed', async () => { | ||
it("should not be possible to transfer from an address that is not allowed", async () => { | ||
await token.approve(randomGirl, 10, { from: notAllowed }); | ||
await expectThrow(token.transferFrom(notAllowed, randomGuy, 10, { from: randomGirl })); | ||
await expectThrow( | ||
token.transferFrom(notAllowed, randomGuy, 10, { from: randomGirl }) | ||
); | ||
}); | ||
it('should be possible to transfer from an address that is not allowed', async () => { | ||
it("should be possible to transfer from an address that is not allowed", async () => { | ||
await token.transfer(allowed, 10, { from: owner }); | ||
@@ -82,3 +85,2 @@ await token.approve(randomGirl, 10, { from: allowed }); | ||
}); | ||
}); |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
1
166534
48
1039