-
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.
feat: add event for voting finished (#82)
* feat: add event for voting finished * chore: fixed linting * chore: add marshal helper and tests * chore: add state manager test * chore: fixed linting
- Loading branch information
1 parent
7fac38e
commit c01f43c
Showing
15 changed files
with
336 additions
and
49 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,8 @@ | ||
{ | ||
"ChainInfos": { | ||
"cosmos": { | ||
"Chain": {}, | ||
"ProposalVotes": {} | ||
} | ||
} | ||
} |
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,18 @@ | ||
package events | ||
|
||
import ( | ||
"main/pkg/types" | ||
) | ||
|
||
type FinishedVotingEvent struct { | ||
Chain *types.Chain | ||
Proposal types.Proposal | ||
} | ||
|
||
func (e FinishedVotingEvent) Name() string { | ||
return "finished_voting" | ||
} | ||
|
||
func (e FinishedVotingEvent) IsAlert() bool { | ||
return false | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package state | ||
|
||
import ( | ||
"main/pkg/fs" | ||
"main/pkg/logger" | ||
"main/pkg/types" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestStateManagerLoadNotExisting(t *testing.T) { | ||
t.Parallel() | ||
|
||
log := logger.GetNopLogger() | ||
filesystem := &fs.TestFS{} | ||
|
||
manager := NewStateManager("non-existing.json", filesystem, log) | ||
manager.Load() | ||
|
||
assert.Empty(t, manager.State.ChainInfos) | ||
} | ||
|
||
func TestStateManagerLoadFailedUnmarshaling(t *testing.T) { | ||
t.Parallel() | ||
|
||
log := logger.GetNopLogger() | ||
filesystem := &fs.TestFS{} | ||
|
||
manager := NewStateManager("invalid-json.json", filesystem, log) | ||
manager.Load() | ||
|
||
assert.Empty(t, manager.State.ChainInfos) | ||
} | ||
|
||
func TestStateManagerLoadSuccess(t *testing.T) { | ||
t.Parallel() | ||
|
||
log := logger.GetNopLogger() | ||
filesystem := &fs.TestFS{} | ||
|
||
manager := NewStateManager("valid-state.json", filesystem, log) | ||
manager.Load() | ||
|
||
assert.NotEmpty(t, manager.State.ChainInfos) | ||
} | ||
|
||
func TestManagerSaveWithError(t *testing.T) { | ||
t.Parallel() | ||
|
||
log := logger.GetNopLogger() | ||
filesystem := &fs.TestFS{WithWriteError: true} | ||
|
||
manager := NewStateManager("out.json", filesystem, log) | ||
manager.Load() | ||
manager.Save() | ||
|
||
assert.Empty(t, manager.State.ChainInfos) | ||
} | ||
|
||
func TestManagerSaveWithoutError(t *testing.T) { | ||
t.Parallel() | ||
|
||
log := logger.GetNopLogger() | ||
filesystem := &fs.TestFS{} | ||
|
||
manager := NewStateManager("out.json", filesystem, log) | ||
manager.Load() | ||
manager.Save() | ||
|
||
assert.Empty(t, manager.State.ChainInfos) | ||
} | ||
|
||
func TestManagerCommitState(t *testing.T) { | ||
t.Parallel() | ||
|
||
log := logger.GetNopLogger() | ||
filesystem := &fs.TestFS{} | ||
|
||
state := NewState() | ||
state.SetProposal(&types.Chain{Name: "chain"}, types.Proposal{ID: "id"}) | ||
|
||
manager := NewStateManager("out.json", filesystem, log) | ||
manager.Load() | ||
assert.Empty(t, manager.State.ChainInfos) | ||
|
||
manager.CommitState(state) | ||
assert.NotEmpty(t, manager.State.ChainInfos) | ||
} |
Oops, something went wrong.