11// SPDX-FileCopyrightText: 2020-2024 IEXEC BLOCKCHAIN TECH <[email protected] > 22// SPDX-License-Identifier: Apache-2.0
33
4- import { HashZero } from '@ethersproject/constants' ;
4+ import { AddressZero , HashZero } from '@ethersproject/constants' ;
55import { loadFixture } from '@nomicfoundation/hardhat-network-helpers' ;
66import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' ;
77import { deployments , ethers , expect } from 'hardhat' ;
88import { loadHardhatFixtureDeployment } from '../../../scripts/hardhat-fixture-deployer' ;
9+ import { IexecInterfaceNative , IexecInterfaceNative__factory } from '../../../typechain' ;
910import {
10- IexecInterfaceNative ,
11- IexecInterfaceNative__factory ,
12- TestClient__factory ,
13- } from '../../../typechain' ;
14- import { OrdersAssets , OrdersPrices , buildOrders } from '../../../utils/createOrders' ;
11+ OrdersAssets ,
12+ OrdersPrices ,
13+ buildOrders ,
14+ createOrderOperation ,
15+ } from '../../../utils/createOrders' ;
1516import {
17+ ContributionStatusEnum ,
18+ OrderOperationEnum ,
1619 TaskStatusEnum ,
1720 buildResultCallbackAndDigest ,
1821 buildUtf8ResultAndDigest ,
@@ -35,10 +38,9 @@ let proxyAddress: string;
3538let iexecPoco : IexecInterfaceNative ;
3639let iexecWrapper : IexecWrapper ;
3740let [ appAddress , datasetAddress , workerpoolAddress ] : string [ ] = [ ] ;
38- let [ requester , scheduler , worker1 , anyone ] : SignerWithAddress [ ] = [ ] ;
41+ let [ requester , appProvider , datasetProvider , scheduler , worker1 , anyone ] : SignerWithAddress [ ] = [ ] ;
3942let ordersAssets : OrdersAssets ;
4043let ordersPrices : OrdersPrices ;
41- let callbackAddress : string ;
4244
4345describe ( 'IexecAccessors' , async ( ) => {
4446 beforeEach ( 'Deploy' , async ( ) => {
@@ -50,7 +52,7 @@ describe('IexecAccessors', async () => {
5052
5153 async function initFixture ( ) {
5254 const accounts = await getIexecAccounts ( ) ;
53- ( { requester, scheduler, worker1, anyone } = accounts ) ;
55+ ( { requester, appProvider , datasetProvider , scheduler, worker1, anyone } = accounts ) ;
5456 iexecWrapper = new IexecWrapper ( proxyAddress , accounts ) ;
5557 ( { appAddress, datasetAddress, workerpoolAddress } = await iexecWrapper . createAssets ( ) ) ;
5658 iexecPoco = IexecInterfaceNative__factory . connect ( proxyAddress , anyone ) ;
@@ -64,11 +66,6 @@ describe('IexecAccessors', async () => {
6466 dataset : datasetPrice ,
6567 workerpool : workerpoolPrice ,
6668 } ;
67- callbackAddress = await new TestClient__factory ( )
68- . connect ( anyone )
69- . deploy ( )
70- . then ( ( contract ) => contract . deployed ( ) )
71- . then ( ( contract ) => contract . address ) ;
7269 }
7370
7471 it ( 'name' , async function ( ) {
@@ -87,11 +84,89 @@ describe('IexecAccessors', async () => {
8784 expect ( await iexecPoco . totalSupply ( ) ) . to . equal ( 0n ) ;
8885 } ) ;
8986
87+ it ( 'balanceOf' , async function ( ) {
88+ const amount = 3 ;
89+ await iexecWrapper . depositInIexecAccount ( anyone , amount ) ;
90+ expect ( await iexecPoco . balanceOf ( anyone . address ) ) . to . equal ( amount ) ;
91+ } ) ;
92+
93+ it ( 'frozenOf' , async function ( ) {
94+ await createDeal ( ) ; // Lock some requester funds.
95+ const dealPrice = appPrice + datasetPrice + workerpoolPrice ; // volume == 1
96+ expect ( await iexecPoco . frozenOf ( requester . address ) ) . to . equal ( dealPrice ) ;
97+ } ) ;
98+
99+ it ( 'allowance' , async function ( ) {
100+ const amount = 10 ;
101+ const spender = ethers . Wallet . createRandom ( ) . address ;
102+ await iexecWrapper . depositInIexecAccount ( anyone , amount ) ;
103+ await iexecPoco . connect ( anyone ) . approve ( spender , amount ) ;
104+ expect ( await iexecPoco . allowance ( anyone . address , spender ) ) . to . equal ( amount ) ;
105+ } ) ;
106+
107+ it ( 'viewAccount' , async function ( ) {
108+ await createDeal ( ) ; // Lock some requester funds.
109+ const dealPrice = appPrice + datasetPrice + workerpoolPrice ;
110+ // Stake some funds.
111+ const stakedBalance = 3 ;
112+ await iexecWrapper . depositInIexecAccount ( requester , stakedBalance ) ;
113+ // Check staked and locked amounts.
114+ const account = await iexecPoco . viewAccount ( requester . address ) ;
115+ expect ( account . stake ) . to . equal ( stakedBalance ) ;
116+ expect ( account . locked ) . to . equal ( dealPrice ) ;
117+ } ) ;
118+
90119 // TODO test the case where token() == 0x0 in native mode.
91120 it ( 'token' , async function ( ) {
92121 expect ( await iexecPoco . token ( ) ) . to . equal ( '0x5FbDB2315678afecb367f032d93F642f64180aa3' ) ;
93122 } ) ;
94123
124+ it ( 'viewDeal' , async function ( ) {
125+ const { dealId } = await createDeal ( ) ;
126+ const deal = await iexecPoco . viewDeal ( dealId ) ;
127+ console . log ( '🚀 ~ deal sponsor:' , deal . sponsor ) ;
128+ expect ( deal . app . pointer ) . to . equal ( appAddress ) ;
129+ expect ( deal . app . owner ) . to . equal ( appProvider . address ) ;
130+ expect ( deal . app . price ) . to . equal ( appPrice ) ;
131+ expect ( deal . dataset . pointer ) . to . equal ( datasetAddress ) ;
132+ expect ( deal . dataset . owner ) . to . equal ( datasetProvider . address ) ;
133+ expect ( deal . dataset . price ) . to . equal ( datasetPrice ) ;
134+ expect ( deal . workerpool . pointer ) . to . equal ( workerpoolAddress ) ;
135+ expect ( deal . workerpool . owner ) . to . equal ( scheduler . address ) ;
136+ expect ( deal . workerpool . price ) . to . equal ( workerpoolPrice ) ;
137+ expect ( deal . trust ) . to . equal ( 1 ) ;
138+ expect ( deal . category ) . to . equal ( 0 ) ;
139+ expect ( deal . tag ) . to . equal ( HashZero ) ; // Standard
140+ expect ( deal . requester ) . to . equal ( requester . address ) ;
141+ expect ( deal . beneficiary ) . to . equal ( AddressZero ) ;
142+ expect ( deal . callback ) . to . equal ( AddressZero ) ;
143+ expect ( deal . params ) . to . equal ( '' ) ;
144+ expect ( deal . startTime ) . to . be . greaterThan ( 0 ) ;
145+ expect ( deal . botFirst ) . to . equal ( 0 ) ;
146+ expect ( deal . botSize ) . to . equal ( 1 ) ;
147+ expect ( deal . workerStake ) . to . be . greaterThan ( 0 ) ;
148+ expect ( deal . schedulerRewardRatio ) . to . be . greaterThan ( 0 ) ;
149+ expect ( deal . sponsor ) . to . equal ( requester . address ) ;
150+ } ) ;
151+
152+ it ( 'viewConsumed' , async function ( ) {
153+ const { orders } = await createDeal ( ) ;
154+ expect ( await iexecPoco . viewConsumed ( iexecWrapper . hashOrder ( orders . app ) ) ) . to . equal ( 1 ) ;
155+ } ) ;
156+
157+ it ( 'viewPresigned' , async function ( ) {
158+ const appOrder = buildOrders ( { assets : ordersAssets , requester : requester . address } ) . app ;
159+ const orderOperation = createOrderOperation ( appOrder , OrderOperationEnum . SIGN ) ;
160+ await iexecWrapper . signOrderOperation ( orderOperation , appProvider ) ;
161+ await iexecPoco
162+ . connect ( appProvider )
163+ . manageAppOrder ( orderOperation )
164+ . then ( ( tx ) => tx . wait ( ) ) ;
165+ expect ( await iexecPoco . viewPresigned ( iexecWrapper . hashOrder ( appOrder ) ) ) . equal (
166+ appProvider . address ,
167+ ) ;
168+ } ) ;
169+
95170 it ( 'viewTask' , async function ( ) {
96171 const { dealId, taskId, taskIndex, startTime, timeRef } = await createDeal ( ) ;
97172 await iexecWrapper . initializeTask ( dealId , taskIndex ) ;
@@ -119,6 +194,25 @@ describe('IexecAccessors', async () => {
119194 expect ( task . resultsCallback ) . to . equal ( '0x' ) ;
120195 } ) ;
121196
197+ it ( 'viewContribution' , async function ( ) {
198+ const { dealId, taskIndex, taskId } = await createDeal ( ) ;
199+ await iexecWrapper . initializeTask ( dealId , taskIndex ) ;
200+ await iexecWrapper . contributeToTask ( dealId , taskIndex , resultDigest , worker1 ) ;
201+ const contribution = await iexecPoco . viewContribution ( taskId , worker1 . address ) ;
202+ expect ( contribution . status ) . to . equal ( ContributionStatusEnum . CONTRIBUTED ) ;
203+ expect ( contribution . resultHash . length ) . to . equal ( 66 ) ;
204+ expect ( contribution . resultSeal . length ) . to . equal ( 66 ) ;
205+ expect ( contribution . enclaveChallenge ) . to . equal ( AddressZero ) ;
206+ expect ( contribution . weight ) . to . equal ( 1 ) ;
207+ console . log ( 'score:' , await iexecPoco . viewScore ( worker1 . address ) ) ;
208+ } ) ;
209+
210+ // viewScore(address _worker)
211+ it ( 'viewScore' , async function ( ) {
212+ // TODO
213+ expect ( await iexecPoco . viewScore ( worker1 . address ) ) . to . equal ( 0 ) ;
214+ } ) ;
215+
122216 it ( 'countCategory' , async function ( ) {
123217 expect ( await iexecPoco . countCategory ( ) ) . to . equal ( 5 ) ;
124218 } ) ;
@@ -236,14 +330,13 @@ async function createDeal(volume: number = 1) {
236330 prices : ordersPrices ,
237331 requester : requester . address ,
238332 volume,
239- callback : callbackAddress ,
240333 } ) ;
241334 const { dealId, taskId, taskIndex, startTime } = await iexecWrapper . signAndMatchOrders (
242335 ...orders . toArray ( ) ,
243336 ) ;
244337 const dealCategory = ( await iexecPoco . viewDeal ( dealId ) ) . category ;
245338 const timeRef = ( await iexecPoco . viewCategory ( dealCategory ) ) . workClockTimeRef . toNumber ( ) ;
246- return { dealId, taskId, taskIndex, startTime, timeRef } ;
339+ return { dealId, taskId, taskIndex, startTime, timeRef, orders } ;
247340}
248341
249342async function verifyTaskStatusAndResult ( taskId : string , expectedStatus : number ) {
0 commit comments