github.com/braveheart12/just@v0.8.7/ledger/storage/storagetest/records.go (about) 1 /* 2 * Copyright 2019 Insolar Technologies 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package storagetest 18 19 import ( 20 "context" 21 22 "github.com/insolar/insolar/ledger/storage/jet" 23 "github.com/insolar/insolar/ledger/storage/record" 24 25 "github.com/insolar/insolar/core" 26 "github.com/insolar/insolar/ledger/storage" 27 "github.com/insolar/insolar/ledger/storage/index" 28 "github.com/insolar/insolar/testutils" 29 ) 30 31 // AddRandIndex adds random index. 32 func AddRandIndex( 33 ctx context.Context, 34 // t *testing.T, 35 objectStorage storage.ObjectStorage, 36 jetID core.RecordID, 37 pulsenum core.PulseNumber, 38 ) (*core.RecordID, error) { 39 parentID := testutils.RandomID() 40 err := objectStorage.SetObjectIndex(ctx, jetID, &parentID, &index.ObjectLifeline{ 41 LatestState: &parentID, 42 }) 43 return &parentID, err 44 } 45 46 // AddRandBlob adds random blob. 47 func AddRandBlob( 48 ctx context.Context, 49 objectStorage storage.ObjectStorage, 50 jetID core.RecordID, 51 pulsenum core.PulseNumber, 52 ) (*core.RecordID, error) { 53 randID := testutils.RandomID() 54 return objectStorage.SetBlob(ctx, jetID, pulsenum, randID[:]) 55 } 56 57 // AddRandRecord adds random record. 58 func AddRandRecord( 59 ctx context.Context, 60 objectStorage storage.ObjectStorage, 61 jetID core.RecordID, 62 pulsenum core.PulseNumber, 63 ) (*core.RecordID, error) { 64 65 randID := testutils.RandomID() 66 record := record.CodeRecord{ 67 Code: &randID, 68 } 69 return objectStorage.SetRecord( 70 ctx, 71 jetID, 72 pulsenum, 73 &record, 74 ) 75 } 76 77 // AddRandDrop adds random drop. 78 func AddRandDrop( 79 ctx context.Context, 80 dropStorage storage.DropStorage, 81 jetID core.RecordID, 82 pulsenum core.PulseNumber, 83 ) (*jet.JetDrop, error) { 84 85 hash1 := testutils.RandomID() 86 hash2 := testutils.RandomID() 87 drop := jet.JetDrop{ 88 Pulse: pulsenum, 89 PrevHash: hash1[:], 90 Hash: hash2[:], 91 } 92 err := dropStorage.SetDrop(ctx, jetID, &drop) 93 if err != nil { 94 return nil, err 95 } 96 return dropStorage.GetDrop(ctx, jetID, pulsenum) 97 }