-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add state generator test (#78)
* chore: add state generator test * chore: add more state generator tests
- Loading branch information
1 parent
0f5acec
commit ed6b4cd
Showing
6 changed files
with
446 additions
and
52 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package fetchers | ||
|
||
import ( | ||
"errors" | ||
"main/pkg/types" | ||
) | ||
|
||
type TestFetcher struct { | ||
WithProposals bool | ||
WithProposalsError bool | ||
WithVote bool | ||
WithVoteError bool | ||
} | ||
|
||
func (f *TestFetcher) GetAllProposals( | ||
prevHeight int64, | ||
) ([]types.Proposal, int64, *types.QueryError) { | ||
if f.WithProposalsError { | ||
return []types.Proposal{}, 123, &types.QueryError{ | ||
QueryError: errors.New("error"), | ||
} | ||
} | ||
|
||
if f.WithProposals { | ||
return []types.Proposal{ | ||
{ | ||
ID: "1", | ||
}, | ||
}, 123, nil | ||
} | ||
|
||
return []types.Proposal{}, 123, nil | ||
} | ||
|
||
func (f *TestFetcher) GetVote( | ||
proposal, voter string, | ||
prevHeight int64, | ||
) (*types.Vote, int64, *types.QueryError) { | ||
if f.WithVoteError { | ||
return nil, 456, &types.QueryError{ | ||
QueryError: errors.New("error"), | ||
} | ||
} | ||
|
||
if f.WithVote { | ||
return &types.Vote{ | ||
ProposalID: "1", | ||
Voter: "me", | ||
Options: types.VoteOptions{}, | ||
}, 456, nil | ||
} | ||
|
||
return nil, 456, nil | ||
} | ||
|
||
func (f *TestFetcher) GetTallies() (types.ChainTallyInfos, error) { | ||
return types.ChainTallyInfos{}, nil | ||
} | ||
|
||
func (f *TestFetcher) GetChainParams() (*types.ChainWithVotingParams, []error) { | ||
return nil, []error{} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package fs | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
type TestFS struct{} | ||
|
||
type TestFile struct { | ||
} | ||
|
||
func (f *TestFile) Write(p []byte) (int, error) { | ||
return 0, nil | ||
} | ||
|
||
func (f *TestFile) Close() error { | ||
return nil | ||
} | ||
|
||
func (fs *TestFS) ReadFile(name string) ([]byte, error) { | ||
return []byte{}, nil | ||
} | ||
|
||
func (fs *TestFS) WriteFile(name string, data []byte, perms os.FileMode) error { | ||
return nil | ||
} | ||
|
||
func (fs *TestFS) Create(path string) (File, error) { | ||
return &TestFile{}, nil // go | ||
} |
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
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
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
Oops, something went wrong.