-
-
Save zsystm/c4f76bb003151e44a5b77b903b12445e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package keeper_test | |
import ( | |
"github.com/cosmos/cosmos-sdk/types/query" | |
"github.com/gogo/protobuf/proto" // Importing gogo/protobuf for Clone and other protobuf utilities | |
"github.com/piplabs/story/client/x/evmstaking/types" | |
) | |
func (s *TestSuite) TestGetWithdrawalQueue() { | |
require := s.Require() | |
ctx, keeper := s.Ctx, s.EVMStakingKeeper | |
testWithdrawals := []types.Withdrawal{ | |
types.NewWithdrawal(1, "delegator1", "validator1", "0x1111111111111111111111111111111111111111", 100), | |
types.NewWithdrawal(2, "delegator2", "validator2", "0x2222222222222222222222222222222222222222", 200), | |
types.NewWithdrawal(3, "delegator3", "validator3", "0x3333333333333333333333333333333333333333", 300), | |
} | |
// Add withdrawals | |
for _, w := range testWithdrawals { | |
err := keeper.AddWithdrawalToQueue(ctx, w) | |
require.NoError(err) | |
} | |
tcs := []struct { | |
name string | |
request *types.QueryGetWithdrawalQueueRequest | |
expectedCount int | |
expectedError string | |
checkPagination bool | |
}{ | |
{ | |
name: "pass: no pagination", | |
request: &types.QueryGetWithdrawalQueueRequest{ | |
Pagination: nil, | |
}, | |
expectedCount: 3, | |
expectedError: "", | |
}, | |
{ | |
name: "pass: with pagination limit 2", | |
request: &types.QueryGetWithdrawalQueueRequest{ | |
Pagination: &query.PageRequest{ | |
Limit: 2, | |
}, | |
}, | |
expectedCount: 2, | |
expectedError: "", | |
checkPagination: true, | |
}, | |
{ | |
name: "pass: with pagination offset 1", | |
request: &types.QueryGetWithdrawalQueueRequest{ | |
Pagination: &query.PageRequest{ | |
Offset: 1, | |
}, | |
}, | |
expectedCount: 2, | |
expectedError: "", | |
checkPagination: true, | |
}, | |
{ | |
name: "fail: nil request", | |
request: nil, | |
expectedCount: 0, | |
expectedError: "empty request", | |
}, | |
} | |
for _, tc := range tcs { | |
s.Run(tc.name, func() { | |
response, err := keeper.GetWithdrawalQueue(ctx, tc.request) | |
if tc.expectedError != "" { | |
require.Error(err) | |
require.Contains(err.Error(), tc.expectedError) | |
require.Nil(response) | |
} else { | |
require.NoError(err) | |
require.NotNil(response) | |
require.Len(response.Withdrawals, tc.expectedCount) | |
if tc.checkPagination { | |
require.NotNil(response.Pagination) | |
if tc.request.Pagination.Limit != 0 { | |
require.NotNil(response.Pagination.NextKey) | |
} | |
} | |
// Verify the content of the returned withdrawals by using proto.Equal | |
for i, w := range response.Withdrawals { | |
require.True(proto.Equal(&testWithdrawals[i], w), "expected: %v, got: %v", testWithdrawals[i], w) | |
} | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment