On certain tokens with high d.p, the value sent is rounded down #68

Open
opened 2025-04-25 14:10:52 +02:00 by kamikazechaser · 2 comments
  1. Enter 0.1 on the USSD menu
  2. Amount actually sent is 99999999999999999
1. Enter 0.1 on the USSD menu 2. Amount actually sent is 99999999999999999
kamikazechaser added the
Kind/Bug
Priority
Medium
labels 2025-04-25 14:10:52 +02:00
Alfred-mk self-assigned this 2025-04-27 15:26:35 +02:00
kamikazechaser added this to the USSD project 2025-04-29 10:16:44 +02:00
Author
Owner

Point out where this code is with tests.

Point out where this code is with tests.
kamikazechaser self-assigned this 2025-05-13 10:48:18 +02:00
Alfred-mk was unassigned by kamikazechaser 2025-05-13 10:48:18 +02:00
Member

The function ValidateAmount handles the user's amount input and writing it to storedb.DATA_AMOUNT
func (h *MenuHandlers) ValidateAmount(ctx context.Context, sym string, input []byte) (resource.Result, error) {


The InitiateTransaction function reads the transaction data and initializes a transaction
func (h *MenuHandlers) InitiateTransaction(ctx context.Context, sym string, input []byte) (resource.Result, error) {


In the InitiateTransaction, the store.ParseAndScaleAmount(data.Amount, data.ActiveDecimal) scales the amount using the active decimal value of the token
func ParseAndScaleAmount(storedAmount, activeDecimal string) (string, error) {


Tests

  1. TestValidateAmount for the ValidateAmount function
    func TestValidateAmount(t *testing.T) {
  2. TestInitiateTransaction for the InitiateTransaction function
    func TestInitiateTransaction(t *testing.T) {
  3. TestParseAndScaleAmount for the ParseAndScaleAmount function in store/tokens_test.go
    func TestParseAndScaleAmount(t *testing.T) {
The function `ValidateAmount` handles the user's amount input and writing it to storedb.DATA_AMOUNT https://git.grassecon.net/grassrootseconomics/sarafu-vise/src/commit/e914d059e26b02baa91a1e44e284fea73669860c/handlers/application/menuhandler.go#L1840 --- --- The `InitiateTransaction` function reads the transaction data and initializes a transaction https://git.grassecon.net/grassrootseconomics/sarafu-vise/src/commit/e914d059e26b02baa91a1e44e284fea73669860c/handlers/application/menuhandler.go#L1966 --- --- In the `InitiateTransaction`, the `store.ParseAndScaleAmount(data.Amount, data.ActiveDecimal)` scales the amount using the active decimal value of the token https://git.grassecon.net/grassrootseconomics/sarafu-vise/src/commit/e914d059e26b02baa91a1e44e284fea73669860c/store/tokens.go#L23 --- --- ### Tests 1. `TestValidateAmount` for the `ValidateAmount` function https://git.grassecon.net/grassrootseconomics/sarafu-vise/src/commit/e914d059e26b02baa91a1e44e284fea73669860c/handlers/application/menuhandler_test.go#L1629 2. `TestInitiateTransaction` for the `InitiateTransaction` function https://git.grassecon.net/grassrootseconomics/sarafu-vise/src/commit/e914d059e26b02baa91a1e44e284fea73669860c/handlers/application/menuhandler_test.go#L1485 3. `TestParseAndScaleAmount` for the `ParseAndScaleAmount` function in store/tokens_test.go https://git.grassecon.net/grassrootseconomics/sarafu-vise/src/commit/e914d059e26b02baa91a1e44e284fea73669860c/store/tokens_test.go#L10
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: grassrootseconomics/sarafu-vise#68
No description provided.