Skip to content

Commit

Permalink
Merge pull request #216 from CosmWasm/upgrade-to-rc1
Browse files Browse the repository at this point in the history
Update to cosmwasm v0.14.0-rc1
  • Loading branch information
webmaster128 authored Apr 28, 2021
2 parents 5e02dd7 + 6f83e32 commit d2e22b4
Show file tree
Hide file tree
Showing 16 changed files with 221 additions and 89 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ default = []
backtraces = []

[dependencies]
cosmwasm-std = { git = "https://github.com/CosmWasm/cosmwasm", rev = "v0.14.0-beta5", features = ["iterator", "staking", "stargate"] }
cosmwasm-vm = { git = "https://github.com/CosmWasm/cosmwasm", rev = "v0.14.0-beta5", features = ["iterator", "staking", "stargate"] }
cosmwasm-std = { git = "https://github.com/CosmWasm/cosmwasm", rev = "v0.14.0-rc1", features = ["iterator", "staking", "stargate"] }
cosmwasm-vm = { git = "https://github.com/CosmWasm/cosmwasm", rev = "v0.14.0-rc1", features = ["iterator", "staking", "stargate"] }
errno = "0.2"
serde_json = "1.0"
thiserror = "1.0"
Expand Down
34 changes: 17 additions & 17 deletions api/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func TestGetMetrics(t *testing.T) {
assert.Equal(t, &types.Metrics{
HitsFsCache: 1,
ElementsMemoryCache: 1,
SizeMemoryCache: 3428923,
SizeMemoryCache: 3432787,
}, metrics)

// Instantiate 2
Expand All @@ -223,7 +223,7 @@ func TestGetMetrics(t *testing.T) {
HitsMemoryCache: 1,
HitsFsCache: 1,
ElementsMemoryCache: 1,
SizeMemoryCache: 3428923,
SizeMemoryCache: 3432787,
}, metrics)

// Pin
Expand All @@ -238,8 +238,8 @@ func TestGetMetrics(t *testing.T) {
HitsFsCache: 1,
ElementsPinnedMemoryCache: 1,
ElementsMemoryCache: 1,
SizePinnedMemoryCache: 3428923,
SizeMemoryCache: 3428923,
SizePinnedMemoryCache: 3432787,
SizeMemoryCache: 3432787,
}, metrics)

// Instantiate 3
Expand All @@ -256,8 +256,8 @@ func TestGetMetrics(t *testing.T) {
HitsFsCache: 1,
ElementsPinnedMemoryCache: 1,
ElementsMemoryCache: 1,
SizePinnedMemoryCache: 3428923,
SizeMemoryCache: 3428923,
SizePinnedMemoryCache: 3432787,
SizeMemoryCache: 3432787,
}, metrics)

// Unpin
Expand All @@ -274,7 +274,7 @@ func TestGetMetrics(t *testing.T) {
ElementsPinnedMemoryCache: 0,
ElementsMemoryCache: 1,
SizePinnedMemoryCache: 0,
SizeMemoryCache: 3428923,
SizeMemoryCache: 3432787,
}, metrics)

// Instantiate 4
Expand All @@ -292,7 +292,7 @@ func TestGetMetrics(t *testing.T) {
ElementsPinnedMemoryCache: 0,
ElementsMemoryCache: 1,
SizePinnedMemoryCache: 0,
SizeMemoryCache: 3428923,
SizeMemoryCache: 3432787,
}, metrics)
}

Expand All @@ -319,7 +319,7 @@ func TestInstantiate(t *testing.T) {
res, cost, err := Instantiate(cache, checksum, env, info, msg, &igasMeter, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
require.NoError(t, err)
requireOkResponse(t, res, 0)
assert.Equal(t, uint64(0x92d1), cost)
assert.Equal(t, uint64(0x8e99), cost)

var result types.ContractResult
err = json.Unmarshal(res, &result)
Expand Down Expand Up @@ -350,7 +350,7 @@ func TestExecute(t *testing.T) {
diff := time.Now().Sub(start)
require.NoError(t, err)
requireOkResponse(t, res, 0)
assert.Equal(t, uint64(0x92d1), cost)
assert.Equal(t, uint64(0x8e99), cost)
t.Logf("Time (%d gas): %s\n", cost, diff)

// execute with the same store
Expand All @@ -363,7 +363,7 @@ func TestExecute(t *testing.T) {
res, cost, err = Execute(cache, checksum, env, info, []byte(`{"release":{}}`), &igasMeter2, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
diff = time.Now().Sub(start)
require.NoError(t, err)
assert.Equal(t, uint64(0xf364), cost)
assert.Equal(t, uint64(0xef2c), cost)
t.Logf("Time (%d gas): %s\n", cost, diff)

// make sure it read the balance properly and we got 250 atoms
Expand Down Expand Up @@ -405,7 +405,7 @@ func TestExecuteCpuLoop(t *testing.T) {
diff := time.Now().Sub(start)
require.NoError(t, err)
requireOkResponse(t, res, 0)
assert.Equal(t, uint64(0x92d1), cost)
assert.Equal(t, uint64(0x8e99), cost)
t.Logf("Time (%d gas): %s\n", cost, diff)

// execute a cpu loop
Expand Down Expand Up @@ -556,7 +556,7 @@ func TestMultipleInstances(t *testing.T) {
require.NoError(t, err)
requireOkResponse(t, res, 0)
// we now count wasm gas charges and db writes
assert.Equal(t, uint64(0x91b0), cost)
assert.Equal(t, uint64(0x8d78), cost)

// instance2 controlled by mary
gasMeter2 := NewMockGasMeter(TESTING_GAS_LIMIT)
Expand All @@ -567,14 +567,14 @@ func TestMultipleInstances(t *testing.T) {
res, cost, err = Instantiate(cache, checksum, env, info, msg, &igasMeter2, store2, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
require.NoError(t, err)
requireOkResponse(t, res, 0)
assert.Equal(t, uint64(0x9255), cost)
assert.Equal(t, uint64(0x8e1d), cost)

// fail to execute store1 with mary
resp := exec(t, cache, checksum, "mary", store1, api, querier, 0x7e26)
resp := exec(t, cache, checksum, "mary", store1, api, querier, 0x79ee)
require.Equal(t, "Unauthorized", resp.Err)

// succeed to execute store1 with fred
resp = exec(t, cache, checksum, "fred", store1, api, querier, 0xf2f0)
resp = exec(t, cache, checksum, "fred", store1, api, querier, 0xeeb8)
require.Equal(t, "", resp.Err)
require.Equal(t, 1, len(resp.Ok.Messages))
attributes := resp.Ok.Attributes
Expand All @@ -583,7 +583,7 @@ func TestMultipleInstances(t *testing.T) {
require.Equal(t, "bob", attributes[1].Value)

// succeed to execute store2 with mary
resp = exec(t, cache, checksum, "mary", store2, api, querier, 0xf32a)
resp = exec(t, cache, checksum, "mary", store2, api, querier, 0xeef2)
require.Equal(t, "", resp.Err)
require.Equal(t, 1, len(resp.Ok.Messages))
attributes = resp.Ok.Attributes
Expand Down
7 changes: 3 additions & 4 deletions api/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ const MOCK_CONTRACT_ADDR = "contract"
func MockEnv() types.Env {
return types.Env{
Block: types.BlockInfo{
Height: 123,
Time: 1578939743,
TimeNanos: 987654321,
ChainID: "foobar",
Height: 123,
Time: 1578939743_987654321,
ChainID: "foobar",
},
Contract: types.ContractInfo{
Address: MOCK_CONTRACT_ADDR,
Expand Down
Binary file modified api/testdata/hackatom.wasm
Binary file not shown.
Binary file modified api/testdata/ibc_reflect.wasm
Binary file not shown.
Binary file modified api/testdata/queue.wasm
Binary file not shown.
Binary file modified api/testdata/reflect.wasm
Binary file not shown.
36 changes: 27 additions & 9 deletions ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ func TestIBCHandshake(t *testing.T) {
channel = api.MockIBCChannel(CHANNEL_ID, types.Ordered, IBC_VERSION)
res, _, err := vm.IBCChannelConnect(checksum, env, channel, store, *goapi, querier, gasMeter2, TESTING_GAS_LIMIT)
require.NoError(t, err)
require.Equal(t, 1, len(res.Messages))
require.Equal(t, 0, len(res.Messages))
require.Equal(t, 1, len(res.Submessages))

// make sure it read the balance properly and we got 250 atoms
dispatch := res.Messages[0]
dispatch := res.Submessages[0].Msg
require.NotNil(t, dispatch.Wasm, "%#v", dispatch)
require.NotNil(t, dispatch.Wasm.Instantiate, "%#v", dispatch)
init := dispatch.Wasm.Instantiate
Expand Down Expand Up @@ -177,20 +178,37 @@ func TestIBCPacketDispatch(t *testing.T) {
store.SetGasMeter(gasMeter3)
// completes and dispatches message to create reflect contract
channel = api.MockIBCChannel(CHANNEL_ID, types.Ordered, IBC_VERSION)
_, _, err = vm.IBCChannelConnect(checksum, env, channel, store, *goapi, querier, gasMeter3, TESTING_GAS_LIMIT)
res, _, err := vm.IBCChannelConnect(checksum, env, channel, store, *goapi, querier, gasMeter3, TESTING_GAS_LIMIT)
require.NoError(t, err)
require.Equal(t, 0, len(res.Messages))
require.Equal(t, 1, len(res.Submessages))
id := res.Submessages[0].ID

// mock reflect init callback (to store address)
gasMeter4 := api.NewMockGasMeter(TESTING_GAS_LIMIT)
store.SetGasMeter(gasMeter4)
handleMsg := IBCExecuteMsg{
InitCallback: InitCallback{
ID: CHANNEL_ID,
ContractAddr: REFLECT_ADDR,
reply := types.Reply{
ID: id,
Result: types.SubcallResult{
Ok: &types.SubcallResponse{
Events: types.Events{{
Type: "message",
Attributes: types.EventAttributes{
{
Key: "module",
Value: "wasm",
},
{
Key: "contract_address",
Value: REFLECT_ADDR,
},
},
}},
Data: nil,
},
},
}
info = api.MockInfo(REFLECT_ADDR, nil)
_, _, err = vm.Execute(checksum, env, info, toBytes(t, handleMsg), store, *goapi, querier, gasMeter4, TESTING_GAS_LIMIT)
_, _, err = vm.Reply(checksum, env, reply, store, *goapi, querier, gasMeter4, TESTING_GAS_LIMIT)
require.NoError(t, err)

// ensure the channel is registered
Expand Down
16 changes: 8 additions & 8 deletions lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestGetMetrics(t *testing.T) {
assert.Equal(t, &types.Metrics{
HitsFsCache: 1,
ElementsMemoryCache: 1,
SizeMemoryCache: 3428923,
SizeMemoryCache: 3432787,
}, metrics)

// Instantiate 2
Expand All @@ -146,7 +146,7 @@ func TestGetMetrics(t *testing.T) {
HitsMemoryCache: 1,
HitsFsCache: 1,
ElementsMemoryCache: 1,
SizeMemoryCache: 3428923,
SizeMemoryCache: 3432787,
}, metrics)

// Pin
Expand All @@ -161,8 +161,8 @@ func TestGetMetrics(t *testing.T) {
HitsFsCache: 1,
ElementsPinnedMemoryCache: 1,
ElementsMemoryCache: 1,
SizePinnedMemoryCache: 3428923,
SizeMemoryCache: 3428923,
SizePinnedMemoryCache: 3432787,
SizeMemoryCache: 3432787,
}, metrics)

// Instantiate 3
Expand All @@ -180,8 +180,8 @@ func TestGetMetrics(t *testing.T) {
HitsFsCache: 1,
ElementsPinnedMemoryCache: 1,
ElementsMemoryCache: 1,
SizePinnedMemoryCache: 3428923,
SizeMemoryCache: 3428923,
SizePinnedMemoryCache: 3432787,
SizeMemoryCache: 3432787,
}, metrics)

// Unpin
Expand All @@ -198,7 +198,7 @@ func TestGetMetrics(t *testing.T) {
ElementsPinnedMemoryCache: 0,
ElementsMemoryCache: 1,
SizePinnedMemoryCache: 0,
SizeMemoryCache: 3428923,
SizeMemoryCache: 3432787,
}, metrics)

// Instantiate 4
Expand All @@ -217,6 +217,6 @@ func TestGetMetrics(t *testing.T) {
ElementsPinnedMemoryCache: 0,
ElementsMemoryCache: 1,
SizePinnedMemoryCache: 0,
SizeMemoryCache: 3428923,
SizeMemoryCache: 3432787,
}, metrics)
}
Loading

0 comments on commit d2e22b4

Please sign in to comment.