Skip to content

Minor fix for integration tests #1295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 27, 2021
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
- run:
name: Run dual layer 1 and layer 2 integration tests
command: |
npx hardhat test:integration:dual --connect
npx hardhat test:integration:dual --deploy --connect
job-lint:
working_directory: ~/repo
docker:
Expand Down
2 changes: 1 addition & 1 deletion .circleci/src/jobs/job-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ steps:
- run:
name: Run dual layer 1 and layer 2 integration tests
command: |
npx hardhat test:integration:dual --connect
npx hardhat test:integration:dual --deploy --connect
56 changes: 51 additions & 5 deletions test/integration/behaviors/exchange.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ const ethers = require('ethers');
const { assert } = require('../../contracts/common');
const { toBytes32 } = require('../../../index');
const { ensureBalance } = require('../utils/balances');
const { wait, sendDummyTx } = require('../utils/rpc');

function itCanPerformExchanges({ ctx }) {
const sUSDAmount = ethers.utils.parseEther('100');

let owner;

let Synthetix, Exchanger, SynthsETH;
let balancesETH, balancesUSD;
let Synthetix, Exchanger, SynthsETH, SynthsUSD, SystemSettings;
let originalWaitingPeriod;

before('target contracts and users', () => {
({ Synthetix, Exchanger, SynthsETH } = ctx.contracts);
({ Synthetix, Exchanger, SynthsETH, SynthsUSD, SystemSettings } = ctx.contracts);

owner = ctx.owner;
});
Expand All @@ -20,9 +22,21 @@ function itCanPerformExchanges({ ctx }) {
await ensureBalance({ ctx, symbol: 'sUSD', user: owner, balance: sUSDAmount });
});

describe('when the owner exchanges from sUSD to sETH', () => {
let balancesETH;
before('record and reduce waiting period', async () => {
SystemSettings = SystemSettings.connect(ctx.owner);

originalWaitingPeriod = await SystemSettings.waitingPeriodSecs();

const tx = await SystemSettings.setWaitingPeriodSecs(1);
await tx.wait();
});

after('restore waiting period', async () => {
const tx = await SystemSettings.setWaitingPeriodSecs(originalWaitingPeriod);
await tx.wait();
});

describe('when the owner exchanges sUSD to sETH', () => {
before('record balances', async () => {
balancesETH = await SynthsETH.balanceOf(owner.address);
});
Expand All @@ -43,6 +57,38 @@ function itCanPerformExchanges({ ctx }) {

assert.bnEqual(await SynthsETH.balanceOf(owner.address), balancesETH.add(expectedAmount));
});

// TODO: Disabled until we understand more about the time granularity of the
// L2 chain on the ops tool.
describe.skip('when the owner exchanges sETH to sUSD', () => {
before('ensure the waiting period has passed', async () => {
await sendDummyTx({ ctx });
await wait({ seconds: 60 });
await sendDummyTx({ ctx });
});

before('record balances', async () => {
balancesUSD = await SynthsUSD.balanceOf(owner.address);
balancesETH = await SynthsETH.balanceOf(owner.address);
});

before('perform the exchange', async () => {
Synthetix = Synthetix.connect(owner);

const tx = await Synthetix.exchange(toBytes32('sETH'), balancesETH, toBytes32('sUSD'));
await tx.wait();
});

it('receives the expected amount of sUSD', async () => {
const [expectedAmount, ,] = await Exchanger.getAmountsForExchange(
balancesETH,
toBytes32('sETH'),
toBytes32('sUSD')
);

assert.bnEqual(await SynthsUSD.balanceOf(owner.address), balancesUSD.add(expectedAmount));
});
});
});
}

Expand Down
21 changes: 21 additions & 0 deletions test/integration/utils/rpc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
async function sendDummyTx({ ctx }) {
const tx = await ctx.owner.sendTransaction({
to: '0x0000000000000000000000000000000000000001',
value: 0,
});

await tx.wait();
}

async function wait({ seconds }) {
return new Promise(resolve => {
setTimeout(() => {
resolve();
}, seconds * 1000);
});
}

module.exports = {
sendDummyTx,
wait,
};
Empty file added test/integration/utils/wait.js
Empty file.