-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_helpers.rs
More file actions
201 lines (178 loc) · 7.96 KB
/
Copy pathtest_helpers.rs
File metadata and controls
201 lines (178 loc) · 7.96 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
// 2026 (c) Copyright Contributors to the GOSH DAO. All rights reserved.
//
// Methods compiled only with the `test-helpers` feature — deploy +
// setup entry points plus the read-only PN getters used by e2e tests
// to verify on-chain state. Used by the api crate's e2e integration
// tests, which spawn an ephemeral PMP + OrderBook per run before
// exercising the trader write-path, and poll PN getters to assert
// on-chain effects.
//
// The prod api/infrastructure build leaves `test-helpers` off so
// `Dex` exposes only the trader-path methods in `client.rs`.
use ackinacki_kit::contracts::dex::oracle::Oracle;
use ackinacki_kit::contracts::dex::oracle::ParamsOfGetEventListAddress;
use ackinacki_kit::contracts::dex::oracle_event_list::OracleEventList;
use ackinacki_kit::contracts::dex::oracle_event_list::ParamsOfAddEvent;
use ackinacki_kit::contracts::dex::oracle_event_list::ResultOfGetEvents;
use ackinacki_kit::contracts::dex::pmp::ParamsOfSubmitResolve;
use ackinacki_kit::contracts::dex::pmp::ParamsOfSubmitSetTimings;
use ackinacki_kit::contracts::dex::pmp::Pmp;
use ackinacki_kit::contracts::dex::pmp::ResultOfGetDetails as PmpKitDetails;
use ackinacki_kit::contracts::dex::private_note::ParamsOfDeployPmp;
use ackinacki_kit::contracts::dex::private_note::ParamsOfSetStake;
use ackinacki_kit::contracts::dex::private_note::PrivateNote;
use ackinacki_kit::contracts::dex::private_note::ResultOfGetDetails as PnDetails;
use ackinacki_kit::contracts::dex::private_note::ResultOfGetStakes as PnStakesRaw;
use ackinacki_kit::contracts::dex::root_oracle::ParamsOfDeployOracle;
use ackinacki_kit::contracts::dex::root_oracle::ParamsOfGetOracleAddress;
use ackinacki_kit::contracts::dex::root_oracle::RootOracle;
use ackinacki_kit::contracts::dex::root_pn::ParamsOfGetPmpAddress;
use ackinacki_kit::contracts::dex::root_pn::RootPn;
use ackinacki_kit::tvm_client::abi::Signer;
use ackinacki_kit::tvm_client::processing::ResultOfSendMessage;
use super::client::Dex;
use super::error::ChainResult;
/// Shape returned by `Pmp.getDetails`. Aliased so call sites don't
/// have to reach for the kit's three-deep contract path.
pub type PmpDetails = PmpKitDetails;
/// Shape returned by `OracleEventList.getEvents`. `.events` is a
/// `HashMap<String, serde_json::Value>` keyed by event id.
pub type OracleEvents = ResultOfGetEvents;
impl Dex {
// ── PrivateNote (deployer-side) ──────────────────────────────────
pub async fn deploy_pmp(
&self,
pn_address: &str,
params: ParamsOfDeployPmp,
signer: Signer,
) -> ChainResult<ResultOfSendMessage> {
PrivateNote::new(self.ctx.clone(), pn_address)
.deploy_pmp(params, signer)
.await
.map_err(Into::into)
}
pub async fn set_stake(
&self,
pn_address: &str,
params: ParamsOfSetStake,
signer: Signer,
) -> ChainResult<ResultOfSendMessage> {
PrivateNote::new(self.ctx.clone(), pn_address)
.set_stake(params, signer)
.await
.map_err(Into::into)
}
/// Read-only `PrivateNote.getDetails` accessor. Surfaces
/// `_balance[tokenType]`, `_busy.busyAddress`, and a handful of
/// other public PN fields without touching the read-model. The
/// production API reads PN state via the GraphQL-backed
/// `pn_state_reader`; this direct accessor exists so e2e tests can
/// verify on-chain balance moves after `splitFullSet` and poll the
/// `_busy` window between submission and the `onSplitAccepted`
/// callback without standing up the GraphQL gateway.
pub async fn get_private_note_details(&self, pn_address: &str) -> ChainResult<PnDetails> {
PrivateNote::new(self.ctx.clone(), pn_address).get_details().await.map_err(Into::into)
}
/// Read-only `PrivateNote._stakes` accessor. Returns the raw
/// `HashMap<String, Value>` keyed by `tvm.hash(eventId,
/// oracleListHash, tokenType)` (0x-prefixed lowercase hex). Each
/// value carries the StakeInfo tuple — `amount`, `debtAmount`,
/// `couponsAmount` plus bookkeeping fields. Sibling of
/// `get_private_note_details`, scoped to the same e2e niche.
pub async fn get_private_note_stakes(&self, pn_address: &str) -> ChainResult<PnStakesRaw> {
PrivateNote::new(self.ctx.clone(), pn_address).get_stakes().await.map_err(Into::into)
}
// ── PMP (oracle-signed ops + getters) ────────────────────────────
pub async fn submit_set_timings(
&self,
pmp_address: &str,
params: ParamsOfSubmitSetTimings,
signer: Signer,
) -> ChainResult<ResultOfSendMessage> {
Pmp::new(self.ctx.clone(), pmp_address)
.submit_set_timings(params, signer)
.await
.map_err(Into::into)
}
pub async fn submit_resolve(
&self,
pmp_address: &str,
params: ParamsOfSubmitResolve,
signer: Signer,
) -> ChainResult<ResultOfSendMessage> {
Pmp::new(self.ctx.clone(), pmp_address)
.submit_resolve(params, signer)
.await
.map_err(Into::into)
}
pub async fn get_pmp_details(&self, pmp_address: &str) -> ChainResult<PmpDetails> {
Pmp::new(self.ctx.clone(), pmp_address).get_details().await.map_err(Into::into)
}
pub async fn get_order_book_address(&self, pmp_address: &str) -> ChainResult<String> {
Pmp::new(self.ctx.clone(), pmp_address)
.get_order_book_address()
.await
.map(|r| r.order_book_address)
.map_err(Into::into)
}
// ── RootPN (address derivation) ──────────────────────────────────
pub async fn get_pmp_address(
&self,
event_id: String,
names: Vec<String>,
token_type: u32,
) -> ChainResult<String> {
RootPn::new_default(self.ctx.clone())
.get_pmp_address(ParamsOfGetPmpAddress { event_id, names, token_type })
.await
.map(|r| r.pmp_address)
.map_err(Into::into)
}
// ── RootOracle ───────────────────────────────────────────────────
pub async fn deploy_oracle(
&self,
params: ParamsOfDeployOracle,
signer: Signer,
) -> ChainResult<ResultOfSendMessage> {
RootOracle::new_default(self.ctx.clone())
.deploy_oracle(params, signer)
.await
.map_err(Into::into)
}
pub async fn get_oracle_address(&self, name: String) -> ChainResult<String> {
RootOracle::new_default(self.ctx.clone())
.get_oracle_address(ParamsOfGetOracleAddress { name })
.await
.map(|r| r.oracle_address)
.map_err(Into::into)
}
// ── Oracle + OracleEventList ─────────────────────────────────────
pub async fn get_event_list_address(
&self,
oracle_address: &str,
params: ParamsOfGetEventListAddress,
) -> ChainResult<String> {
Oracle::new(self.ctx.clone(), oracle_address)
.get_event_list_address(params)
.await
.map(|r| r.address)
.map_err(Into::into)
}
pub async fn add_event(
&self,
event_list_address: &str,
params: ParamsOfAddEvent,
signer: Signer,
) -> ChainResult<ResultOfSendMessage> {
OracleEventList::new(self.ctx.clone(), event_list_address)
.add_event(params, signer)
.await
.map_err(Into::into)
}
pub async fn get_events(&self, event_list_address: &str) -> ChainResult<OracleEvents> {
OracleEventList::new(self.ctx.clone(), event_list_address)
.get_events()
.await
.map_err(Into::into)
}
}