Skip to content

Commit

Permalink
add test for offline dag when the block data is non existent
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-forbes committed Jun 4, 2021
1 parent 4544467 commit 51c7f44
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions p2p/ipld/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/lazyledger/lazyledger-core/ipfs"
"github.com/lazyledger/lazyledger-core/ipfs/plugin"
"github.com/lazyledger/lazyledger-core/p2p/ipld/wrapper"
"github.com/lazyledger/lazyledger-core/types"
Expand Down Expand Up @@ -190,6 +191,39 @@ func TestRetrieveBlockData(t *testing.T) {
}
}

func TestNonExistentBlockData(t *testing.T) {
provider := ipfs.Mock()

dag, _, err := provider(false)
require.NoError(t, err)

// this timeout should not be reached
timeout := 10 * time.Second

ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

blockData := generateRandomBlockData(4, consts.MsgShareSize-2)
block := &types.Block{
Data: blockData,
LastCommit: &types.Commit{},
}

// fill the data availability header
block.Hash()

// time how long it takes to recieve an error
start := time.Now()
_, err = RetrieveBlockData(ctx, &block.DataAvailabilityHeader, dag, rsmt2d.NewRSGF8Codec())
end := time.Now()

// ensure that the error provided is as expected and that the timeout was not reached
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "merkledag: not found")
assert.Less(t, end.Sub(start), timeout)
}
}

func flatten(eds *rsmt2d.ExtendedDataSquare) [][]byte {
flattenedEDSSize := eds.Width() * eds.Width()
out := make([][]byte, flattenedEDSSize)
Expand Down

0 comments on commit 51c7f44

Please sign in to comment.