From 49361fd1a34425843734a74b60f66649e74317f6 Mon Sep 17 00:00:00 2001 From: Zied <26070035+zguesmi@users.noreply.github.com> Date: Wed, 8 Jan 2025 17:52:19 +0100 Subject: [PATCH 1/5] Delete migrated file 400_contributeAndCallback.js --- CHANGELOG.md | 2 +- test/400_contributeAndCallback.js | 692 ------------------------------ 2 files changed, 1 insertion(+), 693 deletions(-) delete mode 100644 test/400_contributeAndCallback.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 26fc0175..a2daa8df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ - Fix balance checks in integration tests (#165) - 300_fullchain-reopen.js (#170, #173) - 000_fullchain-ABILegacy.js (#174, #175) - - 400_contributeAndCallback.js (#176) + - 400_contributeAndCallback.js (#176, #177) - Remove `smock` from unit tests: - IexecEscrow.v8 (#154, #155) - IexecPocoDelegate (#149, #151) diff --git a/test/400_contributeAndCallback.js b/test/400_contributeAndCallback.js deleted file mode 100644 index b1c00c8a..00000000 --- a/test/400_contributeAndCallback.js +++ /dev/null @@ -1,692 +0,0 @@ -// SPDX-FileCopyrightText: 2020-2024 IEXEC BLOCKCHAIN TECH -// SPDX-License-Identifier: Apache-2.0 - -const loadTruffleFixtureDeployment = require('../scripts/truffle-fixture-deployer'); -// Config -var DEPLOYMENT = require('../config/config.json').chains.default; -// Artefacts -var RLC = artifacts.require('rlc-faucet-contract/contracts/RLC'); -var ERC1538Proxy = artifacts.require('iexec-solidity/ERC1538Proxy'); -var IexecInterface = artifacts.require(`IexecInterface${DEPLOYMENT.asset}`); -var AppRegistry = artifacts.require('AppRegistry'); -var DatasetRegistry = artifacts.require('DatasetRegistry'); -var WorkerpoolRegistry = artifacts.require('WorkerpoolRegistry'); -var App = artifacts.require('App'); -var Dataset = artifacts.require('Dataset'); -var Workerpool = artifacts.require('Workerpool'); - -const { BN, expectEvent, expectRevert } = require('@openzeppelin/test-helpers'); -const tools = require('../utils/tools'); -const enstools = require('../utils/ens-tools'); -const odbtools = require('../utils/odb-tools'); -const constants = require('../utils/constants'); - -Object.extract = (obj, keys) => keys.map((key) => obj[key]); - -contract('Fullchain', async (accounts) => { - assert.isAtLeast(accounts.length, 10, 'should have at least 10 accounts'); - let iexecAdmin = null; - let appProvider = null; - let datasetProvider = null; - let scheduler = null; - let worker1 = null; - let worker2 = null; - let worker3 = null; - let worker4 = null; - let worker5 = null; - let user = null; - - var RLCInstance = null; - var IexecInstance = null; - var AppRegistryInstance = null; - var DatasetRegistryInstance = null; - var WorkerpoolRegistryInstance = null; - - var AppInstance = null; - var DatasetInstance = null; - var WorkerpoolInstance = null; - - var apporder = null; - var datasetorder = null; - var workerpoolorder = null; - var requestorder = null; - var dealid = null; - var taskid = null; - - var authorization = {}; - var secret = {}; - var result = {}; - var consensus = null; - var worker = []; - var resultsCallback = null; - - var gasReceipt = []; - - /*************************************************************************** - * Environment configuration * - ***************************************************************************/ - before('configure', async () => { - await loadTruffleFixtureDeployment(); - console.log('# web3 version:', web3.version); - - /** - * Retreive deployed contracts - */ - IexecInstance = await IexecInterface.at((await ERC1538Proxy.deployed()).address); - AppRegistryInstance = await AppRegistry.deployed(); - DatasetRegistryInstance = await DatasetRegistry.deployed(); - WorkerpoolRegistryInstance = await WorkerpoolRegistry.deployed(); - ERC712_domain = await IexecInstance.domain(); - RLCInstance = - DEPLOYMENT.asset == 'Native' - ? { address: constants.NULL.ADDRESS } - : await RLC.at(await IexecInstance.token()); - - broker = new odbtools.Broker(IexecInstance); - iexecAdmin = new odbtools.iExecAgent(IexecInstance, accounts[0]); - appProvider = new odbtools.iExecAgent(IexecInstance, accounts[1]); - datasetProvider = new odbtools.iExecAgent(IexecInstance, accounts[2]); - scheduler = new odbtools.Scheduler(IexecInstance, accounts[3]); - worker1 = new odbtools.Worker(IexecInstance, accounts[4]); - worker2 = new odbtools.Worker(IexecInstance, accounts[5]); - worker3 = new odbtools.Worker(IexecInstance, accounts[6]); - worker4 = new odbtools.Worker(IexecInstance, accounts[7]); - worker5 = new odbtools.Worker(IexecInstance, accounts[8]); - user = new odbtools.iExecAgent(IexecInstance, accounts[9]); - await broker.initialize(); - - trusttarget = 0; - worker = { agent: worker1, useenclave: true, result: 'iExec the wanderer' }; - consensus = 'iExec the wanderer'; - resultsCallback = web3.utils.utf8ToHex('iExec the wanderer'); - }); - - describe('→ setup', async () => { - describe('assets', async () => { - describe('app', async () => { - it('create', async () => { - txMined = await AppRegistryInstance.createApp( - appProvider.address, - 'R Clifford Attractors', - 'DOCKER', - constants.MULTIADDR_BYTES, - constants.NULL.BYTES32, - '0x', - { from: appProvider.address }, - ); - events = tools.extractEvents(txMined, AppRegistryInstance.address, 'Transfer'); - AppInstance = await App.at(tools.BN2Address(events[0].args.tokenId)); - }); - }); - - describe('dataset', async () => { - it('create', async () => { - txMined = await DatasetRegistryInstance.createDataset( - datasetProvider.address, - 'Pi', - constants.MULTIADDR_BYTES, - constants.NULL.BYTES32, - { from: datasetProvider.address }, - ); - events = tools.extractEvents( - txMined, - DatasetRegistryInstance.address, - 'Transfer', - ); - DatasetInstance = await Dataset.at(tools.BN2Address(events[0].args.tokenId)); - }); - }); - - describe('workerpool', async () => { - it('create', async () => { - txMined = await WorkerpoolRegistryInstance.createWorkerpool( - scheduler.address, - 'A test workerpool', - { from: scheduler.address }, - ); - events = tools.extractEvents( - txMined, - WorkerpoolRegistryInstance.address, - 'Transfer', - ); - WorkerpoolInstance = await Workerpool.at( - tools.BN2Address(events[0].args.tokenId), - ); - }); - - it('change policy', async () => { - txMined = await WorkerpoolInstance.changePolicy( - /* worker stake ratio */ 35, - /* scheduler reward ratio */ 5, - { from: scheduler.address }, - ); - events = tools.extractEvents( - txMined, - WorkerpoolInstance.address, - 'PolicyUpdate', - ); - assert.equal(events[0].args.oldWorkerStakeRatioPolicy, 30); - assert.equal(events[0].args.newWorkerStakeRatioPolicy, 35); - assert.equal(events[0].args.oldSchedulerRewardRatioPolicy, 1); - assert.equal(events[0].args.newSchedulerRewardRatioPolicy, 5); - }); - }); - }); - - describe('tokens', async () => { - it('balances before', async () => { - assert.deepEqual(await appProvider.viewAccount(), [0, 0], 'check balance'); - assert.deepEqual(await datasetProvider.viewAccount(), [0, 0], 'check balance'); - assert.deepEqual(await scheduler.viewAccount(), [0, 0], 'check balance'); - assert.deepEqual(await worker1.viewAccount(), [0, 0], 'check balance'); - assert.deepEqual(await worker2.viewAccount(), [0, 0], 'check balance'); - assert.deepEqual(await worker3.viewAccount(), [0, 0], 'check balance'); - assert.deepEqual(await worker4.viewAccount(), [0, 0], 'check balance'); - assert.deepEqual(await worker5.viewAccount(), [0, 0], 'check balance'); - assert.deepEqual(await user.viewAccount(), [0, 0], 'check balance'); - }); - - it('deposit', async () => { - switch (DEPLOYMENT.asset) { - case 'Native': - txMined = await IexecInstance.deposit({ - from: iexecAdmin.address, - value: 10000000 * 10 ** 9, - }); - assert.equal( - tools.extractEvents(txMined, IexecInstance.address, 'Transfer')[0].args - .from, - constants.NULL.ADDRESS, - ); - assert.equal( - tools.extractEvents(txMined, IexecInstance.address, 'Transfer')[0].args - .to, - iexecAdmin.address, - ); - assert.equal( - tools.extractEvents(txMined, IexecInstance.address, 'Transfer')[0].args - .value, - 10000000, - ); - break; - - case 'Token': - txMined = await RLCInstance.approveAndCall( - IexecInstance.address, - 10000000, - '0x', - { from: iexecAdmin.address }, - ); - assert.equal( - tools.extractEvents(txMined, RLCInstance.address, 'Approval')[0].args - .owner, - iexecAdmin.address, - ); - assert.equal( - tools.extractEvents(txMined, RLCInstance.address, 'Approval')[0].args - .spender, - IexecInstance.address, - ); - assert.equal( - tools.extractEvents(txMined, RLCInstance.address, 'Approval')[0].args - .value, - 10000000, - ); - assert.equal( - tools.extractEvents(txMined, RLCInstance.address, 'Transfer')[0].args - .from, - iexecAdmin.address, - ); - assert.equal( - tools.extractEvents(txMined, RLCInstance.address, 'Transfer')[0].args - .to, - IexecInstance.address, - ); - assert.equal( - tools.extractEvents(txMined, RLCInstance.address, 'Transfer')[0].args - .value, - 10000000, - ); - assert.equal( - tools.extractEvents(txMined, IexecInstance.address, 'Transfer')[0].args - .from, - constants.NULL.ADDRESS, - ); - assert.equal( - tools.extractEvents(txMined, IexecInstance.address, 'Transfer')[0].args - .to, - iexecAdmin.address, - ); - assert.equal( - tools.extractEvents(txMined, IexecInstance.address, 'Transfer')[0].args - .value, - 10000000, - ); - break; - } - - const txsMined = [ - await IexecInstance.transfer(scheduler.address, 1000, { - from: iexecAdmin.address, - }), - await IexecInstance.transfer(worker1.address, 1000, { - from: iexecAdmin.address, - }), - await IexecInstance.transfer(worker2.address, 1000, { - from: iexecAdmin.address, - }), - await IexecInstance.transfer(worker3.address, 1000, { - from: iexecAdmin.address, - }), - await IexecInstance.transfer(worker4.address, 1000, { - from: iexecAdmin.address, - }), - await IexecInstance.transfer(worker5.address, 1000, { - from: iexecAdmin.address, - }), - await IexecInstance.transfer(user.address, 1000, { from: iexecAdmin.address }), - ]; - - assert.equal( - tools.extractEvents(txsMined[0], IexecInstance.address, 'Transfer')[0].args - .from, - iexecAdmin.address, - ); - assert.equal( - tools.extractEvents(txsMined[0], IexecInstance.address, 'Transfer')[0].args - .value, - 1000, - ); - assert.equal( - tools.extractEvents(txsMined[1], IexecInstance.address, 'Transfer')[0].args - .from, - iexecAdmin.address, - ); - assert.equal( - tools.extractEvents(txsMined[1], IexecInstance.address, 'Transfer')[0].args - .value, - 1000, - ); - assert.equal( - tools.extractEvents(txsMined[2], IexecInstance.address, 'Transfer')[0].args - .from, - iexecAdmin.address, - ); - assert.equal( - tools.extractEvents(txsMined[2], IexecInstance.address, 'Transfer')[0].args - .value, - 1000, - ); - assert.equal( - tools.extractEvents(txsMined[3], IexecInstance.address, 'Transfer')[0].args - .from, - iexecAdmin.address, - ); - assert.equal( - tools.extractEvents(txsMined[3], IexecInstance.address, 'Transfer')[0].args - .value, - 1000, - ); - assert.equal( - tools.extractEvents(txsMined[4], IexecInstance.address, 'Transfer')[0].args - .from, - iexecAdmin.address, - ); - assert.equal( - tools.extractEvents(txsMined[4], IexecInstance.address, 'Transfer')[0].args - .value, - 1000, - ); - assert.equal( - tools.extractEvents(txsMined[5], IexecInstance.address, 'Transfer')[0].args - .from, - iexecAdmin.address, - ); - assert.equal( - tools.extractEvents(txsMined[5], IexecInstance.address, 'Transfer')[0].args - .value, - 1000, - ); - assert.equal( - tools.extractEvents(txsMined[6], IexecInstance.address, 'Transfer')[0].args - .from, - iexecAdmin.address, - ); - assert.equal( - tools.extractEvents(txsMined[6], IexecInstance.address, 'Transfer')[0].args - .value, - 1000, - ); - }); - - it('balances after', async () => { - assert.deepEqual(await appProvider.viewAccount(), [0, 0], 'check balance'); - assert.deepEqual(await datasetProvider.viewAccount(), [0, 0], 'check balance'); - assert.deepEqual(await scheduler.viewAccount(), [1000, 0], 'check balance'); - assert.deepEqual(await worker1.viewAccount(), [1000, 0], 'check balance'); - assert.deepEqual(await worker2.viewAccount(), [1000, 0], 'check balance'); - assert.deepEqual(await worker3.viewAccount(), [1000, 0], 'check balance'); - assert.deepEqual(await worker4.viewAccount(), [1000, 0], 'check balance'); - assert.deepEqual(await worker5.viewAccount(), [1000, 0], 'check balance'); - assert.deepEqual(await user.viewAccount(), [1000, 0], 'check balance'); - }); - }); - - it('score', async () => { - assert.equal(await worker1.viewScore(), 0, 'score issue'); - assert.equal(await worker2.viewScore(), 0, 'score issue'); - assert.equal(await worker3.viewScore(), 0, 'score issue'); - assert.equal(await worker4.viewScore(), 0, 'score issue'); - assert.equal(await worker5.viewScore(), 0, 'score issue'); - }); - }); - - describe('→ pipeline', async () => { - describe('[0] orders', async () => { - describe('app', async () => { - it('sign', async () => { - apporder = await appProvider.signAppOrder({ - app: AppInstance.address, - appprice: 3, - volume: 1000, - tag: '0x0000000000000000000000000000000000000000000000000000000000000000', - datasetrestrict: constants.NULL.ADDRESS, - workerpoolrestrict: constants.NULL.ADDRESS, - requesterrestrict: constants.NULL.ADDRESS, - salt: web3.utils.randomHex(32), - sign: constants.NULL.SIGNATURE, - }); - }); - - it('verify', async () => { - assert.isTrue( - await IexecInstance.verifySignature( - appProvider.address, - odbtools.utils.hashAppOrder(ERC712_domain, apporder), - apporder.sign, - ), - ); - }); - }); - - describe('dataset', async () => { - it('sign', async () => { - datasetorder = await datasetProvider.signDatasetOrder({ - dataset: DatasetInstance.address, - datasetprice: 1, - volume: 1000, - tag: '0x0000000000000000000000000000000000000000000000000000000000000000', - apprestrict: constants.NULL.ADDRESS, - workerpoolrestrict: constants.NULL.ADDRESS, - requesterrestrict: constants.NULL.ADDRESS, - salt: web3.utils.randomHex(32), - sign: constants.NULL.SIGNATURE, - }); - }); - - it('verify', async () => { - assert.isTrue( - await IexecInstance.verifySignature( - datasetProvider.address, - odbtools.utils.hashDatasetOrder(ERC712_domain, datasetorder), - datasetorder.sign, - ), - ); - }); - }); - - describe('workerpool', async () => { - it('sign', async () => { - workerpoolorder = await scheduler.signWorkerpoolOrder({ - workerpool: WorkerpoolInstance.address, - workerpoolprice: 25, - volume: 3, - category: 4, - trust: trusttarget, - tag: '0x0000000000000000000000000000000000000000000000000000000000000000', - apprestrict: constants.NULL.ADDRESS, - datasetrestrict: constants.NULL.ADDRESS, - requesterrestrict: constants.NULL.ADDRESS, - salt: web3.utils.randomHex(32), - sign: constants.NULL.SIGNATURE, - }); - }); - - it('verify', async () => { - assert.isTrue( - await IexecInstance.verifySignature( - scheduler.address, - odbtools.utils.hashWorkerpoolOrder(ERC712_domain, workerpoolorder), - workerpoolorder.sign, - ), - ); - }); - }); - - describe('request', async () => { - it('sign', async () => { - requestorder = await user.signRequestOrder({ - app: AppInstance.address, - appmaxprice: 3, - dataset: DatasetInstance.address, - datasetmaxprice: 1, - workerpool: constants.NULL.ADDRESS, - workerpoolmaxprice: 25, - volume: 1, // CHANGE FOR BOT - category: 4, - trust: trusttarget, - tag: '0x0000000000000000000000000000000000000000000000000000000000000000', - requester: user.address, - beneficiary: user.address, - callback: ethers.Wallet.createRandom().address, - params: '', - salt: web3.utils.randomHex(32), - sign: constants.NULL.SIGNATURE, - }); - }); - - it('verify', async () => { - assert.isTrue( - await IexecInstance.verifySignature( - user.address, - odbtools.utils.hashRequestOrder(ERC712_domain, requestorder), - requestorder.sign, - ), - ); - }); - }); - }); - - describe('[1] order matching', async () => { - it('[TX] match', async () => { - txMined = await IexecInstance.matchOrders( - apporder, - datasetorder, - workerpoolorder, - requestorder, - { from: user.address }, - ); - gasReceipt.push(['matchOrders', txMined.receipt.gasUsed]); - - dealid = web3.utils.soliditySha3( - { - t: 'bytes32', - v: odbtools.utils.hashRequestOrder(ERC712_domain, requestorder), - }, - { t: 'uint256', v: 0 }, - ); - - events = tools.extractEvents(txMined, IexecInstance.address, 'SchedulerNotice'); - assert.equal(events[0].args.workerpool, WorkerpoolInstance.address); - assert.equal(events[0].args.dealid, dealid); - - events = tools.extractEvents(txMined, IexecInstance.address, 'OrdersMatched'); - assert.equal(events[0].args.dealid, dealid); - assert.equal( - events[0].args.appHash, - odbtools.utils.hashAppOrder(ERC712_domain, apporder), - ); - assert.equal( - events[0].args.datasetHash, - odbtools.utils.hashDatasetOrder(ERC712_domain, datasetorder), - ); - assert.equal( - events[0].args.workerpoolHash, - odbtools.utils.hashWorkerpoolOrder(ERC712_domain, workerpoolorder), - ); - assert.equal( - events[0].args.requestHash, - odbtools.utils.hashRequestOrder(ERC712_domain, requestorder), - ); - assert.equal(events[0].args.volume, 1); - }); - }); - - describe('[2] initialization', async () => { - it('[TX] initialize', async () => { - txMined = await IexecInstance.initialize(dealid, 0, { from: scheduler.address }); - gasReceipt.push(['initialize', txMined.receipt.gasUsed]); - - taskid = web3.utils.soliditySha3( - { t: 'bytes32', v: dealid }, - { t: 'uint256', v: 0 }, - ); - - events = tools.extractEvents(txMined, IexecInstance.address, 'TaskInitialize'); - assert.equal(events[0].args.taskid, taskid); - assert.equal(events[0].args.workerpool, WorkerpoolInstance.address); - }); - }); - - describe('[3] contributeAndFinalize', async () => { - it('authorization signature', async () => { - const preauth = await scheduler.signPreAuthorization(taskid, worker.agent.address); - [authorization, secret] = worker.useenclave - ? await broker.signAuthorization(preauth) - : [preauth, null]; - }); - - it('run', async () => { - consensus = odbtools.utils.hashConsensus(taskid, consensus); - result = await worker.agent.run(authorization, secret, worker.result); - }); - - it('[TX] contributeAndFinalize', async () => { - txMined = await IexecInstance.contributeAndFinalize( - authorization.taskid, // task (authorization) - result.digest, // digest (result) - web3.utils.utf8ToHex('aResult'), // data (result) - resultsCallback, // data (resultsCallback) - authorization.enclave, // address (enclave) - result.sign, // signature (enclave) - authorization.sign, // signature (authorization) - { from: worker.agent.address }, - ); - gasReceipt.push(['contributeAndFinalize', txMined.receipt.gasUsed]); - - events = tools.extractEvents(txMined, IexecInstance.address, 'TaskContribute'); - assert.equal(events[0].args.taskid, authorization.taskid); - assert.equal(events[0].args.worker, worker.agent.address); - assert.equal(events[0].args.hash, result.hash); - - events = tools.extractEvents(txMined, IexecInstance.address, 'TaskConsensus'); - assert.equal(events[0].args.taskid, taskid); - assert.equal(events[0].args.consensus, consensus.hash); - - events = tools.extractEvents(txMined, IexecInstance.address, 'TaskReveal'); - assert.equal(events[0].args.taskid, taskid); - assert.equal(events[0].args.worker, worker.agent.address); - assert.equal(events[0].args.digest, result.digest); - - events = tools.extractEvents(txMined, IexecInstance.address, 'TaskFinalize'); - assert.equal(events[0].args.taskid, taskid); - assert.equal(events[0].args.results, web3.utils.utf8ToHex('aResult')); - }); - //[TODO] contributeAndFinalize without callback - }); - }); - - describe('→ summary', async () => { - it('task', async () => { - task = await IexecInstance.viewTask(taskid); - assert.equal(task.status, constants.TaskStatusEnum.COMPLETED); - assert.equal(task.dealid, dealid); - assert.equal(Number(task.idx), 0); - assert.equal( - Number(task.timeref), - (await IexecInstance.viewCategory(requestorder.category)).workClockTimeRef, - ); - assert.isAbove(Number(task.contributionDeadline), 0); - assert.isAbove(Number(task.revealDeadline), 0); - assert.isAbove(Number(task.finalDeadline), 0); - assert.equal(task.consensusValue, consensus.hash); - assert.equal(Number(task.revealCounter), 1); - assert.equal(Number(task.winnerCounter), 1); - assert.deepEqual( - task.contributors.map((a) => a), - [worker.agent.address], - ); - assert.equal(task.results, web3.utils.utf8ToHex('aResult')); - assert.equal(task.resultsCallback, resultsCallback); - }); - - it('balances', async () => { - assert.deepEqual(await appProvider.viewAccount(), [3, 0], 'check balance'); - assert.deepEqual(await datasetProvider.viewAccount(), [1, 0], 'check balance'); - assert.deepEqual(await scheduler.viewAccount(), [1002, 0], 'check balance'); - assert.deepEqual(await worker1.viewAccount(), [1023, 0], 'check balance'); - assert.deepEqual(await worker2.viewAccount(), [1000, 0], 'check balance'); - assert.deepEqual(await worker3.viewAccount(), [1000, 0], 'check balance'); - assert.deepEqual(await worker4.viewAccount(), [1000, 0], 'check balance'); - assert.deepEqual(await worker5.viewAccount(), [1000, 0], 'check balance'); - assert.deepEqual(await user.viewAccount(), [971, 0], 'check balance'); - }); - - it('balances - extra', async () => { - assert.equal( - Number(await IexecInstance.totalSupply()), - DEPLOYMENT.asset == 'Native' - ? Number(await web3.eth.getBalance(IexecInstance.address)) / 10 ** 9 - : Number(await RLCInstance.balanceOf(IexecInstance.address)), - ); - - for (agent of [ - appProvider, - datasetProvider, - scheduler, - worker1, - worker2, - worker3, - worker4, - worker5, - user, - ]) { - assert.deepEqual( - await agent.viewAccount(), - [ - Number(await IexecInstance.balanceOf(agent.address)), - Number(await IexecInstance.frozenOf(agent.address)), - ], - 'check balance', - ); - } - }); - - it('score', async () => { - assert.equal(await worker1.viewScore(), 0, 'score issue'); - assert.equal(await worker2.viewScore(), 0, 'score issue'); - assert.equal(await worker3.viewScore(), 0, 'score issue'); - assert.equal(await worker4.viewScore(), 0, 'score issue'); - assert.equal(await worker5.viewScore(), 0, 'score issue'); - }); - - it('gas used', async () => { - totalgas = 0; - for ([descr, gas] of gasReceipt) { - console.log(`${descr.padEnd(24, ' ')} ${gas.toString().padStart(8, ' ')}`); - totalgas += gas; - } - console.log(`${'Total gas'.padEnd(24, ' ')} ${totalgas.toString().padStart(8, ' ')}`); - }); - }); -}); From 43ffef546ace70b853151a19d34c3e4bad1e6ed6 Mon Sep 17 00:00:00 2001 From: Zied <26070035+zguesmi@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:20:20 +0100 Subject: [PATCH 2/5] Add prices to created deal --- .../byContract/IexecAccessors/IexecAccessors.test.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/byContract/IexecAccessors/IexecAccessors.test.ts b/test/byContract/IexecAccessors/IexecAccessors.test.ts index 57d28873..3b9ce667 100644 --- a/test/byContract/IexecAccessors/IexecAccessors.test.ts +++ b/test/byContract/IexecAccessors/IexecAccessors.test.ts @@ -11,7 +11,7 @@ import { IexecInterfaceNative__factory, TestClient__factory, } from '../../../typechain'; -import { OrdersAssets, buildOrders } from '../../../utils/createOrders'; +import { OrdersAssets, OrdersPrices, buildOrders } from '../../../utils/createOrders'; import { TaskStatusEnum, buildResultCallbackAndDigest, @@ -25,6 +25,9 @@ import { IexecWrapper } from '../../utils/IexecWrapper'; * Test state view functions. */ +const appPrice = 1000; +const datasetPrice = 1_000_000; +const workerpoolPrice = 1_000_000_000; const { results, resultDigest } = buildUtf8ResultAndDigest('result'); const { resultsCallback, callbackResultDigest } = buildResultCallbackAndDigest(123); @@ -34,6 +37,7 @@ let iexecWrapper: IexecWrapper; let [appAddress, datasetAddress, workerpoolAddress]: string[] = []; let [requester, scheduler, worker1, anyone]: SignerWithAddress[] = []; let ordersAssets: OrdersAssets; +let ordersPrices: OrdersPrices; let callbackAddress: string; describe('IexecAccessors', async () => { @@ -55,6 +59,11 @@ describe('IexecAccessors', async () => { dataset: datasetAddress, workerpool: workerpoolAddress, }; + ordersPrices = { + app: appPrice, + dataset: datasetPrice, + workerpool: workerpoolPrice, + }; callbackAddress = await new TestClient__factory() .connect(anyone) .deploy() @@ -224,6 +233,7 @@ describe('IexecAccessors', async () => { async function createDeal(volume: number = 1) { const orders = buildOrders({ assets: ordersAssets, + prices: ordersPrices, requester: requester.address, volume, callback: callbackAddress, From a8d3c4c99f3e2eb3d654b0089da52582fbe1a3f4 Mon Sep 17 00:00:00 2001 From: Zied <26070035+zguesmi@users.noreply.github.com> Date: Fri, 10 Jan 2025 17:28:10 +0100 Subject: [PATCH 3/5] Fix coverage regression after deleting migrated test file --- .../IexecAccessors/IexecAccessors.test.ts | 125 +++++++++++++++--- 1 file changed, 109 insertions(+), 16 deletions(-) diff --git a/test/byContract/IexecAccessors/IexecAccessors.test.ts b/test/byContract/IexecAccessors/IexecAccessors.test.ts index 3b9ce667..315de44c 100644 --- a/test/byContract/IexecAccessors/IexecAccessors.test.ts +++ b/test/byContract/IexecAccessors/IexecAccessors.test.ts @@ -1,18 +1,21 @@ // SPDX-FileCopyrightText: 2020-2024 IEXEC BLOCKCHAIN TECH // SPDX-License-Identifier: Apache-2.0 -import { HashZero } from '@ethersproject/constants'; +import { AddressZero, HashZero } from '@ethersproject/constants'; import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; import { deployments, ethers, expect } from 'hardhat'; import { loadHardhatFixtureDeployment } from '../../../scripts/hardhat-fixture-deployer'; +import { IexecInterfaceNative, IexecInterfaceNative__factory } from '../../../typechain'; import { - IexecInterfaceNative, - IexecInterfaceNative__factory, - TestClient__factory, -} from '../../../typechain'; -import { OrdersAssets, OrdersPrices, buildOrders } from '../../../utils/createOrders'; + OrdersAssets, + OrdersPrices, + buildOrders, + createOrderOperation, +} from '../../../utils/createOrders'; import { + ContributionStatusEnum, + OrderOperationEnum, TaskStatusEnum, buildResultCallbackAndDigest, buildUtf8ResultAndDigest, @@ -35,10 +38,9 @@ let proxyAddress: string; let iexecPoco: IexecInterfaceNative; let iexecWrapper: IexecWrapper; let [appAddress, datasetAddress, workerpoolAddress]: string[] = []; -let [requester, scheduler, worker1, anyone]: SignerWithAddress[] = []; +let [requester, appProvider, datasetProvider, scheduler, worker1, anyone]: SignerWithAddress[] = []; let ordersAssets: OrdersAssets; let ordersPrices: OrdersPrices; -let callbackAddress: string; describe('IexecAccessors', async () => { beforeEach('Deploy', async () => { @@ -50,7 +52,7 @@ describe('IexecAccessors', async () => { async function initFixture() { const accounts = await getIexecAccounts(); - ({ requester, scheduler, worker1, anyone } = accounts); + ({ requester, appProvider, datasetProvider, scheduler, worker1, anyone } = accounts); iexecWrapper = new IexecWrapper(proxyAddress, accounts); ({ appAddress, datasetAddress, workerpoolAddress } = await iexecWrapper.createAssets()); iexecPoco = IexecInterfaceNative__factory.connect(proxyAddress, anyone); @@ -64,11 +66,6 @@ describe('IexecAccessors', async () => { dataset: datasetPrice, workerpool: workerpoolPrice, }; - callbackAddress = await new TestClient__factory() - .connect(anyone) - .deploy() - .then((contract) => contract.deployed()) - .then((contract) => contract.address); } it('name', async function () { @@ -87,11 +84,89 @@ describe('IexecAccessors', async () => { expect(await iexecPoco.totalSupply()).to.equal(0n); }); + it('balanceOf', async function () { + const amount = 3; + await iexecWrapper.depositInIexecAccount(anyone, amount); + expect(await iexecPoco.balanceOf(anyone.address)).to.equal(amount); + }); + + it('frozenOf', async function () { + await createDeal(); // Lock some requester funds. + const dealPrice = appPrice + datasetPrice + workerpoolPrice; // volume == 1 + expect(await iexecPoco.frozenOf(requester.address)).to.equal(dealPrice); + }); + + it('allowance', async function () { + const amount = 10; + const spender = ethers.Wallet.createRandom().address; + await iexecWrapper.depositInIexecAccount(anyone, amount); + await iexecPoco.connect(anyone).approve(spender, amount); + expect(await iexecPoco.allowance(anyone.address, spender)).to.equal(amount); + }); + + it('viewAccount', async function () { + await createDeal(); // Lock some requester funds. + const dealPrice = appPrice + datasetPrice + workerpoolPrice; + // Stake some funds. + const stakedBalance = 3; + await iexecWrapper.depositInIexecAccount(requester, stakedBalance); + // Check staked and locked amounts. + const account = await iexecPoco.viewAccount(requester.address); + expect(account.stake).to.equal(stakedBalance); + expect(account.locked).to.equal(dealPrice); + }); + // TODO test the case where token() == 0x0 in native mode. it('token', async function () { expect(await iexecPoco.token()).to.equal('0x5FbDB2315678afecb367f032d93F642f64180aa3'); }); + it('viewDeal', async function () { + const { dealId } = await createDeal(); + const deal = await iexecPoco.viewDeal(dealId); + console.log('🚀 ~ deal sponsor:', deal.sponsor); + expect(deal.app.pointer).to.equal(appAddress); + expect(deal.app.owner).to.equal(appProvider.address); + expect(deal.app.price).to.equal(appPrice); + expect(deal.dataset.pointer).to.equal(datasetAddress); + expect(deal.dataset.owner).to.equal(datasetProvider.address); + expect(deal.dataset.price).to.equal(datasetPrice); + expect(deal.workerpool.pointer).to.equal(workerpoolAddress); + expect(deal.workerpool.owner).to.equal(scheduler.address); + expect(deal.workerpool.price).to.equal(workerpoolPrice); + expect(deal.trust).to.equal(1); + expect(deal.category).to.equal(0); + expect(deal.tag).to.equal(HashZero); // Standard + expect(deal.requester).to.equal(requester.address); + expect(deal.beneficiary).to.equal(AddressZero); + expect(deal.callback).to.equal(AddressZero); + expect(deal.params).to.equal(''); + expect(deal.startTime).to.be.greaterThan(0); + expect(deal.botFirst).to.equal(0); + expect(deal.botSize).to.equal(1); + expect(deal.workerStake).to.be.greaterThan(0); + expect(deal.schedulerRewardRatio).to.be.greaterThan(0); + expect(deal.sponsor).to.equal(requester.address); + }); + + it('viewConsumed', async function () { + const { orders } = await createDeal(); + expect(await iexecPoco.viewConsumed(iexecWrapper.hashOrder(orders.app))).to.equal(1); + }); + + it('viewPresigned', async function () { + const appOrder = buildOrders({ assets: ordersAssets, requester: requester.address }).app; + const orderOperation = createOrderOperation(appOrder, OrderOperationEnum.SIGN); + await iexecWrapper.signOrderOperation(orderOperation, appProvider); + await iexecPoco + .connect(appProvider) + .manageAppOrder(orderOperation) + .then((tx) => tx.wait()); + expect(await iexecPoco.viewPresigned(iexecWrapper.hashOrder(appOrder))).equal( + appProvider.address, + ); + }); + it('viewTask', async function () { const { dealId, taskId, taskIndex, startTime, timeRef } = await createDeal(); await iexecWrapper.initializeTask(dealId, taskIndex); @@ -119,6 +194,25 @@ describe('IexecAccessors', async () => { expect(task.resultsCallback).to.equal('0x'); }); + it('viewContribution', async function () { + const { dealId, taskIndex, taskId } = await createDeal(); + await iexecWrapper.initializeTask(dealId, taskIndex); + await iexecWrapper.contributeToTask(dealId, taskIndex, resultDigest, worker1); + const contribution = await iexecPoco.viewContribution(taskId, worker1.address); + expect(contribution.status).to.equal(ContributionStatusEnum.CONTRIBUTED); + expect(contribution.resultHash.length).to.equal(66); + expect(contribution.resultSeal.length).to.equal(66); + expect(contribution.enclaveChallenge).to.equal(AddressZero); + expect(contribution.weight).to.equal(1); + console.log('score:', await iexecPoco.viewScore(worker1.address)); + }); + + // viewScore(address _worker) + it('viewScore', async function () { + // TODO + expect(await iexecPoco.viewScore(worker1.address)).to.equal(0); + }); + it('countCategory', async function () { expect(await iexecPoco.countCategory()).to.equal(5); }); @@ -236,14 +330,13 @@ async function createDeal(volume: number = 1) { prices: ordersPrices, requester: requester.address, volume, - callback: callbackAddress, }); const { dealId, taskId, taskIndex, startTime } = await iexecWrapper.signAndMatchOrders( ...orders.toArray(), ); const dealCategory = (await iexecPoco.viewDeal(dealId)).category; const timeRef = (await iexecPoco.viewCategory(dealCategory)).workClockTimeRef.toNumber(); - return { dealId, taskId, taskIndex, startTime, timeRef }; + return { dealId, taskId, taskIndex, startTime, timeRef, orders }; } async function verifyTaskStatusAndResult(taskId: string, expectedStatus: number) { From e4cdb2fe948f8ca820b4a60ebba4cfab79e4acd2 Mon Sep 17 00:00:00 2001 From: Zied <26070035+zguesmi@users.noreply.github.com> Date: Fri, 10 Jan 2025 18:57:56 +0100 Subject: [PATCH 4/5] Clean --- test/byContract/IexecAccessors/IexecAccessors.test.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/byContract/IexecAccessors/IexecAccessors.test.ts b/test/byContract/IexecAccessors/IexecAccessors.test.ts index 315de44c..9a35279a 100644 --- a/test/byContract/IexecAccessors/IexecAccessors.test.ts +++ b/test/byContract/IexecAccessors/IexecAccessors.test.ts @@ -55,7 +55,7 @@ describe('IexecAccessors', async () => { ({ requester, appProvider, datasetProvider, scheduler, worker1, anyone } = accounts); iexecWrapper = new IexecWrapper(proxyAddress, accounts); ({ appAddress, datasetAddress, workerpoolAddress } = await iexecWrapper.createAssets()); - iexecPoco = IexecInterfaceNative__factory.connect(proxyAddress, anyone); + iexecPoco = IexecInterfaceNative__factory.connect(proxyAddress, ethers.provider); ordersAssets = { app: appAddress, dataset: datasetAddress, @@ -124,7 +124,6 @@ describe('IexecAccessors', async () => { it('viewDeal', async function () { const { dealId } = await createDeal(); const deal = await iexecPoco.viewDeal(dealId); - console.log('🚀 ~ deal sponsor:', deal.sponsor); expect(deal.app.pointer).to.equal(appAddress); expect(deal.app.owner).to.equal(appProvider.address); expect(deal.app.price).to.equal(appPrice); @@ -204,10 +203,8 @@ describe('IexecAccessors', async () => { expect(contribution.resultSeal.length).to.equal(66); expect(contribution.enclaveChallenge).to.equal(AddressZero); expect(contribution.weight).to.equal(1); - console.log('score:', await iexecPoco.viewScore(worker1.address)); }); - // viewScore(address _worker) it('viewScore', async function () { // TODO expect(await iexecPoco.viewScore(worker1.address)).to.equal(0); From 7d375447a6505be7caded22cd3a2c6798a41da95 Mon Sep 17 00:00:00 2001 From: Zied <26070035+zguesmi@users.noreply.github.com> Date: Mon, 13 Jan 2025 13:52:32 +0100 Subject: [PATCH 5/5] Update copyright header year --- test/byContract/IexecAccessors/IexecAccessors.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/byContract/IexecAccessors/IexecAccessors.test.ts b/test/byContract/IexecAccessors/IexecAccessors.test.ts index 9a35279a..66681e66 100644 --- a/test/byContract/IexecAccessors/IexecAccessors.test.ts +++ b/test/byContract/IexecAccessors/IexecAccessors.test.ts @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2020-2024 IEXEC BLOCKCHAIN TECH +// SPDX-FileCopyrightText: 2020-2025 IEXEC BLOCKCHAIN TECH // SPDX-License-Identifier: Apache-2.0 import { AddressZero, HashZero } from '@ethersproject/constants';