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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// use cw_multi_test::wasm_emulation::channel::RemoteChannel;
// use std::path::Path;
// use tokio::runtime::Runtime;
// use cosmwasm_schema::{cw_serde, QueryResponses};
// use cosmwasm_std::Empty;
// use cw_multi_test::error::AnyResult;
// use cw_multi_test::wasm_emulation::contract::WasmContract;
// use cw_multi_test::wasm_emulation::storage::analyzer::StorageAnalyzer;
// use cw_multi_test::AppBuilder;
// use cw_multi_test::Executor;
// use cw_multi_test::WasmKeeper;
// use cw_orch_daemon::networks::PHOENIX_1;
// #[cw_serde]
// pub struct InstantiateMsg {
// pub count: i32,
// }
// // ANCHOR: exec_msg
// #[cw_serde]
// #[cfg_attr(feature = "interface", derive(cw_orch::ExecuteFns))] // Function generation
// pub enum ExecuteMsg {
// Increment {},
// IncrementAndQuery {},
// SetCousin { addr: String },
// Reset { count: i32 },
// }
// // ANCHOR_END: exec_msg
// // ANCHOR: query_msg
// #[cw_serde]
// #[cfg_attr(feature = "interface", derive(cw_orch::QueryFns))] // Function generation
// #[derive(QueryResponses)]
// pub enum QueryMsg {
// // GetCount returns the current count as a json-encoded number
// #[returns(GetCountResponse)]
// GetCount {},
// // GetCount returns the current count of the cousin contract
// #[returns(GetCountResponse)]
// GetCousinCount {},
// }
// // Custom response for the query
// #[cw_serde]
// pub struct GetCountResponse {
// pub count: i32,
// }
// #[cw_serde]
// pub struct GetCousinCountResponse {
// pub raw: i32,
// pub smart: i32,
// }
// // ANCHOR_END: query_msg
// #[cw_serde]
// pub struct MigrateMsg {
// pub t: String,
// }
// pub fn test() -> AnyResult<()> {
// env_logger::init();
// let runtime = Runtime::new()?;
// let chain = PHOENIX_1;
// let remote_channel = RemoteChannel::new(&runtime, chain)?;
// let wasm = WasmKeeper::<Empty, Empty>::new().with_remote(remote_channel.clone());
// // First we instantiate a new app
// let app = AppBuilder::default()
// .with_remote(remote_channel.clone())
// .with_wasm(wasm);
// let mut app = app.build(|_, _, _| {})?;
// // Then we send a message to the blockchain through the app
// let sender = app.next_address();
// let code = std::fs::read(
// Path::new(env!("CARGO_MANIFEST_DIR"))
// .join("artifacts")
// .join("counter_contract.wasm"),
// )
// .unwrap();
// let counter_contract = WasmContract::new_local(code);
// let code_id = app.store_code(counter_contract);
// let counter1 = app
// .instantiate_contract(
// code_id,
// sender.clone(),
// &InstantiateMsg { count: 1 },
// &[],
// "cousin-counter",
// Some(sender.to_string()),
// )
// .unwrap();
// let counter2 = app
// .instantiate_contract(
// code_id,
// sender.clone(),
// &InstantiateMsg { count: 1 },
// &[],
// "cousin-counter",
// Some(sender.to_string()),
// )
// .unwrap();
// app.execute_contract(
// sender.clone(),
// counter1.clone(),
// &ExecuteMsg::Increment {},
// &[],
// )
// .unwrap();
// app.execute_contract(
// sender.clone(),
// counter1.clone(),
// &ExecuteMsg::Increment {},
// &[],
// )
// .unwrap();
// app.execute_contract(
// sender.clone(),
// counter2.clone(),
// &ExecuteMsg::Increment {},
// &[],
// )
// .unwrap();
// app.execute_contract(
// sender.clone(),
// counter1.clone(),
// &ExecuteMsg::SetCousin {
// addr: counter2.to_string(),
// },
// &[],
// )
// .unwrap();
// app.execute_contract(
// sender,
// counter2.clone(),
// &ExecuteMsg::SetCousin {
// addr: counter1.to_string(),
// },
// &[],
// )
// .unwrap();
// let cousin_count: GetCousinCountResponse = app
// .wrap()
// .query_wasm_smart(counter2.clone(), &QueryMsg::GetCousinCount {})
// .unwrap();
// assert_eq!(cousin_count.raw, cousin_count.smart);
// assert_eq!(cousin_count.raw, 3);
// let cousin_count: GetCousinCountResponse = app
// .wrap()
// .query_wasm_smart(counter1.clone(), &QueryMsg::GetCousinCount {})
// .unwrap();
// assert_eq!(cousin_count.raw, cousin_count.smart);
// assert_eq!(cousin_count.raw, 2);
// // Analyze the storage
// let analysis = StorageAnalyzer::new(&app).unwrap();
// log::info!(
// "analysis, wasm1 {:?}",
// analysis.get_contract_storage(counter1.clone())
// );
// log::info!("analysis, wasm1 {:?}", analysis.readable_storage(counter1));
// log::info!(
// "analysis, wasm2 {:?}",
// analysis.get_contract_storage(counter2.clone())
// );
// log::info!("analysis, wasm2 {:?}", analysis.readable_storage(counter2));
// log::info!(
// "All contracts storage {:?}",
// analysis.all_readable_contract_storage()
// );
// analysis.compare_all_readable_contract_storage();
// Ok(())
// }