diff --git a/internal/api/lib_test.go b/internal/api/lib_test.go index 6b11e3faa..c99d6484e 100644 --- a/internal/api/lib_test.go +++ b/internal/api/lib_test.go @@ -580,7 +580,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) - require.Equal(t, uint64(0xd35950), cost.UsedInternally) + require.Equal(t, uint64(0xdf0237), cost.UsedInternally) var result types.ContractResult err = json.Unmarshal(res, &result) @@ -611,7 +611,7 @@ func TestExecute(t *testing.T) { diff := time.Since(start) require.NoError(t, err) requireOkResponse(t, res, 0) - require.Equal(t, uint64(0xd35950), cost.UsedInternally) + require.Equal(t, uint64(0xdf0237), cost.UsedInternally) t.Logf("Time (%d gas): %s\n", cost.UsedInternally, diff) // execute with the same store @@ -624,7 +624,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) - require.Equal(t, uint64(0x16057d3), cost.UsedInternally) + require.Equal(t, uint64(0x16d0d5c), cost.UsedInternally) t.Logf("Time (%d gas): %s\n", cost.UsedInternally, diff) // make sure it read the balance properly and we got 250 atoms @@ -678,7 +678,7 @@ 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.ErrorContains(t, err, "This page intentionally faulted") } func TestExecuteUnreachable(t *testing.T) { @@ -731,7 +731,7 @@ func TestExecuteCpuLoop(t *testing.T) { diff := time.Since(start) require.NoError(t, err) requireOkResponse(t, res, 0) - require.Equal(t, uint64(0x895c33), cost.UsedInternally) + require.Equal(t, uint64(0x8bbb63), cost.UsedInternally) t.Logf("Time (%d gas): %s\n", cost.UsedInternally, diff) // execute a cpu loop @@ -973,7 +973,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(0xd2189c), cost.UsedInternally) + assert.Equal(t, uint64(0xddc183), cost.UsedInternally) // instance2 controlled by mary gasMeter2 := NewMockGasMeter(TESTING_GAS_LIMIT) @@ -984,14 +984,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(0xd2ce86), cost.UsedInternally) + assert.Equal(t, uint64(0xde776d), cost.UsedInternally) // fail to execute store1 with mary - resp := exec(t, cache, checksum, "mary", store1, api, querier, 0xbe8534) + resp := exec(t, cache, checksum, "mary", store1, api, querier, 0xcbb812) require.Equal(t, "Unauthorized", resp.Err) // succeed to execute store1 with fred - resp = exec(t, cache, checksum, "fred", store1, api, querier, 0x15fce67) + resp = exec(t, cache, checksum, "fred", store1, api, querier, 0x16c83f0) require.Empty(t, resp.Err) require.Len(t, resp.Ok.Messages, 1) attributes := resp.Ok.Attributes @@ -1000,7 +1000,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, 0x160131d) + resp = exec(t, cache, checksum, "mary", store2, api, querier, 0x16cc8a6) require.Empty(t, resp.Err) require.Len(t, resp.Ok.Messages, 1) attributes = resp.Ok.Attributes diff --git a/internal/api/mocks.go b/internal/api/mocks.go index 225904224..d268d9e80 100644 --- a/internal/api/mocks.go +++ b/internal/api/mocks.go @@ -1,6 +1,7 @@ package api import ( + "encoding/hex" "encoding/json" "errors" "fmt" @@ -20,6 +21,7 @@ import ( const MOCK_CONTRACT_ADDR = "contract" func MockEnv() types.Env { + tx_hash, _ := hex.DecodeString("AABBCCDDEEFF0011AABBCCDDEEFF0011AABBCCDDEEFF0011AABBCCDDEEFF0011") return types.Env{ Block: types.BlockInfo{ Height: 123, @@ -28,6 +30,7 @@ func MockEnv() types.Env { }, Transaction: &types.TransactionInfo{ Index: 4, + Hash: tx_hash, }, Contract: types.ContractInfo{ Address: MOCK_CONTRACT_ADDR, diff --git a/lib_libwasmvm_test.go b/lib_libwasmvm_test.go index a4661bbc4..a799ab7c9 100644 --- a/lib_libwasmvm_test.go +++ b/lib_libwasmvm_test.go @@ -3,6 +3,7 @@ package cosmwasm import ( + "encoding/hex" "encoding/json" "fmt" "math" @@ -253,6 +254,8 @@ func TestEnv(t *testing.T) { expected, _ := json.Marshal(env) require.Equal(t, expected, ires.Data) + tx_hash, _ := hex.DecodeString("AABBCCDDEEFF0011AABBCCDDEEFF0011AABBCCDDEEFF0011AABBCCDDEEFF0011") + // Execute mirror env with Transaction env = types.Env{ Block: types.BlockInfo{ @@ -265,6 +268,7 @@ func TestEnv(t *testing.T) { }, Transaction: &types.TransactionInfo{ Index: 18, + Hash: tx_hash, }, } info = api.MockInfo("creator", nil) diff --git a/testdata/cyberpunk.wasm b/testdata/cyberpunk.wasm index ea4d73e85..45bdc894f 100644 Binary files a/testdata/cyberpunk.wasm and b/testdata/cyberpunk.wasm differ diff --git a/types/env.go b/types/env.go index 37a19ea38..d853918ac 100644 --- a/types/env.go +++ b/types/env.go @@ -33,6 +33,9 @@ type TransactionInfo struct { // Along with BlockInfo.Height, this allows you to get a unique // transaction identifier for the chain for future queries Index uint32 `json:"index"` + + // Hash of the transaction. + Hash []byte `json:"hash,omitempty"` } type MessageInfo struct {