Skip to content

Commit

Permalink
Merge pull request #3195 from onflow/bastian/3194-fix-address-conversion
Browse files Browse the repository at this point in the history
Fix address conversion
  • Loading branch information
turbolent committed Mar 26, 2024
2 parents ae127d3 + 9175752 commit 1a59183
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions runtime/interpreter/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -21200,6 +21200,10 @@ func NewAddressValueFromConstructor(
}

func ConvertAddress(memoryGauge common.MemoryGauge, value Value, locationRange LocationRange) AddressValue {
if address, ok := value.(AddressValue); ok {
return address
}

converter := func() (result common.Address) {
uint64Value := ConvertUInt64(memoryGauge, value, locationRange)

Expand Down
23 changes: 23 additions & 0 deletions runtime/tests/interpreter/interpreter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12149,3 +12149,26 @@ func TestInterpretSwapDictionaryKeysWithSideEffects(t *testing.T) {
require.Equal(t, interpreter.NewIntValueFromInt64(nil, 3), events[2].event.GetField(inter, interpreter.EmptyLocationRange, "value"))
})
}

func TestInterpretOptionalAddressInConditional(t *testing.T) {

t.Parallel()

inter := parseCheckAndInterpret(t, `
fun test(ok: Bool): Address? {
return ok ? 0x1 : nil
}
`)

value, err := inter.Invoke("test", interpreter.TrueValue)
require.NoError(t, err)

AssertValuesEqual(
t,
inter,
interpreter.NewSomeValueNonCopying(nil,
interpreter.NewUnmeteredAddressValueFromBytes([]byte{0x1}),
),
value,
)
}

0 comments on commit 1a59183

Please sign in to comment.