Add transaction fetch to mock api
This commit is contained in:
parent
a4443cbe4c
commit
da46b6ca1a
@ -1,6 +1,7 @@
|
|||||||
package nats
|
package nats
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -104,7 +105,19 @@ func(m mockApi) FetchVouchers(ctx context.Context, publicKey string) ([]dataserv
|
|||||||
}
|
}
|
||||||
|
|
||||||
func(m mockApi) FetchTransactions(ctx context.Context, publicKey string) ([]dataserviceapi.Last10TxResponse, error) {
|
func(m mockApi) FetchTransactions(ctx context.Context, publicKey string) ([]dataserviceapi.Last10TxResponse, error) {
|
||||||
return nil, nil
|
logg.DebugCtxf(ctx, "mockapi fetchtransactions", "key", publicKey)
|
||||||
|
return []dataserviceapi.Last10TxResponse{
|
||||||
|
dataserviceapi.Last10TxResponse{
|
||||||
|
Sender: "0xeae046BF396e91f5A8D74f863dC57c107c8a4a70",
|
||||||
|
Recipient: "B3117202371853e24B725d4169D87616A7dDb127",
|
||||||
|
TransferValue: "1337",
|
||||||
|
ContractAddress: "0x765DE816845861e75A25fCA122bb6898B8B1282a",
|
||||||
|
TxHash: "0xabcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789",
|
||||||
|
DateBlock: time.Unix(1730592500, 0),
|
||||||
|
TokenSymbol: "FOO",
|
||||||
|
TokenDecimals: "6",
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(m mockApi) VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error) {
|
func(m mockApi) VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error) {
|
||||||
@ -163,4 +176,32 @@ func TestHandleMsg(t *testing.T) {
|
|||||||
data: []byte(data),
|
data: []byte(data),
|
||||||
}
|
}
|
||||||
sub.handleEvent(msg)
|
sub.handleEvent(msg)
|
||||||
|
|
||||||
|
store := common.UserDataStore{
|
||||||
|
Db: userDb,
|
||||||
|
}
|
||||||
|
v, err := store.ReadEntry(ctx, aliceSession, common.DATA_ACTIVE_SYM)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !bytes.Equal(v, []byte("FOO")) {
|
||||||
|
t.Fatalf("expected 'FOO', got %s", v)
|
||||||
|
}
|
||||||
|
|
||||||
|
v, err = store.ReadEntry(ctx, aliceSession, common.DATA_ACTIVE_BAL)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !bytes.Equal(v, []byte("362436")) {
|
||||||
|
t.Fatalf("expected '362436', got %s", v)
|
||||||
|
}
|
||||||
|
|
||||||
|
v, err = store.ReadEntry(ctx, aliceSession, common.DATA_TRANSACTIONS)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(v) == 0 {
|
||||||
|
t.Fatal("no transaction data")
|
||||||
|
}
|
||||||
|
t.Logf("tx %s", v)
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event"
|
geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event"
|
||||||
|
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
||||||
|
|
||||||
"git.defalsify.org/vise.git/db"
|
"git.defalsify.org/vise.git/db"
|
||||||
"git.grassecon.net/urdt/ussd/common"
|
"git.grassecon.net/urdt/ussd/common"
|
||||||
@ -31,7 +32,11 @@ type eventTokenTransfer struct {
|
|||||||
VoucherAddress string
|
VoucherAddress string
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateTokenTransferList(ctx context.Context, store common.UserDataStore, identity lookup.Identity) error {
|
func formatTransaction(idx int, tx dataserviceapi.Last10TxResponse) string {
|
||||||
|
return fmt.Sprintf("%d %s %s", idx, tx.DateBlock, tx.TxHash[:10])
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateTokenTransferList(ctx context.Context, store *common.UserDataStore, identity lookup.Identity) error {
|
||||||
var r []string
|
var r []string
|
||||||
|
|
||||||
txs, err := lookup.Api.FetchTransactions(ctx, identity.ChecksumAddress)
|
txs, err := lookup.Api.FetchTransactions(ctx, identity.ChecksumAddress)
|
||||||
@ -40,10 +45,11 @@ func updateTokenTransferList(ctx context.Context, store common.UserDataStore, id
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, tx := range(txs) {
|
for i, tx := range(txs) {
|
||||||
r = append(r, fmt.Sprintf("%d %s %s", i, tx.DateBlock, tx.TxHash[:10]))
|
r = append(r, formatTransaction(i, tx))
|
||||||
}
|
}
|
||||||
|
|
||||||
s := strings.Join(r, "\n")
|
s := strings.Join(r, "\n")
|
||||||
|
|
||||||
return store.WriteEntry(ctx, identity.SessionId, common.DATA_TRANSACTIONS, []byte(s))
|
return store.WriteEntry(ctx, identity.SessionId, common.DATA_TRANSACTIONS, []byte(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,6 +144,11 @@ func updateToken(ctx context.Context, store *common.UserDataStore, identity look
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = updateTokenTransferList(ctx, store, identity)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user