How to use addInput method of state Package

Best Syzkaller code snippet using state.addInput

pocket_test.go

Source:pocket_test.go Github

copy

Full Screen

...29}30func TestClient_Add(t *testing.T) {31 type args struct {32 ctx context.Context33 addInput AddInput34 }35 testCases := []struct {36 name string37 input args38 expectedStatusCode int39 expectedResponseBody string40 expectedErrorMessage string41 wantErr bool42 }{43 {44 name: "OK_AllFields",45 input: args{46 ctx: context.Background(),47 addInput: AddInput{48 AccessToken: "access-token",49 URL: "https://github.com",50 Title: "title",51 Tags: []string{"github"},52 TweetID: "1",53 },54 },55 expectedStatusCode: 200,56 expectedResponseBody: `{"status":1}`,57 wantErr: false,58 },59 {60 name: "OK_WithoutTweetID",61 input: args{62 ctx: context.Background(),63 addInput: AddInput{64 AccessToken: "access-token",65 URL: "https://github.com",66 Title: "title",67 Tags: []string{"github"},68 },69 },70 expectedStatusCode: 200,71 expectedResponseBody: `{"status":1}`,72 wantErr: false,73 },74 {75 name: "OK_WithoutTagsAndTweetID",76 input: args{77 ctx: context.Background(),78 addInput: AddInput{79 AccessToken: "access-token",80 URL: "https://github.com",81 Title: "title",82 },83 },84 expectedStatusCode: 200,85 expectedResponseBody: `{"status":1}`,86 wantErr: false,87 },88 {89 name: "OK_WithoutTitleAndTagsAndTweetID",90 input: args{91 ctx: context.Background(),92 addInput: AddInput{93 AccessToken: "access-token",94 URL: "https://github.com",95 },96 },97 expectedStatusCode: 200,98 expectedResponseBody: `{"status":1}`,99 wantErr: false,100 },101 {102 name: "Empty access token",103 input: args{104 ctx: context.Background(),105 addInput: AddInput{106 AccessToken: "",107 URL: "https://github.com",108 },109 },110 expectedResponseBody: `{"status":0}`,111 expectedErrorMessage: ErrEmptyAccessToken.Error(),112 wantErr: true,113 },114 {115 name: "Empty URL",116 input: args{117 ctx: context.Background(),118 addInput: AddInput{119 AccessToken: "access-token",120 URL: "",121 },122 },123 expectedStatusCode: 400,124 expectedResponseBody: `{"status":0}`,125 expectedErrorMessage: ErrEmptyItemURL.Error(),126 wantErr: true,127 },128 {129 name: "Non-2XX response",130 input: args{131 ctx: context.Background(),132 addInput: AddInput{133 AccessToken: "access-token",134 URL: "https://github.com",135 Title: "title",136 Tags: []string{"github"},137 TweetID: "1",138 },139 },140 expectedStatusCode: 400,141 expectedResponseBody: `{"status":0}`,142 expectedErrorMessage: "API error : ",143 wantErr: true,144 },145 }146 for _, tc := range testCases {147 t.Run(tc.name, func(t *testing.T) {148 client := newClient(t, tc.expectedStatusCode, "/v3/add", tc.expectedResponseBody)149 err := client.Add(tc.input.ctx, tc.input.addInput)150 if tc.wantErr {151 assert.Error(t, err)152 assert.Equal(t, tc.expectedErrorMessage, err.Error())153 } else {154 assert.NoError(t, err)155 }156 })157 }158}159func TestClient_Modify(t *testing.T) {160 type args struct {161 ctx context.Context162 modifyInput ModifyInput163 }...

Full Screen

Full Screen

transactions.go

Source:transactions.go Github

copy

Full Screen

1// Copyright 2015 Factom Foundation2// Use of this source code is governed by the MIT3// license that can be found in the LICENSE file.4package main5import (6 "encoding/hex"7 "fmt"8 fct "github.com/FactomProject/factoid"9 "github.com/FactomProject/factoid/wallet"10 "strconv"11)12/************************************************************13 * NewTransaction14 ************************************************************/15type NewTransaction struct {16 ICommand17}18// New Transaction: key --19// We create a new transaction, and track it with the user supplied key. The20// user can then use this key to make subsequent calls to add inputs, outputs,21// and to sign. Then they can submit the transaction.22//23// When the transaction is submitted, we clear it from our working memory.24// Multiple transactions can be under construction at one time, but they need25// their own keys. Once a transaction is either submitted or deleted, the key26// can be reused.27func (NewTransaction) Execute(state IState, args []string) error {28 if len(args) != 2 {29 return fmt.Errorf("Invalid Parameters")30 }31 key := args[1]32 // Make sure we don't already have a transaction in process with this key33 t := state.GetFS().GetDB().GetRaw([]byte(fct.DB_BUILD_TRANS), []byte(key))34 if t != nil {35 return fmt.Errorf("Duplicate key: '%s'", key)36 }37 // Create a transaction38 t = state.GetFS().GetWallet().CreateTransaction(state.GetFS().GetTimeMilli())39 // Save it with the key40 state.GetFS().GetDB().PutRaw([]byte(fct.DB_BUILD_TRANS), []byte(key), t)41 fmt.Println("Beginning Transaction ", key)42 return nil43}44func (NewTransaction) Name() string {45 return "NewTransaction"46}47func (NewTransaction) ShortHelp() string {48 return "NewTransaction <key> -- Begins the construction of a transaction.\n" +49 " Subsequent modifications must reference the key."50}51func (NewTransaction) LongHelp() string {52 return `53NewTransaction <key> Begins the construction of a transaction.54 The <key> is any token without whitespace up to55 32 characters in length that can be used in 56 AddInput, AddOutput, AddECOutput, Sign, and57 Submit commands to construct and submit 58 transactions.59`60}61/************************************************************62 * AddInput63 ************************************************************/64type AddInput struct {65 ICommand66}67// AddInput <key> <name|address> amount68//69//70func (AddInput) Execute(state IState, args []string) error {71 if len(args) != 4 {72 return fmt.Errorf("Invalid Parameters")73 }74 key := args[1]75 adr := args[2]76 amt := args[3]77 ib := state.GetFS().GetDB().GetRaw([]byte(fct.DB_BUILD_TRANS), []byte(key))78 trans, ok := ib.(fct.ITransaction)79 if ib == nil || !ok {80 return fmt.Errorf("Unknown Transaction: " + key)81 }82 var addr fct.IAddress83 if !fct.ValidateFUserStr(adr) {84 if len(adr) != 64 {85 if len(adr) > 32 {86 return fmt.Errorf("Invalid Name. Check the address or name for proper entry.", len(adr))87 }88 we := state.GetFS().GetDB().GetRaw([]byte(fct.W_NAME), []byte(adr))89 if we != nil {90 we2 := we.(wallet.IWalletEntry)91 addr, _ = we2.GetAddress()92 adr = hex.EncodeToString(addr.Bytes())93 } else {94 return fmt.Errorf("Name is undefined.")95 }96 } else {97 badr, err := hex.DecodeString(adr)98 if err != nil {99 return fmt.Errorf("Looks like an Invalid hex address. Check that you entered it correctly")100 }101 addr = fct.NewAddress(badr)102 }103 } else {104 fmt.Printf("adr: %x\n", adr)105 addr = fct.NewAddress(fct.ConvertUserStrToAddress(adr))106 }107 amount, _ := fct.ConvertFixedPoint(amt)108 bamount, _ := strconv.ParseInt(amount, 10, 64)109 err := state.GetFS().GetWallet().AddInput(trans, addr, uint64(bamount))110 if err != nil {111 return err112 }113 fmt.Println("Added Input of ", amt, " to be paid from ", args[2],114 fct.ConvertFctAddressToUserStr(addr))115 return nil116}117func (AddInput) Name() string {118 return "AddInput"119}120func (AddInput) ShortHelp() string {121 return "AddInput <key> <name/address> <amount> -- Adds an input to a transaction.\n" +122 " the key should be created by NewTransaction, and\n" +123 " and the address and amount should come from your\n" +124 " wallet."125}126func (AddInput) LongHelp() string {127 return `128AddInput <key> <name|addr> <amt> <key> created by a previous NewTransaction call129 <name|addr> A Valid Name in your Factoid Address 130 book, or a valid Factoid Address131 <amt> to be sent from the specified address to the132 outputs of this transaction.133`134}135/************************************************************136 * AddOutput137 ************************************************************/138type AddOutput struct {139 ICommand140}141// AddOutput <key> <name|address> amount142//143//144func (AddOutput) Execute(state IState, args []string) error {145 if len(args) != 4 {146 return fmt.Errorf("Invalid Parameters")147 }148 key := args[1]149 adr := args[2]150 amt := args[3]151 ib := state.GetFS().GetDB().GetRaw([]byte(fct.DB_BUILD_TRANS), []byte(key))152 trans, ok := ib.(fct.ITransaction)153 if ib == nil || !ok {154 return fmt.Errorf("Unknown Transaction")155 }156 var addr fct.IAddress157 if !fct.ValidateFUserStr(adr) {158 if len(adr) != 64 {159 if len(adr) > 32 {160 return fmt.Errorf("Invalid Address or Name. Check that you entered it correctly.")161 }162 we := state.GetFS().GetDB().GetRaw([]byte(fct.W_NAME), []byte(adr))163 if we != nil {164 we2 := we.(wallet.IWalletEntry)165 addr, _ = we2.GetAddress()166 adr = hex.EncodeToString(addr.Bytes())167 } else {168 return fmt.Errorf("Name is undefined.")169 }170 } else {171 if badHexChar.FindStringIndex(adr) != nil {172 return fmt.Errorf("Looks like an invalid Hex Address. Check that you entered it correctly.")173 }174 }175 } else {176 addr = fct.NewAddress(fct.ConvertUserStrToAddress(adr))177 }178 amount, _ := fct.ConvertFixedPoint(amt)179 bamount, _ := strconv.ParseInt(amount, 10, 64)180 err := state.GetFS().GetWallet().AddOutput(trans, addr, uint64(bamount))181 if err != nil {182 return err183 }184 fmt.Println("Added Output of ", amt, " to be paid to ", args[2],185 fct.ConvertFctAddressToUserStr(addr))186 return nil187}188func (AddOutput) Name() string {189 return "AddOutput"190}191func (AddOutput) ShortHelp() string {192 return "AddOutput <k> <n> <amount> -- Adds an output to a transaction.\n" +193 " the key <k> should be created by NewTransaction.\n" +194 " The address or name <n> can come from your address\n" +195 " book."196}197func (AddOutput) LongHelp() string {198 return `199AddOutput <key> <n|a> <amt> <key> created by a previous NewTransaction call200 <n|a> A Valid Name in your Factoid Address 201 book, or a valid Factoid Address 202 <amt> to be used to purchase Entry Credits at the203 current exchange rate.204`205}206/************************************************************207 * AddECOutput208 ************************************************************/209type AddECOutput struct {210 ICommand211}212// AddECOutput <key> <name|address> amount213//214// Buy Entry Credits215func (AddECOutput) Execute(state IState, args []string) error {216 if len(args) != 4 {217 return fmt.Errorf("Invalid Parameters")218 }219 key := args[1]220 adr := args[2]221 amt := args[3]222 ib := state.GetFS().GetDB().GetRaw([]byte(fct.DB_BUILD_TRANS), []byte(key))223 trans, ok := ib.(fct.ITransaction)224 if ib == nil || !ok {225 return fmt.Errorf("Unknown Transaction")226 }227 var addr fct.IAddress228 if !fct.ValidateECUserStr(adr) {229 if len(adr) != 64 {230 if len(adr) > 32 {231 return fmt.Errorf("Invalid Address or Name. Check that you entered it correctly.")232 }233 we := state.GetFS().GetDB().GetRaw([]byte(fct.W_NAME), []byte(adr))234 if we != nil {235 we2 := we.(wallet.IWalletEntry)236 addr, _ = we2.GetAddress()237 adr = hex.EncodeToString(addr.Bytes())238 } else {239 return fmt.Errorf("Name is undefined.")240 }241 } else {242 if badHexChar.FindStringIndex(adr) != nil {243 return fmt.Errorf("Looks like an invalid hex address. Check that you entered it correctly.")244 }245 }246 } else {247 addr = fct.NewAddress(fct.ConvertUserStrToAddress(adr))248 }249 amount, _ := fct.ConvertFixedPoint(amt)250 bamount, _ := strconv.ParseInt(amount, 10, 64)251 err := state.GetFS().GetWallet().AddECOutput(trans, addr, uint64(bamount))252 if err != nil {253 return err254 }255 fmt.Println("Added Output of ", amt, " to be paid to ", args[2],256 fct.ConvertECAddressToUserStr(addr))257 return nil258}259func (AddECOutput) Name() string {260 return "AddECOutput"261}262func (AddECOutput) ShortHelp() string {263 return "AddECOutput <k> <n> <amount> -- Adds an Entry Credit output (ecoutput)to a \n" +264 " transaction <k>. The Entry Credits are assigned to\n" +265 " the address <n>. The output <amount> is specified in\n" +266 " factoids, and purchases Entry Credits according to\n" +267 " the current exchange rage."268}269func (AddECOutput) LongHelp() string {270 return `271AddECOutput <key> <n|a> <amt> <key> created by a previous NewTransaction call272 <n|a> Name or Address to hold the Entry Credits273 <amt> Amount of Factoids to be used in this purchase. Note274 that the exchange rate between Factoids and Entry275 Credits varies.276`277}...

Full Screen

Full Screen

filterables_test.go

Source:filterables_test.go Github

copy

Full Screen

1package filter2import (3 "sort"4 "testing"5 "time"6 "github.com/metrumresearchgroup/gogridengine"7 "github.com/stretchr/testify/assert"8)9func TestJobOwner(t *testing.T) {10 jo := JobOwner{}11 jo.AddInput("johnd", "janed")12 assert.NotEmpty(t, jo.Inputs)13 assert.Len(t, jo.Inputs, 2)14 jo.Build() //Verify build is creating the filters15 assert.NotEmpty(t, jo.Actions)16 assert.Len(t, jo.Actions, 2)17 //Nullify to test filtering18 jo.Actions = nil19 jl := gogridengine.JobList{20 {21 JBJobNumber: 1,22 JobOwner: "johnd",23 },24 {25 JBJobNumber: 2,26 JobOwner: "johnd",27 },28 {29 JBJobNumber: 3,30 JobOwner: "jilld",31 },32 {33 JBJobNumber: 4,34 JobOwner: "janed",35 },36 {37 JBJobNumber: 5,38 JobOwner: "joed",39 },40 {41 JBJobNumber: 6,42 JobOwner: "janed",43 },44 }45 jl = jo.Filter(jl)46 sort.Slice(jl, func(i, j int) bool {47 return jl[i].JBJobNumber < jl[j].JBJobNumber48 })49 assert.NotEmpty(t, jl)50 assert.Len(t, jl, 4)51 //1,2,4,652 assert.Equal(t, int64(1), jl[0].JBJobNumber)53 assert.Equal(t, int64(2), jl[1].JBJobNumber)54 assert.Equal(t, int64(4), jl[2].JBJobNumber)55 assert.Equal(t, int64(6), jl[3].JBJobNumber)56}57func TestJobState(t *testing.T) {58 js := JobState{}59 js.AddInput("e", "h", "w")60 assert.NotEmpty(t, js.Inputs)61 assert.Len(t, js.Inputs, 3)62 js.Build()63 assert.NotEmpty(t, js.Actions)64 assert.Len(t, js.Actions, 3)65 js.Actions = nil66 jl := gogridengine.JobList{67 {68 JBJobNumber: 1,69 JobOwner: "johnd",70 State: "r",71 },72 {73 JBJobNumber: 2,74 JobOwner: "johnd",75 State: "r",76 },77 {78 JBJobNumber: 3,79 JobOwner: "jilld",80 State: "eh",81 },82 {83 JBJobNumber: 4,84 JobOwner: "janed",85 State: "h",86 },87 {88 JBJobNumber: 5,89 JobOwner: "joed",90 State: "qw",91 },92 {93 JBJobNumber: 6,94 JobOwner: "janed",95 State: "h",96 },97 }98 jl = js.Filter(jl)99 //Forgot that sorts are handled by the top level Filter function to avoid sorting over and over again100 sort.Slice(jl, func(i, j int) bool {101 return jl[i].JBJobNumber < jl[j].JBJobNumber102 })103 //3,4,5,6104 assert.NotEmpty(t, jl)105 assert.Len(t, jl, 4)106 assert.Equal(t, int64(3), jl[0].JBJobNumber)107 assert.Equal(t, int64(4), jl[1].JBJobNumber)108 assert.Equal(t, int64(5), jl[2].JBJobNumber)109 assert.Equal(t, int64(6), jl[3].JBJobNumber)110}111func TestStartingJobNumber(t *testing.T) {112 sjn := StartingJobNumber{}113 err := sjn.AddInput("14")114 assert.Nil(t, err)115 assert.NotEmpty(t, sjn.Input)116 assert.Equal(t, int64(14), sjn.Input)117 err = sjn.AddInput("14", "15")118 assert.Error(t, err)119 err = sjn.AddInput("i'mnotanumber")120 assert.Error(t, err)121 err = sjn.AddInput()122 assert.Error(t, err)123 sjn.Input = int64(14)124 sjn.Build()125 assert.NotEmpty(t, sjn.Actions)126 assert.Len(t, sjn.Actions, 1)127 sjn.Actions = nil128 jl := gogridengine.JobList{129 {130 JBJobNumber: 11,131 JobOwner: "johnd",132 State: "r",133 },134 {135 JBJobNumber: 12,136 JobOwner: "johnd",137 State: "r",138 },139 {140 JBJobNumber: 13,141 JobOwner: "jilld",142 State: "eh",143 },144 {145 JBJobNumber: 14,146 JobOwner: "janed",147 State: "h",148 },149 {150 JBJobNumber: 15,151 JobOwner: "joed",152 State: "qw",153 },154 {155 JBJobNumber: 16,156 JobOwner: "janed",157 State: "h",158 },159 }160 jl = sjn.Filter(jl)161 sort.Slice(jl, func(i, j int) bool {162 return jl[i].JBJobNumber < jl[j].JBJobNumber163 })164 assert.NotEmpty(t, jl)165 assert.Len(t, jl, 3)166 for i := 0; i < len(jl); i++ {167 assert.Equal(t, int64(sjn.Input+int64(i)), jl[i].JBJobNumber)168 }169}170func TestBeforeSubmissionTime(t *testing.T) {171 startTimeString := "2019-01-14T11:34:15"172 parsed, _ := time.Parse(RFC8601, startTimeString)173 bst := BeforeSubmissionTime{}174 err := bst.AddInput(startTimeString)175 assert.Nil(t, err)176 assert.Equal(t, parsed, bst.Input)177 err = bst.AddInput(startTimeString, time.Now().String())178 assert.Error(t, err)179 bst.Input = parsed180 bst.Build()181 assert.NotEmpty(t, bst.Actions)182 assert.Len(t, bst.Actions, 1)183 bst.Actions = nil184 jl := gogridengine.JobList{185 {186 JBJobNumber: 11,187 JobOwner: "johnd",188 State: "r",189 SubmittedTime: "2019-01-13T11:21:15",190 },191 {192 JBJobNumber: 12,193 JobOwner: "johnd",194 State: "r",195 SubmittedTime: "2019-01-14T11:21:15",196 },197 {198 JBJobNumber: 13,199 JobOwner: "jilld",200 State: "eh",201 SubmittedTime: "2019-01-14T11:21:17",202 },203 {204 JBJobNumber: 14,205 JobOwner: "janed",206 State: "h",207 SubmittedTime: "2019-01-14T11:34:15",208 },209 {210 JBJobNumber: 15,211 JobOwner: "joed",212 State: "qw",213 SubmittedTime: "2019-01-15T08:34:15",214 },215 {216 JBJobNumber: 16,217 JobOwner: "janed",218 State: "h",219 SubmittedTime: "2019-01-15T23:34:15",220 },221 {222 JBJobNumber: 17,223 JobOwner: "janed",224 State: "h",225 SubmittedTime: "notavalidtime",226 },227 }228 jl = bst.Filter(jl)229 sort.Slice(jl, func(i, j int) bool {230 return jl[i].JBJobNumber < jl[j].JBJobNumber231 })232 assert.NotEmpty(t, jl)233 assert.Len(t, jl, 3)234 for i := 0; i < len(jl); i++ {235 assert.Equal(t, int64(11+i), jl[i].JBJobNumber)236 }237}238func TestAfterSubmissionTime(t *testing.T) {239 ast := AfterSubmissionTime{}240 startTimeString := "2019-01-14T11:34:15"241 parsed, _ := time.Parse(RFC8601, startTimeString)242 err := ast.AddInput(startTimeString)243 assert.Nil(t, err)244 assert.Equal(t, parsed, ast.Input)245 err = ast.AddInput(startTimeString, time.Now().String())246 assert.Error(t, err)247 ast.Input = parsed248 ast.Build()249 assert.NotEmpty(t, ast.Actions)250 assert.Len(t, ast.Actions, 1)251 ast.Actions = nil252 jl := gogridengine.JobList{253 {254 JBJobNumber: 11,255 JobOwner: "johnd",256 State: "r",257 SubmittedTime: "2019-01-13T11:21:15",258 },259 {260 JBJobNumber: 12,261 JobOwner: "johnd",262 State: "r",263 SubmittedTime: "2019-01-14T11:21:15",264 },265 {266 JBJobNumber: 13,267 JobOwner: "jilld",268 State: "eh",269 SubmittedTime: "2019-01-14T11:21:17",270 },271 {272 JBJobNumber: 14,273 JobOwner: "janed",274 State: "h",275 SubmittedTime: "2019-01-14T11:34:15",276 },277 {278 JBJobNumber: 15,279 JobOwner: "joed",280 State: "qw",281 SubmittedTime: "2019-01-15T08:34:15",282 },283 {284 JBJobNumber: 16,285 JobOwner: "janed",286 State: "h",287 SubmittedTime: "2019-01-15T23:34:15",288 },289 {290 JBJobNumber: 17,291 JobOwner: "janed",292 State: "h",293 SubmittedTime: "notavalidtime",294 },295 }296 jl = ast.Filter(jl)297 sort.Slice(jl, func(i, j int) bool {298 return jl[i].JBJobNumber < jl[j].JBJobNumber299 })300 assert.NotEmpty(t, jl)301 assert.Len(t, jl, 2)302 for i := 0; i < len(jl); i++ {303 assert.Equal(t, int64(15+i), jl[i].JBJobNumber)304 }305}306func TestBeforeStartTime(t *testing.T) {307 startTimeString := "2019-01-14T11:34:15"308 parsed, _ := time.Parse(RFC8601, startTimeString)309 bst := BeforeStartTime{}310 err := bst.AddInput(startTimeString)311 assert.Nil(t, err)312 assert.Equal(t, parsed, bst.Input)313 err = bst.AddInput(startTimeString, time.Now().String())314 assert.Error(t, err)315 bst.Input = parsed316 bst.Build()317 assert.NotEmpty(t, bst.Actions)318 assert.Len(t, bst.Actions, 1)319 bst.Actions = nil320 jl := gogridengine.JobList{321 {322 JBJobNumber: 11,323 JobOwner: "johnd",324 State: "r",325 StartTime: "2019-01-13T11:21:15",326 },327 {328 JBJobNumber: 12,329 JobOwner: "johnd",330 State: "r",331 StartTime: "2019-01-14T11:21:15",332 },333 {334 JBJobNumber: 13,335 JobOwner: "jilld",336 State: "eh",337 StartTime: "2019-01-14T11:21:17",338 },339 {340 JBJobNumber: 14,341 JobOwner: "janed",342 State: "h",343 StartTime: "2019-01-14T11:34:15",344 },345 {346 JBJobNumber: 15,347 JobOwner: "joed",348 State: "qw",349 StartTime: "2019-01-15T08:34:15",350 },351 {352 JBJobNumber: 16,353 JobOwner: "janed",354 State: "h",355 StartTime: "2019-01-15T23:34:15",356 },357 {358 JBJobNumber: 17,359 JobOwner: "janed",360 State: "h",361 SubmittedTime: "notavalidtime",362 },363 }364 jl = bst.Filter(jl)365 sort.Slice(jl, func(i, j int) bool {366 return jl[i].JBJobNumber < jl[j].JBJobNumber367 })368 assert.NotEmpty(t, jl)369 assert.Len(t, jl, 3)370 for i := 0; i < len(jl); i++ {371 assert.Equal(t, int64(11+i), jl[i].JBJobNumber)372 }373}374func TestAfterStartTime(t *testing.T) {375 startTimeString := "2019-01-14T11:34:15"376 parsed, _ := time.Parse(RFC8601, startTimeString)377 ast := AfterStartTime{}378 err := ast.AddInput(startTimeString)379 assert.Nil(t, err)380 assert.Equal(t, parsed, ast.Input)381 err = ast.AddInput(startTimeString, time.Now().String())382 assert.Error(t, err)383 err = ast.AddInput()384 assert.Error(t, err)385 err = ast.AddInput("i'mnotatime")386 assert.Error(t, err)387 ast.Input = parsed388 ast.Build()389 assert.NotEmpty(t, ast.Actions)390 assert.Len(t, ast.Actions, 1)391 ast.Actions = nil392 jl := gogridengine.JobList{393 {394 JBJobNumber: 11,395 JobOwner: "johnd",396 State: "r",397 StartTime: "2019-01-13T11:21:15",398 },399 {400 JBJobNumber: 12,401 JobOwner: "johnd",402 State: "r",403 StartTime: "2019-01-14T11:21:15",404 },405 {406 JBJobNumber: 13,407 JobOwner: "jilld",408 State: "eh",409 StartTime: "2019-01-14T11:21:17",410 },411 {412 JBJobNumber: 14,413 JobOwner: "janed",414 State: "h",415 StartTime: "2019-01-14T11:34:15",416 },417 {418 JBJobNumber: 15,419 JobOwner: "joed",420 State: "qw",421 StartTime: "2019-01-15T08:34:15",422 },423 {424 JBJobNumber: 16,425 JobOwner: "janed",426 State: "h",427 StartTime: "2019-01-15T23:34:15",428 },429 {430 JBJobNumber: 17,431 JobOwner: "janed",432 State: "h",433 SubmittedTime: "notavalidtime",434 },435 }436 jl = ast.Filter(jl)437 sort.Slice(jl, func(i, j int) bool {438 return jl[i].JBJobNumber < jl[j].JBJobNumber439 })440 assert.NotEmpty(t, jl)441 assert.Len(t, jl, 2)442 for i := 0; i < len(jl); i++ {443 assert.Equal(t, int64(15+i), jl[i].JBJobNumber)444 }445}...

Full Screen

Full Screen

addInput

Using AI Code Generation

copy

Full Screen

1import (2type SimpleChaincode struct {3}4func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) peer.Response {5 fmt.Println("Init")6 return shim.Success(nil)7}8func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) peer.Response {9 fmt.Println("Invoke")10 function, args := stub.GetFunctionAndParameters()11 if function == "addInput" {12 return t.addInput(stub, args)13 } else if function == "getInput" {14 return t.getInput(stub, args)15 }16 return shim.Error("Invalid invoke function name. Expecting \"addInput\" \"getInput\"")17}18func (t *SimpleChaincode) addInput(stub shim.ChaincodeStubInterface, args []string) peer.Response {19 if len(args) != 1 {20 return shim.Error("Incorrect number of arguments. Expecting 1")21 }22 err := stub.PutState("input", []byte(args[0]))23 if err != nil {24 return shim.Error("Failed to add input")25 }26 return shim.Success(nil)27}28func (t *SimpleChaincode) getInput(stub shim.ChaincodeStubInterface, args []string) peer.Response {29 if len(args) != 0 {30 return shim.Error("Incorrect number of arguments. Expecting 0")31 }32 input, err := stub.GetState("input")33 if err != nil {34 return shim.Error("Failed to get input")35 }36 return shim.Success(input)37}38func main() {39 err := shim.Start(new(SimpleChaincode))40 if err != nil {41 fmt.Printf("Error starting Simple chaincode: %s", err)42 }43}44import (45type SimpleChaincode struct {46}47func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) peer.Response {48 fmt.Println("Init")49 return shim.Success(nil)50}51func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface

Full Screen

Full Screen

addInput

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 client, err := ethclient.Dial("/home/ethereum/go/src/github.com/ethereum/go-ethereum/build/bin/geth.ipc")4 if err != nil {5 log.Fatalf("Failed to connect to the Ethereum client: %v", err)6 }7 auth, err := bind.NewTransactor(strings.NewReader(keyJSON), "password")8 if err != nil {9 log.Fatalf("Failed to create authorized transactor: %v", err)10 }11 address := common.HexToAddress("0x5b4a

Full Screen

Full Screen

addInput

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 s := state{}4 s.addInput("1")5 s.addInput("2")6 s.addInput("3")7 s.addInput("4")8 s.addInput("5")9 fmt.Println(s)10}11import (12type state struct {13}14func (s *state) addInput(input string) {15 fmt.Println("Adding input to state")16 s.inputs = append(s.inputs, input)17}18import (19type state struct {20}21func (s *state) addInput(input string) {22 fmt.Println("Adding input to state")23 s.inputs = append(s.inputs, input)24}25import (26type state struct {27}28func (s *state) addInput(input string) {29 fmt.Println("Adding input to state")30 s.inputs = append(s.inputs, input)31}32import (33type state struct {34}35func (s *state) addInput(input string) {36 fmt.Println("Adding input to state")37 s.inputs = append(s.inputs, input)38}39import (40type state struct {41}42func (s *state) addInput(input string) {43 fmt.Println("Adding input to state")44 s.inputs = append(s.inputs, input)45}46import (47type state struct {48}49func (s *state) addInput(input string) {50 fmt.Println("Adding input to state")51 s.inputs = append(s.inputs, input)52}53import (54type state struct {55}56func (s *state) addInput

Full Screen

Full Screen

addInput

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 err := shim.Start(new(Chaincode1))4 if err != nil {5 fmt.Printf("Error starting chaincode: %s", err)6 }7}8import (9func main() {10 err := shim.Start(new(Chaincode1))11 if err != nil {12 fmt.Printf("Error starting chaincode: %s", err)13 }14}15import (16func main() {17 err := shim.Start(new(Chaincode1))18 if err != nil {19 fmt.Printf("Error starting chaincode: %s", err)20 }21}22import (23func main() {24 err := shim.Start(new(Chaincode1))25 if err != nil {26 fmt.Printf("Error starting chaincode: %s", err)27 }28}29import (30func main() {31 err := shim.Start(new(Chaincode1))32 if err != nil {33 fmt.Printf("Error starting chaincode: %s", err)34 }35}36import (37func main() {38 err := shim.Start(new(Chaincode1))39 if err != nil {40 fmt.Printf("Error starting chaincode: %s", err)41 }42}43import (

Full Screen

Full Screen

addInput

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 s.addInput("a")4 s.addInput("b")5 s.addInput("c")6 s.addInput("d")7 fmt.Println(s.inputs)8}9import (10func main() {11 s.addState("a")12 s.addState("b")13 s.addState("c")14 s.addState("d")15 fmt.Println(s.states)16}17import (18func main() {19 s.addOutput("a")20 s.addOutput("b")21 s.addOutput("c")22 s.addOutput("d")23 fmt.Println(s.outputs)24}25import (26func main() {27 s.addTransition("a")28 s.addTransition("b")29 s.addTransition("c")30 s.addTransition("d")31 fmt.Println(s.transitions)32}33import (34func main() {35 s.addNextState("a")36 s.addNextState("b")37 s.addNextState("c")38 s.addNextState("d")39 fmt.Println(s.nextStates)40}41import (42func main() {43 s.addOutput("a")44 s.addOutput("b")45 s.addOutput("c")46 s.addOutput("d")47 fmt.Println(s.outputs)48}49import (50func main() {51 s.addTransition("a")52 s.addTransition("b")53 s.addTransition("c")54 s.addTransition("d")55 fmt.Println(s.transitions)56}57import (58func main() {59 s.addNextState("a")60 s.addNextState("b")61 s.addNextState("

Full Screen

Full Screen

addInput

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 stub := shim.NewMockStub("ex02", new(SimpleChaincode))4 res := stub.MockInit("1", [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")})5 if res.Status != shim.OK {6 fmt.Println("Init failed", string(res.Message))7 }8 res = stub.MockInvoke("1", [][]byte{[]byte("addInput"), []byte("a"), []byte("100")})9 if res.Status != shim.OK {10 fmt.Println("Invoke failed", string(res.Message))11 }12}13import (14func main() {15 stub := shim.NewMockStub("ex02", new(SimpleChaincode))16 res := stub.MockInit("1", [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")})17 if res.Status != shim.OK {18 fmt.Println("Init failed", string(res.Message))19 }20 res = stub.MockInvoke("1", [][]byte{[]byte("addOutput"), []byte("b"), []byte("200")})21 if res.Status != shim.OK {22 fmt.Println("Invoke failed", string(res.Message))23 }24}25import (26func main() {27 stub := shim.NewMockStub("ex02", new(SimpleChaincode))28 res := stub.MockInit("1", [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")})29 if res.Status != shim.OK {30 fmt.Println("Init failed", string(res.Message))31 }32 res = stub.MockInvoke("1", [][]byte{[]byte("addInput"), []byte("a"), []byte("

Full Screen

Full Screen

addInput

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 s := state{}4 s.addInput("a")5 s.addInput("b")6 s.addInput("c")7 fmt.Println(s.input)8}9import (10func main() {11 s := state{}12 s.addInput("a")13 s.addInput("b")14 s.addInput("c")15 fmt.Println(s.input)16}17import (18func main() {19 s := state{}20 s.addInput("a")21 s.addInput("b")22 s.addInput("c")23 fmt.Println(s.input)24}25import (26func main() {27 s := state{}28 s.addInput("a")29 s.addInput("b")30 s.addInput("c")31 fmt.Println(s.input)32}33import (34func main() {35 s := state{}36 s.addInput("a")37 s.addInput("b")38 s.addInput("c")39 fmt.Println(s.input)40}41import (42func main() {43 s := state{}44 s.addInput("a")

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