Skip to content

Commit

Permalink
tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
srene committed Oct 9, 2024
1 parent 9270799 commit 54d729b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
1 change: 0 additions & 1 deletion block/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ func TestApplyLocalBlock_WithFraudCheck(t *testing.T) {
}()
<-ctx.Done()
assert.Equal(t, batchs[1].EndHeight(), manager.LastSubmittedHeight.Load())

mockExecutor.AssertExpectations(t)
mockFraudHandler.AssertExpectations(t)
}
Expand Down
12 changes: 6 additions & 6 deletions block/stateupdate_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func TestStateUpdateValidator_ValidateP2PBlocks(t *testing.T) {
proposerKey, _, err := crypto.GenerateEd25519Key(rand.Reader)
require.NoError(t, err)

batch, err := testutil.GenerateBatch(1, 10, proposerKey)
batch, err := testutil.GenerateBatch(1, 10, proposerKey, "test", [32]byte{})
require.NoError(t, err)

doubleSignedBatch, err := testutil.GenerateBatch(1, 10, proposerKey)
doubleSignedBatch, err := testutil.GenerateBatch(1, 10, proposerKey, "test", [32]byte{})
require.NoError(t, err)

mixedBatch := make([]*types.Block, 10)
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestStateUpdateValidator_ValidateDaBlocks(t *testing.T) {
proposerKey, _, err := crypto.GenerateEd25519Key(rand.Reader)
require.NoError(t, err)

batch, err := testutil.GenerateBatch(1, 2, proposerKey)
batch, err := testutil.GenerateBatch(1, 2, proposerKey, "test", [32]byte{})
require.NoError(t, err)

tests := []struct {
Expand Down Expand Up @@ -144,16 +144,16 @@ func TestStateUpdateValidator_ValidateDaBlocks(t *testing.T) {
slBatch: &settlement.ResultRetrieveBatch{
Batch: &settlement.Batch{
BlockDescriptors: []settlement.BlockDescriptor{
{Height: 1, StateRoot: batch.Blocks[1].Header.AppHash[:], Timestamp: batch.Blocks[0].Header.GetTimestamp()},
{Height: 2, StateRoot: batch.Blocks[1].Header.AppHash[:], Timestamp: batch.Blocks[1].Header.GetTimestamp()},
{Height: 1, StateRoot: batch.Blocks[0].Header.AppHash[:], Timestamp: batch.Blocks[0].Header.GetTimestamp()},
{Height: 2, StateRoot: []byte{1, 2, 3, 4}, Timestamp: batch.Blocks[1].Header.GetTimestamp()},
},
},
ResultBase: settlement.ResultBase{
StateIndex: 1,
},
},
daBlocks: batch.Blocks,
expectedError: fmt.Errorf("state root mismatch between state update and DA batch. State index: 1: Height: 1 State root SL: %d State root DA: %d", batch.Blocks[1].Header.AppHash[:], batch.Blocks[0].Header.AppHash[:]),
expectedError: fmt.Errorf("state root mismatch between state update and DA batch. State index: 1: Height: 2 State root SL: %d State root DA: %d", []byte{1, 2, 3, 4}, batch.Blocks[0].Header.AppHash[:]),
},
{
name: "Error - timestamp mismatch",
Expand Down
21 changes: 6 additions & 15 deletions testutil/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (

func createRandomHashes() [][32]byte {
h := [][32]byte{}
for i := 0; i < 8; i++ {
for i := 0; i < 4; i++ {
var h1 [32]byte
_, err := rand.Read(h1[:])
if err != nil {
Expand All @@ -38,15 +38,6 @@ func createRandomHashes() [][32]byte {
return h
}

func createRandomHash() [32]byte {
var h1 [32]byte
_, err := rand.Read(h1[:])
if err != nil {
panic(err)
}
return h1
}

func GetRandomTx() types.Tx {
n, _ := rand.Int(rand.Reader, big.NewInt(100))
size := uint64(n.Int64()) + 100
Expand All @@ -72,10 +63,10 @@ func generateBlock(height uint64, lastHeaderHash [32]byte, proposerHash []byte,
Height: height,
Time: 4567,
LastHeaderHash: lastHeaderHash,
LastCommitHash: h[1],
DataHash: h[2],
ConsensusHash: h[3],
AppHash: createRandomHash(),
LastCommitHash: h[0],
DataHash: h[1],
ConsensusHash: h[2],
AppHash: [32]byte{},
LastResultsHash: GetEmptyLastResultsHash(),
ProposerAddress: proposerAddress,
SequencerHash: [32]byte(proposerHash),
Expand All @@ -89,7 +80,7 @@ func generateBlock(height uint64, lastHeaderHash [32]byte, proposerHash []byte,
},
LastCommit: types.Commit{
Height: 8,
HeaderHash: h[7],
HeaderHash: h[3],
Signatures: []types.Signature{},
},
}
Expand Down

0 comments on commit 54d729b

Please sign in to comment.