Skip to content
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

feat: subgraph testing #123

Merged
merged 3 commits into from
Sep 11, 2024
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
22 changes: 22 additions & 0 deletions contracts/core/test/subgraphMocks/EthUsdAggregator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract MockEthUsdAggregator {
/**
* @notice Reads the current answer from aggregator delegated to.
* @dev overridden function to add the checkAccess() modifier
*
* @dev #[deprecated] Use latestRoundData instead. This does not error if no
* answer has been reached, it will simply return 0. Either wait to point to
* an already answered Aggregator or use the recommended latestRoundData
* instead which includes better verification information.
*/
function latestAnswer() public view checkAccess returns (int256) {
return 244453000000;
}

// Mock of checkAccess modifier to allow compilation
modifier checkAccess() {
_;
}
}
28 changes: 28 additions & 0 deletions contracts/core/test/subgraphMocks/LinkSdlSushiPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract MockLinkSdlSushiPool {
struct Reserves {
uint112 reserve0;
uint112 reserve1;
uint32 blockTimestampLast;
}

Reserves private _reserves;

constructor() {
_reserves = Reserves({
reserve0: 50280390552967262265,
reserve1: 2263776855667093842130,
blockTimestampLast: 1724692727
});
}

function getReserves()
external
view
returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast)
{
return (_reserves.reserve0, _reserves.reserve1, _reserves.blockTimestampLast);
}
}
28 changes: 28 additions & 0 deletions contracts/core/test/subgraphMocks/LinkSdlUniswapPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract MockLinkSdlUniswapPool {
struct Slot0 {
uint160 sqrtPriceX96;
int24 tick;
uint16 observationIndex;
uint16 observationCardinality;
uint16 observationCardinalityNext;
uint8 feeProtocol;
bool unlocked;
}

Slot0 public slot0;

constructor() {
slot0 = Slot0({
sqrtPriceX96: 539950026751222674039685537688,
tick: 38384,
observationIndex: 0,
observationCardinality: 1,
observationCardinalityNext: 1,
feeProtocol: 0,
unlocked: true
});
}
}
22 changes: 22 additions & 0 deletions contracts/core/test/subgraphMocks/LinkUsdAggregator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract MockLinkUsdAggregator {
/**
* @notice Reads the current answer from aggregator delegated to.
* @dev overridden function to add the checkAccess() modifier
*
* @dev #[deprecated] Use latestRoundData instead. This does not error if no
* answer has been reached, it will simply return 0. Either wait to point to
* an already answered Aggregator or use the recommended latestRoundData
* instead which includes better verification information.
*/
function latestAnswer() public view checkAccess returns (int256) {
return 1110908500;
}

// Mock of checkAccess modifier to allow compilation
modifier checkAccess() {
_;
}
}
28 changes: 28 additions & 0 deletions contracts/core/test/subgraphMocks/MetisEthUniswapPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract MockMetisEthUniswapPool {
struct Slot0 {
uint160 sqrtPriceX96;
int24 tick;
uint16 observationIndex;
uint16 observationCardinality;
uint16 observationCardinalityNext;
uint8 feeProtocol;
bool unlocked;
}

Slot0 public slot0;

constructor() {
slot0 = Slot0({
sqrtPriceX96: 921607156908519294832225,
tick: -43030,
observationIndex: 52,
observationCardinality: 80,
observationCardinalityNext: 80,
feeProtocol: 0,
unlocked: true
});
}
}
2 changes: 2 additions & 0 deletions scripts/test/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { deployCore } from './modules/deploy-core'
import { deployLINKStaking } from './modules/deploy-link-staking'
import { deployMETISStaking } from './modules/deploy-metis-staking'
import { deployTestContracts } from './modules/deploy-test-contracts'
import { deploySubgraphMockContracts } from './modules/deploy-subgraph-mocks'

const path = './deployments/localhost.json'

Expand All @@ -15,6 +16,7 @@ async function main() {
await deployCore()
await deployLINKStaking()
await deployMETISStaking()
await deploySubgraphMockContracts()
}

main()
Expand Down
33 changes: 33 additions & 0 deletions scripts/test/deploy/modules/deploy-subgraph-mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { deploy } from '../../../utils/deployment'

export async function deploySubgraphMockContracts() {
const mockEthUsdAggregator = await deploy(
'contracts/core/test/subgraphMocks/EthUsdAggregator.sol:MockEthUsdAggregator',
[]
)
console.log('MockEthUsdAggregator deployed: ', mockEthUsdAggregator.target)

const mockLinkSdlSushiPool = await deploy(
'contracts/core/test/subgraphMocks/LinkSdlSushiPool.sol:MockLinkSdlSushiPool',
[]
)
console.log('MockLinkSdlSushiPool deployed: ', mockLinkSdlSushiPool.target)

const mockLinkSdlUniswapPool = await deploy(
'contracts/core/test/subgraphMocks/LinkSdlUniswapPool.sol:MockLinkSdlUniswapPool',
[]
)
console.log('MockLinkSdlUniswapPool deployed: ', mockLinkSdlUniswapPool.target)

const mockLinkUsdAggregator = await deploy(
'contracts/core/test/subgraphMocks/LinkUsdAggregator.sol:MockLinkUsdAggregator',
[]
)
console.log('MockLinkUsdAggregator deployed: ', mockLinkUsdAggregator.target)

const mockMetisEthUniswapPool = await deploy(
'contracts/core/test/subgraphMocks/MetisEthUniswapPool.sol:MockMetisEthUniswapPool',
[]
)
console.log('MockMetisEthUniswapPool deployed: ', mockMetisEthUniswapPool.target)
}
Loading