Gofmt, remove commented code
This commit is contained in:
parent
7e2d6b8d09
commit
b69115caaa
@ -9,15 +9,15 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"git.defalsify.org/vise.git/logging"
|
"git.defalsify.org/vise.git/logging"
|
||||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/config"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/config"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/event/nats"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/event/nats"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/lookup"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/lookup"
|
||||||
viseevent "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event"
|
viseevent "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event"
|
||||||
|
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
logg = logging.NewVanilla()
|
logg = logging.NewVanilla()
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
viseconfig "git.grassecon.net/grassrootseconomics/visedriver/config"
|
|
||||||
apiconfig "git.grassecon.net/grassrootseconomics/sarafu-api/config"
|
apiconfig "git.grassecon.net/grassrootseconomics/sarafu-api/config"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
||||||
|
viseconfig "git.grassecon.net/grassrootseconomics/visedriver/config"
|
||||||
"git.grassecon.net/grassrootseconomics/visedriver/env"
|
"git.grassecon.net/grassrootseconomics/visedriver/env"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
JetstreamURL string
|
JetstreamURL string
|
||||||
JetstreamClientName string
|
JetstreamClientName string
|
||||||
Apply = config.Apply
|
Apply = config.Apply
|
||||||
GetConns = config.GetConns
|
GetConns = config.GetConns
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultJetstreamURL string = "localhost:4222"
|
defaultJetstreamURL string = "localhost:4222"
|
||||||
defaultJetstreamClientName string = "omnom"
|
defaultJetstreamClientName string = "omnom"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package event
|
package event
|
||||||
|
|
||||||
import (
|
import (
|
||||||
geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event"
|
|
||||||
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
|
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
|
||||||
|
geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -4,20 +4,19 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"git.defalsify.org/vise.git/cache"
|
||||||
"git.defalsify.org/vise.git/db"
|
"git.defalsify.org/vise.git/db"
|
||||||
"git.defalsify.org/vise.git/state"
|
"git.defalsify.org/vise.git/state"
|
||||||
"git.defalsify.org/vise.git/cache"
|
|
||||||
"git.grassecon.net/grassrootseconomics/visedriver/testutil/mocks"
|
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
|
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/config"
|
|
||||||
"git.grassecon.net/grassrootseconomics/common/hex"
|
"git.grassecon.net/grassrootseconomics/common/hex"
|
||||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
|
||||||
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
|
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
|
||||||
apimocks "git.grassecon.net/grassrootseconomics/sarafu-api/testutil/mocks"
|
apimocks "git.grassecon.net/grassrootseconomics/sarafu-api/testutil/mocks"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/config"
|
||||||
viseevent "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event"
|
viseevent "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event"
|
||||||
|
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||||
|
"git.grassecon.net/grassrootseconomics/visedriver/testutil/mocks"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func TestCustodialRegistration(t *testing.T) {
|
func TestCustodialRegistration(t *testing.T) {
|
||||||
err := config.LoadConfig()
|
err := config.LoadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -5,13 +5,13 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"git.defalsify.org/vise.git/logging"
|
||||||
|
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/config"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/event"
|
||||||
|
geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event"
|
||||||
nats "github.com/nats-io/nats.go"
|
nats "github.com/nats-io/nats.go"
|
||||||
"github.com/nats-io/nats.go/jetstream"
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event"
|
|
||||||
"git.defalsify.org/vise.git/logging"
|
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/event"
|
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/config"
|
|
||||||
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -23,10 +23,10 @@ var (
|
|||||||
// Extends Router.
|
// Extends Router.
|
||||||
type NatsSubscription struct {
|
type NatsSubscription struct {
|
||||||
*event.Router
|
*event.Router
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
conn *nats.Conn
|
conn *nats.Conn
|
||||||
js jetstream.JetStream
|
js jetstream.JetStream
|
||||||
cs jetstream.Consumer
|
cs jetstream.Consumer
|
||||||
cctx jetstream.ConsumeContext
|
cctx jetstream.ConsumeContext
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ func NewNatsSubscription(handler *apievent.EventsHandler) *NatsSubscription {
|
|||||||
// Fails if connection fails or the "Jetstream" consumer cannot be set up.
|
// Fails if connection fails or the "Jetstream" consumer cannot be set up.
|
||||||
//
|
//
|
||||||
// Once connected, it will attempt to reconnect if disconnected.
|
// Once connected, it will attempt to reconnect if disconnected.
|
||||||
func(n *NatsSubscription) Connect(ctx context.Context, connStr string) error {
|
func (n *NatsSubscription) Connect(ctx context.Context, connStr string) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// enables set ctx in test, even if the connstr is invalid (js msg handler doesnt take context)
|
// enables set ctx in test, even if the connstr is invalid (js msg handler doesnt take context)
|
||||||
@ -59,8 +59,8 @@ func(n *NatsSubscription) Connect(ctx context.Context, connStr string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
n.cs, err = n.js.CreateConsumer(ctx, "TRACKER", jetstream.ConsumerConfig{
|
n.cs, err = n.js.CreateConsumer(ctx, "TRACKER", jetstream.ConsumerConfig{
|
||||||
Name: config.JetstreamClientName,
|
Name: config.JetstreamClientName,
|
||||||
Durable: config.JetstreamClientName,
|
Durable: config.JetstreamClientName,
|
||||||
FilterSubjects: []string{"TRACKER.*"},
|
FilterSubjects: []string{"TRACKER.*"},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -78,7 +78,7 @@ func(n *NatsSubscription) Connect(ctx context.Context, connStr string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close cleanly brings down the nats and jetstream connection.
|
// Close cleanly brings down the nats and jetstream connection.
|
||||||
func(n *NatsSubscription) Close() error {
|
func (n *NatsSubscription) Close() error {
|
||||||
n.cctx.Stop()
|
n.cctx.Stop()
|
||||||
select {
|
select {
|
||||||
case <-n.cctx.Closed():
|
case <-n.cctx.Closed():
|
||||||
@ -88,7 +88,7 @@ func(n *NatsSubscription) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// jetstream message handler and acknowledger.
|
// jetstream message handler and acknowledger.
|
||||||
func(n *NatsSubscription) handleEvent(m jetstream.Msg) {
|
func (n *NatsSubscription) handleEvent(m jetstream.Msg) {
|
||||||
var ev geEvent.Event
|
var ev geEvent.Event
|
||||||
|
|
||||||
logg.DebugCtxf(n.ctx, "have msg", "msg", m)
|
logg.DebugCtxf(n.ctx, "have msg", "msg", m)
|
||||||
|
@ -9,34 +9,34 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
nats "github.com/nats-io/nats.go"
|
|
||||||
"github.com/nats-io/nats.go/jetstream"
|
|
||||||
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
|
||||||
"git.defalsify.org/vise.git/db"
|
"git.defalsify.org/vise.git/db"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/config"
|
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
|
||||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
|
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/lookup"
|
|
||||||
"git.grassecon.net/grassrootseconomics/common/hex"
|
"git.grassecon.net/grassrootseconomics/common/hex"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
|
||||||
apimocks "git.grassecon.net/grassrootseconomics/sarafu-api/testutil/mocks"
|
apimocks "git.grassecon.net/grassrootseconomics/sarafu-api/testutil/mocks"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/config"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/internal/testutil"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/internal/testutil"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/lookup"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application"
|
||||||
viseevent "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event"
|
viseevent "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||||
|
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||||
"git.grassecon.net/grassrootseconomics/visedriver/testutil/mocks"
|
"git.grassecon.net/grassrootseconomics/visedriver/testutil/mocks"
|
||||||
|
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
||||||
|
nats "github.com/nats-io/nats.go"
|
||||||
|
"github.com/nats-io/nats.go/jetstream"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
txBlock = 42
|
txBlock = 42
|
||||||
tokenAddress = "0x765DE816845861e75A25fCA122bb6898B8B1282a"
|
tokenAddress = "0x765DE816845861e75A25fCA122bb6898B8B1282a"
|
||||||
tokenSymbol = "FOO"
|
tokenSymbol = "FOO"
|
||||||
tokenName = "Foo Token"
|
tokenName = "Foo Token"
|
||||||
tokenDecimals = 6
|
tokenDecimals = 6
|
||||||
txValue = 1337
|
txValue = 1337
|
||||||
tokenBalance = 362436
|
tokenBalance = 362436
|
||||||
txTimestamp = 1730592500
|
txTimestamp = 1730592500
|
||||||
txHash = "0xabcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
|
txHash = "0xabcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
|
||||||
sinkAddress = "0xb42C5920014eE152F2225285219407938469BBfA"
|
sinkAddress = "0xb42C5920014eE152F2225285219407938469BBfA"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: jetstream, would have been nice of you to provide an easier way to make a mock msg
|
// TODO: jetstream, would have been nice of you to provide an easier way to make a mock msg
|
||||||
@ -44,51 +44,51 @@ type testMsg struct {
|
|||||||
data []byte
|
data []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func(m *testMsg) Ack() error {
|
func (m *testMsg) Ack() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(m *testMsg) Nak() error {
|
func (m *testMsg) Nak() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(m *testMsg) NakWithDelay(time.Duration) error {
|
func (m *testMsg) NakWithDelay(time.Duration) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(m *testMsg) Data() []byte {
|
func (m *testMsg) Data() []byte {
|
||||||
return m.data
|
return m.data
|
||||||
}
|
}
|
||||||
|
|
||||||
func(m *testMsg) Reply() string {
|
func (m *testMsg) Reply() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func(m *testMsg) Subject() string {
|
func (m *testMsg) Subject() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func(m *testMsg) Term() error {
|
func (m *testMsg) Term() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(m *testMsg) TermWithReason(string) error {
|
func (m *testMsg) TermWithReason(string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(m *testMsg) DoubleAck(ctx context.Context) error {
|
func (m *testMsg) DoubleAck(ctx context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(m *testMsg) Headers() nats.Header {
|
func (m *testMsg) Headers() nats.Header {
|
||||||
return nats.Header{}
|
return nats.Header{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func(m *testMsg) InProgress() error {
|
func (m *testMsg) InProgress() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(m *testMsg) Metadata() (*jetstream.MsgMetadata, error) {
|
func (m *testMsg) Metadata() (*jetstream.MsgMetadata, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,29 +101,29 @@ func TestHandleMsg(t *testing.T) {
|
|||||||
api := &apimocks.MockApi{}
|
api := &apimocks.MockApi{}
|
||||||
api.TransactionsContent = []dataserviceapi.Last10TxResponse{
|
api.TransactionsContent = []dataserviceapi.Last10TxResponse{
|
||||||
dataserviceapi.Last10TxResponse{
|
dataserviceapi.Last10TxResponse{
|
||||||
Sender: apimocks.AliceChecksum,
|
Sender: apimocks.AliceChecksum,
|
||||||
Recipient: apimocks.BobChecksum,
|
Recipient: apimocks.BobChecksum,
|
||||||
TransferValue: strconv.Itoa(txValue),
|
TransferValue: strconv.Itoa(txValue),
|
||||||
ContractAddress: tokenAddress,
|
ContractAddress: tokenAddress,
|
||||||
TxHash: txHash,
|
TxHash: txHash,
|
||||||
DateBlock: time.Unix(txTimestamp, 0),
|
DateBlock: time.Unix(txTimestamp, 0),
|
||||||
TokenSymbol: tokenSymbol,
|
TokenSymbol: tokenSymbol,
|
||||||
TokenDecimals: strconv.Itoa(tokenDecimals),
|
TokenDecimals: strconv.Itoa(tokenDecimals),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
api.VoucherDataContent = &models.VoucherDataResult{
|
api.VoucherDataContent = &models.VoucherDataResult{
|
||||||
TokenSymbol: tokenSymbol,
|
TokenSymbol: tokenSymbol,
|
||||||
TokenName: tokenName,
|
TokenName: tokenName,
|
||||||
//TokenDecimals: strconv.Itoa(tokenDecimals),
|
//TokenDecimals: strconv.Itoa(tokenDecimals),
|
||||||
TokenDecimals: tokenDecimals,
|
TokenDecimals: tokenDecimals,
|
||||||
SinkAddress: sinkAddress,
|
SinkAddress: sinkAddress,
|
||||||
}
|
}
|
||||||
api.VouchersContent = []dataserviceapi.TokenHoldings{
|
api.VouchersContent = []dataserviceapi.TokenHoldings{
|
||||||
dataserviceapi.TokenHoldings{
|
dataserviceapi.TokenHoldings{
|
||||||
ContractAddress: tokenAddress,
|
ContractAddress: tokenAddress,
|
||||||
TokenSymbol: tokenSymbol,
|
TokenSymbol: tokenSymbol,
|
||||||
TokenDecimals: strconv.Itoa(tokenDecimals),
|
TokenDecimals: strconv.Itoa(tokenDecimals),
|
||||||
Balance: strconv.Itoa(tokenBalance),
|
Balance: strconv.Itoa(tokenBalance),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
lookup.Api = api
|
lookup.Api = api
|
||||||
@ -182,8 +182,8 @@ func TestHandleMsg(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
fmts := fmt.Sprintf("%%1.%df", tokenDecimals)
|
fmts := fmt.Sprintf("%%1.%df", tokenDecimals)
|
||||||
expect := fmt.Sprintf(fmts, float64(tokenBalance) / math.Pow(10, tokenDecimals))
|
expect := fmt.Sprintf(fmts, float64(tokenBalance)/math.Pow(10, tokenDecimals))
|
||||||
//if !bytes.Equal(v, []byte(strconv.Itoa(tokenBalance))) {
|
|
||||||
if !bytes.Equal(v, []byte(expect)) {
|
if !bytes.Equal(v, []byte(expect)) {
|
||||||
t.Fatalf("expected '%d', got %s", tokenBalance, v)
|
t.Fatalf("expected '%d', got %s", tokenBalance, v)
|
||||||
}
|
}
|
||||||
@ -196,7 +196,6 @@ func TestHandleMsg(t *testing.T) {
|
|||||||
t.Fatal("no transaction data")
|
t.Fatal("no transaction data")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mh, err := application.NewMenuHandlers(nil, userStore, nil, testutil.ReplaceSeparatorFunc)
|
mh, err := application.NewMenuHandlers(nil, userStore, nil, testutil.ReplaceSeparatorFunc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -210,14 +209,4 @@ func TestHandleMsg(t *testing.T) {
|
|||||||
if rrs.Content != expect {
|
if rrs.Content != expect {
|
||||||
t.Fatalf("expected '%v', got '%v'", expect, rrs.Content)
|
t.Fatalf("expected '%v', got '%v'", expect, rrs.Content)
|
||||||
}
|
}
|
||||||
// userDb.SetPrefix(event.DATATYPE_USERSUB)
|
|
||||||
// userDb.SetSession(apimocks.AliceSession)
|
|
||||||
// k := append([]byte("vouchers"), []byte("sym")...)
|
|
||||||
// v, err = userDb.Get(ctx, k)
|
|
||||||
// if err != nil {
|
|
||||||
// t.Fatal(err)
|
|
||||||
// }
|
|
||||||
// if !bytes.Contains(v, []byte(fmt.Sprintf("1:%s", tokenSymbol))) {
|
|
||||||
// t.Fatalf("expected '1:%s', got %s", tokenSymbol, v)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ func NewRouter(handler *apievent.EventsHandler) *Router {
|
|||||||
//
|
//
|
||||||
// An error will be returned if no handler can be found, or if the resolved
|
// An error will be returned if no handler can be found, or if the resolved
|
||||||
// handler fails to successfully execute.
|
// handler fails to successfully execute.
|
||||||
func(r *Router) Route(ctx context.Context, gev *geEvent.Event) error {
|
func (r *Router) Route(ctx context.Context, gev *geEvent.Event) error {
|
||||||
logg.DebugCtxf(ctx, "have event", "ev", gev)
|
logg.DebugCtxf(ctx, "have event", "ev", gev)
|
||||||
evCC, ok := asCustodialRegistrationEvent(gev)
|
evCC, ok := asCustodialRegistrationEvent(gev)
|
||||||
if ok {
|
if ok {
|
||||||
|
@ -34,7 +34,6 @@ func formatTransaction(tag string, idx int, item any) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// waiter to check whether object is available on dependency endpoints.
|
// waiter to check whether object is available on dependency endpoints.
|
||||||
func updateWait(ctx context.Context) error {
|
func updateWait(ctx context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
|
@ -9,37 +9,36 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
|
||||||
"git.defalsify.org/vise.git/db"
|
"git.defalsify.org/vise.git/db"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/config"
|
"git.grassecon.net/grassrootseconomics/common/hex"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application"
|
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
|
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
|
||||||
|
apimocks "git.grassecon.net/grassrootseconomics/sarafu-api/testutil/mocks"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/config"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/internal/testutil"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/lookup"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application"
|
||||||
|
viseevent "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/lookup"
|
|
||||||
"git.grassecon.net/grassrootseconomics/common/hex"
|
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/internal/testutil"
|
|
||||||
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
|
|
||||||
apimocks "git.grassecon.net/grassrootseconomics/sarafu-api/testutil/mocks"
|
|
||||||
viseevent "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event"
|
|
||||||
"git.grassecon.net/grassrootseconomics/visedriver/testutil/mocks"
|
"git.grassecon.net/grassrootseconomics/visedriver/testutil/mocks"
|
||||||
|
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
txBlock = 42
|
txBlock = 42
|
||||||
tokenAddress = "0x765DE816845861e75A25fCA122bb6898B8B1282a"
|
tokenAddress = "0x765DE816845861e75A25fCA122bb6898B8B1282a"
|
||||||
tokenSymbol = "FOO"
|
tokenSymbol = "FOO"
|
||||||
tokenName = "Foo Token"
|
tokenName = "Foo Token"
|
||||||
tokenDecimals = 6
|
tokenDecimals = 6
|
||||||
txValue = 1337
|
txValue = 1337
|
||||||
tokenBalance = 362436
|
tokenBalance = 362436
|
||||||
txTimestamp = 1730592500
|
txTimestamp = 1730592500
|
||||||
txHash = "0xabcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
|
txHash = "0xabcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
|
||||||
sinkAddress = "0xb42C5920014eE152F2225285219407938469BBfA"
|
sinkAddress = "0xb42C5920014eE152F2225285219407938469BBfA"
|
||||||
bogusSym = "/-21380u"
|
bogusSym = "/-21380u"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func TestTokenTransfer(t *testing.T) {
|
func TestTokenTransfer(t *testing.T) {
|
||||||
err := config.LoadConfig()
|
err := config.LoadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -49,29 +48,29 @@ func TestTokenTransfer(t *testing.T) {
|
|||||||
api := &apimocks.MockApi{}
|
api := &apimocks.MockApi{}
|
||||||
api.TransactionsContent = []dataserviceapi.Last10TxResponse{
|
api.TransactionsContent = []dataserviceapi.Last10TxResponse{
|
||||||
dataserviceapi.Last10TxResponse{
|
dataserviceapi.Last10TxResponse{
|
||||||
Sender: apimocks.AliceChecksum,
|
Sender: apimocks.AliceChecksum,
|
||||||
Recipient: apimocks.BobChecksum,
|
Recipient: apimocks.BobChecksum,
|
||||||
TransferValue: strconv.Itoa(txValue),
|
TransferValue: strconv.Itoa(txValue),
|
||||||
ContractAddress: tokenAddress,
|
ContractAddress: tokenAddress,
|
||||||
TxHash: txHash,
|
TxHash: txHash,
|
||||||
DateBlock: time.Unix(txTimestamp, 0),
|
DateBlock: time.Unix(txTimestamp, 0),
|
||||||
TokenSymbol: tokenSymbol,
|
TokenSymbol: tokenSymbol,
|
||||||
TokenDecimals: strconv.Itoa(tokenDecimals),
|
TokenDecimals: strconv.Itoa(tokenDecimals),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
api.VoucherDataContent = &models.VoucherDataResult{
|
api.VoucherDataContent = &models.VoucherDataResult{
|
||||||
TokenSymbol: tokenSymbol,
|
TokenSymbol: tokenSymbol,
|
||||||
TokenName: tokenName,
|
TokenName: tokenName,
|
||||||
//TokenDecimals: strconv.Itoa(tokenDecimals),
|
//TokenDecimals: strconv.Itoa(tokenDecimals),
|
||||||
TokenDecimals: tokenDecimals,
|
TokenDecimals: tokenDecimals,
|
||||||
SinkAddress: sinkAddress,
|
SinkAddress: sinkAddress,
|
||||||
}
|
}
|
||||||
api.VouchersContent = []dataserviceapi.TokenHoldings{
|
api.VouchersContent = []dataserviceapi.TokenHoldings{
|
||||||
dataserviceapi.TokenHoldings{
|
dataserviceapi.TokenHoldings{
|
||||||
ContractAddress: tokenAddress,
|
ContractAddress: tokenAddress,
|
||||||
TokenSymbol: tokenSymbol,
|
TokenSymbol: tokenSymbol,
|
||||||
TokenDecimals: strconv.Itoa(tokenDecimals),
|
TokenDecimals: strconv.Itoa(tokenDecimals),
|
||||||
Balance: strconv.Itoa(tokenBalance),
|
Balance: strconv.Itoa(tokenBalance),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
lookup.Api = api
|
lookup.Api = api
|
||||||
@ -98,8 +97,8 @@ func TestTokenTransfer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ev := &apievent.EventTokenTransfer{
|
ev := &apievent.EventTokenTransfer{
|
||||||
From: apimocks.BobChecksum,
|
From: apimocks.BobChecksum,
|
||||||
To: apimocks.AliceChecksum,
|
To: apimocks.AliceChecksum,
|
||||||
Value: txValue,
|
Value: txValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +122,7 @@ func TestTokenTransfer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
//if !bytes.Equal(v, []byte(strconv.Itoa(tokenBalance))) {
|
//if !bytes.Equal(v, []byte(strconv.Itoa(tokenBalance))) {
|
||||||
fmts := fmt.Sprintf("%%1.%df", tokenDecimals)
|
fmts := fmt.Sprintf("%%1.%df", tokenDecimals)
|
||||||
expect := fmt.Sprintf(fmts, float64(tokenBalance) / math.Pow(10, tokenDecimals))
|
expect := fmt.Sprintf(fmts, float64(tokenBalance)/math.Pow(10, tokenDecimals))
|
||||||
if !bytes.Equal(v, []byte(expect)) {
|
if !bytes.Equal(v, []byte(expect)) {
|
||||||
t.Fatalf("expected '%s', got %s", expect, v)
|
t.Fatalf("expected '%s', got %s", expect, v)
|
||||||
}
|
}
|
||||||
@ -160,34 +159,33 @@ func TestTokenMint(t *testing.T) {
|
|||||||
api := &apimocks.MockApi{}
|
api := &apimocks.MockApi{}
|
||||||
api.TransactionsContent = []dataserviceapi.Last10TxResponse{
|
api.TransactionsContent = []dataserviceapi.Last10TxResponse{
|
||||||
dataserviceapi.Last10TxResponse{
|
dataserviceapi.Last10TxResponse{
|
||||||
Sender: apimocks.AliceChecksum,
|
Sender: apimocks.AliceChecksum,
|
||||||
Recipient: apimocks.BobChecksum,
|
Recipient: apimocks.BobChecksum,
|
||||||
TransferValue: strconv.Itoa(txValue),
|
TransferValue: strconv.Itoa(txValue),
|
||||||
ContractAddress: tokenAddress,
|
ContractAddress: tokenAddress,
|
||||||
TxHash: txHash,
|
TxHash: txHash,
|
||||||
DateBlock: time.Unix(txTimestamp, 0),
|
DateBlock: time.Unix(txTimestamp, 0),
|
||||||
TokenSymbol: tokenSymbol,
|
TokenSymbol: tokenSymbol,
|
||||||
TokenDecimals: strconv.Itoa(tokenDecimals),
|
TokenDecimals: strconv.Itoa(tokenDecimals),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
api.VoucherDataContent = &models.VoucherDataResult{
|
api.VoucherDataContent = &models.VoucherDataResult{
|
||||||
TokenSymbol: tokenSymbol,
|
TokenSymbol: tokenSymbol,
|
||||||
TokenName: tokenName,
|
TokenName: tokenName,
|
||||||
//TokenDecimals: strconv.Itoa(tokenDecimals),
|
//TokenDecimals: strconv.Itoa(tokenDecimals),
|
||||||
TokenDecimals: tokenDecimals,
|
TokenDecimals: tokenDecimals,
|
||||||
SinkAddress: sinkAddress,
|
SinkAddress: sinkAddress,
|
||||||
}
|
}
|
||||||
api.VouchersContent = []dataserviceapi.TokenHoldings{
|
api.VouchersContent = []dataserviceapi.TokenHoldings{
|
||||||
dataserviceapi.TokenHoldings{
|
dataserviceapi.TokenHoldings{
|
||||||
ContractAddress: tokenAddress,
|
ContractAddress: tokenAddress,
|
||||||
TokenSymbol: tokenSymbol,
|
TokenSymbol: tokenSymbol,
|
||||||
TokenDecimals: strconv.Itoa(tokenDecimals),
|
TokenDecimals: strconv.Itoa(tokenDecimals),
|
||||||
Balance: strconv.Itoa(tokenBalance),
|
Balance: strconv.Itoa(tokenBalance),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
lookup.Api = api
|
lookup.Api = api
|
||||||
|
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
storageService := mocks.NewMemStorageService(ctx)
|
storageService := mocks.NewMemStorageService(ctx)
|
||||||
eu := viseevent.NewEventsUpdater(api, storageService)
|
eu := viseevent.NewEventsUpdater(api, storageService)
|
||||||
@ -209,7 +207,7 @@ func TestTokenMint(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ev := &apievent.EventTokenMint{
|
ev := &apievent.EventTokenMint{
|
||||||
To: apimocks.AliceChecksum,
|
To: apimocks.AliceChecksum,
|
||||||
Value: txValue,
|
Value: txValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,8 +230,8 @@ func TestTokenMint(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
fmts := fmt.Sprintf("%%1.%df", tokenDecimals)
|
fmts := fmt.Sprintf("%%1.%df", tokenDecimals)
|
||||||
expect := fmt.Sprintf(fmts, float64(tokenBalance) / math.Pow(10, tokenDecimals))
|
expect := fmt.Sprintf(fmts, float64(tokenBalance)/math.Pow(10, tokenDecimals))
|
||||||
//if !bytes.Equal(v, []byte(strconv.Itoa(tokenBalance))) {
|
|
||||||
if !bytes.Equal(v, []byte(expect)) {
|
if !bytes.Equal(v, []byte(expect)) {
|
||||||
t.Fatalf("expected '%d', got %s", tokenBalance, v)
|
t.Fatalf("expected '%d', got %s", tokenBalance, v)
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package lookup
|
package lookup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
|
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-api/remote"
|
"git.grassecon.net/grassrootseconomics/sarafu-api/remote"
|
||||||
|
"git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
Loading…
Reference in New Issue
Block a user