Skip to content
This repository has been archived by the owner on Jun 29, 2020. It is now read-only.

Add claim token function #130

Merged
merged 5 commits into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions blockchain/.solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module.exports = {
testrpcOptions: '-p 8555 --mnemonic "toddler weather rocket off sentence chat unlock flame organ shuffle treat awful"',
compileCommand: '../node_modules/.bin/truffle compile',
testCommand: '../node_modules/.bin/truffle test --network coverage',
skipFiles: ['ERC20.sol', 'TestERC20.sol'],
};
7,299 changes: 4,281 additions & 3,018 deletions blockchain/build/contracts/ProofOfPhysicalAddress.json

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions blockchain/contracts/ERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pragma solidity 0.4.19;


contract ERC20 {
function totalSupply() public constant returns (uint);
function balanceOf(address tokenOwner) public constant returns (uint balance);
function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns (bool success);

event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
12 changes: 12 additions & 0 deletions blockchain/contracts/ProofOfPhysicalAddress.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pragma solidity 0.4.19;

import "./EthereumClaimsRegistryInterface.sol";
import "./PhysicalAddressClaim.sol";
import "./ERC20.sol";


// Checks -> Effects -> Interactions
Expand Down Expand Up @@ -52,6 +53,7 @@ contract ProofOfPhysicalAddress {
event LogAddressRegistered(address indexed wallet, bytes32 keccakIdentifier);
event LogAddressUnregistered(address indexed wallet, bytes32 keccakIdentifier);
event LogAddressConfirmed(address indexed wallet, bytes32 keccakIdentifier);
event LogClaimedTokens(address token, address to, uint256 amount);

// Modifiers:
modifier onlyOwner() {
Expand Down Expand Up @@ -367,4 +369,14 @@ contract ProofOfPhysicalAddress {

LogAddressConfirmed(msg.sender, keccakIdentifier);
}

function claimTokens(address _token, address _to) public onlyOwner {
require(_token != address(0));
require(_to != address(0));

ERC20 token = ERC20(_token);
uint256 balance = token.balanceOf(this);
token.transfer(_to, balance);
LogClaimedTokens(_token, _to, balance);
}
}
44 changes: 44 additions & 0 deletions blockchain/contracts/TestERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
pragma solidity 0.4.19;

import "./ERC20.sol";


// contract used in the tests for ProofOfPhysicalAddress
contract TestERC20 is ERC20 {
uint256 public _totalSupply = 1000;

mapping(address => uint256) balances;

function TestERC20() public {
balances[msg.sender] = _totalSupply;
}

function totalSupply() public constant returns (uint256) {
return _totalSupply;
}

function balanceOf(address tokenOwner) public constant returns (uint256) {
return balances[tokenOwner];
}

function transfer(address to, uint256 tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender] - tokens;
balances[to] = balances[to] + tokens;
return true;
}

// not implemented
// the bodies are just to avoid compiler warnings
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
tokenOwner; spender;
return 0;
}
function approve(address spender, uint tokens) public returns (bool success) {
spender; tokens;
return false;
}
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
from; to; tokens;
return false;
}
}
7 changes: 6 additions & 1 deletion blockchain/migrations/1522104575_popa.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
var POPA = artifacts.require('ProofOfPhysicalAddress');
var PhysicalAddressClaim = artifacts.require('PhysicalAddressClaim');
var EthereumClaimsRegistry = artifacts.require('EthereumClaimsRegistry');
var TestERC20 = artifacts.require('TestERC20');

module.exports = function(deployer, network) {
return deployer.then(async () => {
await deployer.deploy(PhysicalAddressClaim);
await deployer.link(PhysicalAddressClaim, POPA);

let ethereumClaimsRegistryAddress = null;
if (network === 'development' || network === 'coverage') {
if (network === 'development' || network === 'test' || network === 'coverage') {
await deployer.deploy(EthereumClaimsRegistry);
let ethereumClaimsRegistry = await EthereumClaimsRegistry.deployed();
ethereumClaimsRegistryAddress = ethereumClaimsRegistry.address;
} else {
ethereumClaimsRegistryAddress = '0xaca1bcd8d0f5a9bfc95aff331da4c250cd9ac2da';
}

if (network === 'test' || network === 'coverage') {
await deployer.deploy(TestERC20);
}

await deployer.deploy(POPA, ethereumClaimsRegistryAddress);
});
};
2 changes: 1 addition & 1 deletion blockchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"scripts": {
"coverage": "NODE_ENV=test solidity-coverage",
"test": "NODE_ENV=test truffle test"
"test": "NODE_ENV=test truffle test --network test"
},
"dependencies": {},
"devDependencies": {
Expand Down
48 changes: 48 additions & 0 deletions blockchain/test/proof_of_physical_address.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const ProofOfPhysicalAddress = artifacts.require('ProofOfPhysicalAddress');
const TestERC20 = artifacts.require('TestERC20');
const BigNumber = require('bignumber.js');

// solidity-coverage copies all the files to a directory one level deeper, so
Expand Down Expand Up @@ -973,6 +974,53 @@ contract('setRegistry', function(accounts) {
});
});

contract('claimTokens', function(accounts) {
contract('', () => {
it('should allow the owner to send tokens in the contract to another user', async () => {
const popa = await ProofOfPhysicalAddress.deployed();
const token = await TestERC20.deployed();

const initialBalance = Number(await token.balanceOf(accounts[0]));

await token.transfer(popa.address, initialBalance);

assert.equal(Number(await token.balanceOf(popa.address)), initialBalance);
assert.equal(Number(await token.balanceOf(accounts[0])), 0);

await popa.claimTokens(token.address, accounts[0]);

assert.equal(Number(await token.balanceOf(popa.address)), 0);
assert.equal(Number(await token.balanceOf(accounts[0])), initialBalance);
});
});

contract('', () => {
it('should revert if token address is 0', async () => {
const popa = await ProofOfPhysicalAddress.deployed();

return popa.claimTokens('0x0', accounts[0])
.then(
() => assert.fail(), // should reject
() => {}
);
});
});

contract('', () => {
it('should revert if recipient address is 0', async () => {
const popa = await ProofOfPhysicalAddress.deployed();
const token = await TestERC20.deployed();

return popa.claimTokens(token.address, '0x0')
.then(
() => assert.fail(), // should reject
() => {}
);
});
});

});

contract('helpers', function(accounts) {
// userExists
contract('', () => {
Expand Down