Compare commits
5 Commits
0c3ef357df
...
b25288db2c
Author | SHA1 | Date | |
---|---|---|---|
b25288db2c | |||
5aed7c647f | |||
8765077177 | |||
4a6e4ebe55 | |||
525eee93d4 |
2
go.mod
2
go.mod
@ -9,6 +9,8 @@ require (
|
|||||||
gopkg.in/leonelquinteros/gotext.v1 v1.3.1
|
gopkg.in/leonelquinteros/gotext.v1 v1.3.1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require gopkg.in/dnaeon/go-vcr.v4 v4.0.1 // indirect
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/alecthomas/participle/v2 v2.0.0 // indirect
|
github.com/alecthomas/participle/v2 v2.0.0 // indirect
|
||||||
github.com/alecthomas/repr v0.2.0 // indirect
|
github.com/alecthomas/repr v0.2.0 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -30,6 +30,8 @@ github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
|
|||||||
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
|
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/dnaeon/go-vcr.v4 v4.0.1 h1:dIFuOqqDZIJ9BTcK+DXmElzypQ6PV9fBQZSIwY+J1yM=
|
||||||
|
gopkg.in/dnaeon/go-vcr.v4 v4.0.1/go.mod h1:65yxh9goQVrudqofKtHA4JNFWd6XZRkWfKN4YpMx7KI=
|
||||||
gopkg.in/leonelquinteros/gotext.v1 v1.3.1 h1:8d9/fdTG0kn/B7NNGV1BsEyvektXFAbkMsTZS2sFSCc=
|
gopkg.in/leonelquinteros/gotext.v1 v1.3.1 h1:8d9/fdTG0kn/B7NNGV1BsEyvektXFAbkMsTZS2sFSCc=
|
||||||
gopkg.in/leonelquinteros/gotext.v1 v1.3.1/go.mod h1:X1WlGDeAFIYsW6GjgMm4VwUwZ2XjI7Zan2InxSUQWrU=
|
gopkg.in/leonelquinteros/gotext.v1 v1.3.1/go.mod h1:X1WlGDeAFIYsW6GjgMm4VwUwZ2XjI7Zan2InxSUQWrU=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
@ -16,6 +16,7 @@ type AccountServiceInterface interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AccountService struct {
|
type AccountService struct {
|
||||||
|
Client *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -34,7 +35,8 @@ type AccountService struct {
|
|||||||
// If no error occurs, this will be nil.
|
// If no error occurs, this will be nil.
|
||||||
//
|
//
|
||||||
func (as *AccountService) CheckAccountStatus(trackingId string) (string, error) {
|
func (as *AccountService) CheckAccountStatus(trackingId string) (string, error) {
|
||||||
resp, err := http.Get(config.TrackStatusURL + trackingId)
|
resp,err := as.Client.Get(config.TrackStatusURL + trackingId)
|
||||||
|
// resp, err := http.Get(config.TrackStatusURL + trackingId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -62,7 +64,8 @@ func (as *AccountService) CheckAccountStatus(trackingId string) (string, error)
|
|||||||
// - publicKey: The public key associated with the account whose balance needs to be checked.
|
// - publicKey: The public key associated with the account whose balance needs to be checked.
|
||||||
func (as *AccountService) CheckBalance(publicKey string) (string, error) {
|
func (as *AccountService) CheckBalance(publicKey string) (string, error) {
|
||||||
|
|
||||||
resp, err := http.Get(config.BalanceURL + publicKey)
|
//resp, err := http.Get(config.BalanceURL + publicKey)
|
||||||
|
resp, err := as.Client.Get(config.BalanceURL + publicKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "0.0", err
|
return "0.0", err
|
||||||
}
|
}
|
||||||
@ -91,7 +94,8 @@ func (as *AccountService) CheckBalance(publicKey string) (string, error) {
|
|||||||
// - error: An error if any occurred during the HTTP request, reading the response, or unmarshalling the JSON data.
|
// - error: An error if any occurred during the HTTP request, reading the response, or unmarshalling the JSON data.
|
||||||
// If no error occurs, this will be nil.
|
// If no error occurs, this will be nil.
|
||||||
func (as *AccountService) CreateAccount() (*models.AccountResponse, error) {
|
func (as *AccountService) CreateAccount() (*models.AccountResponse, error) {
|
||||||
resp, err := http.Post(config.CreateAccountURL, "application/json", nil)
|
//resp, err := http.Post(config.CreateAccountURL, "application/json", nil)
|
||||||
|
resp, err := as.Client.Post(config.CreateAccountURL, "application/json", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
126
internal/handlers/server/accountservice_test.go
Normal file
126
internal/handlers/server/accountservice_test.go
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/alecthomas/assert/v2"
|
||||||
|
"gopkg.in/dnaeon/go-vcr.v4/pkg/recorder"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCheckBalance(t *testing.T) {
|
||||||
|
r, err := recorder.New("custodial/balance")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer r.Stop()
|
||||||
|
|
||||||
|
client := r.GetDefaultClient()
|
||||||
|
|
||||||
|
as := AccountService{
|
||||||
|
Client: client,
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
balance string
|
||||||
|
publicKey string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Test check balance with correct public key",
|
||||||
|
publicKey: "0x216a4A64E1e699F9d65Dd9CbD0058dAB21DeF002",
|
||||||
|
balance: "3.06000000003 CELO",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Test check balance with public key that doesn't exist in the custodial system",
|
||||||
|
balance: "",
|
||||||
|
publicKey: "0x216a4A64E1e699F9d65Dd9CbD0058dAB21DeF00",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
balance, err := as.CheckBalance(tt.publicKey)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to get balance with error %s", err)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, balance, tt.balance, "Expected balance and actual balance should be equal")
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCheckAccountStatus(t *testing.T) {
|
||||||
|
r, err := recorder.New("custodial/status")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer r.Stop()
|
||||||
|
|
||||||
|
client := r.GetDefaultClient()
|
||||||
|
|
||||||
|
as := AccountService{
|
||||||
|
Client: client,
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
status string
|
||||||
|
trackingId string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Test check status with tracking id that exists in the custodial system",
|
||||||
|
trackingId: "bb23945b-65cd-4110-ac2e-a5df40572e18",
|
||||||
|
status: "SUCCESS",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Test check status with tracking id that doesn't exist in the custodial system",
|
||||||
|
status: "",
|
||||||
|
trackingId: "bb23945b-65cd-4110-ac2e-a5df40572e1",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
status, err := as.CheckAccountStatus(tt.trackingId)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to account status with error %s", err)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, status, tt.status, "Expected status and actual status should be equal")
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCreateAccount(t *testing.T) {
|
||||||
|
r, err := recorder.New("custodial/create")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer r.Stop()
|
||||||
|
|
||||||
|
client := r.GetDefaultClient()
|
||||||
|
|
||||||
|
as := AccountService{
|
||||||
|
Client: client,
|
||||||
|
}
|
||||||
|
accountRes, err := as.CreateAccount()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create an account with error %s", err)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, accountRes.Ok, true, "account response status is true")
|
||||||
|
|
||||||
|
}
|
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -73,10 +74,13 @@ func NewHandlers(appFlags *asm.FlagParser, userdataStore db.Db) (*Handlers, erro
|
|||||||
userDb := &utils.UserDataStore{
|
userDb := &utils.UserDataStore{
|
||||||
Db: userdataStore,
|
Db: userdataStore,
|
||||||
}
|
}
|
||||||
|
client := &http.Client{}
|
||||||
h := &Handlers{
|
h := &Handlers{
|
||||||
userdataStore: userDb,
|
userdataStore: userDb,
|
||||||
flagManager: appFlags,
|
flagManager: appFlags,
|
||||||
accountService: &server.AccountService{},
|
accountService: &server.AccountService{
|
||||||
|
Client: client,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
return h, nil
|
return h, nil
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
LOAD authorize_account 6
|
||||||
MAP validate_amount
|
MAP validate_amount
|
||||||
RELOAD get_recipient
|
RELOAD get_recipient
|
||||||
MAP get_recipient
|
MAP get_recipient
|
||||||
@ -6,9 +7,9 @@ MAP get_sender
|
|||||||
MOUT back 0
|
MOUT back 0
|
||||||
MOUT quit 9
|
MOUT quit 9
|
||||||
HALT
|
HALT
|
||||||
LOAD authorize_account 6
|
|
||||||
RELOAD authorize_account
|
RELOAD authorize_account
|
||||||
CATCH incorrect_pin flag_incorrect_pin 1
|
CATCH incorrect_pin flag_incorrect_pin 1
|
||||||
|
CATCH transaction_initiated flag_account_authorized 1
|
||||||
INCMP _ 0
|
INCMP _ 0
|
||||||
INCMP quit 9
|
INCMP quit 9
|
||||||
INCMP transaction_initiated *
|
|
||||||
|
Loading…
Reference in New Issue
Block a user