Skip to content

Commit

Permalink
fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
sasurobert committed Sep 25, 2019
1 parent 6fec434 commit 2f52ce8
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 59 deletions.
82 changes: 23 additions & 59 deletions integrationTests/vm/arwen/arwenVM_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
}
Expand All @@ -149,27 +144,21 @@ 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,
gasLimit,
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))
Expand All @@ -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)
Expand All @@ -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()))
Expand Down
51 changes: 51 additions & 0 deletions integrationTests/vm/testInitializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
}
}
1 change: 1 addition & 0 deletions process/smartContract/scDataGetter.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (scdg *scDataGetter) getVMFromAddress(scAddress []byte) (vmcommon.VMExecuti
if err != nil {
return nil, err
}

return vm, nil
}

Expand Down

0 comments on commit 2f52ce8

Please sign in to comment.