trigger-balance-reload #193
@ -112,6 +112,9 @@ func (h *Handlers) Init(ctx context.Context, sym string, input []byte) (resource
|
|||||||
logg.WarnCtxf(ctx, "handler init called before it is ready or more than once", "state", h.st, "cache", h.ca)
|
logg.WarnCtxf(ctx, "handler init called before it is ready or more than once", "state", h.st, "cache", h.ca)
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
h.pe = nil
|
||||||
|
}()
|
||||||
|
|
||||||
h.st = h.pe.GetState()
|
h.st = h.pe.GetState()
|
||||||
h.ca = h.pe.GetMemory()
|
h.ca = h.pe.GetMemory()
|
||||||
@ -131,7 +134,6 @@ func (h *Handlers) Init(ctx context.Context, sym string, input []byte) (resource
|
|||||||
logg.ErrorCtxf(ctx, "perister fail in handler", "state", h.st, "cache", h.ca)
|
logg.ErrorCtxf(ctx, "perister fail in handler", "state", h.st, "cache", h.ca)
|
||||||
return r, fmt.Errorf("cannot get state and memory for handler")
|
return r, fmt.Errorf("cannot get state and memory for handler")
|
||||||
}
|
}
|
||||||
h.pe = nil
|
|
||||||
|
|
||||||
logg.DebugCtxf(ctx, "handler has been initialized", "state", h.st, "cache", h.ca)
|
logg.DebugCtxf(ctx, "handler has been initialized", "state", h.st, "cache", h.ca)
|
||||||
|
|
||||||
@ -1688,10 +1690,9 @@ func (h *Handlers) GetVoucherDetails(ctx context.Context, sym string, input []by
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenSymbol := voucherData.TokenSymbol
|
res.Content = fmt.Sprintf(
|
||||||
tokenName := voucherData.TokenName
|
"Name: %s\nSymbol: %s\nCommodity: %s\nLocation: %s", voucherData.TokenName, voucherData.TokenSymbol, voucherData.TokenCommodity, voucherData.TokenLocation,
|
||||||
|
)
|
||||||
res.Content = fmt.Sprintf("%s %s", tokenSymbol, tokenName)
|
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
@ -2024,3 +2024,42 @@ func TestSetVoucher(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(t, string(tempData.TokenSymbol), res.Content)
|
assert.Equal(t, string(tempData.TokenSymbol), res.Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetVoucherDetails(t *testing.T) {
|
||||||
|
ctx, store := InitializeTestStore(t)
|
||||||
|
fm, err := NewFlagManager(flagsPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Logf(err.Error())
|
||||||
|
}
|
||||||
|
mockAccountService := new(mocks.MockAccountService)
|
||||||
|
|
||||||
|
sessionId := "session123"
|
||||||
|
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||||
|
expectedResult := resource.Result{}
|
||||||
|
|
||||||
|
tokA_AAddress := "0x0000000000000000000000000000000000000000"
|
||||||
|
|
||||||
|
h := &Handlers{
|
||||||
|
userdataStore: store,
|
||||||
|
flagManager: fm.parser,
|
||||||
|
accountService: mockAccountService,
|
||||||
|
}
|
||||||
|
err = store.WriteEntry(ctx, sessionId, common.DATA_ACTIVE_ADDRESS, []byte(tokA_AAddress))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
tokenDetails := &models.VoucherDataResult{
|
||||||
|
TokenName: "Token A",
|
||||||
|
TokenSymbol: "TOKA",
|
||||||
|
TokenLocation: "Kilifi,Kenya",
|
||||||
|
TokenCommodity: "Farming",
|
||||||
|
}
|
||||||
|
expectedResult.Content = fmt.Sprintf(
|
||||||
|
"Name: %s\nSymbol: %s\nCommodity: %s\nLocation: %s", tokenDetails.TokenName, tokenDetails.TokenSymbol, tokenDetails.TokenCommodity, tokenDetails.TokenLocation,
|
||||||
|
)
|
||||||
|
mockAccountService.On("VoucherData", string(tokA_AAddress)).Return(tokenDetails, nil)
|
||||||
|
|
||||||
|
res, err := h.GetVoucherDetails(ctx, "SessionId", []byte(""))
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, expectedResult, res)
|
||||||
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
type VoucherDataResult struct {
|
type VoucherDataResult struct {
|
||||||
TokenName string `json:"tokenName"`
|
TokenName string `json:"tokenName"`
|
||||||
TokenSymbol string `json:"tokenSymbol"`
|
TokenSymbol string `json:"tokenSymbol"`
|
||||||
TokenDecimals int `json:"tokenDecimals"`
|
TokenDecimals int `json:"tokenDecimals"`
|
||||||
SinkAddress string `json:"sinkAddress"`
|
SinkAddress string `json:"sinkAddress"`
|
||||||
|
TokenCommodity string `json:"tokenCommodity"`
|
||||||
|
TokenLocation string `json:"tokenLocation"`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user