Skip to content

Commit

Permalink
New event Created() in marketJobFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
tiero committed Nov 28, 2017
1 parent e8e896b commit a1c9709
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 51 deletions.
27 changes: 20 additions & 7 deletions dao/contracts/market/MarketJobFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@ import "./MarketJob.sol";

contract MarketJobFactory {

event Created(address creator, address contractAddress);

function create(
address[] agents,
uint256[] amounts,
uint256[] services,
address token,
address payer,
bytes firstPacket) public returns (MarketJob)
address[] agents,
uint256[] amounts,
uint256[] services,
address token,
address payer,
bytes firstPacket ) public returns (MarketJob)
{
return new MarketJob(agents, amounts, services, token, payer, firstPacket);
MarketJob marketJob = new MarketJob(
agents,
amounts,
services,
token,
payer,
firstPacket
);

Created(msg.sender, marketJob);

return marketJob;
}

}
16 changes: 3 additions & 13 deletions dao/js/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
/**
*
*
AgentFactory: 0xc2950c3526254417351438babe5f2100cba90bf2
Agent: 0x2bb2fdf0eb609046bbba217bca0765759a95600d
AgentRegistry: 0x7988941a7d6037ef89b031af8606b88a1aa09e91
FixedSupplyToken: 0xc180a3910eb79f257a849a0ecd5f1876223c2858
Escrow: 0x278c4b8a81eebc94f2b2ebcac2ae33d4b889f5eb
ownable: 0x4593de2c43ec702262480f6b0a57a200fa1296ed
*
*/

//web3js
const Web3 = require('web3')
const web3 = new Web3(Web3.givenProvider || 'http://localhost:8545')
const web3 = new Web3(Web3.givenProvider)
const OWNER = web3.eth.accounts[0]
console.log(OWNER)
//const OWNER = '0xb9d2bdfe453640730919fbd8acc5083e991177ff'
Expand Down Expand Up @@ -121,4 +111,4 @@ async function main() {
}


main()
//main()
61 changes: 61 additions & 0 deletions dao/js/market.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//web3js
const Web3 = require('web3')
const web3 = new Web3("http://localhost:8545")
//contracts ABI
const marketFactory = require("../build/contracts/MarketJobFactory.json")
const token = require("../build/contracts/SingularityNetToken.json")
//constants
const MARKET_FACTORY_ADDRESS = "0xB86d5Ec230F706104eA3CDA6664AA02548591124"
const TOKEN_ADDRESS = "0xbf625fD0aE8C827D9A9ecbA19fe959723CE052EC"
const firstAgent = "0x951BE8FAE44CD16a1152DA1CcC8c414f7aEC7bd6"
const PAYER = "0xabdd6525BC4012B07a3A3758070C676fAd70869B"

const tokenContract = new web3.eth.Contract(token.abi,TOKEN_ADDRESS)
const factoryContract = new web3.eth.Contract(marketFactory.abi,MARKET_FACTORY_ADDRESS)
//payload dev
const GAS = 200000, GAS_PRICE = 10000000000000,
PAYLOAD = { from:PAYER, gas: GAS, gasPrice: GAS_PRICE}


async function getSymbol() {
return await new Promise((resolve,reject) => {
tokenContract.methods.SYMBOL.call()
.then(resolve)
.catch(reject)
})
}
//appendPacket
async function createMarketJob() {
return await new Promise((resolve,reject) => {
factoryContract.methods.create(
[firstAgent], //agents
[300], //amounts
[101], //ids services
TOKEN_ADDRESS, //token addrss
PAYER, //payer
"0x01"
).send(PAYLOAD)
.then(result => {
resolve(result)
})
.catch( reason => {
reject(reason)
})
})
}


async function main() {
try {
//console.log(Object.keys(tokenContract.methods))
console.log(await tokenContract.methods.SYMBOL().call())
const result = await createMarketJob()
console.log(result.events)
//const marketJobContract = new web3.eth.Contract(marketJob.abi)
} catch (reason) {
console.log(reason)
}
}

main()

2 changes: 1 addition & 1 deletion dao/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"web3": "^1.0.0-beta.20"
"web3": "^1.0.0-beta.26"
}
}
3 changes: 1 addition & 2 deletions dao/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
"author": "tiero",
"license": "MIT",
"dependencies": {
"web3": "^1.0.0-beta.24",
"truffle": "^3.4.9",
"ethereumjs-testrpc": "^4.1.3",
"truffle-hdwallet-provider": "0.0.3",
"zeppelin-solidity": "^1.3.0"
}
}
5 changes: 0 additions & 5 deletions dao/test/TestMarketJob.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ contract('Market Job', function ([payer, firstAgent, secondAgent, thirdAgent]) {

const amounts = [new web3.BigNumber(300), new web3.BigNumber(300), new web3.BigNumber(400)]

beforeEach(async () => {

})



it('DEPOSIT # only the payer can deposit AGI token', async () => {
const token = await AGIToken.new(payer, 1000)
Expand Down
19 changes: 13 additions & 6 deletions dao/test/TestMarketJobFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,35 @@ const MarketJob = artifacts.require('market/MarketJob.sol')
const AGIToken = artifacts.require('tokens/SingularityNetTokenMock.sol')

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


beforeEach(async () => {
token = await AGIToken.new(agent, 100)
factory = await Factory.new()

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

assert.isNotNull(tx)

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

const result = await marketJob.setJobCompleted("0x0", { from: agent })

assert.equal(result.logs[0].event, 'JobCompleted', 'Job was not completed')
})


Expand Down
35 changes: 18 additions & 17 deletions dao/truffle.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
const HDWalletProvider = require("truffle-hdwallet-provider")
const mnemonic //MNEMONIC
const host //NODE

module.exports = {
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*" // Match any network id
},
docker: {
host: "testrpc",
port: 8545,
network_id: "*" // Match any network id
},
kovan: {
host: "localhost",
port: 8549,
network_id: "*" // Match any network id
}
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*" // Match any network id
},
};
kovan: {
provider: () => {
return new HDWalletProvider(mnemonic, host)
},
gas: 4700000,
network_id: "*" // Match any network id
}
},
}

0 comments on commit a1c9709

Please sign in to comment.