First relayprovider typescript test

This commit is contained in:
derpy-duck 2023-02-08 20:47:54 +00:00 committed by chase-45
parent 840f18b931
commit 58f34e0805
7 changed files with 67 additions and 105 deletions

View File

@ -4,31 +4,31 @@
"relayProviders": [
{
"chainId": 2,
"address": ""
"address": "0xd45A464a2412A2f83498d13635698a041b9dBe9b"
},
{
"chainId": 4,
"address": ""
"address": "0x9ce4cd6D7f5e8b14c7a3e8e6A257A86Bd5a6EeA0"
}
],
"coreRelayers": [
{
"chainId": 2,
"address": ""
"address": "0x0d3C71782055bD88A71b611972152d6e984EDF79"
},
{
"chainId": 4,
"address": ""
"address": "0xd45A464a2412A2f83498d13635698a041b9dBe9b"
}
],
"mockIntegrations": [
{
"chainId": 2,
"address": ""
"address": "0x81920CAF1F99Bb0f7D72Fdfba840cff21d63CcC5"
},
{
"chainId": 4,
"address": ""
"address": "0xe6dA6E31540239b4a09eC574f147004D50f1b140"
}
]
}
}

View File

@ -1,49 +0,0 @@
import { expect } from "chai";
import { ethers } from "ethers";
import { GasOracle__factory } from "../../sdk/src";
import {
CHAIN_ID_AVAX,
CHAIN_ID_ETH,
GAS_ORACLE_ADDRESS,
LOCALHOST,
ORACLE_DEPLOYER_PRIVATE_KEY,
} from "./helpers/consts";
const ETHEREUM_ROOT = `${__dirname}/..`;
describe("Gas Oracle Integration Test", () => {
const provider = new ethers.providers.StaticJsonRpcProvider(LOCALHOST);
// signers
const oracleDeployer = new ethers.Wallet(ORACLE_DEPLOYER_PRIVATE_KEY, provider);
const gasOracleAbiPath = `${ETHEREUM_ROOT}/build/GasOracle.sol/GasOracle.json`;
const gasOracle = GasOracle__factory.connect( GAS_ORACLE_ADDRESS, oracleDeployer);
const ethPrice = ethers.utils.parseUnits("2000.00", 8);
const ethereumGasPrice = ethers.utils.parseUnits("100", 9);
const avaxPrice = ethers.utils.parseUnits("20.00", 8);
const avalancheGasPrice = ethers.utils.parseUnits("100", 9);
describe("Core Relayer Interaction", () => {
it("updatePrices", async () => {
const updates = [
{
chainId: CHAIN_ID_ETH,
gasPrice: ethereumGasPrice,
nativeCurrencyPrice: ethPrice,
},
{
chainId: CHAIN_ID_AVAX,
gasPrice: avalancheGasPrice,
nativeCurrencyPrice: avaxPrice,
},
];
const updatePricesTx = await gasOracle.updatePrices(updates).then((tx: any) => tx.wait());
// TODO: check getter
});
});
});

View File

@ -0,0 +1,42 @@
import { expect } from "chai";
import { ethers } from "ethers";
import { RelayProvider__factory } from "../../sdk/src";
import {
ORACLE_DEPLOYER_PRIVATE_KEY,
ChainInfo
} from "./helpers/consts";
import { init, loadChains, loadRelayProviders } from "../ts-scripts/helpers/env";
const ETHEREUM_ROOT = `${__dirname}/..`;
init()
const chains = loadChains();
const relayProviders = loadRelayProviders();
describe("Relay Provider Test", () => {
const chain = chains[0]
const provider = new ethers.providers.StaticJsonRpcProvider(chain.rpc);
// signers
const oracleDeployer = new ethers.Wallet(ORACLE_DEPLOYER_PRIVATE_KEY, provider);
const relayProviderAddress = relayProviders.find((p)=>(p.chainId==chain.chainId))?.address as string
const relayProviderAbiPath = `${ETHEREUM_ROOT}/build/RelayProvider.sol/RelayProvider.json`;
const relayProvider = RelayProvider__factory.connect(relayProviderAddress, oracleDeployer);
describe("Read Prices Correctly", () => {
it("readPrices", async () => {
const tokenPrice = ethers.BigNumber.from("100000");
const gasPrice = ethers.BigNumber.from("300000000000")
const tokenPriceReturned = await relayProvider.nativeCurrencyPrice(chain.chainId);
const gasPriceReturned = await relayProvider.gasPrice(chain.chainId);
expect(tokenPriceReturned.toString()).to.equal(tokenPrice.toString());
expect(gasPriceReturned.toString()).to.equal(gasPrice.toString());
// TODO: check getter
});
});
});

View File

@ -1,13 +1,8 @@
import { expect } from "chai";
import { ethers } from "ethers";
import { TestResults } from "./helpers/structs";
import { ChainId, tryNativeToHexString } from "@certusone/wormhole-sdk";
import {
CHAIN_ID_ETH,
CORE_RELAYER_ADDRESS,
LOCALHOST,
RELAYER_DEPLOYER_PRIVATE_KEY,
MOCK_RELAYER_INTEGRATION_ADDRESS,
} from "./helpers/consts";
import {
getSignedBatchVaaFromReceiptOnEth,
@ -16,16 +11,22 @@ import {
} from "./helpers/utils";
import { CoreRelayer__factory, MockRelayerIntegration__factory } from "../../sdk/src";
import { CoreRelayerStructs } from "../../sdk/src/ethers-contracts/CoreRelayer";
import { init, loadChains, loadCoreRelayers, loadMockIntegrations } from "../ts-scripts/helpers/env";
const ETHEREUM_ROOT = `${__dirname}/..`;
init()
const chains = loadChains();
const coreRelayers = loadCoreRelayers();
const mockIntegrations = loadMockIntegrations();
describe("Core Relayer Integration Test", () => {
const provider = new ethers.providers.StaticJsonRpcProvider(LOCALHOST);
const provider = new ethers.providers.StaticJsonRpcProvider(chains[0].rpc);
// signers
const wallet = new ethers.Wallet(RELAYER_DEPLOYER_PRIVATE_KEY, provider);
const coreRelayer = CoreRelayer__factory.connect(CORE_RELAYER_ADDRESS, wallet);
const coreRelayer = CoreRelayer__factory.connect(coreRelayers, wallet);
const mockContract = MockRelayerIntegration__factory.connect(MOCK_RELAYER_INTEGRATION_ADDRESS, wallet);
// test batch VAA information

View File

@ -1,24 +1,20 @@
// rpc
export const LOCALHOST = "http://localhost:8545";
// wormhole
export const CORE_BRIDGE_ADDRESS = "0xC89Ce4735882C9F0f0FE26686c53074E09B0D550";
import { ChainId } from "@certusone/wormhole-sdk";
// signer
export const ORACLE_DEPLOYER_PRIVATE_KEY = "0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d";
export const RELAYER_DEPLOYER_PRIVATE_KEY = "0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d";
export const GUARDIAN_PRIVATE_KEY = "cfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0";
// contract address
export const GAS_ORACLE_ADDRESS = "0x9561C133DD8580860B6b7E504bC5Aa500f0f06a7";
export const CORE_RELAYER_ADDRESS = "0x9b1f7F645351AF3631a656421eD2e40f2802E6c0";
export const MOCK_RELAYER_INTEGRATION_ADDRESS = "0x2612Af3A521c2df9EAF28422Ca335b04AdF3ac66";
// misc
export const CHAIN_ID_ETH = 2;
export const CHAIN_ID_AVAX = 6;
// wormhole event ABIs
export const WORMHOLE_MESSAGE_EVENT_ABI = [
"event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, uint8 consistencyLevel)",
];
export type ChainInfo = {
evmNetworkId: number
chainId: ChainId
rpc: string
wormholeAddress: string
coreRelayerAddress: string
description: string
};

View File

@ -1,11 +0,0 @@
import { ethers } from "ethers";
import fs from "fs";
import { MockRelayerIntegration, MockRelayerIntegration__factory } from "../../../sdk/src";
export function makeContract(
signerOrProvider: ethers.Signer | ethers.providers.Provider,
contractAddress: string,
abiPath: string
): MockRelayerIntegration {
return MockRelayerIntegration__factory.connect(contractAddress, signerOrProvider)
}

View File

@ -1,17 +0,0 @@
import { ethers } from "ethers";
import { MockRelayerIntegration } from "../../../sdk/src/ethers-contracts/MockRelayerIntegration";
export interface RelayerArgs {
nonce: number;
targetChainId: number;
targetAddress: string;
targetGasLimit: number;
consistencyLevel: number;
}
export interface TestResults {
relayerArgs: MockRelayerIntegration.RelayerArgsStruct;
signedBatchVM: ethers.BytesLike;
targetChainGasEstimate: ethers.BigNumber;
deliveryStatusVM: ethers.BytesLike;
}