Skip to content

Commit

Permalink
Update IBC test cases and internal API tests for contract migration a…
Browse files Browse the repository at this point in the history
…nd gas usage; adjust dependencies in Cargo files for cosmwasm packages to version 2.2.0
  • Loading branch information
faddat committed Jan 9, 2025
1 parent a43089f commit d244eb2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func TestAnalyzeCode(t *testing.T) {
require.NoError(t, err)
require.False(t, report.HasIBCEntryPoints)
require.Equal(t, "cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4,cosmwasm_2_0,cosmwasm_2_1,cosmwasm_2_2", report.RequiredCapabilities)
require.Equal(t, uint64(42), *report.ContractMigrateVersion)
require.Equal(t, uint64(0x1a4), *report.ContractMigrateVersion)

// Store IBC contract
wasm2, err := os.ReadFile(IBC_TEST_CONTRACT)
Expand All @@ -313,7 +313,7 @@ func TestAnalyzeCode(t *testing.T) {
report2, err := vm.AnalyzeCode(checksum2)
require.NoError(t, err)
require.True(t, report2.HasIBCEntryPoints)
require.Equal(t, "iterator,stargate", report2.RequiredCapabilities)
require.Equal(t, "cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4,cosmwasm_2_0,cosmwasm_2_1,cosmwasm_2_2,iterator,stargate", report2.RequiredCapabilities)
require.Nil(t, report2.ContractMigrateVersion)
}

Expand Down
25 changes: 13 additions & 12 deletions internal/api/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,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(0xb1fe27), cost.UsedInternally)
assert.Equal(t, uint64(0xa3e4ae), cost.UsedInternally)

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

// execute with the same store
Expand All @@ -617,7 +617,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.Since(start)
require.NoError(t, err)
assert.Equal(t, uint64(0x1416da5), cost.UsedInternally)
assert.Equal(t, uint64(0x12899a6), cost.UsedInternally)
t.Logf("Time (%d gas): %s\n", cost.UsedInternally, diff)

// make sure it read the balance properly and we got 250 atoms
Expand Down Expand Up @@ -672,7 +672,8 @@ func TestExecutePanic(t *testing.T) {
store.SetGasMeter(gasMeter2)
info = MockInfoBin(t, "fred")
_, _, err = Execute(cache, checksum, env, info, []byte(`{"panic":{}}`), &igasMeter2, store, api, &querier, maxGas, TESTING_PRINT_DEBUG)
require.ErrorContains(t, err, "RuntimeError: Aborted: panicked at 'This page intentionally faulted'")
require.Error(t, err)
require.Contains(t, err.Error(), "RuntimeError: Aborted: panicked at src/contract.rs:127:5:\nThis page intentionally faulted")
}

func TestExecuteUnreachable(t *testing.T) {
Expand Down Expand Up @@ -725,7 +726,7 @@ func TestExecuteCpuLoop(t *testing.T) {
diff := time.Since(start)
require.NoError(t, err)
requireOkResponse(t, res, 0)
assert.Equal(t, uint64(0x79f527), cost.UsedInternally)
assert.Equal(t, uint64(0x72c3ce), cost.UsedInternally)
t.Logf("Time (%d gas): %s\n", cost.UsedInternally, diff)

// execute a cpu loop
Expand Down Expand Up @@ -923,7 +924,8 @@ func TestMigrate(t *testing.T) {

// migrate to a new verifier - alice
// we use the same code blob as we are testing hackatom self-migration
_, _, err = Migrate(cache, checksum, env, []byte(`{"verifier":"alice"}`), &igasMeter, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
info = MockInfoBin(t, "admin")
_, _, err = MigrateWithInfo(cache, checksum, env, []byte(`{"verifier":"alice"}`), info, &igasMeter, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
require.NoError(t, err)

// should update verifier to alice
Expand Down Expand Up @@ -953,8 +955,7 @@ func TestMultipleInstances(t *testing.T) {
res, cost, err := Instantiate(cache, checksum, env, info, msg, &igasMeter1, store1, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
require.NoError(t, err)
requireOkResponse(t, res, 0)
// we now count wasm gas charges and db writes
assert.Equal(t, uint64(0xb0c2cd), cost.UsedInternally)
assert.Equal(t, uint64(0xa2aeb8), cost.UsedInternally)

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

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

// succeed to execute store1 with fred
resp = exec(t, cache, checksum, "fred", store1, api, querier, 0x140e8ad)
resp = exec(t, cache, checksum, "fred", store1, api, querier, 0x1281a12)
require.Equal(t, "", resp.Err)
require.Equal(t, 1, len(resp.Ok.Messages))
attributes := resp.Ok.Attributes
Expand All @@ -981,7 +982,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, 0x1412b29)
resp = exec(t, cache, checksum, "mary", store2, api, querier, 0x12859dc)
require.Equal(t, "", resp.Err)
require.Equal(t, 1, len(resp.Ok.Messages))
attributes = resp.Ok.Attributes
Expand Down

0 comments on commit d244eb2

Please sign in to comment.