From 23b4180e50ba97801cf87647805aa90acc05dfa7 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 20 Jan 2025 17:27:19 +0300 Subject: [PATCH 1/6] persist aliases,construct the fqdn --- dev/api.go | 235 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 133 insertions(+), 102 deletions(-) diff --git a/dev/api.go b/dev/api.go index ff5ae02..03af12a 100644 --- a/dev/api.go +++ b/dev/api.go @@ -12,65 +12,66 @@ import ( "strings" "time" - "github.com/gofrs/uuid" - "git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/db" - "git.grassecon.net/grassrootseconomics/sarafu-api/models" - "git.grassecon.net/grassrootseconomics/sarafu-api/event" + "git.defalsify.org/vise.git/logging" "git.grassecon.net/grassrootseconomics/common/phone" + "git.grassecon.net/grassrootseconomics/sarafu-api/event" + "git.grassecon.net/grassrootseconomics/sarafu-api/models" "git.grassecon.net/grassrootseconomics/visedriver/storage" + "github.com/gofrs/uuid" dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api" ) var ( - logg = logging.NewVanilla().WithDomain("sarafu-api.devapi") + logg = logging.NewVanilla().WithDomain("sarafu-api.devapi") aliasRegex = regexp.MustCompile("^\\+?[a-zA-Z0-9\\-_]+$") + searchDomain = ".sarafu.local" ) const ( - pubKeyLen int = 20 - hashLen int = 32 - defaultDecimals = 6 - zeroAddress string = "0x0000000000000000000000000000000000000000" + pubKeyLen int = 20 + hashLen int = 32 + defaultDecimals = 6 + zeroAddress string = "0x0000000000000000000000000000000000000000" ) type Tx struct { - Track string `json: "track"` - Hsh string `json:"hash"` - To string `json:"to"` - From string `json: "from"` - Voucher string `json: "voucher"` - Value int `json: "value"` - When time.Time `json: "when"` + Track string `json: "track"` + Hsh string `json:"hash"` + To string `json:"to"` + From string `json: "from"` + Voucher string `json: "voucher"` + Value int `json: "value"` + When time.Time `json: "when"` } func (t *Tx) ToTransferEvent() event.EventTokenTransfer { return event.EventTokenTransfer{ - To: t.To, - Value: t.Value, + To: t.To, + Value: t.Value, VoucherAddress: t.Voucher, - TxHash: t.Hsh, - From: t.From, + TxHash: t.Hsh, + From: t.From, } } func (t *Tx) ToMintEvent() event.EventTokenMint { return event.EventTokenMint{ - To: t.To, - Value: t.Value, + To: t.To, + Value: t.Value, VoucherAddress: t.Voucher, - TxHash: t.Hsh, + TxHash: t.Hsh, } } type Account struct { - Track string `json: "track"` - Address string `json: "address"` - Nonce int `json: "nonce"` - DefaultVoucher string `json: "defaultVoucher"` - Balances map[string]int `json: "balances"` - Alias string - Txs []string `json: "txs"` + Track string `json: "track"` + Address string `json: "address"` + Nonce int `json: "nonce"` + DefaultVoucher string `json: "defaultVoucher"` + Balances map[string]int `json: "balances"` + Alias string + Txs []string `json: "txs"` } func (a *Account) ToRegistrationEvent() event.EventCustodialRegistration { @@ -80,45 +81,45 @@ func (a *Account) ToRegistrationEvent() event.EventCustodialRegistration { } type Voucher struct { - Name string `json: "name"` - Address string `json: "address"` - Symbol string `json: "symbol"` - Decimals int `json: "decimals"` - Sink string `json: "sink"` + Name string `json: "name"` + Address string `json: "address"` + Symbol string `json: "symbol"` + Decimals int `json: "decimals"` + Sink string `json: "sink"` Commodity string `json: "commodity"` - Location string `json: "location"` + Location string `json: "location"` } type DevAccountService struct { - db db.Db - accounts map[string]Account - accountsTrack map[string]string - accountsAlias map[string]string - vouchers map[string]Voucher - vouchersAddress map[string]string - txs map[string]Tx - txsTrack map[string]string - toAutoCreate bool - autoVouchers []string + db db.Db + accounts map[string]Account + accountsTrack map[string]string + accountsAlias map[string]string + vouchers map[string]Voucher + vouchersAddress map[string]string + txs map[string]Tx + txsTrack map[string]string + toAutoCreate bool + autoVouchers []string autoVoucherValue map[string]int - defaultAccount string - emitterFunc event.EmitterFunc - pfx []byte -// accountsSession map[string]string + defaultAccount string + emitterFunc event.EmitterFunc + pfx []byte + // accountsSession map[string]string } func NewDevAccountService(ctx context.Context, ss storage.StorageService) *DevAccountService { svc := &DevAccountService{ - accounts: make(map[string]Account), - accountsTrack: make(map[string]string), - accountsAlias: make(map[string]string), - vouchers: make(map[string]Voucher), - vouchersAddress: make(map[string]string), - txs: make(map[string]Tx), - txsTrack: make(map[string]string), + accounts: make(map[string]Account), + accountsTrack: make(map[string]string), + accountsAlias: make(map[string]string), + vouchers: make(map[string]Voucher), + vouchersAddress: make(map[string]string), + txs: make(map[string]Tx), + txsTrack: make(map[string]string), autoVoucherValue: make(map[string]int), - defaultAccount: zeroAddress, - pfx: []byte("__"), + defaultAccount: zeroAddress, + pfx: []byte("__"), } if ss != nil { var err error @@ -151,7 +152,7 @@ func (das *DevAccountService) WithPrefix(pfx []byte) *DevAccountService { } func (das *DevAccountService) prefixKeyFor(k string, v string) []byte { - return append(das.pfx, []byte(k + "_" + v)...) + return append(das.pfx, []byte(k+"_"+v)...) } func (das *DevAccountService) loadAccount(ctx context.Context, pubKey string, v []byte) error { @@ -183,6 +184,15 @@ func (das *DevAccountService) loadTx(ctx context.Context, hsh string, v []byte) return nil } +func (das *DevAccountService) loadAlias(ctx context.Context, alias string, key []byte) error { + result, err := das.db.Get(ctx, key) + if err != nil { + return err + } + das.accountsAlias[alias] = strings.ReplaceAll(string(result), `"`, "") + return nil +} + func (das *DevAccountService) loadItem(ctx context.Context, k []byte, v []byte) error { var err error s := string(k) @@ -194,6 +204,8 @@ func (das *DevAccountService) loadItem(ctx context.Context, k []byte, v []byte) err = das.loadAccount(ctx, ss[1], v) } else if ss[0] == "tx" { err = das.loadTx(ctx, ss[1], v) + } else if ss[0] == "alias" { + err = das.loadAlias(ctx, ss[1], k) } else { logg.ErrorCtxf(ctx, "unknown double underscore key", "key", ss[0]) } @@ -225,7 +237,7 @@ func (das *DevAccountService) loadAll(ctx context.Context) error { } func (das *DevAccountService) indexAll(ctx context.Context) error { - for k, v := range(das.txs) { + for k, v := range das.txs { acc := das.accounts[v.From] acc.Txs = append(acc.Txs, k) logg.TraceCtxf(ctx, "add tx to sender index", "from", v.From, "tx", k) @@ -265,8 +277,8 @@ func (das *DevAccountService) AddVoucher(ctx context.Context, symbol string) err z := h.Sum(nil) address := fmt.Sprintf("0x%x", z) das.vouchers[symbol] = Voucher{ - Name: symbol, - Symbol: symbol, + Name: symbol, + Symbol: symbol, Address: address, } das.vouchersAddress[address] = symbol @@ -288,14 +300,14 @@ func (das *DevAccountService) CheckBalance(ctx context.Context, publicKey string if !ok { return nil, fmt.Errorf("balance not found for default token %s pubkey %v", acc.DefaultVoucher, publicKey) } - return &models.BalanceResult { + return &models.BalanceResult{ Balance: strconv.Itoa(bal), - Nonce: json.Number(strconv.Itoa(acc.Nonce)), + Nonce: json.Number(strconv.Itoa(acc.Nonce)), }, nil } func (das *DevAccountService) balanceAuto(ctx context.Context, pubKey string) error { - for _, v := range(das.autoVouchers) { + for _, v := range das.autoVouchers { voucher, ok := das.vouchers[v] if !ok { return fmt.Errorf("balance auto voucher set but not resolved: %s", v) @@ -326,6 +338,23 @@ func (das *DevAccountService) saveAccount(ctx context.Context, acc Account) erro return das.db.Put(ctx, []byte(k), v) } +func (das *DevAccountService) saveAlias(ctx context.Context, alias map[string]string) error { + if das.db == nil { + return fmt.Errorf("Db cannot be nil") + } + for k, v := range alias { + k_ := das.prefixKeyFor("alias", k) + v_, err := json.Marshal(v) + if err != nil { + return err + } + das.db.SetSession("") + das.db.SetPrefix(db.DATATYPE_USERDATA) + return das.db.Put(ctx, []byte(k_), v_) + } + return nil +} + func (das *DevAccountService) CreateAccount(ctx context.Context) (*models.AccountResult, error) { var b [pubKeyLen]byte uid, err := uuid.NewV4() @@ -341,7 +370,7 @@ func (das *DevAccountService) CreateAccount(ctx context.Context) (*models.Accoun } pubKey := fmt.Sprintf("0x%x", b) acc := Account{ - Track: uid.String(), + Track: uid.String(), Address: pubKey, } @@ -363,7 +392,7 @@ func (das *DevAccountService) CreateAccount(ctx context.Context) (*models.Accoun if das.emitterFunc != nil { msg := event.Msg{ - Typ: event.EventRegistrationTag, + Typ: event.EventRegistrationTag, Item: acc, } err = das.emitterFunc(ctx, msg) @@ -374,7 +403,7 @@ func (das *DevAccountService) CreateAccount(ctx context.Context) (*models.Accoun logg.TraceCtxf(ctx, "account created", "account", acc) return &models.AccountResult{ - PublicKey: pubKey, + PublicKey: pubKey, TrackingId: uid.String(), }, nil } @@ -392,22 +421,20 @@ func (das *DevAccountService) TrackAccountStatus(ctx context.Context, publicKey func (das *DevAccountService) FetchVouchers(ctx context.Context, publicKey string) ([]dataserviceapi.TokenHoldings, error) { var holdings []dataserviceapi.TokenHoldings - acc, ok := das.accounts[publicKey] + _, ok := das.accounts[publicKey] if !ok { return nil, fmt.Errorf("account not found (publickey): %v", publicKey) } - for k, v := range(acc.Balances) { - voucher, ok := das.vouchers[k] - if !ok { - return nil, fmt.Errorf("voucher has balance but object not found: %v", k) - } + //TODO: Iterate over the account acc.Balances object + for _, voucher := range das.vouchers { holdings = append(holdings, dataserviceapi.TokenHoldings{ ContractAddress: voucher.Address, - TokenSymbol: voucher.Symbol, - TokenDecimals: strconv.Itoa(voucher.Decimals), - Balance: strconv.Itoa(v), + TokenSymbol: voucher.Symbol, + TokenDecimals: strconv.Itoa(voucher.Decimals), + Balance: strconv.Itoa(500), }) } + return holdings, nil } @@ -417,24 +444,24 @@ func (das *DevAccountService) FetchTransactions(ctx context.Context, publicKey s if !ok { return nil, fmt.Errorf("account not found (publickey): %v", publicKey) } - for i, v := range(acc.Txs) { + for i, v := range acc.Txs { mytx := das.txs[v] if i == 10 { - break + break } voucher, ok := das.vouchers[mytx.Voucher] if !ok { return nil, fmt.Errorf("voucher %s in tx list but not found in voucher list", mytx.Voucher) } lasttx = append(lasttx, dataserviceapi.Last10TxResponse{ - Sender: mytx.From, - Recipient: mytx.To, - TransferValue: strconv.Itoa(mytx.Value), + Sender: mytx.From, + Recipient: mytx.To, + TransferValue: strconv.Itoa(mytx.Value), ContractAddress: voucher.Address, - TxHash: mytx.Hsh, - DateBlock: mytx.When, - TokenSymbol: voucher.Symbol, - TokenDecimals: strconv.Itoa(voucher.Decimals), + TxHash: mytx.Hsh, + DateBlock: mytx.When, + TokenSymbol: voucher.Symbol, + TokenDecimals: strconv.Itoa(voucher.Decimals), }) } return lasttx, nil @@ -450,13 +477,12 @@ func (das *DevAccountService) VoucherData(ctx context.Context, address string) ( return nil, fmt.Errorf("voucher address %v found but does not resolve", address) } return &models.VoucherDataResult{ - TokenName: voucher.Name, - TokenSymbol: voucher.Symbol, - TokenDecimals: voucher.Decimals, - SinkAddress: voucher.Sink, + TokenName: voucher.Name, + TokenSymbol: voucher.Symbol, + TokenDecimals: voucher.Decimals, + SinkAddress: voucher.Sink, TokenCommodity: voucher.Commodity, - TokenLocation: voucher.Location, - + TokenLocation: voucher.Location, }, nil } @@ -481,12 +507,12 @@ func (das *DevAccountService) TokenTransfer(ctx context.Context, amount, from, t } accFrom, ok := das.accounts[from] if !ok { - return nil, fmt.Errorf("sender account %v not found", from) + return nil, fmt.Errorf("sender account %v not found", from) } accTo, ok := das.accounts[to] if !ok { if !das.toAutoCreate { - return nil, fmt.Errorf("recipient account %v not found, and not creating", from) + return nil, fmt.Errorf("recipient account %v not found, and not creating", from) } } @@ -512,13 +538,13 @@ func (das *DevAccountService) TokenTransfer(ctx context.Context, amount, from, t } hsh := fmt.Sprintf("0x%x", b) mytx := Tx{ - Hsh: hsh, - To: accTo.Address, - From: accFrom.Address, + Hsh: hsh, + To: accTo.Address, + From: accFrom.Address, Voucher: voucher.Symbol, - Value: value, - Track: uid.String(), - When: time.Now(), + Value: value, + Track: uid.String(), + When: time.Now(), } err = das.saveTokenTransfer(ctx, mytx) if err != nil { @@ -527,7 +553,7 @@ func (das *DevAccountService) TokenTransfer(ctx context.Context, amount, from, t das.txs[hsh] = mytx if das.emitterFunc != nil { msg := event.Msg{ - Typ: event.EventTokenTransferTag, + Typ: event.EventTokenTransferTag, Item: mytx, } err = das.emitterFunc(ctx, msg) @@ -592,7 +618,12 @@ func (das *DevAccountService) RequestAlias(ctx context.Context, publicKey string alias += "x" } acc.Alias = alias + alias = alias + searchDomain das.accountsAlias[alias] = publicKey + err := das.saveAlias(ctx, map[string]string{alias: publicKey}) + if err != nil { + return nil, fmt.Errorf("Failed to save the account alias with error: %s", err.Error()) + } } logg.DebugCtxf(ctx, "set alias", "addr", publicKey, "alias", alias) return &models.RequestAliasResult{ -- 2.45.2 From 8a47d1d674efa0e79fd3a637759ce9236650c2b2 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 20 Jan 2025 17:28:03 +0300 Subject: [PATCH 2/6] implement request alias --- remote/http/service.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/remote/http/service.go b/remote/http/service.go index 2c1aa85..6057681 100644 --- a/remote/http/service.go +++ b/remote/http/service.go @@ -3,13 +3,14 @@ package http import ( "bytes" "context" - "fmt" "encoding/json" "errors" + "fmt" "io" "log" "net/http" "net/url" + "regexp" "git.grassecon.net/grassrootseconomics/sarafu-api/config" "git.grassecon.net/grassrootseconomics/sarafu-api/models" @@ -17,6 +18,11 @@ import ( dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api" ) +var ( + aliasRegex = regexp.MustCompile("^\\+?[a-zA-Z0-9\\-_]+$") + searchDomain = ".sarafu.eth" +) + type HTTPAccountService struct { } @@ -220,8 +226,17 @@ func (as *HTTPAccountService) CheckAliasAddress(ctx context.Context, alias strin return &r, err } +// TODO: Use actual custodial api to request available alias func (as *HTTPAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) { - return nil, fmt.Errorf("not yet implemented") + var alias string + if !aliasRegex.MatchString(hint) { + return nil, fmt.Errorf("alias hint does not match: %s", publicKey) + } + alias = hint + alias = alias + searchDomain + return &models.RequestAliasResult{ + Alias: alias, + }, nil } // TODO: remove eth-custodial api dependency -- 2.45.2 From ed549cba7046818638f28ce28fae15c3eb344bc8 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 20 Jan 2025 20:11:08 +0300 Subject: [PATCH 3/6] bind session id for aliases,soft code voucher balance --- dev/api.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/dev/api.go b/dev/api.go index 03af12a..0f93789 100644 --- a/dev/api.go +++ b/dev/api.go @@ -23,16 +23,17 @@ import ( ) var ( - logg = logging.NewVanilla().WithDomain("sarafu-api.devapi") - aliasRegex = regexp.MustCompile("^\\+?[a-zA-Z0-9\\-_]+$") - searchDomain = ".sarafu.local" + logg = logging.NewVanilla().WithDomain("sarafu-api.devapi") + aliasRegex = regexp.MustCompile("^\\+?[a-zA-Z0-9\\-_]+$") + searchDomain = ".sarafu.local" ) const ( - pubKeyLen int = 20 - hashLen int = 32 - defaultDecimals = 6 - zeroAddress string = "0x0000000000000000000000000000000000000000" + pubKeyLen int = 20 + hashLen int = 32 + defaultDecimals = 6 + zeroAddress string = "0x0000000000000000000000000000000000000000" + defaultVoucherBalance float64 = 500.00 ) type Tx struct { @@ -105,7 +106,6 @@ type DevAccountService struct { defaultAccount string emitterFunc event.EmitterFunc pfx []byte - // accountsSession map[string]string } func NewDevAccountService(ctx context.Context, ss storage.StorageService) *DevAccountService { @@ -342,13 +342,17 @@ func (das *DevAccountService) saveAlias(ctx context.Context, alias map[string]st if das.db == nil { return fmt.Errorf("Db cannot be nil") } + sessionId, ok := ctx.Value("SessionId").(string) + if !ok { + return fmt.Errorf("unresolved session id") + } for k, v := range alias { k_ := das.prefixKeyFor("alias", k) v_, err := json.Marshal(v) if err != nil { return err } - das.db.SetSession("") + das.db.SetSession(sessionId) das.db.SetPrefix(db.DATATYPE_USERDATA) return das.db.Put(ctx, []byte(k_), v_) } @@ -431,7 +435,7 @@ func (das *DevAccountService) FetchVouchers(ctx context.Context, publicKey strin ContractAddress: voucher.Address, TokenSymbol: voucher.Symbol, TokenDecimals: strconv.Itoa(voucher.Decimals), - Balance: strconv.Itoa(500), + Balance: strconv.Itoa(int(defaultVoucherBalance)), }) } -- 2.45.2 From 99c704f6ff3ccdf7a83f97ba7bf01be446266c26 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 20 Jan 2025 20:12:56 +0300 Subject: [PATCH 4/6] implement request alias based on dev implementation --- remote/http/service.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/remote/http/service.go b/remote/http/service.go index 6057681..40aa4a1 100644 --- a/remote/http/service.go +++ b/remote/http/service.go @@ -5,7 +5,6 @@ import ( "context" "encoding/json" "errors" - "fmt" "io" "log" "net/http" @@ -13,14 +12,15 @@ import ( "regexp" "git.grassecon.net/grassrootseconomics/sarafu-api/config" + "git.grassecon.net/grassrootseconomics/sarafu-api/dev" "git.grassecon.net/grassrootseconomics/sarafu-api/models" + "git.grassecon.net/grassrootseconomics/visedriver/testutil/mocks" "github.com/grassrootseconomics/eth-custodial/pkg/api" dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api" ) var ( - aliasRegex = regexp.MustCompile("^\\+?[a-zA-Z0-9\\-_]+$") - searchDomain = ".sarafu.eth" + aliasRegex = regexp.MustCompile("^\\+?[a-zA-Z0-9\\-_]+$") ) type HTTPAccountService struct { @@ -228,15 +228,9 @@ func (as *HTTPAccountService) CheckAliasAddress(ctx context.Context, alias strin // TODO: Use actual custodial api to request available alias func (as *HTTPAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) { - var alias string - if !aliasRegex.MatchString(hint) { - return nil, fmt.Errorf("alias hint does not match: %s", publicKey) - } - alias = hint - alias = alias + searchDomain - return &models.RequestAliasResult{ - Alias: alias, - }, nil + storageService := mocks.NewMemStorageService(ctx) + svc := dev.NewDevAccountService(ctx, storageService) + return svc.RequestAlias(ctx, publicKey, hint) } // TODO: remove eth-custodial api dependency -- 2.45.2 From fa355e37293f2c1da8b43599e892ec0866dd99a7 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 20 Jan 2025 22:28:16 +0300 Subject: [PATCH 5/6] handle accounts created via the api,add getter for the account aliases --- dev/api.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/dev/api.go b/dev/api.go index 0f93789..aa5edec 100644 --- a/dev/api.go +++ b/dev/api.go @@ -324,6 +324,10 @@ func (das *DevAccountService) balanceAuto(ctx context.Context, pubKey string) er return nil } +func (das *DevAccountService) GetAliases(ctx context.Context) map[string]string { + return das.accountsAlias +} + func (das *DevAccountService) saveAccount(ctx context.Context, acc Account) error { if das.db == nil { return nil @@ -598,12 +602,22 @@ func (das *DevAccountService) applyPhoneAlias(ctx context.Context, publicKey str func (das *DevAccountService) RequestAlias(ctx context.Context, publicKey string, hint string) (*models.RequestAliasResult, error) { var alias string + uid, err := uuid.NewV4() if !aliasRegex.MatchString(hint) { return nil, fmt.Errorf("alias hint does not match: %s", publicKey) } acc, ok := das.accounts[publicKey] if !ok { - return nil, fmt.Errorf("address %s not found", publicKey) + //Handle accounts created via the api + acc = Account{ + Track: uid.String(), + Address: publicKey, + } + err = das.saveAccount(ctx, acc) + if err != nil { + return nil, err + } + das.accounts[publicKey] = acc } alias = hint isPhone, err := das.applyPhoneAlias(ctx, publicKey, alias) -- 2.45.2 From a63164bcf531131f10b3358ed21d98931db9e934 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Tue, 21 Jan 2025 08:45:03 +0300 Subject: [PATCH 6/6] fix failing test --- dev/api_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dev/api_test.go b/dev/api_test.go index 2382bf0..ca00d96 100644 --- a/dev/api_test.go +++ b/dev/api_test.go @@ -9,6 +9,7 @@ import ( func TestApiRequestAlias(t *testing.T) { ctx := context.Background() + ctx = context.WithValue(ctx, "SessionId", "+25471234565") storageService := mocks.NewMemStorageService(ctx) svc := NewDevAccountService(ctx, storageService) ra, err := svc.CreateAccount(ctx) @@ -16,10 +17,10 @@ func TestApiRequestAlias(t *testing.T) { t.Fatal(err) } addr := ra.PublicKey - + _, err = svc.RequestAlias(ctx, addr, "+254f00") if err == nil { - t.Fatalf("expected error") + t.Fatalf("expected error") } alias := "+254712345678" rb, err := svc.RequestAlias(ctx, addr, alias) @@ -39,6 +40,7 @@ func TestApiRequestAlias(t *testing.T) { if err != nil { t.Fatal(err) } + alias = "foo.sarafu.local" if rb.Alias != alias { t.Fatalf("expected '%s', got '%s'", alias, rb.Alias) } @@ -56,12 +58,12 @@ func TestApiRequestAlias(t *testing.T) { t.Fatal(err) } addr = ra.PublicKey - + alias = "foox" rb, err = svc.RequestAlias(ctx, addr, alias) if err != nil { t.Fatal(err) } - alias = "foox" + alias = "foox.sarafu.local" if rb.Alias != alias { t.Fatalf("expected '%s', got '%s'", alias, rb.Alias) } -- 2.45.2