MCPcopy Create free account
hub / github.com/consensus-shipyard/ipc / check_writable

Function check_writable

fendermint/storage/src/testing.rs:151–186  ·  view source on GitHub ↗

State machine test for an implementation of a `KVWritable` using a sequence of random ops.

(sut: &impl KVWritable<S>, data: TestData)

Source from the content-addressed store, hash-verified

149
150/// State machine test for an implementation of a `KVWritable` using a sequence of random ops.
151pub fn check_writable<S>(sut: &impl KVWritable<S>, data: TestData) -> bool
152where
153 S: KVStore<Namespace = TestNamespace> + Clone + Codec<String> + Codec<u8>,
154 S::Repr: Ord + 'static,
155{
156 let mut model = Model::default();
157 // Creating a collection doesn't add much to the test but at least we exercise this path.
158 let mut colls = Collections::<S>::default();
159 // Start the transaction.
160 let mut tx = sut.write();
161 let mut ok = true;
162 for d in data.ops {
163 match d {
164 TestOpNs::S2I(ns, op) => {
165 let coll = colls.s2i(ns);
166 if !apply_both(&mut tx, &mut model.s2i, coll, ns, op) {
167 ok = false;
168 }
169 }
170 TestOpNs::I2S(ns, op) => {
171 let coll = colls.i2s(ns);
172 if !apply_both(&mut tx, &mut model.i2s, coll, ns, op) {
173 ok = false;
174 }
175 }
176 TestOpNs::Rollback => {
177 //println!("ROLLBACK");
178 model = Model::default();
179 tx.rollback().unwrap();
180 tx = sut.write();
181 }
182 }
183 }
184 tx.rollback().unwrap();
185 ok
186}
187
188/// Check that two write transactions don't see each others' changes.
189///

Callers 2

writableFunction · 0.85

Calls 5

apply_bothFunction · 0.85
s2iMethod · 0.80
i2sMethod · 0.80
writeMethod · 0.45
rollbackMethod · 0.45

Tested by

no test coverage detected