-
Notifications
You must be signed in to change notification settings - Fork 3
/
mod.rs
155 lines (132 loc) · 4.65 KB
/
mod.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
pub mod constants;
mod erc20_bridge;
mod eth_bridge;
mod madara;
use rstest::rstest;
use crate::contract_clients::config::Clients;
use crate::tests::erc20_bridge::erc20_bridge_test_helper;
use crate::tests::eth_bridge::eth_bridge_test_helper;
use crate::tests::madara::{MadaraCmd, MadaraCmdBuilder};
use crate::{bootstrap, setup_core_contract, setup_l2, BootstrapperOutput, ConfigFile};
async fn test_setup(args: &ConfigFile, clients: &Clients) -> (BootstrapperOutput, MadaraCmd) {
// Setup L1 (core contract)
let core_contract_client = setup_core_contract(args, clients).await;
let core_contract_address = core_contract_client.core_contract_client.address();
let core_contract_implementation_address = core_contract_client.core_contract_client.implementation_address();
// Create a new config with the core contract addresses
let mut config = get_test_config_file();
config.core_contract_address = Some(format!("{:?}", core_contract_address));
config.core_contract_implementation_address = Some(format!("{:?}", core_contract_implementation_address));
let mut node = MadaraCmdBuilder::new()
.args([
"--no-sync-polling",
"--l1-endpoint",
"http://localhost:8545",
"--chain-config-path=./bin/devnet.yaml",
"--rpc-cors",
"*",
"--rpc-external",
"--sequencer",
"--feeder-gateway-enable",
"--gateway-enable",
"--gateway-external",
"--rpc-methods",
"unsafe",
"--gas-price",
"0",
"--blob-gas-price",
"0",
"--strk-gas-price",
"0",
"--strk-blob-gas-price",
"0",
])
.run();
node.wait_for_ready().await;
// Setup L2 with the updated config
let l2_output = setup_l2(&config, clients).await;
let output = BootstrapperOutput {
starknet_contract_address: Some(core_contract_address),
starknet_contract_implementation_address: Some(core_contract_implementation_address),
..l2_output
};
(output, node)
}
#[rstest]
#[tokio::test]
#[ignore = "ignored because we have a e2e test, and this is for a local test"]
async fn deploy_bridge() -> Result<(), anyhow::Error> {
env_logger::init();
let config = get_test_config_file();
let clients = Clients::init_from_config(&config).await;
bootstrap(&config, &clients).await;
Ok(())
}
#[rstest]
#[tokio::test]
#[ignore = "ignored because we have a e2e test, and this is for a local test"]
async fn deposit_and_withdraw_eth_bridge() -> Result<(), anyhow::Error> {
env_logger::init();
let config = get_test_config_file();
let clients = Clients::init_from_config(&config).await;
let out = bootstrap(&config, &clients).await;
let eth_bridge_setup = out.eth_bridge_setup_outputs.unwrap();
let _ = eth_bridge_test_helper(
&clients,
&config,
eth_bridge_setup.l2_eth_proxy_address,
eth_bridge_setup.l2_eth_bridge_proxy_address,
eth_bridge_setup.l1_bridge,
)
.await;
Ok(())
}
#[rstest]
#[tokio::test]
#[ignore = "ignored because we have a e2e test, and this is for a local test"]
async fn deposit_and_withdraw_erc20_bridge() -> Result<(), anyhow::Error> {
env_logger::init();
let config = get_test_config_file();
let clients = Clients::init_from_config(&config).await;
let out = bootstrap(&config, &clients).await;
let eth_token_setup = out.erc20_bridge_setup_outputs.unwrap();
let _ = erc20_bridge_test_helper(
&clients,
&config,
eth_token_setup.test_erc20_token_address,
eth_token_setup.token_bridge,
eth_token_setup.l2_token_bridge,
)
.await;
Ok(())
}
#[rstest]
#[tokio::test]
async fn deposit_tests_both_bridges() -> Result<(), anyhow::Error> {
env_logger::init();
let config = get_test_config_file();
let clients = Clients::init_from_config(&config).await;
let (out, _madara) = test_setup(&config, &clients).await;
let eth_bridge_setup = out.eth_bridge_setup_outputs.unwrap();
let eth_token_setup = out.erc20_bridge_setup_outputs.unwrap();
let _ = eth_bridge_test_helper(
&clients,
&config,
eth_bridge_setup.l2_eth_proxy_address,
eth_bridge_setup.l2_eth_bridge_proxy_address,
eth_bridge_setup.l1_bridge,
)
.await;
let _ = erc20_bridge_test_helper(
&clients,
&config,
eth_token_setup.test_erc20_token_address,
eth_token_setup.token_bridge,
eth_token_setup.l2_token_bridge,
)
.await;
Ok(())
}
fn get_test_config_file() -> ConfigFile {
ConfigFile::default()
}