Skip to content

Commit

Permalink
Added test to partially ensure HashableValue does not regress (#1431)
Browse files Browse the repository at this point in the history
* Added test to partially ensure HashableValue does not regress

* add similar tests and use dedicated enum


Co-authored-by: robert <[email protected]>
  • Loading branch information
robert-e-davidson3 and robert authored Mar 24, 2022
1 parent 8846b7d commit 777e169
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 1 deletion.
5 changes: 5 additions & 0 deletions runtime/interpreter/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ const (
CBORTagReferenceStaticType
CBORTagRestrictedStaticType
CBORTagCapabilityStaticType

// !!! *WARNING* !!!
// ADD NEW TYPES *BEFORE* THIS WARNING.
// DO *NOT* ADD NEW TYPES AFTER THIS LINE!
CBORTag_Count
)

// CBOREncMode
Expand Down
8 changes: 8 additions & 0 deletions runtime/interpreter/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3824,3 +3824,11 @@ func TestEncodeDecodeStaticType(t *testing.T) {
require.Equal(t, ty, actualType)
})
}

func TestCBORTagValue(t *testing.T) {
t.Parallel()

t.Run("No new types added in between", func(t *testing.T) {
require.Equal(t, byte(222), byte(CBORTag_Count))
})
}
6 changes: 6 additions & 0 deletions runtime/interpreter/hashablevalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func newHashInputProvider(interpreter *Interpreter, getLocationRange func() Loca
//
// Only remove types by:
// - replace existing types with a placeholder `_`
// and a comment indicating that this placeholder cannot be used for a new type
//
// DO *NOT* REPLACE EXISTING TYPES!
// DO *NOT* ADD NEW TYPES IN BETWEEN!
Expand Down Expand Up @@ -114,4 +115,9 @@ const (
_ // future: UFix128
_ // future: UFix256
_

// !!! *WARNING* !!!
// ADD NEW TYPES *BEFORE* THIS WARNING.
// DO *NOT* ADD NEW TYPES AFTER THIS LINE!
HashInputType_Count
)
33 changes: 33 additions & 0 deletions runtime/interpreter/hashablevalue_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Cadence - The resource-oriented smart contract programming language
*
* Copyright 2021 Dapper Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package interpreter

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestHashableValue(t *testing.T) {
t.Parallel()

t.Run("No new types added in between", func(t *testing.T) {
require.Equal(t, byte(50), byte(HashInputType_Count))
})
}
5 changes: 5 additions & 0 deletions runtime/interpreter/primitivestatictype.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ const (
PrimitiveStaticTypeAuthAccountKeys
PrimitiveStaticTypePublicAccountKeys
PrimitiveStaticTypeAccountKey

// !!! *WARNING* !!!
// ADD NEW TYPES *BEFORE* THIS WARNING.
// DO *NOT* ADD NEW TYPES AFTER THIS LINE!
PrimitiveStaticType_Count
)

func (PrimitiveStaticType) isStaticType() {}
Expand Down
4 changes: 3 additions & 1 deletion runtime/interpreter/primitivestatictype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions runtime/interpreter/statictype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,3 +942,11 @@ func TestRestrictedStaticType_Equal(t *testing.T) {
)
})
}

func TestPrimitiveStaticTypeCount(t *testing.T) {
t.Parallel()

t.Run("No new types added in between", func(t *testing.T) {
require.Equal(t, byte(98), byte(PrimitiveStaticType_Count))
})
}

0 comments on commit 777e169

Please sign in to comment.