Currently, we do not have a framework for testing implementations of BalanceHandler. This is an issue as, if key permissions are incorrectly allocated or if the various setter methods of BalanceHandler don't behave as expected, then this can corrupt the fee-logic of a HyperVM.
Design Doc
Ideally, there are two things that any implementation of BalanceHandler should do:
Provide the correct set of state keys required for CanDeduct() and Deduct()
As per #1589, failing to provide the correct set of state keys will result in the VM forever being borked
For AddBalance() and Deduct(), these functions update an account's balance as expected
With the above in mind (and taking inspiration from action tests), a test suite for BalanceHandler could come with the following:
BalanceHandlerStateKeyTest: given an address and a positive integer, this test would call AddBalance(), CanDeduct(), and Deduct() in that order.
This test would mimic the history of an account. That is, it would mimic the account being prefunded during VM initialization, followed by the account then submitting a TX
BalanceHandlerFundsTest: given an address and the method to test (Deduct() or AddBalance()), this test would call the method and check if the expected balance is equal to the actual balance of the account provided
Currently, we do not have a framework for testing implementations of
BalanceHandler
. This is an issue as, if key permissions are incorrectly allocated or if the various setter methods ofBalanceHandler
don't behave as expected, then this can corrupt the fee-logic of a HyperVM.Design Doc
Ideally, there are two things that any implementation of
BalanceHandler
should do:CanDeduct()
andDeduct()
AddBalance()
andDeduct()
, these functions update an account's balance as expectedWith the above in mind (and taking inspiration from action tests), a test suite for
BalanceHandler
could come with the following:BalanceHandlerStateKeyTest
: given an address and a positive integer, this test would callAddBalance()
,CanDeduct()
, andDeduct()
in that order.BalanceHandlerFundsTest
: given an address and the method to test (Deduct()
orAddBalance()
), this test would call the method and check if the expected balance is equal to the actual balance of the account provided