fn plasma_client_create_then_seal()

in plasma-store/src/tests.rs [181:232]


fn plasma_client_create_then_seal() {
    let pc = build_client();
    let pc2 = build_client();

    // create an object of a given size
    let oid = ObjectId::rand();
    let data_size = 16;
    let meta = [1, 2, 3, 4];
    let mut ob = pc.create(oid.clone(), data_size, &meta).unwrap();

    assert_eq!(true, ob.is_mutable(), "object should be mutable");
    assert_eq!(meta, ob.meta(), "object metadata should match");
    assert_eq!(
        data_size,
        ob.data().len(),
        "object data buffer should be of correct length"
    );
    assert_eq!(
        false,
        pc2.contains(ob.id()).unwrap(),
        "client2: object should not be in the store"
    );

    // update data buffer and seal the object
    let data = [1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
    let data_buf = ob.data_mut();
    for i in 0..data_buf.len() {
        data_buf[i] = data[i];
    }
    ob.seal().unwrap();

    assert_eq!(false, ob.is_mutable(), "object should not be mutable");
    assert_eq!(data, ob.data(), "object data should match");
    assert_eq!(
        true,
        pc2.contains(ob.id()).unwrap(),
        "object should be in the store"
    );

    // trying to seal twice should result in an error
    assert!(ob.seal().is_err());

    // make sure the object can be retrieved correctly from another client
    let ob = pc2.get(oid, 5).unwrap().unwrap();
    assert_eq!(data, ob.data(), "client2: object data should match");
    assert_eq!(meta, ob.meta(), "client2: object metadata should match");
    assert_eq!(
        false,
        ob.is_mutable(),
        "client2: object should not be mutable"
    );
}