Skip to content

Commit

Permalink
refactor: replace index with sample.ZetaIndex(t)
Browse files Browse the repository at this point in the history
Signed-off-by: Francisco de Borja Aranda Castillejo <[email protected]>
  • Loading branch information
Francisco de Borja Aranda Castillejo committed Jul 13, 2024
1 parent 18e7acf commit 6e9e2cf
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions x/observer/keeper/voting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,13 @@ func TestKeeper_VoteOnBallot(t *testing.T) {
},
},
})
chain, _ := k.GetSupportedChainFromChainID(ctx, 0)

chain, _ := k.GetSupportedChainFromChainID(ctx, 0)
index := sample.ZetaIndex(t)
_, _, _, err := k.VoteOnBallot(
ctx,
chain,
"index",
index,
types.ObservationType_InboundTx,
sample.AccAddress(),
types.VoteType_SuccessObservation)
Expand All @@ -357,12 +358,13 @@ func TestKeeper_VoteOnBallot(t *testing.T) {
},
},
})
chain, _ := k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0))

chain, _ := k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0))
index := sample.ZetaIndex(t)
_, _, _, err := k.VoteOnBallot(
ctx,
chain,
"index",
index,
types.ObservationType_InboundTx,
sample.AccAddress(),
types.VoteType_SuccessObservation)
Expand All @@ -381,25 +383,26 @@ func TestKeeper_VoteOnBallot(t *testing.T) {
},
},
})
chain, _ := k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0))

voter := sample.AccAddress()
k.SetObserverSet(ctx, types.ObserverSet{
ObserverList: []string{voter},
})

chain, _ := k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0))
index := sample.ZetaIndex(t)
ballot, isFinalized, isNew, err := k.VoteOnBallot(
ctx,
chain,
"index",
index,
types.ObservationType_InboundTx,
voter,
types.VoteType_SuccessObservation)

require.NoError(t, err)
require.True(t, isFinalized)
require.True(t, isNew)
expectedBallot, found := k.GetBallot(ctx, "index")
expectedBallot, found := k.GetBallot(ctx, index)
require.True(t, found)
require.Equal(t, expectedBallot, ballot)
})
Expand All @@ -419,7 +422,6 @@ func TestKeeper_VoteOnBallot(t *testing.T) {
},
},
})
chain, _ := k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0))

voter := sample.AccAddress()
k.SetObserverSet(ctx, types.ObserverSet{
Expand All @@ -429,18 +431,20 @@ func TestKeeper_VoteOnBallot(t *testing.T) {
},
})

chain, _ := k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0))
index := sample.ZetaIndex(t)
ballot, isFinalized, isNew, err := k.VoteOnBallot(
ctx,
chain,
"index",
index,
types.ObservationType_InboundTx,
voter,
types.VoteType_SuccessObservation)

require.NoError(t, err)
require.False(t, isFinalized)
require.True(t, isNew)
expectedBallot, found := k.GetBallot(ctx, "index")
expectedBallot, found := k.GetBallot(ctx, index)
require.True(t, found)
require.Equal(t, expectedBallot, ballot)
})
Expand All @@ -456,18 +460,20 @@ func TestKeeper_VoteOnBallot(t *testing.T) {
},
},
})
chain, _ := k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0))

voter := sample.AccAddress()
k.SetObserverSet(ctx, types.ObserverSet{
ObserverList: []string{voter},
})

chain, _ := k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0))
index := sample.ZetaIndex(t)
threshold, err := sdk.NewDecFromStr("0.7")
require.NoError(t, err)

ballot := types.Ballot{
Index: "index",
BallotIdentifier: "index",
Index: index,
BallotIdentifier: index,
VoterList: []string{
sample.AccAddress(),
sample.AccAddress(),
Expand All @@ -485,15 +491,15 @@ func TestKeeper_VoteOnBallot(t *testing.T) {
ballot, isFinalized, isNew, err := k.VoteOnBallot(
ctx,
chain,
"index",
index,
types.ObservationType_InboundTx,
voter,
types.VoteType_SuccessObservation)

require.NoError(t, err)
require.False(t, isFinalized)
require.False(t, isNew)
expectedBallot, found := k.GetBallot(ctx, "index")
expectedBallot, found := k.GetBallot(ctx, index)
require.True(t, found)
require.Equal(t, expectedBallot, ballot)
})
Expand All @@ -509,18 +515,19 @@ func TestKeeper_VoteOnBallot(t *testing.T) {
},
},
})
chain, _ := k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0))

voter := sample.AccAddress()
k.SetObserverSet(ctx, types.ObserverSet{
ObserverList: []string{voter},
})

index := sample.ZetaIndex(t)
threshold, err := sdk.NewDecFromStr("0.1")
require.NoError(t, err)

ballot := types.Ballot{
Index: "index",
BallotIdentifier: "index",
Index: index,
BallotIdentifier: index,
VoterList: []string{
sample.AccAddress(),
sample.AccAddress(),
Expand All @@ -535,18 +542,19 @@ func TestKeeper_VoteOnBallot(t *testing.T) {
}
k.SetBallot(ctx, &ballot)

chain, _ := k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0))
ballot, isFinalized, isNew, err := k.VoteOnBallot(
ctx,
chain,
"index",
index,
types.ObservationType_InboundTx,
voter,
types.VoteType_SuccessObservation)

require.NoError(t, err)
require.True(t, isFinalized)
require.False(t, isNew)
expectedBallot, found := k.GetBallot(ctx, "index")
expectedBallot, found := k.GetBallot(ctx, index)
require.True(t, found)
require.Equal(t, expectedBallot, ballot)
})
Expand Down

0 comments on commit 6e9e2cf

Please sign in to comment.