2021-11-01 09:43:22 +00:00
|
|
|
//
|
|
|
|
// Copyright 2021 Vulcanize, Inc.
|
|
|
|
//
|
|
|
|
|
2021-12-08 12:54:46 +00:00
|
|
|
import { BaseProvider } from '@ethersproject/providers';
|
2022-09-09 11:43:01 +00:00
|
|
|
import { getCustomProvider } from '@cerc-io/util';
|
|
|
|
import { EthClient } from '@cerc-io/ipld-eth-client';
|
|
|
|
import { StorageLayout } from '@cerc-io/solidity-mapper';
|
2021-12-08 12:54:46 +00:00
|
|
|
|
2021-11-01 09:43:22 +00:00
|
|
|
import { EventData } from '../../src/utils';
|
2021-11-10 07:42:37 +00:00
|
|
|
import { Database } from '../../src/database';
|
2021-11-29 12:21:16 +00:00
|
|
|
import { Indexer } from './indexer';
|
2021-11-01 09:43:22 +00:00
|
|
|
|
2021-12-08 12:54:46 +00:00
|
|
|
const NETWORK_URL = 'http://127.0.0.1:8081';
|
2022-08-17 10:55:49 +00:00
|
|
|
const IPLD_ETH_SERVER_GQL_URL = 'http://127.0.0.1:8082/graphql';
|
2021-12-08 12:54:46 +00:00
|
|
|
|
2021-11-01 09:43:22 +00:00
|
|
|
export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
|
|
export const ZERO_HASH = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
|
|
|
2021-12-08 12:54:46 +00:00
|
|
|
export const getDummyEventData = async (): Promise<EventData> => {
|
|
|
|
// Get the latest mined block from the chain.
|
|
|
|
const provider = getCustomProvider(NETWORK_URL);
|
|
|
|
const blockNumber = await provider.getBlockNumber();
|
|
|
|
const ethersBlock = await provider.getBlock(blockNumber);
|
|
|
|
|
2021-11-01 09:43:22 +00:00
|
|
|
const block = {
|
2021-12-30 07:42:32 +00:00
|
|
|
headerId: 0,
|
2021-12-08 12:54:46 +00:00
|
|
|
blockHash: ethersBlock.hash,
|
|
|
|
blockNumber: ethersBlock.number.toString(),
|
2021-11-10 07:42:37 +00:00
|
|
|
timestamp: '0',
|
|
|
|
parentHash: ZERO_HASH,
|
|
|
|
stateRoot: ZERO_HASH,
|
|
|
|
td: ZERO_HASH,
|
|
|
|
txRoot: ZERO_HASH,
|
2021-11-25 10:49:45 +00:00
|
|
|
receiptRoot: ZERO_HASH,
|
|
|
|
uncleHash: ZERO_HASH,
|
|
|
|
difficulty: '0',
|
|
|
|
gasLimit: '0',
|
2021-12-01 10:52:37 +00:00
|
|
|
gasUsed: '0',
|
2021-12-02 12:37:17 +00:00
|
|
|
author: ZERO_ADDRESS,
|
|
|
|
size: '0'
|
2021-11-01 09:43:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const tx = {
|
|
|
|
hash: ZERO_HASH,
|
|
|
|
index: 0,
|
|
|
|
from: ZERO_ADDRESS,
|
2021-12-30 07:42:32 +00:00
|
|
|
to: ZERO_ADDRESS,
|
|
|
|
value: '0',
|
|
|
|
gasLimit: '0',
|
|
|
|
gasPrice: '0',
|
|
|
|
input: ZERO_HASH
|
2021-11-01 09:43:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
block,
|
|
|
|
tx,
|
2021-11-25 10:49:45 +00:00
|
|
|
inputs: [],
|
|
|
|
event: {},
|
2021-11-01 09:43:22 +00:00
|
|
|
eventIndex: 0
|
|
|
|
};
|
|
|
|
};
|
2021-11-10 07:42:37 +00:00
|
|
|
|
2021-11-29 12:21:16 +00:00
|
|
|
export const getDummyGraphData = (): any => {
|
|
|
|
return {
|
|
|
|
dataSource: {
|
2021-12-30 12:27:34 +00:00
|
|
|
address: ZERO_ADDRESS,
|
|
|
|
network: 'mainnet'
|
2021-11-29 12:21:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-11-10 07:42:37 +00:00
|
|
|
export const getTestDatabase = (): Database => {
|
|
|
|
return new Database({ type: 'postgres' }, '');
|
|
|
|
};
|
2021-11-29 12:21:16 +00:00
|
|
|
|
2022-08-17 10:55:49 +00:00
|
|
|
export const getTestIndexer = (storageLayout?: Map<string, StorageLayout>): Indexer => {
|
|
|
|
const ethClient = new EthClient({
|
|
|
|
gqlEndpoint: IPLD_ETH_SERVER_GQL_URL,
|
|
|
|
cache: undefined
|
|
|
|
});
|
|
|
|
|
|
|
|
return new Indexer(ethClient, storageLayout);
|
2021-11-29 12:21:16 +00:00
|
|
|
};
|
2021-12-08 12:54:46 +00:00
|
|
|
|
|
|
|
export const getTestProvider = (): BaseProvider => {
|
|
|
|
const provider = getCustomProvider(NETWORK_URL);
|
|
|
|
|
|
|
|
return provider;
|
|
|
|
};
|