Skip to content

Commit

Permalink
first draft of token wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
JGcarv committed Aug 17, 2017
1 parent 0ed98ea commit 6f47076
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
29 changes: 29 additions & 0 deletions contracts/token/TokenWallet.sol
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);
}
}
42 changes: 42 additions & 0 deletions test/TokenWallet.js
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);
// }
// });

});

0 comments on commit 6f47076

Please sign in to comment.