Skip to content

Commit

Permalink
Move RPC oracles to a separate subfolder
Browse files Browse the repository at this point in the history
  • Loading branch information
LogvinovLeon committed May 28, 2024
1 parent 310bcdf commit a1ae452
Show file tree
Hide file tree
Showing 52 changed files with 113 additions and 110 deletions.
10 changes: 5 additions & 5 deletions ethereum/oracles/src/noir/oracles/oracles.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { type ForeignCallOutput } from '@noir-lang/noir_js';
import { MultiChainClient } from '../../ethereum/client.js';
import { getAccountOracle } from './accountOracle.js';
import { getHeaderOracle } from './headerOracle.js';
import { getProofOracle } from './proofOracle.js';
import { getReceiptOracle } from './receiptOracle.js';
import { getTransactionOracle } from './transactionOracle.js';
import { getAccountOracle } from './rpc/accountOracle.js';
import { getHeaderOracle } from './rpc/headerOracle.js';
import { getProofOracle } from './rpc/proofOracle.js';
import { getReceiptOracle } from './rpc/receiptOracle.js';
import { getTransactionOracle } from './rpc/transactionOracle.js';

export type NoirArgument = string[];
export type NoirArguments = NoirArgument[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
import { OFFSETS, getAccountOracle } from './accountOracle.js';
import { createMockMultiChainClient } from '../../ethereum/mockClient.js';
import { createMockMultiChainClient } from '../../../ethereum/mockClient.js';

describe('accountOracle', () => {
it('getAccountOracle', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { CRYPTO_PUNKS_ADDRESS } from '../../ethereum/recordingClient.test.js';
import { CRYPTO_PUNKS_ADDRESS } from '../../../ethereum/recordingClient.test.js';
import { decodeGetAccountArguments } from './accountOracle.js';
import { mainnet } from 'viem/chains';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { type ForeignCallOutput } from '@noir-lang/noir_js';
import { type Address } from 'viem';
import { assert } from '../../util/assert.js';
import { assert } from '../../../util/assert.js';
import { encodeAccount, encodeStateProof } from './accountOracle/encode.js';
import { decodeAddress, decodeField } from './common/decode.js';
import { NoirArguments } from './oracles.js';
import { MultiChainClient } from '../../ethereum/client.js';
import { Enum } from '../../util/enum.js';
import { decodeAddress, decodeField } from '../common/decode.js';
import { NoirArguments } from '../oracles.js';
import { MultiChainClient } from '../../../ethereum/client.js';
import { Enum } from '../../../util/enum.js';

export enum ARGS {
CHAIN_ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { loadProofFixture } from '../../../historyAPIFixtures.js';
import { loadProofFixture } from '../../../../historyAPIFixtures.js';
import accountAsFields from './fixtures/accountAsFields.json';
import stateProofAsFields from './fixtures/stateProofAsFields.json';
import storageProofAsFields from './fixtures/storageProofAsFields.json';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ForeignCallOutput } from '@noir-lang/noir_js';
import { GetProofReturnType, Hex, fromRlp, isHex } from 'viem';
import { encodeBytes32, encodeField, encodeHex, encodeProof } from '../common/encode.js';
import { padArray } from '../../../util/array.js';
import { ZERO_PAD_VALUE } from '../common/const.js';
import { assert } from '../../../util/assert.js';
import { encodeBytes32, encodeField, encodeHex, encodeProof } from '../../common/encode.js';
import { padArray } from '../../../../util/array.js';
import { ZERO_PAD_VALUE } from '../../common/const.js';
import { assert } from '../../../../util/assert.js';
import { accountProofConfig, LEGACY_MAX_ACCOUNT_STATE_LEN } from '../common/proofConfig/account.js';
import { storageProofConfig } from '../common/proofConfig/storage.js';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
import { getProofConfig } from './proofConfig.js';
import { MAX_TRIE_NODE_LEN } from './const.js';
import { MAX_TRIE_NODE_LEN } from '../../common/const.js';

describe('getProofConfig', () => {
it('state proof', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BYTE_HEX_LEN } from '../../../util/const.js';
import { MAX_TRIE_NODE_LEN } from './const.js';
import { BYTE_HEX_LEN } from '../../../../util/const.js';
import { MAX_TRIE_NODE_LEN } from '../../common/const.js';
import { getMaxRlpEncodedSize } from './util.js';

export interface ProofConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { U64_LEN, BYTES32_LEN } from '../const.js';
import { U64_LEN, BYTES32_LEN } from '../../../common/const.js';
import { getProofConfig } from '../proofConfig.js';
import { getMaxRlpEncodedSize } from '../util.js';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BYTE_HEX_LEN } from '../../../../util/const.js';
import { BYTE_HEX_LEN } from '../../../../../util/const.js';
import { getProofConfig } from '../proofConfig.js';

// TODO: Remove this when we remove legacy fixtures
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BYTES32_LEN } from '../const.js';
import { BYTES32_LEN } from '../../../common/const.js';
import { getProofConfig } from '../proofConfig.js';

const KEY_LEN = BYTES32_LEN;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BYTE_HEX_LEN } from '../../../../util/const.js';
import { BYTE_HEX_LEN } from '../../../../../util/const.js';
import { getProofConfig } from '../proofConfig.js';

// TODO: Remove this when we remove legacy fixtures
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
import { RLP_SHORT_ENTITY_MAX_LEN, getMaxRlpEncodedSize, getMaxRlpHeaderSize } from './util.js';
import { ADDRESS_LEN, BYTES32_LEN } from './const.js';
import { ADDRESS_LEN, BYTES32_LEN } from '../../common/const.js';

describe('getRlpHeaderSize', () => {
it('should return 1 for short entities', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BYTE_HEX_LEN } from '../../../util/const.js';
import { BYTE_HEX_LEN } from '../../../../util/const.js';

export const RLP_SHORT_ENTITY_MAX_LEN = 55;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { describe, expect, it } from 'vitest';
import { getBlockHeader, getHeaderOracle } from './headerOracle.js';
import { type ForeignCallOutput } from '@noir-lang/noir_js';
import { createMockClient } from '../../ethereum/mockClient.js';
import { HISTORY_API_FIXTURES } from '../../fixtures/historyAPIConfig.js';
import { MultiChainClient } from '../../ethereum/client.js';
import { createMockClient } from '../../../ethereum/mockClient.js';
import { HISTORY_API_FIXTURES } from '../../../fixtures/historyAPIConfig.js';
import { MultiChainClient } from '../../../ethereum/client.js';

describe('headerOracle', async () => {
const mockFilePaths = ['./fixtures/mainnet/paris/usdc_circle/eth_getBlockByHash_19000000.json'];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { type ForeignCallOutput } from '@noir-lang/noir_js';
import { type BlockHeader, blockToHeader } from '../../ethereum/blockHeader.js';
import { assert } from '../../util/assert.js';
import { type BlockHeader, blockToHeader } from '../../../ethereum/blockHeader.js';
import { assert } from '../../../util/assert.js';
import { encodeBlockHeader } from './headerOracle/encode.js';
import { decodeField } from './common/decode.js';
import { NoirArguments } from './oracles.js';
import { type Block } from '../../ethereum/blockHeader.js';
import { AlchemyClient, MultiChainClient } from '../../ethereum/client.js';
import { Enum } from '../../util/enum.js';
import { decodeField } from '../common/decode.js';
import { NoirArguments } from '../oracles.js';
import { type Block } from '../../../ethereum/blockHeader.js';
import { AlchemyClient, MultiChainClient } from '../../../ethereum/client.js';
import { Enum } from '../../../util/enum.js';

export enum ARGS {
CHAIN_ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ForeignCallOutput } from '@noir-lang/noir_js';
import { hexToBytes, keccak256 } from 'viem';
import { BlockHeader, headerToRlp } from '../../../ethereum/blockHeader.js';
import { padArray } from '../../../util/array.js';
import { encodeField, encodeHex } from '../common/encode.js';
import { BlockHeader, headerToRlp } from '../../../../ethereum/blockHeader.js';
import { padArray } from '../../../../util/array.js';
import { encodeField, encodeHex } from '../../common/encode.js';

export const MAX_HEADER_RLP_LEN = 708;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { createMockMultiChainClient } from '../../ethereum/mockClient.js';
import { createMockMultiChainClient } from '../../../ethereum/mockClient.js';
import { getProofOracle } from './proofOracle.js';

describe(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest';
import { CRYPTO_PUNKS_ADDRESS } from '../../ethereum/recordingClient.test.js';
import { CRYPTO_PUNKS_ADDRESS } from '../../../ethereum/recordingClient.test.js';
import { decodeGetProofArguments } from './proofOracle.js';
import { CIRCLE_USDC_BALANCE_STORAGE_KEY } from '../../fixtures/historyAPIConfig.js';
import { CIRCLE_USDC_BALANCE_STORAGE_KEY } from '../../../fixtures/historyAPIConfig.js';
import { mainnet } from 'viem/chains';

describe('proofOracle', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { type ForeignCallOutput } from '@noir-lang/noir_js';
import { assert } from '../../util/assert.js';
import { assert } from '../../../util/assert.js';
import { encodeAccount, encodeStateProof, encodeStorageProof } from './accountOracle/encode.js';
import { decodeAddress, decodeBytes32, decodeField } from './common/decode.js';
import { NoirArguments } from './oracles.js';
import { decodeAddress, decodeBytes32, decodeField } from '../common/decode.js';
import { NoirArguments } from '../oracles.js';
import { Hex } from 'viem';
import { MultiChainClient } from '../../ethereum/client.js';
import { Enum } from '../../util/enum.js';
import { MultiChainClient } from '../../../ethereum/client.js';
import { Enum } from '../../../util/enum.js';

export enum ARGS {
CHAIN_ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, it } from 'vitest';
import { createMockMultiChainClient } from '../../ethereum/mockClient.js';
import { createMockMultiChainClient } from '../../../ethereum/mockClient.js';
import { OFFSETS, getReceiptOracle } from './receiptOracle.js';
import { BYTES32_LEN, ZERO_PAD_VALUE } from './common/const.js';
import { padArray } from '../../util/array.js';
import { BYTES32_LEN, ZERO_PAD_VALUE } from '../common/const.js';
import { padArray } from '../../../util/array.js';
import { receiptProofConfigM } from './common/proofConfig/receipt.js';

describe('getReceiptOracle', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { type ForeignCallOutput } from '@noir-lang/noir_js';
import { assert } from '../../util/assert.js';
import { decodeField } from './common/decode.js';
import { NoirArguments } from './oracles.js';
import { MultiChainClient } from '../../ethereum/client.js';
import { getReceiptProof } from '../../ethereum/receiptProof.js';
import { assert } from '../../../util/assert.js';
import { decodeField } from '../common/decode.js';
import { NoirArguments } from '../oracles.js';
import { MultiChainClient } from '../../../ethereum/client.js';
import { getReceiptProof } from '../../../ethereum/receiptProof.js';
import { encodeReceipt, encodeReceiptProof } from './receiptOracle/encode.js';
import { txTypeToHex } from '../../ethereum/receipt.js';
import { Enum } from '../../util/enum.js';
import { txTypeToHex } from '../../../ethereum/receipt.js';
import { Enum } from '../../../util/enum.js';

export enum ARGS {
CHAIN_ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, it } from 'vitest';
import { assert } from '../../../util/assert.js';
import { assert } from '../../../../util/assert.js';
import { RECEIPT_OFFSETS } from './encode.js';
import { encodeReceipt } from '../receiptOracle/encode.js';
import { loadReceiptFixture } from '../../../historyAPIFixtures.js';
import { encodeReceipt } from './encode.js';
import { loadReceiptFixture } from '../../../../historyAPIFixtures.js';

describe('ReceiptOracle encode', () => {
describe('encodeReceipt', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { type ForeignCallOutput } from '@noir-lang/noir_js';
import { statusToHex } from '../../../ethereum/receipt.js';
import { padArray } from '../../../util/array.js';
import { encodeField, encodeHex, encodeProof, encodeBytes } from '../common/encode.js';
import { MAX_TRIE_NODE_LEN, ZERO_PAD_VALUE } from '../common/const.js';
import { Proof } from '../../../ethereum/proof.js';
import { TransactionReceipt } from '../../../types.js';
import { BYTES_32_ZERO, U1_ZERO } from '../../../util/const.js';
import { statusToHex } from '../../../../ethereum/receipt.js';
import { padArray } from '../../../../util/array.js';
import { encodeField, encodeHex, encodeProof, encodeBytes } from '../../common/encode.js';
import { MAX_TRIE_NODE_LEN, ZERO_PAD_VALUE } from '../../common/const.js';
import { Proof } from '../../../../ethereum/proof.js';
import { TransactionReceipt } from '../../../../types.js';
import { BYTES_32_ZERO, U1_ZERO } from '../../../../util/const.js';
import { receiptProofConfigM } from '../common/proofConfig/receipt.js';

export enum RECEIPT_OFFSETS {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { describe, expect, it } from 'vitest';
import { createMockMultiChainClient } from '../../ethereum/mockClient.js';
import { createMockMultiChainClient } from '../../../ethereum/mockClient.js';
import { OFFSETS, getTransactionOracle } from './transactionOracle.js';
import { MAX_DATA_LEN_M } from './common/txConfig.js';
import { ZERO_PAD_VALUE } from './common/const.js';
import { padArray } from '../../util/array.js';
import { padArray } from '../../../util/array.js';
import { ZERO_PAD_VALUE } from '../common/const.js';
import { txProofConfigM } from './common/proofConfig/tx.js';

describe('getTransactionOracle', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { type ForeignCallOutput } from '@noir-lang/noir_js';
import { NoirArguments } from './oracles.js';
import { MultiChainClient } from '../../ethereum/client.js';
import { txTypeToHex } from '../../ethereum/receipt.js';
import { getTxProof } from '../../ethereum/txProof.js';
import { NoirArguments } from '../oracles.js';
import { MultiChainClient } from '../../../ethereum/client.js';
import { txTypeToHex } from '../../../ethereum/receipt.js';
import { getTxProof } from '../../../ethereum/txProof.js';
import { encodeTx, encodeTxProof } from './transactionOracle/encode.js';
import { decodeGetReceiptArguments } from './receiptOracle.js';
import { assert } from '../../util/assert.js';
import { assert } from '../../../util/assert.js';

export enum OFFSETS {
TX_TYPE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { describe, expect, it } from 'vitest';
import { TX_OFFSETS, encodeTx } from './encode.js';
import { loadTxFixture } from '../../../historyAPIFixtures.js';
import { ETH_TRANSFER_TX_HASH, CHAIN_LINK_TRANSFER_TX_HASH } from '../../../fixtures/historyAPIConfig.js';
import { loadTxFixture } from '../../../../historyAPIFixtures.js';
import { ETH_TRANSFER_TX_HASH, CHAIN_LINK_TRANSFER_TX_HASH } from '../../../../fixtures/historyAPIConfig.js';
import { MAX_DATA_LEN_M } from '../common/txConfig.js';
import { ZERO_PAD_VALUE } from '../common/const.js';
import { padArray } from '../../../util/array.js';
import { ZERO_PAD_VALUE } from '../../common/const.js';
import { padArray } from '../../../../util/array.js';

// TODO: Add a test for contract creation transaction when we support transactions longer than trie nodes.
describe('TransactionOracle encode', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Transaction } from 'viem';
import { MAX_TRIE_NODE_LEN, ZERO_PAD_VALUE } from '../common/const.js';
import { MAX_DATA_LEN_M } from '../common/txConfig.js';
import { ForeignCallOutput } from '@noir-lang/noir_js';
import { encodeAddress, encodeBytes, encodeField, encodeHex, encodeProof, encodeU128 } from '../common/encode.js';
import { BYTE_HEX_LEN, U1_ZERO } from '../../../util/const.js';
import { Proof } from '../../../ethereum/proof.js';
import { padArray } from '../../../util/array.js';
import { removeHexPrefix } from '../../../util/hex.js';
import { padArray } from '../../../../util/array.js';
import { U1_ZERO, BYTE_HEX_LEN } from '../../../../util/const.js';
import { removeHexPrefix } from '../../../../util/hex.js';
import { ZERO_PAD_VALUE, MAX_TRIE_NODE_LEN } from '../../common/const.js';
import { encodeField, encodeAddress, encodeU128, encodeHex, encodeBytes, encodeProof } from '../../common/encode.js';
import { txProofConfigM } from '../common/proofConfig/tx.js';
import { MAX_DATA_LEN_M } from '../common/txConfig.js';
import { Proof } from '../../../../ethereum/proof.js';

export enum TX_OFFSETS {
NONCE,
Expand Down
10 changes: 5 additions & 5 deletions ethereum/oracles/src/noir/oracles/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import Fastify from 'fastify';
import http from 'http';
import { JSONRPCServerMethods, ServerParams, getOracleHandler } from './handlers.js';
import { MultiChainClient } from '../../../ethereum/client.js';
import { getHeaderOracle } from '../headerOracle.js';
import { getAccountOracle } from '../accountOracle.js';
import { getProofOracle } from '../proofOracle.js';
import { getReceiptOracle } from '../receiptOracle.js';
import { getTransactionOracle } from '../transactionOracle.js';
import { getHeaderOracle } from '../rpc/headerOracle.js';
import { getAccountOracle } from '../rpc/accountOracle.js';
import { getProofOracle } from '../rpc/proofOracle.js';
import { getReceiptOracle } from '../rpc/receiptOracle.js';
import { getTransactionOracle } from '../rpc/transactionOracle.js';

const HTTP_STATUS_NO_CONTENT = 204;

Expand Down
2 changes: 1 addition & 1 deletion ethereum/oracles/src/script/noir_fixtures/account.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GetProofReturnType } from 'viem';
import { encodeHexString, joinArray } from '../../noir/noir_js/encode.js';
import { encodeValue } from '../../noir/oracles/accountOracle/encode.js';
import { encodeValue } from '../../noir/oracles/rpc/accountOracle/encode.js';

export function createAccountFixture(stateProof: GetProofReturnType): string {
const address = encodeHexString(stateProof.address);
Expand Down
2 changes: 1 addition & 1 deletion ethereum/oracles/src/script/noir_fixtures/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GetBlockReturnType } from 'viem';
import { encodeHexString, joinArray } from '../../noir/noir_js/encode.js';
import { blockToHeader, headerToRlp } from '../../ethereum/blockHeader.js';
import { padArray } from '../../util/array.js';
import { MAX_HEADER_RLP_LEN } from '../../noir/oracles/headerOracle/encode.js';
import { MAX_HEADER_RLP_LEN } from '../../noir/oracles/rpc/headerOracle/encode.js';
import { ZERO_PAD_VALUE } from '../../noir/oracles/common/const.js';

export function createHeaderFixture(block: GetBlockReturnType): string {
Expand Down
2 changes: 1 addition & 1 deletion ethereum/oracles/src/script/noir_fixtures/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BYTES_32_ZERO } from '../../util/const.js';
import { logToRlpFields } from '../../ethereum/receipt.js';
import { encodeHex } from '../../noir/oracles/common/encode.js';
import { ZERO_PAD_VALUE } from '../../noir/oracles/common/const.js';
import { LEGACY_MAX_RECEIPT_RLP_LEN } from '../../noir/oracles/common/proofConfig/receipt.js';
import { LEGACY_MAX_RECEIPT_RLP_LEN } from '../../noir/oracles/rpc/common/proofConfig/receipt.js';

const MAX_TOPICS = 4;

Expand Down
2 changes: 1 addition & 1 deletion ethereum/oracles/src/script/noir_fixtures/new_proof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { padArray } from '../../util/array.js';
import { MAX_TRIE_NODE_LEN, ZERO_PAD_VALUE } from '../../noir/oracles/common/const.js';
import { Proof } from '../../ethereum/proof.js';
import { Hex, padHex } from 'viem';
import { ProofConfig } from '../../noir/oracles/common/proofConfig.js';
import { ProofConfig } from '../../noir/oracles/rpc/common/proofConfig.js';

export function createNewTopLevelProofFixtureWithRoot(proof: Proof, root: Hex[], config: ProofConfig): string {
return `use crate::merkle_patricia_proofs::proof::{Proof, ProofInput};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Proof } from '../../ethereum/proof.js';
import { receiptProofConfigM } from '../../noir/oracles/common/proofConfig/receipt.js';
import { receiptProofConfigM } from '../../noir/oracles/rpc/common/proofConfig/receipt.js';
import { createNewTopLevelProofFixture } from './new_proof.js';

export function createNewReceiptProofFixture(proof: Proof): string {
Expand Down
Loading

0 comments on commit a1ae452

Please sign in to comment.