Skip to content

Commit

Permalink
Merge branch 'rc/v1.7.next1' into convert-small-int
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica authored Jul 19, 2024
2 parents 9b16039 + c7de865 commit 4a1c679
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57
github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240509103544-247ce5639c7a
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240715100647-8ce0ec25ff1d
github.com/multiversx/mx-components-big-int v1.0.0
github.com/pelletier/go-toml v1.9.3
github.com/stretchr/testify v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00
github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00/go.mod h1:pnIIfWopbDMQ1EW5Ddc6KDMqv8Qtx+hxbH9rorHpCyo=
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f h1:yd/G8iPBGOEAwbaS8zndJpO6bQk7Tk72ZhmlqRasThI=
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f/go.mod h1:E6nfj9EQzGxWDGM3Dn6eZWRC3qFy1G8IqOsYsBOcgWw=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240509103544-247ce5639c7a h1:7M+jXVlnl43zd2NuimL1KnAVAdpUr/QoHqG0TUKoyaM=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240509103544-247ce5639c7a/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240715100647-8ce0ec25ff1d h1:GqwJaWDgWFuHx4AsUBMwpHWzY4afyTbWBk0nwYG6lsY=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240715100647-8ce0ec25ff1d/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo=
github.com/multiversx/mx-components-big-int v1.0.0 h1:Wkr8lSzK2nDqixOrrBa47VNuqdhV1m/aJhaP1EMaiS8=
github.com/multiversx/mx-components-big-int v1.0.0/go.mod h1:maIEMgHlNE2u78JaDD0oLzri+ShgU4okHfzP3LWGdQM=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand Down
2 changes: 1 addition & 1 deletion vmhost/contexts/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (context *storageContext) GetStorageFromAddress(address []byte, key []byte)
!core.IsSmartContractAddress(address)

metadata := vmcommon.CodeMetadataFromBytes(userAcc.GetCodeMetadata())
if !metadata.Readable || isReadFromUserAddress {
if !metadata.Readable && !isReadFromUserAddress {
context.useExtraGasForKeyIfNeeded(key, false)
return nil, 0, false, nil
}
Expand Down
49 changes: 35 additions & 14 deletions vmhost/contexts/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package contexts
import (
"bytes"
"errors"
"github.com/multiversx/mx-chain-core-go/core"
"math/big"
"testing"

Expand Down Expand Up @@ -444,11 +445,20 @@ func TestStorageContext_StorageProtection(t *testing.T) {
func TestStorageContext_GetStorageFromAddress(t *testing.T) {
t.Parallel()

scAddress := []byte("account")
readable := []byte("readable")
nonreadable := []byte("nonreadable")
scAddress := bytes.Repeat([]byte{0}, 32)
readable := bytes.Repeat([]byte{0}, 32)
readable[31] = 1
nonreadable := bytes.Repeat([]byte{0}, 32)
nonreadable[31] = 2

enableEpochsHandler := &worldmock.EnableEpochsHandlerStub{}
userAddress := bytes.Repeat([]byte{1}, 32)

isEnabled := false
enableEpochsHandler := &worldmock.EnableEpochsHandlerStub{
IsFlagEnabledCalled: func(_ core.EnableEpochFlag) bool {
return isEnabled
},
}

mockOutput := &contextmock.OutputContextMock{}
account := mockOutput.NewVMOutputAccount(scAddress)
Expand All @@ -470,9 +480,7 @@ func TestStorageContext_GetStorageFromAddress(t *testing.T) {
t.Run("blockchain hook errors", func(t *testing.T) {
errTooManyRequests := errors.New("too many requests")
bcHook := makeBcHookStub(
scAddress,
readable,
nonreadable,
nil,
errTooManyRequests)

Expand All @@ -491,14 +499,22 @@ func TestStorageContext_GetStorageFromAddress(t *testing.T) {
data, _, _, _ = storageCtx.GetStorageFromAddress(nonreadable, key)
require.Nil(t, data)
require.Equal(t, errTooManyRequests, err)

isEnabled = false
data, _, _, _ = storageCtx.GetStorageFromAddress(userAddress, key)
require.Nil(t, data)
require.Equal(t, errTooManyRequests, err)

isEnabled = true
data, _, _, _ = storageCtx.GetStorageFromAddress(userAddress, key)
require.Nil(t, data)
require.Equal(t, errTooManyRequests, err)
})
t.Run("should work when blockchain hook does not error", func(t *testing.T) {
internalData := []byte("internalData")

bcHook := makeBcHookStub(
scAddress,
readable,
nonreadable,
internalData,
nil)

Expand All @@ -517,13 +533,21 @@ func TestStorageContext_GetStorageFromAddress(t *testing.T) {
data, _, _, err = storageCtx.GetStorageFromAddress(nonreadable, key)
require.Nil(t, err)
require.Nil(t, data)

isEnabled = false
data, _, _, err = storageCtx.GetStorageFromAddress(userAddress, key)
require.Nil(t, err)
require.Nil(t, data)

isEnabled = true
data, _, _, err = storageCtx.GetStorageFromAddress(userAddress, key)
require.Nil(t, err)
require.Equal(t, data, internalData)
})
}

func makeBcHookStub(
scAddress []byte,
readable []byte,
nonreadable []byte,
internalData []byte,
getStorageErr error,
) *contextmock.BlockchainHookStub {
Expand All @@ -532,10 +556,7 @@ func makeBcHookStub(
if bytes.Equal(readable, address) {
return &worldmock.Account{CodeMetadata: []byte{4, 0}}, nil
}
if bytes.Equal(nonreadable, address) || bytes.Equal(scAddress, address) {
return &worldmock.Account{CodeMetadata: []byte{0, 0}}, nil
}
return nil, nil
return &worldmock.Account{CodeMetadata: []byte{0, 0}}, nil
},
GetStorageDataCalled: func(accountsAddress []byte, index []byte) ([]byte, uint32, error) {
return internalData, 0, getStorageErr
Expand Down

0 comments on commit 4a1c679

Please sign in to comment.