github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/evm/txs/factory_test.go (about)

     1  package txs
     2  
     3  import (
     4  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     5  	"github.com/fibonacci-chain/fbc/x/evm/txs/base"
     6  	"github.com/fibonacci-chain/fbc/x/evm/txs/check"
     7  	"github.com/fibonacci-chain/fbc/x/evm/txs/deliver"
     8  	"github.com/fibonacci-chain/fbc/x/evm/txs/tracetxlog"
     9  	"reflect"
    10  	"testing"
    11  )
    12  
    13  func Test_factory_CreateTx(t *testing.T) {
    14  	type fields struct {
    15  		Config base.Config
    16  	}
    17  	traceTxConfig := base.Config{Keeper: &base.Keeper{}, Ctx: sdk.Context{}.WithIsTraceTxLog(true)}
    18  	checkTxConfig := base.Config{Keeper: &base.Keeper{}, Ctx: sdk.Context{}.WithIsCheckTx(true)}
    19  	deliverTxConfig := base.Config{Keeper: &base.Keeper{}, Ctx: sdk.Context{}}
    20  	tests := []struct {
    21  		name    string
    22  		fields  fields
    23  		want    Tx
    24  		wantErr bool
    25  	}{
    26  		{"1. factory keeper is nil", fields{Config: base.Config{Keeper: nil, Ctx: sdk.Context{}}}, nil, true},
    27  		{"2. create trace tx log", fields{Config: traceTxConfig}, tracetxlog.NewTx(traceTxConfig), false},
    28  		{"3. create check tx log", fields{Config: checkTxConfig}, check.NewTx(checkTxConfig), false},
    29  		{"4. create deliver(default) tx log", fields{Config: deliverTxConfig}, deliver.NewTx(deliverTxConfig), false},
    30  	}
    31  	for _, tt := range tests {
    32  		t.Run(tt.name, func(t *testing.T) {
    33  			factory := NewFactory(tt.fields.Config)
    34  			got, err := factory.CreateTx()
    35  			if (err != nil) != tt.wantErr {
    36  				t.Errorf("CreateTx() error = %v, wantErr %v", err, tt.wantErr)
    37  				return
    38  			}
    39  			if !reflect.DeepEqual(got, tt.want) {
    40  				t.Errorf("CreateTx() got = %v, want %v", got, tt.want)
    41  			}
    42  		})
    43  	}
    44  }