Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
test/byContract/IexecOrderManagement/** \
test/byContract/IexecRelay/** \
test/byContract/IexecPoco/** \
test/byContract/IexecPocoBoost/** \
test/byContract/registries/** \
test/*fullchain*
- name: Run deployment
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- test/*fullchain* (#190, #196)
- IexecAccessors (#189, #191, #196)
- IexecPoco (#196)
- IexecPocoBoost (#198)
- Migrate scripts to TypeScript: (#184)
- `getFunctionSignatures.js`, `common-test-snapshot.js`, `test-storage.js`, `timelock.js`
- Migrated utility files to TypeScript : (#183)
Expand Down
8 changes: 4 additions & 4 deletions test/000_fullchain-boost.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ describe('IexecPocoBoostDelegate (IT)', function () {
expect(deal.workerReward)
.to.be.equal((workerpoolPrice * (100n - schedulerRewardRatio)) / 100n)
.to.be.greaterThan(0);
expect(deal.deadline).to.be.equal(startTime + 7 * 300); // Category 0
expect(deal.deadline).to.be.equal(startTime + 7n * 300n); // Category 0
expect(deal.botFirst).to.be.equal(0);
expect(deal.botSize).to.be.equal(1);
expect(deal.shortTag).to.be.equal('0x000001');
Expand Down Expand Up @@ -375,7 +375,7 @@ describe('IexecPocoBoostDelegate (IT)', function () {
expect(deal.workerReward)
.to.be.equal((workerpoolPrice * (100n - schedulerRewardRatio)) / 100n)
.to.be.greaterThan(0);
expect(deal.deadline).to.be.equal(startTime + 7 * 300); // Category 0
expect(deal.deadline).to.be.equal(startTime + 7n * 300n); // Category 0
expect(deal.botFirst).to.be.equal(0);
expect(deal.botSize).to.be.equal(1);
expect(deal.shortTag).to.be.equal('0x000001');
Expand Down Expand Up @@ -649,7 +649,7 @@ describe('IexecPocoBoostDelegate (IT)', function () {
expect(await iexecInstance.frozenOf(scheduler.address)).to.be.equal(schedulerDealStake);
expect(await iexecInstance.balanceOf(kittyAddress)).to.be.equal(0);
expect(await iexecInstance.frozenOf(kittyAddress)).to.be.equal(0);
await time.setNextBlockTimestamp(startTime + 7 * 300);
await time.setNextBlockTimestamp(startTime + 7n * 300n);

await expect(iexecPocoBoostInstance.connect(worker).claimBoost(dealId, taskIndex))
.to.emit(iexecPocoBoostInstance, 'Transfer')
Expand Down Expand Up @@ -730,7 +730,7 @@ describe('IexecPocoBoostDelegate (IT)', function () {
expect(await iexecInstance.frozenOf(scheduler.address)).to.be.equal(schedulerDealStake);
expect(await iexecInstance.balanceOf(kittyAddress)).to.be.equal(0);
expect(await iexecInstance.frozenOf(kittyAddress)).to.be.equal(0);
await time.setNextBlockTimestamp(startTime + 7 * 300);
await time.setNextBlockTimestamp(startTime + 7n * 300n);

await expect(iexecPocoBoostInstance.connect(anyone).claimBoost(dealId, taskIndex))
.to.emit(iexecPocoBoostInstance, 'Transfer')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const appPrice = 1000n;
const datasetPrice = 1_000_000n;
const workerpoolPrice = 1_000_000_000n;
const taskPrice = appPrice + datasetPrice + workerpoolPrice;
const timeRef = CONFIG.categories[0].workClockTimeRef;
const timeRef = BigInt(CONFIG.categories[0].workClockTimeRef);
const trust = 1;
const volume = 1n;
const teeDealTag = '0x0000000000000000000000000000000000000000000000000000000000000001';
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('IexecPoco2#contributeAndFinalize', () => {
const task = await iexecPoco.viewTask(taskId);
expect(task.status).to.equal(TaskStatusEnum.COMPLETED);
expect(task.consensusValue).to.equal(resultHash);
expect(task.revealDeadline).to.equal(contributeAndFinalizeBlockTimestamp + timeRef * 2);
expect(task.revealDeadline).to.equal(contributeAndFinalizeBlockTimestamp + timeRef * 2n);
expect(task.revealCounter).to.equal(1);
expect(task.winnerCounter).to.equal(1);
expect(task.resultDigest).to.equal(resultsCallbackDigest);
Expand Down
4 changes: 2 additions & 2 deletions test/byContract/IexecPoco/IexecPoco2-contribute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { IexecWrapper } from '../../utils/IexecWrapper';
import { loadHardhatFixtureDeployment } from '../../utils/hardhat-fixture-deployer';
const CONFIG = require('../../../config/config.json');

const timeRef = CONFIG.categories[0].workClockTimeRef;
const timeRef = BigInt(CONFIG.categories[0].workClockTimeRef);
const volume = 3n;
const teeDealTag = '0x0000000000000000000000000000000000000000000000000000000000000001';
const standardDealTag = ZeroHash;
Expand Down Expand Up @@ -200,7 +200,7 @@ describe('IexecPoco2#contribute', () => {
expect(task.status).equal(TaskStatusEnum.REVEALING);
expect(task.consensusValue).equal(buildResultHash(taskId, resultDigest));
assert(contributeBlockTimestamp != undefined);
expect(task.revealDeadline).equal(contributeBlockTimestamp + timeRef * 2);
expect(task.revealDeadline).equal(contributeBlockTimestamp + timeRef * 2n);
expect(task.revealCounter).equal(0);
expect(task.winnerCounter).equal(winningWorkers.length);
});
Expand Down
2 changes: 1 addition & 1 deletion test/byContract/IexecPoco/IexecPoco2-finalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('IexecPoco2#finalize', async () => {
requester: requester.address,
prices: ordersPrices,
volume: expectedVolume,
trust: 3,
trust: 3n,
callback: await oracleConsumerInstance.getAddress(),
});
const { dealId, taskId, taskIndex, dealPrice } =
Expand Down
100 changes: 55 additions & 45 deletions test/byContract/IexecPocoBoost/IexecEscrow.v8.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// SPDX-FileCopyrightText: 2023-2024 IEXEC BLOCKCHAIN TECH <contact@iex.ec>
// SPDX-FileCopyrightText: 2023-2025 IEXEC BLOCKCHAIN TECH <contact@iex.ec>
// SPDX-License-Identifier: Apache-2.0

import { HashZero } from '@ethersproject/constants';
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers';
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { expect } from 'chai';
import { constants } from 'ethers';
import { ZeroAddress } from 'ethers';
import { IexecEscrowTestContract, IexecEscrowTestContract__factory } from '../../../typechain';
import { getIexecAccounts } from '../../../utils/poco-tools';

const accountBalance = 1000;
const amount = 3;
const accountBalance = 1000n;
const amount = 3n;

let iexecEscrow: IexecEscrowTestContract;
let iexecEscrowAddress: string;
let account: SignerWithAddress;

describe('IexecEscrow.v8', function () {
Expand All @@ -27,37 +28,39 @@ describe('IexecEscrow.v8', function () {
iexecEscrow = await new IexecEscrowTestContract__factory()
.connect(account) // Anyone works.
.deploy()
.then((contract) => contract.deployed());
.then((contract) => contract.waitForDeployment());
iexecEscrowAddress = await iexecEscrow.getAddress();
// Initialize account with some funds.
await iexecEscrow.setBalance(account.address, accountBalance).then((tx) => tx.wait());
}

describe('Lock', function () {
it('Should lock funds', async function () {
const frozenBefore = (await iexecEscrow.frozenOf(account.address)).toNumber();
await expect(iexecEscrow.lock_(account.address, amount))
.to.changeTokenBalances(
iexecEscrow,
[iexecEscrow.address, account.address],
[amount, -amount],
)
const frozenBefore = await iexecEscrow.frozenOf(account.address);
const tx = await iexecEscrow.lock_(account.address, amount);
await expect(tx).to.changeTokenBalances(
iexecEscrow,
[iexecEscrowAddress, account.address],
[amount, -amount],
);
await expect(tx)
.to.emit(iexecEscrow, 'Transfer')
.withArgs(account.address, iexecEscrow.address, amount)
.withArgs(account.address, iexecEscrowAddress, amount)
.to.emit(iexecEscrow, 'Lock')
.withArgs(account.address, amount);
expect(await iexecEscrow.frozenOf(account.address)).to.equal(frozenBefore + amount);
});

it('Should not lock funds for empty address', async function () {
await expect(iexecEscrow.lock_(constants.AddressZero, amount)).to.be.revertedWith(
await expect(iexecEscrow.lock_(ZeroAddress, amount)).to.be.revertedWith(
'IexecEscrow: Transfer from empty address',
);
});

it('Should not lock funds when insufficient balance', async function () {
await expect(iexecEscrow.lock_(account.address, accountBalance + 1)).to.be.revertedWith(
'IexecEscrow: Transfer amount exceeds balance',
);
await expect(
iexecEscrow.lock_(account.address, accountBalance + 1n),
).to.be.revertedWith('IexecEscrow: Transfer amount exceeds balance');
});
});

Expand All @@ -66,22 +69,23 @@ describe('IexecEscrow.v8', function () {
// Lock some funds to be able to unlock.
await iexecEscrow.lock_(account.address, accountBalance).then((tx) => tx.wait());

const frozenBefore = (await iexecEscrow.frozenOf(account.address)).toNumber();
await expect(iexecEscrow.unlock_(account.address, amount))
.to.changeTokenBalances(
iexecEscrow,
[iexecEscrow.address, account.address],
[-amount, amount],
)
const frozenBefore = await iexecEscrow.frozenOf(account.address);
const tx = await iexecEscrow.unlock_(account.address, amount);
await expect(tx).to.changeTokenBalances(
iexecEscrow,
[iexecEscrowAddress, account.address],
[-amount, amount],
);
await expect(tx)
.to.emit(iexecEscrow, 'Transfer')
.withArgs(iexecEscrow.address, account.address, amount)
.withArgs(iexecEscrowAddress, account.address, amount)
.to.emit(iexecEscrow, 'Unlock')
.withArgs(account.address, amount);
expect(await iexecEscrow.frozenOf(account.address)).to.equal(frozenBefore - amount);
});

it('Should not unlock funds for empty address', async function () {
await expect(iexecEscrow.unlock_(constants.AddressZero, amount)).to.be.revertedWith(
await expect(iexecEscrow.unlock_(ZeroAddress, amount)).to.be.revertedWith(
'IexecEscrow: Transfer to empty address',
);
});
Expand All @@ -96,24 +100,25 @@ describe('IexecEscrow.v8', function () {
describe('Reward', function () {
it('Should reward', async function () {
// Fund iexecEscrow so it can reward.
await iexecEscrow.setBalance(iexecEscrow.address, amount).then((tx) => tx.wait());

await expect(iexecEscrow.reward_(account.address, amount, HashZero))
.to.changeTokenBalances(
iexecEscrow,
[iexecEscrow.address, account.address],
[-amount, amount],
)
await iexecEscrow.setBalance(iexecEscrowAddress, amount).then((tx) => tx.wait());

const tx = await iexecEscrow.reward_(account.address, amount, HashZero);
await expect(tx).to.changeTokenBalances(
iexecEscrow,
[iexecEscrowAddress, account.address],
[-amount, amount],
);
await expect(tx)
.to.emit(iexecEscrow, 'Transfer')
.withArgs(iexecEscrow.address, account.address, amount)
.withArgs(iexecEscrowAddress, account.address, amount)
.to.emit(iexecEscrow, 'Reward')
.withArgs(account.address, amount, HashZero);
});

it('Should not reward empty address', async function () {
await expect(
iexecEscrow.reward_(constants.AddressZero, amount, HashZero),
).to.be.revertedWith('IexecEscrow: Transfer to empty address');
await expect(iexecEscrow.reward_(ZeroAddress, amount, HashZero)).to.be.revertedWith(
'IexecEscrow: Transfer to empty address',
);
});

it('Should not reward when insufficient balance', async function () {
Expand All @@ -128,18 +133,23 @@ describe('IexecEscrow.v8', function () {
// Lock some funds to be able to seize.
await iexecEscrow.lock_(account.address, accountBalance).then((tx) => tx.wait());

const frozenBefore = (await iexecEscrow.frozenOf(account.address)).toNumber();
await expect(iexecEscrow.seize_(account.address, amount, HashZero))
.to.changeTokenBalances(iexecEscrow, [iexecEscrow.address, account.address], [0, 0])
const frozenBefore = await iexecEscrow.frozenOf(account.address);
const tx = await iexecEscrow.seize_(account.address, amount, HashZero);
await expect(tx).to.changeTokenBalances(
iexecEscrow,
[iexecEscrowAddress, account.address],
[0, 0],
);
await expect(tx)
.to.emit(iexecEscrow, 'Seize')
.withArgs(account.address, amount, HashZero);
expect(await iexecEscrow.frozenOf(account.address)).to.equal(frozenBefore - amount);
});

it('Should not seize funds for empty address', async function () {
await expect(
iexecEscrow.seize_(constants.AddressZero, amount, HashZero),
).to.be.revertedWithPanic(0x11);
await expect(iexecEscrow.seize_(ZeroAddress, amount, HashZero)).to.be.revertedWithPanic(
0x11,
);
});

it('Should not seize funds when insufficient balance', async function () {
Expand Down
Loading