Skip to content

Commit

Permalink
Fix to run test with correct Header.Proof
Browse files Browse the repository at this point in the history
  • Loading branch information
Mdaiki0730 committed Nov 25, 2022
1 parent 75fb3c3 commit 4e6f34d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
13 changes: 7 additions & 6 deletions evidence/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"
"time"

"github.com/line/ostracon/crypto"
"github.com/line/ostracon/crypto/bls"
"github.com/line/ostracon/crypto/composite"
"github.com/line/ostracon/crypto/ed25519"
Expand Down Expand Up @@ -325,12 +326,11 @@ func TestLightClientAttackEvidenceLifecycle(t *testing.T) {
func TestRecoverPendingEvidence(t *testing.T) {
height := int64(10)
val := types.NewMockPV(types.PrivKeyComposite) // TODO 🏺 need to test by all key types
valAddress := val.PrivKey.PubKey().Address()
evidenceDB := dbm.NewMemDB()
stateStore := initializeValidatorState(val, height)
state, err := stateStore.Load()
require.NoError(t, err)
blockStore := initializeBlockStore(dbm.NewMemDB(), state, valAddress)
blockStore := initializeBlockStore(dbm.NewMemDB(), state, val.PrivKey)
// create previous pool and populate it
pool, err := evidence.NewPool(evidenceDB, stateStore, blockStore)
require.NoError(t, err)
Expand Down Expand Up @@ -424,13 +424,15 @@ func initializeValidatorState(privVal types.PrivValidator, height int64) sm.Stor

// initializeBlockStore creates a block storage and populates it w/ a dummy
// block at +height+.
func initializeBlockStore(db dbm.DB, state sm.State, valAddr []byte) *store.BlockStore {
func initializeBlockStore(db dbm.DB, state sm.State, valPrivkey crypto.PrivKey) *store.BlockStore {
blockStore := store.NewBlockStore(db)
valAddr := valPrivkey.PubKey().Address()

for i := int64(1); i <= state.LastBlockHeight; i++ {
round := int32(0)
lastCommit := makeCommit(i-1, valAddr)
proof := state.MakeHashMessage(round)
message := state.MakeHashMessage(round)
proof, _ := valPrivkey.VRFProve(message)
block, _ := state.MakeBlock(i, []types.Tx{}, lastCommit, nil,
state.Validators.SelectProposer(proof, i, round).Address, round, proof)
block.Header.Time = defaultEvidenceTime.Add(time.Duration(i) * time.Minute)
Expand All @@ -457,11 +459,10 @@ func makeCommit(height int64, valAddr []byte) *types.Commit {

func defaultTestPool(height int64) (*evidence.Pool, types.MockPV) {
val := types.NewMockPV(types.PrivKeyComposite) // TODO 🏺 need to test by all key types
valAddress := val.PrivKey.PubKey().Address()
evidenceDB := dbm.NewMemDB()
stateStore := initializeValidatorState(val, height)
state, _ := stateStore.Load()
blockStore := initializeBlockStore(dbm.NewMemDB(), state, valAddress)
blockStore := initializeBlockStore(dbm.NewMemDB(), state, val.PrivKey)
pool, err := evidence.NewPool(evidenceDB, stateStore, blockStore)
if err != nil {
panic("test evidence pool could not be created")
Expand Down
5 changes: 2 additions & 3 deletions evidence/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import (

"github.com/line/ostracon/light"

"github.com/coniks-sys/coniks-go/crypto/vrf"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

dbm "github.com/tendermint/tm-db"

"github.com/line/ostracon/crypto"
"github.com/line/ostracon/crypto/tmhash"
"github.com/line/ostracon/crypto/vrf"
"github.com/line/ostracon/evidence"
"github.com/line/ostracon/evidence/mocks"
"github.com/line/ostracon/libs/log"
Expand Down Expand Up @@ -735,7 +734,7 @@ func makeHeaderRandom(height int64) *types.Header {
LastResultsHash: crypto.CRandBytes(tmhash.Size),
EvidenceHash: crypto.CRandBytes(tmhash.Size),
ProposerAddress: crypto.CRandBytes(crypto.AddressSize),
Proof: crypto.CRandBytes(vrf.ProofSize),
Proof: crypto.CRandBytes(vrf.ProofLength()),
}
}

Expand Down

0 comments on commit 4e6f34d

Please sign in to comment.