-
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 7 commits
204908c
8959e8f
faaf273
5ed2219
62e1210
2987050
5ffa344
b1718a8
86ffee7
cdf5a5e
d4903cd
519d0e4
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 |
|---|---|---|
|
|
@@ -47,10 +47,7 @@ impl<T: Config> OrderSwapInterface<T::AccountId> for Pallet<T> { | |
| ); | ||
| } | ||
| let alpha_out = | ||
| Self::stake_into_subnet(hotkey, coldkey, netuid, tao_amount, amm_limit, false, false)?; | ||
| if validate { | ||
| Self::set_stake_operation_limit(hotkey, coldkey, netuid); | ||
| } | ||
| Self::stake_into_subnet(hotkey, coldkey, netuid, tao_amount, amm_limit, false)?; | ||
| Ok(alpha_out) | ||
| } | ||
|
|
||
|
|
@@ -136,7 +133,6 @@ impl<T: Config> OrderSwapInterface<T::AccountId> for Pallet<T> { | |
| TaoBalance::from(tao_equiv) >= DefaultMinStake::<T>::get(), | ||
| Error::<T>::AmountTooLow | ||
| ); | ||
| Self::ensure_stake_operation_limit_not_exceeded(from_hotkey, from_coldkey, netuid)?; | ||
| Self::ensure_available_to_unstake(from_coldkey, netuid, amount)?; | ||
|
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. [HIGH] Restore sender staking rate-limit validation
|
||
| } | ||
|
|
||
|
|
@@ -145,7 +141,6 @@ impl<T: Config> OrderSwapInterface<T::AccountId> for Pallet<T> { | |
| Self::hotkey_account_exists(to_hotkey), | ||
| Error::<T>::HotKeyAccountNotExists | ||
| ); | ||
| Self::set_stake_operation_limit(to_hotkey, to_coldkey, netuid); | ||
| } | ||
|
|
||
| let available = | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,6 +120,38 @@ | |
| "endpoints": ["ws://127.0.0.1:9947"] | ||
| } | ||
| ] | ||
| }, { | ||
| "name": "zombienet_evm", | ||
|
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. [MEDIUM] Wire the new EVM suite into CI This registers a new Add |
||
| "timeout": 600000, | ||
| "testFileDir": ["suites/zombienet_evm"], | ||
| "runScripts": [ | ||
| "generate-types.sh", | ||
| "build-spec.sh" | ||
| ], | ||
| "foundation": { | ||
| "type": "zombie", | ||
| "zombieSpec": { | ||
| "configPath": "./configs/zombie_node.json", | ||
| "skipBlockCheck": [] | ||
| } | ||
| }, | ||
| "vitestArgs": { | ||
| "bail": 1 | ||
| }, | ||
| "connections": [ | ||
| { | ||
| "name": "Node", | ||
| "type": "papi", | ||
| "endpoints": ["ws://127.0.0.1:9947"], | ||
| "descriptor": "subtensor" | ||
| }, | ||
| { | ||
| "name": "EVM", | ||
| "type": "ethers", | ||
| "endpoints": ["http://127.0.0.1:9947"], | ||
| "descriptor": "evm" | ||
| } | ||
| ] | ||
| }, { | ||
| "name": "zombienet_subnets", | ||
| "timeout": 600000, | ||
|
|
||
| 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
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
Comment on lines
+21
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 These entries are still the literal placeholder strings from
Comment on lines
+21
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 These literal placeholder strings are still committed under
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| 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,28 @@ | ||
| 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.
[HIGH] Restore sender staking rate-limit validation
transfer_staked_alpha(..., validate_sender: true, ...)is the pathpallets/limit-ordersuses when collecting staked alpha from sell-order signers, and that call site explicitly relies onvalidate_senderto check the user's rate limit. The trait contract also says this flag must reject a sender that already staked in the current block. This hunk removes the only sender-side stake-operation-limit check and leaves onlyensure_available_to_unstake, so a signer can stake and then transfer that same-block stake into order matching, bypassing the intended anti-same-block staking guard. Restore an equivalent rate-limit check before the availability check; the removed helper name may need to be reintroduced or replaced with the current rate-limit API.