-
Notifications
You must be signed in to change notification settings - Fork 319
migrate contract e2e #2716
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
base: devnet-ready
Are you sure you want to change the base?
migrate contract e2e #2716
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,3 +13,16 @@ onlyBuiltDependencies: | |||||||||||||||||||||||||||||||||||||
| - protobufjs | ||||||||||||||||||||||||||||||||||||||
| - sqlite3 | ||||||||||||||||||||||||||||||||||||||
| - ssh2 | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # Allow exotic subdependencies (needed for toml dependency) | ||||||||||||||||||||||||||||||||||||||
| allowExoticSubdeps: true | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| allowBuilds: | ||||||||||||||||||||||||||||||||||||||
| '@biomejs/biome': set this to true or false | ||||||||||||||||||||||||||||||||||||||
| '@parcel/watcher': set this to true or false | ||||||||||||||||||||||||||||||||||||||
| cpu-features: set this to true or false | ||||||||||||||||||||||||||||||||||||||
| esbuild: set this to true or false | ||||||||||||||||||||||||||||||||||||||
| msgpackr-extract: set this to true or false | ||||||||||||||||||||||||||||||||||||||
| protobufjs: set this to true or false | ||||||||||||||||||||||||||||||||||||||
| sqlite3: set this to true or false | ||||||||||||||||||||||||||||||||||||||
| ssh2: set this to true or false | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+20
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [LOW] Resolve The new
Suggested change
Comment on lines
+20
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [LOW] Resolve This |
||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { beforeAll, describeSuite, expect } from "@moonwall/cli"; | ||
| import { subtensor } from "@polkadot-api/descriptors"; | ||
| import { ethers } from "ethers"; | ||
| import type { TypedApi } from "polkadot-api"; | ||
| import { convertH160ToSS58, forceSetBalance, raoToEth, tao, waitForFinalizedBlocks } from "../../utils"; | ||
|
|
||
| function createEthersWallet(provider: ethers.JsonRpcProvider): ethers.Wallet { | ||
| const account = ethers.Wallet.createRandom(); | ||
| return new ethers.Wallet(account.privateKey, provider); | ||
| } | ||
|
|
||
| async function estimateTransactionCost( | ||
| provider: ethers.Provider, | ||
| tx: ethers.TransactionRequest, | ||
| ): Promise<bigint> { | ||
| const feeData = await provider.getFeeData(); | ||
| const estimatedGas = await provider.estimateGas(tx); | ||
| const gasPrice = feeData.gasPrice ?? feeData.maxFeePerGas; | ||
| if (gasPrice == null) { | ||
| return estimatedGas; | ||
| } | ||
| return estimatedGas * gasPrice; | ||
| } | ||
|
|
||
| describeSuite({ | ||
| id: "evm-substrate-transfer-basic", | ||
| title: "Basic EVM-Substrate Transfer Tests", | ||
| foundationMethods: "zombie", | ||
| testCases: ({ it, context }) => { | ||
| let api: TypedApi<typeof subtensor>; | ||
| let ethWallet: ethers.Wallet; | ||
| let ethWallet2: ethers.Wallet; | ||
|
|
||
| beforeAll(async () => { | ||
| api = context.papi("Node").getTypedApi(subtensor); | ||
|
|
||
| const provider = context.ethers("EVM").provider as ethers.JsonRpcProvider; | ||
| ethWallet = createEthersWallet(provider); | ||
| ethWallet2 = createEthersWallet(provider); | ||
|
|
||
| await forceSetBalance(api, convertH160ToSS58(ethWallet.address)); | ||
| await forceSetBalance(api, convertH160ToSS58(ethWallet2.address)); | ||
| await waitForFinalizedBlocks(api, 1); | ||
| }, 120000); | ||
|
|
||
| it({ | ||
| id: "T01", | ||
| title: "Can transfer token from EVM to EVM", | ||
| test: async () => { | ||
| const provider = ethWallet.provider; | ||
| if (provider == null) { | ||
| throw new Error("ethWallet has no provider"); | ||
| } | ||
|
|
||
| const senderBalanceBefore = await provider.getBalance(ethWallet.address); | ||
| const receiverBalanceBefore = await provider.getBalance(ethWallet2.address); | ||
|
|
||
| const transferAmount = raoToEth(tao(1)); | ||
| const tx: ethers.TransactionRequest = { | ||
| to: ethWallet2.address, | ||
| value: transferAmount, | ||
| }; | ||
|
|
||
| const txFee = await estimateTransactionCost(provider, tx); | ||
|
|
||
| const txResponse = await ethWallet.sendTransaction(tx); | ||
| const receipt = await txResponse.wait(); | ||
| expect(receipt).toBeDefined(); | ||
| expect(receipt!.status).toEqual(1); | ||
|
|
||
| const senderBalanceAfter = await provider.getBalance(ethWallet.address); | ||
| const receiverBalanceAfter = await provider.getBalance(ethWallet2.address); | ||
|
|
||
| expect(senderBalanceAfter).toEqual(senderBalanceBefore - transferAmount - txFee); | ||
| expect(receiverBalanceAfter).toEqual(receiverBalanceBefore + transferAmount); | ||
| }, | ||
| }); | ||
| }, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { hexToU8a } from "@polkadot/util"; | ||
| import { blake2AsU8a, encodeAddress } from "@polkadot/util-crypto"; | ||
|
|
||
| const SS58_PREFIX = 42; | ||
|
|
||
| export function convertH160ToPublicKey(ethAddress: string) { | ||
| const prefix = "evm:"; | ||
| const prefixBytes = new TextEncoder().encode(prefix); | ||
| const addressBytes = hexToU8a( | ||
| ethAddress.startsWith("0x") ? ethAddress : `0x${ethAddress}`, | ||
| ); | ||
| const combined = new Uint8Array(prefixBytes.length + addressBytes.length); | ||
|
|
||
| // Concatenate prefix and Ethereum address | ||
| combined.set(prefixBytes); | ||
| combined.set(addressBytes, prefixBytes.length); | ||
|
|
||
| // Hash the combined data (the public key) | ||
| const hash = blake2AsU8a(combined); | ||
| return hash; | ||
| } | ||
|
|
||
| export function convertH160ToSS58(ethAddress: string) { | ||
| // get the public key | ||
| const hash = convertH160ToPublicKey(ethAddress); | ||
|
|
||
| // Convert the hash to SS58 format | ||
| const ss58Address = encodeAddress(hash, SS58_PREFIX); | ||
| return ss58Address; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| export * from "./transactions.js"; | ||
| export * from "./balance.js"; | ||
| export * from "./subnet.js"; | ||
| export * from "./staking.js"; | ||
| export * from "./shield_helpers.ts"; | ||
| export * from "./account.ts"; | ||
| export * from "./address.ts"; | ||
| export * from "./balance.js"; | ||
| export * from "./coldkey_swap.ts"; | ||
| export * from "./config.js"; | ||
| export * from "./shield_helpers.ts"; | ||
| export * from "./staking.js"; | ||
| export * from "./subnet.js"; | ||
| export * from "./transactions.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[MEDIUM] Wire the new EVM suite into CI
This registers a new
zombienet_evmMoonwall suite, but.github/workflows/typescript-e2e.ymlstill only runsdev,zombienet_shield,zombienet_staking,zombienet_coldkey_swap, andzombienet_subnets. As written, the migrated EVM test can go stale because PR CI never invokespnpm moonwall test zombienet_evm.Add
zombienet_evmto therun-e2e-testsmatrix, likely against the release binary unless there is a specific fast-runtime reason.