Skip to content

Commit

Permalink
Merge pull request #2976 from darkdrag00nv2/revertible_random
Browse files Browse the repository at this point in the history
Update interface of `revertibleRandom`
  • Loading branch information
SupunS authored Dec 11, 2023
2 parents 0de878b + 901bb55 commit 3946910
Show file tree
Hide file tree
Showing 33 changed files with 703 additions and 158 deletions.
1 change: 1 addition & 0 deletions encoding/ccf/ccf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7811,6 +7811,7 @@ func TestEncodeSimpleTypes(t *testing.T) {
ccf.SimpleTypeSignedNumber: cadence.SignedNumberType,
ccf.SimpleTypeInteger: cadence.IntegerType,
ccf.SimpleTypeSignedInteger: cadence.SignedIntegerType,
ccf.SimpleTypeFixedSizeUnsignedInteger: cadence.FixedSizeUnsignedIntegerType,
ccf.SimpleTypeFixedPoint: cadence.FixedPointType,
ccf.SimpleTypeSignedFixedPoint: cadence.SignedFixedPointType,
ccf.SimpleTypeInt: cadence.IntType,
Expand Down
2 changes: 2 additions & 0 deletions encoding/ccf/simpletype.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const ( // Cadence simple type IDs
SimpleTypeCapabilitiesMapping
SimpleTypeAccountMapping
SimpleTypeHashableStruct
SimpleTypeFixedSizeUnsignedInteger

// !!! *WARNING* !!!
// ADD NEW TYPES *BEFORE* THIS WARNING.
Expand Down Expand Up @@ -168,6 +169,7 @@ func initSimpleTypeIDBiMap() (m *bimap.BiMap[cadence.PrimitiveType, SimpleType])
m.Insert(cadence.SignedNumberType, SimpleTypeSignedNumber)
m.Insert(cadence.IntegerType, SimpleTypeInteger)
m.Insert(cadence.SignedIntegerType, SimpleTypeSignedInteger)
m.Insert(cadence.FixedSizeUnsignedIntegerType, SimpleTypeFixedSizeUnsignedInteger)
m.Insert(cadence.FixedPointType, SimpleTypeFixedPoint)
m.Insert(cadence.SignedFixedPointType, SimpleTypeSignedFixedPoint)

Expand Down
9 changes: 5 additions & 4 deletions encoding/ccf/simpletype_string.go

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

1 change: 1 addition & 0 deletions encoding/ccf/traverse_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ func (ct *compositeTypes) traverseType(typ cadence.Type) (checkRuntimeType bool)
cadence.SignedNumberType,
cadence.IntegerType,
cadence.SignedIntegerType,
cadence.FixedSizeUnsignedIntegerType,
cadence.FixedPointType,
cadence.SignedFixedPointType:

Expand Down
2 changes: 2 additions & 0 deletions runtime/convertTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func ExportMeteredType(
return cadence.IntegerType
case sema.SignedIntegerType:
return cadence.SignedIntegerType
case sema.FixedSizeUnsignedIntegerType:
return cadence.FixedSizeUnsignedIntegerType
case sema.FixedPointType:
return cadence.FixedPointType
case sema.SignedFixedPointType:
Expand Down
5 changes: 5 additions & 0 deletions runtime/convertValues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,11 @@ func TestRuntimeImportRuntimeType(t *testing.T) {
actual: cadence.SignedIntegerType,
expected: interpreter.PrimitiveStaticTypeSignedInteger,
},
{
label: "FixedSizeUnsignedInteger",
actual: cadence.FixedSizeUnsignedIntegerType,
expected: interpreter.PrimitiveStaticTypeFixedSizeUnsignedInteger,
},
{
label: "FixedPoint",
actual: cadence.FixedPointType,
Expand Down
12 changes: 12 additions & 0 deletions runtime/imported_values_memory_metering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ func TestRuntimeImportedValueMemoryMetering(t *testing.T) {
assert.Equal(t, uint64(32), meter[common.MemoryKindBigInt])
})

t.Run("FixedSizeUnsignedInteger", func(t *testing.T) {
t.Parallel()

script := []byte(`
access(all) fun main(x: FixedSizeUnsignedInteger) {}
`)

meter := make(map[common.MemoryKind]uint64)
executeScript(t, script, meter, cadence.NewUInt256(2))
assert.Equal(t, uint64(32), meter[common.MemoryKindBigInt])
})

t.Run("Int", func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion runtime/interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3343,7 +3343,7 @@ func init() {

switch numberType {
case sema.NumberType, sema.SignedNumberType,
sema.IntegerType, sema.SignedIntegerType,
sema.IntegerType, sema.SignedIntegerType, sema.FixedSizeUnsignedIntegerType,
sema.FixedPointType, sema.SignedFixedPointType:
continue
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/interpreter/interpreter_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ func (interpreter *Interpreter) NewIntegerValueFromBigInt(value *big.Int, intege
case sema.UInt128Type:
// BigInt value is already metered at parser.
return NewUnmeteredUInt128ValueFromBigInt(value)
case sema.UInt256Type:
case sema.UInt256Type, sema.FixedSizeUnsignedIntegerType:
// BigInt value is already metered at parser.
return NewUnmeteredUInt256ValueFromBigInt(value)

Expand Down
7 changes: 6 additions & 1 deletion runtime/interpreter/primitivestatictype.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const (
// Integer
PrimitiveStaticTypeInteger
PrimitiveStaticTypeSignedInteger
_
PrimitiveStaticTypeFixedSizeUnsignedInteger
_
_
_
Expand Down Expand Up @@ -303,6 +303,7 @@ func (t PrimitiveStaticType) elementSize() uint {
PrimitiveStaticTypeWord256,
PrimitiveStaticTypeInteger,
PrimitiveStaticTypeSignedInteger,
PrimitiveStaticTypeFixedSizeUnsignedInteger,
PrimitiveStaticTypeNumber,
PrimitiveStaticTypeSignedNumber:
return UnknownElementSize
Expand Down Expand Up @@ -480,6 +481,8 @@ func (t PrimitiveStaticType) SemaType() sema.Type {
return sema.IntegerType
case PrimitiveStaticTypeSignedInteger:
return sema.SignedIntegerType
case PrimitiveStaticTypeFixedSizeUnsignedInteger:
return sema.FixedSizeUnsignedIntegerType

// FixedPoint
case PrimitiveStaticTypeFixedPoint:
Expand Down Expand Up @@ -693,6 +696,8 @@ func ConvertSemaToPrimitiveStaticType(
typ = PrimitiveStaticTypeInteger
case sema.SignedIntegerType:
typ = PrimitiveStaticTypeSignedInteger
case sema.FixedSizeUnsignedIntegerType:
typ = PrimitiveStaticTypeFixedSizeUnsignedInteger

// FixedPoint
case sema.FixedPointType:
Expand Down
Loading

0 comments on commit 3946910

Please sign in to comment.