From 9b7d0c78fda476aeba6a53122abd1797947e044e Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Thu, 26 Sep 2024 10:31:25 +0200 Subject: [PATCH 01/17] test verifyPresignature and verifyPresignatureOrSignature --- test/byContract/IexecPoco/IexecPoco1.test.ts | 130 +++++++++++++++++- .../IexecPoco/{verify.js => verify.js.skip} | 0 2 files changed, 126 insertions(+), 4 deletions(-) rename test/byContract/IexecPoco/{verify.js => verify.js.skip} (100%) diff --git a/test/byContract/IexecPoco/IexecPoco1.test.ts b/test/byContract/IexecPoco/IexecPoco1.test.ts index 889439bc0..199b4a2c6 100644 --- a/test/byContract/IexecPoco/IexecPoco1.test.ts +++ b/test/byContract/IexecPoco/IexecPoco1.test.ts @@ -25,11 +25,17 @@ import { OrdersAssets, OrdersPrices, buildOrders, + createOrderOperation, hashOrder, signOrder, signOrders, } from '../../../utils/createOrders'; -import { getDealId, getIexecAccounts, setNextBlockTimestamp } from '../../../utils/poco-tools'; +import { + OrderOperationEnum, + getDealId, + getIexecAccounts, + setNextBlockTimestamp, +} from '../../../utils/poco-tools'; import { compactSignature } from '../../../utils/tools'; import { IexecWrapper } from '../../utils/IexecWrapper'; @@ -71,6 +77,7 @@ describe('IexecPoco1', () => { let ordersAssets: OrdersAssets; let ordersPrices: OrdersPrices; let orders: IexecOrders; + let appOrderHash: string; let [randomAddress, randomSignature]: string[] = []; let randomContract: OwnableMock; let erc1271MockContract: ERC1271Mock; @@ -115,6 +122,8 @@ describe('IexecPoco1', () => { tag: teeDealTag, volume: volume, }); + appOrderHash = iexecWrapper.hashOrder(orders.app); + const randomWallet = ethers.Wallet.createRandom(); randomAddress = randomWallet.address; randomSignature = await randomWallet.signMessage('random'); @@ -206,9 +215,122 @@ describe('IexecPoco1', () => { }); }); }); - // TODO - describe('Verify presignature', () => {}); - describe('Verify presignature or signature', () => {}); + + describe('verifyPresignature', () => { + it('Should verify the correct presignature', async () => { + // Assume appProvider presigned the appOrderHash + await iexecPoco + .connect(appProvider) + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)); + + expect(await iexecPocoContract.verifyPresignature(appProvider.address, appOrderHash)).to + .be.true; + }); + + it('Should fail to verify presignature when not presigned', async () => { + // App provider hasn't presigned the order yet + expect(await iexecPocoContract.verifyPresignature(appProvider.address, appOrderHash)).to + .be.false; + }); + + it('Should fail to verify presignature with an incorrect account', async () => { + await iexecPoco + .connect(appProvider) + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)); + + expect( + await iexecPocoContract.verifyPresignature(datasetProvider.address, appOrderHash), + ).to.be.false; + }); + + it('Should fail to verify presignature for an unknown messageHash', async () => { + const unknownMessageHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('unknown')); + + expect( + await iexecPocoContract.verifyPresignature(appProvider.address, unknownMessageHash), + ).to.be.false; + }); + + it('Should fail to verify presignature when account is address(0)', async () => { + await iexecPoco + .connect(appProvider) + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)); + + expect( + await iexecPocoContract.verifyPresignature( + ethers.constants.AddressZero, + appOrderHash, + ), + ).to.be.false; + }); + }); + + describe('Verify presignature or signature', () => { + it('Should verifyPresignatureOrSignature when the presignature is valid', async () => { + // Assume appProvider presigned the appOrderHash + await iexecPoco + .connect(appProvider) + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)); + + expect( + await iexecPocoContract.verifyPresignatureOrSignature( + appProvider.address, + appOrderHash, + '0x', + ), + ).to.be.true; // No signature needed for presigned + }); + + it(`Should fail to verifyPresignatureOrSignature when not presigned and invalid signature`, async () => { + expect( + await iexecPocoContract.verifyPresignatureOrSignature( + appProvider.address, + appOrderHash, + ethers.Wallet.createRandom().signMessage(someMessage), + ), + ).to.be.false; + }); + + it(`Should fail to verifyPresignatureOrSignature with an incorrect account for presignature`, async () => { + await iexecPoco + .connect(appProvider) + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)); + + expect( + await iexecPocoContract.verifyPresignatureOrSignature( + datasetProvider.address, + appOrderHash, + ethers.Wallet.createRandom().signMessage(someMessage), + ), + ).to.be.false; + }); + + it(`Should fail to verifyPresignatureOrSignature for an unknown messageHash`, async () => { + const unknownMessageHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('unknown')); + + expect( + await iexecPocoContract.verifyPresignatureOrSignature( + appProvider.address, + unknownMessageHash, + ethers.Wallet.createRandom().signMessage(unknownMessageHash), + ), + ).to.be.false; + }); + + it(`Should fail to verifyPresignatureOrSignature when account is address(0)`, async () => { + await iexecPoco + .connect(appProvider) + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)); + + expect( + await iexecPocoContract.verifyPresignatureOrSignature( + ethers.constants.AddressZero, + appOrderHash, + ethers.Wallet.createRandom().signMessage(someMessage), + ), + ).to.be.false; + }); + }); describe('Match orders', () => { it('Should match orders with: all assets, beneficiary, BoT, callback, replication', async () => { diff --git a/test/byContract/IexecPoco/verify.js b/test/byContract/IexecPoco/verify.js.skip similarity index 100% rename from test/byContract/IexecPoco/verify.js rename to test/byContract/IexecPoco/verify.js.skip From c3a8ede83100f025e8b0a6802b9dd69f8381b08d Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Thu, 26 Sep 2024 10:32:33 +0200 Subject: [PATCH 02/17] update change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2178a093e..2729d7baf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - finalize (#79, #117, #119) - reveal (#114, #118) - contribute (#108, #109, #110) + - verify (#136) - IexecPoco1 (#107, #113, #115, #116) - Add `.test` suffix to unit test files (#106) - ENSIntegration (#105) From ac07c42fb988c22b6caba82e976dd3156287030d Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Thu, 26 Sep 2024 14:52:08 +0200 Subject: [PATCH 03/17] update changelog --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2729d7baf..273d7beac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,8 +21,7 @@ - finalize (#79, #117, #119) - reveal (#114, #118) - contribute (#108, #109, #110) - - verify (#136) - - IexecPoco1 (#107, #113, #115, #116) + - IexecPoco1 (#107, #113, #115, #116, #136) - Add `.test` suffix to unit test files (#106) - ENSIntegration (#105) - IexecOrderManagement (#101, #102, #103, #104) From 1c2cac8d5937435edba4c5dd615a49c28d96230f Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Thu, 26 Sep 2024 15:14:58 +0200 Subject: [PATCH 04/17] add then tx.wait() --- test/byContract/IexecPoco/IexecPoco1.test.ts | 23 ++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/test/byContract/IexecPoco/IexecPoco1.test.ts b/test/byContract/IexecPoco/IexecPoco1.test.ts index 199b4a2c6..d423185f2 100644 --- a/test/byContract/IexecPoco/IexecPoco1.test.ts +++ b/test/byContract/IexecPoco/IexecPoco1.test.ts @@ -221,7 +221,8 @@ describe('IexecPoco1', () => { // Assume appProvider presigned the appOrderHash await iexecPoco .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)); + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) + .then((tx) => tx.wait()); expect(await iexecPocoContract.verifyPresignature(appProvider.address, appOrderHash)).to .be.true; @@ -236,11 +237,11 @@ describe('IexecPoco1', () => { it('Should fail to verify presignature with an incorrect account', async () => { await iexecPoco .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)); + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) + .then((tx) => tx.wait()); - expect( - await iexecPocoContract.verifyPresignature(datasetProvider.address, appOrderHash), - ).to.be.false; + expect(await iexecPocoContract.verifyPresignature(anyone.address, appOrderHash)).to.be + .false; }); it('Should fail to verify presignature for an unknown messageHash', async () => { @@ -254,7 +255,8 @@ describe('IexecPoco1', () => { it('Should fail to verify presignature when account is address(0)', async () => { await iexecPoco .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)); + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) + .then((tx) => tx.wait()); expect( await iexecPocoContract.verifyPresignature( @@ -270,7 +272,8 @@ describe('IexecPoco1', () => { // Assume appProvider presigned the appOrderHash await iexecPoco .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)); + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) + .then((tx) => tx.wait()); expect( await iexecPocoContract.verifyPresignatureOrSignature( @@ -294,7 +297,8 @@ describe('IexecPoco1', () => { it(`Should fail to verifyPresignatureOrSignature with an incorrect account for presignature`, async () => { await iexecPoco .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)); + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) + .then((tx) => tx.wait()); expect( await iexecPocoContract.verifyPresignatureOrSignature( @@ -320,7 +324,8 @@ describe('IexecPoco1', () => { it(`Should fail to verifyPresignatureOrSignature when account is address(0)`, async () => { await iexecPoco .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)); + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) + .then((tx) => tx.wait()); expect( await iexecPocoContract.verifyPresignatureOrSignature( From 6e048d205ed90804a7d3b52ba9acd02fe0719db7 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Thu, 26 Sep 2024 15:46:13 +0200 Subject: [PATCH 05/17] use single array to test verifyPresignature and verifyPresignatureOrSignature --- test/byContract/IexecPoco/IexecPoco1.test.ts | 162 +++++++------------ 1 file changed, 61 insertions(+), 101 deletions(-) diff --git a/test/byContract/IexecPoco/IexecPoco1.test.ts b/test/byContract/IexecPoco/IexecPoco1.test.ts index d423185f2..9345d50ad 100644 --- a/test/byContract/IexecPoco/IexecPoco1.test.ts +++ b/test/byContract/IexecPoco/IexecPoco1.test.ts @@ -216,124 +216,84 @@ describe('IexecPoco1', () => { }); }); - describe('verifyPresignature', () => { - it('Should verify the correct presignature', async () => { - // Assume appProvider presigned the appOrderHash - await iexecPoco - .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) - .then((tx) => tx.wait()); - - expect(await iexecPocoContract.verifyPresignature(appProvider.address, appOrderHash)).to - .be.true; - }); - - it('Should fail to verify presignature when not presigned', async () => { - // App provider hasn't presigned the order yet - expect(await iexecPocoContract.verifyPresignature(appProvider.address, appOrderHash)).to - .be.false; - }); - - it('Should fail to verify presignature with an incorrect account', async () => { - await iexecPoco - .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) - .then((tx) => tx.wait()); - - expect(await iexecPocoContract.verifyPresignature(anyone.address, appOrderHash)).to.be - .false; - }); - - it('Should fail to verify presignature for an unknown messageHash', async () => { - const unknownMessageHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('unknown')); - - expect( - await iexecPocoContract.verifyPresignature(appProvider.address, unknownMessageHash), - ).to.be.false; - }); - - it('Should fail to verify presignature when account is address(0)', async () => { - await iexecPoco - .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) - .then((tx) => tx.wait()); - - expect( - await iexecPocoContract.verifyPresignature( - ethers.constants.AddressZero, + describe('Verify presignature and presignatureOrSignature', () => { + ['verifyPresignature', 'verifyPresignatureOrSignature'].forEach((verifyFunction) => { + it(`Should ${verifyFunction} when the presignature is valid`, async () => { + await iexecPoco + .connect(appProvider) + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) + .then((tx) => tx.wait()); + + const args = [ + appProvider.address, appOrderHash, - ), - ).to.be.false; - }); - }); + ...(verifyFunction === 'verifyPresignature' ? [] : ['0x']), + ]; - describe('Verify presignature or signature', () => { - it('Should verifyPresignatureOrSignature when the presignature is valid', async () => { - // Assume appProvider presigned the appOrderHash - await iexecPoco - .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) - .then((tx) => tx.wait()); + expect(await iexecPocoContract[verifyFunction](...args)).to.be.true; + }); - expect( - await iexecPocoContract.verifyPresignatureOrSignature( + it(`Should fail to ${verifyFunction} when not presigned and invalid signature`, async () => { + const args = [ appProvider.address, appOrderHash, - '0x', - ), - ).to.be.true; // No signature needed for presigned - }); + ...(verifyFunction === 'verifyPresignature' + ? [] + : [ethers.Wallet.createRandom().signMessage(someMessage)]), + ]; - it(`Should fail to verifyPresignatureOrSignature when not presigned and invalid signature`, async () => { - expect( - await iexecPocoContract.verifyPresignatureOrSignature( - appProvider.address, - appOrderHash, - ethers.Wallet.createRandom().signMessage(someMessage), - ), - ).to.be.false; - }); + expect(await iexecPocoContract[verifyFunction](...args)).to.be.false; + }); - it(`Should fail to verifyPresignatureOrSignature with an incorrect account for presignature`, async () => { - await iexecPoco - .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) - .then((tx) => tx.wait()); + it(`Should fail to ${verifyFunction} with an incorrect account for presignature`, async () => { + await iexecPoco + .connect(appProvider) + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) + .then((tx) => tx.wait()); - expect( - await iexecPocoContract.verifyPresignatureOrSignature( - datasetProvider.address, + const args = [ + anyone.address, appOrderHash, - ethers.Wallet.createRandom().signMessage(someMessage), - ), - ).to.be.false; - }); + ...(verifyFunction === 'verifyPresignature' + ? [] + : [ethers.Wallet.createRandom().signMessage(someMessage)]), + ]; - it(`Should fail to verifyPresignatureOrSignature for an unknown messageHash`, async () => { - const unknownMessageHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('unknown')); + expect(await iexecPocoContract[verifyFunction](...args)).to.be.false; + }); - expect( - await iexecPocoContract.verifyPresignatureOrSignature( + it(`Should fail to ${verifyFunction} for an unknown messageHash`, async () => { + const unknownMessageHash = ethers.utils.keccak256( + ethers.utils.toUtf8Bytes('unknown'), + ); + + const args = [ appProvider.address, unknownMessageHash, - ethers.Wallet.createRandom().signMessage(unknownMessageHash), - ), - ).to.be.false; - }); + ...(verifyFunction === 'verifyPresignature' + ? [] + : [ethers.Wallet.createRandom().signMessage(unknownMessageHash)]), + ]; - it(`Should fail to verifyPresignatureOrSignature when account is address(0)`, async () => { - await iexecPoco - .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) - .then((tx) => tx.wait()); + expect(await iexecPocoContract[verifyFunction](...args)).to.be.false; + }); - expect( - await iexecPocoContract.verifyPresignatureOrSignature( + it(`Should fail to ${verifyFunction} when account is address(0)`, async () => { + await iexecPoco + .connect(appProvider) + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) + .then((tx) => tx.wait()); + + const args = [ ethers.constants.AddressZero, appOrderHash, - ethers.Wallet.createRandom().signMessage(someMessage), - ), - ).to.be.false; + ...(verifyFunction === 'verifyPresignature' + ? [] + : [ethers.Wallet.createRandom().signMessage(someMessage)]), + ]; + + expect(await iexecPocoContract[verifyFunction](...args)).to.be.false; + }); }); }); From 6e7875ec460dccd6e061a0a351cfdfdfcd495b55 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Thu, 26 Sep 2024 15:47:35 +0200 Subject: [PATCH 06/17] clean --- test/byContract/IexecPoco/IexecPoco1.test.ts | 152 ++++++++++--------- 1 file changed, 79 insertions(+), 73 deletions(-) diff --git a/test/byContract/IexecPoco/IexecPoco1.test.ts b/test/byContract/IexecPoco/IexecPoco1.test.ts index 9345d50ad..45d3a1d59 100644 --- a/test/byContract/IexecPoco/IexecPoco1.test.ts +++ b/test/byContract/IexecPoco/IexecPoco1.test.ts @@ -216,85 +216,91 @@ describe('IexecPoco1', () => { }); }); - describe('Verify presignature and presignatureOrSignature', () => { - ['verifyPresignature', 'verifyPresignatureOrSignature'].forEach((verifyFunction) => { - it(`Should ${verifyFunction} when the presignature is valid`, async () => { - await iexecPoco - .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) - .then((tx) => tx.wait()); - - const args = [ - appProvider.address, - appOrderHash, - ...(verifyFunction === 'verifyPresignature' ? [] : ['0x']), - ]; - - expect(await iexecPocoContract[verifyFunction](...args)).to.be.true; - }); - - it(`Should fail to ${verifyFunction} when not presigned and invalid signature`, async () => { - const args = [ - appProvider.address, - appOrderHash, - ...(verifyFunction === 'verifyPresignature' - ? [] - : [ethers.Wallet.createRandom().signMessage(someMessage)]), - ]; - - expect(await iexecPocoContract[verifyFunction](...args)).to.be.false; - }); - - it(`Should fail to ${verifyFunction} with an incorrect account for presignature`, async () => { - await iexecPoco - .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) - .then((tx) => tx.wait()); - - const args = [ - anyone.address, - appOrderHash, - ...(verifyFunction === 'verifyPresignature' - ? [] - : [ethers.Wallet.createRandom().signMessage(someMessage)]), - ]; - - expect(await iexecPocoContract[verifyFunction](...args)).to.be.false; - }); + describe('Verify presignature', () => { + ['verifyPresignature', 'verifyPresignatureOrSignature'].forEach( + (verifyPreSignatureFunction) => { + it(`Should ${verifyPreSignatureFunction} when the presignature is valid`, async () => { + await iexecPoco + .connect(appProvider) + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) + .then((tx) => tx.wait()); + + const args = [ + appProvider.address, + appOrderHash, + ...(verifyPreSignatureFunction === 'verifyPresignature' ? [] : ['0x']), + ]; + + expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be.true; + }); - it(`Should fail to ${verifyFunction} for an unknown messageHash`, async () => { - const unknownMessageHash = ethers.utils.keccak256( - ethers.utils.toUtf8Bytes('unknown'), - ); + it(`Should fail to ${verifyPreSignatureFunction} when not presigned and invalid signature`, async () => { + const args = [ + appProvider.address, + appOrderHash, + ...(verifyPreSignatureFunction === 'verifyPresignature' + ? [] + : [ethers.Wallet.createRandom().signMessage(someMessage)]), + ]; + + expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be + .false; + }); - const args = [ - appProvider.address, - unknownMessageHash, - ...(verifyFunction === 'verifyPresignature' - ? [] - : [ethers.Wallet.createRandom().signMessage(unknownMessageHash)]), - ]; + it(`Should fail to ${verifyPreSignatureFunction} with an incorrect account for presignature`, async () => { + await iexecPoco + .connect(appProvider) + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) + .then((tx) => tx.wait()); + + const args = [ + anyone.address, + appOrderHash, + ...(verifyPreSignatureFunction === 'verifyPresignature' + ? [] + : [ethers.Wallet.createRandom().signMessage(someMessage)]), + ]; + + expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be + .false; + }); - expect(await iexecPocoContract[verifyFunction](...args)).to.be.false; - }); + it(`Should fail to ${verifyPreSignatureFunction} for an unknown messageHash`, async () => { + const unknownMessageHash = ethers.utils.keccak256( + ethers.utils.toUtf8Bytes('unknown'), + ); - it(`Should fail to ${verifyFunction} when account is address(0)`, async () => { - await iexecPoco - .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) - .then((tx) => tx.wait()); + const args = [ + appProvider.address, + unknownMessageHash, + ...(verifyPreSignatureFunction === 'verifyPresignature' + ? [] + : [ethers.Wallet.createRandom().signMessage(unknownMessageHash)]), + ]; - const args = [ - ethers.constants.AddressZero, - appOrderHash, - ...(verifyFunction === 'verifyPresignature' - ? [] - : [ethers.Wallet.createRandom().signMessage(someMessage)]), - ]; + expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be + .false; + }); - expect(await iexecPocoContract[verifyFunction](...args)).to.be.false; - }); - }); + it(`Should fail to ${verifyPreSignatureFunction} when account is address(0)`, async () => { + await iexecPoco + .connect(appProvider) + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) + .then((tx) => tx.wait()); + + const args = [ + ethers.constants.AddressZero, + appOrderHash, + ...(verifyPreSignatureFunction === 'verifyPresignature' + ? [] + : [ethers.Wallet.createRandom().signMessage(someMessage)]), + ]; + + expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be + .false; + }); + }, + ); }); describe('Match orders', () => { From a1e7c95a83d018591beb54db0d481304c5d2fd36 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Fri, 27 Sep 2024 09:14:36 +0200 Subject: [PATCH 07/17] create a loop through orders to cover all cases --- test/byContract/IexecPoco/IexecPoco1.test.ts | 228 ++++++++++++------- 1 file changed, 140 insertions(+), 88 deletions(-) diff --git a/test/byContract/IexecPoco/IexecPoco1.test.ts b/test/byContract/IexecPoco/IexecPoco1.test.ts index 45d3a1d59..2603fffba 100644 --- a/test/byContract/IexecPoco/IexecPoco1.test.ts +++ b/test/byContract/IexecPoco/IexecPoco1.test.ts @@ -13,6 +13,7 @@ import { IERC721__factory, IexecInterfaceNative, IexecInterfaceNative__factory, + IexecLibOrders_v5, IexecPocoAccessors__factory, OwnableMock, OwnableMock__factory, @@ -77,10 +78,22 @@ describe('IexecPoco1', () => { let ordersAssets: OrdersAssets; let ordersPrices: OrdersPrices; let orders: IexecOrders; - let appOrderHash: string; + let [appOrderHash, datasetOrderHash, workerpoolOrderHash, requestOrderHash]: string[] = []; let [randomAddress, randomSignature]: string[] = []; let randomContract: OwnableMock; let erc1271MockContract: ERC1271Mock; + let orderManagement: { + [key: string]: { + iexecPocoManageOrder: (orderArgs: any) => Promise; + iexecPocoManageOrderArgs: + | IexecLibOrders_v5.AppOrderOperationStruct + | IexecLibOrders_v5.DatasetOrderOperationStruct + | IexecLibOrders_v5.WorkerpoolOrderOperationStruct + | IexecLibOrders_v5.RequestOrderOperationStruct; + providerAddress: string; + orderHash: string; + }; + }; beforeEach('Deploy', async () => { // Deploy all contracts @@ -122,8 +135,47 @@ describe('IexecPoco1', () => { tag: teeDealTag, volume: volume, }); - appOrderHash = iexecWrapper.hashOrder(orders.app); - + ({ appOrderHash, datasetOrderHash, workerpoolOrderHash, requestOrderHash } = + iexecWrapper.hashOrders(orders)); + orderManagement = { + app: { + providerAddress: appProvider.address, + orderHash: appOrderHash, + iexecPocoManageOrder: (orderArgs) => + iexecPoco.connect(appProvider).manageAppOrder(orderArgs), + iexecPocoManageOrderArgs: createOrderOperation(orders.app, OrderOperationEnum.SIGN), + }, + dataset: { + providerAddress: datasetProvider.address, + orderHash: datasetOrderHash, + iexecPocoManageOrder: (orderArgs) => + iexecPoco.connect(datasetProvider).manageDatasetOrder(orderArgs), + iexecPocoManageOrderArgs: createOrderOperation( + orders.dataset, + OrderOperationEnum.SIGN, + ), + }, + workerpool: { + providerAddress: scheduler.address, + orderHash: workerpoolOrderHash, + iexecPocoManageOrder: (orderArgs) => + iexecPoco.connect(scheduler).manageWorkerpoolOrder(orderArgs), + iexecPocoManageOrderArgs: createOrderOperation( + orders.workerpool, + OrderOperationEnum.SIGN, + ), + }, + requester: { + providerAddress: requester.address, + orderHash: requestOrderHash, + iexecPocoManageOrder: (orderArgs) => + iexecPoco.connect(requester).manageRequestOrder(orderArgs), + iexecPocoManageOrderArgs: createOrderOperation( + orders.requester, + OrderOperationEnum.SIGN, + ), + }, + }; const randomWallet = ethers.Wallet.createRandom(); randomAddress = randomWallet.address; randomSignature = await randomWallet.signMessage('random'); @@ -216,91 +268,91 @@ describe('IexecPoco1', () => { }); }); - describe('Verify presignature', () => { - ['verifyPresignature', 'verifyPresignatureOrSignature'].forEach( - (verifyPreSignatureFunction) => { - it(`Should ${verifyPreSignatureFunction} when the presignature is valid`, async () => { - await iexecPoco - .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) - .then((tx) => tx.wait()); - - const args = [ - appProvider.address, - appOrderHash, - ...(verifyPreSignatureFunction === 'verifyPresignature' ? [] : ['0x']), - ]; - - expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be.true; - }); - - it(`Should fail to ${verifyPreSignatureFunction} when not presigned and invalid signature`, async () => { - const args = [ - appProvider.address, - appOrderHash, - ...(verifyPreSignatureFunction === 'verifyPresignature' - ? [] - : [ethers.Wallet.createRandom().signMessage(someMessage)]), - ]; - - expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be - .false; - }); - - it(`Should fail to ${verifyPreSignatureFunction} with an incorrect account for presignature`, async () => { - await iexecPoco - .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) - .then((tx) => tx.wait()); - - const args = [ - anyone.address, - appOrderHash, - ...(verifyPreSignatureFunction === 'verifyPresignature' - ? [] - : [ethers.Wallet.createRandom().signMessage(someMessage)]), - ]; - - expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be - .false; - }); - - it(`Should fail to ${verifyPreSignatureFunction} for an unknown messageHash`, async () => { - const unknownMessageHash = ethers.utils.keccak256( - ethers.utils.toUtf8Bytes('unknown'), - ); - - const args = [ - appProvider.address, - unknownMessageHash, - ...(verifyPreSignatureFunction === 'verifyPresignature' - ? [] - : [ethers.Wallet.createRandom().signMessage(unknownMessageHash)]), - ]; - - expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be - .false; - }); - - it(`Should fail to ${verifyPreSignatureFunction} when account is address(0)`, async () => { - await iexecPoco - .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)) - .then((tx) => tx.wait()); - - const args = [ - ethers.constants.AddressZero, - appOrderHash, - ...(verifyPreSignatureFunction === 'verifyPresignature' - ? [] - : [ethers.Wallet.createRandom().signMessage(someMessage)]), - ]; - - expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be - .false; - }); - }, - ); + describe.only('Verify presignature', () => { + ['app', 'dataset', 'workerpool', 'requester'].forEach((asset) => { + ['verifyPresignature', 'verifyPresignatureOrSignature'].forEach( + (verifyPreSignatureFunction) => { + it(`Should ${verifyPreSignatureFunction} when the presignature is valid for ${asset}`, async () => { + await orderManagement[asset] + .iexecPocoManageOrder(orderManagement[asset].iexecPocoManageOrderArgs) + .then((tx) => tx.wait()); + + const args = [ + orderManagement[asset].providerAddress, + orderManagement[asset].orderHash, + ...(verifyPreSignatureFunction === 'verifyPresignature' ? [] : ['0x']), + ]; + + expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be + .true; + }); + + it(`Should fail to ${verifyPreSignatureFunction} when not presigned and invalid signature for ${asset}`, async () => { + const args = [ + orderManagement[asset].providerAddress, + orderManagement[asset].orderHash, + ...(verifyPreSignatureFunction === 'verifyPresignature' + ? [] + : [ethers.Wallet.createRandom().signMessage('Some message')]), + ]; + + expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be + .false; + }); + + it(`Should fail to ${verifyPreSignatureFunction} with an incorrect account for presignature for ${asset}`, async () => { + await orderManagement[asset] + .iexecPocoManageOrder(orderManagement[asset].iexecPocoManageOrderArgs) + .then((tx) => tx.wait()); + + const args = [ + anyone.address, + orderManagement[asset].orderHash, + ...(verifyPreSignatureFunction === 'verifyPresignature' + ? [] + : [ethers.Wallet.createRandom().signMessage('Some message')]), + ]; + + expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be + .false; + }); + + it(`Should fail to ${verifyPreSignatureFunction} for an unknown messageHash for ${asset}`, async () => { + const unknownMessageHash = ethers.utils.keccak256( + ethers.utils.toUtf8Bytes('unknown'), + ); + + const args = [ + orderManagement[asset].providerAddress, + unknownMessageHash, + ...(verifyPreSignatureFunction === 'verifyPresignature' + ? [] + : [ethers.Wallet.createRandom().signMessage(unknownMessageHash)]), + ]; + + expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be + .false; + }); + + it(`Should fail to ${verifyPreSignatureFunction} when account is address(0) for ${asset}`, async () => { + await orderManagement[asset] + .iexecPocoManageOrder(orderManagement[asset].iexecPocoManageOrderArgs) + .then((tx) => tx.wait()); + + const args = [ + AddressZero, + orderManagement[asset].orderHash, + ...(verifyPreSignatureFunction === 'verifyPresignature' + ? [] + : [ethers.Wallet.createRandom().signMessage('Some message')]), + ]; + + expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be + .false; + }); + }, + ); + }); }); describe('Match orders', () => { From 8a9a8343f5d43cefb2cc4703b1221176bdbf6cce Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Fri, 27 Sep 2024 09:14:55 +0200 Subject: [PATCH 08/17] remove describe only --- test/byContract/IexecPoco/IexecPoco1.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/byContract/IexecPoco/IexecPoco1.test.ts b/test/byContract/IexecPoco/IexecPoco1.test.ts index 2603fffba..77f24563c 100644 --- a/test/byContract/IexecPoco/IexecPoco1.test.ts +++ b/test/byContract/IexecPoco/IexecPoco1.test.ts @@ -268,7 +268,7 @@ describe('IexecPoco1', () => { }); }); - describe.only('Verify presignature', () => { + describe('Verify presignature', () => { ['app', 'dataset', 'workerpool', 'requester'].forEach((asset) => { ['verifyPresignature', 'verifyPresignatureOrSignature'].forEach( (verifyPreSignatureFunction) => { From 5a18bfd178e0622113baf5a68ef4284ab0b11b3e Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Fri, 27 Sep 2024 10:37:56 +0200 Subject: [PATCH 09/17] combine tx function and args and set const for repetitive allocation --- test/byContract/IexecPoco/IexecPoco1.test.ts | 88 ++++++++++---------- 1 file changed, 43 insertions(+), 45 deletions(-) diff --git a/test/byContract/IexecPoco/IexecPoco1.test.ts b/test/byContract/IexecPoco/IexecPoco1.test.ts index 77f24563c..64a9127ae 100644 --- a/test/byContract/IexecPoco/IexecPoco1.test.ts +++ b/test/byContract/IexecPoco/IexecPoco1.test.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { AddressZero, HashZero } from '@ethersproject/constants'; -import { Contract } from '@ethersproject/contracts'; +import { Contract, ContractTransaction } from '@ethersproject/contracts'; import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; import { ethers, expect } from 'hardhat'; @@ -13,7 +13,6 @@ import { IERC721__factory, IexecInterfaceNative, IexecInterfaceNative__factory, - IexecLibOrders_v5, IexecPocoAccessors__factory, OwnableMock, OwnableMock__factory, @@ -82,14 +81,12 @@ describe('IexecPoco1', () => { let [randomAddress, randomSignature]: string[] = []; let randomContract: OwnableMock; let erc1271MockContract: ERC1271Mock; + let iexecPocoManageOrderTx: () => Promise; + let providerAddress: string; + let orderHash: string; let orderManagement: { [key: string]: { - iexecPocoManageOrder: (orderArgs: any) => Promise; - iexecPocoManageOrderArgs: - | IexecLibOrders_v5.AppOrderOperationStruct - | IexecLibOrders_v5.DatasetOrderOperationStruct - | IexecLibOrders_v5.WorkerpoolOrderOperationStruct - | IexecLibOrders_v5.RequestOrderOperationStruct; + iexecPocoManageOrderTx: () => Promise; providerAddress: string; orderHash: string; }; @@ -141,39 +138,40 @@ describe('IexecPoco1', () => { app: { providerAddress: appProvider.address, orderHash: appOrderHash, - iexecPocoManageOrder: (orderArgs) => - iexecPoco.connect(appProvider).manageAppOrder(orderArgs), - iexecPocoManageOrderArgs: createOrderOperation(orders.app, OrderOperationEnum.SIGN), + iexecPocoManageOrderTx: () => + iexecPoco + .connect(appProvider) + .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)), }, dataset: { providerAddress: datasetProvider.address, orderHash: datasetOrderHash, - iexecPocoManageOrder: (orderArgs) => - iexecPoco.connect(datasetProvider).manageDatasetOrder(orderArgs), - iexecPocoManageOrderArgs: createOrderOperation( - orders.dataset, - OrderOperationEnum.SIGN, - ), + iexecPocoManageOrderTx: () => + iexecPoco + .connect(datasetProvider) + .manageDatasetOrder( + createOrderOperation(orders.dataset, OrderOperationEnum.SIGN), + ), }, workerpool: { providerAddress: scheduler.address, orderHash: workerpoolOrderHash, - iexecPocoManageOrder: (orderArgs) => - iexecPoco.connect(scheduler).manageWorkerpoolOrder(orderArgs), - iexecPocoManageOrderArgs: createOrderOperation( - orders.workerpool, - OrderOperationEnum.SIGN, - ), + iexecPocoManageOrderTx: () => + iexecPoco + .connect(scheduler) + .manageWorkerpoolOrder( + createOrderOperation(orders.workerpool, OrderOperationEnum.SIGN), + ), }, requester: { providerAddress: requester.address, orderHash: requestOrderHash, - iexecPocoManageOrder: (orderArgs) => - iexecPoco.connect(requester).manageRequestOrder(orderArgs), - iexecPocoManageOrderArgs: createOrderOperation( - orders.requester, - OrderOperationEnum.SIGN, - ), + iexecPocoManageOrderTx: () => + iexecPoco + .connect(requester) + .manageRequestOrder( + createOrderOperation(orders.requester, OrderOperationEnum.SIGN), + ), }, }; const randomWallet = ethers.Wallet.createRandom(); @@ -272,14 +270,18 @@ describe('IexecPoco1', () => { ['app', 'dataset', 'workerpool', 'requester'].forEach((asset) => { ['verifyPresignature', 'verifyPresignatureOrSignature'].forEach( (verifyPreSignatureFunction) => { + beforeEach(() => { + providerAddress = orderManagement[asset].providerAddress; + orderHash = orderManagement[asset].orderHash; + iexecPocoManageOrderTx = orderManagement[asset].iexecPocoManageOrderTx; + }); + it(`Should ${verifyPreSignatureFunction} when the presignature is valid for ${asset}`, async () => { - await orderManagement[asset] - .iexecPocoManageOrder(orderManagement[asset].iexecPocoManageOrderArgs) - .then((tx) => tx.wait()); + await iexecPocoManageOrderTx().then((tx) => tx.wait()); const args = [ - orderManagement[asset].providerAddress, - orderManagement[asset].orderHash, + providerAddress, + orderHash, ...(verifyPreSignatureFunction === 'verifyPresignature' ? [] : ['0x']), ]; @@ -289,8 +291,8 @@ describe('IexecPoco1', () => { it(`Should fail to ${verifyPreSignatureFunction} when not presigned and invalid signature for ${asset}`, async () => { const args = [ - orderManagement[asset].providerAddress, - orderManagement[asset].orderHash, + providerAddress, + orderHash, ...(verifyPreSignatureFunction === 'verifyPresignature' ? [] : [ethers.Wallet.createRandom().signMessage('Some message')]), @@ -301,13 +303,11 @@ describe('IexecPoco1', () => { }); it(`Should fail to ${verifyPreSignatureFunction} with an incorrect account for presignature for ${asset}`, async () => { - await orderManagement[asset] - .iexecPocoManageOrder(orderManagement[asset].iexecPocoManageOrderArgs) - .then((tx) => tx.wait()); + await iexecPocoManageOrderTx().then((tx) => tx.wait()); const args = [ anyone.address, - orderManagement[asset].orderHash, + orderHash, ...(verifyPreSignatureFunction === 'verifyPresignature' ? [] : [ethers.Wallet.createRandom().signMessage('Some message')]), @@ -323,7 +323,7 @@ describe('IexecPoco1', () => { ); const args = [ - orderManagement[asset].providerAddress, + providerAddress, unknownMessageHash, ...(verifyPreSignatureFunction === 'verifyPresignature' ? [] @@ -335,13 +335,11 @@ describe('IexecPoco1', () => { }); it(`Should fail to ${verifyPreSignatureFunction} when account is address(0) for ${asset}`, async () => { - await orderManagement[asset] - .iexecPocoManageOrder(orderManagement[asset].iexecPocoManageOrderArgs) - .then((tx) => tx.wait()); + await iexecPocoManageOrderTx().then((tx) => tx.wait()); const args = [ AddressZero, - orderManagement[asset].orderHash, + orderHash, ...(verifyPreSignatureFunction === 'verifyPresignature' ? [] : [ethers.Wallet.createRandom().signMessage('Some message')]), From 4628930e8deeca1988294f42beb4e21ffecfc606 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Fri, 27 Sep 2024 11:19:53 +0200 Subject: [PATCH 10/17] remove OrderHash and save directly order and compute single orderHash --- test/byContract/IexecPoco/IexecPoco1.test.ts | 26 +++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/test/byContract/IexecPoco/IexecPoco1.test.ts b/test/byContract/IexecPoco/IexecPoco1.test.ts index 64a9127ae..0b065d4e1 100644 --- a/test/byContract/IexecPoco/IexecPoco1.test.ts +++ b/test/byContract/IexecPoco/IexecPoco1.test.ts @@ -13,6 +13,7 @@ import { IERC721__factory, IexecInterfaceNative, IexecInterfaceNative__factory, + IexecLibOrders_v5, IexecPocoAccessors__factory, OwnableMock, OwnableMock__factory, @@ -77,18 +78,26 @@ describe('IexecPoco1', () => { let ordersAssets: OrdersAssets; let ordersPrices: OrdersPrices; let orders: IexecOrders; - let [appOrderHash, datasetOrderHash, workerpoolOrderHash, requestOrderHash]: string[] = []; let [randomAddress, randomSignature]: string[] = []; let randomContract: OwnableMock; let erc1271MockContract: ERC1271Mock; let iexecPocoManageOrderTx: () => Promise; let providerAddress: string; + let order: + | IexecLibOrders_v5.AppOrderStruct + | IexecLibOrders_v5.DatasetOrderStruct + | IexecLibOrders_v5.WorkerpoolOrderStruct + | IexecLibOrders_v5.RequestOrderStruct; let orderHash: string; let orderManagement: { [key: string]: { iexecPocoManageOrderTx: () => Promise; providerAddress: string; - orderHash: string; + order: + | IexecLibOrders_v5.AppOrderStruct + | IexecLibOrders_v5.DatasetOrderStruct + | IexecLibOrders_v5.WorkerpoolOrderStruct + | IexecLibOrders_v5.RequestOrderStruct; }; }; @@ -132,12 +141,10 @@ describe('IexecPoco1', () => { tag: teeDealTag, volume: volume, }); - ({ appOrderHash, datasetOrderHash, workerpoolOrderHash, requestOrderHash } = - iexecWrapper.hashOrders(orders)); orderManagement = { app: { providerAddress: appProvider.address, - orderHash: appOrderHash, + order: orders.app, iexecPocoManageOrderTx: () => iexecPoco .connect(appProvider) @@ -145,7 +152,7 @@ describe('IexecPoco1', () => { }, dataset: { providerAddress: datasetProvider.address, - orderHash: datasetOrderHash, + order: orders.dataset, iexecPocoManageOrderTx: () => iexecPoco .connect(datasetProvider) @@ -155,7 +162,7 @@ describe('IexecPoco1', () => { }, workerpool: { providerAddress: scheduler.address, - orderHash: workerpoolOrderHash, + order: orders.workerpool, iexecPocoManageOrderTx: () => iexecPoco .connect(scheduler) @@ -165,7 +172,7 @@ describe('IexecPoco1', () => { }, requester: { providerAddress: requester.address, - orderHash: requestOrderHash, + order: orders.requester, iexecPocoManageOrderTx: () => iexecPoco .connect(requester) @@ -272,7 +279,8 @@ describe('IexecPoco1', () => { (verifyPreSignatureFunction) => { beforeEach(() => { providerAddress = orderManagement[asset].providerAddress; - orderHash = orderManagement[asset].orderHash; + order = orderManagement[asset].order; + orderHash = iexecWrapper.hashOrder(order); iexecPocoManageOrderTx = orderManagement[asset].iexecPocoManageOrderTx; }); From ae06e0fd489937d6afd93fb56c08b7716f7da4fa Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Fri, 27 Sep 2024 14:09:19 +0200 Subject: [PATCH 11/17] integarate orderManagement in before each of the specific test describe --- test/byContract/IexecPoco/IexecPoco1.test.ts | 94 +++++++++++--------- 1 file changed, 54 insertions(+), 40 deletions(-) diff --git a/test/byContract/IexecPoco/IexecPoco1.test.ts b/test/byContract/IexecPoco/IexecPoco1.test.ts index 0b065d4e1..98879a841 100644 --- a/test/byContract/IexecPoco/IexecPoco1.test.ts +++ b/test/byContract/IexecPoco/IexecPoco1.test.ts @@ -141,46 +141,6 @@ describe('IexecPoco1', () => { tag: teeDealTag, volume: volume, }); - orderManagement = { - app: { - providerAddress: appProvider.address, - order: orders.app, - iexecPocoManageOrderTx: () => - iexecPoco - .connect(appProvider) - .manageAppOrder(createOrderOperation(orders.app, OrderOperationEnum.SIGN)), - }, - dataset: { - providerAddress: datasetProvider.address, - order: orders.dataset, - iexecPocoManageOrderTx: () => - iexecPoco - .connect(datasetProvider) - .manageDatasetOrder( - createOrderOperation(orders.dataset, OrderOperationEnum.SIGN), - ), - }, - workerpool: { - providerAddress: scheduler.address, - order: orders.workerpool, - iexecPocoManageOrderTx: () => - iexecPoco - .connect(scheduler) - .manageWorkerpoolOrder( - createOrderOperation(orders.workerpool, OrderOperationEnum.SIGN), - ), - }, - requester: { - providerAddress: requester.address, - order: orders.requester, - iexecPocoManageOrderTx: () => - iexecPoco - .connect(requester) - .manageRequestOrder( - createOrderOperation(orders.requester, OrderOperationEnum.SIGN), - ), - }, - }; const randomWallet = ethers.Wallet.createRandom(); randomAddress = randomWallet.address; randomSignature = await randomWallet.signMessage('random'); @@ -278,6 +238,60 @@ describe('IexecPoco1', () => { ['verifyPresignature', 'verifyPresignatureOrSignature'].forEach( (verifyPreSignatureFunction) => { beforeEach(() => { + orderManagement = { + app: { + providerAddress: appProvider.address, + order: orders.app, + iexecPocoManageOrderTx: () => + iexecPoco + .connect(appProvider) + .manageAppOrder( + createOrderOperation( + orders.app, + OrderOperationEnum.SIGN, + ), + ), + }, + dataset: { + providerAddress: datasetProvider.address, + order: orders.dataset, + iexecPocoManageOrderTx: () => + iexecPoco + .connect(datasetProvider) + .manageDatasetOrder( + createOrderOperation( + orders.dataset, + OrderOperationEnum.SIGN, + ), + ), + }, + workerpool: { + providerAddress: scheduler.address, + order: orders.workerpool, + iexecPocoManageOrderTx: () => + iexecPoco + .connect(scheduler) + .manageWorkerpoolOrder( + createOrderOperation( + orders.workerpool, + OrderOperationEnum.SIGN, + ), + ), + }, + requester: { + providerAddress: requester.address, + order: orders.requester, + iexecPocoManageOrderTx: () => + iexecPoco + .connect(requester) + .manageRequestOrder( + createOrderOperation( + orders.requester, + OrderOperationEnum.SIGN, + ), + ), + }, + }; providerAddress = orderManagement[asset].providerAddress; order = orderManagement[asset].order; orderHash = iexecWrapper.hashOrder(order); From 010a5b76c3e21a1c85bb7adb40471059e506cfae Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Fri, 27 Sep 2024 15:53:05 +0200 Subject: [PATCH 12/17] set orderManagement to a before section to run only once --- test/byContract/IexecPoco/IexecPoco1.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/byContract/IexecPoco/IexecPoco1.test.ts b/test/byContract/IexecPoco/IexecPoco1.test.ts index 98879a841..310204271 100644 --- a/test/byContract/IexecPoco/IexecPoco1.test.ts +++ b/test/byContract/IexecPoco/IexecPoco1.test.ts @@ -237,7 +237,7 @@ describe('IexecPoco1', () => { ['app', 'dataset', 'workerpool', 'requester'].forEach((asset) => { ['verifyPresignature', 'verifyPresignatureOrSignature'].forEach( (verifyPreSignatureFunction) => { - beforeEach(() => { + before(() => { orderManagement = { app: { providerAddress: appProvider.address, @@ -292,6 +292,9 @@ describe('IexecPoco1', () => { ), }, }; + }); + + beforeEach(() => { providerAddress = orderManagement[asset].providerAddress; order = orderManagement[asset].order; orderHash = iexecWrapper.hashOrder(order); From d732be76fed2a15d34d2fd346e07e5a9f64489af Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Fri, 27 Sep 2024 15:55:07 +0200 Subject: [PATCH 13/17] rename to iexecPocoSignManageOrder --- test/byContract/IexecPoco/IexecPoco1.test.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/byContract/IexecPoco/IexecPoco1.test.ts b/test/byContract/IexecPoco/IexecPoco1.test.ts index 310204271..4be88e6f0 100644 --- a/test/byContract/IexecPoco/IexecPoco1.test.ts +++ b/test/byContract/IexecPoco/IexecPoco1.test.ts @@ -81,7 +81,7 @@ describe('IexecPoco1', () => { let [randomAddress, randomSignature]: string[] = []; let randomContract: OwnableMock; let erc1271MockContract: ERC1271Mock; - let iexecPocoManageOrderTx: () => Promise; + let iexecPocoSignManageOrder: () => Promise; let providerAddress: string; let order: | IexecLibOrders_v5.AppOrderStruct @@ -91,7 +91,7 @@ describe('IexecPoco1', () => { let orderHash: string; let orderManagement: { [key: string]: { - iexecPocoManageOrderTx: () => Promise; + iexecPocoSignManageOrder: () => Promise; providerAddress: string; order: | IexecLibOrders_v5.AppOrderStruct @@ -242,7 +242,7 @@ describe('IexecPoco1', () => { app: { providerAddress: appProvider.address, order: orders.app, - iexecPocoManageOrderTx: () => + iexecPocoSignManageOrder: () => iexecPoco .connect(appProvider) .manageAppOrder( @@ -255,7 +255,7 @@ describe('IexecPoco1', () => { dataset: { providerAddress: datasetProvider.address, order: orders.dataset, - iexecPocoManageOrderTx: () => + iexecPocoSignManageOrder: () => iexecPoco .connect(datasetProvider) .manageDatasetOrder( @@ -268,7 +268,7 @@ describe('IexecPoco1', () => { workerpool: { providerAddress: scheduler.address, order: orders.workerpool, - iexecPocoManageOrderTx: () => + iexecPocoSignManageOrder: () => iexecPoco .connect(scheduler) .manageWorkerpoolOrder( @@ -281,7 +281,7 @@ describe('IexecPoco1', () => { requester: { providerAddress: requester.address, order: orders.requester, - iexecPocoManageOrderTx: () => + iexecPocoSignManageOrder: () => iexecPoco .connect(requester) .manageRequestOrder( @@ -298,11 +298,11 @@ describe('IexecPoco1', () => { providerAddress = orderManagement[asset].providerAddress; order = orderManagement[asset].order; orderHash = iexecWrapper.hashOrder(order); - iexecPocoManageOrderTx = orderManagement[asset].iexecPocoManageOrderTx; + iexecPocoSignManageOrder = orderManagement[asset].iexecPocoSignManageOrder; }); it(`Should ${verifyPreSignatureFunction} when the presignature is valid for ${asset}`, async () => { - await iexecPocoManageOrderTx().then((tx) => tx.wait()); + await iexecPocoSignManageOrder().then((tx) => tx.wait()); const args = [ providerAddress, @@ -328,7 +328,7 @@ describe('IexecPoco1', () => { }); it(`Should fail to ${verifyPreSignatureFunction} with an incorrect account for presignature for ${asset}`, async () => { - await iexecPocoManageOrderTx().then((tx) => tx.wait()); + await iexecPocoSignManageOrder().then((tx) => tx.wait()); const args = [ anyone.address, @@ -360,7 +360,7 @@ describe('IexecPoco1', () => { }); it(`Should fail to ${verifyPreSignatureFunction} when account is address(0) for ${asset}`, async () => { - await iexecPocoManageOrderTx().then((tx) => tx.wait()); + await iexecPocoSignManageOrder().then((tx) => tx.wait()); const args = [ AddressZero, From b4d5cd2b140fe91106aa8625ade197dc301d33bd Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Fri, 27 Sep 2024 15:55:47 +0200 Subject: [PATCH 14/17] clean --- test/byContract/IexecPoco/IexecPoco1.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/byContract/IexecPoco/IexecPoco1.test.ts b/test/byContract/IexecPoco/IexecPoco1.test.ts index 4be88e6f0..395c89e2e 100644 --- a/test/byContract/IexecPoco/IexecPoco1.test.ts +++ b/test/byContract/IexecPoco/IexecPoco1.test.ts @@ -295,10 +295,9 @@ describe('IexecPoco1', () => { }); beforeEach(() => { - providerAddress = orderManagement[asset].providerAddress; - order = orderManagement[asset].order; + ({ providerAddress, order, iexecPocoSignManageOrder } = + orderManagement[asset]); orderHash = iexecWrapper.hashOrder(order); - iexecPocoSignManageOrder = orderManagement[asset].iexecPocoSignManageOrder; }); it(`Should ${verifyPreSignatureFunction} when the presignature is valid for ${asset}`, async () => { From e71bf599f3e84f5231dc89d73962d6140beac06f Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Fri, 27 Sep 2024 16:45:29 +0200 Subject: [PATCH 15/17] set before each in each it block --- test/byContract/IexecPoco/IexecPoco1.test.ts | 139 ++++++++----------- 1 file changed, 57 insertions(+), 82 deletions(-) diff --git a/test/byContract/IexecPoco/IexecPoco1.test.ts b/test/byContract/IexecPoco/IexecPoco1.test.ts index 395c89e2e..1dca1a8e3 100644 --- a/test/byContract/IexecPoco/IexecPoco1.test.ts +++ b/test/byContract/IexecPoco/IexecPoco1.test.ts @@ -235,72 +235,60 @@ describe('IexecPoco1', () => { describe('Verify presignature', () => { ['app', 'dataset', 'workerpool', 'requester'].forEach((asset) => { + before(() => { + orderManagement = { + app: { + providerAddress: appProvider.address, + order: orders.app, + iexecPocoSignManageOrder: () => + iexecPoco + .connect(appProvider) + .manageAppOrder( + createOrderOperation(orders.app, OrderOperationEnum.SIGN), + ), + }, + dataset: { + providerAddress: datasetProvider.address, + order: orders.dataset, + iexecPocoSignManageOrder: () => + iexecPoco + .connect(datasetProvider) + .manageDatasetOrder( + createOrderOperation(orders.dataset, OrderOperationEnum.SIGN), + ), + }, + workerpool: { + providerAddress: scheduler.address, + order: orders.workerpool, + iexecPocoSignManageOrder: () => + iexecPoco + .connect(scheduler) + .manageWorkerpoolOrder( + createOrderOperation( + orders.workerpool, + OrderOperationEnum.SIGN, + ), + ), + }, + requester: { + providerAddress: requester.address, + order: orders.requester, + iexecPocoSignManageOrder: () => + iexecPoco + .connect(requester) + .manageRequestOrder( + createOrderOperation(orders.requester, OrderOperationEnum.SIGN), + ), + }, + }; + }); + ['verifyPresignature', 'verifyPresignatureOrSignature'].forEach( (verifyPreSignatureFunction) => { - before(() => { - orderManagement = { - app: { - providerAddress: appProvider.address, - order: orders.app, - iexecPocoSignManageOrder: () => - iexecPoco - .connect(appProvider) - .manageAppOrder( - createOrderOperation( - orders.app, - OrderOperationEnum.SIGN, - ), - ), - }, - dataset: { - providerAddress: datasetProvider.address, - order: orders.dataset, - iexecPocoSignManageOrder: () => - iexecPoco - .connect(datasetProvider) - .manageDatasetOrder( - createOrderOperation( - orders.dataset, - OrderOperationEnum.SIGN, - ), - ), - }, - workerpool: { - providerAddress: scheduler.address, - order: orders.workerpool, - iexecPocoSignManageOrder: () => - iexecPoco - .connect(scheduler) - .manageWorkerpoolOrder( - createOrderOperation( - orders.workerpool, - OrderOperationEnum.SIGN, - ), - ), - }, - requester: { - providerAddress: requester.address, - order: orders.requester, - iexecPocoSignManageOrder: () => - iexecPoco - .connect(requester) - .manageRequestOrder( - createOrderOperation( - orders.requester, - OrderOperationEnum.SIGN, - ), - ), - }, - }; - }); - - beforeEach(() => { - ({ providerAddress, order, iexecPocoSignManageOrder } = - orderManagement[asset]); - orderHash = iexecWrapper.hashOrder(order); - }); - it(`Should ${verifyPreSignatureFunction} when the presignature is valid for ${asset}`, async () => { + const { providerAddress, order, iexecPocoSignManageOrder } = + orderManagement[asset]; + const orderHash = iexecWrapper.hashOrder(order); await iexecPocoSignManageOrder().then((tx) => tx.wait()); const args = [ @@ -308,12 +296,14 @@ describe('IexecPoco1', () => { orderHash, ...(verifyPreSignatureFunction === 'verifyPresignature' ? [] : ['0x']), ]; - expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be .true; }); it(`Should fail to ${verifyPreSignatureFunction} when not presigned and invalid signature for ${asset}`, async () => { + const { providerAddress, order } = orderManagement[asset]; + const orderHash = iexecWrapper.hashOrder(order); + const args = [ providerAddress, orderHash, @@ -321,12 +311,13 @@ describe('IexecPoco1', () => { ? [] : [ethers.Wallet.createRandom().signMessage('Some message')]), ]; - expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be .false; }); it(`Should fail to ${verifyPreSignatureFunction} with an incorrect account for presignature for ${asset}`, async () => { + const { order, iexecPocoSignManageOrder } = orderManagement[asset]; + const orderHash = iexecWrapper.hashOrder(order); await iexecPocoSignManageOrder().then((tx) => tx.wait()); const args = [ @@ -336,12 +327,12 @@ describe('IexecPoco1', () => { ? [] : [ethers.Wallet.createRandom().signMessage('Some message')]), ]; - expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be .false; }); it(`Should fail to ${verifyPreSignatureFunction} for an unknown messageHash for ${asset}`, async () => { + const { providerAddress } = orderManagement[asset]; const unknownMessageHash = ethers.utils.keccak256( ethers.utils.toUtf8Bytes('unknown'), ); @@ -353,22 +344,6 @@ describe('IexecPoco1', () => { ? [] : [ethers.Wallet.createRandom().signMessage(unknownMessageHash)]), ]; - - expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be - .false; - }); - - it(`Should fail to ${verifyPreSignatureFunction} when account is address(0) for ${asset}`, async () => { - await iexecPocoSignManageOrder().then((tx) => tx.wait()); - - const args = [ - AddressZero, - orderHash, - ...(verifyPreSignatureFunction === 'verifyPresignature' - ? [] - : [ethers.Wallet.createRandom().signMessage('Some message')]), - ]; - expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be .false; }); From 63794219289c9658da042b3a931caab17d5aff2a Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Fri, 27 Sep 2024 16:46:00 +0200 Subject: [PATCH 16/17] typo --- test/byContract/IexecPoco/IexecPoco1.test.ts | 26 ++++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/byContract/IexecPoco/IexecPoco1.test.ts b/test/byContract/IexecPoco/IexecPoco1.test.ts index 1dca1a8e3..06936df37 100644 --- a/test/byContract/IexecPoco/IexecPoco1.test.ts +++ b/test/byContract/IexecPoco/IexecPoco1.test.ts @@ -284,8 +284,8 @@ describe('IexecPoco1', () => { }); ['verifyPresignature', 'verifyPresignatureOrSignature'].forEach( - (verifyPreSignatureFunction) => { - it(`Should ${verifyPreSignatureFunction} when the presignature is valid for ${asset}`, async () => { + (verifyPresignatureFunction) => { + it(`Should ${verifyPresignatureFunction} when the presignature is valid for ${asset}`, async () => { const { providerAddress, order, iexecPocoSignManageOrder } = orderManagement[asset]; const orderHash = iexecWrapper.hashOrder(order); @@ -294,28 +294,28 @@ describe('IexecPoco1', () => { const args = [ providerAddress, orderHash, - ...(verifyPreSignatureFunction === 'verifyPresignature' ? [] : ['0x']), + ...(verifyPresignatureFunction === 'verifyPresignature' ? [] : ['0x']), ]; - expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be + expect(await iexecPocoContract[verifyPresignatureFunction](...args)).to.be .true; }); - it(`Should fail to ${verifyPreSignatureFunction} when not presigned and invalid signature for ${asset}`, async () => { + it(`Should fail to ${verifyPresignatureFunction} when not presigned and invalid signature for ${asset}`, async () => { const { providerAddress, order } = orderManagement[asset]; const orderHash = iexecWrapper.hashOrder(order); const args = [ providerAddress, orderHash, - ...(verifyPreSignatureFunction === 'verifyPresignature' + ...(verifyPresignatureFunction === 'verifyPresignature' ? [] : [ethers.Wallet.createRandom().signMessage('Some message')]), ]; - expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be + expect(await iexecPocoContract[verifyPresignatureFunction](...args)).to.be .false; }); - it(`Should fail to ${verifyPreSignatureFunction} with an incorrect account for presignature for ${asset}`, async () => { + it(`Should fail to ${verifyPresignatureFunction} with an incorrect account for presignature for ${asset}`, async () => { const { order, iexecPocoSignManageOrder } = orderManagement[asset]; const orderHash = iexecWrapper.hashOrder(order); await iexecPocoSignManageOrder().then((tx) => tx.wait()); @@ -323,15 +323,15 @@ describe('IexecPoco1', () => { const args = [ anyone.address, orderHash, - ...(verifyPreSignatureFunction === 'verifyPresignature' + ...(verifyPresignatureFunction === 'verifyPresignature' ? [] : [ethers.Wallet.createRandom().signMessage('Some message')]), ]; - expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be + expect(await iexecPocoContract[verifyPresignatureFunction](...args)).to.be .false; }); - it(`Should fail to ${verifyPreSignatureFunction} for an unknown messageHash for ${asset}`, async () => { + it(`Should fail to ${verifyPresignatureFunction} for an unknown messageHash for ${asset}`, async () => { const { providerAddress } = orderManagement[asset]; const unknownMessageHash = ethers.utils.keccak256( ethers.utils.toUtf8Bytes('unknown'), @@ -340,11 +340,11 @@ describe('IexecPoco1', () => { const args = [ providerAddress, unknownMessageHash, - ...(verifyPreSignatureFunction === 'verifyPresignature' + ...(verifyPresignatureFunction === 'verifyPresignature' ? [] : [ethers.Wallet.createRandom().signMessage(unknownMessageHash)]), ]; - expect(await iexecPocoContract[verifyPreSignatureFunction](...args)).to.be + expect(await iexecPocoContract[verifyPresignatureFunction](...args)).to.be .false; }); }, From 571aadf0bef75a8aaf4ebe3edccd426c06d475c8 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Fri, 27 Sep 2024 17:07:42 +0200 Subject: [PATCH 17/17] remove useless vars --- test/byContract/IexecPoco/IexecPoco1.test.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/byContract/IexecPoco/IexecPoco1.test.ts b/test/byContract/IexecPoco/IexecPoco1.test.ts index 06936df37..1d91ea497 100644 --- a/test/byContract/IexecPoco/IexecPoco1.test.ts +++ b/test/byContract/IexecPoco/IexecPoco1.test.ts @@ -81,14 +81,6 @@ describe('IexecPoco1', () => { let [randomAddress, randomSignature]: string[] = []; let randomContract: OwnableMock; let erc1271MockContract: ERC1271Mock; - let iexecPocoSignManageOrder: () => Promise; - let providerAddress: string; - let order: - | IexecLibOrders_v5.AppOrderStruct - | IexecLibOrders_v5.DatasetOrderStruct - | IexecLibOrders_v5.WorkerpoolOrderStruct - | IexecLibOrders_v5.RequestOrderStruct; - let orderHash: string; let orderManagement: { [key: string]: { iexecPocoSignManageOrder: () => Promise;