Skip to content

Commit 37ec77f

Browse files
committed
feat(examples): Add expected CLI output for given inputs
1 parent 6fdd7a1 commit 37ec77f

File tree

7 files changed

+89
-0
lines changed

7 files changed

+89
-0
lines changed

.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
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/account-deposit.in

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

examples/account-deposit.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 TEST
7+
Authorized signer(s):
8+
1. NcPzNW3YU2T+ugNUtUWtoQnRvbOL9dYSaBfbjHLP1pE= (ed25519)
9+
Nonce: 0
10+
Fee:
11+
Amount: 0.001131 TEST
12+
Gas limit: 11310
13+
(gas price: 0.0000001 TEST per gas unit)
14+
15+
Network: testnet
16+
ParaTime: sapphire
17+
Account: test:alice

examples/first-run.in

Whitespace-only changes.

examples/first-run.out

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
inspect Inspect the network
13+
network Manage network endpoints
14+
paratime Manage paratimes
15+
registry Registry operations
16+
tx Raw transaction operations
17+
wallet Manage accounts in the local wallet
18+
19+
Flags:
20+
--config string config file to use
21+
-h, --help help for oasis
22+
-v, --version version for oasis
23+
24+
Use "oasis [command] --help" for more information about a command.

scripts/gen_example.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
OASIS_CMD=./oasis
6+
IN=$1
7+
OUT=$2
8+
9+
# Runs Oasis CLI with command line arguments passed as $1 and stores output
10+
# to $2. Oasis CLI is automatically terminated when "Sign this transaction"
11+
# occurs on the output.
12+
13+
${OASIS_CMD} $(cat $IN) > $OUT &
14+
PID=$!
15+
while ! test -f $OUT || ! grep -q "Sign this transaction" "$OUT" && ps -p ${PID} > /dev/null
16+
do
17+
sleep 0.5
18+
done
19+
20+
kill -9 ${PID} 2&>/dev/null || true
21+
22+
# Trim "Sign this transaction" prompt.
23+
if tail -n 1 $OUT | grep -q "Sign this transaction"
24+
then
25+
head -n -1 $OUT > $OUT.tmp
26+
mv $OUT.tmp $OUT
27+
fi

0 commit comments

Comments
 (0)