github.com/gravity-devs/liquidity@v1.5.3/x/liquidity/types/keys_test.go (about)

     1  package types_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/suite"
     7  
     8  	"github.com/gravity-devs/liquidity/x/liquidity/types"
     9  )
    10  
    11  type keysTestSuite struct {
    12  	suite.Suite
    13  }
    14  
    15  func TestKeysTestSuite(t *testing.T) {
    16  	suite.Run(t, new(keysTestSuite))
    17  }
    18  
    19  func (s *keysTestSuite) TestGetLiquidityPoolKey() {
    20  	s.Require().Equal([]byte{0x11, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x9}, types.GetPoolKey(9))
    21  	s.Require().Equal([]byte{0x11, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, types.GetPoolKey(0))
    22  }
    23  
    24  func (s *keysTestSuite) TestGetLiquidityPoolByReserveAccIndexKey() {
    25  	len20acc, err := types.GetReserveAcc("poolD35A0CC16EE598F90B044CE296A405BA9C381E38837599D96F2F70C2F02A23A4", false)
    26  	s.Require().NoError(err)
    27  	len32acc, err := types.GetReserveAcc("poolD35A0CC16EE598F90B044CE296A405BA9C381E38837599D96F2F70C2F02A23A4", true)
    28  	s.Require().NoError(err)
    29  
    30  	s.Require().Equal([]byte{0x12}, types.GetPoolByReserveAccIndexKey(nil))
    31  	s.Require().Equal([]byte{0x12, 0x14, 0xd3, 0x5a, 0xc, 0xc1, 0x6e, 0xe5, 0x98, 0xf9, 0xb, 0x4, 0x4c, 0xe2, 0x96, 0xa4, 0x5, 0xba, 0x9c, 0x38, 0x1e, 0x38}, types.GetPoolByReserveAccIndexKey(len20acc))
    32  	s.Require().Equal([]byte{0x12, 0x20, 0x87, 0xec, 0x7d, 0x8f, 0xca, 0xee, 0xb0, 0xaa, 0x2, 0x1d, 0xc7, 0xd0, 0x69, 0xb, 0x1e, 0xb8, 0xfb, 0x3e, 0x8e, 0xb1, 0x22, 0x7f, 0x78, 0xae, 0x6c, 0x5e, 0x8a, 0x96, 0xc6, 0x7, 0xc4, 0x98}, types.GetPoolByReserveAccIndexKey(len32acc))
    33  }
    34  
    35  func (s *keysTestSuite) TestGetLiquidityPoolBatchKey() {
    36  	s.Require().Equal([]byte{0x22, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa}, types.GetPoolBatchKey(10))
    37  	s.Require().Equal([]byte{0x22, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, types.GetPoolBatchKey(0))
    38  }
    39  
    40  func (s *keysTestSuite) TestGetLiquidityPoolBatchDepositMsgsPrefix() {
    41  	s.Require().Equal([]byte{0x31, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa}, types.GetPoolBatchDepositMsgStatesPrefix(10))
    42  	s.Require().Equal([]byte{0x31, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, types.GetPoolBatchDepositMsgStatesPrefix(0))
    43  }
    44  
    45  func (s *keysTestSuite) TestGetLiquidityPoolBatchWithdrawMsgsPrefix() {
    46  	s.Require().Equal([]byte{0x32, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa}, types.GetPoolBatchWithdrawMsgsPrefix(10))
    47  	s.Require().Equal([]byte{0x32, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, types.GetPoolBatchWithdrawMsgsPrefix(0))
    48  }
    49  
    50  func (s *keysTestSuite) TestGetLiquidityPoolBatchSwapMsgsPrefix() {
    51  	s.Require().Equal([]byte{0x33, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa}, types.GetPoolBatchSwapMsgStatesPrefix(10))
    52  	s.Require().Equal([]byte{0x33, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, types.GetPoolBatchSwapMsgStatesPrefix(0))
    53  }
    54  
    55  func (s *keysTestSuite) TestGetLiquidityPoolBatchDepositMsgIndex() {
    56  	s.Require().Equal([]byte{0x31, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa},
    57  		types.GetPoolBatchDepositMsgStateIndexKey(10, 10))
    58  	s.Require().Equal([]byte{0x31, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
    59  		types.GetPoolBatchDepositMsgStateIndexKey(0, 0))
    60  }
    61  
    62  func (s *keysTestSuite) TestGetLiquidityPoolBatchWithdrawMsgIndex() {
    63  	s.Require().Equal([]byte{0x32, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa},
    64  		types.GetPoolBatchWithdrawMsgStateIndexKey(10, 10))
    65  	s.Require().Equal([]byte{0x32, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
    66  		types.GetPoolBatchWithdrawMsgStateIndexKey(0, 0))
    67  }
    68  
    69  func (s *keysTestSuite) TestGetLiquidityPoolBatchSwapMsgIndex() {
    70  	s.Require().Equal([]byte{0x33, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa},
    71  		types.GetPoolBatchSwapMsgStateIndexKey(10, 10))
    72  	s.Require().Equal([]byte{0x33, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
    73  		types.GetPoolBatchSwapMsgStateIndexKey(0, 0))
    74  }