1use platform_value::platform_value;
2
3use crate::data_contract::created_data_contract::CreatedDataContract;
4use crate::prelude::*;
5use crate::{
6 data_contract::DataContractFactory, identifier, tests::utils::generate_random_identifier_struct,
7};
8
9pub fn get_data_contract_fixture(
10 owner_id: Option<Identifier>,
11 identity_nonce: IdentityNonce,
12 protocol_version: u32,
13) -> CreatedDataContract {
14 let defs = platform_value!(
15 {
16 "lastName": {
17 "type" : "string",
18 },
19 });
20
21 let documents = platform_value!(
22 {
23 "niceDocument": {
24 "type": "object",
25 "properties": {
26 "name": {
27 "type": "string",
28 "position": 0
29 }
30 },
31 "required": [
32 "$createdAt"
33 ],
34 "additionalProperties": false
35 },
36 "prettyDocument": {
37 "type": "object",
38 "properties": {
39 "lastName": {
40 "$ref": "#/$defs/lastName",
41 "position": 0
42 }
43 },
44 "required": [
45
46 "lastName",
47 "$updatedAt"
48 ],
49 "additionalProperties": false
50 },
51 "indexedDocument": {
52 "type": "object",
53 "indices": [
54 {
55 "name": "index1",
56 "properties": [
57 {
58 "$ownerId": "asc"
59 },
60 {
61 "firstName": "asc"
62 }
63 ],
64 "unique": true
65 },
66 {
67 "name": "index2",
68 "properties": [
69 {
70 "$ownerId": "asc"
71 },
72 {
73 "lastName": "asc"
74 }
75 ],
76 "unique": true
77 },
78 {
79 "name": "index3",
80 "properties": [
81 {
82 "lastName": "asc"
83 }
84 ]
85 },
86 {
87 "name": "index4",
88 "properties": [
89 {
90 "$createdAt": "asc"
91 },
92 {
93 "$updatedAt": "asc"
94 }
95 ]
96 },
97 {
98 "name": "index5",
99 "properties": [
100 {
101 "$updatedAt": "asc"
102 }
103 ]
104 },
105 {
106 "name": "index6",
107 "properties": [
108 {
109 "$createdAt": "asc"
110 }
111 ]
112 }
113 ],
114 "properties": {
115 "firstName": {
116 "type": "string",
117 "maxLength": 63u32,
118 "position": 0
119 },
120 "lastName": {
121 "type": "string",
122 "maxLength": 63u32,
123 "position": 1
124 }
125 },
126 "required": [
127 "firstName",
128 "$createdAt",
129 "$updatedAt",
130 "lastName"
131 ],
132 "additionalProperties": false
133 },
134 "noTimeDocument": {
135 "type": "object",
136 "properties": {
137 "name": {
138 "type": "string",
139 "position": 0
140 },
141 },
142 "additionalProperties": false
143 },
144 "uniqueDates": {
145 "type": "object",
146 "indices": [
147 {
148 "name": "index1",
149 "properties": [
150 {
151 "$createdAt": "asc"
152 },
153 {
154 "$updatedAt": "asc"
155 }
156 ],
157 "unique": true
158 },
159 {
160 "name": "index2",
161 "properties": [
162 {
163 "$updatedAt": "asc"
164 }
165 ]
166 }
167 ],
168 "properties": {
169 "firstName": {
170 "type": "string",
171 "position": 0
172 },
173 "lastName": {
174 "type": "string",
175 "position": 1
176 }
177 },
178 "required": [
179 "firstName",
180 "$createdAt",
181 "$updatedAt"
182 ],
183 "additionalProperties": false
184 },
185 "withByteArrays": {
186 "type": "object",
187 "indices": [
188 {
189 "name": "index1",
190 "properties": [
191 {
192 "byteArrayField": "asc"
193 }
194 ]
195 }
196 ],
197 "properties": {
198 "byteArrayField": {
199 "type": "array",
200 "byteArray": true,
201 "maxItems": 16u32,
202 "position": 0
203 },
204 "identifierField": {
205 "type": "array",
206 "byteArray": true,
207 "contentMediaType": identifier::MEDIA_TYPE,
208 "minItems": 32u32,
209 "maxItems": 32u32,
210 "position": 1
211 }
212 },
213 "required": [
214 "byteArrayField"
215 ],
216 "additionalProperties": false
217 },
218 "optionalUniqueIndexedDocument": {
219 "type": "object",
220 "properties": {
221 "firstName": {
222 "type": "string",
223 "maxLength": 63u32,
224 "position": 0
225 },
226 "lastName": {
227 "type": "string",
228 "maxLength": 63u32,
229 "position": 1
230 },
231 "country": {
232 "type": "string",
233 "maxLength": 63u32,
234 "position": 2
235 },
236 "city": {
237 "type": "string",
238 "maxLength": 63u32,
239 "position": 3
240 }
241 },
242 "indices": [
243 {
244 "name": "index1",
245 "properties": [
246 {
247 "firstName": "asc"
248 }
249 ],
250 "unique": true
251 },
252 {
253 "name": "index2",
254 "properties": [
255 {
256 "$ownerId": "asc"
257 },
258 {
259 "firstName": "asc"
260 },
261 {
262 "lastName": "asc"
263 }
264 ],
265 "unique": true
266 },
267 {
268 "name": "index3",
269 "properties": [
270 {
271 "country": "asc"
272 },
273 {
274 "city": "asc"
275 }
276 ],
277 "unique": true
278 }
279 ],
280 "required": [
281 "firstName",
282 "lastName"
283 ],
284 "additionalProperties": false
285 }
286 });
287
288 let factory = DataContractFactory::new(protocol_version).expect("expected to create a factory");
289
290 let owner_id = owner_id.unwrap_or_else(generate_random_identifier_struct);
291
292 factory
293 .create_with_value_config(owner_id, identity_nonce, documents, None, Some(defs))
294 .expect("data in fixture should be correct")
295}