Skip to content

Commit 38baae0

Browse files
Port some of the old optimism tests to the new integration tests format (Synthetixio#1281)
* Basic integration tests for L2 deposits * Basic integration tests for L2 deposits * Polish deposit integration tests * Progress porting withdrawal integration tests * Working withdrawals in new integration tests * Using watcher tool more * Unify action and actionTo in integration tests * Progress porting integration tests * Remove comment * Implemented exchanges in new integration tests * Rename gas util
1 parent 347e5b6 commit 38baae0

23 files changed

+628
-81
lines changed

hardhat/tasks/task-test-integration-dual.js

-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const {
77

88
task('test:integration:dual', 'run integrated layer 1 and layer 2 production tests')
99
.addFlag('deploy', 'Deploy l1 and l2 instances before running the tests')
10-
.addFlag('connect', 'Connect already deployed l1 and l2 instances before running the tests')
1110
.setAction(async (taskArguments, hre) => {
1211
hre.config.paths.tests = './test/integration/dual/';
1312

@@ -28,9 +27,7 @@ task('test:integration:dual', 'run integrated layer 1 and layer 2 production tes
2827

2928
await compileInstance({ useOvm: true });
3029
await deployInstance({ useOvm: true, providerUrl, providerPort: providerPortL2 });
31-
}
3230

33-
if (taskArguments.connect) {
3431
await connectInstances({ providerUrl, providerPortL1, providerPortL2 });
3532
}
3633

hardhat/tasks/task-test-integration-l1.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ const { compileInstance, deployInstance } = require('../../test/integration/util
44
task('test:integration:l1', 'run isolated layer 1 production tests')
55
.addFlag('compile', 'Compile an l1 instance before running the tests')
66
.addFlag('deploy', 'Deploy an l1 instance before running the tests')
7+
.addOptionalParam(
8+
'providerPort',
9+
'The target port for the running local chain to test on',
10+
'9545'
11+
)
712
.setAction(async (taskArguments, hre) => {
813
hre.config.paths.tests = './test/integration/l1/';
914

1015
const providerUrl = (hre.config.providerUrl = 'http://localhost');
11-
const providerPort = (hre.config.providerPort = '9545');
16+
const providerPort = (hre.config.providerPort = taskArguments.providerPort);
1217

1318
const timeout = 5 * 60 * 1000;
1419
hre.config.mocha.timeout = timeout;

hardhat/tasks/task-test-integration-l2.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ const { compileInstance, deployInstance } = require('../../test/integration/util
44
task('test:integration:l2', 'run isolated layer 2 production tests')
55
.addFlag('compile', 'Compile an l2 instance before running the tests')
66
.addFlag('deploy', 'Deploy an l2 instance before running the tests')
7+
.addOptionalParam(
8+
'providerPort',
9+
'The target port for the running local chain to test on',
10+
'9545'
11+
)
712
.setAction(async (taskArguments, hre) => {
813
hre.config.paths.tests = './test/integration/l2/';
914

1015
const providerUrl = (hre.config.providerUrl = 'http://localhost');
11-
const providerPort = (hre.config.providerPort = '8545');
16+
const providerPort = (hre.config.providerPort = taskArguments.providerPort);
1217

1318
const timeout = 5 * 60 * 1000;
1419
hre.config.mocha.timeout = timeout;
@@ -22,7 +27,12 @@ task('test:integration:l2', 'run isolated layer 2 production tests')
2227
}
2328

2429
if (taskArguments.deploy) {
25-
await deployInstance({ useOvm: true, providerUrl, providerPort });
30+
await deployInstance({
31+
useOvm: true,
32+
ignoreCustomParameters: true,
33+
providerUrl,
34+
providerPort,
35+
});
2636
}
2737

2838
await hre.run('test', taskArguments);

test/integration/behaviors/Synthetix.behavior.js

-30
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const ethers = require('ethers');
2+
const { assert } = require('../../contracts/common');
3+
const { toBytes32 } = require('../../../index');
4+
const { ensureBalance } = require('../utils/balances');
5+
6+
function itCanPerformExchanges({ ctx }) {
7+
const sUSDAmount = ethers.utils.parseEther('100');
8+
9+
let owner;
10+
11+
let Synthetix, Exchanger, SynthsETH;
12+
13+
before('target contracts and users', () => {
14+
({ Synthetix, Exchanger, SynthsETH } = ctx.contracts);
15+
16+
owner = ctx.owner;
17+
});
18+
19+
before('ensure the owner has sUSD', async () => {
20+
await ensureBalance({ ctx, symbol: 'sUSD', user: owner, balance: sUSDAmount });
21+
});
22+
23+
describe('when the owner exchanges from sUSD to sETH', () => {
24+
let balancesETH;
25+
26+
before('record balances', async () => {
27+
balancesETH = await SynthsETH.balanceOf(owner.address);
28+
});
29+
30+
before('perform the exchange', async () => {
31+
Synthetix = Synthetix.connect(owner);
32+
33+
const tx = await Synthetix.exchange(toBytes32('sUSD'), sUSDAmount, toBytes32('sETH'));
34+
await tx.wait();
35+
});
36+
37+
it('receives the expected amount of sETH', async () => {
38+
const [expectedAmount, ,] = await Exchanger.getAmountsForExchange(
39+
sUSDAmount,
40+
toBytes32('sUSD'),
41+
toBytes32('sETH')
42+
);
43+
44+
assert.bnEqual(await SynthsETH.balanceOf(owner.address), balancesETH.add(expectedAmount));
45+
});
46+
});
47+
}
48+
49+
module.exports = {
50+
itCanPerformExchanges,
51+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const ethers = require('ethers');
2+
const { assert } = require('../../contracts/common');
3+
const { bootstrapDual } = require('../utils/bootstrap');
4+
const { finalizationOnL2 } = require('../utils/watchers');
5+
const { approveIfNeeded } = require('../utils/approve');
6+
7+
describe('deposit() integration tests (L1, L2)', () => {
8+
const ctx = this;
9+
bootstrapDual({ ctx });
10+
11+
const amountToDeposit = ethers.utils.parseEther('10');
12+
13+
let owner;
14+
let Synthetix, SynthetixBridgeToOptimism, SynthetixBridgeEscrow;
15+
16+
let ownerBalance, escrowBalance;
17+
18+
let depositReceipt;
19+
20+
describe('when the owner deposits SNX', () => {
21+
before('target contracts and users', () => {
22+
({ Synthetix, SynthetixBridgeToOptimism, SynthetixBridgeEscrow } = ctx.l1.contracts);
23+
24+
owner = ctx.l1.owner;
25+
});
26+
27+
before('record balances', async () => {
28+
ownerBalance = await Synthetix.balanceOf(owner.address);
29+
escrowBalance = await Synthetix.balanceOf(SynthetixBridgeEscrow.address);
30+
});
31+
32+
before('approve if needed', async () => {
33+
await approveIfNeeded({
34+
token: Synthetix,
35+
owner,
36+
beneficiary: SynthetixBridgeToOptimism,
37+
amount: amountToDeposit,
38+
});
39+
});
40+
41+
before('make the deposit', async () => {
42+
SynthetixBridgeToOptimism = SynthetixBridgeToOptimism.connect(owner);
43+
44+
const tx = await SynthetixBridgeToOptimism.deposit(amountToDeposit);
45+
depositReceipt = await tx.wait();
46+
});
47+
48+
it('decreases the owner balance', async () => {
49+
const newOwnerBalance = await Synthetix.balanceOf(owner.address);
50+
51+
assert.bnEqual(newOwnerBalance, ownerBalance.sub(amountToDeposit));
52+
});
53+
54+
it('increases the escrow balance', async () => {
55+
const newEscrowBalance = await Synthetix.balanceOf(SynthetixBridgeEscrow.address);
56+
57+
assert.bnEqual(newEscrowBalance, escrowBalance.add(amountToDeposit));
58+
});
59+
60+
describe('when the deposit gets picked up in L2', () => {
61+
before('target contracts and users', () => {
62+
({ Synthetix } = ctx.l2.contracts);
63+
64+
owner = ctx.l2.owner;
65+
});
66+
67+
before('record balances', async () => {
68+
ownerBalance = await Synthetix.balanceOf(owner.address);
69+
});
70+
71+
before('wait for deposit finalization', async () => {
72+
await finalizationOnL2({ ctx, transactionHash: depositReceipt.transactionHash });
73+
});
74+
75+
it('increases the owner balance', async () => {
76+
assert.bnEqual(await Synthetix.balanceOf(owner.address), ownerBalance.add(amountToDeposit));
77+
});
78+
});
79+
});
80+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
const ethers = require('ethers');
2+
const { assert } = require('../../contracts/common');
3+
const { bootstrapDual } = require('../utils/bootstrap');
4+
const { finalizationOnL2 } = require('../utils/watchers');
5+
const { approveIfNeeded } = require('../utils/approve');
6+
7+
describe('depositTo() integration tests (L1, L2)', () => {
8+
const ctx = this;
9+
bootstrapDual({ ctx });
10+
11+
const amountToDeposit = ethers.utils.parseEther('10');
12+
13+
let owner, user;
14+
let Synthetix, SynthetixBridgeToOptimism, SynthetixBridgeEscrow;
15+
16+
let ownerBalance, beneficiaryBalance, escrowBalance;
17+
18+
let depositReceipt;
19+
20+
describe('when the owner deposits SNX for a user', () => {
21+
before('target contracts and users', () => {
22+
({ Synthetix, SynthetixBridgeToOptimism, SynthetixBridgeEscrow } = ctx.l1.contracts);
23+
24+
owner = ctx.l1.owner;
25+
user = ctx.l1.user;
26+
});
27+
28+
before('record balances', async () => {
29+
ownerBalance = await Synthetix.balanceOf(owner.address);
30+
escrowBalance = await Synthetix.balanceOf(SynthetixBridgeEscrow.address);
31+
});
32+
33+
before('approve if needed', async () => {
34+
await approveIfNeeded({
35+
token: Synthetix,
36+
owner,
37+
beneficiary: SynthetixBridgeToOptimism,
38+
amount: amountToDeposit,
39+
});
40+
});
41+
42+
before('make the deposit', async () => {
43+
SynthetixBridgeToOptimism = SynthetixBridgeToOptimism.connect(owner);
44+
45+
const tx = await SynthetixBridgeToOptimism.depositTo(user.address, amountToDeposit);
46+
depositReceipt = await tx.wait();
47+
});
48+
49+
it('decreases the owner balance', async () => {
50+
const newOwnerBalance = await Synthetix.balanceOf(owner.address);
51+
52+
assert.bnEqual(newOwnerBalance, ownerBalance.sub(amountToDeposit));
53+
});
54+
55+
it('increases the escrow balance', async () => {
56+
const newEscrowBalance = await Synthetix.balanceOf(SynthetixBridgeEscrow.address);
57+
58+
assert.bnEqual(newEscrowBalance, escrowBalance.add(amountToDeposit));
59+
});
60+
61+
describe('when the deposit gets picked up in L2', () => {
62+
before('target contracts and users', () => {
63+
({ Synthetix } = ctx.l2.contracts);
64+
65+
owner = ctx.l2.owner;
66+
});
67+
68+
before('record balances', async () => {
69+
beneficiaryBalance = await Synthetix.balanceOf(user.address);
70+
});
71+
72+
before('wait for deposit finalization', async () => {
73+
await finalizationOnL2({ ctx, transactionHash: depositReceipt.transactionHash });
74+
});
75+
76+
it('increases the beneficiary balance', async () => {
77+
assert.bnEqual(
78+
await Synthetix.balanceOf(user.address),
79+
beneficiaryBalance.add(amountToDeposit)
80+
);
81+
});
82+
});
83+
});
84+
});

test/integration/dual/deposits.integration.js

-11
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const ethers = require('ethers');
2+
const { assert } = require('../../contracts/common');
3+
const { bootstrapDual } = require('../utils/bootstrap');
4+
const { finalizationOnL2 } = require('../utils/watchers');
5+
const { approveIfNeeded } = require('../utils/approve');
6+
7+
describe('depositReward() integration tests (L1, L2)', () => {
8+
const ctx = this;
9+
bootstrapDual({ ctx });
10+
11+
const amountToDeposit = ethers.utils.parseEther('10');
12+
13+
let owner;
14+
let Synthetix, SynthetixBridgeToOptimism, FeePool;
15+
16+
let depositReceipt;
17+
18+
describe('when the owner deposits SNX for rewards', () => {
19+
before('target contracts and users', () => {
20+
({ Synthetix, SynthetixBridgeToOptimism } = ctx.l1.contracts);
21+
22+
owner = ctx.l1.owner;
23+
});
24+
25+
before('approve if needed', async () => {
26+
await approveIfNeeded({
27+
token: Synthetix,
28+
owner,
29+
beneficiary: SynthetixBridgeToOptimism,
30+
amount: amountToDeposit,
31+
});
32+
});
33+
34+
before('make the deposit', async () => {
35+
SynthetixBridgeToOptimism = SynthetixBridgeToOptimism.connect(owner);
36+
37+
const tx = await SynthetixBridgeToOptimism.depositReward(amountToDeposit);
38+
depositReceipt = await tx.wait();
39+
});
40+
41+
describe('when the deposit gets picked up in L2', () => {
42+
let currentFeePeriodRewards;
43+
44+
before('target contracts and users', () => {
45+
({ FeePool } = ctx.l2.contracts);
46+
});
47+
48+
before('record current fee period rewards', async () => {
49+
currentFeePeriodRewards = (await FeePool.recentFeePeriods(0)).rewardsToDistribute;
50+
});
51+
52+
before('wait for deposit finalization', async () => {
53+
await finalizationOnL2({ ctx, transactionHash: depositReceipt.transactionHash });
54+
});
55+
56+
it('increases the current fee periods rewards to distribute', async () => {
57+
assert.bnEqual(
58+
(await FeePool.recentFeePeriods(0)).rewardsToDistribute,
59+
currentFeePeriodRewards.add(amountToDeposit)
60+
);
61+
});
62+
});
63+
});
64+
});

0 commit comments

Comments
 (0)