github.com/aergoio/aergo@v1.3.1/consensus/chain/gathertx_test.go (about)

     1  package chain
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"testing"
     7  
     8  	"github.com/aergoio/aergo/state"
     9  	"github.com/aergoio/aergo/types"
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestGatherTXs(t *testing.T) {
    14  	txOp := NewCompTxOp(
    15  		TxOpFn(func(bState *state.BlockState, tx types.Transaction) error {
    16  			fmt.Println("x")
    17  			return nil
    18  		}),
    19  		TxOpFn(func(bState *state.BlockState, tx types.Transaction) error {
    20  			fmt.Println("y")
    21  			return nil
    22  		}))
    23  	err := txOp.Apply(nil, nil)
    24  	assert.New(t).Nil(err)
    25  }
    26  
    27  func TestGatherTXsWithError(t *testing.T) {
    28  	txDo := NewCompTxOp(
    29  		TxOpFn(func(bState *state.BlockState, tx types.Transaction) error {
    30  			fmt.Println("haha")
    31  			return nil
    32  		}),
    33  		TxOpFn(func(bState *state.BlockState, tx types.Transaction) error {
    34  			fmt.Println("blah")
    35  			return errors.New("blah blah error")
    36  		}))
    37  	err := txDo.Apply(nil, nil)
    38  	assert.New(t).NotNil(err)
    39  }