github.com/Finschia/finschia-sdk@v0.49.1/x/token/client/testutil/tx.go (about) 1 package testutil 2 3 import ( 4 "fmt" 5 6 "github.com/Finschia/finschia-sdk/client/flags" 7 clitestutil "github.com/Finschia/finschia-sdk/testutil/cli" 8 sdk "github.com/Finschia/finschia-sdk/types" 9 "github.com/Finschia/finschia-sdk/x/token" 10 "github.com/Finschia/finschia-sdk/x/token/client/cli" 11 ) 12 13 func (s *IntegrationTestSuite) TestNewTxCmdSend() { 14 val := s.network.Validators[0] 15 commonArgs := []string{ 16 fmt.Sprintf("--%s=%s", flags.FlagFrom, s.customer), 17 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), 18 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), 19 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), 20 } 21 22 testCases := map[string]struct { 23 args []string 24 valid bool 25 }{ 26 "valid transaction": { 27 []string{ 28 s.classes[0].Id, 29 s.customer.String(), 30 s.vendor.String(), 31 "1", 32 }, 33 true, 34 }, 35 "extra args": { 36 []string{ 37 s.classes[0].Id, 38 s.customer.String(), 39 s.vendor.String(), 40 "1", 41 "extra", 42 }, 43 false, 44 }, 45 "not enough args": { 46 []string{ 47 s.classes[0].Id, 48 s.customer.String(), 49 s.vendor.String(), 50 }, 51 false, 52 }, 53 "amount out of range": { 54 []string{ 55 s.classes[0].Id, 56 s.customer.String(), 57 s.vendor.String(), 58 "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", 59 }, 60 false, 61 }, 62 } 63 64 for name, tc := range testCases { 65 s.Run(name, func() { 66 cmd := cli.NewTxCmdSend() 67 out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) 68 if !tc.valid { 69 s.Require().Error(err) 70 return 71 } 72 s.Require().NoError(err) 73 74 var res sdk.TxResponse 75 s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out.String()) 76 s.Require().EqualValues(0, res.Code, out.String()) 77 }) 78 } 79 } 80 81 func (s *IntegrationTestSuite) TestNewTxCmdOperatorSend() { 82 val := s.network.Validators[0] 83 commonArgs := []string{ 84 fmt.Sprintf("--%s=%s", flags.FlagFrom, s.vendor), 85 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), 86 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), 87 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), 88 } 89 90 testCases := map[string]struct { 91 args []string 92 valid bool 93 }{ 94 "valid transaction": { 95 []string{ 96 s.classes[0].Id, 97 s.vendor.String(), 98 s.customer.String(), 99 s.vendor.String(), 100 "1", 101 }, 102 true, 103 }, 104 "extra args": { 105 []string{ 106 s.classes[0].Id, 107 s.vendor.String(), 108 s.customer.String(), 109 s.vendor.String(), 110 "1", 111 "extra", 112 }, 113 false, 114 }, 115 "not enough args": { 116 []string{ 117 s.classes[0].Id, 118 s.vendor.String(), 119 s.customer.String(), 120 s.vendor.String(), 121 }, 122 false, 123 }, 124 "amount out of range": { 125 []string{ 126 s.classes[0].Id, 127 s.vendor.String(), 128 s.customer.String(), 129 s.vendor.String(), 130 "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", 131 }, 132 false, 133 }, 134 } 135 136 for name, tc := range testCases { 137 s.Run(name, func() { 138 cmd := cli.NewTxCmdOperatorSend() 139 out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) 140 if !tc.valid { 141 s.Require().Error(err) 142 return 143 } 144 s.Require().NoError(err) 145 146 var res sdk.TxResponse 147 s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out.String()) 148 s.Require().EqualValues(0, res.Code, out.String()) 149 }) 150 } 151 } 152 153 func (s *IntegrationTestSuite) TestNewTxCmdAuthorizeOperator() { 154 val := s.network.Validators[0] 155 commonArgs := []string{ 156 fmt.Sprintf("--%s=%s", flags.FlagFrom, s.vendor), 157 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), 158 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), 159 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), 160 } 161 162 testCases := map[string]struct { 163 args []string 164 valid bool 165 }{ 166 "valid transaction": { 167 []string{ 168 s.classes[0].Id, 169 s.vendor.String(), 170 s.customer.String(), 171 }, 172 true, 173 }, 174 "extra args": { 175 []string{ 176 s.classes[0].Id, 177 s.vendor.String(), 178 s.customer.String(), 179 "extra", 180 }, 181 false, 182 }, 183 "not enough args": { 184 []string{ 185 s.classes[0].Id, 186 s.vendor.String(), 187 }, 188 false, 189 }, 190 } 191 192 for name, tc := range testCases { 193 s.Run(name, func() { 194 cmd := cli.NewTxCmdAuthorizeOperator() 195 out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) 196 if !tc.valid { 197 s.Require().Error(err) 198 return 199 } 200 s.Require().NoError(err) 201 202 var res sdk.TxResponse 203 s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out.String()) 204 s.Require().EqualValues(0, res.Code, out.String()) 205 }) 206 } 207 } 208 209 func (s *IntegrationTestSuite) TestNewTxCmdRevokeOperator() { 210 val := s.network.Validators[0] 211 commonArgs := []string{ 212 fmt.Sprintf("--%s=%s", flags.FlagFrom, s.customer), 213 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), 214 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), 215 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), 216 } 217 218 testCases := map[string]struct { 219 args []string 220 valid bool 221 }{ 222 "valid transaction": { 223 []string{ 224 s.classes[1].Id, 225 s.customer.String(), 226 s.vendor.String(), 227 }, 228 true, 229 }, 230 "extra args": { 231 []string{ 232 s.classes[1].Id, 233 s.customer.String(), 234 s.vendor.String(), 235 "extra", 236 }, 237 false, 238 }, 239 "not enough args": { 240 []string{ 241 s.classes[1].Id, 242 s.customer.String(), 243 }, 244 false, 245 }, 246 } 247 248 for name, tc := range testCases { 249 s.Run(name, func() { 250 cmd := cli.NewTxCmdRevokeOperator() 251 out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) 252 if !tc.valid { 253 s.Require().Error(err) 254 return 255 } 256 s.Require().NoError(err) 257 258 var res sdk.TxResponse 259 s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out.String()) 260 s.Require().EqualValues(0, res.Code, out.String()) 261 }) 262 } 263 } 264 265 func (s *IntegrationTestSuite) TestNewTxCmdIssue() { 266 val := s.network.Validators[0] 267 commonArgs := []string{ 268 fmt.Sprintf("--%s=%s", flags.FlagFrom, s.vendor), 269 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), 270 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), 271 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), 272 } 273 274 testCases := map[string]struct { 275 args []string 276 valid bool 277 }{ 278 "valid transaction": { 279 []string{ 280 s.vendor.String(), 281 s.vendor.String(), 282 "Test class", 283 "TT", 284 fmt.Sprintf("--%s=%s", cli.FlagImageURI, "URI"), 285 fmt.Sprintf("--%s=%s", cli.FlagMeta, "META"), 286 fmt.Sprintf("--%s=%d", cli.FlagDecimals, 8), 287 fmt.Sprintf("--%s=%s", cli.FlagSupply, "10000000000"), 288 fmt.Sprintf("--%s=%v", cli.FlagMintable, true), 289 }, 290 true, 291 }, 292 "extra args": { 293 []string{ 294 s.vendor.String(), 295 s.vendor.String(), 296 "Test class", 297 "TT", 298 "extra", 299 }, 300 false, 301 }, 302 "not enough args": { 303 []string{ 304 s.vendor.String(), 305 s.vendor.String(), 306 "Test class", 307 }, 308 false, 309 }, 310 } 311 312 for name, tc := range testCases { 313 s.Run(name, func() { 314 cmd := cli.NewTxCmdIssue() 315 out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) 316 if !tc.valid { 317 s.Require().Error(err) 318 return 319 } 320 s.Require().NoError(err) 321 322 var res sdk.TxResponse 323 s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out.String()) 324 s.Require().EqualValues(0, res.Code, out.String()) 325 }) 326 } 327 } 328 329 func (s *IntegrationTestSuite) TestNewTxCmdGrantPermission() { 330 val := s.network.Validators[0] 331 commonArgs := []string{ 332 fmt.Sprintf("--%s=%s", flags.FlagFrom, s.vendor), 333 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), 334 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), 335 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), 336 } 337 338 testCases := map[string]struct { 339 args []string 340 valid bool 341 }{ 342 "valid transaction": { 343 []string{ 344 s.classes[1].Id, 345 s.vendor.String(), 346 s.customer.String(), 347 token.LegacyPermissionMint.String(), 348 }, 349 true, 350 }, 351 "extra args": { 352 []string{ 353 s.classes[1].Id, 354 s.vendor.String(), 355 s.customer.String(), 356 token.LegacyPermissionMint.String(), 357 "extra", 358 }, 359 false, 360 }, 361 "not enough args": { 362 []string{ 363 s.classes[1].Id, 364 s.vendor.String(), 365 s.customer.String(), 366 }, 367 false, 368 }, 369 } 370 371 for name, tc := range testCases { 372 s.Run(name, func() { 373 cmd := cli.NewTxCmdGrantPermission() 374 out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) 375 if !tc.valid { 376 s.Require().Error(err) 377 return 378 } 379 s.Require().NoError(err) 380 381 var res sdk.TxResponse 382 s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out.String()) 383 s.Require().EqualValues(0, res.Code, out.String()) 384 }) 385 } 386 } 387 388 func (s *IntegrationTestSuite) TestNewTxCmdRevokePermission() { 389 val := s.network.Validators[0] 390 commonArgs := []string{ 391 fmt.Sprintf("--%s=%s", flags.FlagFrom, s.vendor), 392 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), 393 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), 394 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), 395 } 396 397 testCases := map[string]struct { 398 args []string 399 valid bool 400 }{ 401 "valid transaction": { 402 []string{ 403 s.classes[1].Id, 404 s.vendor.String(), 405 token.LegacyPermissionModify.String(), 406 }, 407 true, 408 }, 409 "extra args": { 410 []string{ 411 s.classes[1].Id, 412 s.vendor.String(), 413 token.LegacyPermissionModify.String(), 414 "extra", 415 }, 416 false, 417 }, 418 "not enough args": { 419 []string{ 420 s.classes[1].Id, 421 s.vendor.String(), 422 }, 423 false, 424 }, 425 } 426 427 for name, tc := range testCases { 428 s.Run(name, func() { 429 cmd := cli.NewTxCmdRevokePermission() 430 out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) 431 if !tc.valid { 432 s.Require().Error(err) 433 return 434 } 435 s.Require().NoError(err) 436 437 var res sdk.TxResponse 438 s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out.String()) 439 s.Require().EqualValues(0, res.Code, out.String()) 440 }) 441 } 442 } 443 444 func (s *IntegrationTestSuite) TestNewTxCmdMint() { 445 val := s.network.Validators[0] 446 commonArgs := []string{ 447 fmt.Sprintf("--%s=%s", flags.FlagFrom, s.vendor), 448 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), 449 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), 450 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), 451 } 452 453 testCases := map[string]struct { 454 args []string 455 valid bool 456 }{ 457 "valid transaction": { 458 []string{ 459 s.classes[0].Id, 460 s.vendor.String(), 461 s.customer.String(), 462 "1", 463 }, 464 true, 465 }, 466 "extra args": { 467 []string{ 468 s.classes[0].Id, 469 s.vendor.String(), 470 s.customer.String(), 471 "1", 472 "extra", 473 }, 474 false, 475 }, 476 "not enough args": { 477 []string{ 478 s.classes[0].Id, 479 s.vendor.String(), 480 s.customer.String(), 481 }, 482 false, 483 }, 484 } 485 486 for name, tc := range testCases { 487 s.Run(name, func() { 488 cmd := cli.NewTxCmdMint() 489 out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) 490 if !tc.valid { 491 s.Require().Error(err) 492 return 493 } 494 s.Require().NoError(err) 495 496 var res sdk.TxResponse 497 s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out.String()) 498 s.Require().EqualValues(0, res.Code, out.String()) 499 }) 500 } 501 } 502 503 func (s *IntegrationTestSuite) TestNewTxCmdBurn() { 504 val := s.network.Validators[0] 505 commonArgs := []string{ 506 fmt.Sprintf("--%s=%s", flags.FlagFrom, s.vendor), 507 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), 508 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), 509 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), 510 } 511 512 testCases := map[string]struct { 513 args []string 514 valid bool 515 }{ 516 "valid transaction": { 517 []string{ 518 s.classes[1].Id, 519 s.vendor.String(), 520 "1", 521 }, 522 true, 523 }, 524 "extra args": { 525 []string{ 526 s.classes[1].Id, 527 s.vendor.String(), 528 "1", 529 "extra", 530 }, 531 false, 532 }, 533 "not enough args": { 534 []string{ 535 s.classes[1].Id, 536 s.vendor.String(), 537 }, 538 false, 539 }, 540 } 541 542 for name, tc := range testCases { 543 s.Run(name, func() { 544 cmd := cli.NewTxCmdBurn() 545 out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) 546 if !tc.valid { 547 s.Require().Error(err) 548 return 549 } 550 s.Require().NoError(err) 551 552 var res sdk.TxResponse 553 s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out.String()) 554 s.Require().EqualValues(0, res.Code, out.String()) 555 }) 556 } 557 } 558 559 func (s *IntegrationTestSuite) TestNewTxCmdOperatorBurn() { 560 val := s.network.Validators[0] 561 commonArgs := []string{ 562 fmt.Sprintf("--%s=%s", flags.FlagFrom, s.vendor), 563 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), 564 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), 565 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), 566 } 567 568 testCases := map[string]struct { 569 args []string 570 valid bool 571 }{ 572 "valid transaction": { 573 []string{ 574 s.classes[0].Id, 575 s.vendor.String(), 576 s.customer.String(), 577 "1", 578 }, 579 true, 580 }, 581 "extra args": { 582 []string{ 583 s.classes[0].Id, 584 s.vendor.String(), 585 s.customer.String(), 586 "1", 587 "extra", 588 }, 589 false, 590 }, 591 "not enough args": { 592 []string{ 593 s.classes[0].Id, 594 s.vendor.String(), 595 s.customer.String(), 596 }, 597 false, 598 }, 599 } 600 601 for name, tc := range testCases { 602 s.Run(name, func() { 603 cmd := cli.NewTxCmdOperatorBurn() 604 out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) 605 if !tc.valid { 606 s.Require().Error(err) 607 return 608 } 609 s.Require().NoError(err) 610 611 var res sdk.TxResponse 612 s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out.String()) 613 s.Require().EqualValues(0, res.Code, out.String()) 614 }) 615 } 616 } 617 618 func (s *IntegrationTestSuite) TestNewTxCmdModify() { 619 val := s.network.Validators[0] 620 commonArgs := []string{ 621 fmt.Sprintf("--%s=%s", flags.FlagFrom, s.vendor), 622 fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), 623 fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), 624 fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), 625 } 626 627 testCases := map[string]struct { 628 args []string 629 valid bool 630 }{ 631 "valid transaction": { 632 []string{ 633 s.classes[0].Id, 634 s.vendor.String(), 635 token.AttributeKeyName.String(), 636 "cool token", 637 }, 638 true, 639 }, 640 "extra args": { 641 []string{ 642 s.classes[0].Id, 643 s.vendor.String(), 644 token.AttributeKeyName.String(), 645 "cool token", 646 "extra", 647 }, 648 false, 649 }, 650 "not enough args": { 651 []string{ 652 s.classes[0].Id, 653 s.vendor.String(), 654 token.AttributeKeyName.String(), 655 }, 656 false, 657 }, 658 } 659 660 for name, tc := range testCases { 661 s.Run(name, func() { 662 cmd := cli.NewTxCmdModify() 663 out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...)) 664 if !tc.valid { 665 s.Require().Error(err) 666 return 667 } 668 s.Require().NoError(err) 669 670 var res sdk.TxResponse 671 s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res), out.String()) 672 s.Require().EqualValues(0, res.Code, out.String()) 673 }) 674 } 675 }