Skip to content

Commit

Permalink
fix: replace test-helpers mainnetTokens with common mainnetTokens (#75)
Browse files Browse the repository at this point in the history
Co-authored-by: Bob Lu <[email protected]>
  • Loading branch information
LuPoYi and Bob Lu authored Aug 9, 2024
1 parent 71d51bc commit 35d465d
Show file tree
Hide file tree
Showing 34 changed files with 339 additions and 260 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-years-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@protocolink/logics': patch
---

replace test-helpers mainnetTokens with common mainnetTokens
6 changes: 3 additions & 3 deletions test/logics/aave-v2/borrow.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import * as aavev2 from 'src/logics/aave-v2';
import { claimToken, getChainId, mainnetTokens, snapshotAndRevertEach } from '@protocolink/test-helpers';
import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers';
import * as common from '@protocolink/common';
import * as core from '@protocolink/core';
import { expect } from 'chai';
Expand All @@ -15,8 +15,8 @@ describe('mainnet-pb: Test AaveV2 Borrow Logic', function () {
chainId = await getChainId();
const [, user1, user2] = await hre.ethers.getSigners();
users = [user1, user2];
await claimToken(chainId, user1.address, mainnetTokens.USDC, '20000');
await claimToken(chainId, user2.address, mainnetTokens.WETH, '100');
await claimToken(chainId, user1.address, common.mainnetTokens.USDC, '20000');
await claimToken(chainId, user2.address, common.mainnetTokens.WETH, '100');
});

snapshotAndRevertEach();
Expand Down
6 changes: 3 additions & 3 deletions test/logics/aave-v2/deposit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import * as aavev2 from 'src/logics/aave-v2';
import { claimToken, getChainId, mainnetTokens, snapshotAndRevertEach } from '@protocolink/test-helpers';
import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers';
import * as common from '@protocolink/common';
import * as core from '@protocolink/core';
import { expect } from 'chai';
Expand All @@ -14,8 +14,8 @@ describe('mainnet-pb: Test AaveV2 Deposit Logic', function () {
before(async function () {
chainId = await getChainId();
[, user] = await hre.ethers.getSigners();
await claimToken(chainId, user.address, mainnetTokens.USDC, '100');
await claimToken(chainId, user.address, mainnetTokens.WETH, '100');
await claimToken(chainId, user.address, common.mainnetTokens.USDC, '100');
await claimToken(chainId, user.address, common.mainnetTokens.WETH, '100');
});

snapshotAndRevertEach();
Expand Down
16 changes: 11 additions & 5 deletions test/logics/aave-v2/flash-loan.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import * as aavev2 from 'src/logics/aave-v2';
import { claimToken, getChainId, mainnetTokens, snapshotAndRevertEach } from '@protocolink/test-helpers';
import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers';
import * as common from '@protocolink/common';
import * as core from '@protocolink/core';
import { expect } from 'chai';
Expand All @@ -15,10 +15,16 @@ describe('mainnet-pb: Test AaveV2 FlashLoan Logic', function () {
before(async function () {
chainId = await getChainId();
[, user] = await hre.ethers.getSigners();
await claimToken(chainId, user.address, mainnetTokens.WETH, '2');
await claimToken(chainId, user.address, mainnetTokens.USDC, '2');
await claimToken(chainId, user.address, mainnetTokens.USDT, '2');
await claimToken(chainId, user.address, mainnetTokens.DAI, '2', '0x8A610c1C93da88c59F51A6264A4c70927814B320');
await claimToken(chainId, user.address, common.mainnetTokens.WETH, '2');
await claimToken(chainId, user.address, common.mainnetTokens.USDC, '2');
await claimToken(chainId, user.address, common.mainnetTokens.USDT, '2');
await claimToken(
chainId,
user.address,
common.mainnetTokens.DAI,
'2',
'0x8A610c1C93da88c59F51A6264A4c70927814B320'
);
});

snapshotAndRevertEach();
Expand Down
10 changes: 5 additions & 5 deletions test/logics/aave-v2/repay.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import * as aavev2 from 'src/logics/aave-v2';
import { claimToken, getChainId, mainnetTokens, snapshotAndRevertEach } from '@protocolink/test-helpers';
import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers';
import * as common from '@protocolink/common';
import * as core from '@protocolink/core';
import { expect } from 'chai';
Expand All @@ -16,10 +16,10 @@ describe('mainnet-pb: Test AaveV2 Repay Logic', function () {
chainId = await getChainId();
const [, user1, user2] = await hre.ethers.getSigners();
users = [user1, user2];
await claimToken(chainId, user1.address, mainnetTokens.USDC, '40000');
await claimToken(chainId, user1.address, mainnetTokens.WETH, '100');
await claimToken(chainId, user2.address, mainnetTokens.USDC, '100');
await claimToken(chainId, user2.address, mainnetTokens.WETH, '100');
await claimToken(chainId, user1.address, common.mainnetTokens.USDC, '40000');
await claimToken(chainId, user1.address, common.mainnetTokens.WETH, '100');
await claimToken(chainId, user2.address, common.mainnetTokens.USDC, '100');
await claimToken(chainId, user2.address, common.mainnetTokens.WETH, '100');
});

snapshotAndRevertEach();
Expand Down
6 changes: 3 additions & 3 deletions test/logics/aave-v2/withdraw.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import * as aavev2 from 'src/logics/aave-v2';
import { claimToken, getChainId, mainnetTokens, snapshotAndRevertEach } from '@protocolink/test-helpers';
import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers';
import * as common from '@protocolink/common';
import * as core from '@protocolink/core';
import { expect } from 'chai';
Expand All @@ -15,8 +15,8 @@ describe('mainnet-pb: Test AaveV2 Withdraw Logic', function () {
before(async function () {
chainId = await getChainId();
[, user] = await hre.ethers.getSigners();
await claimToken(chainId, user.address, mainnetTokens.WETH, '100');
await claimToken(chainId, user.address, mainnetTokens.USDC, '100');
await claimToken(chainId, user.address, common.mainnetTokens.WETH, '100');
await claimToken(chainId, user.address, common.mainnetTokens.USDC, '100');
});

snapshotAndRevertEach();
Expand Down
6 changes: 3 additions & 3 deletions test/logics/aave-v3/borrow.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import * as aavev3 from 'src/logics/aave-v3';
import { claimToken, getChainId, mainnetTokens, snapshotAndRevertEach } from '@protocolink/test-helpers';
import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers';
import * as common from '@protocolink/common';
import * as core from '@protocolink/core';
import { expect } from 'chai';
Expand All @@ -15,8 +15,8 @@ describe('mainnet-pb: Test AaveV3 Borrow Logic', function () {
chainId = await getChainId();
const [, user1, user2] = await hre.ethers.getSigners();
users = [user1, user2];
await claimToken(chainId, user1.address, mainnetTokens.USDC, '10000');
await claimToken(chainId, user2.address, mainnetTokens.WETH, '100');
await claimToken(chainId, user1.address, common.mainnetTokens.USDC, '10000');
await claimToken(chainId, user2.address, common.mainnetTokens.WETH, '100');
});

snapshotAndRevertEach();
Expand Down
18 changes: 12 additions & 6 deletions test/logics/aave-v3/flash-loan.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import * as aavev3 from 'src/logics/aave-v3';
import { claimToken, getChainId, mainnetTokens, snapshotAndRevertEach } from '@protocolink/test-helpers';
import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers';
import * as common from '@protocolink/common';
import * as core from '@protocolink/core';
import { expect } from 'chai';
Expand All @@ -15,11 +15,17 @@ describe('mainnet-pb: Test AaveV3 FlashLoan Logic', function () {
before(async function () {
chainId = await getChainId();
[, user] = await hre.ethers.getSigners();
await claimToken(chainId, user.address, mainnetTokens.WETH, '2');
await claimToken(chainId, user.address, mainnetTokens.USDC, '2');
await claimToken(chainId, user.address, mainnetTokens.USDT, '2');
await claimToken(chainId, user.address, mainnetTokens.DAI, '2', '0x8A610c1C93da88c59F51A6264A4c70927814B320');
await claimToken(chainId, user.address, mainnetTokens.WBTC, '2');
await claimToken(chainId, user.address, common.mainnetTokens.WETH, '2');
await claimToken(chainId, user.address, common.mainnetTokens.USDC, '2');
await claimToken(chainId, user.address, common.mainnetTokens.USDT, '2');
await claimToken(
chainId,
user.address,
common.mainnetTokens.DAI,
'2',
'0x8A610c1C93da88c59F51A6264A4c70927814B320'
);
await claimToken(chainId, user.address, common.mainnetTokens.WBTC, '2');
});

snapshotAndRevertEach();
Expand Down
10 changes: 5 additions & 5 deletions test/logics/aave-v3/repay.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import * as aavev3 from 'src/logics/aave-v3';
import { claimToken, getChainId, mainnetTokens, snapshotAndRevertEach } from '@protocolink/test-helpers';
import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers';
import * as common from '@protocolink/common';
import * as core from '@protocolink/core';
import { expect } from 'chai';
Expand All @@ -16,10 +16,10 @@ describe('mainnet-pb: Test AaveV3 Repay Logic', function () {
chainId = await getChainId();
const [, user1, user2] = await hre.ethers.getSigners();
users = [user1, user2];
await claimToken(chainId, user1.address, mainnetTokens.USDC, '20000');
await claimToken(chainId, user1.address, mainnetTokens.WETH, '100');
await claimToken(chainId, user2.address, mainnetTokens.USDC, '100');
await claimToken(chainId, user2.address, mainnetTokens.WETH, '100');
await claimToken(chainId, user1.address, common.mainnetTokens.USDC, '20000');
await claimToken(chainId, user1.address, common.mainnetTokens.WETH, '100');
await claimToken(chainId, user2.address, common.mainnetTokens.USDC, '100');
await claimToken(chainId, user2.address, common.mainnetTokens.WETH, '100');
});

snapshotAndRevertEach();
Expand Down
6 changes: 3 additions & 3 deletions test/logics/aave-v3/supply.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import * as aavev3 from 'src/logics/aave-v3';
import { claimToken, getChainId, mainnetTokens, snapshotAndRevertEach } from '@protocolink/test-helpers';
import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers';
import * as common from '@protocolink/common';
import * as core from '@protocolink/core';
import { expect } from 'chai';
Expand All @@ -14,8 +14,8 @@ describe('mainnet-pb: Test AaveV3 Supply Logic', function () {
before(async function () {
chainId = await getChainId();
[, user] = await hre.ethers.getSigners();
await claimToken(chainId, user.address, mainnetTokens.USDC, '100');
await claimToken(chainId, user.address, mainnetTokens.WETH, '100');
await claimToken(chainId, user.address, common.mainnetTokens.USDC, '100');
await claimToken(chainId, user.address, common.mainnetTokens.WETH, '100');
});

snapshotAndRevertEach();
Expand Down
6 changes: 3 additions & 3 deletions test/logics/aave-v3/withdraw.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import * as aavev3 from 'src/logics/aave-v3';
import { claimToken, getChainId, mainnetTokens, snapshotAndRevertEach } from '@protocolink/test-helpers';
import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers';
import * as common from '@protocolink/common';
import * as core from '@protocolink/core';
import { expect } from 'chai';
Expand All @@ -15,8 +15,8 @@ describe('mainnet-pb: Test AaveV3 Withdraw Logic', function () {
before(async function () {
chainId = await getChainId();
[, user] = await hre.ethers.getSigners();
await claimToken(chainId, user.address, mainnetTokens.WETH, '100');
await claimToken(chainId, user.address, mainnetTokens.USDC, '100');
await claimToken(chainId, user.address, common.mainnetTokens.WETH, '100');
await claimToken(chainId, user.address, common.mainnetTokens.USDC, '100');
});

snapshotAndRevertEach();
Expand Down
24 changes: 15 additions & 9 deletions test/logics/balancer-v2/flash-loan.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import * as balancerv2 from 'src/logics/balancer-v2';
import { claimToken, getChainId, mainnetTokens, snapshotAndRevertEach } from '@protocolink/test-helpers';
import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers';
import * as common from '@protocolink/common';
import * as core from '@protocolink/core';
import { expect } from 'chai';
Expand All @@ -15,19 +15,25 @@ describe('mainnet-pb: Test BalancerV2 FlashLoan Logic', function () {
before(async function () {
chainId = await getChainId();
[, user] = await hre.ethers.getSigners();
await claimToken(chainId, user.address, mainnetTokens.WETH, '2');
await claimToken(chainId, user.address, mainnetTokens.USDC, '2');
await claimToken(chainId, user.address, mainnetTokens.USDT, '2');
await claimToken(chainId, user.address, mainnetTokens.DAI, '2', '0x8A610c1C93da88c59F51A6264A4c70927814B320');
await claimToken(chainId, user.address, common.mainnetTokens.WETH, '2');
await claimToken(chainId, user.address, common.mainnetTokens.USDC, '2');
await claimToken(chainId, user.address, common.mainnetTokens.USDT, '2');
await claimToken(
chainId,
user.address,
common.mainnetTokens.DAI,
'2',
'0x8A610c1C93da88c59F51A6264A4c70927814B320'
);
});

snapshotAndRevertEach();

const testCases = [
{ loans: new common.TokenAmounts([mainnetTokens.WETH, '1'], [mainnetTokens.USDC, '1']) },
{ repays: new common.TokenAmounts([mainnetTokens.WETH, '1'], [mainnetTokens.USDC, '1']) },
{ loans: new common.TokenAmounts([mainnetTokens.USDT, '1'], [mainnetTokens.DAI, '1']) },
{ repays: new common.TokenAmounts([mainnetTokens.USDT, '1'], [mainnetTokens.DAI, '1']) },
{ loans: new common.TokenAmounts([common.mainnetTokens.WETH, '1'], [common.mainnetTokens.USDC, '1']) },
{ repays: new common.TokenAmounts([common.mainnetTokens.WETH, '1'], [common.mainnetTokens.USDC, '1']) },
{ loans: new common.TokenAmounts([common.mainnetTokens.USDT, '1'], [common.mainnetTokens.DAI, '1']) },
{ repays: new common.TokenAmounts([common.mainnetTokens.USDT, '1'], [common.mainnetTokens.DAI, '1']) },
];

testCases.forEach((params, i) => {
Expand Down
28 changes: 17 additions & 11 deletions test/logics/compound-v2/claim.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { claimToken, getChainId, mainnetTokens, snapshotAndRevertEach } from '@protocolink/test-helpers';
import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers';
import * as common from '@protocolink/common';
import * as compoundv2 from 'src/logics/compound-v2';
import * as core from '@protocolink/core';
Expand All @@ -16,8 +16,14 @@ describe('mainnet-pb: Test CompoundV2 Claim Logic', function () {
chainId = await getChainId();
const [, user1, user2] = await hre.ethers.getSigners();
users = [user1, user2];
await claimToken(chainId, user1.address, mainnetTokens.USDC, '5000');
await claimToken(chainId, user1.address, mainnetTokens.DAI, '5000', '0x8A610c1C93da88c59F51A6264A4c70927814B320');
await claimToken(chainId, user1.address, common.mainnetTokens.USDC, '5000');
await claimToken(
chainId,
user1.address,
common.mainnetTokens.DAI,
'5000',
'0x8A610c1C93da88c59F51A6264A4c70927814B320'
);
});

snapshotAndRevertEach();
Expand All @@ -27,26 +33,26 @@ describe('mainnet-pb: Test CompoundV2 Claim Logic', function () {
{
ownerIndex: 0,
claimerIndex: 0,
supply: new common.TokenAmount(mainnetTokens.DAI, '1000'),
borrow: new common.TokenAmount(mainnetTokens.USDC, '100'),
supply: new common.TokenAmount(common.mainnetTokens.DAI, '1000'),
borrow: new common.TokenAmount(common.mainnetTokens.USDC, '100'),
},
{
ownerIndex: 0,
claimerIndex: 0,
supply: new common.TokenAmount(mainnetTokens.USDC, '3000'),
borrow: new common.TokenAmount(mainnetTokens.DAI, '100'),
supply: new common.TokenAmount(common.mainnetTokens.USDC, '3000'),
borrow: new common.TokenAmount(common.mainnetTokens.DAI, '100'),
},
{
ownerIndex: 0,
claimerIndex: 1,
supply: new common.TokenAmount(mainnetTokens.DAI, '1000'),
borrow: new common.TokenAmount(mainnetTokens.USDC, '100'),
supply: new common.TokenAmount(common.mainnetTokens.DAI, '1000'),
borrow: new common.TokenAmount(common.mainnetTokens.USDC, '100'),
},
{
ownerIndex: 0,
claimerIndex: 1,
supply: new common.TokenAmount(mainnetTokens.USDC, '3000'),
borrow: new common.TokenAmount(mainnetTokens.DAI, '100'),
supply: new common.TokenAmount(common.mainnetTokens.USDC, '3000'),
borrow: new common.TokenAmount(common.mainnetTokens.DAI, '100'),
},
];

Expand Down
26 changes: 16 additions & 10 deletions test/logics/compound-v2/repay.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { claimToken, getChainId, mainnetTokens, snapshotAndRevertEach } from '@protocolink/test-helpers';
import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers';
import * as common from '@protocolink/common';
import * as compoundv2 from 'src/logics/compound-v2';
import * as core from '@protocolink/core';
Expand All @@ -16,28 +16,34 @@ describe('mainnet-pb: Test CompoundV2 Repay Logic', function () {
before(async function () {
chainId = await getChainId();
[, user] = await hre.ethers.getSigners();
await claimToken(chainId, user.address, mainnetTokens.WBTC, '10', '0x9ff58f4ffb29fa2266ab25e75e2a8b3503311656');
await claimToken(
chainId,
user.address,
common.mainnetTokens.WBTC,
'10',
'0x9ff58f4ffb29fa2266ab25e75e2a8b3503311656'
);
});

snapshotAndRevertEach();

const testCases = [
{
supply: new common.TokenAmount(mainnetTokens.ETH, '100'),
borrow: new common.TokenAmount(mainnetTokens.WBTC, '1'),
supply: new common.TokenAmount(common.mainnetTokens.ETH, '100'),
borrow: new common.TokenAmount(common.mainnetTokens.WBTC, '1'),
},
{
supply: new common.TokenAmount(mainnetTokens.WBTC, '1'),
borrow: new common.TokenAmount(mainnetTokens.ETH, '1'),
supply: new common.TokenAmount(common.mainnetTokens.WBTC, '1'),
borrow: new common.TokenAmount(common.mainnetTokens.ETH, '1'),
},
{
supply: new common.TokenAmount(mainnetTokens.ETH, '100'),
borrow: new common.TokenAmount(mainnetTokens.WBTC, '1'),
supply: new common.TokenAmount(common.mainnetTokens.ETH, '100'),
borrow: new common.TokenAmount(common.mainnetTokens.WBTC, '1'),
balanceBps: 5000,
},
{
supply: new common.TokenAmount(mainnetTokens.WBTC, '1'),
borrow: new common.TokenAmount(mainnetTokens.ETH, '1'),
supply: new common.TokenAmount(common.mainnetTokens.WBTC, '1'),
borrow: new common.TokenAmount(common.mainnetTokens.ETH, '1'),
balanceBps: 5000,
},
];
Expand Down
Loading

0 comments on commit 35d465d

Please sign in to comment.