github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/ammswap/keeper/swap_test.go (about)

     1  //go:build ignore
     2  
     3  package keeper
     4  
     5  import (
     6  	"fmt"
     7  	"testing"
     8  
     9  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
    10  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/supply"
    11  	abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types"
    12  	"github.com/fibonacci-chain/fbc/x/ammswap/types"
    13  	token "github.com/fibonacci-chain/fbc/x/token/types"
    14  	"github.com/stretchr/testify/require"
    15  )
    16  
    17  func TestKeeper_IsTokenExistTable(t *testing.T) {
    18  	mapp, _ := GetTestInput(t, 1)
    19  	keeper := mapp.swapKeeper
    20  	mapp.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: 2}})
    21  	ctx := mapp.BaseApp.NewContext(false, abci.Header{}).WithBlockHeight(10)
    22  	mapp.supplyKeeper.SetSupply(ctx, supply.NewSupply(mapp.TotalCoinsSupply))
    23  
    24  	tests := []struct {
    25  		testCase         string
    26  		tokennames       []string
    27  		tokentypes       []int
    28  		tokenname        string
    29  		exceptResultCode uint32
    30  	}{
    31  		{"token is not exist", []string{"toa", "tob"}, []int{1, 1}, "nota", sdk.CodeInternal},
    32  		{"token is not exist", nil, nil, "nota", sdk.CodeInternal},
    33  		{"token is exist", []string{"boa", "bob"}, []int{1, 1}, "boa", sdk.CodeOK},
    34  		{"token is pool token", []string{"tkoa", "tkob"}, []int{1, 2}, "tkob", sdk.CodeInvalidCoins},
    35  	}
    36  
    37  	for _, testCase := range tests {
    38  		fmt.Println(testCase.testCase)
    39  		genToken(mapp, ctx, testCase.tokennames, testCase.tokentypes)
    40  		result := keeper.IsTokenExist(ctx, testCase.tokenname)
    41  		if nil != result {
    42  			if testCase.exceptResultCode == 0 {
    43  				require.Nil(t, result)
    44  			} else {
    45  				require.NotNil(t, result)
    46  			}
    47  		}
    48  	}
    49  
    50  }
    51  
    52  func genToken(mapp *TestInput, ctx sdk.Context, tokennames []string, tokentypes []int) {
    53  	for i, t := range tokennames {
    54  		tok := token.Token{
    55  			Description:         t,
    56  			Symbol:              t,
    57  			OriginalSymbol:      t,
    58  			WholeName:           t,
    59  			OriginalTotalSupply: sdk.NewDec(0),
    60  			Owner:               supply.NewModuleAddress(types.ModuleName),
    61  			Mintable:            true,
    62  			Type:                tokentypes[i],
    63  		}
    64  		mapp.tokenKeeper.NewToken(ctx, tok)
    65  	}
    66  }