How to use CreateTestSuite method of client Package

Best Testkube code snippet using client.CreateTestSuite

benchmark_tests.go

Source:benchmark_tests.go Github

copy

Full Screen

1package zcnsc2import (3 "log"4 "math/rand"5 "strconv"6 "testing"7 "0chain.net/chaincore/currency"8 "0chain.net/smartcontract"9 "0chain.net/smartcontract/stakepool"10 "0chain.net/smartcontract/stakepool/spenum"11 "github.com/spf13/viper"12 cstate "0chain.net/chaincore/chain/state"13 "0chain.net/chaincore/config"14 "0chain.net/chaincore/transaction"15 "0chain.net/core/common"16 "0chain.net/core/datastore"17 "0chain.net/core/encryption"18 "0chain.net/smartcontract/benchmark"19)20const (21 owner = "1746b06bb09f55ee01b33b5e2e055d6cc7a900cb57c0a3a5eaabb8a0e7745802"22)23type benchTest struct {24 name string25 endpoint func(26 *transaction.Transaction,27 []byte,28 cstate.StateContextI,29 ) (string, error)30 txn *transaction.Transaction31 input []byte32}33func (bt benchTest) Name() string {34 return bt.name35}36func (bt benchTest) Transaction() *transaction.Transaction {37 return bt.txn38}39func (bt benchTest) Run(state cstate.TimedQueryStateContext, b *testing.B) error {40 b.Logf("Running test '%s' from ZCNSC Bridge", bt.name)41 _, err := bt.endpoint(bt.Transaction(), bt.input, state)42 return err43}44// Mint testing stages:45// Create BurnTicketPayload46// Get wallet of a random authorizer47// Get private key from wallet48// Sign payload using authorizer private key49// Collect N signatures50// Send it to mint endpoint51func BenchmarkTests(data benchmark.BenchData, scheme benchmark.SignatureScheme) benchmark.TestSuite {52 sc := createSmartContract()53 indexOfNewAuth := len(data.Clients) - 154 return createTestSuite(55 []benchTest{56 {57 name: benchmark.ZcnSc + AddAuthorizerFunc,58 endpoint: sc.AddAuthorizer,59 txn: createTransaction(data.Clients[indexOfNewAuth], data.PublicKeys[indexOfNewAuth]),60 input: createAuthorizerPayload(data, indexOfNewAuth),61 },62 {63 name: benchmark.ZcnSc + DeleteAuthorizerFunc,64 endpoint: sc.DeleteAuthorizer,65 txn: createTransaction(data.Clients[0], data.PublicKeys[0]),66 input: nil,67 },68 {69 name: benchmark.ZcnSc + BurnFunc,70 endpoint: sc.Burn,71 txn: createRandomBurnTransaction(data.Clients, data.PublicKeys),72 input: createBurnPayloadForZCNSCBurn(),73 },74 {75 name: benchmark.ZcnSc + MintFunc + strconv.Itoa(viper.GetInt(benchmark.NumAuthorizers)) + "Confirmations",76 endpoint: sc.Mint,77 txn: createRandomTransaction(data.Clients[0], data.PublicKeys[0]),78 input: createMintPayloadForZCNSCMint(scheme, data),79 },80 {81 name: benchmark.ZcnSc + UpdateGlobalConfigFunc,82 endpoint: sc.UpdateGlobalConfig,83 txn: createTransaction(owner, ""),84 input: (&smartcontract.StringMap{85 Fields: map[string]string{86 MinMintAmount: "2",87 MinBurnAmount: "3",88 MinStakeAmount: "1",89 MinLockAmount: "4",90 MinAuthorizers: "17",91 PercentAuthorizers: "73",92 MaxFee: "800",93 BurnAddress: "7000000000000000000000000000000000000000000000000000000000000000",94 },95 }).Encode(),96 },97 {98 name: benchmark.ZcnSc + UpdateAuthorizerConfigFunc,99 endpoint: sc.UpdateAuthorizerConfig,100 txn: createTransaction(data.Clients[0], data.PublicKeys[0]),101 input: (&AuthorizerNode{102 ID: data.Clients[0],103 PublicKey: data.PublicKeys[0],104 URL: "http://localhost:3030",105 Config: &AuthorizerConfig{106 Fee: currency.Coin(viper.GetInt(benchmark.ZcnMaxFee) / 2),107 },108 }).Encode(),109 },110 {111 name: benchmark.ZcnSc + UpdateAuthorizerStakePoolFunc,112 endpoint: sc.UpdateAuthorizerStakePool,113 txn: createTransaction(data.Clients[0], data.PublicKeys[0]),114 input: (&UpdateAuthorizerStakePoolPayload{115 StakePoolSettings: stakepool.Settings{116 DelegateWallet: data.Clients[0],117 MinStake: currency.Coin(1.1 * 1e10),118 MaxStake: currency.Coin(103 * 1e10),119 MaxNumDelegates: 7,120 ServiceChargeRatio: 0.17,121 },122 }).Encode(),123 },124 {125 name: benchmark.ZcnSc + CollectRewardsFunc,126 endpoint: sc.CollectRewards,127 txn: createTransaction(data.Clients[0], data.PublicKeys[0]),128 input: (&stakepool.CollectRewardRequest{129 ProviderType: spenum.Authorizer,130 PoolId: getMockAuthoriserStakePoolId(data.Clients[0], 0),131 }).Encode(),132 },133 {134 name: benchmark.ZcnSc + AddToDelegatePoolFunc,135 endpoint: sc.AddToDelegatePool,136 txn: createTransaction(data.Clients[0], data.PublicKeys[0]),137 input: (&stakePoolRequest{138 AuthorizerID: data.Clients[0],139 }).encode(),140 },141 {142 name: benchmark.ZcnSc + DeleteFromDelegatePoolFunc,143 endpoint: sc.DeleteFromDelegatePool,144 txn: createTransaction(data.Clients[0], data.PublicKeys[0]),145 input: (&stakePoolRequest{146 PoolID: getMockAuthoriserStakePoolId(data.Clients[0], 0),147 AuthorizerID: data.Clients[0],148 }).encode(),149 },150 },151 )152}153func createMintPayloadForZCNSCMint(scheme benchmark.SignatureScheme, data benchmark.BenchData) []byte {154 var sigs []*AuthorizerSignature155 client := data.Clients[1]156 for i := 0; i < viper.GetInt(benchmark.NumAuthorizers); i++ {157 pb := &proofOfBurn{158 TxnID: encryption.Hash(strconv.Itoa(i)),159 Amount: 100,160 ReceivingClientID: client,161 Nonce: 0,162 Scheme: scheme,163 }164 err := pb.sign(data.PrivateKeys[i])165 if err != nil {166 panic(err)167 }168 sig := &AuthorizerSignature{169 ID: data.Clients[i],170 Signature: pb.Signature,171 }172 err = pb.verifySignature(data.PublicKeys[i])173 if err != nil {174 panic(err)175 }176 sigs = append(sigs, sig)177 }178 // mintNonce = mintNonce + 1179 payload := &MintPayload{180 EthereumTxnID: "0xc8285f5304b1B7aAB09a7d26721D6F585448D0ed",181 Amount: 1,182 Nonce: mintNonce + 1,183 Signatures: sigs,184 ReceivingClientID: client,185 }186 return payload.Encode()187}188func createBurnPayloadForZCNSCBurn() []byte {189 payload := &BurnPayload{190 EthereumAddress: "0xc8285f5304b1B7aAB09a7d26721D6F585448D0ed",191 }192 return payload.Encode()193}194func createAuthorizerPayload(data benchmark.BenchData, index int) []byte {195 an := &AddAuthorizerPayload{196 PublicKey: data.PublicKeys[index],197 URL: "http://localhost:303" + strconv.Itoa(index),198 StakePoolSettings: getMockStakePoolSettings(data.Clients[index]),199 }200 ap, err := an.Encode()201 if err != nil {202 log.Fatal(err)203 }204 return ap205}206func createRandomTransaction(id, publicKey string) *transaction.Transaction {207 return createTransaction(id, publicKey)208}209func createRandomBurnTransaction(clients, publicKey []string) *transaction.Transaction {210 index := randomIndex(len(clients))211 return createBurnTransaction(clients[index], publicKey[index])212}213func createBurnTransaction(clientId, publicKey string) *transaction.Transaction {214 return &transaction.Transaction{215 HashIDField: datastore.HashIDField{216 Hash: encryption.Hash("mock transaction hash"),217 },218 ClientID: clientId,219 PublicKey: publicKey,220 ToClientID: config.SmartContractConfig.GetString(benchmark.ZcnBurnAddress),221 Value: 3000,222 CreationDate: common.Now(),223 }224}225func createTransaction(clientId, publicKey string) *transaction.Transaction {226 creationTimeRaw := viper.GetInt64(benchmark.MptCreationTime)227 creationTime := common.Now()228 if creationTimeRaw != 0 {229 creationTime = common.Timestamp(creationTimeRaw)230 }231 return &transaction.Transaction{232 HashIDField: datastore.HashIDField{233 Hash: encryption.Hash("mock transaction hash"),234 },235 ClientID: clientId,236 PublicKey: publicKey,237 ToClientID: ADDRESS,238 Value: 3000,239 CreationDate: creationTime,240 }241}242func randomIndex(max int) int {243 return rand.Intn(max)244}245func createTestSuite(restTests []benchTest) benchmark.TestSuite {246 var tests []benchmark.BenchTestI247 for _, test := range restTests {248 tests = append(tests, test)249 }250 return benchmark.TestSuite{251 Source: benchmark.ZCNSCBridge,252 Benchmarks: tests,253 }254}...

Full Screen

Full Screen

bench_test.go

Source:bench_test.go Github

copy

Full Screen

1package bank_test2import (3 "math/rand"4 "testing"5 "time"6 "github.com/stretchr/testify/require"7 abci "github.com/tendermint/tendermint/abci/types"8 tmproto "github.com/tendermint/tendermint/proto/tendermint/types"9 "github.com/cosmos/cosmos-sdk/client"10 cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"11 simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"12 sdk "github.com/cosmos/cosmos-sdk/types"13 moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"14 "github.com/cosmos/cosmos-sdk/x/auth/types"15 authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"16 "github.com/cosmos/cosmos-sdk/x/bank/testutil"17 stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"18)19var moduleAccAddr = authtypes.NewModuleAddress(stakingtypes.BondedPoolName)20// GenSequenceOfTxs generates a set of signed transactions of messages, such21// that they differ only by having the sequence numbers incremented between22// every transaction.23func genSequenceOfTxs(txGen client.TxConfig,24 msgs []sdk.Msg,25 accNums []uint64,26 initSeqNums []uint64,27 numToGenerate int,28 priv ...cryptotypes.PrivKey,29) ([]sdk.Tx, error) {30 txs := make([]sdk.Tx, numToGenerate)31 var err error32 for i := 0; i < numToGenerate; i++ {33 txs[i], err = simtestutil.GenSignedMockTx(34 rand.New(rand.NewSource(time.Now().UnixNano())),35 txGen,36 msgs,37 sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)},38 simtestutil.DefaultGenTxGas,39 "",40 accNums,41 initSeqNums,42 priv...,43 )44 if err != nil {45 break46 }47 for i := 0; i < len(initSeqNums); i++ {48 initSeqNums[i]++49 }50 }51 return txs, err52}53func BenchmarkOneBankSendTxPerBlock(b *testing.B) {54 // b.Skip("Skipping benchmark with buggy code reported at https://github.com/cosmos/cosmos-sdk/issues/10023")55 b.ReportAllocs()56 // Add an account at genesis57 acc := authtypes.BaseAccount{58 Address: addr1.String(),59 }60 // construct genesis state61 genAccs := []types.GenesisAccount{&acc}62 s := createTestSuite(&testing.T{}, genAccs)63 baseApp := s.App.BaseApp64 ctx := baseApp.NewContext(false, tmproto.Header{})65 // some value conceivably higher than the benchmarks would ever go66 require.NoError(b, testutil.FundAccount(s.BankKeeper, ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 100000000000))))67 baseApp.Commit()68 txGen := moduletestutil.MakeTestEncodingConfig().TxConfig69 // Precompute all txs70 txs, err := genSequenceOfTxs(txGen, []sdk.Msg{sendMsg1}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1)71 require.NoError(b, err)72 b.ResetTimer()73 height := int64(3)74 // Run this with a profiler, so its easy to distinguish what time comes from75 // Committing, and what time comes from Check/Deliver Tx.76 for i := 0; i < b.N; i++ {77 baseApp.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: height}})78 _, _, err := baseApp.SimCheck(txGen.TxEncoder(), txs[i])79 if err != nil {80 panic("something is broken in checking transaction")81 }82 _, _, err = baseApp.SimDeliver(txGen.TxEncoder(), txs[i])83 require.NoError(b, err)84 baseApp.EndBlock(abci.RequestEndBlock{Height: height})85 baseApp.Commit()86 height++87 }88}89func BenchmarkOneBankMultiSendTxPerBlock(b *testing.B) {90 // b.Skip("Skipping benchmark with buggy code reported at https://github.com/cosmos/cosmos-sdk/issues/10023")91 b.ReportAllocs()92 // Add an account at genesis93 acc := authtypes.BaseAccount{94 Address: addr1.String(),95 }96 // Construct genesis state97 genAccs := []authtypes.GenesisAccount{&acc}98 s := createTestSuite(&testing.T{}, genAccs)99 baseApp := s.App.BaseApp100 ctx := baseApp.NewContext(false, tmproto.Header{})101 // some value conceivably higher than the benchmarks would ever go102 require.NoError(b, testutil.FundAccount(s.BankKeeper, ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 100000000000))))103 baseApp.Commit()104 txGen := moduletestutil.MakeTestEncodingConfig().TxConfig105 // Precompute all txs106 txs, err := genSequenceOfTxs(txGen, []sdk.Msg{multiSendMsg1}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1)107 require.NoError(b, err)108 b.ResetTimer()109 height := int64(3)110 // Run this with a profiler, so its easy to distinguish what time comes from111 // Committing, and what time comes from Check/Deliver Tx.112 for i := 0; i < b.N; i++ {113 baseApp.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: height}})114 _, _, err := baseApp.SimCheck(txGen.TxEncoder(), txs[i])115 if err != nil {116 panic("something is broken in checking transaction")117 }118 _, _, err = baseApp.SimDeliver(txGen.TxEncoder(), txs[i])119 require.NoError(b, err)120 baseApp.EndBlock(abci.RequestEndBlock{Height: height})121 baseApp.Commit()122 height++123 }124}...

Full Screen

Full Screen

CreateTestSuite

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 testSuite, err := client.CreateTestSuite(1, "TestSuiteName", "TestSuiteDetails", "test", 1, "test", time.Now())4 if err != nil {5 fmt.Println(err)6 }7 fmt.Println(testSuite)8}9import (10func main() {11 testCase, err := client.CreateTestCase(1, "TestCaseName", "TestCaseSummary", "TestCasePreconditions", "TestCaseSteps", "TestCaseExpectedResults", "test", 1, "test", time.Now())12 if err != nil {13 fmt.Println(err)14 }15 fmt.Println(testCase)16}17import (18func main() {19 build, err := client.CreateBuild(1, "BuildName", "BuildNotes", "test", 1, "test", time.Now())20 if err != nil {21 fmt.Println(err)22 }23 fmt.Println(build)24}25import (26func main() {27 platform, err := client.CreatePlatform(1, "PlatformName", "PlatformNotes", "test", 1, "test", time.Now())

Full Screen

Full Screen

CreateTestSuite

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 testSuite := contract.TestSuite{Title: "TestSuite1"}4 client.CreateTestSuite(&testSuite)5 fmt.Println(testSuite.Id)6}7import (8func main() {9 testSuites := client.ListTestSuites()10 fmt.Println(testSuites[0].Title)11}12import (13func main() {14 testSuite := client.RetrieveTestSuite(1)15 fmt.Println(testSuite.Title)16}17import (18func main() {

Full Screen

Full Screen

CreateTestSuite

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ts, err := client.CreateTestSuite("Test Suite 1", "Test Suite 1", 1, 1, 1)4 if err != nil {5 fmt.Println(err)6 }7 fmt.Println(ts)8}9{1 Test Suite 1 Test Suite 1 1 1 1 1}10import (11func main() {12 ts, err := client.GetTestSuite(1)13 if err != nil {14 fmt.Println(err)15 }16 fmt.Println(ts)17}18{1 Test Suite 1 Test Suite 1 1 1 1 1}19import (20func main() {

Full Screen

Full Screen

CreateTestSuite

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var clientObj = client.Client{}4 var testSuite = clientObj.CreateTestSuite("test suite name", "test suite description")5 fmt.Println("Test suite name: " + testSuite.Name)6 fmt.Println("Test suite description: " + testSuite.Description)7 fmt.Println("Test suite id: " + testSuite.ID)8}9import (10func main() {11 var clientObj = client.Client{}12 var testCase = clientObj.CreateTestCase("test case name", "test case description")13 fmt.Println("Test case name: " + testCase.Name)14 fmt.Println("Test case description: " + testCase.Description)15 fmt.Println("Test case id: " + testCase.ID)16}17import (18func main() {19 var clientObj = client.Client{}20 var testStep = clientObj.CreateTestStep("test step name", "test step description")21 fmt.Println("Test step name: " + testStep.Name)22 fmt.Println("Test step description: " + testStep.Description)23 fmt.Println("Test step id: " + testStep.ID)24}25import (26func main() {27 var clientObj = client.Client{}28 var testStep = clientObj.CreateTestStep("test step

Full Screen

Full Screen

CreateTestSuite

Using AI Code Generation

copy

Full Screen

1import "github.com/onsi/ginkgo/ginkgo/testrunner"2func main() {3client := testrunner.Client{}4client.CreateTestSuite("test_suite_name")5}6type Client struct {}7func (c *Client) CreateTestSuite(suiteName string) {8}9import "testing"10func TestCreateTestSuite(t *testing.T) {11}

Full Screen

Full Screen

CreateTestSuite

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 testSuite := GoTestNG.CreateTestSuite("TestSuiteName")4 testSuite.AddTest("TestName", "TestMethodName")5 testSuite.RunTestSuite()6}7import (8type TestClass struct {9}10func (testClass *TestClass) TestMethodName() {11 fmt.Println("Test Method")12}13func main() {14 testClass := TestClass{}15 testClass.InitTestClass()16}17import (18func main() {19 testSuite := GoTestNG.CreateTestSuite("TestSuiteName")20 testSuite.AddTest("TestName", "TestMethodName")21 testSuite.RunTestSuite()22}23import (24func TestMethodName() {25 fmt.Println("Test Method")26}27func main() {28 testClass := GoTestNG.TestClass{}29 testClass.InitTestClass()30}31import (32func main() {33 testSuite := GoTestNG.CreateTestSuite("TestSuiteName")34 testSuite.AddTest("TestName", "TestMethodName")35 testSuite.RunTestSuite()36}37import (38func TestMethodName() {39 fmt.Println("Test Method")40}41func main() {42 testClass := GoTestNG.TestClass{}43 testClass.InitTestClass()44}45import (

Full Screen

Full Screen

CreateTestSuite

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 client := junitreport.NewClient()4 testSuite := junitreport.CreateTestSuite("testSuite", "testSuite")5 testCase := junitreport.CreateTestCase("testCase", "testCase")6 junitreport.AddFailure(testCase, "Failure", "Failure")7 junitreport.AddTestCase(testSuite, testCase)8 junitreport.AddTestSuite(client, testSuite)9 junitreport.GenerateReport(client, "report.xml")10}11import (12func main() {13 client := junitreport.NewClient()14 testSuite := junitreport.CreateTestSuite("testSuite", "testSuite")15 testCase := junitreport.CreateTestCase("testCase", "testCase")16 junitreport.AddFailure(testCase, "Failure", "Failure")17 junitreport.AddTestCase(testSuite, testCase)18 junitreport.AddTestSuite(client, testSuite)19 junitreport.GenerateReport(client, "report.xml")20}21import (22func main() {23 client := junitreport.NewClient()24 testSuite := junitreport.CreateTestSuite("testSuite", "testSuite")25 testCase := junitreport.CreateTestCase("testCase", "testCase")26 junitreport.AddFailure(testCase, "Failure", "Failure")

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.

Run Testkube automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful