Skip to content

Commit

Permalink
test: fixing tests [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase committed Aug 19, 2024
1 parent 204a505 commit c038f62
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 115 deletions.
10 changes: 4 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
NODE_URI_ETHEREUM=
NODE_URI_OPTIMISM=
NODE_URI_POLYGON=
NODE_URI_GOERLI=
NODE_URI_OPTIMISTICGOERLI=
NODE_URI_MUMBAI=
NODE_URI_SEPOLIA=
NODE_URI_OPTIMISTICSEPOLIA=

# Account's private keys
ETHEREUM_1_PRIVATE_KEY=
Expand All @@ -13,9 +12,8 @@ TEST_1_PRIVATE_KEY=
# Etherscan (optional, only for verifying smart contracts)
ETHEREUM_ETHERSCAN_API_KEY=
OPTIMISTICETHEREUM_ETHERSCAN_API_KEY=
GOERLI_ETHERSCAN_API_KEY=
OPTIMISTICGOERLI_ETHERSCAN_API_KEY=
POLYGONMUMBAI_ETHERSCAN_API_KEY=
SEPOLIA_ETHERSCAN_API_KEY=
OPTIMISTICSEPOLIA_ETHERSCAN_API_KEY=
POLYGON_ETHERSCAN_API_KEY=

# Mocha (10 minutes)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ jobs:
run: yarn test:e2e
env:
NODE_URI_ETHEREUM: ${{ secrets.NODE_URI_MAINNET }}
NODE_URI_GOERLI: https://eth-goerli.alchemyapi.io/v2/${{ secrets.ALCHEMYKEY }}
NODE_URI_SEPOLIA: https://eth-sepolia.alchemyapi.io/v2/${{ secrets.ALCHEMYKEY }}
32 changes: 12 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
- [Setup](#setup)
- [Address Registry](#address-registry)
- [Testnet](#testnet)
- [Goerli (sender and _receiver_)](#goerli-sender-and-receiver)
- [OP Goerli (_receiver_)](#op-goerli-receiver)
- [Mumbai (manual sender)](#mumbai-manual-sender)
- [Sepolia (sender and _receiver_)](#sepolia-sender-and-receiver)
- [OP Sepolia (_receiver_)](#op-sepolia-receiver)
- [Sepolia (manual sender)](#sepolia-manual-sender)
- [Whitelisted pipelines](#whitelisted-pipelines)

## Scope
Expand Down Expand Up @@ -169,7 +169,7 @@ NOTE: A more gas-efficient array-filling strategy can be built by making more ex

## Setup

Clone the repo in your preferred way, and fill the `.env` file using the `.env.example` as a reference. The environment is yet set to work with testnets, using Goerli to OP Goerli bridge as default.
Clone the repo in your preferred way, and fill the `.env` file using the `.env.example` as a reference. The environment is yet set to work with testnets, using Sepolia to OP Sepolia bridge as default.

For a dummy setup (without bridging) run:

Expand All @@ -195,15 +195,15 @@ yarn deploy:work
```

For 1 tag manual-deployment and bridging
`yarn deploy --network mumbai --tags manual-send-test-observation`
`yarn deploy --network sepolia --tags manual-send-test-observation`

In `/utils/constants.ts`, one can find the configuration of the strategies chosen by chain. The default for Goerli is set to refresh each 1/2 day, using periods of 1hr, and comparing a 2hr twap with 500 ticks (+-5%) threshold.
In `/utils/constants.ts`, one can find the configuration of the strategies chosen by chain. The default for Sepolia is set to refresh each 1/2 day, using periods of 1hr, and comparing a 2hr twap with 500 ticks (+-5%) threshold.

## Address Registry

#### Testnet

##### Goerli (sender and _receiver_)
##### Sepolia (sender and _receiver_)

| Contract | Address |
| ------------------------- | -------------------------------------------- |
Expand All @@ -215,25 +215,17 @@ In `/utils/constants.ts`, one can find the configuration of the strategies chose
| _DataReceiver_ | `0xa09683377E5cE0bB7eEa90D2b64e3644f7eA1B8a` |
| _OracleFactory_ | `0x0594Dc74043b93Bdb371f01187704C98D45bd4E6` |

##### OP Goerli (_receiver_)
##### OP Sepolia (_receiver_)

| Contract | Address |
| ------------------------- | -------------------------------------------- |
| _Connext ReceiverAdapter_ | `0x4D81A5C9F7706377df368D1716460da03faEcBcb` |
| _DataReceiver_ | `0x768c227320165A71A4001fE23A0C38CD6B5585c0` |
| _OracleFactory_ | `0xB8aD440Ad7A3298C73258b1Fc202A081Db9107cb` |

##### Mumbai (manual sender)

| Contract | Address |
| --------------------- | -------------------------------------------- |
| DataFeed | `0x1c9Bc091f070A10E23B2a90eA543AD38AA3De1EE` |
| Connext SenderAdapter | `0x4C8589e7D1d91e454F5f30C3e1bb3e197B5Bf368` |

##### Whitelisted pipelines:

| Chain - Pool | Chain - OracleSidechain |
| ----------------------------------------------------- | -------------------------------------------------------- |
| Goerli - `0x317ceCd3eB02158f97DF0B67B788edCda4E066e5` | OP Goerli - `0x4ECFF2c532d47D7be3D957E4a332AB134cad1fd9` |
| Mumbai - `0xd69f1635dc28a11E05841AE25Fd1572FD0EF1eF4` | Goerli - `0x050BBA5E4abde750Ea5610D8412cD46171C665e7` |
| Goerli - `0x317ceCd3eB02158f97DF0B67B788edCda4E066e5` | Goerli - `0xED7f635EE962537b4DB13a1e1c3922EC65366fE2` |
| Chain - Pool | Chain - OracleSidechain |
| ------------------------------------------------------ | --------------------------------------------------------- |
| Sepolia - `0x317ceCd3eB02158f97DF0B67B788edCda4E066e5` | OP Sepolia - `0x4ECFF2c532d47D7be3D957E4a332AB134cad1fd9` |
| Sepolia - `0x317ceCd3eB02158f97DF0B67B788edCda4E066e5` | Sepolia - `0xED7f635EE962537b4DB13a1e1c3922EC65366fE2` |
12 changes: 6 additions & 6 deletions deploy/1-setup/102_setup_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
import { calculateSalt } from '../../test/utils/misc';
import { ZERO_ADDRESS } from '../../test/utils/constants';
import { TEST_FEE, UNI_V3_FACTORY } from '../../utils/constants';
import { TEST_FEE } from '../../utils/constants';
import { getReceiverChainId } from '../../utils/deploy';

const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer, tokenA, tokenB } = await hre.getNamedAccounts();
const { deployer, tokenA, tokenB, uniV3Factory } = await hre.getNamedAccounts();
const DESTINATION_CHAIN_ID = await getReceiverChainId(hre);

const txSettings = {
Expand All @@ -18,18 +18,18 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro

await hre.deployments.save('UniswapV3Factory', {
abi: IUniswapV3Factory.abi,
address: UNI_V3_FACTORY,
address: uniV3Factory,
});

const POOL_ADDRESS = await hre.deployments.read('UniswapV3Factory', 'getPool', tokenA, tokenB, TEST_FEE);
if (ZERO_ADDRESS == POOL_ADDRESS) {
let poolAddress = await hre.deployments.read('UniswapV3Factory', 'getPool', tokenA, tokenB, TEST_FEE);
if (ZERO_ADDRESS == poolAddress) {
console.log('Pool does not exist', tokenA, tokenB, TEST_FEE);
return;
}

await hre.deployments.save('UniswapV3Pool', {
abi: IUniswapV3Pool.abi,
address: POOL_ADDRESS,
address: poolAddress,
});

const salt = calculateSalt(tokenA, tokenB, TEST_FEE);
Expand Down
6 changes: 3 additions & 3 deletions deploy/1-setup/121_setup_dummy_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
import { calculateSalt } from '../../test/utils/misc';
import { ZERO_ADDRESS } from '../../test/utils/constants';
import { TEST_FEE, UNI_V3_FACTORY } from '../../utils/constants';
import { TEST_FEE } from '../../utils/constants';

const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer, tokenA, tokenB } = await hre.getNamedAccounts();
const { deployer, tokenA, tokenB, uniV3Factory } = await hre.getNamedAccounts();
const DESTINATION_CHAIN_ID = await hre.getChainId();

const txSettings = {
Expand All @@ -17,7 +17,7 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro

await hre.deployments.save('UniswapV3Factory', {
abi: IUniswapV3Factory.abi,
address: UNI_V3_FACTORY,
address: uniV3Factory,
});

const POOL_ADDRESS = await hre.deployments.read('UniswapV3Factory', 'getPool', tokenA, tokenB, TEST_FEE);
Expand Down
6 changes: 3 additions & 3 deletions deploy/2-token-actions/202_save_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import IUniswapV3Pool from '../../artifacts/@uniswap/v3-core/contracts/interface
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
import { ZERO_ADDRESS } from '../../test/utils/constants';
import { TEST_FEE, UNI_V3_FACTORY } from '../../utils/constants';
import { TEST_FEE } from '../../utils/constants';

const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { tokenA, tokenB } = await hre.getNamedAccounts();
const { tokenA, tokenB, uniV3Factory } = await hre.getNamedAccounts();

await hre.deployments.save('UniswapV3Factory', {
abi: IUniswapV3Factory.abi,
address: UNI_V3_FACTORY,
address: uniV3Factory,
});

const POOL_ADDRESS = await hre.deployments.read('UniswapV3Factory', 'getPool', tokenA, tokenB, TEST_FEE);
Expand Down
6 changes: 3 additions & 3 deletions deploy/2-token-actions/212_deploy_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import IUniswapV3Factory from '../../artifacts/@uniswap/v3-core/contracts/interf
import IUniswapV3Pool from '../../artifacts/@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol/IUniswapV3Pool.json';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
import { TEST_FEE, UNI_V3_FACTORY } from '../../utils/constants';
import { TEST_FEE } from '../../utils/constants';

const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts();
const { deployer, uniV3Factory } = await hre.getNamedAccounts();
const addressZero = '0x0000000000000000000000000000000000000000';

const txSettings = {
Expand All @@ -15,7 +15,7 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro

await hre.deployments.save('UniswapV3Factory', {
abi: IUniswapV3Factory.abi,
address: UNI_V3_FACTORY,
address: uniV3Factory,
});

/* DEPLOY POOL */
Expand Down
31 changes: 11 additions & 20 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const networks: NetworksUserConfig =
hardhat: {
forking: {
enabled: process.env.FORK ? true : false,
url: env.getNodeUrl('goerli'),
url: env.getNodeUrl('sepolia'),
},
chainId: 5,
chainId: 11155111,
companionNetworks: {
receiver: 'hardhat',
},
Expand All @@ -48,29 +48,20 @@ const networks: NetworksUserConfig =
chainId: 137,
companionNetworks: { sender: 'ethereum' },
},
goerli: {
url: env.getNodeUrl('goerli'),
sepolia: {
url: env.getNodeUrl('sepolia'),
accounts: env.getAccounts('test'),
chainId: 5,
chainId: 11155111,
companionNetworks: {
receiver: 'optimisticGoerli',
sender: 'polygonMumbai',
receiver: 'optimisticSepolia',
},
},
polygonMumbai: {
url: env.getNodeUrl('mumbai'),
optimisticSepolia: {
url: env.getNodeUrl('optimisticSepolia'),
accounts: env.getAccounts('test'),
chainId: 80001,
chainId: 11155420,
companionNetworks: {
receiver: 'goerli',
},
},
optimisticGoerli: {
url: env.getNodeUrl('optimisticGoerli'),
accounts: env.getAccounts('test'),
chainId: 420,
companionNetworks: {
sender: 'goerli',
sender: 'sepolia',
},
},
};
Expand Down Expand Up @@ -116,7 +107,7 @@ const config: HardhatUserConfig = {
onlyCalledMethods: false,
},
etherscan: {
apiKey: env.getEtherscanAPIKeys(['ethereum', 'optimisticEthereum', 'polygon', 'goerli', 'optimisticGoerli', 'polygonMumbai']),
apiKey: env.getEtherscanAPIKeys(['ethereum', 'optimisticEthereum', 'polygon', 'sepolia', 'optimisticSepolia']),
},
typechain: {
outDir: 'typechained',
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
"compile:test": "cross-env TEST=true hardhat compile",
"coverage": "hardhat coverage",
"deploy": "npx hardhat deploy",
"deploy:bridge": "yarn deploy --network goerli --tags bridge-observation",
"deploy:bridge-dummy": "yarn deploy --network goerli --tags dummy-bridge-observation",
"deploy:fetch": "yarn deploy --network goerli --tags fetch-observation",
"deploy:force-fetch": "yarn deploy --network goerli --tags force-fetch-observation",
"deploy:setup": "yarn deploy --network goerli --tags setup-connext-default",
"deploy:setup-dummy": "yarn deploy --network mumbai --tags data-receiver",
"deploy:work": "yarn deploy --network goerli --tags work-job",
"deploy:bridge": "yarn deploy --network sepolia --tags bridge-observation",
"deploy:bridge-dummy": "yarn deploy --network sepolia --tags dummy-bridge-observation",
"deploy:fetch": "yarn deploy --network sepolia --tags fetch-observation",
"deploy:force-fetch": "yarn deploy --network sepolia --tags force-fetch-observation",
"deploy:setup": "yarn deploy --network sepolia --tags setup-connext-default",
"deploy:setup-dummy": "yarn deploy --network sepolia --tags data-receiver",
"deploy:work": "yarn deploy --network sepolia --tags work-job",
"fork:node": "cross-env FORK=true hardhat node",
"fork:script": "cross-env FORK=true hardhat run",
"postinstall": "husky install && yarn compile:test",
Expand Down Expand Up @@ -111,7 +111,7 @@
"dotenv": "16.0.0",
"ethereum-waffle": "3.4.4",
"ethers": "5.6.4",
"hardhat": "2.12.0",
"hardhat": "2.12.1-unknown-txs.0",
"hardhat-contract-sizer": "2.6.1",
"hardhat-deploy": "0.11.23",
"hardhat-gas-reporter": "1.0.8",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/data-bridging.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('@skip-on-coverage Data Bridging Flow', () => {
let broadcastTx: ContractTransaction;
let snapshotId: string;

const destinationDomain = 420;
const destinationDomain = 11155111;
const nonce = 1;
const connextFee = toUnit(0.1);

Expand Down
8 changes: 4 additions & 4 deletions test/e2e/deployment-fixtures.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ describe('@skip-on-coverage Fixture', () => {
({ deployer } = await getNamedAccounts());

await evm.reset({
jsonRpcUrl: getNodeUrl('goerli'),
blockNumber: forkBlockNumber.goerli,
jsonRpcUrl: getNodeUrl('sepolia'),
blockNumber: forkBlockNumber.sepolia,
});
});

Expand Down Expand Up @@ -71,7 +71,7 @@ describe('@skip-on-coverage Fixture', () => {

describe('when pool is deployed', () => {
beforeEach(async () => {
await deployments.fixture(['save-tokens', 'pool-whitelisting'], { keepExistingDeployments: true });
await deployments.fixture(['save-tokens', 'create-pool', 'pool-whitelisting'], { keepExistingDeployments: true });

tokenA = (await getContractFromFixture('TokenA', 'IERC20')) as Type.IERC20;
tokenB = (await getContractFromFixture('TokenB', 'IERC20')) as Type.IERC20;
Expand Down Expand Up @@ -173,7 +173,7 @@ describe('@skip-on-coverage Fixture', () => {

const fetchData = dataFeed.interface.decodeEventLog('PoolObserved', queryResults[0].data);

const REAL_CHAIN_ID = 420;
const REAL_CHAIN_ID = 11155111;

await expect(
strategyJob['work(uint32,bytes32,uint24,(uint32,int24)[])'](REAL_CHAIN_ID, poolSalt, lastPoolNonce, fetchData._observationsData)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/fork-block-numbers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const forkBlockNumber: { [name: string]: number } = {
oracleSidechain: 16250000,
goerli: 8189000,
sepolia: 6500000,
};

export default forkBlockNumber;
24 changes: 16 additions & 8 deletions test/unit/DataReceiver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,28 @@ describe('DataReceiver.sol', () => {
expect(oracleFactory.deployOracle).to.not.be.called;
});

it('should revert if the observations are not writable', async () => {
it('should revert if the observations are already written', async () => {
oracleSidechain.write.whenCalledWith(observationsData, randomNonce).returns(false);
oracleSidechain.poolNonce.whenCalledWith().returns(randomNonce + 1);
await expect(dataReceiver.connect(fakeAdapter).addObservations(observationsData, randomSalt, randomNonce)).to.be.revertedWith(
'ObservationsNotWritable()'
);
});

it('should cache the observations that should not be written yet', async () => {
oracleSidechain.write.whenCalledWith(observationsData, randomNonce).returns(false);
oracleSidechain.poolNonce.whenCalledWith().returns(randomNonce - 1);
const tx = await dataReceiver.connect(fakeAdapter).addObservations(observationsData, randomSalt, randomNonce);

let eventAdapter = await readArgFromEvent(tx, 'ObservationsCached', '_receiverAdapter');
let eventSalt = await readArgFromEvent(tx, 'ObservationsCached', '_poolSalt');
let eventNonce = await readArgFromEvent(tx, 'ObservationsCached', '_poolNonce');

expect(eventAdapter).to.eq(fakeAdapter.address);
expect(eventSalt).to.eq(randomSalt);
expect(eventNonce).to.eq(randomNonce);
});

it('should emit ObservationsAdded', async () => {
const tx = await dataReceiver.connect(fakeAdapter).addObservations(observationsData, randomSalt, randomNonce);
let eventAdapter = await readArgFromEvent(tx, 'ObservationsAdded', '_receiverAdapter');
Expand Down Expand Up @@ -155,13 +170,6 @@ describe('DataReceiver.sol', () => {
expect(deployedOracle).to.eq(oracleSidechain.address);
});

it('should revert if the observations are not writable', async () => {
oracleSidechain.write.whenCalledWith(observationsData, randomNonce).returns(false);
await expect(dataReceiver.connect(fakeAdapter).addObservations(observationsData, randomSalt, randomNonce)).to.be.revertedWith(
'ObservationsNotWritable()'
);
});

it('should emit ObservationsAdded', async () => {
tx = await dataReceiver.connect(fakeAdapter).addObservations(observationsData, randomSalt, randomNonce);
let eventAdapter = await readArgFromEvent(tx, 'ObservationsAdded', '_receiverAdapter');
Expand Down
Loading

0 comments on commit c038f62

Please sign in to comment.