github.com/ethersphere/bee/v2@v2.2.0/pkg/file/testing/vector.go (about)

     1  // Copyright 2020 The Swarm Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package testing
     6  
     7  import (
     8  	"testing"
     9  
    10  	"github.com/ethersphere/bee/v2/pkg/swarm"
    11  	mockbytes "gitlab.com/nolash/go-mockbytes"
    12  )
    13  
    14  var (
    15  	fileByteMod int = 255
    16  	fileLengths     = []int{
    17  		31,                           // 0
    18  		32,                           // 1
    19  		33,                           // 2
    20  		63,                           // 3
    21  		64,                           // 4
    22  		65,                           // 5
    23  		swarm.ChunkSize,              // 6
    24  		swarm.ChunkSize + 31,         // 7
    25  		swarm.ChunkSize + 32,         // 8
    26  		swarm.ChunkSize + 63,         // 9
    27  		swarm.ChunkSize + 64,         // 10
    28  		swarm.ChunkSize * 2,          // 11
    29  		swarm.ChunkSize*2 + 32,       // 12
    30  		swarm.ChunkSize * 128,        // 13
    31  		swarm.ChunkSize*128 + 31,     // 14
    32  		swarm.ChunkSize*128 + 32,     // 15
    33  		swarm.ChunkSize*128 + 64,     // 16
    34  		swarm.ChunkSize * 129,        // 17
    35  		swarm.ChunkSize * 130,        // 18
    36  		swarm.ChunkSize * 128 * 128,  // 19
    37  		swarm.ChunkSize*128*128 + 32, // 20
    38  	}
    39  	fileExpectHashHex = []string{
    40  		"ece86edb20669cc60d142789d464d57bdf5e33cb789d443f608cbd81cfa5697d", // 0
    41  		"0be77f0bb7abc9cd0abed640ee29849a3072ccfd1020019fe03658c38f087e02", // 1
    42  		"3463b46d4f9d5bfcbf9a23224d635e51896c1daef7d225b86679db17c5fd868e", // 2
    43  		"95510c2ff18276ed94be2160aed4e69c9116573b6f69faaeed1b426fea6a3db8", // 3
    44  		"490072cc55b8ad381335ff882ac51303cc069cbcb8d8d3f7aa152d9c617829fe", // 4
    45  		"541552bae05e9a63a6cb561f69edf36ffe073e441667dbf7a0e9a3864bb744ea", // 5
    46  		"c10090961e7682a10890c334d759a28426647141213abda93b096b892824d2ef", // 6
    47  		"91699c83ed93a1f87e326a29ccd8cc775323f9e7260035a5f014c975c5f3cd28", // 7
    48  		"73759673a52c1f1707cbb61337645f4fcbd209cdc53d7e2cedaaa9f44df61285", // 8
    49  		"db1313a727ffc184ae52a70012fbbf7235f551b9f2d2da04bf476abe42a3cb42", // 9
    50  		"ade7af36ac0c7297dc1c11fd7b46981b629c6077bce75300f85b02a6153f161b", // 10
    51  		"29a5fb121ce96194ba8b7b823a1f9c6af87e1791f824940a53b5a7efe3f790d9", // 11
    52  		"61416726988f77b874435bdd89a419edc3861111884fd60e8adf54e2f299efd6", // 12
    53  		"3047d841077898c26bbe6be652a2ec590a5d9bd7cd45d290ea42511b48753c09", // 13
    54  		"e5c76afa931e33ac94bce2e754b1bb6407d07f738f67856783d93934ca8fc576", // 14
    55  		"485a526fc74c8a344c43a4545a5987d17af9ab401c0ef1ef63aefcc5c2c086df", // 15
    56  		"624b2abb7aefc0978f891b2a56b665513480e5dc195b4a66cd8def074a6d2e94", // 16
    57  		"b8e1804e37a064d28d161ab5f256cc482b1423d5cd0a6b30fde7b0f51ece9199", // 17
    58  		"59de730bf6c67a941f3b2ffa2f920acfaa1713695ad5deea12b4a121e5f23fa1", // 18
    59  		"522194562123473dcfd7a457b18ee7dee8b7db70ed3cfa2b73f348a992fdfd3b", // 19
    60  		"ed0cc44c93b14fef2d91ab3a3674eeb6352a42ac2f0bbe524711824aae1e7bcc", // 20
    61  	}
    62  )
    63  
    64  // GetVector returns test data corresponding to the test vector index,
    65  // and the expected result address.
    66  func GetVector(t *testing.T, idx int) ([]byte, swarm.Address) {
    67  	t.Helper()
    68  	if idx > fileLengths[idx] {
    69  		t.Fatalf("idx %d out of bound for count %d", idx, GetVectorCount())
    70  	}
    71  	g := mockbytes.New(0, mockbytes.MockTypeStandard).WithModulus(fileByteMod)
    72  	data, err := g.SequentialBytes(fileLengths[idx])
    73  	if err != nil {
    74  		t.Fatal(err)
    75  	}
    76  	return data, swarm.MustParseHexAddress(fileExpectHashHex[idx])
    77  }
    78  
    79  // GetVectorCount returns the number of available test vectors.
    80  func GetVectorCount() int {
    81  	return len(fileLengths)
    82  }