forked from jl777/SuperNET
-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy patheth_wasm_tests.rs
96 lines (88 loc) · 3.03 KB
/
eth_wasm_tests.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use super::*;
use crate::lp_coininit;
use crypto::CryptoCtx;
use mm2_core::mm_ctx::MmCtxBuilder;
use mm2_test_helpers::for_tests::{ETH_SEPOLIA_NODES, ETH_SEPOLIA_SWAP_CONTRACT};
use wasm_bindgen_test::*;
use web_sys::console;
wasm_bindgen_test_configure!(run_in_browser);
#[wasm_bindgen_test]
fn pass() {
let ctx = MmCtxBuilder::default().into_mm_arc();
let _coins_context = CoinsContext::from_ctx(&ctx).unwrap();
}
async fn init_eth_coin_helper() -> Result<(MmArc, MmCoinEnum), String> {
let conf = json!({
"coins": [{
"coin": "ETH",
"name": "ethereum",
"fname": "Ethereum",
"chain_id": 1337,
"protocol":{
"type": "ETH"
},
"chain_id": 1,
"rpcport": 80,
"mm2": 1,
"max_eth_tx_type": 2
}]
});
let ctx = MmCtxBuilder::new().with_conf(conf).into_mm_arc();
CryptoCtx::init_with_iguana_passphrase(
ctx.clone(),
"spice describe gravity federal blast come thank unfair canal monkey style afraid",
)
.unwrap();
let req = json!({
"urls":ETH_SEPOLIA_NODES,
"swap_contract_address":ETH_SEPOLIA_SWAP_CONTRACT
});
Ok((ctx.clone(), lp_coininit(&ctx, "ETH", &req).await?))
}
#[wasm_bindgen_test]
async fn test_init_eth_coin() { let (_ctx, _coin) = init_eth_coin_helper().await.unwrap(); }
#[wasm_bindgen_test]
async fn wasm_test_sign_eth_tx() {
// we need to hold ref to _ctx until the end of the test (because of the weak ref to MmCtx in EthCoinImpl)
let (_ctx, coin) = init_eth_coin_helper().await.unwrap();
let sign_req = json::from_value(json!({
"coin": "ETH",
"type": "ETH",
"tx": {
"to": "0x7Bc1bBDD6A0a722fC9bffC49c921B685ECB84b94".to_string(),
"value": "1.234",
"gas_limit": "21000"
}
}))
.unwrap();
let res = coin.sign_raw_tx(&sign_req).await;
console::log_1(&format!("res={:?}", res).into());
assert!(res.is_ok());
}
#[wasm_bindgen_test]
async fn wasm_test_sign_eth_tx_with_priority_fee() {
// we need to hold ref to _ctx until the end of the test (because of the weak ref to MmCtx in EthCoinImpl)
let (_ctx, coin) = init_eth_coin_helper().await.unwrap();
let sign_req = json::from_value(json!({
"coin": "ETH",
"type": "ETH",
"tx": {
"to": "0x7Bc1bBDD6A0a722fC9bffC49c921B685ECB84b94".to_string(),
"value": "1.234",
"gas_limit": "21000",
"pay_for_gas": {
"tx_type": "Eip1559",
"max_fee_per_gas": "1234.567",
"max_priority_fee_per_gas": "1.2",
}
}
}))
.unwrap();
let res = coin.sign_raw_tx(&sign_req).await;
console::log_1(&format!("res={:?}", res).into());
assert!(res.is_ok());
let tx: UnverifiedTransactionWrapper = rlp::decode(&res.unwrap().tx_hex).expect("decoding signed tx okay");
if !matches!(tx, UnverifiedTransactionWrapper::Eip1559(..)) {
panic!("expected eip1559 tx");
}
}