How to use Exec method of generated Package

Best Keploy code snippet using generated.Exec

cli_test.go

Source:cli_test.go Github

copy

Full Screen

...58 s.network.Cleanup()59}60func (s *IntegrationTestSuite) TestCLIValidateSignatures() {61 val := s.network.Validators[0]62 res, err := bankcli.MsgSendExec(63 val.ClientCtx,64 val.Address,65 val.Address,66 sdk.NewCoins(67 sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), sdk.NewInt(10)),68 sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)),69 ),70 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),71 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),72 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),73 fmt.Sprintf("--%s=true", flags.FlagGenerateOnly),74 )75 s.Require().NoError(err)76 // write unsigned tx to file77 unsignedTx, cleanup := testutil.WriteToNewTempFile(s.T(), res.String())78 defer cleanup()79 res, err = authtest.TxSignExec(val.ClientCtx, val.Address, unsignedTx.Name())80 s.Require().NoError(err)81 signedTx, err := val.ClientCtx.TxConfig.TxJSONDecoder()(res.Bytes())82 s.Require().NoError(err)83 signedTxFile, cleanup := testutil.WriteToNewTempFile(s.T(), res.String())84 defer cleanup()85 txBuilder, err := val.ClientCtx.TxConfig.WrapTxBuilder(signedTx)86 res, err = authtest.TxValidateSignaturesExec(val.ClientCtx, signedTxFile.Name())87 s.Require().NoError(err)88 txBuilder.SetMemo("MODIFIED TX")89 bz, err := val.ClientCtx.TxConfig.TxJSONEncoder()(txBuilder.GetTx())90 s.Require().NoError(err)91 modifiedTxFile, cleanup := testutil.WriteToNewTempFile(s.T(), string(bz))92 defer cleanup()93 res, err = authtest.TxValidateSignaturesExec(val.ClientCtx, modifiedTxFile.Name())94 s.Require().EqualError(err, "signatures validation failed")95}96func (s *IntegrationTestSuite) TestCLISignBatch() {97 val := s.network.Validators[0]98 generatedStd, err := bankcli.MsgSendExec(99 val.ClientCtx,100 val.Address,101 val.Address,102 sdk.NewCoins(103 sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), sdk.NewInt(10)),104 sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)),105 ),106 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),107 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),108 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),109 fmt.Sprintf("--%s=true", flags.FlagGenerateOnly),110 )111 s.Require().NoError(err)112 // Write the output to disk113 filename, cleanup1 := testutil.WriteToNewTempFile(s.T(), strings.Repeat(generatedStd.String(), 3))114 defer cleanup1()115 // sign-batch file - offline is set but account-number and sequence are not116 val.ClientCtx.HomeDir = strings.Replace(val.ClientCtx.HomeDir, "simd", "simcli", 1)117 res, err := authtest.TxSignBatchExec(val.ClientCtx, val.Address, filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--offline")118 s.Require().EqualError(err, "required flag(s) \"account-number\", \"sequence\" not set")119 // sign-batch file120 res, err = authtest.TxSignBatchExec(val.ClientCtx, val.Address, filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID))121 s.Require().NoError(err)122 s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n")))123 // sign-batch file124 res, err = authtest.TxSignBatchExec(val.ClientCtx, val.Address, filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--signature-only")125 s.Require().NoError(err)126 s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n")))127 // Sign batch malformed tx file.128 malformedFile, cleanup2 := testutil.WriteToNewTempFile(s.T(), fmt.Sprintf("%smalformed", generatedStd))129 defer cleanup2()130 res, err = authtest.TxSignBatchExec(val.ClientCtx, val.Address, malformedFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID))131 s.Require().Error(err)132 // Sign batch malformed tx file signature only.133 res, err = authtest.TxSignBatchExec(val.ClientCtx, val.Address, malformedFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--signature-only")134 s.Require().Error(err)135}136func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {137 val1 := s.network.Validators[0]138 account, err := val1.ClientCtx.Keyring.Key("newAccount")139 s.Require().NoError(err)140 sendTokens := sdk.NewCoin(s.cfg.BondDenom, sdk.TokensFromConsensusPower(10))141 normalGeneratedTx, err := bankcli.MsgSendExec(142 val1.ClientCtx,143 val1.Address,144 account.GetAddress(),145 sdk.NewCoins(sendTokens),146 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),147 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),148 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),149 fmt.Sprintf("--%s=true", flags.FlagGenerateOnly),150 )151 s.Require().NoError(err)152 txCfg := val1.ClientCtx.TxConfig153 normalGeneratedStdTx, err := txCfg.TxJSONDecoder()(normalGeneratedTx.Bytes())154 s.Require().NoError(err)155 txBuilder, err := txCfg.WrapTxBuilder(normalGeneratedStdTx)156 s.Require().NoError(err)157 s.Require().Equal(txBuilder.GetTx().GetGas(), uint64(flags.DefaultGasLimit))158 s.Require().Equal(len(txBuilder.GetTx().GetMsgs()), 1)159 sigs, err := txBuilder.GetTx().GetSignaturesV2()160 s.Require().NoError(err)161 s.Require().Equal(0, len(sigs))162 // Test generate sendTx with --gas=$amount163 limitedGasGeneratedTx, err := bankcli.MsgSendExec(164 val1.ClientCtx,165 val1.Address,166 account.GetAddress(),167 sdk.NewCoins(sendTokens),168 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),169 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),170 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),171 fmt.Sprintf("--gas=%d", 100),172 fmt.Sprintf("--%s=true", flags.FlagGenerateOnly),173 )174 s.Require().NoError(err)175 limitedGasStdTx, err := txCfg.TxJSONDecoder()(limitedGasGeneratedTx.Bytes())176 s.Require().NoError(err)177 txBuilder, err = txCfg.WrapTxBuilder(limitedGasStdTx)178 s.Require().NoError(err)179 s.Require().Equal(txBuilder.GetTx().GetGas(), uint64(100))180 s.Require().Equal(len(txBuilder.GetTx().GetMsgs()), 1)181 sigs, err = txBuilder.GetTx().GetSignaturesV2()182 s.Require().NoError(err)183 s.Require().Equal(0, len(sigs))184 resp, err := bankcli.QueryBalancesExec(val1.ClientCtx, val1.Address)185 s.Require().NoError(err)186 var balRes banktypes.QueryAllBalancesResponse187 err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes)188 s.Require().NoError(err)189 startTokens := balRes.Balances.AmountOf(s.cfg.BondDenom)190 // Test generate sendTx, estimate gas191 finalGeneratedTx, err := bankcli.MsgSendExec(192 val1.ClientCtx,193 val1.Address,194 account.GetAddress(),195 sdk.NewCoins(sendTokens),196 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),197 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),198 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),199 fmt.Sprintf("--gas=%d", flags.DefaultGasLimit),200 fmt.Sprintf("--%s=true", flags.FlagGenerateOnly),201 )202 s.Require().NoError(err)203 finalStdTx, err := txCfg.TxJSONDecoder()(finalGeneratedTx.Bytes())204 s.Require().NoError(err)205 txBuilder, err = txCfg.WrapTxBuilder(finalStdTx)206 s.Require().NoError(err)207 s.Require().Equal(uint64(flags.DefaultGasLimit), txBuilder.GetTx().GetGas())208 s.Require().Equal(len(finalStdTx.GetMsgs()), 1)209 // Write the output to disk210 unsignedTxFile, cleanup := testutil.WriteToNewTempFile(s.T(), finalGeneratedTx.String())211 defer cleanup()212 // Test validate-signatures213 res, err := authtest.TxValidateSignaturesExec(val1.ClientCtx, unsignedTxFile.Name())214 s.Require().EqualError(err, "signatures validation failed")215 s.Require().True(strings.Contains(res.String(), fmt.Sprintf("Signers:\n 0: %v\n\nSignatures:\n\n", val1.Address.String())))216 // Test sign217 // Does not work in offline mode218 res, err = authtest.TxSignExec(val1.ClientCtx, val1.Address, unsignedTxFile.Name(), "--offline")219 s.Require().EqualError(err, "required flag(s) \"account-number\", \"sequence\" not set")220 // But works offline if we set account number and sequence221 val1.ClientCtx.HomeDir = strings.Replace(val1.ClientCtx.HomeDir, "simd", "simcli", 1)222 res, err = authtest.TxSignExec(val1.ClientCtx, val1.Address, unsignedTxFile.Name(), "--offline", "--account-number", "1", "--sequence", "1")223 s.Require().NoError(err)224 // Sign transaction225 signedTx, err := authtest.TxSignExec(val1.ClientCtx, val1.Address, unsignedTxFile.Name())226 s.Require().NoError(err)227 signedFinalTx, err := txCfg.TxJSONDecoder()(signedTx.Bytes())228 s.Require().NoError(err)229 txBuilder, err = val1.ClientCtx.TxConfig.WrapTxBuilder(signedFinalTx)230 s.Require().NoError(err)231 s.Require().Equal(len(txBuilder.GetTx().GetMsgs()), 1)232 sigs, err = txBuilder.GetTx().GetSignaturesV2()233 s.Require().NoError(err)234 s.Require().Equal(1, len(sigs))235 s.Require().Equal(val1.Address.String(), txBuilder.GetTx().GetSigners()[0].String())236 // Write the output to disk237 signedTxFile, cleanup2 := testutil.WriteToNewTempFile(s.T(), signedTx.String())238 defer cleanup2()239 // Validate Signature240 res, err = authtest.TxValidateSignaturesExec(val1.ClientCtx, signedTxFile.Name())241 s.Require().NoError(err)242 s.Require().True(strings.Contains(res.String(), "[OK]"))243 // Ensure foo has right amount of funds244 resp, err = bankcli.QueryBalancesExec(val1.ClientCtx, val1.Address)245 s.Require().NoError(err)246 err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes)247 s.Require().NoError(err)248 s.Require().Equal(startTokens, balRes.Balances.AmountOf(s.cfg.BondDenom))249 // Test broadcast250 // Does not work in offline mode251 res, err = authtest.TxBroadcastExec(val1.ClientCtx, signedTxFile.Name(), "--offline")252 s.Require().EqualError(err, "cannot broadcast tx during offline mode")253 s.Require().NoError(s.network.WaitForNextBlock())254 // Broadcast correct transaction.255 val1.ClientCtx.BroadcastMode = flags.BroadcastBlock256 res, err = authtest.TxBroadcastExec(val1.ClientCtx, signedTxFile.Name())257 s.Require().NoError(err)258 s.Require().NoError(s.network.WaitForNextBlock())259 // Ensure destiny account state260 resp, err = bankcli.QueryBalancesExec(val1.ClientCtx, account.GetAddress())261 s.Require().NoError(err)262 err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes)263 s.Require().NoError(err)264 s.Require().Equal(sendTokens.Amount, balRes.Balances.AmountOf(s.cfg.BondDenom))265 // Ensure origin account state266 resp, err = bankcli.QueryBalancesExec(val1.ClientCtx, val1.Address)267 s.Require().NoError(err)268 err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes)269 s.Require().NoError(err)270}271func (s *IntegrationTestSuite) TestCLIMultisignInsufficientCosigners() {272 val1 := s.network.Validators[0]273 codec := codec2.NewLegacyAmino()274 sdk.RegisterLegacyAminoCodec(codec)275 banktypes.RegisterLegacyAminoCodec(codec)276 val1.ClientCtx.LegacyAmino = codec277 // Generate 2 accounts and a multisig.278 account1, err := val1.ClientCtx.Keyring.Key("newAccount1")279 s.Require().NoError(err)280 multisigInfo, err := val1.ClientCtx.Keyring.Key("multi")281 s.Require().NoError(err)282 // Send coins from validator to multisig.283 _, err = bankcli.MsgSendExec(284 val1.ClientCtx,285 val1.Address,286 multisigInfo.GetAddress(),287 sdk.NewCoins(288 sdk.NewInt64Coin(s.cfg.BondDenom, 10),289 ),290 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),291 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),292 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),293 fmt.Sprintf("--gas=%d", flags.DefaultGasLimit),294 )295 s.Require().NoError(err)296 s.Require().NoError(s.network.WaitForNextBlock())297 // Generate multisig transaction.298 multiGeneratedTx, err := bankcli.MsgSendExec(299 val1.ClientCtx,300 multisigInfo.GetAddress(),301 val1.Address,302 sdk.NewCoins(303 sdk.NewInt64Coin(s.cfg.BondDenom, 5),304 ),305 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),306 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),307 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),308 fmt.Sprintf("--%s=true", flags.FlagGenerateOnly),309 )310 s.Require().NoError(err)311 // Save tx to file312 multiGeneratedTxFile, cleanup := testutil.WriteToNewTempFile(s.T(), multiGeneratedTx.String())313 defer cleanup()314 // Multisign, sign with one signature315 val1.ClientCtx.HomeDir = strings.Replace(val1.ClientCtx.HomeDir, "simd", "simcli", 1)316 account1Signature, err := authtest.TxSignExec(val1.ClientCtx, account1.GetAddress(), multiGeneratedTxFile.Name(), "--multisig", multisigInfo.GetAddress().String())317 s.Require().NoError(err)318 sign1File, cleanup2 := testutil.WriteToNewTempFile(s.T(), account1Signature.String())319 defer cleanup2()320 multiSigWith1Signature, err := authtest.TxMultiSignExec(val1.ClientCtx, multisigInfo.GetName(), multiGeneratedTxFile.Name(), sign1File.Name())321 s.Require().NoError(err)322 // Save tx to file323 multiSigWith1SignatureFile, cleanup3 := testutil.WriteToNewTempFile(s.T(), multiSigWith1Signature.String())324 defer cleanup3()325 exec, err := authtest.TxValidateSignaturesExec(val1.ClientCtx, multiSigWith1SignatureFile.Name())326 s.Require().Error(err)327 fmt.Printf("%s", exec)328}329func (s *IntegrationTestSuite) TestCLIEncode() {330 val1 := s.network.Validators[0]331 sendTokens := sdk.NewCoin(s.cfg.BondDenom, sdk.TokensFromConsensusPower(10))332 normalGeneratedTx, err := bankcli.MsgSendExec(333 val1.ClientCtx,334 val1.Address,335 val1.Address,336 sdk.NewCoins(sendTokens),337 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),338 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),339 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),340 fmt.Sprintf("--%s=true", flags.FlagGenerateOnly), "--memo", "deadbeef",341 )342 s.Require().NoError(err)343 // Save tx to file344 savedTxFile, cleanup := testutil.WriteToNewTempFile(s.T(), normalGeneratedTx.String())345 defer cleanup()346 // Encode347 encodeExec, err := authtest.TxEncodeExec(val1.ClientCtx, savedTxFile.Name())348 s.Require().NoError(err)349 trimmedBase64 := strings.Trim(encodeExec.String(), "\"\n")350 // Check that the transaction decodes as expected351 decodedTx, err := authtest.TxDecodeExec(val1.ClientCtx, trimmedBase64)352 s.Require().NoError(err)353 txCfg := val1.ClientCtx.TxConfig354 theTx, err := txCfg.TxJSONDecoder()(decodedTx.Bytes())355 s.Require().NoError(err)356 txBuilder, err := val1.ClientCtx.TxConfig.WrapTxBuilder(theTx)357 s.Require().NoError(err)358 s.Require().Equal("deadbeef", txBuilder.GetTx().GetMemo())359}360func (s *IntegrationTestSuite) TestCLIMultisignSortSignatures() {361 val1 := s.network.Validators[0]362 codec := codec2.NewLegacyAmino()363 sdk.RegisterLegacyAminoCodec(codec)364 banktypes.RegisterLegacyAminoCodec(codec)365 val1.ClientCtx.LegacyAmino = codec366 // Generate 2 accounts and a multisig.367 account1, err := val1.ClientCtx.Keyring.Key("newAccount1")368 s.Require().NoError(err)369 account2, err := val1.ClientCtx.Keyring.Key("newAccount2")370 s.Require().NoError(err)371 multisigInfo, err := val1.ClientCtx.Keyring.Key("multi")372 s.Require().NoError(err)373 resp, err := bankcli.QueryBalancesExec(val1.ClientCtx, multisigInfo.GetAddress())374 s.Require().NoError(err)375 var balRes banktypes.QueryAllBalancesResponse376 err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes)377 s.Require().NoError(err)378 intialCoins := balRes.Balances379 // Send coins from validator to multisig.380 sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 10)381 _, err = bankcli.MsgSendExec(382 val1.ClientCtx,383 val1.Address,384 multisigInfo.GetAddress(),385 sdk.NewCoins(sendTokens),386 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),387 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),388 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),389 fmt.Sprintf("--gas=%d", flags.DefaultGasLimit),390 )391 s.Require().NoError(err)392 s.Require().NoError(s.network.WaitForNextBlock())393 resp, err = bankcli.QueryBalancesExec(val1.ClientCtx, multisigInfo.GetAddress())394 s.Require().NoError(err)395 err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes)396 s.Require().NoError(err)397 diff, _ := balRes.Balances.SafeSub(intialCoins)398 s.Require().Equal(sendTokens.Amount, diff.AmountOf(s.cfg.BondDenom))399 // Generate multisig transaction.400 multiGeneratedTx, err := bankcli.MsgSendExec(401 val1.ClientCtx,402 multisigInfo.GetAddress(),403 val1.Address,404 sdk.NewCoins(405 sdk.NewInt64Coin(s.cfg.BondDenom, 5),406 ),407 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),408 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),409 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),410 fmt.Sprintf("--%s=true", flags.FlagGenerateOnly),411 )412 s.Require().NoError(err)413 // Save tx to file414 multiGeneratedTxFile, cleanup := testutil.WriteToNewTempFile(s.T(), multiGeneratedTx.String())415 defer cleanup()416 // Sign with account1417 val1.ClientCtx.HomeDir = strings.Replace(val1.ClientCtx.HomeDir, "simd", "simcli", 1)418 account1Signature, err := authtest.TxSignExec(val1.ClientCtx, account1.GetAddress(), multiGeneratedTxFile.Name(), "--multisig", multisigInfo.GetAddress().String())419 s.Require().NoError(err)420 sign1File, cleanup2 := testutil.WriteToNewTempFile(s.T(), account1Signature.String())421 defer cleanup2()422 // Sign with account1423 account2Signature, err := authtest.TxSignExec(val1.ClientCtx, account2.GetAddress(), multiGeneratedTxFile.Name(), "--multisig", multisigInfo.GetAddress().String())424 s.Require().NoError(err)425 sign2File, cleanup3 := testutil.WriteToNewTempFile(s.T(), account2Signature.String())426 defer cleanup3()427 multiSigWith2Signatures, err := authtest.TxMultiSignExec(val1.ClientCtx, multisigInfo.GetName(), multiGeneratedTxFile.Name(), sign1File.Name(), sign2File.Name())428 s.Require().NoError(err)429 // Write the output to disk430 signedTxFile, cleanup4 := testutil.WriteToNewTempFile(s.T(), multiSigWith2Signatures.String())431 defer cleanup4()432 _, err = authtest.TxValidateSignaturesExec(val1.ClientCtx, signedTxFile.Name())433 s.Require().NoError(err)434 val1.ClientCtx.BroadcastMode = flags.BroadcastBlock435 _, err = authtest.TxBroadcastExec(val1.ClientCtx, signedTxFile.Name())436 s.Require().NoError(err)437 s.Require().NoError(s.network.WaitForNextBlock())438}439func (s *IntegrationTestSuite) TestCLIMultisign() {440 val1 := s.network.Validators[0]441 codec := codec2.NewLegacyAmino()442 sdk.RegisterLegacyAminoCodec(codec)443 banktypes.RegisterLegacyAminoCodec(codec)444 val1.ClientCtx.LegacyAmino = codec445 // Generate 2 accounts and a multisig.446 account1, err := val1.ClientCtx.Keyring.Key("newAccount1")447 s.Require().NoError(err)448 account2, err := val1.ClientCtx.Keyring.Key("newAccount2")449 s.Require().NoError(err)450 multisigInfo, err := val1.ClientCtx.Keyring.Key("multi")451 s.Require().NoError(err)452 // Send coins from validator to multisig.453 sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 10)454 _, err = bankcli.MsgSendExec(455 val1.ClientCtx,456 val1.Address,457 multisigInfo.GetAddress(),458 sdk.NewCoins(sendTokens),459 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),460 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),461 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),462 fmt.Sprintf("--gas=%d", flags.DefaultGasLimit),463 )464 s.Require().NoError(s.network.WaitForNextBlock())465 resp, err := bankcli.QueryBalancesExec(val1.ClientCtx, multisigInfo.GetAddress())466 s.Require().NoError(err)467 var balRes banktypes.QueryAllBalancesResponse468 err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes)469 s.Require().NoError(err)470 s.Require().Equal(sendTokens.Amount, balRes.Balances.AmountOf(s.cfg.BondDenom))471 // Generate multisig transaction.472 multiGeneratedTx, err := bankcli.MsgSendExec(473 val1.ClientCtx,474 multisigInfo.GetAddress(),475 val1.Address,476 sdk.NewCoins(477 sdk.NewInt64Coin(s.cfg.BondDenom, 5),478 ),479 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),480 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),481 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),482 fmt.Sprintf("--%s=true", flags.FlagGenerateOnly),483 )484 s.Require().NoError(err)485 // Save tx to file486 multiGeneratedTxFile, cleanup := testutil.WriteToNewTempFile(s.T(), multiGeneratedTx.String())487 defer cleanup()488 // Sign with account1489 val1.ClientCtx.HomeDir = strings.Replace(val1.ClientCtx.HomeDir, "simd", "simcli", 1)490 account1Signature, err := authtest.TxSignExec(val1.ClientCtx, account1.GetAddress(), multiGeneratedTxFile.Name(), "--multisig", multisigInfo.GetAddress().String())491 s.Require().NoError(err)492 sign1File, cleanup2 := testutil.WriteToNewTempFile(s.T(), account1Signature.String())493 defer cleanup2()494 // Sign with account1495 account2Signature, err := authtest.TxSignExec(val1.ClientCtx, account2.GetAddress(), multiGeneratedTxFile.Name(), "--multisig", multisigInfo.GetAddress().String())496 s.Require().NoError(err)497 sign2File, cleanup3 := testutil.WriteToNewTempFile(s.T(), account2Signature.String())498 defer cleanup3()499 // Does not work in offline mode.500 _, err = authtest.TxMultiSignExec(val1.ClientCtx, multisigInfo.GetName(), multiGeneratedTxFile.Name(), "--offline", sign1File.Name(), sign2File.Name())501 s.Require().EqualError(err, "couldn't verify signature: unable to verify single signer signature")502 val1.ClientCtx.Offline = false503 multiSigWith2Signatures, err := authtest.TxMultiSignExec(val1.ClientCtx, multisigInfo.GetName(), multiGeneratedTxFile.Name(), sign1File.Name(), sign2File.Name())504 s.Require().NoError(err)505 // Write the output to disk506 signedTxFile, cleanup4 := testutil.WriteToNewTempFile(s.T(), multiSigWith2Signatures.String())507 defer cleanup4()508 _, err = authtest.TxValidateSignaturesExec(val1.ClientCtx, signedTxFile.Name())509 s.Require().NoError(err)510 val1.ClientCtx.BroadcastMode = flags.BroadcastBlock511 _, err = authtest.TxBroadcastExec(val1.ClientCtx, signedTxFile.Name())512 s.Require().NoError(err)513 s.Require().NoError(s.network.WaitForNextBlock())514}515func (s *IntegrationTestSuite) TestGetAccountCmd() {516 val := s.network.Validators[0]517 _, _, addr1 := testdata.KeyTestPubAddr()518 testCases := []struct {519 name string520 args []string521 expectErr bool522 }{523 {524 "invalid address",525 []string{addr1.String(),526 fmt.Sprintf("--%s=json", tmcli.OutputFlag)},527 true,528 },529 {530 "valid address",531 []string{val.Address.String(),532 fmt.Sprintf("--%s=json", tmcli.OutputFlag)},533 false,534 },535 }536 for _, tc := range testCases {537 tc := tc538 s.Run(tc.name, func() {539 cmd := authcli.GetAccountCmd()540 clientCtx := val.ClientCtx541 out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)542 if tc.expectErr {543 s.Require().Error(err)544 s.Require().NotEqual("internal", err.Error())545 } else {546 var any types.Any547 s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), &any))548 var acc authtypes.AccountI549 s.Require().NoError(val.ClientCtx.InterfaceRegistry.UnpackAny(&any, &acc))550 s.Require().Equal(val.Address, acc.GetAddress())551 }552 })553 }554}555func TestGetBroadcastCommand_OfflineFlag(t *testing.T) {556 clientCtx := client.Context{}.WithOffline(true)557 clientCtx = clientCtx.WithTxConfig(simapp.MakeEncodingConfig().TxConfig)558 cmd := authcli.GetBroadcastCommand()559 _ = testutil.ApplyMockIODiscardOutErr(cmd)560 cmd.SetArgs([]string{fmt.Sprintf("--%s=true", flags.FlagOffline), ""})561 require.EqualError(t, cmd.Execute(), "cannot broadcast tx during offline mode")562}563func TestGetBroadcastCommand_WithoutOfflineFlag(t *testing.T) {564 clientCtx := client.Context{}565 txCfg := simapp.MakeEncodingConfig().TxConfig566 clientCtx = clientCtx.WithTxConfig(txCfg)567 ctx := context.Background()568 ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)569 cmd := authcli.GetBroadcastCommand()570 _, out := testutil.ApplyMockIO(cmd)571 testDir, cleanFunc := testutil.NewTestCaseDir(t)572 t.Cleanup(cleanFunc)573 // Create new file with tx574 builder := txCfg.NewTxBuilder()575 builder.SetGasLimit(200000)576 from, err := sdk.AccAddressFromBech32("cosmos1cxlt8kznps92fwu3j6npahx4mjfutydyene2qw")577 require.NoError(t, err)578 to, err := sdk.AccAddressFromBech32("cosmos1cxlt8kznps92fwu3j6npahx4mjfutydyene2qw")579 require.NoError(t, err)580 err = builder.SetMsgs(banktypes.NewMsgSend(from, to, sdk.Coins{sdk.NewInt64Coin("stake", 10000)}))581 require.NoError(t, err)582 txContents, err := txCfg.TxJSONEncoder()(builder.GetTx())583 txFileName := filepath.Join(testDir, "tx.json")584 err = ioutil.WriteFile(txFileName, txContents, 0644)585 require.NoError(t, err)586 cmd.SetArgs([]string{txFileName})587 require.Error(t, cmd.ExecuteContext(ctx))588 require.Contains(t, out.String(), "unsupported return type ; supported types: sync, async, block")589}590func TestIntegrationTestSuite(t *testing.T) {591 suite.Run(t, new(IntegrationTestSuite))592}...

Full Screen

Full Screen

zz_generated.conversion.go

Source:zz_generated.conversion.go Github

copy

Full Screen

...25}26// RegisterConversions adds conversion functions to the given scheme.27// Public to allow building arbitrary schemes.28func RegisterConversions(s *runtime.Scheme) error {29 if err := s.AddGeneratedConversionFunc((*ExecCredential)(nil), (*clientauthentication.ExecCredential)(nil), func(a, b interface{}, scope conversion.Scope) error {30 return Convert_v1alpha1_ExecCredential_To_clientauthentication_ExecCredential(a.(*ExecCredential), b.(*clientauthentication.ExecCredential), scope)31 }); err != nil {32 return err33 }34 if err := s.AddGeneratedConversionFunc((*clientauthentication.ExecCredential)(nil), (*ExecCredential)(nil), func(a, b interface{}, scope conversion.Scope) error {35 return Convert_clientauthentication_ExecCredential_To_v1alpha1_ExecCredential(a.(*clientauthentication.ExecCredential), b.(*ExecCredential), scope)36 }); err != nil {37 return err38 }39 if err := s.AddGeneratedConversionFunc((*ExecCredentialSpec)(nil), (*clientauthentication.ExecCredentialSpec)(nil), func(a, b interface{}, scope conversion.Scope) error {40 return Convert_v1alpha1_ExecCredentialSpec_To_clientauthentication_ExecCredentialSpec(a.(*ExecCredentialSpec), b.(*clientauthentication.ExecCredentialSpec), scope)41 }); err != nil {42 return err43 }44 if err := s.AddGeneratedConversionFunc((*clientauthentication.ExecCredentialSpec)(nil), (*ExecCredentialSpec)(nil), func(a, b interface{}, scope conversion.Scope) error {45 return Convert_clientauthentication_ExecCredentialSpec_To_v1alpha1_ExecCredentialSpec(a.(*clientauthentication.ExecCredentialSpec), b.(*ExecCredentialSpec), scope)46 }); err != nil {47 return err48 }49 if err := s.AddGeneratedConversionFunc((*ExecCredentialStatus)(nil), (*clientauthentication.ExecCredentialStatus)(nil), func(a, b interface{}, scope conversion.Scope) error {50 return Convert_v1alpha1_ExecCredentialStatus_To_clientauthentication_ExecCredentialStatus(a.(*ExecCredentialStatus), b.(*clientauthentication.ExecCredentialStatus), scope)51 }); err != nil {52 return err53 }54 if err := s.AddGeneratedConversionFunc((*clientauthentication.ExecCredentialStatus)(nil), (*ExecCredentialStatus)(nil), func(a, b interface{}, scope conversion.Scope) error {55 return Convert_clientauthentication_ExecCredentialStatus_To_v1alpha1_ExecCredentialStatus(a.(*clientauthentication.ExecCredentialStatus), b.(*ExecCredentialStatus), scope)56 }); err != nil {57 return err58 }59 if err := s.AddGeneratedConversionFunc((*Response)(nil), (*clientauthentication.Response)(nil), func(a, b interface{}, scope conversion.Scope) error {60 return Convert_v1alpha1_Response_To_clientauthentication_Response(a.(*Response), b.(*clientauthentication.Response), scope)61 }); err != nil {62 return err63 }64 if err := s.AddGeneratedConversionFunc((*clientauthentication.Response)(nil), (*Response)(nil), func(a, b interface{}, scope conversion.Scope) error {65 return Convert_clientauthentication_Response_To_v1alpha1_Response(a.(*clientauthentication.Response), b.(*Response), scope)66 }); err != nil {67 return err68 }69 return nil70}71func autoConvert_v1alpha1_ExecCredential_To_clientauthentication_ExecCredential(in *ExecCredential, out *clientauthentication.ExecCredential, s conversion.Scope) error {72 if err := Convert_v1alpha1_ExecCredentialSpec_To_clientauthentication_ExecCredentialSpec(&in.Spec, &out.Spec, s); err != nil {73 return err74 }75 out.Status = (*clientauthentication.ExecCredentialStatus)(unsafe.Pointer(in.Status))76 return nil77}78// Convert_v1alpha1_ExecCredential_To_clientauthentication_ExecCredential is an autogenerated conversion function.79func Convert_v1alpha1_ExecCredential_To_clientauthentication_ExecCredential(in *ExecCredential, out *clientauthentication.ExecCredential, s conversion.Scope) error {80 return autoConvert_v1alpha1_ExecCredential_To_clientauthentication_ExecCredential(in, out, s)81}82func autoConvert_clientauthentication_ExecCredential_To_v1alpha1_ExecCredential(in *clientauthentication.ExecCredential, out *ExecCredential, s conversion.Scope) error {83 if err := Convert_clientauthentication_ExecCredentialSpec_To_v1alpha1_ExecCredentialSpec(&in.Spec, &out.Spec, s); err != nil {84 return err85 }86 out.Status = (*ExecCredentialStatus)(unsafe.Pointer(in.Status))87 return nil88}89// Convert_clientauthentication_ExecCredential_To_v1alpha1_ExecCredential is an autogenerated conversion function.90func Convert_clientauthentication_ExecCredential_To_v1alpha1_ExecCredential(in *clientauthentication.ExecCredential, out *ExecCredential, s conversion.Scope) error {91 return autoConvert_clientauthentication_ExecCredential_To_v1alpha1_ExecCredential(in, out, s)92}93func autoConvert_v1alpha1_ExecCredentialSpec_To_clientauthentication_ExecCredentialSpec(in *ExecCredentialSpec, out *clientauthentication.ExecCredentialSpec, s conversion.Scope) error {94 out.Response = (*clientauthentication.Response)(unsafe.Pointer(in.Response))95 out.Interactive = in.Interactive96 return nil97}98// Convert_v1alpha1_ExecCredentialSpec_To_clientauthentication_ExecCredentialSpec is an autogenerated conversion function.99func Convert_v1alpha1_ExecCredentialSpec_To_clientauthentication_ExecCredentialSpec(in *ExecCredentialSpec, out *clientauthentication.ExecCredentialSpec, s conversion.Scope) error {100 return autoConvert_v1alpha1_ExecCredentialSpec_To_clientauthentication_ExecCredentialSpec(in, out, s)101}102func autoConvert_clientauthentication_ExecCredentialSpec_To_v1alpha1_ExecCredentialSpec(in *clientauthentication.ExecCredentialSpec, out *ExecCredentialSpec, s conversion.Scope) error {103 out.Response = (*Response)(unsafe.Pointer(in.Response))104 out.Interactive = in.Interactive105 return nil106}107// Convert_clientauthentication_ExecCredentialSpec_To_v1alpha1_ExecCredentialSpec is an autogenerated conversion function.108func Convert_clientauthentication_ExecCredentialSpec_To_v1alpha1_ExecCredentialSpec(in *clientauthentication.ExecCredentialSpec, out *ExecCredentialSpec, s conversion.Scope) error {109 return autoConvert_clientauthentication_ExecCredentialSpec_To_v1alpha1_ExecCredentialSpec(in, out, s)110}111func autoConvert_v1alpha1_ExecCredentialStatus_To_clientauthentication_ExecCredentialStatus(in *ExecCredentialStatus, out *clientauthentication.ExecCredentialStatus, s conversion.Scope) error {112 out.ExpirationTimestamp = (*v1.Time)(unsafe.Pointer(in.ExpirationTimestamp))113 out.Token = in.Token114 out.ClientCertificateData = in.ClientCertificateData115 out.ClientKeyData = in.ClientKeyData116 return nil117}118// Convert_v1alpha1_ExecCredentialStatus_To_clientauthentication_ExecCredentialStatus is an autogenerated conversion function.119func Convert_v1alpha1_ExecCredentialStatus_To_clientauthentication_ExecCredentialStatus(in *ExecCredentialStatus, out *clientauthentication.ExecCredentialStatus, s conversion.Scope) error {120 return autoConvert_v1alpha1_ExecCredentialStatus_To_clientauthentication_ExecCredentialStatus(in, out, s)121}122func autoConvert_clientauthentication_ExecCredentialStatus_To_v1alpha1_ExecCredentialStatus(in *clientauthentication.ExecCredentialStatus, out *ExecCredentialStatus, s conversion.Scope) error {123 out.ExpirationTimestamp = (*v1.Time)(unsafe.Pointer(in.ExpirationTimestamp))124 out.Token = in.Token125 out.ClientCertificateData = in.ClientCertificateData126 out.ClientKeyData = in.ClientKeyData127 return nil128}129// Convert_clientauthentication_ExecCredentialStatus_To_v1alpha1_ExecCredentialStatus is an autogenerated conversion function.130func Convert_clientauthentication_ExecCredentialStatus_To_v1alpha1_ExecCredentialStatus(in *clientauthentication.ExecCredentialStatus, out *ExecCredentialStatus, s conversion.Scope) error {131 return autoConvert_clientauthentication_ExecCredentialStatus_To_v1alpha1_ExecCredentialStatus(in, out, s)132}133func autoConvert_v1alpha1_Response_To_clientauthentication_Response(in *Response, out *clientauthentication.Response, s conversion.Scope) error {134 out.Header = *(*map[string][]string)(unsafe.Pointer(&in.Header))135 out.Code = in.Code136 return nil137}138// Convert_v1alpha1_Response_To_clientauthentication_Response is an autogenerated conversion function.139func Convert_v1alpha1_Response_To_clientauthentication_Response(in *Response, out *clientauthentication.Response, s conversion.Scope) error {140 return autoConvert_v1alpha1_Response_To_clientauthentication_Response(in, out, s)141}142func autoConvert_clientauthentication_Response_To_v1alpha1_Response(in *clientauthentication.Response, out *Response, s conversion.Scope) error {143 out.Header = *(*map[string][]string)(unsafe.Pointer(&in.Header))144 out.Code = in.Code145 return nil...

Full Screen

Full Screen

Exec

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 out, err := golexec.Exec("ls", "-l")4 if err != nil {5 fmt.Printf("Error: %s\n", err)6 } else {7 fmt.Printf("Output: %s\n", out)8 }9}10import (11func main() {12 out, err := golexec.Exec("ls", "-l")13 if err != nil {14 fmt.Printf("Error: %s\n", err)15 } else {16 fmt.Printf("Output: %s\n", out)17 }18}19import (20func main() {21 out, err := golexec.Exec("ls", "-l")22 if err != nil {23 fmt.Printf("Error: %s\n", err)24 } else {25 fmt.Printf("Output: %s\n", out)26 }27}28import (29func main() {30 out, err := golexec.Exec("ls", "-l")31 if err != nil {32 fmt.Printf("Error: %s\n", err)33 } else {34 fmt.Printf("Output: %s\n", out)35 }36}37import (38func main() {39 out, err := golexec.Exec("ls", "-l")40 if err != nil {41 fmt.Printf("Error: %s\n", err)42 } else {43 fmt.Printf("Output: %s\n", out)44 }45}46import (47func main() {

Full Screen

Full Screen

Exec

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 x.Exec()4 fmt.Println("Hello, playground")5}6import (7func main() {8 x.Exec()9 fmt.Println("Hello, playground")10}11import (12func main() {13 x.Exec()14 fmt.Println("Hello, playground")15}16import (17func main() {18 x.Exec()19 fmt.Println("Hello, playground")20}21import (22func main() {23 x.Exec()24 fmt.Println("Hello, playground")25}26import (27func main() {28 x.Exec()29 fmt.Println("Hello, playground")30}31import (32func main() {33 x.Exec()34 fmt.Println("Hello, playground")35}36import (37func main() {38 x.Exec()39 fmt.Println("Hello, playground")40}41import (42func main() {43 x.Exec()44 fmt.Println("Hello, playground")45}46import (47func main() {48 x.Exec()49 fmt.Println("Hello, playground")50}

Full Screen

Full Screen

Exec

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("hello world")4 fmt.Println(golenv.Env("GOPATH"))5}6import (7func main() {8 fmt.Println("hello world")9 fmt.Println(golenv.Env("GOPATH"))10}

Full Screen

Full Screen

Exec

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter two numbers")4 fmt.Scan(&a, &b)5 fmt.Println("Sum of two numbers: ", _1.Exec(a, b))6}

Full Screen

Full Screen

Exec

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 vm := GoJava.NewJavaVM()4 opt := GoJava.NewJavaVMOption()5 opt.SetOption("-Djava.class.path=/path/to/your/jar.jar")6 vm.AddOption(opt)7 initargs := GoJava.NewJavaVMInitArgs()8 initargs.AddOption(opt)9 env := GoJava.NewJNIEnv()10 vm.CreateJVM(initargs)11 vm.AttachCurrentThread(env)12 class := env.FindClass("com/example/MyClass")13 method := env.GetStaticMethodID(class, "myMethod", "(Ljava/lang/String;)I")14 str := GoJava.NewGoString("Hello World!")15 env.CallStaticObjectMethod(class, method, str)16 vm.DetachCurrentThread()17 vm.DestroyJVM()18}19import (20func main() {21 vm := GoJava.NewJavaVM()22 opt := GoJava.NewJavaVMOption()23 opt.SetOption("-Djava.class.path=/path/to/your/jar.jar")24 vm.AddOption(opt)25 initargs := GoJava.NewJavaVMInitArgs()26 initargs.AddOption(opt)27 env := GoJava.NewJNIEnv()

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 Keploy automation tests on LambdaTest cloud grid

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

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful