Skip to content

Commit

Permalink
feat: added interchaintest suite and gRPC query client generators (#47)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
srdtrk authored May 17, 2024
1 parent bd1814a commit b4c9c46
Show file tree
Hide file tree
Showing 63 changed files with 7,172 additions and 129 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@ on:
paths:
- '**.go'
- '.github/workflows/integration.yml'
- '**.plush'
permissions:
contents: read
jobs:
test:
name: test
strategy:
fail-fast: false
matrix:
test:
# List your tests here
- TestWithMySuite/TestMessageComposer
- TestWithMySuite/TestQueryClient
- TestWithMySuite/TestInterchaintestScaffold
name: ${{ matrix.test }}
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
Expand All @@ -25,5 +34,7 @@ jobs:
working-directory: integration_test
- name: Build
run: make build
- name: Test
run: make integration-tests
- name: Run Tests
run: |
cd integration_test
go test -v -mod=readonly . -run=${{ matrix.test }}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v0.2.0 (2024-05-17)

- Added support for generating a gRPC query client [#14](https://github.com/srdtrk/go-codegen/issues/14)
- Added support for generating an [`interchaintest`](https://github.com/strangelove-ventures/interchaintest) based test suite [#45](https://github.com/srdtrk/go-codegen/issues/45).
- Various API breaking changes on the CLI commands and go packages.

## v0.1.3 (2024-04-22)

- Fixed issue [#30](https://github.com/srdtrk/go-codegen/issues/30)
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ unit-test:

integration-tests:
@echo "Running integration tests..."
@cd integration_test && go test -v -mod=readonly -tags=integration ./...
@cd integration_test && go test -v -mod=readonly -run=TestWithMySuite/TestMessageComposer
@cd integration_test && go test -v -mod=readonly -run=TestWithMySuite/TestInterchaintestScaffold
@echo "Integration tests complete!"
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,52 @@ Generate Go code for your CosmWasm smart contracts.
go install github.com/srdtrk/go-codegen@latest
```

The quickest way to generate Go code for your CosmWasm smart contracts. Currently, this tool only supports generating the types needed to interact
with the smart contract. Support for a gRPC query client and a gRPC transaction client is planned.
The quickest way to generate Go code for your CosmWasm smart contracts. Currently, this tool supports generating:

- Message types
- A gRPC query client
- An [`interchaintest`](https://github.com/strangelove-ventures/interchaintest) based test suite

## Usage

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

### Generate messages

```sh
go-codegen generate /path/to/contract-api.json --output /path/to/output.go --package-name mypackage
go-codegen generate messages /path/to/contract-api.json --output /path/to/output.go --package-name mypackage
```

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.
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.
Package name is also optional, if not specified, it will use the name of the contract.

### Generate gRPC query client

```sh
go-codegen generate query-client /path/to/contract-api.json --output /path/to/output.go --package-name mypackage
```

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/[email protected]` for a specific version) and `go get google.golang.org/grpc@latest` (or `go get google.golang.org/[email protected]` for a specific version).

### Generate interchaintest test suite

```sh
go-codegen interchaintest scaffold
```

This will launch an interactive prompt to guide you through the process of generating the test suite.
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.

### Adding a contract to the interchaintest test suite

```sh
go-codegen interchaintest add-contract /path/to/contract-api.json --suite-dir /path/to/suite
```

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.

## Acknowledgements

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/).
Expand Down
13 changes: 13 additions & 0 deletions cmd/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cmd

const (
OutputFlag = "output"
PackageNameFlag = "package-name"

YesFlag = "yes"
SuiteDirFlag = "suite-dir"
ContractNameFlag = "contract-name"
MessagesOnlyFlag = "messages-only"

DebugFlag = "debug"
)
Loading

0 comments on commit b4c9c46

Please sign in to comment.