Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evlekht committed Jan 15, 2024
1 parent 647d0df commit 3cd455f
Showing 1 changed file with 59 additions and 36 deletions.
95 changes: 59 additions & 36 deletions db/dbmodel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,7 @@ func TestQueryDACProposals(t *testing.T) {

baseFeeProposalType := models.ProposalTypeBaseFee
proposalStatusSuccess := models.ProposalStatusSuccess
params := &params.ListDACProposalsParams{
queryParams := &params.ListDACProposalsParams{
ListParams: params.ListParams{
Limit: 3,
Offset: 1,
Expand All @@ -1742,9 +1742,9 @@ func TestQueryDACProposals(t *testing.T) {
{ // 0
ID: "1111111111111111111111111111111111111111111111111",
ProposerAddr: "111111111111111111111111111111111",
StartTime: params.MinStartTime,
EndTime: params.MinStartTime.Add(time.Hour),
Type: *params.ProposalType,
StartTime: queryParams.MinStartTime,
EndTime: queryParams.MinStartTime.Add(time.Hour),
Type: *queryParams.ProposalType,
IsAdminProposal: false,
SerializedBytes: []byte("1 serialized proposal bytes 1"),
Options: []byte("1 serialized proposal options 1"),
Expand All @@ -1755,105 +1755,118 @@ func TestQueryDACProposals(t *testing.T) {
{ // 1
ID: "2222222222222222222222222222222222222222222222222",
ProposerAddr: "222222222222222222222222222222222",
StartTime: params.MinStartTime,
EndTime: params.MinStartTime.Add(time.Hour),
StartTime: queryParams.MinStartTime,
EndTime: queryParams.MinStartTime.Add(time.Hour),
Type: models.ProposalType(100), // different proposal type
IsAdminProposal: false,
SerializedBytes: []byte("2 serialized proposal bytes 2"),
Options: []byte("2 serialized proposal options 2"),
Data: []byte("2 serialized proposal data 2"),
Memo: []byte("2 serialized proposal memo 2"),
Status: *params.ProposalStatus,
Status: *queryParams.ProposalStatus,
},
{ // 2
ID: "3333333333333333333333333333333333333333333333333",
ProposerAddr: "333333333333333333333333333333333",
StartTime: params.MinStartTime.Add(-time.Second), // starttime is before
EndTime: params.MinStartTime.Add(time.Hour),
Type: *params.ProposalType,
StartTime: queryParams.MinStartTime.Add(-time.Second), // starttime is before
EndTime: queryParams.MinStartTime.Add(time.Hour),
Type: *queryParams.ProposalType,
IsAdminProposal: false,
SerializedBytes: []byte("3 serialized proposal bytes 3"),
Options: []byte("3 serialized proposal options 3"),
Data: []byte("3 serialized proposal data 3"),
Memo: []byte("3 serialized proposal memo 3"),
Status: *params.ProposalStatus,
Status: *queryParams.ProposalStatus,
},
{ // 3
ID: "4444444444444444444444444444444444444444444444444",
ProposerAddr: "444444444444444444444444444444444",
StartTime: params.MaxStartTime.Add(time.Second), // starttime is after
EndTime: params.MaxStartTime.Add(time.Hour),
Type: *params.ProposalType,
StartTime: queryParams.MaxStartTime.Add(time.Second), // starttime is after
EndTime: queryParams.MaxStartTime.Add(time.Hour),
Type: *queryParams.ProposalType,
IsAdminProposal: false,
SerializedBytes: []byte("4 serialized proposal bytes 4"),
Options: []byte("4 serialized proposal options 4"),
Data: []byte("4 serialized proposal data 4"),
Memo: []byte("4 serialized proposal memo 4"),
Status: *params.ProposalStatus,
Status: *queryParams.ProposalStatus,
},
{ // 4 // cut by offset
ID: "5555555555555555555555555555555555555555555555555",
ProposerAddr: "555555555555555555555555555555555",
StartTime: params.MinStartTime,
EndTime: params.MinStartTime.Add(time.Hour),
Type: *params.ProposalType,
StartTime: queryParams.MinStartTime,
EndTime: queryParams.MinStartTime.Add(time.Hour),
Type: *queryParams.ProposalType,
IsAdminProposal: false,
SerializedBytes: []byte("5 serialized proposal bytes 5"),
Options: []byte("5 serialized proposal options 5"),
Data: []byte("5 serialized proposal data 5"),
Memo: []byte("5 serialized proposal memo 5"),
Status: *params.ProposalStatus,
Status: *queryParams.ProposalStatus,
},
{ // 5
ID: "6666666666666666666666666666666666666666666666666",
ProposerAddr: "666666666666666666666666666666666",
StartTime: params.MinStartTime,
EndTime: params.MinStartTime.Add(time.Hour),
Type: *params.ProposalType,
StartTime: queryParams.MinStartTime,
EndTime: queryParams.MinStartTime.Add(time.Hour),
Type: *queryParams.ProposalType,
SerializedBytes: []byte("6 serialized proposal bytes 6"),
Options: []byte("6 serialized proposal options 6"),
Data: []byte("6 serialized proposal data 6"),
Memo: []byte("6 serialized proposal memo 6"),
Status: *params.ProposalStatus,
Status: *queryParams.ProposalStatus,
},
{ // 6
ID: "7777777777777777777777777777777777777777777777777",
ProposerAddr: "777777777777777777777777777777777",
StartTime: params.MinStartTime,
EndTime: params.MinStartTime.Add(time.Hour),
Type: *params.ProposalType,
StartTime: queryParams.MinStartTime,
EndTime: queryParams.MinStartTime.Add(time.Hour),
Type: *queryParams.ProposalType,
IsAdminProposal: false,
SerializedBytes: []byte("7 serialized proposal bytes 7"),
Options: []byte("7 serialized proposal options 7"),
Data: []byte("7 serialized proposal data 7"),
Memo: []byte("7 serialized proposal memo 7"),
Status: *params.ProposalStatus,
Status: *queryParams.ProposalStatus,
},
{ // 7
ID: "8888888888888888888888888888888888888888888888888",
ProposerAddr: "888888888888888888888888888888888",
StartTime: params.MinStartTime,
EndTime: params.MinStartTime.Add(time.Hour),
Type: *params.ProposalType,
StartTime: queryParams.MinStartTime,
EndTime: queryParams.MinStartTime.Add(time.Hour),
Type: *queryParams.ProposalType,
IsAdminProposal: true,
SerializedBytes: []byte("8 serialized proposal bytes 8"),
Options: []byte("8 serialized proposal options 8"),
Data: []byte("8 serialized proposal data 8"),
Memo: []byte("8 serialized proposal memo 8"),
Status: *params.ProposalStatus,
Status: *queryParams.ProposalStatus,
},
{ // 8 // cut by limit
ID: "9999999999999999999999999999999999999999999999999",
ProposerAddr: "999999999999999999999999999999999",
StartTime: params.MinStartTime,
EndTime: params.MinStartTime.Add(time.Hour),
Type: *params.ProposalType,
StartTime: queryParams.MinStartTime,
EndTime: queryParams.MinStartTime.Add(time.Hour),
Type: *queryParams.ProposalType,
IsAdminProposal: false,
SerializedBytes: []byte("9 serialized proposal bytes 9"),
Options: []byte("9 serialized proposal options 9"),
Data: []byte("9 serialized proposal data 9"),
Memo: []byte("9 serialized proposal memo 9"),
Status: *params.ProposalStatus,
Status: *queryParams.ProposalStatus,
},
{ // 9
ID: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
ProposerAddr: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
StartTime: queryParams.MinStartTime,
EndTime: queryParams.MinStartTime.Add(time.Hour),
Type: *queryParams.ProposalType,
IsAdminProposal: true,
SerializedBytes: []byte("A serialized proposal bytes A"),
Options: []byte("A serialized proposal options A"),
Data: []byte("A serialized proposal data A"),
Memo: []byte("A serialized proposal memo A"),
Status: models.ProposalStatusFailed, // different proposal status, but will be included in "completed" status query
},
}

Expand All @@ -1866,9 +1879,19 @@ func TestQueryDACProposals(t *testing.T) {
require.NoError(t, p.InsertDACProposal(ctx, rawDBConn.NewSession(stream), proposal))
}

resultProposals, err := p.QueryDACProposals(ctx, rawDBConn.NewSession(stream), params)
resultProposals, err := p.QueryDACProposals(ctx, rawDBConn.NewSession(stream), queryParams)
require.NoError(t, err)
require.Equal(t, []DACProposal{*proposals[5], *proposals[6], *proposals[7]}, resultProposals)

proposalStatusCompleted := models.ProposalStatusCompleted
queryParams = &params.ListDACProposalsParams{
ProposalStatus: &proposalStatusCompleted,
}
resultProposals, err = p.QueryDACProposals(ctx, rawDBConn.NewSession(stream), queryParams)
require.NoError(t, err)
require.Equal(t,
[]DACProposal{*proposals[1], *proposals[2], *proposals[3], *proposals[4], *proposals[5], *proposals[6], *proposals[7], *proposals[8], *proposals[9]},
resultProposals)
}

// TestInsertDACVote also tests QueryDACProposalVotes
Expand Down

0 comments on commit 3cd455f

Please sign in to comment.