-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Showing
2 changed files
with
71 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
pragma solidity ^0.4.11; | ||
|
||
import "./ERC20Basic.sol"; | ||
import "../ownership/Ownable.sol"; | ||
|
||
contract TokenWallet is Ownable{ | ||
|
||
mapping(bytes32 => address) public tokens; | ||
|
||
function registerToken(address tokenAddr, bytes32 tokenName) onlyOwner{ | ||
tokens[tokenName] = tokenAddr; | ||
} | ||
|
||
function transferToken(address tokenAddr, address to, uint value) onlyOwner returns(bool){ | ||
return ERC20Basic(tokenAddr).transfer(to, value); | ||
} | ||
|
||
function transferToken(bytes32 tokenName, address to, uint value) onlyOwner returns(bool){ | ||
return ERC20Basic(tokens[tokenName]).transfer(to, value); | ||
} | ||
|
||
function checkBalance(address tokenAddr) constant returns(uint){ | ||
return ERC20Basic(tokenAddr).balanceOf(this); | ||
} | ||
|
||
function checkBalance(bytes32 tokenName) constant returns(uint){ | ||
return ERC20Basic(tokens[tokenName]).balanceOf(this); | ||
} | ||
} |
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,42 @@ | ||
const assertJump = require('./helpers/assertJump'); | ||
|
||
var TokenWallet = artifacts.require("../contracts/token/TokenWallet.sol") | ||
var BasicTokenMock = artifacts.require("./helpers/BasicTokenMock.sol"); | ||
|
||
contract('TokenWallet', function(accounts) { | ||
let token; | ||
let tokenWallet; | ||
let owner; | ||
|
||
beforeEach(async () => { | ||
token = await BasicTokenMock.new(accounts[0], 100); | ||
tokenWallet = await TokenWallet(); | ||
owner = await tokenWallet.owner(); | ||
|
||
await token.transfer(tokenWallet, 10 , {from: owner}); | ||
}); | ||
|
||
it("should be able to register tokens", async function() { | ||
let tokenAddress = await token.address; | ||
await tokenWallet.registerToken(tokenAddress, "BasicToken", {from: owner}); | ||
let tkAddr = await tokenWallet.tokens["BasicToken"]; | ||
assert.isEqual(tkAddr, tokenAddress); | ||
}) | ||
|
||
it("should check balance correctly by address", async function(){ | ||
let tokenAddress = await token.addres; | ||
let balance = await tokenWallet.checkBalance(tokenAddress); | ||
assert.equal(balance, 10); | ||
}); | ||
|
||
// it("should throw an error when trying to transfer more than balance", async function() { | ||
// let token = await BasicTokenMock.new(accounts[0], 100); | ||
// try { | ||
// let transfer = await token.transfer(accounts[1], 101); | ||
// assert.fail('should have thrown before'); | ||
// } catch(error) { | ||
// assertJump(error); | ||
// } | ||
// }); | ||
|
||
}); |