Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ts-mocha test framework #46

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,27 @@
},
"devDependencies": {
"@types/eventsource": "^1.1.11",
"@types/expect": "^24.3.0",
"@types/mocha": "^10.0.2",
"@types/node": "^18.14.4",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"dotenv": "^16.0.3",
"eslint": "^8.36.0",
"eslint-plugin-tsdoc": "^0.2.17",
"ethers": "^6.5.1",
"mocha": "^10.2.0",
"release-it": "^15.8.0",
"ts-mocha": "^10.0.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
"typescript": "^5.2.2"
},
"peerDependencies": {
"ethers": "^6.5.1"
},
"scripts": {
"build": "tsc",
"test": "echo \"no test specified\" && exit 0",
"test": "ts-mocha -p ./tsconfig.json src/tests/*.spec.ts",
"lint": "eslint src/*.ts src/**/*.ts",
"example.backrun": "ts-node src/examples/sendBackrunBundle.ts",
"example.composableBundle": "ts-node src/examples/sendComposableBundle.ts",
Expand Down
53 changes: 53 additions & 0 deletions src/tests/rpc.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { describe } from "mocha"
import assert from "assert"
import MevShareClient, { BundleParams, HintPreferences } from '..'
import { JsonRpcProvider, Wallet } from 'ethers'
import { mungeBundleParams } from '../api/mungers'

const checkEnv = (names: string[]) => {
for (const name of names) {
if (!process.env[name]) {
throw new Error(`Missing environment variable ${name}`)
}
}
}

describe("interfaces", () => {
checkEnv(["RPC_URL"])
const authSigner = new Wallet("0x0123456789012345678901234567890123456789012345678901234567890123")
const mevshare = MevShareClient.useEthereumMainnet(authSigner)
const eth = new JsonRpcProvider(process.env.RPC_URL)

it("should encode hints in snake_case", async () => {
const hints: HintPreferences = {
calldata: true,
contractAddress: true,
defaultLogs: true,
functionSelector: true,
logs: true,
txHash: true,
}
const bundleParams: BundleParams = {
body: [],
inclusion: {
block: 13333337,
},
privacy: {
hints,
}
}
const encodedParams = mungeBundleParams(bundleParams)
const expectedHints = [
'contract_address',
'function_selector',
'calldata',
'logs',
'default_logs',
'tx_hash',
'hash'
]
for (const hint of expectedHints) {
assert(encodedParams.privacy?.hints?.includes(hint))
}
})
})
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
},
"exclude": [
"node_modules",
"build/**/*"
"build/**/*",
"src/tests/**/*",
]
}
Loading
Loading