From 18aa3a16d11346fb5a9659b7a3033d18c94915d3 Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Tue, 15 Jan 2019 16:36:04 +0100 Subject: [PATCH 1/4] Add information about test scenarios to docs --- services/horizon/internal/docs/developing.md | 63 ++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/services/horizon/internal/docs/developing.md b/services/horizon/internal/docs/developing.md index e970091df8..bce5772cb5 100644 --- a/services/horizon/internal/docs/developing.md +++ b/services/horizon/internal/docs/developing.md @@ -6,6 +6,7 @@ This document contains topics related to the development of Horizon. - [Initial set up](#setup) - [Regenerating generated code](#regen) +- [Adding and rebuilding test scenarios](#scenarios) - [Running tests](#tests) - [Logging](#logging) @@ -24,6 +25,68 @@ Horizon uses two Go tools you'll need to install: After the above are installed, run `go generate github.com/stellar/go/services/horizon/...`. This will look for any `.tmpl` files in the directory and use them to generate code when annotated structs are found in the package source. +## Addind, rebuilding and using test scenarios + +In order to simulate ledgers Horizon is using [`stellar-core-commander`](https://github.com/stellar/stellar_core_commander) recipe files to add transactions and operations to ledgers using stellar-core test framework. + +In order to add a new scenario or rebuild existing scenarios you need: + +1. [`stellar-core-commander`](https://github.com/stellar/stellar_core_commander) (in short: `scc`) installed and [configured](https://github.com/stellar/stellar_core_commander#assumptions-about-environment). +2. [`stellar-core`](https://github.com/stellar/stellar-core) binary. +3. This repository forked locally. + +`scc` allows you to write scripts/recipes that are later executed in `stellar-core` isolated network. After executing a recipe you can then export `stellar-core` database to be able to run Horizon ingestion system against it (this repository contains a script that does this for you - read below). + +### Example recipe + +Here's an example of recipe file with comments: +```rb +# Define two accounts test accounts +account :scott, Stellar::KeyPair.from_seed("SBZWG33UOQQCAIBAEAQCAIBAEAQCAIBAEAQCAIBAEAQCAIBAEAQCAPSA") +account :bartek, Stellar::KeyPair.from_seed("SBRGC4TUMVVSAIBAEAQCAIBAEAQCAIBAEAQCAIBAEAQCAIBAEAQCBDHV") + +# use_manual_close causes scc to run a process with MANUAL_CLOSE=true +use_manual_close + +# Create 2 accounts `scott` and `bartek` +create_account :scott, :master, 100 +create_account :bartek, :master, 100 + +# Close ledger +close_ledger + +# Send 5 XLM from `scott` to `bartek` +payment :scott, :bartek, [:native, 5] +``` + +You can find more recipes in [`scc` examples](https://github.com/stellar/stellar_core_commander/tree/84d5ffb97202ecc3a0ed34a739c98e69536c0c2c/examples) and [horizon test scenarios](https://github.com/stellar/go/tree/master/services/horizon/internal/test/scenarios). + +### Rebuilding scenarios + +1. Create a new or modify existing recipe. All new recipes should be added to [horizon test scenarios](https://github.com/stellar/go/tree/master/services/horizon/internal/test/scenarios) directory. +2. In `stellar/go` repository root directory run `./services/horizon/internal/scripts/build_test_scenarios.bash`. +3. The command above will rebuild all test scenarios. If need to rebuild only one scenario modify `PACKAGES` environment variable temporarily in the script. + +### Using test scenarios + +In your `Test*` function execute: + +```go +ht := StartHTTPTest(t, scenarioName) +defer ht.Finish() +``` +where `scenarioName` is the name of the scenario you want to use. This will start test Horizon server with data loaded from the recipe. + +When testing ingestion you can load scenario data without Horizon database like: + +```go +tt := test.Start(t).ScenarioWithoutHorizon("kahuna") +defer tt.Finish() +s := ingest(tt, true) +``` + +Check existing tests for more examples. + ## Running Tests start a redis server on port `6379` From ce7f2ac41fe0ea41e01b1ae751121803972fbbc8 Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Tue, 15 Jan 2019 17:41:10 +0100 Subject: [PATCH 2/4] cloned --- services/horizon/internal/docs/developing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/horizon/internal/docs/developing.md b/services/horizon/internal/docs/developing.md index bce5772cb5..aefca54eb0 100644 --- a/services/horizon/internal/docs/developing.md +++ b/services/horizon/internal/docs/developing.md @@ -33,7 +33,7 @@ In order to add a new scenario or rebuild existing scenarios you need: 1. [`stellar-core-commander`](https://github.com/stellar/stellar_core_commander) (in short: `scc`) installed and [configured](https://github.com/stellar/stellar_core_commander#assumptions-about-environment). 2. [`stellar-core`](https://github.com/stellar/stellar-core) binary. -3. This repository forked locally. +3. This repository cloned locally. `scc` allows you to write scripts/recipes that are later executed in `stellar-core` isolated network. After executing a recipe you can then export `stellar-core` database to be able to run Horizon ingestion system against it (this repository contains a script that does this for you - read below). From 6426656b07f68f03d92fc88bd9c5d58f215495f7 Mon Sep 17 00:00:00 2001 From: Tom Quisel Date: Tue, 15 Jan 2019 09:36:19 -0800 Subject: [PATCH 3/4] Update developing.md --- services/horizon/internal/docs/developing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/horizon/internal/docs/developing.md b/services/horizon/internal/docs/developing.md index aefca54eb0..20c034b3a8 100644 --- a/services/horizon/internal/docs/developing.md +++ b/services/horizon/internal/docs/developing.md @@ -25,9 +25,9 @@ Horizon uses two Go tools you'll need to install: After the above are installed, run `go generate github.com/stellar/go/services/horizon/...`. This will look for any `.tmpl` files in the directory and use them to generate code when annotated structs are found in the package source. -## Addind, rebuilding and using test scenarios +## Adding, rebuilding and using test scenarios -In order to simulate ledgers Horizon is using [`stellar-core-commander`](https://github.com/stellar/stellar_core_commander) recipe files to add transactions and operations to ledgers using stellar-core test framework. +In order to simulate ledgers Horizon uses [`stellar-core-commander`](https://github.com/stellar/stellar_core_commander) recipe files to add transactions and operations to ledgers using stellar-core test framework. In order to add a new scenario or rebuild existing scenarios you need: From 8cf5ef62d9e92e5a47fb405ae448ea7f32d2d17c Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Wed, 16 Jan 2019 15:25:22 +0100 Subject: [PATCH 4/4] Update developing.md --- services/horizon/internal/docs/developing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/horizon/internal/docs/developing.md b/services/horizon/internal/docs/developing.md index 20c034b3a8..e4f1b4ad92 100644 --- a/services/horizon/internal/docs/developing.md +++ b/services/horizon/internal/docs/developing.md @@ -65,7 +65,7 @@ You can find more recipes in [`scc` examples](https://github.com/stellar/stellar 1. Create a new or modify existing recipe. All new recipes should be added to [horizon test scenarios](https://github.com/stellar/go/tree/master/services/horizon/internal/test/scenarios) directory. 2. In `stellar/go` repository root directory run `./services/horizon/internal/scripts/build_test_scenarios.bash`. -3. The command above will rebuild all test scenarios. If need to rebuild only one scenario modify `PACKAGES` environment variable temporarily in the script. +3. The command above will rebuild all test scenarios. If you need to rebuild only one scenario modify `PACKAGES` environment variable temporarily in the script. ### Using test scenarios