From f6efc2597b4a647b8027252b58bb84b47ccdacd2 Mon Sep 17 00:00:00 2001 From: Denali Marsh Date: Tue, 12 Jan 2021 10:03:09 +0100 Subject: [PATCH] Hard: investigate sdk.RelativePow runtime panic (#762) * interest rate practical test * add clarification comment --- x/hard/keeper/interest_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/x/hard/keeper/interest_test.go b/x/hard/keeper/interest_test.go index 2bbedf63..05e65523 100644 --- a/x/hard/keeper/interest_test.go +++ b/x/hard/keeper/interest_test.go @@ -289,8 +289,6 @@ func (suite *InterestTestSuite) TestCalculateBorrowInterestFactor() { expectedValue: sdk.MustNewDecFromStr("40628388.864535408465693310"), }, }, - // If we raise the per second interest rate too much we'll cause an integer overflow. - // For example, perSecondInterestRate: '1.000005555555' will cause a panic. { "1 year: highest interest rate", args{ @@ -299,6 +297,14 @@ func (suite *InterestTestSuite) TestCalculateBorrowInterestFactor() { expectedValue: sdk.MustNewDecFromStr("2017093013158200407564.613502861572552603"), }, }, + { + "largest per second interest rate with practical elapsed time", + args{ + perSecondInterestRate: sdk.MustNewDecFromStr("18.445"), // Begins to panic at ~18.45 (1845%/second interest rate) + timeElapsed: sdk.NewInt(30), // Assume a 30 second period, longer than any expected individual block + expectedValue: sdk.MustNewDecFromStr("94702138679846565921082258202543002089.215969366091911769"), + }, + }, } for _, tc := range testCases {