Skip to content

Commit b37a5b2

Browse files
author
Soumya Mohapatra
committed
fix: unmarshal CallView result as []byte before asserting uint64
CallView returns JSON-encoded []byte, not the raw Go type. The Check*Balance functions were doing res.(uint64) which panics because res is actually []byte. Use JSONUnmarshalUint64 helper (analogous to existing JSONUnmarshalFloat64) to properly decode the result. Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
1 parent 508a4a6 commit b37a5b2

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

integration/token/fungible/support.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ func CheckIssuedBalance(network *integration.Infrastructure, issuer *token3.Node
416416
TokenType: typ,
417417
}))
418418
gomega.Expect(err).NotTo(gomega.HaveOccurred())
419-
balance := res.(uint64)
419+
balance := JSONUnmarshalUint64(res)
420420
gomega.Expect(balance).To(gomega.Equal(expected), "issued balance: got %d, expected %d", balance, expected)
421421
}
422422

@@ -426,7 +426,7 @@ func CheckRedeemedBalance(network *integration.Infrastructure, issuer *token3.No
426426
TokenType: typ,
427427
}))
428428
gomega.Expect(err).NotTo(gomega.HaveOccurred())
429-
balance := res.(uint64)
429+
balance := JSONUnmarshalUint64(res)
430430
gomega.Expect(balance).To(gomega.Equal(expected), "redeemed balance: got %d, expected %d", balance, expected)
431431
}
432432

@@ -436,7 +436,7 @@ func CheckOutstandingBalance(network *integration.Infrastructure, issuer *token3
436436
TokenType: typ,
437437
}))
438438
gomega.Expect(err).NotTo(gomega.HaveOccurred())
439-
balance := res.(uint64)
439+
balance := JSONUnmarshalUint64(res)
440440
gomega.Expect(balance).To(gomega.Equal(expected), "outstanding balance: got %d, expected %d", balance, expected)
441441
}
442442

@@ -1254,6 +1254,22 @@ func JSONUnmarshalFloat64(v interface{}) float64 {
12541254
return s
12551255
}
12561256

1257+
func JSONUnmarshalUint64(v interface{}) uint64 {
1258+
var s uint64
1259+
switch v := v.(type) {
1260+
case []byte:
1261+
err := json.Unmarshal(v, &s)
1262+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
1263+
case string:
1264+
err := json.Unmarshal([]byte(v), &s)
1265+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
1266+
default:
1267+
panic(fmt.Sprintf("type not recognized [%T]", v))
1268+
}
1269+
1270+
return s
1271+
}
1272+
12571273
type deleteVaultPlatform interface {
12581274
DeleteVault(id string)
12591275
}

0 commit comments

Comments
 (0)