github.com/algorand/go-algorand-sdk@v1.24.0/test/applications_unit_test.go (about) 1 package test 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/cucumber/godog" 8 9 "github.com/algorand/go-algorand-sdk/client/v2/algod" 10 "github.com/algorand/go-algorand-sdk/client/v2/indexer" 11 "github.com/algorand/go-algorand-sdk/encoding/msgpack" 12 ) 13 14 func feeFieldIsInTxn() error { 15 var txn map[string]interface{} 16 err := msgpack.Decode(stx, &txn) 17 if err != nil { 18 return fmt.Errorf("Error while decoding txn. %v", err) 19 } 20 if _, ok := txn["txn"].(map[interface{}]interface{})["fee"]; !ok { 21 return fmt.Errorf("fee field missing. %v", err) 22 } 23 return nil 24 } 25 26 func feeFieldNotInTxn() error { 27 var txn map[string]interface{} 28 err := msgpack.Decode(stx, &txn) 29 if err != nil { 30 return fmt.Errorf("Error while decoding txn. %v", err) 31 } 32 if _, ok := txn["txn"].(map[interface{}]interface{})["fee"]; ok { 33 return fmt.Errorf("fee field found but it should have been omitted. %v", err) 34 } 35 return nil 36 } 37 38 func weMakeAGetAssetByIDCall(assetID int) error { 39 clt, err := algod.MakeClient(mockServer.URL, "") 40 if err != nil { 41 return err 42 } 43 clt.GetAssetByID(uint64(assetID)).Do(context.Background()) 44 return nil 45 } 46 47 func weMakeAGetApplicationByIDCall(applicationID int) error { 48 clt, err := algod.MakeClient(mockServer.URL, "") 49 if err != nil { 50 return err 51 } 52 clt.GetApplicationByID(uint64(applicationID)).Do(context.Background()) 53 return nil 54 } 55 56 func weMakeASearchForApplicationsCall(applicationID int) error { 57 clt, err := indexer.MakeClient(mockServer.URL, "") 58 if err != nil { 59 return err 60 } 61 clt.SearchForApplications().ApplicationId(uint64(applicationID)).Do(context.Background()) 62 return nil 63 } 64 65 func weMakeALookupApplicationsCall(applicationID int) error { 66 clt, err := indexer.MakeClient(mockServer.URL, "") 67 if err != nil { 68 return err 69 } 70 clt.LookupApplicationByID(uint64(applicationID)).Do(context.Background()) 71 return nil 72 } 73 74 func ApplicationsUnitContext(s *godog.Suite) { 75 // @unit.transactions 76 s.Step(`^fee field is in txn$`, feeFieldIsInTxn) 77 s.Step(`^fee field not in txn$`, feeFieldNotInTxn) 78 79 //@unit.applications 80 s.Step(`^we make a GetAssetByID call for assetID (\d+)$`, weMakeAGetAssetByIDCall) 81 s.Step(`^we make a GetApplicationByID call for applicationID (\d+)$`, weMakeAGetApplicationByIDCall) 82 s.Step(`^we make a SearchForApplications call with applicationID (\d+)$`, weMakeASearchForApplicationsCall) 83 s.Step(`^we make a LookupApplications call with applicationID (\d+)$`, weMakeALookupApplicationsCall) 84 }