Skip to content

Commit b4c9c46

Browse files
authored
feat: added interchaintest suite and gRPC query client generators (#47)
* imp: added interchaintest commands * deps: ran 'go get github.com/charmbracelet/huh' * imp: added new interchaintest command * deps: ran 'go get github.com/gobuffalo/genny/v2' * feat: adding templates * deps: ran 'go get github.com/gobuffalo/plush/v4' * feat: starting to work * feat: suite working * feat: added chainconfig for 2 chains * feat: improve template * feat: basic functionality done * test: added new integration test * imp: improved some files * imp: added workflows * feat: made chainNum more customizable * refactor: improvement * feat: e2esuite generalized * feat: support interchaintest scaffold * feat: added `add-contract` subcmd (#23) * feat: added basic boilerplate * imp: added diagnostics support when chain number is 1 * style: file rename * feat: interchaintest add contract works * imp: basically works * feat: works better * fix: linter issue * fix: linter * imp: install go mod after scaffold (#25) * imp: reorganize go code * deps: ran 'go get github.com/charmbracelet/huh/spinner' * feat: did issue * imp: removed unneeded goenv package * test: improved cleanup * imp: moved spinner to Stdout * test: added debug logs * test: added debug logs * test: disable download for test * test: added debug mode * fix: test * imp: made debug flag hidden * fix: fixed basic_test * ci: improved integration test ci (#33) * ci: better ci * ci: added plush to workflow * test: improved test command * feat: added the feature (#35) * refactor: improve public API (#36) * refactor: privatized generateFieldsFromOneOf * refactor: removed WithoutTags methods * refactor: removed unneeded code * feat: add grpc querier (#37) * imp: added generate cmd * imp: new commands added * imp: kinda working * imp: added more functions * feat: works * fix * ci: fix * ci: fix * ci: added back hidden debug mode * ci: debug * imp: add query-client to `interchaintest add-contract` (#39) * imp: added query client generation to add-contract * feat: integrate QueryClient * imp: added more helpers (#40) * fix: fixed query client generation and added tests (#43) * test: added query client tests * test: wrap in subtest * fix: fixed cw3 multisig * fix: fixed all except ics721 * fix: ics721 but broke account-nft * fix: all passing * docs: updated docs for v0.2 release (#44) * imp: default output is now 'msgs.go' * docs: updated README.md * docs: updated CHANGELOG.md * docs: fix typo * imp: remove the unimplemented messages-only flag (#48) * docs: imp * imp: removed messages-only flag
1 parent bd1814a commit b4c9c46

Some content is hidden

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

63 files changed

+7172
-129
lines changed

.github/workflows/integration.yml

+14-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@ on:
66
paths:
77
- '**.go'
88
- '.github/workflows/integration.yml'
9+
- '**.plush'
910
permissions:
1011
contents: read
1112
jobs:
1213
test:
13-
name: test
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
test:
18+
# List your tests here
19+
- TestWithMySuite/TestMessageComposer
20+
- TestWithMySuite/TestQueryClient
21+
- TestWithMySuite/TestInterchaintestScaffold
22+
name: ${{ matrix.test }}
1423
runs-on: ubuntu-latest
1524
steps:
1625
- uses: actions/setup-go@v4
@@ -25,5 +34,7 @@ jobs:
2534
working-directory: integration_test
2635
- name: Build
2736
run: make build
28-
- name: Test
29-
run: make integration-tests
37+
- name: Run Tests
38+
run: |
39+
cd integration_test
40+
go test -v -mod=readonly . -run=${{ matrix.test }}

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v0.2.0 (2024-05-17)
4+
5+
- Added support for generating a gRPC query client [#14](https://github.com/srdtrk/go-codegen/issues/14)
6+
- Added support for generating an [`interchaintest`](https://github.com/strangelove-ventures/interchaintest) based test suite [#45](https://github.com/srdtrk/go-codegen/issues/45).
7+
- Various API breaking changes on the CLI commands and go packages.
8+
39
## v0.1.3 (2024-04-22)
410

511
- Fixed issue [#30](https://github.com/srdtrk/go-codegen/issues/30)

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ unit-test:
2121

2222
integration-tests:
2323
@echo "Running integration tests..."
24-
@cd integration_test && go test -v -mod=readonly -tags=integration ./...
24+
@cd integration_test && go test -v -mod=readonly -run=TestWithMySuite/TestMessageComposer
25+
@cd integration_test && go test -v -mod=readonly -run=TestWithMySuite/TestInterchaintestScaffold
2526
@echo "Integration tests complete!"

README.md

+34-4
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,52 @@ Generate Go code for your CosmWasm smart contracts.
1818
go install github.com/srdtrk/go-codegen@latest
1919
```
2020

21-
The quickest way to generate Go code for your CosmWasm smart contracts. Currently, this tool only supports generating the types needed to interact
22-
with the smart contract. Support for a gRPC query client and a gRPC transaction client is planned.
21+
The quickest way to generate Go code for your CosmWasm smart contracts. Currently, this tool supports generating:
22+
23+
- Message types
24+
- A gRPC query client
25+
- An [`interchaintest`](https://github.com/strangelove-ventures/interchaintest) based test suite
2326

2427
## Usage
2528

2629
In order to generate Go code for your CosmWasm smart contract, you need to have its full API exported as a JSON file
2730
using [`cosmwasm-schema`](https://crates.io/crates/cosmwasm-schema).
2831
Once you have the JSON file, you can use it to generate the Go code.
2932

33+
### Generate messages
34+
3035
```sh
31-
go-codegen generate /path/to/contract-api.json --output /path/to/output.go --package-name mypackage
36+
go-codegen generate messages /path/to/contract-api.json --output /path/to/output.go --package-name mypackage
3237
```
3338

34-
This will generate the Go code in the specified optional output directory, if not specified, it will generate the code in `output.go` in the current directory.
39+
This will generate the Go code in the specified optional output directory, if not specified, it will generate the code in `msgs.go` in the current directory.
3540
Package name is also optional, if not specified, it will use the name of the contract.
3641

42+
### Generate gRPC query client
43+
44+
```sh
45+
go-codegen generate query-client /path/to/contract-api.json --output /path/to/output.go --package-name mypackage
46+
```
47+
48+
This will generate the Go code in the specified optional output directory, if not specified, it will generate the code in `query.go` in the current directory. Package name is also optional, if not specified, it will use the name of the contract. The generated code depends on the generated messages, the [wasmd package](https://pkg.go.dev/github.com/CosmWasm/wasmd), and the [grpc package](https://pkg.go.dev/google.golang.org/grpc). You can install them by running `go get github.com/CosmWasm/wasmd@latest` (or `go get github.com/CosmWasm/wasmd@v0.50.0` for a specific version) and `go get google.golang.org/grpc@latest` (or `go get google.golang.org/grpc@v1.63.3` for a specific version).
49+
50+
### Generate interchaintest test suite
51+
52+
```sh
53+
go-codegen interchaintest scaffold
54+
```
55+
56+
This will launch an interactive prompt to guide you through the process of generating the test suite.
57+
The scaffolded test suite will include a basic test and instructions on how to run it. This test suite will not contain any contract specific code, or tests, you will need to add them using `add-contract` command.
58+
59+
### Adding a contract to the interchaintest test suite
60+
61+
```sh
62+
go-codegen interchaintest add-contract /path/to/contract-api.json --suite-dir /path/to/suite
63+
```
64+
65+
This will add a contract to the test suite. The suite directory is the directory where the test suite is located. If not specified, it will use the current directory. The contract API JSON file is the same file that was used to generate the messages and query client.
66+
3767
## Acknowledgements
3868

3969
The Go Gopher mascot was created by [Renee French](https://reneefrench.blogspot.com/) and is licensed under the [Creative Commons 4.0 Attribution License](https://creativecommons.org/licenses/by/4.0/).

cmd/constants.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cmd
2+
3+
const (
4+
OutputFlag = "output"
5+
PackageNameFlag = "package-name"
6+
7+
YesFlag = "yes"
8+
SuiteDirFlag = "suite-dir"
9+
ContractNameFlag = "contract-name"
10+
MessagesOnlyFlag = "messages-only"
11+
12+
DebugFlag = "debug"
13+
)

0 commit comments

Comments
 (0)