@@ -8,15 +8,15 @@ mod cluster_database_tests {
88 // Test inserting a cluster into the database
99 fn test_insert_retrieve_cluster ( ) {
1010 let fixture = TestFixture :: new ( ) ;
11- assertions:: cluster:: exists_in_db ( & fixture. db , & fixture. cluster ) ;
11+
12+ let mut conn = fixture. db . connection ( ) . unwrap ( ) ;
13+ let tx = conn. transaction ( ) . unwrap ( ) ;
14+
15+ assertions:: cluster:: exists_in_db ( & fixture. cluster , & tx) ;
1216 assertions:: cluster:: exists_in_memory ( & fixture. db , & fixture. cluster ) ;
1317 assertions:: validator:: exists_in_memory ( & fixture. db , & fixture. validator ) ;
14- assertions:: validator:: exists_in_db ( & fixture. db , & fixture. validator ) ;
15- assertions:: share:: exists_in_db (
16- & fixture. db ,
17- & fixture. validator . public_key ,
18- & fixture. shares ,
19- ) ;
18+ assertions:: validator:: exists_in_db ( & fixture. validator , & tx) ;
19+ assertions:: share:: exists_in_db ( & fixture. validator . public_key , & fixture. shares , & tx) ;
2020 }
2121
2222 #[ test]
@@ -25,14 +25,18 @@ mod cluster_database_tests {
2525 fn test_delete_last_validator ( ) {
2626 let fixture = TestFixture :: new ( ) ;
2727 let pubkey = fixture. validator . public_key ;
28- assert ! ( fixture. db. delete_validator( & pubkey) . is_ok( ) ) ;
28+
29+ let mut conn = fixture. db . connection ( ) . unwrap ( ) ;
30+ let tx = conn. transaction ( ) . unwrap ( ) ;
31+
32+ assert ! ( fixture. db. delete_validator( & pubkey, & tx) . is_ok( ) ) ;
2933
3034 // Since there was only one validator in the cluster, everything should be removed
31- assertions:: cluster:: exists_not_in_db ( & fixture. db , fixture . cluster . cluster_id ) ;
35+ assertions:: cluster:: exists_not_in_db ( fixture. cluster . cluster_id , & tx ) ;
3236 assertions:: cluster:: exists_not_in_memory ( & fixture. db , fixture. cluster . cluster_id ) ;
33- assertions:: validator:: exists_not_in_db ( & fixture. db , & fixture . validator ) ;
37+ assertions:: validator:: exists_not_in_db ( & fixture. validator , & tx ) ;
3438 assertions:: validator:: exists_not_in_memory ( & fixture. db , & fixture. validator ) ;
35- assertions:: share:: exists_not_in_db ( & fixture . db , & pubkey ) ;
39+ assertions:: share:: exists_not_in_db ( & pubkey , & tx ) ;
3640 assertions:: share:: exists_not_in_memory ( & fixture. db , & pubkey) ;
3741 }
3842
@@ -43,17 +47,20 @@ mod cluster_database_tests {
4347 let mut cluster = fixture. cluster ;
4448 let new_fee_recipient = Address :: random ( ) ;
4549
50+ let mut conn = fixture. db . connection ( ) . unwrap ( ) ;
51+ let tx = conn. transaction ( ) . unwrap ( ) ;
52+
4653 // Update fee recipient
4754 assert ! (
4855 fixture
4956 . db
50- . update_fee_recipient( cluster. owner, new_fee_recipient)
57+ . update_fee_recipient( cluster. owner, new_fee_recipient, & tx )
5158 . is_ok( )
5259 ) ;
5360
5461 // assertions will compare the data
5562 cluster. fee_recipient = new_fee_recipient;
56- assertions:: cluster:: exists_in_db ( & fixture . db , & cluster ) ;
63+ assertions:: cluster:: exists_in_db ( & cluster , & tx ) ;
5764 assertions:: cluster:: exists_in_memory ( & fixture. db , & cluster) ;
5865 }
5966
@@ -68,9 +75,11 @@ mod cluster_database_tests {
6875 OperatorId ( 1 ) ,
6976 & fixture. validator. public_key,
7077 ) ] ;
78+ let mut conn = fixture. db . connection ( ) . unwrap ( ) ;
79+ let tx = conn. transaction ( ) . unwrap ( ) ;
7180 fixture
7281 . db
73- . insert_validator ( cluster, metadata, shares)
82+ . insert_validator ( cluster, metadata, shares, & tx )
7483 . expect_err ( "Insertion should fail" ) ;
7584 }
7685
@@ -80,25 +89,30 @@ mod cluster_database_tests {
8089 let fixture = TestFixture :: new ( ) ;
8190 let mut cluster = fixture. cluster ;
8291
92+ let mut conn = fixture. db . connection ( ) . unwrap ( ) ;
93+ let tx = conn. transaction ( ) . unwrap ( ) ;
94+
8395 // Test updating to liquidated
8496 fixture
8597 . db
86- . update_status ( cluster. cluster_id , true )
98+ . update_status ( cluster. cluster_id , true , & tx )
8799 . expect ( "Failed to update cluster status" ) ;
88100
89101 // verify in memory and db
90102 cluster. liquidated = true ;
91- assertions:: cluster:: exists_in_db ( & fixture . db , & cluster ) ;
103+ assertions:: cluster:: exists_in_db ( & cluster , & tx ) ;
92104 assertions:: cluster:: exists_in_memory ( & fixture. db , & cluster) ;
93105 }
94106
95107 #[ test]
96108 // Test inserting a cluster that already exists
97109 fn test_duplicate_cluster_insert ( ) {
98110 let fixture = TestFixture :: new ( ) ;
111+ let mut conn = fixture. db . connection ( ) . unwrap ( ) ;
112+ let tx = conn. transaction ( ) . unwrap ( ) ;
99113 fixture
100114 . db
101- . insert_validator ( fixture. cluster , fixture. validator , fixture. shares )
115+ . insert_validator ( fixture. cluster , fixture. validator , fixture. shares , & tx )
102116 . expect_err ( "Expected failure when inserting cluster that already exists" ) ;
103117 }
104118
@@ -108,26 +122,35 @@ mod cluster_database_tests {
108122 let fixture = TestFixture :: new ( ) ;
109123 let mut cluster = fixture. cluster ;
110124
125+ let mut conn = fixture. db . connection ( ) . unwrap ( ) ;
126+ let tx = conn. transaction ( ) . unwrap ( ) ;
127+
111128 // Confirm that the fee recipient was inserted when the cluster was made
112- let fee_recipient = fixture. db . fee_recipient_for_owner ( & cluster. owner ) . unwrap ( ) ;
129+ let fee_recipient = fixture
130+ . db
131+ . fee_recipient_for_owner ( & cluster. owner , & tx)
132+ . unwrap ( ) ;
113133 assert_eq ! ( fee_recipient, Some ( cluster. fee_recipient) ) ;
114134
115135 // Update fee recipient
116136 let new_fee_recipient = Address :: random ( ) ;
117137 assert ! (
118138 fixture
119139 . db
120- . update_fee_recipient( cluster. owner, new_fee_recipient)
140+ . update_fee_recipient( cluster. owner, new_fee_recipient, & tx )
121141 . is_ok( )
122142 ) ;
123143
124144 // Confirm that fee recipient was updated
125145 cluster. fee_recipient = new_fee_recipient;
126- assertions:: cluster:: exists_in_db ( & fixture . db , & cluster ) ;
146+ assertions:: cluster:: exists_in_db ( & cluster , & tx ) ;
127147 assertions:: cluster:: exists_in_memory ( & fixture. db , & cluster) ;
128148
129149 // Confirm that we have set the correct fee recipient for the owner
130- let stored_fee_recipient = fixture. db . fee_recipient_for_owner ( & cluster. owner ) . unwrap ( ) ;
150+ let stored_fee_recipient = fixture
151+ . db
152+ . fee_recipient_for_owner ( & cluster. owner , & tx)
153+ . unwrap ( ) ;
131154 assert_eq ! ( stored_fee_recipient, Some ( new_fee_recipient) ) ;
132155 }
133156}
0 commit comments