Skip to content

Commit

Permalink
Update to sol 4.18
Browse files Browse the repository at this point in the history
  • Loading branch information
tiero committed Nov 26, 2017
1 parent 8e38c4d commit b4f8759
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 81 deletions.
2 changes: 1 addition & 1 deletion dao/contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.15;
pragma solidity ^0.4.18;


contract Migrations {
Expand Down
2 changes: 1 addition & 1 deletion dao/contracts/agent/Agent.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.15;
pragma solidity ^0.4.18;

import "./AgentInterface.sol";
import 'zeppelin-solidity/contracts/ownership/Ownable.sol';
Expand Down
2 changes: 1 addition & 1 deletion dao/contracts/agent/AgentFactory.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.15;
pragma solidity ^0.4.18;

import './Agent.sol';

Expand Down
2 changes: 1 addition & 1 deletion dao/contracts/agent/AgentInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.15;
pragma solidity ^0.4.18;

import "../market/MarketJob.sol";

Expand Down
2 changes: 1 addition & 1 deletion dao/contracts/foundation/AgiCrowdsale.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.15;
pragma solidity ^0.4.18;

import '../tokens/SingularityNetToken.sol';
import 'zeppelin-solidity/contracts/math/SafeMath.sol';
Expand Down
14 changes: 7 additions & 7 deletions dao/contracts/market/MarketJob.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
pragma solidity ^0.4.15;
pragma solidity ^0.4.18;

import 'zeppelin-solidity/contracts/ownership/Ownable.sol';
import 'zeppelin-solidity/contracts/math/SafeMath.sol';
import '../tokens/SingularityNetToken.sol';
import './MarketJobInterface.sol';


contract MarketJob is MarketJobInterface, Ownable {
contract MarketJob is MarketJobInterface {
using SafeMath for uint256;

SingularityNetToken public token;
Expand Down Expand Up @@ -76,11 +75,12 @@ contract MarketJob is MarketJobInterface, Ownable {
}

function deposit(uint256 amount) onlyPayer jobPending public {
require(token.balanceOf(msg.sender) >= amount);
require(token.transferFrom(msg.sender, address(this), amount));
Deposited(msg.sender,amount);
}

function setJobCompleted(bytes _jobResult) onlyOwner onlyMasterAgent jobPending public {
function setJobCompleted(bytes _jobResult) onlyMasterAgent jobPending public {
jobCompleted = true;
jobResult = _jobResult;
JobCompleted();
Expand All @@ -93,12 +93,12 @@ contract MarketJob is MarketJobInterface, Ownable {

function withdraw() jobDone jobApproved public {
address agent = msg.sender;
require(amounts[agent].amount > 0);

uint256 amount = amounts[agent].amount;
require(amount > 0);
require(this.balance >= amount);

amounts[agent].amount = 0;
require(token.transferFrom(address(this), agent, amount));
assert(agent.send(amount));
Withdrew(agent,amount);
}
}
2 changes: 1 addition & 1 deletion dao/contracts/market/MarketJobFactory.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.15;
pragma solidity ^0.4.18;

import './MarketJob.sol';

Expand Down
2 changes: 1 addition & 1 deletion dao/contracts/market/MarketJobInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.15;
pragma solidity ^0.4.18;


contract MarketJobInterface {
Expand Down
2 changes: 1 addition & 1 deletion dao/contracts/registries/AgentRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.15;
pragma solidity ^0.4.18;

import "./AgentRegistryInterface.sol";

Expand Down
2 changes: 1 addition & 1 deletion dao/contracts/registries/AgentRegistryInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.15;
pragma solidity ^0.4.18;


contract AgentRegistryInterface {
Expand Down
2 changes: 1 addition & 1 deletion dao/contracts/tokens/SingularityNetToken.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.15;
pragma solidity ^0.4.18;

import "zeppelin-solidity/contracts/token/PausableToken.sol";
import "zeppelin-solidity/contracts/token/BurnableToken.sol";
Expand Down
71 changes: 35 additions & 36 deletions dao/test/TestAgiCrowdsale.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Crowdsale = artifacts.require('./helpers/AgiCrowdsaleMock.sol')
const AGIToken = artifacts.require('SingularityNetToken.sol')

const { latestTime, duration } = require('./helpers/latestTime')
const { increaseTimeTo } = require('./helpers/increaseTime')
const { increaseTimeTo } = require('./helpers/increaseTime')


contract('AgiCrowdsale', async ([miner, firstContributor, secondContributor, wallet]) => {
Expand All @@ -18,105 +18,104 @@ contract('AgiCrowdsale', async ([miner, firstContributor, secondContributor, wal
const goal = new web3.BigNumber(3000 * Math.pow(10, 18))
const cap = new web3.BigNumber(15000 * Math.pow(10, 18))
agiCrowdsale = await Crowdsale.new(token.address, wallet, startTime, endTime, rate, cap, goal)
await agiCrowdsale.setBlockTimestamp(startTime + duration.days(1))
await agiCrowdsale.setBlockTimestamp(startTime + duration.days(2))
})

describe('initialization', () => {

it('should not be finalized', async () => {
const isFinalized = await agiCrowdsale.isFinalized()

assert.isFalse(isFinalized, "isFinalized should be false")
})

it('goal should be 3000 ETH', async () => {
const goal = await agiCrowdsale.goal()
assert.equal(goal.toString(10), '3000000000000000000000', "goal is incorrect")
})

it('cap should be 15000 ETH', async () => {
const cap = await agiCrowdsale.cap()
assert.equal(cap.toString(10), '15000000000000000000000', "cap is incorrect")
})

it('should set the agiCrowdsale as a new owner of AGI token', async () => {
await token.setOwnership(agiCrowdsale.address)
const owner = await token.owner.call()
assert.equal(owner, agiCrowdsale.address, 'Crowdsale is not the owner of the token')
})

})

describe('whitelist', async () => {

it('should add two contributors into the whitelist', async () => {
await agiCrowdsale.updateWhitelist([firstContributor, secondContributor], 1, true)
await agiCrowdsale.updateWhitelist([firstContributor, secondContributor], true)
assert.isTrue(await agiCrowdsale.isWhitelisted(firstContributor))
assert.isTrue(await agiCrowdsale.isWhitelisted(secondContributor))
})

it('should add and remove the same contributor in whitelist', async () => {
await agiCrowdsale.updateWhitelist([firstContributor], 1, true)
await agiCrowdsale.updateWhitelist([firstContributor], true)
assert.isTrue(await agiCrowdsale.isWhitelisted(firstContributor))

await agiCrowdsale.updateWhitelist([firstContributor], 1, false)
await agiCrowdsale.updateWhitelist([firstContributor], false)
assert.isFalse(await agiCrowdsale.isWhitelisted(firstContributor))
})

// it('should set the agiCrowdsale as a new owner of AGI token', async () => {
// await token.setOwnership(agiCrowdsale.address)
// const owner = await token.owner.call()
// assert.equal(owner, agiCrowdsale.address, 'Crowdsale is not the owner of the token')
// })
})

describe('sale', async () => {

it('should not accept purchase before start', async () => {
try {
await agiCrowdsale.sendTransaction({value:new web3.BigNumber(web3.toWei(1, 'ether')),from:firstContributor})
await agiCrowdsale.sendTransaction({ value: new web3.BigNumber(web3.toWei(1, 'ether')), from: firstContributor })
assert.fail('should have thrown before')
} catch (error) {
assert.isAbove(error.message.search('invalid opcode'), -1, 'Invalid opcode error must be returned');
}
})

it('should accept payments during the sale', async () => {
await agiCrowdsale.updateWhitelist([firstContributor], 1, true)
it('should accept payments during the sale and issue tokens', async () => {
await agiCrowdsale.updateWhitelist([firstContributor], true)

await token.setOwnership(agiCrowdsale.address)

const rate = new web3.BigNumber(1000)
const weiToCogs = new web3.BigNumber(Math.pow(10,-10))
const weiToCogs = new web3.BigNumber(Math.pow(10, -10))
const startTime = latestTime() + duration.seconds(1)

const investmentAmount = new web3.BigNumber(web3.toWei(0.5, 'ether'))
const expectedCotributorAmount = rate.mul(investmentAmount).mul(weiToCogs)

await increaseTimeTo(startTime)

const value = new web3.BigNumber(web3.toWei(0.5, 'ether'))

await agiCrowdsale.sendTransaction({ value, from: firstContributor })

const initialSupply = await token.INITIAL_SUPPLY.call()
const contributorAmount = await token.balanceOf(firstContributor)

assert.equal(contributorAmount.toString(), expectedCotributorAmount.toString())
assert.equal((initialSupply - contributorAmount).toString(), (initialSupply - expectedCotributorAmount).toString())
});

it('should purchase tokens', async () => {
assert.isFalse(await agiCrowdsale.isWhitelisted(firstContributor))
try {
await token.transfer(secondContributor, 100)
assert.fail('should have thrown before')
} catch (error) {
assert.isAbove(error.message.search('invalid opcode'), -1, 'Invalid opcode error must be returned');
}

await agiCrowdsale.updateWhitelist([firstContributor], 1, true)
assert.isTrue(await agiCrowdsale.isWhitelisted(firstContributor))

const balance = await token.balanceOf(firstContributor)
assert.equal(balance.toNumber(), 0)
const isFinalized = await agiCrowdsale.isFinalized()

assert.isFalse(isFinalized, "isFinalized should be true")

// await token.setOwnership(agiCrowdsale.address)

const value = web3.toWei(1, 'ether')
const balanceAfter = await token.balanceOf(firstContributor)
assert.equal(balanceAfter.toNumber(), 0)
//const contributedAmount = await agiCrowdsale.whitelist.call(firstContributor).contributedAmount
//assert.isTrue(contributedAmount.toNumber(10) > 0, 'balanceOf is 0 for contributor who just bought tokens')
})

})

})



50 changes: 31 additions & 19 deletions dao/test/TestMarketJob.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,53 @@
const Market = artifacts.require('market/MarketJob.sol')
const AGIToken = artifacts.require('tokens/SingularityNetTokenMock.sol')

contract('Market Job', function ([firstAgent,secondAgent,thirdAgent,payer]) {
contract('Market Job', function ([payer,firstAgent,secondAgent,thirdAgent]) {

let marketJob
let token
const amounts = [30, 40, 30]

beforeEach(async () => {
const agiToken = await AGIToken.new(payer,100)
token = await AGIToken.new(payer,100)
marketJob = await Market.new(
[firstAgent, secondAgent, thirdAgent], // agents
amounts, //amounts
[101, 102, 103], // services id
agiToken.address, //token address
token.address, //token address
payer, // payer address
"0x0" // first bytes packet
)
console.log(await marketJob.owner.call(),marketJob.address)
})



it('only the payer can deposit AGI token', async () => {
// console.log(await token.balanceOf(payer))
const token = await AGIToken.new(payer,100)
const watch = token.Approval()
amount = 100
const amount = new web3.BigNumber(1000)

const watch = token.Approval()


await token.approve(marketJob.address, amount, {from: payer})
const allowance = await token.allowance(marketJob.address, payer)
const allowance = await token.allowance.call(marketJob.address,payer)


assert.equal(watch.get()[0].args.owner, payer)
assert.equal(watch.get()[0].args.spender, marketJob.address)

const result = await marketJob.deposit(amount, {from:payer})
//console.log(allowance.toNumber())

await marketJob.deposit(amount)

assert.strictEqual(
(await token.balanceOf.call(marketJob.address)).toNumber(),
amount.toNumber()
);

assert.equal(result.logs[0].event, 'Deposited', 'Amount was not deposited')
})

it('only the the master agent can set the job as completed and trigger an event', async () => {
it('COMPLETION # only the the master agent can set the job as completed and trigger an event', async () => {
const hash = '0x01'

const result = await marketJob.setJobCompleted(hash)
Expand All @@ -46,22 +57,23 @@ contract('Market Job', function ([firstAgent,secondAgent,thirdAgent,payer]) {
assert.equal(result.logs[0].event, 'JobCompleted', 'Job was not completed')
})

it('only the the payer can set the job as approved and trigger an event', async () => {
it('APPROVAL # only the the payer can set the job as approved ', async () => {

const result = await marketJob.setJobAccepted({from:payer})
const result = await marketJob.setJobAccepted()
const jobAccepted = await marketJob.jobAccepted.call()

assert.equal(jobAccepted,true,'the job state is euqal to approved')
assert.equal(jobAccepted, true,'the job state is euqal to approved')
assert.equal(result.logs[0].event, 'JobApproved', 'Job was not approved')
})

it('only allowed agents can request a withdrawal', async () => {

const amount = amounts[0]
it('WITHDRAW # only allowed agents can request a withdrawal', async () => {

await token.approve(firstAgent, amount);

const result = await marketJob.withdraw({from:firstAgent})
await marketJob.setJobCompleted("0x0")
await marketJob.setJobAccepted()

const result = await marketJob.withdraw()
console.log(result)
console.log(await token.balanceOf(firstAgent))

assert.equal(result.logs[0].event, 'Withdrew', 'Withdrawal was not approved')
})
Expand Down
18 changes: 11 additions & 7 deletions dao/test/TestMarketJobFactory.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
const Factory = artifacts.require('market/MarketJobFactory.sol')
const MarketJob = artifacts.require('market/MarketJob.sol')
const AGIToken = artifacts.require('tokens/SingularityNetTokenMock.sol')

contract('Market Job Factory', function (accounts) {
contract('Market Job Factory', function ([agent,payer]) {
let factory
let token

beforeEach(async () => {
token = await AGIToken.new(accounts[0],100)
token = await AGIToken.new(agent,100)
factory = await Factory.new()
})
// master agent: accounts[0]
it('verifies that someone can create a market job', async () => {
const marketJob = await factory.create(
[accounts[0]], // agents
it('verifies that an agent can create a market job', async () => {
const tx = await factory.create.sendTransaction(
[agent], // agents
[100], // amounts
[12300], //id service
token.address, // token address
accounts[1], // payer address
payer, // payer address
"0x0" // first packet )
)

assert.isNotNull(marketJob)
assert.isNotNull(tx)
const marketJob = await MarketJob.new(tx)
assert.isNotNull(marketJob.address)

})


Expand Down
2 changes: 1 addition & 1 deletion dao/test/helpers/AgiCrowdsaleMock.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.15;
pragma solidity ^0.4.18;

import '../../contracts/foundation/AgiCrowdsale.sol';

Expand Down
Loading

0 comments on commit b4f8759

Please sign in to comment.