diff --git a/blockchain/msgs_test.go b/blockchain/msgs_test.go index 1deac988b..a4df2d48d 100644 --- a/blockchain/msgs_test.go +++ b/blockchain/msgs_test.go @@ -3,13 +3,15 @@ package blockchain import ( "encoding/hex" "fmt" - "github.com/gogo/protobuf/proto" + "math" + "testing" + "github.com/Finschia/ostracon/crypto" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "math" - "testing" + voivrf "github.com/oasisprotocol/curve25519-voi/primitives/ed25519/extra/ecvrf" bcproto "github.com/tendermint/tendermint/proto/tendermint/blockchain" ocbcproto "github.com/Finschia/ostracon/proto/ostracon/blockchain" @@ -146,6 +148,9 @@ func TestEncodeDecodeValidateMsg(t *testing.T) { nil, sm.InitStateVersion.Consensus) block.ProposerAddress = make([]byte, crypto.AddressSize) + round := int32(0) + proof := make([]byte, voivrf.ProofSize) + block.Entropy.Populate(round, proof) bpb, err := block.ToProto() require.NoError(t, err) @@ -167,7 +172,7 @@ func TestEncodeDecodeValidateMsg(t *testing.T) { { name: "ocbcproto.BlockResponse", // Ostracon args: args{pb: &ocbcproto.BlockResponse{Block: bpb}}, - want: []byte{0x1a, 0xf0, 0x1, 0xa, 0xed, 0x1, 0xa, 0x93, 0x1, 0xa, 0x2, 0x8, 0xb, 0x18, 0x3, 0x22, 0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1, 0x2a, 0x2, 0x12, 0x0, 0x32, 0x20, 0x1e, 0xba, 0x40, 0x13, 0xa, 0xf2, 0x5e, 0xd1, 0x9, 0x5f, 0x67, 0x86, 0xe5, 0x8d, 0xb9, 0x4d, 0xeb, 0xf4, 0x6a, 0x0, 0x7f, 0xc6, 0x8c, 0x20, 0x32, 0x39, 0x2f, 0xde, 0xdd, 0x32, 0x26, 0x7e, 0x3a, 0x20, 0xc4, 0xda, 0x88, 0xe8, 0x76, 0x6, 0x2a, 0xa1, 0x54, 0x34, 0x0, 0xd5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, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc2, 0x3e, 0x52, 0x12, 0x50, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, wantErr: assert.NoError, }, { diff --git a/rpc/core/blocks_test.go b/rpc/core/blocks_test.go index 526b70440..8b30e32cd 100644 --- a/rpc/core/blocks_test.go +++ b/rpc/core/blocks_test.go @@ -16,6 +16,7 @@ import ( cfg "github.com/Finschia/ostracon/config" "github.com/Finschia/ostracon/crypto" + "github.com/Finschia/ostracon/crypto/ed25519" tmrand "github.com/Finschia/ostracon/libs/rand" ctypes "github.com/Finschia/ostracon/rpc/core/types" rpctypes "github.com/Finschia/ostracon/rpc/jsonrpc/types" @@ -306,7 +307,11 @@ func storeTestBlocks(startHeight, numToMakeBlocks, numToMakeTxs int64, state sm. env.TxIndexer.Index(&abci.TxResult{Height: height, Index: uint32(txIndex), Tx: tx}) // nolint:errcheck } lastCommit := types.NewCommit(lastHeight, round, blockID, commitSigs) - block, _ := state.MakeBlock(height, txs, lastCommit, nil, proposer.Address, round, nil) + message := state.MakeHashMessage(round) + pk := ed25519.GenPrivKeyFromSecret([]byte("test private validator")) + privVal := types.NewMockPVWithParams(pk, false, false) + proof, _ := privVal.GenerateVRFProof(message) + block, _ := state.MakeBlock(height, txs, lastCommit, nil, proposer.Address, round, proof) blockPart := block.MakePartSet(partSize) // Indexing env.BlockIndexer.Index(types.EventDataNewBlockHeader{Header: block.Header}) // nolint:errcheck diff --git a/store/store_test.go b/store/store_test.go index 1c7ca8afc..084688d88 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -19,6 +19,7 @@ import ( cfg "github.com/Finschia/ostracon/config" "github.com/Finschia/ostracon/crypto" + "github.com/Finschia/ostracon/crypto/ed25519" "github.com/Finschia/ostracon/libs/log" tmrand "github.com/Finschia/ostracon/libs/rand" sm "github.com/Finschia/ostracon/state" @@ -51,8 +52,13 @@ func makeTxs(height int64) (txs []types.Tx) { } func makeBlock(height int64, state sm.State, lastCommit *types.Commit) *types.Block { + round := int32(0) + message := state.MakeHashMessage(round) + pk := ed25519.GenPrivKeyFromSecret([]byte("test private validator")) + privVal := types.NewMockPVWithParams(pk, false, false) + proof, _ := privVal.GenerateVRFProof(message) block, _ := state.MakeBlock(height, makeTxs(height), lastCommit, nil, - state.Validators.SelectProposer(state.LastProofHash, height, 0).Address, 0, nil) + state.Validators.SelectProposer(state.LastProofHash, height, round).Address, round, proof) return block } diff --git a/types/block_test.go b/types/block_test.go index 8522e5eb1..5cac8056c 100644 --- a/types/block_test.go +++ b/types/block_test.go @@ -137,7 +137,10 @@ func TestBlockValidateBasic(t *testing.T) { i := i t.Run(tc.testName, func(t *testing.T) { block := MakeBlock(h, txs, commit, evList, TestConsensusVersion) - block.ProposerAddress = valSet.SelectProposer([]byte{}, block.Height, 0).Address + round := int32(0) + block.ProposerAddress = valSet.SelectProposer([]byte{}, block.Height, round).Address + proof := make([]byte, vrf.ProofSize) + block.Entropy.Populate(round, proof) tc.malleateBlock(block) err = block.ValidateBasic() assert.Equal(t, tc.expErr, err != nil, "#%d: %v", i, err)