Skip to content

Commit

Permalink
fix string formatting for values
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed May 23, 2024
1 parent 4748ee7 commit 1e55587
Show file tree
Hide file tree
Showing 6 changed files with 305 additions and 80 deletions.
3 changes: 2 additions & 1 deletion runtime/common/metering.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ var (
AccountCapabilitiesStringMemoryUsage = NewRawStringMemoryUsage(len("Account.Capabilities()"))
AccountInboxStringMemoryUsage = NewRawStringMemoryUsage(len("Account.Inbox()"))
AccountStorageStringMemoryUsage = NewRawStringMemoryUsage(len("Account.Storage()"))
CapabilityValueStringMemoryUsage = NewRawStringMemoryUsage(len("Capability<>(address: , id: )"))
IDCapabilityValueStringMemoryUsage = NewRawStringMemoryUsage(len("Capability<>(address: , id: )"))
PathCapabilityValueStringMemoryUsage = NewRawStringMemoryUsage(len("Capability<>(address: , path: )"))
StorageCapabilityControllerValueStringMemoryUsage = NewRawStringMemoryUsage(len("StorageCapabilityController(borrowType: , capabilityID: , target: )"))
AccountCapabilityControllerValueStringMemoryUsage = NewRawStringMemoryUsage(len("AccountCapabilityController(borrowType: , capabilityID: )"))
PublishedValueStringMemoryUsage = NewRawStringMemoryUsage(len("PublishedValue<>()"))
Expand Down
4 changes: 2 additions & 2 deletions runtime/format/capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Capability(borrowType string, address string, id string) string {

func StorageCapabilityController(borrowType string, capabilityID string, target string) string {
return fmt.Sprintf(
"StorageCapabilityController(borrowType: %s, capabilityID: %s, target: %s)",
"StorageCapabilityController(borrowType: Type<%s>(), capabilityID: %s, target: %s)",
borrowType,
capabilityID,
target,
Expand All @@ -42,7 +42,7 @@ func StorageCapabilityController(borrowType string, capabilityID string, target

func AccountCapabilityController(borrowType string, capabilityID string) string {
return fmt.Sprintf(
"AccountCapabilityController(borrowType: %s, capabilityID: %s)",
"AccountCapabilityController(borrowType: Type<%s>(), capabilityID: %s)",
borrowType,
capabilityID,
)
Expand Down
2 changes: 1 addition & 1 deletion runtime/interpreter/value_capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (v *IDCapabilityValue) RecursiveString(seenReferences SeenReferences) strin
}

func (v *IDCapabilityValue) MeteredString(interpreter *Interpreter, seenReferences SeenReferences, locationRange LocationRange) string {
common.UseMemory(interpreter, common.CapabilityValueStringMemoryUsage)
common.UseMemory(interpreter, common.IDCapabilityValueStringMemoryUsage)

return format.Capability(
v.BorrowType.MeteredString(interpreter),
Expand Down
24 changes: 22 additions & 2 deletions runtime/interpreter/value_pathcapability.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,28 @@ func (v *PathCapabilityValue) RecursiveString(seenReferences SeenReferences) str
}
}

func (v *PathCapabilityValue) MeteredString(_ *Interpreter, _ SeenReferences, _ LocationRange) string {
panic(errors.NewUnreachableError())
func (v *PathCapabilityValue) MeteredString(
interpreter *Interpreter,
seenReferences SeenReferences,
locationRange LocationRange,
) string {
common.UseMemory(interpreter, common.PathCapabilityValueStringMemoryUsage)

borrowType := v.BorrowType
if borrowType == nil {
return fmt.Sprintf(
"Capability(address: %s, path: %s)",
v.Address.MeteredString(interpreter, seenReferences, locationRange),
v.Path.MeteredString(interpreter, seenReferences, locationRange),
)
} else {
return fmt.Sprintf(
"Capability<%s>(address: %s, path: %s)",
borrowType.String(),
v.Address.MeteredString(interpreter, seenReferences, locationRange),
v.Path.MeteredString(interpreter, seenReferences, locationRange),
)
}
}

func (v *PathCapabilityValue) GetMember(_ *Interpreter, _ LocationRange, _ string) Value {
Expand Down
2 changes: 1 addition & 1 deletion runtime/interpreter/value_storagecapabilitycontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ func (v *StorageCapabilityControllerValue) String() string {
func (v *StorageCapabilityControllerValue) RecursiveString(seenReferences SeenReferences) string {
return format.StorageCapabilityController(
v.BorrowType.String(),
v.TargetPath.RecursiveString(seenReferences),
v.CapabilityID.RecursiveString(seenReferences),
v.TargetPath.RecursiveString(seenReferences),
)
}

Expand Down
Loading

0 comments on commit 1e55587

Please sign in to comment.