From 383ef511345407f6466065b25e7f3daf280d8928 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 23 Jun 2025 10:07:53 +0300 Subject: [PATCH] use the TokenAddress instead of ContractAddress --- go.mod | 4 +-- go.sum | 4 +++ handlers/application/menuhandler.go | 2 +- handlers/application/menuhandler_test.go | 34 ++++++++++---------- store/swap.go | 8 ++--- store/swap_test.go | 4 +-- store/vouchers.go | 18 +++++------ store/vouchers_test.go | 40 ++++++++++++------------ 8 files changed, 59 insertions(+), 55 deletions(-) diff --git a/go.mod b/go.mod index e5ba1f5..f435345 100644 --- a/go.mod +++ b/go.mod @@ -5,13 +5,13 @@ go 1.23.4 require ( git.defalsify.org/vise.git v0.3.2-0.20250528124150-03bf7bfc1b66 git.grassecon.net/grassrootseconomics/common v0.9.0-beta.1.0.20250417111317-2953f4c2f32e - git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250623063234-c1797e7a32b5 + git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250623070026-d945964b0b46 git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.2.0.20250408094335-e2d1f65bb306 git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250129070628-5a539172c694 github.com/alecthomas/assert/v2 v2.2.2 github.com/gofrs/uuid v4.4.0+incompatible github.com/grassrootseconomics/ethutils v1.3.1 - github.com/grassrootseconomics/ussd-data-service v1.5.0-beta + github.com/grassrootseconomics/ussd-data-service v1.6.0-beta github.com/jackc/pgx/v5 v5.7.1 github.com/peteole/testdata-loader v0.3.0 github.com/stretchr/testify v1.9.0 diff --git a/go.sum b/go.sum index d34976f..d567d72 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ git.grassecon.net/grassrootseconomics/common v0.9.0-beta.1.0.20250417111317-2953 git.grassecon.net/grassrootseconomics/common v0.9.0-beta.1.0.20250417111317-2953f4c2f32e/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60= git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250623063234-c1797e7a32b5 h1:VnRe01kHkZUBK/QjE7iV6gElSqSwQnAkWV3yCHtuYrI= git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250623063234-c1797e7a32b5/go.mod h1:H97hR+VOnZvR5BiGVb0ScCPwH/IoKBOlKM+yrQNVpq0= +git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250623070026-d945964b0b46 h1:0+XkSRe7XSHa9WHXKpGPuC0myDszjchr4syH006lQ28= +git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250623070026-d945964b0b46/go.mod h1:y/vsN8UO0wSxZk3gv0y5df4RPKMJI6TIxjVcVCPF8T8= git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.2.0.20250408094335-e2d1f65bb306 h1:Jo+yWysWw/N5BJQtAyEMN8ePVvAyPHv+JG4lQti+1N4= git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.2.0.20250408094335-e2d1f65bb306/go.mod h1:FdLwYtzsjOIcDiW4uDgDYnB4Wdzq12uJUe0QHSSPbSo= git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250129070628-5a539172c694 h1:DjJlBSz0S13acft5XZDWk7ZYnzElym0xLMYEVgyNJ+E= @@ -99,6 +101,8 @@ github.com/grassrootseconomics/ethutils v1.3.1 h1:LlQO90HjJkl7ejC8fv6jP7RJUrAm1j github.com/grassrootseconomics/ethutils v1.3.1/go.mod h1:Wuv1VEZrkLIXqTSEYI3Nh9HG/ZHOUQ+U+xvWJ8QtjgQ= github.com/grassrootseconomics/ussd-data-service v1.5.0-beta h1:BSSQL/yPEvTVku9ja/ENZyZdwZkEaiTzzOUfg72bTy4= github.com/grassrootseconomics/ussd-data-service v1.5.0-beta/go.mod h1:9sGnorpKaK76FmOGXoh/xv7x5siSFNYdXxQo9BKW4DI= +github.com/grassrootseconomics/ussd-data-service v1.6.0-beta h1:pY6zns6ifXyClRxP+JJaWrged3oRE7tTS2xaftF9clA= +github.com/grassrootseconomics/ussd-data-service v1.6.0-beta/go.mod h1:9sGnorpKaK76FmOGXoh/xv7x5siSFNYdXxQo9BKW4DI= github.com/graygnuorg/go-gdbm v0.0.0-20220711140707-71387d66dce4 h1:U4kkNYryi/qfbBF8gh7Vsbuz+cVmhf5kt6pE9bYYyLo= github.com/graygnuorg/go-gdbm v0.0.0-20220711140707-71387d66dce4/go.mod h1:zpZDgZFzeq9s0MIeB1P50NIEWDFFHSFBohI/NbaTD/Y= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= diff --git a/handlers/application/menuhandler.go b/handlers/application/menuhandler.go index 3b56665..7f31c5b 100644 --- a/handlers/application/menuhandler.go +++ b/handlers/application/menuhandler.go @@ -2044,7 +2044,7 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b defaultSym := firstVoucher.TokenSymbol defaultBal := firstVoucher.Balance defaultDec := firstVoucher.TokenDecimals - defaultAddr := firstVoucher.ContractAddress + defaultAddr := firstVoucher.TokenAddress // Scale down the balance scaledBalance := store.ScaleDownBalance(defaultBal, defaultDec) diff --git a/handlers/application/menuhandler_test.go b/handlers/application/menuhandler_test.go index a608b7d..a2485c0 100644 --- a/handlers/application/menuhandler_test.go +++ b/handlers/application/menuhandler_test.go @@ -2107,10 +2107,10 @@ func TestManageVouchers(t *testing.T) { name: "Set default voucher when no active voucher is set", vouchersResp: []dataserviceapi.TokenHoldings{ { - ContractAddress: "0x123", - TokenSymbol: "TOKEN1", - TokenDecimals: "18", - Balance: "100", + TokenAddress: "0x123", + TokenSymbol: "TOKEN1", + TokenDecimals: "18", + Balance: "100", }, }, expectedVoucherSymbols: []byte("1:TOKEN1"), @@ -2122,8 +2122,8 @@ func TestManageVouchers(t *testing.T) { { name: "Check and update active voucher balance", vouchersResp: []dataserviceapi.TokenHoldings{ - {ContractAddress: "0xd4c288865Ce", TokenSymbol: "SRF", TokenDecimals: "6", Balance: "100"}, - {ContractAddress: "0x41c188d63Qa", TokenSymbol: "MILO", TokenDecimals: "4", Balance: "200"}, + {TokenAddress: "0xd4c288865Ce", TokenSymbol: "SRF", TokenDecimals: "6", Balance: "100"}, + {TokenAddress: "0x41c188d63Qa", TokenSymbol: "MILO", TokenDecimals: "4", Balance: "200"}, }, storedActiveVoucher: "SRF", expectedVoucherSymbols: []byte("1:SRF\n2:MILO"), @@ -2255,13 +2255,13 @@ func TestSetVoucher(t *testing.T) { // Define the temporary voucher data tempData := &dataserviceapi.TokenHoldings{ - TokenSymbol: "SRF", - Balance: "200", - TokenDecimals: "6", - ContractAddress: "0xd4c288865Ce0985a481Eef3be02443dF5E2e4Ea9", + TokenSymbol: "SRF", + Balance: "200", + TokenDecimals: "6", + TokenAddress: "0xd4c288865Ce0985a481Eef3be02443dF5E2e4Ea9", } - expectedData := fmt.Sprintf("%s,%s,%s,%s", tempData.TokenSymbol, tempData.Balance, tempData.TokenDecimals, tempData.ContractAddress) + expectedData := fmt.Sprintf("%s,%s,%s,%s", tempData.TokenSymbol, tempData.Balance, tempData.TokenDecimals, tempData.TokenAddress) // store the expectedData if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(expectedData)); err != nil { @@ -2529,11 +2529,11 @@ func TestCheckTransactions(t *testing.T) { mockTXResponse := []dataserviceapi.Last10TxResponse{ { - Sender: "0X13242618721", Recipient: "0x41c188d63Qa", TransferValue: "100", ContractAddress: "0X1324262343rfdGW23", + Sender: "0X13242618721", Recipient: "0x41c188d63Qa", TransferValue: "100", TokenAddress: "0X1324262343rfdGW23", TxHash: "0x123wefsf34rf", DateBlock: time.Now(), TokenSymbol: "SRF", TokenDecimals: "6", }, { - Sender: "0x41c188d63Qa", Recipient: "0X13242618721", TransferValue: "200", ContractAddress: "0X1324262343rfdGW23", + Sender: "0x41c188d63Qa", Recipient: "0X13242618721", TransferValue: "200", TokenAddress: "0X1324262343rfdGW23", TxHash: "0xq34wresfdb44", DateBlock: time.Now(), TokenSymbol: "SRF", TokenDecimals: "6", }, } @@ -2585,11 +2585,11 @@ func TestGetTransactionsList(t *testing.T) { mockTXResponse := []dataserviceapi.Last10TxResponse{ { - Sender: "0X13242618721", Recipient: "0x41c188d63Qa", TransferValue: "1000", ContractAddress: "0X1324262343rfdGW23", + Sender: "0X13242618721", Recipient: "0x41c188d63Qa", TransferValue: "1000", TokenAddress: "0X1324262343rfdGW23", TxHash: "0x123wefsf34rf", DateBlock: dateBlock, TokenSymbol: "SRF", TokenDecimals: "2", }, { - Sender: "0x41c188d63Qa", Recipient: "0X13242618721", TransferValue: "2000", ContractAddress: "0X1324262343rfdGW23", + Sender: "0x41c188d63Qa", Recipient: "0X13242618721", TransferValue: "2000", TokenAddress: "0X1324262343rfdGW23", TxHash: "0xq34wresfdb44", DateBlock: dateBlock, TokenSymbol: "SRF", TokenDecimals: "2", }, } @@ -2654,11 +2654,11 @@ func TestViewTransactionStatement(t *testing.T) { mockTXResponse := []dataserviceapi.Last10TxResponse{ { - Sender: "0X13242618721", Recipient: "0x41c188d63Qa", TransferValue: "1000", ContractAddress: "0X1324262343rfdGW23", + Sender: "0X13242618721", Recipient: "0x41c188d63Qa", TransferValue: "1000", TokenAddress: "0X1324262343rfdGW23", TxHash: "0x123wefsf34rf", DateBlock: dateBlock, TokenSymbol: "SRF", TokenDecimals: "2", }, { - Sender: "0x41c188d63Qa", Recipient: "0X13242618721", TransferValue: "2000", ContractAddress: "0X1324262343rfdGW23", + Sender: "0x41c188d63Qa", Recipient: "0X13242618721", TransferValue: "2000", TokenAddress: "0X1324262343rfdGW23", TxHash: "0xq34wresfdb44", DateBlock: dateBlock, TokenSymbol: "SRF", TokenDecimals: "2", }, } diff --git a/store/swap.go b/store/swap.go index c4a20fa..b25686a 100644 --- a/store/swap.go +++ b/store/swap.go @@ -125,10 +125,10 @@ func GetSwapFromVoucherData(ctx context.Context, store DataStore, sessionId stri } return &dataserviceapi.TokenHoldings{ - TokenSymbol: string(symbol), - Balance: string(balance), - TokenDecimals: string(decimal), - ContractAddress: string(address), + TokenSymbol: string(symbol), + Balance: string(balance), + TokenDecimals: string(decimal), + TokenAddress: string(address), }, nil } diff --git a/store/swap_test.go b/store/swap_test.go index 179eeee..ceabe99 100644 --- a/store/swap_test.go +++ b/store/swap_test.go @@ -114,7 +114,7 @@ func TestGetSwapFromVoucherData(t *testing.T) { assert.Equal(t, "AMANI", result.TokenSymbol) assert.Equal(t, "", result.Balance) assert.Equal(t, "6", result.TokenDecimals) - assert.Equal(t, "0xc7B78Ac9ACB9E025C8234621FC515bC58179dEAe", result.ContractAddress) + assert.Equal(t, "0xc7B78Ac9ACB9E025C8234621FC515bC58179dEAe", result.TokenAddress) } func TestGetSwapToVoucherData(t *testing.T) { @@ -142,5 +142,5 @@ func TestGetSwapToVoucherData(t *testing.T) { assert.Equal(t, "cUSD", result.TokenSymbol) assert.Equal(t, "", result.Balance) assert.Equal(t, "6", result.TokenDecimals) - assert.Equal(t, "0xc7B78Ac9ACB9E025C8234621", result.ContractAddress) + assert.Equal(t, "0xc7B78Ac9ACB9E025C8234621", result.TokenAddress) } diff --git a/store/vouchers.go b/store/vouchers.go index 42da3e0..d8c28f5 100644 --- a/store/vouchers.go +++ b/store/vouchers.go @@ -36,7 +36,7 @@ func ProcessVouchers(holdings []dataserviceapi.TokenHoldings) VoucherMetadata { balances = append(balances, fmt.Sprintf("%d:%s", i+1, scaledBalance)) decimals = append(decimals, fmt.Sprintf("%d:%s", i+1, h.TokenDecimals)) - addresses = append(addresses, fmt.Sprintf("%d:%s", i+1, h.ContractAddress)) + addresses = append(addresses, fmt.Sprintf("%d:%s", i+1, h.TokenAddress)) } data.Symbols = strings.Join(symbols, "\n") @@ -55,7 +55,7 @@ func ProcessTokens(holdings []dataserviceapi.TokenHoldings) VoucherMetadata { for i, h := range holdings { symbols = append(symbols, fmt.Sprintf("%d:%s", i+1, h.TokenSymbol)) decimals = append(decimals, fmt.Sprintf("%d:%d", i+1, h.TokenDecimals)) - addresses = append(addresses, fmt.Sprintf("%d:%s", i+1, h.ContractAddress)) + addresses = append(addresses, fmt.Sprintf("%d:%s", i+1, h.TokenAddress)) } data.Symbols = strings.Join(symbols, "\n") @@ -115,10 +115,10 @@ func GetVoucherData(ctx context.Context, store DataStore, sessionId string, inpu } return &dataserviceapi.TokenHoldings{ - TokenSymbol: string(symbol), - Balance: string(balance), - TokenDecimals: string(decimal), - ContractAddress: string(address), + TokenSymbol: string(symbol), + Balance: string(balance), + TokenDecimals: string(decimal), + TokenAddress: string(address), }, nil } @@ -152,7 +152,7 @@ func MatchVoucher(input, symbols, balances, decimals, addresses string) (symbol, // StoreTemporaryVoucher saves voucher metadata as temporary entries in the DataStore. func StoreTemporaryVoucher(ctx context.Context, store DataStore, sessionId string, data *dataserviceapi.TokenHoldings) error { - tempData := fmt.Sprintf("%s,%s,%s,%s", data.TokenSymbol, data.Balance, data.TokenDecimals, data.ContractAddress) + tempData := fmt.Sprintf("%s,%s,%s,%s", data.TokenSymbol, data.Balance, data.TokenDecimals, data.TokenAddress) if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tempData)); err != nil { return err @@ -175,7 +175,7 @@ func GetTemporaryVoucherData(ctx context.Context, store DataStore, sessionId str data.TokenSymbol = values[0] data.Balance = values[1] data.TokenDecimals = values[2] - data.ContractAddress = values[3] + data.TokenAddress = values[3] return data, nil } @@ -188,7 +188,7 @@ func UpdateVoucherData(ctx context.Context, store DataStore, sessionId string, d storedb.DATA_ACTIVE_SYM: []byte(data.TokenSymbol), storedb.DATA_ACTIVE_BAL: []byte(data.Balance), storedb.DATA_ACTIVE_DECIMAL: []byte(data.TokenDecimals), - storedb.DATA_ACTIVE_ADDRESS: []byte(data.ContractAddress), + storedb.DATA_ACTIVE_ADDRESS: []byte(data.TokenAddress), } // Write active data diff --git a/store/vouchers_test.go b/store/vouchers_test.go index 711f93b..3526772 100644 --- a/store/vouchers_test.go +++ b/store/vouchers_test.go @@ -59,8 +59,8 @@ func TestMatchVoucher(t *testing.T) { func TestProcessVouchers(t *testing.T) { holdings := []dataserviceapi.TokenHoldings{ - {ContractAddress: "0xd4c288865Ce", TokenSymbol: "SRF", TokenDecimals: "6", Balance: "100000000"}, - {ContractAddress: "0x41c188d63Qa", TokenSymbol: "MILO", TokenDecimals: "4", Balance: "200000000"}, + {TokenAddress: "0xd4c288865Ce", TokenSymbol: "SRF", TokenDecimals: "6", Balance: "100000000"}, + {TokenAddress: "0x41c188d63Qa", TokenSymbol: "MILO", TokenDecimals: "4", Balance: "200000000"}, } expectedResult := VoucherMetadata{ @@ -101,7 +101,7 @@ func TestGetVoucherData(t *testing.T) { assert.Equal(t, "SRF", result.TokenSymbol) assert.Equal(t, "100", result.Balance) assert.Equal(t, "6", result.TokenDecimals) - assert.Equal(t, "0xd4c288865Ce", result.ContractAddress) + assert.Equal(t, "0xd4c288865Ce", result.TokenAddress) } func TestStoreTemporaryVoucher(t *testing.T) { @@ -110,10 +110,10 @@ func TestStoreTemporaryVoucher(t *testing.T) { // Test data voucherData := &dataserviceapi.TokenHoldings{ - TokenSymbol: "SRF", - Balance: "200", - TokenDecimals: "6", - ContractAddress: "0xd4c288865Ce0985a481Eef3be02443dF5E2e4Ea9", + TokenSymbol: "SRF", + Balance: "200", + TokenDecimals: "6", + TokenAddress: "0xd4c288865Ce0985a481Eef3be02443dF5E2e4Ea9", } // Execute the function being tested @@ -134,10 +134,10 @@ func TestGetTemporaryVoucherData(t *testing.T) { // Test voucher data tempData := &dataserviceapi.TokenHoldings{ - TokenSymbol: "SRF", - Balance: "200", - TokenDecimals: "6", - ContractAddress: "0xd4c288865Ce0985a481Eef3be02443dF5E2e4Ea9", + TokenSymbol: "SRF", + Balance: "200", + TokenDecimals: "6", + TokenAddress: "0xd4c288865Ce0985a481Eef3be02443dF5E2e4Ea9", } // Store the data @@ -156,18 +156,18 @@ func TestUpdateVoucherData(t *testing.T) { // New voucher data newData := &dataserviceapi.TokenHoldings{ - TokenSymbol: "SRF", - Balance: "200", - TokenDecimals: "6", - ContractAddress: "0xd4c288865Ce0985a481Eef3be02443dF5E2e4Ea9", + TokenSymbol: "SRF", + Balance: "200", + TokenDecimals: "6", + TokenAddress: "0xd4c288865Ce0985a481Eef3be02443dF5E2e4Ea9", } // Old temporary data tempData := &dataserviceapi.TokenHoldings{ - TokenSymbol: "OLD", - Balance: "100", - TokenDecimals: "8", - ContractAddress: "0xold", + TokenSymbol: "OLD", + Balance: "100", + TokenDecimals: "8", + TokenAddress: "0xold", } require.NoError(t, StoreTemporaryVoucher(ctx, store, sessionId, tempData)) @@ -180,7 +180,7 @@ func TestUpdateVoucherData(t *testing.T) { storedb.DATA_ACTIVE_SYM: []byte(newData.TokenSymbol), storedb.DATA_ACTIVE_BAL: []byte(newData.Balance), storedb.DATA_ACTIVE_DECIMAL: []byte(newData.TokenDecimals), - storedb.DATA_ACTIVE_ADDRESS: []byte(newData.ContractAddress), + storedb.DATA_ACTIVE_ADDRESS: []byte(newData.TokenAddress), } for key, expectedValue := range activeEntries {