github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/cmd/srv-applet-mgr/tests/integrations/contract_log_test.go (about) 1 package integrations 2 3 import ( 4 "testing" 5 6 . "github.com/onsi/gomega" 7 8 "github.com/machinefi/w3bstream/cmd/srv-applet-mgr/tests/clients/applet_mgr" 9 "github.com/machinefi/w3bstream/cmd/srv-applet-mgr/tests/requires" 10 "github.com/machinefi/w3bstream/pkg/depends/kit/statusx" 11 "github.com/machinefi/w3bstream/pkg/errors/status" 12 "github.com/machinefi/w3bstream/pkg/modules/blockchain" 13 "github.com/machinefi/w3bstream/pkg/types" 14 ) 15 16 func TestContractLogAPIs(t *testing.T) { 17 var ( 18 ctx = requires.Context() 19 client = requires.AuthClient() 20 projectName = "test_project" 21 contractLogID types.SFID 22 baseReq = applet_mgr.CreateContractLog{} 23 ) 24 25 baseReq.ProjectName = projectName 26 baseReq.CreateContractLogReq.BlockStart = 20299310 27 baseReq.CreateContractLogReq.ChainID = 4690 28 baseReq.CreateContractLogReq.EventType = "DEFAULT" 29 baseReq.CreateContractLogReq.ContractAddress = "0x1AA325E5144f763a520867c56FC77cC1411430d0" 30 baseReq.CreateContractLogReq.Topic0 = "0x9ffdf0136249d99680088653555755221714868b4f7ca1ff7d8523e3bef1dc4a" 31 32 t.Logf("random a project name: %s", projectName) 33 34 t.Run("ContractLog", func(t *testing.T) { 35 t.Run("#CreateContractLog", func(t *testing.T) { 36 t.Run("#Success", func(t *testing.T) { 37 38 // create project without user defined config(database/env) 39 { 40 req := &applet_mgr.CreateProject{} 41 req.CreateReq.Name = projectName 42 43 rsp, _, err := client.CreateProject(req) 44 45 NewWithT(t).Expect(err).To(BeNil()) 46 NewWithT(t).Expect(rsp.Name).To(Equal(projectName)) 47 } 48 49 // init blockchain config 50 { 51 err := blockchain.InitChainDB(ctx) 52 NewWithT(t).Expect(err).To(BeNil()) 53 } 54 55 // create contract log monitor 56 { 57 req := baseReq 58 rsp, _, err := client.CreateContractLog(&req) 59 60 NewWithT(t).Expect(err).To(BeNil()) 61 contractLogID = rsp.ContractLogID 62 } 63 64 // check contract log is created 65 { 66 _, err := blockchain.GetContractLogBySFID(ctx, contractLogID) 67 NewWithT(t).Expect(err).To(BeNil()) 68 } 69 70 // remove contract log 71 { 72 req := &applet_mgr.RemoveContractLog{ 73 ProjectName: projectName, 74 ContractLogID: contractLogID, 75 } 76 _, err := client.RemoveContractLog(req) 77 NewWithT(t).Expect(err).To(BeNil()) 78 } 79 80 // check contract log is removed 81 { 82 _, err := blockchain.GetContractLogBySFID(ctx, contractLogID) 83 requires.CheckError(t, err, status.ContractLogNotFound) 84 } 85 86 // remove project 87 { 88 req := &applet_mgr.RemoveProject{ProjectName: projectName} 89 _, err := client.RemoveProject(req) 90 NewWithT(t).Expect(err).To(BeNil()) 91 } 92 }) 93 t.Run("#InvalidContractLogParam", func(t *testing.T) { 94 // contract address is empty 95 { 96 req := baseReq 97 req.CreateContractLogReq.ContractAddress = "" 98 99 _, _, err := client.CreateContractLog(&req) 100 requires.CheckError(t, err, &statusx.StatusErr{ 101 Key: "badRequest", 102 }) 103 } 104 105 // block start is empty 106 { 107 req := baseReq 108 req.CreateContractLogReq.BlockStart = 0 109 _, _, err := client.CreateContractLog(&req) 110 requires.CheckError(t, err, &statusx.StatusErr{ 111 Key: "badRequest", 112 }) 113 } 114 115 // chain id is empty 116 { 117 req := baseReq 118 req.CreateContractLogReq.ChainID = 0 119 _, _, err := client.CreateContractLog(&req) 120 requires.CheckError(t, err, &statusx.StatusErr{ 121 Key: "badRequest", 122 }) 123 } 124 }) 125 }) 126 }) 127 }