-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ALL-2878 - Add Beacon methods to eth (#999)
- Loading branch information
Showing
19 changed files
with
453 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface GetI { | ||
path: string | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
basePath?: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { EvmE2eUtils } from './rpc/evm/evm.e2e.utils'; | ||
import { Network } from '../dto'; | ||
import fs from 'fs'; | ||
|
||
describe.skip('IPFS', () => { | ||
it('should upload file to IPFS', async () => { | ||
const tatum = await EvmE2eUtils.initTatum(Network.ETHEREUM, process.env.V4_API_KEY_MAINNET); | ||
const fileData = fs.readFileSync('./test.txt'); // Adjust the path to your file | ||
const response = await tatum.ipfs.uploadFile({ file: fileData }); | ||
expect(response.status).toBe('SUCCESS'); | ||
expect(response.data.ipfsHash).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Network } from '../../../../dto' | ||
import { EvmE2eUtils } from '../evm.e2e.utils' | ||
import { Ethereum } from '../../../../service' | ||
|
||
describe('Beacon', () => { | ||
describe('v1', () => { | ||
const networks = [ | ||
Network.ETHEREUM_HOLESKY, | ||
Network.ETHEREUM_SEPOLIA, | ||
Network.ETHEREUM | ||
]; | ||
|
||
describe.each(networks)('%s', (network) => { | ||
it('should get genesis', async () => { | ||
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, process.env.V4_API_KEY_TESTNET); | ||
const { data } = await tatum.rpc.beacon.v1.getGenesis(); | ||
await tatum.destroy(); | ||
expect(data).toBeDefined(); | ||
}); | ||
|
||
it('should get state root', async () => { | ||
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, process.env.V4_API_KEY_TESTNET); | ||
const { data } = await tatum.rpc.beacon.v1.getStateRoot({ stateId: 'head' }); | ||
await tatum.destroy(); | ||
expect(data).toBeDefined(); | ||
}); | ||
|
||
it('should get block headers', async () => { | ||
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, process.env.V4_API_KEY_TESTNET); | ||
const { data } = await tatum.rpc.beacon.v1.getBlockHeaders({ slot: '1'}); | ||
await tatum.destroy(); | ||
expect(data).toBeDefined(); | ||
}); | ||
|
||
it('should get block root', async () => { | ||
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, process.env.V4_API_KEY_TESTNET); | ||
const { data } = await tatum.rpc.beacon.v1.getBlockRoot({ blockId: 'head' }); | ||
await tatum.destroy(); | ||
expect(data).toBeDefined(); | ||
}); | ||
|
||
it('should get state committees', async () => { | ||
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, process.env.V4_API_KEY_TESTNET); | ||
const { data } = await tatum.rpc.beacon.v1.getStateCommittees({ stateId: 'head' }); | ||
await tatum.destroy(); | ||
expect(data).toBeDefined(); | ||
}); | ||
|
||
it('should get state finality checkpoints', async () => { | ||
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, process.env.V4_API_KEY_TESTNET); | ||
const { data } = await tatum.rpc.beacon.v1.getStateFinalityCheckpoints({ stateId: 'head' }); | ||
await tatum.destroy(); | ||
expect(data).toBeDefined(); | ||
}); | ||
|
||
it('should get state fork', async () => { | ||
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, process.env.V4_API_KEY_TESTNET); | ||
const { data } = await tatum.rpc.beacon.v1.getStateFork({ stateId: 'head' }); | ||
await tatum.destroy(); | ||
expect(data).toBeDefined(); | ||
}); | ||
|
||
it('should get state sync committees', async () => { | ||
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, process.env.V4_API_KEY_TESTNET); | ||
const { data } = await tatum.rpc.beacon.v1.getStateSyncCommittees({ stateId: 'head' }); | ||
await tatum.destroy(); | ||
expect(data).toBeDefined(); | ||
}); | ||
}) | ||
}) | ||
}) |
4 changes: 2 additions & 2 deletions
4
src/e2e/rpc/evm/tatum.rpc.ethereum.spec.ts β ...2e/rpc/evm/eth/tatum.rpc.ethereum.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { Service } from 'typedi' | ||
import { | ||
BlockQuery, | ||
EvmBeaconV1Interface, | ||
EvmBeaconResponse, | ||
StateCommitteesQuery, | ||
StateQuery, | ||
StateSyncCommitteesQuery, ValidatorBalancesQuery, ValidatorQuery, ValidatorsQuery, | ||
} from '../../../dto' | ||
import { GetI } from '../../../dto/GetI' | ||
import { Constant, Utils } from '../../../util' | ||
|
||
@Service() | ||
export abstract class AbstractBeaconV1EvmRpc implements EvmBeaconV1Interface { | ||
protected abstract get<T>(get: GetI): Promise<T> | ||
|
||
getBlockAttestations({ blockId, ...rest }: BlockQuery): Promise<EvmBeaconResponse<any>> { | ||
const path = Utils.addQueryParams(`${Constant.BEACON_PREFIX}/blocks/${blockId}/attestations`, rest); | ||
return this.get({ path }); | ||
} | ||
|
||
getBlockHeader({ blockId, ...rest }: BlockQuery): Promise<EvmBeaconResponse<any>> { | ||
const path = Utils.addQueryParams(`${Constant.BEACON_PREFIX}/blocks/${blockId}/header`, rest); | ||
return this.get({ path }); | ||
} | ||
getBlockHeaders({ slot, parentRoot, ...rest }: { slot?: string; parentRoot?: string } = {}): Promise<EvmBeaconResponse<any>> { | ||
const queryParams = { | ||
...(slot ? { slot } : {}), | ||
...(parentRoot ? { parentRoot } : {}), | ||
...rest | ||
}; | ||
const path = Utils.addQueryParams(`${Constant.BEACON_PREFIX}/headers`, queryParams); | ||
return this.get({ path }); | ||
} | ||
|
||
getBlockRoot({ blockId, ...rest }: BlockQuery): Promise<EvmBeaconResponse<any>> { | ||
const path = Utils.addQueryParams(`${Constant.BEACON_PREFIX}/blocks/${blockId}/root`, rest); | ||
return this.get({ path }); | ||
} | ||
|
||
getGenesis(): Promise<EvmBeaconResponse<any>> { | ||
const path = Utils.addQueryParams(`${Constant.BEACON_PREFIX}/genesis`); | ||
return this.get({ path }); | ||
} | ||
|
||
getStateCommittees({ stateId, ...rest }: StateCommitteesQuery): Promise<EvmBeaconResponse<any>> { | ||
const path = Utils.addQueryParams(`${Constant.BEACON_PREFIX}/states/${stateId}/committees`, rest); | ||
return this.get({ path }); | ||
} | ||
|
||
getStateFinalityCheckpoints({ stateId, ...rest }: StateQuery): Promise<EvmBeaconResponse<any>> { | ||
const path = Utils.addQueryParams(`${Constant.BEACON_PREFIX}/states/${stateId}/finality_checkpoints`, rest); | ||
return this.get({ path }); | ||
} | ||
|
||
getStateFork({ stateId, ...rest }: StateQuery): Promise<EvmBeaconResponse<any>> { | ||
const path = Utils.addQueryParams(`${Constant.BEACON_PREFIX}/states/${stateId}/fork`, rest); | ||
return this.get({ path }); | ||
} | ||
|
||
getStateRoot({ stateId, ...rest }: StateQuery): Promise<EvmBeaconResponse<any>> { | ||
const path = Utils.addQueryParams(`${Constant.BEACON_PREFIX}/states/${stateId}/root`, rest); | ||
return this.get({ path }); | ||
} | ||
|
||
getStateSyncCommittees({ stateId, ...rest }: StateSyncCommitteesQuery): Promise<EvmBeaconResponse<any>> { | ||
const path = Utils.addQueryParams(`${Constant.BEACON_PREFIX}/states/${stateId}/sync_committees`, rest); | ||
return this.get({ path }); | ||
} | ||
|
||
getStateValidator({ stateId, validatorId, ...rest }: ValidatorQuery): Promise<EvmBeaconResponse<any>> { | ||
const path = Utils.addQueryParams(`${Constant.BEACON_PREFIX}/states/${stateId}/validators/${validatorId}`, rest); | ||
return this.get({ path }); | ||
} | ||
|
||
getStateValidatorBalances({ stateId, ...rest }: ValidatorBalancesQuery): Promise<EvmBeaconResponse<any>> { | ||
const path = Utils.addQueryParams(`${Constant.BEACON_PREFIX}/states/${stateId}/validator_balances`, rest); | ||
return this.get({ path }); | ||
} | ||
|
||
getStateValidators({ stateId, ...rest }: ValidatorsQuery): Promise<EvmBeaconResponse<any>> { | ||
const path = Utils.addQueryParams(`${Constant.BEACON_PREFIX}/states/${stateId}/validators`, rest); | ||
return this.get({ path }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { Container, Service } from 'typedi' | ||
import { LoadBalancer } from '../generic/LoadBalancer' | ||
import { AbstractBeaconV1EvmRpc } from './AbstractBeaconV1EvmRpc' | ||
import { GetI } from '../../../dto/GetI' | ||
|
||
@Service({ | ||
factory: (data: { id: string }) => { | ||
return new BeaconV1EvmRpc(data.id) | ||
}, | ||
transient: true, | ||
}) | ||
export class BeaconV1EvmRpc extends AbstractBeaconV1EvmRpc { | ||
protected readonly loadBalancer: LoadBalancer | ||
|
||
constructor(id: string) { | ||
super() | ||
this.loadBalancer = Container.of(id).get(LoadBalancer) | ||
} | ||
|
||
public destroy() { | ||
this.loadBalancer.destroy() | ||
} | ||
|
||
protected get<T>(get: GetI): Promise<T> { | ||
return this.loadBalancer.get(get) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { Container, Service } from 'typedi' | ||
import { EvmBasedBeaconRpcSuite } from '../../../dto' | ||
import { LoadBalancer } from '../generic/LoadBalancer' | ||
import { EvmArchiveLoadBalancerRpc } from './EvmArchiveLoadBalancerRpc' | ||
import { BeaconV1EvmRpc } from './BeaconV1EvmRpc' | ||
|
||
@Service({ | ||
factory: (data: { id: string }) => { | ||
return new EvmBeaconArchiveLoadBalancerRpc(data.id) | ||
}, | ||
transient: true, | ||
}) | ||
export class EvmBeaconArchiveLoadBalancerRpc extends EvmArchiveLoadBalancerRpc implements EvmBasedBeaconRpcSuite { | ||
protected readonly loadBalancerRpc: LoadBalancer | ||
public readonly beacon = { | ||
v1: Container.of(this.id).get(BeaconV1EvmRpc), | ||
}; | ||
|
||
constructor(private id: string) { | ||
super(id); | ||
this.loadBalancerRpc = Container.of(id).get(LoadBalancer); | ||
} | ||
} |
Oops, something went wrong.