Skip to content

Commit 4e66cda

Browse files
committed
feat(examples): Add expected CLI output for given inputs
1 parent 57b800e commit 4e66cda

19 files changed

Lines changed: 323 additions & 0 deletions

.github/workflows/ci-tests.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,10 @@ jobs:
4040
- name: Run tests
4141
run: |
4242
make test
43+
- name: Check examples
44+
run: |
45+
make clean-examples
46+
make examples
47+
git diff --exit-code examples
48+
49+

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
include common.mk
22

3+
EXAMPLES := $(patsubst %.in,%.out,$(wildcard examples/*.in))
4+
35
# Check if Go's linkers flags are set in common.mk and add them as extra flags.
46
ifneq ($(GOLDFLAGS),)
57
GO_EXTRA_FLAGS += -ldflags $(GOLDFLAGS)
@@ -13,6 +15,15 @@ build:
1315
@$(ECHO) "$(MAGENTA)*** Building Go code...$(OFF)"
1416
@$(GO) build -v -o oasis $(GOFLAGS) $(GO_EXTRA_FLAGS)
1517

18+
examples: build $(EXAMPLES)
19+
20+
examples/%.out: examples/%.in $(shell find -name "*.go" -type f) go.sum go.mod
21+
@rm -f $@
22+
@scripts/gen_example.sh $< $@
23+
24+
clean-examples:
25+
@rm -f examples/*.out
26+
1627
# Format code.
1728
fmt:
1829
@$(ECHO) "$(CYAN)*** Running Go formatters...$(OFF)"
@@ -64,6 +75,8 @@ clean:
6475
# List of targets that are not actual files.
6576
.PHONY: \
6677
all build \
78+
examples \
79+
clean-examples \
6780
fmt \
6881
$(lint-targets) lint \
6982
$(test-targets) test \

examples/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Oasis CLI Examples
2+
3+
This folder contains a number of Oasis CLI invocations and expected outputs.
4+
The snippets are included in the documentation and serve as a check for
5+
potential regressions in the CI.
6+
7+
## Input files
8+
9+
The invocation parameters of each Oasis CLI example consists of one or more
10+
`<EXAMPLE_NAME>[.NUMBER].in` files. Each file begins with `oasis` command,
11+
which will be replaced with the actual path of the Oasis CLI command during
12+
execution. If multiple files exist for the same example name, they will be
13+
executed sequentially based on NUMBER and they will all share the config
14+
file. This way, you can prepare and execute a scenario of Oasis CLI
15+
invocations.
16+
17+
## Output files
18+
19+
The Oasis CLI output for the given input is stored in the corresponding
20+
`<EXAMPLE_NAME>[.NUMBER].out` file.
21+
22+
## Custom config files
23+
24+
Sometimes, you want to use the existing config file for the Oasis CLI. Put
25+
your desired Oasis CLI config folder inside `examples/<EXAMPLE_NAME>`. Upon
26+
example invocation, the folder will be copied over to a temporary location and
27+
provided to CLI with `--config` parameter.
28+
29+
## Example output generation
30+
31+
To run the examples and generate outputs, run:
32+
33+
```sh
34+
make examples
35+
```

examples/account-deposit.0.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oasis account deposit 10 test:dave --account test:alice

examples/account-deposit.0.out

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
You are about to sign the following transaction:
2+
Format: plain
3+
Method: consensus.Deposit
4+
Body:
5+
To: test:dave (oasis1qrk58a6j2qn065m6p06jgjyt032f7qucy5wqeqpt)
6+
Amount: 10.0 ROSE
7+
Authorized signer(s):
8+
1. NcPzNW3YU2T+ugNUtUWtoQnRvbOL9dYSaBfbjHLP1pE= (ed25519)
9+
Nonce: 0
10+
Fee:
11+
Amount: 0.001131 ROSE
12+
Gas limit: 11310
13+
(gas price: 0.0000001 ROSE per gas unit)
14+
15+
Network: mainnet
16+
ParaTime: emerald
17+
Account: test:alice

examples/first-run.in

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

examples/first-run.out

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CLI for interacting with the Oasis network
2+
3+
Usage:
4+
oasis [command]
5+
6+
Available Commands:
7+
account Account operations
8+
addressbook Manage addresses in the local address book
9+
completion Generate the autocompletion script for the specified shell
10+
contract WebAssembly smart contracts operations
11+
help Help about any command
12+
network Consensus layer operations
13+
paratime ParaTime layer operations
14+
transaction Raw transaction operations
15+
wallet Manage accounts in the local wallet
16+
17+
Flags:
18+
--config string config file to use
19+
-h, --help help for oasis
20+
-v, --version version for oasis
21+
22+
Use "oasis [command] --help" for more information about a command.

examples/network.0.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oasis network list

examples/network.0.out

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
NAME CHAIN CONTEXT RPC
2+
mainnet (*) b11b369e0da5bb230b220127f5e7b242d385ef8c6f54906243f30af63c815535 grpc.oasis.dev:443
3+
mainnet_local b11b369e0da5bb230b220127f5e7b242d385ef8c6f54906243f30af63c815535 unix:/serverdir_mainnet/internal.sock
4+
testnet 50304f98ddb656620ea817cc1446c401752a05a249b36c9b90dba4616829977a testnet.grpc.oasis.dev:443
5+
testnet_alt 50304f98ddb656620ea817cc1446c401752a05a249b36c9b90dba4616829977a testnet2.grpc.oasis.dev:443

examples/network.1.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oasis network remove testnet_alt

0 commit comments

Comments
 (0)