|
| 1 | +//lint:file-ignore U1001 Ignore all unused code, this is only used in tests. |
1 | 2 | package integration
|
2 | 3 |
|
3 | 4 | import (
|
@@ -333,18 +334,33 @@ func (i *Test) Client() *sdk.Client {
|
333 | 334 | // ingested by Horizon. Panics in case of errors.
|
334 | 335 | func (i *Test) LedgerIngested(sequence uint32) bool {
|
335 | 336 | root, err := i.Client().Root()
|
336 |
| - if err != nil { |
337 |
| - panic(err) |
338 |
| - } |
| 337 | + panicIf(err) |
339 | 338 |
|
340 | 339 | return root.IngestSequence >= sequence
|
341 | 340 | }
|
342 | 341 |
|
| 342 | +// LedgerClosed returns true if the ledger with a given sequence has been |
| 343 | +// closed by Stellar-Core. Panics in case of errors. Note it's different |
| 344 | +// than LedgerIngested because it checks if the ledger was closed, not |
| 345 | +// necessarily ingested (ex. when rebuilding state Horizon does not ingest |
| 346 | +// recent ledgers). |
| 347 | +func (i *Test) LedgerClosed(sequence uint32) bool { |
| 348 | + root, err := i.Client().Root() |
| 349 | + panicIf(err) |
| 350 | + |
| 351 | + return root.CoreSequence >= int32(sequence) |
| 352 | +} |
| 353 | + |
343 | 354 | // AdminPort returns Horizon admin port.
|
344 | 355 | func (i *Test) AdminPort() int {
|
345 | 356 | return 6060
|
346 | 357 | }
|
347 | 358 |
|
| 359 | +// Metrics URL returns Horizon metrics URL. |
| 360 | +func (i *Test) MetricsURL() string { |
| 361 | + return fmt.Sprintf("http://localhost:%d/metrics", i.AdminPort()) |
| 362 | +} |
| 363 | + |
348 | 364 | // Master returns a keypair of the network master account.
|
349 | 365 | func (i *Test) Master() *keypair.Full {
|
350 | 366 | return keypair.Master(NetworkPassphrase).(*keypair.Full)
|
@@ -638,9 +654,43 @@ func (i *Test) CreateSignedTransaction(
|
638 | 654 | return tx, nil
|
639 | 655 | }
|
640 | 656 |
|
| 657 | +// CloseCoreLedgersUntilSequence will close ledgers until sequence. |
| 658 | +// Note: because manualclose command doesn't block until ledger is actually |
| 659 | +// closed, after running this method the last sequence can be higher than seq. |
| 660 | +func (i *Test) CloseCoreLedgersUntilSequence(seq int) error { |
| 661 | + for { |
| 662 | + ctx, cancel := context.WithTimeout(context.Background(), time.Second) |
| 663 | + defer cancel() |
| 664 | + info, err := i.cclient.Info(ctx) |
| 665 | + if err != nil { |
| 666 | + return err |
| 667 | + } |
| 668 | + |
| 669 | + if info.Info.Ledger.Num >= seq { |
| 670 | + return nil |
| 671 | + } |
| 672 | + |
| 673 | + i.t.Logf( |
| 674 | + "Currently at ledger: %d, want: %d.", |
| 675 | + info.Info.Ledger.Num, |
| 676 | + seq, |
| 677 | + ) |
| 678 | + |
| 679 | + err = i.CloseCoreLedger() |
| 680 | + if err != nil { |
| 681 | + return err |
| 682 | + } |
| 683 | + // manualclose command in core doesn't block until ledger is actually |
| 684 | + // closed. Let's give it time to close the ledger. |
| 685 | + time.Sleep(200 * time.Millisecond) |
| 686 | + } |
| 687 | +} |
| 688 | + |
| 689 | +// CloseCoreLedgers will close one ledger. |
641 | 690 | func (i *Test) CloseCoreLedger() error {
|
642 | 691 | ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
643 | 692 | defer cancel()
|
| 693 | + i.t.Log("Closing one ledger manually...") |
644 | 694 | return i.cclient.ManualClose(ctx)
|
645 | 695 | }
|
646 | 696 |
|
@@ -686,6 +736,20 @@ func (i *Test) LogFailedTx(txResponse proto.Transaction, horizonResult error) {
|
686 | 736 | "Transaction doesn't have success code.")
|
687 | 737 | }
|
688 | 738 |
|
| 739 | +func (i *Test) RunHorizonCLICommand(cmd ...string) { |
| 740 | + fullCmd := append([]string{"/stellar/horizon/bin/horizon"}, cmd...) |
| 741 | + id, err := i.cli.ContainerExecCreate( |
| 742 | + context.Background(), |
| 743 | + i.container.ID, |
| 744 | + types.ExecConfig{ |
| 745 | + Cmd: fullCmd, |
| 746 | + }, |
| 747 | + ) |
| 748 | + panicIf(err) |
| 749 | + err = i.cli.ContainerExecStart(context.Background(), id.ID, types.ExecStartCheck{}) |
| 750 | + panicIf(err) |
| 751 | +} |
| 752 | + |
689 | 753 | // Cluttering code with if err != nil is absolute nonsense.
|
690 | 754 | func panicIf(err error) {
|
691 | 755 | if err != nil {
|
|
0 commit comments