How to use extractEvents method in Playwright Internal

Best JavaScript code snippet using playwright-internal

callback.js

Source:callback.js Github

copy

Full Screen

...101 constants.NULL.BYTES32,102 "0x",103 { from: appProvider.address }104 );105 events = tools.extractEvents(txMined, AppRegistryInstance.address, "Transfer");106 AppInstance = await App.at(tools.BN2Address(events[0].args.tokenId));107 });108 });109 describe("dataset", async () => {110 it("create", async () => {111 txMined = await DatasetRegistryInstance.createDataset(112 datasetProvider.address,113 "Pi",114 constants.MULTIADDR_BYTES,115 constants.NULL.BYTES32,116 { from: datasetProvider.address }117 );118 events = tools.extractEvents(txMined, DatasetRegistryInstance.address, "Transfer");119 DatasetInstance = await Dataset.at(tools.BN2Address(events[0].args.tokenId));120 });121 });122 describe("workerpool", async () => {123 it("create", async () => {124 txMined = await WorkerpoolRegistryInstance.createWorkerpool(125 scheduler.address,126 "A test workerpool",127 { from: scheduler.address }128 );129 events = tools.extractEvents(txMined, WorkerpoolRegistryInstance.address, "Transfer");130 WorkerpoolInstance = await Workerpool.at(tools.BN2Address(events[0].args.tokenId));131 });132 it("change policy", async () => {133 await WorkerpoolInstance.changePolicy(/* worker stake ratio */ 35, /* scheduler reward ratio */ 5, { from: scheduler.address });134 });135 });136 });137 describe("tokens", async () => {138 it("balances before", async () => {139 assert.deepEqual(await appProvider.viewAccount(), [ 0, 0 ], "check balance");140 assert.deepEqual(await datasetProvider.viewAccount(), [ 0, 0 ], "check balance");141 assert.deepEqual(await scheduler.viewAccount(), [ 0, 0 ], "check balance");142 assert.deepEqual(await worker1.viewAccount(), [ 0, 0 ], "check balance");143 assert.deepEqual(await worker2.viewAccount(), [ 0, 0 ], "check balance");144 assert.deepEqual(await worker3.viewAccount(), [ 0, 0 ], "check balance");145 assert.deepEqual(await worker4.viewAccount(), [ 0, 0 ], "check balance");146 assert.deepEqual(await worker5.viewAccount(), [ 0, 0 ], "check balance");147 assert.deepEqual(await user.viewAccount(), [ 0, 0 ], "check balance");148 });149 it("deposit", async () => {150 switch (DEPLOYMENT.asset)151 {152 case "Native":153 txMined = await IexecInstance.deposit({ from: iexecAdmin.address, value: 10000000 * 10 ** 9 });154 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.from, constants.NULL.ADDRESS);155 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.to, iexecAdmin.address);156 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.value, 10000000);157 break;158 case "Token":159 txMined = await RLCInstance.approveAndCall(IexecInstance.address, 10000000, "0x", { from: iexecAdmin.address });160 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.owner, iexecAdmin.address);161 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.spender, IexecInstance.address);162 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.value, 10000000);163 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.from, iexecAdmin.address);164 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.to, IexecInstance.address);165 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.value, 10000000);166 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.from, constants.NULL.ADDRESS);167 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.to, iexecAdmin.address);168 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.value, 10000000);169 break;170 }171 txsMined = await Promise.all([172 IexecInstance.transfer(scheduler.address, 1000, { from: iexecAdmin.address }),173 IexecInstance.transfer(worker1.address, 1000, { from: iexecAdmin.address }),174 IexecInstance.transfer(worker2.address, 1000, { from: iexecAdmin.address }),175 IexecInstance.transfer(worker3.address, 1000, { from: iexecAdmin.address }),176 IexecInstance.transfer(worker4.address, 1000, { from: iexecAdmin.address }),177 IexecInstance.transfer(worker5.address, 1000, { from: iexecAdmin.address }),178 IexecInstance.transfer(user.address, 1000, { from: iexecAdmin.address }),179 ]);180 assert.equal(tools.extractEvents(txsMined[0], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);181 assert.equal(tools.extractEvents(txsMined[0], IexecInstance.address, "Transfer")[0].args.value, 1000);182 assert.equal(tools.extractEvents(txsMined[1], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);183 assert.equal(tools.extractEvents(txsMined[1], IexecInstance.address, "Transfer")[0].args.value, 1000);184 assert.equal(tools.extractEvents(txsMined[2], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);185 assert.equal(tools.extractEvents(txsMined[2], IexecInstance.address, "Transfer")[0].args.value, 1000);186 assert.equal(tools.extractEvents(txsMined[3], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);187 assert.equal(tools.extractEvents(txsMined[3], IexecInstance.address, "Transfer")[0].args.value, 1000);188 assert.equal(tools.extractEvents(txsMined[4], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);189 assert.equal(tools.extractEvents(txsMined[4], IexecInstance.address, "Transfer")[0].args.value, 1000);190 assert.equal(tools.extractEvents(txsMined[5], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);191 assert.equal(tools.extractEvents(txsMined[5], IexecInstance.address, "Transfer")[0].args.value, 1000);192 assert.equal(tools.extractEvents(txsMined[6], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);193 assert.equal(tools.extractEvents(txsMined[6], IexecInstance.address, "Transfer")[0].args.value, 1000);194 });195 it("balances after", async () => {196 assert.deepEqual(await appProvider.viewAccount(), [ 0, 0 ], "check balance");197 assert.deepEqual(await datasetProvider.viewAccount(), [ 0, 0 ], "check balance");198 assert.deepEqual(await scheduler.viewAccount(), [ 1000, 0 ], "check balance");199 assert.deepEqual(await worker1.viewAccount(), [ 1000, 0 ], "check balance");200 assert.deepEqual(await worker2.viewAccount(), [ 1000, 0 ], "check balance");201 assert.deepEqual(await worker3.viewAccount(), [ 1000, 0 ], "check balance");202 assert.deepEqual(await worker4.viewAccount(), [ 1000, 0 ], "check balance");203 assert.deepEqual(await worker5.viewAccount(), [ 1000, 0 ], "check balance");204 assert.deepEqual(await user.viewAccount(), [ 1000, 0 ], "check balance");205 });206 });207 it("score", async () => {208 assert.equal(await worker1.viewScore(), 0, "score issue");209 assert.equal(await worker2.viewScore(), 0, "score issue");210 assert.equal(await worker3.viewScore(), 0, "score issue");211 assert.equal(await worker4.viewScore(), 0, "score issue");212 assert.equal(await worker5.viewScore(), 0, "score issue");213 });214 });215 describe("→ pipeline", async () => {216 describe("[0] orders", async () => {217 describe("app", async () => {218 it("sign", async () => {219 apporder = await appProvider.signAppOrder({220 app: AppInstance.address,221 appprice: 3,222 volume: 1000,223 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",224 datasetrestrict: constants.NULL.ADDRESS,225 workerpoolrestrict: constants.NULL.ADDRESS,226 requesterrestrict: constants.NULL.ADDRESS,227 salt: web3.utils.randomHex(32),228 sign: constants.NULL.SIGNATURE,229 });230 });231 it("verify", async () => {232 assert.isTrue(await IexecInstance.verifySignature(233 appProvider.address,234 odbtools.utils.hashAppOrder(ERC712_domain, apporder),235 apporder.sign236 ));237 });238 });239 describe("dataset", async () => {240 it("sign", async () => {241 datasetorder = await datasetProvider.signDatasetOrder({242 dataset: DatasetInstance.address,243 datasetprice: 0,244 volume: 1000,245 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",246 apprestrict: constants.NULL.ADDRESS,247 workerpoolrestrict: constants.NULL.ADDRESS,248 requesterrestrict: constants.NULL.ADDRESS,249 salt: web3.utils.randomHex(32),250 sign: constants.NULL.SIGNATURE,251 });252 });253 it("verify", async () => {254 assert.isTrue(await IexecInstance.verifySignature(255 datasetProvider.address,256 odbtools.utils.hashDatasetOrder(ERC712_domain, datasetorder),257 datasetorder.sign258 ));259 });260 });261 describe("workerpool", async () => {262 it("sign", async () => {263 workerpoolorder = await scheduler.signWorkerpoolOrder({264 workerpool: WorkerpoolInstance.address,265 workerpoolprice: 25,266 volume: 1000,267 category: 4,268 trust: 0,269 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",270 apprestrict: constants.NULL.ADDRESS,271 datasetrestrict: constants.NULL.ADDRESS,272 requesterrestrict: constants.NULL.ADDRESS,273 salt: web3.utils.randomHex(32),274 sign: constants.NULL.SIGNATURE,275 });276 });277 it("verify", async () => {278 assert.isTrue(await IexecInstance.verifySignature(279 scheduler.address,280 odbtools.utils.hashWorkerpoolOrder(ERC712_domain, workerpoolorder),281 workerpoolorder.sign282 ));283 });284 });285 describe("request", async () => {286 describe("no callback", async () => {287 it("sign", async () => {288 requestorder1 = await user.signRequestOrder({289 app: AppInstance.address,290 appmaxprice: 3,291 dataset: DatasetInstance.address,292 datasetmaxprice: 0,293 workerpool: constants.NULL.ADDRESS,294 workerpoolmaxprice: 25,295 volume: 1,296 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",297 category: 4,298 trust: 0,299 requester: user.address,300 beneficiary: user.address,301 callback: constants.NULL.ADDRESS,302 params: "<parameters>",303 salt: web3.utils.randomHex(32),304 sign: constants.NULL.SIGNATURE,305 });306 });307 it("verify", async () => {308 assert.isTrue(await IexecInstance.verifySignature(309 user.address,310 odbtools.utils.hashRequestOrder(ERC712_domain, requestorder1),311 requestorder1.sign312 ));313 });314 });315 describe("invalid callback", async () => {316 it("sign", async () => {317 requestorder2 = await user.signRequestOrder({318 app: AppInstance.address,319 appmaxprice: 3,320 dataset: DatasetInstance.address,321 datasetmaxprice: 0,322 workerpool: constants.NULL.ADDRESS,323 workerpoolmaxprice: 25,324 volume: 1,325 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",326 category: 4,327 trust: 0,328 requester: user.address,329 beneficiary: user.address,330 callback: AppInstance.address,331 params: "<parameters>",332 salt: web3.utils.randomHex(32),333 sign: constants.NULL.SIGNATURE,334 });335 });336 it("verify", async () => {337 assert.isTrue(await IexecInstance.verifySignature(338 user.address,339 odbtools.utils.hashRequestOrder(ERC712_domain, requestorder2),340 requestorder2.sign341 ));342 });343 });344 describe("valid callback", async () => {345 it("sign", async () => {346 requestorder3 = await user.signRequestOrder({347 app: AppInstance.address,348 appmaxprice: 3,349 dataset: DatasetInstance.address,350 datasetmaxprice: 0,351 workerpool: constants.NULL.ADDRESS,352 workerpoolmaxprice: 25,353 volume: 1,354 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",355 category: 4,356 trust: 0,357 requester: user.address,358 beneficiary: user.address,359 callback: TestClientInstance.address,360 params: "<parameters>",361 salt: web3.utils.randomHex(32),362 sign: constants.NULL.SIGNATURE,363 });364 });365 it("verify", async () => {366 assert.isTrue(await IexecInstance.verifySignature(367 user.address,368 odbtools.utils.hashRequestOrder(ERC712_domain, requestorder3),369 requestorder3.sign370 ));371 });372 });373 describe("callback EOA", async () => {374 it("sign", async () => {375 requestorder4 = await user.signRequestOrder({376 app: AppInstance.address,377 appmaxprice: 3,378 dataset: DatasetInstance.address,379 datasetmaxprice: 0,380 workerpool: constants.NULL.ADDRESS,381 workerpoolmaxprice: 25,382 volume: 1,383 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",384 category: 4,385 trust: 0,386 requester: user.address,387 beneficiary: user.address,388 callback: "0x0000000000000000000000000000000000000001",389 params: "<parameters>",390 salt: web3.utils.randomHex(32),391 sign: constants.NULL.SIGNATURE,392 });393 });394 it("verify", async () => {395 assert.isTrue(await IexecInstance.verifySignature(396 user.address,397 odbtools.utils.hashRequestOrder(ERC712_domain, requestorder4),398 requestorder4.sign399 ));400 });401 });402 });403 });404 describe("[1] order matching", async () => {405 it("[TX] match", async () => {406 txsMined = await Promise.all([407 IexecInstance.matchOrders(apporder, datasetorder, workerpoolorder, requestorder1, { from: user.address }),408 IexecInstance.matchOrders(apporder, datasetorder, workerpoolorder, requestorder2, { from: user.address }),409 IexecInstance.matchOrders(apporder, datasetorder, workerpoolorder, requestorder3, { from: user.address }),410 IexecInstance.matchOrders(apporder, datasetorder, workerpoolorder, requestorder4, { from: user.address }),411 ]);412 deals[1] = tools.extractEvents(txsMined[0], IexecInstance.address, "OrdersMatched")[0].args.dealid;413 deals[2] = tools.extractEvents(txsMined[1], IexecInstance.address, "OrdersMatched")[0].args.dealid;414 deals[3] = tools.extractEvents(txsMined[2], IexecInstance.address, "OrdersMatched")[0].args.dealid;415 deals[4] = tools.extractEvents(txsMined[3], IexecInstance.address, "OrdersMatched")[0].args.dealid;416 });417 });418 describe("[2] initialization", async () => {419 it("[TX] initialize", async () => {420 txsMined = await Promise.all([421 IexecInstance.initialize(deals[1], 0, { from: scheduler.address }),422 IexecInstance.initialize(deals[2], 0, { from: scheduler.address }),423 IexecInstance.initialize(deals[3], 0, { from: scheduler.address }),424 IexecInstance.initialize(deals[4], 0, { from: scheduler.address }),425 ]);426 tasks[1] = tools.extractEvents(txsMined[0], IexecInstance.address, "TaskInitialize")[0].args.taskid;427 tasks[2] = tools.extractEvents(txsMined[1], IexecInstance.address, "TaskInitialize")[0].args.taskid;428 tasks[3] = tools.extractEvents(txsMined[2], IexecInstance.address, "TaskInitialize")[0].args.taskid;429 tasks[4] = tools.extractEvents(txsMined[3], IexecInstance.address, "TaskInitialize")[0].args.taskid;430 });431 });432 async function sendContribution(worker, taskid, result, useenclave = true, callback)433 {434 const preauth = await scheduler.signPreAuthorization(taskid, worker.address);435 const [ auth, secret ] = useenclave ? await broker.signAuthorization(preauth) : [ preauth, null ];436 const results = await worker.run(auth, secret, result, callback);437 return IexecInstance.contribute(438 auth.taskid, // task (authorization)439 results.hash, // common (result)440 results.seal, // unique (result)441 auth.enclave, // address (enclave)442 results.sign, // signature (enclave)443 auth.sign, // signature (authorization)444 { from: worker.address }445 );446 }447 describe("[3] contribute", async () => {448 it("[TX] contribute", async () => {449 await sendContribution(worker1, tasks[1], "aResult 1", false, web3.utils.utf8ToHex("callback-1"));450 await sendContribution(worker1, tasks[2], "aResult 2", false, web3.utils.utf8ToHex("callback-2"));451 await sendContribution(worker1, tasks[3], "aResult 3", false, web3.utils.utf8ToHex("callback-3"));452 await sendContribution(worker1, tasks[4], "aResult 4", false, web3.utils.utf8ToHex("callback-4"));453 });454 });455 describe("[4] reveal", async () => {456 it("[TX] reveal", async () => {457 await IexecInstance.reveal(tasks[1], odbtools.utils.hashByteResult(tasks[1], web3.utils.soliditySha3({t: 'bytes', v: web3.utils.utf8ToHex("callback-1") })).digest, { from: worker1.address });458 await IexecInstance.reveal(tasks[2], odbtools.utils.hashByteResult(tasks[2], web3.utils.soliditySha3({t: 'bytes', v: web3.utils.utf8ToHex("callback-2") })).digest, { from: worker1.address });459 await IexecInstance.reveal(tasks[3], odbtools.utils.hashByteResult(tasks[3], web3.utils.soliditySha3({t: 'bytes', v: web3.utils.utf8ToHex("callback-3") })).digest, { from: worker1.address });460 await IexecInstance.reveal(tasks[4], odbtools.utils.hashByteResult(tasks[4], web3.utils.soliditySha3({t: 'bytes', v: web3.utils.utf8ToHex("callback-4") })).digest, { from: worker1.address });461 });462 });463 describe("[5] finalization", async () => {464 describe("bad callback", async () => {465 it("[TX] no call", async () => {466 await expectRevert.unspecified(IexecInstance.finalize(467 tasks[1],468 web3.utils.utf8ToHex("aResult 1"),469 web3.utils.utf8ToHex("wrong-callback"),470 { from: scheduler.address }471 ));472 });473 });474 describe("no callback", async () => {475 it("[TX] no call", async () => {476 txMined = await IexecInstance.finalize(477 tasks[1],478 web3.utils.utf8ToHex("aResult 1"),479 web3.utils.utf8ToHex("callback-1"),480 { from: scheduler.address }481 );482 events = tools.extractEvents(txMined, IexecInstance.address, "TaskFinalize");483 assert.equal(events[0].args.taskid, tasks[1], "check taskid");484 assert.equal(events[0].args.results, web3.utils.utf8ToHex("aResult 1"), "check consensus (results)");485 });486 });487 describe("invalid callback", async () => {488 it("[TX] doesn't revert", async () => {489 txMined = await IexecInstance.finalize(490 tasks[2],491 web3.utils.utf8ToHex("aResult 2"),492 web3.utils.utf8ToHex("callback-2"),493 { from: scheduler.address }494 );495 events = tools.extractEvents(txMined, IexecInstance.address, "TaskFinalize");496 assert.equal(events[0].args.taskid, tasks[2], "check taskid");497 assert.equal(events[0].args.results, web3.utils.utf8ToHex("aResult 2"), "check consensus (results)");498 });499 });500 describe("valid callback", async () => {501 it("[TX] call", async () => {502 assert.equal(await TestClientInstance.store(tasks[3]), null, "Error in test client: store empty");503 txMined = await IexecInstance.finalize(504 tasks[3],505 web3.utils.utf8ToHex("aResult 3"),506 web3.utils.utf8ToHex("callback-3"),507 { from: scheduler.address }508 );509 events = tools.extractEvents(txMined, IexecInstance.address, "TaskFinalize");510 assert.equal(events[0].args.taskid, tasks[3], "check taskid");511 assert.equal(events[0].args.results, web3.utils.utf8ToHex("aResult 3"), "check consensus (results)");512 });513 it("check", async () => {514 assert.equal(await TestClientInstance.store(tasks[3]), web3.utils.utf8ToHex("callback-3"), "Error in test client: dataset not stored");515 // fails under coverage because of additional cost for instrumentation516 // assert.equal(await TestClientInstance.gstore(tasks[3]), await IexecInstance.callbackgas()-343);517 });518 });519 describe("callback EOA", async () => {520 it("[TX] doesn't revert", async () => {521 txMined = await IexecInstance.finalize(522 tasks[4],523 web3.utils.utf8ToHex("aResult 4"),524 web3.utils.utf8ToHex("callback-4"),525 { from: scheduler.address }526 );527 events = tools.extractEvents(txMined, IexecInstance.address, "TaskFinalize");528 assert.equal(events[0].args.taskid, tasks[4], "check taskid");529 assert.equal(events[0].args.results, web3.utils.utf8ToHex("aResult 4"), "check consensus (results)");530 });531 });532 });533 });...

Full Screen

Full Screen

100_fullchain-5workers-1error.js

Source:100_fullchain-5workers-1error.js Github

copy

Full Screen

...111 constants.NULL.BYTES32,112 "0x",113 { from: appProvider.address }114 );115 events = tools.extractEvents(txMined, AppRegistryInstance.address, "Transfer");116 AppInstance = await App.at(tools.BN2Address(events[0].args.tokenId));117 });118 });119 describe("dataset", async () => {120 it("create", async () => {121 txMined = await DatasetRegistryInstance.createDataset(122 datasetProvider.address,123 "Pi",124 constants.MULTIADDR_BYTES,125 constants.NULL.BYTES32,126 { from: datasetProvider.address }127 );128 events = tools.extractEvents(txMined, DatasetRegistryInstance.address, "Transfer");129 DatasetInstance = await Dataset.at(tools.BN2Address(events[0].args.tokenId));130 });131 });132 describe("workerpool", async () => {133 it("create", async () => {134 txMined = await WorkerpoolRegistryInstance.createWorkerpool(135 scheduler.address,136 "A test workerpool",137 { from: scheduler.address }138 );139 events = tools.extractEvents(txMined, WorkerpoolRegistryInstance.address, "Transfer");140 WorkerpoolInstance = await Workerpool.at(tools.BN2Address(events[0].args.tokenId));141 });142 it("change policy", async () => {143 txMined = await WorkerpoolInstance.changePolicy(/* worker stake ratio */ 35, /* scheduler reward ratio */ 5, { from: scheduler.address });144 events = tools.extractEvents(txMined, WorkerpoolInstance.address, "PolicyUpdate");145 assert.equal(events[0].args.oldWorkerStakeRatioPolicy, 30);146 assert.equal(events[0].args.newWorkerStakeRatioPolicy, 35);147 assert.equal(events[0].args.oldSchedulerRewardRatioPolicy, 1);148 assert.equal(events[0].args.newSchedulerRewardRatioPolicy, 5);149 });150 });151 });152 describe("tokens", async () => {153 it("balances before", async () => {154 assert.deepEqual(await appProvider.viewAccount(), [ 0, 0 ], "check balance");155 assert.deepEqual(await datasetProvider.viewAccount(), [ 0, 0 ], "check balance");156 assert.deepEqual(await scheduler.viewAccount(), [ 0, 0 ], "check balance");157 assert.deepEqual(await worker1.viewAccount(), [ 0, 0 ], "check balance");158 assert.deepEqual(await worker2.viewAccount(), [ 0, 0 ], "check balance");159 assert.deepEqual(await worker3.viewAccount(), [ 0, 0 ], "check balance");160 assert.deepEqual(await worker4.viewAccount(), [ 0, 0 ], "check balance");161 assert.deepEqual(await worker5.viewAccount(), [ 0, 0 ], "check balance");162 assert.deepEqual(await user.viewAccount(), [ 0, 0 ], "check balance");163 });164 it("deposit", async () => {165 switch (DEPLOYMENT.asset)166 {167 case "Native":168 txMined = await IexecInstance.deposit({ from: iexecAdmin.address, value: 10000000 * 10 ** 9 });169 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.from, constants.NULL.ADDRESS);170 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.to, iexecAdmin.address);171 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.value, 10000000);172 break;173 case "Token":174 txMined = await RLCInstance.approveAndCall(IexecInstance.address, 10000000, "0x", { from: iexecAdmin.address });175 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.owner, iexecAdmin.address);176 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.spender, IexecInstance.address);177 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.value, 10000000);178 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.from, iexecAdmin.address);179 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.to, IexecInstance.address);180 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.value, 10000000);181 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.from, constants.NULL.ADDRESS);182 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.to, iexecAdmin.address);183 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.value, 10000000);184 break;185 }186 txsMined = await Promise.all([187 IexecInstance.transfer(scheduler.address, 1000, { from: iexecAdmin.address }),188 IexecInstance.transfer(worker1.address, 1000, { from: iexecAdmin.address }),189 IexecInstance.transfer(worker2.address, 1000, { from: iexecAdmin.address }),190 IexecInstance.transfer(worker3.address, 1000, { from: iexecAdmin.address }),191 IexecInstance.transfer(worker4.address, 1000, { from: iexecAdmin.address }),192 IexecInstance.transfer(worker5.address, 1000, { from: iexecAdmin.address }),193 IexecInstance.transfer(user.address, 1000, { from: iexecAdmin.address }),194 ]);195 assert.equal(tools.extractEvents(txsMined[0], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);196 assert.equal(tools.extractEvents(txsMined[0], IexecInstance.address, "Transfer")[0].args.value, 1000);197 assert.equal(tools.extractEvents(txsMined[1], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);198 assert.equal(tools.extractEvents(txsMined[1], IexecInstance.address, "Transfer")[0].args.value, 1000);199 assert.equal(tools.extractEvents(txsMined[2], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);200 assert.equal(tools.extractEvents(txsMined[2], IexecInstance.address, "Transfer")[0].args.value, 1000);201 assert.equal(tools.extractEvents(txsMined[3], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);202 assert.equal(tools.extractEvents(txsMined[3], IexecInstance.address, "Transfer")[0].args.value, 1000);203 assert.equal(tools.extractEvents(txsMined[4], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);204 assert.equal(tools.extractEvents(txsMined[4], IexecInstance.address, "Transfer")[0].args.value, 1000);205 assert.equal(tools.extractEvents(txsMined[5], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);206 assert.equal(tools.extractEvents(txsMined[5], IexecInstance.address, "Transfer")[0].args.value, 1000);207 assert.equal(tools.extractEvents(txsMined[6], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);208 assert.equal(tools.extractEvents(txsMined[6], IexecInstance.address, "Transfer")[0].args.value, 1000);209 });210 it("balances after", async () => {211 assert.deepEqual(await appProvider.viewAccount(), [ 0, 0 ], "check balance");212 assert.deepEqual(await datasetProvider.viewAccount(), [ 0, 0 ], "check balance");213 assert.deepEqual(await scheduler.viewAccount(), [ 1000, 0 ], "check balance");214 assert.deepEqual(await worker1.viewAccount(), [ 1000, 0 ], "check balance");215 assert.deepEqual(await worker2.viewAccount(), [ 1000, 0 ], "check balance");216 assert.deepEqual(await worker3.viewAccount(), [ 1000, 0 ], "check balance");217 assert.deepEqual(await worker4.viewAccount(), [ 1000, 0 ], "check balance");218 assert.deepEqual(await worker5.viewAccount(), [ 1000, 0 ], "check balance");219 assert.deepEqual(await user.viewAccount(), [ 1000, 0 ], "check balance");220 });221 });222 it("score", async () => {223 assert.equal(await worker1.viewScore(), 0, "score issue");224 assert.equal(await worker2.viewScore(), 0, "score issue");225 assert.equal(await worker3.viewScore(), 0, "score issue");226 assert.equal(await worker4.viewScore(), 0, "score issue");227 assert.equal(await worker5.viewScore(), 0, "score issue");228 });229 });230 describe("→ pipeline", async () => {231 describe("[0] orders", async () => {232 describe("app", async () => {233 it("sign", async () => {234 apporder = await appProvider.signAppOrder({235 app: AppInstance.address,236 appprice: 3,237 volume: 1000,238 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",239 datasetrestrict: constants.NULL.ADDRESS,240 workerpoolrestrict: constants.NULL.ADDRESS,241 requesterrestrict: constants.NULL.ADDRESS,242 salt: web3.utils.randomHex(32),243 sign: constants.NULL.SIGNATURE,244 });245 });246 it("verify", async () => {247 assert.isTrue(await IexecInstance.verifySignature(248 appProvider.address,249 odbtools.utils.hashAppOrder(ERC712_domain, apporder),250 apporder.sign251 ));252 });253 });254 describe("dataset", async () => {255 it("sign", async () => {256 datasetorder = await datasetProvider.signDatasetOrder({257 dataset: DatasetInstance.address,258 datasetprice: 1,259 volume: 1000,260 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",261 apprestrict: constants.NULL.ADDRESS,262 workerpoolrestrict: constants.NULL.ADDRESS,263 requesterrestrict: constants.NULL.ADDRESS,264 salt: web3.utils.randomHex(32),265 sign: constants.NULL.SIGNATURE,266 });267 });268 it("verify", async () => {269 assert.isTrue(await IexecInstance.verifySignature(270 datasetProvider.address,271 odbtools.utils.hashDatasetOrder(ERC712_domain, datasetorder),272 datasetorder.sign273 ));274 });275 });276 describe("workerpool", async () => {277 it("sign", async () => {278 workerpoolorder = await scheduler.signWorkerpoolOrder({279 workerpool: WorkerpoolInstance.address,280 workerpoolprice: 25,281 volume: 3,282 category: 4,283 trust: trusttarget,284 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",285 apprestrict: constants.NULL.ADDRESS,286 datasetrestrict: constants.NULL.ADDRESS,287 requesterrestrict: constants.NULL.ADDRESS,288 salt: web3.utils.randomHex(32),289 sign: constants.NULL.SIGNATURE,290 });291 });292 it("verify", async () => {293 assert.isTrue(await IexecInstance.verifySignature(294 scheduler.address,295 odbtools.utils.hashWorkerpoolOrder(ERC712_domain, workerpoolorder),296 workerpoolorder.sign297 ));298 });299 });300 describe("request", async () => {301 it("sign", async () => {302 requestorder = await user.signRequestOrder({303 app: AppInstance.address,304 appmaxprice: 3,305 dataset: DatasetInstance.address,306 datasetmaxprice: 1,307 workerpool: constants.NULL.ADDRESS,308 workerpoolmaxprice: 25,309 volume: 1, // CHANGE FOR BOT310 category: 4,311 trust: trusttarget,312 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",313 requester: user.address,314 beneficiary: user.address,315 callback: constants.NULL.ADDRESS,316 params: "<parameters>",317 salt: web3.utils.randomHex(32),318 sign: constants.NULL.SIGNATURE,319 });320 });321 it("verify", async () => {322 assert.isTrue(await IexecInstance.verifySignature(323 user.address,324 odbtools.utils.hashRequestOrder(ERC712_domain, requestorder),325 requestorder.sign326 ));327 });328 });329 });330 describe("[1] order matching", async () => {331 it("[TX] match", async () => {332 txMined = await IexecInstance.matchOrders(apporder, datasetorder, workerpoolorder, requestorder, { from: user.address });333 gasReceipt.push([ "matchOrders", txMined.receipt.gasUsed ]);334 dealid = web3.utils.soliditySha3(335 { t: 'bytes32', v: odbtools.utils.hashRequestOrder(ERC712_domain, requestorder) },336 { t: 'uint256', v: 0 },337 );338 events = tools.extractEvents(txMined, IexecInstance.address, "SchedulerNotice");339 assert.equal(events[0].args.workerpool, WorkerpoolInstance.address);340 assert.equal(events[0].args.dealid, dealid );341 events = tools.extractEvents(txMined, IexecInstance.address, "OrdersMatched");342 assert.equal(events[0].args.dealid, dealid );343 assert.equal(events[0].args.appHash, odbtools.utils.hashAppOrder (ERC712_domain, apporder ));344 assert.equal(events[0].args.datasetHash, odbtools.utils.hashDatasetOrder (ERC712_domain, datasetorder ));345 assert.equal(events[0].args.workerpoolHash, odbtools.utils.hashWorkerpoolOrder(ERC712_domain, workerpoolorder));346 assert.equal(events[0].args.requestHash, odbtools.utils.hashRequestOrder (ERC712_domain, requestorder ));347 assert.equal(events[0].args.volume, 1 );348 });349 });350 describe("[2] initialization", async () => {351 it("[TX] initialize", async () => {352 txMined = await IexecInstance.initialize(dealid, 0, { from: scheduler.address });353 gasReceipt.push([ "initialize", txMined.receipt.gasUsed ]);354 taskid = web3.utils.soliditySha3({ t: 'bytes32', v: dealid }, { t: 'uint256', v: 0 });355 events = tools.extractEvents(txMined, IexecInstance.address, "TaskInitialize");356 assert.equal(events[0].args.taskid, taskid );357 assert.equal(events[0].args.workerpool, WorkerpoolInstance.address);358 });359 });360 describe("[3] contribute", async () => {361 it("authorization signature", async () => {362 for (w of workers)363 {364 const preauth = await scheduler.signPreAuthorization(taskid, w.agent.address);365 const [ auth, secret ] = w.useenclave ? await broker.signAuthorization(preauth) : [ preauth, null ];366 authorizations[w.agent.address] = auth;367 secrets[w.agent.address] = secret;368 }369 });370 it("run", async () => {371 consensus = odbtools.utils.hashConsensus(taskid, consensus);372 for (w of workers)373 {374 results[w.agent.address] = await w.agent.run(authorizations[w.agent.address], secrets[w.agent.address], w.result);375 }376 });377 it("[TX] contribute", async () => {378 for (w of workers)379 {380 txMined = await IexecInstance.contribute(381 authorizations[w.agent.address].taskid, // task (authorization)382 results [w.agent.address].hash, // common (result)383 results [w.agent.address].seal, // unique (result)384 authorizations[w.agent.address].enclave, // address (enclave)385 results [w.agent.address].sign, // signature (enclave)386 authorizations[w.agent.address].sign, // signature (authorization)387 { from: w.agent.address }388 );389 gasReceipt.push([ "contribute", txMined.receipt.gasUsed ]);390 events = tools.extractEvents(txMined, IexecInstance.address, "TaskContribute");391 assert.equal(events[0].args.taskid, authorizations[w.agent.address].taskid);392 assert.equal(events[0].args.worker, w.agent.address );393 assert.equal(events[0].args.hash, results[w.agent.address].hash );394 }395 });396 });397 describe("[4] reveal", async () => {398 it("[TX] reveal", async () => {399 for (w of workers)400 if (results[w.agent.address].hash == consensus.hash)401 {402 txMined = await IexecInstance.reveal(403 taskid,404 results[w.agent.address].digest,405 { from: w.agent.address }406 );407 gasReceipt.push([ "reveal", txMined.receipt.gasUsed ]);408 events = tools.extractEvents(txMined, IexecInstance.address, "TaskReveal");409 assert.equal(events[0].args.taskid, taskid );410 assert.equal(events[0].args.worker, w.agent.address );411 assert.equal(events[0].args.digest, results[w.agent.address].digest);412 }413 });414 });415 describe("[5] finalization", async () => {416 it("[TX] finalize", async () => {417 txMined = await IexecInstance.finalize(418 taskid,419 web3.utils.utf8ToHex("aResult"),420 "0x",421 { from: scheduler.address }422 );423 gasReceipt.push([ "finalize", txMined.receipt.gasUsed ]);424 events = tools.extractEvents(txMined, IexecInstance.address, "TaskFinalize");425 assert.equal(events[0].args.taskid, taskid );426 assert.equal(events[0].args.results, web3.utils.utf8ToHex("aResult"));427 // TODO: check 2 events by w.agent.address for w in workers428 // How to retreive events from the IexecClerk (5 rewards and 1 seize)429 });430 });431 });432 describe("→ summary", async () => {433 it("task", async () => {434 task = await IexecInstance.viewTask(taskid);435 assert.equal ( task.status, constants.TaskStatusEnum.COMPLETED );436 assert.equal ( task.dealid, dealid );437 assert.equal (Number(task.idx), 0 );438 assert.equal (Number(task.timeref), (await IexecInstance.viewCategory(requestorder.category)).workClockTimeRef);...

Full Screen

Full Screen

004_fullchain-4workers.js

Source:004_fullchain-4workers.js Github

copy

Full Screen

...110 constants.NULL.BYTES32,111 "0x",112 { from: appProvider.address }113 );114 events = tools.extractEvents(txMined, AppRegistryInstance.address, "Transfer");115 AppInstance = await App.at(tools.BN2Address(events[0].args.tokenId));116 });117 });118 describe("dataset", async () => {119 it("create", async () => {120 txMined = await DatasetRegistryInstance.createDataset(121 datasetProvider.address,122 "Pi",123 constants.MULTIADDR_BYTES,124 constants.NULL.BYTES32,125 { from: datasetProvider.address }126 );127 events = tools.extractEvents(txMined, DatasetRegistryInstance.address, "Transfer");128 DatasetInstance = await Dataset.at(tools.BN2Address(events[0].args.tokenId));129 });130 });131 describe("workerpool", async () => {132 it("create", async () => {133 txMined = await WorkerpoolRegistryInstance.createWorkerpool(134 scheduler.address,135 "A test workerpool",136 { from: scheduler.address }137 );138 events = tools.extractEvents(txMined, WorkerpoolRegistryInstance.address, "Transfer");139 WorkerpoolInstance = await Workerpool.at(tools.BN2Address(events[0].args.tokenId));140 });141 it("change policy", async () => {142 txMined = await WorkerpoolInstance.changePolicy(/* worker stake ratio */ 35, /* scheduler reward ratio */ 5, { from: scheduler.address });143 events = tools.extractEvents(txMined, WorkerpoolInstance.address, "PolicyUpdate");144 assert.equal(events[0].args.oldWorkerStakeRatioPolicy, 30);145 assert.equal(events[0].args.newWorkerStakeRatioPolicy, 35);146 assert.equal(events[0].args.oldSchedulerRewardRatioPolicy, 1);147 assert.equal(events[0].args.newSchedulerRewardRatioPolicy, 5);148 });149 });150 });151 describe("tokens", async () => {152 it("balances before", async () => {153 assert.deepEqual(await appProvider.viewAccount(), [ 0, 0 ], "check balance");154 assert.deepEqual(await datasetProvider.viewAccount(), [ 0, 0 ], "check balance");155 assert.deepEqual(await scheduler.viewAccount(), [ 0, 0 ], "check balance");156 assert.deepEqual(await worker1.viewAccount(), [ 0, 0 ], "check balance");157 assert.deepEqual(await worker2.viewAccount(), [ 0, 0 ], "check balance");158 assert.deepEqual(await worker3.viewAccount(), [ 0, 0 ], "check balance");159 assert.deepEqual(await worker4.viewAccount(), [ 0, 0 ], "check balance");160 assert.deepEqual(await worker5.viewAccount(), [ 0, 0 ], "check balance");161 assert.deepEqual(await user.viewAccount(), [ 0, 0 ], "check balance");162 });163 it("deposit", async () => {164 switch (DEPLOYMENT.asset)165 {166 case "Native":167 txMined = await IexecInstance.deposit({ from: iexecAdmin.address, value: 10000000 * 10 ** 9 });168 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.from, constants.NULL.ADDRESS);169 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.to, iexecAdmin.address);170 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.value, 10000000);171 break;172 case "Token":173 txMined = await RLCInstance.approveAndCall(IexecInstance.address, 10000000, "0x", { from: iexecAdmin.address });174 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.owner, iexecAdmin.address);175 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.spender, IexecInstance.address);176 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.value, 10000000);177 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.from, iexecAdmin.address);178 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.to, IexecInstance.address);179 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.value, 10000000);180 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.from, constants.NULL.ADDRESS);181 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.to, iexecAdmin.address);182 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.value, 10000000);183 break;184 }185 txsMined = await Promise.all([186 IexecInstance.transfer(scheduler.address, 1000, { from: iexecAdmin.address }),187 IexecInstance.transfer(worker1.address, 1000, { from: iexecAdmin.address }),188 IexecInstance.transfer(worker2.address, 1000, { from: iexecAdmin.address }),189 IexecInstance.transfer(worker3.address, 1000, { from: iexecAdmin.address }),190 IexecInstance.transfer(worker4.address, 1000, { from: iexecAdmin.address }),191 IexecInstance.transfer(worker5.address, 1000, { from: iexecAdmin.address }),192 IexecInstance.transfer(user.address, 1000, { from: iexecAdmin.address }),193 ]);194 assert.equal(tools.extractEvents(txsMined[0], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);195 assert.equal(tools.extractEvents(txsMined[0], IexecInstance.address, "Transfer")[0].args.value, 1000);196 assert.equal(tools.extractEvents(txsMined[1], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);197 assert.equal(tools.extractEvents(txsMined[1], IexecInstance.address, "Transfer")[0].args.value, 1000);198 assert.equal(tools.extractEvents(txsMined[2], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);199 assert.equal(tools.extractEvents(txsMined[2], IexecInstance.address, "Transfer")[0].args.value, 1000);200 assert.equal(tools.extractEvents(txsMined[3], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);201 assert.equal(tools.extractEvents(txsMined[3], IexecInstance.address, "Transfer")[0].args.value, 1000);202 assert.equal(tools.extractEvents(txsMined[4], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);203 assert.equal(tools.extractEvents(txsMined[4], IexecInstance.address, "Transfer")[0].args.value, 1000);204 assert.equal(tools.extractEvents(txsMined[5], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);205 assert.equal(tools.extractEvents(txsMined[5], IexecInstance.address, "Transfer")[0].args.value, 1000);206 assert.equal(tools.extractEvents(txsMined[6], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);207 assert.equal(tools.extractEvents(txsMined[6], IexecInstance.address, "Transfer")[0].args.value, 1000);208 });209 it("balances after", async () => {210 assert.deepEqual(await appProvider.viewAccount(), [ 0, 0 ], "check balance");211 assert.deepEqual(await datasetProvider.viewAccount(), [ 0, 0 ], "check balance");212 assert.deepEqual(await scheduler.viewAccount(), [ 1000, 0 ], "check balance");213 assert.deepEqual(await worker1.viewAccount(), [ 1000, 0 ], "check balance");214 assert.deepEqual(await worker2.viewAccount(), [ 1000, 0 ], "check balance");215 assert.deepEqual(await worker3.viewAccount(), [ 1000, 0 ], "check balance");216 assert.deepEqual(await worker4.viewAccount(), [ 1000, 0 ], "check balance");217 assert.deepEqual(await worker5.viewAccount(), [ 1000, 0 ], "check balance");218 assert.deepEqual(await user.viewAccount(), [ 1000, 0 ], "check balance");219 });220 });221 it("score", async () => {222 assert.equal(await worker1.viewScore(), 0, "score issue");223 assert.equal(await worker2.viewScore(), 0, "score issue");224 assert.equal(await worker3.viewScore(), 0, "score issue");225 assert.equal(await worker4.viewScore(), 0, "score issue");226 assert.equal(await worker5.viewScore(), 0, "score issue");227 });228 });229 describe("→ pipeline", async () => {230 describe("[0] orders", async () => {231 describe("app", async () => {232 it("sign", async () => {233 apporder = await appProvider.signAppOrder({234 app: AppInstance.address,235 appprice: 3,236 volume: 1000,237 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",238 datasetrestrict: constants.NULL.ADDRESS,239 workerpoolrestrict: constants.NULL.ADDRESS,240 requesterrestrict: constants.NULL.ADDRESS,241 salt: web3.utils.randomHex(32),242 sign: constants.NULL.SIGNATURE,243 });244 });245 it("verify", async () => {246 assert.isTrue(await IexecInstance.verifySignature(247 appProvider.address,248 odbtools.utils.hashAppOrder(ERC712_domain, apporder),249 apporder.sign250 ));251 });252 });253 describe("dataset", async () => {254 it("sign", async () => {255 datasetorder = await datasetProvider.signDatasetOrder({256 dataset: DatasetInstance.address,257 datasetprice: 1,258 volume: 1000,259 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",260 apprestrict: constants.NULL.ADDRESS,261 workerpoolrestrict: constants.NULL.ADDRESS,262 requesterrestrict: constants.NULL.ADDRESS,263 salt: web3.utils.randomHex(32),264 sign: constants.NULL.SIGNATURE,265 });266 });267 it("verify", async () => {268 assert.isTrue(await IexecInstance.verifySignature(269 datasetProvider.address,270 odbtools.utils.hashDatasetOrder(ERC712_domain, datasetorder),271 datasetorder.sign272 ));273 });274 });275 describe("workerpool", async () => {276 it("sign", async () => {277 workerpoolorder = await scheduler.signWorkerpoolOrder({278 workerpool: WorkerpoolInstance.address,279 workerpoolprice: 25,280 volume: 3,281 category: 4,282 trust: trusttarget,283 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",284 apprestrict: constants.NULL.ADDRESS,285 datasetrestrict: constants.NULL.ADDRESS,286 requesterrestrict: constants.NULL.ADDRESS,287 salt: web3.utils.randomHex(32),288 sign: constants.NULL.SIGNATURE,289 });290 });291 it("verify", async () => {292 assert.isTrue(await IexecInstance.verifySignature(293 scheduler.address,294 odbtools.utils.hashWorkerpoolOrder(ERC712_domain, workerpoolorder),295 workerpoolorder.sign296 ));297 });298 });299 describe("request", async () => {300 it("sign", async () => {301 requestorder = await user.signRequestOrder({302 app: AppInstance.address,303 appmaxprice: 3,304 dataset: DatasetInstance.address,305 datasetmaxprice: 1,306 workerpool: constants.NULL.ADDRESS,307 workerpoolmaxprice: 25,308 volume: 1, // CHANGE FOR BOT309 category: 4,310 trust: trusttarget,311 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",312 requester: user.address,313 beneficiary: user.address,314 callback: constants.NULL.ADDRESS,315 params: "<parameters>",316 salt: web3.utils.randomHex(32),317 sign: constants.NULL.SIGNATURE,318 });319 });320 it("verify", async () => {321 assert.isTrue(await IexecInstance.verifySignature(322 user.address,323 odbtools.utils.hashRequestOrder(ERC712_domain, requestorder),324 requestorder.sign325 ));326 });327 });328 });329 describe("[1] order matching", async () => {330 it("[TX] match", async () => {331 txMined = await IexecInstance.matchOrders(apporder, datasetorder, workerpoolorder, requestorder, { from: user.address });332 gasReceipt.push([ "matchOrders", txMined.receipt.gasUsed ]);333 dealid = web3.utils.soliditySha3(334 { t: 'bytes32', v: odbtools.utils.hashRequestOrder(ERC712_domain, requestorder) },335 { t: 'uint256', v: 0 },336 );337 events = tools.extractEvents(txMined, IexecInstance.address, "SchedulerNotice");338 assert.equal(events[0].args.workerpool, WorkerpoolInstance.address);339 assert.equal(events[0].args.dealid, dealid );340 events = tools.extractEvents(txMined, IexecInstance.address, "OrdersMatched");341 assert.equal(events[0].args.dealid, dealid );342 assert.equal(events[0].args.appHash, odbtools.utils.hashAppOrder (ERC712_domain, apporder ));343 assert.equal(events[0].args.datasetHash, odbtools.utils.hashDatasetOrder (ERC712_domain, datasetorder ));344 assert.equal(events[0].args.workerpoolHash, odbtools.utils.hashWorkerpoolOrder(ERC712_domain, workerpoolorder));345 assert.equal(events[0].args.requestHash, odbtools.utils.hashRequestOrder (ERC712_domain, requestorder ));346 assert.equal(events[0].args.volume, 1 );347 });348 });349 describe("[2] initialization", async () => {350 it("[TX] initialize", async () => {351 txMined = await IexecInstance.initialize(dealid, 0, { from: scheduler.address });352 gasReceipt.push([ "initialize", txMined.receipt.gasUsed ]);353 taskid = web3.utils.soliditySha3({ t: 'bytes32', v: dealid }, { t: 'uint256', v: 0 });354 events = tools.extractEvents(txMined, IexecInstance.address, "TaskInitialize");355 assert.equal(events[0].args.taskid, taskid );356 assert.equal(events[0].args.workerpool, WorkerpoolInstance.address);357 });358 });359 describe("[3] contribute", async () => {360 it("authorization signature", async () => {361 for (w of workers)362 {363 const preauth = await scheduler.signPreAuthorization(taskid, w.agent.address);364 const [ auth, secret ] = w.useenclave ? await broker.signAuthorization(preauth) : [ preauth, null ];365 authorizations[w.agent.address] = auth;366 secrets[w.agent.address] = secret;367 }368 });369 it("run", async () => {370 consensus = odbtools.utils.hashConsensus(taskid, consensus);371 for (w of workers)372 {373 results[w.agent.address] = await w.agent.run(authorizations[w.agent.address], secrets[w.agent.address], w.result);374 }375 });376 it("[TX] contribute", async () => {377 for (w of workers)378 {379 txMined = await IexecInstance.contribute(380 authorizations[w.agent.address].taskid, // task (authorization)381 results [w.agent.address].hash, // common (result)382 results [w.agent.address].seal, // unique (result)383 authorizations[w.agent.address].enclave, // address (enclave)384 results [w.agent.address].sign, // signature (enclave)385 authorizations[w.agent.address].sign, // signature (authorization)386 { from: w.agent.address }387 );388 gasReceipt.push([ "contribute", txMined.receipt.gasUsed ]);389 events = tools.extractEvents(txMined, IexecInstance.address, "TaskContribute");390 assert.equal(events[0].args.taskid, authorizations[w.agent.address].taskid);391 assert.equal(events[0].args.worker, w.agent.address );392 assert.equal(events[0].args.hash, results[w.agent.address].hash );393 }394 });395 });396 describe("[4] reveal", async () => {397 it("[TX] reveal", async () => {398 for (w of workers)399 if (results[w.agent.address].hash == consensus.hash)400 {401 txMined = await IexecInstance.reveal(402 taskid,403 results[w.agent.address].digest,404 { from: w.agent.address }405 );406 gasReceipt.push([ "reveal", txMined.receipt.gasUsed ]);407 events = tools.extractEvents(txMined, IexecInstance.address, "TaskReveal");408 assert.equal(events[0].args.taskid, taskid );409 assert.equal(events[0].args.worker, w.agent.address );410 assert.equal(events[0].args.digest, results[w.agent.address].digest);411 }412 });413 });414 describe("[5] finalization", async () => {415 it("[TX] finalize", async () => {416 txMined = await IexecInstance.finalize(417 taskid,418 web3.utils.utf8ToHex("aResult"),419 "0x",420 { from: scheduler.address }421 );422 gasReceipt.push([ "finalize", txMined.receipt.gasUsed ]);423 events = tools.extractEvents(txMined, IexecInstance.address, "TaskFinalize");424 assert.equal(events[0].args.taskid, taskid );425 assert.equal(events[0].args.results, web3.utils.utf8ToHex("aResult"));426 // TODO: check 2 events by w.agent.address for w in workers427 // How to retreive events from the IexecClerk (5 rewards and 1 seize)428 });429 });430 });431 describe("→ summary", async () => {432 it("task", async () => {433 task = await IexecInstance.viewTask(taskid);434 assert.equal ( task.status, constants.TaskStatusEnum.COMPLETED );435 assert.equal ( task.dealid, dealid );436 assert.equal (Number(task.idx), 0 );437 assert.equal (Number(task.timeref), (await IexecInstance.viewCategory(requestorder.category)).workClockTimeRef);...

Full Screen

Full Screen

003_fullchain-3workers.js

Source:003_fullchain-3workers.js Github

copy

Full Screen

...109 constants.NULL.BYTES32,110 "0x",111 { from: appProvider.address }112 );113 events = tools.extractEvents(txMined, AppRegistryInstance.address, "Transfer");114 AppInstance = await App.at(tools.BN2Address(events[0].args.tokenId));115 });116 });117 describe("dataset", async () => {118 it("create", async () => {119 txMined = await DatasetRegistryInstance.createDataset(120 datasetProvider.address,121 "Pi",122 constants.MULTIADDR_BYTES,123 constants.NULL.BYTES32,124 { from: datasetProvider.address }125 );126 events = tools.extractEvents(txMined, DatasetRegistryInstance.address, "Transfer");127 DatasetInstance = await Dataset.at(tools.BN2Address(events[0].args.tokenId));128 });129 });130 describe("workerpool", async () => {131 it("create", async () => {132 txMined = await WorkerpoolRegistryInstance.createWorkerpool(133 scheduler.address,134 "A test workerpool",135 { from: scheduler.address }136 );137 events = tools.extractEvents(txMined, WorkerpoolRegistryInstance.address, "Transfer");138 WorkerpoolInstance = await Workerpool.at(tools.BN2Address(events[0].args.tokenId));139 });140 it("change policy", async () => {141 txMined = await WorkerpoolInstance.changePolicy(/* worker stake ratio */ 35, /* scheduler reward ratio */ 5, { from: scheduler.address });142 events = tools.extractEvents(txMined, WorkerpoolInstance.address, "PolicyUpdate");143 assert.equal(events[0].args.oldWorkerStakeRatioPolicy, 30);144 assert.equal(events[0].args.newWorkerStakeRatioPolicy, 35);145 assert.equal(events[0].args.oldSchedulerRewardRatioPolicy, 1);146 assert.equal(events[0].args.newSchedulerRewardRatioPolicy, 5);147 });148 });149 });150 describe("tokens", async () => {151 it("balances before", async () => {152 assert.deepEqual(await appProvider.viewAccount(), [ 0, 0 ], "check balance");153 assert.deepEqual(await datasetProvider.viewAccount(), [ 0, 0 ], "check balance");154 assert.deepEqual(await scheduler.viewAccount(), [ 0, 0 ], "check balance");155 assert.deepEqual(await worker1.viewAccount(), [ 0, 0 ], "check balance");156 assert.deepEqual(await worker2.viewAccount(), [ 0, 0 ], "check balance");157 assert.deepEqual(await worker3.viewAccount(), [ 0, 0 ], "check balance");158 assert.deepEqual(await worker4.viewAccount(), [ 0, 0 ], "check balance");159 assert.deepEqual(await worker5.viewAccount(), [ 0, 0 ], "check balance");160 assert.deepEqual(await user.viewAccount(), [ 0, 0 ], "check balance");161 });162 it("deposit", async () => {163 switch (DEPLOYMENT.asset)164 {165 case "Native":166 txMined = await IexecInstance.deposit({ from: iexecAdmin.address, value: 10000000 * 10 ** 9 });167 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.from, constants.NULL.ADDRESS);168 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.to, iexecAdmin.address);169 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.value, 10000000);170 break;171 case "Token":172 txMined = await RLCInstance.approveAndCall(IexecInstance.address, 10000000, "0x", { from: iexecAdmin.address });173 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.owner, iexecAdmin.address);174 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.spender, IexecInstance.address);175 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.value, 10000000);176 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.from, iexecAdmin.address);177 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.to, IexecInstance.address);178 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.value, 10000000);179 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.from, constants.NULL.ADDRESS);180 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.to, iexecAdmin.address);181 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.value, 10000000);182 break;183 }184 txsMined = await Promise.all([185 IexecInstance.transfer(scheduler.address, 1000, { from: iexecAdmin.address }),186 IexecInstance.transfer(worker1.address, 1000, { from: iexecAdmin.address }),187 IexecInstance.transfer(worker2.address, 1000, { from: iexecAdmin.address }),188 IexecInstance.transfer(worker3.address, 1000, { from: iexecAdmin.address }),189 IexecInstance.transfer(worker4.address, 1000, { from: iexecAdmin.address }),190 IexecInstance.transfer(worker5.address, 1000, { from: iexecAdmin.address }),191 IexecInstance.transfer(user.address, 1000, { from: iexecAdmin.address }),192 ]);193 assert.equal(tools.extractEvents(txsMined[0], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);194 assert.equal(tools.extractEvents(txsMined[0], IexecInstance.address, "Transfer")[0].args.value, 1000);195 assert.equal(tools.extractEvents(txsMined[1], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);196 assert.equal(tools.extractEvents(txsMined[1], IexecInstance.address, "Transfer")[0].args.value, 1000);197 assert.equal(tools.extractEvents(txsMined[2], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);198 assert.equal(tools.extractEvents(txsMined[2], IexecInstance.address, "Transfer")[0].args.value, 1000);199 assert.equal(tools.extractEvents(txsMined[3], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);200 assert.equal(tools.extractEvents(txsMined[3], IexecInstance.address, "Transfer")[0].args.value, 1000);201 assert.equal(tools.extractEvents(txsMined[4], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);202 assert.equal(tools.extractEvents(txsMined[4], IexecInstance.address, "Transfer")[0].args.value, 1000);203 assert.equal(tools.extractEvents(txsMined[5], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);204 assert.equal(tools.extractEvents(txsMined[5], IexecInstance.address, "Transfer")[0].args.value, 1000);205 assert.equal(tools.extractEvents(txsMined[6], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);206 assert.equal(tools.extractEvents(txsMined[6], IexecInstance.address, "Transfer")[0].args.value, 1000);207 });208 it("balances after", async () => {209 assert.deepEqual(await appProvider.viewAccount(), [ 0, 0 ], "check balance");210 assert.deepEqual(await datasetProvider.viewAccount(), [ 0, 0 ], "check balance");211 assert.deepEqual(await scheduler.viewAccount(), [ 1000, 0 ], "check balance");212 assert.deepEqual(await worker1.viewAccount(), [ 1000, 0 ], "check balance");213 assert.deepEqual(await worker2.viewAccount(), [ 1000, 0 ], "check balance");214 assert.deepEqual(await worker3.viewAccount(), [ 1000, 0 ], "check balance");215 assert.deepEqual(await worker4.viewAccount(), [ 1000, 0 ], "check balance");216 assert.deepEqual(await worker5.viewAccount(), [ 1000, 0 ], "check balance");217 assert.deepEqual(await user.viewAccount(), [ 1000, 0 ], "check balance");218 });219 });220 it("score", async () => {221 assert.equal(await worker1.viewScore(), 0, "score issue");222 assert.equal(await worker2.viewScore(), 0, "score issue");223 assert.equal(await worker3.viewScore(), 0, "score issue");224 assert.equal(await worker4.viewScore(), 0, "score issue");225 assert.equal(await worker5.viewScore(), 0, "score issue");226 });227 });228 describe("→ pipeline", async () => {229 describe("[0] orders", async () => {230 describe("app", async () => {231 it("sign", async () => {232 apporder = await appProvider.signAppOrder({233 app: AppInstance.address,234 appprice: 3,235 volume: 1000,236 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",237 datasetrestrict: constants.NULL.ADDRESS,238 workerpoolrestrict: constants.NULL.ADDRESS,239 requesterrestrict: constants.NULL.ADDRESS,240 salt: web3.utils.randomHex(32),241 sign: constants.NULL.SIGNATURE,242 });243 });244 it("verify", async () => {245 assert.isTrue(await IexecInstance.verifySignature(246 appProvider.address,247 odbtools.utils.hashAppOrder(ERC712_domain, apporder),248 apporder.sign249 ));250 });251 });252 describe("dataset", async () => {253 it("sign", async () => {254 datasetorder = await datasetProvider.signDatasetOrder({255 dataset: DatasetInstance.address,256 datasetprice: 1,257 volume: 1000,258 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",259 apprestrict: constants.NULL.ADDRESS,260 workerpoolrestrict: constants.NULL.ADDRESS,261 requesterrestrict: constants.NULL.ADDRESS,262 salt: web3.utils.randomHex(32),263 sign: constants.NULL.SIGNATURE,264 });265 });266 it("verify", async () => {267 assert.isTrue(await IexecInstance.verifySignature(268 datasetProvider.address,269 odbtools.utils.hashDatasetOrder(ERC712_domain, datasetorder),270 datasetorder.sign271 ));272 });273 });274 describe("workerpool", async () => {275 it("sign", async () => {276 workerpoolorder = await scheduler.signWorkerpoolOrder({277 workerpool: WorkerpoolInstance.address,278 workerpoolprice: 25,279 volume: 3,280 category: 4,281 trust: trusttarget,282 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",283 apprestrict: constants.NULL.ADDRESS,284 datasetrestrict: constants.NULL.ADDRESS,285 requesterrestrict: constants.NULL.ADDRESS,286 salt: web3.utils.randomHex(32),287 sign: constants.NULL.SIGNATURE,288 });289 });290 it("verify", async () => {291 assert.isTrue(await IexecInstance.verifySignature(292 scheduler.address,293 odbtools.utils.hashWorkerpoolOrder(ERC712_domain, workerpoolorder),294 workerpoolorder.sign295 ));296 });297 });298 describe("request", async () => {299 it("sign", async () => {300 requestorder = await user.signRequestOrder({301 app: AppInstance.address,302 appmaxprice: 3,303 dataset: DatasetInstance.address,304 datasetmaxprice: 1,305 workerpool: constants.NULL.ADDRESS,306 workerpoolmaxprice: 25,307 volume: 1, // CHANGE FOR BOT308 category: 4,309 trust: trusttarget,310 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",311 requester: user.address,312 beneficiary: user.address,313 callback: constants.NULL.ADDRESS,314 params: "<parameters>",315 salt: web3.utils.randomHex(32),316 sign: constants.NULL.SIGNATURE,317 });318 });319 it("verify", async () => {320 assert.isTrue(await IexecInstance.verifySignature(321 user.address,322 odbtools.utils.hashRequestOrder(ERC712_domain, requestorder),323 requestorder.sign324 ));325 });326 });327 });328 describe("[1] order matching", async () => {329 it("[TX] match", async () => {330 txMined = await IexecInstance.matchOrders(apporder, datasetorder, workerpoolorder, requestorder, { from: user.address });331 gasReceipt.push([ "matchOrders", txMined.receipt.gasUsed ]);332 dealid = web3.utils.soliditySha3(333 { t: 'bytes32', v: odbtools.utils.hashRequestOrder(ERC712_domain, requestorder) },334 { t: 'uint256', v: 0 },335 );336 events = tools.extractEvents(txMined, IexecInstance.address, "SchedulerNotice");337 assert.equal(events[0].args.workerpool, WorkerpoolInstance.address);338 assert.equal(events[0].args.dealid, dealid );339 events = tools.extractEvents(txMined, IexecInstance.address, "OrdersMatched");340 assert.equal(events[0].args.dealid, dealid );341 assert.equal(events[0].args.appHash, odbtools.utils.hashAppOrder (ERC712_domain, apporder ));342 assert.equal(events[0].args.datasetHash, odbtools.utils.hashDatasetOrder (ERC712_domain, datasetorder ));343 assert.equal(events[0].args.workerpoolHash, odbtools.utils.hashWorkerpoolOrder(ERC712_domain, workerpoolorder));344 assert.equal(events[0].args.requestHash, odbtools.utils.hashRequestOrder (ERC712_domain, requestorder ));345 assert.equal(events[0].args.volume, 1 );346 });347 });348 describe("[2] initialization", async () => {349 it("[TX] initialize", async () => {350 txMined = await IexecInstance.initialize(dealid, 0, { from: scheduler.address });351 gasReceipt.push([ "initialize", txMined.receipt.gasUsed ]);352 taskid = web3.utils.soliditySha3({ t: 'bytes32', v: dealid }, { t: 'uint256', v: 0 });353 events = tools.extractEvents(txMined, IexecInstance.address, "TaskInitialize");354 assert.equal(events[0].args.taskid, taskid );355 assert.equal(events[0].args.workerpool, WorkerpoolInstance.address);356 });357 });358 describe("[3] contribute", async () => {359 it("authorization signature", async () => {360 for (w of workers)361 {362 const preauth = await scheduler.signPreAuthorization(taskid, w.agent.address);363 const [ auth, secret ] = w.useenclave ? await broker.signAuthorization(preauth) : [ preauth, null ];364 authorizations[w.agent.address] = auth;365 secrets[w.agent.address] = secret;366 }367 });368 it("run", async () => {369 consensus = odbtools.utils.hashConsensus(taskid, consensus);370 for (w of workers)371 {372 results[w.agent.address] = await w.agent.run(authorizations[w.agent.address], secrets[w.agent.address], w.result);373 }374 });375 it("[TX] contribute", async () => {376 for (w of workers)377 {378 txMined = await IexecInstance.contribute(379 authorizations[w.agent.address].taskid, // task (authorization)380 results [w.agent.address].hash, // common (result)381 results [w.agent.address].seal, // unique (result)382 authorizations[w.agent.address].enclave, // address (enclave)383 results [w.agent.address].sign, // signature (enclave)384 authorizations[w.agent.address].sign, // signature (authorization)385 { from: w.agent.address }386 );387 gasReceipt.push([ "contribute", txMined.receipt.gasUsed ]);388 events = tools.extractEvents(txMined, IexecInstance.address, "TaskContribute");389 assert.equal(events[0].args.taskid, authorizations[w.agent.address].taskid);390 assert.equal(events[0].args.worker, w.agent.address );391 assert.equal(events[0].args.hash, results[w.agent.address].hash );392 }393 });394 });395 describe("[4] reveal", async () => {396 it("[TX] reveal", async () => {397 for (w of workers)398 if (results[w.agent.address].hash == consensus.hash)399 {400 txMined = await IexecInstance.reveal(401 taskid,402 results[w.agent.address].digest,403 { from: w.agent.address }404 );405 gasReceipt.push([ "reveal", txMined.receipt.gasUsed ]);406 events = tools.extractEvents(txMined, IexecInstance.address, "TaskReveal");407 assert.equal(events[0].args.taskid, taskid );408 assert.equal(events[0].args.worker, w.agent.address );409 assert.equal(events[0].args.digest, results[w.agent.address].digest);410 }411 });412 });413 describe("[5] finalization", async () => {414 it("[TX] finalize", async () => {415 txMined = await IexecInstance.finalize(416 taskid,417 web3.utils.utf8ToHex("aResult"),418 "0x",419 { from: scheduler.address }420 );421 gasReceipt.push([ "finalize", txMined.receipt.gasUsed ]);422 events = tools.extractEvents(txMined, IexecInstance.address, "TaskFinalize");423 assert.equal(events[0].args.taskid, taskid );424 assert.equal(events[0].args.results, web3.utils.utf8ToHex("aResult"));425 // TODO: check 2 events by w.agent.address for w in workers426 // How to retreive events from the IexecClerk (5 rewards and 1 seize)427 });428 });429 });430 describe("→ summary", async () => {431 it("task", async () => {432 task = await IexecInstance.viewTask(taskid);433 assert.equal ( task.status, constants.TaskStatusEnum.COMPLETED );434 assert.equal ( task.dealid, dealid );435 assert.equal (Number(task.idx), 0 );436 assert.equal (Number(task.timeref), (await IexecInstance.viewCategory(requestorder.category)).workClockTimeRef);...

Full Screen

Full Screen

002_fullchain-2workers.js

Source:002_fullchain-2workers.js Github

copy

Full Screen

...108 constants.NULL.BYTES32,109 "0x",110 { from: appProvider.address }111 );112 events = tools.extractEvents(txMined, AppRegistryInstance.address, "Transfer");113 AppInstance = await App.at(tools.BN2Address(events[0].args.tokenId));114 });115 });116 describe("dataset", async () => {117 it("create", async () => {118 txMined = await DatasetRegistryInstance.createDataset(119 datasetProvider.address,120 "Pi",121 constants.MULTIADDR_BYTES,122 constants.NULL.BYTES32,123 { from: datasetProvider.address }124 );125 events = tools.extractEvents(txMined, DatasetRegistryInstance.address, "Transfer");126 DatasetInstance = await Dataset.at(tools.BN2Address(events[0].args.tokenId));127 });128 });129 describe("workerpool", async () => {130 it("create", async () => {131 txMined = await WorkerpoolRegistryInstance.createWorkerpool(132 scheduler.address,133 "A test workerpool",134 { from: scheduler.address }135 );136 events = tools.extractEvents(txMined, WorkerpoolRegistryInstance.address, "Transfer");137 WorkerpoolInstance = await Workerpool.at(tools.BN2Address(events[0].args.tokenId));138 });139 it("change policy", async () => {140 txMined = await WorkerpoolInstance.changePolicy(/* worker stake ratio */ 35, /* scheduler reward ratio */ 5, { from: scheduler.address });141 events = tools.extractEvents(txMined, WorkerpoolInstance.address, "PolicyUpdate");142 assert.equal(events[0].args.oldWorkerStakeRatioPolicy, 30);143 assert.equal(events[0].args.newWorkerStakeRatioPolicy, 35);144 assert.equal(events[0].args.oldSchedulerRewardRatioPolicy, 1);145 assert.equal(events[0].args.newSchedulerRewardRatioPolicy, 5);146 });147 });148 });149 describe("tokens", async () => {150 it("balances before", async () => {151 assert.deepEqual(await appProvider.viewAccount(), [ 0, 0 ], "check balance");152 assert.deepEqual(await datasetProvider.viewAccount(), [ 0, 0 ], "check balance");153 assert.deepEqual(await scheduler.viewAccount(), [ 0, 0 ], "check balance");154 assert.deepEqual(await worker1.viewAccount(), [ 0, 0 ], "check balance");155 assert.deepEqual(await worker2.viewAccount(), [ 0, 0 ], "check balance");156 assert.deepEqual(await worker3.viewAccount(), [ 0, 0 ], "check balance");157 assert.deepEqual(await worker4.viewAccount(), [ 0, 0 ], "check balance");158 assert.deepEqual(await worker5.viewAccount(), [ 0, 0 ], "check balance");159 assert.deepEqual(await user.viewAccount(), [ 0, 0 ], "check balance");160 });161 it("deposit", async () => {162 switch (DEPLOYMENT.asset)163 {164 case "Native":165 txMined = await IexecInstance.deposit({ from: iexecAdmin.address, value: 10000000 * 10 ** 9 });166 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.from, constants.NULL.ADDRESS);167 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.to, iexecAdmin.address);168 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.value, 10000000);169 break;170 case "Token":171 txMined = await RLCInstance.approveAndCall(IexecInstance.address, 10000000, "0x", { from: iexecAdmin.address });172 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.owner, iexecAdmin.address);173 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.spender, IexecInstance.address);174 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.value, 10000000);175 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.from, iexecAdmin.address);176 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.to, IexecInstance.address);177 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.value, 10000000);178 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.from, constants.NULL.ADDRESS);179 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.to, iexecAdmin.address);180 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.value, 10000000);181 break;182 }183 txsMined = await Promise.all([184 IexecInstance.transfer(scheduler.address, 1000, { from: iexecAdmin.address }),185 IexecInstance.transfer(worker1.address, 1000, { from: iexecAdmin.address }),186 IexecInstance.transfer(worker2.address, 1000, { from: iexecAdmin.address }),187 IexecInstance.transfer(worker3.address, 1000, { from: iexecAdmin.address }),188 IexecInstance.transfer(worker4.address, 1000, { from: iexecAdmin.address }),189 IexecInstance.transfer(worker5.address, 1000, { from: iexecAdmin.address }),190 IexecInstance.transfer(user.address, 1000, { from: iexecAdmin.address }),191 ]);192 assert.equal(tools.extractEvents(txsMined[0], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);193 assert.equal(tools.extractEvents(txsMined[0], IexecInstance.address, "Transfer")[0].args.value, 1000);194 assert.equal(tools.extractEvents(txsMined[1], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);195 assert.equal(tools.extractEvents(txsMined[1], IexecInstance.address, "Transfer")[0].args.value, 1000);196 assert.equal(tools.extractEvents(txsMined[2], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);197 assert.equal(tools.extractEvents(txsMined[2], IexecInstance.address, "Transfer")[0].args.value, 1000);198 assert.equal(tools.extractEvents(txsMined[3], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);199 assert.equal(tools.extractEvents(txsMined[3], IexecInstance.address, "Transfer")[0].args.value, 1000);200 assert.equal(tools.extractEvents(txsMined[4], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);201 assert.equal(tools.extractEvents(txsMined[4], IexecInstance.address, "Transfer")[0].args.value, 1000);202 assert.equal(tools.extractEvents(txsMined[5], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);203 assert.equal(tools.extractEvents(txsMined[5], IexecInstance.address, "Transfer")[0].args.value, 1000);204 assert.equal(tools.extractEvents(txsMined[6], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);205 assert.equal(tools.extractEvents(txsMined[6], IexecInstance.address, "Transfer")[0].args.value, 1000);206 });207 it("balances after", async () => {208 assert.deepEqual(await appProvider.viewAccount(), [ 0, 0 ], "check balance");209 assert.deepEqual(await datasetProvider.viewAccount(), [ 0, 0 ], "check balance");210 assert.deepEqual(await scheduler.viewAccount(), [ 1000, 0 ], "check balance");211 assert.deepEqual(await worker1.viewAccount(), [ 1000, 0 ], "check balance");212 assert.deepEqual(await worker2.viewAccount(), [ 1000, 0 ], "check balance");213 assert.deepEqual(await worker3.viewAccount(), [ 1000, 0 ], "check balance");214 assert.deepEqual(await worker4.viewAccount(), [ 1000, 0 ], "check balance");215 assert.deepEqual(await worker5.viewAccount(), [ 1000, 0 ], "check balance");216 assert.deepEqual(await user.viewAccount(), [ 1000, 0 ], "check balance");217 });218 });219 it("score", async () => {220 assert.equal(await worker1.viewScore(), 0, "score issue");221 assert.equal(await worker2.viewScore(), 0, "score issue");222 assert.equal(await worker3.viewScore(), 0, "score issue");223 assert.equal(await worker4.viewScore(), 0, "score issue");224 assert.equal(await worker5.viewScore(), 0, "score issue");225 });226 });227 describe("→ pipeline", async () => {228 describe("[0] orders", async () => {229 describe("app", async () => {230 it("sign", async () => {231 apporder = await appProvider.signAppOrder({232 app: AppInstance.address,233 appprice: 3,234 volume: 1000,235 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",236 datasetrestrict: constants.NULL.ADDRESS,237 workerpoolrestrict: constants.NULL.ADDRESS,238 requesterrestrict: constants.NULL.ADDRESS,239 salt: web3.utils.randomHex(32),240 sign: constants.NULL.SIGNATURE,241 });242 });243 it("verify", async () => {244 assert.isTrue(await IexecInstance.verifySignature(245 appProvider.address,246 odbtools.utils.hashAppOrder(ERC712_domain, apporder),247 apporder.sign248 ));249 });250 });251 describe("dataset", async () => {252 it("sign", async () => {253 datasetorder = await datasetProvider.signDatasetOrder({254 dataset: DatasetInstance.address,255 datasetprice: 1,256 volume: 1000,257 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",258 apprestrict: constants.NULL.ADDRESS,259 workerpoolrestrict: constants.NULL.ADDRESS,260 requesterrestrict: constants.NULL.ADDRESS,261 salt: web3.utils.randomHex(32),262 sign: constants.NULL.SIGNATURE,263 });264 });265 it("verify", async () => {266 assert.isTrue(await IexecInstance.verifySignature(267 datasetProvider.address,268 odbtools.utils.hashDatasetOrder(ERC712_domain, datasetorder),269 datasetorder.sign270 ));271 });272 });273 describe("workerpool", async () => {274 it("sign", async () => {275 workerpoolorder = await scheduler.signWorkerpoolOrder({276 workerpool: WorkerpoolInstance.address,277 workerpoolprice: 25,278 volume: 3,279 category: 4,280 trust: trusttarget,281 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",282 apprestrict: constants.NULL.ADDRESS,283 datasetrestrict: constants.NULL.ADDRESS,284 requesterrestrict: constants.NULL.ADDRESS,285 salt: web3.utils.randomHex(32),286 sign: constants.NULL.SIGNATURE,287 });288 });289 it("verify", async () => {290 assert.isTrue(await IexecInstance.verifySignature(291 scheduler.address,292 odbtools.utils.hashWorkerpoolOrder(ERC712_domain, workerpoolorder),293 workerpoolorder.sign294 ));295 });296 });297 describe("request", async () => {298 it("sign", async () => {299 requestorder = await user.signRequestOrder({300 app: AppInstance.address,301 appmaxprice: 3,302 dataset: DatasetInstance.address,303 datasetmaxprice: 1,304 workerpool: constants.NULL.ADDRESS,305 workerpoolmaxprice: 25,306 volume: 1, // CHANGE FOR BOT307 category: 4,308 trust: trusttarget,309 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",310 requester: user.address,311 beneficiary: user.address,312 callback: constants.NULL.ADDRESS,313 params: "<parameters>",314 salt: web3.utils.randomHex(32),315 sign: constants.NULL.SIGNATURE,316 });317 });318 it("verify", async () => {319 assert.isTrue(await IexecInstance.verifySignature(320 user.address,321 odbtools.utils.hashRequestOrder(ERC712_domain, requestorder),322 requestorder.sign323 ));324 });325 });326 });327 describe("[1] order matching", async () => {328 it("[TX] match", async () => {329 txMined = await IexecInstance.matchOrders(apporder, datasetorder, workerpoolorder, requestorder, { from: user.address });330 gasReceipt.push([ "matchOrders", txMined.receipt.gasUsed ]);331 dealid = web3.utils.soliditySha3(332 { t: 'bytes32', v: odbtools.utils.hashRequestOrder(ERC712_domain, requestorder) },333 { t: 'uint256', v: 0 },334 );335 events = tools.extractEvents(txMined, IexecInstance.address, "SchedulerNotice");336 assert.equal(events[0].args.workerpool, WorkerpoolInstance.address);337 assert.equal(events[0].args.dealid, dealid );338 events = tools.extractEvents(txMined, IexecInstance.address, "OrdersMatched");339 assert.equal(events[0].args.dealid, dealid );340 assert.equal(events[0].args.appHash, odbtools.utils.hashAppOrder (ERC712_domain, apporder ));341 assert.equal(events[0].args.datasetHash, odbtools.utils.hashDatasetOrder (ERC712_domain, datasetorder ));342 assert.equal(events[0].args.workerpoolHash, odbtools.utils.hashWorkerpoolOrder(ERC712_domain, workerpoolorder));343 assert.equal(events[0].args.requestHash, odbtools.utils.hashRequestOrder (ERC712_domain, requestorder ));344 assert.equal(events[0].args.volume, 1 );345 });346 });347 describe("[2] initialization", async () => {348 it("[TX] initialize", async () => {349 txMined = await IexecInstance.initialize(dealid, 0, { from: scheduler.address });350 gasReceipt.push([ "initialize", txMined.receipt.gasUsed ]);351 taskid = web3.utils.soliditySha3({ t: 'bytes32', v: dealid }, { t: 'uint256', v: 0 });352 events = tools.extractEvents(txMined, IexecInstance.address, "TaskInitialize");353 assert.equal(events[0].args.taskid, taskid );354 assert.equal(events[0].args.workerpool, WorkerpoolInstance.address);355 });356 });357 describe("[3] contribute", async () => {358 it("authorization signature", async () => {359 for (w of workers)360 {361 const preauth = await scheduler.signPreAuthorization(taskid, w.agent.address);362 const [ auth, secret ] = w.useenclave ? await broker.signAuthorization(preauth) : [ preauth, null ];363 authorizations[w.agent.address] = auth;364 secrets[w.agent.address] = secret;365 }366 });367 it("run", async () => {368 consensus = odbtools.utils.hashConsensus(taskid, consensus);369 for (w of workers)370 {371 results[w.agent.address] = await w.agent.run(authorizations[w.agent.address], secrets[w.agent.address], w.result);372 }373 });374 it("[TX] contribute", async () => {375 for (w of workers)376 {377 txMined = await IexecInstance.contribute(378 authorizations[w.agent.address].taskid, // task (authorization)379 results [w.agent.address].hash, // common (result)380 results [w.agent.address].seal, // unique (result)381 authorizations[w.agent.address].enclave, // address (enclave)382 results [w.agent.address].sign, // signature (enclave)383 authorizations[w.agent.address].sign, // signature (authorization)384 { from: w.agent.address }385 );386 gasReceipt.push([ "contribute", txMined.receipt.gasUsed ]);387 events = tools.extractEvents(txMined, IexecInstance.address, "TaskContribute");388 assert.equal(events[0].args.taskid, authorizations[w.agent.address].taskid);389 assert.equal(events[0].args.worker, w.agent.address );390 assert.equal(events[0].args.hash, results[w.agent.address].hash );391 }392 });393 });394 describe("[4] reveal", async () => {395 it("[TX] reveal", async () => {396 for (w of workers)397 if (results[w.agent.address].hash == consensus.hash)398 {399 txMined = await IexecInstance.reveal(400 taskid,401 results[w.agent.address].digest,402 { from: w.agent.address }403 );404 gasReceipt.push([ "reveal", txMined.receipt.gasUsed ]);405 events = tools.extractEvents(txMined, IexecInstance.address, "TaskReveal");406 assert.equal(events[0].args.taskid, taskid );407 assert.equal(events[0].args.worker, w.agent.address );408 assert.equal(events[0].args.digest, results[w.agent.address].digest);409 }410 });411 });412 describe("[5] finalization", async () => {413 it("[TX] finalize", async () => {414 txMined = await IexecInstance.finalize(415 taskid,416 web3.utils.utf8ToHex("aResult"),417 "0x",418 { from: scheduler.address }419 );420 gasReceipt.push([ "finalize", txMined.receipt.gasUsed ]);421 events = tools.extractEvents(txMined, IexecInstance.address, "TaskFinalize");422 assert.equal(events[0].args.taskid, taskid );423 assert.equal(events[0].args.results, web3.utils.utf8ToHex("aResult"));424 // TODO: check 2 events by w.address for w in workers425 // How to retreive events from the IexecClerk (5 rewards and 1 seize)426 });427 });428 });429 describe("→ summary", async () => {430 it("task", async () => {431 task = await IexecInstance.viewTask(taskid);432 assert.equal ( task.status, constants.TaskStatusEnum.COMPLETED );433 assert.equal ( task.dealid, dealid );434 assert.equal (Number(task.idx), 0 );435 assert.equal (Number(task.timeref), (await IexecInstance.viewCategory(requestorder.category)).workClockTimeRef);...

Full Screen

Full Screen

001_fullchain-1workers.js

Source:001_fullchain-1workers.js Github

copy

Full Screen

...107 constants.NULL.BYTES32,108 "0x",109 { from: appProvider.address }110 );111 events = tools.extractEvents(txMined, AppRegistryInstance.address, "Transfer");112 AppInstance = await App.at(tools.BN2Address(events[0].args.tokenId));113 });114 });115 describe("dataset", async () => {116 it("create", async () => {117 txMined = await DatasetRegistryInstance.createDataset(118 datasetProvider.address,119 "Pi",120 constants.MULTIADDR_BYTES,121 constants.NULL.BYTES32,122 { from: datasetProvider.address }123 );124 events = tools.extractEvents(txMined, DatasetRegistryInstance.address, "Transfer");125 DatasetInstance = await Dataset.at(tools.BN2Address(events[0].args.tokenId));126 });127 });128 describe("workerpool", async () => {129 it("create", async () => {130 txMined = await WorkerpoolRegistryInstance.createWorkerpool(131 scheduler.address,132 "A test workerpool",133 { from: scheduler.address }134 );135 events = tools.extractEvents(txMined, WorkerpoolRegistryInstance.address, "Transfer");136 WorkerpoolInstance = await Workerpool.at(tools.BN2Address(events[0].args.tokenId));137 });138 it("change policy", async () => {139 txMined = await WorkerpoolInstance.changePolicy(/* worker stake ratio */ 35, /* scheduler reward ratio */ 5, { from: scheduler.address });140 events = tools.extractEvents(txMined, WorkerpoolInstance.address, "PolicyUpdate");141 assert.equal(events[0].args.oldWorkerStakeRatioPolicy, 30);142 assert.equal(events[0].args.newWorkerStakeRatioPolicy, 35);143 assert.equal(events[0].args.oldSchedulerRewardRatioPolicy, 1);144 assert.equal(events[0].args.newSchedulerRewardRatioPolicy, 5);145 });146 });147 });148 describe("tokens", async () => {149 it("balances before", async () => {150 assert.deepEqual(await appProvider.viewAccount(), [ 0, 0 ], "check balance");151 assert.deepEqual(await datasetProvider.viewAccount(), [ 0, 0 ], "check balance");152 assert.deepEqual(await scheduler.viewAccount(), [ 0, 0 ], "check balance");153 assert.deepEqual(await worker1.viewAccount(), [ 0, 0 ], "check balance");154 assert.deepEqual(await worker2.viewAccount(), [ 0, 0 ], "check balance");155 assert.deepEqual(await worker3.viewAccount(), [ 0, 0 ], "check balance");156 assert.deepEqual(await worker4.viewAccount(), [ 0, 0 ], "check balance");157 assert.deepEqual(await worker5.viewAccount(), [ 0, 0 ], "check balance");158 assert.deepEqual(await user.viewAccount(), [ 0, 0 ], "check balance");159 });160 it("deposit", async () => {161 switch (DEPLOYMENT.asset)162 {163 case "Native":164 txMined = await IexecInstance.deposit({ from: iexecAdmin.address, value: 10000000 * 10 ** 9 });165 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.from, constants.NULL.ADDRESS);166 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.to, iexecAdmin.address);167 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.value, 10000000);168 break;169 case "Token":170 txMined = await RLCInstance.approveAndCall(IexecInstance.address, 10000000, "0x", { from: iexecAdmin.address });171 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.owner, iexecAdmin.address);172 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.spender, IexecInstance.address);173 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.value, 10000000);174 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.from, iexecAdmin.address);175 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.to, IexecInstance.address);176 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.value, 10000000);177 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.from, constants.NULL.ADDRESS);178 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.to, iexecAdmin.address);179 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.value, 10000000);180 break;181 }182 txsMined = await Promise.all([183 IexecInstance.transfer(scheduler.address, 1000, { from: iexecAdmin.address }),184 IexecInstance.transfer(worker1.address, 1000, { from: iexecAdmin.address }),185 IexecInstance.transfer(worker2.address, 1000, { from: iexecAdmin.address }),186 IexecInstance.transfer(worker3.address, 1000, { from: iexecAdmin.address }),187 IexecInstance.transfer(worker4.address, 1000, { from: iexecAdmin.address }),188 IexecInstance.transfer(worker5.address, 1000, { from: iexecAdmin.address }),189 IexecInstance.transfer(user.address, 1000, { from: iexecAdmin.address }),190 ]);191 assert.equal(tools.extractEvents(txsMined[0], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);192 assert.equal(tools.extractEvents(txsMined[0], IexecInstance.address, "Transfer")[0].args.value, 1000);193 assert.equal(tools.extractEvents(txsMined[1], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);194 assert.equal(tools.extractEvents(txsMined[1], IexecInstance.address, "Transfer")[0].args.value, 1000);195 assert.equal(tools.extractEvents(txsMined[2], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);196 assert.equal(tools.extractEvents(txsMined[2], IexecInstance.address, "Transfer")[0].args.value, 1000);197 assert.equal(tools.extractEvents(txsMined[3], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);198 assert.equal(tools.extractEvents(txsMined[3], IexecInstance.address, "Transfer")[0].args.value, 1000);199 assert.equal(tools.extractEvents(txsMined[4], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);200 assert.equal(tools.extractEvents(txsMined[4], IexecInstance.address, "Transfer")[0].args.value, 1000);201 assert.equal(tools.extractEvents(txsMined[5], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);202 assert.equal(tools.extractEvents(txsMined[5], IexecInstance.address, "Transfer")[0].args.value, 1000);203 assert.equal(tools.extractEvents(txsMined[6], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);204 assert.equal(tools.extractEvents(txsMined[6], IexecInstance.address, "Transfer")[0].args.value, 1000);205 });206 it("balances after", async () => {207 assert.deepEqual(await appProvider.viewAccount(), [ 0, 0 ], "check balance");208 assert.deepEqual(await datasetProvider.viewAccount(), [ 0, 0 ], "check balance");209 assert.deepEqual(await scheduler.viewAccount(), [ 1000, 0 ], "check balance");210 assert.deepEqual(await worker1.viewAccount(), [ 1000, 0 ], "check balance");211 assert.deepEqual(await worker2.viewAccount(), [ 1000, 0 ], "check balance");212 assert.deepEqual(await worker3.viewAccount(), [ 1000, 0 ], "check balance");213 assert.deepEqual(await worker4.viewAccount(), [ 1000, 0 ], "check balance");214 assert.deepEqual(await worker5.viewAccount(), [ 1000, 0 ], "check balance");215 assert.deepEqual(await user.viewAccount(), [ 1000, 0 ], "check balance");216 });217 });218 it("score", async () => {219 assert.equal(await worker1.viewScore(), 0, "score issue");220 assert.equal(await worker2.viewScore(), 0, "score issue");221 assert.equal(await worker3.viewScore(), 0, "score issue");222 assert.equal(await worker4.viewScore(), 0, "score issue");223 assert.equal(await worker5.viewScore(), 0, "score issue");224 });225 });226 describe("→ pipeline", async () => {227 describe("[0] orders", async () => {228 describe("app", async () => {229 it("sign", async () => {230 apporder = await appProvider.signAppOrder({231 app: AppInstance.address,232 appprice: 3,233 volume: 1000,234 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",235 datasetrestrict: constants.NULL.ADDRESS,236 workerpoolrestrict: constants.NULL.ADDRESS,237 requesterrestrict: constants.NULL.ADDRESS,238 salt: web3.utils.randomHex(32),239 sign: constants.NULL.SIGNATURE,240 });241 });242 it("verify", async () => {243 assert.isTrue(await IexecInstance.verifySignature(244 appProvider.address,245 odbtools.utils.hashAppOrder(ERC712_domain, apporder),246 apporder.sign247 ));248 });249 });250 describe("dataset", async () => {251 it("sign", async () => {252 datasetorder = await datasetProvider.signDatasetOrder({253 dataset: DatasetInstance.address,254 datasetprice: 1,255 volume: 1000,256 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",257 apprestrict: constants.NULL.ADDRESS,258 workerpoolrestrict: constants.NULL.ADDRESS,259 requesterrestrict: constants.NULL.ADDRESS,260 salt: web3.utils.randomHex(32),261 sign: constants.NULL.SIGNATURE,262 });263 });264 it("verify", async () => {265 assert.isTrue(await IexecInstance.verifySignature(266 datasetProvider.address,267 odbtools.utils.hashDatasetOrder(ERC712_domain, datasetorder),268 datasetorder.sign269 ));270 });271 });272 describe("workerpool", async () => {273 it("sign", async () => {274 workerpoolorder = await scheduler.signWorkerpoolOrder({275 workerpool: WorkerpoolInstance.address,276 workerpoolprice: 25,277 volume: 3,278 category: 4,279 trust: trusttarget,280 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",281 apprestrict: constants.NULL.ADDRESS,282 datasetrestrict: constants.NULL.ADDRESS,283 requesterrestrict: constants.NULL.ADDRESS,284 salt: web3.utils.randomHex(32),285 sign: constants.NULL.SIGNATURE,286 });287 });288 it("verify", async () => {289 assert.isTrue(await IexecInstance.verifySignature(290 scheduler.address,291 odbtools.utils.hashWorkerpoolOrder(ERC712_domain, workerpoolorder),292 workerpoolorder.sign293 ));294 });295 });296 describe("request", async () => {297 it("sign", async () => {298 requestorder = await user.signRequestOrder({299 app: AppInstance.address,300 appmaxprice: 3,301 dataset: DatasetInstance.address,302 datasetmaxprice: 1,303 workerpool: constants.NULL.ADDRESS,304 workerpoolmaxprice: 25,305 volume: 1, // CHANGE FOR BOT306 category: 4,307 trust: trusttarget,308 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",309 requester: user.address,310 beneficiary: user.address,311 callback: constants.NULL.ADDRESS,312 params: "<parameters>",313 salt: web3.utils.randomHex(32),314 sign: constants.NULL.SIGNATURE,315 });316 });317 it("verify", async () => {318 assert.isTrue(await IexecInstance.verifySignature(319 user.address,320 odbtools.utils.hashRequestOrder(ERC712_domain, requestorder),321 requestorder.sign322 ));323 });324 });325 });326 describe("[1] order matching", async () => {327 it("[TX] match", async () => {328 txMined = await IexecInstance.matchOrders(apporder, datasetorder, workerpoolorder, requestorder, { from: user.address });329 gasReceipt.push([ "matchOrders", txMined.receipt.gasUsed ]);330 dealid = web3.utils.soliditySha3(331 { t: 'bytes32', v: odbtools.utils.hashRequestOrder(ERC712_domain, requestorder) },332 { t: 'uint256', v: 0 },333 );334 events = tools.extractEvents(txMined, IexecInstance.address, "SchedulerNotice");335 assert.equal(events[0].args.workerpool, WorkerpoolInstance.address);336 assert.equal(events[0].args.dealid, dealid );337 events = tools.extractEvents(txMined, IexecInstance.address, "OrdersMatched");338 assert.equal(events[0].args.dealid, dealid );339 assert.equal(events[0].args.appHash, odbtools.utils.hashAppOrder (ERC712_domain, apporder ));340 assert.equal(events[0].args.datasetHash, odbtools.utils.hashDatasetOrder (ERC712_domain, datasetorder ));341 assert.equal(events[0].args.workerpoolHash, odbtools.utils.hashWorkerpoolOrder(ERC712_domain, workerpoolorder));342 assert.equal(events[0].args.requestHash, odbtools.utils.hashRequestOrder (ERC712_domain, requestorder ));343 assert.equal(events[0].args.volume, 1 );344 });345 });346 describe("[2] initialization", async () => {347 it("[TX] initialize", async () => {348 txMined = await IexecInstance.initialize(dealid, 0, { from: scheduler.address });349 gasReceipt.push([ "initialize", txMined.receipt.gasUsed ]);350 taskid = web3.utils.soliditySha3({ t: 'bytes32', v: dealid }, { t: 'uint256', v: 0 });351 events = tools.extractEvents(txMined, IexecInstance.address, "TaskInitialize");352 assert.equal(events[0].args.taskid, taskid );353 assert.equal(events[0].args.workerpool, WorkerpoolInstance.address);354 });355 });356 describe("[3] contribute", async () => {357 it("authorization signature", async () => {358 for (w of workers)359 {360 const preauth = await scheduler.signPreAuthorization(taskid, w.agent.address);361 const [ auth, secret ] = w.useenclave ? await broker.signAuthorization(preauth) : [ preauth, null ];362 authorizations[w.agent.address] = auth;363 secrets[w.agent.address] = secret;364 }365 });366 it("run", async () => {367 consensus = odbtools.utils.hashConsensus(taskid, consensus);368 for (w of workers)369 {370 results[w.agent.address] = await w.agent.run(authorizations[w.agent.address], secrets[w.agent.address], w.result);371 }372 });373 it("[TX] contribute", async () => {374 for (w of workers)375 {376 txMined = await IexecInstance.contribute(377 authorizations[w.agent.address].taskid, // task (authorization)378 results [w.agent.address].hash, // common (result)379 results [w.agent.address].seal, // unique (result)380 authorizations[w.agent.address].enclave, // address (enclave)381 results [w.agent.address].sign, // signature (enclave)382 authorizations[w.agent.address].sign, // signature (authorization)383 { from: w.agent.address }384 );385 gasReceipt.push([ "contribute", txMined.receipt.gasUsed ]);386 events = tools.extractEvents(txMined, IexecInstance.address, "TaskContribute");387 assert.equal(events[0].args.taskid, authorizations[w.agent.address].taskid);388 assert.equal(events[0].args.worker, w.agent.address );389 assert.equal(events[0].args.hash, results[w.agent.address].hash );390 }391 });392 });393 describe("[4] reveal", async () => {394 it("[TX] reveal", async () => {395 for (w of workers)396 if (results[w.agent.address].hash == consensus.hash)397 {398 txMined = await IexecInstance.reveal(399 taskid,400 results[w.agent.address].digest,401 { from: w.agent.address }402 );403 gasReceipt.push([ "reveal", txMined.receipt.gasUsed ]);404 events = tools.extractEvents(txMined, IexecInstance.address, "TaskReveal");405 assert.equal(events[0].args.taskid, taskid );406 assert.equal(events[0].args.worker, w.agent.address );407 assert.equal(events[0].args.digest, results[w.agent.address].digest);408 }409 });410 });411 describe("[5] finalization", async () => {412 it("[TX] finalize", async () => {413 txMined = await IexecInstance.finalize(414 taskid,415 web3.utils.utf8ToHex("aResult"),416 "0x",417 { from: scheduler.address }418 );419 gasReceipt.push([ "finalize", txMined.receipt.gasUsed ]);420 events = tools.extractEvents(txMined, IexecInstance.address, "TaskFinalize");421 assert.equal(events[0].args.taskid, taskid );422 assert.equal(events[0].args.results, web3.utils.utf8ToHex("aResult"));423 // TODO: check 2 events by w.address for w in workers424 // How to retreive events from the IexecClerk (5 rewards and 1 seize)425 });426 });427 });428 describe("→ summary", async () => {429 it("task", async () => {430 task = await IexecInstance.viewTask(taskid);431 assert.equal ( task.status, constants.TaskStatusEnum.COMPLETED );432 assert.equal ( task.dealid, dealid );433 assert.equal (Number(task.idx), 0 );434 assert.equal (Number(task.timeref), (await IexecInstance.viewCategory(requestorder.category)).workClockTimeRef);...

Full Screen

Full Screen

400_contributeAndCallback.js

Source:400_contributeAndCallback.js Github

copy

Full Screen

...105 constants.NULL.BYTES32,106 "0x",107 { from: appProvider.address }108 );109 events = tools.extractEvents(txMined, AppRegistryInstance.address, "Transfer");110 AppInstance = await App.at(tools.BN2Address(events[0].args.tokenId));111 });112 });113 describe("dataset", async () => {114 it("create", async () => {115 txMined = await DatasetRegistryInstance.createDataset(116 datasetProvider.address,117 "Pi",118 constants.MULTIADDR_BYTES,119 constants.NULL.BYTES32,120 { from: datasetProvider.address }121 );122 events = tools.extractEvents(txMined, DatasetRegistryInstance.address, "Transfer");123 DatasetInstance = await Dataset.at(tools.BN2Address(events[0].args.tokenId));124 });125 });126 describe("workerpool", async () => {127 it("create", async () => {128 txMined = await WorkerpoolRegistryInstance.createWorkerpool(129 scheduler.address,130 "A test workerpool",131 { from: scheduler.address }132 );133 events = tools.extractEvents(txMined, WorkerpoolRegistryInstance.address, "Transfer");134 WorkerpoolInstance = await Workerpool.at(tools.BN2Address(events[0].args.tokenId));135 });136 it("change policy", async () => {137 txMined = await WorkerpoolInstance.changePolicy(/* worker stake ratio */ 35, /* scheduler reward ratio */ 5, { from: scheduler.address });138 events = tools.extractEvents(txMined, WorkerpoolInstance.address, "PolicyUpdate");139 assert.equal(events[0].args.oldWorkerStakeRatioPolicy, 30);140 assert.equal(events[0].args.newWorkerStakeRatioPolicy, 35);141 assert.equal(events[0].args.oldSchedulerRewardRatioPolicy, 1);142 assert.equal(events[0].args.newSchedulerRewardRatioPolicy, 5);143 });144 });145 });146 describe("tokens", async () => {147 it("balances before", async () => {148 assert.deepEqual(await appProvider.viewAccount(), [ 0, 0 ], "check balance");149 assert.deepEqual(await datasetProvider.viewAccount(), [ 0, 0 ], "check balance");150 assert.deepEqual(await scheduler.viewAccount(), [ 0, 0 ], "check balance");151 assert.deepEqual(await worker1.viewAccount(), [ 0, 0 ], "check balance");152 assert.deepEqual(await worker2.viewAccount(), [ 0, 0 ], "check balance");153 assert.deepEqual(await worker3.viewAccount(), [ 0, 0 ], "check balance");154 assert.deepEqual(await worker4.viewAccount(), [ 0, 0 ], "check balance");155 assert.deepEqual(await worker5.viewAccount(), [ 0, 0 ], "check balance");156 assert.deepEqual(await user.viewAccount(), [ 0, 0 ], "check balance");157 });158 it("deposit", async () => {159 switch (DEPLOYMENT.asset)160 {161 case "Native":162 txMined = await IexecInstance.deposit({ from: iexecAdmin.address, value: 10000000 * 10 ** 9 });163 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.from, constants.NULL.ADDRESS);164 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.to, iexecAdmin.address);165 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.value, 10000000);166 break;167 case "Token":168 txMined = await RLCInstance.approveAndCall(IexecInstance.address, 10000000, "0x", { from: iexecAdmin.address });169 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.owner, iexecAdmin.address);170 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.spender, IexecInstance.address);171 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.value, 10000000);172 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.from, iexecAdmin.address);173 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.to, IexecInstance.address);174 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.value, 10000000);175 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.from, constants.NULL.ADDRESS);176 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.to, iexecAdmin.address);177 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.value, 10000000);178 break;179 }180 txsMined = await Promise.all([181 IexecInstance.transfer(scheduler.address, 1000, { from: iexecAdmin.address }),182 IexecInstance.transfer(worker1.address, 1000, { from: iexecAdmin.address }),183 IexecInstance.transfer(worker2.address, 1000, { from: iexecAdmin.address }),184 IexecInstance.transfer(worker3.address, 1000, { from: iexecAdmin.address }),185 IexecInstance.transfer(worker4.address, 1000, { from: iexecAdmin.address }),186 IexecInstance.transfer(worker5.address, 1000, { from: iexecAdmin.address }),187 IexecInstance.transfer(user.address, 1000, { from: iexecAdmin.address }),188 ]);189 assert.equal(tools.extractEvents(txsMined[0], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);190 assert.equal(tools.extractEvents(txsMined[0], IexecInstance.address, "Transfer")[0].args.value, 1000);191 assert.equal(tools.extractEvents(txsMined[1], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);192 assert.equal(tools.extractEvents(txsMined[1], IexecInstance.address, "Transfer")[0].args.value, 1000);193 assert.equal(tools.extractEvents(txsMined[2], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);194 assert.equal(tools.extractEvents(txsMined[2], IexecInstance.address, "Transfer")[0].args.value, 1000);195 assert.equal(tools.extractEvents(txsMined[3], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);196 assert.equal(tools.extractEvents(txsMined[3], IexecInstance.address, "Transfer")[0].args.value, 1000);197 assert.equal(tools.extractEvents(txsMined[4], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);198 assert.equal(tools.extractEvents(txsMined[4], IexecInstance.address, "Transfer")[0].args.value, 1000);199 assert.equal(tools.extractEvents(txsMined[5], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);200 assert.equal(tools.extractEvents(txsMined[5], IexecInstance.address, "Transfer")[0].args.value, 1000);201 assert.equal(tools.extractEvents(txsMined[6], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);202 assert.equal(tools.extractEvents(txsMined[6], IexecInstance.address, "Transfer")[0].args.value, 1000);203 });204 it("balances after", async () => {205 assert.deepEqual(await appProvider.viewAccount(), [ 0, 0 ], "check balance");206 assert.deepEqual(await datasetProvider.viewAccount(), [ 0, 0 ], "check balance");207 assert.deepEqual(await scheduler.viewAccount(), [ 1000, 0 ], "check balance");208 assert.deepEqual(await worker1.viewAccount(), [ 1000, 0 ], "check balance");209 assert.deepEqual(await worker2.viewAccount(), [ 1000, 0 ], "check balance");210 assert.deepEqual(await worker3.viewAccount(), [ 1000, 0 ], "check balance");211 assert.deepEqual(await worker4.viewAccount(), [ 1000, 0 ], "check balance");212 assert.deepEqual(await worker5.viewAccount(), [ 1000, 0 ], "check balance");213 assert.deepEqual(await user.viewAccount(), [ 1000, 0 ], "check balance");214 });215 });216 it("score", async () => {217 assert.equal(await worker1.viewScore(), 0, "score issue");218 assert.equal(await worker2.viewScore(), 0, "score issue");219 assert.equal(await worker3.viewScore(), 0, "score issue");220 assert.equal(await worker4.viewScore(), 0, "score issue");221 assert.equal(await worker5.viewScore(), 0, "score issue");222 });223 });224 describe("→ pipeline", async () => {225 describe("[0] orders", async () => {226 describe("app", async () => {227 it("sign", async () => {228 apporder = await appProvider.signAppOrder({229 app: AppInstance.address,230 appprice: 3,231 volume: 1000,232 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",233 datasetrestrict: constants.NULL.ADDRESS,234 workerpoolrestrict: constants.NULL.ADDRESS,235 requesterrestrict: constants.NULL.ADDRESS,236 salt: web3.utils.randomHex(32),237 sign: constants.NULL.SIGNATURE,238 });239 });240 it("verify", async () => {241 assert.isTrue(await IexecInstance.verifySignature(242 appProvider.address,243 odbtools.utils.hashAppOrder(ERC712_domain, apporder),244 apporder.sign245 ));246 });247 });248 describe("dataset", async () => {249 it("sign", async () => {250 datasetorder = await datasetProvider.signDatasetOrder({251 dataset: DatasetInstance.address,252 datasetprice: 1,253 volume: 1000,254 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",255 apprestrict: constants.NULL.ADDRESS,256 workerpoolrestrict: constants.NULL.ADDRESS,257 requesterrestrict: constants.NULL.ADDRESS,258 salt: web3.utils.randomHex(32),259 sign: constants.NULL.SIGNATURE,260 });261 });262 it("verify", async () => {263 assert.isTrue(await IexecInstance.verifySignature(264 datasetProvider.address,265 odbtools.utils.hashDatasetOrder(ERC712_domain, datasetorder),266 datasetorder.sign267 ));268 });269 });270 describe("workerpool", async () => {271 it("sign", async () => {272 workerpoolorder = await scheduler.signWorkerpoolOrder({273 workerpool: WorkerpoolInstance.address,274 workerpoolprice: 25,275 volume: 3,276 category: 4,277 trust: trusttarget,278 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",279 apprestrict: constants.NULL.ADDRESS,280 datasetrestrict: constants.NULL.ADDRESS,281 requesterrestrict: constants.NULL.ADDRESS,282 salt: web3.utils.randomHex(32),283 sign: constants.NULL.SIGNATURE,284 });285 });286 it("verify", async () => {287 assert.isTrue(await IexecInstance.verifySignature(288 scheduler.address,289 odbtools.utils.hashWorkerpoolOrder(ERC712_domain, workerpoolorder),290 workerpoolorder.sign291 ));292 });293 });294 describe("request", async () => {295 it("sign", async () => {296 requestorder = await user.signRequestOrder({297 app: AppInstance.address,298 appmaxprice: 3,299 dataset: DatasetInstance.address,300 datasetmaxprice: 1,301 workerpool: constants.NULL.ADDRESS,302 workerpoolmaxprice: 25,303 volume: 1, // CHANGE FOR BOT304 category: 4,305 trust: trusttarget,306 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",307 requester: user.address,308 beneficiary: user.address,309 callback: constants.NULL.ADDRESS,310 params: "<parameters>",311 salt: web3.utils.randomHex(32),312 sign: constants.NULL.SIGNATURE,313 });314 });315 it("verify", async () => {316 assert.isTrue(await IexecInstance.verifySignature(317 user.address,318 odbtools.utils.hashRequestOrder(ERC712_domain, requestorder),319 requestorder.sign320 ));321 });322 });323 });324 describe("[1] order matching", async () => {325 it("[TX] match", async () => {326 txMined = await IexecInstance.matchOrders(apporder, datasetorder, workerpoolorder, requestorder, { from: user.address });327 gasReceipt.push([ "matchOrders", txMined.receipt.gasUsed ]);328 dealid = web3.utils.soliditySha3(329 { t: 'bytes32', v: odbtools.utils.hashRequestOrder(ERC712_domain, requestorder) },330 { t: 'uint256', v: 0 },331 );332 events = tools.extractEvents(txMined, IexecInstance.address, "SchedulerNotice");333 assert.equal(events[0].args.workerpool, WorkerpoolInstance.address);334 assert.equal(events[0].args.dealid, dealid );335 events = tools.extractEvents(txMined, IexecInstance.address, "OrdersMatched");336 assert.equal(events[0].args.dealid, dealid );337 assert.equal(events[0].args.appHash, odbtools.utils.hashAppOrder (ERC712_domain, apporder ));338 assert.equal(events[0].args.datasetHash, odbtools.utils.hashDatasetOrder (ERC712_domain, datasetorder ));339 assert.equal(events[0].args.workerpoolHash, odbtools.utils.hashWorkerpoolOrder(ERC712_domain, workerpoolorder));340 assert.equal(events[0].args.requestHash, odbtools.utils.hashRequestOrder (ERC712_domain, requestorder ));341 assert.equal(events[0].args.volume, 1 );342 });343 });344 describe("[2] initialization", async () => {345 it("[TX] initialize", async () => {346 txMined = await IexecInstance.initialize(dealid, 0, { from: scheduler.address });347 gasReceipt.push([ "initialize", txMined.receipt.gasUsed ]);348 taskid = web3.utils.soliditySha3({ t: 'bytes32', v: dealid }, { t: 'uint256', v: 0 });349 events = tools.extractEvents(txMined, IexecInstance.address, "TaskInitialize");350 assert.equal(events[0].args.taskid, taskid );351 assert.equal(events[0].args.workerpool, WorkerpoolInstance.address);352 });353 });354 describe("[3] contributeAndFinalize", async () => {355 it("authorization signature", async () => {356 const preauth = await scheduler.signPreAuthorization(taskid, worker.agent.address);357 [ authorization, secret ] = worker.useenclave ? await broker.signAuthorization(preauth) : [ preauth, null ];358 });359 it("run", async () => {360 consensus = odbtools.utils.hashConsensus(taskid, consensus);361 result = await worker.agent.run(authorization, secret, worker.result);362 });363 it("[TX] contributeAndFinalize", async () => {364 txMined = await IexecInstance.contributeAndFinalize(365 authorization.taskid, // task (authorization)366 result.digest, // digest (result)367 web3.utils.utf8ToHex("aResult"), // data (result)368 "0x", // data (callback)369 authorization.enclave, // address (enclave)370 result.sign, // signature (enclave)371 authorization.sign, // signature (authorization)372 { from: worker.agent.address }373 );374 gasReceipt.push([ "contributeAndFinalize", txMined.receipt.gasUsed ]);375 events = tools.extractEvents(txMined, IexecInstance.address, "TaskContribute");376 assert.equal(events[0].args.taskid, authorization.taskid);377 assert.equal(events[0].args.worker, worker.agent.address);378 assert.equal(events[0].args.hash, result.hash );379 events = tools.extractEvents(txMined, IexecInstance.address, "TaskConsensus");380 assert.equal(events[0].args.taskid, taskid );381 assert.equal(events[0].args.consensus, consensus.hash);382 events = tools.extractEvents(txMined, IexecInstance.address, "TaskReveal");383 assert.equal(events[0].args.taskid, taskid );384 assert.equal(events[0].args.worker, worker.agent.address);385 assert.equal(events[0].args.digest, result.digest );386 events = tools.extractEvents(txMined, IexecInstance.address, "TaskFinalize");387 assert.equal(events[0].args.taskid, taskid );388 assert.equal(events[0].args.results, web3.utils.utf8ToHex("aResult"));389 });390 });391 });392 describe("→ summary", async () => {393 it("task", async () => {394 task = await IexecInstance.viewTask(taskid);395 assert.equal ( task.status, constants.TaskStatusEnum.COMPLETED );396 assert.equal ( task.dealid, dealid );397 assert.equal (Number(task.idx), 0 );398 assert.equal (Number(task.timeref), (await IexecInstance.viewCategory(requestorder.category)).workClockTimeRef);399 assert.isAbove (Number(task.contributionDeadline), 0 );400 assert.isAbove (Number(task.revealDeadline), 0 );...

Full Screen

Full Screen

resultFor.js

Source:resultFor.js Github

copy

Full Screen

...96 constants.NULL.BYTES32,97 "0x",98 { from: appProvider.address }99 );100 events = tools.extractEvents(txMined, AppRegistryInstance.address, "Transfer");101 AppInstance = await App.at(tools.BN2Address(events[0].args.tokenId));102 });103 });104 describe("dataset", async () => {105 it("create", async () => {106 txMined = await DatasetRegistryInstance.createDataset(107 datasetProvider.address,108 "Pi",109 constants.MULTIADDR_BYTES,110 constants.NULL.BYTES32,111 { from: datasetProvider.address }112 );113 events = tools.extractEvents(txMined, DatasetRegistryInstance.address, "Transfer");114 DatasetInstance = await Dataset.at(tools.BN2Address(events[0].args.tokenId));115 });116 });117 describe("workerpool", async () => {118 it("create", async () => {119 txMined = await WorkerpoolRegistryInstance.createWorkerpool(120 scheduler.address,121 "A test workerpool",122 { from: scheduler.address }123 );124 events = tools.extractEvents(txMined, WorkerpoolRegistryInstance.address, "Transfer");125 WorkerpoolInstance = await Workerpool.at(tools.BN2Address(events[0].args.tokenId));126 });127 it("change policy", async () => {128 await WorkerpoolInstance.changePolicy(/* worker stake ratio */ 35, /* scheduler reward ratio */ 5, { from: scheduler.address });129 });130 });131 });132 describe("tokens", async () => {133 it("balances before", async () => {134 assert.deepEqual(await appProvider.viewAccount(), [ 0, 0 ], "check balance");135 assert.deepEqual(await datasetProvider.viewAccount(), [ 0, 0 ], "check balance");136 assert.deepEqual(await scheduler.viewAccount(), [ 0, 0 ], "check balance");137 assert.deepEqual(await worker1.viewAccount(), [ 0, 0 ], "check balance");138 assert.deepEqual(await worker2.viewAccount(), [ 0, 0 ], "check balance");139 assert.deepEqual(await worker3.viewAccount(), [ 0, 0 ], "check balance");140 assert.deepEqual(await worker4.viewAccount(), [ 0, 0 ], "check balance");141 assert.deepEqual(await worker5.viewAccount(), [ 0, 0 ], "check balance");142 assert.deepEqual(await user.viewAccount(), [ 0, 0 ], "check balance");143 });144 it("deposit", async () => {145 switch (DEPLOYMENT.asset)146 {147 case "Native":148 txMined = await IexecInstance.deposit({ from: iexecAdmin.address, value: 10000000 * 10 ** 9 });149 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.from, constants.NULL.ADDRESS);150 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.to, iexecAdmin.address);151 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.value, 10000000);152 break;153 case "Token":154 txMined = await RLCInstance.approveAndCall(IexecInstance.address, 10000000, "0x", { from: iexecAdmin.address });155 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.owner, iexecAdmin.address);156 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.spender, IexecInstance.address);157 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Approval")[0].args.value, 10000000);158 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.from, iexecAdmin.address);159 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.to, IexecInstance.address);160 assert.equal(tools.extractEvents(txMined, RLCInstance.address, "Transfer")[0].args.value, 10000000);161 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.from, constants.NULL.ADDRESS);162 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.to, iexecAdmin.address);163 assert.equal(tools.extractEvents(txMined, IexecInstance.address, "Transfer")[0].args.value, 10000000);164 break;165 }166 txsMined = await Promise.all([167 IexecInstance.transfer(scheduler.address, 1000, { from: iexecAdmin.address }),168 IexecInstance.transfer(worker1.address, 1000, { from: iexecAdmin.address }),169 IexecInstance.transfer(worker2.address, 1000, { from: iexecAdmin.address }),170 IexecInstance.transfer(worker3.address, 1000, { from: iexecAdmin.address }),171 IexecInstance.transfer(worker4.address, 1000, { from: iexecAdmin.address }),172 IexecInstance.transfer(worker5.address, 1000, { from: iexecAdmin.address }),173 IexecInstance.transfer(user.address, 1000, { from: iexecAdmin.address }),174 ]);175 assert.equal(tools.extractEvents(txsMined[0], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);176 assert.equal(tools.extractEvents(txsMined[0], IexecInstance.address, "Transfer")[0].args.value, 1000);177 assert.equal(tools.extractEvents(txsMined[1], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);178 assert.equal(tools.extractEvents(txsMined[1], IexecInstance.address, "Transfer")[0].args.value, 1000);179 assert.equal(tools.extractEvents(txsMined[2], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);180 assert.equal(tools.extractEvents(txsMined[2], IexecInstance.address, "Transfer")[0].args.value, 1000);181 assert.equal(tools.extractEvents(txsMined[3], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);182 assert.equal(tools.extractEvents(txsMined[3], IexecInstance.address, "Transfer")[0].args.value, 1000);183 assert.equal(tools.extractEvents(txsMined[4], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);184 assert.equal(tools.extractEvents(txsMined[4], IexecInstance.address, "Transfer")[0].args.value, 1000);185 assert.equal(tools.extractEvents(txsMined[5], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);186 assert.equal(tools.extractEvents(txsMined[5], IexecInstance.address, "Transfer")[0].args.value, 1000);187 assert.equal(tools.extractEvents(txsMined[6], IexecInstance.address, "Transfer")[0].args.from, iexecAdmin.address);188 assert.equal(tools.extractEvents(txsMined[6], IexecInstance.address, "Transfer")[0].args.value, 1000);189 });190 it("balances after", async () => {191 assert.deepEqual(await appProvider.viewAccount(), [ 0, 0 ], "check balance");192 assert.deepEqual(await datasetProvider.viewAccount(), [ 0, 0 ], "check balance");193 assert.deepEqual(await scheduler.viewAccount(), [ 1000, 0 ], "check balance");194 assert.deepEqual(await worker1.viewAccount(), [ 1000, 0 ], "check balance");195 assert.deepEqual(await worker2.viewAccount(), [ 1000, 0 ], "check balance");196 assert.deepEqual(await worker3.viewAccount(), [ 1000, 0 ], "check balance");197 assert.deepEqual(await worker4.viewAccount(), [ 1000, 0 ], "check balance");198 assert.deepEqual(await worker5.viewAccount(), [ 1000, 0 ], "check balance");199 assert.deepEqual(await user.viewAccount(), [ 1000, 0 ], "check balance");200 });201 });202 it("score", async () => {203 assert.equal(await worker1.viewScore(), 0, "score issue");204 assert.equal(await worker2.viewScore(), 0, "score issue");205 assert.equal(await worker3.viewScore(), 0, "score issue");206 assert.equal(await worker4.viewScore(), 0, "score issue");207 assert.equal(await worker5.viewScore(), 0, "score issue");208 });209 });210 describe("→ pipeline", async () => {211 describe("[0] orders", async () => {212 describe("app", async () => {213 it("sign", async () => {214 apporder = await appProvider.signAppOrder({215 app: AppInstance.address,216 appprice: 3,217 volume: 1000,218 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",219 datasetrestrict: constants.NULL.ADDRESS,220 workerpoolrestrict: constants.NULL.ADDRESS,221 requesterrestrict: constants.NULL.ADDRESS,222 salt: web3.utils.randomHex(32),223 sign: constants.NULL.SIGNATURE,224 });225 });226 it("verify", async () => {227 assert.isTrue(await IexecInstance.verifySignature(228 appProvider.address,229 odbtools.utils.hashAppOrder(ERC712_domain, apporder),230 apporder.sign231 ));232 });233 });234 describe("dataset", async () => {235 it("sign", async () => {236 datasetorder = await datasetProvider.signDatasetOrder({237 dataset: DatasetInstance.address,238 datasetprice: 0,239 volume: 1000,240 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",241 apprestrict: constants.NULL.ADDRESS,242 workerpoolrestrict: constants.NULL.ADDRESS,243 requesterrestrict: constants.NULL.ADDRESS,244 salt: web3.utils.randomHex(32),245 sign: constants.NULL.SIGNATURE,246 });247 });248 it("verify", async () => {249 assert.isTrue(await IexecInstance.verifySignature(250 datasetProvider.address,251 odbtools.utils.hashDatasetOrder(ERC712_domain, datasetorder),252 datasetorder.sign253 ));254 });255 });256 describe("workerpool", async () => {257 it("sign", async () => {258 workerpoolorder = await scheduler.signWorkerpoolOrder({259 workerpool: WorkerpoolInstance.address,260 workerpoolprice: 25,261 volume: 1000,262 category: 4,263 trust: 0,264 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",265 apprestrict: constants.NULL.ADDRESS,266 datasetrestrict: constants.NULL.ADDRESS,267 requesterrestrict: constants.NULL.ADDRESS,268 salt: web3.utils.randomHex(32),269 sign: constants.NULL.SIGNATURE,270 });271 });272 it("verify", async () => {273 assert.isTrue(await IexecInstance.verifySignature(274 scheduler.address,275 odbtools.utils.hashWorkerpoolOrder(ERC712_domain, workerpoolorder),276 workerpoolorder.sign277 ));278 });279 });280 describe("request", async () => {281 it("sign", async () => {282 requestorder = await user.signRequestOrder({283 app: AppInstance.address,284 appmaxprice: 3,285 dataset: DatasetInstance.address,286 datasetmaxprice: 0,287 workerpool: constants.NULL.ADDRESS,288 workerpoolmaxprice: 25,289 volume: 10,290 tag: "0x0000000000000000000000000000000000000000000000000000000000000000",291 category: 4,292 trust: 0,293 requester: user.address,294 beneficiary: user.address,295 callback: constants.NULL.ADDRESS,296 params: "<parameters>",297 salt: web3.utils.randomHex(32),298 sign: constants.NULL.SIGNATURE,299 });300 });301 it("verify", async () => {302 assert.isTrue(await IexecInstance.verifySignature(303 user.address,304 odbtools.utils.hashRequestOrder(ERC712_domain, requestorder),305 requestorder.sign306 ));307 });308 });309 });310 describe("[1] order matching", async () => {311 it("[TX] match", async () => {312 await IexecInstance.matchOrders(apporder, datasetorder, workerpoolorder, requestorder, { from: user.address });313 deals = await odbtools.utils.requestToDeal(IexecInstance, odbtools.utils.hashRequestOrder(ERC712_domain, requestorder));314 });315 });316 describe("[2] initialization", async () => {317 it("[TX] initialize", async () => {318 tasks[0] = web3.utils.soliditySha3({ t: 'bytes32', v: deals[0] }, { t: 'uint256', v: 0 }); // uninitialized319 tasks[1] = tools.extractEvents(await IexecInstance.initialize(deals[0], 1, { from: scheduler.address }), IexecInstance.address, "TaskInitialize")[0].args.taskid; // finalized320 tasks[2] = tools.extractEvents(await IexecInstance.initialize(deals[0], 2, { from: scheduler.address }), IexecInstance.address, "TaskInitialize")[0].args.taskid; // initialized321 tasks[3] = tools.extractEvents(await IexecInstance.initialize(deals[0], 3, { from: scheduler.address }), IexecInstance.address, "TaskInitialize")[0].args.taskid; // contributions322 tasks[4] = tools.extractEvents(await IexecInstance.initialize(deals[0], 4, { from: scheduler.address }), IexecInstance.address, "TaskInitialize")[0].args.taskid; // consensus323 tasks[5] = tools.extractEvents(await IexecInstance.initialize(deals[0], 5, { from: scheduler.address }), IexecInstance.address, "TaskInitialize")[0].args.taskid; // reveal324 });325 });326 async function sendContribution(worker, taskid, result, useenclave = true, callback)327 {328 const preauth = await scheduler.signPreAuthorization(taskid, worker.address);329 const [ auth, secret ] = useenclave ? await broker.signAuthorization(preauth) : [ preauth, null ];330 const results = await worker.run(auth, secret, result, callback);331 return IexecInstance.contribute(332 auth.taskid, // task (authorization)333 results.hash, // common (result)334 results.seal, // unique (result)335 auth.enclave, // address (enclave)336 results.sign, // signature (enclave)337 auth.sign, // signature (authorization)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { extractEvents } = require('playwright-core/lib/server/trace/recorder');2const { chromium } = require('playwright-core');3const fs = require('fs');4(async () => {5 const browser = await chromium.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 const trace = await page.context().tracing.stop({ screenshots: true, snapshots: true });9 const events = extractEvents(trace);10 fs.writeFileSync('trace.json', JSON.stringify(events, null, 2));11 await browser.close();12})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { extractEvents } = require('@playwright/test/lib/trace/recorder/events');2const fs = require('fs');3const path = require('path');4(async () => {5 const events = await extractEvents(path.join(__dirname, 'trace.zip'));6 fs.writeFileSync(path.join(__dirname, 'trace.json'), JSON.stringify(events));7})();8const { extractEvents } = require('@playwright/test/lib/trace/recorder/events');9const fs = require('fs');10const path = require('path');11(async () => {12 const events = await extractEvents(path.join(__dirname, 'trace.zip'));13 fs.writeFileSync(path.join(__dirname, 'trace.json'), JSON.stringify(events));14})();15const { extractEvents } = require('@playwright/test/lib/trace/recorder/events');16const fs = require('fs');17const path = require('path');18(async () => {19 const events = await extractEvents(path.join(__dirname, 'trace.zip'));20 fs.writeFileSync(path.join(__dirname, 'trace.json'), JSON.stringify(events));21})();22const { extractEvents } = require('@playwright/test/lib/trace/recorder/events');23const fs = require('fs');24const path = require('path');25(async () => {26 const events = await extractEvents(path.join(__dirname, 'trace.zip'));27 fs.writeFileSync(path.join(__dirname, 'trace.json'), JSON.stringify(events));28})();29const { extractEvents } = require('@playwright/test/lib/trace/recorder/events');30const fs = require('fs');31const path = require('path');32(async () => {33 const events = await extractEvents(path.join(__dirname, 'trace.zip'));34 fs.writeFileSync(path.join(__dirname, 'trace.json'), JSON.stringify(events));35})();36const { extractEvents } = require('@playwright/test/lib/trace/recorder/events');37const fs = require('fs');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { extractEvents } = require('playwright/lib/trace/viewer/traceModel');2const fs = require('fs');3const path = require('path');4const tracePath = path.join(__dirname, 'trace.zip');5const traceContent = fs.readFileSync(tracePath);6const events = extractEvents(traceContent);7console.log(events);8 {9 args: {10 data: {11 }12 }13 },14 {15 args: {16 data: {17 }18 }19 },20 {21 args: {22 data: {23 }24 }25 },26 {27 args: {28 data: {29 }30 }31 },32 {33 args: {34 data: {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { extractEvents } = require('playwright/lib/server/trace/recorder/recorderApp');2const fs = require('fs');3const path = require('path');4const events = extractEvents(fs.readFileSync(path.join(__dirname, 'trace.json'), 'utf8'));5console.log(events);6 {7 viewportSize: { width: 1280, height: 720 },8 },9 {10 viewportSize: { width: 1280, height: 720 },11 },12 {13 },14 {15 },16 {17 },18 {19 },20 {21 },22 {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { extractEvents } = require('playwright-core/lib/server/trace/recorder');2const fs = require('fs');3const path = require('path');4const { chromium } = require('playwright-core');5async function main() {6 const browser = await chromium.launch({7 });8 const page = await browser.newPage();9 await page.close();10 await browser.close();11 const trace = await extractEvents('trace.zip');12 fs.writeFileSync(path.join(__dirname, 'trace.json'), JSON.stringify(trace, null, 2));13}14main();15{16 {17 "args": {18 "data": {19 {20 }21 }22 },23 },24 {25 "args": {26 "data": {27 }28 },29 },30 {31 "args": {32 "data": {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { extractEvents } = require('playwright/lib/server/trace/recorder/screencastFrameCollector');2const fs = require('fs');3const path = require('path');4const tracePath = path.join(__dirname, 'trace.json');5const trace = JSON.parse(fs.readFileSync(tracePath, 'utf8'));6const events = extractEvents(trace);7console.log(events);8{9 {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { extractEvents } = require("@playwright/test/lib/server/trace/recorder/snapshotter");2const { chromium } = require("playwright");3const fs = require("fs");4const run = async () => {5 const browser = await chromium.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 const snapshot = await page._delegate._mainFrame._contextSnapshotter._snapshotter._snapshotter.takeSnapshot();9 const events = extractEvents(snapshot);10 fs.writeFileSync("events.json", JSON.stringify(events, null, 2));11 await browser.close();12};13run();14{15 {16 "snapshot": {17 {18 "contentType": "text/html; charset=ISO-8859-1",

Full Screen

Using AI Code Generation

copy

Full Screen

1const extractEvents = require('playwright/lib/trace/snapshotter').extractEvents;2const snapshotter = new Snapshotter(page, {3});4const events = await snapshotter.extractEvents();5console.log(events);6const snapshotter = new Snapshotter(page, {7});8const events = await snapshotter.extractEvents();9console.log(events);10const snapshotter = new Snapshotter(page, {11});12const events = await snapshotter.extractEvents();13console.log(events);14const snapshotter = new Snapshotter(page, {15});16const events = await snapshotter.extractEvents();17console.log(events);18const snapshotter = new Snapshotter(page, {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { extractEvents } = require('playwright-core/lib/server/trace/recorder');2const trace = require('./trace.json');3const events = extractEvents(trace);4console.log(events);5 {6 metadata: { frameId: '0x1' }7 },8 {9 metadata: {10 }11 },12 {13 metadata: {14 }15 },16 {17 metadata: {18 }19 },20 {21 metadata: {22 }23 },24 {25 metadata: {26 }27 },28 {29 metadata: {30 }31 },32 {33 metadata: {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { extractEvents } = require('@playwright/test/lib/server/trace/recorder/recorderApp');2const events = extractEvents('trace.zip');3console.log(events);4const { extractEvents } = require('@playwright/test/lib/server/trace/recorder/recorderApp');5const events = extractEvents('trace.zip');6const fs = require('fs');7fs.writeFileSync('events.json', JSON.stringify(events, null, 2));8import { test, expect } from '@playwright/test';9import { extractEvents } from '@playwright/test/lib/server/trace/recorder/recorderApp';10test('My test', async ({ page }) => {11 const events = extractEvents('trace.zip');12 await page.tracing.start({ screenshots: true, snapshots: true });13 await page.tracing.stop({ path: 'trace.zip' });14 const events2 = extractEvents('trace.zip');15 expect(events2).toEqual(events);16});17import { test, expect } from '@playwright/test';18import { extractEvents } from '@playwright/test/lib/server/trace/recorder/recorderApp';19test.beforeAll(async ({ page }) => {20 await page.tracing.start({ screenshots: true, snapshots: true });21});22test.afterAll(async ({ page }) => {23 await page.tracing.stop({ path: 'trace.zip' });24 const events = extractEvents('trace.zip');25 console.log(events);26});

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful