Skip to content

Commit

Permalink
Merge branch 'rc/v1.6.next1' into sandbox-queries
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau authored Feb 15, 2024
2 parents d7339ec + 5531e7f commit 624413b
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 28 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ require (
github.com/multiversx/mx-chain-crypto-go v1.2.9
github.com/multiversx/mx-chain-es-indexer-go v1.4.18
github.com/multiversx/mx-chain-logger-go v1.0.13
github.com/multiversx/mx-chain-scenario-go v1.3.0
github.com/multiversx/mx-chain-scenario-go v1.4.2
github.com/multiversx/mx-chain-storage-go v1.0.14
github.com/multiversx/mx-chain-vm-common-go v1.5.11
github.com/multiversx/mx-chain-vm-go v1.5.26
github.com/multiversx/mx-chain-vm-go v1.5.27
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.65
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.66
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.94
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.95
github.com/pelletier/go-toml v1.9.3
github.com/pkg/errors v0.9.1
github.com/shirou/gopsutil v3.21.11+incompatible
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -395,20 +395,20 @@ github.com/multiversx/mx-chain-es-indexer-go v1.4.18 h1:rCA+/mn/77MyB7c8FjtabdQe
github.com/multiversx/mx-chain-es-indexer-go v1.4.18/go.mod h1:maraR9xXcfi0lLifhGMc+DVHpw1IOPX/c89HVckF1Js=
github.com/multiversx/mx-chain-logger-go v1.0.13 h1:eru/TETo0MkO4ZTnXsQDKf4PBRpAXmqjT02klNT/JnY=
github.com/multiversx/mx-chain-logger-go v1.0.13/go.mod h1:MZJhTAtZTJxT+yK2EHc4ZW3YOHUc1UdjCD0iahRNBZk=
github.com/multiversx/mx-chain-scenario-go v1.3.0 h1:Vm6jYipJuIcJt8kamgXkePtKkwXaF5Lv5DglZjE5o8I=
github.com/multiversx/mx-chain-scenario-go v1.3.0/go.mod h1:Sdgz8nzA9Ki/pdY/e2a4k90LALBKQB1Eo8HeCV3Bkzo=
github.com/multiversx/mx-chain-scenario-go v1.4.2 h1:iGgqMHup7DfMYFEynGjn2CX9ZNBfgPQLqzZx1AWHJzc=
github.com/multiversx/mx-chain-scenario-go v1.4.2/go.mod h1:Sdgz8nzA9Ki/pdY/e2a4k90LALBKQB1Eo8HeCV3Bkzo=
github.com/multiversx/mx-chain-storage-go v1.0.14 h1:h0acoqPS3FKJ4S3cKBEriTU0OabSQnpxai5WKhi1YCs=
github.com/multiversx/mx-chain-storage-go v1.0.14/go.mod h1:sJ2q49tgjxNpMpsHysjABqCAB0FLBmDblbjBkQ8XfmA=
github.com/multiversx/mx-chain-vm-common-go v1.5.11 h1:rAQR00ALKOmWAuNA8XW8hR02M9gmrAE4WZwyJH4dMMU=
github.com/multiversx/mx-chain-vm-common-go v1.5.11/go.mod h1:T04rZt/VdwjPXcXVxltMmDmrhxNXsqlByYbWNWcNLYA=
github.com/multiversx/mx-chain-vm-go v1.5.26 h1:ZjUJTG9cO2h5WNRIZ50ZSZNsTEPqXXPGS9Y/SAGyC2A=
github.com/multiversx/mx-chain-vm-go v1.5.26/go.mod h1:gNZ/s4Z6OHg6ZeBsW6aDxWQduXsRS0Bsv4pfkmHeRzs=
github.com/multiversx/mx-chain-vm-go v1.5.27 h1:80AdXyjAnN5w4hucPMtpsXnoWtcV47ZLcjECsTTccsA=
github.com/multiversx/mx-chain-vm-go v1.5.27/go.mod h1:Y1O50Z7+suo4D1hnSBA7n34KvgKs5W9jzoEGwpfAjks=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.65 h1:TxFjQH0dXC/ACQxlIgJbO7pVoh00rcqeKSnIjWTDMxg=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.65/go.mod h1:UUUxIU7mlRkz+Jz4GWV2GkgJt2mKd+j1kky++RNYc9s=
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.66 h1:xgrXfHKa0Za4xjFj5W0FcYEivjrQIhLvGEFXXa1uQZU=
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.66/go.mod h1:mx6IOAqo7zjSinYd8D2YqlpMWsuqFoYXJ6bntnTOeQg=
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.94 h1:MZFEBjDmfwLGB0cZb/pvlLx+qRv/9tO83bEgHUk34is=
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.94/go.mod h1:uuSbZGe0UwOWQyHA4EeJWhs8UeDdhtmMwlhNaX9ppx0=
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.95 h1:zswK06SKd8VYjFTeC/4Jat5PhU9PT4pO5hw01U9ZjtE=
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.95/go.mod h1:t4YcFK6VJkG1wGKx1JK4jyowo9zfGFpi8Jl3ycfqAxw=
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/multiversx/protobuf v1.3.2 h1:RaNkxvGTGbA0lMcnHAN24qE1G1i+Xs5yHA6MDvQ4mSM=
Expand Down
Binary file not shown.
58 changes: 58 additions & 0 deletions integrationTests/vm/wasm/testdata/transferValue/transferValue.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
typedef unsigned char byte;
typedef unsigned int i32;
typedef unsigned long long i64;

int getArgument(int argumentIndex, byte *argument);
int transferValueExecute(byte *destination, byte *value, long long gas, byte *function, int functionLength, int numArguments, byte *argumentsLengths, byte *arguments);
void getCaller(byte *callerAddress);
i32 createAsyncCall(byte *destination, byte *value, byte *data, int dataLength, byte *success, int successLength, byte *error, int errorLength, long long gas, long long extraGasForCallback);

byte zero32_a[32] = {0};
byte zero32_b[32] = {0};
byte zero32_c[32] = {0};

byte oneAtomOfEGLD[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
byte functionNameAskMoney[] = "askMoney";
byte functionNameMyCallback[] = "myCallback";

void init()
{
}

void upgrade()
{
}

void fund()
{
}

void forwardAskMoney()
{
byte *otherContract = zero32_a;
getArgument(0, otherContract);

createAsyncCall(
otherContract,
0,
functionNameAskMoney,
sizeof(functionNameAskMoney) - 1,
functionNameMyCallback,
sizeof(functionNameMyCallback) - 1,
functionNameMyCallback,
sizeof(functionNameMyCallback) - 1,
15000000,
0);
}

void askMoney()
{
byte *caller = zero32_a;

getCaller(caller);
transferValueExecute(caller, oneAtomOfEGLD, 0, 0, 0, 0, 0, 0);
}

void myCallback()
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
init
upgrade
fund
forwardAskMoney
askMoney
myCallback
62 changes: 62 additions & 0 deletions integrationTests/vm/wasm/transfers/transfers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//go:build !race

package transfers

import (
"encoding/hex"
"fmt"
"math/big"
"testing"

"github.com/multiversx/mx-chain-go/integrationTests/vm/wasm"
"github.com/stretchr/testify/require"
)

func TestTransfers_DuplicatedTransferValueEvents(t *testing.T) {
context := wasm.SetupTestContext(t)
defer context.Close()

err := context.DeploySC("../testdata/transferValue/output/transferValue.wasm", "")
require.Nil(t, err)
vault := context.ScAddress

err = context.DeploySC("../testdata/transferValue/output/transferValue.wasm", "")
require.Nil(t, err)
forwarder := context.ScAddress

// Add money to the vault
context.ScAddress = vault
err = context.ExecuteSCWithValue(&context.Owner, "fund", big.NewInt(42))
require.Nil(t, err)

// Ask money from the vault, via the forwarder
context.ScAddress = forwarder
err = context.ExecuteSC(&context.Owner, fmt.Sprintf("forwardAskMoney@%s", hex.EncodeToString(vault)))
require.Nil(t, err)
require.Len(t, context.LastLogs, 1)
require.Len(t, context.LastLogs[0].GetLogEvents(), 5)

events := context.LastLogs[0].GetLogEvents()

require.Equal(t, "transferValueOnly", string(events[0].GetIdentifier()))
require.Equal(t, "AsyncCall", string(events[0].GetData()))
require.Equal(t, []byte{}, events[0].GetTopics()[0])
require.Equal(t, forwarder, events[0].GetAddress())
require.Equal(t, vault, events[0].GetTopics()[1])

require.Equal(t, "transferValueOnly", string(events[1].GetIdentifier()))
require.Equal(t, "BackTransfer", string(events[1].GetData()))
require.Equal(t, []byte{0x01}, events[1].GetTopics()[0])
require.Equal(t, vault, events[1].GetAddress())
require.Equal(t, forwarder, events[1].GetTopics()[1])

// Duplicated "transferValueOnly" events are fixed in #5936.
require.Equal(t, "transferValueOnly", string(events[2].GetIdentifier()))
require.Equal(t, "AsyncCallback", string(events[2].GetData()))
require.Equal(t, []byte{}, events[2].GetTopics()[0])
require.Equal(t, vault, events[2].GetAddress())
require.Equal(t, forwarder, events[2].GetTopics()[1])

require.Equal(t, "writeLog", string(events[3].GetIdentifier()))
require.Equal(t, "completedTxEvent", string(events[4].GetIdentifier()))
}
42 changes: 23 additions & 19 deletions integrationTests/vm/wasm/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/pubkeyConverter"
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-core-go/data/rewardTx"
"github.com/multiversx/mx-chain-core-go/data/smartContractResult"
Expand Down Expand Up @@ -102,6 +103,7 @@ type TestContext struct {
ScAddress []byte
ScCodeMetadata vmcommon.CodeMetadata
Accounts *state.AccountsDB
TxLogsProcessor process.TransactionLogProcessor
TxProcessor process.TransactionProcessor
ScProcessor scrCommon.TestSmartContractProcessor
QueryService external.SCQueryService
Expand All @@ -112,6 +114,7 @@ type TestContext struct {
LastTxHash []byte
SCRForwarder *mock.IntermediateTransactionHandlerMock
LastSCResults []*smartContractResult.SmartContractResult
LastLogs []*data.LogData
}

type testParticipant struct {
Expand Down Expand Up @@ -164,7 +167,7 @@ func SetupTestContextWithGasSchedule(t *testing.T, gasSchedule map[string]map[st
context.initFeeHandlers()
context.initVMAndBlockchainHook()
context.initTxProcessorWithOneSCExecutorWithVMs()
context.ScAddress, _ = context.BlockchainHook.NewAddress(context.Owner.Address, context.Owner.Nonce, factory.WasmVirtualMachine)

argsNewSCQueryService := smartContract.ArgsNewSCQueryService{
VmContainer: context.VMContainer,
EconomicsFee: context.EconomicsFee,
Expand Down Expand Up @@ -364,8 +367,11 @@ func (context *TestContext) initTxProcessorWithOneSCExecutorWithVMs() {
defaults.FillGasMapInternal(gasSchedule, 1)

argsLogProcessor := transactionLog.ArgTxLogProcessor{Marshalizer: marshalizer}
logsProcessor, _ := transactionLog.NewTxLogProcessor(argsLogProcessor)
context.TxLogsProcessor, err = transactionLog.NewTxLogProcessor(argsLogProcessor)
require.Nil(context.T, err)

context.SCRForwarder = &mock.IntermediateTransactionHandlerMock{}

argsNewSCProcessor := scrCommon.ArgsNewSmartContractProcessor{
VmContainer: context.VMContainer,
ArgsParser: smartContract.NewArgumentParser(),
Expand All @@ -385,14 +391,14 @@ func (context *TestContext) initTxProcessorWithOneSCExecutorWithVMs() {
SetGasRefundedCalled: func(gasRefunded uint64, hash []byte) {},
},
GasSchedule: mock.NewGasScheduleNotifierMock(gasSchedule),
TxLogsProcessor: logsProcessor,
TxLogsProcessor: context.TxLogsProcessor,
EnableRoundsHandler: context.EnableRoundsHandler,
EnableEpochsHandler: context.EnableEpochsHandler,
WasmVMChangeLocker: context.WasmVMChangeLocker,
VMOutputCacher: txcache.NewDisabledCache(),
}

context.ScProcessor, _ = processProxy.NewTestSmartContractProcessorProxy(argsNewSCProcessor, context.EpochNotifier)
context.ScProcessor, err = processProxy.NewTestSmartContractProcessorProxy(argsNewSCProcessor, context.EpochNotifier)
require.Nil(context.T, err)

argsNewTxProcessor := processTransaction.ArgsNewTxProcessor{
Expand All @@ -414,7 +420,7 @@ func (context *TestContext) initTxProcessorWithOneSCExecutorWithVMs() {
EnableEpochsHandler: context.EnableEpochsHandler,
TxVersionChecker: &testscommon.TxVersionCheckerStub{},
GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{},
TxLogsProcessor: logsProcessor,
TxLogsProcessor: context.TxLogsProcessor,
}

context.TxProcessor, err = processTransaction.NewTxProcessor(argsNewTxProcessor)
Expand Down Expand Up @@ -544,20 +550,20 @@ func (context *TestContext) DeploySC(wasmPath string, parametersString string) e
return err
}

context.ScAddress, _ = context.BlockchainHook.NewAddress(context.Owner.Address, context.Owner.Nonce, factory.WasmVirtualMachine)

owner.Nonce++
_, err = context.Accounts.Commit()
if err != nil {
return err
}

err = context.GetCompositeTestError()
err = context.acquireOutcome()
if err != nil {
return err
}

_ = context.UpdateLastSCResults()

return nil
return context.GetCompositeTestError()
}

// UpgradeSC -
Expand Down Expand Up @@ -604,14 +610,12 @@ func (context *TestContext) UpgradeSC(wasmPath string, parametersString string)
return err
}

err = context.GetCompositeTestError()
err = context.acquireOutcome()
if err != nil {
return err
}

_ = context.UpdateLastSCResults()

return nil
return context.GetCompositeTestError()
}

// GetSCCode -
Expand Down Expand Up @@ -680,18 +684,16 @@ func (context *TestContext) ExecuteSCWithValue(sender *testParticipant, txData s
return err
}

err = context.GetCompositeTestError()
err = context.acquireOutcome()
if err != nil {
return err
}

_ = context.UpdateLastSCResults()

return nil
return context.GetCompositeTestError()
}

// UpdateLastSCResults --
func (context *TestContext) UpdateLastSCResults() error {
// acquireOutcome -
func (context *TestContext) acquireOutcome() error {
transactions := context.SCRForwarder.GetIntermediateTransactions()
context.LastSCResults = make([]*smartContractResult.SmartContractResult, len(transactions))
for i, tx := range transactions {
Expand All @@ -703,6 +705,8 @@ func (context *TestContext) UpdateLastSCResults() error {
}
}

context.LastLogs = context.TxLogsProcessor.GetAllCurrentLogs()

return nil
}

Expand Down

0 comments on commit 624413b

Please sign in to comment.