Skip to content

Commit

Permalink
Merge migrations to a single tool (#4218)
Browse files Browse the repository at this point in the history
* Move files around

* Move more files

* Add migration selector

* Remove unused routes

* Update nav icon

* Add test

* Fix TextSelector padding

* Update copy slightly

* Fix test

* Use default param value

* Auto select a default migration if possible

* Add migration E2E
  • Loading branch information
FrederikBolding committed Dec 3, 2021
1 parent e9b5c88 commit c50dc20
Show file tree
Hide file tree
Showing 65 changed files with 338 additions and 281 deletions.
17 changes: 16 additions & 1 deletion __tests__/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const PAGES = {
SWAP: `${FIXTURES_CONST.BASE_URL}/swap`,
BUY_MEMBERSHIP: `${FIXTURES_CONST.BASE_URL}/membership/buy`,
INTERACT_WITH_CONTRACTS: `${FIXTURES_CONST.BASE_URL}/interact-with-contracts`,
DEPLOY_CONTRACTS: `${FIXTURES_CONST.BASE_URL}/deploy-contracts`
DEPLOY_CONTRACTS: `${FIXTURES_CONST.BASE_URL}/deploy-contracts`,
MIGRATE: `${FIXTURES_CONST.BASE_URL}/migrate`
};

const FIXTURE_ETHEREUM = 'Ethereum';
Expand Down Expand Up @@ -185,6 +186,20 @@ const FIXTURE_HARDHAT = {
uuid: 'e1f698bf-cb85-5405-b563-14774af14bf1',
balance: '9998866308480000000000',
mtime: 1621347441875
},
{
ticker: 'LEND',
name: 'EthLend',
decimal: 18,
support: {},
social: {},
networkId: 'Ethereum',
type: 'erc20',
isCustom: false,
contractAddress: '0x80fB784B7eD66730e8b1DBd9820aFD29931aab03',
uuid: '1c77b322-a88c-57cc-b956-78c2bc17c360',
balance: '9998866308480000000000',
mtime: 1621347441875
}
],
transactions: [],
Expand Down
41 changes: 23 additions & 18 deletions __tests__/hardhat-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ export const resetFork = async (stickyBlockNum = true) => {
]);
};

// Transfers DAI to the test address
export const setupDAI = async () => {
await provider.send('hardhat_impersonateAccount', ['0x28c6c06298d514db089934071355e5743bf21d60']);
const setupERC20 = async (account, contract, amount) => {
await provider.send('hardhat_impersonateAccount', [account]);

const signer = await provider.getSigner('0x28c6c06298d514db089934071355e5743bf21d60');
const signer = await provider.getSigner(account);

const abi = [
// Read-Only Functions
Expand All @@ -36,24 +35,30 @@ export const setupDAI = async () => {
];

// send ERC20
const erc20 = new Contract('0x6b175474e89094c44da98b954eedeac495271d0f', abi, signer);
const tx = await erc20.populateTransaction.transfer(
FIXTURE_WEB3_ADDRESS,
'100000000000000000000'
);
const sent = await signer.sendTransaction({
...tx,
maxFeePerGas: '0xe8990a4600',
maxPriorityFeePerGas: '0xe8990a4600'
});
const erc20 = new Contract(contract, abi, signer);
const tx = await erc20.populateTransaction.transfer(FIXTURE_WEB3_ADDRESS, amount);

await sent.wait();
await sendTx({ ...tx, from: account });

await provider.send('hardhat_stopImpersonatingAccount', [
'0x28c6c06298d514db089934071355e5743bf21d60'
]);
await provider.send('hardhat_stopImpersonatingAccount', [account]);
};

// Transfers DAI to the test address
export const setupDAI = async () =>
setupERC20(
'0x28c6c06298d514db089934071355e5743bf21d60',
'0x6b175474e89094c44da98b954eedeac495271d0f',
'100000000000000000000'
);

// Transfers LEND to the test address
export const setupLEND = async () =>
setupERC20(
'0xb4Ad52fBBBb46871C043Cc8B4c074ad8B2a0c83b',
'0x80fB784B7eD66730e8b1DBd9820aFD29931aab03',
'100000000000000000000'
);

export const sendTx = async (tx) => {
const signer = await provider.getSigner(tx.from);

Expand Down
17 changes: 17 additions & 0 deletions __tests__/migration-page.po.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import BasePage from './base-page.po';
import { setupEthereumMock } from './ethereum-mock';
import { FIXTURE_HARDHAT_PRIVATE_KEY, PAGES } from './fixtures';

export default class MigrationPage extends BasePage {
async navigateToPage() {
this.navigateTo(PAGES.MIGRATE);
}

async waitPageLoaded(timeout) {
await this.waitForPage(PAGES.MIGRATE, timeout);
}

async setupMock() {
await setupEthereumMock(FIXTURE_HARDHAT_PRIVATE_KEY, 1);
}
}
47 changes: 47 additions & 0 deletions __tests__/migration.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { getByTestId, queryAllByTestId, queryAllByText } from '@testing-library/testcafe';

import { injectLS } from './clientScripts';
import { FIXTURE_HARDHAT, FIXTURES_CONST, PAGES } from './fixtures';
import { resetFork, setupLEND } from './hardhat-utils';
import MigrationPage from './migration-page.po';
import { findByTKey } from './translation-utils';

const migrationPage = new MigrationPage();

fixture('Migration')
.clientScripts({ content: injectLS(FIXTURE_HARDHAT) })
.page(PAGES.MIGRATE);

test('can do a LEND migration', async (t) => {
await resetFork();
await setupLEND();
await migrationPage.waitPageLoaded();
await migrationPage.setupMock();

await t.wait(FIXTURES_CONST.TIMEOUT);

const button = await getByTestId('confirm-migrate');
await t.click(button);

const approve = await queryAllByText(findByTKey('APPROVE_AAVE_TOKEN_MIGRATION'))
.with({
timeout: FIXTURES_CONST.HARDHAT_TIMEOUT
})
.nth(1);
await t.expect(approve.exists).ok({ timeout: FIXTURES_CONST.HARDHAT_TIMEOUT });
await t.click(approve);

await t.wait(FIXTURES_CONST.TIMEOUT);

const send = await queryAllByText(findByTKey('CONFIRM_TRANSACTION'))
.with({
timeout: FIXTURES_CONST.HARDHAT_TIMEOUT
})
.nth(1);
await t.expect(send.exists).ok({ timeout: FIXTURES_CONST.HARDHAT_TIMEOUT });
await t.click(send);

await t
.expect(queryAllByTestId('SUCCESS').with({ timeout: FIXTURES_CONST.HARDHAT_TIMEOUT }).count)
.eql(2, { timeout: FIXTURES_CONST.HARDHAT_TIMEOUT });
});
9 changes: 6 additions & 3 deletions jest_config/__fixtures__/tokenMigrationMultiTx.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { REPV1UUID } from '@config';
import { repTokenMigrationConfig } from '@features/RepTokenMigration/config';
import { createApproveTx, createRepMigrationTx } from '@features/RepTokenMigration/helpers';
import { MIGRATION_CONFIGS } from '@features/TokenMigration/config';
import {
createApproveTx,
createRepMigrationTx
} from '@features/TokenMigration/RepTokenMigration/helpers';
import { fApproveERC20TxResponse, fREPTokenMigrationTxResponse } from '@fixtures';
import { ITokenMigrationFormFull, ITxStatus, ITxType, TxParcel } from '@types';
import { generateUUID, inputGasLimitToHex, inputNonceToHex } from '@utils';
Expand All @@ -11,7 +14,7 @@ import { fNetwork } from './network';

export const fTokenMigrationTxs = (): TxParcel[] => {
const tokenMigrationPayload: ITokenMigrationFormFull = {
tokenConfig: repTokenMigrationConfig,
tokenConfig: MIGRATION_CONFIGS.REP,
asset: fAssets.find(({ uuid }) => uuid === REPV1UUID)!,
network: fNetwork,
address: fAccount.address,
Expand Down
3 changes: 0 additions & 3 deletions src/assets/icons/navigation/migrate-ant.svg

This file was deleted.

3 changes: 0 additions & 3 deletions src/assets/icons/navigation/migrate-gnt.svg

This file was deleted.

3 changes: 0 additions & 3 deletions src/assets/icons/navigation/migrate-lend.svg

This file was deleted.

3 changes: 0 additions & 3 deletions src/assets/icons/navigation/migrate-rep.svg

This file was deleted.

Loading

0 comments on commit c50dc20

Please sign in to comment.