Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make smoke tests check if CBOR tag nums are reserved #436

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading