Skip to content

Commit

Permalink
Merge pull request #4010 from ElrondNetwork/fix-integration-tests
Browse files Browse the repository at this point in the history
Fixed integration tests
  • Loading branch information
iulianpascalau committed Apr 20, 2022
2 parents e8701e1 + c20cc76 commit 49f8528
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ on:
branches:
- master
pull_request:
branches: [ master, development ]
branches: [ master, development, feat/*, rc/* ]

workflow_dispatch:

jobs:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ on:
branches:
- master
pull_request:
branches: [ master, development ]
branches: [ master, development, feat/*, rc/* ]

jobs:
golangci:
name: golangci linter
Expand Down
2 changes: 1 addition & 1 deletion integrationTests/vm/arwen/arwenvm/arwenVM_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func TestSCMoveBalanceBeforeSCDeploy(t *testing.T) {
_, err = testContext.TxProcessor.ProcessTransaction(tx)

require.Equal(t, process.ErrFailedTransaction, err)
require.Equal(t, process.ErrAccountNotPayable, testContext.GetLatestError())
require.Equal(t, process.ErrAccountNotPayable, testContext.GetCompositeTestError())
vm.TestAccount(
t,
testContext.Accounts,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !race
// +build !race

package badcontracts
Expand Down
12 changes: 6 additions & 6 deletions integrationTests/vm/arwen/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func (context *TestContext) DeploySC(wasmPath string, parametersString string) e
return err
}

err = context.GetLatestError()
err = context.GetCompositeTestError()
if err != nil {
return err
}
Expand Down Expand Up @@ -550,7 +550,7 @@ func (context *TestContext) UpgradeSC(wasmPath string, parametersString string)
return err
}

err = context.GetLatestError()
err = context.GetCompositeTestError()
if err != nil {
return err
}
Expand Down Expand Up @@ -626,7 +626,7 @@ func (context *TestContext) ExecuteSCWithValue(sender *testParticipant, txData s
return err
}

err = context.GetLatestError()
err = context.GetCompositeTestError()
if err != nil {
return err
}
Expand Down Expand Up @@ -698,9 +698,9 @@ func (context *TestContext) GoToEpoch(epoch int) {
context.BlockchainHook.SetCurrentHeader(header)
}

// GetLatestError -
func (context *TestContext) GetLatestError() error {
return context.ScProcessor.GetLatestTestError()
// GetCompositeTestError -
func (context *TestContext) GetCompositeTestError() error {
return context.ScProcessor.GetCompositeTestError()
}

// FormatHexNumber -
Expand Down
6 changes: 3 additions & 3 deletions integrationTests/vm/testInitializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ func (vmTestContext *VMTestContext) Close() {
_ = vmTestContext.VMContainer.Close()
}

// GetLatestError -
func (vmTestContext *VMTestContext) GetLatestError() error {
return vmTestContext.ScProcessor.GetLatestTestError()
// GetCompositeTestError -
func (vmTestContext *VMTestContext) GetCompositeTestError() error {
return vmTestContext.ScProcessor.GetCompositeTestError()
}

// CreateBlockStarted -
Expand Down
6 changes: 3 additions & 3 deletions integrationTests/vm/txsFee/multiESDTTransfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestMultiESDTTransferShouldWork(t *testing.T) {
retCode, err := testContext.TxProcessor.ProcessTransaction(tx)
require.Equal(t, vmcommon.Ok, retCode)
require.Nil(t, err)
require.Nil(t, testContext.GetLatestError())
require.Nil(t, testContext.GetCompositeTestError())

_, err = testContext.Accounts.Commit()
require.Nil(t, err)
Expand Down Expand Up @@ -68,8 +68,8 @@ func TestMultiESDTTransferShouldWork(t *testing.T) {
testIndexer.SaveTransaction(tx, block.TxBlock, intermediateTxs)

indexerTx := testIndexer.GetIndexerPreparedTransaction(t)
require.Equal(t, uint64(4000), indexerTx.GasUsed)
require.Equal(t, "40000", indexerTx.Fee)
require.Equal(t, uint64(133), indexerTx.GasUsed)
require.Equal(t, "1330", indexerTx.Fee)

allLogs := testContext.TxsLogsProcessor.GetAllCurrentLogs()
require.NotNil(t, allLogs)
Expand Down
4 changes: 2 additions & 2 deletions integrationTests/vm/txsFee/multiShard/moveBalance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestMoveBalanceContractAddressDataFieldNilShouldConsumeGas(t *testing.T) {
retCode, err := testContext.TxProcessor.ProcessTransaction(tx)
require.Equal(t, vmcommon.UserError, retCode)
require.Nil(t, err)
require.Equal(t, errors.New("sending value to non payable contract"), testContext.GetLatestError())
require.Equal(t, errors.New("sending value to non payable contract"), testContext.GetCompositeTestError())

_, err = testContext.Accounts.Commit()
require.Nil(t, err)
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestMoveBalanceContractAddressDataFieldNotNilShouldConsumeGas(t *testing.T)
retCode, err := testContext.TxProcessor.ProcessTransaction(tx)
require.Equal(t, vmcommon.UserError, retCode)
require.Nil(t, err)
require.Equal(t, errors.New("invalid contract code (not found)"), testContext.GetLatestError())
require.Equal(t, errors.New("invalid contract code (not found): contract not found"), testContext.GetCompositeTestError())

_, err = testContext.Accounts.Commit()
require.Nil(t, err)
Expand Down
4 changes: 2 additions & 2 deletions integrationTests/vm/txsFee/scDeploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestScDeployShouldWork(t *testing.T) {

_, err = testContext.TxProcessor.ProcessTransaction(tx)
require.Nil(t, err)
require.Nil(t, testContext.GetLatestError())
require.Nil(t, testContext.GetCompositeTestError())

_, err = testContext.Accounts.Commit()
require.Nil(t, err)
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestScDeployInsufficientGasLimitShouldNotConsumeGas(t *testing.T) {

_, err = testContext.TxProcessor.ProcessTransaction(tx)
require.Equal(t, process.ErrInsufficientGasLimitInTx, err)
require.Nil(t, testContext.GetLatestError())
require.Nil(t, testContext.GetCompositeTestError())

_, err = testContext.Accounts.Commit()
require.Nil(t, err)
Expand Down
31 changes: 23 additions & 8 deletions process/smartContract/testScProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ func NewTestScProcessor(internalData *scProcessor) *TestScProcessor {
return &TestScProcessor{internalData}
}

// GetLatestTestError locates the latest error in the collection of smart contracts results
func (tsp *TestScProcessor) GetLatestTestError() error {
// GetCompositeTestError composes all errors found in the logs or by parsing the scr forwarder's contents
func (tsp *TestScProcessor) GetCompositeTestError() error {
var returnError error

if tsp.flagCleanUpInformativeSCRs.IsSet() {
allLogs := tsp.txLogsProcessor.GetAllCurrentLogs()
for _, logs := range allLogs {
for _, event := range logs.GetLogEvents() {
if string(event.GetIdentifier()) == signalError {
return fmt.Errorf(string(event.GetTopics()[1]))
returnError = wrapErrorIfNotContains(returnError, string(event.GetTopics()[1]))
}
}
}
Expand All @@ -39,7 +40,7 @@ func (tsp *TestScProcessor) GetLatestTestError() error {
GetIntermediateTransactions() []data.TransactionHandler
})
if !ok {
return nil
return returnError
}

scResults := scrProvider.GetIntermediateTransactions()
Expand All @@ -64,17 +65,31 @@ func (tsp *TestScProcessor) GetLatestTestError() error {
if err == nil {
returnCodeAsString := string(returnCode)
if returnCodeAsString == "ok" || returnCodeAsString == "" {
return nil
return returnError
}
return fmt.Errorf(returnCodeAsString)
return wrapErrorIfNotContains(returnError, returnCodeAsString)
}

return fmt.Errorf(returnCodeHex)
return wrapErrorIfNotContains(returnError, returnCodeHex)
}

tsp.txLogsProcessor.Clean()
tsp.scrForwarder.CreateBlockStarted()

return nil
return returnError
}

func wrapErrorIfNotContains(originalError error, msg string) error {
if originalError == nil {
return fmt.Errorf(msg)
}

alreadyContainsMessage := strings.Contains(originalError.Error(), msg)
if alreadyContainsMessage {
return originalError
}

return fmt.Errorf("%s: %s", originalError.Error(), msg)
}

// GetGasRemaining returns the remaining gas from the last transaction
Expand Down

0 comments on commit 49f8528

Please sign in to comment.