Skip to content

Commit 3d95bd7

Browse files
committed
feat(examples): Add expected CLI output for given inputs
1 parent f7478d2 commit 3d95bd7

197 files changed

Lines changed: 2781 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci-tests.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,8 @@ jobs:
4343
- name: Run tests
4444
run: |
4545
make test
46+
- name: Check examples
47+
run: |
48+
make clean-examples
49+
make examples
50+
git diff --exit-code examples

Makefile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
include common.mk
22

3+
# Each Oasis CLI example's input .in must have a corresponding output .out.
4+
EXAMPLES := $(patsubst %.in,%.out,$(wildcard examples/*/*.in))
5+
36
# Check if Go's linkers flags are set in common.mk and add them as extra flags.
47
ifneq ($(GOLDFLAGS),)
58
GO_EXTRA_FLAGS += -ldflags $(GOLDFLAGS)
@@ -9,10 +12,20 @@ endif
912
all: build
1013

1114
# Build.
12-
build:
15+
build: oasis
16+
oasis: $(shell find . -name "*.go" -type f) go.sum go.mod
1317
@$(PRINT) "$(MAGENTA)*** Building Go code...$(OFF)\n"
1418
@$(GO) build -v -o oasis $(GOFLAGS) $(GO_EXTRA_FLAGS)
1519

20+
examples: $(EXAMPLES)
21+
22+
examples/%.out: examples/%.in oasis scripts/gen_example.sh
23+
@rm -f $@
24+
@scripts/gen_example.sh $< $@
25+
26+
clean-examples:
27+
@rm -f examples/*/*.out
28+
1629
# Format code.
1730
fmt:
1831
@$(PRINT) "$(CYAN)*** Running Go formatters...$(OFF)\n"
@@ -64,6 +77,8 @@ clean:
6477
# List of targets that are not actual files.
6578
.PHONY: \
6679
all build \
80+
examples \
81+
clean-examples \
6782
fmt \
6883
$(lint-targets) lint \
6984
$(test-targets) test \

examples/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Oasis CLI Examples
2+
3+
This folder contains example scenarios for the Oasis CLI. The snippets are
4+
included in the documentation and also serve as a check for potential
5+
regressions in the CLI.
6+
7+
Each example is stored inside its own folder. The folder contains:
8+
9+
- one or more invocation files,
10+
- output file for each invocation file with the content of the resulting
11+
standard output,
12+
- input and output artifacts
13+
- `config` folder containing custom config file to be used for the scenario.
14+
15+
## Invocation files
16+
17+
Invocation files have `.in` extension and they will be executed in
18+
alphabetic order. This is important, if you have destructive operations (e.g
19+
adding or removing a wallet) where the order of execution should be respected.
20+
In this case, name the files starting with a number, for example `00-create.in`.
21+
22+
Each `.in` file begins with `oasis` command, which will be replaced with the
23+
path to the actual Oasis CLI command when generating example outputs.
24+
25+
An example invocation file content to create a new wallet:
26+
27+
```
28+
oasis wallet create john
29+
```
30+
31+
### Non-Interactive Execution
32+
33+
If you want to invoke Oasis in a non-interactive mode (by appending
34+
`-y -o /dev/null` parameters), name the invocation file by appending `.y` after
35+
the `NUMBER`. For example `00.in` becomes `00.y.in`.
36+
37+
### Custom Config Files
38+
39+
Sometimes, you want to use a predefined config file for the Oasis CLI. Put
40+
your desired Oasis CLI config folder inside the `config` subfolder inside the
41+
example folder. Upon example invocation, the folder will be copied over to a
42+
temporary location and provided to CLI with `--config` parameter. Then, the
43+
example will be invoked beginning with the provided config file. This way, you
44+
can prepare and execute specific CLI scenarios without a dozen of presteps.
45+
46+
### Example Artifacts
47+
48+
If an example requires external files such as a JSON file containing an entity
49+
descriptor or a raw transaction, simply put it alongside the input file.
50+
Assume the working directory will be the one that the input file resides in.
51+
The same goes for the output artifacts (e.g. signed transaction).
52+
53+
## Output Files
54+
55+
The Oasis CLI output for the given input will be stored in a file named the same
56+
as the corresponding invocation file, but having `.out` extension instead of
57+
`.in`.
58+
59+
Scenarios should be designed in a way that the output files remain equal unless
60+
a different behavior of the Oasis CLI is expected.
61+
62+
## Static examples
63+
64+
If you do not want the example to be executed, but you simply want to store
65+
Oasis CLI execution snippets for example to be included in the documentation,
66+
append `.static` to the corresponding `.in` and `.out` files. Such files will
67+
not be tested and regenerated each time, but you will have to update it
68+
manually. We discourage using this mechanism, but it may be useful in cases when
69+
the output is expected to change and would not make sense to update it each time
70+
(e.g. `oasis network status` returns the current block height).
71+
72+
## Running Examples
73+
74+
To run the examples and generate outputs, invoke in the top-level directory:
75+
76+
```sh
77+
make examples
78+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oasis account allow logan -- -10
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
You are about to sign the following transaction:
2+
Method: staking.Allow
3+
Body:
4+
Beneficiary: oasis1qpl4axynedmdrrgrg7dpw3yxc4a8crevr5dkuksl
5+
Amount change: -10.0 TEST
6+
Nonce: 0
7+
Fee:
8+
Amount: 0.0 TEST
9+
Gas limit: 1288
10+
(gas price: 0.0 TEST per gas unit)
11+
12+
Network: testnet
13+
ParaTime: none (consensus layer)
14+
Account: oscar
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oasis account allow paratime:sapphire 10
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
You are about to sign the following transaction:
2+
Method: staking.Allow
3+
Body:
4+
Beneficiary: oasis1qqczuf3x6glkgjuf0xgtcpjjw95r3crf7y2323xd
5+
Amount change: +10.0 TEST
6+
Nonce: 1
7+
Fee:
8+
Amount: 0.0 TEST
9+
Gas limit: 1278
10+
(gas price: 0.0 TEST per gas unit)
11+
12+
Network: testnet
13+
ParaTime: none (consensus layer)
14+
Account: oscar

examples/account/allow.y.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oasis account allow logan 10

examples/account/allow.y.out

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
You are about to sign the following transaction:
2+
Method: staking.Allow
3+
Body:
4+
Beneficiary: oasis1qpl4axynedmdrrgrg7dpw3yxc4a8crevr5dkuksl
5+
Amount change: +10.0 TEST
6+
Nonce: 1
7+
Fee:
8+
Amount: 0.0 TEST
9+
Gas limit: 1278
10+
(gas price: 0.0 TEST per gas unit)
11+
12+
Network: testnet
13+
ParaTime: none (consensus layer)
14+
Account: oscar
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oasis account amend-commission-schedule --bounds 29000/1000/2000,35000/900/1900 --rates 29000/1500

0 commit comments

Comments
 (0)