diff --git a/contracts/wasm/corecontracts/test/core_blob_test.go b/contracts/wasm/corecontracts/test/core_blob_test.go index 2f0f0238ce..387de372f0 100644 --- a/contracts/wasm/corecontracts/test/core_blob_test.go +++ b/contracts/wasm/corecontracts/test/core_blob_test.go @@ -14,7 +14,7 @@ import ( ) // this is the expected blob hash for key0/val0 key1/val1 -const expectedBlobHash = "0x5fec3bfc701d80bdf75e337cb3dcb401c2423d15fc17a74d5b644dae143118b1" +const expectedBlobHash = "0xc3a428b98c8a0385da56aceaa36d82032fb22fe372bb78b9ec9993a24acb1d35" func setupBlob(t *testing.T) *wasmsolo.SoloContext { ctx := setup(t) @@ -81,7 +81,7 @@ func TestListBlobs(t *testing.T) { fStore.Params.Blobs().GetBytes("key1").SetValue([]byte("_val1")) fStore.Func.Post() require.NoError(t, ctx.Err) - expectedHash := "0x462af4abe5977f4dd985a0a097705925b9fa6c033c9d931c1e2171f710693462" + expectedHash := "0xc5b04323dd23505d1c6af7dfdf3ef3ea102c516ad787fcc1ec4ccee39168af54" require.Equal(t, expectedHash, fStore.Results.Hash().Value().String()) fList := coreblob.ScFuncs.ListBlobs(ctx) diff --git a/packages/vm/core/blob/internal.go b/packages/vm/core/blob/internal.go index 4baca537cd..cc234503e1 100644 --- a/packages/vm/core/blob/internal.go +++ b/packages/vm/core/blob/internal.go @@ -28,8 +28,8 @@ func mustGetBlobHash(fields dict.Dict) (hashing.HashValue, []kv.Key, [][]byte) { for _, k := range sorted { v := fields.Get(k) values = append(values, v) - all = append(all, v) all = append(all, []byte(k)) + all = append(all, v) } return hashing.HashData(all...), sorted, values } diff --git a/packages/vm/core/blob/internal_test.go b/packages/vm/core/blob/internal_test.go new file mode 100644 index 0000000000..e74b77befa --- /dev/null +++ b/packages/vm/core/blob/internal_test.go @@ -0,0 +1,26 @@ +package blob + +import ( + "encoding/hex" + "testing" + + "github.com/iotaledger/wasp/packages/kv/dict" + "github.com/stretchr/testify/require" +) + +func TestMustGetBlobHash(t *testing.T) { + fields := dict.Dict{ + "field1": []byte("value1"), + "field2": []byte("value2"), + } + + h, keys, values := mustGetBlobHash(fields) + for i, k := range keys { + require.Equal(t, fields[k], values[i]) + } + + // blobHash = hash(fieldName1 || binaryChunk1 || fieldName2 || binaryChunk2 || ... || fieldNameN || binaryChunkN) + resHash, err := hex.DecodeString("d45cd5dee59f83b3334c1acce7a38f12280d264aada764ed0d65e8a88c4693b0") + require.NoError(t, err) + require.Equal(t, resHash, h.Bytes()) +}