Skip to content

Commit

Permalink
Cleanup and README explanations
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Jan 24, 2020
1 parent 33c4e92 commit a8fd5e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ This code was forked from the `cosmos/gaia` repository and the majority of the c

**Compatibility**: Last merge from `cosmos/gaia` was `090c545347b03e59415a18107a0a279c703c8f40` (Jan 23, 2020)

## Stability

**This is alpha software, do not run on a production system.** Notably, we currently provide **no migration path** not even "dump state and restart" to move to future versions. At **beta** we will begin to offer migrations and better backwards compatibility guarantees.

With the `v0.6.0` tag, we are entering semver. That means anything with `v0.6.x` tags is compatible. We will have a series of minor version updates prior to `v1.0.0`, where we offer strong backwards compatibility guarantees. In particular, work has begun in the `cosmwasm` library on `v0.7`, which will change many internal APIs, in order to allow adding other languages for writing smart contracts. We hope to stabilize much of this well before `v1`, but we are still in the process of learning from real-world use-cases

## Encoding

We use standard cosmos-sdk encoding (amino) for all sdk Messages. However, the message body sent to all contracts, as well as the internal state is encoded using JSON. Cosmwasm allows arbitrary bytes with the contract itself responsible for decodng. For better UX, we often use `json.RawMessage` to contain these bytes, which enforces that it is valid json, but also give a much more readable interface. If you want to use another encoding in the contracts, that is a relatively minor change to wasmd but would currently require a fork. Please open in issue if this is important for your use case.

## Quick Start

```
Expand Down
16 changes: 7 additions & 9 deletions x/wasm/internal/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
)

func TestQueryContractState(t *testing.T) {
type model = types.Model

tempDir, err := ioutil.TempDir("", "wasm")
require.NoError(t, err)
defer os.RemoveAll(tempDir)
Expand Down Expand Up @@ -55,18 +53,18 @@ func TestQueryContractState(t *testing.T) {
specs := map[string]struct {
srcPath []string
srcReq abci.RequestQuery
// smart queries return raw bytes from contract not []model
// smart queries return raw bytes from contract not []types.Model
// if this is set, then we just compare - (should be json encoded string)
expSmartRes string
// if success and expSmartRes is not set, we parse into []model and compare
// if success and expSmartRes is not set, we parse into []types.Model and compare
expModelLen int
expModelContains []model
expModelContains []types.Model
expErr *sdkErrors.Error
}{
"query all": {
srcPath: []string{QueryGetContractState, addr.String(), QueryMethodContractStateAll},
expModelLen: 3,
expModelContains: []model{
expModelContains: []types.Model{
{Key: []byte("foo"), Value: []byte(`"bar"`)},
{Key: []byte{0x0, 0x1}, Value: []byte(`{"count":8}`)},
},
Expand All @@ -75,13 +73,13 @@ func TestQueryContractState(t *testing.T) {
srcPath: []string{QueryGetContractState, addr.String(), QueryMethodContractStateRaw},
srcReq: abci.RequestQuery{Data: []byte("foo")},
expModelLen: 1,
expModelContains: []model{{Key: []byte("foo"), Value: []byte(`"bar"`)}},
expModelContains: []types.Model{{Key: []byte("foo"), Value: []byte(`"bar"`)}},
},
"query raw binary key": {
srcPath: []string{QueryGetContractState, addr.String(), QueryMethodContractStateRaw},
srcReq: abci.RequestQuery{Data: []byte{0x0, 0x1}},
expModelLen: 1,
expModelContains: []model{{Key: []byte{0x0, 0x1}, Value: []byte(`{"count":8}`)}},
expModelContains: []types.Model{{Key: []byte{0x0, 0x1}, Value: []byte(`{"count":8}`)}},
},
"query smart": {
srcPath: []string{QueryGetContractState, addr.String(), QueryMethodContractStateSmart},
Expand Down Expand Up @@ -130,7 +128,7 @@ func TestQueryContractState(t *testing.T) {
}

// otherwise, check returned models
var r []model
var r []types.Model
if spec.expErr == nil {
require.NoError(t, json.Unmarshal(binResult, &r))
require.NotNil(t, r)
Expand Down

0 comments on commit a8fd5e9

Please sign in to comment.