Skip to content

Commit

Permalink
E2E test for SNX Rewards Distributor on Base Mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
noisekit committed Mar 26, 2024
1 parent d7e6e23 commit 742e7df
Show file tree
Hide file tree
Showing 3 changed files with 410 additions and 55 deletions.
63 changes: 63 additions & 0 deletions e2e/tasks/setMainnetTokenBalance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env node

const { ethers } = require('ethers');
const { setEthBalance } = require('./setEthBalance');
const { parseError } = require('../parseError');
const { gasLog } = require('../gasLog');

const log = require('debug')(`e2e:${require('path').basename(__filename, '.js')}`);

async function setMainnetTokenBalance({ wallet, balance, tokenAddress, friendlyWhale }) {
const Token = new ethers.Contract(
tokenAddress,
[
'function symbol() view returns (string)',
'function decimals() view returns (uint8)',
'function balanceOf(address account) view returns (uint256)',
'function transfer(address to, uint256 value) returns (bool)',
],
wallet
);
const decimals = await Token.decimals();
const symbol = await Token.symbol();

const oldBalance = parseFloat(
ethers.utils.formatUnits(await Token.balanceOf(wallet.address), decimals)
);
log({ symbol, tokenAddress, oldBalance });
if (oldBalance > balance) {
log({ result: 'SKIP' });
return;
}

// Mainnet only!
const whaleBalance = parseFloat(
ethers.utils.formatUnits(await Token.balanceOf(friendlyWhale), decimals)
);
log({ friendlyWhale, whaleBalance });

await setEthBalance({ address: friendlyWhale, balance: 1000 });

await wallet.provider.send('anvil_impersonateAccount', [friendlyWhale]);
const signer = wallet.provider.getSigner(friendlyWhale);
const tx = await Token.connect(signer).transfer(
wallet.address,
ethers.utils.parseUnits(`${balance - oldBalance}`, decimals)
);
await tx
.wait()
.then((txn) => log(txn.events) || txn, parseError)
.then(gasLog({ action: 'Token.transfer', log }));
await wallet.provider.send('anvil_stopImpersonatingAccount', [friendlyWhale]);

const newBalance = parseFloat(
ethers.utils.formatUnits(await Token.balanceOf(wallet.address), decimals)
);
log({ symbol, tokenAddress: tokenAddress, newBalance });

return null;
}

module.exports = {
setMainnetTokenBalance,
};
59 changes: 4 additions & 55 deletions e2e/tasks/setUSDCTokenBalance.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,13 @@
#!/usr/bin/env node

const { ethers } = require('ethers');
const { getCollateralConfig } = require('./getCollateralConfig');
const { setEthBalance } = require('./setEthBalance');
const { parseError } = require('../parseError');
const { gasLog } = require('../gasLog');

const log = require('debug')(`e2e:${require('path').basename(__filename, '.js')}`);
const { setMainnetTokenBalance } = require('./setMainnetTokenBalance');

async function setUSDCTokenBalance({ wallet, balance }) {
const config = await getCollateralConfig('USDC');
const Token = new ethers.Contract(
config.tokenAddress,
[
'function symbol() view returns (string)',
'function decimals() view returns (uint8)',
'function balanceOf(address account) view returns (uint256)',
'function transfer(address to, uint256 value) returns (bool)',
],
wallet
);
const decimals = await Token.decimals();
const symbol = await Token.symbol();

const oldBalance = parseFloat(
ethers.utils.formatUnits(await Token.balanceOf(wallet.address), decimals)
);
log({ symbol, tokenAddress: config.tokenAddress, oldBalance });
if (oldBalance > balance) {
log({ result: 'SKIP' });
return;
}

// Mainnet only!
const { tokenAddress } = await getCollateralConfig('USDC');
// BASE Mainnet only!
const friendlyWhale = '0xcdac0d6c6c59727a65f871236188350531885c43';
const whaleBalance = parseFloat(
ethers.utils.formatUnits(await Token.balanceOf(friendlyWhale), decimals)
);
log({ friendlyWhale, whaleBalance });

await setEthBalance({ address: friendlyWhale, balance: 1000 });

await wallet.provider.send('anvil_impersonateAccount', [friendlyWhale]);
const signer = wallet.provider.getSigner(friendlyWhale);
const tx = await Token.connect(signer).transfer(
wallet.address,
ethers.utils.parseUnits(`${balance - oldBalance}`, decimals)
);
await tx
.wait()
.then((txn) => log(txn.events) || txn, parseError)
.then(gasLog({ action: 'Token.transfer', log }));
await wallet.provider.send('anvil_stopImpersonatingAccount', [friendlyWhale]);

const newBalance = parseFloat(
ethers.utils.formatUnits(await Token.balanceOf(wallet.address), decimals)
);
log({ symbol, tokenAddress: config.tokenAddress, newBalance });

return null;
return setMainnetTokenBalance({ wallet, balance, tokenAddress, friendlyWhale });
}

module.exports = {
Expand Down
Loading

0 comments on commit 742e7df

Please sign in to comment.