Skip to content

Commit

Permalink
Merge a44f502 into 11a95b3
Browse files Browse the repository at this point in the history
  • Loading branch information
Janther committed Oct 30, 2017
2 parents 11a95b3 + a44f502 commit c64f0c0
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 8 deletions.
12 changes: 10 additions & 2 deletions contracts/Contribution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ contract Contribution is Controlled, TokenController {
address public remainderHolder;
address public devHolder;
address public communityHolder;
address public exchanger;

address public collector;
uint256 public collectorWeiCap;
Expand Down Expand Up @@ -126,6 +127,7 @@ contract Contribution is Controlled, TokenController {

// Exchangerate from apt to aix 2500 considering 25% bonus.
require(aix.generateTokens(_exchanger, weiPreCollected.mul(2500)));
exchanger = _exchanger;

Initialized(initializedBlock);
}
Expand Down Expand Up @@ -218,11 +220,17 @@ contract Contribution is Controlled, TokenController {
return true;
}

function onTransfer(address, address, uint256) public returns (bool) {
function onTransfer(address _from, address, uint256) public returns (bool) {
if (_from == exchanger) {
return true;
}
return transferable;
}

function onApprove(address, address, uint256) public returns (bool) {
function onApprove(address _from, address, uint256) public returns (bool) {
if (_from == exchanger) {
return true;
}
return transferable;
}

Expand Down
137 changes: 137 additions & 0 deletions test/exchanger_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
const MockContribution = artifacts.require("MockContribution");
const AIX = artifacts.require("AIX");
const APT = artifacts.require("APT");
const MiniMeTokenFactory = artifacts.require("MiniMeTokenFactory");
const Exchanger = artifacts.require("MockExchanger");
const MockRemainderTokenHolder = artifacts.require("MockRemainderTokenHolder");
const assert = require("chai").assert;
const BigNumber = web3.BigNumber;
import { expectThrow, duration, latestBlock, getTime } from "./utils.js";

contract(
"Exchanger",
([miner, owner, dev, community, remainder, collector]) => {
let tokenFactory;
let aix;
let contribution;
let exchanger;
let apt;
let tokensPreSold = new BigNumber(50 * 10 ** 18);
let multiSig = owner;
let totalCap;
let collectorWeiCap;
let sendingAmount;
let currentTime;
let remainderHolder;
let _devHolder;
let _communityHolder;
let latestBlockNumber;

describe("collect", async function() {
before(async function() {
tokenFactory = await MiniMeTokenFactory.new();
});

beforeEach(async function() {
apt = await APT.new(tokenFactory.address);
await apt.generateTokens(owner, tokensPreSold);
aix = await AIX.new(tokenFactory.address);
contribution = await MockContribution.new(aix.address);
exchanger = await Exchanger.new(
apt.address,
aix.address,
contribution.address
);

remainderHolder = await MockRemainderTokenHolder.new(
remainder,
contribution.address,
aix.address
);

totalCap = new BigNumber(5 * 10 ** 18); // 5 eth
collectorWeiCap = totalCap.div(10);
sendingAmount = new BigNumber(10 ** 18); // 1 eth
currentTime = getTime();
_devHolder = "0x0039F22efB07A647557C7C5d17854CFD6D489eF2";
_communityHolder = "0x0039F22efB07A647557C7C5d17854CFD6D489eF3";

latestBlockNumber = await latestBlock();

await contribution.setBlockTimestamp(currentTime);
await contribution.setBlockNumber(latestBlockNumber);

await aix.changeController(contribution.address);

await contribution.initialize(
apt.address,
exchanger.address,
multiSig,
remainderHolder.address,
_devHolder,
_communityHolder,
collector,
collectorWeiCap,
totalCap,
currentTime + 1,
currentTime + 10
);

currentTime = getTime();
latestBlockNumber = await latestBlock();
await contribution.setBlockTimestamp(currentTime + 1);
await contribution.setBlockNumber(latestBlockNumber + 1);
});

it("collect()", async function() {
const exchangerBalance = await aix.balanceOf(exchanger.address);
assert.equal(exchangerBalance.toNumber(), 50 * 2500 * 10 ** 18);
let ownerBalance = await aix.balanceOf(owner);
assert.equal(ownerBalance.toNumber(), 0);
await exchanger.setBlockTimestamp(currentTime + 10);
await exchanger.collect({ from: owner });
ownerBalance = await aix.balanceOf(owner);
assert.equal(ownerBalance.toNumber(), 50 * 2500 * 10 ** 18);
});

it("()", async function() {
const exchangerBalance = await aix.balanceOf(exchanger.address);
assert.equal(exchangerBalance.toNumber(), 50 * 2500 * 10 ** 18);
let ownerBalance = await aix.balanceOf(owner);
assert.equal(ownerBalance.toNumber(), 0);
await exchanger.setBlockTimestamp(currentTime + 10);
await exchanger.sendTransaction({ from: owner });
ownerBalance = await aix.balanceOf(owner);
assert.equal(ownerBalance.toNumber(), 50 * 2500 * 10 ** 18);
});

it("with transferable false", async function() {
const exchangerBalance = await aix.balanceOf(exchanger.address);
assert.equal(exchangerBalance.toNumber(), 50 * 2500 * 10 ** 18);
let ownerBalance = await aix.balanceOf(owner);
assert.equal(ownerBalance.toNumber(), 0);
await contribution.allowTransfers(false);
let transferable = await contribution.transferable();
assert.isFalse(transferable);
await exchanger.setBlockTimestamp(currentTime + 10);
await exchanger.collect({ from: owner });
ownerBalance = await aix.balanceOf(owner);
assert.equal(ownerBalance.toNumber(), 50 * 2500 * 10 ** 18);
});

it("with transferable true", async function() {
const exchangerBalance = await aix.balanceOf(exchanger.address);
assert.equal(exchangerBalance.toNumber(), 50 * 2500 * 10 ** 18);
let ownerBalance = await aix.balanceOf(owner);
assert.equal(ownerBalance.toNumber(), 0);
await contribution.allowTransfers(true);
let transferable = await contribution.transferable();
assert.isTrue(transferable);
await exchanger.setBlockTimestamp(currentTime + 10);
await exchanger.collect({ from: owner });
ownerBalance = await aix.balanceOf(owner);
assert.equal(ownerBalance.toNumber(), 50 * 2500 * 10 ** 18);
});
});
}
);
5 changes: 2 additions & 3 deletions test/mocks/MockContribution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ contract MockContribution is Contribution {
uint256 public blockNumber;
uint256 public timeStamp;

function MockContribution(address _aix)
Contribution(_aix)
{
function MockContribution(address _aix) Contribution(_aix) {
timeStamp = now;
}


Expand Down
23 changes: 23 additions & 0 deletions test/mocks/MockExchanger.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pragma solidity ^0.4.15;

import '../../contracts/Exchanger.sol';

contract MockExchanger is Exchanger {
uint256 public timeStamp;

function MockExchanger(
address _apt,
address _aix,
address _contribution
) Exchanger(_apt, _aix, _contribution) {
timeStamp = now;
}

function getBlockTimestamp() internal constant returns (uint256) {
return timeStamp;
}

function setBlockTimestamp(uint256 _timeStamp) public {
timeStamp = _timeStamp;
}
}
8 changes: 5 additions & 3 deletions test/mocks/MockRemainderTokenHolder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import '../../contracts/RemainderTokenHolder.sol';
contract MockRemainderTokenHolder is RemainderTokenHolder {
uint256 public timeStamp;

function MockRemainderTokenHolder(address _controller, address _contribution, address _aix)
RemainderTokenHolder(_controller, _contribution, _aix)
{
function MockRemainderTokenHolder(
address _controller,
address _contribution,
address _aix
) RemainderTokenHolder(_controller, _contribution, _aix) {
timeStamp = now;
}

Expand Down

0 comments on commit c64f0c0

Please sign in to comment.