github.com/lino-network/lino@v0.6.11/test/bandwidth/general_fee_test.go (about)

     1  package bandwidth
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	sdk "github.com/cosmos/cosmos-sdk/types"
     8  	"github.com/cosmos/cosmos-sdk/x/auth"
     9  	"github.com/tendermint/tendermint/crypto/secp256k1"
    10  
    11  	"github.com/lino-network/lino/test"
    12  	linotypes "github.com/lino-network/lino/types"
    13  	bandwidthmn "github.com/lino-network/lino/x/bandwidth/manager"
    14  	bandwidthmodel "github.com/lino-network/lino/x/bandwidth/model"
    15  	types "github.com/lino-network/lino/x/vote/types"
    16  )
    17  
    18  // test validator deposit
    19  func TestMsgFee(t *testing.T) {
    20  
    21  	newAccountSignPriv := secp256k1.GenPrivKey()
    22  	newAccountName := "newuser"
    23  	baseT := time.Unix(0, 0)
    24  	baseTime := baseT.Unix()
    25  
    26  	lb := test.NewTestLinoBlockchain(t, test.DefaultNumOfVal, baseT)
    27  	bandwidthmn.BandwidthManagerTestMode = false
    28  
    29  	test.CreateAccountWithTime(t, newAccountName, lb, 0,
    30  		secp256k1.GenPrivKey(), newAccountSignPriv, "5000000000", baseTime)
    31  
    32  	voteDepositMsg := types.NewStakeInMsg(newAccountName, linotypes.LNO("3000000"))
    33  	test.SignCheckDeliver(t, lb, voteDepositMsg, 1, true, newAccountSignPriv, baseTime)
    34  
    35  	test.CheckBalance(t, newAccountName, lb, linotypes.NewCoinFromInt64((5000000000-3000000-1)*linotypes.Decimals-2523))
    36  
    37  	voteDepositSmallMsg := types.NewStakeInMsg(newAccountName, linotypes.LNO("1000"))
    38  	fee := auth.StdFee{Amount: sdk.NewCoins(sdk.NewCoin(linotypes.LinoCoinDenom, sdk.NewInt(100000000)))}
    39  	smFee := auth.StdFee{Amount: sdk.NewCoins(sdk.NewCoin(linotypes.LinoCoinDenom, sdk.NewInt(1)))}
    40  	test.SignCheckDeliverWithFee(t, lb, voteDepositSmallMsg, 1, false, newAccountSignPriv, baseTime+1, smFee)
    41  	test.SignCheckDeliverWithFee(t, lb, voteDepositSmallMsg, 2, true, newAccountSignPriv, baseTime+1, fee)
    42  
    43  	curU := "0.501692631996395802"
    44  	curUDec, _ := sdk.NewDecFromStr(curU)
    45  	test.CheckCurBlockInfo(t, bandwidthmodel.BlockInfo{
    46  		TotalMsgSignedByApp:  0,
    47  		TotalMsgSignedByUser: 1,
    48  		CurMsgFee:            linotypes.NewCoinFromInt64(2523),
    49  		CurU:                 curUDec,
    50  	}, lb)
    51  
    52  	test.RepeatSignCheckDeliver(t, lb, voteDepositSmallMsg, 3, true, newAccountSignPriv, baseTime+4, 900)
    53  	test.SimulateOneBlock(lb, baseTime+5)
    54  	test.CheckCurBlockInfo(t, bandwidthmodel.BlockInfo{
    55  		TotalMsgSignedByApp:  0,
    56  		TotalMsgSignedByUser: 0,
    57  		CurMsgFee:            linotypes.NewCoinFromInt64(50006),
    58  		CurU:                 curUDec,
    59  	}, lb)
    60  
    61  	test.RepeatSignCheckDeliver(t, lb, voteDepositSmallMsg, 903, true, newAccountSignPriv, baseTime+8, 900)
    62  	test.SimulateOneBlock(lb, baseTime+9)
    63  	test.CheckCurBlockInfo(t, bandwidthmodel.BlockInfo{
    64  		TotalMsgSignedByApp:  0,
    65  		TotalMsgSignedByUser: 0,
    66  		CurMsgFee:            linotypes.NewCoinFromInt64(565615),
    67  		CurU:                 curUDec,
    68  	}, lb)
    69  
    70  	test.RepeatSignCheckDeliver(t, lb, voteDepositSmallMsg, 1803, true, newAccountSignPriv, baseTime+12, 900)
    71  	test.SimulateOneBlock(lb, baseTime+13)
    72  	test.CheckCurBlockInfo(t, bandwidthmodel.BlockInfo{
    73  		TotalMsgSignedByApp:  0,
    74  		TotalMsgSignedByUser: 0,
    75  		CurMsgFee:            linotypes.NewCoinFromInt64(4044452),
    76  		CurU:                 curUDec,
    77  	}, lb)
    78  
    79  }