48 lines
1.7 KiB
Rust
48 lines
1.7 KiB
Rust
// This file contains WASM-only integration tests for EVM client balance and signing logic.
|
|
// All code is strictly separated from native using cfg attributes.
|
|
#![cfg(target_arch = "wasm32")]
|
|
use wasm_bindgen_test::*;
|
|
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
|
|
|
|
use evm_client::provider::{Transaction, parse_signature_rs_v, get_balance};
|
|
use ethers_core::types::{U256, Address, Bytes};
|
|
use hex;
|
|
|
|
#[wasm_bindgen_test]
|
|
fn test_rlp_encode_unsigned() {
|
|
let tx = Transaction {
|
|
to: Address::zero(),
|
|
value: U256::from(100),
|
|
data: Bytes::new(),
|
|
gas: Some(U256::from(21000)),
|
|
gas_price: Some(U256::from(1)),
|
|
nonce: Some(U256::from(1)),
|
|
chain_id: Some(1),
|
|
};
|
|
let rlp = tx.rlp_encode_unsigned();
|
|
assert!(!rlp.is_empty());
|
|
}
|
|
|
|
|
|
#[wasm_bindgen_test(async)]
|
|
pub async fn test_get_balance_real_address_wasm_unique() {
|
|
web_sys::console::log_1(&"WASM balance test running!".into());
|
|
// Vitalik's address
|
|
let address = "d8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
let address = Address::from_slice(&hex::decode(address).unwrap());
|
|
let url = "https://ethereum.blockpi.network/v1/rpc/public";
|
|
let balance = get_balance(url, address).await.expect("Failed to get balance"); // TODO: Update to use new EvmClient API
|
|
web_sys::console::log_1(&format!("Balance: {balance:?}").into());
|
|
assert!(balance > U256::zero(), "Vitalik's balance should be greater than zero");
|
|
}
|
|
|
|
#[wasm_bindgen_test]
|
|
fn test_parse_signature_rs_v() {
|
|
let mut sig = [0u8; 65];
|
|
sig[31] = 1; sig[63] = 2; sig[64] = 27;
|
|
let (r, s, v) = parse_signature_rs_v(&sig, 1).unwrap();
|
|
assert_eq!(r, U256::from(1));
|
|
assert_eq!(s, U256::from(2));
|
|
assert_eq!(v, 27 + 1 * 2 + 8);
|
|
}
|