Best Testkube code snippet using client.baseExec
tx.go
Source:tx.go
1package walletapi2import (3 "encoding/hex"4 "github.com/33cn/chain33/common/address"5 "github.com/33cn/chain33/common/crypto"6 chainTypes "github.com/33cn/chain33/types"7 chainUtil "github.com/33cn/chain33/util"8 "github.com/gogo/protobuf/proto"9 "github.com/pkg/errors"10 "math/rand"11 "strings"12)13const (14 SECP256K1 = 115 minFeeRate = 10000016 noFeeRate = -117)18// Config19type Config struct {20 Chain Chain21 Encrypt Encrypt22}23type Chain struct {24 FeePrikey string25 FeeAddr string26 Title string27 BaseExec string `json:",default=none"`28}29type Encrypt struct {30 SignType int32 `json:",default=1"` // Invalid=0,SECP256K1=1,ED25519=2,SM2=331}32type TxInfo struct {33 Exec string34 Payload []byte35 FeeRate int6436 Prikey string37}38type ChainClient struct {39 cfg *Config40 FeePri crypto.PrivKey41}42func NewChainClient(c *Config) (*ChainClient, error) {43 if c == nil {44 return nil, errors.New("ChainClient: illegal ChainClient configure")45 }46 if c.Encrypt.SignType == 0 {47 c.Encrypt.SignType = SECP256K148 }49 c.Chain.BaseExec = c.Chain.Title + chainTypes.NoneX50 var pri crypto.PrivKey51 if c.Chain.FeePrikey != "" {52 pri = chainUtil.HexToPrivkey(c.Chain.FeePrikey)53 }54 return &ChainClient{cfg: c, FeePri: pri}, nil55}56// CreateTx57func (c *ChainClient) createTx(t *TxInfo) *chainTypes.Transaction {58 tx := &chainTypes.Transaction{59 Execer: []byte(t.Exec),60 Payload: t.Payload,61 Nonce: rand.Int63(),62 To: address.ExecAddress(t.Exec),63 }64 if t.FeeRate != noFeeRate {65 if t.FeeRate == 0 {66 t.FeeRate = minFeeRate67 }68 tx.SetRealFee(t.FeeRate)69 }70 return tx71}72func (c *ChainClient) createSignTx(prikey string, tx *chainTypes.Transaction) *chainTypes.Transaction {73 priv := chainUtil.HexToPrivkey(prikey)74 tx.Sign(c.cfg.Encrypt.SignType, priv)75 return tx76}77func (c *ChainClient) createBaseTx(exec string) *chainTypes.Transaction {78 tx := &chainTypes.Transaction{79 Execer: []byte(exec),80 Nonce: rand.Int63(),81 To: address.ExecAddress(exec),82 }83 return tx84}85func (c *ChainClient) createSignTxGroup(prikey string, tx2 *chainTypes.Transaction) (*chainTypes.Transaction, error) {86 var txs []*chainTypes.Transaction87 tx1 := c.createBaseTx(c.cfg.Chain.BaseExec)88 txs = append(txs, tx1, tx2)89 txGroup, err := chainTypes.CreateTxGroup(txs, minFeeRate)90 if err != nil {91 return nil, err92 }93 err = txGroup.SignN(0, c.cfg.Encrypt.SignType, c.FeePri)94 if err != nil {95 return nil, err96 }97 priv := chainUtil.HexToPrivkey(prikey)98 err = txGroup.SignN(1, c.cfg.Encrypt.SignType, priv)99 if err != nil {100 return nil, err101 }102 return txGroup.Tx(), nil103}104func (c *ChainClient) SignTransaction(txHex string, privKey string) (string, error) {105 txHex = strings.Replace(txHex, "0x", "", -1)106 txBuf, err := hex.DecodeString(txHex)107 if err != nil {108 return "", err109 }110 var tx chainTypes.Transaction111 err = proto.Unmarshal(txBuf, &tx)112 if err != nil {113 return "", err114 }115 txGroup := c.createSignTx(privKey, &tx)116 rltBuf, err := proto.Marshal(txGroup)117 if err != nil {118 return "", err119 }120 return hex.EncodeToString(rltBuf), nil121}122func (c *ChainClient) SignTransactionGroup(index int32, txHex string, privKey string) (string, error) {123 txHex = strings.Replace(txHex, "0x", "", -1)124 txBuf, err := hex.DecodeString(txHex)125 if err != nil {126 return "", err127 }128 var tx chainTypes.Transaction129 err = proto.Unmarshal(txBuf, &tx)130 if err != nil {131 return "", err132 }133 txs, err := tx.GetTxGroup()134 if err != nil {135 return "", err136 }137 priv := chainUtil.HexToPrivkey(privKey)138 if index == 0 {139 for i := range txs.Txs {140 err = txs.SignN(i, c.cfg.Encrypt.SignType, priv)141 if err != nil {142 return "", err143 }144 }145 } else {146 index--147 err = txs.SignN(int(index), c.cfg.Encrypt.SignType, priv)148 if err != nil {149 return "", err150 }151 }152 rltBuf, err := proto.Marshal(txs.Tx())153 if err != nil {154 return "", err155 }156 return hex.EncodeToString(rltBuf), nil157}158func (c *ChainClient) SignNoBalanceTransaction(txHex string, privKey string) (string, error) {159 txHex = strings.Replace(txHex, "0x", "", -1)160 txBuf, err := hex.DecodeString(txHex)161 if err != nil {162 return "", err163 }164 var tx chainTypes.Transaction165 err = proto.Unmarshal(txBuf, &tx)166 if err != nil {167 return "", err168 }169 txGroup, err := c.createSignTxGroup(privKey, &tx)170 if err != nil {171 return "", err172 }173 rltBuf, err := proto.Marshal(txGroup)174 if err != nil {175 return "", err176 }177 return hex.EncodeToString(rltBuf), nil178}...
docker_test.go
Source:docker_test.go
...26}27func TestDockerExec_invalidDocument(t *testing.T) {28 doc := &mockDocument{"", io.ErrClosedPipe, "b", nil}29 exec := &dockerExec{30 baseExec: baseExec{doc: doc},31 cli: nil, // not accessed32 }33 err := exec.Run(bg, zap.NewNop())34 require.EqualError(t, err, "invalid document: "+io.ErrClosedPipe.Error())35}36func TestDockerExec_latexmkFailed(t *testing.T) {37 mainFile := "index.tex"38 doc := &mockDocument{"/texd", nil, mainFile, nil}39 errStart := errors.New("command not found")40 cli := &dockerClientMock{}41 cli.On("Run", bg, "", "/texd", doc.Engine().LatexmkCmd(mainFile)).42 Return("outputlog", errStart)43 exec := &dockerExec{44 baseExec: baseExec{doc: doc},45 cli: cli,46 }47 err := exec.Run(bg, zap.NewNop())48 require.EqualError(t, err, "compilation failed: "+errStart.Error())49 assert.True(t, tex.IsCompilationError(err))50 catErr, ok := err.(*tex.ErrWithCategory)51 require.True(t, ok)52 kv := catErr.Extra()53 assert.EqualValues(t, kv["output"], "outputlog")54}55func TestDockerExec_success(t *testing.T) {56 mainFile := "index.tex"57 doc := &mockDocument{"/texd", nil, mainFile, nil}58 cli := &dockerClientMock{}59 cli.On("Run", bg, "", "/texd", doc.Engine().LatexmkCmd(mainFile)).60 Return("", nil)61 exec := &dockerExec{62 baseExec: baseExec{doc: doc},63 cli: cli,64 }65 err := exec.Run(bg, zap.NewNop())66 require.NoError(t, err)67}...
docker.go
Source:docker.go
...8 Run(ctx context.Context, tag, wd string, cmd []string) (string, error)9}10type dockerExec struct {11 cli dockerRunner12 baseExec13}14func (dc *DockerClient) Executor(doc Document) Exec {15 return &dockerExec{16 baseExec: baseExec{doc: doc},17 cli: dc,18 }19}20func (x *dockerExec) Run(ctx context.Context, log *zap.Logger) error {21 dir, cmd, err := x.extract()22 if err != nil {23 return tex.CompilationError("invalid document", err, nil)24 }25 tag := x.doc.Image()26 log.Debug("running latexmk", zap.Strings("args", cmd[1:]))27 output, err := x.cli.Run(ctx, tag, dir, cmd)28 if err != nil {29 log.Error("compilation failed", zap.Error(err))30 return tex.CompilationError("compilation failed", err, tex.KV{...
baseExec
Using AI Code Generation
1import (2func main() {3 if err != nil {4 log.Fatal(err)5 }6 ethClient := ethclient.NewClient(client)7 _, err = ethClient.BaseExec(common.HexT
baseExec
Using AI Code Generation
1func main() {2 client := client.NewClient()3 client.BaseExec("ls", "-l")4}5func main() {6 client := client.NewClient()7 client.Exec("ls", "-l")8}9func main() {10 client := client.NewClient()11 client.Exec("ls", "-l")12}13func main() {14 client := client.NewClient()15 client.Exec("ls", "-l")16}17func main() {18 client := client.NewClient()19 client.Exec("ls", "-l")20}21func main() {22 client := client.NewClient()23 client.Exec("ls", "-l")24}25func main() {26 client := client.NewClient()27 client.Exec("ls", "-l")28}29func main() {30 client := client.NewClient()31 client.Exec("ls", "-l")32}33func main() {34 client := client.NewClient()35 client.Exec("ls", "-l")36}37func main() {38 client := client.NewClient()39 client.Exec("ls", "-l")40}41func main() {42 client := client.NewClient()43 client.Exec("ls", "-l")44}45func main() {46 client := client.NewClient()47 client.Exec("ls", "-l")48}49func main() {50 client := client.NewClient()51 client.Exec("ls", "-l")52}53func main()
baseExec
Using AI Code Generation
1import (2func main() {3 p := process.Process{Pid: 1260}4 name, err := p.Name()5 if err != nil {6 log.Fatal(err)7 }8 status, err := p.Status()9 if err != nil {10 log.Fatal(err)11 }12 creationTime, err := p.CreateTime()13 if err != nil {14 log.Fatal(err)15 }16 cpuTimes, err := p.Times()17 if err != nil {18 log.Fatal(err)19 }20 memoryInfo, err := p.MemoryInfo()21 if err != nil {22 log.Fatal(err)23 }24 memoryPercent, err := p.MemoryPercent()25 if err != nil {26 log.Fatal(err)27 }28 cpuPercent, err := p.CPUPercent()29 if err != nil {30 log.Fatal(err)31 }32 cpuAffinity, err := p.CPUAffinity()33 if err != nil {34 log.Fatal(err)35 }36 numThreads, err := p.NumThreads()37 if err != nil {38 log.Fatal(err)39 }40 numOpenFiles, err := p.NumFDs()41 if err != nil {42 log.Fatal(err)43 }44 numOpenConnections, err := p.NumCtxSwitches()45 if err != nil {46 log.Fatal(err)47 }48 pageFaults, err := p.NumCtxSwitches()49 if err != nil {50 log.Fatal(err)51 }52 ioCounters, err := p.IOCounters()53 if err != nil {54 log.Fatal(err)55 }56 username, err := p.Username()57 if err != nil {58 log.Fatal(err)59 }
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!