Compare commits

..

No commits in common. "6200728435c09aa010f65a66862fbcd2e6420bb8" and "59d044602031700f96097cad8dcebbd9ad18d77f" have entirely different histories.

2 changed files with 26 additions and 11 deletions

View File

@ -906,7 +906,7 @@ func (h *Handlers) GetRecipient(ctx context.Context, sym string, input []byte) (
return res, nil
}
// GetSender returns the sessionId (phoneNumber)
// GetSender retrieves the public key from the Gdbm Db
func (h *Handlers) GetSender(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result
@ -915,7 +915,10 @@ func (h *Handlers) GetSender(ctx context.Context, sym string, input []byte) (res
return res, fmt.Errorf("missing session")
}
res.Content = string(sessionId)
store := h.userdataStore
publicKey, _ := store.ReadEntry(ctx, sessionId, utils.DATA_PUBLIC_KEY)
res.Content = string(publicKey)
return res, nil
}
@ -952,12 +955,13 @@ func (h *Handlers) InitiateTransaction(ctx context.Context, sym string, input []
// TODO
// Use the amount, recipient and sender to call the API and initialize the transaction
store := h.userdataStore
publicKey, _ := store.ReadEntry(ctx, sessionId, utils.DATA_PUBLIC_KEY)
amount, _ := store.ReadEntry(ctx, sessionId, utils.DATA_AMOUNT)
recipient, _ := store.ReadEntry(ctx, sessionId, utils.DATA_RECIPIENT)
res.Content = l.Get("Your request has been sent. %s will receive %s from %s.", string(recipient), string(amount), string(sessionId))
res.Content = l.Get("Your request has been sent. %s will receive %s from %s.", string(recipient), string(amount), string(publicKey))
account_authorized_flag, err := h.flagManager.GetFlag("flag_account_authorized")
if err != nil {

View File

@ -509,8 +509,12 @@ func TestGetSender(t *testing.T) {
mockStore := new(mocks.MockUserDataStore)
// Define test data
sessionId := "254712345678"
sessionId := "session123"
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
publicKey := "0xcasgatweksalw1018221"
// Set up the expected behavior of the mock
mockStore.On("ReadEntry", ctx, sessionId, utils.DATA_PUBLIC_KEY).Return([]byte(publicKey), nil)
// Create the Handlers instance with the mock store
h := &Handlers{
@ -518,10 +522,11 @@ func TestGetSender(t *testing.T) {
}
// Call the method
res, _ := h.GetSender(ctx, "get_sender", []byte(""))
res, _ := h.GetSender(ctx, "max_amount", []byte("check_balance"))
//Assert that the public key from readentry operation is what was set as the result content.
assert.Equal(t, publicKey, res.Content)
//Assert that the sessionId is what was set as the result content.
assert.Equal(t, sessionId, res.Content)
}
func TestGetAmount(t *testing.T) {
@ -1279,7 +1284,7 @@ func TestResetInvalidAmount(t *testing.T) {
}
func TestInitiateTransaction(t *testing.T) {
sessionId := "254712345678"
sessionId := "session123"
fm, err := NewFlagManager(flagsPath)
@ -1302,26 +1307,30 @@ func TestInitiateTransaction(t *testing.T) {
tests := []struct {
name string
input []byte
PublicKey []byte
Recipient []byte
Amount []byte
status string
expectedResult resource.Result
}{
{
name: "Test initiate transaction",
name: "Test amount reset",
PublicKey: []byte("0x1241527192"),
Amount: []byte("0.002CELO"),
Recipient: []byte("0x12415ass27192"),
expectedResult: resource.Result{
FlagReset: []uint32{account_authorized_flag},
Content: "Your request has been sent. 0x12415ass27192 will receive 0.002 CELO from 254712345678.",
Content: "Your request has been sent. 0x12415ass27192 will receive 0.002CELO from 0x1241527192.",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Define expected interactions with the mock
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_PUBLIC_KEY).Return(tt.PublicKey, nil)
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_AMOUNT).Return(tt.Amount, nil)
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_RECIPIENT).Return(tt.Recipient, nil)
//mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_AMOUNT, []byte("")).Return(nil)
// Call the method under test
res, _ := h.InitiateTransaction(ctx, "transaction_reset_amount", tt.input)
@ -1334,8 +1343,10 @@ func TestInitiateTransaction(t *testing.T) {
// Assert that expectations were met
mockDataStore.AssertExpectations(t)
})
}
}
func TestQuit(t *testing.T) {