Skip to content

Commit

Permalink
Merge pull request #436 from onflow/fxamacker/check-smoke-tests-tag-n…
Browse files Browse the repository at this point in the history
…umbers

Make smoke tests check if CBOR tag nums are reserved
  • Loading branch information
fxamacker authored Aug 27, 2024
2 parents ace6bb1 + 273a611 commit 37b6546
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 16 deletions.
51 changes: 51 additions & 0 deletions cmd/stress/storable.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,63 @@ import (
// This file contains value implementations for testing purposes.

const (
reservedMinTagNum = 161
reservedMinTagNumForContainerType = 230
reservedMaxTagNum = 239
)

const (
// CBOR tag numbers used to encode elements.

cborTagUInt8Value = 161
cborTagUInt16Value = 162
cborTagUInt32Value = 163
cborTagUInt64Value = 164

// CBOR tag numbers in this block cannot exceed 230 (reservedMinTagNumForContainerType).
)

const (
// CBOR tag numbers used to encode container types.
// Replace _ when new tag number is needed (use lower tag numbers first).

arrayTypeTagNum = reservedMinTagNumForContainerType + iota
compositeTypeTagNum
mapTypeTagNum
_
_
_
_
_
_
_
)

func init() {
// Check if the CBOR tag number range is reserved for internal use by atree.
// Smoke tests must only use available (unreserved by atree) CBOR tag numbers
// to encode elements in atree managed containers.

// As of Aug 15, 2024:
// - Atree reserves CBOR tag numbers [240, 255] for atree internal use.
// - Smoke tests reserve CBOR tag numbers [161, 239] to encode elements.

tagNumOK, err := atree.IsCBORTagNumberRangeAvailable(reservedMinTagNum, reservedMaxTagNum)
if err != nil {
panic(err)
}

if !tagNumOK {
atreeMinTagNum, atreeMaxTagNum := atree.ReservedCBORTagNumberRange()
panic(fmt.Errorf(
"smoke test tag numbers [%d, %d] overlaps with atree internal tag numbers [%d, %d]",
reservedMinTagNum,
reservedMaxTagNum,
atreeMinTagNum,
atreeMaxTagNum))
}
}

type Uint8Value uint8

var _ atree.Value = Uint8Value(0)
Expand Down
16 changes: 0 additions & 16 deletions cmd/stress/typeinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ import (
const (
maxArrayTypeValue = 10
maxMapTypeValue = 10

arrayTypeTagNum = 246
mapTypeTagNum = 245
compositeTypeTagNum = 244
)

type arrayTypeInfo struct {
Expand All @@ -53,10 +49,6 @@ func (i arrayTypeInfo) IsComposite() bool {
return false
}

func (i arrayTypeInfo) Identifier() string {
return fmt.Sprintf("array(%d)", i)
}

func (i arrayTypeInfo) Encode(e *cbor.StreamEncoder) error {
err := e.EncodeTagHead(arrayTypeTagNum)
if err != nil {
Expand Down Expand Up @@ -88,10 +80,6 @@ func (i mapTypeInfo) IsComposite() bool {
return false
}

func (i mapTypeInfo) Identifier() string {
return fmt.Sprintf("map(%d)", i)
}

func (i mapTypeInfo) Encode(e *cbor.StreamEncoder) error {
err := e.EncodeTagHead(mapTypeTagNum)
if err != nil {
Expand Down Expand Up @@ -153,10 +141,6 @@ func (i compositeTypeInfo) IsComposite() bool {
return true
}

func (i compositeTypeInfo) Identifier() string {
return fmt.Sprintf("composite(%d_%d)", i.fieldStartIndex, i.fieldEndIndex)
}

func (i compositeTypeInfo) Encode(e *cbor.StreamEncoder) error {
err := e.EncodeTagHead(compositeTypeTagNum)
if err != nil {
Expand Down

0 comments on commit 37b6546

Please sign in to comment.