holochain_data 0.7.0-dev.13

Database abstraction layer for Holochain using sqlx
Documentation
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
//! Database handle operations for the Wasm database table.
//!
//! Provides [`DbRead`] and [`DbWrite`] impls for querying and mutating the Wasm database table.

use holo_hash::{AgentPubKey, WasmHash};
use holochain_types::prelude::{CellId, DnaDef, DnaWasmHashed, EntryDef};

use crate::handles::{DbRead, DbWrite};
use crate::kind::Wasm;

use super::{reads, writes};

impl DbRead<Wasm> {
    /// Check if WASM bytecode exists in the database.
    pub async fn wasm_exists(&self, hash: &WasmHash) -> sqlx::Result<bool> {
        reads::wasm_exists(self.pool(), hash).await
    }

    /// Get WASM bytecode by hash.
    pub async fn get_wasm(&self, hash: &WasmHash) -> sqlx::Result<Option<DnaWasmHashed>> {
        reads::get_wasm(self.pool(), hash).await
    }

    /// Check if a DNA definition exists in the database.
    pub async fn dna_def_exists(&self, cell_id: &CellId) -> sqlx::Result<bool> {
        reads::dna_def_exists(self.pool(), cell_id).await
    }

    /// Get a DNA definition for the passed [`CellId`].
    pub async fn get_dna_def(&self, cell_id: &CellId) -> sqlx::Result<Option<DnaDef>> {
        reads::get_dna_def(self.pool(), cell_id).await
    }

    /// Check if an entry definition exists in the database.
    pub async fn entry_def_exists(&self, key: &[u8]) -> sqlx::Result<bool> {
        reads::entry_def_exists(self.pool(), key).await
    }

    /// Get an entry definition by key.
    pub async fn get_entry_def(&self, key: &[u8]) -> sqlx::Result<Option<EntryDef>> {
        reads::get_entry_def(self.pool(), key).await
    }

    /// Get all entry definitions.
    pub async fn get_all_entry_defs(&self) -> sqlx::Result<Vec<(Vec<u8>, EntryDef)>> {
        reads::get_all_entry_defs(self.pool()).await
    }

    /// Get all DNA definitions with their associated cell IDs.
    pub async fn get_all_dna_defs(&self) -> sqlx::Result<Vec<(CellId, DnaDef)>> {
        reads::get_all_dna_defs(self.pool()).await
    }
}

impl DbWrite<Wasm> {
    /// Store WASM bytecode.
    pub async fn put_wasm(&self, wasm: DnaWasmHashed) -> sqlx::Result<()> {
        writes::put_wasm(self.pool(), wasm).await
    }

    /// Store a DNA definition and its associated zomes.
    ///
    /// This operation is transactional - either all data is stored or none is.
    pub async fn put_dna_def(&self, agent: &AgentPubKey, dna_def: &DnaDef) -> sqlx::Result<()> {
        writes::put_dna_def(self.pool(), agent, dna_def).await
    }

    /// Store an entry definition.
    pub async fn put_entry_def(&self, key: Vec<u8>, entry_def: &EntryDef) -> sqlx::Result<()> {
        writes::put_entry_def(self.pool(), key, entry_def).await
    }
}

#[cfg(test)]
mod tests {
    use holo_hash::{HasHash, HashableContentExtAsync, HashableContentExtSync};
    use holochain_integrity_types::{zome::ZomeName, EntryDefId, EntryVisibility};
    use holochain_serialized_bytes::SerializedBytes;
    use holochain_types::prelude::{
        AgentPubKey, CoordinatorZomeDef, DnaHash, DnaModifiers, DnaWasm, IntegrityZomeDef,
    };

    use crate::kind::Wasm;
    use crate::test_open_db;

    use super::*;

    /// Helper to create a test database
    async fn test_db() -> DbWrite<Wasm> {
        test_open_db(Wasm)
            .await
            .expect("Failed to create test database")
    }

    /// Helper to create a test CellId
    fn test_cell_id(dna_hash: &DnaHash) -> CellId {
        // Create a test agent key
        let agent = AgentPubKey::from_raw_32(vec![0u8; 32]);
        CellId::new(dna_hash.clone(), agent)
    }

    #[tokio::test]
    async fn wasm_roundtrip() {
        let db = test_db().await;

        // Create test WASM bytecode
        let code = vec![0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]; // WASM magic bytes
        let wasm = DnaWasm {
            code: code.clone().into(),
        };
        let hash = wasm.to_hash().await;
        let wasm_with_hash = DnaWasmHashed::with_pre_hashed(wasm, hash.clone());

        // Should not exist initially
        assert!(!db.as_ref().wasm_exists(&hash).await.unwrap());
        assert!(db.as_ref().get_wasm(&hash).await.unwrap().is_none());

        // Store WASM
        db.put_wasm(wasm_with_hash.clone()).await.unwrap();

        // Should exist now
        assert!(db.as_ref().wasm_exists(&hash).await.unwrap());

        // Retrieve and verify
        let retrieved = db.as_ref().get_wasm(&hash).await.unwrap().unwrap();
        assert_eq!(retrieved.as_hash(), &hash);
        assert_eq!(retrieved.as_content().code.as_ref(), code.as_slice());
    }

    #[tokio::test]
    async fn dna_def_roundtrip() {
        let db = test_db().await;

        // Create test DNA definition
        let mut integrity_zomes = Vec::new();
        let integrity_code = vec![0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00];
        let integrity_wasm = DnaWasm {
            code: integrity_code.into(),
        };
        let integrity_hash = integrity_wasm.to_hash().await;
        let integrity_wasm_hashed =
            DnaWasmHashed::with_pre_hashed(integrity_wasm, integrity_hash.clone());

        // Store the WASM first
        db.put_wasm(integrity_wasm_hashed).await.unwrap();

        integrity_zomes.push((
            ZomeName::from("integrity_zome"),
            IntegrityZomeDef::from_hash(integrity_hash),
        ));

        let mut coordinator_zomes = Vec::new();
        let coordinator_code = vec![0x00, 0x61, 0x73, 0x6d, 0x02, 0x00, 0x00, 0x00];
        let coordinator_wasm = DnaWasm {
            code: coordinator_code.into(),
        };
        let coordinator_hash = coordinator_wasm.to_hash().await;
        let coordinator_wasm_hashed =
            DnaWasmHashed::with_pre_hashed(coordinator_wasm, coordinator_hash.clone());

        // Store the WASM first
        db.put_wasm(coordinator_wasm_hashed).await.unwrap();

        coordinator_zomes.push((
            ZomeName::from("coordinator_zome"),
            CoordinatorZomeDef::from_hash(coordinator_hash),
        ));

        let dna_def = DnaDef {
            name: "test_dna".to_string(),
            modifiers: DnaModifiers {
                network_seed: "test_seed".to_string(),
                properties: SerializedBytes::default(),
            },
            integrity_zomes,
            coordinator_zomes,
            #[cfg(feature = "unstable-migration")]
            lineage: std::collections::HashSet::new(),
        };

        let hash = dna_def.to_hash();
        let cell_id = test_cell_id(&hash);

        // Should not exist initially
        assert!(!db.as_ref().dna_def_exists(&cell_id).await.unwrap());
        assert!(db.as_ref().get_dna_def(&cell_id).await.unwrap().is_none());

        // Store DNA definition
        db.put_dna_def(cell_id.agent_pubkey(), &dna_def)
            .await
            .unwrap();

        // Should exist now
        assert!(db.as_ref().dna_def_exists(&cell_id).await.unwrap());

        // Retrieve and verify
        let retrieved = db.as_ref().get_dna_def(&cell_id).await.unwrap().unwrap();
        assert_eq!(retrieved.name, "test_dna");
        assert_eq!(retrieved.modifiers.network_seed, "test_seed");
        assert_eq!(retrieved.integrity_zomes.len(), 1);
        assert_eq!(retrieved.coordinator_zomes.len(), 1);

        // Verify zome names
        assert!(retrieved
            .integrity_zomes
            .iter()
            .any(|(name, _)| name == &ZomeName::from("integrity_zome")));
        assert!(retrieved
            .coordinator_zomes
            .iter()
            .any(|(name, _)| name == &ZomeName::from("coordinator_zome")));
    }

    #[tokio::test]
    async fn entry_def_roundtrip() {
        let db = test_db().await;

        // Create test entry definitions
        let key1 = vec![1, 2, 3, 4];
        let entry_def1 = EntryDef {
            id: EntryDefId::App("test_entry".into()),
            visibility: EntryVisibility::Public,
            required_validations: 5u8.into(),
            cache_at_agent_activity: false,
        };

        let key2 = vec![5, 6, 7, 8];
        let entry_def2 = EntryDef {
            id: EntryDefId::CapGrant,
            visibility: EntryVisibility::Private,
            required_validations: 3u8.into(),
            cache_at_agent_activity: false,
        };

        // Should not exist initially
        assert!(!db.as_ref().entry_def_exists(&key1).await.unwrap());
        assert!(db.as_ref().get_entry_def(&key1).await.unwrap().is_none());

        // Store entry definitions
        db.put_entry_def(key1.clone(), &entry_def1).await.unwrap();
        db.put_entry_def(key2.clone(), &entry_def2).await.unwrap();

        // Should exist now
        assert!(db.as_ref().entry_def_exists(&key1).await.unwrap());
        assert!(db.as_ref().entry_def_exists(&key2).await.unwrap());

        // Retrieve and verify entry_def1
        let retrieved1 = db.as_ref().get_entry_def(&key1).await.unwrap().unwrap();
        assert_eq!(retrieved1.id, EntryDefId::App("test_entry".into()));
        assert_eq!(retrieved1.visibility, EntryVisibility::Public);
        assert_eq!(u8::from(retrieved1.required_validations), 5);

        // Retrieve and verify entry_def2
        let retrieved2 = db.as_ref().get_entry_def(&key2).await.unwrap().unwrap();
        assert_eq!(retrieved2.id, EntryDefId::CapGrant);
        assert_eq!(retrieved2.visibility, EntryVisibility::Private);
        assert_eq!(u8::from(retrieved2.required_validations), 3);

        // Test get_all_entry_defs
        let all_defs = db.as_ref().get_all_entry_defs().await.unwrap();
        assert_eq!(all_defs.len(), 2);

        // Verify both entries are present (order may vary)
        let keys: Vec<_> = all_defs.iter().map(|(k, _)| k.clone()).collect();
        assert!(keys.contains(&key1));
        assert!(keys.contains(&key2));
    }

    #[tokio::test]
    async fn dna_def_with_dependencies() {
        let db = test_db().await;

        // Create WASM for zomes
        let wasm_code = vec![0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00];
        let wasm = DnaWasm {
            code: wasm_code.into(),
        };
        let wasm_hash = wasm.to_hash().await;
        let wasm_hashed = DnaWasmHashed::with_pre_hashed(wasm, wasm_hash.clone());
        db.put_wasm(wasm_hashed).await.unwrap();

        // Create integrity zome with dependencies
        let mut integrity_zomes = Vec::new();
        let integrity_def = IntegrityZomeDef::from_hash(wasm_hash.clone());
        integrity_zomes.push((ZomeName::from("base_integrity"), integrity_def));

        // Create coordinator zome with dependencies on integrity zome
        let mut coordinator_zomes = Vec::new();
        let coordinator_def = CoordinatorZomeDef::from_hash(wasm_hash.clone());
        coordinator_zomes.push((ZomeName::from("coordinator"), coordinator_def));

        let dna_def = DnaDef {
            name: "test_dna_deps".to_string(),
            modifiers: DnaModifiers {
                network_seed: "seed".to_string(),
                properties: SerializedBytes::default(),
            },
            integrity_zomes,
            coordinator_zomes,
            #[cfg(feature = "unstable-migration")]
            lineage: std::collections::HashSet::new(),
        };

        let hash = dna_def.to_hash();
        let cell_id = test_cell_id(&hash);

        // Store and retrieve
        db.put_dna_def(cell_id.agent_pubkey(), &dna_def)
            .await
            .unwrap();
        let retrieved = db.as_ref().get_dna_def(&cell_id).await.unwrap().unwrap();

        // Verify structure
        assert_eq!(retrieved.name, "test_dna_deps");
        assert_eq!(retrieved.integrity_zomes.len(), 1);
        assert_eq!(retrieved.coordinator_zomes.len(), 1);
    }

    #[tokio::test]
    async fn entry_def_all_types() {
        let db = test_db().await;

        // Test all EntryDefId variants
        let app_key = vec![1];
        let app_entry = EntryDef {
            id: EntryDefId::App("my_app_entry".into()),
            visibility: EntryVisibility::Public,
            required_validations: 5u8.into(),
            cache_at_agent_activity: false,
        };

        let cap_claim_key = vec![2];
        let cap_claim_entry = EntryDef {
            id: EntryDefId::CapClaim,
            visibility: EntryVisibility::Private,
            required_validations: 3u8.into(),
            cache_at_agent_activity: false,
        };

        let cap_grant_key = vec![3];
        let cap_grant_entry = EntryDef {
            id: EntryDefId::CapGrant,
            visibility: EntryVisibility::Public,
            required_validations: 2u8.into(),
            cache_at_agent_activity: false,
        };

        // Store all types
        db.put_entry_def(app_key.clone(), &app_entry).await.unwrap();
        db.put_entry_def(cap_claim_key.clone(), &cap_claim_entry)
            .await
            .unwrap();
        db.put_entry_def(cap_grant_key.clone(), &cap_grant_entry)
            .await
            .unwrap();

        // Retrieve and verify each type
        let retrieved_app = db.as_ref().get_entry_def(&app_key).await.unwrap().unwrap();
        assert!(matches!(retrieved_app.id, EntryDefId::App(_)));
        assert_eq!(retrieved_app.visibility, EntryVisibility::Public);

        let retrieved_cap_claim = db
            .as_ref()
            .get_entry_def(&cap_claim_key)
            .await
            .unwrap()
            .unwrap();
        assert!(matches!(retrieved_cap_claim.id, EntryDefId::CapClaim));
        assert_eq!(retrieved_cap_claim.visibility, EntryVisibility::Private);

        let retrieved_cap_grant = db
            .as_ref()
            .get_entry_def(&cap_grant_key)
            .await
            .unwrap()
            .unwrap();
        assert!(matches!(retrieved_cap_grant.id, EntryDefId::CapGrant));
        assert_eq!(retrieved_cap_grant.visibility, EntryVisibility::Public);

        // Verify all are in get_all
        let all = db.as_ref().get_all_entry_defs().await.unwrap();
        assert_eq!(all.len(), 3);
    }

    #[tokio::test]
    async fn update_dna_def_removes_orphaned_zomes() {
        let db = test_db().await;

        // Create WASM for zomes
        let wasm_code = vec![0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00];
        let wasm = DnaWasm {
            code: wasm_code.into(),
        };
        let wasm_hash = wasm.to_hash().await;
        let wasm_hashed = DnaWasmHashed::with_pre_hashed(wasm, wasm_hash.clone());
        db.put_wasm(wasm_hashed).await.unwrap();

        // Create initial DNA with 3 integrity zomes and 2 coordinator zomes
        let integrity_zomes = vec![
            (
                ZomeName::from("integrity1"),
                IntegrityZomeDef::from_hash(wasm_hash.clone()),
            ),
            (
                ZomeName::from("integrity2"),
                IntegrityZomeDef::from_hash(wasm_hash.clone()),
            ),
            (
                ZomeName::from("integrity3"),
                IntegrityZomeDef::from_hash(wasm_hash.clone()),
            ),
        ];

        let coordinator_zomes = vec![
            (
                ZomeName::from("coordinator1"),
                CoordinatorZomeDef::from_hash(wasm_hash.clone()),
            ),
            (
                ZomeName::from("coordinator2"),
                CoordinatorZomeDef::from_hash(wasm_hash.clone()),
            ),
        ];

        let dna_def_v1 = DnaDef {
            name: "test_update".to_string(),
            modifiers: DnaModifiers {
                network_seed: "seed".to_string(),
                properties: SerializedBytes::default(),
            },
            integrity_zomes,
            coordinator_zomes,
            #[cfg(feature = "unstable-migration")]
            lineage: std::collections::HashSet::new(),
        };

        let hash = dna_def_v1.to_hash();
        let cell_id = test_cell_id(&hash);
        db.put_dna_def(cell_id.agent_pubkey(), &dna_def_v1)
            .await
            .unwrap();

        // Verify initial state
        let retrieved_v1 = db.as_ref().get_dna_def(&cell_id).await.unwrap().unwrap();
        assert_eq!(retrieved_v1.integrity_zomes.len(), 3);
        assert_eq!(retrieved_v1.coordinator_zomes.len(), 2);

        // Count zomes directly in the database
        let integrity_count: i64 =
            sqlx::query_scalar("SELECT COUNT(*) FROM IntegrityZome WHERE dna_hash = ?")
                .bind(hash.get_raw_32())
                .fetch_one(db.pool())
                .await
                .unwrap();
        assert_eq!(integrity_count, 3);

        let coordinator_count: i64 =
            sqlx::query_scalar("SELECT COUNT(*) FROM CoordinatorZome WHERE dna_hash = ?")
                .bind(hash.get_raw_32())
                .fetch_one(db.pool())
                .await
                .unwrap();
        assert_eq!(coordinator_count, 2);

        // Update DNA with fewer zomes (1 integrity, 1 coordinator)
        let integrity_zomes_v2 = vec![(
            ZomeName::from("integrity1"),
            IntegrityZomeDef::from_hash(wasm_hash.clone()),
        )];

        let coordinator_zomes_v2 = vec![(
            ZomeName::from("coordinator1"),
            CoordinatorZomeDef::from_hash(wasm_hash.clone()),
        )];

        let dna_def_v2 = DnaDef {
            name: "test_update_v2".to_string(),
            modifiers: DnaModifiers {
                network_seed: "seed_v2".to_string(),
                properties: SerializedBytes::default(),
            },
            integrity_zomes: integrity_zomes_v2,
            coordinator_zomes: coordinator_zomes_v2,
            #[cfg(feature = "unstable-migration")]
            lineage: std::collections::HashSet::new(),
        };

        // Different hash since zomes changed
        let hash_v2 = dna_def_v2.to_hash();
        let cell_id_v2 = test_cell_id(&hash_v2);
        assert_ne!(hash, hash_v2, "Hash should change when zomes change");

        // Update the DNA definition
        db.put_dna_def(cell_id_v2.agent_pubkey(), &dna_def_v2)
            .await
            .unwrap();

        // Verify old DNA still has original zomes
        let retrieved_v1 = db.as_ref().get_dna_def(&cell_id).await.unwrap().unwrap();
        assert_eq!(retrieved_v1.integrity_zomes.len(), 3);
        assert_eq!(retrieved_v1.coordinator_zomes.len(), 2);

        // Verify new DNA has new zomes
        let retrieved_v2 = db.as_ref().get_dna_def(&cell_id_v2).await.unwrap().unwrap();
        assert_eq!(retrieved_v2.integrity_zomes.len(), 1);
        assert_eq!(retrieved_v2.coordinator_zomes.len(), 1);

        // Verify no orphaned zomes remain for the old DNA hash
        let integrity_count_after: i64 =
            sqlx::query_scalar("SELECT COUNT(*) FROM IntegrityZome WHERE dna_hash = ?")
                .bind(hash.get_raw_32())
                .fetch_one(db.pool())
                .await
                .unwrap();
        assert_eq!(
            integrity_count_after, 3,
            "Original DNA should still have 3 integrity zomes"
        );

        let coordinator_count_after: i64 =
            sqlx::query_scalar("SELECT COUNT(*) FROM CoordinatorZome WHERE dna_hash = ?")
                .bind(hash.get_raw_32())
                .fetch_one(db.pool())
                .await
                .unwrap();
        assert_eq!(
            coordinator_count_after, 2,
            "Original DNA should still have 2 coordinator zomes"
        );

        // Verify new DNA has correct counts
        let new_integrity_count: i64 =
            sqlx::query_scalar("SELECT COUNT(*) FROM IntegrityZome WHERE dna_hash = ?")
                .bind(hash_v2.get_raw_32())
                .fetch_one(db.pool())
                .await
                .unwrap();
        assert_eq!(
            new_integrity_count, 1,
            "New DNA should have 1 integrity zome"
        );

        let new_coordinator_count: i64 =
            sqlx::query_scalar("SELECT COUNT(*) FROM CoordinatorZome WHERE dna_hash = ?")
                .bind(hash_v2.get_raw_32())
                .fetch_one(db.pool())
                .await
                .unwrap();
        assert_eq!(
            new_coordinator_count, 1,
            "New DNA should have 1 coordinator zome"
        );
    }

    #[tokio::test]
    async fn get_all_dna_defs_test() {
        let db = test_db().await;

        // Create and store multiple DNA definitions
        let wasm_code = vec![0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00];
        let wasm = DnaWasm {
            code: wasm_code.into(),
        };
        let wasm_hash = wasm.to_hash().await;
        let wasm_hashed = DnaWasmHashed::with_pre_hashed(wasm, wasm_hash.clone());
        db.put_wasm(wasm_hashed).await.unwrap();

        // Create first DNA
        let integrity_zomes1 = vec![(
            ZomeName::from("integrity1"),
            IntegrityZomeDef::from_hash(wasm_hash.clone()),
        )];
        let coordinator_zomes1 = vec![(
            ZomeName::from("coordinator1"),
            CoordinatorZomeDef::from_hash(wasm_hash.clone()),
        )];
        let dna_def1 = DnaDef {
            name: "dna1".to_string(),
            modifiers: DnaModifiers {
                network_seed: "seed1".to_string(),
                properties: SerializedBytes::default(),
            },
            integrity_zomes: integrity_zomes1,
            coordinator_zomes: coordinator_zomes1,
            #[cfg(feature = "unstable-migration")]
            lineage: std::collections::HashSet::new(),
        };
        let hash1 = dna_def1.to_hash();
        let cell_id1 = test_cell_id(&hash1);
        db.put_dna_def(cell_id1.agent_pubkey(), &dna_def1)
            .await
            .unwrap();

        // Create second DNA with different agent
        let agent2 = AgentPubKey::from_raw_32(vec![1u8; 32]);
        let integrity_zomes2 = vec![(
            ZomeName::from("integrity2"),
            IntegrityZomeDef::from_hash(wasm_hash.clone()),
        )];
        let coordinator_zomes2 = vec![(
            ZomeName::from("coordinator2"),
            CoordinatorZomeDef::from_hash(wasm_hash.clone()),
        )];
        let dna_def2 = DnaDef {
            name: "dna2".to_string(),
            modifiers: DnaModifiers {
                network_seed: "seed2".to_string(),
                properties: SerializedBytes::default(),
            },
            integrity_zomes: integrity_zomes2,
            coordinator_zomes: coordinator_zomes2,
            #[cfg(feature = "unstable-migration")]
            lineage: std::collections::HashSet::new(),
        };
        let hash2 = dna_def2.to_hash();
        let cell_id2 = CellId::new(hash2.clone(), agent2);
        db.put_dna_def(cell_id2.agent_pubkey(), &dna_def2)
            .await
            .unwrap();

        // Get all DNA definitions
        let all_dnas = db.as_ref().get_all_dna_defs().await.unwrap();

        // Verify we got both DNAs
        assert_eq!(all_dnas.len(), 2);

        // Verify the cell IDs and DNA names
        let names: Vec<_> = all_dnas.iter().map(|(_, dna)| &dna.name).collect();
        assert!(names.contains(&&"dna1".to_string()));
        assert!(names.contains(&&"dna2".to_string()));

        // Verify we can find each DNA by cell ID
        let cell_ids: Vec<_> = all_dnas.iter().map(|(cell_id, _)| cell_id).collect();
        assert!(cell_ids.contains(&&cell_id1));
        assert!(cell_ids.contains(&&cell_id2));
    }
}