Skip to content

Commit

Permalink
Merge pull request #47 from discoverdefiteam/v1.0.0
Browse files Browse the repository at this point in the history
v1.0.0 prep
  • Loading branch information
discoverdefiteam authored Apr 5, 2023
2 parents 92ba63a + a2e8d2c commit 22f9b29
Show file tree
Hide file tree
Showing 193 changed files with 11,131 additions and 9,289 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2.1
executors:
golang:
docker:
- image: cimg/go:1.19
- image: cimg/go:1.20.0

commands:
make:
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:

lint:
docker:
- image: golangci/golangci-lint:v1.50.1
- image: golangci/golangci-lint:v1.51.1
steps:
- checkout
- run:
Expand Down Expand Up @@ -124,7 +124,7 @@ jobs:
- run:
name: Run simulations
command: |
make test-sim-multi-seed-short
make test-sim-multi-seed-short test-sim-import-export test-sim-deterministic
- store_artifacts:
path: /tmp

Expand Down
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ updates:
- 0.14.0-beta4
- 0.14.0-beta5
- 0.14.0-rc1
- dependency-name: github.com/tendermint/tendermint
- dependency-name: github.com/cometbft/cometbft
versions:
- 0.34.10
- 0.34.4
Expand All @@ -40,6 +40,6 @@ updates:
- dependency-name: github.com/spf13/cobra
versions:
- 1.1.2
- dependency-name: github.com/tendermint/tm-db
- dependency-name: github.com/cometbft/cometbft-db
versions:
- 0.6.4
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: 1.20.0
go-version: "1.20"
- run: go build ./...

tidy:
Expand All @@ -26,12 +26,12 @@ jobs:
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: 1.20.0
go-version: "1.20"
- run: |
go mod tidy
CHANGES_IN_REPO=$(git status --porcelain)
if [[ -n "$CHANGES_IN_REPO" ]]; then
echo "Repository is dirty. Showing 'git status' and 'git --no-pager diff' for debugging now:"
git status && git --no-pager diff
exit 1
fi
fi
2 changes: 1 addition & 1 deletion .github/workflows/codacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ jobs:
- name: Upload SARIF results file
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: results.sarif
sarif_file: results.sarif
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3.3.0
uses: actions/checkout@v3.5.0

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql-cosmos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.20.0
go-version: "1.20"
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand All @@ -37,4 +37,4 @@ jobs:
run: make build

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v2
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ jobs:
uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: "1.20"
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: "go"
queries: crypto-com/cosmos-sdk-codeql@main,security-and-quality

- name: Build
run: make build

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: 'Checkout Repository'
uses: actions/checkout@v3
- name: 'Dependency Review'
uses: actions/dependency-review-action@v3
uses: actions/dependency-review-action@v3
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.20.0
go-version: "1.20"
- uses: actions/checkout@v3

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout 10m
args: --timeout 10m
6 changes: 3 additions & 3 deletions .github/workflows/proto-buf-publisher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.3.0
- uses: bufbuild/buf-setup-action@v1.15.1
- uses: actions/checkout@v3.5.0
- uses: bufbuild/buf-setup-action@v1.16.0

# lint checks
- uses: bufbuild/buf-lint-action@v1
Expand All @@ -29,7 +29,7 @@ jobs:
#- uses: bufbuild/buf-breaking-action@v1
# with:
# input: 'proto'
# against: 'https://github.com/CosmWasm/wasmd.git#branch=master'
# against: 'https://github.com/terpnetwork/terp-core.git#branch=master'

# publish proto files
- uses: bufbuild/buf-push-action@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.20.0
go-version: "1.20"
- name: Checkout code
uses: actions/checkout@v3
- name: Test
run: go test ./...
run: go test ./...
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ linters:
- staticcheck
- stylecheck
- typecheck
- thelper
- unconvert
- unparam
- unused
Expand Down
14 changes: 11 additions & 3 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ queue_rules:
- "#approved-reviews-by>0"

pull_request_rules:
- name: backport patches to sdk47 feature branch
- name: backport patches to main branch
conditions:
- base=releases/v0.3x
- label=backport/main
actions:
backport:
branches:
- main
- name: backport patches to sdk45 release branch
conditions:
- base=main
- label=backport/sdk47-dev
- label=backport/v0.3x
actions:
backport:
branches:
- develop_sdk47
- releases/v0.3x
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Contributing to this repo can mean many things, such as participating in
discussion or proposing code changes. To ensure a smooth workflow for all
contributors, the general procedure for contributing has been established:

1. Start by browsing [new issues](https://github.com/CosmWasm/wasmd/issues).
* Looking for a good place to start contributing? How about checking out some [good first issues](https://github.com/CosmWasm/wasmd/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) or [bugs](https://github.com/CosmWasm/wasmd/issues?q=is%3Aopen+is%3Aissue+label%3Abug)?
1. Start by browsing [new issues](https://github.com/terpnetwork/terp-core/issues).
* Looking for a good place to start contributing? How about checking out some [good first issues](https://github.com/terpnetwork/terp-core/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) or [bugs](https://github.com/terpnetwork/terp-core/issues?q=is%3Aopen+is%3Aissue+label%3Abug)?
2. Determine whether a GitHub issue or discussion is more appropriate for your needs:
1. If the issue you want addressed is a specific proposal or a bug, then open a [new issue](https://github.com/CosmWasm/wasmd/issues/new).
2. Review existing [issues](https://github.com/CosmWasm/wasmd/issues) to find an issue you'd like to help with.
1. If the issue you want addressed is a specific proposal or a bug, then open a [new issue](https://github.com/terpnetwork/terp-core/issues/new).
2. Review existing [issues](https://github.com/terpnetwork/terp-core/issues) to find an issue you'd like to help with.
3. Participate in thoughtful discussion on that issue.
4. If you would like to contribute:
1. Ensure that the proposal has been accepted.
Expand Down
24 changes: 12 additions & 12 deletions INTEGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ to `bank` and `staking`... more below on [customization](#Adding-Custom-Hooks)).

The requirement here is that you have imported the standard sdk modules
from the Cosmos SDK, and enabled them in `app.go`. If so, you can just look
at [`wasmd/app/app.go`](https://github.com/CosmWasm/wasmd/blob/master/app/app.go#)
at [`wasmd/app/app.go`](https://github.com/terpnetwork/terp-core/blob/master/app/app.go#)
for how to do so (just search there for lines with `wasm`).

`wasmd` also comes with 2 custom `ante handlers`:
* `CountTXDecorator` adds the TX position in the block into the context and passes it to the contracts
* `LimitSimulationGasDecorator` prevents an "infinite gas" query

In order to support these features you would need to add our custom
ante handlers into the `ante handler chain` as in: [`app/ante.go`](https://github.com/CosmWasm/wasmd/blob/master/app/ante.go)
ante handlers into the `ante handler chain` as in: [`app/ante.go`](https://github.com/terpnetwork/terp-core/blob/master/app/ante.go)

### Copied into your app

Expand Down Expand Up @@ -122,7 +122,7 @@ token contracts, your exchange code can simply call `wasm.Keeper.Execute`
with a properly formatted message to move funds, or `wasm.Keeper.SmartQuery`
to check balances.

If you look at the unit tests in [`x/wasm/internal/keeper`](https://github.com/CosmWasm/wasmd/tree/master/x/wasm/internal/keeper),
If you look at the unit tests in [`x/wasm/internal/keeper`](https://github.com/terpnetwork/terp-core/tree/master/x/wasm/internal/keeper),
it should be pretty straight forward.

### Extending the Contract Interface
Expand Down Expand Up @@ -165,22 +165,22 @@ please **do not make these changes to `x/wasm`**.
We will add a new module, eg. `x/contracts`, that will contain custom
bindings between CosmWasm contracts and your native modules. There are two entry points
for you to use. The first is
[`CustomQuerier`](https://github.com/CosmWasm/wasmd/blob/v0.8.0-rc1/x/wasm/internal/keeper/query_plugins.go#L35),
[`CustomQuerier`](https://github.com/terpnetwork/terp-core/blob/v0.8.0-rc1/x/wasm/internal/keeper/query_plugins.go#L35),
which allows you to handle your custom queries. The second is
[`CustomEncoder`](https://github.com/CosmWasm/wasmd/blob/v0.8.0-rc1/x/wasm/internal/keeper/handler_plugin.go#L30)
[`CustomEncoder`](https://github.com/terpnetwork/terp-core/blob/v0.8.0-rc1/x/wasm/internal/keeper/handler_plugin.go#L30)
which allows you to convert the `CosmosMsg::Custom(YourMessage)` types to `[]sdk.Msg` to be dispatched.

Writing stubs for these is rather simple. You can look at the `reflect_test.go` file to see this in action.
In particular, here [we define a `CustomQuerier`](https://github.com/CosmWasm/wasmd/blob/v0.8.0-rc1/x/wasm/internal/keeper/reflect_test.go#L355-L385),
and here [we define a `CustomHandler`](https://github.com/CosmWasm/wasmd/blob/v0.8.0-rc1/x/wasm/internal/keeper/reflect_test.go#L303-L353).
In particular, here [we define a `CustomQuerier`](https://github.com/terpnetwork/terp-core/blob/v0.8.0-rc1/x/wasm/internal/keeper/reflect_test.go#L355-L385),
and here [we define a `CustomHandler`](https://github.com/terpnetwork/terp-core/blob/v0.8.0-rc1/x/wasm/internal/keeper/reflect_test.go#L303-L353).
This code is responsible to take `json.RawMessage` from the raw bytes serialized from your custom types in rust and parse it into
Go structs. Then take these go structs and properly convert them for your custom SDK modules.

You can look at the implementations for the `staking` module to see how to build these for non-trivial
cases, including passing in the `Keeper` via a closure. Here we
[encode staking messages](https://github.com/CosmWasm/wasmd/blob/v0.8.0-rc1/x/wasm/internal/keeper/handler_plugin.go#L114-L192).
[encode staking messages](https://github.com/terpnetwork/terp-core/blob/v0.8.0-rc1/x/wasm/internal/keeper/handler_plugin.go#L114-L192).
Note that withdraw returns 2 messages, which is an option you can use if needed to translate into native messages.
When we [handle staking queries](https://github.com/CosmWasm/wasmd/blob/v0.8.0-rc1/x/wasm/internal/keeper/query_plugins.go#L109-L172)
When we [handle staking queries](https://github.com/terpnetwork/terp-core/blob/v0.8.0-rc1/x/wasm/internal/keeper/query_plugins.go#L109-L172)
we take in a `Keeper in the closure` and dispatch the custom `QueryRequest` from the contract to the native `Keeper` interface,
then encodes a response. When defining the return types, note that for proper parsing in the Rust contract, you
should properly name the JSON fields and use the `omitempty` keyword if Rust expects `Option<T>`. You must also use
Expand All @@ -193,13 +193,13 @@ The first step is to write an integration test with a contract compiled with you
then you need to configure this in `app.go`.

For the test cases, you must
[define the supported feature set](https://github.com/CosmWasm/wasmd/blob/ade03a1d39a9b8882e9a1ce80572d39d57bb9bc3/x/wasm/internal/keeper/reflect_test.go#L52)
[define the supported feature set](https://github.com/terpnetwork/terp-core/blob/ade03a1d39a9b8882e9a1ce80572d39d57bb9bc3/x/wasm/internal/keeper/reflect_test.go#L52)
to include your custom name (remember `requires_XYZ` above?). Then, when creating `TestInput`,
you can [pass in your custom encoder and querier](https://github.com/CosmWasm/wasmd/blob/ade03a1d39a9b8882e9a1ce80572d39d57bb9bc3/x/wasm/internal/keeper/reflect_test.go#L52).
you can [pass in your custom encoder and querier](https://github.com/terpnetwork/terp-core/blob/ade03a1d39a9b8882e9a1ce80572d39d57bb9bc3/x/wasm/internal/keeper/reflect_test.go#L52).
Run a few tests with your compiled contract, ideally exercising the majority of the interfaces to ensure that all parsing between the contract and
the SDK is implemented properly.

Once you have tested this and are happy with the results, you can wire it up in `app.go`.
Just edit [the default `NewKeeper` constructor](https://github.com/CosmWasm/wasmd/blob/v0.8.0-rc1/app/app.go#L257-L258)
Just edit [the default `NewKeeper` constructor](https://github.com/terpnetwork/terp-core/blob/v0.8.0-rc1/app/app.go#L257-L258)
to have the proper `availableCapabilities` and pass in the `CustomEncoder` and `CustomQuerier` as the last two arguments to `NewKeeper`.
Now you can compile your chain and upload your custom contracts on it.
24 changes: 13 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ test-sim-import-export: runsim

test-sim-multi-seed-short: runsim
@echo "Running short multi-seed application simulation. This may take awhile!"
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 50 10 TestFullAppSimulation
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 50 5 TestFullAppSimulation

test-sim-deterministic: runsim
@echo "Running short multi-seed application simulation. This may take awhile!"
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 1 1 TestAppStateDeterminism


###############################################################################
### Linting ###
Expand All @@ -159,32 +164,29 @@ format-tools:

lint: format-tools
golangci-lint run --tests=false
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*_test.go" | xargs gofumpt -d -s

find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*_test.go" | xargs gofumpt -d
format: format-tools
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gofumpt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gofumpt -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs goimports -w -local github.com/terpnetwork/terpd


###############################################################################
### Protobuf ###
###############################################################################
PROTO_BUILDER_IMAGE=tendermintdev/sdk-proto-gen:v0.7
PROTO_FORMATTER_IMAGE=tendermintdev/docker-build-proto@sha256:aabcfe2fc19c31c0f198d4cd26393f5e5ca9502d7ea3feafbfe972448fee7cae
protoVer=0.11.6
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)

proto-all: proto-format proto-lint proto-gen format

proto-gen:
@echo "Generating Protobuf files"
$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(PROTO_BUILDER_IMAGE) sh ./scripts/protocgen.sh
@$(protoImage) sh ./scripts/protocgen.sh

proto-format:
@echo "Formatting Protobuf files"
$(DOCKER) run --rm -v $(CURDIR):/workspace \
--workdir /workspace $(PROTO_FORMATTER_IMAGE) \
find ./ -name *.proto -exec clang-format -i {} \;

@$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \;
proto-swagger-gen:
@./scripts/protoc-swagger-gen.sh

Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ A VM can support one or more contract-VM interface versions. The interface
version is communicated by the contract via a Wasm export. This is the current
compatibility list:

| terpd | wasmvm | cosmwasm-vm | cosmwasm-std |
|-------|--------------|-------------|--------------|
| v1.0 | v1.2.0 | | 1.0-1.2 |
| v0.4.0| v1.2.0 | | 1.0-1.1 |
| terpd | wasmvm | cosmwasm-vm | cosmwasm-std |
|--------|--------------|-------------|--------------|
| v1.0.0 | v1.2.0 | | 1.0-1.2 |
| v0.5.0 | v1.2.0 | | 1.0-1.2 |
| v0.4.0 | v1.2.0 | | 1.0-1.1 |


Note: `cosmwasm_std v1.0` means it supports contracts compiled by any `v1.0.0-betaX` or `1.0.x`.
Expand Down Expand Up @@ -73,7 +74,7 @@ your use case.
make install
make test
```
if you are using a linux without X or headless linux, look at [this article](https://ahelpme.com/linux/dbusexception-could-not-get-owner-of-name-org-freedesktop-secrets-no-such-name) or [#31](https://github.com/CosmWasm/wasmd/issues/31#issuecomment-577058321).
if you are using a linux without X or headless linux, look at [this article](https://ahelpme.com/linux/dbusexception-could-not-get-owner-of-name-org-freedesktop-secrets-no-such-name) or [#31](https://github.com/terpnetwork/terp-core/issues/31#issuecomment-577058321).

## Protobuf
The protobuf files for this project are published automatically to the [buf repository](https://buf.build/) to make integration easier:
Expand Down
2 changes: 1 addition & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ testnet and upgrade path, and the default `wasmd` will never have a registered h
on master. In this case, we make a `musselnet` branch off of `v0.14.0` just
registering one handler with a given name.

Look at [PR 351](https://github.com/CosmWasm/wasmd/pull/351/files) for an example
Look at [PR 351](https://github.com/terpnetwork/terp-core/pull/351/files) for an example
of a minimal handler. We do not make any state migrations, but rather use this
as a flag to coordinate all validators to stop the old version at one height, and
start the specified v2 version on the next block.
Expand Down
Loading

0 comments on commit 22f9b29

Please sign in to comment.