github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/cmd/util/ledger/reporters/atree_decode_test.go (about)

     1  package reporters
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func TestMapDataSlabCollisionCount(t *testing.T) {
    10  
    11  	testCases := []struct {
    12  		name                              string
    13  		data                              []byte
    14  		expectedLevel0ElementCount        uint
    15  		expectedLevel0CollisionGroupCount uint
    16  		expectedLevel0InlineCollsionCount []uint
    17  	}{
    18  		{
    19  			name: "empty",
    20  			data: []byte{
    21  				// extra data
    22  				// version
    23  				0x00,
    24  				// flag: root + map data
    25  				0x88,
    26  				// extra data (CBOR encoded array of 3 elements)
    27  				0x83,
    28  				// type info
    29  				0x18, 0x2a,
    30  				// count: 0
    31  				0x00,
    32  				// seed
    33  				0x1b, 0x52, 0xa8, 0x78, 0x3, 0x85, 0x2c, 0xaa, 0x49,
    34  
    35  				// version
    36  				0x00,
    37  				// flag: root + map data
    38  				0x88,
    39  
    40  				// the following encoded data is valid CBOR
    41  
    42  				// elements (array of 3 elements)
    43  				0x83,
    44  
    45  				// level: 0
    46  				0x00,
    47  
    48  				// hkeys (byte string of length 8 * 1)
    49  				0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    50  
    51  				// elements (array of 0 elements)
    52  				// each element is encoded as CBOR array of 2 elements (key, value)
    53  				0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    54  			},
    55  			expectedLevel0ElementCount:        0,
    56  			expectedLevel0CollisionGroupCount: 0,
    57  			expectedLevel0InlineCollsionCount: nil,
    58  		},
    59  		{
    60  			name: "dataslab as root",
    61  			data: []byte{
    62  				// extra data
    63  				// version
    64  				0x00,
    65  				// flag: root + map data
    66  				0x88,
    67  				// extra data (CBOR encoded array of 3 elements)
    68  				0x83,
    69  				// type info
    70  				0x18, 0x2a,
    71  				// count: 1
    72  				0x01,
    73  				// seed
    74  				0x1b, 0x52, 0xa8, 0x78, 0x3, 0x85, 0x2c, 0xaa, 0x49,
    75  
    76  				// version
    77  				0x00,
    78  				// flag: root + map data
    79  				0x88,
    80  
    81  				// the following encoded data is valid CBOR
    82  
    83  				// elements (array of 3 elements)
    84  				0x83,
    85  
    86  				// level: 0
    87  				0x00,
    88  
    89  				// hkeys (byte string of length 8 * 1)
    90  				0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
    91  				// hkey: 0
    92  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    93  
    94  				// elements (array of 1 elements)
    95  				// each element is encoded as CBOR array of 2 elements (key, value)
    96  				0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    97  				// element: [uint64(0):uint64(0)]
    98  				0x82, 0xd8, 0xa4, 0x00, 0xd8, 0xa4, 0x00,
    99  			},
   100  			expectedLevel0ElementCount:        1,
   101  			expectedLevel0CollisionGroupCount: 0,
   102  			expectedLevel0InlineCollsionCount: nil,
   103  		},
   104  		{
   105  			name: "has pointer no collision",
   106  			data: []byte{
   107  				// version
   108  				0x00,
   109  				// flag: has pointer + map data
   110  				0x48,
   111  				// next storage id
   112  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   113  
   114  				// the following encoded data is valid CBOR
   115  
   116  				// elements (array of 3 elements)
   117  				0x83,
   118  
   119  				// level: 0
   120  				0x00,
   121  
   122  				// hkeys (byte string of length 8 * 4)
   123  				0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
   124  				// hkey: 4
   125  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
   126  				// hkey: 5
   127  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
   128  				// hkey: 6
   129  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
   130  				// hkey: 7
   131  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
   132  
   133  				// elements (array of 4 elements)
   134  				// each element is encoded as CBOR array of 2 elements (key, value)
   135  				0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
   136  				// element: [eeeeeeeeeeeeeeeeeeeeee:eeeeeeeeeeeeeeeeeeeeee]
   137  				0x82,
   138  				0x76, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65,
   139  				0x76, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65, 0x65,
   140  				// element: [ffffffffffffffffffffff:ffffffffffffffffffffff]
   141  				0x82,
   142  				0x76, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
   143  				0x76, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
   144  				// element: [gggggggggggggggggggggg:gggggggggggggggggggggg]
   145  				0x82,
   146  				0x76, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67,
   147  				0x76, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67, 0x67,
   148  				// element: [hhhhhhhhhhhhhhhhhhhhhh:StorageID(1,2,3,4,5,6,7,8,0,0,0,0,0,0,0,4)]
   149  				0x82,
   150  				0x76, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68, 0x68,
   151  				0xd8, 0xff, 0x50, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
   152  			},
   153  			expectedLevel0ElementCount:        4,
   154  			expectedLevel0CollisionGroupCount: 0,
   155  			expectedLevel0InlineCollsionCount: nil,
   156  		},
   157  		{
   158  			name: "inline collision 1 level",
   159  			data: []byte{
   160  				// extra data
   161  				// version
   162  				0x00,
   163  				// flag: root + map data
   164  				0x88,
   165  				// extra data (CBOR encoded array of 3 elements)
   166  				0x83,
   167  				// type info: "map"
   168  				// 0x63, 0x6d, 0x61, 0x70,
   169  				0x18, 0x2A,
   170  				// count: 8
   171  				0x08,
   172  				// seed
   173  				0x1b, 0x52, 0xa8, 0x78, 0x3, 0x85, 0x2c, 0xaa, 0x49,
   174  
   175  				// version
   176  				0x00,
   177  				// flag: root + map data
   178  				0x88,
   179  
   180  				// the following encoded data is valid CBOR
   181  
   182  				// elements (array of 3 elements)
   183  				0x83,
   184  
   185  				// level: 0
   186  				0x00,
   187  
   188  				// hkeys (byte string of length 8 * 4)
   189  				0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
   190  				// hkey: 0
   191  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   192  				// hkey: 1
   193  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
   194  				// hkey: 2
   195  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
   196  				// hkey: 3
   197  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
   198  
   199  				// elements (array of 2 elements)
   200  				0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
   201  
   202  				// inline collision group corresponding to hkey 0
   203  				// (tag number CBORTagInlineCollisionGroup)
   204  				0xd8, 0xfd,
   205  				// (tag content: array of 3 elements)
   206  				0x83,
   207  
   208  				// level: 1
   209  				0x01,
   210  
   211  				// hkeys (byte string of length 8 * 2)
   212  				0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
   213  				// hkey: 0
   214  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   215  				// hkey: 4
   216  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
   217  
   218  				// elements (array of 2 elements)
   219  				// each element is encoded as CBOR array of 2 elements (key, value)
   220  				0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
   221  				// element: [uint64(0), uint64(0)]
   222  				0x82, 0xd8, 0xa4, 0x00, 0xd8, 0xa4, 0x00,
   223  				// element: [uint64(4), uint64(8)]
   224  				0x82, 0xd8, 0xa4, 0x04, 0xd8, 0xa4, 0x08,
   225  
   226  				// inline collision group corresponding to hkey 1
   227  				// (tag number CBORTagInlineCollisionGroup)
   228  				0xd8, 0xfd,
   229  				// (tag content: array of 3 elements)
   230  				0x83,
   231  
   232  				// level: 1
   233  				0x01,
   234  
   235  				// hkeys (byte string of length 8 * 2)
   236  				0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
   237  				// hkey: 1
   238  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
   239  				// hkey: 5
   240  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
   241  
   242  				// elements (array of 2 elements)
   243  				// each element is encoded as CBOR array of 2 elements (key, value)
   244  				0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
   245  				// element: [uint64(1), uint64(2)]
   246  				0x82, 0xd8, 0xa4, 0x01, 0xd8, 0xa4, 0x02,
   247  				// element: [uint64(5), uint64(10)]
   248  				0x82, 0xd8, 0xa4, 0x05, 0xd8, 0xa4, 0x0a,
   249  
   250  				// inline collision group corresponding to hkey 2
   251  				// (tag number CBORTagInlineCollisionGroup)
   252  				0xd8, 0xfd,
   253  				// (tag content: array of 3 elements)
   254  				0x83,
   255  
   256  				// level: 1
   257  				0x01,
   258  
   259  				// hkeys (byte string of length 8 * 2)
   260  				0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
   261  				// hkey: 2
   262  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
   263  				// hkey: 6
   264  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
   265  
   266  				// elements (array of 2 elements)
   267  				// each element is encoded as CBOR array of 2 elements (key, value)
   268  				0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
   269  				// element: [uint64(2), uint64(4)]
   270  				0x82, 0xd8, 0xa4, 0x02, 0xd8, 0xa4, 0x04,
   271  				// element: [uint64(6), uint64(12)]
   272  				0x82, 0xd8, 0xa4, 0x06, 0xd8, 0xa4, 0x0c,
   273  
   274  				// inline collision group corresponding to hkey 3
   275  				// (tag number CBORTagInlineCollisionGroup)
   276  				0xd8, 0xfd,
   277  				// (tag content: array of 3 elements)
   278  				0x83,
   279  
   280  				// level: 1
   281  				0x01,
   282  
   283  				// hkeys (byte string of length 8 * 2)
   284  				0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
   285  				// hkey: 3
   286  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
   287  				// hkey: 7
   288  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
   289  
   290  				// elements (array of 2 elements)
   291  				// each element is encoded as CBOR array of 2 elements (key, value)
   292  				0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
   293  				// element: [uint64(3), uint64(6)]
   294  				0x82, 0xd8, 0xa4, 0x03, 0xd8, 0xa4, 0x06,
   295  				// element: [uint64(7), uint64(14)]
   296  				0x82, 0xd8, 0xa4, 0x07, 0xd8, 0xa4, 0x0e,
   297  			},
   298  			expectedLevel0ElementCount:        4,
   299  			expectedLevel0CollisionGroupCount: 4,
   300  			expectedLevel0InlineCollsionCount: []uint{2, 2, 2, 2},
   301  		},
   302  		{
   303  			name: "inline collision 2 levels",
   304  			data: []byte{
   305  				// extra data
   306  				// version
   307  				0x00,
   308  				// flag: root + map data
   309  				0x88,
   310  				// extra data (CBOR encoded array of 3 elements)
   311  				0x83,
   312  				// type info: "map"
   313  				// 0x63, 0x6d, 0x61, 0x70,
   314  				0x18, 0x2A,
   315  				// count: 8
   316  				0x08,
   317  				// seed
   318  				0x1b, 0x52, 0xa8, 0x78, 0x3, 0x85, 0x2c, 0xaa, 0x49,
   319  
   320  				// version
   321  				0x00,
   322  				// flag: root + map data
   323  				0x88,
   324  
   325  				// the following encoded data is valid CBOR
   326  
   327  				// elements (array of 3 elements)
   328  				0x83,
   329  
   330  				// level: 0
   331  				0x00,
   332  
   333  				// hkeys (byte string of length 8 * 4)
   334  				0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
   335  				// hkey: 0
   336  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   337  				// hkey: 1
   338  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
   339  				// hkey: 2
   340  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
   341  				// hkey: 3
   342  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
   343  
   344  				// elements (array of 4 elements)
   345  				0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
   346  
   347  				// inline collision group corresponding to hkey 0
   348  				// (tag number CBORTagInlineCollisionGroup)
   349  				0xd8, 0xfd,
   350  				// (tag content: array of 3 elements)
   351  				0x83,
   352  
   353  				// level 1
   354  				0x01,
   355  
   356  				// hkeys (byte string of length 8 * 1)
   357  				0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
   358  				// hkey: 0
   359  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   360  
   361  				// elements (array of 1 elements)
   362  				0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
   363  
   364  				// inline collision group corresponding to hkey [0, 0]
   365  				// (tag number CBORTagInlineCollisionGroup)
   366  				0xd8, 0xfd,
   367  				// (tag content: array of 3 elements)
   368  				0x83,
   369  
   370  				// level: 2
   371  				0x02,
   372  
   373  				// hkeys (empty byte string)
   374  				0x40,
   375  
   376  				// elements (array of 2 elements)
   377  				// each element is encoded as CBOR array of 2 elements (key, value)
   378  				0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
   379  				// element: [uint64(0), uint64(0)]
   380  				0x82, 0xd8, 0xa4, 0x00, 0xd8, 0xa4, 0x00,
   381  				// element: [uint64(4), uint64(8)]
   382  				0x82, 0xd8, 0xa4, 0x04, 0xd8, 0xa4, 0x08,
   383  
   384  				// inline collision group corresponding to hkey 1
   385  				// (tag number CBORTagInlineCollisionGroup)
   386  				0xd8, 0xfd,
   387  				// (tag content: array of 3 elements)
   388  				0x83,
   389  
   390  				// level: 1
   391  				0x01,
   392  
   393  				// hkeys (byte string of length 8 * 1)
   394  				0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
   395  				// hkey: 1
   396  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
   397  
   398  				// elements (array of 1 elements)
   399  				0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
   400  
   401  				// inline collision group corresponding to hkey [1, 1]
   402  				// (tag number CBORTagInlineCollisionGroup)
   403  				0xd8, 0xfd,
   404  				// (tag content: array of 3 elements)
   405  				0x83,
   406  
   407  				// level: 2
   408  				0x02,
   409  
   410  				// hkeys (empty byte string)
   411  				0x40,
   412  
   413  				// elements (array of 2 elements)
   414  				// each element is encoded as CBOR array of 2 elements (key, value)
   415  				0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
   416  				// element: [uint64(1), uint64(2)]
   417  				0x82, 0xd8, 0xa4, 0x01, 0xd8, 0xa4, 0x02,
   418  				// element: [uint64(5), uint64(10)]
   419  				0x82, 0xd8, 0xa4, 0x05, 0xd8, 0xa4, 0x0a,
   420  
   421  				// inline collision group corresponding to hkey 2
   422  				// (tag number CBORTagInlineCollisionGroup)
   423  				0xd8, 0xfd,
   424  				// (tag content: array of 3 elements)
   425  				0x83,
   426  
   427  				// level: 1
   428  				0x01,
   429  
   430  				// hkeys (byte string of length 8 * 1)
   431  				0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
   432  				// hkey: 0
   433  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   434  
   435  				// elements (array of 1 element)
   436  				0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
   437  
   438  				// inline collision group corresponding to hkey [2, 0]
   439  				// (tag number CBORTagInlineCollisionGroup)
   440  				0xd8, 0xfd,
   441  				// (tag content: array of 3 elements)
   442  				0x83,
   443  
   444  				// level: 2
   445  				0x02,
   446  
   447  				// hkeys (empty byte string)
   448  				0x40,
   449  
   450  				// elements (array of 2 element)
   451  				0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
   452  				// element: [uint64(2), uint64(4)]
   453  				0x82, 0xd8, 0xa4, 0x02, 0xd8, 0xa4, 0x04,
   454  				// element: [uint64(6), uint64(12)]
   455  				0x82, 0xd8, 0xa4, 0x06, 0xd8, 0xa4, 0x0c,
   456  
   457  				// inline collision group corresponding to hkey 3
   458  				// (tag number CBORTagInlineCollisionGroup)
   459  				0xd8, 0xfd,
   460  				// (tag content: array of 3 elements)
   461  				0x83,
   462  
   463  				// level: 1
   464  				0x01,
   465  
   466  				// hkeys (byte string of length 8 * 1)
   467  				0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
   468  				// hkey: 1
   469  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
   470  
   471  				// elements (array of 1 element)
   472  				0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
   473  
   474  				// inline collision group corresponding to hkey [3, 1]
   475  				// (tag number CBORTagInlineCollisionGroup)
   476  				0xd8, 0xfd,
   477  				// (tag content: array of 3 elements)
   478  				0x83,
   479  
   480  				// level: 2
   481  				0x02,
   482  
   483  				// hkeys (empty byte string)
   484  				0x40,
   485  
   486  				// elements (array of 2 element)
   487  				0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
   488  				// element: [uint64(3), uint64(6)]
   489  				0x82, 0xd8, 0xa4, 0x03, 0xd8, 0xa4, 0x06,
   490  				// element: [uint64(7), uint64(14)]
   491  				0x82, 0xd8, 0xa4, 0x07, 0xd8, 0xa4, 0x0e,
   492  			},
   493  			expectedLevel0ElementCount:        4,
   494  			expectedLevel0CollisionGroupCount: 4,
   495  			expectedLevel0InlineCollsionCount: []uint{1, 1, 1, 1},
   496  		},
   497  		{
   498  			name: "external collision",
   499  			data: []byte{
   500  				// extra data
   501  				// version
   502  				0x00,
   503  				// flag: root + has pointer + map data
   504  				0xc8,
   505  				// extra data (CBOR encoded array of 3 elements)
   506  				0x83,
   507  				// type info: "map"
   508  				// 0x63, 0x6d, 0x61, 0x70,
   509  				0x18, 0x2A,
   510  				// count: 10
   511  				0x14,
   512  				// seed
   513  				0x1b, 0x52, 0xa8, 0x78, 0x3, 0x85, 0x2c, 0xaa, 0x49,
   514  
   515  				// version
   516  				0x00,
   517  				// flag: root + has pointer + map data
   518  				0xc8,
   519  
   520  				// the following encoded data is valid CBOR
   521  
   522  				// elements (array of 3 elements)
   523  				0x83,
   524  
   525  				// level: 0
   526  				0x00,
   527  
   528  				// hkeys (byte string of length 8 * 2)
   529  				0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
   530  				// hkey: 0
   531  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   532  				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
   533  
   534  				// elements (array of 2 elements)
   535  				0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
   536  
   537  				// external collision group corresponding to hkey 0
   538  				// (tag number CBORTagExternalCollisionGroup)
   539  				0xd8, 0xfe,
   540  				// (tag content: storage id)
   541  				0xd8, 0xff, 0x50,
   542  				0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
   543  
   544  				// external collision group corresponding to hkey 1
   545  				// (tag number CBORTagExternalCollisionGroup)
   546  				0xd8, 0xfe,
   547  				// (tag content: storage id)
   548  				0xd8, 0xff, 0x50,
   549  				0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
   550  			},
   551  			expectedLevel0ElementCount:        2,
   552  			expectedLevel0CollisionGroupCount: 2,
   553  			expectedLevel0InlineCollsionCount: nil,
   554  		},
   555  	}
   556  
   557  	for _, tc := range testCases {
   558  		t.Run(tc.name, func(t *testing.T) {
   559  			collisionLevel, collisionGroupCount, err := getCollisionGroupCountFromSlabMapData(tc.data)
   560  			require.NoError(t, err)
   561  			require.Equal(t, uint(0), collisionLevel)
   562  			require.Equal(t, tc.expectedLevel0CollisionGroupCount, collisionGroupCount)
   563  
   564  			collisionLevel, inlineCollisionCount, err := getInlineCollisionCountsFromSlabMapData(tc.data)
   565  			require.NoError(t, err)
   566  			require.Equal(t, uint(0), collisionLevel)
   567  			require.Equal(t, tc.expectedLevel0InlineCollsionCount, inlineCollisionCount)
   568  		})
   569  	}
   570  }
   571  
   572  func TestMapDataSlabExternalCollisionCount(t *testing.T) {
   573  	data := []byte{
   574  		// version
   575  		0x00,
   576  		// flag: any size + collision group
   577  		0x2b,
   578  		// next storage id
   579  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   580  
   581  		// the following encoded data is valid CBOR
   582  
   583  		// elements (array of 3 elements)
   584  		0x83,
   585  
   586  		// level: 1
   587  		0x01,
   588  
   589  		// hkeys (byte string of length 8 * 10)
   590  		0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50,
   591  		// hkey: 0
   592  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   593  		// hkey: 2
   594  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
   595  		// hkey: 4
   596  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
   597  		// hkey: 6
   598  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
   599  		// hkey: 8
   600  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
   601  		// hkey: 10
   602  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
   603  		// hkey: 12
   604  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
   605  		// hkey: 14
   606  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e,
   607  		// hkey: 16
   608  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
   609  		// hkey: 18
   610  		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12,
   611  
   612  		// elements (array of 10 elements)
   613  		// each element is encoded as CBOR array of 2 elements (key, value)
   614  		0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
   615  		// element: [uint64(0), uint64(0)]
   616  		0x82, 0xd8, 0xa4, 0x00, 0xd8, 0xa4, 0x00,
   617  		// element: [uint64(2), uint64(4)]
   618  		0x82, 0xd8, 0xa4, 0x02, 0xd8, 0xa4, 0x04,
   619  		// element: [uint64(4), uint64(8)]
   620  		0x82, 0xd8, 0xa4, 0x04, 0xd8, 0xa4, 0x08,
   621  		// element: [uint64(6), uint64(12)]
   622  		0x82, 0xd8, 0xa4, 0x06, 0xd8, 0xa4, 0x0c,
   623  		// element: [uint64(8), uint64(16)]
   624  		0x82, 0xd8, 0xa4, 0x08, 0xd8, 0xa4, 0x10,
   625  		// element: [uint64(10), uint64(20)]
   626  		0x82, 0xd8, 0xa4, 0x0a, 0xd8, 0xa4, 0x14,
   627  		// element: [uint64(12), uint64(24)]
   628  		0x82, 0xd8, 0xa4, 0x0c, 0xd8, 0xa4, 0x18, 0x18,
   629  		// element: [uint64(14), uint64(28)]
   630  		0x82, 0xd8, 0xa4, 0x0e, 0xd8, 0xa4, 0x18, 0x1c,
   631  		// element: [uint64(16), uint64(32)]
   632  		0x82, 0xd8, 0xa4, 0x10, 0xd8, 0xa4, 0x18, 0x20,
   633  		// element: [uint64(18), uint64(36)]
   634  		0x82, 0xd8, 0xa4, 0x12, 0xd8, 0xa4, 0x18, 0x24,
   635  	}
   636  
   637  	const expectedElementCount = 10
   638  
   639  	elements, err := parseSlabMapData(data)
   640  	require.NoError(t, err)
   641  
   642  	level, rawElements, err := parseRawElements(elements, decMode)
   643  	require.NoError(t, err)
   644  	require.Equal(t, uint(1), level)
   645  	require.Equal(t, expectedElementCount, len(rawElements))
   646  }