Skip to content
Open
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
16 changes: 0 additions & 16 deletions .eslintrc

This file was deleted.

4 changes: 1 addition & 3 deletions e2e/calldata.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Interface } from "ethers";


export function encodeCalldata(funcSignature: string, args: any) {
export function encodeCalldata(funcSignature: string, args: string[] | []) {
const iface = new Interface([`function ${funcSignature}`]);
const functionName = funcSignature.split('(')[0]; // "balanceOf" gibi
const callData = iface.encodeFunctionData(functionName, args);
Expand Down
2 changes: 0 additions & 2 deletions e2e/jest.globalSetup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable no-console */
import { getDevAccount, getEthStrkHolderAccount, sendERC20FromSnAccount, sendStrksFromSnAccount, startNode, testConfig, updateNodeConfig } from './utils'
import { declareContract, deployContract } from './transaction'
import { ETH_ADDRESS, SN_ADDRESS_TEST_1, STRK_ADDRESS } from './constants'
Expand Down
2 changes: 0 additions & 2 deletions e2e/jest.globalTeardown.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable no-console */
export default async function globalTeardown() {
console.log('\n🛠️ Global teardown: Tests are done. Exiting...')
}
28 changes: 11 additions & 17 deletions e2e/registers.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
/* eslint-disable no-console */
import { Abi, Account, Contract } from "starknet";
import { Abi, Account, Contract } from "starknet";
import { ETH_ADDRESS, SN_ADDRESS_TEST_1, STRK_ADDRESS } from "./constants";
import { getContractAbi, getProvider } from "./utils";
import { addHexPrefix } from "../src/utils/padding";
import { getEthAddressFromRegistry } from "./registry/rosettanet";


interface RosettanetCompatibleAddress {
starknet: string;
ethereum: string;
}
import { RosettanetCompatibleAddress } from "../src/types/types";

export async function updateRegistry(account: Account, rosettanetAddress: string) {
try {
Expand All @@ -18,7 +12,7 @@ export async function updateRegistry(account: Account, rosettanetAddress: string
await registerContract(account, ETH_ADDRESS, rosettanetAddress);
await getEthAddressFromRegistry(STRK_ADDRESS);
await registerContract(account, SN_ADDRESS_TEST_1, rosettanetAddress);

console.log('Registry updated.')
return;
} catch (ex) {
Expand All @@ -29,14 +23,14 @@ export async function updateRegistry(account: Account, rosettanetAddress: string

async function registerContract(account: Account, contractAddress: string, rosettanetAddress: string): Promise<string> {
const abi: Abi = await getContractAbi('Rosettanet')

const contract = new Contract(abi, rosettanetAddress, getProvider())

contract.connect(account)

await contract.register_contract(contractAddress)
const generatedAddress = await getEthAddressFromRegistry(contractAddress)

return addHexPrefix(generatedAddress.toLowerCase())
}

Expand All @@ -53,21 +47,21 @@ export async function registerFunction(account: Account, rosettanetAddress: stri
const abi: Abi = await getContractAbi('Rosettanet')

//const EvmTypes = EVMTypesEnum;

const contract = new Contract(abi, rosettanetAddress, getProvider())
contract.connect(account)

const params = getParameters(fn_name);

await contract.invoke('register_function',params, { parseRequest: false});
await contract.invoke('register_function', params, { parseRequest: false });

console.log(`Function ${fn_name} registered to registry.`)
}

function getParameters(fn_name:string): string[] {
function getParameters(fn_name: string): string[] {
switch (fn_name) {
case 'transfer':
return ['0x0', '0x7472616E7366657228616464726573732C75696E7432353629', '0x19',
return ['0x0', '0x7472616E7366657228616464726573732C75696E7432353629', '0x19',
'0x2', '0x3', '0x24']
default:
throw 'fn_name not found'
Expand Down
1 change: 0 additions & 1 deletion e2e/registry/rosettanet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export async function registerFunction(/* account: Account, fn: string */) {
// Implementation pending
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export async function registerContractIfNotRegistered(
account: Account,
contractAddress: string,
Expand Down
2 changes: 1 addition & 1 deletion e2e/rpc/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Server robustness tests', () => {
},
{ timeout: 2000 },
)
} catch (error) {
} catch {
// Skip all tests in this suite
fail('server is not working')
}
Expand Down
61 changes: 3 additions & 58 deletions e2e/signing.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,10 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Wallet, Transaction, AbiCoder } from 'ethers';
import { Wallet } from 'ethers';

const PRIVATE_KEY = '0x72dd28749115344b785e66ec88f439471e10895693b6d659aaa8264f30272212'
const ETH_ADDRESS ='0x188669dbc25577B33d3eEFe1030bB7134bbaeC2A';
// const ETH_ADDRESS = '0x188669dbc25577B33d3eEFe1030bB7134bbaeC2A';

export function getTestAccount(): Wallet {
const signer = new Wallet(PRIVATE_KEY);

return signer;
}

export function getTestAccountAddress(): string {
return ETH_ADDRESS;
}

export interface Eip1559Transaction {
to: string,
gasLimit: number,
nonce: number,
value: bigint,
chainId: number,
maxPriorityFeePerGas: number,
maxFeePerGas: number
}

export interface SignedTransaction {
txHash: string,
signature: any,
unsignedHash: string,
signedSerialized: string
}

export async function eip1559Sign(tx: Eip1559Transaction, selector:string, abi: string[], params: any[]): Promise<SignedTransaction> {
const testAccount = getTestAccount()

const abicoder = new AbiCoder();

const calldata = abicoder.encode(abi, params);
const { to, gasLimit, nonce, value, chainId, maxPriorityFeePerGas, maxFeePerGas } = tx;
const transaction = {
to,
gasLimit,
nonce,
value,
chainId,
accessList: [],
maxPriorityFeePerGas,
maxFeePerGas,
data: `${selector}${calldata.replace('0x','')}`
}

const signedTx = Transaction.from(await testAccount.signTransaction(transaction));

if(signedTx.hash == null) {
throw 'Error at signing tx'
}

return {
txHash: signedTx.hash,
signature: signedTx.signature,
unsignedHash: signedTx.unsignedHash,
signedSerialized: signedTx.serialized
}
return signer;
}
8 changes: 4 additions & 4 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable no-console */
import { initNode } from '../src/index'
/* eslint-disable no-console */
import { promises as fs } from 'fs'
import path from 'path'
import { Abi, Account, BigNumberish, RpcProvider, uint256 } from 'starknet'
Expand Down Expand Up @@ -32,6 +30,8 @@ export const testConfig = {
},
}

export type NodeConfig = typeof testConfig

// These values are used in the devnet setup script
// export const rpcList = ["https://free-rpc.nethermind.io/mainnet-juno/v0_7"]
// export const accountSeed = "1223632"
Expand Down Expand Up @@ -89,8 +89,8 @@ export async function updateNodeConfig(config: string) {
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export async function readNodeConfig(): Promise<any> {

export async function readNodeConfig(): Promise<NodeConfig> {
try {
const configFilePath = path.resolve(__dirname, '../config.test.json')

Expand Down
48 changes: 48 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { defineConfig } from "eslint/config";
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default defineConfig([{
extends: compat.extends(
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
),

plugins: {
"@typescript-eslint": typescriptEslint,
},

languageOptions: {
parser: tsParser,
},

rules: {
"no-console": 2,
},
}, {
files: ["e2e/**/*.ts"],

rules: {
"no-console": "off",
},
}, {
files: ["jest.config.js"],
rules: {
"no-undef": "off"
}
}
]);
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
"@types/mocha": "^10.0.10",
"@types/node": "^20.17.24",
"@types/supertest": "^6.0.2",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"@typescript-eslint/eslint-plugin": "^8.46.2",
"@typescript-eslint/parser": "^8.46.2",
"chai": "^5.2.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint": "^9.38.0",
"eslint-config-prettier": "^10.1.8",
"jest": "^29.7.0",
"mocha": "^11.1.0",
"nodemon": "^3.0.3",
Expand All @@ -52,6 +52,7 @@
"typescript": "^5.8.3"
},
"dependencies": {
"@starknet-io/types-js": "0.8.4",
"@types/cors": "^2.8.17",
"axios": "^1.6.7",
"bignumber.js": "^9.1.2",
Expand Down
1 change: 0 additions & 1 deletion src/cache/blockNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export async function initialSyncBlockNumber() {
}

export async function syncBlockNumber() {
// eslint-disable-next-line no-constant-condition
while (true) {
await new Promise<void>(resolve => setTimeout(resolve, 10000)) // Sync new blocks in every 10 seconds
await updateBlockNumber()
Expand Down
26 changes: 3 additions & 23 deletions src/cache/gasPrice.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { writeLog } from '../logger'
import { isStarknetRPCError } from '../types/typeGuards'
import { RPCResponse, StarknetRPCError } from '../types/types'
import { callStarknet } from '../utils/callHelper'

export interface SyncedGas {
l1: {
fri: string
wei: string
},
l1_data: {
fri: string
wei: string
},
l2: {
fri: string
wei: string
}
}

interface GasData {
price_in_fri: string
price_in_wei: string
}

import { GasData, SyncedGas } from '../types/types'

let syncedGasPrice: SyncedGas

Expand Down Expand Up @@ -88,7 +70,6 @@ async function updateGasPrice() {
syncedGasPrice = gas;
writeLog(0, `Gas sync, l1: ${gas.l1.wei} (wei) ${gas.l1.fri} (fri), l1_data: ${gas.l1_data.wei} (wei) ${gas.l1_data.fri} (fri), l2: ${gas.l2.wei} (wei) ${gas.l2.fri} (fri)`)
return
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
writeLog(2, 'Error at gas sync: ' + e.message)
}
Expand All @@ -100,7 +81,6 @@ export async function initialSyncGasPrice() {
}

export async function syncGasPrice() {
// eslint-disable-next-line no-constant-condition
while (true) {
await new Promise<void>(resolve => setTimeout(resolve, 10000)) // Sync new blocks in every 10 seconds
await updateGasPrice()
Expand Down
2 changes: 1 addition & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function appendLog(
severity: getSeverityString(severity),
message: JSON.parse(text),
})
} catch (error) {
} catch {
logMessage = JSON.stringify({
date: now.toLocaleDateString(),
time: now.toTimeString().split(' ')[0],
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/calls.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Router, Response, Request } from 'express'
import { ResponseHandler, RPCError, RPCResponse } from '../types/types'
import { chainIdHandler } from './calls/chainId'
Expand Down Expand Up @@ -235,7 +236,6 @@ Methods.set('eth_createAccessList', {
handler: createAccessListHandler,
})

// eslint-disable-next-line @typescript-eslint/no-explicit-any
async function handleRequest(request: any): Promise<RPCResponse | RPCError> {
try {
if (request && typeof request === 'object') {
Expand Down Expand Up @@ -272,7 +272,7 @@ async function handleRequest(request: any): Promise<RPCResponse | RPCError> {
return result
} catch (ex) {
const errorMessage = ex instanceof Error ? ex.message : String(ex);
writeLog(2, JSON.stringify({request, error: errorMessage}))
writeLog(2, JSON.stringify({ request, error: errorMessage }))
return <RPCError>{
jsonrpc: '2.0',
id: id,
Expand Down
Loading