Skip to content

Commit

Permalink
Update testing contracts and adapt code
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Feb 8, 2022
1 parent 927d299 commit ea1c17c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
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: 5576140,
SizeMemoryCache: 5549819,
}, metrics)

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

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

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

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

// Instantiate 4
Expand All @@ -292,7 +292,7 @@ func TestGetMetrics(t *testing.T) {
ElementsPinnedMemoryCache: 0,
ElementsMemoryCache: 1,
SizePinnedMemoryCache: 0,
SizeMemoryCache: 5576140,
SizeMemoryCache: 5549819,
}, 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(0x1302be720), cost)
assert.Equal(t, uint64(0x12dbfa210), 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(0x1302be720), cost)
assert.Equal(t, uint64(0x12dbfa210), 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(0x22beeb9c0), cost)
assert.Equal(t, uint64(0x21ed35160), 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 @@ -414,7 +414,7 @@ func TestExecuteCpuLoop(t *testing.T) {
diff := time.Now().Sub(start)
require.NoError(t, err)
requireOkResponse(t, res, 0)
assert.Equal(t, uint64(0x1302be720), cost)
assert.Equal(t, uint64(0x12dbfa210), cost)
t.Logf("Time (%d gas): %s\n", cost, diff)

// execute a cpu loop
Expand Down Expand Up @@ -565,7 +565,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(0x12df69090), cost)
assert.Equal(t, uint64(0x12b9c9b00), cost)

// instance2 controlled by mary
gasMeter2 := NewMockGasMeter(TESTING_GAS_LIMIT)
Expand All @@ -576,14 +576,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(0x12f3b93b0), cost)
assert.Equal(t, uint64(0x12cd87660), cost)

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

// succeed to execute store1 with fred
resp = exec(t, cache, checksum, "fred", store1, api, querier, 0x22ae53900)
resp = exec(t, cache, checksum, "fred", store1, api, querier, 0x21dd2f860)
require.Equal(t, "", resp.Err)
require.Equal(t, 1, len(resp.Ok.Messages))
attributes := resp.Ok.Attributes
Expand All @@ -592,7 +592,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, 0x22b69f960)
resp = exec(t, cache, checksum, "mary", store2, api, querier, 0x21e5324e0)
require.Equal(t, "", resp.Err)
require.Equal(t, 1, len(resp.Ok.Messages))
attributes = resp.Ok.Attributes
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.
16 changes: 8 additions & 8 deletions lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestGetMetrics(t *testing.T) {
assert.Equal(t, &types.Metrics{
HitsFsCache: 1,
ElementsMemoryCache: 1,
SizeMemoryCache: 5576140,
SizeMemoryCache: 5549819,
}, metrics)

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

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

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

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

// Instantiate 4
Expand All @@ -220,6 +220,6 @@ func TestGetMetrics(t *testing.T) {
ElementsPinnedMemoryCache: 0,
ElementsMemoryCache: 1,
SizePinnedMemoryCache: 0,
SizeMemoryCache: 5576140,
SizeMemoryCache: 5549819,
}, metrics)
}
2 changes: 1 addition & 1 deletion libwasmvm/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ mod tests {
misses: 0,
elements_pinned_memory_cache: 1,
elements_memory_cache: 0,
size_pinned_memory_cache: 5576140,
size_pinned_memory_cache: 5549819,
size_memory_cache: 0,
}
);
Expand Down

0 comments on commit ea1c17c

Please sign in to comment.