diff --git a/integrationTests/vm/arwen/arwenVM_test.go b/integrationTests/vm/arwen/arwenVM_test.go index c1423c5a15a..d69ef39996c 100644 --- a/integrationTests/vm/arwen/arwenVM_test.go +++ b/integrationTests/vm/arwen/arwenVM_test.go @@ -109,27 +109,22 @@ func runWASMVMBenchmark(tb testing.TB, fileSC string, numRun int, testingValue u aliceNonce := uint64(0) _ = vm.CreateAccount(accnts, alice, aliceNonce, big.NewInt(10000000000)) + tx = &transaction.Transaction{ + Nonce: aliceNonce, + Value: big.NewInt(0).SetUint64(testingValue), + RcvAddr: scAddress, + SndAddr: alice, + GasPrice: 0, + GasLimit: 5000, + Data: "_main", + Signature: nil, + Challenge: nil, + } + for i := 0; i < numRun; i++ { - tx = &transaction.Transaction{ - Nonce: aliceNonce, - Value: big.NewInt(0).SetUint64(testingValue), - RcvAddr: scAddress, - SndAddr: alice, - GasPrice: 0, - GasLimit: 5000, - Data: "_main", - Signature: nil, - Challenge: nil, - } - - startTime := time.Now() - err = txProc.ProcessTransaction(tx, round) - elapsedTime := time.Since(startTime) - fmt.Printf("time elapsed full process %s \n", elapsedTime.String()) - assert.Nil(tb, err) + tx.Nonce = aliceNonce - _, err = accnts.Commit() - assert.Nil(tb, err) + _ = txProc.ProcessTransaction(tx, round) aliceNonce++ } @@ -149,10 +144,11 @@ func TestVmDeployWithTransferAndExecuteERC20(t *testing.T) { scCodeString := hex.EncodeToString(scCode) - tx := vm.CreateTx( - t, + txProc, accnts, blockchainHook := vm.CreatePreparedTxProcessorAndAccountsWithVMs(t, ownerNonce, ownerAddressBytes, ownerBalance) + scAddress, _ := blockchainHook.NewAddress(ownerAddressBytes, ownerNonce, factory.ArwenVirtualMachine) + + tx := vm.CreateDeployTx( ownerAddressBytes, - vm.CreateEmptyAddress().Bytes(), ownerNonce, transferOnCalls, gasPrice, @@ -160,16 +156,9 @@ func TestVmDeployWithTransferAndExecuteERC20(t *testing.T) { scCodeString+"@"+hex.EncodeToString(factory.ArwenVirtualMachine), ) - txProc, accnts, blockchainHook := vm.CreatePreparedTxProcessorAndAccountsWithVMs(t, ownerNonce, ownerAddressBytes, ownerBalance) - err = txProc.ProcessTransaction(tx, round) assert.Nil(t, err) - _, err = accnts.Commit() - assert.Nil(t, err) - - scAddress, _ := blockchainHook.NewAddress(ownerAddressBytes, ownerNonce, factory.ArwenVirtualMachine) - alice := []byte("12345678901234567890123456789111") aliceNonce := uint64(0) _ = vm.CreateAccount(accnts, alice, aliceNonce, big.NewInt(1000000)) @@ -178,43 +167,18 @@ func TestVmDeployWithTransferAndExecuteERC20(t *testing.T) { _ = vm.CreateAccount(accnts, bob, 0, big.NewInt(1000000)) initAlice := big.NewInt(100000) - tx = &transaction.Transaction{ - Nonce: aliceNonce, - Value: initAlice, - RcvAddr: scAddress, - SndAddr: alice, - GasPrice: 0, - GasLimit: 5000, - Data: "topUp", - Signature: nil, - Challenge: nil, - } - start := time.Now() - err = txProc.ProcessTransaction(tx, round) - elapsedTime := time.Since(start) - fmt.Printf("time elapsed to process topup %s \n", elapsedTime.String()) - assert.Nil(t, err) + tx = vm.CreateTopUpTx(aliceNonce, initAlice, scAddress, alice) - _, err = accnts.Commit() + err = txProc.ProcessTransaction(tx, round) assert.Nil(t, err) aliceNonce++ - start = time.Now() + start := time.Now() nrTxs := 10000 for i := 0; i < nrTxs; i++ { - tx = &transaction.Transaction{ - Nonce: aliceNonce, - Value: big.NewInt(0), - RcvAddr: scAddress, - SndAddr: alice, - GasPrice: 0, - GasLimit: 5000, - Data: "transfer@" + hex.EncodeToString(bob) + "@" + transferOnCalls.String(), - Signature: nil, - Challenge: nil, - } + tx = vm.CreateTransferTx(aliceNonce, transferOnCalls, scAddress, alice, bob) err = txProc.ProcessTransaction(tx, round) assert.Nil(t, err) @@ -225,7 +189,7 @@ func TestVmDeployWithTransferAndExecuteERC20(t *testing.T) { _, err = accnts.Commit() assert.Nil(t, err) - elapsedTime = time.Since(start) + elapsedTime := time.Since(start) fmt.Printf("time elapsed to process %d ERC20 transfers %s \n", nrTxs, elapsedTime.String()) finalAlice := big.NewInt(0).Sub(initAlice, big.NewInt(int64(nrTxs)*transferOnCalls.Int64())) diff --git a/integrationTests/vm/testInitializer.go b/integrationTests/vm/testInitializer.go index 0e220124e6a..8e4dab51fe6 100644 --- a/integrationTests/vm/testInitializer.go +++ b/integrationTests/vm/testInitializer.go @@ -247,6 +247,26 @@ func CreateTx( return tx } +func CreateDeployTx( + senderAddressBytes []byte, + senderNonce uint64, + value *big.Int, + gasPrice uint64, + gasLimit uint64, + scCodeAndVMType string, +) *dataTransaction.Transaction { + + return &dataTransaction.Transaction{ + Nonce: senderNonce, + Value: value, + SndAddr: senderAddressBytes, + RcvAddr: CreateEmptyAddress().Bytes(), + Data: scCodeAndVMType, + GasPrice: gasPrice, + GasLimit: gasLimit, + } +} + func TestAccount( t *testing.T, accnts state.AccountsAdapter, @@ -290,5 +310,36 @@ func GetIntValueFromSC(accnts state.AccountsAdapter, scAddressBytes []byte, func scgd, _ := smartContract.NewSCDataGetter(vmContainer) returnedVals, _ := scgd.Get(scAddressBytes, funcName, args...) + return big.NewInt(0).SetBytes(returnedVals) } + +func CreateTopUpTx(nonce uint64, value *big.Int, scAddrress []byte, sndAddress []byte) *dataTransaction.Transaction { + return &dataTransaction.Transaction{ + Nonce: nonce, + Value: value, + RcvAddr: scAddrress, + SndAddr: sndAddress, + GasPrice: 0, + GasLimit: 5000, + Data: "topUp", + } +} + +func CreateTransferTx( + nonce uint64, + value *big.Int, + scAddrress []byte, + sndAddress []byte, + rcvAddress []byte, +) *dataTransaction.Transaction { + return &dataTransaction.Transaction{ + Nonce: nonce, + Value: big.NewInt(0), + RcvAddr: scAddrress, + SndAddr: sndAddress, + GasPrice: 0, + GasLimit: 5000, + Data: "transfer@" + hex.EncodeToString(rcvAddress) + "@" + value.String(), + } +} diff --git a/process/smartContract/scDataGetter.go b/process/smartContract/scDataGetter.go index 8389482f3ab..e613840997f 100644 --- a/process/smartContract/scDataGetter.go +++ b/process/smartContract/scDataGetter.go @@ -40,6 +40,7 @@ func (scdg *scDataGetter) getVMFromAddress(scAddress []byte) (vmcommon.VMExecuti if err != nil { return nil, err } + return vm, nil }