Skip to content

Commit 01153f8

Browse files
authored
Merge pull request #225 from CosmWasm/cosmwasm-0.15
Cosmwasm 0.15
2 parents 8e89099 + eaf4a2a commit 01153f8

File tree

13 files changed

+424
-300
lines changed

13 files changed

+424
-300
lines changed

api/lib_test.go

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func TestGetMetrics(t *testing.T) {
208208
assert.Equal(t, &types.Metrics{
209209
HitsFsCache: 1,
210210
ElementsMemoryCache: 1,
211-
SizeMemoryCache: 3432787,
211+
SizeMemoryCache: 2953616,
212212
}, metrics)
213213

214214
// Instantiate 2
@@ -223,7 +223,7 @@ func TestGetMetrics(t *testing.T) {
223223
HitsMemoryCache: 1,
224224
HitsFsCache: 1,
225225
ElementsMemoryCache: 1,
226-
SizeMemoryCache: 3432787,
226+
SizeMemoryCache: 2953616,
227227
}, metrics)
228228

229229
// Pin
@@ -238,8 +238,8 @@ func TestGetMetrics(t *testing.T) {
238238
HitsFsCache: 1,
239239
ElementsPinnedMemoryCache: 1,
240240
ElementsMemoryCache: 1,
241-
SizePinnedMemoryCache: 3432787,
242-
SizeMemoryCache: 3432787,
241+
SizePinnedMemoryCache: 2953616,
242+
SizeMemoryCache: 2953616,
243243
}, metrics)
244244

245245
// Instantiate 3
@@ -256,8 +256,8 @@ func TestGetMetrics(t *testing.T) {
256256
HitsFsCache: 1,
257257
ElementsPinnedMemoryCache: 1,
258258
ElementsMemoryCache: 1,
259-
SizePinnedMemoryCache: 3432787,
260-
SizeMemoryCache: 3432787,
259+
SizePinnedMemoryCache: 2953616,
260+
SizeMemoryCache: 2953616,
261261
}, metrics)
262262

263263
// Unpin
@@ -274,7 +274,7 @@ func TestGetMetrics(t *testing.T) {
274274
ElementsPinnedMemoryCache: 0,
275275
ElementsMemoryCache: 1,
276276
SizePinnedMemoryCache: 0,
277-
SizeMemoryCache: 3432787,
277+
SizeMemoryCache: 2953616,
278278
}, metrics)
279279

280280
// Instantiate 4
@@ -292,7 +292,7 @@ func TestGetMetrics(t *testing.T) {
292292
ElementsPinnedMemoryCache: 0,
293293
ElementsMemoryCache: 1,
294294
SizePinnedMemoryCache: 0,
295-
SizeMemoryCache: 3432787,
295+
SizeMemoryCache: 2953616,
296296
}, metrics)
297297
}
298298

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

324324
var result types.ContractResult
325325
err = json.Unmarshal(res, &result)
@@ -350,7 +350,7 @@ func TestExecute(t *testing.T) {
350350
diff := time.Now().Sub(start)
351351
require.NoError(t, err)
352352
requireOkResponse(t, res, 0)
353-
assert.Equal(t, uint64(0x8e99), cost)
353+
assert.Equal(t, uint64(0x85b0), cost)
354354
t.Logf("Time (%d gas): %s\n", cost, diff)
355355

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

369369
// make sure it read the balance properly and we got 250 atoms
@@ -372,7 +372,16 @@ func TestExecute(t *testing.T) {
372372
require.NoError(t, err)
373373
require.Equal(t, "", result.Err)
374374
require.Equal(t, 1, len(result.Ok.Messages))
375-
dispatch := result.Ok.Messages[0]
375+
376+
// Ensure we got our custom event
377+
assert.Equal(t, len(result.Ok.Events), 1)
378+
ev := result.Ok.Events[0]
379+
assert.Equal(t, ev.Type, "hackatom")
380+
assert.Equal(t, len(ev.Attributes), 1)
381+
assert.Equal(t, ev.Attributes[0].Key, "action")
382+
assert.Equal(t, ev.Attributes[0].Value, "release")
383+
384+
dispatch := result.Ok.Messages[0].Msg
376385
require.NotNil(t, dispatch.Bank, "%#v", dispatch)
377386
require.NotNil(t, dispatch.Bank.Send, "%#v", dispatch)
378387
send := dispatch.Bank.Send
@@ -405,7 +414,7 @@ func TestExecuteCpuLoop(t *testing.T) {
405414
diff := time.Now().Sub(start)
406415
require.NoError(t, err)
407416
requireOkResponse(t, res, 0)
408-
assert.Equal(t, uint64(0x8e99), cost)
417+
assert.Equal(t, uint64(0x85b0), cost)
409418
t.Logf("Time (%d gas): %s\n", cost, diff)
410419

411420
// execute a cpu loop
@@ -556,7 +565,7 @@ func TestMultipleInstances(t *testing.T) {
556565
require.NoError(t, err)
557566
requireOkResponse(t, res, 0)
558567
// we now count wasm gas charges and db writes
559-
assert.Equal(t, uint64(0x8d78), cost)
568+
assert.Equal(t, uint64(0x84ad), cost)
560569

561570
// instance2 controlled by mary
562571
gasMeter2 := NewMockGasMeter(TESTING_GAS_LIMIT)
@@ -567,14 +576,14 @@ func TestMultipleInstances(t *testing.T) {
567576
res, cost, err = Instantiate(cache, checksum, env, info, msg, &igasMeter2, store2, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
568577
require.NoError(t, err)
569578
requireOkResponse(t, res, 0)
570-
assert.Equal(t, uint64(0x8e1d), cost)
579+
assert.Equal(t, uint64(0x8541), cost)
571580

572581
// fail to execute store1 with mary
573-
resp := exec(t, cache, checksum, "mary", store1, api, querier, 0x79ee)
582+
resp := exec(t, cache, checksum, "mary", store1, api, querier, 0x75ab)
574583
require.Equal(t, "Unauthorized", resp.Err)
575584

576585
// succeed to execute store1 with fred
577-
resp = exec(t, cache, checksum, "fred", store1, api, querier, 0xeeb8)
586+
resp = exec(t, cache, checksum, "fred", store1, api, querier, 0xefcf)
578587
require.Equal(t, "", resp.Err)
579588
require.Equal(t, 1, len(resp.Ok.Messages))
580589
attributes := resp.Ok.Attributes
@@ -583,7 +592,7 @@ func TestMultipleInstances(t *testing.T) {
583592
require.Equal(t, "bob", attributes[1].Value)
584593

585594
// succeed to execute store2 with mary
586-
resp = exec(t, cache, checksum, "mary", store2, api, querier, 0xeef2)
595+
resp = exec(t, cache, checksum, "mary", store2, api, querier, 0xf009)
587596
require.Equal(t, "", resp.Err)
588597
require.Equal(t, 1, len(resp.Ok.Messages))
589598
attributes = resp.Ok.Attributes
@@ -627,7 +636,7 @@ func TestSudo(t *testing.T) {
627636
require.NoError(t, err)
628637
require.Equal(t, "", result.Err)
629638
require.Equal(t, 1, len(result.Ok.Messages))
630-
dispatch := result.Ok.Messages[0]
639+
dispatch := result.Ok.Messages[0].Msg
631640
require.NotNil(t, dispatch.Bank, "%#v", dispatch)
632641
require.NotNil(t, dispatch.Bank.Send, "%#v", dispatch)
633642
send := dispatch.Bank.Send
@@ -667,7 +676,7 @@ func TestDispatchSubmessage(t *testing.T) {
667676
}
668677
payloadBin, err := json.Marshal(payload)
669678
require.NoError(t, err)
670-
payloadMsg := []byte(fmt.Sprintf(`{"reflect_sub_call":{"msgs":[%s]}}`, string(payloadBin)))
679+
payloadMsg := []byte(fmt.Sprintf(`{"reflect_sub_msg":{"msgs":[%s]}}`, string(payloadBin)))
671680

672681
gasMeter2 := NewMockGasMeter(TESTING_GAS_LIMIT)
673682
igasMeter2 := GasMeter(gasMeter2)
@@ -681,9 +690,8 @@ func TestDispatchSubmessage(t *testing.T) {
681690
err = json.Unmarshal(res, &result)
682691
require.NoError(t, err)
683692
require.Equal(t, "", result.Err)
684-
require.Equal(t, 0, len(result.Ok.Messages))
685-
require.Equal(t, 1, len(result.Ok.Submessages))
686-
dispatch := result.Ok.Submessages[0]
693+
require.Equal(t, 1, len(result.Ok.Messages))
694+
dispatch := result.Ok.Messages[0]
687695
assert.Equal(t, id, dispatch.ID)
688696
assert.Equal(t, payload.Msg, dispatch.Msg)
689697
assert.Nil(t, dispatch.GasLimit)
@@ -739,12 +747,12 @@ func TestReplyAndQuery(t *testing.T) {
739747
requireOkResponse(t, res, 0)
740748

741749
// now query the state to see if it stored the data properly
742-
badQuery := []byte(`{"sub_call_result":{"id":7777}}`)
750+
badQuery := []byte(`{"sub_msg_result":{"id":7777}}`)
743751
res, _, err = Query(cache, checksum, env, badQuery, &igasMeter2, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
744752
require.NoError(t, err)
745753
requireQueryError(t, res)
746754

747-
query := []byte(`{"sub_call_result":{"id":1234}}`)
755+
query := []byte(`{"sub_msg_result":{"id":1234}}`)
748756
res, _, err = Query(cache, checksum, env, query, &igasMeter2, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
749757
require.NoError(t, err)
750758
qres := requireQueryOk(t, res)

api/testdata/hackatom.wasm

-22.7 KB
Binary file not shown.

api/testdata/ibc_reflect.wasm

-29.6 KB
Binary file not shown.

api/testdata/queue.wasm

-23.6 KB
Binary file not shown.

api/testdata/reflect.wasm

-24.7 KB
Binary file not shown.

ibc_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,15 @@ func TestIBCHandshake(t *testing.T) {
126126
channel = api.MockIBCChannel(CHANNEL_ID, types.Ordered, IBC_VERSION)
127127
res, _, err := vm.IBCChannelConnect(checksum, env, channel, store, *goapi, querier, gasMeter2, TESTING_GAS_LIMIT)
128128
require.NoError(t, err)
129-
require.Equal(t, 0, len(res.Messages))
130-
require.Equal(t, 1, len(res.Submessages))
129+
require.Equal(t, 1, len(res.Messages))
131130

132131
// make sure it read the balance properly and we got 250 atoms
133-
dispatch := res.Submessages[0].Msg
132+
dispatch := res.Messages[0].Msg
134133
require.NotNil(t, dispatch.Wasm, "%#v", dispatch)
135134
require.NotNil(t, dispatch.Wasm.Instantiate, "%#v", dispatch)
136135
init := dispatch.Wasm.Instantiate
137136
assert.Equal(t, REFLECT_ID, init.CodeID)
138-
assert.Empty(t, init.Send)
137+
assert.Empty(t, init.Funds)
139138
}
140139

141140
func TestIBCPacketDispatch(t *testing.T) {
@@ -180,9 +179,8 @@ func TestIBCPacketDispatch(t *testing.T) {
180179
channel = api.MockIBCChannel(CHANNEL_ID, types.Ordered, IBC_VERSION)
181180
res, _, err := vm.IBCChannelConnect(checksum, env, channel, store, *goapi, querier, gasMeter3, TESTING_GAS_LIMIT)
182181
require.NoError(t, err)
183-
require.Equal(t, 0, len(res.Messages))
184-
require.Equal(t, 1, len(res.Submessages))
185-
id := res.Submessages[0].ID
182+
require.Equal(t, 1, len(res.Messages))
183+
id := res.Messages[0].ID
186184

187185
// mock reflect init callback (to store address)
188186
gasMeter4 := api.NewMockGasMeter(TESTING_GAS_LIMIT)

lib.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ func (vm *VM) IBCPacketReceive(
483483
func (vm *VM) IBCPacketAck(
484484
checksum Checksum,
485485
env types.Env,
486-
ack types.IBCAcknowledgement,
486+
ack types.IBCAcknowledgementWithPacket,
487487
store KVStore,
488488
goapi GoAPI,
489489
querier Querier,

lib_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestHappyPath(t *testing.T) {
8282
require.Equal(t, 1, len(hres.Messages))
8383

8484
// make sure it read the balance properly and we got 250 atoms
85-
dispatch := hres.Messages[0]
85+
dispatch := hres.Messages[0].Msg
8686
require.NotNil(t, dispatch.Bank, "%#v", dispatch)
8787
require.NotNil(t, dispatch.Bank.Send, "%#v", dispatch)
8888
send := dispatch.Bank.Send
@@ -130,7 +130,7 @@ func TestGetMetrics(t *testing.T) {
130130
assert.Equal(t, &types.Metrics{
131131
HitsFsCache: 1,
132132
ElementsMemoryCache: 1,
133-
SizeMemoryCache: 3432787,
133+
SizeMemoryCache: 2953616,
134134
}, metrics)
135135

136136
// Instantiate 2
@@ -146,7 +146,7 @@ func TestGetMetrics(t *testing.T) {
146146
HitsMemoryCache: 1,
147147
HitsFsCache: 1,
148148
ElementsMemoryCache: 1,
149-
SizeMemoryCache: 3432787,
149+
SizeMemoryCache: 2953616,
150150
}, metrics)
151151

152152
// Pin
@@ -161,8 +161,8 @@ func TestGetMetrics(t *testing.T) {
161161
HitsFsCache: 1,
162162
ElementsPinnedMemoryCache: 1,
163163
ElementsMemoryCache: 1,
164-
SizePinnedMemoryCache: 3432787,
165-
SizeMemoryCache: 3432787,
164+
SizePinnedMemoryCache: 2953616,
165+
SizeMemoryCache: 2953616,
166166
}, metrics)
167167

168168
// Instantiate 3
@@ -180,8 +180,8 @@ func TestGetMetrics(t *testing.T) {
180180
HitsFsCache: 1,
181181
ElementsPinnedMemoryCache: 1,
182182
ElementsMemoryCache: 1,
183-
SizePinnedMemoryCache: 3432787,
184-
SizeMemoryCache: 3432787,
183+
SizePinnedMemoryCache: 2953616,
184+
SizeMemoryCache: 2953616,
185185
}, metrics)
186186

187187
// Unpin
@@ -198,7 +198,7 @@ func TestGetMetrics(t *testing.T) {
198198
ElementsPinnedMemoryCache: 0,
199199
ElementsMemoryCache: 1,
200200
SizePinnedMemoryCache: 0,
201-
SizeMemoryCache: 3432787,
201+
SizeMemoryCache: 2953616,
202202
}, metrics)
203203

204204
// Instantiate 4
@@ -217,6 +217,6 @@ func TestGetMetrics(t *testing.T) {
217217
ElementsPinnedMemoryCache: 0,
218218
ElementsMemoryCache: 1,
219219
SizePinnedMemoryCache: 0,
220-
SizeMemoryCache: 3432787,
220+
SizeMemoryCache: 2953616,
221221
}, metrics)
222222
}

0 commit comments

Comments
 (0)