How to use purgeCorpus method of state Package

Best Syzkaller code snippet using state.purgeCorpus

state.go

Source:state.go Github

copy

Full Screen

...89 }90 Logf(0, "read %v programs", len(mgr.Corpus.Records))91 }92 Logf(0, "purging corpus...")93 st.purgeCorpus()94 Logf(0, "done, %v programs", len(st.Corpus.Records))95 return st, err96}97func (st *State) Connect(name string, fresh bool, calls []string, corpus [][]byte) error {98 mgr := st.Managers[name]99 if mgr == nil {100 mgr = new(Manager)101 st.Managers[name] = mgr102 mgr.dir = filepath.Join(st.dir, "manager", name)103 os.MkdirAll(mgr.dir, 0700)104 }105 mgr.Connected = time.Now()106 if fresh {107 mgr.seq = 0108 }109 writeFile(filepath.Join(mgr.dir, "seq"), []byte(fmt.Sprint(mgr.seq)))110 mgr.Calls = make(map[string]struct{})111 for _, c := range calls {112 mgr.Calls[c] = struct{}{}113 }114 corpusFile := filepath.Join(mgr.dir, "corpus.db")115 os.Remove(corpusFile)116 var err error117 mgr.Corpus, err = db.Open(corpusFile)118 if err != nil {119 Logf(0, "failed to open corpus database: %v", err)120 return err121 }122 st.addInputs(mgr, corpus)123 st.purgeCorpus()124 return nil125}126func (st *State) Sync(name string, add [][]byte, del []string) ([][]byte, error) {127 mgr := st.Managers[name]128 if mgr == nil || mgr.Connected.IsZero() {129 return nil, fmt.Errorf("unconnected manager %v", name)130 }131 if len(del) != 0 {132 for _, sig := range del {133 mgr.Corpus.Delete(sig)134 }135 if err := mgr.Corpus.Flush(); err != nil {136 Logf(0, "failed to flush corpus database: %v", err)137 }138 st.purgeCorpus()139 }140 st.addInputs(mgr, add)141 inputs, err := st.pendingInputs(mgr)142 mgr.Added += len(add)143 mgr.Deleted += len(del)144 mgr.New += len(inputs)145 return inputs, err146}147func (st *State) pendingInputs(mgr *Manager) ([][]byte, error) {148 if mgr.seq == st.seq {149 return nil, nil150 }151 var inputs [][]byte152 for key, rec := range st.Corpus.Records {153 if mgr.seq > rec.Seq {154 continue155 }156 if _, ok := mgr.Corpus.Records[key]; ok {157 continue158 }159 calls, err := prog.CallSet(rec.Val)160 if err != nil {161 return nil, fmt.Errorf("failed to extract call set: %v\nprogram: %s", err, rec.Val)162 }163 if !managerSupportsAllCalls(mgr.Calls, calls) {164 continue165 }166 inputs = append(inputs, rec.Val)167 }168 mgr.seq = st.seq169 writeFile(filepath.Join(mgr.dir, "seq"), []byte(fmt.Sprint(mgr.seq)))170 return inputs, nil171}172func (st *State) addInputs(mgr *Manager, inputs [][]byte) {173 if len(inputs) == 0 {174 return175 }176 st.seq++177 for _, input := range inputs {178 st.addInput(mgr, input)179 }180 if err := mgr.Corpus.Flush(); err != nil {181 Logf(0, "failed to flush corpus database: %v", err)182 }183 if err := st.Corpus.Flush(); err != nil {184 Logf(0, "failed to flush corpus database: %v", err)185 }186}187func (st *State) addInput(mgr *Manager, input []byte) {188 if _, err := prog.CallSet(input); err != nil {189 Logf(0, "manager %v: failed to extract call set: %v, program:\n%v", mgr.name, err, string(input))190 return191 }192 sig := hash.String(input)193 mgr.Corpus.Save(sig, nil, 0)194 if _, ok := st.Corpus.Records[sig]; !ok {195 st.Corpus.Save(sig, input, st.seq)196 }197}198func writeFile(name string, data []byte) {199 if err := ioutil.WriteFile(name, data, 0600); err != nil {200 Logf(0, "failed to write file %v: %v", name, err)201 }202}203func (st *State) purgeCorpus() {204 used := make(map[string]bool)205 for _, mgr := range st.Managers {206 for sig := range mgr.Corpus.Records {207 used[sig] = true208 }209 }210 for key := range st.Corpus.Records {211 if used[key] {212 continue213 }214 st.Corpus.Delete(key)215 }216 if err := st.Corpus.Flush(); err != nil {217 Logf(0, "failed to flush corpus database: %v", err)...

Full Screen

Full Screen

purgeCorpus

Using AI Code Generation

copy

Full Screen

1import (2func (s *SimpleChaincode) purgeCorpus(stub shim.ChaincodeStubInterface, args []string) peer.Response {3 if len(args) != 1 {4 return shim.Error("Incorrect number of arguments. Expecting 1")5 }6 corpusData, err = stub.GetState(corpusKey)7 if err != nil {8 return shim.Error("Failed to get state")9 }10 if corpusData == nil {11 return shim.Error("Corpus does not exist")12 }13 err = stub.DelState(corpusKey)14 if err != nil {15 return shim.Error("Failed to delete state")16 }17 return shim.Success(nil)18}19import (20func (s *SimpleChaincode) readCorpus(stub shim.ChaincodeStubInterface, args []string) peer.Response {21 if len(args) != 1 {22 return shim.Error("Incorrect number of arguments. Expecting 1")23 }24 corpusData, err = stub.GetState(corpusKey)25 if err != nil {26 return shim.Error("Failed to get state")27 }28 if corpusData == nil {29 return shim.Error("Corpus does not exist")30 }31 err = json.Unmarshal(corpusData, &corpus)32 if err != nil {33 return shim.Error(err.Error())34 }

Full Screen

Full Screen

purgeCorpus

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 trie := trie.New(common.Hash{})4 db, _ := ethdb.NewLDBDatabase("test", 0, 0)5 ts := sync.New(db, trie.Hash(), nil, nil)6 r := rand.New(rand.NewSource(time.Now().UnixNano()))7 for i := 0; i < 100; i++ {8 key := make([]byte, 32)9 r.Read(key)10 keys = append(keys, key)11 }12 for _, key := range keys {13 trie.Update(key, key)14 }15 trie.Commit(nil, false)16 trie = trie.New(trie.Hash())17 for i := 0; i < 10; i++ {18 trie.Delete(keys[i])19 }20 trie.Commit(nil, false)21 trie = trie.New(trie.Hash())22 for i := 0; i < 100; i++ {23 value := make([]byte, 32)24 r.Read(value)25 values = append(values, value)26 }27 for i, value := range values {28 trie.Update(keys[i], value)29 }30 trie.Commit(nil, false)31 trie = trie.New(trie.Hash())32 for i := 0; i < 100

Full Screen

Full Screen

purgeCorpus

Using AI Code Generation

copy

Full Screen

1func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) peer.Response {2    fmt.Println("ex02 Invoke")3    function, args := stub.GetFunctionAndParameters()4    if function == "purgeCorpus" {5        return t.purgeCorpus(stub, args)6    }7    return shim.Error("Invalid invoke function name. Expecting \"purgeCorpus\"")8}

Full Screen

Full Screen

purgeCorpus

Using AI Code Generation

copy

Full Screen

1func (t *SimpleChaincode) purgeCorpus(stub shim.ChaincodeStubInterface, args []string) peer.Response {2    if len(args) != 0 {3        return shim.Error("Incorrect number of arguments. Expecting 0")4    }5    resultsIterator, err := stub.GetStateByRange("", "")6    if err != nil {7        return shim.Error(err.Error())8    }9    defer resultsIterator.Close()10    for i = 0; resultsIterator.HasNext(); i++ {11        responseRange, err := resultsIterator.Next()12        if err != nil {13            return shim.Error(err.Error())14        }15        err = stub.DelState(responseRange.Key)16        if err != nil {17            return shim.Error("Failed to delete state")18        }19    }20    return shim.Success(nil)21}22func main() {

Full Screen

Full Screen

purgeCorpus

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 state := state.NewState()4 block := types.NewBlock()5 block2 := types.NewBlock()6 block3 := types.NewBlock()7 block4 := types.NewBlock()8 block5 := types.NewBlock()9 block6 := types.NewBlock()10 block7 := types.NewBlock()11 block8 := types.NewBlock()12 block9 := types.NewBlock()13 block10 := types.NewBlock()14 block11 := types.NewBlock()15 block12 := types.NewBlock()16 block13 := types.NewBlock()17 block14 := types.NewBlock()18 block15 := types.NewBlock()19 block16 := types.NewBlock()20 block17 := types.NewBlock()21 block18 := types.NewBlock()22 block19 := types.NewBlock()23 block20 := types.NewBlock()24 block21 := types.NewBlock()25 block22 := types.NewBlock()26 block23 := types.NewBlock()27 block24 := types.NewBlock()28 block25 := types.NewBlock()29 block26 := types.NewBlock()30 block27 := types.NewBlock()31 block28 := types.NewBlock()32 block29 := types.NewBlock()

Full Screen

Full Screen

purgeCorpus

Using AI Code Generation

copy

Full Screen

1func main() {2 s := state.NewState()3 s.PurgeCorpus()4}5func main() {6 s := state.NewState()7 s.PurgeCorpus()8}

Full Screen

Full Screen

purgeCorpus

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var state = State{}4 state.purgeCorpus()5}6import (7func main() {8 var state = State{}9 state.purgeCorpus()10}11import (12func main() {13 var state = State{}14 state.purgeCorpus()15}16import (17func main() {18 var state = State{}19 state.purgeCorpus()20}21import (22func main() {23 var state = State{}24 state.purgeCorpus()25}26import (27func main() {28 var state = State{}29 state.purgeCorpus()30}31import (32func main() {33 var state = State{}34 state.purgeCorpus()35}36import (37func main() {38 var state = State{}39 state.purgeCorpus()40}41import (42func main() {43 var state = State{}44 state.purgeCorpus()45}46import (47func main() {48 var state = State{}49 state.purgeCorpus()50}51import (52func main() {53 var state = State{}54 state.purgeCorpus()55}56import (57func main() {58 var state = State{}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful