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 7c99da2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 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
6 changes: 3 additions & 3 deletions types/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ func TestHeaderHash(t *testing.T) {
EvidenceHash: tmhash.Sum([]byte("evidence_hash")),
ProposerAddress: crypto.AddressHash([]byte("proposer_address")),
Round: 1,
Proof: tmhash.Sum([]byte("proof")),
}, hexBytesFromString("0368E6F15B6B7BC9DC5B10F36F37D6F867E132A22333F083A11290324274E183")},
Proof: make([]byte, vrf.ProofLength()),
}, hexBytesFromString("5616282392957326AF5D014F227B82C9EB1081CD7FB85C8BAE1476E2E3BF77F8")},
{"nil header yields nil", nil, nil},
{"nil VotersHash yields nil", &Header{
Version: tmversion.Consensus{Block: 1, App: 2},
Expand All @@ -537,7 +537,7 @@ func TestHeaderHash(t *testing.T) {
EvidenceHash: tmhash.Sum([]byte("evidence_hash")),
ProposerAddress: crypto.AddressHash([]byte("proposer_address")),
Round: 1,
Proof: tmhash.Sum([]byte("proof")),
Proof: make([]byte, vrf.ProofLength()),
}, nil},
}
for _, tc := range testCases {
Expand Down

0 comments on commit 7c99da2

Please sign in to comment.