File tree 2 files changed +22
-0
lines changed 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -379,6 +379,8 @@ extension Value {
379
379
result [ $0. name] = bigInt. description
380
380
} else if let bigUInt = value as? BigUInt {
381
381
result [ $0. name] = bigUInt. description
382
+ } else if let decimal = value as? Decimal {
383
+ result [ $0. name] = decimal
382
384
} else if let encodable = value as? Encodable {
383
385
let value = try encodable. encoded ( with: JSONEncoder ( ) )
384
386
result [ $0. name] = try JSONSerialization . jsonObject (
Original file line number Diff line number Diff line change @@ -657,4 +657,24 @@ final class ValueTests: XCTestCase {
657
657
) . description, " Capability<Int>(address: 0x0000000102030405, path: /storage/foo) " )
658
658
}
659
659
660
+ func testToSwiftValueDecodable( ) throws {
661
+ // Arrange
662
+ struct TestStruct : Codable , Equatable {
663
+ let value : Decimal
664
+ }
665
+ let decimalValue = Decimal ( string: " 0.007601 " ) !
666
+ let value : Cadence . Value = . optional( . struct(
667
+ id: " id " ,
668
+ fields: [
669
+ . init( name: " value " , value: . ufix64( decimalValue) ) ,
670
+ ] )
671
+ )
672
+
673
+ // Act
674
+ let result : TestStruct = try value. toSwiftValue ( )
675
+
676
+ // Assert
677
+ XCTAssertEqual ( result, TestStruct ( value: decimalValue) )
678
+ }
679
+
660
680
}
You can’t perform that action at this time.
0 commit comments