Skip to content

Commit 7d894cc

Browse files
committed
implementing the proper fix
1 parent ca080db commit 7d894cc

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

mock/contracts/transferAndExecuteSC.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package contracts
22

33
import (
4+
"encoding/hex"
45
"fmt"
56
"math/big"
67

@@ -64,6 +65,27 @@ func TransferEGLDToParent(instanceMock *mock.InstanceMock, config interface{}) {
6465
})
6566
}
6667

68+
func TransferAndExecuteWithBuiltIn(instanceMock *mock.InstanceMock, config interface{}) {
69+
instanceMock.AddMockMethod("transferAndExecuteWithBuiltIn", func() *mock.InstanceMock {
70+
testConfig := config.(*test.TestConfig)
71+
host := instanceMock.Host
72+
instance := mock.GetMockInstance(host)
73+
74+
_ = host.Metering().UseGasBounded(testConfig.GasUsedByChild)
75+
76+
transferString := "ESDTTransfer@" + hex.EncodeToString([]byte("XYY-ABCDEF")) + "@" + hex.EncodeToString(big.NewInt(100000).Bytes())
77+
vmhooks.TransferValueExecuteWithTypedArgs(host,
78+
test.UserAddress,
79+
big.NewInt(0),
80+
1,
81+
[]byte(transferString),
82+
[][]byte{},
83+
)
84+
85+
return instance
86+
})
87+
}
88+
6789
// GetChildAddressForTransfer -
6890
func GetChildAddressForTransfer(transfer int) []byte {
6991
return testcommon.MakeTestSCAddress(fmt.Sprintf("childSC-%d", transfer))

vmhost/hosttest/execution_gas_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,36 @@ func TestGasUsed_SingleContract_TransferFromChild(t *testing.T) {
174174
assert.Nil(t, err)
175175
}
176176

177+
func TestGasUsed_SingleContract_TransferFromChildWithBuiltIn(t *testing.T) {
178+
testConfig := makeTestConfig()
179+
180+
_, err := test.BuildMockInstanceCallTest(t).
181+
WithContracts(
182+
test.CreateMockContract(test.ParentAddress).
183+
WithBalance(testConfig.ParentBalance).
184+
WithCodeMetadata([]byte{0, vmcommon.MetadataPayable}).
185+
WithConfig(testConfig).
186+
WithMethods(contracts.ExecOnDestCtxSingleCallParentMock),
187+
test.CreateMockContract(test.ChildAddress).
188+
WithBalance(testConfig.ChildBalance).
189+
WithConfig(testConfig).
190+
WithMethods(contracts.TransferAndExecuteWithBuiltIn)).
191+
WithInput(test.CreateTestContractCallInputBuilder().
192+
WithRecipientAddr(test.ParentAddress).
193+
WithGasProvided(testConfig.GasProvided).
194+
WithFunction("execOnDestCtxSingleCall").
195+
WithArguments(test.ChildAddress, []byte("transferAndExecuteWithBuiltIn")).
196+
Build()).
197+
WithSetup(func(host vmhost.VMHost, world *worldmock.MockWorld) {
198+
createMockBuiltinFunctions(t, host, world)
199+
setZeroCodeCosts(host)
200+
}).
201+
AndAssertResults(func(world *worldmock.MockWorld, verify *test.VMOutputVerifier) {
202+
verify.ReturnCode(vmcommon.ExecutionFailed)
203+
})
204+
assert.Nil(t, err)
205+
}
206+
177207
func TestGasUsed_ExecuteOnDestChain(t *testing.T) {
178208
alphaAddress := test.MakeTestSCAddress("alpha")
179209
betaAddress := test.MakeTestSCAddress("beta")

vmhost/vmhooks/baseOps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ func TransferValueExecuteWithTypedArgs(
848848

849849
lastRound := host.Blockchain().LastRound()
850850
if host.IsBuiltinFunctionCall([]byte(data)) &&
851-
lastRound > uint64(host.EnableEpochsHandler().GetActivationEpoch(vmhost.CheckBuiltInCallOnTransferValueAndFailExecutionFlag)) {
851+
lastRound >= uint64(host.EnableEpochsHandler().GetActivationEpoch(vmhost.CheckBuiltInCallOnTransferValueAndFailExecutionFlag)) {
852852
WithFaultAndHost(host, vmhost.ErrTransferValueOnESDTCall, runtime.BaseOpsErrorShouldFailExecution())
853853
return 1
854854
}

0 commit comments

Comments
 (0)